Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp2496515pxv; Sat, 3 Jul 2021 10:30:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxqYS0uK16eoxYB4TvnlMTC6kpNzVzMsxlfwIpD84vM3SdWTK7/N4BTkF63fizyaAEqleca X-Received: by 2002:a17:907:6092:: with SMTP id ht18mr3565183ejc.223.1625333459765; Sat, 03 Jul 2021 10:30:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625333459; cv=none; d=google.com; s=arc-20160816; b=nP4i8MjKwN3cpcxy0MA9Uo1WsDXnWGI+Z0UD8vmh+DGElpBLWLAi99ls3sxU7qta1u LuEsM2w4GmZ8dINn3Z623HOIWs1kdbi2WRGIXnKuyN5Xk+Ok0uubuuAGUgEV8Y+/DDnX tEEuolZcaeOhg4EHKiDgZiUfgGJegpAQiMQMsewaStitHugJcuN1llNXtWJYMSeJJQw4 NzSgdRdPf5hNsvsj/L2m4n0nyIMRz20/3SExfYhraRKrmy8aEEUFHMbL2FmgTTUrQXgM imPikjOcTl4ReFMrYeMVGY/b3Q5RKYLyITORHX1FFFUHfyuljIaUiQR5RvB/Jd8zQjio Fkrw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=7sn0DaF0wG+Fr83pUGydCXmzXu/QrmNbieyqr+LtNIk=; b=CDLUog9xIGDNQF+4AXMkCsUg1iwyfdoD3u+lafdkz+ZlKdK0ZKuAjLo2+tGpC/HcIJ poD0XRAzXnfq+Hf5dNS7NLRNWQvllfcFPk5sjRJv+Yn8/JxJ1UJ+V6eVfLsMyk/9XzWK LC42cFbSE1d2DBrU1TTb81sEX6VZycQc4Bf5oc4PlmZH16TMeNPUlLkLEL/HM2u5b97n ja7oyfAm3XevHgGJ5wxcht/dd3AzaCWqFdAaQ/+OKApZNUoQNmnR4nPXDc+oGW/yEzR9 HCsN5CLOrNVWSHbC0PAVn/VQRQYyzqw0XbtmDwW1ZH4azr7VwQci+4/LIZxX0biuy3Is dJCA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ec4si6430100ejb.244.2021.07.03.10.30.36; Sat, 03 Jul 2021 10:30:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S229781AbhGCRbJ (ORCPT + 99 others); Sat, 3 Jul 2021 13:31:09 -0400 Received: from mail-pf1-f180.google.com ([209.85.210.180]:35700 "EHLO mail-pf1-f180.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229463AbhGCRbI (ORCPT ); Sat, 3 Jul 2021 13:31:08 -0400 Received: by mail-pf1-f180.google.com with SMTP id d12so12297404pfj.2; Sat, 03 Jul 2021 10:28:33 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=7sn0DaF0wG+Fr83pUGydCXmzXu/QrmNbieyqr+LtNIk=; b=BCCPtNJ0r9rUm6ZIN2VuSfi7nmPHYezpyhMUnAXf6S9t3LDmvPgSqLMxq/JMRAA9F8 p9woqOOP4p1QMur3fxX55F46f9aWK6WpjH+zzCoK19Vp0PSkep3Ov8cxHv7RFbVBVQI5 8O2AF3C7o4eFq2T7e8+yLuYzolQNin0SKR2nQpVmusv2frVoggKKHecyZ4ooo4deUk6k w84nheywT8JAwTtNqBLlhIBS6OWhpaCD1ocDUyTfTMXxhEpdSqK+ZizzdMC27xuQvlrI jJdrVOlKNkOSIbxKx+K/atPlXMh6OFbAkhzayBKtdWHzxdqbL/q/ULZ//vLlQXgV+MLv AKMg== X-Gm-Message-State: AOAM532uTAE9VTc3ipjHrCakhf4s8xBho85X9nF/m6G75Zc5ZcvhfwMh mFw5kWEmy8Hke+L0EKEl1AE= X-Received: by 2002:a65:4985:: with SMTP id r5mr6198260pgs.122.1625333313358; Sat, 03 Jul 2021 10:28:33 -0700 (PDT) Received: from garbanzo ([191.96.121.144]) by smtp.gmail.com with ESMTPSA id z9sm7321452pfa.2.2021.07.03.10.28.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 03 Jul 2021 10:28:32 -0700 (PDT) Date: Sat, 3 Jul 2021 10:28:28 -0700 From: Luis Chamberlain To: Greg KH Cc: tj@kernel.org, shuah@kernel.org, akpm@linux-foundation.org, rafael@kernel.org, davem@davemloft.net, kuba@kernel.org, ast@kernel.org, andriin@fb.com, daniel@iogearbox.net, atenart@kernel.org, alobakin@pm.me, weiwan@google.com, ap420073@gmail.com, jeyu@kernel.org, ngupta@vflare.org, sergey.senozhatsky.work@gmail.com, minchan@kernel.org, axboe@kernel.dk, mbenes@suse.com, jpoimboe@redhat.com, tglx@linutronix.de, keescook@chromium.org, jikos@kernel.org, rostedt@goodmis.org, peterz@infradead.org, linux-block@vger.kernel.org, netdev@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 4/4] test_sysfs: demonstrate deadlock fix Message-ID: <20210703172828.jphifwobf3syirzi@garbanzo> References: <20210703004632.621662-1-mcgrof@kernel.org> <20210703004632.621662-5-mcgrof@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Jul 03, 2021 at 06:49:46AM +0200, Greg KH wrote: > On Fri, Jul 02, 2021 at 05:46:32PM -0700, Luis Chamberlain wrote: > > +#define MODULE_DEVICE_ATTR_FUNC_STORE(_name) \ > > +static ssize_t module_ ## _name ## _store(struct device *dev, \ > > + struct device_attribute *attr, \ > > + const char *buf, size_t len) \ > > +{ \ > > + ssize_t __ret; \ > > + if (!try_module_get(THIS_MODULE)) \ > > + return -ENODEV; \ > > + __ret = _name ## _store(dev, attr, buf, len); \ > > + module_put(THIS_MODULE); \ > > + return __ret; \ > > +} > > As I have pointed out before, doing try_module_get(THIS_MODULE) is racy > and should not be added back to the kernel tree. We got rid of many > instances of this "bad pattern" over the years, please do not encourage > it to be added back as others will somehow think that it correct code. It is noted this is used in lieu of any agreed upon solution to *demonstrate* how this at least does fix it. In this case (and in the generic solution I also had suggested for kernfs a while ago), if the try fails, we give up. If it succeeds, we now know we can rely on the device pointer. If the refcount succeeds, can the module still not be present? Is try_module_get() racy in that way? In what way is it racy and where is this documented? Do we have a selftest to prove the race? Luis