Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp3674967rwd; Mon, 22 May 2023 18:35:10 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5f5u+6xVVGNPvas6j2isnmyUdU3z+x0+tIa+AggpVl8V8QjqwCJifsOIs+JwpsigNgETiW X-Received: by 2002:a17:902:d483:b0:1a6:f755:a4a0 with SMTP id c3-20020a170902d48300b001a6f755a4a0mr14053333plg.58.1684805710365; Mon, 22 May 2023 18:35:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684805710; cv=none; d=google.com; s=arc-20160816; b=DL243SGojAVF338uDS6UVX7MW9nYtVwZbd2RhloFc1XBJtUAn3pPpZKsYMoKGdUfIK ZJ18ord6ofqm2MT3iDd62xrZ3GwQep5y8UKWpKDkbN96rQ4yPuHZgGIbNNohLjSCoQCD GBkFKEL6C9TLkf0TWqDty+z3fIur9NJZwUa5pPsjvTyTNBmJ4uEyLwzKaEx2NWGSTRrY fpSnNfstuaIeBXrQypbq62vmrrex44glgMAiZWSgAD6psa9E1ozQ0YO6ubbkLnePQeRa zCIX9PdLuvm8BwibamYDYFogMH5tOfGFP8RYkX5f5q93flkylyMX1p1+J12EPsogYPDh XlAQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=F/PsL42w42Evs21DJ2r+WgCOEcwi7ln528ntfP6X8ug=; b=enKvre5ZhaD7lBV9pwNapOkATu6e2abXGJ7cQDgw7LRC61uZHriffwrwHFVCEP9ES+ JmrzEbZ+Z0h23mu7LPNadbsdiaJdPihVvonviIOrKJZLci8wXJD3oMIeLpcMYUOaja5V UohRV+LG9MkHw32OZco8k/ExxChcwNocykka8ZQaHgOpy4AxL9y3DqlJWyPipoKWKmXN PPGFFrX2Z4NcgkY1v7bm7jkA18KFF1vc9k/y5PRUoOfsN0rXhlhF+FgodtyCHdsFGNkE oCRd3E+qMw0joY3re9rn/qQEyWLqeP61nFVgw8w+ywPJEBlMeRRbv68llGLUSnmHxueZ DiTw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=g6bHpgGs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k11-20020a170902c40b00b001a6d08dc834si5955568plk.22.2023.05.22.18.34.58; Mon, 22 May 2023 18:35:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=g6bHpgGs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235256AbjEWBCs (ORCPT + 99 others); Mon, 22 May 2023 21:02:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59352 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232644AbjEWBCa (ORCPT ); Mon, 22 May 2023 21:02:30 -0400 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 806F6110; Mon, 22 May 2023 18:00:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1684803658; x=1716339658; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=rtIQBh9F3oyBoHplZAgRHsNnNkZoyG1p6l5/G7ETlYk=; b=g6bHpgGsEu5HkP5I8Kei2teeZIEK2GUqWHJ6GIDDevl/iU0OnxrK2C9E xEHDSh6oC0fk7+Mx1PaI6V5kQKDNx/mI5SVOnM0861AGXivhU+OC6KHOi fKzVsG9d8ulTyXv+1+RPTiGZG1oXRH6h52xWPqYJ5earGNB1PWwaXnA6C bn0Ot/Qdolg/eZT8R0ExGvQCoZDoW24K4DCiDouRE/9X0nUKU7UTr9QbQ I1I9WVGscrnlLgLhzsuUgq8FshzYLSEaiOSjBvE03RZOfFDHlEui1+s87 gR5fFRnJMUP2ss6T/1UweiAaWOPpHm2lH8ehe0qnXhQWvNcxd7M/GNFI1 g==; X-IronPort-AV: E=McAfee;i="6600,9927,10718"; a="351935163" X-IronPort-AV: E=Sophos;i="6.00,184,1681196400"; d="scan'208";a="351935163" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 May 2023 18:00:57 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10718"; a="734557346" X-IronPort-AV: E=Sophos;i="6.00,184,1681196400"; d="scan'208";a="734557346" Received: from xiaoyaol-hp-g830.ccr.corp.intel.com (HELO [10.254.209.247]) ([10.254.209.247]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 May 2023 18:00:53 -0700 Message-ID: Date: Tue, 23 May 2023 09:00:50 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Firefox/102.0 Thunderbird/102.11.0 Subject: Re: [PATCH] KVM: x86: Track supported ARCH_CAPABILITIES in kvm_caps Content-Language: en-US To: Pawan Gupta Cc: Sean Christopherson , Chao Gao , kvm@vger.kernel.org, Paolo Bonzini , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , linux-kernel@vger.kernel.org, Jim Mattson , antonio.gomez.iglesias@linux.intel.com, Daniel Sneddon References: <20230506030435.80262-1-chao.gao@intel.com> <20230520010237.3tepk3q44j52leuk@desk> <20230522212328.uwyvp3hpwvte6t6g@desk> From: Xiaoyao Li In-Reply-To: <20230522212328.uwyvp3hpwvte6t6g@desk> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,HK_RANDOM_ENVFROM, HK_RANDOM_FROM,NICE_REPLY_A,RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 5/23/2023 5:23 AM, Pawan Gupta wrote: > On Tue, May 23, 2023 at 03:31:44AM +0800, Xiaoyao Li wrote: >> On 5/23/2023 1:43 AM, Sean Christopherson wrote: >>>>> 6. Performance aside, KVM should not be speculating (ha!) on what the guest >>>>> will and will not do, and should instead honor whatever behavior is presented >>>>> to the guest. If the guest CPU model indicates that VERW flushes buffers, >>>>> then KVM damn well needs to let VERW flush buffers. >>>> The current implementation allows guests to have VERW flush buffers when >>>> they enumerate FB_CLEAR. It only restricts the flush behavior when the >>>> guest is trying to mitigate against a vulnerability(like MDS) on a >>>> hardware that is not affected. I guess its common for guests to be >>>> running with older gen configuration on a newer hardware. >>> Right, I'm saying that that behavior is wrong. KVM shouldn't assume the guest >>> the guest will do things a certain way and should instead honor the "architectural" >>> definition, in quotes because I realize there probably is no architectural >>> definition for any of this. >>> >>> It might be that the code does (unintentionally?) honor the "architecture", i.e. >>> this code might actually be accurrate with respect to when the guest can expect >>> VERW to flush buffers. But the comment is so, so wrong. >> >> The comment is wrong and the code is wrong in some case as well. >> >> If none of ARCH_CAP_FB_CLEAR, ARCH_CAP_MDS_NO, ARCH_CAP_TAA_NO, >> ARCH_CAP_PSDP_NO, ARCH_CAP_FBSDP_NO and ARCH_CAP_SBDR_SSDP_NO are exposed to >> VM, the VM is type of "affected by MDS". >> >> And accroding to the page https://www.intel.com/content/www/us/en/developer/articles/technical/software-security-guidance/technical-documentation/processor-mmio-stale-data-vulnerabilities.html >> >> if the VM enumerates support for both L1D_FLUSH and MD_CLEAR, it implicitly >> enumerates FB_CLEAR as part of their MD_CLEAR support. > > This is the excerpt from the link that you mentioned: > > "For processors that are affected by MDS and support L1D_FLUSH > operations and MD_CLEAR operations, the VERW instruction flushes fill > buffers." > > You are missing an important information here "For the processors > _affected_ by MDS". On such processors ... > >> However, the code will leave vmx->disable_fb_clear as 1 if hardware supports >> it, and VERW intruction doesn't clear FB in the VM, which conflicts >> "architectural" definition. > > ... Fill buffer clear is not enabled at all: > > vmx_setup_fb_clear_ctrl() > { > u64 msr; > > if (boot_cpu_has(X86_FEATURE_ARCH_CAPABILITIES) && > !boot_cpu_has_bug(X86_BUG_MDS) && > !boot_cpu_has_bug(X86_BUG_TAA)) { > rdmsrl(MSR_IA32_ARCH_CAPABILITIES, msr); > if (msr & ARCH_CAP_FB_CLEAR_CTRL) > vmx_fb_clear_ctrl_available = true; > } > } This is the check of bare metal, while the check in vmx_update_fb_clear_dis() is of guest VM. For example, if the hardware (host) enumerates ARCH_CAP_TAA_NO, ARCH_CAP_MDS_NO, ARCH_CAP_PSDP_NO, ARCH_CAP_FBSDP_NO, ARCH_CAP_SBDR_SSDP_NO, ARCH_CAP_FB_CLEAR, and ARCH_CAP_FB_CLEAR_CTRL, the VERW on this hardware clears Fill Buffer (if FB_CLEAR_DIS is not enabled in MSR_IA32_MCU_OPT_CTRL). vmx_setup_fb_clear_ctrl() does set vmx_fb_clear_ctrl_available to true. If a guest is exposed without ARCH_CAP_TAA_NO, ARCH_CAP_MDS_NO, ARCH_CAP_PSDP_NO, ARCH_CAP_FBSDP_NO, ARCH_CAP_SBDR_SSDP_NO and ARCH_CAP_FB_CLEAR, vmx_update_fb_clear_dis() will leave vmx->disable_fb_clear as true. So VERW doesn't clear Fill Buffer for guest. But in the view of guset, it expects VERW to clear Fill Buffer.