From nobody Mon Feb 9 10:12:02 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=1569505874; cv=none; d=zoho.com; s=zohoarc; b=TiFNpzq6e7x4FJoMcgK4lhShD+V0rjqHMZvt6JhHANovoUzGTTIaOc+A1/S27nlfVBhA/Gj3a+JbfyW2n9kdKL8ZrIJiQPOIz+4ynxJztGdfiS+G3ZU6h5Q1mKMBXHqji2Pyx9MYZacorbXlWjfIFoP2SjcG/3klJaMLMlVvjhU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1569505874; 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=Sf7Gbhbvq8PJTCzmxZTZgzUwUl0q6P1CAsZjeUj0WB8=; b=CA3x1F2G1p9S44Usuyglbb6UjV2oLleHzsq4QTGUWa+u0POiWfKTM0y6WFENUlBuEUcV6FqUQzvIupVoTzaK1pXdrT5F4gAP+3md8m85a8V/PmTX/POfNPwfoa3NWa2Tmr4fPHFrCwTQRaRLRDsqCEF//N6+gfQxs9u8XhBavj4= 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 1569505874240523.7066018486519; Thu, 26 Sep 2019 06:51:14 -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 1iDU9v-0002sQ-V9; Thu, 26 Sep 2019 13:50:15 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iDU9v-0002rM-9Z for xen-devel@lists.xenproject.org; Thu, 26 Sep 2019 13:50:15 +0000 Received: from mga04.intel.com (unknown [192.55.52.120]) by localhost (Halon) with ESMTPS id 86042980-e064-11e9-8628-bc764e2007e4; Thu, 26 Sep 2019 13:49:56 +0000 (UTC) Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 26 Sep 2019 06:49:56 -0700 Received: from gao-cwp.sh.intel.com ([10.239.159.26]) by fmsmga008.fm.intel.com with ESMTP; 26 Sep 2019 06:49:53 -0700 X-Inumbo-ID: 86042980-e064-11e9-8628-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,552,1559545200"; d="scan'208";a="189126073" From: Chao Gao To: xen-devel@lists.xenproject.org Date: Thu, 26 Sep 2019 21:53:35 +0800 Message-Id: <1569506015-26938-8-git-send-email-chao.gao@intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1569506015-26938-1-git-send-email-chao.gao@intel.com> References: <1569506015-26938-1-git-send-email-chao.gao@intel.com> Subject: [Xen-devel] [PATCH v11 7/7] microcode: reject late ucode loading if any core is parked 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: Sergey Dyasli , 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" If a core with all of its thread being parked, late ucode loading which currently only loads ucode on online threads would lead to differing ucode revisions in the system. In general, keeping ucode revision consistent would be less error-prone. To this end, if there is a parked thread doesn't have an online sibling thread, late ucode loading is rejected. Two threads are on the same core or computing unit iff they have the same phys_proc_id and cpu_core_id/compute_unit_id. Based on phys_proc_id and cpu_core_id/compute_unit_id, an unique core id is generated for each thread. And use a bitmap to reduce the number of comparison. Signed-off-by: Chao Gao --- Alternatively, we can mask the thread id off apicid and use it as the unique core id. It needs to introduce new field in cpuinfo_x86 to record the mask for thread id. So I don't take this way. --- xen/arch/x86/microcode.c | 75 +++++++++++++++++++++++++++++++++++++= ++++ xen/include/asm-x86/processor.h | 1 + 2 files changed, 76 insertions(+) diff --git a/xen/arch/x86/microcode.c b/xen/arch/x86/microcode.c index b9fa8bb..b70eb16 100644 --- a/xen/arch/x86/microcode.c +++ b/xen/arch/x86/microcode.c @@ -573,6 +573,64 @@ static int do_microcode_update(void *patch) return ret; } =20 +static unsigned int unique_core_id(unsigned int cpu, unsigned int socket_s= hift) +{ + unsigned int core_id =3D cpu_to_cu(cpu); + + if ( core_id =3D=3D INVALID_CUID ) + core_id =3D cpu_to_core(cpu); + + return (cpu_to_socket(cpu) << socket_shift) + core_id; +} + +static int has_parked_core(void) +{ + int ret =3D 0; + + if ( park_offline_cpus ) + { + unsigned int cpu, max_bits, core_width; + unsigned int max_sockets =3D 1, max_cores =3D 1; + struct cpuinfo_x86 *c =3D cpu_data; + unsigned long *bitmap; + + for_each_present_cpu(cpu) + { + if ( x86_cpu_to_apicid[cpu] =3D=3D BAD_APICID ) + continue; + + /* Note that cpu_to_socket() get an ID starting from 0. */ + if ( cpu_to_socket(cpu) + 1 > max_sockets ) + max_sockets =3D cpu_to_socket(cpu) + 1; + + if ( c[cpu].x86_max_cores > max_cores ) + max_cores =3D c[cpu].x86_max_cores; + } + + core_width =3D fls(max_cores); + max_bits =3D max_sockets << core_width; + bitmap =3D xzalloc_array(unsigned long, BITS_TO_LONGS(max_bits)); + if ( !bitmap ) + return -ENOMEM; + + for_each_present_cpu(cpu) + { + if ( cpu_online(cpu) || x86_cpu_to_apicid[cpu] =3D=3D BAD_APIC= ID ) + continue; + + __set_bit(unique_core_id(cpu, core_width), bitmap); + } + + for_each_online_cpu(cpu) + __clear_bit(unique_core_id(cpu, core_width), bitmap); + + ret =3D (find_first_bit(bitmap, max_bits) < max_bits); + xfree(bitmap); + } + + return ret; +} + int microcode_update(XEN_GUEST_HANDLE_PARAM(const_void) buf, unsigned long= len) { int ret; @@ -611,6 +669,23 @@ int microcode_update(XEN_GUEST_HANDLE_PARAM(const_void= ) buf, unsigned long len) */ ASSERT(cpumask_first(&cpu_online_map) =3D=3D nmi_cpu); =20 + /* + * If there is a core with all of its threads parked, late loading may + * cause differing ucode revisions in the system. Refuse this operatio= n. + */ + ret =3D has_parked_core(); + if ( ret ) + { + if ( ret > 0 ) + { + printk(XENLOG_WARNING + "Ucode loading aborted: found a parked core\n"); + ret =3D -EPERM; + } + xfree(buffer); + goto put; + } + patch =3D parse_blob(buffer, len); xfree(buffer); if ( IS_ERR(patch) ) diff --git a/xen/include/asm-x86/processor.h b/xen/include/asm-x86/processo= r.h index c92956f..753deec 100644 --- a/xen/include/asm-x86/processor.h +++ b/xen/include/asm-x86/processor.h @@ -171,6 +171,7 @@ extern unsigned int init_intel_cacheinfo(struct cpuinfo= _x86 *c); =20 #define cpu_to_core(_cpu) (cpu_data[_cpu].cpu_core_id) #define cpu_to_socket(_cpu) (cpu_data[_cpu].phys_proc_id) +#define cpu_to_cu(_cpu) (cpu_data[_cpu].compute_unit_id) =20 unsigned int apicid_to_socket(unsigned int); =20 --=20 1.8.3.1 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel