Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 90A4CC433F5 for ; Wed, 12 Jan 2022 10:49:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352616AbiALKtN (ORCPT ); Wed, 12 Jan 2022 05:49:13 -0500 Received: from mga03.intel.com ([134.134.136.65]:11364 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239535AbiALKtM (ORCPT ); Wed, 12 Jan 2022 05:49:12 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1641984552; x=1673520552; h=date:from:to:cc:subject:message-id:references: mime-version:content-transfer-encoding:in-reply-to; bh=/Ap0QBU3t/R1DSPsppRpZ66Vza8HREIl/QzjQ9in2CA=; b=F852mrDD6MaVoebHZtss0jgBH+EoROfTSFlO1IsSKy09nuqnFGbydNQr S4qspQGp9/rFSEmuDWlDvM/V1URMVDJFSu23mKLiKTsVf7XPKIAOviE18 07vhGIlI1VVHKvrpDx5ZUW8Gc+H9vpXHeI39gtluIl2dy12+ousH3M+rL KX6rmxb+Xo87zk8NYBRAfX1dpxF/c1/qUKgGa9aZT6Qpr5IrIYZjAQqXk 6meyVTKyBU7Cyf7PErAXzp32ewbkHWi4Q6GxTYlQZVGMdl4wyOZRqlHfA 7NGNDFssOwulknnUowlqAR41e7cdN1Ay4tZeg/vaKjWO4AIKq0cHIJk6w Q==; X-IronPort-AV: E=McAfee;i="6200,9189,10224"; a="243663661" X-IronPort-AV: E=Sophos;i="5.88,282,1635231600"; d="scan'208";a="243663661" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Jan 2022 02:49:11 -0800 X-IronPort-AV: E=Sophos;i="5.88,282,1635231600"; d="scan'208";a="515442067" Received: from gao-cwp.sh.intel.com (HELO gao-cwp) ([10.239.159.105]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Jan 2022 02:49:07 -0800 Date: Wed, 12 Jan 2022 19:00:01 +0800 From: Chao Gao To: Sean Christopherson Cc: "Tian, Kevin" , "kvm@vger.kernel.org" , "pbonzini@redhat.com" , "tglx@linutronix.de" , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , Ingo Molnar , Borislav Petkov , Dave Hansen , "x86@kernel.org" , "H. Peter Anvin" , "linux-kernel@vger.kernel.org" Subject: Re: [PATCH 5/6] KVM: x86: Remove WARN_ON in kvm_arch_check_processor_compat Message-ID: <20220112110000.GA10249@gao-cwp> References: <20211227081515.2088920-1-chao.gao@intel.com> <20211227081515.2088920-6-chao.gao@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.9.4 (2018-02-28) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jan 11, 2022 at 07:48:39PM +0000, Sean Christopherson wrote: >On Tue, Jan 11, 2022, Tian, Kevin wrote: >> > From: Sean Christopherson >> > Sent: Tuesday, January 11, 2022 7:00 AM >> > >> > On Mon, Dec 27, 2021, Chao Gao wrote: >> > > kvm_arch_check_processor_compat() needn't be called with interrupt >> > > disabled, as it only reads some CRs/MSRs which won't be clobbered >> > > by interrupt handlers or softirq. >> > > >> > > What really needed is disabling preemption. No additional check is >> > > added because if CONFIG_DEBUG_PREEMPT is enabled, smp_processor_id() >> > > (right above the WARN_ON()) can help to detect any violation. >> > >> > Hrm, IIRC, the assertion that IRQs are disabled was more about detecting >> > improper usage with respect to KVM doing hardware enabling than it was >> > about ensuring the current task isn't migrated. E.g. as exhibited by patch >> > 06, extra protections (disabling of hotplug in that case) are needed if >> > this helper is called outside of the core KVM hardware enabling flow since >> > hardware_enable_all() does its thing via SMP function call. >> >> Looks the WARN_ON() was added by you. ???? > >Yeah, past me owes current me a beer. > >> commit f1cdecf5807b1a91829a2dc4f254bfe6bafd4776 >> Author: Sean Christopherson >> Date: Tue Dec 10 14:44:14 2019 -0800 >> >> KVM: x86: Ensure all logical CPUs have consistent reserved cr4 bits >> >> Check the current CPU's reserved cr4 bits against the mask calculated >> for the boot CPU to ensure consistent behavior across all CPUs. >> >> Signed-off-by: Sean Christopherson >> Signed-off-by: Paolo Bonzini >> >> But it's unclear to me how this WARN_ON() is related to what the commit >> msg tries to explain. > >Ya, the changelog and lack of a comment is awful. > >> When I read this code it's more like a sanity check on the assumption that it >> is currently called in SMP function call which runs the said function with >> interrupt disabled. > >Yes, and as above, that assertion was more about the helper not really being safe >for general usage as opposed to wanting to detect use from preemptible context. >If we end up keeping the WARN_ON, I'll happily write a comment explaining the >point of the assertion. OK. I will do following changes to keep the WARN_ON(): 1. drop this patch 2. disable interrupt before the call site in patch 6.