Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp1373039ybl; Tue, 13 Aug 2019 11:26:08 -0700 (PDT) X-Google-Smtp-Source: APXvYqylOb7PR//tQYTc5Yf08YNaCl/Miu/zw4xEw5H3Tjv05rg7yOzobdBVgxc5jFmFNvFQIbTk X-Received: by 2002:a17:90a:1aab:: with SMTP id p40mr3409198pjp.7.1565720768119; Tue, 13 Aug 2019 11:26:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565720768; cv=none; d=google.com; s=arc-20160816; b=vfnnhzvRqV79rS6xgfj6JP6+IgyBq+e9vAj6bcXnyAAbroILtxT4YCth1Ci8KvT11J JICNZWard/zDRn27s6an8YczxH+ifWxsOVfZyrAm00Ze1LE/VOeZ36MfsTPfB9aJNOz6 jlB443YoAK7ghvTrZxuWJYUbqTQ9uDYcqQc6ZXpkdGTjPn1WExXumcjA/S0ovI/LmAwC Q7OuoGZfPRQWObGXyQw2syh9gWki2i3dWdvxC2T/RV2+c0j6zBHP73hbm+kLA3oaVLKl gPQCJsmUXceqyQJExgYbM4CQa6ZGg/He74dWH2+CZKssjy136qjkyKLrOD3b+dGSxI91 QTnw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :message-id:in-reply-to:subject:cc:to:from:date:dkim-signature; bh=KKbCR1tFCWObTnhlH9C2d2XLJKP2zhB/LK0xe4rn60I=; b=YmOTPqlfPN7avHW+zUFzadn/WcV1Og7MBuSnlUtYgpymbHSUj0XVxbAbKrfKzcSsVF HmGI+sD9phn0F6bXcjGLK7EyC1XEUkM+pyM4hu8krv65FTe352jPXHf6S/oLYzT0QzMo i2BcEUNI29mLpAidJMAZetTTF1G9ZRcutxi55Bu6NTXmkAlA0zanIS+nF8cL7S+aGv4L F/rfEesCCKMis7KBHt5LDyA/nkiBthRZ4Pi5EQFFKy/twKBnM4WfvwZ0pppqIw9YtK3t ljkCxatHt2is1sS7virj+rxfxza4/pB0/kIXSVqmTXDJ1ztXxNwJ0k4k+LRnDv2azVAK LJ4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=FPOXc0Ao; 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 h5si62832144pls.280.2019.08.13.11.25.51; Tue, 13 Aug 2019 11:26:08 -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=FPOXc0Ao; 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 S1728388AbfHMSZS (ORCPT + 99 others); Tue, 13 Aug 2019 14:25:18 -0400 Received: from mail-ot1-f67.google.com ([209.85.210.67]:42627 "EHLO mail-ot1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728169AbfHMSZS (ORCPT ); Tue, 13 Aug 2019 14:25:18 -0400 Received: by mail-ot1-f67.google.com with SMTP id j7so31484140ota.9 for ; Tue, 13 Aug 2019 11:25:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=date:from:to:cc:subject:in-reply-to:message-id:references :user-agent:mime-version; bh=KKbCR1tFCWObTnhlH9C2d2XLJKP2zhB/LK0xe4rn60I=; b=FPOXc0AodraVwoTfynD6VRQNVTH0DcfUBNErnRpVBxdYrVdGm/iCq9GLJQQW36Phh6 t9N7/MXMvJ7hZVt2cZoJ4QCPMLJkZuuwa808avZrvlCKI8oeWovWt2eMewROtONZzSHd 7UzYHmk1Iwq4AXEfBrQW4GENapMDS+D8ZVk4okXLvHdJW0JuEVglqh7KVJdeW2y2VNo2 CKZlp/Nna+R1ORJci9HqYjLSDhoWYaLYu2B7BXzIJFHh9c4wRToke9T5nlavWf5ZfFFL Dvn1lENwZ6jam7bhQD6lenKt0njDiYWAdrrVXpZGJmQTjVIUxs6ick/0lFz1YlJHqTsU M+TQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:in-reply-to:message-id :references:user-agent:mime-version; bh=KKbCR1tFCWObTnhlH9C2d2XLJKP2zhB/LK0xe4rn60I=; b=ikFxGywhDe6uYd79qaAmTR3AAT9V1/dxEY9wr9bXmJxpTPM2D981ifU9S3UBFEnxzP hfiOjiHEkKef99yll9n3nKR24c1NI8HcuKy46HhsnMecECxp+ox5HFbjA8qwgoWLpThm d5pdWTnJsx37uNdaL2YRYZzdBTqNtmks6vDi3ROcJI13XQGpb16E5a8dsWqnh1tyoFmC SDt0MWVMf0HSIEOZIcOYAepA0rg6FpJixjlDJU2cceDqVz9wKk9w3H+3pZQI96cV+X7e bP26ggmcG2Ftsm9bC9uFH1F2jXQZN3tcHBJVTY750bAzAXBqN7DM0uSR/55KppASAajv tSCQ== X-Gm-Message-State: APjAAAX1NssV7ZilMDGFARSKLLh6okpgwwjkXowJbjX0kF/xdRQosCE3 ymNz0+svJLfpZfBpXdRSmEpZLg== X-Received: by 2002:a02:390c:: with SMTP id l12mr32485157jaa.76.1565720717060; Tue, 13 Aug 2019 11:25:17 -0700 (PDT) Received: from localhost (c-73-95-159-87.hsd1.co.comcast.net. [73.95.159.87]) by smtp.gmail.com with ESMTPSA id k7sm18488997iop.88.2019.08.13.11.25.16 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Tue, 13 Aug 2019 11:25:16 -0700 (PDT) Date: Tue, 13 Aug 2019 11:25:15 -0700 (PDT) From: Paul Walmsley X-X-Sender: paulw@viisi.sifive.com To: Atish Patra cc: linux-kernel@vger.kernel.org, Albert Ou , Alexios Zavras , Allison Randal , Greg Kroah-Hartman , linux-riscv@lists.infradead.org, Palmer Dabbelt , Anup Patel Subject: Re: [PATCH] RISC-V: Issue a local tlb flush if possible. In-Reply-To: <20190810014309.20838-1-atish.patra@wdc.com> Message-ID: References: <20190810014309.20838-1-atish.patra@wdc.com> User-Agent: Alpine 2.21.9999 (DEB 301 2018-08-15) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Atish, On Fri, 9 Aug 2019, Atish Patra wrote: > 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. > > Signed-off-by: Atish Patra A few brief comments/questions beyond the ones that others have mentioned: 1. At some point, some RISC-V systems may implement this SBI call in hardware, rather than in software. Then this might wind up becoming a de-optimization. I don't think there's anything to do about that in code right now, but it might be worth adding a comment, and thinking about how that case might be handled in the platform specification group. 2. If this patch masks or reduces the likelihood of hitting the TLB-related crashes that we're seeing, we probably will want to hold off on merging this one until we're relatively certain that those other problems have been fixed. > --- > arch/riscv/include/asm/tlbflush.h | 33 +++++++++++++++++++++++++++---- > 1 file changed, 29 insertions(+), 4 deletions(-) > > 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 > > #include > +#include > #include > > /* > @@ -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 = smp_processor_id(); > > 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 == 0 && size == -1) || (size > PAGE_SIZE)) > + local_flush_tlb_all(); > + else if (size == 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); > + } > } > > -#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) \ > -- > 2.21.0 > > - Paul