Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp4006298pxb; Tue, 25 Jan 2022 01:11:12 -0800 (PST) X-Google-Smtp-Source: ABdhPJzRLzBT3pAdoujOxHuI8QQ+XU6p97SYhu19BLG3oioXP1r89xLJTPBMLC+qH8YL/w8t51YI X-Received: by 2002:a17:90b:1bc1:: with SMTP id oa1mr2529168pjb.209.1643101872583; Tue, 25 Jan 2022 01:11:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643101872; cv=none; d=google.com; s=arc-20160816; b=kz7k44C3WjBex69V2PR2A3nMwc5FS0r0DvKn0q1oNBKYSkqzQKR2cEZocShv51s87L oUPiOIInya0/FAnyQzOGHRUcliJOCTw25722Wi8n+aTNXNZc+Dsp+T11dJflydvuJb4+ TIXJlMH1xJZiyX/E/7UgbEDnXc8d0cf7jyMLyDH3imr36GaRZ0kgN3IEy/i6vOnb3irq jEs9zeS15HBESzG2cqLR4RRgNRgHh7wDNgXfJQd3++YX3ye+8fPae/VHFfUkNw0lnvdE SjkCcwX7loqdrzjBjrbZRTBBzNb9+1/ZYXE4itjCKaJkbNJnT0/NTyzG7gUvXPUWU6RK nWRQ== 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=ANfiyTNuLH3K34lM7cYA66sM88G94rOT/TdSDWy1dfM=; b=X1yGS3Md9tScbLjxfilNyW9S7eubau9sZazsACp80i9csvyENxIUd4NJQMAcP5mzLA RU/BQ0cUsh9ptgbhUS+ucZCnsmKgYC5HvfR0nKjXmgoKsc3GqD4m1UX+olOGAUATuU3Y qrQDt6vuxiS0WFvsutNFsZpcrCiEppoBVQ/V+cMaVPhJ+G9MUaLvIBRtOQDJwmYKPHfJ QLzTR87r5p3H/9MGT6adw4BdQ2p3RuVrHxl79u4jf/hOLckqRCmPYFxV9GQdvni6VaPL hdDZEsXeRE95ePRus9geF5Jo35mo4QeKkmS2OW9Xp4sKeqN1zwGQQyGAOFk0K79jD6TQ iVxA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b=Z2l3OEwP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p42si15610648pfw.312.2022.01.25.01.11.00; Tue, 25 Jan 2022 01:11:12 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b=Z2l3OEwP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1442473AbiAYHI7 (ORCPT + 99 others); Tue, 25 Jan 2022 02:08:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45958 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1391924AbiAYHEm (ORCPT ); Tue, 25 Jan 2022 02:04:42 -0500 Received: from mail-pf1-x436.google.com (mail-pf1-x436.google.com [IPv6:2607:f8b0:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2F8A2C04188D for ; Mon, 24 Jan 2022 21:44:16 -0800 (PST) Received: by mail-pf1-x436.google.com with SMTP id e28so14028553pfj.5 for ; Mon, 24 Jan 2022 21:44:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ANfiyTNuLH3K34lM7cYA66sM88G94rOT/TdSDWy1dfM=; b=Z2l3OEwPTmcht1x90krU+HvQuTaWfAECasawdJmUmykWoDMEy1GSasrIoFi1UnDWAE Ye/rxw3S4BZl3JeodXOFKlJu+zb5l9yujbNh3LwcmQSTgv3VjTSPVSJObmo56q3kqw88 j5KeMhQUACWMLkNNo9fWDtrFHIcV/x9YjCeYPzku04KhdiAUyGwTlZufjBsdTwwJtwyd xEBaIyIwCsYpXQnJbsBfAjrlnKeEJM7pK/aw1YRN9bw64S+iLpoXAbkddKabkQ1qMPIo CdCcXVL9uOifEcjynI8Jbu53AjS6U+rSaVI3Us/xaiFGIkflxxwbdlJ8AblslAD5rQ09 QjHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ANfiyTNuLH3K34lM7cYA66sM88G94rOT/TdSDWy1dfM=; b=ceY+WY3yuNu1/DAGtWaaVkw91J5MAi5rT9r1ndvkVoN2AM3ZjOEfVQXsIYQ74B+eY4 rtv5UOP/ENTJWVJqazMntCP7sm67J5jsEcTaTFg4HsjX1IgI6amVXIQQUM16/aT/9FJv LclU1tE+WofKYG5z2DgpNnQJ5gN4nqDaZeZq9+6gJ8xTOHfq3GuHMBOq0oDLR2JMkHjm YverkycV/IpKW85blFySnecUKS4gGXIlfyF8qnDMLrdNPFBmgbkbbSmWSpNN349qhoUA U+VqdeqZ5QKCAcNquaLfVcEXmZUqU9jxn7oqmBZXWCignizj9UhHIE069ADSgxPQW4vs PTKQ== X-Gm-Message-State: AOAM5307TWJ5y+o8oPy4CCpjagl6e6UdK+8AZxpwVlsX1ezR4pAeWbdO XQe57eBBenqfUQFqIOAhK6JufQ== X-Received: by 2002:a65:578b:: with SMTP id b11mr6140482pgr.318.1643089455716; Mon, 24 Jan 2022 21:44:15 -0800 (PST) Received: from localhost.localdomain ([122.179.14.218]) by smtp.gmail.com with ESMTPSA id c6sm19524508pfl.200.2022.01.24.21.44.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Jan 2022 21:44:15 -0800 (PST) From: Anup Patel To: Palmer Dabbelt , Paul Walmsley , Thomas Gleixner , Marc Zyngier , Daniel Lezcano , Rob Herring Cc: Atish Patra , Alistair Francis , Anup Patel , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Anup Patel Subject: [PATCH 5/6] RISC-V: Use IPIs for remote TLB flush when possible Date: Tue, 25 Jan 2022 11:12:16 +0530 Message-Id: <20220125054217.383482-6-apatel@ventanamicro.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220125054217.383482-1-apatel@ventanamicro.com> References: <20220125054217.383482-1-apatel@ventanamicro.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org If IPI calls are injected using SBI IPI calls then remote TLB flush using SBI RFENCE calls is much faster because using IPIs for remote TLB flush would still endup as SBI IPI calls with extra processing on kernel side. It is now possible to have specialized hardware (such as RISC-V AIA and RISC-V ACLINT) which allows S-mode software to directly inject IPIs without any assistance from M-mode runtime firmware. This patch extends remote TLB flush functions to use IPIs whenever underlying IPI operations are suitable for remote FENCEs. 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.25.1