From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f72.google.com (mail-pj1-f72.google.com [209.85.216.72]) (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 E31A94ACC92 for ; Wed, 2 Sep 2026 16:41:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.72 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788367297; cv=none; b=TsM7L1jvAdkCqSVhQXOImDu6PKTBaoD8+R+qH/tOgccBb3YciCL5W+An70nGU76y2Q4cw3N+lhEpbRkhX5LdpGEFcwQKVcG+xJ3DguXpjGv5sHmj+zY/PzyIDE0uNlvmLVctWsI46Sl12pJ1ujmytWE/1Yl6mREqPdUXEPdul4A= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788367297; c=relaxed/simple; bh=wsoBQD4qq6Et3vmrWdvEDcU5mPTJSW7kE60nWbUUw1M=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=XNfApxBtzHq0HtrP7E0ULNTHuUtiSU3bKZfNFdrABwHHR2Qb1VV027GqV+gNXMV8ghJvq26sIiNS1ZNB8CqVPWY6aLlgVWAn8qzxDj7hOKPZlprXcfP/+Ve5d/eXQAFPDv8S6+DV9eJXTEq2Z0Br2svBU+kVbam4JyrJiWOra1Y= 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=DgYsy7j7; arc=none smtp.client-ip=209.85.216.72 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="DgYsy7j7" Received: by mail-pj1-f72.google.com with SMTP id 98e67ed59e1d1-396638f9a18so2342006a91.2 for ; Wed, 02 Sep 2026 09:41:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1788367292; x=1788972092; 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=PFS8FckNWR5Ypo1TjtxFOP+XgfwND0gTpHBze+LVvng=; b=DgYsy7j7Bpj0c5vsKxGdlo08Ke494DlSSFv28jrW4U0VNQMH1uGwuLTWPWn9bfniTd 2P4nN47MWQjxz4ZOv6HB2xPbfdOX6yzyUzkHyEjkcWoEuS1ltPHQfEjX4PKFwAvpM0fk tVcfuVs0euLxVOkn5KWP3SQC9S1DjAqMhesafxNSLfllE0Q4QzB1BvcgoPsSht2Smh+A BS91VK8BgCesFWPpbsEt+EuzrOViX4VCbg7UHO7VBh7clUi45gIDQCaW1j3nVkPKGGLo r9+0YSLhAOIZ/nZlarCWkm0SxVR2op/PhGQBwUVMMx7wxbP7x9pge1BmKXtlZ/wHR7V1 acTw== 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=hl4b7pIiVuqo+JpFaW+taQSmZ3vkSxJpTOmDkiaARAL1NNSqauHNShyFbS7LCv7bBh AlZsPLgn36OT5yGil8RCHs2jDS326as0BfF2XClBp1c1wUeinj4QOTFk8oD3l8Ak5tsG KUzMIBZoTdPhv2sjxs3RvuWVR2LX2jG42/HWdfPmkBlrY9ii5HLCJuvjPo6tTUtiYlPJ f7b6YZqPrL1rnpcbspYLehT/blCEKqRGz60HALaaZ2uLBG4WUpsRxSzsO6rmU7uP7NFa yq/t9KmtTJa/mxeLx3k03pP7zFgi1m0bMUsNmdb6gH7z97PK52x5so0efmkvDHdyFi2m IuFA== X-Forwarded-Encrypted: i=1; AKwUvByJAYiW1OZ/MtCEY6V1vFf78NoAGsW6xuR7UcLkTsVLlkjyddAXhEhcS8zm0jg329kN5epmMuwV4OE=@lists.linux.dev X-Gm-Message-State: AFuF++nZx0wIWVyeONaJsWdo/4NFgfFR1wu3bFu4ekk4EfjS50RIbR+H Ba2Z9I8SAicsQ7WRVUmKBUuVxMPg3PhavDg0oaVJoByySIacaiSP76m/m+k0dqdB+vJIfmuQ5qF 6/1ruLw== 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) Reply-To: Sean Christopherson Date: Wed, 2 Sep 2026 09:41:09 -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-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" 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