Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp958835ybl; Mon, 2 Dec 2019 22:15:03 -0800 (PST) X-Google-Smtp-Source: APXvYqyrvr398NppKztxVe5zKRvJlCzgG4vQCjC4EanHVNkCImbyqgr1QD9h59HpIHLmW1GRIX0R X-Received: by 2002:aca:4ad8:: with SMTP id x207mr2364621oia.148.1575353703164; Mon, 02 Dec 2019 22:15:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1575353703; cv=none; d=google.com; s=arc-20160816; b=rqzy21bMZf5+fho43K4qISTWP1Z4xcNqaDv7D7Ng5hx4hQWJ+3srwIHIliNdh2mLTd YYljVYE0mLgoFAn6uybYZY8DbKAe5F/355JlzFI51nrvszx7wHiPZl236LOVKuycx9X0 XRjipWarsNm/mzBJH/S9+EWRqOTrc3Z1gyUi0n6pw7ucMNllH9HN2wiuIdTdfp7XkFnW FB1G3yMaL/sp9y97CXIkwafhGKIK03za+TeH8/sefJI8dBCRsU2Lkj8IHjSq1LG2fgLt u1NacieNMiqhnepzfd0K4ajMLLppSD/oufzmEBy2+/D20fix1TQrl7ewOBsgC7droEGL Tvbw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:message-id:date:subject:cc:to:from:dkim-signature; bh=WYKkZ0NaUuMtg1wb9Sm7oD8AlLc8NBuYe3pygBqlp1g=; b=JHarxSrLoKPV1LW4py1JPcM7wZbKtZsXHKrql8Eimc1mje+INo7XiHYM8xI7b2CLN7 pFygFLqluXo5MAh92cNdzLgbrjv2byRk7MLF2EbdBgp7/c6xgiToaatVbSVMpl4UPKG6 J4pWUhBlZhXijM8sY+jaOw8d9RKtzPHoMe9J47Z9exWaLeRRF9ovwTD9gH8pzcoKSort keaVoAjyvZ3Ag/m/e4IW4EsBZd2HJGxSUIw9MviNCeY1MeT31XirBONe7dyLzQpRbf+Y FyJ7ZkPzjvHwNmWoI+aWiEb8lin1akNyFXi2K71Jo/2AzCIGDlId8l2mCkB2Z3Ch51fJ rgdQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=veuCyeFF; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t26si674371oth.153.2019.12.02.22.14.51; Mon, 02 Dec 2019 22:15:03 -0800 (PST) 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; dkim=pass header.i=@kernel.org header.s=default header.b=veuCyeFF; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727077AbfLCGOM (ORCPT + 99 others); Tue, 3 Dec 2019 01:14:12 -0500 Received: from mail.kernel.org ([198.145.29.99]:46206 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726521AbfLCGOM (ORCPT ); Tue, 3 Dec 2019 01:14:12 -0500 Received: from localhost.localdomain (unknown [180.22.253.92]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 629782068E; Tue, 3 Dec 2019 06:14:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1575353651; bh=PVv+/qAr+M/CeBLnlFxIT4i2RhVSD5tYMtADCQJOYGs=; h=From:To:Cc:Subject:Date:From; b=veuCyeFFvFRIMoPmBXPBGfSDr+Wi4iG/A8HGXiHf0bvunzUTrFF6JD6kp9lW4P9QU zbDzUsQyG60vxVHtOU9wQ6dJEbccCNuiPYMH3b6yr1pnmtKhzi9xRiIbX/XgJX3urB O9VIijfBxLDleN9etI2BxbEoq5QCFnKr9dFiYgT4= From: Masami Hiramatsu To: Jessica Yu Cc: Joel Fernandes , Ingo Molnar , Anders Roxell , paulmck@kernel.org, "Naveen N . Rao" , Anil S Keshavamurthy , David Miller , Linux Kernel Mailing List , mhiramat@kernel.org Subject: [PATCH] modules: lockdep: Suppress suspicious RCU usage warning Date: Tue, 3 Dec 2019 15:14:04 +0900 Message-Id: <157535364480.17342.7937104819926015512.stgit@devnote2> X-Mailer: git-send-email 2.20.1 User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org While running kprobe module test, find_module_all() caused a suspicious RCU usage warning. ----- ============================= WARNING: suspicious RCU usage 5.4.0-next-20191202+ #63 Not tainted ----------------------------- kernel/module.c:619 RCU-list traversed in non-reader section!! other info that might help us debug this: rcu_scheduler_active = 2, debug_locks = 1 1 lock held by rmmod/642: #0: ffffffff8227da80 (module_mutex){+.+.}, at: __x64_sys_delete_module+0x9a/0x230 stack backtrace: CPU: 0 PID: 642 Comm: rmmod Not tainted 5.4.0-next-20191202+ #63 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.12.1-0-ga5cab58e9a3f-prebuilt.qemu.org 04/01/2014 Call Trace: dump_stack+0x71/0xa0 find_module_all+0xc1/0xd0 __x64_sys_delete_module+0xac/0x230 ? do_syscall_64+0x12/0x1f0 do_syscall_64+0x50/0x1f0 entry_SYSCALL_64_after_hwframe+0x49/0xbe RIP: 0033:0x4b6d49 ----- This is because list_for_each_entry_rcu(modules) is called without rcu_read_lock(). This is safe because the module_mutex is locked. Pass lockdep_is_held(&module_lock) to the list_for_each_entry_rcu() to suppress this warning, This also fixes similar issue in mod_find() and each_symbol_section(). Signed-off-by: Masami Hiramatsu --- kernel/module.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/kernel/module.c b/kernel/module.c index cb6250be6ee9..38e5c6a7451b 100644 --- a/kernel/module.c +++ b/kernel/module.c @@ -214,7 +214,8 @@ static struct module *mod_find(unsigned long addr) { struct module *mod; - list_for_each_entry_rcu(mod, &modules, list) { + list_for_each_entry_rcu(mod, &modules, list, + lockdep_is_held(&module_mutex)) { if (within_module(addr, mod)) return mod; } @@ -448,7 +449,8 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr, if (each_symbol_in_section(arr, ARRAY_SIZE(arr), NULL, fn, data)) return true; - list_for_each_entry_rcu(mod, &modules, list) { + list_for_each_entry_rcu(mod, &modules, list, + lockdep_is_held(&module_mutex)) { struct symsearch arr[] = { { mod->syms, mod->syms + mod->num_syms, mod->crcs, NOT_GPL_ONLY, false }, @@ -616,7 +618,8 @@ static struct module *find_module_all(const char *name, size_t len, module_assert_mutex_or_preempt(); - list_for_each_entry_rcu(mod, &modules, list) { + list_for_each_entry_rcu(mod, &modules, list, + lockdep_is_held(&module_mutex)) { if (!even_unformed && mod->state == MODULE_STATE_UNFORMED) continue; if (strlen(mod->name) == len && !memcmp(mod->name, name, len))