Received: by 2002:a05:7412:8521:b0:e2:908c:2ebd with SMTP id t33csp1076652rdf; Sat, 4 Nov 2023 05:52:15 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGdEDnFce0NlNBwYlcs1O0AeqZXcQduA0PwlvZccXfeWaOKOyGyTQNx0n13blyENoIb4qPx X-Received: by 2002:a05:6a00:3929:b0:68b:f529:a329 with SMTP id fh41-20020a056a00392900b0068bf529a329mr23507885pfb.5.1699102335151; Sat, 04 Nov 2023 05:52:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1699102335; cv=none; d=google.com; s=arc-20160816; b=wrqoU/nxYBGbVB4Xjyvw0/pWrtJP70zg8ydkSqGJ6qn+bZZ7RPMtkc4+cyHXKS1fW6 GJoz0wYnbpDdRKWdvut3CdPYdyQxOEdmz5WOlQGmSH7Aj3ipKWLZQIHY7yQ1+AWu6CJi XpE6VsIoHHWkQra06CXTME/CQPLwYmnd59V/usZFzxBs+AztoxulocMHqMcQm5uOqCQE 0q36BWepw4FEiup2fPuGJalLQbkx+wRyMZ8PDUPWtWliU8eRxMHRh0asMa7dXxxnWLR1 6L4ZVnNcYqCClIKzk3nWqvr3HOERsDUkWgvez5pOAQvD181CRJqdYcwfCCA+aos4bNM3 4G5g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=V2AIE4p4WRtdyGEtqiMMAREra62fDWl2hz5iPPeenLI=; fh=+P/YAw2zernQMYCM+6PO88cyfvFWVdhqutSbGYwZXbc=; b=uclF27jJ/kcoJPsiZbpjg4ppQR7S9z52vFqrIgliQBE8p23xzpEQpbow1GSY+1ph/i EobMeW/SxomqU11ALRz8BbT9n/P88UnqgObM0ppCe2ummdngkljSehTA/2UOivZzoYbB rAP93F7teQXwqz7hitAf+UEMIL9EDarkEc4oKGbMYfbLRJPffp6WOafzuaj0/OC9WYWO jTnuqt3XvxIOHZ3dm3Oro6FTkigYT4e0+CyadWnx7qQ7fZXcvYSqxbaN65soRl1NquUX 8VgDVvaf8S+gPyXOhk6XOgfvzDLUXiagORbtA1SI2xBTOiKDjRKxnQEtDe+f/+ktGztw 1bfg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=RXPhzG7k; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 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 fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id cj11-20020a056a00298b00b006c0035ff9dasi3662156pfb.198.2023.11.04.05.52.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 04 Nov 2023 05:52:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=RXPhzG7k; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 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 fry.vger.email (Postfix) with ESMTP id 7C8F0809C909; Sat, 4 Nov 2023 05:52:12 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230151AbjKDMwC (ORCPT + 99 others); Sat, 4 Nov 2023 08:52:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49098 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229456AbjKDMwB (ORCPT ); Sat, 4 Nov 2023 08:52:01 -0400 Received: from mail-ed1-x52a.google.com (mail-ed1-x52a.google.com [IPv6:2a00:1450:4864:20::52a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7548D1B2 for ; Sat, 4 Nov 2023 05:51:58 -0700 (PDT) Received: by mail-ed1-x52a.google.com with SMTP id 4fb4d7f45d1cf-54366bb1c02so3721a12.1 for ; Sat, 04 Nov 2023 05:51:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1699102317; x=1699707117; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=V2AIE4p4WRtdyGEtqiMMAREra62fDWl2hz5iPPeenLI=; b=RXPhzG7kV/uuD1QgBw6ZDyEWL0RwPFIZpJiZSmZ46uBbvuIzkOS57NXghzaj3JwJts BescPL0P3Sx7Xny3ryiDZqP/tA33oFLm3OKDXgfrLnrsLwA0ThZ7CyGco332boEhTtg+ kxP6i/CRrCz9MwvW6MnXxzd6Xd9kePkBQICze7lib4xRMKVBVOo/kJRFDN3UiMtTo2x1 YZs5rzsbEmggHyxNBgXUOc5rbpq8V632gh83ZraoWiJankFRM4QE9S27qMq3vmWGtgMJ rrbSRguQK46GcVzDz99A6KM0fDsbdmzrXh17VZyjCbT0//3KH3RwH9CQ9c+n8y6XdiOY Gxkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699102317; x=1699707117; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=V2AIE4p4WRtdyGEtqiMMAREra62fDWl2hz5iPPeenLI=; b=TN2dQfxNajY35rf2LrO9n4RXc4nZVgkjBtbeJooEbECyJHWaU86N/tLPqQvKavWQmq Y61itRJ26Qd6aNYqKpAZWbZA5wtz3jtxCP2xm7xIEHyYuOSajpJJ+pjprZqZX3EoK6Ur GrlAxHEvYD96Oa0uvCasOhMsMILvQC/CDaCw1fqWqD/YppgoPvN8K4hutjLWGbsFeSrT ldjif3pjtmmvar7RzPZDrSeaOAwsGRiqShmSrN0gF+E2krkHg4WjyHr7geMtYJGL+433 kGybEI2UvJSf2zxY75P4tPawc58s1F0t4kRjOvwZ6XIGv5SvC6saLAJNn6RIX0hbXkq3 ZD/A== X-Gm-Message-State: AOJu0Yxq24vDYMWVYQZv55Q9fmIbPXEK48UOTgal9LmyRVcurC9R6ERr Srnt5Ux1cx3dyAdNWuug1EV3mDgioRKbTsd805LbmZPQNmwCNuCCy/NhuA== X-Received: by 2002:a50:9b07:0:b0:543:fc4f:b7ac with SMTP id o7-20020a509b07000000b00543fc4fb7acmr56154edi.7.1699102316747; Sat, 04 Nov 2023 05:51:56 -0700 (PDT) MIME-Version: 1.0 References: <20231104000239.367005-1-seanjc@google.com> <20231104000239.367005-7-seanjc@google.com> In-Reply-To: <20231104000239.367005-7-seanjc@google.com> From: Jim Mattson Date: Sat, 4 Nov 2023 05:51:45 -0700 Message-ID: Subject: Re: [PATCH v6 06/20] KVM: selftests: Add vcpu_set_cpuid_property() to set properties To: Sean Christopherson Cc: Paolo Bonzini , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Kan Liang , Dapeng Mi , Jinrong Liang , Like Xu , Aaron Lewis Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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 fry.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 (fry.vger.email [0.0.0.0]); Sat, 04 Nov 2023 05:52:12 -0700 (PDT) On Fri, Nov 3, 2023 at 5:02=E2=80=AFPM Sean Christopherson wrote: > > 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 vPM= U > 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/too= ls/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 *vc= pu) > 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/t= esting/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 s= truct 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 =3D vcpu_get_cpuid_entry(vcpu, 0x8= 0000008); > + struct kvm_cpuid_entry2 *entry; > + > + entry =3D __vcpu_get_cpuid_entry(vcpu, property.function, propert= y.index); > + > + (&entry->eax)[property.reg] &=3D ~GENMASK(property.hi_bit, proper= ty.lo_bit); > + (&entry->eax)[property.reg] |=3D value << (property.lo_bit); What if 'value' is too large? Perhaps: value <<=3D property.lo_bit; TEST_ASSERT(!(value & ~GENMASK(property.hi_bit, property.lo_bit)), "value is too large"); (&entry->eax)[property.reg] |=3D value; > - entry->eax =3D (entry->eax & ~0xff) | maxphyaddr; > vcpu_set_cpuid(vcpu); > } > > diff --git a/tools/testing/selftests/kvm/x86_64/smaller_maxphyaddr_emulat= ion_test.c b/tools/testing/selftests/kvm/x86_64/smaller_maxphyaddr_emulatio= n_test.c > index 06edf00a97d6..9b89440dff19 100644 > --- a/tools/testing/selftests/kvm/x86_64/smaller_maxphyaddr_emulation_tes= t.c > +++ b/tools/testing/selftests/kvm/x86_64/smaller_maxphyaddr_emulation_tes= t.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, MAXPHYAD= DR); > > rc =3D 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 >