Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp3653378ybl; Tue, 21 Jan 2020 04:52:01 -0800 (PST) X-Google-Smtp-Source: APXvYqylU+F2E9HF1SI2Y3kpxIaQ5tBiOFLHeRPC5WwK7isFVc44TKdwQBs3XxcChdKqgJrb8pOz X-Received: by 2002:aca:d5d3:: with SMTP id m202mr2725648oig.161.1579611121391; Tue, 21 Jan 2020 04:52:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579611121; cv=none; d=google.com; s=arc-20160816; b=yLdZ8QN8tfN4tgb1LKmlQhSg/KHhRn596kxLIST7BvIV7CamWQ+LchwEPOkc28tqin m3sF4Ybts3u1keuhvRlX58ZnfgLGGK6iXH9afLuonyJaiyvjDFOYsf4t2O17gNvEJWxm Qp/sR0tuMTJ6LNcisu/pxbbAtnBMIELi/oxIGTo+lBrZ2ydzuWYqQv+YE3Fs0/ckPs6l JbbZjoTNR0FTcjgl3cjQSfzdXG2ZJokYC/qs9Q139qyK+fNHZmHwfCJZ9OnjiiY7o2Tl rjTG9s835oQ1HAL7JaAZZ6GFKcgreUCSFvxzPe8s7a+LuBrf6BlFViMxlsvzr0fNKpWM 83oA== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=QSX3p7g/5+mGyY0QbppVn7Dy3rth1hiQMkYqW3UKtds=; b=AjYfuMwajNpNVW1ZL6ZQr16fyUVJ5Z13ulJ7FjG0RcImr6qOE8YuFj/45bwG62KVj2 6NyJ8NkiNqpqu8rvy5Xn4xKQNNWhwe3jqljgccce50soU3rGC0qMavAoS4i+4z9MdhrL oQm8bbD8bzO7ZK+/+2p7hnf4qaBZ6GCVxSKKBNkrrXeV34L7eNVv2zUEcuUPbjjcgil5 jQhjifZB4qFZSCGwChIT+XgS8vrq927blj1lfX2P8Peca/mX99nc3Ojy/pLcOwRlNpQu 89NgnQaNkgAjWoWOlQP8DcXkMlRkjOHpfbVwNNICC1n2dbyJNkfWw/ypiEBItm71vxVF UJdw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=r55YOKxK; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e73si19684253oib.145.2020.01.21.04.51.49; Tue, 21 Jan 2020 04:52:01 -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=@gmail.com header.s=20161025 header.b=r55YOKxK; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729467AbgAUMte (ORCPT + 99 others); Tue, 21 Jan 2020 07:49:34 -0500 Received: from mail-pj1-f67.google.com ([209.85.216.67]:32839 "EHLO mail-pj1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726968AbgAUMte (ORCPT ); Tue, 21 Jan 2020 07:49:34 -0500 Received: by mail-pj1-f67.google.com with SMTP id u63so981634pjb.0 for ; Tue, 21 Jan 2020 04:49:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=QSX3p7g/5+mGyY0QbppVn7Dy3rth1hiQMkYqW3UKtds=; b=r55YOKxKOjaGqMzpf9rvWrfHzXFrtKq54xZ8ZzKZz1tZHG4xSG/F51ZBV3dq9Wk69H RJSYJfopA9X1NU6lvr1ibkGo36C3YbtKms0oS3DWTE8eHI0tUVTDqOCrv0Ke3UypAmkm xbr/7cfk35tSzR7c+OhOixYeLDlg0Fu8WDZXrsUxY7P3AA2rjnQRWAckuhe46ST6nCVC pHDXke+7++2GLBxqFOf4Trj6FvBDJgZlxSNlbcJNpcrjALVR68JgIv/V1qTwezkRaK4s s4XryJ5AXaufZIdbF3dAlBPjZS1HzShnIFxwKBsGoMt28sPpRo3ime+JC9DkLEp6Mzta GGbg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=QSX3p7g/5+mGyY0QbppVn7Dy3rth1hiQMkYqW3UKtds=; b=dUt1Uzg5kblawXQVVfHmuCcS9eAhFfRR7CDl6wGvIXiju1oFsWqCPtsvqZcjqwiuLT aKxTlJEelh9z9zGuWf50nPZuxH6nOkZH+EJZTCgA2p+EZ/meUWhrQp8KBQF5hUVufWEb P5bsGRpk3bW/sGQl6QOJAm0lCFhNl/iWCSCAH4/wYbH55PEeWlBM/4Y5d4UJ4Wv9Pwsw pPU9bB/0xMGbKl9iUw9xANXlZhN/KjqIps8HyXqSM00uB3Ox1C4PYWGdBw46BTDtHq+2 M6sdSZwvZc3KK2EEFtx3QhsThNhAjE2upiLbxE1tK/6CwfSCf85Z/DT6WN1prE0STYcv qphA== X-Gm-Message-State: APjAAAXjCnm/P9mOWfVzCi9JPC9Mtr3upDThIJN7Flo0rAHsU2Ke3gsT sMYN0e0l3OoO2c3HZSAEZ0Q= X-Received: by 2002:a17:902:b08e:: with SMTP id p14mr5446473plr.323.1579610973429; Tue, 21 Jan 2020 04:49:33 -0800 (PST) Received: from localhost.localdomain ([146.196.37.201]) by smtp.googlemail.com with ESMTPSA id g67sm44536999pfb.66.2020.01.21.04.49.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Jan 2020 04:49:32 -0800 (PST) From: Amol Grover To: Jessica Yu Cc: linux-kernel@vger.kernel.org, linux-kernel-mentees@lists.linuxfoundation.org, Joel Fernandes , Madhuparna Bhowmik , "Paul E . McKenney" , Amol Grover Subject: [PATCH] kernel: module: Pass lockdep expression to RCU lists Date: Tue, 21 Jan 2020 18:17:46 +0530 Message-Id: <20200121124745.14864-1-frextrite@gmail.com> X-Mailer: git-send-email 2.24.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org modules is traversed using list_for_each_entry_rcu outside an RCU read-side critical section but under the protection of module_mutex or with preemption disabled. Hence, add corresponding lockdep expression to silence false-positive lockdep warnings, and harden RCU lists. list_for_each_entry_rcu when traversed inside a preempt disabled section, doesn't need an explicit lockdep expression since it is implicitly checked for. Add macro for the corresponding lockdep expression. Signed-off-by: Amol Grover --- kernel/module.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/kernel/module.c b/kernel/module.c index b56f3224b161..2425f58159dd 100644 --- a/kernel/module.c +++ b/kernel/module.c @@ -84,6 +84,8 @@ * 3) module_addr_min/module_addr_max. * (delete and add uses RCU list operations). */ DEFINE_MUTEX(module_mutex); +#define module_mutex_held() \ + lockdep_is_held(&module_mutex) EXPORT_SYMBOL_GPL(module_mutex); static LIST_HEAD(modules); @@ -214,7 +216,7 @@ 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, module_mutex_held()) { if (within_module(addr, mod)) return mod; } @@ -448,7 +450,7 @@ 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, module_mutex_held()) { struct symsearch arr[] = { { mod->syms, mod->syms + mod->num_syms, mod->crcs, NOT_GPL_ONLY, false }, @@ -616,7 +618,7 @@ 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, module_mutex_held()) { if (!even_unformed && mod->state == MODULE_STATE_UNFORMED) continue; if (strlen(mod->name) == len && !memcmp(mod->name, name, len)) @@ -2040,7 +2042,7 @@ void set_all_modules_text_rw(void) return; mutex_lock(&module_mutex); - list_for_each_entry_rcu(mod, &modules, list) { + list_for_each_entry_rcu(mod, &modules, list, module_mutex_held()) { if (mod->state == MODULE_STATE_UNFORMED) continue; @@ -2059,7 +2061,7 @@ void set_all_modules_text_ro(void) return; mutex_lock(&module_mutex); - list_for_each_entry_rcu(mod, &modules, list) { + list_for_each_entry_rcu(mod, &modules, list, module_mutex_held()) { /* * Ignore going modules since it's possible that ro * protection has already been disabled, otherwise we'll -- 2.24.1