Received: by 2002:a05:6a10:a852:0:0:0:0 with SMTP id d18csp4003164pxy; Tue, 4 May 2021 15:18:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzuXl29HOlFkq9qePwfo/SZqAj/j1ZGnRDADd5cmoGkOc6+g/z9JFg0csl/HsDZgaMTWYwO X-Received: by 2002:a17:90a:eac2:: with SMTP id ev2mr4240757pjb.134.1620166693695; Tue, 04 May 2021 15:18:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620166693; cv=none; d=google.com; s=arc-20160816; b=XWL50SiPclEObC1FK8uAEJIpcopnlE3tCIyR9LLQXJHaQ1VtQihGFFUqn2FYzGiB3y 1X6S2LgYUfNdlZq5d6a2+8eF3sg4mHz4vfpKWE/l+1Q8j88UuYEhz/9Kk/24KVugnwTG o54Fbap38oGOG8i5vHVDfZtvzpPLNz4L+AaWL2m07PcgIIWcPZQ6kcQunG39WRUtBCP8 PhT1lgW88xE2AB2oXrLwMAoOhsAYDqZTEefEycTs+Shj2uKxBRZzqZyZdanJt79JebMx nAFqUMtodVfeotWsWLH1QgVgWTywqb7DAq/vmktDMeQpUkhgDLJ4+Ud538ltJaoUcGZX rr8w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=uGuTUwlkCU+unXsaphWAxRTUlNrZZHZiZSNJtWbfPBQ=; b=yJDVrdfp/48oiUKR68DW3LOUZlW76Rsv42JhTOoWPdN7h/AaRgs5+0vBxskWhRUBCJ A/RkHKoOZM54gUuhaauzKsNMS6oYKxKe9urnjq1/p1zoZIG3ZiC43REubTGgB+sMJCXr x3AWKkOHc5LFxdotulnGF3Xwi1DDgKu6CNLvvtzU/TTGL8D2CyzcavHA4Eje+5s6vCzQ 2MltBbidg8As3TAP1+iF6L8AVGVeXyrg49FA79r/ZjiF/1ahuN9CGfB6/I+nIrUab/2L G4S8g198R2Zj0ZRGIb45cFSQScYV9yacFlZFV0F/J87CF8yAQa2Q1ITnToWCXoTDdQZj f0ag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=vWwxWX0U; 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 t127si4435829pgt.514.2021.05.04.15.17.44; Tue, 04 May 2021 15:18:13 -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=vWwxWX0U; 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 S232650AbhEDV5t (ORCPT + 99 others); Tue, 4 May 2021 17:57:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45570 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232633AbhEDV5t (ORCPT ); Tue, 4 May 2021 17:57:49 -0400 Received: from mail-ot1-x329.google.com (mail-ot1-x329.google.com [IPv6:2607:f8b0:4864:20::329]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B0CB9C06174A for ; Tue, 4 May 2021 14:56:53 -0700 (PDT) Received: by mail-ot1-x329.google.com with SMTP id c36-20020a05683034a4b02902a5b84b1d12so9283032otu.8 for ; Tue, 04 May 2021 14:56:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=uGuTUwlkCU+unXsaphWAxRTUlNrZZHZiZSNJtWbfPBQ=; b=vWwxWX0UTtXl061UlBeiTDrqFuwyTDrjgAX7XxZrmYUB4lVjEIF7T6ooJQN4I3b6Ie Iyg5WyVoT8twTMq4Tardwo/JIw6SJCdXcFvqQaUzThSLLVaeWuLVvzS3UjDnDSMHJEZN lYx8u/KPLKOILDKz++ecoW7Y/19nGB7WaNBlHJKz/eV9uYgzY6rreyr9KxSqlNxMYQ3O GDkusYWjbZALyYFT4kHLko5mjBZiv0xyal6zh+bLa/RoOWq/mSW+utJRXjAl9nUCgkwY /XHhk+UPH27vUO4R1DJqZfJNObvoAOTHVw9HWVNwJHSq4VXq9MpAzOKJjXsNMQn4/js6 xzmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=uGuTUwlkCU+unXsaphWAxRTUlNrZZHZiZSNJtWbfPBQ=; b=KXUGspd2+ZFETZKSPDNALGOELoDaPj6BOt9MP8+VM6/6uSG/VHr38sT1mozZ6FycV9 iidXY8PzmoUpPEX9ATgJd1ABFtZhPF3nvG7k4K8CHjdEo10SSbBKpMHgmufrLmOHF+vV KYl/drIy4x9+WoZHSC4zmZORu5zKFL0h6V86+a6nfM5FemN8DAFyqrXjTuSYBLBjq3w9 sy5PFUWXzOp5Fx8h+6Gbz3QasCNeYt9JtZozZtLwG5sOdaW8ItXwjpwXulonStu2r4ZH vbbc82piHP2rLv4n7D5aeQUEn3ds11VgnYcVLrBkIItx25IkOo1vCYu4dNPjmKKehamY UKQQ== X-Gm-Message-State: AOAM5312XMs9lzuJ3GOFQFSn/LBrydaVndsIRGwiP6aUchQEGmu/B3IF Swybemf4JQ7c9FzvOTQpThZMJny6FO4h1sj37RRJtg== X-Received: by 2002:a05:6830:16c8:: with SMTP id l8mr21049151otr.56.1620165411726; Tue, 04 May 2021 14:56:51 -0700 (PDT) MIME-Version: 1.0 References: <20210504171734.1434054-1-seanjc@google.com> <20210504171734.1434054-4-seanjc@google.com> In-Reply-To: From: Jim Mattson Date: Tue, 4 May 2021 14:56:40 -0700 Message-ID: Subject: Re: [PATCH 03/15] KVM: SVM: Inject #UD on RDTSCP when it should be disabled in the guest To: Sean Christopherson Cc: Paolo Bonzini , Vitaly Kuznetsov , Wanpeng Li , Joerg Roedel , kvm list , LKML , Xiaoyao Li , Reiji Watanabe Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, May 4, 2021 at 2:53 PM Sean Christopherson wrote: > > On Tue, May 04, 2021, Jim Mattson wrote: > > On Tue, May 4, 2021 at 10:17 AM Sean Christopherson wrote: > > > > > > Intercept RDTSCP to inject #UD if RDTSC is disabled in the guest. > > > > > > Note, SVM does not support intercepting RDPID. Unlike VMX's > > > ENABLE_RDTSCP control, RDTSCP interception does not apply to RDPID. This > > > is a benign virtualization hole as the host kernel (incorrectly) sets > > > MSR_TSC_AUX if RDTSCP is supported, and KVM loads the guest's MSR_TSC_AUX > > > into hardware if RDTSCP is supported in the host, i.e. KVM will not leak > > > the host's MSR_TSC_AUX to the guest. > > > > > > But, when the kernel bug is fixed, KVM will start leaking the host's > > > MSR_TSC_AUX if RDPID is supported in hardware, but RDTSCP isn't available > > > for whatever reason. This leak will be remedied in a future commit. > > > > > > Fixes: 46896c73c1a4 ("KVM: svm: add support for RDTSCP") > > > Cc: stable@vger.kernel.org > > > Signed-off-by: Sean Christopherson > > > --- > > ... > > > @@ -4007,8 +4017,7 @@ static void svm_vcpu_after_set_cpuid(struct kvm_vcpu *vcpu) > > > svm->nrips_enabled = kvm_cpu_cap_has(X86_FEATURE_NRIPS) && > > > guest_cpuid_has(vcpu, X86_FEATURE_NRIPS); > > > > > > - /* Check again if INVPCID interception if required */ > > > - svm_check_invpcid(svm); > > > + svm_recalc_instruction_intercepts(vcpu, svm); > > > > Does the right thing happen here if the vCPU is in guest mode when > > userspace decides to toggle the CPUID.80000001H:EDX.RDTSCP bit on or > > off? > > I hate our terminology. By "guest mode", do you mean running the vCPU, or do > you specifically mean running in L2? I mean is_guest_mode(vcpu) is true (i.e. running L2).