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 B0BF8C61DD6 for ; Wed, 2 Sep 2026 16:42:17 +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=SeJnYNm/30DDrGtlzlyhX4F8Ff+qodk8muwORsydLHQ=; b=uvrgtZtGdftX0Gdrldez5TCCYq 0gNnoRSXE9gqTgzGOlApDYgYrlTaMLHZFrk0+6uTsyfZp5gvNBEr7cL3w0qZna2szsksf0N2SX8nQ km+UB/YUB/lsRBGTRyzPm7u79SZ5gcP9TUl3NDECqRyYppakxd9h16L/VHWKmnjQo7SODjLau+RgJ Tit4Ds8T1Trx2dagNVOjazuAv0y5axTsM/KYFqiyIVdppBwlY2n5aDI+fnilP+p6fxQnkcE28uS/H Gzer6qn14gAKfZ2kMQIRIAsRj3AEb1oUVXUXaCNGBA3IvgkyWCnXt3A/ecphQhMuLOhzldrK5DOJ1 XCIQvdmg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1x1o2G-0000000FFDl-2Zel; Wed, 02 Sep 2026 16:42:04 +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 1x1o1u-0000000FERL-2Nv6 for linux-arm-kernel@lists.infradead.org; Wed, 02 Sep 2026 16:41:47 +0000 Received: by mail-pj1-x1046.google.com with SMTP id 98e67ed59e1d1-399311947f6so2395331a91.0 for ; Wed, 02 Sep 2026 09:41:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1788367301; x=1788972101; 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=SeJnYNm/30DDrGtlzlyhX4F8Ff+qodk8muwORsydLHQ=; b=r2lfLO9uOoaV5wSHpzvDukz8rXqueOIeZfc3QS6Q5Q86LfsrczrpLKtl1a0wPAVsf6 auXyzqABMtUVQI0aLnYkAys0wc49D3SGB4Jg403T7xxXalLQy1JK5YH/UsrN7V0qK7p8 C1Ix5hblwguvM5oXokEscY3vZ5Kj+f+EA6Ce0ENtoxhUalUl+YDCC4LSCegV4wnghC3X U1Dvyil/7hrD3kgK1nrJTM7mcobdG2qDMhwYC4Yr9h31wr3ACVo5BzYhTYzSWkBCOEAW lw+w5N1+G6VQ6bz0oGr76kL/JjR10MoIst/xJ+sBeSZuYmK8cAe+Ut3WUM3Ygxf4RZX6 XZHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788367301; x=1788972101; 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=SeJnYNm/30DDrGtlzlyhX4F8Ff+qodk8muwORsydLHQ=; b=f9JQ1nJpzxL8/pmvcsdza0uSkMuvguZZ/ah140UqpuslX0m+OIS4E0QHkE1LdlWpZL Q5B1ODIhpM2Nq/gy9FowYW+4rUQ8EipDlIUDu9fyoEb6G7AzTPvgr5ArhxD0wZ1IiOka zz+kzvkL9knc7w40SJ/8A2UbogqnTXisy/GS3gqsVgaSkvddsJ723Pfh1gq7KD9qrtfs Akl5P+B0jYjvQ1cXvL2hSgqDL4ZSCWQwCxL38/soGaDoSsYC4lLgECzHigJ7pxF02NtM m0FhgFiYaGF7BNrvq7liZxZObnI5m2R2z3p9+V55L+ED0SqTSnHM6qlgcrpEsc1h8mFy i7Qg== X-Forwarded-Encrypted: i=1; AKwUvBzqBjJpnsJ1X/QUfvWU98wuUpSIpAk5q6AL3+4jy+CaMYvghFmmiGRtmOrwaReqpnNOxmP89EISnLHPo+3rYfCv@lists.infradead.org X-Gm-Message-State: AFuF++lfWaE3CdHMsZrjpa/4E5ZXkwWGyvZDPCQViDPgiKOFk94xEACd /n/RcHBdzJ5s1bn1O2wobAjA2ybrzX6m7DHriyFJMElHFlTwrSoRYhVCWCsbhvHZLEYSCRbmxrA bzL+8Xw== X-Received: from pjan2.prod.google.com ([2002:a17:90a:1602:b0:398:9c5e:d8f2]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:4ac9:b0:398:9bd5:490c with SMTP id 98e67ed59e1d1-39aee0b498dmr7421235a91.19.1788367300525; Wed, 02 Sep 2026 09:41:40 -0700 (PDT) Date: Wed, 2 Sep 2026 09:41:16 -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-14-seanjc@google.com> Subject: [PATCH v2 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, 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_094142_673821_7F9140D9 X-CRM114-Status: GOOD ( 21.94 ) 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. Tested-by: Itaru Kitayama Signed-off-by: Sean Christopherson --- .../testing/selftests/kvm/include/kvm_util.h | 39 ++++++++++++++++--- tools/testing/selftests/kvm/include/x86/smm.h | 2 +- .../testing/selftests/kvm/lib/x86/processor.c | 7 ++-- 3 files changed, 39 insertions(+), 9 deletions(-) diff --git a/tools/testing/selftests/kvm/include/kvm_util.h b/tools/testing/selftests/kvm/include/kvm_util.h index c8faa8a02b93..b6b96d6978b2 100644 --- a/tools/testing/selftests/kvm/include/kvm_util.h +++ b/tools/testing/selftests/kvm/include/kvm_util.h @@ -82,11 +82,45 @@ 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 except TEST_EXTRA are mapped to memslot '0'. The + * TEXT_EXTRA region is left unmapped as it's intended to be used only for test + * specific allocations, i.e. should never be used by core/infrastructure code. + * 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 +163,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.966.g6673acef38-goog