Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp1122044pxv; Thu, 1 Jul 2021 18:05:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy5+p/4COAET8P8zQyBO1FCxqR5xIM5PVuEDCaGvJAqPz/R7US5H73zmvO0VX3+8s0ME0jG X-Received: by 2002:a92:c846:: with SMTP id b6mr138134ilq.170.1625187941703; Thu, 01 Jul 2021 18:05:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625187941; cv=none; d=google.com; s=arc-20160816; b=pCu/nr+H6OUGuJUpG3GUVcNFfIt3MInUja2zQNayR01Ipj0UEMO+lqrgBP13uCZIHD f7HvGPOloVnWeT4tghnlZkWJp+mUvZDYbP2Am/ShnKT1tHeTWUlHX6QWUel1gxiu4u2a IE9V5fvrX+OicBgL5nlVwqytYmZYKwkNY5wjOIszQNEnBSPG+VbcM4LexYD/g0sggQXF YMqg5efXm3JWnc+86ruvgNa+OuDgfJUNwuH7RVpvaL1A7NTFlklz5qJKUzNmISlZbXrf am3tUmgopF81eoskvCX0rlqmvHwseJl5RAC5bHLGPgXh3FmCjt0B+tnOIREIN2eJlUau S+JQ== 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=eaR++vjtiNX6DzHjutKmZUMGyUp8898EKANyRVFBEw0=; b=Dax7SXfyn38WCi5J6HPz3BdIRVrONxeRn+yuowvyurgU+43aXCO4dk7KbXSpZ18/jM FL7Boh7anjrWF7/35zugve0Vn0ixSyYYgHzfLYOHiuolE1cRINLsJ8TL83rvIf1wl0SI jcu23J2NHl9ET2x3dbHrl5Fug7ih5r92bm40BlZ2a3xupKdwTrjySohLASkWa6GWu9aJ clK8PFfhoaoHcHzhKKDAxdFroH7qi0l9w61gHxtTa0ROP/pAJ+AL9KaAlq4XD0G1aCAQ gA7U/+6a+lDUHrTXz6PnZ+xRBtrdrzltcuTW/5WjX4QxEQjJGC+YoCuLf5m4453K0QOv Yi9g== 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 z7si1512852ile.128.2021.07.01.18.05.30; Thu, 01 Jul 2021 18:05:41 -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 S234604AbhGBBHD (ORCPT + 99 others); Thu, 1 Jul 2021 21:07:03 -0400 Received: from mail-pg1-f174.google.com ([209.85.215.174]:42771 "EHLO mail-pg1-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230427AbhGBBHD (ORCPT ); Thu, 1 Jul 2021 21:07:03 -0400 Received: by mail-pg1-f174.google.com with SMTP id d12so7962189pgd.9; Thu, 01 Jul 2021 18:04:31 -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=eaR++vjtiNX6DzHjutKmZUMGyUp8898EKANyRVFBEw0=; b=GYbRh3WRynklyYDXdXAmwJWBssd06qENgQD20dWyDBzL/0tAzswwRUmLtB3agJVFiJ G3a9UWTFo7hFekXc+IHvgThwgM3j69SFEizORWTV2cp3PVSppUgybJsIQcN4oH5uS3Z3 Fy0p7XfDs0Ew4jvhnfFU3vXEIm+hxy5ESbwrCw92Yw9yUt1sJL9Qc597jpf43/CskvIV QgTnOOuyPsMMt8AGO0OHBZKFn+0XTobrHQWi9S6C/kT01rafjMa9wxb+Ja3QndMu7//u 2T86ddvsiDGUtBh9pIM9tYz7dPfG3yxy054sFy2rI5KdWroGF/ruzx/j/V/hA07tjYPH Ostg== X-Gm-Message-State: AOAM5318R2vDWFR3zfB2h5XqbUYBPoMum1dBhN2SFu3P5aX0OQ7XsqZ1 71bwbfqmNft/u0nUgVZdrWE= X-Received: by 2002:a63:c1e:: with SMTP id b30mr256447pgl.118.1625187870738; Thu, 01 Jul 2021 18:04:30 -0700 (PDT) Received: from garbanzo ([191.96.121.144]) by smtp.gmail.com with ESMTPSA id t5sm1198320pgb.58.2021.07.01.18.04.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Jul 2021 18:04:29 -0700 (PDT) Date: Thu, 1 Jul 2021 18:04:25 -0700 From: Luis Chamberlain To: Greg KH , Tejun Heo Cc: 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-kernel@vger.kernel.org Subject: Re: [PATCH v4] sysfs: fix kobject refcount to address races with kobject removal Message-ID: <20210702010425.frwcbregdyuguaak@garbanzo> References: <20210623215007.862787-1-mcgrof@kernel.org> <20210625215558.xn4a24ts26bdyfzo@garbanzo> <20210701224816.pkzeyo4uqu3kbqdo@garbanzo> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210701224816.pkzeyo4uqu3kbqdo@garbanzo> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jul 01, 2021 at 03:48:22PM -0700, Luis Chamberlain wrote: > On Fri, Jun 25, 2021 at 02:56:03PM -0700, Luis Chamberlain wrote: > > On Thu, Jun 24, 2021 at 01:09:03PM +0200, Greg KH wrote: > > > thanks for making this change and sticking with it! > > > > > > Oh, and with this change, does your modprobe/rmmod crazy test now work? > > > > It does but I wrote a test_syfs driver and I believe I see an issue with > > this. I'll debug a bit more and see what it was, and I'll then also use > > the driver to demo the issue more clearly, and then verification can be > > an easy selftest test. > > OK my conclusion based on a new selftest driver I wrote is we can drop > this patch safely. The selftest will cover this corner case well now. > > In short: the kernfs active reference will ensure the store operation > still exists. The kernfs mutex is not enough, but if the driver removes > the operation prior to getting the active reference, the write will just > fail. The deferencing inside of the sysfs operation is abstract to > kernfs, and while kernfs can't do anything to prevent a driver from > doing something stupid, it at least can ensure an open file ensure the > op is not removed until the operation completes. OK and now its not so clear, as it would seem the refcount can indeed get reduced after we validated it. In any case we'll have enough tools to reproduce any possible failure soon. Luis