Received: by 2002:ab2:2994:0:b0:1ef:ca3e:3cd5 with SMTP id n20csp446424lqb; Thu, 14 Mar 2024 16:36:10 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUvt+umk+WT1MlM9Qj63814dCsHDkrQGCn4qvuOjcHi+mwUyW0IAS1LyCGqZnppcAW8xRn5I4nmHKiVxEfIStsNpdxknDP6wu3GjuVbWg== X-Google-Smtp-Source: AGHT+IFe7HWySve1OyPLVOtTvE7NX4xyF3ZVbgzft7L4KuY0n+20o2A5BTPiUXPPqZLc734g9bkB X-Received: by 2002:a05:6a00:23c9:b0:6e6:98bf:7b62 with SMTP id g9-20020a056a0023c900b006e698bf7b62mr2079593pfc.8.1710459369780; Thu, 14 Mar 2024 16:36:09 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710459369; cv=pass; d=google.com; s=arc-20160816; b=I6B4/i7OYDcTr5VbzB7wCqFlo1lI1wakHrT/1q9gu5m23mmZgwLfS+6IdE0LNnu2P5 m9bHLPJXf59LKtkoNYP/ZnkKj9Ld9N5CaWDpmMSufNNHQboNP8XuSwv1GCOM6qSJ4nIT TqukWdY36xhovsxMPGQLFlf6r2ro9dBZhPvEbTC9q23YJbtJn5yPAKUQsnPHFRjws/9l hhhtrJ9IejqjdS0w1LAhpKIq62gDAFYe0toD/3nxLcWTnY7+MJT5ZY7DA+Th5DRSOqSZ 2ktsbow6frfTH6war7sjzr2qg1XJ2HKo/VLgPaQ6MAZLS7E9+YJNfQhNGpdm88lQV1bU DcmQ== ARC-Message-Signature: i=2; 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=oB3ZfcSJ5G1gMIeNmqomMwFWPYu8/DXA5zj+kntGd24=; fh=OQwkWiby9y5PianJMNtBeF+Z694SWtMSUC4pBdwQ8Ug=; b=PE6zyGnB4FqZRHtDhOqqVSbJOPIME2Ojlcr8YmrttCmkcOucj0RbtXbuBteNjAxBKE NHr7g1xvCZPck5vRl3YUw8n8Chj84c+3yXQhvWTQUm5EQ7IvU47/XJ+T5JksOoCK9vYd 3aVHoxSW4IsHiv1vLQNyYdGF6Ny0SzX0cJ7oRFihlG3kTx4lFV/yxEKakpH6/dbhwg85 1VtQCOde8+L8J4hTF0FMfqH5ZcC9XyW5x6Azs/cbUzuyXd7Zi9YQk9bAH0jXvrMgWKFl MH00/8/P3N37Ep5Hbqb4Twx7cYwGcerV4jH54tcVZlNsEIN7HXE78QNxPP51w+dL4P/L ZjPA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=YKpTtA5h; arc=pass (i=1 spf=pass spfdomain=flex--seanjc.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-103898-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-103898-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id z30-20020a056a001d9e00b006e6c873709bsi2413461pfw.297.2024.03.14.16.36.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Mar 2024 16:36:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-103898-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=YKpTtA5h; arc=pass (i=1 spf=pass spfdomain=flex--seanjc.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-103898-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-103898-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 7D3B7B235DD for ; Thu, 14 Mar 2024 23:33:07 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8A59A249F4; Thu, 14 Mar 2024 23:26:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="YKpTtA5h" Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.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 BA5201B814 for ; Thu, 14 Mar 2024 23:26:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710458813; cv=none; b=ZAzfnppvVACUSUeBwOfy3NVOpRRAAdDuW1kx7L0TEpuMgOoI0CV8PNbJrkG9SkAJC4B9WhpnoQb7ATVr8+uNjFjW00Sn9s602fbaslDUZHwHg++7yqO2yEXr/Ml8dyu28Zl+B4ZcvB9G5w7lnGr15g6cLF7QuAQoMGZcU1Hf+AE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710458813; c=relaxed/simple; bh=meFKVgZcplsrdf4nThtnD2hQo2z4gltSGTp4DLCnmJ4=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=b4idMfT6aSG4WdYv1qAN9otXAM1X/D0nJw+N7LfFP48irBefkxGilLKL5z0ikix2IYC8qi9Klbu5dYKEfTHGH50a6W7Y7iiaVof5dt2ijroiEEXUeELHH6Cv6aF8yaEjbBM5KYZaRM0nWuiJG8nrHDBBiYKyQ+HTfYuGinp8XA0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=YKpTtA5h; arc=none smtp.client-ip=209.85.128.201 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-yw1-f201.google.com with SMTP id 00721157ae682-60a54004e9fso29376077b3.3 for ; Thu, 14 Mar 2024 16:26:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1710458811; x=1711063611; 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=oB3ZfcSJ5G1gMIeNmqomMwFWPYu8/DXA5zj+kntGd24=; b=YKpTtA5hr+jr+CBQWoKSxidJLely1oaPaScPz7o7y0zxRdBggmjFrU1JivphrW9UTa PHkGjxx/pqZin797ThccwJEMwy7VI28g19gzfaCML5CLa5nP49IEWbiZAMfwhvxpQqlZ f5pkTmB03wShEmrGl7BmxQSEME7CcBrVj55TWhZgHHtH3Xc/55nizKivnjC/Zbz52LoN KLQXrPVhSlzEtDAs7wvNRTkiBT4EJ4Udop3BxjwXWjCTtE5n2pT+7prbWT5bS+utu4wc nmgU7lp8jtjZoOf+Ic+c6BB2YHnktVJ5mlj2GAEM7qIz+HGiKK5gmNMjYFLjNe3bA+/s IuPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710458811; x=1711063611; 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=oB3ZfcSJ5G1gMIeNmqomMwFWPYu8/DXA5zj+kntGd24=; b=XN+dVbSWwy1sUafasFeKTb7LzMW7R6VWYWnkwWU794Z02Ak8rs+NQU2UoxNynZA00b 5dyyC1HI11EbFZ9VSJ66DNbKH9/q9NRv0xd0aLjZpxJuBc01Ley3IporaMn4dm0aDZnY UCJkT3AR6cYVtxDxzNuBad01/3GFwZz7HOktaqt7t3SAd8hiCww8kI7/NS/PXXxpb7A9 +wDR6YNWbKeozZ44T3rUpqq8lOsc9XWKwqNYaFDVPDZx0pOY01khc7UTy+fd3L5cocsc XUkttBfEumt3CVjkWLRuJXG5ywbcgsHuduTJg9Uws6x+iJOKlr9d4S5ZRIMixkqaC3vg iUNw== X-Forwarded-Encrypted: i=1; AJvYcCUnmESzgYnQLfT7BmKLSucZBeLGXs5a+cUxWq3aVOkdRg0yyHx3vfMp5QtUgz2ZHJs4lj13w1aRUJE2j6cCOgObLXX+50Lrq0dS9o/z X-Gm-Message-State: AOJu0Yxp0oZ/IvRMDtKpgr9kZwMcoupOowiSungwloOQXoPmA4sTvuVi jAggfiF3cSp/9t3uZElXByJLyOGFch0Lv5euDxXcF6JK4beZUwkzQFYZ3nlAdb8JMcYbACmQy+u p7g== X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a0d:e288:0:b0:60a:56c2:a61f with SMTP id l130-20020a0de288000000b0060a56c2a61fmr797989ywe.8.1710458810918; Thu, 14 Mar 2024 16:26:50 -0700 (PDT) Reply-To: Sean Christopherson Date: Thu, 14 Mar 2024 16:26:25 -0700 In-Reply-To: <20240314232637.2538648-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: <20240314232637.2538648-1-seanjc@google.com> X-Mailer: git-send-email 2.44.0.291.gc1ea87d7ee-goog Message-ID: <20240314232637.2538648-7-seanjc@google.com> Subject: [PATCH 06/18] KVM: selftests: Rework platform_info_test to actually verify #GP From: Sean Christopherson To: Marc Zyngier , Oliver Upton , Paolo Bonzini , Christian Borntraeger , Janosch Frank , Claudio Imbrenda , Sean Christopherson , Anup Patel , Paul Walmsley , Palmer Dabbelt , Albert Ou Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, kvm@vger.kernel.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Ackerley Tng Content-Type: text/plain; charset="UTF-8" Rework platform_info_test to actually handle and verify the expected #GP on RDMSR when the associated KVM capability is disabled. Currently, the test _deliberately_ doesn't handle the #GP, and instead lets it escalated to a triple fault shutdown. In addition to verifying that KVM generates the correct fault, handling the #GP will be necessary (without even more shenanigans) when a future change to the core KVM selftests library configures the IDT and exception handlers by default (the test subtly relies on the IDT limit being '0'). Signed-off-by: Sean Christopherson --- .../selftests/kvm/x86_64/platform_info_test.c | 66 +++++++++---------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/tools/testing/selftests/kvm/x86_64/platform_info_test.c b/tools/testing/selftests/kvm/x86_64/platform_info_test.c index cdad7e2124c8..6300bb70f028 100644 --- a/tools/testing/selftests/kvm/x86_64/platform_info_test.c +++ b/tools/testing/selftests/kvm/x86_64/platform_info_test.c @@ -26,40 +26,18 @@ static void guest_code(void) { uint64_t msr_platform_info; + uint8_t vector; - for (;;) { - msr_platform_info = rdmsr(MSR_PLATFORM_INFO); - GUEST_ASSERT_EQ(msr_platform_info & MSR_PLATFORM_INFO_MAX_TURBO_RATIO, - MSR_PLATFORM_INFO_MAX_TURBO_RATIO); - GUEST_SYNC(0); - asm volatile ("inc %r11"); - } -} + GUEST_SYNC(true); + msr_platform_info = rdmsr(MSR_PLATFORM_INFO); + GUEST_ASSERT_EQ(msr_platform_info & MSR_PLATFORM_INFO_MAX_TURBO_RATIO, + MSR_PLATFORM_INFO_MAX_TURBO_RATIO); -static void test_msr_platform_info_enabled(struct kvm_vcpu *vcpu) -{ - struct ucall uc; + GUEST_SYNC(false); + vector = rdmsr_safe(MSR_PLATFORM_INFO, &msr_platform_info); + GUEST_ASSERT_EQ(vector, GP_VECTOR); - vm_enable_cap(vcpu->vm, KVM_CAP_MSR_PLATFORM_INFO, true); - vcpu_run(vcpu); - TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_IO); - - switch (get_ucall(vcpu, &uc)) { - case UCALL_SYNC: - break; - case UCALL_ABORT: - REPORT_GUEST_ASSERT(uc); - default: - TEST_FAIL("Unexpected ucall %lu", uc.cmd); - break; - } -} - -static void test_msr_platform_info_disabled(struct kvm_vcpu *vcpu) -{ - vm_enable_cap(vcpu->vm, KVM_CAP_MSR_PLATFORM_INFO, false); - vcpu_run(vcpu); - TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_SHUTDOWN); + GUEST_DONE(); } int main(int argc, char *argv[]) @@ -67,16 +45,38 @@ int main(int argc, char *argv[]) struct kvm_vcpu *vcpu; struct kvm_vm *vm; uint64_t msr_platform_info; + struct ucall uc; TEST_REQUIRE(kvm_has_cap(KVM_CAP_MSR_PLATFORM_INFO)); vm = vm_create_with_one_vcpu(&vcpu, guest_code); + vm_init_descriptor_tables(vm); + vcpu_init_descriptor_tables(vcpu); + msr_platform_info = vcpu_get_msr(vcpu, MSR_PLATFORM_INFO); vcpu_set_msr(vcpu, MSR_PLATFORM_INFO, msr_platform_info | MSR_PLATFORM_INFO_MAX_TURBO_RATIO); - test_msr_platform_info_enabled(vcpu); - test_msr_platform_info_disabled(vcpu); + + for (;;) { + vcpu_run(vcpu); + TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_IO); + + switch (get_ucall(vcpu, &uc)) { + case UCALL_SYNC: + vm_enable_cap(vm, KVM_CAP_MSR_PLATFORM_INFO, uc.args[1]); + break; + case UCALL_DONE: + goto done; + case UCALL_ABORT: + REPORT_GUEST_ASSERT(uc); + default: + TEST_FAIL("Unexpected ucall %lu", uc.cmd); + break; + } + } + +done: vcpu_set_msr(vcpu, MSR_PLATFORM_INFO, msr_platform_info); kvm_vm_free(vm); -- 2.44.0.291.gc1ea87d7ee-goog