All of lore.kernel.org
 help / color / mirror / Atom feed
From: Arnd Bergmann <arnd@kernel.org>
To: Andy Lutomirski <luto@kernel.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
	Dave Hansen <dave.hansen@linux.intel.com>,
	x86@kernel.org, Nathan Chancellor <nathan@kernel.org>,
	Nick Desaulniers <ndesaulniers@google.com>,
	Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Cc: Arnd Bergmann <arnd@arndb.de>, "H. Peter Anvin" <hpa@zytor.com>,
	Tom Rix <trix@redhat.com>,
	linux-kernel@vger.kernel.org, llvm@lists.linux.dev
Subject: [PATCH] x86: vdso: sanitize asm helpers for vgetcpu.c
Date: Tue,  7 Feb 2023 17:13:41 +0100	[thread overview]
Message-ID: <20230207161349.309901-1-arnd@kernel.org> (raw)

From: Arnd Bergmann <arnd@arndb.de>

The x86 vdso implementation includes a few include/linux/*.h kernel
headers outside of the include/vdso/*.h space.  This causes a new
warning when building with clang, after the vgetcpu code is added
to the vdso32 support on 64-bit kernels:

In file included from arch/x86/entry/vdso/vdso32/vgetcpu.c:2:
In file included from arch/x86/entry/vdso/vdso32/../vgetcpu.c:8:
In file included from include/linux/kernel.h:22:
In file included from include/linux/bitops.h:68:
In file included from arch/x86/include/asm/bitops.h:420:
arch/x86/include/asm/arch_hweight.h:49:15: error: invalid input size for constraint 'D'
                         : REG_IN (w));
                                   ^
In file included from arch/x86/entry/vdso/vdso32/vgetcpu.c:2:
In file included from arch/x86/entry/vdso/vdso32/../vgetcpu.c:8:
In file included from include/linux/kernel.h:25:
In file included from include/linux/math.h:6:
arch/x86/include/asm/div64.h:85:34: error: invalid output size for constraint '=a'
        asm ("mulq %2; divq %3" : "=a" (q)
                                        ^

Unlike gcc, clang checks inline asm constraints before dead code
elimination, which breaks both __arch_hweight64() and mul_u64_u64_div_u64()
when these are included with CONFIG_64BIT set but compiled with clang -m32,
even when there are no callers.

Change both affected headers to the check for 32-bit vs 64-bit is done
correctly for vdso32. It would be nice to also limit the included headers
further, to avoid subtle differences in the header contents, but that
requires a larger cleanup.

Fixes: 92d33063c081 ("x86/vdso: Provide getcpu for x86-32.")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 arch/x86/entry/vdso/vdso32/vgetcpu.c | 2 ++
 arch/x86/include/asm/arch_hweight.h  | 4 ++--
 arch/x86/include/asm/div64.h         | 2 +-
 3 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/arch/x86/entry/vdso/vdso32/vgetcpu.c b/arch/x86/entry/vdso/vdso32/vgetcpu.c
index b777f84ffae9..9f8cf77c7077 100644
--- a/arch/x86/entry/vdso/vdso32/vgetcpu.c
+++ b/arch/x86/entry/vdso/vdso32/vgetcpu.c
@@ -1,2 +1,4 @@
 // SPDX-License-Identifier: GPL-2.0
+#define BUILD_VDSO32
+
 #include "../vgetcpu.c"
diff --git a/arch/x86/include/asm/arch_hweight.h b/arch/x86/include/asm/arch_hweight.h
index ba88edd0d58b..cca0941673e0 100644
--- a/arch/x86/include/asm/arch_hweight.h
+++ b/arch/x86/include/asm/arch_hweight.h
@@ -4,7 +4,7 @@
 
 #include <asm/cpufeatures.h>
 
-#ifdef CONFIG_64BIT
+#if defined(CONFIG_64BIT) && !defined(BUILD_VDSO32)
 #define REG_IN "D"
 #define REG_OUT "a"
 #else
@@ -33,7 +33,7 @@ static inline unsigned int __arch_hweight8(unsigned int w)
 	return __arch_hweight32(w & 0xff);
 }
 
-#ifdef CONFIG_X86_32
+#if defined(CONFIG_X86_32) || defined(BUILD_VDSO32)
 static inline unsigned long __arch_hweight64(__u64 w)
 {
 	return  __arch_hweight32((u32)w) +
diff --git a/arch/x86/include/asm/div64.h b/arch/x86/include/asm/div64.h
index b8f1dc0761e4..97bd076db0b2 100644
--- a/arch/x86/include/asm/div64.h
+++ b/arch/x86/include/asm/div64.h
@@ -2,7 +2,7 @@
 #ifndef _ASM_X86_DIV64_H
 #define _ASM_X86_DIV64_H
 
-#ifdef CONFIG_X86_32
+#if defined(CONFIG_X86_32) || defined(BUILD_VDSO32)
 
 #include <linux/types.h>
 #include <linux/log2.h>
-- 
2.39.1


             reply	other threads:[~2023-02-07 16:13 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-07 16:13 Arnd Bergmann [this message]
2023-02-07 16:18 ` [PATCH] x86: vdso: sanitize asm helpers for vgetcpu.c Borislav Petkov

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=20230207161349.309901-1-arnd@kernel.org \
    --to=arnd@kernel.org \
    --cc=arnd@arndb.de \
    --cc=bigeasy@linutronix.de \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=llvm@lists.linux.dev \
    --cc=luto@kernel.org \
    --cc=mingo@redhat.com \
    --cc=nathan@kernel.org \
    --cc=ndesaulniers@google.com \
    --cc=tglx@linutronix.de \
    --cc=trix@redhat.com \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.