From mboxrd@z Thu Jan 1 00:00:00 1970 From: Steven Rostedt Subject: [PATCH] comment fix in uaccess for x86_32 Date: Wed, 01 Nov 2006 10:50:12 -0500 Message-ID: <4548C234.1090906@redhat.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------030906090003020809030800" Return-path: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: xen-devel@lists.xensource.com List-Id: xen-devel@lists.xenproject.org This is a multi-part message in MIME format. --------------030906090003020809030800 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit 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 #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 --------------030906090003020809030800 Content-Type: text/x-patch; name="xen-comment-uaccess-fix.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="xen-comment-uaccess-fix.patch" diff -r badf51e24549 xen/include/asm-x86/x86_32/uaccess.h --- a/xen/include/asm-x86/x86_32/uaccess.h Fri Oct 27 11:11:46 2006 -0400 +++ b/xen/include/asm-x86/x86_32/uaccess.h Wed Nov 01 10:42:16 2006 -0500 @@ -8,7 +8,7 @@ * Returns 0 if the range is valid, nonzero otherwise. * * This is equivalent to the following test: - * (u33)addr + (u33)size >= (u33)HYPERVISOR_VIRT_START + * (u33)addr + (u33)size > (u33)HYPERVISOR_VIRT_START */ #define __range_not_ok(addr,size) ({ \ unsigned long flag,sum; \ --------------030906090003020809030800 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel --------------030906090003020809030800--