Received: by 2002:a05:6a10:a841:0:0:0:0 with SMTP id d1csp1722555pxy; Fri, 23 Apr 2021 15:35:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyeqV83bCVs/aKkkv4g16EeYj5CMsILNGoqKY0cUr/sFWAaQxN/ArP+mI3ZxQec7F9hY0Kr X-Received: by 2002:a17:902:ea0e:b029:ec:7cd0:9106 with SMTP id s14-20020a170902ea0eb02900ec7cd09106mr5894464plg.9.1619217325171; Fri, 23 Apr 2021 15:35:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619217325; cv=none; d=google.com; s=arc-20160816; b=kid1kNa559HFLAXlHnrBpfTafU99jTftyBMowZILNSSSVHqeNh07Lv38BkkTpTKScz Ci2EqA4ECxkComTXYq6rGNtJHhuxLHHkioPOxDKEqA35GjL/jnZ01mlbUccU4SrvahM7 TgEY3Opr2Zep7oJg+3cavrpcqf694X1iLBjUKbXIKcl4LV6sj7y05nnWvnvm+DJiISXq te7U71kmRK8fJ/GziI/qVRmHN4Juuv8ONbJeJkEoCXjXsY9PT0JcP813cFr9UDH6YfVM B+E99VGcCUtHfVeOwM8scX8QA0SXaFZK4GiVawJXtWKvJU86yi3aCRUTOiL5wTo2u81s pIGg== 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:references:mime-version :message-id:in-reply-to:date:reply-to:dkim-signature; bh=v1Exyl3dWucGDOE9RB7t5VjbkFrC7Sen6ZzJflRKQCo=; b=Zb/eaz5diQvpaIcmXIWJQxxRFIk35kDn/YCynAJktjD0x8XHpRMSCV+m640Z9wv3Pq Wr9n8DhdpqZRDpoNP9VOezBpgHvVeR4gS3wlmzr8TuxkH4KOCAAC9imlOZ6/mazTraJJ fcvdtVdDErSEnoZgM6mZ6S6SBdww6U+8GSyhhxYPktv/ceqe+YDOlfwkhupanjuqcD1/ xr83e1ImstlWq7i6S1FW2PGRq0Qtm2J12DUY7Da6fm0ZW0S3UhS1afwfFGe3GbfmOxYc mkckPQLlQNT0uW6aSjGZGbb1iVtSzXhgFj1UN4p9NvPG9eRc5WHBLT6RbvwfATI/2j6O vR9A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=NQNFaYhS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b6si7853197pjz.151.2021.04.23.15.35.13; Fri, 23 Apr 2021 15:35:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=NQNFaYhS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244150AbhDWWfN (ORCPT + 99 others); Fri, 23 Apr 2021 18:35:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36214 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237243AbhDWWe4 (ORCPT ); Fri, 23 Apr 2021 18:34:56 -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 EF404C06138B for ; Fri, 23 Apr 2021 15:34:13 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id e65-20020a25e7440000b02904ecfeff1ed8so14583887ybh.19 for ; Fri, 23 Apr 2021 15:34:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=reply-to:date:in-reply-to:message-id:mime-version:references :subject:from:to:cc; bh=v1Exyl3dWucGDOE9RB7t5VjbkFrC7Sen6ZzJflRKQCo=; b=NQNFaYhStGsu5IDFNW+4tcsMQ9oxw8ww6l7ZuV2jrrMlLeeHY2ZIyFdMLsJw6hAC2u 3yHVM0nOt3isla3mrMpwZXmJQQolCZoqR+LMQJHLvPdMmQTsuOtqs6RTixNzHxfgYZ7g J5fcyQSyr36Vowf6b4MgeWCiJX98Dyj46GNHwK5t1rBmZK8ne7D/yCYnnqqCf/O1ilyl NYBobajDtpV34S8VSQixBahj0gAiPDNA0SaU5w+8pueSORa1PkFUHEZJ7pUIkozP1GTz bfuCsTQNavwgf/eroUbAiJi2v4Sele/SZD5grKLwIoymYE51sbISIFt+ef+0HDNBuKbN m94g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:reply-to:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=v1Exyl3dWucGDOE9RB7t5VjbkFrC7Sen6ZzJflRKQCo=; b=UPIm5YsYo169jAFgykdzfL6LSFa7QE5cYPUgDjd3/eE85lsFQU8iGO4cqxgInlOvw8 E5DeOE+BtHVOJ5ThtBvMoo+zjJL1qMjvsmIugxq5x6vZR5x/IESF/FXC9cPz9EHc0J/n 8YPFEMfSsw0NKw+RCZkQ4SJr+Ak2FYtNZQEkaip9fAyqMCgRJP1vCnRU2zMZ4JdnAR+M xHFKav3WIOSGFvKHZl9JzV9oLa39DD1UdPXs1DweGL9hkINXKItg7FMYEfxGA9HC5fec +NYK0O3hrVSXRZyJ3cF33FPgcq+YhsHS4txgMeXl9R9l8JjJ+C9OkQ5vd3+Kum85OQNU wJ1w== X-Gm-Message-State: AOAM533MuCtSY53ORiytzIOAIoQVpb8njj+hQk+bP6hWqCDh0LlQfET2 PxssWywSvnWJSke+XZ8d+kQsBQiQUZU= X-Received: from seanjc798194.pdx.corp.google.com ([2620:15c:f:10:ad52:3246:e190:f070]) (user=seanjc job=sendgmr) by 2002:a25:3c1:: with SMTP id 184mr641459ybd.76.1619217253258; Fri, 23 Apr 2021 15:34:13 -0700 (PDT) Reply-To: Sean Christopherson Date: Fri, 23 Apr 2021 15:34:01 -0700 In-Reply-To: <20210423223404.3860547-1-seanjc@google.com> Message-Id: <20210423223404.3860547-2-seanjc@google.com> Mime-Version: 1.0 References: <20210423223404.3860547-1-seanjc@google.com> X-Mailer: git-send-email 2.31.1.498.g6c1eba8ee3d-goog Subject: [PATCH v3 1/4] KVM: SVM: Inject #GP on guest MSR_TSC_AUX accesses if RDTSCP unsupported From: Sean Christopherson To: Paolo Bonzini Cc: Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Reiji Watanabe Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Inject #GP on guest accesses to MSR_TSC_AUX if RDTSCP is unsupported in the guest's CPUID model. Fixes: 46896c73c1a4 ("KVM: svm: add support for RDTSCP") Cc: stable@vger.kernel.org Signed-off-by: Sean Christopherson --- arch/x86/kvm/svm/svm.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index cd8c333ed2dc..9ed9c7bd7cfd 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -2674,6 +2674,9 @@ static int svm_get_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info) case MSR_TSC_AUX: if (!boot_cpu_has(X86_FEATURE_RDTSCP)) return 1; + if (!msr_info->host_initiated && + !guest_cpuid_has(vcpu, X86_FEATURE_RDTSCP)) + return 1; msr_info->data = svm->tsc_aux; break; /* @@ -2892,6 +2895,10 @@ static int svm_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr) if (!boot_cpu_has(X86_FEATURE_RDTSCP)) return 1; + if (!msr->host_initiated && + !guest_cpuid_has(vcpu, X86_FEATURE_RDTSCP)) + return 1; + /* * This is rare, so we update the MSR here instead of using * direct_access_msrs. Doing that would require a rdmsr in -- 2.31.1.498.g6c1eba8ee3d-goog