From nobody Fri Jul 24 21:53:03 2026 Received: from mail-wm1-f46.google.com (mail-wm1-f46.google.com [209.85.128.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E9CB1352017 for ; Thu, 23 Jul 2026 08:26:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784795208; cv=none; b=K8wDnsq3QbUNZf7n1mEDWF6Wca77V96K7F0p41dnxYeOgvaqsbF604z0gphWU/txMG4Q9J51fkasZWQvHLdTyGulrSsoO+NK0gKC8Ovbd2rb19I7Iv5dIdpDXYJvOZJNw3yYxsS7RU9j7/jVq3gLCIfWL0EDEwFo2e5ayatizjg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784795208; c=relaxed/simple; bh=hLT73xbfSk62esfvnw6GvwdF5YVZpfjTwohB9aspol4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=DQ8dTnc5uqlwbjilaFblk3LzPZkaUGdZlOK8o7mj2MlKymS4nIsoiqiVGtykHq/ggMN3fDRL2yLxzoOO8nDRZ1Kc6Hdx/7gjsHZxTCUomlFLBV8oErG7mkOd+RAnuEOdAOC0MM66k9jZcy1aTfXP0GNRueGOKG1Wpi4G1/eka3I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=MWG41fq2; arc=none smtp.client-ip=209.85.128.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="MWG41fq2" Received: by mail-wm1-f46.google.com with SMTP id 5b1f17b1804b1-4953e04ef16so4040435e9.2 for ; Thu, 23 Jul 2026 01:26:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1784795202; x=1785400002; darn=vger.kernel.org; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to:content-type; bh=0LP6SRmtvPpKp+hB3DWKFFGnbVrOAHbyMKn00zrHg58=; b=MWG41fq21Vq3l2FiNXbsoCRpXYQsjjEAcx2jm20Ew0kru7vpascDXZUENg0uV+Bocm onYiE9OqwcnyZbkjEB6PXQX0Qm4R3IYkOG6Xy6z8eKUgkNUF8u2Kkp5fA/aY/frawbhu zBBp6EL2pXOycKJkVlSGzgxBXpDZ9H6B7cLm0QHEqBBdedcCeJwWwTKBAfB4887Vw73+ p+o994K+XnNUK02AnuEDYuyIbrww7qgVpuWz3M8YLv33LflHRM2UmQMo5zI/YQf+16O9 KApMkHw83fnH+byYjh/HAqybmq8Ar7/4FCJ9xyfK1mUZQ+a65es9wCO2wn5JTj6ST2ks mPCA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784795202; x=1785400002; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=0LP6SRmtvPpKp+hB3DWKFFGnbVrOAHbyMKn00zrHg58=; b=S1+1pK8foRenjtRNBL/hZoIiRz8SwEIAw1kCYqdSNAXVD8aRRWHcHwNt7LfgzOywsV 5pb+6V/Ak3yn8IVpxQFxgSEJT+LEUR5oDaH44ksUawOYs0qFV4r8K0iNNTB7scSRLKBQ jn9704pAHMYEpNnhFWc/6R3Adt+byaOpaXOwWiRHoySw5Ge48pJOC2fJQJ8iFcdh4Cul eHU75Y2aR+T8gBlP1T+5rNIn0LYGcO6BHpTS6lNTSfMjkmZCPV3VLGpG2JUtOTbwQrOf rEkMrTCLN20FCQwalPMQrkpKYz/CBh7e/vjBmYucu8gP3EYaDP4k0PzAggbISPPRTynk 85iQ== X-Forwarded-Encrypted: i=1; AHgh+Rrc67SbUGucUNYEU5pSZFyFiZWIng3LR+5P6RHy187Nw/hkMD+RAGqH3+sWKTQ41Lu3rogOInNiK8SFE94=@vger.kernel.org X-Gm-Message-State: AOJu0Yy1Qt5gFTF1nRLTyIc1cKWUIrHIR5lmwI5XFyUkupODc63ryAdx bDFs+hSR1S8QGycEujZ2udigXXsxkjmoWF94vjPWl6lOxC6XB2l8OpX9wYWrZCN2XCo= X-Gm-Gg: AR+sD13K5V02jAqnQUCuHC48swNUl5DYRf+xDSAdkOcDSH+EaYw/072U5YCCGcrudrD wC5W3W1zEnLavtjqemhLyOKuSWB5PIbBqYSvDwvL4dHIJq1eIE/dGxMCieOcDGNrEEs9HO2OI7b 4oDJOOLRvHRuKxNtWCmYxJ0wSshYmASj2rL4G2OHcojzLXgh76jtAdumT8+6PFYb6oqp0ma7oBO IMrjSE5s52og6iGgR1aSVF5DHk/NVFyNE7gAaRorjNsnN+tyjozzpsP+INR9AJllFAiX9iv0QXU Wv/YI8qrnYnptelsBP1567fEmnBcZKsI75cHto05YLEM/EaTojvPYMe8tJ2p9cVMMmF9RhnxBz8 V86TA1ShJcWxUpzXkynRjOkmC1rQ7+4i9cxo6OAfmg47yEnyTID5gU0fqa20fRY/XBrG0vc1PmQ == X-Received: by 2002:a05:600c:474e:b0:493:ee2b:c876 with SMTP id 5b1f17b1804b1-49573d22ee7mr26112725e9.35.1784795201619; Thu, 23 Jul 2026 01:26:41 -0700 (PDT) Received: from zovi.suse.cz ([2001:af0:8000:1409:193:86:92:181]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4956a4f9a1csm124831645e9.5.2026.07.23.01.26.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Jul 2026 01:26:41 -0700 (PDT) From: Petr Pavlu To: Luis Chamberlain , Petr Pavlu , Daniel Gomez , Sami Tolvanen Cc: Aaron Tomlin , linux-modules@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 1/6] module/dups: Inform duplicate requests about the result directly Date: Thu, 23 Jul 2026 10:25:51 +0200 Message-ID: <20260723-module-stats-rcu-v2-1-bd582261fae3@suse.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260723-module-stats-rcu-v2-0-bd582261fae3@suse.com> References: <20260723-module-stats-rcu-v2-0-bd582261fae3@suse.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable When kmod_dup_request_announce() announces the completion of a request_module() call to duplicate waiters, it queues a work item to invoke kmod_dup_request_complete(), and only that function calls complete_all(). This adds an arbitrary delay that is unnecessary and provides little benefit. Call complete_all() directly from kmod_dup_request_announce() instead. Signed-off-by: Petr Pavlu --- kernel/module/dups.c | 43 +++++++++---------------------------------- 1 file changed, 9 insertions(+), 34 deletions(-) diff --git a/kernel/module/dups.c b/kernel/module/dups.c index 1d720a5311ba..b063bc423aa8 100644 --- a/kernel/module/dups.c +++ b/kernel/module/dups.c @@ -48,7 +48,6 @@ struct kmod_dup_req { struct list_head list; char name[MODULE_NAME_LEN]; struct completion first_req_done; - struct work_struct complete_work; struct delayed_work delete_work; int dup_ret; }; @@ -93,29 +92,6 @@ static void kmod_dup_request_delete(struct work_struct *= work) kfree(kmod_req); } =20 -static void kmod_dup_request_complete(struct work_struct *work) -{ - struct kmod_dup_req *kmod_req; - - kmod_req =3D container_of(work, struct kmod_dup_req, complete_work); - - /* - * This will ensure that the kernel will let all the waiters get - * informed its time to check the return value. It's time to - * go home. - */ - complete_all(&kmod_req->first_req_done); - - /* - * Now that we have allowed prior request_module() calls to go on - * with life, let's schedule deleting this entry. We don't have - * to do it right away, but we *eventually* want to do it so to not - * let this linger forever as this is just a boot optimization for - * possible abuses of vmalloc() incurred by finit_module() thrashing. - */ - queue_delayed_work(system_dfl_wq, &kmod_req->delete_work, 60 * HZ); -} - bool kmod_dup_request_exists_wait(char *module_name, bool wait, int *dup_r= et) { struct kmod_dup_req *kmod_req, *new_kmod_req; @@ -130,7 +106,6 @@ bool kmod_dup_request_exists_wait(char *module_name, bo= ol wait, int *dup_ret) return false; =20 memcpy(new_kmod_req->name, module_name, strlen(module_name)); - INIT_WORK(&new_kmod_req->complete_work, kmod_dup_request_complete); INIT_DELAYED_WORK(&new_kmod_req->delete_work, kmod_dup_request_delete); init_completion(&new_kmod_req->first_req_done); =20 @@ -230,17 +205,17 @@ void kmod_dup_request_announce(char *module_name, int= ret) =20 kmod_req->dup_ret =3D ret; =20 + /* Inform all duplicate waiters to check the return value. */ + complete_all(&kmod_req->first_req_done); + /* - * If we complete() here we may allow duplicate threads - * to continue before the first one that submitted the - * request. We're in no rush also, given that each and - * every bounce back to userspace is slow we avoid that - * with a slight delay here. So queueue up the completion - * and let duplicates suffer, just wait a tad bit longer. - * There is no rush. But we also don't want to hold the - * caller up forever or introduce any boot delays. + * Now that we have allowed prior request_module() calls to go on + * with life, let's schedule deleting this entry. We don't have + * to do it right away, but we *eventually* want to do it so to not + * let this linger forever as this is just a boot optimization for + * possible abuses of vmalloc() incurred by finit_module() thrashing. */ - queue_work(system_dfl_wq, &kmod_req->complete_work); + queue_delayed_work(system_dfl_wq, &kmod_req->delete_work, 60 * HZ); =20 out: mutex_unlock(&kmod_dup_mutex); --=20 2.54.0 From nobody Fri Jul 24 21:53:03 2026 Received: from mail-wm1-f50.google.com (mail-wm1-f50.google.com [209.85.128.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D31A3353EDF for ; Thu, 23 Jul 2026 08:26:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784795210; cv=none; b=j0byu7OrtHLcccUxmSiY2kXFh431odjh3wCbT2XGQDAeyB9kaW62IKpIRpTSezXQGCcJh3XB1b28NWmXOm3MogWumk7awvXM0DsvqMEQ/jDZYKFVdTsU+0qq7kHsv7Y3vnQeFlwg6Ubhg2aREew7lILsZej0R2g/f6ivADNqQEw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784795210; c=relaxed/simple; bh=49xIm8JVVxA1IO8RnKUTcUahhuvMP7ZhANoSnO5slgk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=lPGKFMz1tiHfuALB47o2jNw4BAHUf72IXBGsSDFbLDRzGD/Ts5bFAC6FOxFGPCsVGWOSdI/PrDCrEFjWVoWnpihwPO9QbzcYSbtg2NZIIX+nJBD7BtUKK1DfnsCcYag4KFudfJtU+Umh4OBsympTl+EKAc6T3mZNG8at+LyFLgo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=DKFxVLJW; arc=none smtp.client-ip=209.85.128.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="DKFxVLJW" Received: by mail-wm1-f50.google.com with SMTP id 5b1f17b1804b1-4954f5e8020so1553035e9.2 for ; Thu, 23 Jul 2026 01:26:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1784795203; x=1785400003; darn=vger.kernel.org; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to:content-type; bh=ejMHszX4krSpU2meGRfcTBBnbHvAJ6f3bfAgNnoNb/s=; b=DKFxVLJWHa4Zxp0ys2bXvnrD/jpB8tTc98fsGB2pnuma1BDu7lD7Rmnn6F1Ns7Mu/x 6/h6KFiGbzUPSIK+wNaGn19hAInNIpubk0kSIW1Dg8Bw7kPABEfeIUuq4s3A5XAJqwd6 dvf2Oa1/v0VbgZMnwg5dJD/VHzR5u+nTJnFQy1CERGzhKs3KgCYtDCUB6+OnRfaZsorZ 3jDJXNqk50dYAjVeTEJLsHWR2/qKrHaFYO5cJgYZxBmtFajFtzipc4iUaecQU+bqWT8D uzNey9WVaFtWMALwa5R+biIvmYbk/ME0Rl+k96nqf2BZ/ItFYzDg8/rR6OVPf2VYT94U 1V1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784795203; x=1785400003; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=ejMHszX4krSpU2meGRfcTBBnbHvAJ6f3bfAgNnoNb/s=; b=ph3OM//MOaht4P3q2n2GVHhL0Ct/jui47RJK6Vf0IQq4mbk0ydMIN6t8js//FCHGT6 cRYnSvHrWOi83l+IKHnuwl2GOejJ+xlLv/6NeJO8XTymcUxJyimUCKonJ4EUXpHr8FXy lHSa5KY3HG71kqBY9hsmcCJsiuXKLf5bsXNPAY56j9dF91KixY+A4XPF/6aKXC4w9Fvf 1+Aecbs426/AygEBMmj1Kyhg7ULaiaCu2qvxCijPXgW6h+56esJG7M7Bpx/s7w/lAKSW cZFVqfIaFwbvO4DOSGgqv89C7/D5ifSByeMCwGaZ/pt5wGDUDcBtj3lr67HIl4XLX8k9 M4cw== X-Forwarded-Encrypted: i=1; AHgh+RqrVvL3K9V9thf7pXR5tib4G/fG/bhVWXOEal0IlHblRLgV7Z+Ua0hJ+hgKepdCPToXVTSpQD8GpbvvJkg=@vger.kernel.org X-Gm-Message-State: AOJu0YwZxVS3xdy2aUv9mFRT/5P4D1Q9pwAtutNHx2yV095fAzHtfrRo ZarUNOU3hd+Zwptjy3ky0jHmFzq4pAwO6/fWEjrbwBg4filvg4gmJ4IuD2tlq3iOguY= X-Gm-Gg: AR+sD123sY0/yd6PaM9SZfIUw0SXmzjSCxBCCDJjIBiDsiNY6jdpbi7T4M2EbZLNJkX q2YC9BqIb5QeMSnW+G6nlhYfBla7aAgzeNyKDrwL4Qr5XQa7Tx/viHDn4TmSd9EARnfn5tL5G5m FcHDPP1Prwm+NICl5Ayh24FzFLQ/jPEjTpUQ03vw4dRuzcoTLBw9CHYNaXfcufM4UwCNm1pABmm EIH+H0w8ANqCh04r50AJnOiY6QSsqRLhQTgFaXGQRi+iE5aZHy1B/UwgZP3i/Sxdemoh6vVKQve Je33jBrzWG26cmWi1S27Ow81vD2AE5AYoJhhuCs0iPF6RvBDEKwEvEgU0vChRb/xAcus6Z30nS9 4xCsvesQKg1rwCdJMqOq8zCv474BVnFme/6rztB9W/XFykL6oGlJijr8mT5VydBFjnaXhJsiMrA == X-Received: by 2002:a05:600c:a0a:b0:495:4dea:f7f5 with SMTP id 5b1f17b1804b1-49573ce968emr25120595e9.29.1784795202251; Thu, 23 Jul 2026 01:26:42 -0700 (PDT) Received: from zovi.suse.cz ([2001:af0:8000:1409:193:86:92:181]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4956a4f9a1csm124831645e9.5.2026.07.23.01.26.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Jul 2026 01:26:41 -0700 (PDT) From: Petr Pavlu To: Luis Chamberlain , Petr Pavlu , Daniel Gomez , Sami Tolvanen Cc: Aaron Tomlin , linux-modules@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 2/6] module/dups: Fix use-after-free in kmod_dup_req lifetime handling Date: Thu, 23 Jul 2026 10:25:52 +0200 Message-ID: <20260723-module-stats-rcu-v2-2-bd582261fae3@suse.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260723-module-stats-rcu-v2-0-bd582261fae3@suse.com> References: <20260723-module-stats-rcu-v2-0-bd582261fae3@suse.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable The kmod dups code uses RCU to ensure that a kmod_dup_req instance is freed only after it is no longer referenced. When releasing an instance, the kmod_dup_request_delete() function removes the kmod_dup_req from the dup_kmod_reqs list, waits via synchronize_rcu() and finally frees it. However, this doesn't work correctly because parallel users referencing the instance in kmod_dup_request_exists_wait() don't enter an RCU read-side critical section. This can result in a use-after-free. The kmod_dup_request_exists_wait() function may need to hold a valid reference to a kmod_dup_req instance across a blocking wait until the corresponding modprobe command completes. This makes it unsuitable for RCU. Fix the issue by changing the lifecycle management of kmod_dup_req to use reference counting. Fixes: 8660484ed1cf ("module: add debugging auto-load duplicate module supp= ort") Signed-off-by: Petr Pavlu Reviewed-by: Aaron Tomlin --- kernel/module/dups.c | 56 +++++++++++++++++++++++++++++++++++++-----------= ---- 1 file changed, 40 insertions(+), 16 deletions(-) diff --git a/kernel/module/dups.c b/kernel/module/dups.c index b063bc423aa8..99661236490a 100644 --- a/kernel/module/dups.c +++ b/kernel/module/dups.c @@ -30,6 +30,7 @@ #include #include #include +#include =20 #include "internal.h" =20 @@ -38,13 +39,12 @@ static bool enable_dups_trace =3D IS_ENABLED(CONFIG_MODULE_DEBUG_AUTOLOAD_= DUPS_TRACE); module_param(enable_dups_trace, bool_enable_only, 0644); =20 -/* - * Protects dup_kmod_reqs list, adds / removals with RCU. - */ +/* A mutex-protected list of active kmod requests. */ static DEFINE_MUTEX(kmod_dup_mutex); static LIST_HEAD(dup_kmod_reqs); =20 struct kmod_dup_req { + refcount_t refcount; struct list_head list; char name[MODULE_NAME_LEN]; struct completion first_req_done; @@ -52,12 +52,24 @@ struct kmod_dup_req { int dup_ret; }; =20 +static void get_kmod_req(struct kmod_dup_req *kmod_req) +{ + refcount_inc(&kmod_req->refcount); +} + +static void put_kmod_req(struct kmod_dup_req *kmod_req) +{ + if (refcount_dec_and_test(&kmod_req->refcount)) + kfree(kmod_req); +} + static struct kmod_dup_req *kmod_dup_request_lookup(char *module_name) { struct kmod_dup_req *kmod_req; =20 - list_for_each_entry_rcu(kmod_req, &dup_kmod_reqs, list, - lockdep_is_held(&kmod_dup_mutex)) { + lockdep_assert_held(&kmod_dup_mutex); + + list_for_each_entry(kmod_req, &dup_kmod_reqs, list) { if (strlen(kmod_req->name) =3D=3D strlen(module_name) && !memcmp(kmod_req->name, module_name, strlen(module_name))) { return kmod_req; @@ -86,10 +98,10 @@ static void kmod_dup_request_delete(struct work_struct = *work) * just returning 0. */ mutex_lock(&kmod_dup_mutex); - list_del_rcu(&kmod_req->list); - synchronize_rcu(); + list_del(&kmod_req->list); mutex_unlock(&kmod_dup_mutex); - kfree(kmod_req); + + put_kmod_req(kmod_req); } =20 bool kmod_dup_request_exists_wait(char *module_name, bool wait, int *dup_r= et) @@ -105,6 +117,7 @@ bool kmod_dup_request_exists_wait(char *module_name, bo= ol wait, int *dup_ret) if (!new_kmod_req) return false; =20 + refcount_set(&new_kmod_req->refcount, 1); memcpy(new_kmod_req->name, module_name, strlen(module_name)); INIT_DELAYED_WORK(&new_kmod_req->delete_work, kmod_dup_request_delete); init_completion(&new_kmod_req->first_req_done); @@ -136,10 +149,12 @@ bool kmod_dup_request_exists_wait(char *module_name, = bool wait, int *dup_ret) * keep tab on duplicates later. */ pr_debug("New request_module() for %s\n", module_name); - list_add_rcu(&new_kmod_req->list, &dup_kmod_reqs); + list_add(&new_kmod_req->list, &dup_kmod_reqs); mutex_unlock(&kmod_dup_mutex); return false; } + + get_kmod_req(kmod_req); mutex_unlock(&kmod_dup_mutex); =20 /* We are dealing with a duplicate request now */ @@ -169,7 +184,7 @@ bool kmod_dup_request_exists_wait(char *module_name, bo= ol wait, int *dup_ret) * calls bail out right away. */ *dup_ret =3D 0; - return true; + goto out; } =20 /* @@ -184,12 +199,14 @@ bool kmod_dup_request_exists_wait(char *module_name, = bool wait, int *dup_ret) TASK_KILLABLE); if (ret) { *dup_ret =3D ret; - return true; + goto out; } =20 /* Now the duplicate request has the same exact return value as the first= request */ *dup_ret =3D kmod_req->dup_ret; =20 +out: + put_kmod_req(kmod_req); return true; } =20 @@ -199,15 +216,25 @@ void kmod_dup_request_announce(char *module_name, int= ret) =20 mutex_lock(&kmod_dup_mutex); =20 + /* + * Look for a kmod_dup_req previously added in + * kmod_dup_request_exists_wait(). Note that a request_module_nowait() + * without its own kmod_dup_req entry can announce a result of + * a concurrent request_module() call. + */ kmod_req =3D kmod_dup_request_lookup(module_name); - if (!kmod_req) - goto out; + if (!kmod_req || completion_done(&kmod_req->first_req_done)) { + mutex_unlock(&kmod_dup_mutex); + return; + } =20 kmod_req->dup_ret =3D ret; =20 /* Inform all duplicate waiters to check the return value. */ complete_all(&kmod_req->first_req_done); =20 + mutex_unlock(&kmod_dup_mutex); + /* * Now that we have allowed prior request_module() calls to go on * with life, let's schedule deleting this entry. We don't have @@ -216,7 +243,4 @@ void kmod_dup_request_announce(char *module_name, int r= et) * possible abuses of vmalloc() incurred by finit_module() thrashing. */ queue_delayed_work(system_dfl_wq, &kmod_req->delete_work, 60 * HZ); - -out: - mutex_unlock(&kmod_dup_mutex); } --=20 2.54.0 From nobody Fri Jul 24 21:53:03 2026 Received: from mail-wm1-f48.google.com (mail-wm1-f48.google.com [209.85.128.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 72B653E638C for ; Thu, 23 Jul 2026 08:26:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784795211; cv=none; b=goMWaOaad6Bg5CQACXFYlJickOvcMaGNIufxFeVf6UVLkxQluXRB14LttCs3OFiLlwDRZ0XhH5jalWQEgv3GsgweY1kveW0nkwEwd5NDz8kAyr2ycgkhmRpUbUAcbC1Cnb2jUSMwR4esBOqMUCLhOd64Dhoj8z9LJpbnHgVWzFc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784795211; c=relaxed/simple; bh=tDp73uogEBcFI46+BNueLF1WmFv4AJinc2gyugciW0s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=FLRVDJYbTw7tSoYyiQU2MUvpt65Lo3A27IR+nuuDJJLYATx2IMtMBUfjmD5b8Ue+P80V+IyzWwb+39/14BjnARBXFFHRgdyJn4nnFHP1V67BnzCNEAVXlL40AUSutt2KPuLdsb3OgBEhnsimjzb6wImuH/8i6EswauNtDvXoAU0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=fSP4cjW7; arc=none smtp.client-ip=209.85.128.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="fSP4cjW7" Received: by mail-wm1-f48.google.com with SMTP id 5b1f17b1804b1-4955484387cso2877425e9.1 for ; Thu, 23 Jul 2026 01:26:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1784795203; x=1785400003; darn=vger.kernel.org; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to:content-type; bh=7/fxpbVarwxZfvJOM0Jcqy1IhF862sfboRy7HWs6RnY=; b=fSP4cjW7ubQ/YQIyqJaD5DamYsM2LfApxIZuszousiN78C6VrbE6SrLIG7eqN6w7Vh 3wCUXoNy/nTpRz8g7iFCKVDCcsHaTm+IK4eschInPgCzyd68iatjM0MVY2QDMN7gBVn8 U4QoMRjjoLuJsIhQwbQG0AGlOrJqZpQBS14zADLmpOgP7mcBZhOBlkERMWBq4OLFwMDS Crbl4gu2ok8g9LJQmVOp9wSO/SUnneHvGtFQBrUH+lmSApM2Xh+l8tJEmzlXvDdV32gX OzTG99Xtbpx3KWs2AiXcwKxW5KNpA7IEm/BnmDvAzzugkQQGVqjxUxQuwaEMpGV+Sa0M kaJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784795203; x=1785400003; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=7/fxpbVarwxZfvJOM0Jcqy1IhF862sfboRy7HWs6RnY=; b=fH/TBy36hlvaCZ7lR+sS6w2oc4e1RldYS2H0vSridAmHyAphpljjT9OkHFjpRR9ngM lz7ri2SItWz/duaFrXF4496xdl2ESxydTi7XeBvKZInRFnvSdP3oICImRbRuZaDR+8SE 3i6wggWuQlscE7G1O0ubOuwLFh07isLz+DyuLoWamnz3E2RqKcjzis/yIdxIG0lbRJId Q8myztbjuKtL0DLpptea9r+rphyS64y1T5ztDELXxQ7+xfKDFr2GBHPtcDgFa4dWdNF3 MDw4Fq2ELe2+mcRV3ty7C8+Mi1WFDE1QgHhMS2/jTDsNGpm820SaKYISw8PSUwnPe5oB 0xKg== X-Forwarded-Encrypted: i=1; AHgh+Rron8IhhLfYitXW19nLqYIwfq0sNqpO2IbetD1pwlP/SXarILP0V8EDQQN33OotCoC4+8/vHqLEYgV+MGw=@vger.kernel.org X-Gm-Message-State: AOJu0YwNvSr1acHLE4EYMQk47LENKwdkGHf0e/T7E1hwl/UZAY6y41Vl EmTps7HB7Z+a/zh8zx0DCmjg/TdiGVr8F2kJ4C4CzhLLMhss4d4Y4ubQF2j6UdMRb0M= X-Gm-Gg: AR+sD12tKKuBOEidCoyl6ilzUQphQ8NW0jc7En6HOOJaPaffFOAWC95/44rOkyOXsYT pCdxoXzZOlTm7GJj2Jvty2ciggbkRCg0F320PAdGARTUUcW0tRR6HjBjhiLebowbR95YBvVc9HV Nz0YG1SpX81kz8Cwbl74J3rvshTDFuOzUu2BgvZkdv9WCJeQxQNsxRhMybjnpe5U1imiY1igpbi HqxlZ6S4hjBxwyUDe0dMf3Cy4cMarsJMDZF5lhuMAJ3KS7vFmhNjt/OZei/YR5lgrq23Pr1ydCk EJVUWxtsVJV1SJaLK+L009u/G42/Z9ookbUQo2VRfDrg7nHM4egdrWZKLn4SX2ZstuVID7CXt1T eNbY5bWH+Y5m03pJd2rjqVGfD1tgSpw3BvaO0/n0kPxUUD6LYctYZx8wG504x6iPik+I9Y4sp/w == X-Received: by 2002:a05:600c:4ec8:b0:495:3da3:beb with SMTP id 5b1f17b1804b1-49573c9b559mr21221745e9.10.1784795202878; Thu, 23 Jul 2026 01:26:42 -0700 (PDT) Received: from zovi.suse.cz ([2001:af0:8000:1409:193:86:92:181]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4956a4f9a1csm124831645e9.5.2026.07.23.01.26.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Jul 2026 01:26:42 -0700 (PDT) From: Petr Pavlu To: Luis Chamberlain , Petr Pavlu , Daniel Gomez , Sami Tolvanen Cc: Aaron Tomlin , linux-modules@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 3/6] module/dups: Avoid unnecessary kmod_dup_req allocations Date: Thu, 23 Jul 2026 10:25:53 +0200 Message-ID: <20260723-module-stats-rcu-v2-3-bd582261fae3@suse.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260723-module-stats-rcu-v2-0-bd582261fae3@suse.com> References: <20260723-module-stats-rcu-v2-0-bd582261fae3@suse.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable The kmod dups code preallocates kmod_dup_req before taking kmod_dup_mutex to avoid allocating memory while holding the lock. This provides little benefit, since the allocation is fast and can safely be done under the lock. On the other hand, it leads to unnecessary allocations when the request turns out to be a duplicate and slightly complicates the code. Allocate kmod_dup_req only when needed and introduce a helper function alloc_kmod_req() to initialize the structure. Signed-off-by: Petr Pavlu Reviewed-by: Aaron Tomlin --- kernel/module/dups.c | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/kernel/module/dups.c b/kernel/module/dups.c index 99661236490a..0f6bb05b2d81 100644 --- a/kernel/module/dups.c +++ b/kernel/module/dups.c @@ -104,28 +104,31 @@ static void kmod_dup_request_delete(struct work_struc= t *work) put_kmod_req(kmod_req); } =20 -bool kmod_dup_request_exists_wait(char *module_name, bool wait, int *dup_r= et) +static struct kmod_dup_req *alloc_kmod_req(const char *module_name) { - struct kmod_dup_req *kmod_req, *new_kmod_req; - int ret; + struct kmod_dup_req *kmod_req =3D kzalloc_obj(*kmod_req); =20 - /* - * Pre-allocate the entry in case we have to use it later - * to avoid contention with the mutex. - */ - new_kmod_req =3D kzalloc_obj(*new_kmod_req); - if (!new_kmod_req) - return false; + if (!kmod_req) + return NULL; =20 - refcount_set(&new_kmod_req->refcount, 1); - memcpy(new_kmod_req->name, module_name, strlen(module_name)); - INIT_DELAYED_WORK(&new_kmod_req->delete_work, kmod_dup_request_delete); - init_completion(&new_kmod_req->first_req_done); + refcount_set(&kmod_req->refcount, 1); + memcpy(kmod_req->name, module_name, strlen(module_name)); + INIT_DELAYED_WORK(&kmod_req->delete_work, kmod_dup_request_delete); + init_completion(&kmod_req->first_req_done); + return kmod_req; +} + +bool kmod_dup_request_exists_wait(char *module_name, bool wait, int *dup_r= et) +{ + struct kmod_dup_req *kmod_req; + int ret; =20 mutex_lock(&kmod_dup_mutex); =20 kmod_req =3D kmod_dup_request_lookup(module_name); if (!kmod_req) { + struct kmod_dup_req *new_kmod_req; + /* * If the first request that came through for a module * was with request_module_nowait() we cannot wait for it @@ -138,7 +141,6 @@ bool kmod_dup_request_exists_wait(char *module_name, bo= ol wait, int *dup_ret) * would benefit from duplicate detection. */ if (!wait) { - kfree(new_kmod_req); pr_debug("New request_module_nowait() for %s -- cannot track duplicates= for this request\n", module_name); mutex_unlock(&kmod_dup_mutex); return false; @@ -149,6 +151,11 @@ bool kmod_dup_request_exists_wait(char *module_name, b= ool wait, int *dup_ret) * keep tab on duplicates later. */ pr_debug("New request_module() for %s\n", module_name); + new_kmod_req =3D alloc_kmod_req(module_name); + if (!new_kmod_req) { + mutex_unlock(&kmod_dup_mutex); + return false; + } list_add(&new_kmod_req->list, &dup_kmod_reqs); mutex_unlock(&kmod_dup_mutex); return false; @@ -158,7 +165,6 @@ bool kmod_dup_request_exists_wait(char *module_name, bo= ol wait, int *dup_ret) mutex_unlock(&kmod_dup_mutex); =20 /* We are dealing with a duplicate request now */ - kfree(new_kmod_req); =20 /* * To fix these try to use try_then_request_module() instead as that --=20 2.54.0 From nobody Fri Jul 24 21:53:03 2026 Received: from mail-wm1-f45.google.com (mail-wm1-f45.google.com [209.85.128.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3A62F3EEAC3 for ; Thu, 23 Jul 2026 08:26:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784795214; cv=none; b=mTWHjLPYg4eYOJ2YgpIFuP/Z5/pke2AcGKWnxPg0VYYsl4i2yUFpLbuZXrVV0Q9aSrGP88Y3jXQIXJsOnQzWNh2nKaYko03qwg58oyXxlHJ0Jj2ueY09uRp4w9y1FBMqp4olgNSSUzbg6BL1KO9eljK8KR7kvmByR3Qykj6r9ic= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784795214; c=relaxed/simple; bh=M3w/NX8EtAs4Vp3CPWjzqrrqNViRwAZKhFJyEdDma0Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=tnNZKDXkpM7XyVMI1I1x+LW2+ud25uBvHYvm7IFnS0giGKulB8LZ4jnRGc2PKRiy3tRV5COiCnl+jH9NH7yEKB9+BZ+YW3BBlCE69VA+8x60WGE6e3/oruEe1gcwNZgmLb2jdCXoB2lWCQ/sa4yaoAZshLII6tFFOcn8/n7q2G8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=AZQ9kxEF; arc=none smtp.client-ip=209.85.128.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="AZQ9kxEF" Received: by mail-wm1-f45.google.com with SMTP id 5b1f17b1804b1-4954dff6536so3005715e9.0 for ; Thu, 23 Jul 2026 01:26:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1784795203; x=1785400003; darn=vger.kernel.org; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to:content-type; bh=8CrImD1PV1oAhd0eWI5Z44JgRoeHcEfNsqmH16WcFSY=; b=AZQ9kxEFUchQYlt+brTREg1eZVH20Bjyb3LL0QxyL6XyEOMonuC6MBmI2sztmuxM/U wixwjN3A7/d6UwesdF5F6ZJ9CFZXzQdjVpV9ajV0R/2QrZetNOm2wmmJTW/I+UZ/Czbu jBArDZblt3ic382vyDmxTP96k5G/8s3Wra0ETo89GvSAF5YWcyin81mgmJz4H8KzalYf eNw3HZgXfEq+RGfXyVBXWGvZnA9hf8dHbl2Ox2lnG03WCZullM1EmkYS0nT19Vz/u4yg PuK6DTghZjBK9jID2H4tMlXQIbiHd6iwlxzsi6E0zvhAgR/76jKyq+eQbBJShLSpm7qX 7zyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784795203; x=1785400003; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=8CrImD1PV1oAhd0eWI5Z44JgRoeHcEfNsqmH16WcFSY=; b=axhd4PKkuG2U3LHGqddYIM74gOoED8wEIjkGdZhkTZGB+fTl/pNuYH4fElwrOiFyVU ZXkEq0qGS3wsECgrWVA4wbXNQ4RoDbycVxej1+ySa0MjefpAp4YwdakecxbkctkYk8X4 O5LvCMl9DiMXWu+mmSh3ti9heB7PozMnh9PAQJ5vFlF3GhWDxmS2zjkdisQqVk4Sufdc b45rIa+RvF8fDKGbj3N0+uozl+zZt6RCxIrqhv5E6Jz742su2pxYxECUZFzmKucm6Ys6 Evwp9dkWlz+CKvrSeXFnHJnXna60iLnCdGd1mt2fOT4fjckb8+nYfslQ0yWfqugV4zdn DVqA== X-Forwarded-Encrypted: i=1; AHgh+RrizkBtaZ5xf46u0nQ7oHfoWDVmil5pmrIO7cmqh/URqZkqrQczmEk/Q7xckRhL+gA/w3vZrEOh9iFFF04=@vger.kernel.org X-Gm-Message-State: AOJu0YwnBifbbttDNlQbuczoSYRojz2F8dQcTF11dYYScZDC5h11dY/5 6MckOBaU2osnd2/8CMOQN4OQs8yOHEFSXGsFW9B8XIIj9rT2UPe0WLT+A9IC4QbxjFI= X-Gm-Gg: AR+sD12tuRaIyjX7qzeyAR5jZWf80y8pLHWklt9qyYiDbILIi/6hXOJeVt50O6slswj m4d0ulQR32f8A7B2pKcUaA3u+D6fvrDdOe9Olkrq6r0uyvgLHO8+jIiIC1AD72TJBvBrHmZ5qJb lAmQ9r3ri+WnpoJERJMVTZnaq1tqT84QPgbvA67ki7wE3yZ7XDH0dnpE4CivHVtWNBe9Tk2pDGX 9PQgW5Zn8hr9CHiWspsuFTd86Xkp/lhm4OgFtpbl1xNW9OcS4QcJcnbKCd04r4HvBuAHhMriqG/ 5vP/NFjMZhKD/Z8rZSY4j8rY/tl5xl88x7Xdqx/GZDExL1cUceYZlhFZZ1j5kbi1oFHGzIZ+lGR UJm+UiPmv5XPtDgXMzo8jC8MBuYESWvLhqzwfxU+/cVWYRRwq+3n24eRO8s2tkSmX48FwrDiyHQ == X-Received: by 2002:a05:600c:548a:b0:493:eb71:5cc6 with SMTP id 5b1f17b1804b1-49573d0eac1mr21539715e9.27.1784795203484; Thu, 23 Jul 2026 01:26:43 -0700 (PDT) Received: from zovi.suse.cz ([2001:af0:8000:1409:193:86:92:181]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4956a4f9a1csm124831645e9.5.2026.07.23.01.26.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Jul 2026 01:26:43 -0700 (PDT) From: Petr Pavlu To: Luis Chamberlain , Petr Pavlu , Daniel Gomez , Sami Tolvanen Cc: Aaron Tomlin , linux-modules@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 4/6] module/dups: Use scope-based cleanup helpers Date: Thu, 23 Jul 2026 10:25:54 +0200 Message-ID: <20260723-module-stats-rcu-v2-4-bd582261fae3@suse.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260723-module-stats-rcu-v2-0-bd582261fae3@suse.com> References: <20260723-module-stats-rcu-v2-0-bd582261fae3@suse.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Use scope-based cleanup helpers for kmod_dup_mutex and kmod_req to shorten the code and to clarify where the lock is taken in kmod_dup_request_exists_wait(). Signed-off-by: Petr Pavlu --- kernel/module/dups.c | 56 +++++++++++++++++++++---------------------------= ---- 1 file changed, 23 insertions(+), 33 deletions(-) diff --git a/kernel/module/dups.c b/kernel/module/dups.c index 0f6bb05b2d81..56d659f049c5 100644 --- a/kernel/module/dups.c +++ b/kernel/module/dups.c @@ -63,6 +63,8 @@ static void put_kmod_req(struct kmod_dup_req *kmod_req) kfree(kmod_req); } =20 +DEFINE_FREE(put_kmod_req, struct kmod_dup_req *, if (_T) put_kmod_req(_T)) + static struct kmod_dup_req *kmod_dup_request_lookup(char *module_name) { struct kmod_dup_req *kmod_req; @@ -97,9 +99,8 @@ static void kmod_dup_request_delete(struct work_struct *w= ork) * kmod. The inneficies there are a call to modprobe and modprobe * just returning 0. */ - mutex_lock(&kmod_dup_mutex); - list_del(&kmod_req->list); - mutex_unlock(&kmod_dup_mutex); + scoped_guard(mutex, &kmod_dup_mutex) + list_del(&kmod_req->list); =20 put_kmod_req(kmod_req); } @@ -120,15 +121,18 @@ static struct kmod_dup_req *alloc_kmod_req(const char= *module_name) =20 bool kmod_dup_request_exists_wait(char *module_name, bool wait, int *dup_r= et) { - struct kmod_dup_req *kmod_req; + struct kmod_dup_req *kmod_req __free(put_kmod_req) =3D NULL; int ret; =20 - mutex_lock(&kmod_dup_mutex); - - kmod_req =3D kmod_dup_request_lookup(module_name); - if (!kmod_req) { + scoped_guard(mutex, &kmod_dup_mutex) { struct kmod_dup_req *new_kmod_req; =20 + kmod_req =3D kmod_dup_request_lookup(module_name); + if (kmod_req) { + get_kmod_req(kmod_req); + break; + } + /* * If the first request that came through for a module * was with request_module_nowait() we cannot wait for it @@ -142,7 +146,6 @@ bool kmod_dup_request_exists_wait(char *module_name, bo= ol wait, int *dup_ret) */ if (!wait) { pr_debug("New request_module_nowait() for %s -- cannot track duplicates= for this request\n", module_name); - mutex_unlock(&kmod_dup_mutex); return false; } =20 @@ -152,18 +155,12 @@ bool kmod_dup_request_exists_wait(char *module_name, = bool wait, int *dup_ret) */ pr_debug("New request_module() for %s\n", module_name); new_kmod_req =3D alloc_kmod_req(module_name); - if (!new_kmod_req) { - mutex_unlock(&kmod_dup_mutex); + if (!new_kmod_req) return false; - } list_add(&new_kmod_req->list, &dup_kmod_reqs); - mutex_unlock(&kmod_dup_mutex); return false; } =20 - get_kmod_req(kmod_req); - mutex_unlock(&kmod_dup_mutex); - /* We are dealing with a duplicate request now */ =20 /* @@ -190,7 +187,7 @@ bool kmod_dup_request_exists_wait(char *module_name, bo= ol wait, int *dup_ret) * calls bail out right away. */ *dup_ret =3D 0; - goto out; + return true; } =20 /* @@ -205,14 +202,11 @@ bool kmod_dup_request_exists_wait(char *module_name, = bool wait, int *dup_ret) TASK_KILLABLE); if (ret) { *dup_ret =3D ret; - goto out; + return true; } =20 /* Now the duplicate request has the same exact return value as the first= request */ *dup_ret =3D kmod_req->dup_ret; - -out: - put_kmod_req(kmod_req); return true; } =20 @@ -220,26 +214,22 @@ void kmod_dup_request_announce(char *module_name, int= ret) { struct kmod_dup_req *kmod_req; =20 - mutex_lock(&kmod_dup_mutex); - /* * Look for a kmod_dup_req previously added in * kmod_dup_request_exists_wait(). Note that a request_module_nowait() * without its own kmod_dup_req entry can announce a result of * a concurrent request_module() call. */ - kmod_req =3D kmod_dup_request_lookup(module_name); - if (!kmod_req || completion_done(&kmod_req->first_req_done)) { - mutex_unlock(&kmod_dup_mutex); - return; - } - - kmod_req->dup_ret =3D ret; + scoped_guard(mutex, &kmod_dup_mutex) { + kmod_req =3D kmod_dup_request_lookup(module_name); + if (!kmod_req || completion_done(&kmod_req->first_req_done)) + return; =20 - /* Inform all duplicate waiters to check the return value. */ - complete_all(&kmod_req->first_req_done); + kmod_req->dup_ret =3D ret; =20 - mutex_unlock(&kmod_dup_mutex); + /* Inform all duplicate waiters to check the return value. */ + complete_all(&kmod_req->first_req_done); + } =20 /* * Now that we have allowed prior request_module() calls to go on --=20 2.54.0 From nobody Fri Jul 24 21:53:03 2026 Received: from mail-wm1-f43.google.com (mail-wm1-f43.google.com [209.85.128.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 20C483911A9 for ; Thu, 23 Jul 2026 08:26:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784795210; cv=none; b=F6vgotoC8zRQ3ctnpR/fycsWuylAJHdis7/HMnH0hsrg7XNHEQaKmPpnKjRr9jBfxjN1ZFgexuiatLn0zv8zFbvxwvvcnuwi2UyRIgd01O46wZ8lyDQZkZcafRyHlY1cXqMeEh/9B+ulrV918Wrcf8cK17mhABqep36OAeAtadk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784795210; c=relaxed/simple; bh=1McoUymBymyISLFpJohX21UVwv2KSLo7NWLJUK7vCCQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=kzEk2JhUMa/rnRYvm50b7txQFcNXXyEc80UaOSgfCmX/k/wbMojYmzlnpHlDn4RcK1B9uE4z7dBAyNSuq7ggFJYoy6Vw6OSW/ryjyexotUl/IwKOMc2z5zbWwbaVOsO1p9Xg5irNsvjdM4WAP5TTicsqzGh/JWQQx9uGxg1WGIY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=fdVF9C63; arc=none smtp.client-ip=209.85.128.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="fdVF9C63" Received: by mail-wm1-f43.google.com with SMTP id 5b1f17b1804b1-49556f97a9dso2300115e9.1 for ; Thu, 23 Jul 2026 01:26:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1784795204; x=1785400004; darn=vger.kernel.org; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to:content-type; bh=rlMszdZXGp83rqdq4F5705HBF23F8eoUUsJHW6GLZWI=; b=fdVF9C633PSDVPlg4QYFqjQZ1rhQg2Rb+PeHA/hn5Eqgj2jX1D0F1X29Z9S1LtxyF9 RVlkkagYp6dkWNEJmDfGFefizkupkKAVbbJW0/ORbkXKr/J1ry9Vn4SBZoaSk52VTfi5 HsUJ3xRHeHHbjXHU0JZ8qyWO7gxOydfTnpterguaqatwB3n2Tq8d5POKo7+miXzVG44H zTSpCadMyLYUzOzxQi3HzyZceGALi/p7hO6D9UnfZLbaz/6GrrzJ+u1eOGhxCvngLx4w Bn3Xdx4eCmLMZut2w9m1HHEwyd7mpMnDpeE5FYfVfAjY0fPqbeOkvMBZW4sFCKSnCUuZ IOkQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784795204; x=1785400004; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=rlMszdZXGp83rqdq4F5705HBF23F8eoUUsJHW6GLZWI=; b=Jvh6/mIEgyoB7YKFm1PDMLJHAfGe2XKl/dS9wkHiXfw/qMY/2RySKMMmYskyJ08ZHp dbpF1cary96mckKNYKhpFJA2eueymumygMHgK+FJrY8lmfR0hkANQvgXGfMaWcrk/2TQ TsDGHbbPyHSPFpB9S27jYRJMYjxNkCknNRyz43NsxHVDd50TmL9X6sRrqQD1m7hv+vhj 8qEPqyW9bl6id1U+S+U6fsToMrBFsajtgRyQE/rnnAIT6E6a9kwVr58oSMVCp7H2xkfY FswYdD0ea9WUTQhLaZL4f1CBpfGeJ90dYae8yzV2888r04vNC7Xscnckbl2Tt5skYkcL Wwog== X-Forwarded-Encrypted: i=1; AHgh+RqKHXb8sXa0vkeJjc6eQUZ6U1D9R3n+G1GzyQkQCXPMxF3b0vV0TJnulY/D0WSklvVUsQNudnCtq555BGQ=@vger.kernel.org X-Gm-Message-State: AOJu0Yyn1msctAVXBz/MF5jWsXww56cyh1FNkGlZAUad2lCTLlRlmoSI G+d2mhEz8+VXmx9DFzQ6UFLC5s15dsfAsmxFLt7PAK5d5bZIlYuq20YySqZ0RxDqSYw= X-Gm-Gg: AR+sD13NZzJWdAzA+JBtqn/b+yzHcS16eHDeeweY4FVYxAmBbIRiP32dKfrdw//Umy3 0noeskQmS3F8k32ue8JVdQdFda8X8h4P/yZNxxMsUndO+GspTSCL0IZPKOf07PBQFKMG1lA1b+a RKsXlFz1M4uSDjKxPxavF/o7PBXKI6qfamDDb6TRSlK8WFpauGFmCo8VQshzbsQWm2OOYELF9B4 APVRNzKU4q/QwykQQhmEaARjV7YcG/GskVax+ugnTJzLIHRasTFtAI43W283uiTz1o9yjUo3f2U ClHUA+a6uGRCU+RUsLE7xmip0ah/DibGfRsg8FpcekdpZxbny8RAjnQsdVoKeWaE1lQ1oK0SVvT LPkYbH5Yjb0BzQuiAkURM2yiFn3yYN8Yk2kJXx8dizDK8Nyxl1DnFS5DD1gE9FQyGMkaAOaWFVg == X-Received: by 2002:a05:600c:19cc:b0:493:e451:a9e1 with SMTP id 5b1f17b1804b1-49573c8c29amr21928245e9.2.1784795204083; Thu, 23 Jul 2026 01:26:44 -0700 (PDT) Received: from zovi.suse.cz ([2001:af0:8000:1409:193:86:92:181]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4956a4f9a1csm124831645e9.5.2026.07.23.01.26.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Jul 2026 01:26:43 -0700 (PDT) From: Petr Pavlu To: Luis Chamberlain , Petr Pavlu , Daniel Gomez , Sami Tolvanen Cc: Aaron Tomlin , linux-modules@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 5/6] module/dups: Use strcmp() to compare module names Date: Thu, 23 Jul 2026 10:25:55 +0200 Message-ID: <20260723-module-stats-rcu-v2-5-bd582261fae3@suse.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260723-module-stats-rcu-v2-0-bd582261fae3@suse.com> References: <20260723-module-stats-rcu-v2-0-bd582261fae3@suse.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Use strcmp() instead of strlen()+memcmp() to compare module names in kmod_dup_request_lookup(), since all strings are NUL-terminated. Signed-off-by: Petr Pavlu --- kernel/module/dups.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/kernel/module/dups.c b/kernel/module/dups.c index 56d659f049c5..80e1638ac34a 100644 --- a/kernel/module/dups.c +++ b/kernel/module/dups.c @@ -72,11 +72,9 @@ static struct kmod_dup_req *kmod_dup_request_lookup(char= *module_name) lockdep_assert_held(&kmod_dup_mutex); =20 list_for_each_entry(kmod_req, &dup_kmod_reqs, list) { - if (strlen(kmod_req->name) =3D=3D strlen(module_name) && - !memcmp(kmod_req->name, module_name, strlen(module_name))) { + if (!strcmp(kmod_req->name, module_name)) return kmod_req; - } - } + } =20 return NULL; } --=20 2.54.0 From nobody Fri Jul 24 21:53:03 2026 Received: from mail-wm1-f45.google.com (mail-wm1-f45.google.com [209.85.128.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 318E73EEAEF for ; Thu, 23 Jul 2026 08:26:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784795212; cv=none; b=Heu5Bax8zEcj+QdftahuhVYYqZDacWyVJf/ofA7jfv9OrhwtoRcmS+K8AMOvO0LxOsPrfQw6o9/Znzpwbss6rAX+6s5lUyCwULQgoVrNF9mACO/qyyl3iGLuSvlWxBLBKPSD/WpXxif708OLL8C2ni2yf8OCz74ceMIXwaI6HHk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784795212; c=relaxed/simple; bh=IgiwPhZRnCmibJAtp5gN92zy47gDauD1GBlPirNJdlA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=h59o1p8MT9Lw4qYxvKvToHQ3ZxKhFxod/ZGIzuzW/YJbyVYsb7fnlg/1cCFEu7gEEC8bPR5e+xUDNjcq2mgL/x0yGy4aVYU6MYmBaNkgj5mjyGAO0/lbjSWU/02agOxja9dTMbtOzTmLeGcf7natB+p53tA3JmrAkuTXFwAycjY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=JdlypoLI; arc=none smtp.client-ip=209.85.128.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="JdlypoLI" Received: by mail-wm1-f45.google.com with SMTP id 5b1f17b1804b1-49554ebb87dso3954255e9.3 for ; Thu, 23 Jul 2026 01:26:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1784795205; x=1785400005; darn=vger.kernel.org; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to:content-type; bh=KUb/Fmtm5YHhP1LhLkb3EnQ0f20iq+ZT2Qlt/e1gqvQ=; b=JdlypoLI/UrpB1pSB6RxGkJgYfJNCbQncXnslppynrmhia+uxqmml2HuKkvy0qf0Xj afmj9ozsnS1IdFUPRS00dKTS/q8Bp5lEGMdGwkbuqOYhT0CNCcEpIXWccaAWlGGGx7T6 +I7Bpn3XjvdPIkXSIKPuck1C9vNRkFfPX2j2ibSoqKnTT7tXMntVIgcoc6q6TR2l+AlT heYoZSb3iAGa4z1+OWZyNIppBYWmarPLo0TXS3yJklLPGfMKMhJqAuiaLp7ljRRL0wSw Vq19BTWv+j3AWDGGQwtBSttoL3qCFE8BPv+Fbn1VJW3hi1CzsJAxnaRN7YgWoOAlkrrQ w1lA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784795205; x=1785400005; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=KUb/Fmtm5YHhP1LhLkb3EnQ0f20iq+ZT2Qlt/e1gqvQ=; b=maGBZt6TZ7yGRmCrotEN9GZ/fCiw777lrTDjyBrXKlCbCHsGLEt8b+2ApzWN4peiQf 16+y9OQdz13RjnQL2y3ReXb6lPak0kM9/wmy5sT5Dq/Z5cL1uBSOdTRxJNcr7Fmeoivn OIm8TRFChcXz1avYyQd8gNnf+r/eO7AtIvqWbPmrFzLSleGUs+7ktJBNmmO6ONHpON1o WdclesOBgo3ak+2+PPJ0KlgI2rFTBGvj++Fbrkv1nvtVXYl+LRFdogr0rYt7I3U3DcZX 5CGKS+CNIYVMj2XMclTCclxHBa8pmF5jaJkBvGSBk26Ou1NPeL4tSabXlKuph/QGcv7u AfQg== X-Forwarded-Encrypted: i=1; AHgh+RqdRDtEyaR0X3ei5Rmd3R0qbrfYgIqmIyOjKbk63rEWYzNvfq55OWHP8uOIuVSAw3zI6nBLgxmsMC+Cd90=@vger.kernel.org X-Gm-Message-State: AOJu0YwDHm5iIoGn37jLe+3mI9oueboMpFwArA2pdxQx+BPzBlGc651G lL5gCZd3tVt5zsP58g775yxtjII+Qtjjnm7Oqgs526rIVKvzhfgQJAEMGQhrCPUg41jloBfopMB kJUvD1Fg= X-Gm-Gg: AR+sD136mhxC0VEpbj1DwTatnI6em0a5F4kWqvztT7bG/x+iyTYXxJxRTtlA1xYie0+ O/fsXB5NFv4d8DsUCARazPTxj9b4kzIhRgSaVocVQkUkQSxR8Xgjk/qwGCnuLm+SPf8YB4ntoo3 JcGEHIw8YZ34e7+sQoJiKzRXH2TLCXVv3gqIrlVRm1ld4o1VhBOLrc1OMmdkHt2B1XqLqSjgNAP VvU1Sn8ikfEjTBZHMKWtLdY91hmzYiC/Fg+AAHPw882jtvPDz8/FUksH/AFNR6KdLxwDgmwOYdb aWs+CmBcAAvADz/IqFqNPntj3ucGxm4GI51Xf+J8s4H2QR+lSLMRJ70sRYu+5ZEXKkyW+L1rQZQ uzTFALISk+4Dars1o4u2alcY6k2JgjXGGzxlLsseDJe9LnrSmrF1W4Uxjj14lOiYx35M/2hCvRQ == X-Received: by 2002:a05:600c:6a96:b0:495:641a:bd3f with SMTP id 5b1f17b1804b1-49573cd03f0mr14489445e9.13.1784795204743; Thu, 23 Jul 2026 01:26:44 -0700 (PDT) Received: from zovi.suse.cz ([2001:af0:8000:1409:193:86:92:181]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4956a4f9a1csm124831645e9.5.2026.07.23.01.26.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Jul 2026 01:26:44 -0700 (PDT) From: Petr Pavlu To: Luis Chamberlain , Petr Pavlu , Daniel Gomez , Sami Tolvanen Cc: Aaron Tomlin , linux-modules@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 6/6] module/dups: Clean up includes Date: Thu, 23 Jul 2026 10:25:56 +0200 Message-ID: <20260723-module-stats-rcu-v2-6-bd582261fae3@suse.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260723-module-stats-rcu-v2-0-bd582261fae3@suse.com> References: <20260723-module-stats-rcu-v2-0-bd582261fae3@suse.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable The kernel/module/dups.c file relies on the following definitions and associated functions: * module_param() -> linux/moduleparam.h, * DEFINE_MUTEX() -> linux/mutex.h, * LIST_HEAD(), list_for_each_entry(), ... -> linux/list.h, * refcount_t, refcount_inc(), ... -> linux/refcount.h, * MODULE_NAME_LEN -> linux/module.h, * completion, complete_all(), ... -> linux/completion.h, * delayed_work, work_struct, ... -> linux/workqueue.h, * lockdep_assert_held() -> linux/lockdep.h, * strcmp(), memcpy() -> linux/string.h, * container_of() -> linux/container_of.h, * DEFINE_FREE(), __free(), scoped_guard() -> linux/cleanup.h, * kzalloc_obj(), kfree() -> linux/slab.h, * pr_debug(), pr_warn() -> linux/printk.h, * WARN() -> linux/bug.h, * TASK_KILLABLE -> linux/sched.h, * HZ -> linux/param.h. Update the file's include list accordingly. Signed-off-by: Petr Pavlu --- kernel/module/dups.c | 32 ++++++++++++-------------------- 1 file changed, 12 insertions(+), 20 deletions(-) diff --git a/kernel/module/dups.c b/kernel/module/dups.c index 80e1638ac34a..872db6159b48 100644 --- a/kernel/module/dups.c +++ b/kernel/module/dups.c @@ -7,30 +7,22 @@ =20 #define pr_fmt(fmt) "module: " fmt =20 +#include +#include +#include +#include +#include +#include #include +#include +#include +#include +#include +#include #include -#include -#include -#include -#include -#include #include -#include -#include -#include +#include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include =20 #include "internal.h" =20 --=20 2.54.0