Received: by 2002:a05:7412:3b8b:b0:fc:a2b0:25d7 with SMTP id nd11csp2368632rdb; Mon, 12 Feb 2024 02:29:44 -0800 (PST) X-Google-Smtp-Source: AGHT+IEVawoO2yQIqPHDsy1Edoswr9Fa3zHwPRRpdH8xeiCWzx09MrLmUl2RLeJt5zO3Rlcmpf+Y X-Received: by 2002:a19:f60f:0:b0:511:5c98:acd2 with SMTP id x15-20020a19f60f000000b005115c98acd2mr3692339lfe.37.1707733784319; Mon, 12 Feb 2024 02:29:44 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707733784; cv=pass; d=google.com; s=arc-20160816; b=kowv5flc9yJFr3MlmS03o0UQIvKRJJ8Fh1KEfPXAYOw2gEMFYjEfxCPgThJTXYmPDu fRgeed/6x47k27i4nyepOFBMovpHamZif5BaMrv6eDePaJd69bponl6x2smA0GH0c6by OkEnPkMBn44n+oc65rUdDRDLy6v/zerWB49BEFNS5Nh7xM9/oCGZs0bLUN4WTGQp1LZp byMaJoue/3igSMOX9gAPfPHDvfv6oK4MdEzS5N39cXmbxRtJcUPB2AFQuehZmlGaaWRm btb6Y8QfeZAvc4up6UxpuxUnZSwYwkNfpW/K3xHigAuKUZFOo+kQBFVtN81qugHsDj/B STdQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=8zzxZzAd70wLVlqCQfwTbwt/dFp7veEPvkKLq3mmCGc=; fh=fQtdPmFPGQ+mAPKyFa6+yX28n8vRdmxjHP8eo+dklik=; b=vZTZy1gynlIeSyKyEWLDi3NyzCIcHmBAuKYpAheDuRSxLr355O3RqxbTOuTHWk0ry5 sDJY2cJ828dKAdVxmzFebOavl4jcfJtS7AURcoa6qbhbGaUYmqn6xAFVc/e8zw1pi875 WXDPzQbKUzi8lvfgl6+ntuSabDJr6+qxkeBLCeBUl9ih5OEJiabaPSXTKxaT8MvsJkqL Frs3N5D/3lI5xOHuyfW8X1PeDO+3fUm4c1SJi4q1qyKGpXKbNJpJyFPGUG5DVIIrAqMO m6NcOrmTuS692YJOhZK25hunLtpYOgbENzOhMU8gWCvWmYJGaMAwONg+EIlDN+lVviIc XkcA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@alien8.de header.s=alien8 header.b=ewZU95JZ; arc=pass (i=1 spf=pass spfdomain=alien8.de dkim=pass dkdomain=alien8.de dmarc=pass fromdomain=alien8.de); spf=pass (google.com: domain of linux-kernel+bounces-61309-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-61309-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alien8.de X-Forwarded-Encrypted: i=2; AJvYcCWyVaE2Ok8zyYkALw2noaEO+K/EiI3IbQ0v2nDXqegGsIyx+3LOzVng6shQTiT1KmzKyNbWq5T+oohp5GLyc4EHv9Gk7E/bjljdDYZSJg== Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id b17-20020a170906491100b00a385f1fcea7si55090ejq.682.2024.02.12.02.29.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 02:29:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-61309-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=@alien8.de header.s=alien8 header.b=ewZU95JZ; arc=pass (i=1 spf=pass spfdomain=alien8.de dkim=pass dkdomain=alien8.de dmarc=pass fromdomain=alien8.de); spf=pass (google.com: domain of linux-kernel+bounces-61309-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-61309-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alien8.de 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 0EFCE1F21739 for ; Mon, 12 Feb 2024 10:29:44 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C717F18049; Mon, 12 Feb 2024 10:29:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (4096-bit key) header.d=alien8.de header.i=@alien8.de header.b="ewZU95JZ" Received: from mail.alien8.de (mail.alien8.de [65.109.113.108]) (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 D25D2179B8; Mon, 12 Feb 2024 10:29:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=65.109.113.108 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707733774; cv=none; b=EttkAj+zji33FwdqQgP75l63Fot0DVD2AytoX6yAJnCmpar11x26oBNJS8XTYIchOotywXCjaXvoCw2fYrvuXohpYlgVMuiHdNsJqt20+mnLGWnnEm4ljpdf6nAkCI9E+YPUbwcJ0iyZwi3nWqhfoHY44NBnUfHsU5PvQri2nYg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707733774; c=relaxed/simple; bh=lM1ikn/+ntRnbPmGODrfBa9eMNqWS/z2GjeqQpt4V0Q=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=iqG8JbQ/Us0RtJAH6gJDUbU+Xm73c40s7MSP1TSrPyV2SLSK1j02t+XBqatSuMBqMmhHYuR9XZf1KB6hrDUqjL4UCm4dMIVA5gJoNlyzLVbZUCY7ZvTCA9Bv32hakX0l77A/TXrTkFHAG8mDKmavfIYaoIsO7q/06JF6gdwg8mM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=alien8.de; spf=pass smtp.mailfrom=alien8.de; dkim=pass (4096-bit key) header.d=alien8.de header.i=@alien8.de header.b=ewZU95JZ; arc=none smtp.client-ip=65.109.113.108 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=alien8.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=alien8.de Received: from localhost (localhost.localdomain [127.0.0.1]) by mail.alien8.de (SuperMail on ZX Spectrum 128k) with ESMTP id 54CE940E01A9; Mon, 12 Feb 2024 10:29:28 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at mail.alien8.de Authentication-Results: mail.alien8.de (amavisd-new); dkim=pass (4096-bit key) header.d=alien8.de Received: from mail.alien8.de ([127.0.0.1]) by localhost (mail.alien8.de [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id Qfqc-ypnMKxE; Mon, 12 Feb 2024 10:29:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alien8.de; s=alien8; t=1707733765; bh=8zzxZzAd70wLVlqCQfwTbwt/dFp7veEPvkKLq3mmCGc=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=ewZU95JZ5AgG6rZJLPSyQ4+uco/ylQ/tMZeYqEi7wKs9BhYt/fG7UUUw5O9c+EANz PSom6AgWUMW2IS8WNEUftXLmPq3pN41pcL/lPl3Gs6sVikGhK3Uv147SDRM8qFdvI6 O4ICiy7mrjH18ayfOBcEHRXSI6KU7zjCK+FPdkrx5XyyVDvrNUmK2FIFkjCrUY9t07 nvzxQimDDhYzoLZ/30kpmiOwB5+s5SJLLA0GPjtbH2OhEd6GpQvU2vLDKH5OACoh1G x6of9WfDLm8z5xPXQIpU5179BSwfJtwmo/F5n+6nHTVmrW2ALHtwLNfqohPSK3dJex 6mv7RMbVLCXcVyjluiK0DvUKxPZQJX35vKF2OgcMN8GTmDVlu+J/P8efvxpIzznLs5 rSdU+n7H8mrAxoeQFuNMu3BI9kHDsGDETqPzTo1hCZU6qiXdg/ThRjEoX/Tb/EvajN MDn4GSgKo/gzOq5gv9mJ8vEjCA+/zEBCindjhc+OeCGhW1bIBjK1hsHd3hKxmzky79 fYJiCPIT3BcOQJ7wOUlO0HtgmUFu/x4VyJL+53TbPc3MTLnVijXoCKik3ByfmwzdLN vFdwoJq+FzycmgelzaQn/+VPw3wnvDRgmxWLpW74v7xdmEab8qX0+E4Pv6uzS4FS+l 1ln5F/fr/a3P8lcfbf0/v0YQ= Received: from zn.tnic (pd953021b.dip0.t-ipconnect.de [217.83.2.27]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature ECDSA (P-256) server-digest SHA256) (No client certificate requested) by mail.alien8.de (SuperMail on ZX Spectrum 128k) with ESMTPSA id A5EF940E0192; Mon, 12 Feb 2024 10:29:07 +0000 (UTC) Date: Mon, 12 Feb 2024 11:29:01 +0100 From: Borislav Petkov To: Ard Biesheuvel Cc: linux-kernel@vger.kernel.org, Ard Biesheuvel , Kevin Loughlin , Tom Lendacky , Dionna Glaze , Thomas Gleixner , Ingo Molnar , Dave Hansen , Andy Lutomirski , Arnd Bergmann , Nathan Chancellor , Nick Desaulniers , Justin Stitt , Kees Cook , Brian Gerst , linux-arch@vger.kernel.org, llvm@lists.linux.dev Subject: Re: [PATCH v3 08/19] x86/head64: Replace pointer fixups with PIE codegen Message-ID: <20240212102901.GVZcny7WeK_ZWt0HEP@fat_crate.local> References: <20240129180502.4069817-21-ardb+git@google.com> <20240129180502.4069817-29-ardb+git@google.com> 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-Disposition: inline In-Reply-To: <20240129180502.4069817-29-ardb+git@google.com> On Mon, Jan 29, 2024 at 07:05:11PM +0100, Ard Biesheuvel wrote: > From: Ard Biesheuvel > > Some of the C code in head64.c may be called from a different virtual > address than it was linked at. Currently, we deal with this by using Yeah, make passive pls: "Currently, this is done by using... " > ordinary, position dependent codegen, and fixing up all symbol > references on the fly. This is fragile and tricky to maintain. It is > also unnecessary: we can use position independent codegen (with hidden ^^^ Ditto: "use ..." In the comments below too, pls, where it says "we". > visibility) to ensure that all compiler generated symbol references are > RIP-relative, removing the need for fixups entirely. > > It does mean we need explicit references to kernel virtual addresses to > be generated by hand, so generate those using a movabs instruction in > inline asm in the handful places where we actually need this. > > Signed-off-by: Ard Biesheuvel > --- > arch/x86/Makefile | 8 ++ > arch/x86/boot/compressed/Makefile | 2 +- > arch/x86/include/asm/desc.h | 3 +- > arch/x86/include/asm/setup.h | 4 +- > arch/x86/kernel/Makefile | 5 ++ > arch/x86/kernel/head64.c | 88 +++++++------------- > arch/x86/kernel/head_64.S | 5 +- > 7 files changed, 51 insertions(+), 64 deletions(-) > > diff --git a/arch/x86/Makefile b/arch/x86/Makefile > index 1a068de12a56..2b5954e75318 100644 > --- a/arch/x86/Makefile > +++ b/arch/x86/Makefile > @@ -168,6 +168,14 @@ else > KBUILD_CFLAGS += -mcmodel=kernel > KBUILD_RUSTFLAGS += -Cno-redzone=y > KBUILD_RUSTFLAGS += -Ccode-model=kernel > + > + PIE_CFLAGS-$(CONFIG_STACKPROTECTOR) += -fno-stack-protector Main Makefile has KBUILD_CFLAGS += -fno-PIE and this ends up being: gcc -Wp,-MMD,arch/x86/kernel/.head64.s.d -nostdinc ... -fno-PIE ... -fpie ... -fverbose-asm -S -o arch/x86/kernel/head64.s arch/x86/kernel/head64.c Can you pls remove -fno-PIE from those TUs which use PIE_CFLAGS so that there's no confusion when staring at V=1 output? > + PIE_CFLAGS-$(CONFIG_LTO) += -fno-lto > + > + PIE_CFLAGS := -fpie -mcmodel=small $(PIE_CFLAGS-y) \ > + -include $(srctree)/include/linux/hidden.h > + > + export PIE_CFLAGS > endif > > # Other than that, that code becomes much more readable, cool! Thx. -- Regards/Gruss, Boris. https://people.kernel.org/tglx/notes-about-netiquette