Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp3928709ybl; Mon, 12 Aug 2019 08:37:21 -0700 (PDT) X-Google-Smtp-Source: APXvYqwkZ2Wh+MKnVKnQcQQM0uPB4en48IsbAO6o58Al2DTvm71i0WU0LuXJYXzivM7j3OjGvV28 X-Received: by 2002:a17:902:b944:: with SMTP id h4mr9181957pls.39.1565624241894; Mon, 12 Aug 2019 08:37:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565624241; cv=none; d=google.com; s=arc-20160816; b=lFW8G97CaeaajftAJeBJfurwZF84owxVQY/6GJ8rSimgKK+DjlJVb8QNTIenMLgr+N SHFMdVvIyd8H5ydYwodnQRDK+CddBXF9yQRWJlWWL0C7UzfVf6VYcJGczc9JQgdukQ5r U8F4eKXOyp6C37hpSEKu/JRcye5LZYBHTk27TG/qcRr+zQUP4Z3phBpxOSNGp7Z0B6DB +vsc5Q58jjGojmD5A5wCNjzWN2nYp1QN5i9zZ63+2t57Ko81KRl0lUJji2KzX8vBTQx4 DX/jP0LQbw/uZgPYjUaaibW0FwLSdiRcDnZ6io+g7Ci8cnyIVeFmESO7epY5Ky7oVQBm N5RA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:to:references:message-id :content-transfer-encoding:cc:date:in-reply-to:from:subject :mime-version:dkim-signature; bh=SpVDrjvk0esyF9nfi14Gtm3oms4DcxHW/Qvgatp0oR0=; b=i2PT1W47JLvWr/M0tFhetJk0RvJaknyWBSjjbbhi0wU62QMP28SGZQcXxZidVdv7XO a3boBboVBHGlDhtdOI8sdAuco4zGyZL9vUx67T7nfJSRd53TRDC8klS83+bY7bWnJ2np GQUWnpdl+JabkJkCsY/0n6YM92PNVAufp+uz/tXJyFVyS4l+vntTFBBf+QcpHFHuMJWW birijwqtyixzC7BYwMrUPA0ss4UpTzk7ZXARZzhX7Xx+pzANOroCB7syxHD0BN1hil9c oJyGggXh32xLQzRANZxpEgZVnzi21EbxUArPEaritWM4X1PdGWfY8rz/dIJfD0nyHtir 0SVA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=BfBvPqT1; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a187si60717915pge.269.2019.08.12.08.37.05; Mon, 12 Aug 2019 08:37:21 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=BfBvPqT1; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726316AbfHLPg2 (ORCPT + 99 others); Mon, 12 Aug 2019 11:36:28 -0400 Received: from mail-ot1-f68.google.com ([209.85.210.68]:46437 "EHLO mail-ot1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725843AbfHLPg2 (ORCPT ); Mon, 12 Aug 2019 11:36:28 -0400 Received: by mail-ot1-f68.google.com with SMTP id z17so41901653otk.13 for ; Mon, 12 Aug 2019 08:36:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=SpVDrjvk0esyF9nfi14Gtm3oms4DcxHW/Qvgatp0oR0=; b=BfBvPqT1d5Tmm728CwJnqdt1AuAqlPYluJ26znILoC3rHojNwJJi63xaK77vqBnwY0 jC4hczUEyNpbGRmlYm3O7RHbxJ+HQmPFjnGIiHu9/DRnBWVhV0zuIUoZfYWv/meg6OTu 6zQamXD5eI3R/N1ZwTV/J8GEDVsbnCwMuMqkNcZE7aWFMu7I1MwCGZASh8Ojv53mSMhS DHVCWaNWvYJd4GJ2uKcpe5rtMSHZyoaVwAJuybJ1/inGLETiGCOb6xi6965XpbLncq5b Kvf+tfOL7HLl2WT7NdjsuqlR0n+p1XPxYSK4jnadNN4ddU5zu/yWjwl7Pa5COcAYGemB JYqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=SpVDrjvk0esyF9nfi14Gtm3oms4DcxHW/Qvgatp0oR0=; b=ZCB8+2aU0zIiWucbr4Dlym+OoyjiYV77ENeUNl4b9z9QfVVE+ULYx6fZve8aEXQx/X kRLSo1oHDOGTb2m0BKIhHSL7+YDfAdRgNovTWc9lMf+uWBRtHNL8CUZxE2DotlMszGU1 ei+sQSPo977tIYcNCm/TIAyr7Bt6QvFxAVsh1faTrCMA1qnd01BqSnf2fhPyT2vjfX6p ArZVNPjtm9z6x9rZJvtCYgU8HY5tBxQJpTR3vqoqQaECTjZ8CkiCOr18Ybx+bWySmWwL 45qMT29+mxJfaLXFSV0tws5fz4fF27MHHvD/q3wGVdsOX0bW/abLm18ZPvFjKb5KZuM8 d5GQ== X-Gm-Message-State: APjAAAU0AVrUTcuEF92qXtr8KBgm2wF1a+lhZRqVCJH+WZzqPvZgMuTz 7BDuEs9ZAl15IGnL9KJSrPQMbZct61k= X-Received: by 2002:a05:6638:637:: with SMTP id h23mr20742737jar.59.1565624187149; Mon, 12 Aug 2019 08:36:27 -0700 (PDT) Received: from [192.168.1.138] ([216.160.37.230]) by smtp.gmail.com with ESMTPSA id f1sm10078047ioh.73.2019.08.12.08.36.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 12 Aug 2019 08:36:26 -0700 (PDT) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 11.5 \(3445.9.1\)) Subject: Re: [PATCH] RISC-V: Issue a local tlb flush if possible. From: Troy Benjegerdes In-Reply-To: <20190810014309.20838-1-atish.patra@wdc.com> Date: Mon, 12 Aug 2019 10:36:25 -0500 Cc: Linux Kernel Mailing List , Albert Ou , Alexios Zavras , Greg Kroah-Hartman , Palmer Dabbelt , Anup Patel , Paul Walmsley , linux-riscv@lists.infradead.org, Allison Randal , ron minnich Content-Transfer-Encoding: quoted-printable Message-Id: <118B0DE7-EDCC-4947-88E5-7FF133A757D8@sifive.com> References: <20190810014309.20838-1-atish.patra@wdc.com> To: Atish Patra X-Mailer: Apple Mail (2.3445.9.1) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > On Aug 9, 2019, at 8:43 PM, Atish Patra wrote: >=20 > In RISC-V, tlb flush happens via SBI which is expensive. > If the target cpumask contains a local hartid, some cost > can be saved by issuing a local tlb flush as we do that > in OpenSBI anyways. Is there anything other than convention and current usage that prevents the kernel from natively handling TLB flushes without ever making the = SBI call? Someone is eventually going to want to run the linux kernel in machine = mode, likely for performance and/or security reasons, and this will require = flushing TLBs natively anyway. >=20 > Signed-off-by: Atish Patra > --- > arch/riscv/include/asm/tlbflush.h | 33 +++++++++++++++++++++++++++---- > 1 file changed, 29 insertions(+), 4 deletions(-) >=20 > diff --git a/arch/riscv/include/asm/tlbflush.h = b/arch/riscv/include/asm/tlbflush.h > index 687dd19735a7..b32ba4fa5888 100644 > --- a/arch/riscv/include/asm/tlbflush.h > +++ b/arch/riscv/include/asm/tlbflush.h > @@ -8,6 +8,7 @@ > #define _ASM_RISCV_TLBFLUSH_H >=20 > #include > +#include > #include >=20 > /* > @@ -46,14 +47,38 @@ static inline void remote_sfence_vma(struct = cpumask *cmask, unsigned long start, > unsigned long size) > { > struct cpumask hmask; > + struct cpumask tmask; > + int cpuid =3D smp_processor_id(); >=20 > cpumask_clear(&hmask); > - riscv_cpuid_to_hartid_mask(cmask, &hmask); > - sbi_remote_sfence_vma(hmask.bits, start, size); > + cpumask_clear(&tmask); > + > + if (cmask) > + cpumask_copy(&tmask, cmask); > + else > + cpumask_copy(&tmask, cpu_online_mask); > + > + if (cpumask_test_cpu(cpuid, &tmask)) { > + /* Save trap cost by issuing a local tlb flush here */ > + if ((start =3D=3D 0 && size =3D=3D -1) || (size > = PAGE_SIZE)) > + local_flush_tlb_all(); > + else if (size =3D=3D PAGE_SIZE) > + local_flush_tlb_page(start); > + cpumask_clear_cpu(cpuid, &tmask); > + } else if (cpumask_empty(&tmask)) { > + /* cpumask is empty. So just do a local flush */ > + local_flush_tlb_all(); > + return; > + } > + > + if (!cpumask_empty(&tmask)) { > + riscv_cpuid_to_hartid_mask(&tmask, &hmask); > + sbi_remote_sfence_vma(hmask.bits, start, size); > + } > } >=20 > -#define flush_tlb_all() sbi_remote_sfence_vma(NULL, 0, -1) > -#define flush_tlb_page(vma, addr) flush_tlb_range(vma, addr, 0) > +#define flush_tlb_all() remote_sfence_vma(NULL, 0, -1) > +#define flush_tlb_page(vma, addr) flush_tlb_range(vma, addr, (addr) + = PAGE_SIZE) > #define flush_tlb_range(vma, start, end) \ > remote_sfence_vma(mm_cpumask((vma)->vm_mm), start, (end) - = (start)) > #define flush_tlb_mm(mm) \ > --=20 > 2.21.0 >=20 >=20 > _______________________________________________ > linux-riscv mailing list > linux-riscv@lists.infradead.org > http://lists.infradead.org/mailman/listinfo/linux-riscv