Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp665824iog; Mon, 13 Jun 2022 10:10:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwnSP8r5ngWjlhb3CfDjO7sGpI7/nVYk9y3SNPRIomP4yr6ZCRKuf7hY1zJwwNWUn64qEJf X-Received: by 2002:a17:90a:4749:b0:1e3:27a8:2e2a with SMTP id y9-20020a17090a474900b001e327a82e2amr17115141pjg.170.1655140229952; Mon, 13 Jun 2022 10:10:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655140229; cv=none; d=google.com; s=arc-20160816; b=fHFmgRXu9IlKY3tWsggxira/ROwrp9IroLIDgh+D9ATtCm+PG5N6G+K+yj2jyYLNv1 LR5oPf9/IIY4XIlFpRUesNFymaK+PNwarS+wIqunJSdIyRD09Il0WC69Cf1vhE5d2+iw Q2ulfcAaI0TYmdlWQR0z4I3+IMqaVEPfTTpx7H/kxnjLmaHEaqhIlz2s2tslWbjYVOv5 Bap3VzzvIpDFGUoPL3D+HmW6Ovp39TiGUoyzAofIxBNO7IK1/zZ8vt4yG1H8v8ESLdZA UNZURE1cy4ALXxdiCAoSivBAW75dvYgdx7nRVy0zELq5vDMthMD6AqFY2JDZWNYXWv3T O4Nw== 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; bh=70NE5MwtFRheB9xfJsBQiw+OC8nMy3sypi1ONgWb2L4=; b=oHM3OG9sFsh0PzYKqWo/B7uSc6uLSV3e/5F7t3ls2/k1Y0F8g7KBTNlig6nSsD0Klg PhP9HhXnSizNdU8LvmqQSN300rSbxAJNHMFfaMRFK4ZARlsAA+YmnxJxbrtGrWCefHcz 8cop2/YR7Xd+DkQu6/mSKJcv6pYnGu5SqdGY8fc8glwEhzMF5Pp/XkAnoFKtWRuFnNh/ zZ2wVHx+Xf0m0sTHENWMz7LXyrd4jmDj+v67o8wHlKe65zLN6ihsp3jRvoOUpqr33ecO +3lzGvK7o65gszwAQFy6ORIa51sWSg3pKw8b33l4cKVPI9M84Uq/psxSt0lowlz9yNW6 sNVw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=sntech.de Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u19-20020a170903305300b00163daf783d9si9262452pla.555.2022.06.13.10.10.14; Mon, 13 Jun 2022 10:10:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=sntech.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241536AbiFMQww (ORCPT + 99 others); Mon, 13 Jun 2022 12:52:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43600 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240718AbiFMQwk (ORCPT ); Mon, 13 Jun 2022 12:52:40 -0400 Received: from gloria.sntech.de (gloria.sntech.de [185.11.138.130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EFCA11F2F2A; Mon, 13 Jun 2022 07:37:42 -0700 (PDT) Received: from ip5b412258.dynamic.kabel-deutschland.de ([91.65.34.88] helo=diego.localnet) by gloria.sntech.de with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1o0lCE-00010b-AB; Mon, 13 Jun 2022 16:37:38 +0200 From: Heiko =?ISO-8859-1?Q?St=FCbner?= To: Guo Ren , Paul Walmsley , Palmer Dabbelt , Albert Ou , Anup Patel , Atish Patra , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, kvm-riscv@lists.infradead.org, Alexandre Ghiti Cc: Alexandre Ghiti Subject: Re: [PATCH -fixes v2] riscv: Fix missing PAGE_PFN_MASK Date: Mon, 13 Jun 2022 16:37:37 +0200 Message-ID: <2110796.irdbgypaU6@diego> In-Reply-To: <20220613085307.260256-1-alexandre.ghiti@canonical.com> References: <20220613085307.260256-1-alexandre.ghiti@canonical.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_PASS, T_SCC_BODY_TEXT_LINE,T_SPF_HELO_TEMPERROR autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Am Montag, 13. Juni 2022, 10:53:07 CEST schrieb Alexandre Ghiti: > There are a bunch of functions that use the PFN from a page table entry > that end up with the svpbmt upper-bits because they are missing the newly > introduced PAGE_PFN_MASK which leads to wrong addresses conversions and > then crash: fix this by adding this mask. > > Fixes: 100631b48ded ("riscv: Fix accessing pfn bits in PTEs for non-32bit variants") > Signed-off-by: Alexandre Ghiti Looks great now Reviewed-by: Heiko Stuebner On both qemu-riscv64 and d1-nezha Tested-by: Heiko Stuebner > --- > arch/riscv/include/asm/pgtable-64.h | 12 ++++++------ > arch/riscv/include/asm/pgtable.h | 6 +++--- > arch/riscv/kvm/mmu.c | 2 +- > 3 files changed, 10 insertions(+), 10 deletions(-) > > diff --git a/arch/riscv/include/asm/pgtable-64.h b/arch/riscv/include/asm/pgtable-64.h > index 5c2aba5efbd0..dc42375c2357 100644 > --- a/arch/riscv/include/asm/pgtable-64.h > +++ b/arch/riscv/include/asm/pgtable-64.h > @@ -175,7 +175,7 @@ static inline pud_t pfn_pud(unsigned long pfn, pgprot_t prot) > > static inline unsigned long _pud_pfn(pud_t pud) > { > - return pud_val(pud) >> _PAGE_PFN_SHIFT; > + return __page_val_to_pfn(pud_val(pud)); > } > > static inline pmd_t *pud_pgtable(pud_t pud) > @@ -278,13 +278,13 @@ static inline p4d_t pfn_p4d(unsigned long pfn, pgprot_t prot) > > static inline unsigned long _p4d_pfn(p4d_t p4d) > { > - return p4d_val(p4d) >> _PAGE_PFN_SHIFT; > + return __page_val_to_pfn(p4d_val(p4d)); > } > > static inline pud_t *p4d_pgtable(p4d_t p4d) > { > if (pgtable_l4_enabled) > - return (pud_t *)pfn_to_virt(p4d_val(p4d) >> _PAGE_PFN_SHIFT); > + return (pud_t *)pfn_to_virt(__page_val_to_pfn(p4d_val(p4d))); > > return (pud_t *)pud_pgtable((pud_t) { p4d_val(p4d) }); > } > @@ -292,7 +292,7 @@ static inline pud_t *p4d_pgtable(p4d_t p4d) > > static inline struct page *p4d_page(p4d_t p4d) > { > - return pfn_to_page(p4d_val(p4d) >> _PAGE_PFN_SHIFT); > + return pfn_to_page(__page_val_to_pfn(p4d_val(p4d))); > } > > #define pud_index(addr) (((addr) >> PUD_SHIFT) & (PTRS_PER_PUD - 1)) > @@ -347,7 +347,7 @@ static inline void pgd_clear(pgd_t *pgd) > static inline p4d_t *pgd_pgtable(pgd_t pgd) > { > if (pgtable_l5_enabled) > - return (p4d_t *)pfn_to_virt(pgd_val(pgd) >> _PAGE_PFN_SHIFT); > + return (p4d_t *)pfn_to_virt(__page_val_to_pfn(pgd_val(pgd))); > > return (p4d_t *)p4d_pgtable((p4d_t) { pgd_val(pgd) }); > } > @@ -355,7 +355,7 @@ static inline p4d_t *pgd_pgtable(pgd_t pgd) > > static inline struct page *pgd_page(pgd_t pgd) > { > - return pfn_to_page(pgd_val(pgd) >> _PAGE_PFN_SHIFT); > + return pfn_to_page(__page_val_to_pfn(pgd_val(pgd))); > } > #define pgd_page(pgd) pgd_page(pgd) > > diff --git a/arch/riscv/include/asm/pgtable.h b/arch/riscv/include/asm/pgtable.h > index 1d1be9d9419c..5dbd6610729b 100644 > --- a/arch/riscv/include/asm/pgtable.h > +++ b/arch/riscv/include/asm/pgtable.h > @@ -261,7 +261,7 @@ static inline pgd_t pfn_pgd(unsigned long pfn, pgprot_t prot) > > static inline unsigned long _pgd_pfn(pgd_t pgd) > { > - return pgd_val(pgd) >> _PAGE_PFN_SHIFT; > + return __page_val_to_pfn(pgd_val(pgd)); > } > > static inline struct page *pmd_page(pmd_t pmd) > @@ -590,14 +590,14 @@ static inline pmd_t pmd_mkinvalid(pmd_t pmd) > return __pmd(pmd_val(pmd) & ~(_PAGE_PRESENT|_PAGE_PROT_NONE)); > } > > -#define __pmd_to_phys(pmd) (pmd_val(pmd) >> _PAGE_PFN_SHIFT << PAGE_SHIFT) > +#define __pmd_to_phys(pmd) (__page_val_to_pfn(pmd_val(pmd)) << PAGE_SHIFT) > > static inline unsigned long pmd_pfn(pmd_t pmd) > { > return ((__pmd_to_phys(pmd) & PMD_MASK) >> PAGE_SHIFT); > } > > -#define __pud_to_phys(pud) (pud_val(pud) >> _PAGE_PFN_SHIFT << PAGE_SHIFT) > +#define __pud_to_phys(pud) (__page_val_to_pfn(pud_val(pud)) << PAGE_SHIFT) > > static inline unsigned long pud_pfn(pud_t pud) > { > diff --git a/arch/riscv/kvm/mmu.c b/arch/riscv/kvm/mmu.c > index 1c00695ebee7..9826073fbc67 100644 > --- a/arch/riscv/kvm/mmu.c > +++ b/arch/riscv/kvm/mmu.c > @@ -54,7 +54,7 @@ static inline unsigned long gstage_pte_index(gpa_t addr, u32 level) > > static inline unsigned long gstage_pte_page_vaddr(pte_t pte) > { > - return (unsigned long)pfn_to_virt(pte_val(pte) >> _PAGE_PFN_SHIFT); > + return (unsigned long)pfn_to_virt(__page_val_to_pfn(pte_val(pte))); > } > > static int gstage_page_size_to_level(unsigned long page_size, u32 *out_level) >