From nobody Sun Feb 8 11:26:13 2026 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) (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 A4136487B3 for ; Wed, 21 Feb 2024 11:35:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708515345; cv=none; b=TlPV4cJ9f0eACMdge60EtlRxeVWaC37+UBx7xQv4Q4UNBRcViYkEq/zjg9eSNJy61Gltxdv5UB2/T5uURXRqKfmiExivLlrRrBtAJ+fk5jB9pkUL6mJOx+GVaWVnkSd8P1vBNJjI+JX2sELD3xe7HF8e2s7diJCyRqDDbqZAntM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708515345; c=relaxed/simple; bh=2RZc+OzKZCl8YvmipTaTRDsbfIBsnndPUmVKA1yKSts=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=PMmKTVg72e8bSwooiXxYh4oUWOszikw/UYQH1adzRk1JvfF55yHl8QjYyNyIDxS9RyjSaYf05y/pmurI+AX0gDeeBvWkwbXfG9fkRqs2/7PGrhfz61h6lAhQu3RqK3X1Q90fQkE7w9/lUHYtlZR7f8qBf8qAX0OMrB63gVrS3rg= 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=uMRV0uIH; arc=none smtp.client-ip=209.85.128.201 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="uMRV0uIH" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-603c0e020a6so51050867b3.0 for ; Wed, 21 Feb 2024 03:35:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1708515342; x=1709120142; 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=8Y5gC7csmOryHPxIGBtz1GA+4X+0n6cre/zcvSeIDBs=; b=uMRV0uIHjXPynQUi/G1NZCFhb53bVLW+n95V///OG5499cUBjiIhG6wME9hKF2h0RT uohTMmKBYwXZ89nm/hKdD9Zdmk64sy9YhMy3E0I8JPVhJZjGavl/pTJrYUzH6PYQCaKu 96w+LKfO3nWpX2TLm9WyVRRXUPKtRCVCaS4Rb1tI47jfXaSjcLM37ta5+k0I18y63c12 qiDuFO//ARXQIaMg166xpSbZ+jM3nJa89DKZ3pr9WtGF1mFE+he8L53i6iQVEoQHiWt7 0SzDlReV3V6w40D50HPPfqu3p/lQd4faBRvMfeK9EI9YmHTovfr8QRQyW9+1aMYD+QcM z39Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708515342; x=1709120142; 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=8Y5gC7csmOryHPxIGBtz1GA+4X+0n6cre/zcvSeIDBs=; b=b7Np/8XZlLT8/1O1pA6dDhHwDPDwcnirawB0zlqPGH0DsxgsWYhYFvlcoYqtvkVjC4 vlzsEjDxr3rYvg+euhvtIfdLnF22QMyBNXhXuEwfm8TWw+OmbXvH+B/T0DETs9alKC7h pBe5fTFgZO9FJvT3Rh4/uRh/s25L9JFpeo7NaZhUau4CEBaJdAbymThimeo3IotI3V7E u1jYFrAjyHT7Kt3ygieYWXsIdfOHQp6Ez3yomV3HS6TrVM6hEZDemJENrSgsziVfL07B 7CEV0OoXtZfjh7qZ5IgLr2rhTtIWhpuXUzSrfStno4LrJS4bOuejtATVisvXd2n+SYwj 3b4Q== X-Gm-Message-State: AOJu0YzLo75slrLpt2X/XsT6+W//dfXxWAInBJth9gp9/1ppJRIpg5I6 Ts78ZIwuqWPUzN5EcS87ciX/pDt6KFPfxf0Ov9Cp3jaYMqfDV/ajtxk14Ya2DtshAAi6TdFelIv hFQQEXQMf3BGjR7xjzQmBXi0tFfBJCYvwHsx3Kdg5VuVpnP1J917+xhsizS9+ttDn9LbinN+DOX paj7y+nIyBb/2QZlhOslNLwBm9LfgS4A== X-Google-Smtp-Source: AGHT+IFELx03HuT0Inbkk/6jf+jmcEOFUz77S85HuXmJ2/vo3Tmzp9E1tSdM6FzUvRXx2iV06N6VbqE/ X-Received: from palermo.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:118a]) (user=ardb job=sendgmr) by 2002:a25:c06:0:b0:dbe:387d:a8ef with SMTP id 6-20020a250c06000000b00dbe387da8efmr680600ybm.1.1708515341658; Wed, 21 Feb 2024 03:35:41 -0800 (PST) Date: Wed, 21 Feb 2024 12:35:10 +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=1903; i=ardb@kernel.org; h=from:subject; bh=swM7c8C7m6s+syovcWAlr4I1pvzKmPTAbfvGRxDNNBo=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JIfXq/bf72s8c5X6zfe4kzhLF88Ur7P10Jv1+c5Ij3Kphl 3trnr9SRykLgxgHg6yYIovA7L/vdp6eKFXrPEsWZg4rE8gQBi5OAZiISwXDP+Vl63+6nT136ee+ a7WfF7mxtuzU745WC96z5anM3cc8hWkM/0Nz2E7NSCsXY+vlOrVpn+zruNaY9l8JFYocrFU2Tpo M/AA= X-Mailer: git-send-email 2.44.0.rc0.258.g7320e95886-goog Message-ID: <20240221113506.2565718-21-ardb+git@google.com> Subject: [PATCH v5 03/16] x86/startup_64: Use RIP_REL_REF() to access early_dynamic_pgts[] 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 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Ard Biesheuvel early_dynamic_pgts[] and next_early_pgt are accessed from code that executes from a 1:1 mapping so it cannot use a plain access 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 | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c index f98f5b6a06b5..2ac904110f6a 100644 --- a/arch/x86/kernel/head64.c +++ b/arch/x86/kernel/head64.c @@ -170,6 +170,7 @@ static unsigned long __head sme_postprocess_startup(str= uct boot_params *bp, pmdv unsigned long __head __startup_64(unsigned long physaddr, struct boot_params *bp) { + pmd_t (*early_pgts)[PTRS_PER_PMD] =3D RIP_REL_REF(early_dynamic_pgts); unsigned long load_delta, *p; unsigned long pgtable_flags; pgdval_t *pgd; @@ -179,7 +180,6 @@ unsigned long __head __startup_64(unsigned long physadd= r, pteval_t *mask_ptr; bool la57; int i; - unsigned int *next_pgt_ptr; =20 la57 =3D check_la57_support(physaddr); =20 @@ -231,15 +231,14 @@ unsigned long __head __startup_64(unsigned long physa= ddr, * it avoids problems around wraparound. */ =20 - next_pgt_ptr =3D fixup_pointer(&next_early_pgt, physaddr); - pud =3D fixup_pointer(early_dynamic_pgts[(*next_pgt_ptr)++], physaddr); - pmd =3D fixup_pointer(early_dynamic_pgts[(*next_pgt_ptr)++], physaddr); + pud =3D &early_pgts[0]->pmd; + pmd =3D &early_pgts[1]->pmd; + RIP_REL_REF(next_early_pgt) =3D 2; =20 pgtable_flags =3D _KERNPG_TABLE_NOENC + sme_get_me_mask(); =20 if (la57) { - p4d =3D fixup_pointer(early_dynamic_pgts[(*next_pgt_ptr)++], - physaddr); + p4d =3D &early_pgts[RIP_REL_REF(next_early_pgt)++]->pmd; =20 i =3D (physaddr >> PGDIR_SHIFT) % PTRS_PER_PGD; pgd[i + 0] =3D (pgdval_t)p4d + pgtable_flags; --=20 2.44.0.rc0.258.g7320e95886-goog