Received: by 2002:a05:7412:251c:b0:e2:908c:2ebd with SMTP id w28csp1566257rda; Mon, 23 Oct 2023 17:27:17 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH+GWV2WJOnTHL0z+s00CMXklfQ60jz4+sD0cZX8cUlpYuFEsIuWrrgdQA+iDjSFeUtjQ4Q X-Received: by 2002:a17:90a:af84:b0:27d:28ad:3086 with SMTP id w4-20020a17090aaf8400b0027d28ad3086mr8109248pjq.2.1698107236769; Mon, 23 Oct 2023 17:27:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698107236; cv=none; d=google.com; s=arc-20160816; b=YeSRFvgXObP34ju7Dq546i118lTzyinuzWbJ5wTDI08BDLlyTrHNKCW/vMyeK18air 6TI1JemPKPQAt9JQUVKoMK2/12eDpblH4RIzmiGhJ5wf8ffubrGJOktIULlEoc0RDbj5 m4cnLI3Cn0UVkQrJraoKE6YyxHFpNgozZ7zULpqdr5Orrhi67YJwtZRSaMt0VbmnypM4 33XOLJ0w57Ff6zkZCC7TMfZ/q1beIdUjUytlVsKp2VvtTVdnghb2kc8gc8ibik+bqtrz SXGqNNQjEiJXDFU8gQ/z0sfEg2PfiyORcklf3XFiKKR2yW1sFTmATQbbJV7C0TenBALu Uugw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:reply-to:dkim-signature; bh=F8dxA5PYrMgcC3TCFQUnjkCAgDkYN5FCICeYb/ZzON0=; fh=D//PLXZS63mgWSQM2kcZZyW+2k64a7rh3i2k12EZPR4=; b=vs4YCV1ejiLfBNv6JQ/s+Yr5/G1tRO+M2FgtTjr05ps0U6nWH7UPrsuiJxaNiVOK0G 9BnvdS+4dyvh/1cCL2hCn1iRqy+SBOMBtEdpu8f8G/v+7GSj3Ytoh8gzP0gAUJ0ytHOc nwDie+xjyR7L2a/ZdFT8FVeApw2nMUN1Ln4QZRla+GShTHxZFnhmTouK0OrRzu1Tk7JE nOkmo3rBAX4LaLL5G7kxOEm/jvZSCG+GZU6LtFCMJ9bDfI+egRLfAsghvX0gJxn09Gbm 0z1a5CkC/VrGwVkgIdpywf3y3PxpVKzryFpPT2cq5qgKdDF5wPBpihNW/+ggvW7SDrdu rEtQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=3ANCsRAO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id t2-20020a170902bc4200b001c36705bce1si6908020plz.474.2023.10.23.17.27.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Oct 2023 17:27:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=3ANCsRAO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id A39FD802FDF4; Mon, 23 Oct 2023 17:27:12 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231726AbjJXA0x (ORCPT + 99 others); Mon, 23 Oct 2023 20:26:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41828 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231725AbjJXA0q (ORCPT ); Mon, 23 Oct 2023 20:26:46 -0400 Received: from mail-pl1-x64a.google.com (mail-pl1-x64a.google.com [IPv6:2607:f8b0:4864:20::64a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BBCC210D for ; Mon, 23 Oct 2023 17:26:44 -0700 (PDT) Received: by mail-pl1-x64a.google.com with SMTP id d9443c01a7336-1c9c83b656fso32912225ad.1 for ; Mon, 23 Oct 2023 17:26:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1698107204; x=1698712004; 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=F8dxA5PYrMgcC3TCFQUnjkCAgDkYN5FCICeYb/ZzON0=; b=3ANCsRAOhw2Bys8XhAYGao+LqGKuUu60I6BcYMOl9QOwq9ONFG9TSzR7Db/ay/LHFA Xd8NBJ+hpOPC/ocdqgLZnBu5DE/fOTJ90krxvyQ2J5UJk9h8Pz0y7r9m0LIBN2dnPy8D wWBUmtudodW93UWc3NQdUIAdL1RWCFlkRce3lR+535kkwWn8yZFvMicZtm8MEC1qDk/5 5lcT0fugNM7bDMb4eJgdP4qsw1Vy2qpTUkfOC3OuBaxuye0wAY8lk0XVXrvvRjBk+zQI lBUNt2mdmDA+q/X/U+0ipYte8bmyhk9lhbMjjQradhvWUDxGmKBEMF/Q+8RSWsYhyd4W Xx2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698107204; x=1698712004; 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=F8dxA5PYrMgcC3TCFQUnjkCAgDkYN5FCICeYb/ZzON0=; b=YeDPpcpsA9d56HW4RKf5dSw/tCCTgZDNvxajfo5V783FSaO6z7D5GH94kX7/UMop6g CNwifPIDsOif6zuQxdeibTh3gw9Wz9KqSMPb5ibRQrSBsOydP51eDrza8QNrQORx2X4m oEqHPjBuydA9f0preMHwDqsWAUA00H+Fav0QM1KUpaSdOV8wCppOhVBJBfviFhzcJSxE uB3xgfPv24+zy/yP2SKr9UJPiK454cyjsM48QRRGrJKebMykKNUxfcGnCq7ksPXlq9fo VN6ugV+krmiz3qQXdcHeGuh3NHVJw5W6MhnjQrQyFldiskHwC/MmM3KGyIoQ9099T3tt yPng== X-Gm-Message-State: AOJu0Yw2L+sO2nGSYxbs6w38Sj9g/zGHFDTa/Z/nJA8sKvoTK2Tg/zw3 TA8jPifvTnUWdPtm8/ex4b/IWwWyZzI= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a17:902:c1d4:b0:1bc:2547:b17c with SMTP id c20-20020a170902c1d400b001bc2547b17cmr202838plc.1.1698107204068; Mon, 23 Oct 2023 17:26:44 -0700 (PDT) Reply-To: Sean Christopherson Date: Mon, 23 Oct 2023 17:26:24 -0700 In-Reply-To: <20231024002633.2540714-1-seanjc@google.com> Mime-Version: 1.0 References: <20231024002633.2540714-1-seanjc@google.com> X-Mailer: git-send-email 2.42.0.758.gaed0368e0e-goog Message-ID: <20231024002633.2540714-5-seanjc@google.com> Subject: [PATCH v5 04/13] 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, Jinrong Liang , Like Xu Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Mon, 23 Oct 2023 17:27:12 -0700 (PDT) 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 --- .../testing/selftests/kvm/include/x86_64/processor.h | 4 +++- tools/testing/selftests/kvm/lib/x86_64/processor.c | 12 +++++++++--- .../kvm/x86_64/smaller_maxphyaddr_emulation_test.c | 2 +- 3 files changed, 13 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..9e717bc6bd6d 100644 --- a/tools/testing/selftests/kvm/lib/x86_64/processor.c +++ b/tools/testing/selftests/kvm/lib/x86_64/processor.c @@ -752,11 +752,17 @@ 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); } 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.758.gaed0368e0e-goog