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 A5F15C61DC2 for ; Wed, 26 Aug 2026 23:05:56 +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=ypnv5ADnidmiHmk4i8NjwAmXQS3vAgk870JArYSva+A=; b=l87vLZJIXX8eyv6tbV2GnZvFkP stvjPQByWWPFY2Orpq+/1vW4/Fb30iDgL2utEKEPu+0iOEs3DB4YJgjNLerfJoAaIpgPzbP/ddvVu r+zVwh6J0szHvoRWcKjTWAExBsITrD8FOm4Jos6JkGHM2zCByrnmEv04QAAB5AMsC5tkVO4tMS1dw ibKHlZPrfaNy0QL+gTT1cmmOWZ7BB5r4cTikQm8RbXBNcFSTgYpEgKAbjtgnGpJGSb+w6PwKiwn1N eOFfYGgqgTC0P04/l4TRvcv9qH0NmL+/9XcTaCQsSysjroxeAYIe/GMxHMCihiWxZn6Rmg+7VmM1H 5V8ccBog==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1wzMgn-000000036iL-3BDS; Wed, 26 Aug 2026 23:05:49 +0000 Received: from mail-pg1-x548.google.com ([2607:f8b0:4864:20::548]) by bombadil.infradead.org with esmtps (Exim 4.99.1 #2 (Red Hat Linux)) id 1wzMgP-0000000369F-199s for linux-arm-kernel@lists.infradead.org; Wed, 26 Aug 2026 23:05:26 +0000 Received: by mail-pg1-x548.google.com with SMTP id 41be03b00d2f7-cb835525b10so1842486a12.2 for ; Wed, 26 Aug 2026 16:05:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1787785523; x=1788390323; 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=ypnv5ADnidmiHmk4i8NjwAmXQS3vAgk870JArYSva+A=; b=bxwmYPWAuY2oPvf1g5r3hQO4QnTRH3xxkCpUZOmrxzgS3ylQFHUQD39FG7DH7MXSYm mVcF2PLjaNJjPM+BHPiAw1wK0BBptEZIZgaMCyFaYMzydd1hjURGbPC81GJPN3cBXNPO 2mKYXk1AoHqBV82D5GeLOTl3YC36TvVe1Um4U6VWcgbl9mdraCdjQN5HG/9qWW5RlleW otV6Hum6iYYveQXzW6RJJWJSseOGRsRGf8J8tKpD7SRr4SUAhUGry+xMuvPedR3ir4U8 KEn436dzAQVYc41oao6HyE7IPhPqvyBhaH14wtGAdkGREsVi4GIPIJK+TCoQExPUQPbr QLgg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787785523; x=1788390323; 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=ypnv5ADnidmiHmk4i8NjwAmXQS3vAgk870JArYSva+A=; b=fgHHuSwLkKcAX2afxhlbldoZwN7S5r/HUjfkzJ9TGtRShyevK35o8dFuXX4SZsncFj QrvsyEhcrdJCKdeh506hVY4ylTzRfLeEeCLU2oVlHrtHQHrGOzR0ZTeZQfCJZOe2Dkjc UOvtLmMrjFJFH6qxeAxZ9mcirC0zN2IS4Rds8s3i5GGBnL/BGPqM9aKXUZ8im/5aTJDV +CMy4KTaDeDjjxuqRgg9wzJHD5TIQU5gnhTnKxdK2KyzeuSQMv1IU16rxsWt8INrv8OU M1IFh/Ra/QCvL6XX1zuJKsxTBTzrUIJC9TbLd5JrgK29VLXAF+tbQJAPp/rPIfU3ZVDA OgQg== X-Forwarded-Encrypted: i=1; AHgh+RphWw/V4yFshVp+lZeYm+Oj/VHrqF5A0reAk0EAR5mMczeAPwTkB5j0FD0D1MdqtfOxlW6JQ9rqC9EfGeBYgHsX@lists.infradead.org X-Gm-Message-State: AFuF++kr6fOK+m1pOWfkyq4RAqpEnQ1MhIXn40AmmUqdPBr2L1/6sP1v M5sS/m6k4wCLjDbTsh1q42M9Tli2hSaEYF9VwzWItD/gNRMdYP99qmPuBjNvMFeKU8JU0+cfXG5 mJPVqIw== X-Received: from pghz21.prod.google.com ([2002:a63:e115:0:b0:cbe:ddc9:c670]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a20:a110:b0:3c3:33df:4d9a with SMTP id adf61e73a8af0-3cf7596a65cmr18790428637.1.1787785522980; Wed, 26 Aug 2026 16:05:22 -0700 (PDT) Date: Wed, 26 Aug 2026 16:04:57 -0700 In-Reply-To: <20260826230511.972824-1-seanjc@google.com> 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-7-seanjc@google.com> Subject: [PATCH 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, 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-20260826_160525_436471_0A86A898 X-CRM114-Status: GOOD ( 11.69 ) 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. 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 b1c5597b1def..96c8251c224a 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.887.g758fc8c411-goog