Received: by 2002:a05:7412:cfc7:b0:fc:a2b0:25d7 with SMTP id by7csp2303262rdb; Wed, 21 Feb 2024 03:37:18 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWeg8N8iRVTvBgsCTtG6jI34Qgww4MtvHHwP/Tt8lXcXfb/x/CWmACVyG+Keh5ZpWHo/LqGTpZjYm37l7CXnSlyq/jofvS2lYg+9K2mOQ== X-Google-Smtp-Source: AGHT+IHIUtpslxCykSuoxURQf8dMp396BsZGMpG+tavfkpUFrn0y4g+olyLLxd+P4CoNzL9Us74p X-Received: by 2002:a05:6870:23a8:b0:21e:9e8e:66e7 with SMTP id e40-20020a05687023a800b0021e9e8e66e7mr10190958oap.0.1708515437779; Wed, 21 Feb 2024 03:37:17 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708515437; cv=pass; d=google.com; s=arc-20160816; b=UFTFllcbBbsqcob9zl9LiD+eq+rrZinppsVw5l3gfroxhXjfbOq9h2R9ocpUgJBw0x Rc3l6o+eASQvM+lR8xSiMpr6gx1n8QkjFYuQF8U3mEzu3lZXWP7diScEN1Ge3KlMvH1A SI1z24lemctCneBP72AakL5KBb/Hj5ibreLkwfovdIIVlDTZ3rgZlTQT/sL2AvxZ3MyZ NEboKuZ9aKEm6ord6hILpAeMXsZg2yK5Nkmxe6BnRub75taHk5/rS60EOl6b5fTYWFjI DqYt7mY4Fv/k2a1k0qCgPbz+PEBvdAQRzLHZBbvZqSjrHhzQ0vEeCkiNVvlUOSTSUg5A jArQ== 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=8Y5gC7csmOryHPxIGBtz1GA+4X+0n6cre/zcvSeIDBs=; fh=fMhMPvo8duafGkM4xZHdH7fULbau3etefTGsKa+Qy7I=; b=Ki9S2iPa2ENwN2buIz9LSxbWWG6hRxhlZLznHctjGCeIwzV3I+EYWuBN7Vgbf4OXQd ExraptQrAgiphAHuJkjfoOnvJsPM5rEbEojINFNCT0vkXEKVXx+ga4xCNIPX3gra3zah S6LSf3YVTZANp7Qr6dNK/9fCjTSus+CD6UfIWsuJnnonZZLqM+sXCAFSX8XFWA2fv+Zb O6VV0BxyNcDWPjfVBbPMdjmYyGG1xXof2RzSencuwsrk4GhZaMNqyKIVpNfWydhS3lw6 O7tn2Kush5/wPp0CKOVpP3fOY8sojoYLqKBdu5rUCSjQa3LT1uRA8EfGMhix8Ar5DxKD jIqg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=uMRV0uIH; 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-74633-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-74633-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id e9-20020a631e09000000b005dc88b23289si7931327pge.585.2024.02.21.03.37.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Feb 2024 03:37:17 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-74633-linux.lists.archive=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=uMRV0uIH; 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-74633-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-74633-linux.lists.archive=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 75DE1283188 for ; Wed, 21 Feb 2024 11:37:17 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 28C494CB24; Wed, 21 Feb 2024 11:35:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="uMRV0uIH" 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 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-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-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(struct boot_params *bp, pmdv unsigned long __head __startup_64(unsigned long physaddr, struct boot_params *bp) { + pmd_t (*early_pgts)[PTRS_PER_PMD] = 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 physaddr, pteval_t *mask_ptr; bool la57; int i; - unsigned int *next_pgt_ptr; la57 = check_la57_support(physaddr); @@ -231,15 +231,14 @@ unsigned long __head __startup_64(unsigned long physaddr, * it avoids problems around wraparound. */ - next_pgt_ptr = fixup_pointer(&next_early_pgt, physaddr); - pud = fixup_pointer(early_dynamic_pgts[(*next_pgt_ptr)++], physaddr); - pmd = fixup_pointer(early_dynamic_pgts[(*next_pgt_ptr)++], physaddr); + pud = &early_pgts[0]->pmd; + pmd = &early_pgts[1]->pmd; + RIP_REL_REF(next_early_pgt) = 2; pgtable_flags = _KERNPG_TABLE_NOENC + sme_get_me_mask(); if (la57) { - p4d = fixup_pointer(early_dynamic_pgts[(*next_pgt_ptr)++], - physaddr); + p4d = &early_pgts[RIP_REL_REF(next_early_pgt)++]->pmd; i = (physaddr >> PGDIR_SHIFT) % PTRS_PER_PGD; pgd[i + 0] = (pgdval_t)p4d + pgtable_flags; -- 2.44.0.rc0.258.g7320e95886-goog