Message ID | tencent_6D851035F6F2FD0B5A69FB391AE39AC6300A@qq.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-21275-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2411:b0:101:2151:f287 with SMTP id m17csp314277dyi; Tue, 9 Jan 2024 10:50:49 -0800 (PST) X-Google-Smtp-Source: AGHT+IH/pvJNL4XGpHv7A6yoTh2bzI6kYLBss7k1FEDIUvxq1dXhTPgGpjTjHE56Fn/uHeo3hRMN X-Received: by 2002:a05:651c:1a2b:b0:2cc:eb79:b82c with SMTP id by43-20020a05651c1a2b00b002cceb79b82cmr3040856ljb.54.1704826248974; Tue, 09 Jan 2024 10:50:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704826248; cv=none; d=google.com; s=arc-20160816; b=ChyblJXFjg5EAnMNtmSfi4LHwT5nNDav/EeY1oi98pmnb/m53ySahgDZ3JIBD3EQDB N9X0zln+2z8Oc2EKoDtP7D2UiWzYYuroceCVOEmCUzdj6RDq4Wb9HOFHgWQT4Qm9fZk/ RjO5GLqUD3JIV7LkZbnCIoZfss3/egWhyNStprCUS3rwBcbg91M+Zs5gMAHQg0if/sqF cf1dUy/CLuyETAw4CowSYylIine+umcgJpHw+rVtYQGM/v+LBqMmDdBzfdeRmcNfO/9y npD9s6Ds9XNFHQQ3oBURUO3IKhBVEiYDAH/ogF/Av85g1gHm1L3I1ZTnRHnZwG61vcIN OYKA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:subject:cc:to:from :message-id:dkim-signature; bh=DmGo0slP1Ax+f+6LBWpdzqWeIFagteLk84bt6YYhxSo=; fh=0S+WbBptg+cY3L2akbNbaB7In7/noxQMtFO+gZlK3b4=; b=NFPTiHCAsJX5mcURQLM10hHV4lC2V4YBSCm6IsAYkPtvS7rX2cTcEEzQcDtMD20N7t lxDH6f/ThpI2Txd4Ime0hNsS/dbdrQ8mqchzsaGwP8uQ8YC0aHGQInVvrv8/p+j/g9W8 8+q+hMgAu1MUUk/0lYFaGsoSDS7yswSyospujJqAC3GGEXC2lK/GuiYfmzgKBm0kxy+p CYQMg3jZqyWH/LDzfJUlPExVfmmgdIMgTFXRfhu2wci4Fi2Gz61hykWid/pJrBXYJBHK qbZ7t6CPxl548noyRUrHVfYGnSqC5h8CakrtuE6lybs/9rfBALLzhgQRr0hwrv0VWGJ1 1rkA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@qq.com header.s=s201512 header.b=Pv3kSkEQ; spf=pass (google.com: domain of linux-kernel+bounces-21275-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-21275-ouuuleilei=gmail.com@vger.kernel.org" Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id y6-20020a056402358600b00557139d8f3asi973059edc.361.2024.01.09.10.50.48 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Jan 2024 10:50:48 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-21275-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@qq.com header.s=s201512 header.b=Pv3kSkEQ; spf=pass (google.com: domain of linux-kernel+bounces-21275-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-21275-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 909CA1F2630D for <ouuuleilei@gmail.com>; Tue, 9 Jan 2024 18:50:48 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 604FE3D0B9; Tue, 9 Jan 2024 18:50:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=qq.com header.i=@qq.com header.b="Pv3kSkEQ" Received: from out203-205-221-202.mail.qq.com (out203-205-221-202.mail.qq.com [203.205.221.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7C20C3C482 for <linux-kernel@vger.kernel.org>; Tue, 9 Jan 2024 18:50:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=cyyself.name Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=cyyself.name DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qq.com; s=s201512; t=1704826207; bh=DmGo0slP1Ax+f+6LBWpdzqWeIFagteLk84bt6YYhxSo=; h=From:To:Cc:Subject:Date; b=Pv3kSkEQeCoe/kbuOwwDLcE41Dri9PZGznv+HZJFaLmTep0IhJgqbNy14+/CEk2sY B55M3XBASH0UxdDapwauyn/cafUqFeVgzbVoaMFmEvB2wW3qZruENj8mqevEDlP/V2 i5btftN7KqbRPJ0sJw/EvH/bnGB3qvtAjBSFy6ZI= Received: from cyy-pc.lan ([218.70.255.58]) by newxmesmtplogicsvrsza7-0.qq.com (NewEsmtp) with SMTP id C803E83D; Wed, 10 Jan 2024 02:50:00 +0800 X-QQ-mid: xmsmtpt1704826200t8xep9519 Message-ID: <tencent_6D851035F6F2FD0B5A69FB391AE39AC6300A@qq.com> X-QQ-XMAILINFO: OZZSS56D9fAjwbIh/j+boLSJHX0auiYjrweTADFbG4MJ95HYOrcj5mqN5Gsl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: linux-kernel@vger.kernel.org, Paul Walmsley <paul.walmsley@sifive.com>, Palmer Dabbelt <palmer@dabbelt.com>, Albert Ou <aou@eecs.berkeley.edu>, Alexandre Ghiti <alexghiti@rivosinc.com>, Conor Dooley <conor.dooley@microchip.com>, Jisheng Zhang <jszhang@kernel.org>, Andrew Waterman <andrew@sifive.com>, Yangyu Chen <cyy@cyyself.name> Subject: [PATCH] RISC-V: only flush icache when it has VM_EXEC set Date: Wed, 10 Jan 2024 02:48:59 +0800 X-OQ-MSGID: <20240109184859.379050-1-cyy@cyyself.name> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1787639889043164104 X-GMAIL-MSGID: 1787639889043164104 |
Series |
RISC-V: only flush icache when it has VM_EXEC set
|
|
Commit Message
Yangyu Chen
Jan. 9, 2024, 6:48 p.m. UTC
As I-Cache flush on current RISC-V needs to send IPIs to every CPU cores
in the system is very costly, limiting flush_icache_mm to be called only
when vma->vm_flags has VM_EXEC can help minimize the frequency of these
operations. It improves performance and reduces disturbances when
copy_from_user_page is needed such as profiling with perf.
For I-D coherence concerns, it will not fail if such a page adds VM_EXEC
flags in the future since we have checked it in the __set_pte_at function.
Signed-off-by: Yangyu Chen <cyy@cyyself.name>
---
arch/riscv/include/asm/cacheflush.h | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
Comments
Hi Yangyu, On 09/01/2024 19:48, Yangyu Chen wrote: > As I-Cache flush on current RISC-V needs to send IPIs to every CPU cores > in the system is very costly, limiting flush_icache_mm to be called only > when vma->vm_flags has VM_EXEC can help minimize the frequency of these > operations. It improves performance and reduces disturbances when Which platform did you test this patchset? Do you have any measurement of the performance improvements? > copy_from_user_page is needed such as profiling with perf. > > For I-D coherence concerns, it will not fail if such a page adds VM_EXEC > flags in the future since we have checked it in the __set_pte_at function. > > Signed-off-by: Yangyu Chen <cyy@cyyself.name> > --- > arch/riscv/include/asm/cacheflush.h | 7 +++++-- > 1 file changed, 5 insertions(+), 2 deletions(-) > > diff --git a/arch/riscv/include/asm/cacheflush.h b/arch/riscv/include/asm/cacheflush.h > index 3cb53c4df27c..915f532dc336 100644 > --- a/arch/riscv/include/asm/cacheflush.h > +++ b/arch/riscv/include/asm/cacheflush.h > @@ -33,8 +33,11 @@ static inline void flush_dcache_page(struct page *page) > * so instead we just flush the whole thing. > */ > #define flush_icache_range(start, end) flush_icache_all() > -#define flush_icache_user_page(vma, pg, addr, len) \ > - flush_icache_mm(vma->vm_mm, 0) > +#define flush_icache_user_page(vma, pg, addr, len) \ > +do { \ > + if (vma->vm_flags & VM_EXEC) \ > + flush_icache_mm(vma->vm_mm, 0); \ > +} while (0) > > #ifdef CONFIG_64BIT > #define flush_cache_vmap(start, end) flush_tlb_kernel_range(start, end) Otherwise, it looks good to me, so you can add: Reviewed-by: Alexandre Ghiti <alexghiti@rivosinc.com> Thanks, Alex
On Wed, Jan 10, 2024 at 02:48:59AM +0800, Yangyu Chen wrote: > As I-Cache flush on current RISC-V needs to send IPIs to every CPU cores > in the system is very costly, limiting flush_icache_mm to be called only > when vma->vm_flags has VM_EXEC can help minimize the frequency of these > operations. It improves performance and reduces disturbances when > copy_from_user_page is needed such as profiling with perf. Hi Yangyu, Since this is for "performance", can you please add the benchmark, test platform and performance numbers in your commit msg? thanks > > For I-D coherence concerns, it will not fail if such a page adds VM_EXEC > flags in the future since we have checked it in the __set_pte_at function. > > Signed-off-by: Yangyu Chen <cyy@cyyself.name> > --- > arch/riscv/include/asm/cacheflush.h | 7 +++++-- > 1 file changed, 5 insertions(+), 2 deletions(-) > > diff --git a/arch/riscv/include/asm/cacheflush.h b/arch/riscv/include/asm/cacheflush.h > index 3cb53c4df27c..915f532dc336 100644 > --- a/arch/riscv/include/asm/cacheflush.h > +++ b/arch/riscv/include/asm/cacheflush.h > @@ -33,8 +33,11 @@ static inline void flush_dcache_page(struct page *page) > * so instead we just flush the whole thing. > */ > #define flush_icache_range(start, end) flush_icache_all() > -#define flush_icache_user_page(vma, pg, addr, len) \ > - flush_icache_mm(vma->vm_mm, 0) > +#define flush_icache_user_page(vma, pg, addr, len) \ > +do { \ > + if (vma->vm_flags & VM_EXEC) \ > + flush_icache_mm(vma->vm_mm, 0); \ > +} while (0) > > #ifdef CONFIG_64BIT > #define flush_cache_vmap(start, end) flush_tlb_kernel_range(start, end) > -- > 2.43.0 >
diff --git a/arch/riscv/include/asm/cacheflush.h b/arch/riscv/include/asm/cacheflush.h index 3cb53c4df27c..915f532dc336 100644 --- a/arch/riscv/include/asm/cacheflush.h +++ b/arch/riscv/include/asm/cacheflush.h @@ -33,8 +33,11 @@ static inline void flush_dcache_page(struct page *page) * so instead we just flush the whole thing. */ #define flush_icache_range(start, end) flush_icache_all() -#define flush_icache_user_page(vma, pg, addr, len) \ - flush_icache_mm(vma->vm_mm, 0) +#define flush_icache_user_page(vma, pg, addr, len) \ +do { \ + if (vma->vm_flags & VM_EXEC) \ + flush_icache_mm(vma->vm_mm, 0); \ +} while (0) #ifdef CONFIG_64BIT #define flush_cache_vmap(start, end) flush_tlb_kernel_range(start, end)