From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 3E18640B398 for ; Mon, 14 Sep 2026 08:32:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789374771; cv=none; b=qambDTzuVokTMU+zI+ZwOge7yD4rCVdUNtaCuCFle8tvtB5sdOP+zsvmctV0vumuMncBQJKXR9z4Kg9G4Tm3dZlOcHiF1+Q2HZCWNP/ZQtiArkzkewAywmi1BUryt4nxtpbDEuhct5c3b9ah6EJ7mUbILbr3mEFq2gfElU+aoa4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789374771; c=relaxed/simple; bh=ehdCgQhm5eYRTDU59jX+d3Ax2phw5tmcILcwp7ovUhs=; h=Date:Message-ID:From:To:Cc:Subject:In-Reply-To:References: MIME-Version:Content-Type; b=ngVXOSGP9BH0lMxjeB7ukCzHUmRK28VmTcHNxp0A3QxX32OBI29YllFwaxqgYnP+0s0za4Nxa/HXxXZFcvTeQ70qKdtJt9MZruClgUXHUityq1S+MFQnEiBZg5GqAnWrioDR7oONmzo1krwxZ0u/FsbuE5gMdCA3QAzkANnsDOk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=SLxMMun4; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="SLxMMun4" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2298E1F00899; Mon, 14 Sep 2026 08:32:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1789374770; bh=jqLaTSkRrvlodeW0BhtEHuSwEAtIDlnxV5dSZDwqPlU=; h=Date:From:To:Cc:Subject:In-Reply-To:References; b=SLxMMun4FFsCDBpxh6yi7G6KxHMtGA8/TFOrzQBKXn1cVj2W+ypKVcCif6lXFsfWm qJIuteRsX586nEhIRo3f+5MGCidqBu6D7aCgM0K4GHHd5TZHmCvzqF1Iu9Je1kpjBy iiJT/+wsgqq5LFK2jTHHWqgS7Vzcj/S+fBMQwnFJEarsNpc2y+gAIT1VYeexxjUXTF qT1hujV2o22o6NVdyPnrLRKBiX791QN4qBFCyqGd8znuiFNAXlql6MdbA9HROpEd0c kTsha9BH2Kn0R8oML9NACimQjcMHSo2U7fKVogt4VbsVgWiOahx/GgGT4CmY7GHm4Y xYWNL4B96nIWg== Received: from sofa.misterjones.org ([185.219.108.64] helo=goblin-girl.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1x627L-00000008VEv-3cST; Mon, 14 Sep 2026 08:32:47 +0000 Date: Mon, 14 Sep 2026 09:32:47 +0100 Message-ID: <864ifs6xn4.wl-maz@kernel.org> From: Marc Zyngier To: Vincent Donnefort Cc: oupton@kernel.org, kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, joey.gouly@arm.com, seiden@linux.ibm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com, catalin.marinas@arm.com, will@kernel.org, kernel-team@android.com, fuad.tabba@linux.dev, qperret@google.com Subject: Re: [PATCH v2] KVM: arm64: Fix protected VM fault on system with pages larger than 4K In-Reply-To: <20260914075839.4019904-1-vdonnefort@google.com> References: <20260914075839.4019904-1-vdonnefort@google.com> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/30.1 (aarch64-unknown-linux-gnu) MULE/6.0 (HANACHIRUSATO) Precedence: bulk X-Mailing-List: kvmarm@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: vdonnefort@google.com, oupton@kernel.org, kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, joey.gouly@arm.com, seiden@linux.ibm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com, catalin.marinas@arm.com, will@kernel.org, kernel-team@android.com, fuad.tabba@linux.dev, qperret@google.com X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false On Mon, 14 Sep 2026 08:58:39 +0100, Vincent Donnefort wrote: > > Just like commit 08f97454b7fa ("KVM: arm64: Fix protected mode handling > of pages larger than 4kB") fixed the boot of non-protected VMs on system > larger than 4K pages, align the fault IPA down to the page-size for > protected VMs. > > To paraphrase Marc, pkvm_pgtable_stage2_map() assumes the address passed > as a parameter is aligned to the size of the intended mapping, while > HPFAR_EL2 gives the IPA minus the bottom 12 bits, regardless of the > system page size configuration. > > Add a check at the start of pkvm_pgtable_stage2_map() as we do not > support !PAGE_ALIGNED arguments and use the gfn as an argument in all > callers. > > Fixes: ea03466e806f ("KVM: arm64: Handle aborts from protected VMs") > Signed-off-by: Vincent Donnefort > --- > > Changelog: > > v2: > - Use gfn_to_gpa(gfn) > - Drop "phys" from the PAGE_ALIGNED check, it isn't a requirement. > - Fix gmem_abort() as well (Sashiko) > > v1: https://lore.kernel.org/all/20260913173516.3122436-1-vdonnefort@google.com/ > > arch/arm64/kvm/mmu.c | 7 ++++--- > arch/arm64/kvm/pkvm.c | 3 +++ > 2 files changed, 7 insertions(+), 3 deletions(-) > > diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c > index 9ba86450fe4a..ee78201a44df 100644 > --- a/arch/arm64/kvm/mmu.c > +++ b/arch/arm64/kvm/mmu.c > @@ -1672,10 +1672,10 @@ static int gmem_abort(const struct kvm_s2_fault_desc *s2fd) > * PTE, which will be preserved. > */ Context: if (s2fd->nested) gfn = kvm_s2_trans_output(s2fd->nested) >> PAGE_SHIFT; else gfn = s2fd->fault_ipa >> PAGE_SHIFT; [...] > prot &= ~KVM_NV_GUEST_MAP_SZ; > - ret = KVM_PGT_FN(kvm_pgtable_stage2_relax_perms)(pgt, s2fd->fault_ipa, > + ret = KVM_PGT_FN(kvm_pgtable_stage2_relax_perms)(pgt, gfn_to_gpa(gfn), > prot, flags); > } else { > - ret = KVM_PGT_FN(kvm_pgtable_stage2_map)(pgt, s2fd->fault_ipa, PAGE_SIZE, > + ret = KVM_PGT_FN(kvm_pgtable_stage2_map)(pgt, gfn_to_gpa(gfn), PAGE_SIZE, > __pfn_to_phys(pfn), prot, > memcache, flags); So 'gfn' is not related to the faulting IPA in the nested case, but is the output address of the guest's own S2. You probably end-up with a livelock handling the same fault forever, or worse. It is a bit annoying that neither gmem nor pkvm are using kvm_s2_fault_vma_info, which has the ability to reports all the important stuff, as it would avoid this sort of bugs. Thanks, M. -- Without deviation from the norm, progress is not possible.