From patchwork Tue Apr 18 20:48:15 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Grygorii Strashko X-Patchwork-Id: 9686289 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 3F4C5602C9 for ; Tue, 18 Apr 2017 20:49:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3084D23F88 for ; Tue, 18 Apr 2017 20:49:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 24EBB283E8; Tue, 18 Apr 2017 20:49:05 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 9C4DF23F88 for ; Tue, 18 Apr 2017 20:49:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-ID:Date:Subject:To :From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=n1CjzRZFv5SCgBH3pdJbnMqIbjyQePcK9/2SkUCfwco=; b=YpaQaTLYKP28wy 5S/V8VdTaM2AEOY8Y31fpM06Vjtmjwaj501hTfv+Lway3Gtn/Ml/KdlB3ESDsIxsgzRMUkIvJtUk6 SXsoShMQT6ANPG9v9VhDyIsdIKfj1GuzzkJpkoJUpTeQRDNjXJKfQS2r3vCy0S18dDsi8IiaGpNGX OG2kXZk5Z67092jXNP2zEeCvYEIrdfsdYMsrLVI1oqlZMHaDoBoibpnQZzcVBpP/URGyrgvWtC3kU q6UJKtWvbPH3ypm1z/U6WwCTBR/8zSiXx7bGjvOh5GWL0jSgC1v9kFUkxQDp7OQC2hBYf3xTMmmxh 4blRP7uCyERyS6U0/kBg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1d0a3a-0006TQ-HU; Tue, 18 Apr 2017 20:49:02 +0000 Received: from fllnx210.ext.ti.com ([198.47.19.17]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1d0a3Y-0006M3-1Q for linux-arm-kernel@lists.infradead.org; Tue, 18 Apr 2017 20:49:01 +0000 Received: from dlelxv90.itg.ti.com ([172.17.2.17]) by fllnx210.ext.ti.com (8.15.1/8.15.1) with ESMTP id v3IKmH3a004651; Tue, 18 Apr 2017 15:48:17 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ti.com; s=ti-com-17Q1; t=1492548497; bh=x4V/MW9REpliehoBDewqdF/91mmpi7gZUf9nEtdTktM=; h=From:To:CC:Subject:Date; b=uHBoKUpuCQF+db2v3myX+NPBvMWdrx0DI6CniBEc2aXPT12j7ApDrDgXJ/dET9vlh SsRYu2Xq766S9TIUmh23rfcuqI86TD4AhXJ+TSfGYF46ax45Q5mC8UBaTh42YaEvkV qFDrn3F7EiVYOxpjmkCwZutfCbV+Da5oaNzAz36Y= Received: from DLEE70.ent.ti.com (dlee70.ent.ti.com [157.170.170.113]) by dlelxv90.itg.ti.com (8.14.3/8.13.8) with ESMTP id v3IKmH6j001145; Tue, 18 Apr 2017 15:48:17 -0500 Received: from dflp32.itg.ti.com (10.64.6.15) by DLEE70.ent.ti.com (157.170.170.113) with Microsoft SMTP Server id 14.3.294.0; Tue, 18 Apr 2017 15:48:16 -0500 Received: from legion.dal.design.ti.com (legion.dal.design.ti.com [128.247.22.53]) by dflp32.itg.ti.com (8.14.3/8.13.8) with ESMTP id v3IKmGu2008841; Tue, 18 Apr 2017 15:48:16 -0500 Received: from localhost (uda0226610.am.dhcp.ti.com [128.247.83.96]) by legion.dal.design.ti.com (8.11.7p1+Sun/8.11.7) with ESMTP id v3IKmG311405; Tue, 18 Apr 2017 15:48:16 -0500 (CDT) From: Grygorii Strashko To: Russell King , Sebastian Andrzej Siewior , Subject: [v4.9-rt PATCH] ARM: mm: remove tasklist locking from update_sections_early() Date: Tue, 18 Apr 2017 15:48:15 -0500 Message-ID: <20170418204815.9001-1-grygorii.strashko@ti.com> X-Mailer: git-send-email 2.10.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170418_134900_195732_A7442DE8 X-CRM114-Status: UNSURE ( 9.21 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laura Abbott , Grygorii Strashko , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Kees Cook Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP The below backtrace can be observed on -rt kernel with CONFIG_DEBUG_RODATA option enabled: BUG: sleeping function called from invalid context at kernel/locking/rtmutex.c:993 in_atomic(): 1, irqs_disabled(): 128, pid: 14, name: migration/0 1 lock held by migration/0/14: #0: (tasklist_lock){+.+...}, at: [] update_sections_early+0x24/0xdc irq event stamp: 38 hardirqs last enabled at (37): [] _raw_spin_unlock_irq+0x24/0x68 hardirqs last disabled at (38): [] multi_cpu_stop+0xd8/0x138 softirqs last enabled at (0): [] copy_process.part.5+0x238/0x1b64 softirqs last disabled at (0): [< (null)>] (null) Preemption disabled at: [] cpu_stopper_thread+0x80/0x10c CPU: 0 PID: 14 Comm: migration/0 Not tainted 4.9.21-rt16-02220-g49e319c #15 Hardware name: Generic DRA74X (Flattened Device Tree) [] (unwind_backtrace) from [] (show_stack+0x10/0x14) [] (show_stack) from [] (dump_stack+0xa8/0xd4) [] (dump_stack) from [] (___might_sleep+0x1bc/0x2ac) [] (___might_sleep) from [] (__rt_spin_lock+0x1c/0x30) [] (__rt_spin_lock) from [] (rt_read_lock+0x54/0x68) [] (rt_read_lock) from [] (update_sections_early+0x24/0xdc) [] (update_sections_early) from [] (__fix_kernmem_perms+0x10/0x1c) [] (__fix_kernmem_perms) from [] (multi_cpu_stop+0x100/0x138) [] (multi_cpu_stop) from [] (cpu_stopper_thread+0x88/0x10c) [] (cpu_stopper_thread) from [] (smpboot_thread_fn+0x174/0x31c) [] (smpboot_thread_fn) from [] (kthread+0xf0/0x108) [] (kthread) from [] (ret_from_fork+0x14/0x3c) Freeing unused kernel memory: 1024K (c0d00000 - c0e00000) The stop_machine() is called with cpus = NULL from fix_kernmem_perms() and mark_rodata_ro() which means only one CPU will execute update_sections_early() while all other CPUs will spin and wait. Hence, it's safe to remove tasklist locking from update_sections_early(). As part of this change also mark functions which are local to this module as static to simplify code analize in the future. Cc: Kees Cook Cc: Laura Abbott Signed-off-by: Grygorii Strashko --- arch/arm/mm/init.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c index 370581a..a77953a 100644 --- a/arch/arm/mm/init.c +++ b/arch/arm/mm/init.c @@ -693,30 +693,28 @@ static void update_sections_early(struct section_perm perms[], int n) { struct task_struct *t, *s; - read_lock(&tasklist_lock); for_each_process(t) { if (t->flags & PF_KTHREAD) continue; for_each_thread(t, s) set_section_perms(perms, n, true, s->mm); } - read_unlock(&tasklist_lock); set_section_perms(perms, n, true, current->active_mm); set_section_perms(perms, n, true, &init_mm); } -int __fix_kernmem_perms(void *unused) +static int __fix_kernmem_perms(void *unused) { update_sections_early(nx_perms, ARRAY_SIZE(nx_perms)); return 0; } -void fix_kernmem_perms(void) +static void fix_kernmem_perms(void) { stop_machine(__fix_kernmem_perms, NULL, NULL); } -int __mark_rodata_ro(void *unused) +static int __mark_rodata_ro(void *unused) { update_sections_early(ro_perms, ARRAY_SIZE(ro_perms)); return 0;