From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.48 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796242605; b=TaGTB4UesxBkFrbZYXB8knjV5cSYCNHLN+ifOncp7VaSnH5xFeIRl4mxbrRRS5JLMgpS zJDg+AM6MKjhQeizc+NKCJ+oxUm043jQTrWlsa7scBDK4/I9tKlEEPQ89RBC14SyawAi4 Jvag8E8aEiED6vVlVIvvIcYxqvy4urCP7IEiAq7rlk/E+2XIUGQZe+8yo8JM77MP5eNxi eD5qE1Stx5oMP7dyTEacq+gIt7U8xi1cYl/C0EDpYau7+v0D1c0JvHizuTv+4Le9+UUTT Q03twhyk+SiULl3Fik/Pb2qzhs70Hrs0s5y/BBXilc/K/onSD27AZOb52JxJikJYBxg== 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=cKSZF6xTjTNRGo556ssj/6Fp1j+40d6z9Ta6vL8G2leQuNbNLQJifHpVcJN3tJWdYyjI 2QuyPlB4sykKpWkQsEuogo/nTlFAD7hz+SX1tdSdypZFBhMPKDSowo4XcoPvSCmWbxV77 ZuohLuqlaIVTmULo+zcIKjvHUPs3J5wHsEhfUoIz1u/wSQFmmX0LmZnLGeuYkoN8Tlot+ 4YEEYucTyEjWGZxJRmpUYT4iJScKmN9Ssbq7JytDtWf4M/uGpITONem6Dy2P5sPI5+FRN zhbi9ko2GLu1wZ5T1n7jNRhEIOXyCunGSpAN0GNOImq0nv8q9tK/3YpjdQuuQSqTVOQ== 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.48 Received: from mail-wm1-f48.google.com (mail-wm1-f48.google.com [209.85.128.48]) (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 A4382606A332 for ; Wed, 2 Dec 2026 20:16:44 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org A4382606A332 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-f48.google.com with SMTP id 5b1f17b1804b1-4bb70074ab2so141792895e9.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=EV+iIg1cCYcVWnt3gxADVB3cDjBXmnxqcCmBGibfi4LrbtSTW3roIZkh3uoNrafjiU HDoExivYCiepeso8LA972TCuv4FeP8zG0w8H5PZdLQnPJD+VroAkd47lr8L+t7tECVkF N3fg9U2bl987uTfAG4FnPcd7kvynWBwzqHZZoGNJSZfNZjsrVisihaLTBaYUCHgenxR6 8FE83Y32s4TR+VlUxFREvVP4jn891SoBUXywPGQQZd+br6t8t7D/6pM86nGKJnwp1SXi I93UOx7OT/B4r6rRD3Ym2q2BdBLvkihlTk+DsAFz5JiPwm07W695jGYLLsKMC0fLbhmL M01g== X-Forwarded-Encrypted: i=1; AL+hErEnIja4iRhG4Y3lZM3JE1BN5WvsTS9oNRZgUtl86WAXj6AkYt9/F8NX1mXGm1ZRjrY1PUvAsES58GwCW9o=@vger.kernel.org X-Gm-Message-State: APuU4Z8qdr8GLAdiP8GRw58/IYdKZ0pvsff+xmv3otl9EyxqSW2i4Fdm eSKMVfMczF4/T8PcFZ6DB+X2ZJLgiw6goIll7fP3wpWnjMgsYhBuQenXc4WolOST5A== X-Gm-Gg: AZFdTZf9lkNnLfFoDAdl+TSxU1QEgM8DMSZnvbzZyGlRfpjMlqx1PZV36bYgcpQ7MFf gLTrp3KA5dNwlhPCnzwVisXMOCaf+YHaTjnxFI4AJOUbM1lVJDa/RoDShbXBqvxHKVSIpFkUkj6 cdFWuS3Jku9Ty3PiyfzU1umlH/kDGJqe2qsZivBuHPJrEdJjk6G36DEBBs7v925FwTHKg+EexMu k3CjgXV6SrtWENMX9OCpgOQ0etGRoNnJND5qysbgwRQpDozoT+FUjGvLUs2S3MNdqsroyWArd4M 3sPXN3rVnry4Aq4xCocdhHReF3zwsgn6Yp1VO6en8RC11N1zcWWb084Cpw04XHi17UTiH+RtPSH TISF2LJquwnqxuOrOeXZhwdHuwQBOB7VcniFzA2Tkvt2tRvy/BRLNhwDjbSWvbvigJY5939OK8Z Vwm+C9pFYYRtOWod3HRSworn4EsmWXX+kxL5XXLPhvyNDh+QCd71DVPND7dmJKHII63tvtLZif0 v//D15lHiXCCuYLF/Qs04uj4jcVxB/SUemzFaEtIWlU8TL2lufGcRRs1jfLbqpCPseZkVkncC1u f9Tq3n+A2itioyFNCSWAVSo5M+GIjggThMNc7AbmLnF1tQ9vOQDK+B2hmykaUq04BbqNnztxhz/ E8qIyHH/TWc7/VoZked8v 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: linux-kernel@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