Received: by 2002:a05:7412:e794:b0:fa:551:50a7 with SMTP id o20csp516002rdd; Tue, 9 Jan 2024 10:50:40 -0800 (PST) X-Google-Smtp-Source: AGHT+IHP+s1OsvMwgf2mLoTFo3ZCrszyA1cBqCRaiFcxHGSLpEv8KWyUkIKpMwW6aBuq2Ath7qAR X-Received: by 2002:a17:907:969e:b0:a28:c89b:6f68 with SMTP id hd30-20020a170907969e00b00a28c89b6f68mr767977ejc.125.1704826240358; Tue, 09 Jan 2024 10:50:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704826240; cv=none; d=google.com; s=arc-20160816; b=CzC+YY6bR8kDOlpTNRA1vxfCq2czJABjlRZfPwbFmVmnsSSzFZwJMf11htSwSzcXFk iyj2jwV4uC2oTbaiNv1picujUbo3mmX/LllnYvy9VbIR4tRE5PSTYQK6STS6PuDbVys4 hiqPeTrzlStLVllUADJSzd0keaYPTlF6hbH3SvlyN8u10gMZAINLinz1MUBDAlN8R9zw 9eqzJVaatgPqrc7CpKXtngQGiqmJ8mnFhL3/9n3z0/mhrcRHILBfY4MK22BI12kadmdg ZSWo3CRtgLGwIOlJAkvH9MFggBJryh33MUhRtePRUK14NXlVmxBaZy+lhxKOEp3o8msD YGEw== 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-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-21275-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id h23-20020a170906719700b00a28ef4b9d26si995945ejk.721.2024.01.09.10.50.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Jan 2024 10:50:40 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-21275-linux.lists.archive=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-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-21275-linux.lists.archive=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 155F41F2685B for ; Tue, 9 Jan 2024 18:50:40 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7C3003C6A6; Tue, 9 Jan 2024 18:50:31 +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 ; 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: X-QQ-XMAILINFO: OZZSS56D9fAjwbIh/j+boLSJHX0auiYjrweTADFbG4MJ95HYOrcj5mqN5GslSk gur438jdm2YbxWUFSONaraHqL/MaWpfDIWZuc8uzkHLeOjY5S+OwSlAlVJPOnKDQhPzgFqbEYYu6 WC1XzwINxKL0fGO1huOKjvNV9SJMgyyzzmbTGsvYhqi4UT00fNw6YI5lMDP0L2pWsFz+ir5PPFBl NtXjpodLTGipJkpi7kGWufV/XQ+e3HhWeDq4TwOkEHi7fuouDx4WApcFVVO2FG9w7yPo5LeKRZRy fI1V/siWgnTj0nDO+fxYksksU6Mv0AdHK8F9Hhihe6NkHcrNDKnUfkpX1l2lYjupn1xXWgKuHFHR 0fBadkJoPP85v/n2ha588yKqIly+6+9B2qCFvwQxqwaoQKNoZQy1VzyUrqlRReAZTDPqFw6abMjB HC6xogbgGlnuHYnNioCYESuem3yQzmRd9EWmcjx8NmWcBqSNW1DqXQrsTKMmOOYcrTFHq9ZUM76H D2HZACHyM8k6Z1xIzXYDAI8M4u6YFVd3TVVPDDQC9WXW7bkDiXdqDAgwE2t2ncYZ7S3IU/IzVAgx oL3CNFWOrtVoRt1guvlKqyvfEedvydfvLW1BCceFB4vu1kROuJ/2DAjX5RbZRtftbeOWlbxgJ7GS PsozfzUN9ICbAHq7Jor5ej0PAb/oE2urUL+dqYEV1Cf8FRkeI5ICzgXt8n5DuQml7B0J3t6i2HFB lTR+VjG/bAZISOJNbTKHxTeA3u8jEVgiY+TsIaG6yKrawmsCcWg1kYuU1PZVh2YTnK8C40D0s3xL JHoxQjcl24d8eT8bPebaFqX0uSRQZM7ETOlMqQ7V43NiWWicN7k3J9AjF9bEUSQHiFSVZ+sBTKL/ chv0IM6P0Egm04RrIIIG1cFJXvghlGmRGP7web+cfzx3B09sbOLSySdmUkuD2k9Wh/oUiCfFEUsr Y1v2LJ0NSy+wdKEP01LD/AX3iKTDkmAXDAkp11mTaYNM7OmSOJ31oRab19Yp6XoAlT8v9NRQk= X-QQ-XMRINFO: NS+P29fieYNw95Bth2bWPxk= From: Yangyu Chen To: linux-riscv@lists.infradead.org Cc: linux-kernel@vger.kernel.org, Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , Conor Dooley , Jisheng Zhang , Andrew Waterman , Yangyu Chen 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: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 --- 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