Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp23002973rwd; Fri, 30 Jun 2023 16:18:00 -0700 (PDT) X-Google-Smtp-Source: APBJJlEE8QXnRECwX6Rx5lLkJlglYQEdGB74I/1IgCWZfzh4ZMC64XDlG3aJ4Ch5APmuIg1PWQjC X-Received: by 2002:a17:90a:3486:b0:25e:ad19:5f46 with SMTP id p6-20020a17090a348600b0025ead195f46mr2884493pjb.12.1688167080414; Fri, 30 Jun 2023 16:18:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688167080; cv=none; d=google.com; s=arc-20160816; b=nmrtm0ayBoJLFufXkdrtR+P/IGiZp07NylQBXofkBENyyiYa79j9BFI/h+wp1IzAUK g+RFV+DztowHNZsq4P6GHFhRxYhZmtOkSHvZCSbsoanecXcQbjQuAmopvGJZjRgAd2me QhOw51V5kS0/iacvXsxoFhHTIEh6HJmlhlhwyoZo7Ik9ts7r6atBV9h+D8sZI5HYCZvc PyI8980hbLii97OOY4sOlM2IcRUuLCKgU6wkUeTxXU0PC5AJYJG2EFe2DBxpT8qeRzfy ZvU0YgrtfZpNE1c7K2r47P4BANhZ++XMbn7RZ5P8amZKDaNF88RKZBhKGnSmMsC7E5RC 1JtA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=DtSZxw7+4s6UShYin9vBrjN/t0Voj99AVUvFJAAOEQg=; fh=N4JORZ3oCxNksiSWdNZPt4E6B2+8lYFjD2kfUZPrY8A=; b=WCHpP2Un/oPOLymr4oqVuQTh2d0mDi6jufYJ2Jlz8E5R3a0lbY0iIAPRLVbvHo63ss mvwIifUXUiH7ZcR/07/blPgLPYNhA+FhmeATR06MtLf3bCP9ZL84hQ5Ix+XwWlU83WpC 7ENzdXZ+YJVsDlWxhuSo7hDU3VwQZdtZz/Mvqk4C5dD9wyKlork7p/jN6yZ1T71SQwNW Y5cQMUg692UBHTMU+eB0ZemFGChRf33r9uEqmvrLk3VOhVLi7hFWujpAIsh/we9VNPW0 Ttyd5tR93diRFgDr1onsnjYB3va8Y3M8raMyagubCSnSkYRGf6JlygCwFuLrsz3n79Ld kgJw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b="4Q/Qg6rZ"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y13-20020a17090aca8d00b002639acf55c7si498122pjt.7.2023.06.30.16.17.45; Fri, 30 Jun 2023 16:18:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b="4Q/Qg6rZ"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231810AbjF3XFi (ORCPT + 99 others); Fri, 30 Jun 2023 19:05:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33764 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229484AbjF3XFh (ORCPT ); Fri, 30 Jun 2023 19:05:37 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1F4C12D60; Fri, 30 Jun 2023 16:05:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Sender:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=DtSZxw7+4s6UShYin9vBrjN/t0Voj99AVUvFJAAOEQg=; b=4Q/Qg6rZ+3w8f7fm5+6U2acLh1 74nDEcRKAVFvcECGa8s7Uy4oOh4ZQyJn7U87AIzb9C/jwDQ+l89QwtHLuqVd1yE6p0JDhOAloQhDX wfDmnSy/N6NOnj7S76vOIHB3VSxDTQ8Go73vT9ozuT3s7hOShGslw5rOpZApBOrDikjJRLDxXEnVQ WY+NwyfOwvIajKLq3itECbaBCI/KTU2+UrXqMfTXGTKeCkkXAtfbsI6cRcj5BYv503O2wL4aFI5nY hM/R2OppsVjvqBAjiS4vvfkDRuG9ax4M8D41sq7UXsY7xVCD+gjAyAapTdhXPWuIvYCSVtzRUj1oh 6AV8y2cQ==; Received: from mcgrof by bombadil.infradead.org with local (Exim 4.96 #2 (Red Hat Linux)) id 1qFNBF-004jS0-1J; Fri, 30 Jun 2023 23:05:33 +0000 Date: Fri, 30 Jun 2023 16:05:33 -0700 From: Luis Chamberlain To: Jean Delvare Cc: Michal Hocko , linux-modules@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] module: print module name on refcount error Message-ID: References: <20230626123252.73dbc139@endymion.delvare> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230626123252.73dbc139@endymion.delvare> Sender: Luis Chamberlain X-Spam-Status: No, score=-4.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jun 26, 2023 at 12:32:52PM +0200, Jean Delvare wrote: > If module_put() triggers a refcount error, include the culprit > module name in the warning message, to easy further investigation of > the issue. > > Signed-off-by: Jean Delvare > Suggested-by: Michal Hocko > Cc: Luis Chamberlain > --- > kernel/module/main.c | 4 +++- > 1 file changed, 3 insertions(+), 1 deletion(-) > > --- linux-6.3.orig/kernel/module/main.c > +++ linux-6.3/kernel/module/main.c > @@ -850,7 +850,9 @@ void module_put(struct module *module) > if (module) { > preempt_disable(); > ret = atomic_dec_if_positive(&module->refcnt); > - WARN_ON(ret < 0); /* Failed to put refcount */ > + WARN(ret < 0, > + KERN_WARNING "Failed to put refcount for module %s\n", > + module->name); > trace_module_put(module, _RET_IP_); > preempt_enable(); > } > The mod struct ends up actually being allocated, we first read the ELF passed by userspace and we end up allocating space for struct module when reading the ELF section ".gnu.linkonce.this_module". We cache the ELF section index in info->index.mod, we finally copy the module into the allocated space with move_module(). In linux-next code this is much more clear now. What prevents us from racing to free the module and thus invalidating the name? For instance the system call to delete_module() could hammer and so have tons of threads racing try_stop_module(), eventually one of them could win and free_module() would kick in gear. What prevents code from racing the free with a random module_put() called by some other piece of code? I realize this may implicate even the existing code seems racy. Luis