Received: by 2002:ab2:6c55:0:b0:1fd:c486:4f03 with SMTP id v21csp221166lqp; Tue, 11 Jun 2024 22:07:12 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUAbsm8COOIDdW8hMKm2Y6rhQPmMd/4PHoWJw5tqUyBtVZpxz6DMWztiCewogdwbFBTnLVu6Y+i1IuPxqFdPYGThw/5eCdiQVl5RDYdBw== X-Google-Smtp-Source: AGHT+IFDxzF4PdZDei+FLi84CHhwfCzYUbkCdJfgJvva06HwBK93Mvs0KVjuxXxSJO3C3XwvY5A7 X-Received: by 2002:a17:906:eb06:b0:a6e:9dab:14f9 with SMTP id a640c23a62f3a-a6f47d526e3mr35828666b.10.1718168832186; Tue, 11 Jun 2024 22:07:12 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718168832; cv=pass; d=google.com; s=arc-20160816; b=IA0KGmzIqDUYUyTiPhfKuYnGtxXXuqacD34T+Pun+BmV28Dqcedaelmy0c2G76pPsF 0K4qLQTWK9nUp4zZmTbQmsCzN9aiw5FQ998wYY/fF7JWNTafCcmdUfNhykAJgErdl2nY A84D3pD9PtXVybYMGjnADGeZ3YUunlS/VmXBsP/bAVc+Nb4TBqmHfQS2jQl1jsf5tpNQ fe1IlWVNevCN8qyYE5DhYMDb0Le/nf/MSKcjIlzP/Zd/Q2ljjV39Q7Fh0jKqtWN1emDh ahxEjRPCRRt70r8gGeJyCskVcBQOaYLtZ31HS+pKooLBrSWrdRoD1ZtdSvlVE8yV8id4 rihw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=3YfIkXzYir268XHNs4tpV+aQLJW0QnBzbY6kDtND3To=; fh=5iUbb5prJbxK7tg6eiT5Ya/wikKv43WTjnA6GgBNkjk=; b=s+OPjptfx5u0M/zoGuz0dxBnBTwTTSHTXxw9CNbKphjecB8MUWRCGwWvzEGOqE0Ahg 3+pDtquyQVU4v/yBU3ifcGsXWNOi/PFNalgV9NMJN2NLNWOMR3vyuYGSb4yXx+UqyW00 uZP+RIzBGIMr45VBJg+kx6y31r2dnB2wb0zkzkHaFKU2D1ZAiwVs3Fy2jWU75W7yBMvY YFiB2OOVIEE4s8+blhPDPGF/PV+d8QpID7Mt468uvzd5NcUqMnO6FOfrpudB0rIEJp5+ DAagtMaoLtm3LazXiON7AVZpW2Jf2v9BrnAbPf+u1dAcHkeesLvj6KAxDj0dFBJjkg4g eXlg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="SNw/2eOe"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-210933-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-210933-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id a640c23a62f3a-a6f20f8e939si261789066b.271.2024.06.11.22.07.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Jun 2024 22:07:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-210933-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="SNw/2eOe"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-210933-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-210933-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 am.mirrors.kernel.org (Postfix) with ESMTPS id B78321F24D09 for ; Wed, 12 Jun 2024 05:07:11 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 541DF374CB; Wed, 12 Jun 2024 05:06:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="SNw/2eOe" 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 623D331A83; Wed, 12 Jun 2024 05:06:56 +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=1718168816; cv=none; b=gD7Vscj7bBiklGrxS+Z34TJoktiF7JBv5vYG85a3yI1uphLQbdfraHKG9VEmMTIuNG7hoAZpKIlz1U/M7l2407WQRLBlHyxnjstiwOn5bQl4XmnkTPnbJXzoBCsMJkck7doy5rIV3q9EevUmtwpElmQnSFH4pTui5HULjOdJYsw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718168816; c=relaxed/simple; bh=cTRnCH0nwBTkCrdtg0XBxRgW7inGdX9jawKr9m856vE=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=Ll+gGYHsBapVhSwCsseguLjFcK+PUAS3/h5ouBGkShTKg/5RgdGaZBQEjdmMeS7YpJrQkJA7/5cLdpUEiKD2N6a9dp1J3FI07SYVVFM0BRTiFgwHAqMCyPrVdvzDwqHq1+Hor6Cv4gQ4QY7Hwhn0O84c4U0ZwiSVNWl9naDkFr8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=SNw/2eOe; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id D9B04C4AF4D; Wed, 12 Jun 2024 05:06:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1718168815; bh=cTRnCH0nwBTkCrdtg0XBxRgW7inGdX9jawKr9m856vE=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=SNw/2eOe1RXhRuZQyqkln1jwVD/P6RrLFm5AGi/Yg8PN4okQURPBR7ZolLdFaH+VI vN/YEZ+mvJNUsyYfl7wU3TsQkX8BoR3Qbx+v+oB5HEkfM8Ql7rO+jFUJHd0WjTGSwA OVrX6rN2cmS+51c1g1fEbWjuSWolSWmVjPvToKDpZmsxPOmPMSkLoyRD+2lw4POzC2 X1enO3Pw2WrrKtzTG/NKUhc/1f3Mv83cHBVeeiRuA0LQqOyxtep2RodvLseIfEhJLd dCrl6B7PTHsA1uxOhpj9dtKQUfTOPElE5a7SF8vjadCK13bccYlzudwWM398js7eDY Sm8lMstedQHlQ== Received: by mail-lf1-f50.google.com with SMTP id 2adb3069b0e04-52c8342af5eso3595215e87.3; Tue, 11 Jun 2024 22:06:55 -0700 (PDT) X-Forwarded-Encrypted: i=1; AJvYcCXYtSWaTzgMQF3ult42BulMUfhcfKkHX2+oyGY+qhfSjK85hvTLFQGSGFD31PN1qhWT/bK6H9RbC/89nY1nsav6zZ9nL/aHBrgpi/eMyxXpHnS08isk8MGMZhizv+RmCIk7at4WveX53Iu/ X-Gm-Message-State: AOJu0YwNvdoP4YWj6uZllfUDRHa2lG4qUZu/rPh6EyFkhwvc5RMmcTz0 qgsa9dyUt5YfEztOtUVox/GKy0UEY7pslchHYYbyhSxRlM1YqTSWVcvE5YFmt8BopovSeyMJnDx MoQr5jzHu7ScEYRSGamQqEfOlzYI= X-Received: by 2002:a05:6512:210c:b0:52c:83cf:d8f9 with SMTP id 2adb3069b0e04-52c9a3b7961mr270022e87.13.1718168814502; Tue, 11 Jun 2024 22:06:54 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240612-as-instr-opt-wrussq-v2-1-bd950f7eead7@gmail.com> In-Reply-To: <20240612-as-instr-opt-wrussq-v2-1-bd950f7eead7@gmail.com> From: Masahiro Yamada Date: Wed, 12 Jun 2024 14:06:18 +0900 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH RFC v2] kbuild/x86: Use $(KBUILD_AFLAGS) in Kbuild's version of $(as-instr) To: 0x7f454c46@gmail.com Cc: Borislav Petkov , Dave Hansen , Ingo Molnar , "H. Peter Anvin" , Thomas Gleixner , x86@kernel.org, linux-kernel@vger.kernel.org, linux-kbuild@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Wed, Jun 12, 2024 at 12:29=E2=80=AFPM Dmitry Safonov via B4 Relay wrote: > > 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[sha= 1]=3D6571ad50d8f12eece053f1bac7a95a2c767f32c9, for GNU/Linux 3.2.0, strippe= d > > 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 +=3D -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 :=3D ( > > > > # $(if-success,,,) > > # Return if exits with 0, otherwise. > > -if-success =3D $(shell,{ $(1); } >/dev/null 2>&1 && echo "$(2)" || ech= o "$(3)") > > +if-success =3D $(shell,echo '$(1)' 1>&2;{ $(1); } >/dev/null 2>&1 && e= cho "$(2)" || echo "$(3)") > > I got the following output for the toolchain check, before: > > linux @Bru-na-Boinne% make ARCH=3Dx86_64 oldconfig V=3D1 2>&1 | grep wr= us > > printf "%b\n" "wrussq %rax,(%rbx)" | gcc -c -x assembler-with-cpp -o /= dev/null - > > and after: > > linux @Bru-na-Boinne% make ARCH=3Dx86_64 oldconfig V=3D1 2>&1 | grep wr= us > > 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). > > In order to eliminate a possible circular dependency of > Kconfig =3D> arch/.../Makefile =3D> Kconfig =3D> ... > which exist i.e. in arm64/Makefile for KASAN_SHADOW_SCALE_SHIFT that > depends on CONFIG_KASAH_SW_TAGS and CONFIG_KASAN_GENERIC kconfigs, > ignore KBUILD_AFLAGS difference in auto.conf.cmd as it is expected that > the variable will differ between fist and later Makefile passes. > Use that in Kconfig toolchain checks. > > Signed-off-by: Dmitry Safonov <0x7f454c46@gmail.com> Perhaps, you could pass CROSS_COMPILE=3Dx86_64-linux-gnu- when building the 64-bit kernel. x86_64-linux-gnu-gcc may understand 'wrussq %rax,(%rbx)' even if the default gcc does not. I am not sure if x86_64-linux-gnu-gcc is available on your build machine. Anyway, I think it should be possible to fix it with less hacky code. Please test this patch: https://lore.kernel.org/all/20240612050257.3670768-1-masahiroy@kernel.org/T= /#u --=20 Best Regards Masahiro Yamada