From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-0.9 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5D5F0C433E2 for ; Thu, 4 Jun 2020 00:23:20 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 1EFBD207D5 for ; Thu, 4 Jun 2020 00:23:19 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=ziepe.ca header.i=@ziepe.ca header.b="GGh6loAR" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1EFBD207D5 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=ziepe.ca Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 90770280007; Wed, 3 Jun 2020 20:23:19 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8B7F8280001; Wed, 3 Jun 2020 20:23:19 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7A6B0280007; Wed, 3 Jun 2020 20:23:19 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0039.hostedemail.com [216.40.44.39]) by kanga.kvack.org (Postfix) with ESMTP id 60A7B280001 for ; Wed, 3 Jun 2020 20:23:19 -0400 (EDT) Received: from smtpin05.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 144487FD88 for ; Thu, 4 Jun 2020 00:23:19 +0000 (UTC) X-FDA: 76889630118.05.roof16_1ce605281a136 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin05.hostedemail.com (Postfix) with ESMTP id F3BA21801E69D for ; Thu, 4 Jun 2020 00:23:18 +0000 (UTC) X-HE-Tag: roof16_1ce605281a136 X-Filterd-Recvd-Size: 4856 Received: from mail-qk1-f193.google.com (mail-qk1-f193.google.com [209.85.222.193]) by imf50.hostedemail.com (Postfix) with ESMTP for ; Thu, 4 Jun 2020 00:23:18 +0000 (UTC) Received: by mail-qk1-f193.google.com with SMTP id c185so4300051qke.7 for ; Wed, 03 Jun 2020 17:23:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ziepe.ca; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=FPRtEKt/Sf9m/+5i8pJQSFuKcKvaJeO/DgaLGboQUFw=; b=GGh6loARcWWsrtZZN3VwkXtpUI5030V12zOA4fv+m1KstYA6JjLng+O2J7XgFjXIr+ TBVhJIznea7WA6ElVmsyCjKC6PCGnhf5GvHwfClOXgxdYz06WFzRZRRqKFgzt13L8k1+ 620h8Pb/B1kmxltydPXhDlojYMW1Qae1C5nnhhsk6bklDOLVYrr3phnMhFQA1d7FVp5y ARuTeHkPmVqRQEbjwgx25T0BLEaSCi8ghgqMY98fo/pNg1j/N80B4KzTuD/wxl2WeHvk 9FY4gcr7fUthb56zNV6r8qrFIoiJSwrMiwsUJRf7bw/YiKYMGJHcBwDCexTTWoqkNIRQ ApBw== 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=FPRtEKt/Sf9m/+5i8pJQSFuKcKvaJeO/DgaLGboQUFw=; b=M823D3h/1pofgF+JPdVrGuLgL6KbPNOybGS/mUBehKJbfo/VtnzUW6zanyAwIJm06i LfzNYdj1pdbJ61r/o5j4wqcXFz9K5FdDu1JTmn6EUT0EA1XPZ7vrv7I//76WXZ9ZigDP bVEGSdE2ZikHRDxsYxoIfEYo5gBOsDd824MGFTewRZQAD+1STvn7+1huUF+Q0a+JPPSU 9xE013myjbpVC7M90pod8QlRCRd9QTK089bhTKwtFnM04YsaGTtNxUbq0laKV3CgkLpY xmEP/6vcI/3Odz70rJTlCzFUghjNfww4sZgY2Rv+exFWoLwgZS1nL0kxSkLYgm8kq+MW S7qA== X-Gm-Message-State: AOAM533XeHQpJrMAnyHktpUn/ELH/+6cVTdouKwwXkIgFDSTfCSFjfvX jPSMl7yHWDlgfOLSQfI5CL2cqw== X-Google-Smtp-Source: ABdhPJy7KTjWaqGSJlumwFqqm8BNdf14u29uZGDqN/mlCUnoedIFJr7qzbjYfD1WCRJdp7ewwz9ATQ== X-Received: by 2002:a37:555:: with SMTP id 82mr2256165qkf.279.1591230197836; Wed, 03 Jun 2020 17:23:17 -0700 (PDT) Received: from ziepe.ca (hlfxns017vw-156-34-48-30.dhcp-dynamic.fibreop.ns.bellaliant.net. [156.34.48.30]) by smtp.gmail.com with ESMTPSA id 6sm3049832qkl.26.2020.06.03.17.23.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Jun 2020 17:23:17 -0700 (PDT) Received: from jgg by mlx with local (Exim 4.93) (envelope-from ) id 1jgdfA-0010pG-Bs; Wed, 03 Jun 2020 21:23:16 -0300 Date: Wed, 3 Jun 2020 21:23:16 -0300 From: Jason Gunthorpe To: James Bottomley Cc: Greg Kroah-Hartman , Matthew Wilcox , Wang Hai , cl@linux.com, penberg@kernel.org, rientjes@google.com, iamjoonsoo.kim@lge.com, akpm@linux-foundation.org, khlebnikov@yandex-team.ru, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: kobject_init_and_add is easy to misuse Message-ID: <20200604002316.GM6578@ziepe.ca> References: <20200602173603.GB3579519@kroah.com> <1591127656.16819.7.camel@HansenPartnership.com> <20200602200756.GA3933938@kroah.com> <1591134670.16819.18.camel@HansenPartnership.com> <20200603002205.GE6578@ziepe.ca> <1591207475.4462.41.camel@HansenPartnership.com> <20200603183650.GI6578@ziepe.ca> <1591210928.13983.24.camel@HansenPartnership.com> <20200603193013.GJ6578@ziepe.ca> <1591217780.13983.56.camel@HansenPartnership.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1591217780.13983.56.camel@HansenPartnership.com> X-Rspamd-Queue-Id: F3BA21801E69D X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam02 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Wed, Jun 03, 2020 at 01:56:20PM -0700, James Bottomley wrote: > The store of state_in_sysfs is already done in kobject_add_internal(). > It's an existing flag people already use to tell if the kobject has > been exposed in sysfs. However, it's set after the sysfs directory > creation succeeds. This is the code with some debugging removed: > > error = create_dir(kobj); > if (error) { > kobj_kset_leave(kobj); > kobject_put(parent); > kobj->parent = NULL; > ... > } else > kobj->state_in_sysfs = 1; I was thinking most probably this will need a lock or a smp_store_release() .. > > It feels more robust to stick with the put though.. > > possibly ... like I said, the only concern with the put path is that > ->release has state expectations that aren't met if > kobject_init_and_add fails. Certainly error unwind bugs related to put and release will exist, but I suspect switching to kfree won't solve them, just move them to the next function that fails and needs a put based unwind? At least the patches I reviewed for RDM a from Wang Hai were all correct and didn't seem to have release based errors. Jason