From nobody Fri Oct 2 02:30:17 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 2365442BC36 for ; Thu, 6 Aug 2026 09:11:37 +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=1786007500; cv=none; b=F1I6tl/p9f62SLVA1QduE7wAQdzucVl4aJRSNunAuk55VJ3CIEBjAB5ZW/dPQp5fnC1f2gaFPe37DFouZaaMyR9T5QwWCg41RNQIyk4yhZ4qxo1ju7iasrmvnGTRW0GAjPuaUnpAsukmCGWWf9cewdkf37bNJnYm9jTnk+1090k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786007500; c=relaxed/simple; bh=382YaSX9VKY57gg5Zc2yIAoHK5TXIXYZe3M5xBZpkn4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=nr77M+Nun2LOb6VowKE8nFd2L2OteMmEm6XFVI/3VsAY6g24Cd1cvzzvsRr7IKEpjFT5rRu219yTQQiZNVLx67WP3HxhcPNn09+qVF533pN3kPKl4P3eD7DIYuVf6WU6x/lpHtuR+F4uSMEDqCO2jEOdC1iauJDg3kOcLZhVfSA= 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=YTiesVAj; 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="YTiesVAj" Received: by mail-wm1-f48.google.com with SMTP id 5b1f17b1804b1-49802c418b5so18657125e9.1 for ; Thu, 06 Aug 2026 02:11:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1786007496; x=1786612296; 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=MvPkxu2M1aQJU5khje0h6+xkd+fbHQMlBQ/6GQVZV5w=; b=YTiesVAjxHtqmJmQIQFHLRfSiEAg0FhHVFoo5k1W6XJCE7k6yY6+UL1eN8O3BVQcuf Q2EIqu28hNYT31uDBj0KPLqBihY2/PjwZ1mi64pda2k08IUFGPoV9k181cMvoQFhc3NS SI+q5VpPzgoXCQYHQQ+NIFUv0wTckkxPacjHOBOfMV94sh4vu0c6LFNpyWw016oAy53+ CJANa1hskwIOWX5JKmekvE+k2J1p4/LTOMLZZsMRF+HNtEhq8/4J4twz9qgZjqdwpnAF lUebqI/chX7XBgFrUeIQFNyvqGH2uCdLM+1NQuXvxIlANVUpXwv6O1tEsa8rj281UmmA pDFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786007496; x=1786612296; 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=MvPkxu2M1aQJU5khje0h6+xkd+fbHQMlBQ/6GQVZV5w=; b=LeQNMB1lbtgjmZ1r3gqX8nSv0BtT5w3lu31gxVdaSqApCp5JYnyzDjveDAnEyatGZk YZRoOMLtsmHCa2IARdt0lK4OoguV0HhIFmXpa67AL4yCjqfwIfRN5RxZYet5u3+vjW1V 1F/rEC0eZkaj2OXfzeWxc0kSkU80Afh4NKyxz6KZTG5dOC3nXTiaNpoPHIuui4up3P1d IKQVRrZlCcwKfBF1s0iqDsLl5WPizCHnaevFdRNkP0SNBlBe4iZPf+E3A2rnF2itz5Xb 4jr3ALhaqwVvJW+Fv67c8Xm2q8vYh3wN8OmCYALTPuNHjkkLDM0ke5+NdQ7eKT/yXgM2 QCsA== X-Forwarded-Encrypted: i=1; AHgh+Rq8Gi8SMT72ZtvECEnT191EMbppuk/feg9R2lqLRwjbBOsrUoFMfFy+lmGUO1vpc9jeXhgYkJ7wq3On/IA=@vger.kernel.org X-Gm-Message-State: AOJu0YyZRpvcn3mFL0Ft67VZVw6/4dPw/NN8vfofa1Vp/Ohfiaq4/XSg 9bpq+xofcribZlbqYfvi9k8KKIipvSvpwtCrxCGLmsW4pxz28orb3OvU9x3mQbgAkN0= X-Gm-Gg: AR+sD12zaejBN5qlbPKnd8llJxnrOil32LijT/TtgR8lBut0o1yKfQNISy2dyh0jPMd 40vu3Rp78bgXxCjyY23UsNfHSMavyrFQWZW/LcAII4RZwdi7+LzL4RKYmWWgwRJW4HWYj3krpXx woWbdpimJoMkfUowuXVYGiFcujzeG72xvI8NNxa1InlcSAisTmOhh3t3CTtgUjikgVpQgPHL1LU aZw7gp3qAa99asAidOpwvs1Dgvi8K+aUNyllRVsJZtu+UlS0XDSuoJt8O4Tw2QU/nFc5ErGNxOo h98aGMs17q6itl2J+/cGXkT0Bmmph2BhTfXa0QGONNeTRgos4ZP/pP/DSOj8owb6hZ2WgpxJ3Xi cJE5Xn74nQTCIK/+vDN7198GiTBHnmFUE+fKaupOqjjJLDbZtQMjFBB0TFMOSHqeRAj8uGzfPxX CkfSsxxz3Z8lSLlp7C2EfcuVPAunlfjoJOLIBWHinQe1V7IyMV7uoDeb18dlx85Rf8gqE= X-Received: by 2002:a05:600c:1f86:b0:499:52ab:a50c with SMTP id 5b1f17b1804b1-49952aba5b3mr69266275e9.1.1786007496236; Thu, 06 Aug 2026 02:11:36 -0700 (PDT) Received: from zovi.suse.cz ([2001:af0:8000:1409:193:86:92:181]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4994e4c32e0sm93157095e9.0.2026.08.06.02.11.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Aug 2026 02:11:35 -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 v3 1/6] module/dups: Inform duplicate requests about the result directly Date: Thu, 6 Aug 2026 11:10:15 +0200 Message-ID: <20260806-module-stats-rcu-v3-1-2b0331106f00@suse.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260806-module-stats-rcu-v3-0-2b0331106f00@suse.com> References: <20260806-module-stats-rcu-v3-0-2b0331106f00@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 8b6f8f177de4..45080f451e5c 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 strscpy(new_kmod_req->name, 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.55.0 From nobody Fri Oct 2 02:30:17 2026 Received: from mail-wr1-f44.google.com (mail-wr1-f44.google.com [209.85.221.44]) (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 EDD3C42A15B for ; Thu, 6 Aug 2026 09:11:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786007500; cv=none; b=UX6n9nwOIbZ74n5QTUbS971/YxjNwy212qQmNTaYx81hZLNhG6Te6S82ozS1K+/aou8nGzfwxNuMKxiBpK8vQIQ85Wct3upcs2lPmys/29olzSTYSMEI+/v/AWBtQCSvuHyo76dN1B/D+fNwP9iKjOyfuTk2c57XSENGjL9HFEg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786007500; c=relaxed/simple; bh=NNlWVhX6UHTWMt1ZUwumPlXUWe3hnI6iCyPh4FiaA7M=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=QAxXUImCWyzLCVOqoqb8tVSP+5ui+JZdmkbsc9MAIRZjFdUm3MYzR5F1mhX3kaIBBrFF5JZYbHy+stqTeqOPQfFRH74ILbP+oVX7wTcd5qXxkHLCkUpqAqKZgdhm8fPCtBgCgNP88x7+T5+uFsrZFQc49CyxAdV3x7vm7QmBzyU= 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=GtzzSVKB; arc=none smtp.client-ip=209.85.221.44 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="GtzzSVKB" Received: by mail-wr1-f44.google.com with SMTP id ffacd0b85a97d-47f6609c657so954096f8f.2 for ; Thu, 06 Aug 2026 02:11:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1786007497; x=1786612297; 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=WuNiIa3LGK4xoLnPFwM4puJSPHXpLQhSt0boOdOltIw=; b=GtzzSVKBMq5xyWWH5TJuzT3SQ/3Mxy74yxRtraXougfkzEajl7JqwB6rmHofoQtq4y 5+roQOG3OZZMtHDMKpj2eccmQaotiSLneKLtHCuvJFKVHpz9je6/4Gypp7bO7bLtBSRx mQMxgT183m4SgQL2HCImLxZuwi1hpuGQ+zpP95Iaqkf7U1CubX9B5VxcjQBeyCcuOuKu UOs2s7K/jzRuR3eeu5kuH6tKbNYjNrQxnSOpxf7W4lmkHN71KzP4RuCy5OXn/gGG36AV uzUcBb1yUdIr+gSSMeKAqZZbDOFBbZWaRzf1td6HF+kCvlA6pGwf58G8uJu8AxAESR8+ vMeg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786007497; x=1786612297; 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=WuNiIa3LGK4xoLnPFwM4puJSPHXpLQhSt0boOdOltIw=; b=TX5rY5UxIFCuqunNRplHJSJQyUnUUF7K4+XdsnsmdaOp2mRli8denDEBbs/7V4oS2M 8wZPJAHPPPnEZ6B27wFwh3Eq++HzBqdvv6Dt4W7ADLvQeupLdBpzcZIMGcN0/XnuA117 oAFeEk4vpSij9qOSwFmMxQYikgLJwPqWe/N+UgFv+6oFbKnMsQTf7I5+79wFINXnWeuS vCe/5hC5olmijth7qxGacANhLOEdRlPY1O8y20puE0LWlKob8gwbPBkRnE8xmwCwZqcq Q/d5YP4AlqEAxgXXxe02VfE9DvR9hKB+Nc2LD+yWP+DlD9Po9ftmdGYnLx/OGVswBQiA TyZA== X-Forwarded-Encrypted: i=1; AHgh+Rr7bZC9xIs4vW79c1J796fanlYlLwm0/fsX9ptIftCCVrzEhh5kSoi+TIxXohiCXSOd/KepAEi1NLDIqzc=@vger.kernel.org X-Gm-Message-State: AOJu0YykaTmrA+sYoAH0vCGacEXsXSu1LTT/wMJ448DIN0PxnJYvVbfx JZVxpmPkESSMfoNIMVAkNAMI7JfKjUv46nTJEvpnGxJ/hrVpzh0OA2BCTs1E/832UrU= X-Gm-Gg: AR+sD11nnGOOy6x0tJunDiG5vfrVQbFQXjmlRRgeZD8YoNhlguSOdlVSaFrO15OSXR6 CpMz/ztshQ8FEgIDtCVwPBbq1AtKKF750BsRpm6zjAO7NiBsAiUoLLzDdQFCQAQtlVGmnDlMGtf ninjJW0sA/OFVbCtS3covQly9YzV7q93CVmM5aM+ltCIYDpfJTUUeb6CQSSQdJMs/TboKacBM50 mRSs6sfSlNS09Jwu55ZuyJUza7YhfGCg4BJ22R48mtd8UmBcx0AAxL/7LDtrxdJSIRNCoYoEpjd wAY26dfNYbCru7ZBYYLklk7ldIsNK0XSnjJiNYVhbUmGnxh5bjtzY7JDx7Eirt5D/eH0Bg/YfrC WUT6wkOtH2RYanEHNn1rRT41ffJruL8FDWpJCdZ5XomqNFsa6tbY2xbYL9sMAOJZsebquDEHUnO kFNEVplzHgG/Goi88NvDiICWV4P/mH+fbcckHOMaagdxvSYgMIL+UWPeKa X-Received: by 2002:a05:600c:8b55:b0:495:3de8:33a6 with SMTP id 5b1f17b1804b1-4994e7cdd39mr196760165e9.16.1786007497149; Thu, 06 Aug 2026 02:11:37 -0700 (PDT) Received: from zovi.suse.cz ([2001:af0:8000:1409:193:86:92:181]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4994e4c32e0sm93157095e9.0.2026.08.06.02.11.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Aug 2026 02:11:36 -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 v3 2/6] module/dups: Fix use-after-free in kmod_dup_req lifetime handling Date: Thu, 6 Aug 2026 11:10:16 +0200 Message-ID: <20260806-module-stats-rcu-v3-2-2b0331106f00@suse.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260806-module-stats-rcu-v3-0-2b0331106f00@suse.com> References: <20260806-module-stats-rcu-v3-0-2b0331106f00@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") Reviewed-by: Aaron Tomlin Signed-off-by: Petr Pavlu --- 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 45080f451e5c..db7377229703 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); strscpy(new_kmod_req->name, 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.55.0 From nobody Fri Oct 2 02:30:17 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 9FDA43D75AD for ; Thu, 6 Aug 2026 09:11:39 +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=1786007502; cv=none; b=ajmMlrR5W95/BKvvgvoKKCyMe0JezbwQcEmM+bU/ALFsmTNy/ncGO6F5u24em9woU8sO4Tkq4atm1UNHkmxcqSJkHRg++Abyp5X8rpbe0MUGo0DSP8+ic1w/F+8rQcPFtGLUtyVj4JhITv+PLGgx1UGLDBBgDmZpb6JiYj3B/vw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786007502; c=relaxed/simple; bh=gHYpCiquiPuzfw0VdPmWbBvz8c5AF5pIoFf55eZmMD4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=C4tZouPkIzFVSy6X8iyhZbDWQanIy/ortGowzMuQdpv9Em1UoNl8z4SEl7BD0e40k43NbNsfug0qh0xjdn9EI2zH87jdSC2620/+UolYmFgrL1SyNld6/yg0IwcHrMtNCuM1zaNsaN1dsqyoI4D6d3UcCgCxoOHWUU0xb/acXOU= 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=NWgxOukE; 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="NWgxOukE" Received: by mail-wm1-f45.google.com with SMTP id 5b1f17b1804b1-4954afac04bso21285375e9.0 for ; Thu, 06 Aug 2026 02:11:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1786007498; x=1786612298; 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=3W5Kt8XCRH1ookmt7hLyt3rKd0QiLjUKVXtnwwecrfM=; b=NWgxOukEZ1Ejp78fDnNzgkuS7IvVyzwY1PSZuVTGS0tAVP/+TXl4xN4cjsV7MXtDJf gnG5fHDYPxtpiu1laAnwUbktOZyb/iJ99cWx+v5cVCBWLGGhopmae6Day+cPTQQmv2Ul 3k5o9YhqzhHcocLbm3o6sJtf6DZ6DCid4z8U20foho0giNe/6VTP0gRdeSGFd+SmcoO9 nWHKfok3aM1rzGInHYh+gNfIR+ATQiDqgLt3TfCXcAJx9osKNgr1U+Ng941SLDOe7Tl9 qVeYb6tmUyWhwKHJitLLsIzta4WVl5o8GrK1f+OFAauPK1qRRLO2BXCMrxGE5QwyWoKk Pv9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786007498; x=1786612298; 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=3W5Kt8XCRH1ookmt7hLyt3rKd0QiLjUKVXtnwwecrfM=; b=LOY/W9wTOzn8A01qnuRh+hCmPtvYSN2U9WHRc1iKfUR6HcKFWNHY+SaEeBZKJuZ77V x2DcZjQVJrS4nEn7a7TAoAapdFCLnS02ABTpF8gW5NpBUy4iWGchjR8sVBrj7vwcieyG ZiPsYPfzHtAZSeTIs0444ntIeYkeeFp9uFmTIBsP5aLyOGvWdHbKhQYiR5KSxyNNDgR0 PdsK/O+GkeCWh4hTR8l8d7OiLWOF5TQnR++H7eEM0W1t3513ildWCdNf2SWNBrJqS4kM NXnEuEcTukRR78+MCGmjtVIY7dN6uOLOFv4+LxgYb6YiOxxbhngCK3W+iI21XXXpFey0 Mc1g== X-Forwarded-Encrypted: i=1; AHgh+RqU1EoCTDa6GGfmfTXphraeCVYghhofp3/dHLTq9kcigwL3hI8FY7ARp6cpi3reVUzFUv2msx0nNXFHlMc=@vger.kernel.org X-Gm-Message-State: AOJu0YzM2+IQ1bPJ7H2cnhvH465ojdkAajS9mHXdVn/cbIo8UB+S6ZML WJTyFr5X5o5gqv9UzoLY2AMbtfsVatYYAlLRdMia2RwzJBS/WkCOO+hsyvy4ZAxr3AY= X-Gm-Gg: AR+sD12nHVeZC6rzebAkVBm8Tkr2iq8boJQtHeI4kht+5SnzrVe7MgAuZFft/VCftDs P7z3SFe3JUPdyCMLrQcfCpyIn1LOIWV2Ld6yNno3vK4c/3Ozo6aymOQXQ6rmwSSoxhsGac750yP REmgp8mzP8pB6L1FeTwcygIRWa6EvVr1nBd5zd2JbyfDfvgtai6h3CwO9ZheGxqJ9UZl4StCHvt upV5SvEmuflEcovbZO+LDTTnSbVN2yDFLk5MZYkyNf1rXCBd/daW/tFTyMc/lGsFwgQNnMnR7uQ Bl00MPAv3CeBExQhaf3VVSt4r9OXZd0E9U9NCUc/aZdkn0UnLCVZ7jPfgjgmMn5D06+x5AHb6F2 dwm0XHWJmK7E0eVhH5WqPyg0/P4XSMGskBGf47N+PtavdY2AmViAKkFLyrBdumWoTgCHvLBRfqX meQ/wxKNT/72zGGAoR3Fezo02MDZJvcLhofBMG6rqPG9O2IUJWnIEdwFeY X-Received: by 2002:a05:600c:354c:b0:499:51cc:4e57 with SMTP id 5b1f17b1804b1-49951cc6d0fmr109929275e9.0.1786007497764; Thu, 06 Aug 2026 02:11:37 -0700 (PDT) Received: from zovi.suse.cz ([2001:af0:8000:1409:193:86:92:181]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4994e4c32e0sm93157095e9.0.2026.08.06.02.11.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Aug 2026 02:11:37 -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 v3 3/6] module/dups: Avoid unnecessary kmod_dup_req allocations Date: Thu, 6 Aug 2026 11:10:17 +0200 Message-ID: <20260806-module-stats-rcu-v3-3-2b0331106f00@suse.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260806-module-stats-rcu-v3-0-2b0331106f00@suse.com> References: <20260806-module-stats-rcu-v3-0-2b0331106f00@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. Reviewed-by: Aaron Tomlin Signed-off-by: Petr Pavlu --- 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 db7377229703..276016051ad2 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); - strscpy(new_kmod_req->name, 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); + strscpy(kmod_req->name, 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.55.0 From nobody Fri Oct 2 02:30:17 2026 Received: from mail-wr1-f53.google.com (mail-wr1-f53.google.com [209.85.221.53]) (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 3DBF042BEA1 for ; Thu, 6 Aug 2026 09:11:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786007502; cv=none; b=Jsur6qg+nt67MiebQx2SOuuXjFgyhQ2DGo9PFgFBEQFehbuCPqNlimKEF8i5R5CixVpN4wLAptC/On3Q9GJH87/bxpzU34eu9GAIevlz3i19i1EYy08v72bnz35SM9e9B3aV6OukugyBUU0bXq84YGSbkZm7izjG8nzeybb/UI4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786007502; c=relaxed/simple; bh=Ly3WGL0NRbv56WJAVHhtg4aP/+9+drkqV8QUgw2N0Do=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=qaANpmpMSo4W4SPzBxPzqKnZqxz4SxywAsN17TExjbF5qY50rjb4LH+6o91pL387nKAjwJlNbWKWHc39gzGlJL3Tp4+xgdytsrmnFzrFiJv2UmXBY17p2CForLRlfwI3yNENgHqzPSKheb2oFhzrPepHq7IiFVympjwxpnmnGlo= 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=G73Xd4id; arc=none smtp.client-ip=209.85.221.53 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="G73Xd4id" Received: by mail-wr1-f53.google.com with SMTP id ffacd0b85a97d-47f64ca1c2dso590386f8f.2 for ; Thu, 06 Aug 2026 02:11:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1786007498; x=1786612298; 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=32xW9g5rJC+CATbvSQw32IJJxOMsB4uIKy11LiTDmdY=; b=G73Xd4idz/v5aSoAin/9RCCBs+2hwxBDbgs2uikyqPBk1Ath8DQjcGp4chdoshiA4s HNZynUWrhmm+83dSwPI5fZgdxGmzZyLCTWvzR1eru5bTGTP5HMnppU9TFOAv5yROrXqs ndMZUH2UW2bx4UCfopWzzo4rNIYMdVtqVH4ih6rPNmNtw8kqt0Eanx0vIQ3naIGABEFU o6NDHIWn8QbuOvWeYPffsq5xijnryJuAAiHMKlJrCwWz6/rEl7LzZ6fFEfteRc70X6u6 F8F73mmJ3VEExYd1sPG3GCTd+V1ch0ezizjCli1J0ZURhBUUnc5eHbg4UA/ca4A3mUaZ ojdA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786007498; x=1786612298; 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=32xW9g5rJC+CATbvSQw32IJJxOMsB4uIKy11LiTDmdY=; b=ac7IlnNbSe8HKwX9ik6zpB7367DcYhxSP545NLSTMjbTWXwbcZ+YzHbWzcNeemMT99 iI+AOYf47ZdmwT5GOTXbrVbw/PWeReuv0E/P5iP8vIzwlbZEzsSizR/csa0qjPkDedHi 4Y7TsJndvHRt5LVwVKWOShND97gfcodBd1/jY08sYPmQ5bIwg+tbwrr8qw0hN7BP+k/7 gg89yqVNEUJT70sjFm0GEnmQR38C+EUazTLoJ7B0iUtz28QAHhgXgFo1gRqacM+vTM6C yrPK/magigJH2YpXYKJMjbzOPTz+Da4qyIxDLT8R5mWBTasXPdHgteWVdHSengi4VP+P 0CHQ== X-Forwarded-Encrypted: i=1; AHgh+RqSndDMvvJgG7OUayNrS5RnoIhOxJ651/dP9MK/Ah2p2qga84UvGDPLPSA599feHMUvh7DZ7sN4WBRBLh0=@vger.kernel.org X-Gm-Message-State: AOJu0Yx3UthTMKMzyWNiu50DIrVw9LaaPzKVNBWgv4PbxeZOOnpVq/CI emQy28dL1qj2C5GgwGxUL1K0C+JzQgR7xefIPFk0ENW3jb4cav5ilNpRK2bHGgCjMVg= X-Gm-Gg: AR+sD12gJN7k71xH6n3Y+w3fxwDeuyX8IcNQnoCg0qBE30mthTYkbBk88k2OfRyNXlL UtPMZA46ihFZjUIym2uNdk4Han5gLRUNahlcqCCb+n5uae9BYgLRDJ0i/1PxDQDNA9Xnfci17Y0 +qzP0mupj2T2Oz44JXb4g/GgMYhOwtjpV/c/pEckwtTmu5WYuqreB1HRNkPKDyuLcXwPEbZYwFz ZspCAwU9zdoHszShS5guFFnb4ReAud8y3QsXS1/CSJlM8Lym03Of0NoExdJGngXycMTnYhHSSqj F/keQqJFeZdkHQFZK0By5Csa2L3lydkTzGx10tqIVB6HjhNYaD6vqUChzVQzET9Ge/Vj3KQQrNd zVUbJUu2pAH7HfHpIdkxg7QkQudKOI/p7F9+xxjs8Jm2TNAfs8q2/o6FcbSTZK6hpYMfK6n8PgI 0Rfo1SsXPWPRgXP7N1Kv0lr1/ccouD4qbz0060ohRrjnj3XTBu9k1VuLmXfaL74P5R+HpU X-Received: by 2002:a05:600c:840f:b0:496:bffb:fb7b with SMTP id 5b1f17b1804b1-4994e7c0446mr161352615e9.10.1786007498371; Thu, 06 Aug 2026 02:11:38 -0700 (PDT) Received: from zovi.suse.cz ([2001:af0:8000:1409:193:86:92:181]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4994e4c32e0sm93157095e9.0.2026.08.06.02.11.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Aug 2026 02:11:38 -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 v3 4/6] module/dups: Use scope-based cleanup helpers Date: Thu, 6 Aug 2026 11:10:18 +0200 Message-ID: <20260806-module-stats-rcu-v3-4-2b0331106f00@suse.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260806-module-stats-rcu-v3-0-2b0331106f00@suse.com> References: <20260806-module-stats-rcu-v3-0-2b0331106f00@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 276016051ad2..201a7f4c151f 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.55.0 From nobody Fri Oct 2 02:30:17 2026 Received: from mail-wm1-f47.google.com (mail-wm1-f47.google.com [209.85.128.47]) (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 3C94142AF97 for ; Thu, 6 Aug 2026 09:11:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786007503; cv=none; b=ZX7f1cu0+opcg9E7rCw74P0mwimY5mRIqbUPRC+8Chkuw6kjV7pOk6Xl8mTYcB2EPFoYJOrlIq2qfBPMtTxhKCH5cZeGbp+HSW2ZlUY1Hxq+xiCjYXl61UdXhHzhHbvC/u+8Y2uon893MwzvO20EdFFl1yBbYAzy+UJZQDefT0Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786007503; c=relaxed/simple; bh=uItlWXb8MPOhAwOvNC2QGMkec4Tf49Sn3KyLOnrdPe0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=L6NuK28gjNqtswT45EJpzCb/CqfI/uF5LuOgnZsbQFDajtFkMYvZLm8W1v1o4P2z49CYXQPrpbqkjM/aueY3Hx0tGA2VMF+PEBpN3iRBjK2RRKb2gGB6xC3wVpcYAN2tytHcWI6hfMKT41cuQ0rrXWAxzavpHeDTd8YQriuw4eI= 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=XCPX8c64; arc=none smtp.client-ip=209.85.128.47 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="XCPX8c64" Received: by mail-wm1-f47.google.com with SMTP id 5b1f17b1804b1-495757ccbc1so20493055e9.2 for ; Thu, 06 Aug 2026 02:11:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1786007499; x=1786612299; 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=ctVxRTZld6mMfNeZZIDIMzyUTqfRuvudSqrKgHW0waM=; b=XCPX8c64SM5ZN3DxBegcSa0M+Ptke3o2E8De+TayD7zB1+CkzNRz47cXPNX3Xjr5NE OYsWV3oB48TJyCq5QuTTse0SzlrSXqtmiLi9pKyP5XrS4ZUeqlez1E45fcrjsbcacAvv P4x8FoVxcYaSWbI3djkdOu4PtIIZXMXPihq6G+s4CsIEbAMrLwnErdPw8w0TxrdNp+QF WHtdQFtY0hqi84lwU+H5UDRbqb8CFoAJccxvv49WS7DvX8iL53w+gqyHAIDcCuQe7XlF Is+7AsAl5oZuGBzvKleW9aRTxrYQRxo6UN3aYQN8yHsEfuJ2DnfzHY791KtTmuf61I93 hRLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786007499; x=1786612299; 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=ctVxRTZld6mMfNeZZIDIMzyUTqfRuvudSqrKgHW0waM=; b=Hek+opL60u7HrNmHE2F84jBb7l0XkGaFjN2TkRCv35sC/gdRHJRwl+rI5tu/a1HSNv VpE5fQHR1EUaAQPkXQbhn3ilOQp1yd5SD47vtVHb6NVZJuKbTsNhpQdCi5pp0jifvU2d V6r3SAxzn3EYWlOkkyogRYcVrTKCoTYNnmz8C2lhNO3dF38BHtOEXxJ2Wy+ufJa0Chj9 3UthMF33Np+v8uZluI+tIb1oCOiBEJ5tj9wZkB0a+YGEGDlljras6kzyZfrU+OBCgHdw 8SpMwBlWovH4ha8jKlIdsf/WWozRl5FNUjVtLvXAHDRQGmgb35COlPcGHEvjjupHvxGl E4cQ== X-Forwarded-Encrypted: i=1; AHgh+RoUIu964hWHDwIa1pyHFdtWOQZv7n8j7ppN+2KB8Hl0cVM6ldqbTWVEeuGVzrLIQYLZLrlnsu64cytvJEA=@vger.kernel.org X-Gm-Message-State: AOJu0YyrubglQ5uYafii8yoRvVUG8+V2gQ7tNsmlFyN+rEAXjREErM16 6Dm1Nb3KKU4BbjMXD0IIZKcMfARZ5rYZA/S6bdc1oQDn8LuyVBGHv4Q5xM6n1iFPnaU= X-Gm-Gg: AR+sD101EDlawM5luPe6YkuYEVwQh7sNmAuluk+3/1Di02tzux8gafddvHXRWq6KAzp 2JdujHqBH1KwlS01Go7PMnvh0k4lAPKnzo2HSthcdQBMtfVFmilqQm0UXwy1YeM5QWKWloH2qEW 0KhuniopT5FQgzBD8FLAIkyVlgY6uESWpKT1aF/wwFlHPBfx9glGt96pNhgSQWSLqx5xuyD+wiv MhXyV2Ev06O2zvVuK7A6gGF/AEjuI/jS5MUYe9Y+7mLD17/UDt0yS+g7xYji98Iskqyk6XUnLiY kWpCMWRuLWBRTWIa1+D3MkpvVNvRl2y32Gfjr+F3xi4pYk5HXmVQy/DG8FVvPu6y7Z0HgrLSgcn rSDcJDFA3K0JQoi5n1AxLAgmg2ISSgEjpnd+kWLPRvamgXyx+PRYeJJm0x7QvrhRsE3oC5p4YTG HyWmN+v38np8cD/3XZwBSEjSOD5N5yCPCmvvwszyCK49fzMk2pUVZMxlqZ X-Received: by 2002:a05:600c:4514:b0:496:bbce:f3 with SMTP id 5b1f17b1804b1-4994e71ed7bmr166617635e9.6.1786007499010; Thu, 06 Aug 2026 02:11:39 -0700 (PDT) Received: from zovi.suse.cz ([2001:af0:8000:1409:193:86:92:181]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4994e4c32e0sm93157095e9.0.2026.08.06.02.11.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Aug 2026 02:11:38 -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 v3 5/6] module/dups: Use strcmp() to compare module names Date: Thu, 6 Aug 2026 11:10:19 +0200 Message-ID: <20260806-module-stats-rcu-v3-5-2b0331106f00@suse.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260806-module-stats-rcu-v3-0-2b0331106f00@suse.com> References: <20260806-module-stats-rcu-v3-0-2b0331106f00@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. Reviewed-by: Aaron Tomlin 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 201a7f4c151f..fa3a4e623543 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.55.0 From nobody Fri Oct 2 02:30:17 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 2DFA942CAF5 for ; Thu, 6 Aug 2026 09:11:41 +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=1786007505; cv=none; b=ozQyod1y/FF0fGCC0bI3dX3P79P/xnGlKqzWs/XKCToToWNz3pMm2f1iO/uZEM9K0WvCy5mZJ8ihN4zPLygmLwgMTfo/PEIouhgLwJRVTGOVCMjSGES0M/Q/rm/C2C2tVJZ46y//+PbQUkCQnoQYVheiVIPFsXjdO0s8YuzrzpU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786007505; c=relaxed/simple; bh=8QZMv6e8VZWNSTLr+L7myB6tWqGtrtUDOO5QTM4uNAc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Wtf+yZmEQcmxgIfNtZEfTXucLgG7V6u9UbDcetbcL6C5JpuZTXMRXh7Ry1QP6B7xAIJ/vE/aLlyN8d0e5llJA+qKaye4CLUbUnHzvJT05f6eUxN/DyQuuddCTJ53XDs4YelziA2xSQRntqMjEvRnmCksygOwEZb4QgzJpyQNZ20= 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=dlQUf9Qv; 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="dlQUf9Qv" Received: by mail-wm1-f48.google.com with SMTP id 5b1f17b1804b1-4954aff6088so19520955e9.3 for ; Thu, 06 Aug 2026 02:11:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1786007500; x=1786612300; 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=a05UMz3w4bXA+1T0LMtqVZav3+vL6BphXj7PWM3R9OM=; b=dlQUf9QvktP2lXiJDddwFHp/haTf2Oc1BI6vDnYU6MIpREJeO1AaWaJpzMSYKEyd6m 5YytYUlTY48NOFqm8LsubJqmYvoLwnNPKjcQcSR06a/+YBAaUqW8uqv/b7XJnOksocIo EbjH14pyFSNtLQMnSpEVk/pYu0ank/cN2rmfUL7gl+6Cf7a43CSh+tE/jXwwYg7TMS7V TpM4zuQyjve4TYYn57t8BDmYAItFUzAXJ3SVv+JW4bqB2srEmU2D3OSEneOvcyQKEAMV nhoeNpagODSwTGK0qGcir7Y7355xnrmKNKTtltFTUN+DsfxN3Gs2WkELU86C+rw+d4Sn ePJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786007500; x=1786612300; 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=a05UMz3w4bXA+1T0LMtqVZav3+vL6BphXj7PWM3R9OM=; b=D/yYo/wRAL0gq9fTnJx6nTAQIfgdfS5FJVecvt9qUaVI9xob51atKg+G6pQUVjU7Aq KEwQ5lE5qd037NzQPODUvKEFXrcfoTqMPlFifUv/mw/wGUAsrYynL6yEk28ZUnbWmVkt GBb3B6CIZjQt0osf4wyPTNX7K60c+9Z3eukq8qTZm/XIktJKGk5ae2vbJwZQJBv1kjrl l5gQSMEUwT15zUYafjeEUAb5xDGAT1sPQDjuxP2FWqhRD3lV/hl0bqGRTFJJQ6BrjGil WUzayNwbD0cWOtx/AlVS/s1GVm127cEcDH5HQwMeDtoRULue8AmgfykVS4qu4JJGE6k8 PjSA== X-Forwarded-Encrypted: i=1; AHgh+RqesWocbM76Z/kX4arkozNagNEaNx+H8ZPnClwD5s98FkJh2Kqj/4TIQZqsvtqsNCMSyTi9VwtafNdlYyQ=@vger.kernel.org X-Gm-Message-State: AOJu0YzStMAnk7FePux5d9jBfCtXyDUWJjYC1zRuxokGY8aAMUiNRx3l TF0FzKtp7IJO4F1SMF1zFCDlm+FdamHGCTEeTjtguOXKMApF9olBNA7ZbgQEWjLVKwM= X-Gm-Gg: AR+sD13M31FfFaNl1U3LPAnzAGYgcURFBBcBoSxBtuj3tRLySjNgbP/PrscrUoOgDyH 9F4j009qzk+sKFcBWBoY9wBdfZd8Aucpeoa+xkgLyouANEcRduuzP1peAx+YJC/cUes4eIIiOzz vnXdPVagaAtbBHNbjYlt1/MysJhyyKV3s+mqZanv1uXSBJxadLkDa99ZnfTOyDPLyJn04ZBa0ed erIG5UgaY91jqb24jBnkkE9rIeZaQgJoinr+ivLkJHLVH6xIyMbnmiag/68nzXMSo9c442jHM0p X7kzWU9bQ0A9b9oM9u5GpZPAOG+wVzf0RC7xPPXkV6JFlxnwppxRjobtzZA1eeYLZU4Eyg1q/pR ympRURHdaUyP+w+koNi3dAgaK/N54Kh19BK+hOIT6D7eI3TpJdjBTRz6Gsn56FSpBm8iNjcb1hL ouyCKe9kKTKtS8HJSNibTUUmcnj1xguSV5hRSFAAYnb0sfne1LmzQ5RxJA X-Received: by 2002:a05:600c:c8c:b0:496:c18c:f9a3 with SMTP id 5b1f17b1804b1-4994e79dc76mr151198445e9.5.1786007500018; Thu, 06 Aug 2026 02:11:40 -0700 (PDT) Received: from zovi.suse.cz ([2001:af0:8000:1409:193:86:92:181]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4994e4c32e0sm93157095e9.0.2026.08.06.02.11.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Aug 2026 02:11:39 -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 v3 6/6] module/dups: Clean up includes Date: Thu, 6 Aug 2026 11:10:20 +0200 Message-ID: <20260806-module-stats-rcu-v3-6-2b0331106f00@suse.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260806-module-stats-rcu-v3-0-2b0331106f00@suse.com> References: <20260806-module-stats-rcu-v3-0-2b0331106f00@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 fa3a4e623543..c9be9df6a65d 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.55.0