Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F013F33D6 for ; Wed, 8 Nov 2023 00:31:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="ECT3kBiH" Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1534E10FE for ; Tue, 7 Nov 2023 16:31:50 -0800 (PST) Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-da2b8af7e89so7557226276.1 for ; Tue, 07 Nov 2023 16:31:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1699403509; x=1700008309; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=V1aBnNwJk8GR2J7q9EpiLV4j0BFKjZECzb8pGjdIuF8=; b=ECT3kBiHnT47vcqj67ZBkiRtuPrdVkOyqQ106DWa87K1l4jHc0gkTbSPUxX+uTKuUy d49jrQn43VjO2WPVmPG6OPFDnDYIgso4YyWdB2uXZf7jvNycF6zoo2wOh2v7ncSWxv1f Y8SSrgh1Bda5SgWT12A1MiL8+ZcnS5LJBRHPank9r+0QC0zPbZuU/cJI4h7ZVHMdAs3x 0TdiDnj89yglCsQi3qnyUjYuUxiSsXTmVswIt/4MBPUOwFnlcS8MUfkETRzFqXm/lSsG 7zFOhW5aMfhsWYF28DdvpwyBoxwE19CTPCSKGxqt9njYqfHhhM+s+7ck0VDXr9lRwFDv qDEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699403509; x=1700008309; h=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; bh=V1aBnNwJk8GR2J7q9EpiLV4j0BFKjZECzb8pGjdIuF8=; b=NahuQ6deXdb2vT7pMaPJ4OvotyPGalZKLNkZ83TU+RRh52hhh0td8lyYKoKLJUacTX Picsku+BrF2DOzyXpWLeHOH9x6xO9iqdxXyI6wNLFBMproQ1/jwoUXkLUJhilsqkdNPY JndCiti9BFEA89NsXcwhplLHdrO5j3V3ZwQRKhKqiOmwjXhBaAENmq73qup+L7mnDOti sW1UzHAcDAULEQF5LzhNzKTb9ON8fUhgtcXOjSjdjY6ZcbJq71EZGQnDeaZqRQUH2dmR boqEi7llU3Lpg6BYM40M7uvP2HsQnRIhl1nPMTchQ3o40/IRnvvxjyo6cSui3bP96s+e mGQg== X-Gm-Message-State: AOJu0YzyVE/SBowY+UQGTWiv9ILSgCQarvf7rrDwed6YczIHWOPxTHv8 1CZaQ7DseaMF4+OcSZCmdCtZC1TgltM= X-Google-Smtp-Source: AGHT+IFpFgpdesozaHjv4FfzuGZeZNvtK0EvXpVTarcXHPdSNJKE60f2aVyuBNbz+rubfLmfL0hDmRfgB9s= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a25:e04f:0:b0:d9b:e3f6:c8c6 with SMTP id x76-20020a25e04f000000b00d9be3f6c8c6mr5638ybg.4.1699403509176; Tue, 07 Nov 2023 16:31:49 -0800 (PST) Reply-To: Sean Christopherson Date: Tue, 7 Nov 2023 16:31:21 -0800 In-Reply-To: <20231108003135.546002-1-seanjc@google.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20231108003135.546002-1-seanjc@google.com> X-Mailer: git-send-email 2.42.0.869.gea05f2083d-goog Message-ID: <20231108003135.546002-6-seanjc@google.com> Subject: [PATCH v7 05/19] KVM: selftests: Add vcpu_set_cpuid_property() to set properties From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Kan Liang , Dapeng Mi , Jim Mattson , Jinrong Liang , Aaron Lewis , Like Xu Content-Type: text/plain; charset="UTF-8" From: Jinrong Liang Add vcpu_set_cpuid_property() helper function for setting properties, and use it instead of open coding an equivalent for MAX_PHY_ADDR. Future vPMU testcases will also need to stuff various CPUID properties. Signed-off-by: Jinrong Liang Co-developed-by: Sean Christopherson Signed-off-by: Sean Christopherson --- .../selftests/kvm/include/x86_64/processor.h | 4 +++- .../testing/selftests/kvm/lib/x86_64/processor.c | 15 ++++++++++++--- .../x86_64/smaller_maxphyaddr_emulation_test.c | 2 +- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/tools/testing/selftests/kvm/include/x86_64/processor.h b/tools/testing/selftests/kvm/include/x86_64/processor.h index 25bc61dac5fb..a01931f7d954 100644 --- a/tools/testing/selftests/kvm/include/x86_64/processor.h +++ b/tools/testing/selftests/kvm/include/x86_64/processor.h @@ -994,7 +994,9 @@ static inline void vcpu_set_cpuid(struct kvm_vcpu *vcpu) vcpu_ioctl(vcpu, KVM_GET_CPUID2, vcpu->cpuid); } -void vcpu_set_cpuid_maxphyaddr(struct kvm_vcpu *vcpu, uint8_t maxphyaddr); +void vcpu_set_cpuid_property(struct kvm_vcpu *vcpu, + struct kvm_x86_cpu_property property, + uint32_t value); void vcpu_clear_cpuid_entry(struct kvm_vcpu *vcpu, uint32_t function); void vcpu_set_or_clear_cpuid_feature(struct kvm_vcpu *vcpu, diff --git a/tools/testing/selftests/kvm/lib/x86_64/processor.c b/tools/testing/selftests/kvm/lib/x86_64/processor.c index d8288374078e..67eb82a6c754 100644 --- a/tools/testing/selftests/kvm/lib/x86_64/processor.c +++ b/tools/testing/selftests/kvm/lib/x86_64/processor.c @@ -752,12 +752,21 @@ void vcpu_init_cpuid(struct kvm_vcpu *vcpu, const struct kvm_cpuid2 *cpuid) vcpu_set_cpuid(vcpu); } -void vcpu_set_cpuid_maxphyaddr(struct kvm_vcpu *vcpu, uint8_t maxphyaddr) +void vcpu_set_cpuid_property(struct kvm_vcpu *vcpu, + struct kvm_x86_cpu_property property, + uint32_t value) { - struct kvm_cpuid_entry2 *entry = vcpu_get_cpuid_entry(vcpu, 0x80000008); + struct kvm_cpuid_entry2 *entry; + + entry = __vcpu_get_cpuid_entry(vcpu, property.function, property.index); + + (&entry->eax)[property.reg] &= ~GENMASK(property.hi_bit, property.lo_bit); + (&entry->eax)[property.reg] |= value << property.lo_bit; - entry->eax = (entry->eax & ~0xff) | maxphyaddr; vcpu_set_cpuid(vcpu); + + /* Sanity check that @value doesn't exceed the bounds in any way. */ + TEST_ASSERT_EQ(kvm_cpuid_property(vcpu->cpuid, property), value); } void vcpu_clear_cpuid_entry(struct kvm_vcpu *vcpu, uint32_t function) diff --git a/tools/testing/selftests/kvm/x86_64/smaller_maxphyaddr_emulation_test.c b/tools/testing/selftests/kvm/x86_64/smaller_maxphyaddr_emulation_test.c index 06edf00a97d6..9b89440dff19 100644 --- a/tools/testing/selftests/kvm/x86_64/smaller_maxphyaddr_emulation_test.c +++ b/tools/testing/selftests/kvm/x86_64/smaller_maxphyaddr_emulation_test.c @@ -63,7 +63,7 @@ int main(int argc, char *argv[]) vm_init_descriptor_tables(vm); vcpu_init_descriptor_tables(vcpu); - vcpu_set_cpuid_maxphyaddr(vcpu, MAXPHYADDR); + vcpu_set_cpuid_property(vcpu, X86_PROPERTY_MAX_PHY_ADDR, MAXPHYADDR); rc = kvm_check_cap(KVM_CAP_EXIT_ON_EMULATION_FAILURE); TEST_ASSERT(rc, "KVM_CAP_EXIT_ON_EMULATION_FAILURE is unavailable"); -- 2.42.0.869.gea05f2083d-goog