Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp600628ybl; Thu, 22 Aug 2019 01:53:03 -0700 (PDT) X-Google-Smtp-Source: APXvYqyqdZnYFfhzD4EfjgBsedRF1OFWO4OBeRUo4q3/dlPaOlXsuAtYynXlWoy+nDbBPac+VymL X-Received: by 2002:a17:902:28a2:: with SMTP id f31mr23927268plb.44.1566463983064; Thu, 22 Aug 2019 01:53:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566463983; cv=none; d=google.com; s=arc-20160816; b=a5RrZfnHAUjpgXUM9Vaohn8sM0d1dzaPf+8phSkSpVwgWnDArT6Aqo/aHeAtXO1d9D yGXqlRIlX4GlEAo7ayZ/RI6CoPdscfM96RtWQaatbGXDw7ezlwl8HMX0cawCwcR8TRrq HHeU7CML9YqIQ/ham5CbeFHApGAgKyCzshdfPpHfkZ8qPA/ThNoUPSkgMdqA+RxoMObe lxO3wY8Thj1bFcGjQmi4zc8bbquI4IivQgoKvJDLs3PRWj5bc7W98LSeI42/pIRsP11e HaUuwjQdNDPnhiZbUfKAYg34CsetxQg3JkrifECgS4LjdyfDcZeEkfvFDmfHU0FBM4dz VdyQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :wdcironportexception:ironport-sdr:ironport-sdr:ironport-sdr :dkim-signature; bh=dZv/0Jmwq7f41hmxzK1Cmiq+4IHJ33aX/F6xHyFkSQA=; b=im0eiK500xkRHdjfLsfasC6Lyqsr1Tp+8KIn0Z/HYF4z8n+zwiTdCqX1wCG+0PvU9C rEkDGcfMdBIwKaEzD36fyrfOybVxqJj3vPX7OQ/cUXXnI5NN9L+3yrjjfHTcM0MYLpHt NUfWUPuRB1wHSNDkA2xQZzLoBfSiOHQB8Phac0Wgrfe5L1KQRTpMGkoZZfvSAnnx9JZa pUoR72h1AMdzfuKAPW6sin4S7Zvi/TlldsEBsJseb+clgBuNv/w9Oj1/QOdRuBqd093S kpQWzSuQz1mNmi2P8Ppd3gKiuaG1wdUlDUTQXHu26RGeFiO+V3YaL/7iRhrY0hf4U9L3 JNCQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@wdc.com header.s=dkim.wdc.com header.b=Y+9S9KAo; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=wdc.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id bb21si1956538pjb.37.2019.08.22.01.52.48; Thu, 22 Aug 2019 01:53:03 -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=fail header.i=@wdc.com header.s=dkim.wdc.com header.b=Y+9S9KAo; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=wdc.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731840AbfHVH7E (ORCPT + 99 others); Thu, 22 Aug 2019 03:59:04 -0400 Received: from esa4.hgst.iphmx.com ([216.71.154.42]:20003 "EHLO esa4.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731019AbfHVH67 (ORCPT ); Thu, 22 Aug 2019 03:58:59 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1566460739; x=1597996739; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=8phmIoE0V9/kOpVUv4HvROJtbVLacwF1vHNNlNefEhM=; b=Y+9S9KAoRuLCHYqBNSe6btK4FFi7DgjeOXb9tUEnmbVIkFDkK+2/AFKG eLy4QU+LIWHAtLGHQU1ZW3eG5tQ4ki81I34RVECQsEuoglNUA/3JLlz7U m9Hx3ujUq57LessR3AyBqqBbNEWZR9ELws5Ncf2uucQ9dwhEudslJIktP dy6LR+XfLQ1eMPdllHzi+0o0dqMRnxgoVxAcGH5z8hA2DkoiBhgTgHM1Y ayfvcpxAQMKbyBH0JZAY962Z29c/LcZGCMlaBPw2LiP/liiOjE/H00B8k sZDCMQt33uY1W6E6sgnTWq9QREIz+0wqn/XtTJQ7KPDkjeEdVOyCRwdA8 Q==; IronPort-SDR: AK3GUitXrROvlKPLM10m6FeksFpZWnZ0rozC+VxprfBdJ79Q9+nZTDqkp34ariyKOA0A3JFGAn aQbjgEbvE44P/+1MQiQulIPb0Yevtgs68CLtoo969flCb9ocI3pnZRNsW3jp9GuPX3uczuqGyE +a5tQ1obULVyMeAX6SMOo94VNETQGoyoqPp5SDU/gF5Z6XLPc2bwEboTdeyIRXR0tdXKSaKdYh Qn2FYq25dzc/luLwxhvKg61c6QbiWEzdUTZCUg0N2LBGvZVjTNih/RXhfePGdJ5MI6vdc4yjC/ Pn8= X-IronPort-AV: E=Sophos;i="5.64,415,1559491200"; d="scan'208";a="116397482" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 22 Aug 2019 15:58:59 +0800 IronPort-SDR: NdDRvRVEfnFuy3SuGPxVuUt0RGQAv0zWICK1t51mwiGyJSOelfCLDAq5jnWC3z357lcKuHP8Jg YayzV8es1mS/1czfY+Nup9hHvOVIT0H+4dBHiB3vBNCS5wBszxcbgGeo576/xs5UKTAv6ooAj5 aRbkZIrcW3Ept2038VSMXwuQEBhu5wIqsGW5tWi819pCUiz+2z9zL3PEkOThz2vngXwmaNTrN2 92wC1E65i2TDN6//oXCwh0OjOW28qArRfX0RgpWcUWehtWGazSL8T0M20/7A5DiUP4JYxFhLoC ND2Pk7trd30fRbojQGcDJ0+R Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Aug 2019 00:56:19 -0700 IronPort-SDR: NyAzBNUkbXZSDc3CCgXO4invnzF3pGfNKGTLFadKLNzd3Ur7CPuE7ulisiOMKLtzfBDYC9RyG2 LMaHafEx98U1VaOYEcC0cnvWNpqWA0FB3j4/VMAC1q8O6EemE5bv+FgKtERY0oa9WJzNeyKU+Z g8DVracyX2mKSutvG8FA+QR0bcfzMFM12hYAGW4KAyYhJEzizxfuokO7UPLqF/iodhLhAxJD1Q 5JaglGPag+ntRC2KrnYzUYenP7GCEmKCBCxy07yj4eWOlbfQVNbYp9LH3jeXttyGBwMbWYuITv PYQ= WDCIronportException: Internal Received: from jedi-01.sdcorp.global.sandisk.com (HELO jedi-01.int.fusionio.com) ([10.11.143.218]) by uls-op-cesaip02.wdc.com with ESMTP; 22 Aug 2019 00:58:59 -0700 From: Atish Patra To: linux-kernel@vger.kernel.org Cc: Atish Patra , Albert Ou , linux-riscv@lists.infradead.org, Palmer Dabbelt , Paul Walmsley , Christoph Hellwig , Anup Patel Subject: [PATCH v4 2/3] RISC-V: Issue a local tlbflush if possible. Date: Thu, 22 Aug 2019 00:51:50 -0700 Message-Id: <20190822075151.24838-3-atish.patra@wdc.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190822075151.24838-1-atish.patra@wdc.com> References: <20190822075151.24838-1-atish.patra@wdc.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In RISC-V, tlb flush happens via SBI which is expensive. If the local cpu is the only cpu in cpumask, there is no need to invoke a SBI call. Just do a local flush and return. Signed-off-by: Atish Patra --- arch/riscv/mm/tlbflush.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/arch/riscv/mm/tlbflush.c b/arch/riscv/mm/tlbflush.c index 1293b8017ee0..8172fbf46123 100644 --- a/arch/riscv/mm/tlbflush.c +++ b/arch/riscv/mm/tlbflush.c @@ -2,6 +2,7 @@ #include #include +#include #include void flush_tlb_all(void) @@ -9,16 +10,30 @@ void flush_tlb_all(void) sbi_remote_sfence_vma(NULL, 0, -1); } +/* + * This function must not be called with cmask being null. + * Kernel may panic if cmask is NULL. + */ static void __sbi_tlb_flush_range(struct cpumask *cmask, unsigned long start, unsigned long size) { struct cpumask hmask; + unsigned int cpuid; if (cpumask_empty(cmask)) return; - riscv_cpuid_to_hartid_mask(cmask, &hmask); - sbi_remote_sfence_vma(hmask.bits, start, size); + cpuid = get_cpu(); + + if (cpumask_any_but(cmask, cpuid) >= nr_cpu_ids) { + /* local cpu is the only cpu present in cpumask */ + local_flush_tlb_all(); + } else { + riscv_cpuid_to_hartid_mask(cmask, &hmask); + sbi_remote_sfence_vma(cpumask_bits(&hmask), start, size); + } + + put_cpu(); } void flush_tlb_mm(struct mm_struct *mm) -- 2.21.0