Re: [RFC] x86: bitops asm constraint fixes

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Jan Beulich
Date: Monday, March 17, 2008 - 2:08 am

>>> Jeremy Fitzhardinge <jeremy@goop.org> 14.03.08 19:56 >>>

I'm mainly afraid to break some implicit assumptions potentially made
somewhere that the memory clobber is there (as e.g. implicitly
documented for set_bit() by the comment before clear_bit()) ...


Ah, right, it's there just to accompany the memory clobber.


The fact that a char array may be of a size that is not a multiple of the
word size used by bt{,c,r,s}, i.e. you may either touch memory outside
of the actual bit field (problematic if what follows is an atomic variable,
and the bit operation used is not an atomic one, or if the bit array is
mis-aligned and the access would cross a page boundary).


Apparently not, as you can see from the example I gave that gets
fixed with the patch.


Are you expecting int to ever be other than 32-bits wide? I'm afraid a
lot of other code makes assumptions here...


Not really, since ADDR doesn't take addr as parameter either...


It shouldn't in the end, but as long as the atomic ones that do use
memory clobbers don't use proper "m" operands (where it was part of
the purpose of the original mail to find out whether these need to
stay), they'll continue to use ADDR.


Yes, but I fixed this meanwhile by forcing a maximum size structure
to be used as operand when the bit index is not constant, as in

struct __bits { int _[0x7ffffff]; };
...
#define BIT_ADDR "+m" (((volatile int *) addr)[nr >> 5])
#define FULL_ADDR "+m" (*(volatile struct __bits *) addr)
...
static inline void __clear_bit(int nr, volatile void *addr)
{
	if (__builtin_constant_p(nr))
		asm volatile("btr %1,%2" : BIT_ADDR : "Ir" (nr), BASE_ADDR);
	else
		asm volatile("btr %1,%0" : FULL_ADDR : "r" (nr));
}

Of course, it would be even better if we knew the size of the object,
but that would require all of these to become macros (so __typeof__(),
sizeof(), and __alignof__() could be applied). I'm not certain that's
worthwhile.

Jan
--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[RFC] x86: bitops asm constraint fixes, Jan Beulich, (Thu Mar 13, 2:08 am)
Re: [RFC] x86: bitops asm constraint fixes, H. Peter Anvin, (Fri Mar 14, 12:51 am)
Re: [RFC] x86: bitops asm constraint fixes, Jan Beulich, (Fri Mar 14, 1:09 am)
Re: [RFC] x86: bitops asm constraint fixes, Jeremy Fitzhardinge, (Fri Mar 14, 11:56 am)
Re: [RFC] x86: bitops asm constraint fixes, Chuck Ebbert, (Fri Mar 14, 2:07 pm)
Re: [RFC] x86: bitops asm constraint fixes, Jan Beulich, (Mon Mar 17, 2:08 am)
Re: [RFC] x86: bitops asm constraint fixes, Jan Beulich, (Mon Mar 17, 2:16 am)
Re: [RFC] x86: bitops asm constraint fixes, H. Peter Anvin, (Wed Mar 19, 6:19 am)
Re: [RFC] x86: bitops asm constraint fixes, Ingo Molnar, (Fri Mar 21, 6:54 am)