Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1457982

Re: [PATCH] x86/hweight: Don't clobber %rdi

From Borislav Petkov <bp@alien8.de>
Newsgroups linux.kernel
Subject Re: [PATCH] x86/hweight: Don't clobber %rdi
Date 2016-08-08 20:40 +0200
Message-ID <s3XCW-4YT-11@gated-at.bofh.it> (permalink)
References <s3WGR-4qo-25@gated-at.bofh.it> <s3X9U-4P8-21@gated-at.bofh.it> <s3Xtg-4VJ-17@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


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.
--

Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH] x86/hweight: Don't clobber %rdi ville.syrjala@linux.intel.com - 2016-08-08 19:40 +0200
  Re: [PATCH] x86/hweight: Don't clobber %rdi Linus Torvalds <torvalds@linux-foundation.org> - 2016-08-08 20:00 +0200
    Re: [PATCH] x86/hweight: Don't clobber %rdi Peter Zijlstra <peterz@infradead.org> - 2016-08-08 20:40 +0200
      Re: [PATCH] x86/hweight: Don't clobber %rdi Jiri Kosina <jikos@kernel.org> - 2016-08-08 21:00 +0200
        Re: [PATCH] x86/hweight: Don't clobber %rdi Borislav Petkov <bp@alien8.de> - 2016-08-08 21:40 +0200
  Re: [PATCH] x86/hweight: Don't clobber %rdi Borislav Petkov <bp@alien8.de> - 2016-08-08 20:10 +0200
    Re: [PATCH] x86/hweight: Don't clobber %rdi Linus Torvalds <torvalds@linux-foundation.org> - 2016-08-08 20:30 +0200
      Re: [PATCH] x86/hweight: Don't clobber %rdi Borislav Petkov <bp@alien8.de> - 2016-08-08 20:40 +0200
        Re: [PATCH] x86/hweight: Don't clobber %rdi Linus Torvalds <torvalds@linux-foundation.org> - 2016-08-08 20:50 +0200
          Re: [PATCH] x86/hweight: Don't clobber %rdi Borislav Petkov <bp@alien8.de> - 2016-08-08 21:00 +0200

csiph-web