Received: by 2002:a05:7412:8521:b0:e2:908c:2ebd with SMTP id t33csp818860rdf; Fri, 3 Nov 2023 17:03:20 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGlC4Gdgmv34AOmQ2S74iBZVkIHs55NZL8BzsMcGr+wSoPXTucJWaEykKJ9g6P0JgCwShfz X-Received: by 2002:a17:903:22ca:b0:1c7:8446:d65c with SMTP id y10-20020a17090322ca00b001c78446d65cmr23193558plg.43.1699056200435; Fri, 03 Nov 2023 17:03:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1699056200; cv=none; d=google.com; s=arc-20160816; b=08CvCDpfKld/dV/NsiXqQagkt7VqPSQSVlwtj8/NAdZFDv/VsRNJ39aACZi2Giu1F4 a5LGrYa2h4WidIOpsMYaZPs4GYV2o71E7E4OgpIwbrNPFpha3jG5KxT4K6b/XTBePCcI AxgvuTo45e2koP5f9m+5XwaeROq3ZWVk4X8pHaDkrbnh9qEMzezidhpz1nKDrpLD2mD3 aciBtffA4EbtHJFfdxhyIyb4IIZVsfgmAXXH+O9DhQc6+mwcNRGsuoZeqqptBP9LJNso yBVgjTs08UZ0xRfTTDtGKUCKmgFFSwk2QmkwcfXaE2plVhV6a61ph339RGel+Dj7keVD 9iiQ== 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=yY/rmfF8uWP2qcFcrSxU2iBcqr1KyrUXkO4fHTVenYU=; fh=z/UQYx9FUD9Bz9JyYrmi2ijAScp29gktKr8lejSUuXU=; b=xQP0ddfzQqeAythJvw7L4StjOCGTtj4GHiIRLKMdP0DbNbgUNXsslGzI2rMgQELtkg zleesQWHK7uaV7iJKW5wwEnPuod7M2S9quYPk1eWVHPgqIMrzLIuDBE5CRzmtFBMgI0L RhV9rSOQnOnlo1/T+bhDlv9tqy/ud2zbNDX5HWsL2xw6n3YCAXD9qDEz00l+A6T4PtlY SVtdeRBMiWz/OoU1wtxpVN5lDq+uS1D35DsAMNk5F9zAr2yc//73/mr962IsB5D+g9XM cIiZLcjlU0qniJy0RoQt99wxV2qVczOhOtXyKjnHzIcE97LvIXj+5J6SslL1IbG5sNp+ 4s3A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=bVxgGu2l; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 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 agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id q17-20020a170902f35100b001bbf293f45esi2390947ple.625.2023.11.03.17.03.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Nov 2023 17:03:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=bVxgGu2l; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 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 agentk.vger.email (Postfix) with ESMTP id 3636B8198C7E; Fri, 3 Nov 2023 17:03:15 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231590AbjKDADF (ORCPT + 99 others); Fri, 3 Nov 2023 20:03:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54014 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231203AbjKDAC6 (ORCPT ); Fri, 3 Nov 2023 20:02:58 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 92EAED62 for ; Fri, 3 Nov 2023 17:02:53 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-da040c021aeso3008165276.3 for ; Fri, 03 Nov 2023 17:02:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1699056172; x=1699660972; 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=yY/rmfF8uWP2qcFcrSxU2iBcqr1KyrUXkO4fHTVenYU=; b=bVxgGu2lCXmKuMm5QSCv4s4eEQMRPejB9mbV+VIMt8rwNnEbc4fGpD9gfpa/rIO62D a9YtZYAMX9/ZVajKB5TnBX6lraaMPSTFQGbb3kyLxn0b6AFUdHezzYwQviGz2GydGkWr js0oeQM1pRmxbl+jlS/Kk5Im2HNFp2H3XTCuHjtroLJi3sJl7vLc6MNeJrBi73Y+RZw/ yanHmcJyR6NWW5VC96HE+sxYFKF/MkbkWAu43pvYUWD61Peq0k/g2ztgNUCEOmPR6Ez/ blcVDM8flPsc/ljnxrf6iaeVLAXE0pTXboK1+CrKOv01ZvOPz8i4fsyCGEIxQSpkV+fi /BWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699056172; x=1699660972; 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=yY/rmfF8uWP2qcFcrSxU2iBcqr1KyrUXkO4fHTVenYU=; b=Be2ESMbya+3/fkCULnf9dHKN+8EpcQQNEfllQiyKySNYKT7Jq8kDcq/3sH+QHIUAUg xrQyDa0de7EQc4f2vm8Xk2BNx9PW9cQpIG8PFg65B01lP8zohKGJkMxTWxMKiYUjEUKb FNeW3qKCxU9oxDqgmA4x6dI3vPjk3U4IPVrDyHMK1G6K77XBxlMEwNGVvXWTzgGqI7AF 4CR5Fh4ZZVCU2Be1N0/7Ti6Rcc+c//XRuwsjwPCDlg69/lyP7DRflcooZ1suOmblWml7 dVx8iDjCm9p7lUVK29I6msXMlLJcCvgSzd/KnEqD7leY+EemP0/WuIMtjHdgp22KqEfR 39uw== X-Gm-Message-State: AOJu0YyxeZX0neWBv3lDfaEB9xYFpS1p755F6cw7oiQOyLPFLi5WXPn9 cPeGECqChfrm/6GWaMqN5fvu4a4vmZM= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a25:9011:0:b0:da0:4f83:60c1 with SMTP id s17-20020a259011000000b00da04f8360c1mr432157ybl.9.1699056172262; Fri, 03 Nov 2023 17:02:52 -0700 (PDT) Reply-To: Sean Christopherson Date: Fri, 3 Nov 2023 17:02:24 -0700 In-Reply-To: <20231104000239.367005-1-seanjc@google.com> Mime-Version: 1.0 References: <20231104000239.367005-1-seanjc@google.com> X-Mailer: git-send-email 2.42.0.869.gea05f2083d-goog Message-ID: <20231104000239.367005-7-seanjc@google.com> Subject: [PATCH v6 06/20] 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 , Jinrong Liang , Like Xu , Jim Mattson , Aaron Lewis 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,T_SCC_BODY_TEXT_LINE, 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 agentk.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 (agentk.vger.email [0.0.0.0]); Fri, 03 Nov 2023 17:03:15 -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.869.gea05f2083d-goog