From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751675AbdJ0HPB (ORCPT ); Fri, 27 Oct 2017 03:15:01 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:9518 "EHLO szxga05-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751050AbdJ0HPA (ORCPT ); Fri, 27 Oct 2017 03:15:00 -0400 From: Zhou Chengming To: , , , , , , , CC: , , Subject: [PATCH] x86/alternatives: free smp_alt_modules when enable smp Date: Fri, 27 Oct 2017 15:18:12 +0800 Message-ID: <1509088692-9971-1-git-send-email-zhouchengming1@huawei.com> X-Mailer: git-send-email 1.8.3.1 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.175.113.25] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A090203.59F2DCDE.004C,ss=1,re=0.000,recu=0.000,reip=0.000,cl=1,cld=1,fgs=0, ip=0.0.0.0, so=2014-11-16 11:51:01, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: bb0aa69a5cd5559b95861bdc1423e0b2 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In the current code, we don't free smp_alt_modules when enable smp, so have to wait module unload to call alternatives_smp_module_del() to free its smp_alt_module. This strategy has shortcomings. We can make sure smp_alt_modules will be useless after enable smp, so free it all. And alternatives_smp_module_del() can return directly when !uniproc_patched to avoid a list traversal. Signed-off-by: Zhou Chengming --- arch/x86/kernel/alternative.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c index 3344d33..8549269 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -534,6 +534,9 @@ void __init_or_module alternatives_smp_module_del(struct module *mod) struct smp_alt_module *item; mutex_lock(&smp_alt); + if (!uniproc_patched) + goto unlock; + list_for_each_entry(item, &smp_alt_modules, next) { if (mod != item->mod) continue; @@ -541,12 +544,13 @@ void __init_or_module alternatives_smp_module_del(struct module *mod) kfree(item); break; } +unlock: mutex_unlock(&smp_alt); } void alternatives_enable_smp(void) { - struct smp_alt_module *mod; + struct smp_alt_module *mod, *tmp; /* Why bother if there are no other CPUs? */ BUG_ON(num_possible_cpus() == 1); @@ -558,9 +562,12 @@ void alternatives_enable_smp(void) BUG_ON(num_online_cpus() != 1); clear_cpu_cap(&boot_cpu_data, X86_FEATURE_UP); clear_cpu_cap(&cpu_data(0), X86_FEATURE_UP); - list_for_each_entry(mod, &smp_alt_modules, next) + list_for_each_entry_safe(mod, tmp, &smp_alt_modules, next) { alternatives_smp_lock(mod->locks, mod->locks_end, mod->text, mod->text_end); + list_del(&mod->next); + kfree(mod); + } uniproc_patched = false; } mutex_unlock(&smp_alt); -- 1.8.3.1