From patchwork Thu Sep 12 07:22:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chao Gao X-Patchwork-Id: 11142489 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 74CE516B1 for ; Thu, 12 Sep 2019 07:20:53 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 5A60020678 for ; Thu, 12 Sep 2019 07:20:53 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5A60020678 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=intel.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1i8JOJ-000251-7e; Thu, 12 Sep 2019 07:19:43 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1i8JOI-00024F-72 for xen-devel@lists.xenproject.org; Thu, 12 Sep 2019 07:19:42 +0000 X-Inumbo-ID: a0d2847e-d52d-11e9-83e3-12813bfff9fa Received: from mga01.intel.com (unknown [192.55.52.88]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id a0d2847e-d52d-11e9-83e3-12813bfff9fa; Thu, 12 Sep 2019 07:19:16 +0000 (UTC) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 12 Sep 2019 00:19:15 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,492,1559545200"; d="scan'208";a="189906389" Received: from gao-cwp.sh.intel.com ([10.239.159.26]) by orsmga006.jf.intel.com with ESMTP; 12 Sep 2019 00:19:13 -0700 From: Chao Gao To: xen-devel@lists.xenproject.org Date: Thu, 12 Sep 2019 15:22:28 +0800 Message-Id: <1568272949-1086-16-git-send-email-chao.gao@intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1568272949-1086-1-git-send-email-chao.gao@intel.com> References: <1568272949-1086-1-git-send-email-chao.gao@intel.com> Subject: [Xen-devel] [PATCH v10 15/16] microcode: disable late loading if CPUs are affected by BDF90 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?R?= =?utf-8?q?oger_Pau_Monn=C3=A9?= MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" It ports the implementation of is_blacklisted() in linux kernel to Xen. Late loading may cause system hang if CPUs are affected by BDF90. Check against BDF90 before performing a late loading. Signed-off-by: Chao Gao --- xen/arch/x86/microcode.c | 6 ++++++ xen/arch/x86/microcode_intel.c | 23 +++++++++++++++++++++++ xen/include/asm-x86/microcode.h | 1 + 3 files changed, 30 insertions(+) diff --git a/xen/arch/x86/microcode.c b/xen/arch/x86/microcode.c index 64a4321..dbd2730 100644 --- a/xen/arch/x86/microcode.c +++ b/xen/arch/x86/microcode.c @@ -561,6 +561,12 @@ int microcode_update(XEN_GUEST_HANDLE_PARAM(const_void) buf, unsigned long len) if ( microcode_ops == NULL ) return -EINVAL; + if ( microcode_ops->is_blacklisted && microcode_ops->is_blacklisted() ) + { + printk(XENLOG_WARNING "Late ucode loading is disabled!\n"); + return -EPERM; + } + buffer = xmalloc_bytes(len); if ( !buffer ) return -ENOMEM; diff --git a/xen/arch/x86/microcode_intel.c b/xen/arch/x86/microcode_intel.c index 19f1ba0..bcef668 100644 --- a/xen/arch/x86/microcode_intel.c +++ b/xen/arch/x86/microcode_intel.c @@ -28,6 +28,7 @@ #include #include +#include #include #include #include @@ -283,6 +284,27 @@ static enum microcode_match_result compare_patch( : OLD_UCODE; } +static bool is_blacklisted(void) +{ + struct cpuinfo_x86 *c = ¤t_cpu_data; + uint64_t llc_size = c->x86_cache_size * 1024ULL; + struct cpu_signature *sig = &this_cpu(cpu_sig); + + do_div(llc_size, c->x86_max_cores); + + /* + * Late loading on model 79 with microcode revision less than 0x0b000021 + * and LLC size per core bigger than 2.5MB may result in a system hang. + * This behavior is documented in item BDF90, #334165 (Intel Xeon + * Processor E7-8800/4800 v4 Product Family). + */ + if ( c->x86 == 6 && c->x86_model == 0x4F && c->x86_mask == 0x1 && + llc_size > 2621440 && sig->rev < 0x0b000021 ) + return true; + + return false; +} + static int apply_microcode(const struct microcode_patch *patch) { uint64_t msr_content; @@ -415,6 +437,7 @@ static const struct microcode_ops microcode_intel_ops = { .free_patch = free_patch, .compare_patch = compare_patch, .match_cpu = match_cpu, + .is_blacklisted = is_blacklisted, }; int __init microcode_init_intel(void) diff --git a/xen/include/asm-x86/microcode.h b/xen/include/asm-x86/microcode.h index 7d5a1f8..9ffd9d2 100644 --- a/xen/include/asm-x86/microcode.h +++ b/xen/include/asm-x86/microcode.h @@ -30,6 +30,7 @@ struct microcode_ops { bool (*match_cpu)(const struct microcode_patch *patch); enum microcode_match_result (*compare_patch)( const struct microcode_patch *new, const struct microcode_patch *old); + bool (*is_blacklisted)(void); }; struct cpu_signature {