Received: by 2002:ab2:1347:0:b0:1f4:ac9d:b246 with SMTP id g7csp78999lqg; Wed, 10 Apr 2024 16:24:47 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUiHm7MRnczb/CH15wIJWpIZvAhOl3YwfYFFjfSip4W3kYP1iQt4pPgO+LwqDwiOd8QW3oH9tu28LraYJAH9L8td/MZNYAhzmNLXurAtg== X-Google-Smtp-Source: AGHT+IEDwSTOJdORN5L48VtJvTseWqPE1i4y2I4cRQLhGJhT8wznqB2fxvoqbKK+n1MWbrHwkWI8 X-Received: by 2002:a05:622a:1911:b0:42e:984f:1497 with SMTP id w17-20020a05622a191100b0042e984f1497mr5316703qtc.17.1712791487395; Wed, 10 Apr 2024 16:24:47 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712791487; cv=pass; d=google.com; s=arc-20160816; b=CV4molmduFjxeUSs0H1jcaSwaNNJSVsIbBzv9eV0FSl3hP4++lpwDu3JUIQ/1r8NI3 Ib7ujdJHF7YPTARYzWl+CDS9qulNAbJAKmSdrlnIJZKShtoAysFKH1WKJ9JT88Sk8Zjv 8TVz/zbPXddtBhaf6wzS5AbGcj9CqFu/lD1m9RaRd/Us5ZqdDI1/mxGHDQhz17l2Muzd u5no7xbGoCOtXDTV+X2jpynhvt8b3s8DUrrwDvDgyZm5k0bxHmf6nrjVno7yjCMwkpF0 WNLbvxZPFrUy9Mk/CigDka6XtQiyy6T5iExg3HC9caaG6LBqyAHKFuFRZv7weK/PxdoY 1DVA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=reply-to:cc:to:message-id:content-transfer-encoding:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:subject:date :from:dkim-signature; bh=dOCD5LO5Au4Yyn+szI1vbR5015clRG0djPTILq0+Ves=; fh=puWkgxIkWLoBnwyViHKvzEcX4xWM2rHvVTGm5u0v2P0=; b=brGOl+KDsre+HV7F34oa4Zd1/IXmKty2IGtJMw4+3zaByPYHTZsizTyw1/IIcrWNyK ZnLEsvJkRXFgjNHFVyYLcj2357erzB80HTa30Xb6ioGrI11NON3G1SwRRmipkbTR8v10 byTuH5WiGuooi5tUTa3+JcTBUwEHZTFIkDdSBobEiSRhgVc42u0zgsnYxhdJUgtirMTn yDwoJJAKg5nkh0642MvJIuULRn25QGcrgEipqcGEyIS5u63vqY56Vmt99ZDNdhDpKDMV 7PxC76ZWWHHdbq3DN/i33NxmwZ5BUSowrs8ubo68cbhXxu4/E/cvJMQc8tspJl0qE7kb e7bg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Yfvkk3tt; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-139529-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-139529-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id p19-20020ac84613000000b00434c8a8d09asi238575qtn.394.2024.04.10.16.24.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Apr 2024 16:24:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-139529-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Yfvkk3tt; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-139529-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-139529-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 238DF1C21AA0 for ; Wed, 10 Apr 2024 23:24:47 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 084AC36B08; Wed, 10 Apr 2024 23:24:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Yfvkk3tt" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1D88F39FEF; Wed, 10 Apr 2024 23:24:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712791481; cv=none; b=W9e9KDviiKJ1zXDR4FFVByBWGVhbFxsizPPnRxA7dcsSPGkIZ+NVwrouBSj62KW/OQ246LZZvbFUC4EfHGL3Jcf3DmqYIdcX2RjVkYDX1DYwITZx6cFOPb9fEC3n8jtnqVV0vi0BjVKCbHAeXj5cX/iCNQA2PUNj8crEdWcUuAE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712791481; c=relaxed/simple; bh=VSMecFXyAePUCgsz3RR9EcSrH9KxBkZyQT9d7RkgPQw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To:Cc; b=OXL6VO74CvnrCnNNHvGKac4cD7ZQ2GH1UnE/3QedjS4EX2tVWKWeuOX6Ffqgi8DX1jMc9K946haj8j/YDGLV3h4U1urXzC1vOi4dzFn18AqpfjPXxN9YmyYE0cJHEPlOh3jwJsSpKtVYQ9a2TZWjDLamrWJ3UgHuYBKfygNFhpo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Yfvkk3tt; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPS id AFA8DC433F1; Wed, 10 Apr 2024 23:24:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712791480; bh=VSMecFXyAePUCgsz3RR9EcSrH9KxBkZyQT9d7RkgPQw=; h=From:Date:Subject:To:Cc:Reply-To:From; b=Yfvkk3ttkevWKhpWjnk5GUGu1t24eMxzcURqrCguTdfq5JV+aI3NxM3bmw2FNdLIQ J8sp/IgJqS3yQ5vicxx7zMcLR56cBPPuvx591BPIP4ZreB9vs2YGp9JG5lXG1wyzD1 cldfHM3nM0FI/IQOfijlM0eWeT9BDhyDTeeEJM24SgdAN1ca7iI/Xy19Sw9Cla7YUx QN0nV2A0DFAnN/7h7JHY16SnKHayp7MSqvIUHHA4mT02PEk0FoJjW6HnRUw69l9N5/ hOTxVA7NiTMZoi9DVlUdVAtR18nceI0r1mZtgZ/EqM6ugraah2ks3FCbi4Ca/407x0 bVoGYVpW1uedA== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9C67DCD128A; Wed, 10 Apr 2024 23:24:40 +0000 (UTC) From: Dmitry Safonov via B4 Relay Date: Thu, 11 Apr 2024 00:24:19 +0100 Subject: [PATCH] kbuild/x86: Use $(KBUILD_AFLAGS) in Kbuild's version of $(as-instr) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20240411-as-instr-opt-wrussq-v1-1-99b1a1a99f93@gmail.com> X-B4-Tracking: v=1; b=H4sIAKIfF2YC/x3MwQ6CMAyA4VchPdtkjEWIr2I8lFGhBwa2Q00I7 +7w+B3+fwdjFTa4VTsov8VkSQX1pYI4URoZZSgG73xwoXZIhpIsKy5rxo9uZi8MHcem5ebqXYB SrspP+f6v90dxT8bYK6U4na+ZLLPCcfwA/OQD3n4AAAA= To: Borislav Petkov , Dave Hansen , Ingo Molnar , "H. Peter Anvin" , Masahiro Yamada , Thomas Gleixner , x86@kernel.org Cc: linux-kernel@vger.kernel.org, linux-kbuild@vger.kernel.org, Dmitry Safonov <0x7f454c46@gmail.com> X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1712791479; l=3696; i=0x7f454c46@gmail.com; s=20240410; h=from:subject:message-id; bh=+llTpAM1iXzBXWQE4E3YCDwpY226FU9sEdHRM+0QVpA=; b=8Y1dDthNatE9Xo7kK5BBVgBX5fExnKyrSVxyAhLa+w7TzV95A+BV7gNVUNoKRliO6m+acwj3rYt4 kenCR8tzAX9gMGMTbmRDQllZ2+0SgDhz3Kcz3A1eOdUDCXljlqae X-Developer-Key: i=0x7f454c46@gmail.com; a=ed25519; pk=cFSWovqtkx0HrT5O9jFCEC/Cef4DY8a2FPeqP4THeZQ= X-Endpoint-Received: by B4 Relay for 0x7f454c46@gmail.com/20240410 with auth_id=152 X-Original-From: Dmitry Safonov <0x7f454c46@gmail.com> Reply-To: 0x7f454c46@gmail.com From: Dmitry Safonov <0x7f454c46@gmail.com> At Arista some products use compatible 32-bit userspace running on x86. As a part of disto build for ia32 it also compiles the 64-bit kernel. While the toolchain for the kernel build is yet the same, with 64-bit gcc: > / @Bru-na-Boinne% file /usr/bin/gcc-11 > /usr/bin/gcc-11: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=6571ad50d8f12eece053f1bac7a95a2c767f32c9, for GNU/Linux 3.2.0, stripped It seems that gcc is being smart and detects that it's running in a 32-bit container (personality flag? 32-bit mmap base? something else inherited post-exec? haven't yet figured it out) and by default tries to build 32-bit binaries. That results in a failing toolchain check: > / @Bru-na-Boinne% printf "%b\n" "wrussq %rax, (%rbx)" | /usr/bin/gcc-11 -Wa,--fatal-warnings -c -x assembler-with-cpp -o /dev/null - > : Assembler messages: > :1: Error: `wrussq' is only supported in 64-bit mode Which passes when -m64 is directly specify for the build check: > / @Bru-na-Boinne% printf "%b\n" "wrussq %rax, (%rbx)" | /usr/bin/gcc-11 -m64 -Wa,--fatal-warnings -c -x assembler-with-cpp -o /dev/null - > / @Bru-na-Boinne% echo $? > 0 As a result, kbuild produces different value for CONFIG_AS_WRUSS for native 64-bit containers and ia32 containers with 64-bit gcc, which produces different kernels with enabled/disabled CONFIG_X86_USER_SHADOW_STACK. arch/x86/Makefile already properly defines KBUILD_AFLAGS += -m64, which is luckly already available at the point of toolchain check in arch/x86/Kconfig.assembler By hacking around Kbuild variable the following way: > --- a/scripts/Kconfig.include > +++ b/scripts/Kconfig.include > @@ -13,7 +13,8 @@ left_paren := ( > > # $(if-success,,,) > # Return if exits with 0, otherwise. > -if-success = $(shell,{ $(1); } >/dev/null 2>&1 && echo "$(2)" || echo "$(3)") > +if-success = $(shell,echo '$(1)' 1>&2;{ $(1); } >/dev/null 2>&1 && echo "$(2)" || echo "$(3)") I got the following output for the toolchain check, before: > linux @Bru-na-Boinne% make ARCH=x86_64 oldconfig V=1 2>&1 | grep wrus > printf "%b\n" "wrussq %rax,(%rbx)" | gcc -c -x assembler-with-cpp -o /dev/null - and after: > linux @Bru-na-Boinne% make ARCH=x86_64 oldconfig V=1 2>&1 | grep wrus > printf "%b\n" "wrussq %rax,(%rbx)" | gcc -D__ASSEMBLY__ -fno-PIE -m64 -c -x assembler-with-cpp -o /dev/null - Which seems appropriate to me. This also reflects the existing definition in scripts/Makefile.compiler for $(as-instr) that already has $(KBUILD_AFLAGS). Signed-off-by: Dmitry Safonov <0x7f454c46@gmail.com> --- scripts/Kconfig.include | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/Kconfig.include b/scripts/Kconfig.include index 3ee8ecfb8c04..d8574c1faf2d 100644 --- a/scripts/Kconfig.include +++ b/scripts/Kconfig.include @@ -33,7 +33,7 @@ ld-option = $(success,$(LD) -v $(1)) # $(as-instr,) # Return y if the assembler supports , n otherwise -as-instr = $(success,printf "%b\n" "$(1)" | $(CC) $(CLANG_FLAGS) -Wa$(comma)--fatal-warnings -c -x assembler-with-cpp -o /dev/null -) +as-instr = $(success,printf "%b\n" "$(1)" | $(CC) $(CLANG_FLAGS) $(KBUILD_AFLAGS) -Wa$(comma)--fatal-warnings -c -x assembler-with-cpp -o /dev/null -) # check if $(CC) and $(LD) exist $(error-if,$(failure,command -v $(CC)),C compiler '$(CC)' not found) --- base-commit: 2c71fdf02a95b3dd425b42f28fd47fb2b1d22702 change-id: 20240410-as-instr-opt-wrussq-48ec37e36204 Best regards, -- Dmitry Safonov <0x7f454c46@gmail.com>