Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2388695pxj; Mon, 10 May 2021 01:30:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJysRTYNtdVT5epSmHKWxW7mxW73wg2lvr4WMRZjCRu28iVEMS1K3Eejyh/DdbmBNTaRi/O4 X-Received: by 2002:a5e:8c11:: with SMTP id n17mr8556422ioj.53.1620635455911; Mon, 10 May 2021 01:30:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620635455; cv=none; d=google.com; s=arc-20160816; b=kDTn4228hQmo8BUQ4FEd9liAlnWW5WInksrIAN/CFLqKlu7VKYTalHdYE228B5weI0 m5wnEaptYK91R3qxkZW5BwIGgey4zq15rfNB7QIIdrDkNgfG5UR5wGXiAHxWI5iAt5lu q1UaRljde9omrBelGQV2obSJdAynJdSr5gFF6Ac4s0vdrQ3NQ2QHyDSnEbAqlawd2Cch 18Xr3918glu2nZd9HuGz5u/KQHO8M2F/wb80rYGVza9p0Tsrnow4rgf3ivMVVJP7WFrF j3Ghdytswj09kr2xwc8bYQU9viXv9eWcq2B1vtPNWahsM81YfU74hFMd7GX2Xoh/84B8 +euQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:date:cc:to:from:subject :message-id:dkim-signature; bh=7EQ4vZLkNzKipHnk+EIka5PGObJDdPPscSMPWhaXeCg=; b=rTF1jqsPRnMqt4WxKUSBd7pcRnz8QC+xlERFjX5fc6KupfD5c5+04UD2PMUwpkj60k i3m5sf549KzFUwNwv/S/4kXHwynUD1Q/QtlAojEcE6FtZUGtBK7YT/lyVjspF4hEbvLx RpJu4RLWbLMyHUwuktL0m3Iox+184nAYcAjxyFxl2Wf/tYmoru1AemO3HK5RfeE30Xvh IK52JAxigYVR9aQvxhevkqw+zMKzM1pKcyVGWXB3YzdQJrZ3/kq9wie80FT8nMTW/S7P UaZFr3WnNgMVSCgr6p9FwqOYlXtnbc53Xo4FRgxPbiysqwLNOafboEjkax2peIqjXMXO ukAA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=RGvwT8r8; 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 w6si15629744ill.50.2021.05.10.01.30.43; Mon, 10 May 2021 01:30:55 -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=RGvwT8r8; 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 S230306AbhEJIbB (ORCPT + 99 others); Mon, 10 May 2021 04:31:01 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:38958 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230216AbhEJIa7 (ORCPT ); Mon, 10 May 2021 04:30:59 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620635395; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=7EQ4vZLkNzKipHnk+EIka5PGObJDdPPscSMPWhaXeCg=; b=RGvwT8r83RpLfF/v6Q8liKGpj2k54wSrDkuEL9N1xhARzNOfcXuIv2gHIpsraEJUUl0IDD /7nrekbpuChg7bzzpVK46phE/Wdahz3IXK86BoGBbXiHfWU76KVrfuvmLt7WS+Ghh54UGf jW2MWUzR6K5oUt2ZkMBq7qJTek4vqzk= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-456-GzwQDWOwNwG8cZrE_7tCcA-1; Mon, 10 May 2021 04:29:51 -0400 X-MC-Unique: GzwQDWOwNwG8cZrE_7tCcA-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 705BD818400; Mon, 10 May 2021 08:29:50 +0000 (UTC) Received: from starship (unknown [10.40.194.86]) by smtp.corp.redhat.com (Postfix) with ESMTP id 507A310246F1; Mon, 10 May 2021 08:29:47 +0000 (UTC) Message-ID: <4616405e483e3de185129a478a0ee576827bb6cf.camel@redhat.com> Subject: Re: [PATCH 15/15] KVM: x86: Hide RDTSCP and RDPID if MSR_TSC_AUX probing failed From: Maxim Levitsky To: Sean Christopherson , Paolo Bonzini Cc: Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Xiaoyao Li , Reiji Watanabe Date: Mon, 10 May 2021 11:29:45 +0300 In-Reply-To: <20210504171734.1434054-16-seanjc@google.com> References: <20210504171734.1434054-1-seanjc@google.com> <20210504171734.1434054-16-seanjc@google.com> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.36.5 (3.36.5-2.fc32) MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 2021-05-04 at 10:17 -0700, Sean Christopherson wrote: > If probing MSR_TSC_AUX failed, hide RDTSCP and RDPID, and WARN if either > feature was reported as supported. In theory, such a scenario should > never happen as both Intel and AMD state that MSR_TSC_AUX is available if > RDTSCP or RDPID is supported. But, KVM injects #GP on MSR_TSC_AUX > accesses if probing failed, faults on WRMSR(MSR_TSC_AUX) may be fatal to > the guest (because they happen during early CPU bringup), and KVM itself > has effectively misreported RDPID support in the past. > > Note, this also has the happy side effect of omitting MSR_TSC_AUX from > the list of MSRs that are exposed to userspace if probing the MSR fails. > > Signed-off-by: Sean Christopherson > --- > arch/x86/kvm/cpuid.c | 15 +++++++++++++++ > 1 file changed, 15 insertions(+) > > diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c > index c96f79c9fff2..bf0f74ce4974 100644 > --- a/arch/x86/kvm/cpuid.c > +++ b/arch/x86/kvm/cpuid.c > @@ -567,6 +567,21 @@ void kvm_set_cpu_caps(void) > F(ACE2) | F(ACE2_EN) | F(PHE) | F(PHE_EN) | > F(PMM) | F(PMM_EN) > ); > + > + /* > + * Hide RDTSCP and RDPID if either feature is reported as supported but > + * probing MSR_TSC_AUX failed. This is purely a sanity check and > + * should never happen, but the guest will likely crash if RDTSCP or > + * RDPID is misreported, and KVM has botched MSR_TSC_AUX emulation in > + * the past, e.g. the sanity check may fire if this instance of KVM is > + * running as L1 on top of an older, broken KVM. > + */ > + if (WARN_ON((kvm_cpu_cap_has(X86_FEATURE_RDTSCP) || > + kvm_cpu_cap_has(X86_FEATURE_RDPID)) && > + !kvm_is_supported_user_return_msr(MSR_TSC_AUX))) { > + kvm_cpu_cap_clear(X86_FEATURE_RDTSCP); > + kvm_cpu_cap_clear(X86_FEATURE_RDPID); > + } > } > EXPORT_SYMBOL_GPL(kvm_set_cpu_caps); > Reviewed-by: Maxim Levitsky Best regards, Maxim Levitsky