Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp5570925rdb; Wed, 13 Dec 2023 12:32:34 -0800 (PST) X-Google-Smtp-Source: AGHT+IFQ211AHv7zMGUTRIiojSmB8v1JhNTSVTEgULHfCmzftLmt17Jt4dIjfXGHGOqGJQDlnDKQ X-Received: by 2002:a17:902:c183:b0:1d0:6ffd:cea7 with SMTP id d3-20020a170902c18300b001d06ffdcea7mr4630429pld.96.1702499554425; Wed, 13 Dec 2023 12:32:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702499554; cv=none; d=google.com; s=arc-20160816; b=AcOM5A740D3LXRXK8K3ymLS38mU0+lXYrw9P7CM3x+Nn7kQayQsBhgiYqWCSzeGCB1 EGPci+Wmpjueuqay5/+t+fBs0YJsTjpcGoBByd7ySvSPZn8pYCqEv8zDjqjf7AkidqN/ aHgjfrPF3VD1n8T0Z8w8C+javDzzYCAcFx7FWEHshBVyEw3OhGvMtKNwtxygW/52AdDG Tbz6qrGshFfxs5fhrzU6KupNEkLuuHqgv0+v2GPA5Q9pqsbJA6GixSyZNBo9/aVSQ836 uHi5XW5yGBav4lncQ7EDvOipXbpmNpKqLfeiEySvuRsKqfhEP+LlOKr9b8jbGXf7wLjl DAbg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=lUqvcHnbHjun3bdBJPfvf0B8JWy5i7uak5v/0Wh9cSk=; fh=IGropsY/f620dSTjnkF1U3l/yVuB1Ulli/O+nFZzzpw=; b=EmbIl6HGofjp/heoUAGpVKIyhPMUsukEz+Dn25aJmEUsbj17RUdi8uLTjPC1qnpw18 kUVyJj2BfNeISxezytH2b25qNT/lEG1e149/J5TjWXl/Uh5bm3iJOwXzjTgmS2giprxw jU4QBZnkrM0ytrmEniFaMjhQSt0IFwtp6XY0dOfOi/R6CuIahFsdi3nT+tqVjQCHA8w9 IhtsxDvjMeuOOvc9fau7K4woKrDeDi9xFeNZcJdy/hrMlmoDvS46W8HiOzAoy/liIw6W 3f92hz8UlOLcnHeh3hREQwKKahXX7QBaEHA80ytw0g6PhA3wmSMNB4x85hWF8yUB+MVu EbvQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=tvLg0qc3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id e18-20020a17090301d200b001d3535e0c5asi1260323plh.470.2023.12.13.12.32.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Dec 2023 12:32:34 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=tvLg0qc3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id A400280930E2; Wed, 13 Dec 2023 12:32:31 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233770AbjLMUcQ (ORCPT + 99 others); Wed, 13 Dec 2023 15:32:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50622 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229811AbjLMUcP (ORCPT ); Wed, 13 Dec 2023 15:32:15 -0500 Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E07959C for ; Wed, 13 Dec 2023 12:32:21 -0800 (PST) Received: by mail-wr1-x434.google.com with SMTP id ffacd0b85a97d-336420a244dso655796f8f.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=vger.kernel.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=tvLg0qc3/fTYkGAGuKpUnAKHTew2uRcRyChSM07vme5fcKGFB3WN+ZKItdscpxbwfa ehcQkusNpeGUf/DG8eCkbWaEd4o5DNzpCazXppUhkUmtXyXlzSan80df7lp6eZDmsyeb H2k7IQS5DBz+U8VkSIlSP1nfBRyKB4qhNGwhQPVKrXEdvxohAguSom7TARUOFvQYjxVV veMHqPF/djlN/1P3QdGGdZiri9G7FUBleOGLLVCztdJYcy1xhQdks+vXGPmCX2BhZl42 e70uHg0HClSw4RZ9TqaiqgiPe+7tPl/QE99gls0Te+IHpbszjf0smAcOW3ZCRH9c3ngm qSQg== 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=kj4t8dk1CEAmgUZlMxyQTGYLxH17fVUyK00qKL57mHA9y03U2KJmyCTNfvQfNVk9cQ NmYOnwrxqPpSal3YUltnM3XrZBCTcWISAEIo/nHIFGVurwmmeAqmcEQohJPiYedoV3p2 LGkT1E9babemCxoQM5DutSQBtF5MWvG4t6T0zx6Bcmob9TCtZnGsaYMmBle7g0RGx86L 4iJ9fWVXU5Oafy4zuCfWUnR/mtzDCyK4Abu53yrChlYPS5lLS8a6qzFdLjUBBNnLr24Y 11Fi+uyEum/S8nO1pVMO+I7smoEaIBcqdBbR47TIBXTj0SfY1UBDx1OzJ73IsQaojCQU CSHw== X-Gm-Message-State: AOJu0YzJ/nAuKZX0oE8psUPWiP1r/TF2ooX+X2EujEpmgRRDzscQ6ljE 3sJsSCHMgHaEXPfDNnPWfVGG6g== 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 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Wed, 13 Dec 2023 12:32:31 -0800 (PST) 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, -- 2.39.2