From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-23.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B5EA6C433B4 for ; Tue, 4 May 2021 22:24:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 935CF611CB for ; Tue, 4 May 2021 22:24:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233050AbhEDWZO (ORCPT ); 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-Google-Smtp-Source: ABdhPJxo1sYC258Xmtlr84Guf3FGfzlmaAS4Bfv2FWjEz/7XUJt0x/Hw0EWXImD8YubRD/UmQPLLXeL5grngKF8MWhs= 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