From patchwork Wed Mar 29 05:31:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Chamberlain X-Patchwork-Id: 13191895 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6E37FC74A5B for ; Wed, 29 Mar 2023 05:31:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 085506B0078; Wed, 29 Mar 2023 01:31:58 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 034B16B007B; Wed, 29 Mar 2023 01:31:57 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E3D8A6B007D; Wed, 29 Mar 2023 01:31:57 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id D4DE76B0078 for ; Wed, 29 Mar 2023 01:31:57 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id A6997AC087 for ; Wed, 29 Mar 2023 05:31:57 +0000 (UTC) X-FDA: 80620814274.18.9BD65FA Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf13.hostedemail.com (Postfix) with ESMTP id 04DB02000B for ; Wed, 29 Mar 2023 05:31:54 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=xGWh2JgK; dmarc=fail reason="No valid SPF, DKIM not aligned (relaxed)" header.from=kernel.org (policy=none); spf=none (imf13.hostedemail.com: domain of mcgrof@infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=mcgrof@infradead.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1680067915; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=gd8HbSo5xrQsR5kA4HVA4gKzlE/8w/S5arnYzQjZrxg=; b=0cAytsk36+cP47L1u0Z0PXVcwil7Bq/TGMbOPtL9WU6N7BwxEM2yJHI9soRFU22jJ6n6I7 Z5U5jKK1+NUjsc7K/sElfCxXlBp9IX+p09Jyz1TgFzTLdtMJVIUNWFjM/jdzmIFQgXFhUc Qa8vhnP30ey+JunRb2Y8xIS37HDkLf4= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=xGWh2JgK; dmarc=fail reason="No valid SPF, DKIM not aligned (relaxed)" header.from=kernel.org (policy=none); spf=none (imf13.hostedemail.com: domain of mcgrof@infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=mcgrof@infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1680067915; a=rsa-sha256; cv=none; b=TXBlYV528IFlJvzChwvQSPiRzn8SfiBoTq7sYjwUTVxdcheVzYAa9NXLWwph32Zey44Rfb epR4VLVCmXKk7/RnuNFbVz7PKfavplrzoNwHzIfloKNLyYweFGYxDx7x0jGLALLGC8qDe2 s+WzQocGZEVcwdGlKdWvN5Ez9bd1Qbs= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Sender:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description; bh=gd8HbSo5xrQsR5kA4HVA4gKzlE/8w/S5arnYzQjZrxg=; b=xGWh2JgKRYwpppiRzsWetlki5t SVeBNZzs7bh2gAzAdY3c4dPLIqKQ56oSDKzinEazY6EhcXBffYAE1BcrA4RD1I8UB8UxwhlyXHxmK E/JKeSfdBahNY/fWI+b38Kf0WHEmp5qRM+J5c2Tc9/0JMZB29rDgeZCoKqc2+pse21WP1cvPGgv2j +TS3Aw0BoqVz0XL2rSKX9QyduwIqa0AUcLUQCZUPeNvFM4L5JQcEMNtqv0yXiYcXImRcc4tRvL5c5 GbPvsKhY/FQ4y+Bc0G6I1sdi/F3VcHfN6n+zJlt617XOG53+obPbnyIdgO6d3lukOl04AKooj4asy zW1gZagw==; Received: from mcgrof by bombadil.infradead.org with local (Exim 4.96 #2 (Red Hat Linux)) id 1phOPW-00GgRS-1v; Wed, 29 Mar 2023 05:31:50 +0000 From: Luis Chamberlain To: david@redhat.com, patches@lists.linux.dev, linux-modules@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, pmladek@suse.com, petr.pavlu@suse.com, prarit@redhat.com, torvalds@linux-foundation.org, gregkh@linuxfoundation.org, rafael@kernel.org Cc: christophe.leroy@csgroup.eu, tglx@linutronix.de, peterz@infradead.org, song@kernel.org, rppt@kernel.org, willy@infradead.org, vbabka@suse.cz, mhocko@suse.com, dave.hansen@linux.intel.com, mcgrof@kernel.org Subject: [PATCH 1/7] module: move finished_loading() Date: Tue, 28 Mar 2023 22:31:43 -0700 Message-Id: <20230329053149.3976378-2-mcgrof@kernel.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230329053149.3976378-1-mcgrof@kernel.org> References: <20230329053149.3976378-1-mcgrof@kernel.org> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 04DB02000B X-Stat-Signature: gsjt81fcmcqjmqir1m6b69xbxnj4pkk1 X-HE-Tag: 1680067914-179123 X-HE-Meta: U2FsdGVkX19SS6Koz9zl9rDwI8dcmDtXSwpFBkPXLDnBIFOfyg9BI5bb1Jr7sYifvhuFSxKrckJorQaP6m9C+MHGACYl5Qk9j0uQ8l2uoV7sngPUiTjacwRV+dvVMCfoap6pT4cE9yvxpoVeGSuejFImwJFa7UavmDU0ROh9m6bl2PgiiUSQyngfVtwIpNqBBFi1s6XVNMY2XJJ8ehi5AplRxItKvyZHuSUd4hNVkkfe5fSklC7V/wgWhYtxGGGuhUz2HkBnFKh8Bc4ZuysZp+SXSUAa5ikx3aeKksmz+ex0jvdJ4X4uNPhBkGAeRDOCIK7h21eqcBVtl1JNHdqx0kcFVusd4jYplhLk6xgpG8Rxal2YEg5NUEmFYHPYH7OA9JzRS3yPyPa9NbMR/zU+peh3EmRaQUvhtm6bWnCYLdsC1mGvqN69ach8Ir+Il2RYHjX6s3WlCX3RZWWzUD7iomfVkz+/4yK6FaL0oX24PimtR5UezoHTvU4PdUHAQOK6YFcUJaXlXJQ0XMyouXFcxOQD5G9jrtfsqEE8lvz1mPNCOEwKHr1xlleWOEZdUI+VvvXUdQ+2ujC4HjD30KxVL4l4AjGS9JGImbRkkbc2u7tgilYlI/P9GCu+diIW3KmbK0K+hrndDLlXgjpVw+FpUivh8fwZwcCgJCI364Xcmbp0rk5APGFoaT3PSct9y2TKdZYDXuoHDi/Giih5Oo2Ul0uw5QaDnyAPpw+N/jn01Ehq+Se3bvNiw3bvfB118bZuA5tcrvcb1D4+y3DBJ3DHONCIJTiLP1lIVEMho/HPURGt97LcMjXYvww0zUGqE6RXz4jAAVusqwdjjiKBudrbSsVNMLewQtiJ4e242q/86r3OaWIk774dKEzYlXCdKXn+ibO7N8nokgMyktfUnk/nd1afCU0IJUPVS6g+ErVoO/H0JJhR46XVSLV/ZpzYP0l4UFoD7x9lzsLjsZA6/7B IW3IZe/l mt0dBlFe4XVFn6thuelhBybpTBSZwjcz1cf4XvI4Y4ecrsV20CB9e3zjcWF9iF7AONm53DklSW1kD0VOj3ztatNM2ZESLec/+PzipNw2q5TfieA3n0GbHi0+ejicgLLocln57qUqWccx/RAqkffNBfoPoxALWDCCfMPtj8jI75k3AsiGy19R5gwRoyWJyZne52j+iVfmC3jXtm9MbzuO6hc6IH4YQqXYDzMlQ14ZwfHKK6Msg3TtecCZNsMMtVTV/Pd6/wix2JgD0bRBCm59xzTeffep6+pkV4qKMtQlNii3/6hKjHHL+MOYsuXA3dsmf3i+RPmd7UgqHh9T5kynCFujYsr6JpjEfAnIFyKyo4dMPiS8zb/tp0HpFIMnLdpVuY1VMX7WjcugVgUVfq5O3V31WR1fjEtqdmufXSxSAbFvI1mALrbdCGjWA7bGWAR07TqXX5Yc7R92zLniCAGj36NBosg== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000001, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: This has no functional change, just moves a routine earlier as we'll make use of it next. Signed-off-by: Luis Chamberlain --- kernel/module/main.c | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/kernel/module/main.c b/kernel/module/main.c index 5cc21083af04..af58e63e5daf 100644 --- a/kernel/module/main.c +++ b/kernel/module/main.c @@ -2442,27 +2442,6 @@ static int post_relocation(struct module *mod, const struct load_info *info) return module_finalize(info->hdr, info->sechdrs, mod); } -/* Is this module of this name done loading? No locks held. */ -static bool finished_loading(const char *name) -{ - struct module *mod; - bool ret; - - /* - * The module_mutex should not be a heavily contended lock; - * if we get the occasional sleep here, we'll go an extra iteration - * in the wait_event_interruptible(), which is harmless. - */ - sched_annotate_sleep(); - mutex_lock(&module_mutex); - mod = find_module_all(name, strlen(name), true); - ret = !mod || mod->state == MODULE_STATE_LIVE - || mod->state == MODULE_STATE_GOING; - mutex_unlock(&module_mutex); - - return ret; -} - /* Call module constructors. */ static void do_mod_ctors(struct module *mod) { @@ -2626,6 +2605,27 @@ static int may_init_module(void) return 0; } +/* Is this module of this name done loading? No locks held. */ +static bool finished_loading(const char *name) +{ + struct module *mod; + bool ret; + + /* + * The module_mutex should not be a heavily contended lock; + * if we get the occasional sleep here, we'll go an extra iteration + * in the wait_event_interruptible(), which is harmless. + */ + sched_annotate_sleep(); + mutex_lock(&module_mutex); + mod = find_module_all(name, strlen(name), true); + ret = !mod || mod->state == MODULE_STATE_LIVE + || mod->state == MODULE_STATE_GOING; + mutex_unlock(&module_mutex); + + return ret; +} + /* * We try to place it in the list now to make sure it's unique before * we dedicate too many resources. In particular, temporary percpu From patchwork Wed Mar 29 05:31:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Chamberlain X-Patchwork-Id: 13191894 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id ACCC3C6FD18 for ; Wed, 29 Mar 2023 05:31:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 258AD6B0075; Wed, 29 Mar 2023 01:31:57 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 208036B0078; Wed, 29 Mar 2023 01:31:57 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0D34D6B007B; Wed, 29 Mar 2023 01:31:57 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id EE86F6B0075 for ; Wed, 29 Mar 2023 01:31:56 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id BE2AB1C5DB2 for ; Wed, 29 Mar 2023 05:31:56 +0000 (UTC) X-FDA: 80620814232.23.BFEC09A Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf05.hostedemail.com (Postfix) with ESMTP id 2198E100004 for ; Wed, 29 Mar 2023 05:31:54 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=Hq7MpAhb; dmarc=fail reason="No valid SPF, DKIM not aligned (relaxed)" header.from=kernel.org (policy=none); spf=none (imf05.hostedemail.com: domain of mcgrof@infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=mcgrof@infradead.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1680067915; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=C7tEOVKbmd31kJKkSCr8L6PeUYpxvjj7kEhb9lxj2lU=; b=YtIbLcDFPSgmWu4xe7se5sKLMaFGDOIiOtMNWfHOMTndT0t2Gn8B5S1lJX8XJf7LYFHCSP PH0pyLNBCcCuLU40ph6YCsCOHJT6wrLPZzyIAuPj/1RqRH6uJFmnwJF7feYVcH8iepkq29 l4Rq0GNYa5fapNJp3zNX7HW+asF2q9o= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=Hq7MpAhb; dmarc=fail reason="No valid SPF, DKIM not aligned (relaxed)" header.from=kernel.org (policy=none); spf=none (imf05.hostedemail.com: domain of mcgrof@infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=mcgrof@infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1680067915; a=rsa-sha256; cv=none; b=8b3ih0GH08dGyGveSqyNioq75p7mMTIFlklIe11874myizXvf3ic/NlI3uwyNGJy/4ULwo XPKiCE2Ki/vwXI+X5iSO03t+wsK2iMf1l6O/e++QencEYs29GDadFDufH2jWj3SBoa1SIf 1rkc+vkSV0YGJKbfGuszvb1wyb0vNxk= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Sender:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description; bh=C7tEOVKbmd31kJKkSCr8L6PeUYpxvjj7kEhb9lxj2lU=; b=Hq7MpAhblc40y8k1Y4Pqo/enTW SslWm7fO+exvvf3HZRxh+bgxhZOS3P1IYnAydKJ5ZTarr8GhRDhxNEnxrSNR8qTIPYRQkgU3YNnx+ +hKEQpyCrK+p5tnt4YfYVc53F88QARD2q7d7/0iy49zIQ53fg9qMpgODyjglcWGSsnuydP/xVL3Pf FSVm+HQx1wkfASdfb4mN3vTxsgy2DNRu5unP+d8hu1QfAr3UlqH/JXn0cVkRXiLoYO4YS6swQky9l OqFeYbHv1S5N2op7xH0OmscjuK1xIZLjsk8AFnOHnf/yFLpseFdNdJMXGHqpmE5FhbNXRa3cLgGxL JBMH5C3A==; Received: from mcgrof by bombadil.infradead.org with local (Exim 4.96 #2 (Red Hat Linux)) id 1phOPW-00GgRW-23; Wed, 29 Mar 2023 05:31:50 +0000 From: Luis Chamberlain To: david@redhat.com, patches@lists.linux.dev, linux-modules@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, pmladek@suse.com, petr.pavlu@suse.com, prarit@redhat.com, torvalds@linux-foundation.org, gregkh@linuxfoundation.org, rafael@kernel.org Cc: christophe.leroy@csgroup.eu, tglx@linutronix.de, peterz@infradead.org, song@kernel.org, rppt@kernel.org, willy@infradead.org, vbabka@suse.cz, mhocko@suse.com, dave.hansen@linux.intel.com, mcgrof@kernel.org Subject: [PATCH 2/7] module: extract patient module check into helper Date: Tue, 28 Mar 2023 22:31:44 -0700 Message-Id: <20230329053149.3976378-3-mcgrof@kernel.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230329053149.3976378-1-mcgrof@kernel.org> References: <20230329053149.3976378-1-mcgrof@kernel.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: 2198E100004 X-Rspamd-Server: rspam09 X-Rspam-User: X-Stat-Signature: n5bsmr8sxfbghtof6g61ao51twcot86h X-HE-Tag: 1680067914-95069 X-HE-Meta: U2FsdGVkX18M1AOO509Q6EbxKA/dhKkKhD42UNf0SrMkowI9fZdxI4eGF5MYJFCjwfZRWpZuN9egSgj4sFP6yZbuJAM1wboEaQqwaAZoJkOX4161wljyOtKJw0KbUBAw+JDQuRyguO03Z4SrmmWHvxXAMcMbri6lb6wAtpVYuX3ebQzENMSgmsYzle/qvAUhRXJ9IlhvMMS6gjGjq5XrjtLAIyPdV0xR6GmgwqhBrm+UoIB5kaaV1RlEYDShXBkh70HLXzH9tYfxrQJ8hziKJHkZm6Oyy6ZjE5UW/oDqhvHiCkTJVkvDKppEL0v3fmvVxAOkDDYYuQHhSTzhawcY2VJJvdoEF9fg7akRw8PXS5KeguBEi9M/Zgdz01J2otvxA/Xw0ih5RPBQhT2JZ0QcvKyfm1PlWcRvMFnSRo0E6bg15ZpPRjnk1OMGxzzu3cbHe4nHQGffSW/U7yMKyhcltWqiLysgDUidq1TAwzZMb8UmJZpMC+yPY8d3PA2hK4GRanmm0De+6pLNeCDdWnCi1/gF8Ltfd7k13hXAeBnFKRfnjMEW/JffZEKpLTNTkUk+Idgdgcv62JQTdbdjphnQ92Abx5lpG9WmOrXAYL5lnAOGlNyl9+iBQ/Uz6FXL8bkM5wJc+y88Gb7SzRzsCOn2/88gxMZJzzFTKGaMk6XXcUl0KLiepV3RnILXvRrvCEUwVHe7CbarBovKUtXC+FcVI78EW8iKuLaXSn8+I1Cx0EmzXufv6dD1Z833wWmU+ecCZPgCwW3DzcXQRiXTvnQrwvZImBitnorC8WtLW3lgmJRtFJJ0/UK0AMWAiAdrzunu74Ih1QNQa6o5sF6z8A2xP7XxtLuDGoii9Mce4RZLbnLQrX26biLy/7dtcy3+hq6K+vIztCNIKh3BBAZIQ4qYfgbpSkNO0TPk8HyKORM8fX28P6zV+rbpt4dRvKvjjasL4vlMtV0rxwa1drRWnz0 DpPRlWuw 4jHaT4K6ygEtLDlPp5YNi6uUee5/qJZ4RtRwZVywJVfwbpFHKeNI5zlMLyd5GiAsXGCgW967omNReDXrIQcppoYb7u8ndbarHQxIgnC1I1T/pGNheCW4PEmwQhT3TMI5moHUqXWEYPnwocKGVxFxbKidjye4Pq7zLpdSQOFQtWBIzzhMGEBaxoKT894DHlt0jpsGmX83dk8ba5iesdLffbscpjQF94b9f9Tn/9xyFWS5wONTz006RW4xFoUnkysf4bsY9/O5aCTlGx7LuGprBi4hF5My3UO6BKXcbm1LnBZZBTaWsRkkufjzKAZsh5fOwOOzuXNlzo6o3rYtrCwPhwFH0gbCDHj+dKeUB6rqrH6hgqSG3XdXUlBf59ZU3ngfKzeD5I5B1h6PUMxzeJkqN79VWDbpuS/G4PgbS X-Bogosity: Ham, tests=bogofilter, spamicity=0.000083, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: The patient module check inside add_unformed_module() is large enough as we need it. It is a bit hard to read too, so just move it to a helper and do the inverse checks first to help shift the code and make it easier to read. The new helper then is module_patient_check_exists(). Signed-off-by: Luis Chamberlain --- kernel/module/main.c | 71 +++++++++++++++++++++++++------------------- 1 file changed, 40 insertions(+), 31 deletions(-) diff --git a/kernel/module/main.c b/kernel/module/main.c index af58e63e5daf..77c2e7a60f2e 100644 --- a/kernel/module/main.c +++ b/kernel/module/main.c @@ -2626,6 +2626,43 @@ static bool finished_loading(const char *name) return ret; } +/* Must be called with module_mutex held */ +static int module_patient_check_exists(const char *name) +{ + struct module *old; + int err = 0; + + old = find_module_all(name, strlen(name), true); + if (old == NULL) + return 0; + + if (old->state == MODULE_STATE_COMING + || old->state == MODULE_STATE_UNFORMED) { + /* Wait in case it fails to load. */ + mutex_unlock(&module_mutex); + err = wait_event_interruptible(module_wq, + finished_loading(name)); + if (err) + return err; + + /* The module might have gone in the meantime. */ + mutex_lock(&module_mutex); + old = find_module_all(name, strlen(name), true); + } + + /* + * We are here only when the same module was being loaded. Do + * not try to load it again right now. It prevents long delays + * caused by serialized module load failures. It might happen + * when more devices of the same type trigger load of + * a particular module. + */ + if (old && old->state == MODULE_STATE_LIVE) + return -EEXIST; + else + return -EBUSY; +} + /* * We try to place it in the list now to make sure it's unique before * we dedicate too many resources. In particular, temporary percpu @@ -2634,41 +2671,14 @@ static bool finished_loading(const char *name) static int add_unformed_module(struct module *mod) { int err; - struct module *old; mod->state = MODULE_STATE_UNFORMED; mutex_lock(&module_mutex); - old = find_module_all(mod->name, strlen(mod->name), true); - if (old != NULL) { - if (old->state == MODULE_STATE_COMING - || old->state == MODULE_STATE_UNFORMED) { - /* Wait in case it fails to load. */ - mutex_unlock(&module_mutex); - err = wait_event_interruptible(module_wq, - finished_loading(mod->name)); - if (err) - goto out_unlocked; - - /* The module might have gone in the meantime. */ - mutex_lock(&module_mutex); - old = find_module_all(mod->name, strlen(mod->name), - true); - } - - /* - * We are here only when the same module was being loaded. Do - * not try to load it again right now. It prevents long delays - * caused by serialized module load failures. It might happen - * when more devices of the same type trigger load of - * a particular module. - */ - if (old && old->state == MODULE_STATE_LIVE) - err = -EEXIST; - else - err = -EBUSY; + err = module_patient_check_exists(mod->name); + if (err) goto out; - } + mod_update_bounds(mod); list_add_rcu(&mod->list, &modules); mod_tree_insert(mod); @@ -2676,7 +2686,6 @@ static int add_unformed_module(struct module *mod) out: mutex_unlock(&module_mutex); -out_unlocked: return err; } From patchwork Wed Mar 29 05:31:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Chamberlain X-Patchwork-Id: 13191896 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 26420C6FD18 for ; Wed, 29 Mar 2023 05:32:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 89CDB6B007B; Wed, 29 Mar 2023 01:31:58 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7FD1A6B007D; Wed, 29 Mar 2023 01:31:58 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 58B3E900002; Wed, 29 Mar 2023 01:31:58 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 496A46B007B for ; Wed, 29 Mar 2023 01:31:58 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 2021FA04C5 for ; Wed, 29 Mar 2023 05:31:58 +0000 (UTC) X-FDA: 80620814316.12.5157B38 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf29.hostedemail.com (Postfix) with ESMTP id 61B4F12001C for ; Wed, 29 Mar 2023 05:31:56 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=Rc1W4XBs; spf=none (imf29.hostedemail.com: domain of mcgrof@infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=mcgrof@infradead.org; dmarc=fail reason="No valid SPF, DKIM not aligned (relaxed)" header.from=kernel.org (policy=none) ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1680067916; a=rsa-sha256; cv=none; b=T6gXrrJFrl7ypBGxC4qW7BR6ZSH51+3uXVRLBr5hdujs82F8XLA4UesgdxeMBPEAp1XJu+ RCDra2WXzVqjMU93FDus715EGsrlieNWymbU4zktz2WdPRqNqxhQe2OKC39ey21mStOjDF bNaoXEZcWA6pn64gNyDp9hVaI9YVbnw= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=Rc1W4XBs; spf=none (imf29.hostedemail.com: domain of mcgrof@infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=mcgrof@infradead.org; dmarc=fail reason="No valid SPF, DKIM not aligned (relaxed)" header.from=kernel.org (policy=none) ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1680067916; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=4WklghmhRoXLW11BvhMQXmcUtv91pDbajk9xVWUSoKw=; b=n/hMxdzuA2HwmY7TjftvAs5V9oYZt/CHD07AMjNjUlM6i01hI6rzBbtt7PeQJqhDjOOEn9 mM8oKMKy3katd0A26JjT0JC5JaCZlQTAcirZyGaOMdYUsgO0y3fO3QcO3guBgxX3O3swln 6KugFoEmFcFuUOt7gCkx6xnp6DNAfuU= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Sender:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description; bh=4WklghmhRoXLW11BvhMQXmcUtv91pDbajk9xVWUSoKw=; b=Rc1W4XBsmzSM4fsephNuxA5+Hc hN1F7QwRigICSNV8c1+dRaLlmHSl15upfOraFBq7OwpG+Irgc3a7wongSfIqAiZZfSOn9Vsx1o0J4 LQXqgi70HEADX3OtaFpqZPnDiPLnoNMo1bW9+0Uh/P8BBqyznnMRKUmfZrU49Pb7DA5POilNBpkbE OhzYrkOlMapvraFlDXnKzTlsgNgPpRBElg4Ini3Te0CJpdITvxeakGC1tf+zXJvpBOWnRn+z0YUHg w9LEXdbu+FKrCjDM1jpzTRuCtqNiEhzDAzbDQB+ZOFhsRGAege8eJEtU1q3Ewz1uUm3tlCAcO86kL /ZFLa/6Q==; Received: from mcgrof by bombadil.infradead.org with local (Exim 4.96 #2 (Red Hat Linux)) id 1phOPW-00GgRm-2Z; Wed, 29 Mar 2023 05:31:50 +0000 From: Luis Chamberlain To: david@redhat.com, patches@lists.linux.dev, linux-modules@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, pmladek@suse.com, petr.pavlu@suse.com, prarit@redhat.com, torvalds@linux-foundation.org, gregkh@linuxfoundation.org, rafael@kernel.org Cc: christophe.leroy@csgroup.eu, tglx@linutronix.de, peterz@infradead.org, song@kernel.org, rppt@kernel.org, willy@infradead.org, vbabka@suse.cz, mhocko@suse.com, dave.hansen@linux.intel.com, mcgrof@kernel.org Subject: [PATCH 5/7] modules/kmod: replace implementation with a sempahore Date: Tue, 28 Mar 2023 22:31:47 -0700 Message-Id: <20230329053149.3976378-6-mcgrof@kernel.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230329053149.3976378-1-mcgrof@kernel.org> References: <20230329053149.3976378-1-mcgrof@kernel.org> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Queue-Id: 61B4F12001C X-Rspamd-Server: rspam01 X-Stat-Signature: eud63i5zotar79gwnfqarnukhcb9ghyh X-HE-Tag: 1680067916-195288 X-HE-Meta: U2FsdGVkX1/IMYzrZ5+sbGy3DpPGGOnTt+iNJRU2aXYbAS5Rjg8K/2/WOSS7NW4YKsPQK963dQLR6KDTQhK9PklAAgku8YLi7AVueg9VdTmdZnRSWqe5I+rMdenZpdo9d1seGiZu6T5ihhxjMB1CBQ7HtiUS9yfBbq6UhgDa/3BdbnVIGUek+EU0XnYSiPXA2cA3z3lHQ6Cz3o5fZI8EhsznVYxg8gY+8zomAgYV/Y9BdIly7A5Z4WIVcg2uqWnVf/57P0AGV3UlGiyPrluM5n0lVisyX5OfMA2+0oDli2Pk7txyhVelMUSAxUaPVCvBJDhuNQXRvcBPOMezJoYB1CHz6tSwfHTwuH222OFwdWmYfQ3x/gNVDY5nDtCS5DOtsWMm5gSQJLKNTvOdvrEIwVCz/MkipQFo9QmiK5DywH7ntpcM0KTMiR8bE6L7lopCy3IdAe1ZMRar7Hwny7hqj7hMR2pX2+O6Zb+IfdOWtgd013I10TqmMU9xCEw8kT1gRng/v6SIh9wTvcEDj+H1aA5SK/QkCfXRRLPObt5be8DeInxOZEicFqE8m/Bsipv7U8qv7YjUg1xUXMURBdVNb57Jp5ewBs8LBvwTiMMWw+rNd3eWxJTVdcVce+Wh/j6t8jF2233trbwNznaAzzGBQV766EI3Uejhr+awzb2PRypilvdPFWyWqnHTqsleIXRy/2AZvdV6cjmhwSwR2GTXFn03r2NP1eapCMtdZCixQ0woFK1f4298itY2zTOJfTQmX6yFcyA6scMzTGs62ixDirlDOn8ZzQ5zu8rQyhxMliXPbUuGCTulp27nRzfj1TVXGT3lHWht16mw2phC7HSPVilWRdCEChczh0fiibi9lwKBpYswiqXVJOLDanaDTg06NLjgQufKXU65rCL7Ssj1sfwiV9xiIBXmCL0eREssTpv+fv1VpySI2vp7Hi7UqxqApjdXp42w4zCufrZ73hP l4XWn4te q/U5EcBTTvTlU2XJztZWky4rYLuU1oAOfMKLipx4ULsa2RLpmUdj7gWRtDJRmTzwcr3zHv9+cgqmVLXb01Wg52bFiAePqakUJ4Tb2KZ3mHe3Q6wnGR939rqNwkLrx8GkWLHczquw/T06E0g9NjgbKfDs5fuGSr+paz/jA3cp8v6fSJ6w7/5uDDh1/oYJYTBt7sJf1/7XwowD2wrGRPGzCHXU1MosxmeXIk8MjpvQG4tmVMxjH769UsRcIMLSMbqeUvfdb5sfX0tmTPq4nPJJpn52h9+W91we7DrDb/dcGyDgc9Fg8TONQEJpSFcKcBDPnFEbdFf5iYp7uCuIBk7HNGjBqxGz80v1Cfvsa5PrkyravtYUYja41pM9Jy8EIHgAHxpfXp/e6Njkl0kCG0EEupHsfv7zzk6DPm+Mg X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Simplfy the concurrency delimiter we user for kmod with the semaphore. I had used the kmod strategy to try to implement a similar concurrency delimiter for the kernel_read*() calls from the finit_module() path so to reduce vmalloc() memory pressure. That effort didn't provid yet conclusive results, but one thing that did became clear is we can use the suggested alternative solution with semaphores which Linus hinted at instead of using the atomic / wait strategy. I've stress tested this with kmod test 0008: time /data/linux-next/tools/testing/selftests/kmod/kmod.sh -t 0008 And I get only a *slight* delay. That delay however is small, a few seconds for a full test loop run that runs 150 times, for about ~30-40 seconds. The small delay is worth the simplfication IMHO. Signed-off-by: Luis Chamberlain --- kernel/module/kmod.c | 26 +++++++------------------- 1 file changed, 7 insertions(+), 19 deletions(-) diff --git a/kernel/module/kmod.c b/kernel/module/kmod.c index b717134ebe17..fd7c461387f8 100644 --- a/kernel/module/kmod.c +++ b/kernel/module/kmod.c @@ -40,8 +40,7 @@ * effect. Systems like these are very unlikely if modules are enabled. */ #define MAX_KMOD_CONCURRENT 50 -static atomic_t kmod_concurrent_max = ATOMIC_INIT(MAX_KMOD_CONCURRENT); -static DECLARE_WAIT_QUEUE_HEAD(kmod_wq); +static CONCURRENCY_LIMITER(kmod_concurrent_max, MAX_KMOD_CONCURRENT); /* * This is a restriction on having *all* MAX_KMOD_CONCURRENT threads @@ -148,29 +147,18 @@ int __request_module(bool wait, const char *fmt, ...) if (ret) return ret; - if (atomic_dec_if_positive(&kmod_concurrent_max) < 0) { - pr_warn_ratelimited("request_module: kmod_concurrent_max (%u) close to 0 (max_modprobes: %u), for module %s, throttling...", - atomic_read(&kmod_concurrent_max), - MAX_KMOD_CONCURRENT, module_name); - ret = wait_event_killable_timeout(kmod_wq, - atomic_dec_if_positive(&kmod_concurrent_max) >= 0, - MAX_KMOD_ALL_BUSY_TIMEOUT * HZ); - if (!ret) { - pr_warn_ratelimited("request_module: modprobe %s cannot be processed, kmod busy with %d threads for more than %d seconds now", - module_name, MAX_KMOD_CONCURRENT, MAX_KMOD_ALL_BUSY_TIMEOUT); - return -ETIME; - } else if (ret == -ERESTARTSYS) { - pr_warn_ratelimited("request_module: sigkill sent for modprobe %s, giving up", module_name); - return ret; - } + ret = down_timeout(&kmod_concurrent_max, MAX_KMOD_ALL_BUSY_TIMEOUT); + if (ret) { + pr_warn_ratelimited("request_module: modprobe %s cannot be processed, kmod busy with %d threads for more than %d seconds now", + module_name, MAX_KMOD_CONCURRENT, MAX_KMOD_ALL_BUSY_TIMEOUT); + return ret; } trace_module_request(module_name, wait, _RET_IP_); ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC); - atomic_inc(&kmod_concurrent_max); - wake_up(&kmod_wq); + up(&kmod_concurrent_max); return ret; } From patchwork Wed Mar 29 05:31:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Chamberlain X-Patchwork-Id: 13191897 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id ADFD7C761AF for ; Wed, 29 Mar 2023 05:32:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B819F6B007D; Wed, 29 Mar 2023 01:31:58 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A94B1900002; Wed, 29 Mar 2023 01:31:58 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7871B900004; Wed, 29 Mar 2023 01:31:58 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 5D377900003 for ; Wed, 29 Mar 2023 01:31:58 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 37D70A04C6 for ; Wed, 29 Mar 2023 05:31:58 +0000 (UTC) X-FDA: 80620814316.14.ED82B92 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf20.hostedemail.com (Postfix) with ESMTP id 9422A1C0005 for ; Wed, 29 Mar 2023 05:31:56 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=wRqNpi2g; spf=none (imf20.hostedemail.com: domain of mcgrof@infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=mcgrof@infradead.org; dmarc=fail reason="No valid SPF, DKIM not aligned (relaxed)" header.from=kernel.org (policy=none) ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1680067916; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=9aCwO6lydcYrtyg5yPLXnIQyE+LoOte6FX6HU5bmimM=; b=k6K9s3T3YiEItXi8qMABNKQeSUYp2xhnmBbmY1NCBRqsaiypY5hWLZZu4fjRuyu3T9uFql 8oBcn+6uRwr4la9hWqSTDKGvNNX89KLE848+VAQhSPvTagfuS++xnyQYXSOLC3AbF5ygoS lcIQPM2ioWzjoGj3bxWAu/sigKtFXAQ= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=wRqNpi2g; spf=none (imf20.hostedemail.com: domain of mcgrof@infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=mcgrof@infradead.org; dmarc=fail reason="No valid SPF, DKIM not aligned (relaxed)" header.from=kernel.org (policy=none) ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1680067916; a=rsa-sha256; cv=none; b=dDzxUTFBqOnrby+2oKCVzjCn8+HfwinvbvsGsWN/4kLXLYpBJrDABDVqH2ljCt3tEim2pa YN3aC77965Vpcu5bQCedeHM7jzwSTv5He2x+I3aFmYaSCYzGjgBC87ONnP81OXV4KEZ0dm jmosQcUOWWunOPkqrhdC5x/CnAAOZjk= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Sender:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description; bh=9aCwO6lydcYrtyg5yPLXnIQyE+LoOte6FX6HU5bmimM=; b=wRqNpi2g15Ano4d7S1D1Se8pFe rx5M2O1Oylzh0O3wIDwg5BZf5hYJHEZ4wPOlQT1a/cw9WGV4lbuzzH3WstC9eh95IXhDd/nqi7S+S SFQFG/EjhJzTx7CJXXzo8zx4qEijzU2qxBpNccJBe709o2dplGwgg3D94qIg+svDQ1qh/h/Qv4HuW VxbOuAJqab03K+uJZLBZZzHPknX+5nXLKzGD7VI9droyfDnQ8ZfZ5YS/sPGgUYNx6lCil+4rNyXfd 5PlNA67XBZ4kedjsm+pbkJ7idlMJ0AYK1mNpQyGKJNfsQhIm3llHEAfEAMvgImFfmCkuNtHVzGrJh NWs6awpQ==; Received: from mcgrof by bombadil.infradead.org with local (Exim 4.96 #2 (Red Hat Linux)) id 1phOPW-00GgRq-2i; Wed, 29 Mar 2023 05:31:50 +0000 From: Luis Chamberlain To: david@redhat.com, patches@lists.linux.dev, linux-modules@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, pmladek@suse.com, petr.pavlu@suse.com, prarit@redhat.com, torvalds@linux-foundation.org, gregkh@linuxfoundation.org, rafael@kernel.org Cc: christophe.leroy@csgroup.eu, tglx@linutronix.de, peterz@infradead.org, song@kernel.org, rppt@kernel.org, willy@infradead.org, vbabka@suse.cz, mhocko@suse.com, dave.hansen@linux.intel.com, mcgrof@kernel.org Subject: [PATCH 6/7] debugfs: add debugfs_create_atomic64_t for atomic64_t Date: Tue, 28 Mar 2023 22:31:48 -0700 Message-Id: <20230329053149.3976378-7-mcgrof@kernel.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230329053149.3976378-1-mcgrof@kernel.org> References: <20230329053149.3976378-1-mcgrof@kernel.org> MIME-Version: 1.0 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 9422A1C0005 X-Rspam-User: X-Stat-Signature: 7pmfburuunn319rc48gsf65zak5o9adr X-HE-Tag: 1680067916-107939 X-HE-Meta: U2FsdGVkX18BeaCRsFyZ4NKicgd5bWNiYh/U6QFyf9mUVHSjq9A11y/PxearWKHvZld+lvilK3vX0P/7FaD72bEIv8RL6ApAYPDBtcoiTV+CvBu/48NJsAopA50aQLUgwrT8YUBDD4yg02GqNmXkxSjOlC8sgStvBCB98HOIdnC+YFjClV7wbHzN2SJhrL6pGtH3rqc6OrkQayDZpI065Qq5FH9u7t56MepFAwKplUdnBlI2Q7dBACtr5+Cnbr7Atn3rEqGDkyv2Eqhl0LKbgcs1AO/ZnOVW/g4wPtBwaksO/e4RI1U7LxEPI2nfTQULeWc1WjJ3QLvkNZzh2vhPBc5zF/KYs99zblHtapCmaDPp5yGETaZspL9ahbQfIi7+S9QdT2T/gLWhmUWKsyd/OrS6P0jigX/Gfuh2e88Moz/Lch2dFSX6ezsiwVLOecm8l0O6/c0q1ihg6Jdm1znjwubZvrJmm3BVeg35Nqisc/sGHVfH4Vjh2oVQp+hNCCaYC/H+cw/0UvQXfLy1rTjMdPOR0ailxtM9qNGsowGgMrN6RMHu4O7Lk8Yw06mnorlQa4dWispyoB17NGxNdDKhzvR0fjRIC2YrIKrkVtH01Tg6k3lOxmQ3shMs7HnbNrf5S5sanOM3twBatGXeCVAEtgvzTmIx69X34Dio7akoiekTHfxAt5G9w5Tf9eSqT9wPYv/J8miKfYa7EzVZ/WQz7WswlQS639sUL9lAOudJ+ZUs396s084TfLHTAL6SaOtq2tqpMCSG1VD0bKDh+diwzc3x32L+hMCArAtS/i3lzQBm+K8eWZL5dxuxaJ+CoD5fliLm3ZgASC/z4T9daT7uLvmHxtO/OrSlAQx5SiAGDJ+jNJAYBwvMD/JLg1uUMwVtBdtpErzGK+nwbpPKLNgkaZoHNqbCGYYhd0RWiT1YAjjE4+g/iLWYDqntzevLMG5RYQjkDTKywYvnh+mMlxR g/f6XIpD 0wFnikpwIWUug+DyPkpBK44kklOlm21c03+sBXFaLDuM3C7wcqWpcCF8/d4+yow+sYhuphGySYHSOgCuHkalZff/IdS+p0I9erW5fV9u1EDd7xfEGHJO0zbDoTMl4CrD45n3O7XU9WN2KO1TpJt9jn2UQP3OVffPyPRVxtp37OUyksbEUdDuGQQJ/uGvyjX1JMHb/VKPiAGnLqPV/GkfovBv9dSEx1SYtFFZ7M6jAKf0Gcc60zOxqYlds2OxVZNwbzY4xuSR1pwZ4mCAAC3DDwLlc/a3TibuzOloD4q1Wfs5xHIo2tgW55nWotsKl1TXKVSsqaBvUpHgli/Twn99RIDuTxlJEQdteDk/JhvKEy7riiL8tGZoxxMCEOuygL03Pvmy5NsAvGe3AR3NbxIC71ChW094yJuJ2VBpasVCe/mgVYZ3+6Sw6E1p2MZmo0oNkCzzdS9U9zGI+CAWYo0n+0cAySw== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Sometimes you want to add debugfs entries for atomic counters which can be pretty large using atomic64_t. Add support for these. Signed-off-by: Luis Chamberlain Acked-by: Greg Kroah-Hartman --- fs/debugfs/file.c | 36 ++++++++++++++++++++++++++++++++++++ include/linux/debugfs.h | 2 ++ 2 files changed, 38 insertions(+) diff --git a/fs/debugfs/file.c b/fs/debugfs/file.c index 1f971c880dde..76d923503861 100644 --- a/fs/debugfs/file.c +++ b/fs/debugfs/file.c @@ -780,6 +780,42 @@ void debugfs_create_atomic_t(const char *name, umode_t mode, } EXPORT_SYMBOL_GPL(debugfs_create_atomic_t); +static int debugfs_atomic64_t_set(void *data, u64 val) +{ + atomic64_set((atomic64_t *)data, val); + return 0; +} +static int debugfs_atomic64_t_get(void *data, u64 *val) +{ + *val = atomic64_read((atomic64_t *)data); + return 0; +} +DEFINE_DEBUGFS_ATTRIBUTE_SIGNED(fops_atomic64_t, debugfs_atomic64_t_get, + debugfs_atomic64_t_set, "%lld\n"); +DEFINE_DEBUGFS_ATTRIBUTE_SIGNED(fops_atomic64_t_ro, debugfs_atomic64_t_get, NULL, + "%lld\n"); +DEFINE_DEBUGFS_ATTRIBUTE_SIGNED(fops_atomic64_t_wo, NULL, debugfs_atomic64_t_set, + "%lld\n"); + +/** + * debugfs_create_atomic64_t - create a debugfs file that is used to read and + * write an atomic64_t value + * @name: a pointer to a string containing the name of the file to create. + * @mode: the permission that the file should have + * @parent: a pointer to the parent dentry for this file. This should be a + * directory dentry if set. If this parameter is %NULL, then the + * file will be created in the root of the debugfs filesystem. + * @value: a pointer to the variable that the file should read to and write + * from. + */ +void debugfs_create_atomic64_t(const char *name, umode_t mode, + struct dentry *parent, atomic64_t *value) +{ + debugfs_create_mode_unsafe(name, mode, parent, value, &fops_atomic64_t, + &fops_atomic64_t_ro, &fops_atomic64_t_wo); +} +EXPORT_SYMBOL_GPL(debugfs_create_atomic64_t); + ssize_t debugfs_read_file_bool(struct file *file, char __user *user_buf, size_t count, loff_t *ppos) { diff --git a/include/linux/debugfs.h b/include/linux/debugfs.h index ea2d919fd9c7..f5cc613a545e 100644 --- a/include/linux/debugfs.h +++ b/include/linux/debugfs.h @@ -136,6 +136,8 @@ void debugfs_create_size_t(const char *name, umode_t mode, struct dentry *parent, size_t *value); void debugfs_create_atomic_t(const char *name, umode_t mode, struct dentry *parent, atomic_t *value); +void debugfs_create_atomic64_t(const char *name, umode_t mode, + struct dentry *parent, atomic64_t *value); void debugfs_create_bool(const char *name, umode_t mode, struct dentry *parent, bool *value); void debugfs_create_str(const char *name, umode_t mode,