Received: by 2002:a05:6358:111d:b0:dc:6189:e246 with SMTP id f29csp1081596rwi; Thu, 3 Nov 2022 00:17:52 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7Nn8vP4lCsMilZeKmkcTE/yb2UpSlcK+MIfpQVym6ovl87vMzcqGSPpJaTjwmS1CcgN71j X-Received: by 2002:a17:90a:f612:b0:214:9b8:20a with SMTP id bw18-20020a17090af61200b0021409b8020amr13887558pjb.16.1667459872018; Thu, 03 Nov 2022 00:17:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667459872; cv=none; d=google.com; s=arc-20160816; b=N8qDcCfD6Rg3uYRYYA7MuplSPtIV8yh+6X8D6q1qZJILWLpdr2zexB5UZt6bFei5qb t90crgNuITxsvLJ4mxMVzePAndZNVRMUiXU0btP3uk/KqpItADKWffSk/iZVViPo0eAb wAr19Ozvlyh6wCE5ZbTvt9yurF+p38R4toykBscXoq8J9X5JAzty14gnCkmgZ+WIrRuj JrfZunin/x4xrmKR3I3ssMBQr6FjWDbsGsop4iDXGKndXk53W/zdAvLNyPQAwQCXqW3X 6w0iZ4wTLsqJ6ym5xxZjwUJ1mOTsXuYTOxQHN/HaZOF5hvCs2Y3GLsMipEp1CcnEWTFr zZOg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=kR6ignjGg3LmqCbSdIp9lkLVihLfP058l6KWrmtMNQM=; b=xuykFJOk61UnBxOoCb9rVUyX2fgcFzwSXzjg3lRgvXVtYyz913UUl7c1ODiTcO1NB5 VvNytmHJ8GgE0d8+QiVcdd+LycVYm29hqgKsKlTARh+4M3CgFis5y5LyQP06kU9yETzw jNYsgVxmaQik7xOE9Jj1DfrLM9ITr7J0bRXWqIW3aKqpuv7Bc16/nol2qgSS1jkWrtA7 kODI+rWcuH4MwvRE3zIAYpE8TBqFdklIghmtStIcX/h0TKivUwrq+cT9LGQ8P+BHMMsH reY98R/ij9BdIEM1wD2dMIzSP7hKqR7g+AWZXXFYtofqbKHJokRECGDn/gKDF/EgqzxJ xJVQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@atishpatra.org header.s=google header.b=drK8F1zQ; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id cv6-20020a056a0044c600b0053b36138dc5si2089pfb.222.2022.11.03.00.17.38; Thu, 03 Nov 2022 00:17:51 -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; dkim=pass header.i=@atishpatra.org header.s=google header.b=drK8F1zQ; 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 S229598AbiKCHBM (ORCPT + 97 others); Thu, 3 Nov 2022 03:01:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39530 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229461AbiKCHBJ (ORCPT ); Thu, 3 Nov 2022 03:01:09 -0400 Received: from mail-oi1-x22a.google.com (mail-oi1-x22a.google.com [IPv6:2607:f8b0:4864:20::22a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9E653DB3 for ; Thu, 3 Nov 2022 00:01:08 -0700 (PDT) Received: by mail-oi1-x22a.google.com with SMTP id n186so1086696oih.7 for ; Thu, 03 Nov 2022 00:01:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=atishpatra.org; s=google; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=kR6ignjGg3LmqCbSdIp9lkLVihLfP058l6KWrmtMNQM=; b=drK8F1zQPCBkx+X55Ab6f3areRAfKRxAskSrcFxRfa7+5ZmA/EfZEeatQ3PQmrxmjX iMf0Z/RP2j3EXOQK+I8Yaxy//iOeJu0e8jXbO9Ms08I9thA12xqTj2T/MzWVyrvQGanR bbPf/j8H1QH+FzMRX/krQKI8Hn2jaTgaubgHM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=kR6ignjGg3LmqCbSdIp9lkLVihLfP058l6KWrmtMNQM=; b=HkT+ywdUJ0wrTxHmgR8w7BJ4oqeRFJOU/7aIZ8wW/2SPF6ncLcWw+spI9FVp9KfPaV F+nqeJpWOnscASjhTLJ/OLellPjyEPrNsO41ZSrUtI5MhDqR2r/tudvltHBSI5TfC+v/ WPYc9Hyz8w8iudlwO4Dc/E5BbMy2vpBnDxNEojUpQdfaz+CX+eelQFjlO6qsR9vkKNgw XoMpoFDDZXx6MVVgGPFScTBGV7TuCz5ETXTk2ylrwIuNLL3xRcmgllKAlHIaXwPXBgrs tpPLvf5twu9wjkk7csfUhWwUxhX8XKB75Y+xTHCliGzMbCI+OxwI1279OGb8aTi5VOYO /2VA== X-Gm-Message-State: ACrzQf07NRZHrZ4FetZl3/cd55MDyUjgi+RVtJ9wPCjC2tg9T5XBkHmf ZmywGNsS3YNutPyuMOue9v6OPiyGor+fNUw8PwiOQoqFxw== X-Received: by 2002:a05:6808:485:b0:359:d1b1:2587 with SMTP id z5-20020a056808048500b00359d1b12587mr18843466oid.274.1667458867973; Thu, 03 Nov 2022 00:01:07 -0700 (PDT) MIME-Version: 1.0 References: <20221101143400.690000-1-apatel@ventanamicro.com> <20221101143400.690000-7-apatel@ventanamicro.com> In-Reply-To: <20221101143400.690000-7-apatel@ventanamicro.com> From: Atish Patra Date: Thu, 3 Nov 2022 00:00:56 -0700 Message-ID: Subject: Re: [PATCH v10 6/7] RISC-V: Use IPIs for remote TLB flush when possible To: Anup Patel Cc: Palmer Dabbelt , Paul Walmsley , Thomas Gleixner , Marc Zyngier , Daniel Lezcano , Alistair Francis , Anup Patel , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS 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 On Tue, Nov 1, 2022 at 7:34 AM Anup Patel wrote: > > If we have specialized interrupt controller (such as AIA IMSIC) which > allows supervisor mode to directly inject IPIs without any assistance > from M-mode or HS-mode then using such specialized interrupt controller, > we can do remote TLB flushes directly from supervisor mode instead of > using the SBI RFENCE calls. > > This patch extends remote TLB flush functions to use supervisor mode > IPIs whenever direct supervisor mode IPIs.are supported by interrupt > controller. > > Signed-off-by: Anup Patel > --- > arch/riscv/mm/tlbflush.c | 93 +++++++++++++++++++++++++++++++++------- > 1 file changed, 78 insertions(+), 15 deletions(-) > > diff --git a/arch/riscv/mm/tlbflush.c b/arch/riscv/mm/tlbflush.c > index 37ed760d007c..27a7db8eb2c4 100644 > --- a/arch/riscv/mm/tlbflush.c > +++ b/arch/riscv/mm/tlbflush.c > @@ -23,14 +23,62 @@ static inline void local_flush_tlb_page_asid(unsigned long addr, > : "memory"); > } > > +static inline void local_flush_tlb_range(unsigned long start, > + unsigned long size, unsigned long stride) > +{ > + if (size <= stride) > + local_flush_tlb_page(start); > + else > + local_flush_tlb_all(); > +} > + > +static inline void local_flush_tlb_range_asid(unsigned long start, > + unsigned long size, unsigned long stride, unsigned long asid) > +{ > + if (size <= stride) > + local_flush_tlb_page_asid(start, asid); > + else > + local_flush_tlb_all_asid(asid); > +} > + > +static void __ipi_flush_tlb_all(void *info) > +{ > + local_flush_tlb_all(); > +} > + > void flush_tlb_all(void) > { > - sbi_remote_sfence_vma(NULL, 0, -1); > + if (riscv_use_ipi_for_rfence()) > + on_each_cpu(__ipi_flush_tlb_all, NULL, 1); > + else > + sbi_remote_sfence_vma(NULL, 0, -1); > +} > + > +struct flush_tlb_range_data { > + unsigned long asid; > + unsigned long start; > + unsigned long size; > + unsigned long stride; > +}; > + > +static void __ipi_flush_tlb_range_asid(void *info) > +{ > + struct flush_tlb_range_data *d = info; > + > + local_flush_tlb_range_asid(d->start, d->size, d->stride, d->asid); > +} > + > +static void __ipi_flush_tlb_range(void *info) > +{ > + struct flush_tlb_range_data *d = info; > + > + local_flush_tlb_range(d->start, d->size, d->stride); > } > > -static void __sbi_tlb_flush_range(struct mm_struct *mm, unsigned long start, > - unsigned long size, unsigned long stride) > +static void __flush_tlb_range(struct mm_struct *mm, unsigned long start, > + unsigned long size, unsigned long stride) > { > + struct flush_tlb_range_data ftd; > struct cpumask *cmask = mm_cpumask(mm); > unsigned int cpuid; > bool broadcast; > @@ -45,19 +93,34 @@ static void __sbi_tlb_flush_range(struct mm_struct *mm, unsigned long start, > unsigned long asid = atomic_long_read(&mm->context.id); > > if (broadcast) { > - sbi_remote_sfence_vma_asid(cmask, start, size, asid); > - } else if (size <= stride) { > - local_flush_tlb_page_asid(start, asid); > + if (riscv_use_ipi_for_rfence()) { > + ftd.asid = asid; > + ftd.start = start; > + ftd.size = size; > + ftd.stride = stride; > + on_each_cpu_mask(cmask, > + __ipi_flush_tlb_range_asid, > + &ftd, 1); > + } else > + sbi_remote_sfence_vma_asid(cmask, > + start, size, asid); > } else { > - local_flush_tlb_all_asid(asid); > + local_flush_tlb_range_asid(start, size, stride, asid); > } > } else { > if (broadcast) { > - sbi_remote_sfence_vma(cmask, start, size); > - } else if (size <= stride) { > - local_flush_tlb_page(start); > + if (riscv_use_ipi_for_rfence()) { > + ftd.asid = 0; > + ftd.start = start; > + ftd.size = size; > + ftd.stride = stride; > + on_each_cpu_mask(cmask, > + __ipi_flush_tlb_range, > + &ftd, 1); > + } else > + sbi_remote_sfence_vma(cmask, start, size); > } else { > - local_flush_tlb_all(); > + local_flush_tlb_range(start, size, stride); > } > } > > @@ -66,23 +129,23 @@ static void __sbi_tlb_flush_range(struct mm_struct *mm, unsigned long start, > > void flush_tlb_mm(struct mm_struct *mm) > { > - __sbi_tlb_flush_range(mm, 0, -1, PAGE_SIZE); > + __flush_tlb_range(mm, 0, -1, PAGE_SIZE); > } > > void flush_tlb_page(struct vm_area_struct *vma, unsigned long addr) > { > - __sbi_tlb_flush_range(vma->vm_mm, addr, PAGE_SIZE, PAGE_SIZE); > + __flush_tlb_range(vma->vm_mm, addr, PAGE_SIZE, PAGE_SIZE); > } > > void flush_tlb_range(struct vm_area_struct *vma, unsigned long start, > unsigned long end) > { > - __sbi_tlb_flush_range(vma->vm_mm, start, end - start, PAGE_SIZE); > + __flush_tlb_range(vma->vm_mm, start, end - start, PAGE_SIZE); > } > #ifdef CONFIG_TRANSPARENT_HUGEPAGE > void flush_pmd_tlb_range(struct vm_area_struct *vma, unsigned long start, > unsigned long end) > { > - __sbi_tlb_flush_range(vma->vm_mm, start, end - start, PMD_SIZE); > + __flush_tlb_range(vma->vm_mm, start, end - start, PMD_SIZE); > } > #endif > -- > 2.34.1 > LGTM. Reviewed-by: Atish Patra -- Regards, Atish