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 EE8D2C5DF97 for ; Wed, 26 Aug 2026 23:06:42 +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=Qrd3Eszpzuyl+ARXBwnNOR4mn5401Rmq7plszPl1Tnk=; b=uJeCtJanOwNzapF34VW1SW2YnA jykrZH6WHQg1oEeS5Pt6RGQyBXeJIVOpnPG69QzIo8e49hvHWdbOXWUvwRH7cFILaAzzfx6OiiPJW zCJVteEWua+/r7M74OBiLrNg7VjGI0mJi2HLMXrjLQMcFMTdhwOq7LQpdQ87nuN+mRpNfcd7dyFLY i1ggSUN2q7W5bJ93Dzx+WVL7syzgH15Rk5+yCBtgCAET2ozI5xf9X3G7Tzu0dLX8H8CLf29c2s4K9 AL1qnIJzXlARBoxqDLvwsxthBdkIKCoABy+BnouegkwK2v3nkzZwPJtJEzetIzD+S6odfdwyXdrln nLlzggUg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1wzMhY-000000037jq-0Icj; Wed, 26 Aug 2026 23:06:36 +0000 Received: from mail-pl1-x648.google.com ([2607:f8b0:4864:20::648]) by bombadil.infradead.org with esmtps (Exim 4.99.1 #2 (Red Hat Linux)) id 1wzMgX-000000036KC-42uM for linux-arm-kernel@lists.infradead.org; Wed, 26 Aug 2026 23:05:39 +0000 Received: by mail-pl1-x648.google.com with SMTP id d9443c01a7336-2ccb687f82eso20151765ad.3 for ; Wed, 26 Aug 2026 16:05:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1787785533; x=1788390333; 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=Qrd3Eszpzuyl+ARXBwnNOR4mn5401Rmq7plszPl1Tnk=; b=l2NXdeVdjS6cSKM7Aq6uj8THw1h9YZINVS0iBhYVz4iTxQZsg76VpZJmUr/j04gvo6 i/hK8Z0bP+97YjKTy/s6LxnP5pv0TM2UYj+6E39c9yPWXXPu8G3z7pIsVaeg1F+jkK8D C2EuRmdYOkrguuJ4AeRKAxNf9CT5900JLTTZJjOjm77vJ6MqtI6aZtN9gcKHXnhkaPH+ xGrqr0sDUO4VcY71wlFks91soRo7NrsuNRYftChDpgLQtviNSWJq/9TmYF9uEGq6ROx+ mX1hGHUVlu3rN8l2JIpwFwWE71KukRJN3v0eHTc/QRJHATR4uzpRIVwu6HGqGytmZ5Mf 9wIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787785533; x=1788390333; 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=Qrd3Eszpzuyl+ARXBwnNOR4mn5401Rmq7plszPl1Tnk=; b=Lwt/p2JqA9zyu197agoW2iYOMbzcmXr2Tv3M5FtK7AUW9CdKXG9O2EGVZar0WgQuOP XV+cy6MUt8OtrrKqaRKEbOTLHH3vK75eY2Y/hsV1R76UkKCFQm5FkpZbuE60MGy8tSyn rjse0chidabCj+xShVvl+DIsh//TPEkV45Q4+2uBPrc6KmJJCEvR81t6MRq0/yU8eQ2B zdlszjW588tSRPl1erpCTjdvmSCTWJfvdDpZ6olclPWJnW7wwtMDVQXbqbkQwZZr63if /isK1D71WU0pNd2zxd92KTv0AMU/AeFxOCk8HKVUTUSkhkHhgzAcX/mxfubYWq8JJEuq smbw== X-Forwarded-Encrypted: i=1; AHgh+RrrijdZs1d+MY6YmatUFbN41NbOgsNIDwd0/35oWQLskDHqgw5E6w+/hIGSWctiBhlOesMOAhb8xV+uW7wFjg+z@lists.infradead.org X-Gm-Message-State: AFuF++lOHaH7gboMWQgcD0n3pe46NcB3PMgZ/fl6THgQpwxId7ycFPsq Yb3t2TLaGQBwOp7iwGS1riL+1PFwIRUpDsA26hGtJl9MWFLhvKnwGK94ZPmxKkoKTzYWQxR8fZN z5fYCJQ== X-Received: from plfn5.prod.google.com ([2002:a17:902:e545:b0:2cc:fd6e:8ff3]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a17:903:32c9:b0:2c9:df1b:e948 with SMTP id d9443c01a7336-2d7079eb7e9mr183803125ad.4.1787785532402; Wed, 26 Aug 2026 16:05:32 -0700 (PDT) Date: Wed, 26 Aug 2026 16:05:04 -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-14-seanjc@google.com> Subject: [PATCH 13/20] KVM: selftests: Add TEST_EXTRA memory region type for "special" memslots 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_160534_159145_BB3C0BB0 X-CRM114-Status: GOOD ( 19.53 ) 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 And another memory region type to deal with extra, one-off memory regions, and use the new type to manage x86's SMRAM memslot, as another step towards taking the region type instead of the raw memslot in the physical page allocator APIs. Alternatively, SMRAM setup could simply use the quad-underscore API to continue passing in the memslot, but a surprising number of tests use an "extra" memslot for a variety of reasons. I.e. allocating memory from one (and exactly one) extra memslot isn't all that rare, and so should be treated as normal behavior, not as something extraordinary, as quad-underscore functions typically suggest. Opportunistically add comments to document the intended usage of the types, as the difference between DATA, TEST_DATA, and TEST_EXTRA in particular isn't exactly obvious. Signed-off-by: Sean Christopherson --- .../testing/selftests/kvm/include/kvm_util.h | 37 ++++++++++++++++--- tools/testing/selftests/kvm/include/x86/smm.h | 2 +- .../testing/selftests/kvm/lib/x86/processor.c | 7 ++-- 3 files changed, 37 insertions(+), 9 deletions(-) diff --git a/tools/testing/selftests/kvm/include/kvm_util.h b/tools/testing/selftests/kvm/include/kvm_util.h index 14f87c8a00ec..f4f4f360a10b 100644 --- a/tools/testing/selftests/kvm/include/kvm_util.h +++ b/tools/testing/selftests/kvm/include/kvm_util.h @@ -82,11 +82,43 @@ struct userspace_mem_regions { DECLARE_HASHTABLE(slot_hash, 9); }; +/* + * Memory region types are passed to various page allocators to communicate + * various properties and metadata related to the allocation. Note, the + * descriptions below described the primary usage of each type. Individual + * tests may allocate memory for other purposes. + * + * By default, all regions are mapped to memslot '0'. Tests can override the + * memslot for any or all types, e.g. so that all test data is allocated from a + * curated memslot. + */ enum kvm_mem_region_type { + /* + * The CODE region is used by lib/elf when loading the test's code into + * guest memory. + */ MEM_REGION_CODE, + /* + * The DATA region is used to allocate core data structures, e.g. vCPU + * stacks, VM exception tables, x86's TSS, etc. + */ MEM_REGION_DATA, + /* + * The PT region, a.k.a. Page Table region, is used to allocate page + * table pages. + */ MEM_REGION_PT, + /* + * The TEST_DATA region is used for allocating test data that is either + * test specific, and/or isn't considered a "core" data structure. + */ MEM_REGION_TEST_DATA, + /* + * The TEST_EXTRA region is for special snowflakes, where a test wants + * to create and use a one-off memslot, without impacting "normal" test + * data allocations. + */ + MEM_REGION_TEST_EXTRA, NR_MEM_REGIONS, }; @@ -129,11 +161,6 @@ struct kvm_vm { struct kvm_binary_stats stats; - /* - * KVM region slots. These are the default memslots used by page - * allocators, e.g., lib/elf uses the memslots[MEM_REGION_CODE] - * memslot. - */ u32 memslots[NR_MEM_REGIONS]; }; diff --git a/tools/testing/selftests/kvm/include/x86/smm.h b/tools/testing/selftests/kvm/include/x86/smm.h index 2d1afa09819b..15faaa060126 100644 --- a/tools/testing/selftests/kvm/include/x86/smm.h +++ b/tools/testing/selftests/kvm/include/x86/smm.h @@ -8,7 +8,7 @@ #define SMRAM_MEMSLOT ((1 << 16) | 1) #define SMRAM_PAGES (SMRAM_SIZE / PAGE_SIZE) -void setup_smram(struct kvm_vm *vm, struct kvm_vcpu *vcpu, u64 smram_gpa, +void setup_smram(struct kvm_vm *vm, struct kvm_vcpu *vcpu, gpa_t smram_gpa, const void *smi_handler, size_t handler_size); void inject_smi(struct kvm_vcpu *vcpu); diff --git a/tools/testing/selftests/kvm/lib/x86/processor.c b/tools/testing/selftests/kvm/lib/x86/processor.c index ea5fa59888af..b988eea373ad 100644 --- a/tools/testing/selftests/kvm/lib/x86/processor.c +++ b/tools/testing/selftests/kvm/lib/x86/processor.c @@ -1468,11 +1468,12 @@ bool kvm_arch_has_default_irqchip(void) return true; } -void setup_smram(struct kvm_vm *vm, struct kvm_vcpu *vcpu, u64 smram_gpa, +void setup_smram(struct kvm_vm *vm, struct kvm_vcpu *vcpu, gpa_t smram_gpa, const void *smi_handler, size_t handler_size) { - vm_userspace_mem_region_add(vm, VM_MEM_SRC_ANONYMOUS, smram_gpa, - SMRAM_MEMSLOT, SMRAM_PAGES, 0); + vm_override_mem_region(vm, MEM_REGION_TEST_EXTRA, VM_MEM_SRC_ANONYMOUS, + smram_gpa, SMRAM_MEMSLOT, SMRAM_PAGES); + TEST_ASSERT(vm_phy_pages_alloc(vm, SMRAM_PAGES, smram_gpa, SMRAM_MEMSLOT) == smram_gpa, "Could not allocate guest physical addresses for SMRAM"); -- 2.55.0.887.g758fc8c411-goog