Received: by 2002:a05:7412:8d11:b0:fa:4934:9f with SMTP id bj17csp428460rdb; Mon, 15 Jan 2024 01:41:00 -0800 (PST) X-Google-Smtp-Source: AGHT+IGaMRVBTUP+QLpj1tEDvPz3AfFNU8/BNmIBm5wq2pq/yJgrLIWwTi+A0ies8LQUu81hv/Rv X-Received: by 2002:a05:6870:6494:b0:207:33d2:545b with SMTP id cz20-20020a056870649400b0020733d2545bmr4477378oab.69.1705311660335; Mon, 15 Jan 2024 01:41:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1705311660; cv=none; d=google.com; s=arc-20160816; b=ljt3cP3KUD12iakBPs9OyYngKT+BLxD2csEDzR8ZY6nFBp7idShmm8/8n+1eIrycL/ jlclK0y/m0IzTS+8H9CCXDKX9QQBMDZ7wF8o0hEtScZNBqqE8zzkkqxyTb5oTmgMUtih yoAlRJD+x/VSM7q8FJFOqNu6jedohudBTGKZ9ecVybd9LGH7kTToci64HAca8p2ulegC SE/PIX306GO883FanYcUovoHzUdPOXuobct8MZnN7OMNehMzJxpC5eYFPTSwJ40TntoX /V5zR2FGwLCm64f78kAcMFez4navvO7KtA/0AB+2bryzvC5qxjx//7GB8nTXBh0cbMMN 5Rrw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=eSFV9+sWBfpBCo1xOJ35XW/DcFffFNL5hItvxdhZkOI=; fh=s0JuvGR8sIORLMTojfr1olil9jJAPkTH2AGionA2bGc=; b=JnK82+yyuwjpAs8M7/KwivmD1rOAxgNYN+ePogWZn3h3elE5gVjjCSnCRaePa/bC8S a9Lj34GGHk/SfxWnZVA9p4DCxODXIp40Y11RFicSDUrYPB5OVy4/jRocLZRJpQt9fuxk SXO+2UnCJrfmOrR5jRdX1MvmYnFNh8kOp93Kw5P4O2al/xOA+YNiDtAUgfv4BHJMOdtl sz1SlqxuFwZSCbHM19wsfGp0y/1xh+Rd26EWWlO9acIctp5I8cg4nN87SyFDRO1BJYwS dSnPttP57/+RoW9c6QhdW3Rr+SY6HiSygkoFkyDBwEpXc4oskkuvPoBtsY0RiRGQ/MWF duqA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="uRE/BSnY"; spf=pass (google.com: domain of linux-kernel+bounces-25812-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-25812-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id e1-20020a63e001000000b005b7160263f2si8165145pgh.154.2024.01.15.01.40.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Jan 2024 01:41:00 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-25812-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="uRE/BSnY"; spf=pass (google.com: domain of linux-kernel+bounces-25812-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-25812-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=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 sy.mirrors.kernel.org (Postfix) with ESMTPS id C25ABB20FAD for ; Mon, 15 Jan 2024 09:40:58 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 68B1EF4FA; Mon, 15 Jan 2024 09:40:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="uRE/BSnY" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 9A099F4E7 for ; Mon, 15 Jan 2024 09:40:51 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5820FC433C7; Mon, 15 Jan 2024 09:40:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1705311651; bh=+F7K07Y5fx0dIdwadJy3MnmnbVE+eGFHi4fQFk5p/hs=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=uRE/BSnY7551SxKY3LorlQ3CfD5bzcEiVuBHEQkOhH1W0kKzpggvZZHxYdTWOHz5N 2Egz++9BrZVhXk2fgU+TD8v194sEvcx/z1WKinPt8ERZ16jAFXV4SFTSmNV8XVLYgT COpOPNP7O83+ofyZ4WOzcR/GsyfiTSGmeHXnFo4vLl5c/S+O4VCaq15ennUve1Y7WO 8/B25fs4qFB1KfMCd9kbm4eMCJ3L5gKT9RpWNuX9SuWevSRm/+o2BcwV/LQzHD3wY6 B8f+HYpfMOvWp+/qfazl8ywHuYtC1cua3EqhAr+M6WRtsrSTpVKOM07krn70BPIYug Qqvmrl23RT55Q== Date: Mon, 15 Jan 2024 17:27:59 +0800 From: Jisheng Zhang To: Yangyu Chen Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , Conor Dooley , Andrew Waterman Subject: Re: [PATCH] RISC-V: only flush icache when it has VM_EXEC set Message-ID: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: 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 > --- > 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 >