From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757063AbdEUUCT (ORCPT ); Sun, 21 May 2017 16:02:19 -0400 Received: from terminus.zytor.com ([65.50.211.136]:58593 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756755AbdEUUCR (ORCPT ); Sun, 21 May 2017 16:02:17 -0400 Date: Sun, 21 May 2017 12:59:05 -0700 From: tip-bot for Elena Reshetova Message-ID: Cc: dwindsor@gmail.com, ishkamiel@gmail.com, bp@suse.de, mingo@kernel.org, hpa@zytor.com, tony.luck@intel.com, linux-kernel@vger.kernel.org, keescook@chromium.org, linux-edac@vger.kernel.org, Yazen.Ghannam@amd.com, elena.reshetova@intel.com, tglx@linutronix.de Reply-To: mingo@kernel.org, linux-kernel@vger.kernel.org, tony.luck@intel.com, hpa@zytor.com, dwindsor@gmail.com, bp@suse.de, ishkamiel@gmail.com, Yazen.Ghannam@amd.com, tglx@linutronix.de, elena.reshetova@intel.com, linux-edac@vger.kernel.org, keescook@chromium.org In-Reply-To: <1492695536-5947-1-git-send-email-elena.reshetova@intel.com> References: <1492695536-5947-1-git-send-email-elena.reshetova@intel.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:ras/core] x86/mce: Convert threshold_bank.cpus from atomic_t to refcount_t Git-Commit-ID: 473e90b2e8356f084dcf9c815a5170d4d4925897 X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: 473e90b2e8356f084dcf9c815a5170d4d4925897 Gitweb: http://git.kernel.org/tip/473e90b2e8356f084dcf9c815a5170d4d4925897 Author: Elena Reshetova AuthorDate: Fri, 19 May 2017 11:39:13 +0200 Committer: Thomas Gleixner CommitDate: Sun, 21 May 2017 21:55:13 +0200 x86/mce: Convert threshold_bank.cpus from atomic_t to refcount_t The refcount_t type and corresponding API should be used instead of atomic_t when the variable is used as a reference counter. This allows to avoid accidental refcounter overflows that might lead to use-after-free situations. Suggested-by: Kees Cook Signed-off-by: Elena Reshetova Signed-off-by: Borislav Petkov Reviewed-by: Hans Liljestrand Reviewed-by: David Windsor Cc: Tony Luck Cc: Yazen Ghannam Cc: linux-edac Link: http://lkml.kernel.org/r/1492695536-5947-1-git-send-email-elena.reshetova@intel.com Signed-off-by: Thomas Gleixner --- arch/x86/include/asm/amd_nb.h | 3 ++- arch/x86/kernel/cpu/mcheck/mce_amd.c | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/arch/x86/include/asm/amd_nb.h b/arch/x86/include/asm/amd_nb.h index 00c88a0..da181ad 100644 --- a/arch/x86/include/asm/amd_nb.h +++ b/arch/x86/include/asm/amd_nb.h @@ -3,6 +3,7 @@ #include #include +#include struct amd_nb_bus_dev_range { u8 bus; @@ -55,7 +56,7 @@ struct threshold_bank { struct threshold_block *blocks; /* initialized to the number of CPUs on the node sharing this bank */ - atomic_t cpus; + refcount_t cpus; }; struct amd_northbridge { diff --git a/arch/x86/kernel/cpu/mcheck/mce_amd.c b/arch/x86/kernel/cpu/mcheck/mce_amd.c index 6e4a047..41439ab 100644 --- a/arch/x86/kernel/cpu/mcheck/mce_amd.c +++ b/arch/x86/kernel/cpu/mcheck/mce_amd.c @@ -1202,7 +1202,7 @@ static int threshold_create_bank(unsigned int cpu, unsigned int bank) goto out; per_cpu(threshold_banks, cpu)[bank] = b; - atomic_inc(&b->cpus); + refcount_inc(&b->cpus); err = __threshold_add_blocks(b); @@ -1225,7 +1225,7 @@ static int threshold_create_bank(unsigned int cpu, unsigned int bank) per_cpu(threshold_banks, cpu)[bank] = b; if (is_shared_bank(bank)) { - atomic_set(&b->cpus, 1); + refcount_set(&b->cpus, 1); /* nb is already initialized, see above */ if (nb) { @@ -1289,7 +1289,7 @@ static void threshold_remove_bank(unsigned int cpu, int bank) goto free_out; if (is_shared_bank(bank)) { - if (!atomic_dec_and_test(&b->cpus)) { + if (!refcount_dec_and_test(&b->cpus)) { __threshold_remove_blocks(b); per_cpu(threshold_banks, cpu)[bank] = NULL; return;