Re: [PATCH 10/11] x86, rwsem: provide __down_write_killable

Borislav Petkov
2016-04-20T20:45:01Z

On Wed, Apr 20, 2016 at 11:04:05AM -0700, H. Peter Anvin wrote:
> The reason it breaks is because the same register can't be an
> input-output register and a separate input. However, the input side of
> the input-output is probably undefined, and so gcc may not notice.

So Michal and I talked about this a while ago. Why do we need the '"a"
(sem)' input dependency if '"+a" (ret)' already supplies the same thing?

There's also that "=d" (tmp) thing which we don't really need as an
output, right?

I.e., can we simplify like this?

---
#define ____down_write(sem, slow_path) \
({ \
long tmp = RWSEM_ACTIVE_WRITE_BIAS; \
struct rw_semaphore* ret = sem; \
\
asm volatile("# beginning down_write\n\t" \
LOCK_PREFIX " xadd %[tmp],(%[ret])\n\t" \
/* adds 0xffff0001, returns the old value */ \
" test " __ASM_SEL(%w[tmp],%k[tmp]) "," __ASM_SEL(%w[tmp],%k[tmp]) "\n\t" \
/* was the active mask 0 before? */\
" jz 1f\n" \
" call " slow_path "\n" \
"1:\n" \
"# ending down_write" \
: "+m" (sem->count), [ret] "+a" (ret) \
: [tmp] "d" (tmp) \
: "memory", "cc"); \
ret; \
})

--
Regards/Gruss,
Boris.

ECO tip #101: Trim your mails when you reply.