Received: by 2002:a05:7412:e794:b0:fa:551:50a7 with SMTP id o20csp634046rdd; Tue, 9 Jan 2024 15:07:34 -0800 (PST) X-Google-Smtp-Source: AGHT+IG4sOFZnvC9A0qJEe1V+HmKABzDkvlOF0JrPKMZ+AhdqdjSJ4PdHOAjVlTJN2fh24urFcHI X-Received: by 2002:a05:600c:358a:b0:40e:42ef:c96a with SMTP id p10-20020a05600c358a00b0040e42efc96amr29117wmq.22.1704841654109; Tue, 09 Jan 2024 15:07:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704841654; cv=none; d=google.com; s=arc-20160816; b=U6zNxD04SoU83MicdopUVuDOb1rP+1b6710paukGs8s8hBZp/P/6kxAYliNPkzOqy0 ptgcTlxlDB77CRF7lwhgW443x1SnIyoh6B+d6D9DwbKkpwejbWuYw5+hPTBe6XGIhVaZ cL3xGNqt/p6jPLriAy8rnnqP5XV1SIi4c2NaqbUL6PEaFH4Qq95e1N2nT1WouW3jIRR1 RaZH57Te6ZhtaOKWYDSvedeRKDbac7dGOQIGHYI0otz58GwERfvu4JPrneMfbVJ5N9ix hjN6gMhecJrec4c04PoZ3wTDdjIa+2lPGdZ1ovkNNH1JF9Obd9H0Z9yyoJWr8hadOQIp iSDw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:references:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:in-reply-to:date :reply-to:dkim-signature; bh=zpfa/x9yEuVfUmpeFfAFqOYrAZ+6Wf628MHaj6l1xFg=; fh=gm96CM+cG0KJxn7vnhn0c1c98ILNP1HHUrKfrGecw3M=; b=wQOsIYFfzHBxxmoUGeT5l4iWacspDiuJIy9rj9hJvc5wvMeGXFRLKMbFsBZoZ9l0So 3tcIcO/jYTyF4CFq8YnvZ9ojVF3WmxYO5POsuYi+6ccI8e/Q/QzA3VH1YqfSK2URRkVB Utucm5XmNtpufnXMatQuLJtOv3MBIOQNX0AjEbRaxmYOymuA/zLzm03UVequoCyWgL0t UK4wk9u9hWZqZeI1XtzpEMyWq+EGrqsUjC4Mc14ds+rIBQrScUHED+kQxx1Cnn5pEXbi uHElDHTlD8mkUTDyUzuDMJQpTTRMvZ8+9I3xVLf/YUqPAz2ZeZGgOtn3eMWkZII0lvXC 2aoQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=yNNaX1GP; spf=pass (google.com: domain of linux-kernel+bounces-21501-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-21501-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id c17-20020a17090603d100b00a2af7e3f74bsi1160690eja.172.2024.01.09.15.07.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Jan 2024 15:07:34 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-21501-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=yNNaX1GP; spf=pass (google.com: domain of linux-kernel+bounces-21501-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-21501-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id D6B451F20F18 for ; Tue, 9 Jan 2024 23:07:33 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1BE8A47A70; Tue, 9 Jan 2024 23:03:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="yNNaX1GP" Received: from mail-pf1-f201.google.com (mail-pf1-f201.google.com [209.85.210.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 03EB04777D for ; Tue, 9 Jan 2024 23:03:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Received: by mail-pf1-f201.google.com with SMTP id d2e1a72fcca58-6d9b09d1afaso4150544b3a.3 for ; Tue, 09 Jan 2024 15:03:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1704841396; x=1705446196; 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=zpfa/x9yEuVfUmpeFfAFqOYrAZ+6Wf628MHaj6l1xFg=; b=yNNaX1GP1q4m5xr/3s6qd/MKn0c99a00cxzOVGk5Y0wZ2u3uW1IW3ucZr1gWsFvF4Q srtqQOMTEknuMO/m4YBzB2ywUlGjMXdLJ3f2VsITEStN5jC1ilnrpdHDFunJfXlT8tng EkFkiGTiMF6ktrlBoeGDDWnkskVew+HsfHDZOIY9uw5kysNnd22HwosInh6QX+zGrXDf 5YMalFKd7fPXBuYoX8R9HRg22c5fSvw9PxV9jxLOkVGkhCah/CSpG/C8kkXAMADj3QKK Z1tRtH50hK8td3Qp0s3OGkdfm6upaczkPL5lXspNtg3lMG5CbEsmAny4/9QyyjNFD1x1 Oy5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704841396; x=1705446196; 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=zpfa/x9yEuVfUmpeFfAFqOYrAZ+6Wf628MHaj6l1xFg=; b=XVzIoUqAgJ8dyrrDGaJGJa3AN8zGGIRIC0OXayINaIrp04+UGoXEZGftvlXQuUkmZE O71yt0E4vYTxwK5xD0BJET5JCcZ70OfUoGnln/ubVpY4r/k4SyN/4qCU94bqEsQeQ1wU Qbk+HjewkWWvCM4EdiJVZITQplTsl+WFFbScNP9wJjur8LO95sXnsbcOf9GQUdOtY77p 4vejZIzLWef6L9xbelVS7OFP/tsNPNJAG+Ke5NMRLDqZiQ88zX4wEwEGoEMWL3int//y IhoYZuVdKFVu4ohe/BlgIYgo7AeX5Cpr8KSKa8G8TOI2eiRIPtItOOEb0Dnrz62PLE/a OXOw== X-Gm-Message-State: AOJu0YyuxtweYTH9Y9lV8P3SgH+NmI5uWld9Vu5j03r2fkhoVGpoFsUg KSu1xo9XBrUiI0erlnmCD3TDIUjvzZRkVVJeRQ== X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a05:6a00:2e90:b0:6d9:cb95:d738 with SMTP id fd16-20020a056a002e9000b006d9cb95d738mr42128pfb.2.1704841396543; Tue, 09 Jan 2024 15:03:16 -0800 (PST) Reply-To: Sean Christopherson Date: Tue, 9 Jan 2024 15:02:32 -0800 In-Reply-To: <20240109230250.424295-1-seanjc@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240109230250.424295-1-seanjc@google.com> X-Mailer: git-send-email 2.43.0.472.g3155946c3a-goog Message-ID: <20240109230250.424295-13-seanjc@google.com> Subject: [PATCH v10 12/29] 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. Reviewed-by: Jim Mattson 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 a84863503fcb..932944c4ea01 100644 --- a/tools/testing/selftests/kvm/include/x86_64/processor.h +++ b/tools/testing/selftests/kvm/include/x86_64/processor.h @@ -995,7 +995,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.43.0.472.g3155946c3a-goog