From mboxrd@z Thu Jan 1 00:00:00 1970 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 6634026E706; Wed, 4 Mar 2026 18:55:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772650507; cv=none; b=tSVy72swo7CWx9KnfXGC1v4gsMhjUcoLUQ6zCRVNJHD33/LbjpZMI8mD4o7s4ad1wyOjEj9DOmgf982v3wY5y5oxRzMHRPpEqznxqK0QS5mKVKcs8YgWoPsGykoEj/fWCnJKcbvn/GOrteeHGS7iEBDFUg5Nq6STlzpOo3he03E= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772650507; c=relaxed/simple; bh=+CoFz2M+9c2pM948N4zJ4k6R6xzkN9GVI18Y8Jz++GU=; h=Date:Message-ID:From:To:Cc:Subject:In-Reply-To:References: MIME-Version:Content-Type; b=Qpa5tqhSK+ofnUgUwl2ItTE0imPARIrs5tRT9S5/u+qhs9fmAg4y9Kc1H6eHM+Omr7UekYaMreWht7dWZVV2rL0YzSyDstJqog+ANWl6H54BTDDMEPLhmdVgJtrBT5Bmr3ROavfGr2pv2BdBqCFwB4ovmLMdkomtp7FYFCDMXN4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=MrtTvA8f; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="MrtTvA8f" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3B9DDC4CEF7; Wed, 4 Mar 2026 18:55:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1772650507; bh=+CoFz2M+9c2pM948N4zJ4k6R6xzkN9GVI18Y8Jz++GU=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=MrtTvA8fVlEGm7jd+BRu4fiEpM1dH6JF1nFXXcniv3cdXtwxiqw/L2f/jsagLxsoH Mv2gByqrF1LvsNwOezxnAMIMEre8p7t9QTAf5DUp/0MxBDd0CAu6c5ZC6y7kkPz6kG Uo3OMeL2l8UFOp/R/11hTWCgKf2hnNtO1mLokNFbIUIrS3HWqOQpzCgxPGJn3kpZRx VYXKn8BCVRO8Z9UjAAtJMVjbmxui5S71N5UGpJ7HvrMiJmuWUxw0s8rK5kWhiQUs64 q9zVXdmnHMELCRZuPPOi+/c8MICBNcA1F2sc498CWlaZG5Y6mVDF8ngnWHoT9DwKm8 UB7DwUqhfp8TA== 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 1vxrNA-0000000GBPd-2kmH; Wed, 04 Mar 2026 18:55:04 +0000 Date: Wed, 04 Mar 2026 18:55:04 +0000 Message-ID: <86wlzr77cn.wl-maz@kernel.org> From: Marc Zyngier To: Quentin Perret Cc: Oliver Upton , Joey Gouly , Suzuki K Poulose , Zenghui Yu , Catalin Marinas , Will Deacon , linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org, Leo Yan Subject: Re: [PATCH] KVM: arm64: Adjust range correctly during host stage-2 faults In-Reply-To: <20250625105548.984572-1-qperret@google.com> References: <20250625105548.984572-1-qperret@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: linux-kernel@vger.kernel.org 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: qperret@google.com, oliver.upton@linux.dev, joey.gouly@arm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com, catalin.marinas@arm.com, will@kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org, leo.yan@arm.com X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false On Wed, 25 Jun 2025 11:55:48 +0100, Quentin Perret wrote: > > host_stage2_adjust_range() tries to find the largest block mapping that > fits within a memory or mmio region (represented by a kvm_mem_range in > this function) during host stage-2 faults under pKVM. To do so, it walks > the host stage-2 page-table, finds the faulting PTE and its level, and > then progressively increments the level until it finds a granule of the > appropriate size. However, the condition in the loop implementing the > above is broken as it checks kvm_level_supports_block_mapping() for the > next level instead of the current, so pKVM may attempt to map a region > larger than can be covered with a single block. > > This is not a security problem and is quite rare in practice (the > kvm_mem_range check usually forces host_stage2_adjust_range() to choose a > smaller granule), but this is clearly not the expected behaviour. > > Refactor the loop to fix the bug and improve readability. > > Fixes: c4f0935e4d95 ("KVM: arm64: Optimize host memory aborts") > Signed-off-by: Quentin Perret This patch prevents my O6 board from booting in protected mode as of e728e705802fe. Reverting it on top of 7.0-rc2 make the box work again. I haven't quite worked out why though. The hack below makes it work, but implies that we can get ranges that are smaller than a page. That feels unlikely, but I'm not sure we can rule it out (the kernel page size could be pretty large anyway). Any idea? M. diff --git a/arch/arm64/kvm/hyp/nvhe/mem_protect.c b/arch/arm64/kvm/hyp/nvhe/mem_protect.c index 38f66a56a7665..d815265bd374f 100644 --- a/arch/arm64/kvm/hyp/nvhe/mem_protect.c +++ b/arch/arm64/kvm/hyp/nvhe/mem_protect.c @@ -518,7 +518,7 @@ static int host_stage2_adjust_range(u64 addr, struct kvm_mem_range *range) granule = kvm_granule_size(level); cur.start = ALIGN_DOWN(addr, granule); cur.end = cur.start + granule; - if (!range_included(&cur, range)) + if (!range_included(&cur, range) && level < KVM_PGTABLE_LAST_LEVEL) continue; *range = cur; return 0; -- Without deviation from the norm, progress is not possible.