Received: by 2002:a05:6a10:a841:0:0:0:0 with SMTP id d1csp3448017pxy; Mon, 26 Apr 2021 01:50:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxO/s+6q9/bA6jtmKvEb3HIu/eHHkfc6pIN16wGU9BcAKBMVJkJi8aoODYT2YaGwri5yrcq X-Received: by 2002:a17:906:7806:: with SMTP id u6mr16513314ejm.130.1619427036709; Mon, 26 Apr 2021 01:50:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619427036; cv=none; d=google.com; s=arc-20160816; b=z4MzI0et8IaRyajZSi/OizKNedZz65Z1fE/KF7R31Hg7EAyw5azCSbD4PNW+NEufQx AJSjSbvSu/utivdwWzZHKLw7O7HaqwF2dS8f8Zpweyq/FjyTQvtQ85REPX6eAaGGoU71 N0/eFMjXxObmPp0DBu2a/qFEJQaW6jmFWjhzbRCmRMtKKdTiqWByroIR1sGChf/wr+BD URTItZ1Se7quguQC2GBM7B1LocA7NErqSg1Czqu7v8S1dF2U8TyFFrCUXRvQYj1MCSGe /8zzpksbE9un1ijFyFNO+VyS9CjB25xGu66l1N7mLVqs89dopPTJotf+FGwii0gojmHL NL4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:references :in-reply-to:subject:cc:to:from:dkim-signature; bh=+hmNV/IZvupUHnll2PVZlj2hkS5F6Q9x72zJCUhsn3I=; b=OMfyXJQIn1DELvkriwA+N4AiprRUrsp2hL9eiI8I9vVSXROmSDQ4OA+3THmLuYVtlt SeFwDeN79hMmgYMHogrFtb6ULeQ0HGOTpwKLOu+3GzTfXJIZNmYplP67bgMrlI4/mtZj 4EDeRJIYcdkTT+G3N85+zDFZfvojZlLqbYe3b193Zfn3wPJJb5ohacfU+v71FuW6vz0K 6zAKft1uBM1jn9McP6YNl/NRzW9r3MoiK7FjU9T76F8ZglL1QniTHEh5YZu6lU/h0FkT wu90ZTeN3ZC/ToMaU5yZ2vXzvHYHShz6HnFuL9W3KTcNaRkV+HxVpzcV2hfnA3yfRi74 hG4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Ifu8iIDI; 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=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s6si5642171eja.652.2021.04.26.01.50.13; Mon, 26 Apr 2021 01:50:36 -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=@redhat.com header.s=mimecast20190719 header.b=Ifu8iIDI; 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=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232227AbhDZIuD (ORCPT + 99 others); Mon, 26 Apr 2021 04:50:03 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:59603 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232078AbhDZIuC (ORCPT ); Mon, 26 Apr 2021 04:50:02 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1619426961; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=+hmNV/IZvupUHnll2PVZlj2hkS5F6Q9x72zJCUhsn3I=; b=Ifu8iIDINB3dG4EaZw8sYrOlokForwdtnxaNy+dQJ4Fk5hMR6zyxuWGZYJknovD47V1+1m /rI4gqPAHryy3NF15pBfPqtQfT28JRqXLCc6gP93+4sK7IFgXRFv7SEss5HT+0mIPNkoH5 y3P4xKr+ietIj8bfpTz4bskg8tJ7Ae0= Received: from mail-ed1-f70.google.com (mail-ed1-f70.google.com [209.85.208.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-339-rtU-eVzNOg6guOlvHqrueA-1; Mon, 26 Apr 2021 04:49:18 -0400 X-MC-Unique: rtU-eVzNOg6guOlvHqrueA-1 Received: by mail-ed1-f70.google.com with SMTP id bf25-20020a0564021a59b0290385169cebf8so15302939edb.8 for ; Mon, 26 Apr 2021 01:49:18 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:in-reply-to:references:date :message-id:mime-version; bh=+hmNV/IZvupUHnll2PVZlj2hkS5F6Q9x72zJCUhsn3I=; b=tb3zj9dvcRVj1p77+Ok3QQtmYAjKezGNHmRxozs5Wl43aQBRG5Kppww5Cf9/OYxWGd +zH4uQEyvrz5YlQJ5LVD5M/7oEdj22UYFHS2qIGeHeyll1ax5ilnvQiEcGVF92evw5KR wlt+AFN9Z2yT0TFaXA2vxjBf2TpqynzTd3Wry2nMSMl6K09+2zbIE+NMCWYYlxnEUW+w Vk8HWJRUpN/c5YafmV96QIWddw9ieTte5OqVwQ4bx2zJMAH6sfT//mWMqlSSR76uxpgB mNZynMsyVnyYPzZiKnymfWb1OTsVMlGnWbmkYXdRBoOgBxngy9BFHeL8SYQqGCzf2CnY Lz6w== X-Gm-Message-State: AOAM530I485oz+NlaC3ppyjQuJuy6a9FGBMfQjUcKLOXTNdKdaRt0YlK 4RScGl/at1QIQ42RZbnzi3yOWbCSXdAfk82rsoJ/jKHdPOm7iPy437qotc9NNak2XPKWaGNo7rn L48uo9yHYXnwMyTKbAzkjmf6k X-Received: by 2002:a17:906:3952:: with SMTP id g18mr17526722eje.104.1619426957430; Mon, 26 Apr 2021 01:49:17 -0700 (PDT) X-Received: by 2002:a17:906:3952:: with SMTP id g18mr17526714eje.104.1619426957295; Mon, 26 Apr 2021 01:49:17 -0700 (PDT) Received: from vitty.brq.redhat.com (g-server-2.ign.cz. [91.219.240.2]) by smtp.gmail.com with ESMTPSA id hc43sm11350506ejc.97.2021.04.26.01.49.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Apr 2021 01:49:16 -0700 (PDT) From: Vitaly Kuznetsov To: Sean Christopherson , Paolo Bonzini Cc: Wanpeng Li , Jim Mattson , Joerg Roedel , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Reiji Watanabe Subject: Re: [PATCH v3 1/4] KVM: SVM: Inject #GP on guest MSR_TSC_AUX accesses if RDTSCP unsupported In-Reply-To: <20210423223404.3860547-2-seanjc@google.com> References: <20210423223404.3860547-1-seanjc@google.com> <20210423223404.3860547-2-seanjc@google.com> Date: Mon, 26 Apr 2021 10:49:15 +0200 Message-ID: <87mttlfn1w.fsf@vitty.brq.redhat.com> MIME-Version: 1.0 Content-Type: text/plain Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Sean Christopherson writes: > 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; Super-nit: a blank like before and after the condition would make this consistent with the hunk you add to svm_set_msr() below. > 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 Reviewed-by: Vitaly Kuznetsov -- Vitaly