Steven Rostedt
2006-Nov-01 15:50 UTC
[Xen-devel] [PATCH] comment fix in uaccess for x86_32
In the xen/include/asm-x86/x68_32/uaccess.h For range_not_ok we have: /* * Test whether a block of memory is a valid user space address. * Returns 0 if the range is valid, nonzero otherwise. * * This is equivalent to the following test: * (u33)addr + (u33)size >= (u33)HYPERVISOR_VIRT_START */ #define __range_not_ok(addr,size) ({ \ unsigned long flag,sum; \ asm("addl %3,%1 ; sbbl %0,%0; cmpl %1,%4; sbbl $0,%0" \ :"=&r" (flag), "=r" (sum) \ :"1" (addr),"g" ((int)(size)),"r" (HYPERVISOR_VIRT_START)); \ flag; }) The code is fine, but it is *not* equivalent to >=, but it is for >. This is not a bug in the code, since it is fine to have an address go up to the limit, since that just means it touches the byte before the limit. But I''d figure that the comment should really reflect what it is doing. Here''s a simple program to prove that the comment is wrong: ---- #include <stdio.h> #define HYPERVISOR_VIRT_START 0xFC000000UL #define chk(addr,size) ({\ unsigned long flag,sum; \ asm("addl %3,%1 ; sbbl %0,%0; cmpl %1,%4; sbbl $0,%0" \ :"=&r" (flag), "=r" (sum) \ :"1" (addr),"g" ((int)(size)),"r" (HYPERVISOR_VIRT_START)); \ flag; }) int main (int argc, char **argv) { unsigned long addr; addr = 0xfc000000UL - 10; printf("chk 9 = %d\n",chk(addr,9)); printf("chk 10 = %d\n",chk(addr,10)); printf("chk 11 = %d\n",chk(addr,11)); return -1; } ---- Which produces: chk 9 = 0 chk 10 = 0 chk 11 = -1 So I''ve added a patch to update the comment. Signed-off-by: Steven Rostedt <srostedt@redhat.com> _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel