From nobody Mon Feb 9 20:32:42 2026 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1566177788; cv=none; d=zoho.com; s=zohoarc; b=U7CGy/72tNNiD54aCYqto9me5zG5tEQYkQecZnRnhdwlVyC26KbD++oGvD+477HYid1BmUjIDGhPr2WC5QK+eVHaX9Vx/lIZCj0MKP1TZhc0D13VBuBjsNkbwjo07KydHFoc4HkadmtA2sKXeJu4HCyPo+NTM5+FfaTKOgiAiYw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1566177788; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=DEXEQHHE921KP4VhiXOXzsNjZN+MVASHZaAtv4hjQtU=; b=hRNfiQL5jksmN14xu9ICShH6eMks5ZHSOoz5Hr9xptbQz4QvafZUKd3hxzrDK+vd/F1V0y3Y1QZ9G4WhwX9vyylzxHSCqnaa5FykkSHCVTqEcGhQ3JhV/5/Swo/Ygf5qihlGLWkJvc51tR5hhxQ8P9fnsQE2D7Zt57RikEU0TVU= ARC-Authentication-Results: i=1; mx.zoho.com; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 156617778831888.20349834462877; Sun, 18 Aug 2019 18:23:08 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hzWNV-0001qM-US; Mon, 19 Aug 2019 01:22:33 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hzWNU-0001pW-LU for xen-devel@lists.xenproject.org; Mon, 19 Aug 2019 01:22:32 +0000 Received: from mga09.intel.com (unknown [134.134.136.24]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id d1010542-c21f-11e9-aee9-bc764e2007e4; Mon, 19 Aug 2019 01:22:31 +0000 (UTC) Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 18 Aug 2019 18:22:31 -0700 Received: from gao-cwp.sh.intel.com ([10.239.159.26]) by orsmga001.jf.intel.com with ESMTP; 18 Aug 2019 18:22:30 -0700 X-Inumbo-ID: d1010542-c21f-11e9-aee9-bc764e2007e4 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,403,1559545200"; d="scan'208";a="261684035" From: Chao Gao To: xen-devel@lists.xenproject.org Date: Mon, 19 Aug 2019 09:25:28 +0800 Message-Id: <1566177928-19114-16-git-send-email-chao.gao@intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1566177928-19114-1-git-send-email-chao.gao@intel.com> References: <1566177928-19114-1-git-send-email-chao.gao@intel.com> Subject: [Xen-devel] [PATCH v9 15/15] microcode: block #NMI handling when loading an ucode X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Ashok Raj , Wei Liu , Andrew Cooper , Jan Beulich , Chao Gao , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" register an nmi callback. And this callback does busy-loop on threads which are waiting for loading completion. Control threads send NMI to slave threads to prevent NMI acceptance during ucode loading. Signed-off-by: Chao Gao --- Changes in v9: - control threads send NMI to all other threads. Slave threads will stay in the NMI handling to prevent NMI acceptance during ucode loading. Note that self-nmi is invalid according to SDM. - s/rep_nop/cpu_relax - remove debug message in microcode_nmi_callback(). Printing debug message would take long times and control thread may timeout. - rebase and fix conflicts Changes in v8: - new --- xen/arch/x86/microcode.c | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/xen/arch/x86/microcode.c b/xen/arch/x86/microcode.c index 91f9e81..d943835 100644 --- a/xen/arch/x86/microcode.c +++ b/xen/arch/x86/microcode.c @@ -38,6 +38,7 @@ =20 #include #include +#include #include #include #include @@ -339,14 +340,8 @@ static int microcode_update_cpu(const struct microcode= _patch *patch) =20 static int slave_thread_fn(void) { - unsigned int cpu =3D smp_processor_id(); unsigned int master =3D cpumask_first(this_cpu(cpu_sibling_mask)); =20 - while ( loading_state !=3D LOADING_CALLIN ) - cpu_relax(); - - cpumask_set_cpu(cpu, &cpu_callin_map); - while ( loading_state !=3D LOADING_EXIT ) cpu_relax(); =20 @@ -399,6 +394,8 @@ static int control_thread_fn(const struct microcode_pat= ch *patch) =20 cpumask_set_cpu(cpu, &cpu_callin_map); =20 + smp_send_nmi_allbutself(); + /* Waiting for all threads calling in */ ret =3D wait_for_condition(wait_cpu_callin, (void *)(unsigned long)num_online_cpus(), @@ -481,12 +478,28 @@ static int do_microcode_update(void *patch) return ret; } =20 +static int microcode_nmi_callback(const struct cpu_user_regs *regs, int cp= u) +{ + /* The first thread of a core is to load an update. Don't block it. */ + if ( cpu =3D=3D cpumask_first(per_cpu(cpu_sibling_mask, cpu)) || + loading_state !=3D LOADING_CALLIN ) + return 0; + + cpumask_set_cpu(cpu, &cpu_callin_map); + + while ( loading_state !=3D LOADING_EXIT ) + cpu_relax(); + + return 0; +} + int microcode_update(XEN_GUEST_HANDLE_PARAM(const_void) buf, unsigned long= len) { int ret; void *buffer; unsigned int cpu, updated; struct microcode_patch *patch; + nmi_callback_t *saved_nmi_callback; =20 if ( len !=3D (uint32_t)len ) return -E2BIG; @@ -551,6 +564,8 @@ int microcode_update(XEN_GUEST_HANDLE_PARAM(const_void)= buf, unsigned long len) * watchdog timeout. */ watchdog_disable(); + + saved_nmi_callback =3D set_nmi_callback(microcode_nmi_callback); /* * Late loading dance. Why the heavy-handed stop_machine effort? * @@ -563,6 +578,7 @@ int microcode_update(XEN_GUEST_HANDLE_PARAM(const_void)= buf, unsigned long len) * conservative and good. */ ret =3D stop_machine_run(do_microcode_update, patch, NR_CPUS); + set_nmi_callback(saved_nmi_callback); watchdog_enable(); =20 updated =3D atomic_read(&cpu_updated); --=20 1.8.3.1 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel