Re: [PATCH] x86/hweight: Don't clobber %rdi
From: Borislav Petkov
Date: Mon Aug 08 2016 - 14:37:51 EST
On Mon, Aug 08, 2016 at 11:21:20AM -0700, Linus Torvalds wrote:
> ...
> in arch/x86/events/intel/core.c, which then corrupts something related
> to the event constraints, and then you get the oops in
> x86_perf_event_update() later.
Damn.
And I thought that when I hold on to the C ABI and since %rdi is
callee-clobbered, I can simply do "call __sw_hweight64" from within an
asm() statement and it'll all be fine.
Ok, so do you think it would work too if I stated that the input
register gets clobbered:
asm (ALTERNATIVE("call __sw_hweight64", POPCNT64, X86_FEATURE_POPCNT)
: "="REG_OUT (res)
: REG_IN (w)
: REG_IN);
(untested of course).
Because my primitive way of thinking would go like this: well, the input
register is in the list of clobbers and gcc should take care of stashing
it away if it is live across the hweight call. IOW, let gcc do the
push/pop instead of us doing it explicitly.
Or am I missing some aspect?
> The compiler has absolutely nothing to do with this. It's all assembly
> language and an inline asm.
I meant I shouldn't do the compiler's job by coding __sw_hweightXX in
asm. Even though arch/x86/lib/hweight.S is basically copied gcc asm
output, more or less.
But that got us rid of the special calling convention which was a win in
itself.
Thanks.
--
Regards/Gruss,
Boris.
ECO tip #101: Trim your mails when you reply.
--