From patchwork Mon Sep 17 03:33:54 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 10602047 X-Patchwork-Delegate: snitzer@redhat.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9B84617E0 for ; Mon, 17 Sep 2018 03:34:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 89CB329761 for ; Mon, 17 Sep 2018 03:34:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7D8B929765; Mon, 17 Sep 2018 03:34:37 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id F34EB29761 for ; Mon, 17 Sep 2018 03:34:36 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5F6D8307D911; Mon, 17 Sep 2018 03:34:34 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7AB78308BDA0; Mon, 17 Sep 2018 03:34:32 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id DA38218005D0; Mon, 17 Sep 2018 03:34:28 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w8H3YR4Q026798 for ; Sun, 16 Sep 2018 23:34:27 -0400 Received: by smtp.corp.redhat.com (Postfix) id 6680D7BCDB; Mon, 17 Sep 2018 03:34:27 +0000 (UTC) Delivered-To: dm-devel@redhat.com Received: from mx1.redhat.com (ext-mx07.extmail.prod.ext.phx2.redhat.com [10.5.110.31]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 643E775550; Mon, 17 Sep 2018 03:34:21 +0000 (UTC) Received: from out002.mailprotect.be (out002.mailprotect.be [83.217.72.86]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 46ECEC049E3A; Mon, 17 Sep 2018 03:34:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mailprotect.be; s=mail; h=Content-Transfer-Encoding:MIME-Version:Message-Id :Date:Subject:Cc:To:From:reply-to:sender:bcc:in-reply-to:references: content-type; bh=a32aHTOIfYszY12+LZN43+yoCk9ROAUUvgPH9bc38hw=; b=DcRA1eEqdvEB c/iwHIO8y4AmvL8YBauIgqAfotW75Krr9JT2I4H5UV3W1OXB7xPePb7L9tnOAq/A8VWCRjCJDq+DF 4G31WqVx1aqcGy3E+FEQHvxATfS5xdhgbLP0xK2AK5rb37lvMsQFpDsq7yEaC28+h0puMsLluDlK8 xfdLOCZ9TdUhyQid5dejB+oTe+t0boGYz/siYhKNlYey0Gjowi27+TUOBGeTT+nNHiUGyAdLGiuTj FtQqv3pPMZMi0Rmwx7VRW0r9iSqFqIgS0cQy3UCSUaXJ0rXKVPm1Pm2KwhbXb6yai7P9x25TSoja0 fr1sybQ3Xx0pN2ATX5bwDQ==; Received: from smtp-auth.mailprotect.be ([178.208.39.159]) by com-mpt-out002.mailprotect.be with esmtp (Exim 4.89) (envelope-from ) id 1g1kIf-0006qJ-S5; Mon, 17 Sep 2018 05:34:14 +0200 Received: from asus.hsd1.ca.comcast.net (c-174-62-111-89.hsd1.ca.comcast.net [174.62.111.89]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp-auth.mailprotect.be (Postfix) with ESMTPSA id 35965C0495; Mon, 17 Sep 2018 05:34:08 +0200 (CEST) From: Bart Van Assche To: Mike Snitzer Date: Sun, 16 Sep 2018 20:33:54 -0700 Message-Id: <20180917033354.30745-1-bvanassche@acm.org> MIME-Version: 1.0 X-Originating-IP: 178.208.39.159 X-SpamExperts-Domain: mailprotect.be X-SpamExperts-Username: 178.208.39.128/27 Authentication-Results: mailprotect.be; auth=pass smtp.auth=178.208.39.128/27@mailprotect.be X-SpamExperts-Outgoing-Class: ham X-SpamExperts-Outgoing-Evidence: SB/global_tokens (0.002640068394) X-Recommended-Action: accept X-Filter-ID: EX5BVjFpneJeBchSMxfU5sCxA94adYb7GVq9e7mqyut602E9L7XzfQH6nu9C/Fh9KJzpNe6xgvOx q3u0UDjvO1tLifGj39bI0bcPyaJsYTZ7QK0WU3LUj3UHXzbUASm9XOOUuyetxOTKD3CqQaLHb43D tHwQUJQefogQ+Exyxm1EogtGVFY0z+8gkjv9QsJNo9WAgw1wIIm66HVoEBI92d1HYUlkuAXzEWTt Fc/rM3wA+dWWWFmTWxm5O777yhSj58fMnqZUTt7CyKlJUh+zhgP1vV5F3sfoCSK4R9Dy7hWBIw5D STRBrkTZ/s6Otz3nZK2G8IWtbTgrNeTZsO6Ph+zKwhCHdzW2nJyJhuoK++DqBGfN9ceMgMZgt75e 1zn8xrInO/MpnXjN1WRJuwFdP4p3WbibGSbJYBtA1ZdircE+PB9oHasT9LYGFAGTCUrRSAoKui/U ZqxZXW+PYL7Slxe4BPzpam1U3Cj9xZx6U4Mjle0LcSTVPooEuo2QsxqqcgXNOE5BiBPvUc+zssFN Xm1kHkAJl9I0+cmjX7E2n2Y6rDn0tTOVcmJwqI8Ju2neCJuKmef1JCbmfgcv6zoJwFJu7FDv4j45 gQXmNtbGh1mGpS+C6BPAIEs8PiiVo3EbEwkik6gMKaVf0IaQYSSecGDmnroh/8hHWR/Etfk4HCQT o4dLz8XEDoyijq2CEGKcGplHcpVCCoX989hgB8R+yKCCqjfv8OYz/CaOCJaG37snjs04wTiBXou3 brhgZNfwlrCb6Lnz+Hpp6wlw4DjlEcFtWN8kScQdq50jvk3FjoIAqiq4/ykf3NBI7bnQCAMLzKjZ Yl4zJtP0B06d0V4wiREVniihuDwEGDcmr6e3OPQANmv9bAqoyVNiejMG/mgizAR0Gxu2j7JMIaz9 VNJCBCrBcp0zW0QadxQTA67qsOEN1Z/4ymBDqm5yWSS21vtMctgzcDoFd+96Xw4QUNtTnQQnl4Zf rBmTEyuPOO9TJNQyauIF/Czj1bDAz4LnbJZxYRZ6HzXgXBCnYQkKU3lKNedKEy7bP5gIt23U7fpA nNOOuCwjXCEFYFIPENBAw9BsACze+9Z5PqxOodVH2i+afXBEn95eECKi3gxjzXac2CKjkM6s+U6v 8mROuTBeANUWBBQvOz+eHT/omN+7iKqigWKURvSolfd8/ql2ZSuoOkw= X-Report-Abuse-To: spam@com-mpt-mgt001.mailprotect.be X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 214 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Mon, 17 Sep 2018 03:34:19 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Mon, 17 Sep 2018 03:34:19 +0000 (UTC) for IP:'83.217.72.86' DOMAIN:'out002.mailprotect.be' HELO:'out002.mailprotect.be' FROM:'bvanassche@acm.org' RCPT:'' X-RedHat-Spam-Score: 0.272 (DKIM_SIGNED, DKIM_VALID, RCVD_IN_DNSWL_LOW, SPF_SOFTFAIL) 83.217.72.86 out002.mailprotect.be 83.217.72.86 out002.mailprotect.be X-Scanned-By: MIMEDefang 2.78 on 10.5.110.31 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: dm-devel@redhat.com Cc: stable@vger.kernel.org, dm-devel@redhat.com, Bart Van Assche , "Martin K . Petersen" Subject: [dm-devel] [PATCH] dm-mpath: Fix setup_scsi_dh() X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Mon, 17 Sep 2018 03:34:36 +0000 (UTC) X-Virus-Scanned: ClamAV using ClamSMTP This patch fixes two bugs that got introduced recently in setup_scsi_dh(): - Avoid that a memory leak occurs if attached_handler_name is not assigned to m->hw_handler_name. - Avoid that m->hw_handler_name becomes a dangling pointer if the RETAIN_ATTACHED_HW_HANDLER flag is set and scsi_dh_attach() returns -EBUSY. Fixes: e8f74a0f0011 ("dm mpath: eliminate need to use scsi_device_from_queue") Signed-off-by: Bart Van Assche Cc: Martin K. Petersen Cc: --- drivers/md/dm-mpath.c | 14 +++++++++----- include/scsi/scsi_device.h | 9 +++++++++ 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/drivers/md/dm-mpath.c b/drivers/md/dm-mpath.c index d94ba6f72ff5..0ba58a537182 100644 --- a/drivers/md/dm-mpath.c +++ b/drivers/md/dm-mpath.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -806,13 +807,15 @@ static int parse_path_selector(struct dm_arg_set *as, struct priority_group *pg, } static int setup_scsi_dh(struct block_device *bdev, struct multipath *m, - const char *attached_handler_name, char **error) + char **error) { struct request_queue *q = bdev_get_queue(bdev); + const char *attached_handler_name; int r; if (test_bit(MPATHF_RETAIN_ATTACHED_HW_HANDLER, &m->flags)) { retain: + attached_handler_name = scsi_dh_attached_handler_name(q, GFP_KERNEL); if (attached_handler_name) { /* * Clear any hw_handler_params associated with a @@ -867,7 +870,7 @@ static struct pgpath *parse_path(struct dm_arg_set *as, struct path_selector *ps struct pgpath *p; struct multipath *m = ti->private; struct request_queue *q; - const char *attached_handler_name; + struct scsi_device *sdev; /* we need at least a path arg */ if (as->argc < 1) { @@ -887,10 +890,11 @@ static struct pgpath *parse_path(struct dm_arg_set *as, struct path_selector *ps } q = bdev_get_queue(p->path.dev->bdev); - attached_handler_name = scsi_dh_attached_handler_name(q, GFP_KERNEL); - if (attached_handler_name || m->hw_handler_name) { + sdev = scsi_device_from_queue(q); + if (sdev) { + put_device(&sdev->sdev_gendev); INIT_DELAYED_WORK(&p->activate_path, activate_path_work); - r = setup_scsi_dh(p->path.dev->bdev, m, attached_handler_name, &ti->error); + r = setup_scsi_dh(p->path.dev->bdev, m, &ti->error); if (r) { dm_put_device(ti, p->path.dev); goto bad; diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h index 202f4d6a4342..1c839089c711 100644 --- a/include/scsi/scsi_device.h +++ b/include/scsi/scsi_device.h @@ -2,6 +2,7 @@ #ifndef _SCSI_SCSI_DEVICE_H #define _SCSI_SCSI_DEVICE_H +#include #include #include #include @@ -335,7 +336,15 @@ extern void scsi_remove_device(struct scsi_device *); extern int scsi_unregister_device_handler(struct scsi_device_handler *scsi_dh); void scsi_attach_vpd(struct scsi_device *sdev); +#if IS_ENABLED(CONFIG_SCSI) extern struct scsi_device *scsi_device_from_queue(struct request_queue *q); +#else +static inline struct scsi_device * +scsi_device_from_queue(struct request_queue *q) +{ + return NULL; +} +#endif extern int __must_check scsi_device_get(struct scsi_device *); extern void scsi_device_put(struct scsi_device *); extern struct scsi_device *scsi_device_lookup(struct Scsi_Host *,