From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ed1-f47.google.com (mail-ed1-f47.google.com [209.85.208.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5B9A52FB97D for ; Tue, 21 Jul 2026 08:42:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.47 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784623373; cv=none; b=TL91TxuNd5uoSZz4WSZPyIHP+yvJ5jwMDPmTIg2Gt13CYwwVB89psMWSD00J/tVUr6dHuLwnVc8KPhW2cIm1ktENOKBlqN1rmqXAJ/+bPjHcdw+X3X85B7O8SKLO7V+iR7ZFcHyEPIZtnIvLMOKmVLOMAJu+GIvtLgpPtBSlInk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784623373; c=relaxed/simple; bh=HUIGo3Rn1Vrg89tTohSZukqtXGYTPYfLx2A27acqApw=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=RDVDmO+igmgvST4+bhBU4OAEHu2urRQmC6JqcJRP9MEG50pOdROwHyQRmZjg9x8KwjFBYwqdLw8V5OyrwXMF7PEx3QjH2yvW5ISC5iavkayBvaG1HpalTkk4nuG1gAxiwhT4duPS64qyEgm7IGuWVzu9snNISyovPiI0bEL4iFE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=I7l2+bDw; arc=none smtp.client-ip=209.85.208.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="I7l2+bDw" Received: by mail-ed1-f47.google.com with SMTP id 4fb4d7f45d1cf-698411099d6so41802a12.0 for ; Tue, 21 Jul 2026 01:42:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1784623369; x=1785228169; darn=vger.kernel.org; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to:content-type; bh=OshMXjh7Cgoor6MMiGrVEQRdUgGOjdKbShq5C0Pf5vg=; b=I7l2+bDw3R7FDnkqdRNej2gazaEs/EcN0/ZmV74V2NnNVsjgmZmrJeH17dKWYjWcAe YtqzUtftU2pXbsryZAkeK0suLPIMP95H5il6Agfgqb//QgabefxwbUAItsLR145sGwC2 IDy9+lbKdMafrw1F6Krqri+ihEKX1bsFlEI9Ej/Sg1q2W0IKSBG1KbXXCkeUghyxJPQG ZBKKnZkN8yPh1z8IAIAIaN587clrjOGtXf8TMCVwCAUdS9sIQH1R562tD5thSDi3ArG5 jxh9Hnc/cXKuKuO43fMy6cOBhMf3L8PV5Ww53OpRv2YuPF14b6OhpPB0DDuFWVDTFsd7 Yy7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784623369; x=1785228169; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=OshMXjh7Cgoor6MMiGrVEQRdUgGOjdKbShq5C0Pf5vg=; b=Lapb1G8S7gnuHbXrxaFhub/AxfKfvDz/V6avkB0FjcByqb/9sU7PayfA/eAzz1GieT bAty5hYaKibIic1ekEqcOu6SaKuzFuzHJjftEBaij7y/g60FXncAIDjM/Bj/N0BeDWn4 9v1OMtS7U8vGwxVd2rXL6SsKV4MM6WtvmKtfmNRLpP6S/Ssz/atO2KOOXfo76O/VGFoy Cy2lbLi1LoMjsPSc016fC/xXjIsHpfihm2j4Q0MXA2YMTlpJtcZ4ewCdREqHGeE7zSVD 3zHex6zuHRMn2fAAQFqI3W0UrfCUqybRntK97QD0XrRLWI+DPC+t8z0IA0+8f+kr1F0W hrgQ== X-Gm-Message-State: AOJu0YwA0D1IsQM/zSYS1NRf7G0GtAG7PCnFQfYaQZRWLJ5Hl8n/01iV illh/EvEFdl7kKwEv4VxJ8J1ERJgYF3dS4ok1d5KqRyyhK01yao8UAu+y1X2ffqarw== X-Gm-Gg: AR+sD13qnTXxLQGoKD+j//UyGFeqIUDXOn7Ee8tT3Kmn+8k0AT4c75lqCyBKWQogXHY ZpRbmJwxJPTN8u4O/qMyzHCf6bzBxWTJ+qU7Ku4kvORGAMtGCwJ98tlZ7wd96OyBFM2DN45xZ41 d32wpzCCwY0JsTSvyLt8WrfYa4qSj8E3Ap8Y6WM4xF+TsfJpjuxQPhsJYq+CwpoGCtJ5fAG4lgQ iGif2HN1t+G6JtSlT+S8PTA0PU5slkzzBA1lgR1rxEHYgrEb5JFtskM1bVATwyGcZFYZtV8qwJP mexYIFfeektIoHlscYHhUdcnEq3L6/gsnwVGj41c1wlDbumISRCE4bTBY8/699gk00Wn0U05AS4 dCRKifESLvdSMtOIQumzmCk78pBtR/5z9CVKbRh0bKqpYeIh5WGb/lklyJZjtvxV3Nxa2NYLzDc CaigVueDJj/d1N9OoU4mWJhk2/jrostqAz4g68yLy+J32BY+lj X-Received: by 2002:aa7:dd03:0:b0:69e:98c8:e958 with SMTP id 4fb4d7f45d1cf-69ef509967emr74880a12.7.1784623369037; Tue, 21 Jul 2026 01:42:49 -0700 (PDT) Received: from google.com (220.60.76.34.bc.googleusercontent.com. [34.76.60.220]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-c1705a0a4c2sm566318166b.16.2026.07.21.01.42.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Jul 2026 01:42:45 -0700 (PDT) Date: Tue, 21 Jul 2026 08:42:39 +0000 From: Mostafa Saleh To: Fuad Tabba Cc: linux-kernel@vger.kernel.org, kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, maz@kernel.org, oupton@kernel.org, seiden@linux.ibm.com, joey.gouly@arm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com, catalin.marinas@arm.com, will@kernel.org, vdonnefort@google.com, sebastianene@google.com, keirf@google.com Subject: Re: [PATCH] KVM: arm64: Optimize protected mode and FWB Message-ID: References: <20260720203529.1276355-1-smostafa@google.com> 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=us-ascii Content-Disposition: inline In-Reply-To: On Tue, Jul 21, 2026 at 08:49:26AM +0100, Fuad Tabba wrote: > On Mon, 20 Jul 2026 at 21:35, Mostafa Saleh wrote: > > > > KVM opportunistically enables FWB if supported by the system for guest > > VMs, which allows it to elude cache maintenance for data as they are > > forced to be cacheable from stage-2. > > In that case, __clean_dcache_guest_page() will immediately return. > > However in protected mode, before calling __clean_dcache_guest_page() > > it loops over the range and fix_map/unmap it, issuing TLB > > invalidations, dsb() and isb() unnecessarily. > > > > This can be optimized by returning early if FWB is supported, > > kvm_pgtable_stage2_map() already issues dsb() and tlb invalidation > > functions issue dsb() for the unmap path. > > > > Signed-off-by: Mostafa Saleh > > --- > > arch/arm64/kvm/hyp/nvhe/mem_protect.c | 4 ++++ > > 1 file changed, 4 insertions(+) > > > > diff --git a/arch/arm64/kvm/hyp/nvhe/mem_protect.c b/arch/arm64/kvm/hyp/nvhe/mem_protect.c > > index 4e329e39a695..6e9229106a25 100644 > > --- a/arch/arm64/kvm/hyp/nvhe/mem_protect.c > > +++ b/arch/arm64/kvm/hyp/nvhe/mem_protect.c > > @@ -261,6 +261,10 @@ static void __apply_guest_page(void *va, size_t size, > > > > static void clean_dcache_guest_page(void *va, size_t size) > > { > > + /* See __clean_dcache_guest_page() */ > > This looks good to me. One comment: this file also has > hyp_poison_page(), which deliberately avoids > __clean_dcache_guest_page() because the FWB elision would be wrong > there (it even notes "Prefer kvm_flush_dcache_to_poc() over > __clean_dcache_guest_page()"). Given the two opposite treatments in > the same file, could this comment say why eliding is safe here, e.g. > that the consumer is the guest via the FWB-forced stage-2? It would > save the next reader (if they're anything like me) from reconciling > the two. __clean_dcache_guest_page() already have this comment. /* * With FWB, we ensure that the guest always accesses memory using * cacheable attributes, and we don't have to clean to PoC when * faulting in pages. Furthermore, FWB implies IDC, so cleaning to * PoU is not required either in this case. */ I will add comment to clarify guest vs host: /* * Guest stage-2 uses FWB if it exists, in that case it is * safe to elide CMOs. * Unlike the host stage-2 which never have FWB enabled. */ Thanks, Mostafa > > That fuller comment could also replace "See > __clean_dcache_guest_page()", which mostly just points back at the > function passed in the __apply_guest_page() call below. > > With that fixed: > > Reviewed-by: Fuad Tabba > > Cheers, > /fuad > > > + if (cpus_have_final_cap(ARM64_HAS_STAGE2_FWB)) > > + return; > > + > > __apply_guest_page(va, size, __clean_dcache_guest_page); > > } > > > > -- > > 2.55.0.229.g6434b31f56-goog > >