Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp3623044img; Mon, 25 Mar 2019 14:13:13 -0700 (PDT) X-Google-Smtp-Source: APXvYqzFACZGlemGqg0WOASieKVAWXkvUEsXb+E3MHusn/S9vAyWdfQZ+ZHKT4VzlmECbGzJKtGX X-Received: by 2002:a63:4f43:: with SMTP id p3mr25489901pgl.207.1553548393197; Mon, 25 Mar 2019 14:13:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553548393; cv=none; d=google.com; s=arc-20160816; b=BOxzZho/b7rzc4N4nlaQQZuSj0kOHhm6RCxi6M5xT3KhHPTEnVX+UWy8NAsmZCKkZp JbGvA5DcG3UyHsBTC4f2tkOWYuLBdGAchRKdOA0hB66x+/YWj8yxeXjttg5l/msDMbzc Px0MGiaxwho0zCLOvxt5TiTRVKZwzgguxzwDnwWV6RZxk5uPv6RUzKmBmj4gfg1fyz2H BvGhHcxY+z+PupDs17Gkg2KLIN7iQx23o0RzWbH4z5Pq+6aBnYYNxXtptKaOyD30blt9 61uXIfBUv4WrcMFbAiBzyGJZoSUWJTZUMgTo7SS/S79iUt6uu5JpgqpIuv/Uxsy6Q1EO GV+w== 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 :content-language:accept-language:in-reply-to:references:message-id :date:thread-index:thread-topic:subject:cc:to:from:dkim-signature; bh=cAwPvXsCWZ3cpcvf9QbzipmitR/zHEsIecZYq3OfFf8=; b=grhek6wTyLA9lht46+0xRrjdVF1Kl9jVyqUDkKjsiuObETBAHGSAgMxmL1xUpfWddB LCvXJS64deX0BohMF74DhZdPbTD0xBVEvuuvHFGIu95c5MoPoXHT3+0rj9G4BuCw/x2u 0N1lmjPfcvSEhYiMiuZCUMbzM0VgjuYlWuQToyuoA7xe/2Ln9tVIKxuw7uJKoX54gb4g KTC2eCKYJCk4x6cGvlg7EpqEAA5z8EGl6KW0ICJTIMhMvszOr5zZCze3gbZ+YblqDdzZ kYnJ1lh9KIyb/MmFgTLaqFHQHECFphKEjT2lZ4Om/ZeWSnscls++cpCQE08bqaudVfdi dlYg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@Mellanox.com header.s=selector1 header.b=V+bk5GRP; 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=NONE sp=NONE dis=NONE) header.from=mellanox.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d6si15241077plr.246.2019.03.25.14.12.57; Mon, 25 Mar 2019 14:13:13 -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=@Mellanox.com header.s=selector1 header.b=V+bk5GRP; 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=NONE sp=NONE dis=NONE) header.from=mellanox.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730399AbfCYVMD (ORCPT + 99 others); Mon, 25 Mar 2019 17:12:03 -0400 Received: from mail-eopbgr70088.outbound.protection.outlook.com ([40.107.7.88]:52102 "EHLO EUR04-HE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1729569AbfCYVMD (ORCPT ); Mon, 25 Mar 2019 17:12:03 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Mellanox.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=cAwPvXsCWZ3cpcvf9QbzipmitR/zHEsIecZYq3OfFf8=; b=V+bk5GRP9Ge/kOY0ih11e/knq+OJ+MZPP+SLWSw//YXn8FH4H/OQc4if19NGT/LoEbahX2Ch1lzQ/iJxNL9nrN0fd39g1LJgZhQBTsg79ctf/O/nlJI9v8PWRIaQQ9Wp1RyoXoj61RdStZmm1epUae3fA54l37vgBZ2FNnpgNDE= Received: from VI1PR0501MB2271.eurprd05.prod.outlook.com (10.169.135.8) by VI1PR0501MB2749.eurprd05.prod.outlook.com (10.172.11.11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1730.16; Mon, 25 Mar 2019 21:11:58 +0000 Received: from VI1PR0501MB2271.eurprd05.prod.outlook.com ([fe80::a0b8:7ed8:d657:2f59]) by VI1PR0501MB2271.eurprd05.prod.outlook.com ([fe80::a0b8:7ed8:d657:2f59%6]) with mapi id 15.20.1730.019; Mon, 25 Mar 2019 21:11:58 +0000 From: Parav Pandit To: Alex Williamson , Kirti Wankhede CC: "kvm@vger.kernel.org" , "linux-kernel@vger.kernel.org" Subject: RE: [PATCH 1/8] vfio/mdev: Fix to not do put_device on device_register failure Thread-Topic: [PATCH 1/8] vfio/mdev: Fix to not do put_device on device_register failure Thread-Index: AQHU4QX8efp2y+k+mUSt3U8lp+tcVaYcq/gAgAAR3oCAAB6vMA== Date: Mon, 25 Mar 2019 21:11:58 +0000 Message-ID: References: <1553296835-37522-1-git-send-email-parav@mellanox.com> <1553296835-37522-2-git-send-email-parav@mellanox.com> <2c096714-74cd-48ff-496f-b3919990e3e5@nvidia.com> <20190325132127.7430864b@x1.home> In-Reply-To: <20190325132127.7430864b@x1.home> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: spf=none (sender IP is ) smtp.mailfrom=parav@mellanox.com; x-originating-ip: [208.176.44.194] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 22141de8-91f6-4ecc-2567-08d6b1668439 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0;PCL:0;RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600127)(711020)(4605104)(4618075)(2017052603328)(7153060)(7193020);SRVR:VI1PR0501MB2749; x-ms-traffictypediagnostic: VI1PR0501MB2749: x-microsoft-antispam-prvs: x-forefront-prvs: 0987ACA2E2 x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(136003)(346002)(396003)(366004)(39860400002)(376002)(189003)(199004)(13464003)(99286004)(316002)(3846002)(7736002)(186003)(446003)(11346002)(486006)(476003)(55016002)(9686003)(25786009)(26005)(4326008)(6246003)(6436002)(5660300002)(110136005)(229853002)(6116002)(93886005)(305945005)(52536014)(14444005)(97736004)(86362001)(8936002)(2906002)(102836004)(66066001)(76176011)(105586002)(478600001)(6506007)(53546011)(256004)(54906003)(71190400001)(71200400001)(74316002)(53936002)(68736007)(33656002)(81156014)(81166006)(8676002)(14454004)(7696005)(106356001);DIR:OUT;SFP:1101;SCL:1;SRVR:VI1PR0501MB2749;H:VI1PR0501MB2271.eurprd05.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; received-spf: None (protection.outlook.com: mellanox.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: 5E0bOlDo0retosB2Z21Ri/OOFO+KNYv3Lcnh5aKg4yN3P9EqXhl7mPeRBTVuLnaZtBmd3Z1b2YIpEmd1WTMib2XchUVkb72atVwVtc+5W5C/YKMR3+IBuSyO2jfOonZTuKF3HZIp6bGLV6lYjU7xwFINi/X8ykIYMZCacKYRnUnCOZdixvtwi6Encu91bpfx/wxVZaDxQ4ZVs1EvcQU5lUMykm/7YL5otTUqY8oAmoqJBBfaRwWY4Vu/Ac7xNZRopzsouHtHx1+GAvEVCWhoZs/BKRm5d0ibBxj+r7C9eE++PPvboPAg1nfi2ovYv+MG8OmPDnPmrNl2xxUbHk/KvT5Uy+mVK04TIDunGY4wj6BUPSOKZwYY8fSBoBQGxBb6QlnV6exmEQKs/To0C6ZWzkQrWRfvFMX8zkRiQ9wv18w= Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: Mellanox.com X-MS-Exchange-CrossTenant-Network-Message-Id: 22141de8-91f6-4ecc-2567-08d6b1668439 X-MS-Exchange-CrossTenant-originalarrivaltime: 25 Mar 2019 21:11:58.1280 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: a652971c-7d2e-4d9b-a6a4-d149256f461b X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0501MB2749 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > -----Original Message----- > From: Alex Williamson > Sent: Monday, March 25, 2019 2:21 PM > To: Kirti Wankhede > Cc: Parav Pandit ; kvm@vger.kernel.org; linux- > kernel@vger.kernel.org > Subject: Re: [PATCH 1/8] vfio/mdev: Fix to not do put_device on > device_register failure >=20 > On Mon, 25 Mar 2019 23:47:30 +0530 > Kirti Wankhede wrote: >=20 > > On 3/23/2019 4:50 AM, Parav Pandit wrote: > > > device_register() performs put_device() if device_add() fails. > > > This balances with device_initialize(). > > > > > > mdev core performing put_device() when device_register() fails, is > > > an error that puts already released device again. > > > Therefore, don't put the device on error. > > > > > > > device_add() on all errors doesn't call put_device(dev). It releases > > reference to its parent, put_device(parent), but not the device > > itself, put_device(dev). >=20 > Sort of, device_initialize() initializes the reference count to 1, > device_add() increments the reference count to 2 via the get_device() and > then drops it back to 1 on all exit paths. The oddity is the failure pat= h of > get_device() itself, but that can only happen if passed a NULL device, wh= ere > put_device() is a no-op and not relevant here. So in all cases > device_register() returns with a reference count of 1 and we need to call > put_device() to free the allocated object. The below change would leak t= he > mdev on error. Thanks, >=20 Yes. I missed the NOTE at the starting of device_add() comment block. I will drop this patch in series. > Alex >=20 > > > Fixes: 7b96953bc640 ("vfio: Mediated device Core driver") > > > Signed-off-by: Parav Pandit > > > --- > > > drivers/vfio/mdev/mdev_core.c | 4 +--- > > > 1 file changed, 1 insertion(+), 3 deletions(-) > > > > > > diff --git a/drivers/vfio/mdev/mdev_core.c > > > b/drivers/vfio/mdev/mdev_core.c index 0212f0e..3e5880a 100644 > > > --- a/drivers/vfio/mdev/mdev_core.c > > > +++ b/drivers/vfio/mdev/mdev_core.c > > > @@ -318,10 +318,8 @@ int mdev_device_create(struct kobject *kobj, > struct device *dev, uuid_le uuid) > > > dev_set_name(&mdev->dev, "%pUl", uuid.b); > > > > > > ret =3D device_register(&mdev->dev); > > > - if (ret) { > > > - put_device(&mdev->dev); > > > + if (ret) > > > goto mdev_fail; > > > - } > > > > > > ret =3D mdev_device_create_ops(kobj, mdev); > > > if (ret) > > >