From patchwork Wed Dec 13 20:29:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Ghiti X-Patchwork-Id: 13491849 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8F097C4332F for ; Wed, 13 Dec 2023 20:32:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1FA6C6B04CF; Wed, 13 Dec 2023 15:32:24 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 183FE6B04D0; Wed, 13 Dec 2023 15:32:24 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F187A6B04D1; Wed, 13 Dec 2023 15:32:23 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id D75566B04CF for ; Wed, 13 Dec 2023 15:32:23 -0500 (EST) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id AAC29140C0C for ; Wed, 13 Dec 2023 20:32:23 +0000 (UTC) X-FDA: 81562942566.01.AB835C6 Received: from mail-wm1-f44.google.com (mail-wm1-f44.google.com [209.85.128.44]) by imf01.hostedemail.com (Postfix) with ESMTP id BED9940017 for ; Wed, 13 Dec 2023 20:32:21 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=CweviSw0; spf=pass (imf01.hostedemail.com: domain of alexghiti@rivosinc.com designates 209.85.128.44 as permitted sender) smtp.mailfrom=alexghiti@rivosinc.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1702499541; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=lUqvcHnbHjun3bdBJPfvf0B8JWy5i7uak5v/0Wh9cSk=; b=WSS6/h2NsQRdskU8AunnBauHiOtvmLbOyMgsVHTKJR2aH8eQF1xnsp2y6l2gdQoX/mBtBY qa7LcSXzJst8J0ATI0NObU49dECyJrRuVYs/KYBdBiuPuAi+MOK2IF2xljjmuK6qcET2hv /NckAjuEiaIe0carK3BnNqGiAPOiLUk= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=CweviSw0; spf=pass (imf01.hostedemail.com: domain of alexghiti@rivosinc.com designates 209.85.128.44 as permitted sender) smtp.mailfrom=alexghiti@rivosinc.com; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1702499541; a=rsa-sha256; cv=none; b=Dz23Ws28Xp1ryd1XLKxlxU/qPCWsZm+tue1LcMraf6hCMYnhJFc9r1Qk/u3EMPJmcnhUTL Y1BxPUQxqxS9hfkDn8M16sPdWLVmj2GI7cnLkA6hyDqEKbWU8poUzE4KzlmUHk/0wDSiAO z4wEOsOgtc3cAqFBGhuhUpS+le9Ymh0= Received: by mail-wm1-f44.google.com with SMTP id 5b1f17b1804b1-40c29f7b068so69586335e9.0 for ; Wed, 13 Dec 2023 12:32:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1702499540; x=1703104340; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=lUqvcHnbHjun3bdBJPfvf0B8JWy5i7uak5v/0Wh9cSk=; b=CweviSw0okce6WRfJ0cPJZLXivNElU+SVKDyYi/2jMA9EHZkUcVDJ+pov0Fwy3FLLi SAX8q5uc2pL0Fb7CJ8IuZTH8z8G7Ogi2goyHz2klE0WeQYpjvK0GMsFoglFrjxqn8eW1 thLR4WCBdQAl1s42tw9tfa+bjTW6VXbLj1c/kLnkNKJyhcdRXQHOEMxM7QlAWvoT+N2s m62paHoq1qsLBRz3KUheEih9XheEt1kDTfHebSA8Fllxz+RsaCHN8SIsuhGNuXftRnvG ZjxFbN6D+ZKCUh0cZPg+hV11BgnHVEW8A9uG6XXda3iQV3pVenruz/b9nfpybOxHYwbr Z83A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702499540; x=1703104340; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=lUqvcHnbHjun3bdBJPfvf0B8JWy5i7uak5v/0Wh9cSk=; b=Ipmq5HGoPsuVU+IOSCvgflwBmToUUpVpT6w+pSAAKHXwI1qOVCLZH/WBgfrOOuKCeL jquzWUVV8DXZ4PyhNLIv8+y554zzRh+Tz3rofxeCnYqutWCFqZJ1vusi8mnX7dZxUrfn +ra1rSv8mHKtVajtbZACo18BDNb0jurfHUEjVzuTSiqlWEnM5SnDWwr5R8wmvqilMXb8 +9NpF+t7jaG7TK2uTYDGhWc2lirPBYp3ySgIvLHEXR3ECpMhlXfYm4veoqzqOf1vA9dr HL2axlmFT7K988epxfaYiED61W/rJ7LELH9UeRsk+wQSXevqudvbhWhUWew6jqDo/a0/ qyPQ== X-Gm-Message-State: AOJu0YzRptF+FZZ0SHdooGUqLUI0J2igZv/EjwvbC+/uKfevZQEruq+k wYkoD79Ch2Q5QTssNPUgc32rUw== X-Google-Smtp-Source: AGHT+IGeWwb4mZTjVlnfL3Tc7x0njpKhguH1T5u5o7xiWbZOuJ+qDIheC5NMdpL6eYcBnXpv6MaCcA== X-Received: by 2002:a5d:51cc:0:b0:336:353b:2193 with SMTP id n12-20020a5d51cc000000b00336353b2193mr1550679wrv.61.1702499540379; Wed, 13 Dec 2023 12:32:20 -0800 (PST) Received: from alex-rivos.ba.rivosinc.com (amontpellier-656-1-456-62.w92-145.abo.wanadoo.fr. [92.145.124.62]) by smtp.gmail.com with ESMTPSA id n10-20020a5d4c4a000000b003333abf3edfsm14139649wrt.47.2023.12.13.12.32.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Dec 2023 12:32:20 -0800 (PST) From: Alexandre Ghiti To: Russell King , Ryan Roberts , Alexander Potapenko , Marco Elver , Dmitry Vyukov , Paul Walmsley , Palmer Dabbelt , Albert Ou , Anup Patel , Atish Patra , Ard Biesheuvel , Andrey Ryabinin , Andrey Konovalov , Vincenzo Frascino , kasan-dev@googlegroups.com, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, kvm-riscv@lists.infradead.org, linux-efi@vger.kernel.org, linux-mm@kvack.org Cc: Alexandre Ghiti Subject: [PATCH v2 2/4] mm: Introduce pudp/p4dp/pgdp_get() functions Date: Wed, 13 Dec 2023 21:29:59 +0100 Message-Id: <20231213203001.179237-3-alexghiti@rivosinc.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231213203001.179237-1-alexghiti@rivosinc.com> References: <20231213203001.179237-1-alexghiti@rivosinc.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: BED9940017 X-Rspam-User: X-Stat-Signature: ww5ss3rfwh8us5o71cebh1tggyxruduy X-Rspamd-Server: rspam01 X-HE-Tag: 1702499541-965946 X-HE-Meta: U2FsdGVkX1+Wnjr4ezmFx0m0LFggbrimz3vDEYUPyjuZ3M8HhP6Fium7vD8yqV8H7Z605ysJ53CzAxIR+fJTp+BSv6npts6iIAuditR/GTRVe2v0OKxt+zKeIK/lFz9nUG4U2i8STupiyEFIlX/68ROEtyxeny2q41bI8pSa1369mOXYbsCuIhuUFdd6HIPC+qm034gR/Z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Aw8eAQUOacJTP+R+mK6JW4KYlevA1YohGuPMi+hXFdgj5uAFCi8GUQPN2A7YMY3haCF4OYvgaReWC4xHlgO9bfjJn5R4kuPAIIWGMtPwMRxTrOhiwYjM8PbMFGbJ/1tgfY2uXjqIObzhA+r7fvZBGGQiqLKduUuOhwe7LtlS7F3hOhkRLjZ8YpheD819Zss5aliYRbBdMHho3vCrtoIMkAi0QBdLC+9zOmBHopliM7KvmrrIEC8b2S2Jgegs6e/IGA0oBdeYCFyMoflSbBu4UO/IoGiuCbKFYM1dD+xAgnerV0pCljm6m4b4WbeN9uQ= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Instead of directly dereferencing page tables entries, which can cause issues (see commit 20a004e7b017 ("arm64: mm: Use READ_ONCE/WRITE_ONCE when accessing page tables"), let's introduce new functions to get the pud/p4d/pgd entries (the pte and pmd versions already exist). Note that arm pgd_t is actually an array so pgdp_get() is defined as a macro to avoid a build error. Those new functions will be used in subsequent commits by the riscv architecture. Signed-off-by: Alexandre Ghiti --- arch/arm/include/asm/pgtable.h | 2 ++ include/linux/pgtable.h | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/arch/arm/include/asm/pgtable.h b/arch/arm/include/asm/pgtable.h index 16b02f44c7d3..d657b84b6bf7 100644 --- a/arch/arm/include/asm/pgtable.h +++ b/arch/arm/include/asm/pgtable.h @@ -151,6 +151,8 @@ extern pgprot_t phys_mem_access_prot(struct file *file, unsigned long pfn, extern pgd_t swapper_pg_dir[PTRS_PER_PGD]; +#define pgdp_get(pgpd) READ_ONCE(*pgdp) + #define pud_page(pud) pmd_page(__pmd(pud_val(pud))) #define pud_write(pud) pmd_write(__pmd(pud_val(pud))) diff --git a/include/linux/pgtable.h b/include/linux/pgtable.h index af7639c3b0a3..8b7daccd11be 100644 --- a/include/linux/pgtable.h +++ b/include/linux/pgtable.h @@ -292,6 +292,27 @@ static inline pmd_t pmdp_get(pmd_t *pmdp) } #endif +#ifndef pudp_get +static inline pud_t pudp_get(pud_t *pudp) +{ + return READ_ONCE(*pudp); +} +#endif + +#ifndef p4dp_get +static inline p4d_t p4dp_get(p4d_t *p4dp) +{ + return READ_ONCE(*p4dp); +} +#endif + +#ifndef pgdp_get +static inline pgd_t pgdp_get(pgd_t *pgdp) +{ + return READ_ONCE(*pgdp); +} +#endif + #ifndef __HAVE_ARCH_PTEP_TEST_AND_CLEAR_YOUNG static inline int ptep_test_and_clear_young(struct vm_area_struct *vma, unsigned long address,