Linux内核:分散列表的最大“长度"为允许吗? [英] Linux kernel: scatterlist maximum "length" allowed?
问题描述
已经解决了我的Linux加密示例,并且可以正确调用aead密码,我遇到了一个有趣的问题.
Having solved my Linux crypto example, and I can call the aead ciphers correctly, I have come across an interesting issue.
我将散列表定义如下:
struct scatterlist sg[2];
sg_init_table(sg, 2 );
sg_set_buf(&sg[0], address, 512);
sg_set_buf(&sg[1], mac, 16);
aead_request_set_crypt(req, sg, sg, 512, iv);
crypto_aead_encrypt(req);
,效果很好.但是,如果将缓冲区大小从512072(即131072)增加,则会非常频繁地"出现恐慌.
and that works great. However, if you increase the buffer size from 512, to say, 131072, then it will "very often" panic.
BUG: unable to handle kernel paging request at ffffeb04000cea80
IP: [<ffffffff812f4880>] scatterwalk_done+0x50/0x60
现在,由于所有密码最终都调用了scatterwalk_函数,因此我假定,这是将sg-> length设置为较大值的问题.大概这么大,有时可能会跳到下一页.
Now, since all ciphers end up calling the scatterwalk_ functions, I assume it is a problem with setting the sg->length to something large. Presumably so large it sometimes crosses over to the next page.
在这里应该做什么?我是否必须将其拆分为多个散列表,以确保每个散列表都不会转到下一页?这听起来很麻烦,或者是否有功能对我有用?还是只需要确保每个页面都可用"?
What is the proper thing to do here? Do I have to split it up into many scatterlists, making sure each one does not go over to the next page? That sounds like a hassle, or is there a function that does this for me? Or do I simply need to make sure each page is "available" ?
推荐答案
好吧,事实上,有两件事困扰着我.第一个是偶尔交给我的内存实际上来自vmalloc()分配的内存.这意味着我应该改用sg_set_page(,vmalloc_to_page()).
Ok, there were in fact 2 things bothering me here. The first one was that occasionally the memory handed to me was in fact from vmalloc() allocated memory. Which means I should use sg_set_page( , vmalloc_to_page() ) instead.
第二个问题是,scatterwalk函数不正确,如果设置了也会生成mac的密码作为第二缓冲区,则易于测试;
The second problem is that the scatterwalk functions are incorrect, it is easy to test, if you setup any cipher that also generates a mac, as a second buffer;
cipherout = kmalloc( size, ...
macout = kmalloc( maclen, ...
这通常会起作用,因为新分配的内存在页面边界上.但是,将其更改为;
this will generally work, because new allocated memory is on page boundary. However, change it to;
macout = kmalloc( maclen + 16, ...
macout += 16;
我要做的就是分配一个更大的缓冲区,然后以16个字节为单位启动内存.(+ 1024或+3480无关紧要),这将使scatterwalk感到恐慌.在linux-crypto邮件列表上有一个建议的补丁程序,对将来很有用,但现在对我没有帮助.我需要确保mac地址是对齐的,否则,请分配临时缓冲区(至少很小).
All I do is allocate a larger buffer, then start the memory 16 bytes in. (+1024, or +3480, doesn't matter) This will make scatterwalk panic. There is a suggested patch on the linux-crypto mailing list, which is great for future, but does not help me right now. I need to make sure the mac address is aligned, and if not, allocate temporary buffer (which is small at least).
这篇关于Linux内核:分散列表的最大“长度"为允许吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!