Message ID | 20230406093056.33916-2-frank.li@vivo.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp894215vqo; Thu, 6 Apr 2023 02:43:58 -0700 (PDT) X-Google-Smtp-Source: AKy350YkhatEaJLoIwFO7RPUC1mgXE68hKQZ9RztEmkoMggcMS0M2ipJcZ8UTOXMfq6MxWRskXyO X-Received: by 2002:a17:90b:33cc:b0:237:40a5:7cb9 with SMTP id lk12-20020a17090b33cc00b0023740a57cb9mr10431945pjb.5.1680774237834; Thu, 06 Apr 2023 02:43:57 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1680774237; cv=pass; d=google.com; s=arc-20160816; b=sXeZdUW1T9eIJaf0Mt/KSfKivg78wKzedPlbSYUTnfHcObOp44RI5AX9wB+uoupgOK 23uHkaKqXDhmb1SC63Prp05MZlQMMSpr74tUP4ZeNCO7plwp902R1BF6cFtropPGdnMI p1AcaZcwOxeTSrGf/7FdwSR7tfv06Z/W0P9vOwZ7BM19uiEdT2fG8XG/NbabclAXSP4J 6+4borfdxJ6p7PjOLTNIsc7OTm6wG1o5rvNaqIy/tYXbnpQ/Gts3f4XRDGbPkeqp+m7b zNcFegr2bE75+Elso4/27mprNNr65DvAOaSIQ29sz4zeJujOFVdjoXti+ZrgS5/FhoR1 Sq6g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=jx3LPpRVZASZ0NonrMCGIl/8nEX/C7veMEX03jGe01w=; b=BvRypZBZAnAK0LBo5W5VGJ9yIzqSPdwUIRC+v8LzjMaiE5u+xHs4neGOJ7VGh1JMgz bXzUw1H+3lTCOYbcqyB+aswZ249KOT1sgebKfSPq2dupOnKHCvbX42qSU8d5TZ/w/2ys 4zeCsiZ6jsJFF83BlFxIZOzBTK9JXR6ejQPFJO5iy8bdauZGztUIez57OMSH4MbgxvZr meRrYQzsbzh+U2xd2NkyohCusVFa+W5LagVKsiYhjQgemwRIY+q64cAtTxyTIvAIsmU3 4PnnvwZOAW8FxgA0RpqcOaAV8hHHDax5e//k369pvkUsPVB+od2G+S0qnaom48/zBNCE x8rA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@vivo.com header.s=selector2 header.b=NJclsDNP; arc=pass (i=1 spf=pass spfdomain=vivo.com dkim=pass dkdomain=vivo.com dmarc=pass fromdomain=vivo.com); 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=vivo.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p4-20020a17090b010400b00240ef97dd52si900078pjz.159.2023.04.06.02.43.46; Thu, 06 Apr 2023 02:43:57 -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=@vivo.com header.s=selector2 header.b=NJclsDNP; arc=pass (i=1 spf=pass spfdomain=vivo.com dkim=pass dkdomain=vivo.com dmarc=pass fromdomain=vivo.com); 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=vivo.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236425AbjDFJbR (ORCPT <rfc822;lkml4gm@gmail.com> + 99 others); Thu, 6 Apr 2023 05:31:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41154 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236409AbjDFJbP (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Thu, 6 Apr 2023 05:31:15 -0400 Received: from APC01-TYZ-obe.outbound.protection.outlook.com (mail-tyzapc01on2130.outbound.protection.outlook.com [40.107.117.130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8F3D865B6; Thu, 6 Apr 2023 02:31:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YqjEbqHURaqcMLCvpVJkcjX4DP8yETLaDjThKMW8HWZkR63Q6iGS0jKbPXAYVR/zEMOvm4gikyi7P31fFgptQYsZhmIm8d1c4GM+6lanF2tvePsOoNhmPJ6XPzeVq8ZlSnAY5LxohWSireDEuGj2LpvVJqgJQSBrOyJXdtZaXclMAvljTvGY7/41d8Vi9ynZi+dYwqTIja1QOEO+clRYE7HB2nog+5hti83dA7O+YkjqD9GEfHYd+PwZ2gp4sCXCZfuAeXzYggCPGmomSYWgNzg2PYZk6NH4wQL/YPeM2+lXty87p8YRzKvAInYTrH/8vdNbTYTpwtCkTxIY4b7sAw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=jx3LPpRVZASZ0NonrMCGIl/8nEX/C7veMEX03jGe01w=; b=gwe03sjV9WeSxiBXNfHmRyFuEySvlvB+eP294bWGqDqhEfOoKvwbJ7fEJ3APwSEUFPfHgZFoPP703HSySwSmw7dvIc8oJzUSA7A8D889ajfHYAZ+xodgp7ufKwO/+SfMIEKD4KAiboT64BIkttdq0lM+mscyXu2GeRNKezRzaG4VwK4B8qarx1klLw/E7a1/6aDIyoWj0d8oktGx2CWdwFyiuD3dZMWksVQaQSAexKPqRR7cKgR6ONRBOhSEdHou2NyNCHq/5m/Na9Tr5o3Y63/3D0ruXAj7YnLEca9jSMkMs/pMDBSEAk8eGgnCNz9HgkoNhOvcHohQX44NRz0clA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=vivo.com; dmarc=pass action=none header.from=vivo.com; dkim=pass header.d=vivo.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vivo.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=jx3LPpRVZASZ0NonrMCGIl/8nEX/C7veMEX03jGe01w=; b=NJclsDNPTmlnWMMiSnhaZJOPVDvcFWDsY/whInLqg2my7dJ38Twlls71zUEBtBiwFucAgWbLQ/N5dOi7tfI+CySKYS7v5KAuIkjl7YWreQiUMpQFwYZjm0a6a5nhWxMMYdPEonEMHSQEF8yb1SNIyUCmVpZFrUwWnrMa/9e5oFCAs59tPE+XFtmlu3LI5bJedzQD1xuJ0z304aAGYE2dUCtQDyfiuZsXTyxALrGD9RgWloJRT3MIOcXftg5NgrN6ktKZP87lpM67f9onaffCHFFW0zP6uczoDUBn3Nme/pslWMEn5csrXcSCtSdfFqmfQ/QVPBMVY7Ijt1xy2Yp/YA== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=vivo.com; Received: from TYZPR06MB5275.apcprd06.prod.outlook.com (2603:1096:400:1f5::6) by PUZPR06MB5772.apcprd06.prod.outlook.com (2603:1096:301:f0::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6254.35; Thu, 6 Apr 2023 09:31:12 +0000 Received: from TYZPR06MB5275.apcprd06.prod.outlook.com ([fe80::16db:8a6e:6861:4bb]) by TYZPR06MB5275.apcprd06.prod.outlook.com ([fe80::16db:8a6e:6861:4bb%5]) with mapi id 15.20.6277.031; Thu, 6 Apr 2023 09:31:12 +0000 From: Yangtao Li <frank.li@vivo.com> To: xiang@kernel.org, chao@kernel.org, huyue2@coolpad.com, jefflexu@linux.alibaba.com, damien.lemoal@opensource.wdc.com, naohiro.aota@wdc.com, jth@kernel.org, gregkh@linuxfoundation.org, rafael@kernel.org Cc: linux-erofs@lists.ozlabs.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Yangtao Li <frank.li@vivo.com> Subject: [PATCH 2/3] erofs: convert to use kobject_is_added() Date: Thu, 6 Apr 2023 17:30:55 +0800 Message-Id: <20230406093056.33916-2-frank.li@vivo.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20230406093056.33916-1-frank.li@vivo.com> References: <20230406093056.33916-1-frank.li@vivo.com> Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: SG2P153CA0021.APCP153.PROD.OUTLOOK.COM (2603:1096:4:c7::8) To TYZPR06MB5275.apcprd06.prod.outlook.com (2603:1096:400:1f5::6) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: TYZPR06MB5275:EE_|PUZPR06MB5772:EE_ X-MS-Office365-Filtering-Correlation-Id: 8170c1d8-b98d-4372-ff9b-08db3681a912 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 72ZPUACYtx/YRirpcMhxSmSupxy/1cYwOBu2VRNOkxpUKzY70bplrwgIRN17u8+H43D30OaqPWlTShbFDVosrcZk1m/ofO+NTJ2UcBjhGHbQHVPzLOJg+YK6l/jdXyPgEYALqTDURxchSfsqRbYOgz/p0uJjByQWzUHpsJu1KByZKXY+DvGlZe5TvSXVwIqIFi2oPxrTSV/GnnctZ3TxD4x+L7nTrjElDDyqIQkepj6wRKLWaskhB+o244bEW1ap7WjaYa2YN+JhH4mwN3Q6Cxn9oXxUnctBhC3OE6V6wsR81jOcbBSvD1U7m4it/4/KWgin1hiilBFuvTLX94TxSjhxnNC+8TwCzyaa1qCrh1SeKE41Qt8rwqMkVcTtYmouZF8QKUycpbFc0xd47Ht+zlwqWB/xLhQlJHJK0s/UCsMhXnH+DqqhKp0BAIJatKQDTbGTbJLETjtnynfi6nKNwEmnkzH24QiUSmsl5Vz9F3/Ao/fUTnxesutZAJxY1HIVA4neNNcep4+WV52583Hzj0TC5E2Ls6SUXplOspl8iCTuVDrSWQzW5sFrjeTH+uuap2ThHGQ3CVHYPM6NAQPJgLcUPEqwdfmSO5SjIPvGhN1Nr/475CRGVaW1yAwFbm+C X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:TYZPR06MB5275.apcprd06.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(39860400002)(396003)(376002)(346002)(136003)(366004)(451199021)(4744005)(86362001)(36756003)(2906002)(6666004)(2616005)(186003)(83380400001)(6486002)(6506007)(6512007)(107886003)(1076003)(26005)(8676002)(4326008)(66556008)(66946007)(66476007)(52116002)(316002)(5660300002)(38350700002)(38100700002)(41300700001)(478600001)(7416002)(8936002);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 8xu4ODqKtAEl1g7E56zucgOxpsbcH9SlAcjmR8ueI2nrU8hvfWKC3AHqkiBeV67C4dD7uK+b1EpisG7emocEAqwqOkrGRGD5N8H3UYCars6Kz5ILiLYlke5APEP9fSc1ej1k319glHbQS/vovIPPfWF5/3AUqSxIvJq8Ljgz6GedjIjiVWZuX/84LGNjFbgraHdm8+P/pfi1CBnPXZ1ftpqIjb7v30uy0B1jefCiWV1yZD7y5DOTNJ3hMfPIQk5hg1gZrtEj1mbTSYw0sXEq1DaKQDIdJyEOBOK/W/BHitV0peWOghgs4M28bi8wbnXZqNIM54LENo90IRM6SXoCq5mwEpI/KplzQEf68eQugLQv3Su18mf9UVGAymh3dUlsbmrf4XoPAC6BXcvz8H841nTSBTZRLg3v7QTnVr6tLRXAvq1k0NXZ13E4Rp2bnTUpUrrAGMkdl+mZsDyEUkULyKI2YZtfHtca27QQ/yTopMjWTjCT2rT9fDQ2NF7mnPXVyGtQdlAvWFoNTZMxCeJekwTAilDmtDexjFpidJeB3xxS1AXDYxUD32UNnExBv2VKWe9ysWKxf7VB9qcnWaUZRnSox0BvwCPf4N2YKwJvAnsVEittK1kfvMaV9ijjszOrc3xz9PZ4otl9imyBp7wsNtSEUwbza3NfHRLABBOET9FV783+hUqLPobHO5diyHn5xRmNMh1G1aS8+5x4Z3HlxzS3fsDb6F+lP0Xoz5PSoSfW5yHB0NmbHN+GajicnJiSqJNUrW5C16T4mhhpLSUl296x3F/jCiEnAasv8yR3rHhnWDRt/F+tCrFqCR8PgkfyjTTs1e/v9qAiSVfMLyOBb14qzs4sk1DXH+6RdE/SjMyiBvWiwzwE7BYSl2hpF0zsETNWEdT49MVuldHCGVocir5yi56wyRgorWwWnB/h8rChNKn+QXWUM7rIhcagONZyhd4dRtLcddcYgnFOMgCeUJi8wTcUSQKdi+GwdaVUYnKCnET8jhChKqlI//HYRI3Dz6IPEb3GQn6JdeDS9Plkd/zqj7lxsTBZf8UWoawKtubXZb0ZPiE4ICXr5Q7vCoFuJtx1QKaAEe8uElrQSBxowB3L2QJ0g02bXXTzVDqGHRKjxQI00ti1Xkiw4Z0kog876vt+pJKmXBneqUX01whm7i5uN1iFtJyGHnuv3RKwX8CU++ouiEHJnOlKcWFdxT+x1THxJBxBrwydyLb1lfRzQB68j67HczBDfAFi3h13dljbe5SBjrGBJZxfpJ6TztPePm4YxJQiBpNM1uFJ7R+yle6cxyQ6uJ2ax0/3IMVFjLfeFTxKQ3BRGqyttJAN+wwbt66iaP9Ty43Zmd9dHeNc8CjG7PMtQ5vdHijAvz8PwKU0on8e6VkL+ER8qNBuUGFyrHdJ2BdEsdjPoNGRAuzFWfex5/ru7cVVJrSHYj466J3rB9CRKE3D7iojBp0w49acGWmj2V25IxI/2avkEKnkq841ss74rT/JYHt4AAmLaaiV9GtVWpNX0g65lJ8UEaB/JS6W+AYoDSH6lyNY27RruuRw/hKSYuaUaCuQv73mvJGt2pVomsdXh51cDBz+MM21 X-OriginatorOrg: vivo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8170c1d8-b98d-4372-ff9b-08db3681a912 X-MS-Exchange-CrossTenant-AuthSource: TYZPR06MB5275.apcprd06.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Apr 2023 09:31:12.0469 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 923e42dc-48d5-4cbe-b582-1a797a6412ed X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: Ucu/GWhOFtHHd9+lmAZP+zHCRhmy8WjLG6Owda8gfhS1ot0DwgzrvJF/ixbprPVuVtsZoo7q+Bl1MR1XyI38mw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PUZPR06MB5772 X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2, SPF_HELO_PASS,SPF_PASS autolearn=unavailable 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762419527142315493?= X-GMAIL-MSGID: =?utf-8?q?1762419527142315493?= |
Series |
[1/3] kobject: introduce kobject_is_added()
|
|
Commit Message
李扬韬
April 6, 2023, 9:30 a.m. UTC
Use kobject_is_added() instead of directly accessing the internal
variables of kobject. BTW kill kobject_del() directly, because
kobject_put() actually covers kobject removal automatically.
Signed-off-by: Yangtao Li <frank.li@vivo.com>
---
fs/erofs/sysfs.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
Comments
On Thu, Apr 06, 2023 at 05:30:55PM +0800, Yangtao Li wrote: > Use kobject_is_added() instead of directly accessing the internal > variables of kobject. BTW kill kobject_del() directly, because > kobject_put() actually covers kobject removal automatically. > > Signed-off-by: Yangtao Li <frank.li@vivo.com> > --- > fs/erofs/sysfs.c | 3 +-- > 1 file changed, 1 insertion(+), 2 deletions(-) > > diff --git a/fs/erofs/sysfs.c b/fs/erofs/sysfs.c > index 435e515c0792..daac23e32026 100644 > --- a/fs/erofs/sysfs.c > +++ b/fs/erofs/sysfs.c > @@ -240,8 +240,7 @@ void erofs_unregister_sysfs(struct super_block *sb) > { > struct erofs_sb_info *sbi = EROFS_SB(sb); > > - if (sbi->s_kobj.state_in_sysfs) { > - kobject_del(&sbi->s_kobj); > + if (kobject_is_added(&sbi->s_kobj)) { I do not understand why this check is even needed, I do not think it should be there at all as obviously the kobject was registered if it now needs to not be registered. Meta-comment, we need to come up with a "filesystem kobject type" to get rid of lots of the boilerplate filesystem kobject logic as it's duplicated in every filesystem in tiny different ways and lots of times (like here), it's wrong. kobjects were not designed to be "used raw" like this, ideally they would be wrapped in a subsystem that makes them easier to be used (like the driver model), but filesystems decided to use them and that usage just grew over the years. That's evolution for you... thanks, greg k-h
Hi Greg, On 2023/4/6 18:03, Greg KH wrote: > On Thu, Apr 06, 2023 at 05:30:55PM +0800, Yangtao Li wrote: >> Use kobject_is_added() instead of directly accessing the internal >> variables of kobject. BTW kill kobject_del() directly, because >> kobject_put() actually covers kobject removal automatically. >> >> Signed-off-by: Yangtao Li <frank.li@vivo.com> >> --- >> fs/erofs/sysfs.c | 3 +-- >> 1 file changed, 1 insertion(+), 2 deletions(-) >> >> diff --git a/fs/erofs/sysfs.c b/fs/erofs/sysfs.c >> index 435e515c0792..daac23e32026 100644 >> --- a/fs/erofs/sysfs.c >> +++ b/fs/erofs/sysfs.c >> @@ -240,8 +240,7 @@ void erofs_unregister_sysfs(struct super_block *sb) >> { >> struct erofs_sb_info *sbi = EROFS_SB(sb); >> >> - if (sbi->s_kobj.state_in_sysfs) { >> - kobject_del(&sbi->s_kobj); >> + if (kobject_is_added(&sbi->s_kobj)) { > > I do not understand why this check is even needed, I do not think it > should be there at all as obviously the kobject was registered if it now > needs to not be registered. I think Yangtao sent a new patchset which missed the whole previous background discussions as below: https://lore.kernel.org/r/028a1b56-72c9-75f6-fb68-1dc5181bf2e8@linux.alibaba.com It's needed because once a syzbot complaint as below: https://lore.kernel.org/r/CAD-N9QXNx=p3-QoWzk6pCznF32CZy8kM3vvo8mamfZZ9CpUKdw@mail.gmail.com I'd suggest including the previous backgrounds at least in the newer patchset, otherwise it makes me explain again and again... Thanks, Gao Xiang > > Meta-comment, we need to come up with a "filesystem kobject type" to get > rid of lots of the boilerplate filesystem kobject logic as it's > duplicated in every filesystem in tiny different ways and lots of times > (like here), it's wrong. > > kobjects were not designed to be "used raw" like this, ideally they > would be wrapped in a subsystem that makes them easier to be used (like > the driver model), but filesystems decided to use them and that usage > just grew over the years. That's evolution for you...> > thanks, > > greg k-h
On Thu, Apr 06, 2023 at 06:13:05PM +0800, Gao Xiang wrote: > Hi Greg, > > On 2023/4/6 18:03, Greg KH wrote: > > On Thu, Apr 06, 2023 at 05:30:55PM +0800, Yangtao Li wrote: > > > Use kobject_is_added() instead of directly accessing the internal > > > variables of kobject. BTW kill kobject_del() directly, because > > > kobject_put() actually covers kobject removal automatically. > > > > > > Signed-off-by: Yangtao Li <frank.li@vivo.com> > > > --- > > > fs/erofs/sysfs.c | 3 +-- > > > 1 file changed, 1 insertion(+), 2 deletions(-) > > > > > > diff --git a/fs/erofs/sysfs.c b/fs/erofs/sysfs.c > > > index 435e515c0792..daac23e32026 100644 > > > --- a/fs/erofs/sysfs.c > > > +++ b/fs/erofs/sysfs.c > > > @@ -240,8 +240,7 @@ void erofs_unregister_sysfs(struct super_block *sb) > > > { > > > struct erofs_sb_info *sbi = EROFS_SB(sb); > > > - if (sbi->s_kobj.state_in_sysfs) { > > > - kobject_del(&sbi->s_kobj); > > > + if (kobject_is_added(&sbi->s_kobj)) { > > > > I do not understand why this check is even needed, I do not think it > > should be there at all as obviously the kobject was registered if it now > > needs to not be registered. > > I think Yangtao sent a new patchset which missed the whole previous > background discussions as below: > https://lore.kernel.org/r/028a1b56-72c9-75f6-fb68-1dc5181bf2e8@linux.alibaba.com > > It's needed because once a syzbot complaint as below: > https://lore.kernel.org/r/CAD-N9QXNx=p3-QoWzk6pCznF32CZy8kM3vvo8mamfZZ9CpUKdw@mail.gmail.com > > I'd suggest including the previous backgrounds at least in the newer patchset, > otherwise it makes me explain again and again... That would be good, as I do not think this is correct, it should be fixed in a different way, see my response to the zonefs patch in this series as a much simpler method to use. thanks, greg k-h
On 2023/4/6 18:27, Greg KH wrote: > On Thu, Apr 06, 2023 at 06:13:05PM +0800, Gao Xiang wrote: >> Hi Greg, >> >> On 2023/4/6 18:03, Greg KH wrote: >>> On Thu, Apr 06, 2023 at 05:30:55PM +0800, Yangtao Li wrote: >>>> Use kobject_is_added() instead of directly accessing the internal >>>> variables of kobject. BTW kill kobject_del() directly, because >>>> kobject_put() actually covers kobject removal automatically. >>>> >>>> Signed-off-by: Yangtao Li <frank.li@vivo.com> >>>> --- >>>> fs/erofs/sysfs.c | 3 +-- >>>> 1 file changed, 1 insertion(+), 2 deletions(-) >>>> >>>> diff --git a/fs/erofs/sysfs.c b/fs/erofs/sysfs.c >>>> index 435e515c0792..daac23e32026 100644 >>>> --- a/fs/erofs/sysfs.c >>>> +++ b/fs/erofs/sysfs.c >>>> @@ -240,8 +240,7 @@ void erofs_unregister_sysfs(struct super_block *sb) >>>> { >>>> struct erofs_sb_info *sbi = EROFS_SB(sb); >>>> - if (sbi->s_kobj.state_in_sysfs) { >>>> - kobject_del(&sbi->s_kobj); >>>> + if (kobject_is_added(&sbi->s_kobj)) { >>> >>> I do not understand why this check is even needed, I do not think it >>> should be there at all as obviously the kobject was registered if it now >>> needs to not be registered. >> >> I think Yangtao sent a new patchset which missed the whole previous >> background discussions as below: >> https://lore.kernel.org/r/028a1b56-72c9-75f6-fb68-1dc5181bf2e8@linux.alibaba.com >> >> It's needed because once a syzbot complaint as below: >> https://lore.kernel.org/r/CAD-N9QXNx=p3-QoWzk6pCznF32CZy8kM3vvo8mamfZZ9CpUKdw@mail.gmail.com >> >> I'd suggest including the previous backgrounds at least in the newer patchset, >> otherwise it makes me explain again and again... > > That would be good, as I do not think this is correct, it should be > fixed in a different way, see my response to the zonefs patch in this > series as a much simpler method to use. Yes, but here (sbi->s_kobj) is not a kobject pointer (also at a quick glance it seems that zonefs has similar code), and also we couldn't just check the sbi is NULL or not here only, since sbi is already non-NULL in this path and there are some others in sbi to free in other functions. s_kobj could be changed into a pointer if needed. I'm all fine with either way since as you said, it's a boilerplate filesystem kobject logic duplicated from somewhere. Hopefully Yangtao could help take this task since he sent me patches about this multiple times. Thanks, Gao Xiang > > thanks, > > greg k-h
On Thu, Apr 06, 2023 at 06:55:40PM +0800, Gao Xiang wrote: > > > On 2023/4/6 18:27, Greg KH wrote: > > On Thu, Apr 06, 2023 at 06:13:05PM +0800, Gao Xiang wrote: > > > Hi Greg, > > > > > > On 2023/4/6 18:03, Greg KH wrote: > > > > On Thu, Apr 06, 2023 at 05:30:55PM +0800, Yangtao Li wrote: > > > > > Use kobject_is_added() instead of directly accessing the internal > > > > > variables of kobject. BTW kill kobject_del() directly, because > > > > > kobject_put() actually covers kobject removal automatically. > > > > > > > > > > Signed-off-by: Yangtao Li <frank.li@vivo.com> > > > > > --- > > > > > fs/erofs/sysfs.c | 3 +-- > > > > > 1 file changed, 1 insertion(+), 2 deletions(-) > > > > > > > > > > diff --git a/fs/erofs/sysfs.c b/fs/erofs/sysfs.c > > > > > index 435e515c0792..daac23e32026 100644 > > > > > --- a/fs/erofs/sysfs.c > > > > > +++ b/fs/erofs/sysfs.c > > > > > @@ -240,8 +240,7 @@ void erofs_unregister_sysfs(struct super_block *sb) > > > > > { > > > > > struct erofs_sb_info *sbi = EROFS_SB(sb); > > > > > - if (sbi->s_kobj.state_in_sysfs) { > > > > > - kobject_del(&sbi->s_kobj); > > > > > + if (kobject_is_added(&sbi->s_kobj)) { > > > > > > > > I do not understand why this check is even needed, I do not think it > > > > should be there at all as obviously the kobject was registered if it now > > > > needs to not be registered. > > > > > > I think Yangtao sent a new patchset which missed the whole previous > > > background discussions as below: > > > https://lore.kernel.org/r/028a1b56-72c9-75f6-fb68-1dc5181bf2e8@linux.alibaba.com > > > > > > It's needed because once a syzbot complaint as below: > > > https://lore.kernel.org/r/CAD-N9QXNx=p3-QoWzk6pCznF32CZy8kM3vvo8mamfZZ9CpUKdw@mail.gmail.com > > > > > > I'd suggest including the previous backgrounds at least in the newer patchset, > > > otherwise it makes me explain again and again... > > > > That would be good, as I do not think this is correct, it should be > > fixed in a different way, see my response to the zonefs patch in this > > series as a much simpler method to use. > > Yes, but here (sbi->s_kobj) is not a kobject pointer (also at a quick > glance it seems that zonefs has similar code), and also we couldn't > just check the sbi is NULL or not here only, since sbi is already > non-NULL in this path and there are some others in sbi to free in > other functions. > > s_kobj could be changed into a pointer if needed. I'm all fine with > either way since as you said, it's a boilerplate filesystem kobject > logic duplicated from somewhere. Hopefully Yangtao could help take > this task since he sent me patches about this multiple times. I made the same mistake with the zonefs code. If the kobject in this structure controls the lifespan of it (which makes it not a pointer, my mistake), then that whole memory chunk can't be valid anymore if the kobject registering function failed so you need to get rid of it then, not later. thanks, greg k-h
> Meta-comment, we need to come up with a "filesystem kobject type" to get > rid of lots of the boilerplate filesystem kobject logic as it's > duplicated in every filesystem in tiny different ways and lots of times > (like here), it's wrong. Can we add the following structure? struct filesystem_kobject { struct kobject kobject; struct completion unregister; }; w/ it, we can simplify something: 1. merge init_completion and kobject_init_and_add 2. merge kobject_put and wait_for_completion 3. we can have a common release func for kobj_type release MBR, Yangtao
> > Meta-comment, we need to come up with a "filesystem kobject type" to get > > rid of lots of the boilerplate filesystem kobject logic as it's > > duplicated in every filesystem in tiny different ways and lots of times > > (like here), it's wrong. > > Can we add the following structure? > > struct filesystem_kobject { > struct kobject kobject; > struct completion unregister; > }; > > w/ it, we can simplify something: > > 1. merge init_completion and kobject_init_and_add > > 2. merge kobject_put and wait_for_completion > > 3. we can have a common release func for kobj_type release It seems that the above ideas are not crazy enough, maybe we should do more. Any ideas and suggestions are very welcome. MBR, Yangtao
On Thu, Apr 06, 2023 at 08:07:16PM +0800, Yangtao Li wrote: > > Meta-comment, we need to come up with a "filesystem kobject type" to get > > rid of lots of the boilerplate filesystem kobject logic as it's > > duplicated in every filesystem in tiny different ways and lots of times > > (like here), it's wrong. > > Can we add the following structure? > > struct filesystem_kobject { > struct kobject kobject; > struct completion unregister; > }; Ah, no, I see the problem. The filesystem authors are treating the kobject NOT as the thing that handles the lifespan of the structure it is embedded in, but rather as something else (i.e. a convient place to put filesystem information to userspace.) That isn't going to work, and as proof of that, the release callback should be a simple call to kfree(), NOT as a completion notification which then something else will go off and free the memory here. That implies that there are multiple reference counting structures happening on the same structure, which is not ok. Either we let the kobject code properly handle the lifespan of the structure, OR we pull it out of the structure and just let it hang off as a separate structure (i.e. a pointer to something else.) As the superblock lifespan rules ALREADY control the reference counting logic of the filesystem superblock structure, let's stick with that and just tack-on the kobject as a separate structure entirely. Does that make sense? Let me do a quick pass at this for zonefs as that's pretty simple to show you what I mean... thanks, greg k-h
Hi Greg, > That isn't going to work, and as proof of that, the release callback > should be a simple call to kfree(), NOT as a completion notification > which then something else will go off and free the memory here. That > implies that there are multiple reference counting structures happening > on the same structure, which is not ok. The release() function did nothing inside, but we need to wait asynchronously... Can we directly export the kobject_cleanup(kobj) interface so that kobj_type->release() doesn't have to do anything? If do it, the use of init_completion, wait_for_completion, etc. will no longer be needed. > OR we pull it out of the structure and just let it hang off as a separate > structure (i.e. a pointer to something else.) Make something like sbi->s_kobj a pointer instead of data embedded in sbi? When kobject_init_and_add fails, call kobject_put(sbi->s_kobj), and assign sbi->s_kobj = NULL at the same time? Thx, Yangtao
Hi Greg,
> just let it hang off as a separate structure (i.e. a pointer to something else.)
I have made some attempts. According to my understanding, the reason why the
filesystem needs to embed the kobj structure (not a pointer) is that the kobj_to_sbi
method is required in the attr_store/attr_show method for subsequent data processing.
130 static ssize_t erofs_attr_store(struct kobject *kobj, struct attribute *attr,
131 const char *buf, size_t len)
132 {
133 struct erofs_sb_info *sbi = container_of(kobj, struct erofs_sb_info,
134 s_kobj);
If we turn the kobject in sbi into a pointer, then we need to insert a pointer
to sbi in the kobject, or perform the following encapsulation.
struct filesystem_kobject {
struct kobject kobject;
void *private;
};
Later, I thought I could send some demo code that strips the kobject in sbi into a pointer.
BTW, Now sysfs.c in many file systems is full of a lot of repetitive code, maybe we can abstract the common part?
Like filesystem_attr、filesystem_kobject_ops、filesystem_kobject_ktype...
Thx,
Yangtao
Hi all,
> Later, I thought I could send some demo code that strips the kobject in sbi into a pointer.
I made the following modifications, not sure if I'm going the right way.
diff --git a/fs/erofs/internal.h b/fs/erofs/internal.h
index 1db018f8c2e8..8e1799f690c0 100644
--- a/fs/erofs/internal.h
+++ b/fs/erofs/internal.h
@@ -165,8 +165,7 @@ struct erofs_sb_info {
u32 feature_incompat;
/* sysfs support */
- struct kobject s_kobj; /* /sys/fs/erofs/<devname> */
- struct completion s_kobj_unregister;
+ struct filesystem_kobject *f_kobj;
/* fscache support */
struct fscache_volume *volume;
diff --git a/fs/erofs/sysfs.c b/fs/erofs/sysfs.c
index 435e515c0792..70e915906012 100644
--- a/fs/erofs/sysfs.c
+++ b/fs/erofs/sysfs.c
@@ -8,6 +8,33 @@
#include "internal.h"
+//maybe we should add following thins to include/linux/filesystem_kobject.h ?
+struct filesystem_kobject {
+ struct kobject kobject;
+ void *private;
+};
+
+void filesystem_kobject_put(struct filesystem_kobject *f_kobj)
+{
+ if (f_kobj)
+ kobject_put(&f_kobj->kobject);
+}
+
+void filesystem_kobject_set_private(struct filesystem_kobject *f_kobj, void *p)
+{
+ f_kobj->private = p;
+}
+
+void *filesystem_kobject_get_private(struct filesystem_kobject *f_kobj)
+{
+ return f_kobj->private;
+}
+
+struct kobject *filesystem_kobject_get_kobject(struct filesystem_kobject *f_kobj)
+{
+ return &f_kobj->kobject;
+}
+
enum {
attr_feature,
attr_pointer_ui,
@@ -107,8 +134,9 @@ static unsigned char *__struct_ptr(struct erofs_sb_info *sbi,
static ssize_t erofs_attr_show(struct kobject *kobj,
struct attribute *attr, char *buf)
{
- struct erofs_sb_info *sbi = container_of(kobj, struct erofs_sb_info,
- s_kobj);
+ struct filesystem_kobject *f_kobject = container_of(kobj, struct filesystem_kobject,
+ kobject);
+ struct erofs_sb_info *sbi = filesystem_kobject_get_private(f_kobject);
struct erofs_attr *a = container_of(attr, struct erofs_attr, attr);
unsigned char *ptr = __struct_ptr(sbi, a->struct_type, a->offset);
@@ -130,8 +158,9 @@ static ssize_t erofs_attr_show(struct kobject *kobj,
static ssize_t erofs_attr_store(struct kobject *kobj, struct attribute *attr,
const char *buf, size_t len)
{
- struct erofs_sb_info *sbi = container_of(kobj, struct erofs_sb_info,
- s_kobj);
+ struct filesystem_kobject *f_kobject = container_of(kobj, struct filesystem_kobject,
+ kobject);
+ struct erofs_sb_info *sbi = filesystem_kobject_get_private(f_kobject);
struct erofs_attr *a = container_of(attr, struct erofs_attr, attr);
unsigned char *ptr = __struct_ptr(sbi, a->struct_type, a->offset);
unsigned long t;
@@ -169,9 +198,12 @@ static ssize_t erofs_attr_store(struct kobject *kobj, struct attribute *attr,
static void erofs_sb_release(struct kobject *kobj)
{
- struct erofs_sb_info *sbi = container_of(kobj, struct erofs_sb_info,
- s_kobj);
- complete(&sbi->s_kobj_unregister);
+ struct filesystem_kobject *f_kobject = container_of(kobj, struct filesystem_kobject,
+ kobject);
+ struct erofs_sb_info *sbi = filesystem_kobject_get_private(f_kobject);
+
+ kfree(f_kobject);
+ sbi->f_kobj = NULL;
}
static const struct sysfs_ops erofs_attr_ops = {
@@ -205,6 +237,7 @@ static struct kobject erofs_feat = {
int erofs_register_sysfs(struct super_block *sb)
{
struct erofs_sb_info *sbi = EROFS_SB(sb);
+ struct kobject *kobj;
char *name;
char *str = NULL;
int err;
@@ -222,17 +255,24 @@ int erofs_register_sysfs(struct super_block *sb)
} else {
name = sb->s_id;
}
- sbi->s_kobj.kset = &erofs_root;
- init_completion(&sbi->s_kobj_unregister);
- err = kobject_init_and_add(&sbi->s_kobj, &erofs_sb_ktype, NULL, "%s", name);
+
+ sbi->f_kobj = kzalloc(sizeof(struct filesystem_kobject), GFP_KERNEL);
+ if (!sbi->f_kobj) {
+ kfree(str);
+ return -ENOMEM;
+ }
+ filesystem_kobject_set_private(sbi->f_kobj, sbi);
+ kobj = filesystem_kobject_get_kobject(sbi->f_kobj);
+ kobj->kset = &erofs_root;
+
+ err = kobject_init_and_add(&sbi->f_kobj->kobject, &erofs_sb_ktype, NULL, "%s", name);
kfree(str);
if (err)
goto put_sb_kobj;
return 0;
put_sb_kobj:
- kobject_put(&sbi->s_kobj);
- wait_for_completion(&sbi->s_kobj_unregister);
+ filesystem_kobject_put(sbi->f_kobj);
return err;
}
@@ -240,11 +280,7 @@ void erofs_unregister_sysfs(struct super_block *sb)
{
struct erofs_sb_info *sbi = EROFS_SB(sb);
- if (sbi->s_kobj.state_in_sysfs) {
- kobject_del(&sbi->s_kobj);
- kobject_put(&sbi->s_kobj);
- wait_for_completion(&sbi->s_kobj_unregister);
- }
+ filesystem_kobject_put(sbi->f_kobj);
}
int __init erofs_init_sysfs(void)
diff --git a/fs/erofs/sysfs.c b/fs/erofs/sysfs.c index 435e515c0792..daac23e32026 100644 --- a/fs/erofs/sysfs.c +++ b/fs/erofs/sysfs.c @@ -240,8 +240,7 @@ void erofs_unregister_sysfs(struct super_block *sb) { struct erofs_sb_info *sbi = EROFS_SB(sb); - if (sbi->s_kobj.state_in_sysfs) { - kobject_del(&sbi->s_kobj); + if (kobject_is_added(&sbi->s_kobj)) { kobject_put(&sbi->s_kobj); wait_for_completion(&sbi->s_kobj_unregister); }