2000-10-14 02:01:05

by Linus Torvalds

[permalink] [raw]
Subject: Re: [PATCH] Clean up x86 write-protect test



On Fri, 13 Oct 2000, Brian Gerst wrote:
>
> Also, Could somebody who has a machine with a known buggy processor give
> this patch a try?

I like the patch. Would you mind re-writing the exception handling the
other way around, though:

Instead of doing it like this:

+ __asm__ __volatile__(
+ " movb %0,%1 \n"
+ "1: movb %1,%0 \n"
+ " jmp 3f \n"
+ "2: incl %2 \n"
+ "3: \n"
+ ".section __ex_table,\"a\"\n"
+ " .align 4 \n"
+ " .long 1b,2b \n"
+ ".previous \n"
+:"=m" (*(char *) vaddr),
+ "=q" (tmp_reg),
+ "=r" (flag)
+:"2" (flag)
+:"memory");

it would be nicer to simply to the other way around (if exception happens,
"flag" is untouched and jumped over, if not, flag is cleared):

+ __asm__ __volatile__(
+ " movb %0,%1 \n"
+ "1: movb %1,%0 \n"
+ " xor %2,%2 \n"
+ "2: \n"
+ ".section __ex_table,\"a\"\n"
+ " .align 4 \n"
+ " .long 1b,2b \n"
+ ".previous \n"
+:"=m" (*(char *) vaddr),
+ "=q" (tmp_reg),
+ "=r" (flag)
+:"2" (1)
+:"memory");

which basically means that if flag stays as "1", then the exception
happened, but if the exception didn't happen the code will fall through
the "xor" and clear "flag".

After that, and testing that it works on a broken machine, I'd love to
apply it.

Linus