From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9A9C1606A322 for ; Wed, 2 Dec 2026 20:17:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=iQbwP95Y; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=f0cdhHsh DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Unsubscribe-Post:List-Owner; bh=hyaLhioGSBuv7s9pB9iat3LppU8lx8aYn/SBsMDpK48=; b=iQbwP95YW/lZVgsUNBWle9uRu2 jnRRfC74yZbKqcvOmGfe4grtIKSWvpa6kfUWxRIjsJB1ELpOsvZeFLQKE9eBvT+G0MiiH5ki/4Z6W doq9T3ZzVqvWVnt4qlTFZMKwVRcRwM1G1BmpyONvPSLhB1g0C3WaWiJ1fctSUVZmJj0ZBx/4tlt9+ yOM+EAwg1bri1dgSibiJBu4xeJ/ToZhSfOiiTQvEc08hB7BnLrCxIahS6t7Oamzhj251swDVZ0R2c 2UhG3cCHw2n+KQqLdiHH0n8v5bUuB5hb+042WSqoKRI8DS2rr3o9kcS9e8a7rLF57oTiKAmtutGy+ wCj0w89A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xYqkz-0000000ChvL-1Znh; Wed, 02 Dec 2026 20:16:49 +0000 Received: from mail-wm1-x32c.google.com ([2a00:1450:4864:20::32c]) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xYqku-0000000ChqS-43zU for linux-arm-kernel@lists.infradead.org; Wed, 02 Dec 2026 20:16:47 +0000 Received: by mail-wm1-x32c.google.com with SMTP id 5b1f17b1804b1-4bb702a7548so123587575e9.1 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=lists.infradead.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=f0cdhHshXyFzbQfHDCLcz8D5JsK5nVkSt84bwkbcFAAVCXyRwYPkXvb9v5wAteTH2j Ixsu+liM3FYOYXA9o77fqGKQ/KzQoE3g2SpGvR9HJ8afU2vG7lOsOyIugfUOA5iWIOqD kz0udpj7xqzQ5r5DNPR/N1GGDryBLdi5EbPaL+/kbdq7nT76bfqe/xxJbcsbrE8b8shS fuRope/b7lzcO83JgfNdjpoVjA7c95CbrToRFQlTJ6AXU9VC9YB8Un9VdeuxBD6pYq/l nMPf6iUvMDVgSRGR17cYD6kuGXWs3eVVg3hk6xbVjCSF9DMAKkw38BT1UhNV42MrhFDz XQOA== 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=c+GDEAic2duZxVIf/QFjmiTt0LZsOkzEkKmBZcqDQzWxOARHfbUqnZfhh2p8WGxQ7V lUTCl9QScVYJlf8plsqnOvN0JqeaWF/mm1IJeklOaN6xkVirpj78GDLK2vK1ehgLOwIC eZ4kpNZI5HHbu+vC0b5DJjmhqQRFbg5nePJ0jYsrFE9xMN887WVAjBN+06csihL/PWSB ZpzoqGxXQ44zqcpSfACRHWvKb7yUvd+AHVgpp2oI+tbHje4fwH77NYCndhgdmJsMuXsG 54gj91sC1QALiTsBDctPKhNrKVfk2hGUtc6jsVCatoGnrccfIqqHwNtIN0Fig98zjgjJ lkGA== X-Forwarded-Encrypted: i=1; AL+hErE7v5hFzfSn4reFFqXba5P91owdWZkDYCsV506XALVyMmayDFpnf3VebZ4kKNBBjv1lynrx1OqF4zTJEo52hZMG@lists.infradead.org X-Gm-Message-State: APuU4Z/8bCLMB8R93snhk6gJTm8GidBkFjRM7OYJw0sPlgyN+7r9aXHr 6DDDPjR9zPwFqRPUewCNe1/CgcqRBUY7m8I/7etLPZ0l2XyMhn+JdrJGEk0XjkGGkQ== X-Gm-Gg: AZFdTZcads6fcTP9/ACuzZIYjh5rBzZtOLdC8T/18s/qVdb5xUlHl76p8CvP1vrNR9x 8v3O1b8JMUmnY0dR47QDDZGZhAfFpzZYZKenlI/IKfJMHK2caoqhXsZUpxhFI8dcgSsZK6AhYiE TNMrqLO6WaoureFNwZaXlicSC7iXzlnLD4i7rV6VglCxcXokNyKZFW2nWa7OdOvzdIy4USyaSAD AbANDnqmoxsMkakKeAoGr+aBeSuAsv5D+7DitwXWtBEzcgViqr9zCMoehugtf7V+cFM6HoVos5c qAqkCZb42ZjI4z/5TwOZY0RAX2OYSQ5EOMm2ahuSj8KYRtELGesA40OFPd2TGlp+StpLbv3vY8j aABla5UbnrnuXq/EBAPQJjqSKpgl1luA0UhL4TNmFMGV7gj7H2Uwq9gsUfVU3bPJc/UXiBI/OOi iUVSfJCamDW17gWFqj8CsPB1anRTe4cbuMknYUWZ+RR1jridLoEH63cYWUF+G5Pqt0hTnKHEoGW ig64N1PdFIz/rjdZ2pcc3s4AqF5lzUSjPlDb0P/5IQruuEwqAdrh9BxQ1o9krJlnGPa7CUa9B86 z+CcrQkcQ2Dv2CjOlcpG5NrHFHbQ39NPNgidxdbLAnQx4xoqAPB4ymQZ6KoICDPuKovmip7FeAf MSl8QZ3hcg/KHYRz4EAtq 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-Archived-By: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20261105075606.367005-2-fuad.tabba@linux.dev> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20261202_121645_046944_3C9497ED X-CRM114-Status: GOOD ( 26.66 ) X-Spam-Score: -17.6 (-----------------) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" X-Spam-Status: No, score=-23.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIMWL_WL_MED,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 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