From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f199.google.com (mail-pf1-f199.google.com [209.85.210.199]) (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 854B14AE8C2 for ; Wed, 2 Sep 2026 16:41:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.199 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788367320; cv=none; b=CAL4GKrVek1I5kc6J9H/OYQPqt0VDwyZa5qnUnEmHprcgR6VnIW6uZ9LOCJm6KIpqu4TzgwKrl4zmr1oAzxyh660R69ieb0h4v9C33u0r+vE5yZgPyqxRx0baQwHFs1yhzk5JRniBgRpu4brnUqI08PJL75eap92nO0/Bhs8xpo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788367320; c=relaxed/simple; bh=lnkr8N7+2rACdUGX5u+8RqWUkOW9mDRi0UYpxqwxQt8=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=OPnHT4JB0OB723NsKALR9ufQli8yhq8zIJMk4T1XimDSub+fnMzlUI0DZtq4l9Eld9OtyM6nr2CB1f75lZZykz+RTCSUkHK04JVNt24fzSnsjmyuR96XBALJBPDWS3Anh2uRcB/R8UyhS8CreTl5c7bdPvmQLUtl5QB2TONo2tY= 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=DdaXbIfh; arc=none smtp.client-ip=209.85.210.199 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="DdaXbIfh" Received: by mail-pf1-f199.google.com with SMTP id d2e1a72fcca58-85599cf98e5so2301917b3a.1 for ; Wed, 02 Sep 2026 09:41:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1788367309; x=1788972109; darn=lists.linux.dev; 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=BHZG1y8vqLRAbs9gwwYCsROxfX8BN1ebrpFia3yeMLQ=; b=DdaXbIfhCsSaG2QvWAHy5ivC092kgXjEGHLHDjPlSS5/mjBsa7Nm1XLsldrQpkF97/ 6aW0YaHtdMg3mUxoQo2fo9KOmYPYeRao4JTtCd2/hhJ6hEgINDoc5yAb/zuX8/uxGTW/ u7MoE6+hq/HdXhHhxxPoPSJ3A/h+6TZ4DhqPbbhYLQnXmwjkzc0fatqCf0b3lw7LjGNg NYgQBskEQ/JydKClK9xgUzQhZQmUEh9wwdaNoQrKl5c12hQbvO53Lj02tAVC+zAD7R0V qhLFZdkoFXKc/8iVUvPNvSrJ4x+L2+YtXZY0fUwN5Dsh+x86t94fpbxuzEyKrcd42Awl uHNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788367309; x=1788972109; 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=BHZG1y8vqLRAbs9gwwYCsROxfX8BN1ebrpFia3yeMLQ=; b=BIF1jXq5/27eZwi8yHGZUdYKdm+HBF0vV8bpIxpn4//OjpFkezTWK860RM0l7rXFrY pDF52y7/to91ukkWONHz+kgDRhA9RnSdMhpQC3SDfrZFexq5Zs1BVbf+jfcHeJV9d8yl Kz0pjC9owlBlCD0WWJxZJqqeWalyTXnrSyO96nBHLLYaBPTsIfvYkTNI4eLh5yhTksEO PoRhJkSV4hQAOU3mAzFBmmB8ZfaWuluh+/uYEctx6+T/sVY1fg/e7GailB5fzBrFGd/X pld8PCN6863nx3n1dQD+kmni7IYkWq/GUcskyNggZLGvlMLzzC9nHcjkK17TQ9ds4GJv CPjw== X-Forwarded-Encrypted: i=1; AKwUvBwibEx5mmg0WCbkEa9QNcAfgI2fjGSd2rVUvVqHYFYL5W1Jcsfow0oQc5hQIc8/TZUfK5vFc0LQTKg=@lists.linux.dev X-Gm-Message-State: AFuF++mRnCttxTYvkd+7se/CclpJaAD61MkWBucmvFNv/qnHlgc/M84N JTkLoH0/lDY3YbtkAHCHY6pMr0wm8MTZO/OFbNCjSN15YEzd4HVkBTmXzpZVN5cQ8fTvcDxf6Vr 5v0i2Zw== X-Received: from pfaz23.prod.google.com ([2002:aa7:91d7:0:b0:847:9472:cf8e]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:e8f:b0:857:72f8:dc91 with SMTP id d2e1a72fcca58-85ed850a6d7mr9743799b3a.18.1788367308520; Wed, 02 Sep 2026 09:41:48 -0700 (PDT) Reply-To: Sean Christopherson Date: Wed, 2 Sep 2026 09:41:23 -0700 In-Reply-To: <20260902164123.2546762-1-seanjc@google.com> Precedence: bulk X-Mailing-List: loongarch@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260902164123.2546762-1-seanjc@google.com> X-Mailer: git-send-email 2.55.0.966.g6673acef38-goog Message-ID: <20260902164123.2546762-21-seanjc@google.com> Subject: [PATCH v2 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, Itaru Kitayama , 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) Tested-by: Itaru Kitayama 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 43b49d0ad4eb..89b4fc2af751 100644 --- a/tools/testing/selftests/kvm/include/kvm_util.h +++ b/tools/testing/selftests/kvm/include/kvm_util.h @@ -1052,6 +1052,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.966.g6673acef38-goog