mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Sebastian Sumpf <Sebastian.Sumpf@genode-labs.com>
To: tglx@linutronix.de, mingo@redhat.com, bp@alien8.de,
	dave.hansen@linux.intel.com, x86@kernel.org
Cc: linux-kernel@vger.kernel.org
Subject: [Bug report] __arch_hweight32/64 x86
Date: Mon, 26 Jun 2023 22:49:44 +0200	[thread overview]
Message-ID: <cb18590f-686e-cc53-7781-1a36e91faade@genode-labs.com> (raw)

Hello kernel developers,

I recently stumbled over a bug in the inline assembly of '__arch_hweight32' and 
'__arch_hweight64'  in 'arch/x86/include/asm/arch_hweight.h' (present in 6.4 as 
well):

! asm (ALTERNATIVE("call __sw_hweight64", "popcntq %1, %0",
! X86_FEATURE_POPCNT)
! 			 : "="REG_OUT (res)
! 			 : REG_IN (w));

The 'ALTERNATIVE' macro checks for the popcnt feature. In case this fails the 
'__sw_hweight' C-function is called from inline assembly with rax and rdi as 
intput/output operands. However, the code does not contain a clobber list of any 
callee safe registers that might be touched by the '__sw_height64' C-function. 
Therefore, these registers will not be restored upon function return by the 
compiler. This leads to varying exceptions/bad behavior caused by the thus 
corrupted registers later on.

Kind regards,

Sebastian


-- 
Sebastian Sumpf
Genode Labs

http://www.genode-labs.com · http://genode.org

Genode Labs GmbH · Amtsgericht Dresden · HRB 28424 · Sitz Dresden
Geschäftsführer: Dr.-Ing. Norman Feske, Christian Helmuth




             reply	other threads:[~2023-06-26 21:10 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-26 20:49 Sebastian Sumpf [this message]
2023-06-26 21:06 ` Borislav Petkov
2023-06-26 21:42   ` Sebastian Sumpf
2023-06-26 22:41     ` Dave Hansen
2023-06-27  4:25       ` Borislav Petkov
2023-06-27 16:57         ` Sebastian Sumpf
2023-06-29  9:10         ` David Laight

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=cb18590f-686e-cc53-7781-1a36e91faade@genode-labs.com \
    --to=sebastian.sumpf@genode-labs.com \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®