Received: by 2002:a05:7412:5112:b0:fa:6e18:a558 with SMTP id fm18csp51366rdb; Mon, 22 Jan 2024 11:35:12 -0800 (PST) X-Google-Smtp-Source: AGHT+IGgGRljRbsk4q9bpurykDQb4t39ITkLHYMRiA0YztIkz/vSx8TxPrZPdGIFMN8suVBNcN1C X-Received: by 2002:a17:903:2487:b0:1d7:6a42:616a with SMTP id p7-20020a170903248700b001d76a42616amr341671plw.114.1705952112428; Mon, 22 Jan 2024 11:35:12 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705952112; cv=pass; d=google.com; s=arc-20160816; b=BtEVSNCah8kF7sXhchW01gZUteej4Ivr20Po030TGQG49qFDt70wmEpre4+LqnFYcC gJSZWOVf/oooj40zvGRdNTIpwi2puiSn3QgMId+RXGb43Z4JdCw7Wh0JkE1Qa01Tgq7N A7XVBq89Q/jSduwOXHjAR+oI8kYq07HXy0siS69ytsaKjLBcfpPOSzo59UG2ghrZeyui n+GRnZ/4CZh8TWTxkxr49bJL8kMAipJcP6mxAnfl7fDBcPmYY1xpvKFDg/rUN1E7lSxC wDzWlc5KrcRS9MwNPjGmPn64wkXaTYXeBPLGfJJV2lfIA2mkMeMX5FMbO0LzUeXiHX1x BPFg== 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=dsyX6o96ll0tborqmT2tH2D5yYkTiItob646Hhae/V0=; fh=c4He1Hv+G+hPTT7zyAv+zurM3DuFXgbk1JmBgw+u4d4=; b=w5YMUWie8l/3R8hZ/5q70YzLXNBy2VZmWSalUaViOeS/gThJYJDwaLJeds3lz0fGnj H4RPdhY8HtysPFXdyP49BnzD/uGKOi5LytYWsrH8mWC40u8DAAAaH2eA5/7voGpsqnf8 OWxhBjWoUtPSg2u+LlC92oUamQNOECoCZ1VBoUZKmpd4YlRDt4ls7Ddl6tyhb+yH0+il hxYk/HkHpuP5ohOhjAHQrJoK/xbcYLLrXe/e9eVjFXYklK8gTd7O/7oE3K9LzDzL8TJv 7SR0ZNSSVDKkLOJj/gsTAp4M44BgY7s7yBcMyBQftIfJ91wjYVxx6Hzm2jqTHyLBSTkd i68A== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=NLUHDki6; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-34057-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-34057-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id u7-20020a17090282c700b001d4872d1e49si950698plz.76.2024.01.22.11.35.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jan 2024 11:35:12 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-34057-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=NLUHDki6; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-34057-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-34057-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com 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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 17F2229455B for ; Mon, 22 Jan 2024 19:35:12 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 386923F8F8; Mon, 22 Jan 2024 19:35:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="NLUHDki6" Received: from mail-lf1-f48.google.com (mail-lf1-f48.google.com [209.85.167.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C96EC3B790; Mon, 22 Jan 2024 19:35:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.48 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705952103; cv=none; b=U0PRKLaR9hZtOSTnoBsNNSKbhMRkD4NM17299HDhY3N5h4F0qYyBuAViZ6DvF/zcGFZXYKo54MQ9s7nkCXGUiUuKztNh4MqiyU+CZvHdGvvUmfEKVSuoFD0lGMm3d69JtdGE2vhuqhx2YG6r53b4BfvatKkB4L/SCzV5oR6Rbf0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705952103; c=relaxed/simple; bh=vdvpcTidybzQ1RK072QFzF5p8j2Hvk8YbCbq1G5RlCs=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=jP83d0Emhd+jp748QHz+iBLwKdq9BBAOcwuo2iPX/cQjK6aUDkCQDH76j87c7hC4lMhfAy4owdog3v9PffPUBBfN6a1IVE6BIDaq+ZnUosj18/b2amFX/HVV7WXUMLix5Dl1tjn2y1IwofnOc23iN2XXfmuWR3Fpgrfe3GgewVw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=NLUHDki6; arc=none smtp.client-ip=209.85.167.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-lf1-f48.google.com with SMTP id 2adb3069b0e04-50e7abe4be4so4737029e87.2; Mon, 22 Jan 2024 11:35:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1705952099; x=1706556899; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=dsyX6o96ll0tborqmT2tH2D5yYkTiItob646Hhae/V0=; b=NLUHDki6j21vUA3iMM5sEiD3mJs/BfCmFlXnWEGxUelkswe9SCLBsiRC4rbyePxeVi qmMPWLmvFXKG3LDjCxW9VyUHwJqDDjOA3VFEBZnM00hLkts82ITWcpgfFIHITe//f8tS OZ9dOtsu90PenqHumlvepYSXywBnK6z3HUiqu+ln6XgmQGzvKRy+2i/ZiRc0zYkx5OPb dZ8c+ZaQeXSwaXqQ3Q9PG20v0R1whS9yawOIzVl+tdEOCtbV4KfBRnY/rbsM63GsruOF gsEhv2MiMRbL6Q/ieopTKNHhqG4V+8zqPYVHeqNQDVuIb7/qBMNXZs0RG5o1cIHyI7Vr vviw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705952099; x=1706556899; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=dsyX6o96ll0tborqmT2tH2D5yYkTiItob646Hhae/V0=; b=d431WbVy2xgROFyETDwyL9YB4dB+J0o1+RzPQUGF04StFuBzr8XdH2PlSnNiR4Y6+Q MO4F7YqPRK9n2K/bEtPUFRif44fDMLsEaVB4EzB0ZCM2VKctqJJgSaXt8/oPTZSEMd6D nDCJnAfgnZOtKsSGQV29qqSGSBaOuIqaK7G4iNDNSW9l6VOwmkGm4cK+PPuVU6c1Qzv2 d0knVMXTHYzqdsCP0CFHa0QRmARm+tZ00UQb41Cj4VILWPC7LrHqWK9LN1bTYbqPTgeE dYJoNxiq43MeFr8a5u9pjstmoyt6bnRNe2q3sew59toKQgQ+2F9PSHXwCV/wLLytLzMU dJZg== X-Gm-Message-State: AOJu0YxDMZ/th8aNhetDaYfyROQgYtH4pyFv7k6cOt4+80XT1cOG7ETW 3AzZzxiQPzJsEXsuPDV73vWWLc35mP9V8WU2RWBkoHORo7WI4XdgVnPwrs8H8nsboJ69qreTGly 7fQFJzD0IoPeczsOXvK0P0XOhHA== X-Received: by 2002:ac2:5471:0:b0:50e:67c5:9854 with SMTP id e17-20020ac25471000000b0050e67c59854mr1869713lfn.123.1705952098697; Mon, 22 Jan 2024 11:34:58 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240122090851.851120-7-ardb+git@google.com> <20240122090851.851120-11-ardb+git@google.com> In-Reply-To: <20240122090851.851120-11-ardb+git@google.com> From: Brian Gerst Date: Mon, 22 Jan 2024 14:34:46 -0500 Message-ID: Subject: Re: [RFC PATCH 4/5] x86/head64: Replace pointer fixups with PIE codegen To: Ard Biesheuvel Cc: linux-kernel@vger.kernel.org, Ard Biesheuvel , Kevin Loughlin , Tom Lendacky , Dionna Glaze , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , Andy Lutomirski , Arnd Bergmann , Martin KaFai Lau , Nathan Chancellor , Nick Desaulniers , Justin Stitt , linux-arch@vger.kernel.org, bpf@vger.kernel.org, llvm@lists.linux.dev Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Mon, Jan 22, 2024 at 4:14=E2=80=AFAM 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 > 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 > 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. > > While at it, move these routines to .inittext where they belong. > > Signed-off-by: Ard Biesheuvel > --- > arch/x86/Makefile | 11 ++ > arch/x86/boot/compressed/Makefile | 2 +- > arch/x86/include/asm/init.h | 2 - > arch/x86/include/asm/setup.h | 2 +- > arch/x86/kernel/Makefile | 4 + > arch/x86/kernel/head64.c | 117 +++++++------------- > 6 files changed, 60 insertions(+), 78 deletions(-) > > diff --git a/arch/x86/Makefile b/arch/x86/Makefile > index 1a068de12a56..bed0850d91b0 100644 > --- a/arch/x86/Makefile > +++ b/arch/x86/Makefile > @@ -168,6 +168,17 @@ else > KBUILD_CFLAGS +=3D -mcmodel=3Dkernel > KBUILD_RUSTFLAGS +=3D -Cno-redzone=3Dy > KBUILD_RUSTFLAGS +=3D -Ccode-model=3Dkernel > + > + PIE_CFLAGS :=3D -fpie -mcmodel=3Dsmall \ > + -include $(srctree)/include/linux/hidden.h > + > + ifeq ($(CONFIG_STACKPROTECTOR),y) > + ifeq ($(CONFIG_SMP),y) > + PIE_CFLAGS +=3D -mstack-protector-guard-reg=3Dgs > + endif This compiler flag requires GCC 8.1 or later. When I posted a patch series[1] to convert the stack protector to a normal percpu variable instead of the fixed offset, there was pushback over requiring GCC 8.1 to keep stack protector support. I added code to objtool to convert code from older compilers, but there hasn't been any feedback since. Similar conversion code would be needed in objtool for this unless the decision is made to require GCC 8.1 for stack protector support going forward. Brian Gerst [1] https://lore.kernel.org/lkml/20231115173708.108316-1-brgerst@gmail.com/