Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp1703175lqp; Sat, 23 Mar 2024 05:40:01 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVR61wEcYozKlN5eQI73sfCBxA0J/BH4+J0HzCz4nKvhF0um4amh8w3jxqLYu2z92EGIaNLkPsRmO03/Zp5nVx1PyBcGtGXiRFDGWmBzw== X-Google-Smtp-Source: AGHT+IFvTToA2k9OImpl+d7hnljHFGHWdZtWFr4LfOytK6+KIgbfelkZL3DACMLNr2Qnrgzkday7 X-Received: by 2002:a54:4407:0:b0:3c3:570f:1852 with SMTP id k7-20020a544407000000b003c3570f1852mr2305538oiw.31.1711197601499; Sat, 23 Mar 2024 05:40:01 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711197601; cv=pass; d=google.com; s=arc-20160816; b=Nken4p+oprSW+3FwOD75iWXqkjFV9zAKLL950S/Q9iyxOW1wEj3gPUYuX/DV4LvC9s cg1MfO2NbMpM4FAPaf5if6c1TVLfEo8ZEDMe5HTtM4i1AoYtS5f9pxM8RmLB7m+o4dON O7vym/nh1mnTx16CuwOJujmvifmf7KwqcqN50NfUIbPj5wSrozWdViMN/xm6QFjUAxIT SDynslYb8A4rThyFppgp/ZwyP5kv77OUMm7DcO5Wl0+vhK/S2iJMxU+2GcZRAeeP8zOF TIzzKrGH3uu3tsDMtZK3HptBal8j1EMe4dH2Mn4g4LMehoqlOkouB5jW/ke8BSU4PRuP I3ZA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=to:references:content-transfer-encoding:cc:date:in-reply-to:from :subject:mime-version:list-unsubscribe:list-subscribe:list-id :precedence:message-id:dkim-signature; bh=4QAwHmLtmam4GpY5M1geCT/OMSnNUTDPePbkUBJaklk=; fh=zzQmSMen5cgqL7d19WFuUZxSh4iiKEddox75fXgAcQI=; b=ErJBJUg0gni0aNawOZRDa8q+QtYlld/4/cZdD1QPTXYBeWUQzl57hHoQfvY46eeusR O63T+/OEK+ZsZjiogai/KowLRPjlsJL33y/Pafx0yqsZI8SxWf/RlpFQvc2M8vteMf8+ uvGseGIxEriuEZyZog0moW6zxs3bD1IfrNADZnKEL/AishJfXz+7H0ttXtVSU46mh3FC JYoDEdBCh/nMVoSKiRDtxKXG+PeCRDMTcgZ85EeErA7DpitI5OhUTr71F1ZPm5fIPWge DciS/7BNfBdw/EPdRWvTcPBC0Sg8oka9E/0enD2/0CDZiJy5H2j0eMCIWDwlKnrkeEGl A5+Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@qq.com header.s=s201512 header.b=NLoMF8en; arc=pass (i=1 dkim=pass dkdomain=qq.com); spf=pass (google.com: domain of linux-kernel+bounces-112346-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-112346-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id g7-20020ac85807000000b004314946de69si196766qtg.311.2024.03.23.05.40.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Mar 2024 05:40:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-112346-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@qq.com header.s=s201512 header.b=NLoMF8en; arc=pass (i=1 dkim=pass dkdomain=qq.com); spf=pass (google.com: domain of linux-kernel+bounces-112346-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-112346-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 0E5291C21FD7 for ; Sat, 23 Mar 2024 12:40:01 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C3011282FB; Sat, 23 Mar 2024 12:39:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=qq.com header.i=@qq.com header.b="NLoMF8en" Received: from out203-205-221-205.mail.qq.com (out203-205-221-205.mail.qq.com [203.205.221.205]) (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 4A0BACA6F for ; Sat, 23 Mar 2024 12:39:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=203.205.221.205 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711197594; cv=none; b=SS2Abh4ZHIiO7sUmaeeXSXlAhRriHu/NF+8E//N2ba4BoDaB6tTorDCtwNtgsteAPbHMcz91toDti7rm08RLdTite41WznteY7Ym5xcOBsxQt8c2hRqKEhtSL7A5rF1A7cHmb6r+XefGc01OEabr/GX/0OyGOkfQrlcCz/Ow17g= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711197594; c=relaxed/simple; bh=B/jAiF8VY/uocK1kJECN3SXXqitfg+zAL5Z6/SRJl6M=; h=Message-ID:Content-Type:Mime-Version:Subject:From:In-Reply-To: Date:Cc:References:To; b=ey1Urwex0oHdvS4dUn/FC+G0JwN5IR2f83RlrJVVX/PCyq2X/FjyzxZ/BhTsH3Qu3jhTyf/SLMErayV2a4hV118kZW+r/lhQLR0F9NiEcY9TIWcmV0U5F+LeCpU4O3f0A9LA7Bhfc3h1B7Q8kiSrSmdjS1jCxcC0LqWk0XBkvmY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=cyyself.name; spf=none smtp.mailfrom=cyyself.name; dkim=pass (1024-bit key) header.d=qq.com header.i=@qq.com header.b=NLoMF8en; arc=none smtp.client-ip=203.205.221.205 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=1711197574; bh=4QAwHmLtmam4GpY5M1geCT/OMSnNUTDPePbkUBJaklk=; h=Subject:From:In-Reply-To:Date:Cc:References:To; b=NLoMF8enAFqjf01d9SzHNv95eYOAeFqS1KQdyQtg0GMBraKHXb+njaAlQpRiUbpfD vfmJIu7A3Qj+w79CGPfuA3keWQu0qVcmZtEhYgyQur1OKG72PT71kKwye35BDK87ok dUauFiYGI9BslO/mZsVK0rxOiw1VfMuzVl1tyPXw= Received: from smtpclient.apple ([240e:467:1bf4:3ea0:e479:c9a1:95aa:d444]) by newxmesmtplogicsvrszb6-0.qq.com (NewEsmtp) with SMTP id 9DF97C22; Sat, 23 Mar 2024 20:39:31 +0800 X-QQ-mid: xmsmtpt1711197571txj3ebjsu Message-ID: X-QQ-XMAILINFO: OKkKo7I1HxIeYsRDFAmm8SNn+E/R6zSHEkIhqlCo7BV7aYryBV9V/zL/PjuuAn bMxFX/trQWhKgEj09W+dtZ1fd18tQ+GxX3HIelQ0JcpLprrp+9Uc0Lzhl8IjRAd7XkqybMlZsNQ6 dt9narQlT+bv/0SNmYPB7Z/fYdkhfFduFYNNFK4q2QfNUHsBqwOOudP/dv5q88CBB+pYNYRyE85L EKwVgBb7eVs7hKcINbKjBT+tuo1VwqVfqagn/TQPnfsftrFbDS26RvXTPHKSHQ7VucwBRxxOTVwE 0en2jWtCJpC/mdqpB7GrDchr3+ciE+mePG4X0gnucNkdsg7sTYZjTt3W9QwASA6xbxWM+0Wnkvsm zDLnrEHOxzuE07UxhzgZHneNLkVBupp5UGIPJVwaSbE7UOtSvbd8qM5BnmtTsWEC0NwC2jsPbL5k NmOnLTyRRS/UzCKUGZh7z78Nps2Vx3mv2RJ4IOlahiR6kOHgWeExyJV8Y7mizHTfbi3LHVgaGDn2 mPFWY6XNvEEsAyMO5wtG9NioCEBUGzqksDob78qlcGwALJt2dKZRniTfCCrI6M2Qpw5Re/oeUbu8 0xMe1Nzva56/UDyZuO+Relk76LRrUd5j9xIalJfTN2VAh1NalaJHwV8G8s5cIjQ/v+LHYIWZOEHC fiVPsdzEBdqKd5NuW7+W7HFsKRL3sL3ys9AHph4eoFY7XNYqPssqrg0mRhsK91ZLkVNUz1cQOyqo EU6oEXNLpyAGIo77ZM5i4RT8Chzg8CAvAZYLTOY9J0ugSGiEYyd26gevbBSxBqOqw9kdNI8VKqRA CzBENb1ujJ+ek020HeycQ1x/5I3MCju+p7xTopK4l9xPE4gQQib2FK4hfFmBKgIISqvFI4fLx/n/ Djko4NBNLy4KpGBGku7nvJLA6gtmVMTsuwRVXuvKkLrdSBiUmMUIzRukNiqx6jSCV3YNZasO9eIt oPUcvySbILJJ9xkZ1G3Jc6YN7ApAnr2+zd7FQ8+rE05Gy9fj035Mii+UOB+54YvenmFjIKfX2jNX ovOrm2Ug== X-QQ-XMRINFO: Mp0Kj//9VHAxr69bL5MkOOs= Content-Type: text/plain; charset=utf-8 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3774.500.171.1.1\)) Subject: Re: [PATCH] RISC-V: only flush icache when it has VM_EXEC set From: Yangyu Chen In-Reply-To: Date: Sat, 23 Mar 2024 20:39:21 +0800 Cc: Palmer Dabbelt , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Paul Walmsley , Albert Ou , Conor Dooley , jszhang@kernel.org, Andrew Waterman Content-Transfer-Encoding: quoted-printable X-OQ-MSGID: <29CFE66B-53EA-4AB7-94C5-840583BC9002@cyyself.name> References: To: Alexandre Ghiti X-Mailer: Apple Mail (2.3774.500.171.1.1) > On Mar 22, 2024, at 23:50, Alexandre Ghiti = wrote: >=20 > On Wed, Mar 20, 2024 at 1:48=E2=80=AFAM Palmer Dabbelt = wrote: >>=20 >> On Tue, 09 Jan 2024 10:48:59 PST (-0800), cyy@cyyself.name 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. >>>=20 >>> 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. >>>=20 >>> Signed-off-by: Yangyu Chen >>> --- >>> arch/riscv/include/asm/cacheflush.h | 7 +++++-- >>> 1 file changed, 5 insertions(+), 2 deletions(-) >>>=20 >>> 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) >>>=20 >>> #ifdef CONFIG_64BIT >>> #define flush_cache_vmap(start, end) flush_tlb_kernel_range(start, = end) >>=20 >> I'm not super worried about the benchmarks, I think we can just >> open-loop assume this is faster by avoiding the flushes. I do think = we >> need a hook into at least tlb_update_vma_flags(), though, to insert = the >> fence.i when upgrading a mapping to include VM_EXEC. >=20 > I'd say Yangyu is right when he mentions in the commit log: "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.". > If a region indeed becomes executable, the page table will be modified > to reflect that and then will pass in __set_pte_at() which, as Yangyu > mentions, does the right thing. Or am I missing something? >=20 I think so. Unless we have any other way to update PTE rather than using __set_pte_at, I think it=E2=80=99s safe. I=E2=80=99m too busy = these days to provide a micro enough benchmark. Thanks, Yangyu Chen