Message ID | 20230224104001.2743135-1-dylan@andestech.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp840192wrd; Fri, 24 Feb 2023 03:07:44 -0800 (PST) X-Google-Smtp-Source: AK7set+ZiUG9A/ay4dl4UyHoDFLRhpFBfRtvDs8FvAl7aW8VgKSPUyKbz3Uh5HRIcvrMDN5cJhxc X-Received: by 2002:a05:6402:4024:b0:4af:6227:763b with SMTP id d36-20020a056402402400b004af6227763bmr9489865eda.18.1677236864814; Fri, 24 Feb 2023 03:07:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677236864; cv=none; d=google.com; s=arc-20160816; b=GCmRiVR9vosoDlxZNQiWdcxc+QN/Hiun1xYZhhNTmR0f2Lo/PL6sQIBx6EHFn2Gn5f 6SCwPlYnWgk/TzaASwYDlU13wwSNvO6BTcjcoYsrhv8jAVfLRroHZiMebqZOB0yg7tmY m0qQFdvhicr/+t1ZPsyZSOe70HYBzKnvlZyHf0v6FhYz3FBeaRsRRjOiBhuz+VFnTKiy Ir6Ia9/7hZ4zAKkhd3jq6fbE1k0AHbIFeqJsxAmKvtUDBaq6cptHWB/e2MKrRLZHS2B/ K9vFHq4wuxRZ3Y2eJordIMThq5bS6HzgN62VOR2wJ4NiQ6sWCOFkwkXxvSMseq3WoOZX Xrfw== 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 :message-id:date:subject:cc:to:from; bh=xoJu5pMkCqiPcgKvH52UNtlDR679BrOZiiYAs+R2KqY=; b=PtW1ZrMOgdL1+43oaZnP8pIVgQ9m4R+HKezYZROAWT299sMnmysyiT2neYk4StUp6g tNLOIBuEkNFz6hiuP0klzP2WDoe4ZWJ0NZMJCw8Z6xgIaNYd3Op84ieDdrF05GJvxE9P ppXJpDsOcx+j1SY8sivceiYicbz2ZcT/rJiLDjC97/mYPC8duSJHc3b2oWIzqp228m5v qhMQgv9mcI8vUCZaam14yhiQfbW7Q3HnySPWMucyUsgTH1oezt4OngS5AnG3hlBcEtMs R6pdJyFHnYW0ld4+789+0BVaRPojM3R/dxDTDMOQpHEBSKFMv7FCQJvzyeVssv1LcGq0 kJbA== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id vw17-20020a170907059100b008d2606e415dsi14671429ejb.708.2023.02.24.03.07.21; Fri, 24 Feb 2023 03:07:44 -0800 (PST) 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230343AbjBXLCZ (ORCPT <rfc822;jeff.pang.chn@gmail.com> + 99 others); Fri, 24 Feb 2023 06:02:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60446 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230154AbjBXLCA (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Fri, 24 Feb 2023 06:02:00 -0500 X-Greylist: delayed 1212 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Fri, 24 Feb 2023 03:00:33 PST Received: from Atcsqr.andestech.com (60-248-80-70.hinet-ip.hinet.net [60.248.80.70]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A233425297 for <linux-kernel@vger.kernel.org>; Fri, 24 Feb 2023 03:00:33 -0800 (PST) Received: from Atcsqr.andestech.com (localhost [127.0.0.2] (may be forged)) by Atcsqr.andestech.com with ESMTP id 31OAeLfr055962 for <linux-kernel@vger.kernel.org>; Fri, 24 Feb 2023 18:40:21 +0800 (+08) (envelope-from dylan@andestech.com) Received: from mail.andestech.com (ATCPCS16.andestech.com [10.0.1.222]) by Atcsqr.andestech.com with ESMTP id 31OAe6bd055911; Fri, 24 Feb 2023 18:40:06 +0800 (+08) (envelope-from dylan@andestech.com) Received: from atctrx.andestech.com (10.0.15.173) by ATCPCS16.andestech.com (10.0.1.222) with Microsoft SMTP Server id 14.3.498.0; Fri, 24 Feb 2023 18:40:05 +0800 From: Dylan Jhong <dylan@andestech.com> To: <linux-riscv@lists.infradead.org>, <linux-kernel@vger.kernel.org> CC: <liushixin2@huawei.com>, <x5710999x@gmail.com>, <bjorn@rivosinc.com>, <abrestic@rivosinc.com>, <peterx@redhat.com>, <hanchuanhua@oppo.com>, <apopple@nvidia.com>, <hca@linux.ibm.com>, <aou@eecs.berkeley.edu>, <palmer@dabbelt.com>, <paul.walmsley@sifive.com>, <tim609@andestech.com>, <peterlin@andestech.com>, <ycliang@andestech.com>, Dylan Jhong <dylan@andestech.com> Subject: [PATCH] RISC-V: mm: Support huge page in vmalloc_fault() Date: Fri, 24 Feb 2023 18:40:01 +0800 Message-ID: <20230224104001.2743135-1-dylan@andestech.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.0.15.173] X-DNSRBL: X-SPAM-SOURCE-CHECK: pass X-MAIL: Atcsqr.andestech.com 31OAeLfr055962 X-Spam-Status: No, score=-0.9 required=5.0 tests=BAYES_00,PDS_RDNS_DYNAMIC_FP, RDNS_DYNAMIC,SPF_HELO_NONE,SPF_PASS autolearn=no 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1758710322954017608?= X-GMAIL-MSGID: =?utf-8?q?1758710322954017608?= |
Series |
RISC-V: mm: Support huge page in vmalloc_fault()
|
|
Commit Message
Dylan Jhong
Feb. 24, 2023, 10:40 a.m. UTC
RISC-V supports ioremap() with huge page (pud/pmd) mapping, but
vmalloc_fault() assumes that the vmalloc range is limited to pte
mappings. Add huge page support to complete the vmalloc_fault()
function.
Fixes: 310f541a027b ("riscv: Enable HAVE_ARCH_HUGE_VMAP for 64BIT")
Signed-off-by: Dylan Jhong <dylan@andestech.com>
---
arch/riscv/mm/fault.c | 5 +++++
1 file changed, 5 insertions(+)
Comments
Hi Dylan, On 2/24/23 11:40, Dylan Jhong wrote: > RISC-V supports ioremap() with huge page (pud/pmd) mapping, but > vmalloc_fault() assumes that the vmalloc range is limited to pte > mappings. Add huge page support to complete the vmalloc_fault() > function. > > Fixes: 310f541a027b ("riscv: Enable HAVE_ARCH_HUGE_VMAP for 64BIT") > > Signed-off-by: Dylan Jhong <dylan@andestech.com> > --- > arch/riscv/mm/fault.c | 5 +++++ > 1 file changed, 5 insertions(+) > > diff --git a/arch/riscv/mm/fault.c b/arch/riscv/mm/fault.c > index eb0774d9c03b..4b9953b47d81 100644 > --- a/arch/riscv/mm/fault.c > +++ b/arch/riscv/mm/fault.c > @@ -143,6 +143,8 @@ static inline void vmalloc_fault(struct pt_regs *regs, int code, unsigned long a > no_context(regs, addr); > return; > } > + if (pud_leaf(*pud_k)) > + goto flush_tlb; > > /* > * Since the vmalloc area is global, it is unnecessary > @@ -153,6 +155,8 @@ static inline void vmalloc_fault(struct pt_regs *regs, int code, unsigned long a > no_context(regs, addr); > return; > } > + if (pmd_leaf(*pmd_k)) > + goto flush_tlb; > > /* > * Make sure the actual PTE exists as well to > @@ -172,6 +176,7 @@ static inline void vmalloc_fault(struct pt_regs *regs, int code, unsigned long a > * ordering constraint, not a cache flush; it is > * necessary even after writing invalid entries. > */ > +flush_tlb: > local_flush_tlb_page(addr); > } > This looks good to me, you can add: Reviewed-by: Alexandre Ghiti <alexghiti@rivosinc.com> One question: how did you encounter this bug? Thanks, Alex
On Fri, Feb 24, 2023 at 01:47:20PM +0100, Alexandre Ghiti wrote: > Hi Dylan, > > On 2/24/23 11:40, Dylan Jhong wrote: > > RISC-V supports ioremap() with huge page (pud/pmd) mapping, but > > vmalloc_fault() assumes that the vmalloc range is limited to pte > > mappings. Add huge page support to complete the vmalloc_fault() > > function. > > > > Fixes: 310f541a027b ("riscv: Enable HAVE_ARCH_HUGE_VMAP for 64BIT") > > > > Signed-off-by: Dylan Jhong <dylan@andestech.com> > > --- > > arch/riscv/mm/fault.c | 5 +++++ > > 1 file changed, 5 insertions(+) > > > > diff --git a/arch/riscv/mm/fault.c b/arch/riscv/mm/fault.c > > index eb0774d9c03b..4b9953b47d81 100644 > > --- a/arch/riscv/mm/fault.c > > +++ b/arch/riscv/mm/fault.c > > @@ -143,6 +143,8 @@ static inline void vmalloc_fault(struct pt_regs *regs, int code, unsigned long a > > no_context(regs, addr); > > return; > > } > > + if (pud_leaf(*pud_k)) > > + goto flush_tlb; > > /* > > * Since the vmalloc area is global, it is unnecessary > > @@ -153,6 +155,8 @@ static inline void vmalloc_fault(struct pt_regs *regs, int code, unsigned long a > > no_context(regs, addr); > > return; > > } > > + if (pmd_leaf(*pmd_k)) > > + goto flush_tlb; > > /* > > * Make sure the actual PTE exists as well to > > @@ -172,6 +176,7 @@ static inline void vmalloc_fault(struct pt_regs *regs, int code, unsigned long a > > * ordering constraint, not a cache flush; it is > > * necessary even after writing invalid entries. > > */ > > +flush_tlb: > > local_flush_tlb_page(addr); > > } > > > This looks good to me, you can add: > > Reviewed-by: Alexandre Ghiti <alexghiti@rivosinc.com> > > One question: how did you encounter this bug? > > Thanks, > > Alex > Hi Alex, >>> One question: how did you encounter this bug? This bug is caused by the combination of out-of-order excutiuon and ioremap(). The OoO excution will try to access the VA that is given by ioremap() and record a page fault in TLB before the mapping is created in ioremap(). When the CPU really accesses the VA after ioremap(), the CPU will trigger page fault because of the TLB already has the VA mapping. We hope that the vmalloc_fault() in page fault handler will trigger sfence.vma to invalidate the TLB[1]. But since we do not support the huge page in vmalloc_fault(), we encountered the nested page faults in vmalloc_fault() while forcing the pmd/pud huge pages to resolve pte entry. This is the reason I send this patch. ref: [1]: https://patchwork.kernel.org/project/linux-riscv/patch/20210412000531.12249-1-liu@jiuyang.me/
diff --git a/arch/riscv/mm/fault.c b/arch/riscv/mm/fault.c index eb0774d9c03b..4b9953b47d81 100644 --- a/arch/riscv/mm/fault.c +++ b/arch/riscv/mm/fault.c @@ -143,6 +143,8 @@ static inline void vmalloc_fault(struct pt_regs *regs, int code, unsigned long a no_context(regs, addr); return; } + if (pud_leaf(*pud_k)) + goto flush_tlb; /* * Since the vmalloc area is global, it is unnecessary @@ -153,6 +155,8 @@ static inline void vmalloc_fault(struct pt_regs *regs, int code, unsigned long a no_context(regs, addr); return; } + if (pmd_leaf(*pmd_k)) + goto flush_tlb; /* * Make sure the actual PTE exists as well to @@ -172,6 +176,7 @@ static inline void vmalloc_fault(struct pt_regs *regs, int code, unsigned long a * ordering constraint, not a cache flush; it is * necessary even after writing invalid entries. */ +flush_tlb: local_flush_tlb_page(addr); }