Received: by 2002:a05:6a10:a852:0:0:0:0 with SMTP id d18csp4010722pxy; Tue, 4 May 2021 15:31:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyJqlG8W8OyJgYt0TPaJUXvAMSkNrfqBaWTzqa39fEMd2QWCnH9b1Tc6rx+c6dDuOBBn7mg X-Received: by 2002:aa7:d955:: with SMTP id l21mr19522903eds.118.1620167473187; Tue, 04 May 2021 15:31:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620167473; cv=none; d=google.com; s=arc-20160816; b=CPwySpbvraaQcMqjudKgHBW9ZzMRhPAnvzw9cArMI4Tf0ncWsaxRQu/AdT2BJUNhVY SYONywgltqLBreTPysivEE77C9bM6vX7wbkgpTCLqqd58X8maXkEYeNj67Q/T8rKhzti Ca06uUBOcJCoExx7EY0uE+vGy/HDmvFlfzV0kDRvF7UnJ4bxsY8TtdQ7KUJSwdX8mE+4 fN/aOJl/0+suG780Se4IBSXsYgOhusjxhd1vD1HrOU+UCXJhlqj8qbXjMLazitVLVuT7 jPFXl7ayQZ0oS+DzL7vdqGAbB1EFJGex+jOKkAOIocP8ZIDBLcHQZeLoBiS794rGrDzB ghTQ== 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=G/mynJyVd6OqUtlJeADQl+MoXNb+9GbiDjZ8MMglkq0=; b=HG5U5fJ8K3LiQx3ZziQZe5rfMUScf/dHG612Ev4GIX3Jy6r+wHnrhvvmGjG76Zgikd mwOODwBpCqKdoF/7Qs+RtY6a+WxqAzhVy6s9pKtVLvwEC8ECZg8xwPmt2xwIje8axxO3 CIGceZMNYq760pWa0hvNvv3mUIikxwmPnnQtcnzdqmymkS0r+DVLEPHpV6cla7P6e+qF eZb0KCQ9OyzverDmRze0TCcVZ2er2+1V1l9bF1A/ikiU92fZSnwRyvkRJa/yNTWDs5KR I27bpgCmFtmOB0nfGdyqWLBUoP77u+9EGr/bvkeVIXTg3XjnP7xuwJ2m7MTju1rT9o5z VuEg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=ZzZ3kUkX; 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 zc8si3621513ejb.452.2021.05.04.15.30.49; Tue, 04 May 2021 15:31: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=ZzZ3kUkX; 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 S233046AbhEDWZO (ORCPT + 99 others); Tue, 4 May 2021 18:25:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51626 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232963AbhEDWZN (ORCPT ); Tue, 4 May 2021 18:25:13 -0400 Received: from mail-oo1-xc2e.google.com (mail-oo1-xc2e.google.com [IPv6:2607:f8b0:4864:20::c2e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 73C39C06174A for ; Tue, 4 May 2021 15:24:16 -0700 (PDT) Received: by mail-oo1-xc2e.google.com with SMTP id i20-20020a4a8d940000b02901bc71746525so56854ook.2 for ; Tue, 04 May 2021 15:24:16 -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=G/mynJyVd6OqUtlJeADQl+MoXNb+9GbiDjZ8MMglkq0=; b=ZzZ3kUkX93v63Jb3vme8k9OXJxDVZy2d4Qc3VpSVGzi0IxBMOWHLm2TYMxFI0esBWD T35MJNUTB1WP34XtEKngIQ25gkZvtXppq/TpEP8vVy20dd0y3yPLwrZ8ky1JpQdp9gBw 6MdWseZzEbo1Q1OEfHl3kJgQNaUwubelotgMRyfIEmsIJhbb2+6qHUe6sO+YCtfomzcX pNN+o/vIUNia2nxYuc59jkTt0wUs32NPVlscVUQzImJsbAIQrRct9CIpwZmx6w9jZZpp gKq8XKbXx1EN2kfVUmXfD+qjEzPsVvdUmez2s4W3AkJnSJf+I94xyeyWP9cjWiJObCjA REaQ== 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=G/mynJyVd6OqUtlJeADQl+MoXNb+9GbiDjZ8MMglkq0=; b=t+KHL9uLwtnNLwLoSXENXh6jaC+Y94/ab7VlPpPJxP3XJhYsQIO6Bz1l+upbiie9DK ogZ605lgoJItaerJWNxuWDoXxwbjZZLI3YMvqB0civrOZVRDVQG9bakKgnRTaqNTaFDy 3Yt65nRk98BV7xMzQQElQTWv8AyejTaARUTMoC3+sGr5no9ymknA9EYQPzMTwjFZkWWn Cno2RCz4Szpb7mVufR37pf6+Ne5pTH4qzbFIc9Jf5UME66T3wgxygdiK5Q0ViUZm5Pjy /PbKDulMn0rfoWaDVEcIm2Wp/h4TLPQ7+Gjk/tqO09RR48YGjYcABHHvWXneffkKY0E5 Jdjg== X-Gm-Message-State: AOAM531/s0mEw+9bDb0mj7VVgDgupSxWJp6eyK5159XNSkj3IiGrDr4K 3/cTg4ai50PGMH3KmDtK0JuDi3VVafIQPll7zwuooA== X-Received: by 2002:a4a:ea94:: with SMTP id r20mr7794217ooh.81.1620167055541; Tue, 04 May 2021 15:24:15 -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 15:24:04 -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 3:10 PM Sean Christopherson wrote: > > On Tue, May 04, 2021, Jim Mattson wrote: > > 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). > > No, it will not do the right thing, whatever "right thing" even means in this > context. That's a pre-existing issue, e.g. INVCPID handling is also wrong. > I highly doubt VMX does, or even can, do the right thing either. > > I'm pretty sure I lobbied in the past to disallow KVM_SET_CPUID* if the vCPU is > in guest mode since it's impossible to do the right thing without forcing an > exit to L1, e.g. changing MAXPHYSADDR will allow running L2 with an illegal > CR3, ditto for various CR4 bits. With that caveat understood, Reviewed-by: Jim Mattson