Received: by 2002:a05:7412:a9a2:b0:e2:908c:2ebd with SMTP id o34csp703572rdh; Thu, 26 Oct 2023 13:18:06 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHa9ia0o4S/PuePHYn37oxaMnxat8DlpZ1FGU6f5q/LW9ilkiler1BaBq0YcSWz7Mqka0SG X-Received: by 2002:a81:440d:0:b0:5a8:1812:a7ed with SMTP id r13-20020a81440d000000b005a81812a7edmr582989ywa.15.1698351485988; Thu, 26 Oct 2023 13:18:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698351485; cv=none; d=google.com; s=arc-20160816; b=EtyCkiqn3vZzt9WOxvwz13KiMpXcGqYxsuH7QVlAVyEYA4odDPqbro4XiAGoc77l9J mtUEvpxMLGUX4lSIrnoF/8BKF3fyx1iJETxZeHuXsxZOXpUgw620fChMVWNGmWpOplbS /hIbllmZekNWI+SeahOFbJvabAyKfxlm44xLeVUmtcoJnQyd/cHQBLDyyY9UCADJks73 LYjJ31X75ykd0OzywzIxrZ3Cv76WNxXV2Mse5XP6gvPBaygt+ehw4WXWF4x/Yp1z9v7a UN4r3Zyy89w4l+FQsxLCBetzb3mQL2RoMXaL92YLmEyMLx9HaIHlzNs1KT6RAgrIQopI rZ6w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=k/Y1cqVei499MeRuO0JkL2AwtSOgPbZS08N4+Ku0vIU=; fh=SyxcvViqygumIva4yJbQoxy7Vq6BRqnWLLPsvZppLLU=; b=UTwJPgy/+ucVYh26Va7TUTbwpSOxtbkURquEANAS9rIFTP1RjiIlDvn68ds2DJFPZn c/ruo3ZoAJoWpjoPyJELfkcAclekG3DA4p3kTsRasP7vu9EysAJpWGXVuDQ3iItz+21f 7IsvCGv+QehYejwREP3EaHC6GU7gRmwUIn47Wwv8oGXOjjNG7hfYTI9CbAFyUUV8B/Rq HqOryGIJxtkW1S1MaEHsmqZ0txozMiwGlqaC6aHyK9ft4mKW4yRkV2dU80MjA+NIbSgM yO+Wiv6ErOSVXYSQsvhkD+TT4jwa0pdX50cQZFZhxU2HRZVW9914EGRBYirep2FMA1AG koww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=Xtlo0DJM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 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 howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id w2-20020a818602000000b005a7bbdc2b56si88727ywf.200.2023.10.26.13.18.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Oct 2023 13:18:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=Xtlo0DJM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id D8677824E7B2; Thu, 26 Oct 2023 13:18:02 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344732AbjJZURy (ORCPT + 99 others); Thu, 26 Oct 2023 16:17:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46098 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231546AbjJZURx (ORCPT ); Thu, 26 Oct 2023 16:17:53 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B12B390 for ; Thu, 26 Oct 2023 13:17:50 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-d9cb79eb417so958307276.2 for ; Thu, 26 Oct 2023 13:17:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1698351470; x=1698956270; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=k/Y1cqVei499MeRuO0JkL2AwtSOgPbZS08N4+Ku0vIU=; b=Xtlo0DJMwcg6S4xevIDOsvEqHIAD3oJWPu6TexObC/R5QGBs5RiNbzVIjTUXLr1SUH 6VWMaRfoV8+aSyNPJJc65D1qNOgYSqCFysaQMsGHEIiE4X4M2YQsB/Li+FuoWBb7TY5y o5I7j0/uvlA49lpn6ULMQwBv/g6PEQAPBQu0K5P1ywFHyOoqgIV980c8OSXUSbS7NwNQ P/pjGnoEjem1QgcCOFBMtQ1fnPo8GBrn+LYSxaJOsF8jx+dj7sUrl3igNlmQM9Kbz4oc OtXg2FqbktOKZBRPzpXMv4l7geQfUTEaUj9hUCt/hfqhW1oSkJVNscPCJaxcAOz6dQGI gNpg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698351470; x=1698956270; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=k/Y1cqVei499MeRuO0JkL2AwtSOgPbZS08N4+Ku0vIU=; b=rloNY9lbUuDosM2+S8Z9vG69CmDast4FUEkpQt+9SeOJPFHT33KuEEje/nDY8aNYfi pqY+e265uNIRWjEE066qg71060wRCld/p+TJwR74oBdZAg6OhkqUBCih04k14IFZhVWb ZPC4FLrm96vbjHYXlnQ/+Hv41StkGNly60LpXZc1adOYYgtNQb2QrRH2qPbVjEKL4zPM t1qoTipR4M9jQWb/3LAGeys5OstH/UJzUse/FMs0IdEesxIKpI8eLDYtyk8+2am3FjOQ zi2el/I1DUS3u5G3aV0uFX8tB/OIDnQWCm9dICDX4W+E/KednW4S9TNzHiBKf2ecTxnp iLJg== X-Gm-Message-State: AOJu0YzM/haXIR8Dk4KBwUehvr8xAJRrEdMf+sRm/8vO6i44IZQPGZVc nxKLe3FvPZFZm3xzfx3IuUSPdHfWgUM= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a05:6902:1788:b0:da0:c9a5:b529 with SMTP id ca8-20020a056902178800b00da0c9a5b529mr7678ybb.12.1698351469567; Thu, 26 Oct 2023 13:17:49 -0700 (PDT) Date: Thu, 26 Oct 2023 13:17:47 -0700 In-Reply-To: Mime-Version: 1.0 References: <20231025-delay-verw-v3-0-52663677ee35@linux.intel.com> <20231025-delay-verw-v3-6-52663677ee35@linux.intel.com> Message-ID: Subject: Re: [PATCH v3 6/6] KVM: VMX: Move VERW closer to VMentry for MDS mitigation From: Sean Christopherson To: Pawan Gupta Cc: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Peter Zijlstra , Josh Poimboeuf , Andy Lutomirski , Jonathan Corbet , Paolo Bonzini , tony.luck@intel.com, ak@linux.intel.com, tim.c.chen@linux.intel.com, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, kvm@vger.kernel.org, Alyssa Milburn , Daniel Sneddon , antonio.gomez.iglesias@linux.intel.com Content-Type: text/plain; charset="us-ascii" X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Thu, 26 Oct 2023 13:18:03 -0700 (PDT) On Thu, Oct 26, 2023, Sean Christopherson wrote: > On Wed, Oct 25, 2023, Pawan Gupta wrote: > > vmx_disable_fb_clear(vmx); > > LOL, nice. IIUC, setting FB_CLEAR_DIS is mutually exclusive with doing a late > VERW, as KVM will never set FB_CLEAR_DIS if the CPU is susceptible to X86_BUG_MDS. > But the checks aren't identical, which makes this _look_ sketchy. > > Can you do something like this to ensure we don't accidentally neuter the late VERW? > > static void vmx_update_fb_clear_dis(struct kvm_vcpu *vcpu, struct vcpu_vmx *vmx) > { > vmx->disable_fb_clear = (host_arch_capabilities & ARCH_CAP_FB_CLEAR_CTRL) && > !boot_cpu_has_bug(X86_BUG_MDS) && > !boot_cpu_has_bug(X86_BUG_TAA); > > if (vmx->disable_fb_clear && > WARN_ON_ONCE(cpu_feature_enabled(X86_FEATURE_CLEAR_CPU_BUF))) > vmx->disable_fb_clear = false; > > ... > } Alternatively, and maybe even preferably, this would make it more obvious that the two are mutually exclusive and would also be a (very, very) small perf win when the mitigation is enabled. diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index 0936516cb93b..592103df1754 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -7236,7 +7236,8 @@ static noinstr void vmx_vcpu_enter_exit(struct kvm_vcpu *vcpu, kvm_arch_has_assigned_device(vcpu->kvm)) mds_clear_cpu_buffers(); - vmx_disable_fb_clear(vmx); + if (!cpu_feature_enabled(X86_FEATURE_CLEAR_CPU_BUF)) + vmx_disable_fb_clear(vmx); if (vcpu->arch.cr2 != native_read_cr2()) native_write_cr2(vcpu->arch.cr2); @@ -7249,7 +7250,8 @@ static noinstr void vmx_vcpu_enter_exit(struct kvm_vcpu *vcpu, vmx->idt_vectoring_info = 0; - vmx_enable_fb_clear(vmx); + if (!cpu_feature_enabled(X86_FEATURE_CLEAR_CPU_BUF)) + vmx_enable_fb_clear(vmx); if (unlikely(vmx->fail)) { vmx->exit_reason.full = 0xdead;