From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f198.google.com (mail-pf1-f198.google.com [209.85.210.198]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BD5E33E49EB for ; Wed, 26 Aug 2026 23:05:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.198 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787785548; cv=none; b=jh3JZA26HnQus2PvPKNtiP0iRfpvjvDx6w/Hoq8FkCsqvaI6cYhBQyY53qHkX4KN46UQlv1HMcJEFypdp3LVpJyKZa4iA6Qt9Nt4OAG7DW5FOK28rJIHRWXtBQUd2hrKUpnIDly0onV76bonaqaIIGSfHX2+KuO2+YdFlDQ1zCw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787785548; c=relaxed/simple; bh=X9xnhlePSqIAyLBCipdOU0BNauH8Bhdv8PSGmQMr+Ik=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=GkygkBbdHmB50Mikw5n/wFCIvh4bu7Xn/YjWpJP564DdEYrUuourrFrQj6c2ecldsY6rX3Indn94dWJvi/7ii7IlTcJ8WXHcu5nPAEnNAzUEc1wU1yDb9tBpJgR3DhRwYI7Iq1eFN1SGSl3H4/93K4zPAXE/4jcqWyS5L1cW+M8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=YajOMh2j; arc=none smtp.client-ip=209.85.210.198 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=flex--seanjc.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="YajOMh2j" Received: by mail-pf1-f198.google.com with SMTP id d2e1a72fcca58-8485d853b08so109324b3a.1 for ; Wed, 26 Aug 2026 16:05:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1787785540; x=1788390340; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:reply-to:from:to:cc:subject:date:message-id :reply-to:content-type; bh=pHiSvQXl4tkWm+SikbwEM4QvcPfHzRPC0s7Gep7aVew=; b=YajOMh2jfK+v8gJoi0acaU/2VAINB1kXhM2eeFEnf9WX8/3zQD/Ck3UN8qnhaWbJYr ipOngiWYIRwtc99CXNfImE6dJVREQcSdLm/afJYs4j7gXfjmzZwVlELiL+Jj1ks2Qzo9 HDupiCkAatdKX69e3urytIOliO6yzSI4Shrw8rqqUhWuQI80umP49tF6TWnNAQZOjq7a r2Db3WwoLuuOIPoeKNc0cNkevPqOWtpFh+I4s4KFF+Xn0tBAr3cgiGB2l6XJyAKlcJ91 /yU4+qetmkqenBXGUNkVBoXNpaLMjFl25zhOIojIHhnGJWu8whJRa+NzzK1CFn0Ad2iW IWqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787785540; x=1788390340; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:reply-to:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to:content-type; bh=pHiSvQXl4tkWm+SikbwEM4QvcPfHzRPC0s7Gep7aVew=; b=J/9Fa6qhbm0KgQhJkWMo+633VGXzQxAEgN+w9Whhs0QYlAF4Cr8tQ2EyZwAjevLoae HNCi2FJBvIM2RLV4hSrvpzJeX2St37ngtaiUJSarn17aFKV0KNgOzEs5d8cZoB9+YxSL jITi7y28q9sZ9Zc6RR4csJ5Hw8m3VMNViJhNZ9IsYlJ6NJc8TKpwmL6NubnJvb2d4YIa upSexq9BqxblSoZHueVuirQ0ksAsB6NzZ9BFRh8ggKpkDCpdUKcobxzoUa6mYa2m8Lkd CYClX8Xv4vZZmhwGbCb/JuwuSet4HpwMUarFYUha0DW4I90ocKXkUszegXj/M8Cr9KyM 4SAA== X-Forwarded-Encrypted: i=1; AHgh+RqaZxFAlm6eGXyV/IdjRUfg69udzI3aV/oWyIkpL6uw0cOhpek0Go8x9p7PhzHXJEf3FqU=@vger.kernel.org X-Gm-Message-State: AFuF++nEeNZPlHf4VvflihRPuxcADr6HkhAPGnl3ig64pg67HEOQLqUP NQdsGbi6hJgJq8LwMkG9oCyW8Kgry9TwP6nZl6oP/5Iy8Ap+mdafsv/20tviwQZKbEYrz5AMFNv JeoarPg== X-Received: from pfbcb3.prod.google.com ([2002:a05:6a00:4303:b0:847:aa6c:47fc]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:b53:b0:851:8baf:5b26 with SMTP id d2e1a72fcca58-853749a5e4emr17924734b3a.14.1787785540289; Wed, 26 Aug 2026 16:05:40 -0700 (PDT) Reply-To: Sean Christopherson Date: Wed, 26 Aug 2026 16:05:11 -0700 In-Reply-To: <20260826230511.972824-1-seanjc@google.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260826230511.972824-1-seanjc@google.com> X-Mailer: git-send-email 2.55.0.887.g758fc8c411-goog Message-ID: <20260826230511.972824-21-seanjc@google.com> Subject: [PATCH 20/20] KVM: selftests: Add arch hook to force page tables to be naturally aligned From: Sean Christopherson To: Marc Zyngier , Oliver Upton , Sean Christopherson , Paolo Bonzini , Tianrui Zhao , Bibo Mao , Huacai Chen , Anup Patel , Paul Walmsley , Palmer Dabbelt , Albert Ou , Christian Borntraeger , Janosch Frank , Claudio Imbrenda Cc: Fuad Tabba , Joey Gouly , Steffen Eiden , Suzuki K Poulose , Zenghui Yu , Atish Patra , Alexandre Ghiti , David Hildenbrand , linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, kvm@vger.kernel.org, loongarch@lists.linux.dev, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Nicholas Piggin , Ritesh Harjani Content-Type: text/plain; charset="UTF-8" Add an arch hook to communicate to the core physical page allocator that page table allocations need to be naturally aligned. The hook will be used for upcoming PowerPC support, which has MMU tables that are larger than the guest base page size and need to be naturally aligned. Bury the hook in the physical page allocator to avoid having to plumb a rarely used param into the main APIs. Cc: Ritesh Harjani (IBM) Signed-off-by: Sean Christopherson --- tools/testing/selftests/kvm/include/kvm_util.h | 2 ++ tools/testing/selftests/kvm/lib/kvm_util.c | 9 ++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/kvm/include/kvm_util.h b/tools/testing/selftests/kvm/include/kvm_util.h index 1264cd1a343a..ffd4cf740d7f 100644 --- a/tools/testing/selftests/kvm/include/kvm_util.h +++ b/tools/testing/selftests/kvm/include/kvm_util.h @@ -1050,6 +1050,8 @@ void kvm_gsi_routing_write(struct kvm_vm *vm, struct kvm_irq_routing *routing); const char *exit_reason_str(unsigned int exit_reason); +bool kvm_arch_needs_naturally_aligned_page_tables(void); + gpa_t ____vm_phy_pages_alloc(struct kvm_vm *vm, size_t nr_pages, gpa_t min_gpa, u32 memslot, bool protected, bool naturally_aligned); gpa_t __vm_phy_pages_alloc(struct kvm_vm *vm, size_t nr_pages, diff --git a/tools/testing/selftests/kvm/lib/kvm_util.c b/tools/testing/selftests/kvm/lib/kvm_util.c index 8b5b330a5889..57b653fbd0b1 100644 --- a/tools/testing/selftests/kvm/lib/kvm_util.c +++ b/tools/testing/selftests/kvm/lib/kvm_util.c @@ -2085,10 +2085,16 @@ gpa_t ____vm_phy_pages_alloc(struct kvm_vm *vm, size_t nr_pages, gpa_t min_gpa, __builtin_unreachable(); } +__weak bool kvm_arch_needs_naturally_aligned_page_tables(void) +{ + return false; +} + gpa_t __vm_phy_pages_alloc(struct kvm_vm *vm, size_t nr_pages, enum kvm_mem_region_type type, bool protected) { struct userspace_mem_region *region = vm_get_mem_region(vm, type); + bool naturally_aligned = false; gpa_t min_gpa; TEST_ASSERT(region, "No region for type '%u', memslot '%u'", @@ -2110,6 +2116,7 @@ gpa_t __vm_phy_pages_alloc(struct kvm_vm *vm, size_t nr_pages, break; case MEM_REGION_PT: min_gpa = KVM_GUEST_PAGE_TABLE_MIN_PADDR; + naturally_aligned = kvm_arch_needs_naturally_aligned_page_tables(); break; case MEM_REGION_TEST_EXTRA: min_gpa = region->region.guest_phys_addr; @@ -2120,7 +2127,7 @@ gpa_t __vm_phy_pages_alloc(struct kvm_vm *vm, size_t nr_pages, } return ____vm_phy_pages_alloc(vm, nr_pages, min_gpa, vm->memslots[type], - protected, false); + protected, naturally_aligned); } /* -- 2.55.0.887.g758fc8c411-goog