From patchwork Fri Sep 6 08:22:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: WangYuli X-Patchwork-Id: 13793671 Received: from smtpbgbr2.qq.com (smtpbgbr2.qq.com [54.207.22.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0295015921D; Fri, 6 Sep 2024 08:23:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=54.207.22.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725611041; cv=none; b=Fi7J61KjxfJeHqhpcNTgbldj8VypCgzOUEnXslekTMOebZt1yDVpVxq0SdEf5QmdR/GTODacknAZTi7OfGa9ngsIeT5VQDqvNsQzz4yVV2Muw4bDLXsxsLxGb92WM+g6QGpVXZCoaftvVPHT+ws5R0GthqFpUd/GVNM1tKx/2bA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725611041; c=relaxed/simple; bh=8F9XaRWHMNG7EvVOUOvkWUIfuhwTZ0VJVoqYolLWlM4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=oBHdfDdHPe3DF77d7helhVmvvrWMnUrzQfylptpfICC7fzs52YGGOonh1VeHo/nenyyk/sWNMQEZ6YYoqrUQH79Tf3lSHUsg9RGB5K0uJxEmuMlEaCCiNPJcKc/oq/msNgzpq2obHlX+UwX6FDcWUkS7wtXJrP0oFyDkEf3mH3Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=uniontech.com; spf=pass smtp.mailfrom=uniontech.com; dkim=pass (1024-bit key) header.d=uniontech.com header.i=@uniontech.com header.b=jd+MWnZf; arc=none smtp.client-ip=54.207.22.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=uniontech.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=uniontech.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=uniontech.com header.i=@uniontech.com header.b="jd+MWnZf" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=uniontech.com; s=onoh2408; t=1725611012; bh=c2Y6hDcW5soaI9k7gniI980VucnVpsyCwVOK429FvIA=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=jd+MWnZfO4h+4NVqsgObOFwNTZ9NqQrJovEt5nq4OexSnARloV5q9e1g3bi7A22g6 ya+AIOFlbmg5GQVPg+MwB9nJAi6i6hM92BSEG2A5hh2uq3pHzzPmQfDMCv+7222bsD 41RPpIsmmO0HsllDPspMz+CCnn0KcXurpAuPe1x4= X-QQ-mid: bizesmtp82t1725610993tbhs3wew X-QQ-Originating-IP: gB/3WYVXTwnwfUfShFtfuqtn/wTOkf9uPbAVVydCjDE= Received: from localhost.localdomain ( [113.57.152.160]) by bizesmtp.qq.com (ESMTP) with id ; Fri, 06 Sep 2024 16:23:07 +0800 (CST) X-QQ-SSF: 0000000000000000000000000000000 X-QQ-GoodBg: 1 X-BIZMAIL-ID: 10217785498291060438 From: WangYuli To: stable@vger.kernel.org, gregkh@linuxfoundation.org, sashal@kernel.org, alexghiti@rivosinc.com, palmer@rivosinc.com, wangyuli@uniontech.com Cc: paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu, anup@brainfault.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, rdunlap@infradead.org, dvlachos@ics.forth.gr, bhe@redhat.com, samuel.holland@sifive.com, guoren@kernel.org, linux@armlinux.org.uk, linux-arm-kernel@lists.infradead.org, willy@infradead.org, akpm@linux-foundation.org, fengwei.yin@intel.com, prabhakar.mahadev-lad.rj@bp.renesas.com, conor.dooley@microchip.com, glider@google.com, elver@google.com, dvyukov@google.com, kasan-dev@googlegroups.com, ardb@kernel.org, linux-efi@vger.kernel.org, atishp@atishpatra.org, kvm@vger.kernel.org, kvm-riscv@lists.infradead.org, qiaozhe@iscas.ac.cn, ryan.roberts@arm.com, ryabinin.a.a@gmail.com, andreyknvl@gmail.com, vincenzo.frascino@arm.com, namcao@linutronix.de Subject: [PATCH 6.6 2/4] mm: Introduce pudp/p4dp/pgdp_get() functions Date: Fri, 6 Sep 2024 16:22:37 +0800 Message-ID: <0BC12DAA7222E361+20240906082254.435410-2-wangyuli@uniontech.com> X-Mailer: git-send-email 2.43.4 In-Reply-To: <20240906082254.435410-1-wangyuli@uniontech.com> References: <20240906082254.435410-1-wangyuli@uniontech.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:uniontech.com:qybglogicsvrgz:qybglogicsvrgz8a-1 From: Alexandre Ghiti [ Upstream commit eba2591d99d1f14a04c8a8a845ab0795b93f5646 ] 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 Link: https://lore.kernel.org/r/20231213203001.179237-3-alexghiti@rivosinc.com Signed-off-by: Palmer Dabbelt Signed-off-by: WangYuli --- 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,