From patchwork Wed Feb 21 11:35:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 204169 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp978594dyc; Wed, 21 Feb 2024 03:37:52 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVRPTf2YVv3ed3i537LrMTYHi1K189YBxVmZGtrNR7GboSzckegJG2+XwuuFuYPQVv75RdXUC6RYcolEwi+jmIs5/LIew== X-Google-Smtp-Source: AGHT+IGy3Dqg00gCsVomidgPS9Lg5HDsWIuN3JLGIKkIo8A0vGVnftKAcWYbTyETZgV2GjJ52dxE X-Received: by 2002:a05:6a21:6da3:b0:1a0:b5cb:36d4 with SMTP id wl35-20020a056a216da300b001a0b5cb36d4mr5832612pzb.19.1708515472380; Wed, 21 Feb 2024 03:37:52 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708515472; cv=pass; d=google.com; s=arc-20160816; b=mtCIudapUXzvL4fXHAWXXVHCEbInipupcAGtbYRkJualAOyOZ0G2VkE9CMPXAYoci2 GGUWQS0Sib/ArKvMP75JKfr+stQf7sEH2X+QqYbv2bNB7natrP2jJO791mYdTddQ2/+4 LbQ1g/RjLu2iN3xoHdiK/k2dEwJee935M0mD9B8gQrApP1MvUqdqLk0auWd1MT9jZkOX zLayyNjD3EctVDuBKoIMiujcG5m/oguBZDTieJ1vAIgpg9yeWIXGu38KMere7LPLdFm0 O2EFglVZHOaueGAx8hrFZ50+kF+qactQWXwHUDGWZ0KSlZPEmGShQJ/288+/7TRy1gz6 DA/A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:references:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:in-reply-to:date :dkim-signature; bh=mh8YQtdjDFBeR5IIfvtfOkH3iYneTElPPQWzRP3dQ5U=; fh=fMhMPvo8duafGkM4xZHdH7fULbau3etefTGsKa+Qy7I=; b=K+jEVUGGyjEsvjkOPBcYwj4WhUUoQi7EHEozOJhQFksSbfcIlyovteL3waeAGHU7kM F7IiYV6rc5Jqi1yQzS396NQ5NEdcDc7yL06ZRL5Qkgvfk9TWlPy0l+313eAvO29bPslT pCmHu/IK8n1Ly8I0qvIH47xX/6c0cJzQdHwL24rBsG3bZpUobyFZTYIKAjc9XSmMq+db naPDKo2Hf8A7YMXRnzIW1aHgxFLRs1EIazTqH+93acXc5hwlDFmeTllQuDkEr2mPN0pI Phu5VMSPHnAVKlfM4sHprannHflImIImK1D34wdJxIltqpVR6koNyt8cZy4xIm1SCWb9 XQKw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=yoKn8IIl; arc=pass (i=1 spf=pass spfdomain=flex--ardb.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-74635-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-74635-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id b20-20020a656694000000b005d8e1f10c3asi7730857pgw.877.2024.02.21.03.37.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Feb 2024 03:37:52 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-74635-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=yoKn8IIl; arc=pass (i=1 spf=pass spfdomain=flex--ardb.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-74635-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-74635-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.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 05911284301 for ; Wed, 21 Feb 2024 11:37:52 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5C84C4D10A; Wed, 21 Feb 2024 11:35:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="yoKn8IIl" Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) (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 369054174F for ; Wed, 21 Feb 2024 11:35:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708515349; cv=none; b=Ll3ZSfkVIzjcnD3DcU+ZvVCuUxXQPIv5xsUp80NZMSfcZimUjKkzi/x32DROuZFkmMfzQDdr8cA38LogUkhAWwPsUeyo+anB9UWGl8PqAli842FKBXDA/qxQx9YHBjmitiIMcCuqBkjjUmBI+0AdjUTmlXjdfX33JGz4uD7aAeM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708515349; c=relaxed/simple; bh=GAlPtq8JkQJ3A2WVw8c46QbR1WtxNjQfx1w8AVpPTjc=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=kzMTYKZnkG+1bJho1PtFODPzrkZvK7v8IqtjjpoVROoba2R9VDyLoqDe+Za0DG4ZGA1Zprecyc/POp2uXgeoaCRZMW5y1shI65L0Kc3ZUeLO8Vlkkd2AMaNNx6nqHqBiUuOzzgTHx7W8gA3hVcWbOJhFN7xZUEj+4T+N4VeI4xA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--ardb.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=yoKn8IIl; arc=none smtp.client-ip=209.85.128.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--ardb.bounces.google.com Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-608575317f8so35420697b3.3 for ; Wed, 21 Feb 2024 03:35:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1708515347; x=1709120147; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=mh8YQtdjDFBeR5IIfvtfOkH3iYneTElPPQWzRP3dQ5U=; b=yoKn8IIlNUE26g5hYhsL1NTTncQyij9u7eThJAI1n31mtRwVIUbMO+3bu8DBrMeK1/ /9tmcPZhQOXj2cPSN20U0RoUnEgKacAlF91tOZRn7oJJ7dRQyJlZtogAx4jeXUTGXS2w h3L4azD7aePLTJHCavuwYWbDOVXMSLm7W5YUsRspBZtW9UBqza77wkMZhBVLG2w3tJoW qOAkYTzo1cZUumRgQl7o8S4r5zKKKbnZqkCGn4P5I4lK+9Pn42eq2OZLxppNWrUHxKJt Ybe2qaTZA3zbvj/mLGqnpeYeYSmb+mfGi5UpB4X08PB6+4pSlA+2V0VjgRmFIqpQ71aB MSFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708515347; x=1709120147; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=mh8YQtdjDFBeR5IIfvtfOkH3iYneTElPPQWzRP3dQ5U=; b=esypS/nf8o5iLZBXA5lk3GewpZQaefr1ib6oOVheIZ1/ykmP9gBxAW9EsgG83eceUh EKdm6zajxhflrs/gOKhIETv9XP2WbweKFmd14P4KPanVIoKxqEICqZ6J9pN4S1lZpKpt exs9HvGAd8oVVpyMbCevsj/A2M1B30beXpb7VpwDzCx047iYAiQWuursr0sw9K/O/afN hM/ZpRsZTfwt2uBKAioJWMWpQGmb1KlpoBSbHRK7X30780oJSIQfqNopy/iOpeBbh/Pt +EdHFnE1B/s4pouRiWjRNPXRWifky6Yjvbggw4w9FTeChrUzPgJjYEeIJlQgqtADomWa Z8ag== X-Gm-Message-State: AOJu0YzCR9fHM1WOqpUiXM4Oi6Ft2HDgXlaib8v8qBNu8V9y7rNGm789 CnO9AR2shB6K/j1e95d2I3LWYg3erjUAVCcrrGoR4q/QVSNpjcPz9jkLW3dso9KesQvIxjg32GH sp/y/V2NbItSeIwgBIfvBNsmTtt3CirPFwXhBcSxwNFhbOxs1BPFX22IveHqfVShyUNg/6LLcGP MdHcq9D8TW0BTS4Qk2D6z6c2+9r4gHvQ== X-Received: from palermo.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:118a]) (user=ardb job=sendgmr) by 2002:a0d:e6c5:0:b0:608:801a:e66e with SMTP id p188-20020a0de6c5000000b00608801ae66emr232627ywe.3.1708515346559; Wed, 21 Feb 2024 03:35:46 -0800 (PST) Date: Wed, 21 Feb 2024 12:35:12 +0100 In-Reply-To: <20240221113506.2565718-18-ardb+git@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240221113506.2565718-18-ardb+git@google.com> X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Developer-Signature: v=1; a=openpgp-sha256; l=1582; i=ardb@kernel.org; h=from:subject; bh=cvzedKkAgUYV71bwW+wRLG9NvEsRD1LqBxLDjio6avo=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JIfXq/XcfP02y/sG1PGlJDc9qpSi1Q69MXf6u41urqrbMb sH7yR81OkpZGMQ4GGTFFFkEZv99t/P0RKla51myMHNYmUCGMHBxCsBEJmxi+B/G7rLguUZMl3+R 0vtNEibBlX9ZVJt10g8o/TM9Ily2zY2RYZFpSYf4SxEfXrMP20O46g6+2tbuk+T93lr0pKL5u+8 PGQA= X-Mailer: git-send-email 2.44.0.rc0.258.g7320e95886-goog Message-ID: <20240221113506.2565718-23-ardb+git@google.com> Subject: [PATCH v5 05/16] x86/startup_64: Use RIP_REL_REF() to access early page tables From: Ard Biesheuvel To: linux-kernel@vger.kernel.org Cc: Ard Biesheuvel , Kevin Loughlin , Tom Lendacky , Dionna Glaze , Thomas Gleixner , Ingo Molnar , Borislav Petkov , 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791508319886233081 X-GMAIL-MSGID: 1791508319886233081 From: Ard Biesheuvel The early statically allocated page tables are populated from code that executes from a 1:1 mapping so it cannot use plain accesses from C. Replace the use of fixup_pointer() with RIP_REL_REF(), which is better and simpler. Signed-off-by: Ard Biesheuvel --- arch/x86/kernel/head64.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c index e2573ddae32f..7e2c9b581d58 100644 --- a/arch/x86/kernel/head64.c +++ b/arch/x86/kernel/head64.c @@ -215,13 +215,11 @@ unsigned long __head __startup_64(unsigned long physaddr, p4d[511] += load_delta; } - pud = fixup_pointer(level3_kernel_pgt, physaddr); - pud[510] += load_delta; - pud[511] += load_delta; + RIP_REL_REF(level3_kernel_pgt)[PTRS_PER_PUD - 2].pud += load_delta; + RIP_REL_REF(level3_kernel_pgt)[PTRS_PER_PUD - 1].pud += load_delta; - pmd = fixup_pointer(level2_fixmap_pgt, physaddr); for (i = FIXMAP_PMD_TOP; i > FIXMAP_PMD_TOP - FIXMAP_PMD_NUM; i--) - pmd[i] += load_delta; + RIP_REL_REF(level2_fixmap_pgt)[i].pmd += load_delta; /* * Set up the identity mapping for the switchover. These @@ -284,7 +282,7 @@ unsigned long __head __startup_64(unsigned long physaddr, * error, causing the BIOS to halt the system. */ - pmd = fixup_pointer(level2_kernel_pgt, physaddr); + pmd = &RIP_REL_REF(level2_kernel_pgt)->pmd; /* invalidate pages before the kernel image */ for (i = 0; i < pmd_index((unsigned long)_text); i++)