From patchwork Fri Feb 16 23:59:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 13560942 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 6DD24C48260 for ; Sat, 17 Feb 2024 00:00:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:Message-ID: Mime-Version:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=8g+d//kn+1CxVI2npYLUyePljViTd3onJLkM2l43lkA=; b=Md1 UuYdBUZdaDA8ghu8PIL5mcR+cBP9JoCohrcTn21Aud2Tq/NF8XpbLsgWaRu7dVYsvnd79oHm0OfXr SFbJ3hIRQGjMpSitXvO3qlgtJhru7NCE8bpY4KN8XPB0t1LrsPUW//Mev5nBD8TS3X8gKO0gkjl+n LrDO6WG4Q45QBARkxIf8VrWx22/ONeIqDH9/6Av2bt9tI3iL3gdKXFqcBDwLBICh0MJO1F60R+e9H oChT1yuKHTyn74Yf+2XJtz2C2t3wVeP5fUwrbX/+ZqieOmONjqkbP2A1mu5M1CiHGkayba5EuPTV7 cwH6AKERslZQIUcXIrhhGV/j3ac3onw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rb87p-000000048qz-1Bks; Sat, 17 Feb 2024 00:00:13 +0000 Received: from mail-yb1-xb4a.google.com ([2607:f8b0:4864:20::b4a]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rb87m-000000048q8-0vya for linux-arm-kernel@lists.infradead.org; Sat, 17 Feb 2024 00:00:11 +0000 Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-dc74ac7d015so3376462276.0 for ; Fri, 16 Feb 2024 16:00:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1708128009; x=1708732809; darn=lists.infradead.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=lcFGqCQQWVZ/NLyI739SxxiDadPlLj0LxcA3K7FiYNg=; b=0csxZyI20dKxWe7OsCmBr9StToSnejey3PRaIhsmSHOxvvaamS+J0vb1FfcIn74/mF kXcu/5q4okbYFhQOrJo9gTChaZ6FcE+Ac2kT4IaafA13oYSxlI/b8gPbGIEacrXAY7KY aypNxy4D7APRmS2JmyBsRMlUgMKLZTF1bv0VdZCUrFSBJ3pDjGTKI6yJaROmm0uSYiB3 RK4/eGZeafmtO4wwA1N1BvKq1FDJAReYdAe4OCTcMnSeflGPL1251m6DoiGn17YYpwDs rzzC7XW5BF95HEKB1wm1TH3kD/Gq5sL6tyr0YdwSrayX3aozkifCrhpfwV9ZidSy5yCj 9+0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708128009; x=1708732809; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=lcFGqCQQWVZ/NLyI739SxxiDadPlLj0LxcA3K7FiYNg=; b=k0XKvwvl+4mNhVDJlcUP8qa/kIy1Gdumdfxx/f0FvYr9YXYnme5Too4aCDZH3Q9DUP 8cbCGKuWXaxmliQx3PLqRjfy4YJOz7hhfPfbizfpnDjmIoMKx1mxwUz5Y+5RP5Xbd+Cx /1IedEv5Y/s92BqqOlcSECfUadSinikFHjP/s0hAc2mP9p48Ht6m9qf4+RV7HNvZe/WD kJh9wKUe53rxjM+MvEta8OrxwRjpipM1gKTHYZU0Wk+PkeRSVodRvQXYN/6Dr9xadDM3 QVgQ7kx57d5Iw5a6WJxeTwzkz6v0ADhmPKrd1hVFu/f5qoXq9zlB6NC6/XlZLi0R8pUQ bR9A== X-Gm-Message-State: AOJu0YwlvJc36dQe2XwGa8X8moJZ2jCXDDkHMzsrcxjFN2j7vdTklQuv 3wBBVaWsILz43fT24iLfa4y7Cj2Pq8u1kzr98hfC4xPF88lOE381PlsDTXMPhcB9Rlt/+7d/wUL jKVN3FriVPUGmGOcamwuU4Uxkfuy78RqfGePrFFWpRSHdg7LWfYvI+r0DmWIUkLi8QzjNYiw0qD GucJYsIsb7hZXD24r+mEnnA5BO4RblIQA5YxpwI0g8 X-Google-Smtp-Source: AGHT+IFKYbncWxzFLmDbtWqI3QobGywJWdVtFys7cLZSn40jxXJ4FNtCwmX44z91tYoJbn0rz1zq65kR X-Received: from palermo.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:118a]) (user=ardb job=sendgmr) by 2002:a05:6902:1001:b0:dcc:79ab:e522 with SMTP id w1-20020a056902100100b00dcc79abe522mr253512ybt.11.1708128008459; Fri, 16 Feb 2024 16:00:08 -0800 (PST) Date: Sat, 17 Feb 2024 00:59:44 +0100 Mime-Version: 1.0 X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Developer-Signature: v=1; a=openpgp-sha256; l=1597; i=ardb@kernel.org; h=from:subject; bh=hX9e/KChv73ZTMGNCFO3sZ6tU4jCzEW4S2C10cN9/Xs=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JIfX8tw/G0ZNWv3u9besypYDkc37innPmHW03s31W6ZLpV eJ1dbNuRykLgxgHg6yYIovA7L/vdp6eKFXrPEsWZg4rE8gQBi5OAZgIz1NGhg9bE3OnZ9mnfzy5 Uz/lLPeJnxNdnmss9mHfdu33p/iDAVMYGTbYBC+3iT45zXEtt1rD5oJnSicT1bhbdy+f9MR0V7H qIVYA X-Mailer: git-send-email 2.44.0.rc0.258.g7320e95886-goog Message-ID: <20240216235944.3677178-2-ardb+git@google.com> Subject: [PATCH] arm64: mm: Make PUD folding check in set_pud() a runtime check From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org Cc: Ard Biesheuvel , Catalin Marinas , Will Deacon , Marc Zyngier , Mark Rutland , Ryan Roberts X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240216_160010_285589_273DF1B1 X-CRM114-Status: GOOD ( 12.56 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Ard Biesheuvel When set_pud() is called on a 4-level paging build config that runs with 3 levels at runtime (which happens with 16k page size builds with support for LPA2), the updated entry is in fact a PGD in swapper_pg_dir[], and this is mapped read-only after boot. So in this case, the existing check needs to be performed as well, even though __PAGETABLE_PUD_FOLDED is not #define'd. So replace the #ifdef with a call to pgtable_l4_enabled(). Cc: Catalin Marinas Cc: Will Deacon Cc: Marc Zyngier Cc: Mark Rutland Cc: Ryan Roberts Signed-off-by: Ard Biesheuvel --- arch/arm64/include/asm/pgtable.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgtable.h index b3c716fa8121..8bec85350865 100644 --- a/arch/arm64/include/asm/pgtable.h +++ b/arch/arm64/include/asm/pgtable.h @@ -699,14 +699,14 @@ static inline unsigned long pmd_page_vaddr(pmd_t pmd) #define pud_user(pud) pte_user(pud_pte(pud)) #define pud_user_exec(pud) pte_user_exec(pud_pte(pud)) +static inline bool pgtable_l4_enabled(void); + static inline void set_pud(pud_t *pudp, pud_t pud) { -#ifdef __PAGETABLE_PUD_FOLDED - if (in_swapper_pgdir(pudp)) { + if (!pgtable_l4_enabled() && in_swapper_pgdir(pudp)) { set_swapper_pgd((pgd_t *)pudp, __pgd(pud_val(pud))); return; } -#endif /* __PAGETABLE_PUD_FOLDED */ WRITE_ONCE(*pudp, pud);