From patchwork Fri Nov 20 22:13:19 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 7671671 Return-Path: X-Original-To: patchwork-linux-scsi@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 0AA8A9F392 for ; Fri, 20 Nov 2015 22:13:29 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 000D62052A for ; Fri, 20 Nov 2015 22:13:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D7522204D5 for ; Fri, 20 Nov 2015 22:13:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1759863AbbKTWN0 (ORCPT ); Fri, 20 Nov 2015 17:13:26 -0500 Received: from mail-bl2on0056.outbound.protection.outlook.com ([65.55.169.56]:35488 "EHLO na01-bl2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752076AbbKTWNY (ORCPT ); Fri, 20 Nov 2015 17:13:24 -0500 Received: from BY2PR02CA0115.namprd02.prod.outlook.com (10.163.44.169) by BY2PR02MB300.namprd02.prod.outlook.com (10.141.140.26) with Microsoft SMTP Server (TLS) id 15.1.318.15; Fri, 20 Nov 2015 22:13:21 +0000 Received: from BN1AFFO11FD020.protection.gbl (2a01:111:f400:7c10::130) by BY2PR02CA0115.outlook.office365.com (2a01:111:e400:5261::41) with Microsoft SMTP Server (TLS) id 15.1.331.20 via Frontend Transport; Fri, 20 Nov 2015 22:13:21 +0000 Authentication-Results: spf=pass (sender IP is 63.163.107.173) smtp.mailfrom=sandisk.com; vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=bestguesspass action=none header.from=sandisk.com; Received-SPF: Pass (protection.outlook.com: domain of sandisk.com designates 63.163.107.173 as permitted sender) receiver=protection.outlook.com; client-ip=63.163.107.173; helo=milsmgep12.sandisk.com; Received: from milsmgep12.sandisk.com (63.163.107.173) by BN1AFFO11FD020.mail.protection.outlook.com (10.58.52.80) with Microsoft SMTP Server id 15.1.331.11 via Frontend Transport; Fri, 20 Nov 2015 22:13:20 +0000 Received: from MILHUBIP03.sdcorp.global.sandisk.com ( [172.22.12.162]) by milsmgep12.sandisk.com (Symantec Messaging Gateway) with SMTP id CB.10.32178.00B9F465; Fri, 20 Nov 2015 14:13:20 -0800 (PST) Received: from milsmgip12.sandisk.com (10.177.8.100) by MILHUBIP03.sdcorp.global.sandisk.com (10.177.9.96) with Microsoft SMTP Server id 14.3.248.2; Fri, 20 Nov 2015 14:13:19 -0800 X-AuditID: ac160a69-f79f76d000007db2-ee-564f9b00974a Received: from [10.60.52.33] ( [10.177.8.100]) by milsmgip12.sandisk.com (Symantec Messaging Gateway) with SMTP id 8F.98.04661.FFA9F465; Fri, 20 Nov 2015 14:13:19 -0800 (PST) To: James Bottomley CC: "Martin K. Petersen" , Jens Axboe , Tejun Heo , Jan Kara , "Hannes Reinecke" , Aaro Koskinen , "linux-scsi@vger.kernel.org" , From: Bart Van Assche Subject: [PATCH] Fix a bdi reregistration race, v2 Message-ID: <564F9AFF.3050605@sandisk.com> Date: Fri, 20 Nov 2015 14:13:19 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0 MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprEIsWRmVeSWpSXmKPExsWyRoxnkS7DbP8wg5VdQhZrXjhY/N9zjM1i z6JJTBazpzczWVzqXcJqcW/Nf1aL7us72CyWH//HZPFr+VFGB06Pic3v2D0Of13I4rFpVSeb x6ZPk9g9Pj69xeJxct5PNo8zC46we2w+Xe3xeZNcAGcUl01Kak5mWWqRvl0CV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8ksztZLzs/dxAgOa86oHYzXJ5ofYmTi4JRqYGy4wtn9/1O4w5cFNYLKf1tjDjz5 J3Bg9upD9+z1Gxb2qAuX/czb4/K23Z3b5vvBHQ+eWa3O3aYcvTtk/dEDTIHRVYFz219dObg8 58STY2mB3ZO0Pumy9iQlLuxz0vq/xXfzzqtVPNuPymx6Wva59PDqj1xxy0zuSP8VrnX9xhpZ G3/JpzXH7JcSS3FGoqEWc1FxIgDp/s8LGwIAAA== X-EOPAttributedMessage: 0 X-Microsoft-Exchange-Diagnostics: 1; BN1AFFO11FD020; 1:MHp3MkTgN6DTMx6AyC53KNd7K0uORdNJVyGydRFTI0yKBRXtnzrq+TK5aqEyb2tcDXQR6R6g0MTiqppPWE5doyPgMHA6Y4L4nZfcewDpNboYUYs+CAP1uJiCveWqYIQis20MjTBTFqHnTFqojMwXAMGtaFv25mZ0yPNvKpgykjAhFPCfEz5YfW6FeZaV9BCgwFFINnuzJJg5Evqph942LdZgVNPLWzuQ6/8OMOrY6ykndu6ca6sd3vemMMTaHx49mJPE/XNaxiRcHQqQnlwkWFXB7MGA4/1RWVN/JA8naw6/DcshnTeedg7dH0+jn8iq+r9rS1iNu+Pq/jowY/ClUxyfAotAEDQA7qmM1anULpkOK2PQVUR0J6U492Wgih+OgBN14ovDltW8auYKbNtYLw== X-Forefront-Antispam-Report: CIP:63.163.107.173; CTRY:US; IPV:NLI; EFV:NLI; SFV:NSPM; SFS:(10009020)(6009001)(2980300002)(438002)(189002)(199003)(51234002)(77096005)(87936001)(47776003)(5008740100001)(87266999)(5001960100002)(4001350100001)(83506001)(86362001)(59896002)(50986999)(23676002)(19580405001)(230700001)(189998001)(92566002)(81156007)(97736004)(229853001)(50466002)(106466001)(65956001)(69596002)(110136002)(65816999)(65806001)(5007970100001)(5001920100001)(64126003)(11100500001)(80316001)(586003)(33656002)(54356999)(19580395003)(36756003); DIR:OUT; SFP:1101; SCL:1; SRVR:BY2PR02MB300; H:milsmgep12.sandisk.com; FPR:; SPF:Pass; PTR:InfoDomainNonexistent; MX:1; A:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BY2PR02MB300; 2:hy3S9ixUFFRj0GuBdvHrV2OBssl8gGLKrn5EvfXdufZhREfoQHnQUxftGAlQk/5cKG8LNiUXAOr/nHZeVe4a5jU4dlSvNNLXVyHA75gNfuwL3o8SkW6nALNN78faX0pq5bJVwTq2n3yi1fi2wG81hsarzkhLsT5DuGW6TX+cnFQ=; 3:eFi3WgYBzarrNBsE8HxXTs7HSEBBuF3VEywLww9PDMZqjg0GzAYy+Ke0nAlW61zA3EzKxClOkWgK0tvfOcYxp/kML3rJ5QDZPW8IpXVlZg/XrYn0jYjIG1A51FZL35aA32Iz9+j52QlgbDqB2SS/FyW0cIKqlLhXb3AIXYLtbYalNXJ76p661zCi5RRu9n8T/dbVO3gfTEiA1q/Dp1lQU94CdT7NsahoVPIGred3jJ74yBIryc3QLYOaPY74NXeFaoqIc0cs3Bd5I5R3OIryVA==; 25:HG4aGxfwm+N0mA20xZaIqCe7fvxQm93Rciz+/sS1X2bO4DuKUjIW+cfERikCVXmJugWCMe0tHtsTf40+N4mY/xwZRDeMepxfvJBw4IdZl2VsrKGkC4GxQMFQzcvLl4riMQrVVqYdbuuJxakULMAS7sQi6rX3ip9eQs7r0OlkpXpt087qZIKludhSMoTZFH/kBENEjcpG3cR6U4QapuPuo38/HCtUKYA7jXCXIqQPWTYdXn5Bcmx9QiAXVUzxkZdkXyZpUijtGy/UVGhP8+5X/A== X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(8251501001); SRVR:BY2PR02MB300; X-Microsoft-Exchange-Diagnostics: 1; BY2PR02MB300; 20:GM3Lm0CHavq1TFmkLOcj/r7BpN76WTVlYcYBTGldlMYiBOPlZksEbtHEY7uPAJ4xseBzjTO9Y5hN0XlNyGy5Jqz38kC/0jCTcZhWt2T5orqRHgEowmdAe3U/8Zdrf9U5YWShaZxt7U9MboYQtYoqjnOdqgELlYObqgjLKq7XTxi2nWhtRmAk5peIO5tMpfpDjGD7pD2RJiOF+VqKJisXTlDjFbigNFFPx3FGiwbtBd9UOfBUpaTnKJwxdS34K+g8uRoEmA1PklVz9PzCA0H2UfhAkr1BSJSGRQ41q8YhC6Bh+8oSfvTmqpgCGxjID0PHiMGXCKXQk/ra/1wsP9A/s0GPIqede7pKGbYbp/K58/x4rBWJBLPyB6xdoIERA+/sioxYLs9oAnhQcrfmXBISRhEOYzGVBtcU+OD3ykybAJILBpMHf0ed5bJgEYqLmjUtGrgJ+0kN4yUZfF6RR8wnQOew50PKGzqiIETmdFvHlRcYS4egR2No7pa3ODjzrexo; 4:B1rlNzJM9E/4GiJPyLqDy9CMp/rxdLy9Xil4HBkNYxBZO0qDXqvjxtE3cCUGb3uekLyrRnJ5X1lro/5BD8qZ6BVVGlrRJzc+YKeaMOlOapD5slRR5qbDvAH+7cgeKSM7ad3BXNHTPVZHShnfR5J2Js7e8xNhlfI4OtqzaV/V0sJa6iEUQobpFeD1LkMTsBGVfrp15Cfzi6QgxKBK4AThhIND4gxWGTSGTIhAJ1UhaVTLwtk7rr7sKCJDvkV2DgEksg4CHTydPidUZHtaEXLg8nC8esBZqrjBTgSMdnqmQJA/ryVKGHzRppEK6Yx1+SDoiP+F8nTeor+4Ip6mZB9Hq1igyHDRF6A16Yz9vyzCVrQAbptbq746N6Llnc8Vz4omr7KXWbJRu3cNEC77KESQFw== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(42932892334569); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(2401047)(8121501046)(5005006)(520078)(10201501046)(3002001); SRVR:BY2PR02MB300; BCL:0; PCL:0; RULEID:; SRVR:BY2PR02MB300; X-Forefront-PRVS: 07665BE9D1 X-Microsoft-Exchange-Diagnostics: =?utf-8?B?MTtCWTJQUjAyTUIzMDA7MjM6dy9rR2srTmI3ODJ3UTU4VHlITGFqMkxxeS9N?= =?utf-8?B?SzFHK0FyWVlr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947vLF4GsKz3RYrTfNTMlfq4XDKFolUMS0ZvUhewKtKV5qpBxrWyUqmCgsfSGQMy0iprPW+DY1BbT8jaSnfPk9KaQScAogDpLqWwj/3tiAtKDjFmScTYTq+oKPgJNw77jbTCyMDzMFSPc7RXaOc4jPgKfO0zaoGNHT3D+6bxxy78BPfLkpBWPvTIFINcNeeQV76ctI5+ SpamDiagnosticOutput: 1:23 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: sandisk.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Nov 2015 22:13:20.3616 (UTC) X-MS-Exchange-CrossTenant-Id: fcd9ea9c-ae8c-460c-ab3c-3db42d7ac64d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=fcd9ea9c-ae8c-460c-ab3c-3db42d7ac64d; Ip=[63.163.107.173]; Helo=[milsmgep12.sandisk.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY2PR02MB300 Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org X-Spam-Status: No, score=-7.5 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Unregister and reregister BDI devices in the proper order. This patch avoids that the following kernel warning can be triggered during SCSI device reregistration: WARNING: CPU: 7 PID: 203 at fs/sysfs/dir.c:31 sysfs_warn_dup+0x68/0x80() sysfs: cannot create duplicate filename '/devices/virtual/bdi/8:32' Workqueue: events_unbound async_run_entry_fn Call Trace: [] dump_stack+0x4c/0x65 [] warn_slowpath_common+0x8a/0xc0 [] warn_slowpath_fmt+0x46/0x50 [] sysfs_warn_dup+0x68/0x80 [] sysfs_create_dir_ns+0x7e/0x90 [] kobject_add_internal+0xa8/0x320 [] kobject_add+0x60/0xb0 [] device_add+0x107/0x5e0 [] device_create_groups_vargs+0xd8/0x100 [] device_create_vargs+0x1c/0x20 [] bdi_register+0x63/0x2a0 [] bdi_register_dev+0x27/0x30 [] add_disk+0x1a9/0x4e0 [] sd_probe_async+0x119/0x1d0 [sd_mod] [] async_run_entry_fn+0x4a/0x140 [] process_one_work+0x1d8/0x7c0 [] worker_thread+0x114/0x460 [] kthread+0xf8/0x110 [] ret_from_fork+0x3f/0x70 Signed-off-by: Bart Van Assche Cc: Jens Axboe Cc: Tejun Heo Cc: Jan Kara Cc: Hannes Reinecke Cc: Aaro Koskinen Cc: --- drivers/scsi/scsi_sysfs.c | 2 ++ include/linux/backing-dev-defs.h | 1 + include/linux/backing-dev.h | 1 + mm/backing-dev.c | 28 ++++++++++++++++++++++++++-- 4 files changed, 30 insertions(+), 2 deletions(-) diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c index f5ace2b..8d64518 100644 --- a/drivers/scsi/scsi_sysfs.c +++ b/drivers/scsi/scsi_sysfs.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include @@ -1110,6 +1111,7 @@ void __scsi_remove_device(struct scsi_device *sdev) device_unregister(&sdev->sdev_dev); transport_remove_device(dev); scsi_dh_remove_device(sdev); + bdi_sysfs_del(&sdev->request_queue->backing_dev_info); device_del(dev); } else put_device(&sdev->sdev_dev); diff --git a/include/linux/backing-dev-defs.h b/include/linux/backing-dev-defs.h index 1b4d69f..1a42ecb 100644 --- a/include/linux/backing-dev-defs.h +++ b/include/linux/backing-dev-defs.h @@ -135,6 +135,7 @@ struct bdi_writeback { struct backing_dev_info { struct list_head bdi_list; + bool is_visible; unsigned long ra_pages; /* max readahead in PAGE_CACHE_SIZE units */ unsigned int capabilities; /* Device capabilities */ congested_fn *congested_fn; /* Function pointer if device is md/dm */ diff --git a/include/linux/backing-dev.h b/include/linux/backing-dev.h index c82794f..9004d90 100644 --- a/include/linux/backing-dev.h +++ b/include/linux/backing-dev.h @@ -24,6 +24,7 @@ __printf(3, 4) int bdi_register(struct backing_dev_info *bdi, struct device *parent, const char *fmt, ...); int bdi_register_dev(struct backing_dev_info *bdi, dev_t dev); +void bdi_sysfs_del(struct backing_dev_info *bdi); void bdi_unregister(struct backing_dev_info *bdi); int __must_check bdi_setup_and_register(struct backing_dev_info *, char *); diff --git a/mm/backing-dev.c b/mm/backing-dev.c index 8ed2ffd..b56971f 100644 --- a/mm/backing-dev.c +++ b/mm/backing-dev.c @@ -774,6 +774,7 @@ int bdi_init(struct backing_dev_info *bdi) int ret; bdi->dev = NULL; + bdi->is_visible = false; bdi->min_ratio = 0; bdi->max_ratio = 100; @@ -806,6 +807,7 @@ int bdi_register(struct backing_dev_info *bdi, struct device *parent, return PTR_ERR(dev); bdi->dev = dev; + bdi->is_visible = true; bdi_debug_register(bdi, dev_name(dev)); set_bit(WB_registered, &bdi->wb.state); @@ -837,6 +839,28 @@ static void bdi_remove_from_list(struct backing_dev_info *bdi) synchronize_rcu_expedited(); } +/** + * bdi_sysfs_del - remove a BDI device from sysfs + * @bdi: BDI device pointer. + * + * It is safe to call this function more than once. + */ +void bdi_sysfs_del(struct backing_dev_info *bdi) +{ + bool is_visible = false; + + spin_lock_bh(&bdi_lock); + swap(bdi->is_visible, is_visible); + spin_unlock_bh(&bdi_lock); + + if (!is_visible) + return; + + bdi_debug_unregister(bdi); + device_del(bdi->dev); +} +EXPORT_SYMBOL(bdi_sysfs_del); + void bdi_unregister(struct backing_dev_info *bdi) { /* make sure nobody finds us on the bdi_list anymore */ @@ -845,8 +869,8 @@ void bdi_unregister(struct backing_dev_info *bdi) cgwb_bdi_destroy(bdi); if (bdi->dev) { - bdi_debug_unregister(bdi); - device_unregister(bdi->dev); + bdi_sysfs_del(bdi); + put_device(bdi->dev); bdi->dev = NULL; } }