From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C5052C61DD6 for ; Wed, 2 Sep 2026 16:41:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:Reply-To:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type:Cc:To: From:Subject:Message-ID:References:Mime-Version:In-Reply-To:Date: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=PFS8FckNWR5Ypo1TjtxFOP+XgfwND0gTpHBze+LVvng=; b=kcxID7DPTaCKLquuS1/vz3RJZi PvhRqzqWQSYBDIXNwTDQKpQCk3wyTokX/h2mi9vMv19mhhX79l4doiDvFut1B96WC3PjdezT9zWva /yKWSBaIUtRym5CJIXAqmY+DAHxTp3c+u2d2bLmZrWBGw95GGmsphXCaZ/TwOLmwDdsQdlvI9BUDc bNXlzVz5Yu7b7RqJHUSSiaozgaxGBApcgOjaT/qfaUJwyr8+cGTgEhBb/TVh6A5eCSlNcBdfQsWCJ vAkOBosqGq3Q/jsFC90+YuAdU8GUXh7Sw8Dz6ih285bhDDI8M7+mHPk7rAKsqNmSICJnbxpZdl352 OtKVdIOQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1x1o1t-0000000FERI-0wQ8; Wed, 02 Sep 2026 16:41:41 +0000 Received: from mail-pj1-x1046.google.com ([2607:f8b0:4864:20::1046]) by bombadil.infradead.org with esmtps (Exim 4.99.1 #2 (Red Hat Linux)) id 1x1o1l-0000000FE9n-44up for linux-arm-kernel@lists.infradead.org; Wed, 02 Sep 2026 16:41:35 +0000 Received: by mail-pj1-x1046.google.com with SMTP id 98e67ed59e1d1-396638f9a18so2342002a91.2 for ; Wed, 02 Sep 2026 09:41:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1788367292; x=1788972092; darn=lists.infradead.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=PFS8FckNWR5Ypo1TjtxFOP+XgfwND0gTpHBze+LVvng=; b=Lofer9YP61jyT+xNxZ7D9c4/a21Vq8aDe+pyjYMo4ynNi1TdlBPUCR0SSM9nSkxTZ2 QCZ3+aQDq2FVcJDLbFnqtyhhWsW4fTYmC770QpzstqhKERZ0+HCBK9JDrGVIo4YTmFOS Ip8isrCq3OVivIjoNy6ra6odT/B4kksC94PbktnVwZlhd+Vjp0GnvaIhX6DCfGFHhx+F 0UNeKLMCg+BkJjY0oBYrouzk0gSCx7MLRwZOgn3v3/iJ2x/HqyReHZehew5dTWP/5g+T 9Er0bkjLqgELDxWYxB7PXh3h8uL5vt/kEi8yhDroMxdYtYaMgOdZWpjP/7lR9/aI7/8A xixw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788367292; x=1788972092; 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=PFS8FckNWR5Ypo1TjtxFOP+XgfwND0gTpHBze+LVvng=; b=k85pfc+p8UjIJikNDrNBvMfiiFuQGX3xRwiSbuoYM9E1jMDBqIsznPsxCXOhwVH9JJ XE2BYjDyROrp3DAgDNxVZ/cTORH0Ymv18LI8EEHd5U7M8d+GN1YCDtaI5Y7vCObT+BTK 813gPo5QIWk9jVkXH3aTWX9iPwBiVbDb0BUAd0gzuYftDGYJNDFn8J1xx/2it4pLwVLj l5pKmzfAtXYfWKe8Bd9mBqS02cpC3hco5SnCF4EN/GKnAPRpguVMbO9hHQIbhmmIDDoc +5y1viFHff+T1HBF71E+1myZUL3dezjKBGx82oei0keNRvQLlNCIDBcfnLpDypTQXW2S YjsQ== X-Forwarded-Encrypted: i=1; AKwUvBy2HdNNrW1wyN4q59QpWQnxLaSNyUAdHM4iqNHQVWoqvbpX8Or+pj4CvxhY0PEGpQeBlmzKdhLYwGCvTVe3Gh1M@lists.infradead.org X-Gm-Message-State: AFuF++lEeIqaMgf/is07a1Po/rp+/h77d5VjmqFWPUF2VZkb39KwN0CH KCFQyXmna4C6o24697t9Uq8H3nEfjPl6f9pi/XfL6QiFvBYNJTgOYVS5mO5RwxVeKgHuMI5EGtl aNBWycg== X-Received: from pjmm16.prod.google.com ([2002:a17:90b:5810:b0:383:7b51:b1cd]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90a:e7cb:b0:396:65dd:4093 with SMTP id 98e67ed59e1d1-39aee153a7amr7412902a91.14.1788367292151; Wed, 02 Sep 2026 09:41:32 -0700 (PDT) Date: Wed, 2 Sep 2026 09:41:09 -0700 In-Reply-To: <20260902164123.2546762-1-seanjc@google.com> 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-7-seanjc@google.com> Subject: [PATCH v2 06/20] KVM: selftests: Extend page allocator to support naturally aligned allocations 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" X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20260902_094134_131170_C8BC5A63 X-CRM114-Status: GOOD ( 12.72 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Sean Christopherson Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Extend the page allocator to support naturally aligned allocations, as some flavors of PowerPC page tables require multiple guest pages per table, and those tables need to be naturally aligned. Take care to align the potential base address *inside* the retry loop, i.e. the base needs to be (re)aligned on every attempt. 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 | 13 +++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/kvm/include/kvm_util.h b/tools/testing/selftests/kvm/include/kvm_util.h index 95bc0a78d2bc..4732b9528812 100644 --- a/tools/testing/selftests/kvm/include/kvm_util.h +++ b/tools/testing/selftests/kvm/include/kvm_util.h @@ -991,6 +991,8 @@ void kvm_gsi_routing_write(struct kvm_vm *vm, struct kvm_irq_routing *routing); const char *exit_reason_str(unsigned int exit_reason); gpa_t vm_phy_page_alloc(struct kvm_vm *vm, gpa_t min_gpa, u32 memslot); +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, gpa_t min_gpa, u32 memslot, bool protected); gpa_t vm_alloc_page_table(struct kvm_vm *vm); diff --git a/tools/testing/selftests/kvm/lib/kvm_util.c b/tools/testing/selftests/kvm/lib/kvm_util.c index bbf6d7684c0c..896da440659e 100644 --- a/tools/testing/selftests/kvm/lib/kvm_util.c +++ b/tools/testing/selftests/kvm/lib/kvm_util.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #define KVM_UTIL_MIN_PFN 2 @@ -2032,9 +2033,10 @@ const char *exit_reason_str(unsigned int exit_reason) * * Note, success is guaranteed! */ -gpa_t __vm_phy_pages_alloc(struct kvm_vm *vm, size_t nr_pages, gpa_t min_gpa, - u32 memslot, bool protected) +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) { + size_t alignment = naturally_aligned ? nr_pages : 1; struct userspace_mem_region *region; sparsebit_idx_t pg, base; @@ -2051,6 +2053,7 @@ gpa_t __vm_phy_pages_alloc(struct kvm_vm *vm, size_t nr_pages, gpa_t min_gpa, base = min_gpa >> vm->page_shift; again: + base = ALIGN(base, alignment); for (pg = base; pg < base + nr_pages; ++pg) { if (!sparsebit_is_set(region->unused_phy_pages, pg)) { base = sparsebit_next_set(region->unused_phy_pages, pg); @@ -2077,6 +2080,12 @@ gpa_t __vm_phy_pages_alloc(struct kvm_vm *vm, size_t nr_pages, gpa_t min_gpa, __builtin_unreachable(); } +gpa_t __vm_phy_pages_alloc(struct kvm_vm *vm, size_t nr_pages, gpa_t min_gpa, + u32 memslot, bool protected) +{ + return ____vm_phy_pages_alloc(vm, nr_pages, min_gpa, memslot, protected, false); +} + gpa_t vm_phy_page_alloc(struct kvm_vm *vm, gpa_t min_gpa, u32 memslot) { return vm_phy_pages_alloc(vm, 1, min_gpa, memslot); -- 2.55.0.966.g6673acef38-goog