Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp3611844imm; Thu, 17 May 2018 11:31:44 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqN+p96XWnVxRuCU0GYVBhOE+4HCUqH1Ts9WLN2gyhLTGLWrR2vK/Eo+yqZ0GL9UcSJ1asD X-Received: by 2002:a17:902:a714:: with SMTP id w20-v6mr6056467plq.374.1526581904937; Thu, 17 May 2018 11:31:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526581904; cv=none; d=google.com; s=arc-20160816; b=Fv/q2b4GDL05clABuoDCD+bY3x+FX6GTAshTNXH/Upgk61LwAjwNHboEjaCjWhYf+q iH80/j4QbxFZblslxGEOJjmWos3PgXTvf5D09K70Kj5KCWv+WcYc+G96gW/7lTJMEGHA WqtDSOueBmYY5TkdAZOo780IyzSy0fQsX8phj0HOir10SYqvOPU7EB5UuHzUot3sokXE RJQUcS0kfjpIeRZo+CcPhpUzbDCgC1cJLMbNFG7GHZyrtUIdDioEawUWbpbK8sXzGBza V2BH+uXMfSzCJ0l3q0UkRemJ/CEYEkCGZEB+X97cPnHaWh1v/q+4itG/lurtxTk/7HsN cZXg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date :arc-authentication-results; bh=6OufBn6oUc7YrzFp4UVV2Szoq748bgr0MzWqyVfIOd0=; b=woHBKeofgi7FJoUkHKbNUwRQNQSbtlhkWPj8etkYekaklYIBGV0Ck35lIisUqBrLa4 i1nv3hOGGbfdCt0tOYztM+phAEYiM0ddiH87dPz5nafLN1f3UJeVPdLEzlh9BhEJrn/j WJy/u3O75qDXSaIPNWCgemNkmrqvgFn973X7bY5uaTgWONOUkT0uk/mhB3muF0+c+iGM A4CMISV0kRQHM6UtNQuyCRtQd72IbOpyxx+OmDDDGotMdK3MoDrYVsJyoGxQUJSs/VBL 0DVGV+bfhPh7uFNwEy75humGRLJGRa/Ik/YsO+bHKYLkR4elVpzydO9fWHsq99jiyyrY 2Gew== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s10-v6si4441074pgs.189.2018.05.17.11.31.30; Thu, 17 May 2018 11:31:44 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751977AbeEQSbT (ORCPT + 99 others); Thu, 17 May 2018 14:31:19 -0400 Received: from mx2.suse.de ([195.135.220.15]:35239 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751047AbeEQSbR (ORCPT ); Thu, 17 May 2018 14:31:17 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 1A83EACBF; Thu, 17 May 2018 18:31:16 +0000 (UTC) Date: Thu, 17 May 2018 20:30:58 +0200 From: Borislav Petkov To: "Ghannam, Yazen" Cc: Johannes Hirte , "linux-edac@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "tony.luck@intel.com" , "x86@kernel.org" Subject: [PATCH 1/2] x86/MCE/AMD: Cache SMCA MISC block addresses Message-ID: <20180517183058.GA24312@pd.tnic> References: <20180414004230.GA2033@probook> <20180416115624.GA1543@probook> <20180515093953.GA1746@probook> <20180516224641.GA31929@pd.tnic> <20180517064930.GA26421@probook> <20180517104124.GA25595@pd.tnic> <20180517134415.GC27738@pd.tnic> 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.3 (2018-01-21) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Borislav Petkov ... into a global, two-dimensional array and service subsequent reads from that cache to avoid rdmsr_on_cpu() calls during CPU hotplug (IPIs with IRQs disabled). In addition, this fixes a KASAN slab-out-of-bounds read due to wrong usage of the bank->blocks pointer. Reported-by: Johannes Hirte Signed-off-by: Borislav Petkov Cc: Yazen Ghannam Fixes: 27bd59502702 ("x86/mce/AMD: Get address from already initialized block") Link: http://lkml.kernel.org/r/20180414004230.GA2033@probook --- arch/x86/kernel/cpu/mcheck/mce_amd.c | 29 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/arch/x86/kernel/cpu/mcheck/mce_amd.c b/arch/x86/kernel/cpu/mcheck/mce_amd.c index f7666eef4a87..c8e038800591 100644 --- a/arch/x86/kernel/cpu/mcheck/mce_amd.c +++ b/arch/x86/kernel/cpu/mcheck/mce_amd.c @@ -94,6 +94,11 @@ static struct smca_bank_name smca_names[] = { [SMCA_SMU] = { "smu", "System Management Unit" }, }; +static u32 smca_bank_addrs[MAX_NR_BANKS][NR_BLOCKS] __ro_after_init = +{ + [0 ... MAX_NR_BANKS - 1] = { [0 ... NR_BLOCKS - 1] = -1 } +}; + const char *smca_get_name(enum smca_bank_types t) { if (t >= N_SMCA_BANK_TYPES) @@ -443,20 +448,26 @@ static u32 smca_get_block_address(unsigned int cpu, unsigned int bank, if (!block) return MSR_AMD64_SMCA_MCx_MISC(bank); + /* Check our cache first: */ + if (smca_bank_addrs[bank][block] != -1) + return smca_bank_addrs[bank][block]; + /* * For SMCA enabled processors, BLKPTR field of the first MISC register * (MCx_MISC0) indicates presence of additional MISC regs set (MISC1-4). */ if (rdmsr_safe_on_cpu(cpu, MSR_AMD64_SMCA_MCx_CONFIG(bank), &low, &high)) - return addr; + goto out; if (!(low & MCI_CONFIG_MCAX)) - return addr; + goto out; if (!rdmsr_safe_on_cpu(cpu, MSR_AMD64_SMCA_MCx_MISC(bank), &low, &high) && (low & MASK_BLKPTR_LO)) - return MSR_AMD64_SMCA_MCx_MISCy(bank, block - 1); + addr = MSR_AMD64_SMCA_MCx_MISCy(bank, block - 1); +out: + smca_bank_addrs[bank][block] = addr; return addr; } @@ -468,18 +479,6 @@ static u32 get_block_address(unsigned int cpu, u32 current_addr, u32 low, u32 hi if ((bank >= mca_cfg.banks) || (block >= NR_BLOCKS)) return addr; - /* Get address from already initialized block. */ - if (per_cpu(threshold_banks, cpu)) { - struct threshold_bank *bankp = per_cpu(threshold_banks, cpu)[bank]; - - if (bankp && bankp->blocks) { - struct threshold_block *blockp = &bankp->blocks[block]; - - if (blockp) - return blockp->address; - } - } - if (mce_flags.smca) return smca_get_block_address(cpu, bank, block); -- 2.17.0.391.g1f1cddd558b5 SUSE Linux GmbH, GF: Felix Imendörffer, Jane Smithard, Graham Norton, HRB 21284 (AG Nürnberg) --