From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.51 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796242605; b=AGP9VBFTtFfegXXoSs+OZbQRK5cLsv+MHt30HC6D0E5REIOkjmoQM0lctU6MRv7B3nYB 7AqyqZvSOrxVlPjYXVAZvB6QMplcXuZQcb3hE+QNj/tQkUZGJcPNJOwqKhmrHj28oxaoz P1i0Nn3uE+L81V3YaVmDoqttJHl485rkJv8fwGt6E/vhSYFTLB7AHIAWONpTTfqtUAcj6 n4f+aTC86Aoz+OYnTgYAX7JpslbtI/K0VDAmOrFdPcppvErmzrulhC7+v0OFrcoYnd8/9 YUl6ql4nRS/9qUVY04Nj7UHJcISNniNsTOeAQC5nSlNPEVkYoCDZfTxyG2BpC9m5RTA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796242605; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; bh=hyaLhioGSBuv7s9pB9iat3LppU8lx8aYn/SBsMDpK48=; b=RK1Cm3Lj7oIFaYKdrYRSlPKCEETY/xawGz4yygDuH7l0fMIUV5hVm1h3Cu9EpPPKkax6 0Jq91a9sxTMMdhnNDUJrz2tMuFhJvIAHAf4zjwRi43EHjZKL+QA/fNHkpPDZ/f+UiSPP4 BhB+qt8o4HlLQ2O3yeZ9vVtetQl+Xu+fsYG7VJ3WHJsZy8FuqGLo0orTlQa4GQhaNJ98K zzC171x+B8c5/r/xPlSh3A8v2k8PyoB/20VbjZvQw0TRPzFFd3b4IJ0EKTBXLuiRccgHb XsTjrJWjyuy/nmU1roNP2re9lUF816KOHYv/FwSEz5RdICNbMtcAA6t9UbkRWzGGsJw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=L3AGhBdH; arc=none smtp.remote-ip=209.85.128.51 Received: from mail-wm1-f51.google.com (mail-wm1-f51.google.com [209.85.128.51]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 93122606A330 for ; Wed, 2 Dec 2026 20:16:44 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 93122606A330 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.a=rsa-sha256 header.s=20260707 header.b=L3AGhBdH Received: by mail-wm1-f51.google.com with SMTP id 5b1f17b1804b1-4bb70074ab2so141792955e9.0 for ; Wed, 02 Dec 2026 12:16:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1796242603; x=1796847403; 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=hyaLhioGSBuv7s9pB9iat3LppU8lx8aYn/SBsMDpK48=; b=L3AGhBdHHr8McDkDJwp6rppHP4JkuSVXWBtkVjJnqqLkYpnugE5n4UPI5XuPErTf3L 9bIK+V75D3yqoUwrZcMK0/6pUbzPUM7WRKFe3TkNgepgM8ht738o9JPC+fv5S0A4pdSc oKSqOj4pNkbydVrNuqhJapnYQuaXvaczRh7qmgLD/yWAbnUVXNUXlO9kN53G0D42rv+t jLVEtc9iQ0rAoYd+lxcEh92on1xIg5snZK0UXMg7TDrz2OO7tVBLpyBTKJCeprbMRPYT 5EqxXtMHQuyDgzVH+u3W+liYuWxmjqETz81VrIn8Pihqa7eqPQ8WCLdnxqLZl4R9+hK6 f75Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796242603; x=1796847403; 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=hyaLhioGSBuv7s9pB9iat3LppU8lx8aYn/SBsMDpK48=; b=WmozNmoYEuLTbu3xuWbc2mUZmf7yag7e3JrcscOQNEpG852CwBssU5uHrYCzcLh192 vH0s3jLMqYcjdZkFms9+pxX/tZIyPI+aS5rf5oK0sBbAC7cZwp6XMLsj1zaZAwYYpz7L I16Kog8qtkFpXLPTul19Xi1H/kXQh7W8TZYDGPZzYmUEe0ZnwFpw0Fs45BRnn5dTY+nX 4hvUm7nYa8yUQpZfEst3HPtQd0P50KZlLKceky9YKFs8sa7zCSGSrO5+mfHQI7cQ5HjI aLUqZEfXgbX12twmZSLkRQ1XK/dnPX1vRqDI6jkho1RSmK+Okod5TsddLCYZWyIIa5MS 22cg== X-Forwarded-Encrypted: i=1; AL+hErFitPyVWgpTId9+cZet4tQBOhiMm3ax9qeQOHJrWegU0iZgDMyHLu2E/pwF3QiWTZhwIVs=@vger.kernel.org X-Gm-Message-State: APuU4Z9AtzY2h8Xz3uDFQjrduLdSILdd6Guoea5R6AZW2nkf4ATGzbJY WpcIc+EAQ7SD1cYB7NHf60i4iuWwrppYRhR/yMrwmcP0KyDmsKX7nelG6r+7cBoZ6g== X-Gm-Gg: AZFdTZezyk5N4J3kkoby3WGJNx/mbt9XRTfFbHNge7ed+VJln9bw1n69Ki7SG4L3j0k d6x+L3q+mYrz5jjgz4cFfgyYNgG8uQI04F9sIgvxzc1F4nAjhd03WdC8DhcXFvbsWVk2EpJbGyj 5sdxnqW9AhcPR8id8RTiS3xcsPzwN+kSfU2L6FBBxyEPw+yA1fu1ymzppK0+2H3jNzhBtG48aps 9kFual6gK0Pl2PwMSEfV7S1pxIBEbd6Reit/hk54lxOOH5fnPSC2zsZ8bPGw3Cu+RyCp5WxUxe+ z5psuV8bUpPuAKRKNkq2jB7d6QnqcxUDXReoWZqHyCX+TVkwtvnSKlp1nxwr8m1MNyArVaZLL4E mSw23qFQ2RG8I48lSKvvWCeS64GinkT0m1HJyvitZkafsS9Dn4vKRT1RL40FKkmO1P/mHIBKzRw sYsw6Y3Sky/1mwqEG/ypqu6ju1jX/6YoKzXVQp3QGe/PBh7Xd1TWZS9Y9jcThMZSbFNoov9X44/ dKagazcLYf6kA+dzEutc034f42lZbzE0x5G293PzAuQiHB9npDZCLBAcWMiKQVPxKbNwqsmi5RT umbpq7TEyM1wokXfCTzq9j/Nw7519X5LyLXcv1mt6lerV68Ic+g5g2evfsSaGAvZeB+jReLDoq8 2kZC1jywcY4nTd2JxtiMF X-Received: by 2002:a05:600c:37ca:b0:4bb:ddef:1587 with SMTP id 5b1f17b1804b1-4bbddef15a2mr19030375e9.6.1796242602280; Wed, 02 Dec 2026 12:16:42 -0800 (PST) Received: from google.com (0.182.34.34.bc.googleusercontent.com. [34.34.182.0]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4ab69bf680fsm91018916f8f.14.2026.12.02.12.16.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Dec 2026 12:16:41 -0800 (PST) Date: Wed, 2 Dec 2026 20:16:38 +0000 From: Vincent Donnefort To: Fuad Tabba Cc: Marc Zyngier , Oliver Upton , Joey Gouly , Suzuki K Poulose , Zenghui Yu , Catalin Marinas , Will Deacon , Mark Rutland , Quentin Perret , Martijn Bogaard , Steffen Eiden , Fuad Tabba , kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 1/3] KVM: arm64: Check PGD alignment when creating a pVM Message-ID: References: <20261105075606.367005-1-fuad.tabba@linux.dev> <20261105075606.367005-2-fuad.tabba@linux.dev> X-Mailing-List: kvm@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20261105075606.367005-2-fuad.tabba@linux.dev> On Thu, Nov 05, 2026 at 07:56:04AM +0000, Fuad Tabba wrote: > From: Quentin Perret > > Martijn reported a hypervisor crash when providing pKVM with an > undersized PGD allocation. Indeed, although the size of the PGD > allocation at EL2 is not under host control, a smaller host-side > allocation can lead to providing pKVM with a misaligned PGD, which will > cause the guest stage-2 init to fail in a bad way. Specifically, > guest_s2_zalloc_pages_exact() expects a successful allocation from > hyp_alloc_pages(), which can only happen if the pool has been pre-filled > with a physically aligned high-order page. > > In order to guarantee allocation success in this path, check the > host-provided PGD alignment early on. > > Fixes: 60dfe093ec13 ("KVM: arm64: Instantiate guest stage-2 page-tables at EL2") > Reported-by: Martijn Bogaard > Signed-off-by: Quentin Perret > [Fuad: Returned -EINVAL and moved the check ahead of hyp_alloc(), with > the other input checks in __pkvm_init_vm(). Cast pgd_hva for its __kern > type, updated the comment, and pointed Fixes: at the commit that > initialises the guest's pool from the PGD.] > Signed-off-by: Fuad Tabba > --- > arch/arm64/kvm/hyp/nvhe/mem_protect.c | 2 +- > arch/arm64/kvm/hyp/nvhe/pkvm.c | 8 ++++++-- > 2 files changed, 7 insertions(+), 3 deletions(-) > > diff --git a/arch/arm64/kvm/hyp/nvhe/mem_protect.c b/arch/arm64/kvm/hyp/nvhe/mem_protect.c > index d4c332a918035..5b624b1ab32e8 100644 > --- a/arch/arm64/kvm/hyp/nvhe/mem_protect.c > +++ b/arch/arm64/kvm/hyp/nvhe/mem_protect.c > @@ -186,7 +186,7 @@ static void *guest_s2_zalloc_pages_exact(size_t size) > { > void *addr = hyp_alloc_pages(¤t_vm->pool, get_order(size)); > > - WARN_ON(size != (PAGE_SIZE << get_order(size))); > + WARN_ON(!addr || size != (PAGE_SIZE << get_order(size))); Instead of adding to the WARN_ON, perhaps we could if (!addr) return NULL; > hyp_split_page(hyp_virt_to_page(addr)); > > return addr; > diff --git a/arch/arm64/kvm/hyp/nvhe/pkvm.c b/arch/arm64/kvm/hyp/nvhe/pkvm.c > index fc0475f0877d1..03e530e15b4a2 100644 > --- a/arch/arm64/kvm/hyp/nvhe/pkvm.c > +++ b/arch/arm64/kvm/hyp/nvhe/pkvm.c > @@ -892,8 +892,8 @@ void teardown_selftest_vm(void) > * > * host_kvm: A pointer to the host's struct kvm. > * pgd_hva: The host va of the area being donated for the stage-2 PGD for > - * the VM. Must be page aligned. Its size is implied by the VM's > - * VTCR. > + * the VM. Must be aligned to its size, which is implied by the > + * VM's VTCR. > * > * Return 0 success, negative error code on failure. > */ > @@ -924,6 +924,10 @@ int __pkvm_init_vm(struct kvm *host_kvm, void __kern *pgd_hva) > > vm_size = pkvm_get_hyp_vm_size(nr_vcpus); > pgd_size = kvm_pgtable_stage2_pgd_size(host_mmu.arch.mmu.vtcr); > + if (!IS_ALIGNED((unsigned long)pgd_hva, pgd_size)) { > + ret = -EINVAL; > + goto err_unpin_kvm; > + } With this, map_donated_memory_noclear() is really just calling __pkvm_host_donate_hyp(). Could we remove it? Also, I wonder if it isn't better to first have pgd = kern_hyp_va(pgd_hva); if (!IS_ALIGNED(pgd....)) to avoid casting a __kern annotated variable? > > hyp_vm = hyp_alloc(vm_size); > if (!hyp_vm) { > -- > 2.47.3 > -- Vincent