Received: by 10.213.65.68 with SMTP id h4csp1857020imn; Mon, 19 Mar 2018 15:23:49 -0700 (PDT) X-Google-Smtp-Source: AG47ELucTbZLihBx3ysMzSBiiqipXeXelTmTeKG5doT9eJS5MBybQaSU6dC52uA0XfplMft9m7PH X-Received: by 10.101.87.138 with SMTP id b10mr10309707pgr.241.1521498229522; Mon, 19 Mar 2018 15:23:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521498229; cv=none; d=google.com; s=arc-20160816; b=BEV+0s4q0glHTmKjqY4wFQ8Z2VHF8x3iXfzQNEtjPYXcT33knYzQwAyduX0kA3hyvR PeL7evr146u7VbNp5Vz+iL43gDgQipIAP6DQe+p0SlIHINRPvbo47sgYTbx4pdLBbmZi fzb10uHGjytkDa31UCn0MZWL2u6jJ8Vj68OfcFqFg3KP5J+H3KVg1cSmZ/Gcebhouc7h InAOI+QRN1pa0RZZy8nPC1BBEkMv2yDddKo8yPgBSVrnTdhqSle3MpRy8RXTd2z/ExIV MW0fufgoDnUH+pq7LxBKM4ZTx1sBVBfAmqeG6MkdWB7Rv64ZGleHTQeUK15aHhiUk0RJ almg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :spamdiagnosticmetadata:spamdiagnosticoutput:content-language :accept-language:in-reply-to:references:message-id:date:thread-index :thread-topic:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=oGDDqD0frAx5ljHvI0dgTrR5/iwBWns/Bxf52Nmz+Ao=; b=hRjLGoPzCuGb6LUnfwhYoiu738iAp32oc/JEysDF7no52aaIjkE0IWv8fyPp24qr1r a6/hSXjwENimmaMdHqAohm+SCcOzn9smHMcqgzZlu0iJU6SYNqmLlo3IBEGeisX+cU6m bvTe8jJWRLwCck2XvFytSqfljtoBJykRyubYntkB3KOmNF+f0D38dYfvYs5myioGuQ1V bYfdjGLbf88CL0YdTpLyFnxmKKlNZb0RMIN6CYHiQPHXSUW8jnDSt85nV77aumhxo/ha MTSqhHxJY2+fx3BYTJzQ75lfEME656bb02DyTtLebfvADIO+AbX6Bl3hPoT6P+6IoPp7 1nrQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=B6U4RR4q; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m11si134564pgc.243.2018.03.19.15.23.35; Mon, 19 Mar 2018 15:23:49 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=B6U4RR4q; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933919AbeCSPtO (ORCPT + 99 others); Mon, 19 Mar 2018 11:49:14 -0400 Received: from mail-sn1nam02on0103.outbound.protection.outlook.com ([104.47.36.103]:38940 "EHLO NAM02-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S933841AbeCSPsx (ORCPT ); Mon, 19 Mar 2018 11:48:53 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=oGDDqD0frAx5ljHvI0dgTrR5/iwBWns/Bxf52Nmz+Ao=; b=B6U4RR4qMwtYNfaj5YpcWUe+VBk0nDthoNumC4DEZoymAxDIz+Ln0dC80SS/k0XXZOWw4UL50Q2JRTMG8eTvaTfOkP2wVkyfy7q1DRzB8fvL20INoZh8gvhJDxK9Csu6CKFRI7tj+qViNy/kEr5KDXNnOXiZKHaSPp5QJu0SqpU= Received: from DM5PR2101MB1032.namprd21.prod.outlook.com (52.132.128.13) by DM5PR2101MB0936.namprd21.prod.outlook.com (52.132.131.166) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.609.2; Mon, 19 Mar 2018 15:48:49 +0000 Received: from DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::3d9b:79e7:94eb:5d62]) by DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::3d9b:79e7:94eb:5d62%5]) with mapi id 15.20.0631.004; Mon, 19 Mar 2018 15:48:49 +0000 From: Sasha Levin To: "linux-kernel@vger.kernel.org" , "stable@vger.kernel.org" CC: James Smart , James Smart , Christoph Hellwig , Sasha Levin Subject: [PATCH AUTOSEL for 4.15 062/124] nvme_fcloop: disassocate local port structs Thread-Topic: [PATCH AUTOSEL for 4.15 062/124] nvme_fcloop: disassocate local port structs Thread-Index: AQHTv5msh2l3On71iE6FWf7DlbD/vw== Date: Mon, 19 Mar 2018 15:48:06 +0000 Message-ID: <20180319154645.11350-62-alexander.levin@microsoft.com> References: <20180319154645.11350-1-alexander.levin@microsoft.com> In-Reply-To: <20180319154645.11350-1-alexander.levin@microsoft.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [52.168.54.252] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;DM5PR2101MB0936;7:3rWlzMu6TRRDWvlXiTgH7Jx6k/LL5zkCKtdOTjLVLUJ7jj32eXoXfai9aZ0vt3naZ6vxhOr58dPcG32wOT9JrBF9GXUqa5iIKN7QEbMJCGz3meATP/k/6Rx8jYfDymFeV9uWDtE8KboGbNsjafnWgSnX3ui6okfKd4IfrkPWXiYJz72Ngvvxvy28qCpJpLdkz75SIVOmbUI4vRUm8ByRr0foc/tsPefK66SP1i7024ZeDxiuGxjjQtfEJgbd91qw;20:nPSwjS87ldPiYK/08uUeyxhVFpB3wH+NSJE004dixvoSRMbaEgvchgwcoojLftTtASACsdCntAKyKyi8PB1GIyLHhwDE5Dgqr00+wx/ITm6213ORF3YrMNroF8d/Vqj35dNrfsRLQFxmdspmm1EFSVw/YRK6/S+wNtD6nGZLveQ= x-ms-office365-filtering-ht: Tenant x-ms-office365-filtering-correlation-id: 9d42994a-f1c6-4f40-eca3-08d58db0e868 x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(48565401081)(5600026)(4604075)(3008032)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7193020);SRVR:DM5PR2101MB0936; x-ms-traffictypediagnostic: DM5PR2101MB0936: x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(28532068793085)(89211679590171)(85827821059158); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(8211001083)(61425038)(6040522)(2401047)(5005006)(8121501046)(10201501046)(3002001)(93006095)(93001095)(3231221)(944501300)(52105095)(6055026)(61426038)(61427038)(6041310)(20161123558120)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123564045)(20161123560045)(20161123562045)(6072148)(201708071742011);SRVR:DM5PR2101MB0936;BCL:0;PCL:0;RULEID:;SRVR:DM5PR2101MB0936; x-forefront-prvs: 06167FAD59 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(39380400002)(346002)(39860400002)(366004)(376002)(396003)(199004)(189003)(2900100001)(3280700002)(2950100002)(10290500003)(66066001)(106356001)(76176011)(86612001)(6666003)(478600001)(5250100002)(6512007)(6486002)(107886003)(36756003)(97736004)(72206003)(25786009)(6436002)(53936002)(7736002)(2501003)(54906003)(110136005)(105586002)(10090500001)(2906002)(86362001)(305945005)(5660300001)(316002)(8676002)(6346003)(1076002)(3846002)(3660700001)(81156014)(4326008)(14454004)(26005)(6116002)(102836004)(8936002)(81166006)(6506007)(186003)(22452003)(39060400002)(59450400001)(99286004)(68736007)(575784001)(22906009)(217873001);DIR:OUT;SFP:1102;SCL:1;SRVR:DM5PR2101MB0936;H:DM5PR2101MB1032.namprd21.prod.outlook.com;FPR:;SPF:None;PTR:InfoNoRecords;A:1;MX:1;LANG:en; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) authentication-results: spf=none (sender IP is ) smtp.mailfrom=Alexander.Levin@microsoft.com; x-microsoft-antispam-message-info: DyrVJpfKEyqI+77x2M0qhneKL8csL5/JtwpOBWO3CGOJvIPwD13BgpJhOV/RRKS9yYE6FTGs+k40ckbLAZ2uCti0+RmU5g9B0RO5YIGAiHhwUOuyZO1YiC/YDvnQQ2pJQpFsLn+je+MIcAXg2bvcrauHZ1cCtb4IQe8RpieofB8q35Nh859xwF9jabtQS7iNpeE2X6B76840TI1E01a8EJMrl4NPx0/n6UBY/wvCM+v930rB6ISaAjSns4FQLyadk77n3eBmeg0zgXF1C549tbFRPIVg449MxmYn1Jj9fyi5UkLw+lLcBhcaUBCIQUv1Llpwli26wMuAshbp66ToVA== spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9d42994a-f1c6-4f40-eca3-08d58db0e868 X-MS-Exchange-CrossTenant-originalarrivaltime: 19 Mar 2018 15:48:06.6264 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR2101MB0936 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: James Smart [ Upstream commit 6fda20283e55b9d288cd56822ce39fc8e64f2208 ] The current fcloop driver gets its lport structure from the private area co-allocated with the fc_localport. All is fine except the teardown path, which wants to wait on the completion, which is marked complete by the delete_localport callback performed after unregister_localport. The issue is, the nvme_fc transport frees the localport structure immediately after delete_localport is called, meaning the original routine is trying to wait on a complete that was just freed. Change such that a lport struct is allocated coincident with the addition and registration of a localport. The private area of the localport now contains just a backpointer to the real lport struct. Now, the completion can be waited for, and after completing, the new structure can be kfree'd. Signed-off-by: James Smart Signed-off-by: Christoph Hellwig Signed-off-by: Sasha Levin --- drivers/nvme/target/fcloop.c | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/drivers/nvme/target/fcloop.c b/drivers/nvme/target/fcloop.c index 6a018a0bd6ce..bedb66521a4a 100644 --- a/drivers/nvme/target/fcloop.c +++ b/drivers/nvme/target/fcloop.c @@ -204,6 +204,10 @@ struct fcloop_lport { struct completion unreg_done; }; =20 +struct fcloop_lport_priv { + struct fcloop_lport *lport; +}; + struct fcloop_rport { struct nvme_fc_remote_port *remoteport; struct nvmet_fc_target_port *targetport; @@ -657,7 +661,8 @@ fcloop_nport_get(struct fcloop_nport *nport) static void fcloop_localport_delete(struct nvme_fc_local_port *localport) { - struct fcloop_lport *lport =3D localport->private; + struct fcloop_lport_priv *lport_priv =3D localport->private; + struct fcloop_lport *lport =3D lport_priv->lport; =20 /* release any threads waiting for the unreg to complete */ complete(&lport->unreg_done); @@ -697,7 +702,7 @@ static struct nvme_fc_port_template fctemplate =3D { .max_dif_sgl_segments =3D FCLOOP_SGL_SEGS, .dma_boundary =3D FCLOOP_DMABOUND_4G, /* sizes of additional private data for data structures */ - .local_priv_sz =3D sizeof(struct fcloop_lport), + .local_priv_sz =3D sizeof(struct fcloop_lport_priv), .remote_priv_sz =3D sizeof(struct fcloop_rport), .lsrqst_priv_sz =3D sizeof(struct fcloop_lsreq), .fcprqst_priv_sz =3D sizeof(struct fcloop_ini_fcpreq), @@ -728,11 +733,17 @@ fcloop_create_local_port(struct device *dev, struct d= evice_attribute *attr, struct fcloop_ctrl_options *opts; struct nvme_fc_local_port *localport; struct fcloop_lport *lport; - int ret; + struct fcloop_lport_priv *lport_priv; + unsigned long flags; + int ret =3D -ENOMEM; + + lport =3D kzalloc(sizeof(*lport), GFP_KERNEL); + if (!lport) + return -ENOMEM; =20 opts =3D kzalloc(sizeof(*opts), GFP_KERNEL); if (!opts) - return -ENOMEM; + goto out_free_lport; =20 ret =3D fcloop_parse_options(opts, buf); if (ret) @@ -752,23 +763,25 @@ fcloop_create_local_port(struct device *dev, struct d= evice_attribute *attr, =20 ret =3D nvme_fc_register_localport(&pinfo, &fctemplate, NULL, &localport)= ; if (!ret) { - unsigned long flags; - /* success */ - lport =3D localport->private; + lport_priv =3D localport->private; + lport_priv->lport =3D lport; + lport->localport =3D localport; INIT_LIST_HEAD(&lport->lport_list); =20 spin_lock_irqsave(&fcloop_lock, flags); list_add_tail(&lport->lport_list, &fcloop_lports); spin_unlock_irqrestore(&fcloop_lock, flags); - - /* mark all of the input buffer consumed */ - ret =3D count; } =20 out_free_opts: kfree(opts); +out_free_lport: + /* free only if we're going to fail */ + if (ret) + kfree(lport); + return ret ? ret : count; } =20 @@ -790,6 +803,8 @@ __wait_localport_unreg(struct fcloop_lport *lport) =20 wait_for_completion(&lport->unreg_done); =20 + kfree(lport); + return ret; } =20 --=20 2.14.1