Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp4955369rwb; Wed, 21 Sep 2022 00:41:40 -0700 (PDT) X-Google-Smtp-Source: AMsMyM71S5Y6IYylY4RuBkbd1xjlRfxQ6oZ3kMApHcoJEn6aNIuUtmDNmwUsDDcWo/u6ClLFGOGq X-Received: by 2002:a17:907:2e02:b0:77c:5020:b8ef with SMTP id ig2-20020a1709072e0200b0077c5020b8efmr19658518ejc.299.1663746099961; Wed, 21 Sep 2022 00:41:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663746099; cv=none; d=google.com; s=arc-20160816; b=0zfZXxIhEHj68+pwOSzAXL911sIArs1/UaLgWKLE2DHFQUv6l8z2TTa2nx3k1j3ZKp Frer2ntsg/xmZu4NDhap1vXuTQMAZmm48JYPeqsicPLN6XMPdhDjGVmps4sDC5VeH1Xk OVxlXWyRaJX3uj5Ms2mg1u2M5IZzRI5GM3Zk4A9P4A3NmwkaGsZ8psyjXpyd3MeXxdY7 QMdegMvWSr6yyrklLNk3vKvGY3nk+18rfltz/k2owkDEnfz8cwe6Pekl8XD9fZb7mzgy 61PWivTrqEgY48SQqPYPXl/em94P0SFdIaXYBlTtlTZJZzVYhi7/EdSzg9imtX7pDDeT F3NQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :content-language:accept-language:in-reply-to:references:message-id :date:thread-index:thread-topic:subject:cc:to:from; bh=ogn7Um5JWnk/jf2Hr0bWcqvLF7+UIVTmeLMAzdyM3Ww=; b=hr9S9qT6s7dRbEIujJrYRK05ZswNAYU6s3yZcS/OPZCWNUSquNCwefYXafQI1IjSon 0ItJvZWKGNb+07sNJn8RacfkU6ZQLpl2CMNywaINacbca+NHw//FUB8J3bHdKg53/1py X9eMSchOEb4JEHsh9UXRCmhZgxwgP4yIFzJU8G+8jTlKnaUqaKNtNYN5f3PNJwImEx9W n2kmLjAF3VJ9vf1cjKOotoahl6mcxXvnlTGsKIaZR8NUYWJiXUZ1GZP34seZtQ5cBPJS 9w0NnA0xnVXXX1U+tp6TeeL0XkQDunVPNiwf7z0M7qoWIFk4c4PRGTXtDtRLeMEl3nnr hQbQ== ARC-Authentication-Results: i=1; mx.google.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=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v1-20020a1709064e8100b0072b3a874867si1325778eju.874.2022.09.21.00.41.14; Wed, 21 Sep 2022 00:41:39 -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; 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=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229809AbiIUH1Q convert rfc822-to-8bit (ORCPT + 99 others); Wed, 21 Sep 2022 03:27:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45714 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229718AbiIUH1O (ORCPT ); Wed, 21 Sep 2022 03:27:14 -0400 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6C7737C1A2 for ; Wed, 21 Sep 2022 00:27:12 -0700 (PDT) Received: from dggemv711-chm.china.huawei.com (unknown [172.30.72.54]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4MXVHq1WPmz14QjM; Wed, 21 Sep 2022 15:23:03 +0800 (CST) Received: from kwepemm000007.china.huawei.com (7.193.23.189) by dggemv711-chm.china.huawei.com (10.1.198.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Wed, 21 Sep 2022 15:27:09 +0800 Received: from lhrpeml500005.china.huawei.com (7.191.163.240) by kwepemm000007.china.huawei.com (7.193.23.189) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Wed, 21 Sep 2022 15:27:08 +0800 Received: from lhrpeml500005.china.huawei.com ([7.191.163.240]) by lhrpeml500005.china.huawei.com ([7.191.163.240]) with mapi id 15.01.2375.031; Wed, 21 Sep 2022 08:27:06 +0100 From: Shameerali Kolothum Thodi To: liulongfang , Jason Gunthorpe , Alex Williamson CC: "cohuck@redhat.com" , "linux-kernel@vger.kernel.org" , "linuxarm@openeuler.org" Subject: RE: [PATCH 1/5] hisi_acc_vfio_pci: Fixes a memory leak bug Thread-Topic: [PATCH 1/5] hisi_acc_vfio_pci: Fixes a memory leak bug Thread-Index: AQHYyKNl0n81Lxv0MUKz8I4GKo4bYq3oe7uAgAABAQCAABOTkIAAneEAgABVjQA= Date: Wed, 21 Sep 2022 07:27:06 +0000 Message-ID: References: <20220915013157.60771-1-liulongfang@huawei.com> <20220915013157.60771-2-liulongfang@huawei.com> <20220920103443.72654dd7.alex.williamson@redhat.com> <04a17bfa71c440e8a38cba2337a8c6ac@huawei.com> In-Reply-To: Accept-Language: en-GB, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.202.227.178] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 8BIT MIME-Version: 1.0 X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=ham 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: X-Mailing-List: linux-kernel@vger.kernel.org > -----Original Message----- > From: liulongfang > Sent: 21 September 2022 04:13 > To: Shameerali Kolothum Thodi ; > Jason Gunthorpe ; Alex Williamson > > Cc: cohuck@redhat.com; linux-kernel@vger.kernel.org; > linuxarm@openeuler.org > Subject: Re: [PATCH 1/5] hisi_acc_vfio_pci: Fixes a memory leak bug > > On 2022/9/21 1:03, Shameerali Kolothum Thodi wrote: > > > > > >> -----Original Message----- > >> From: Jason Gunthorpe [mailto:jgg@nvidia.com] > >> Sent: 20 September 2022 17:38 > >> To: Alex Williamson > >> Cc: liulongfang ; Shameerali Kolothum Thodi > >> ; cohuck@redhat.com; > >> linux-kernel@vger.kernel.org; linuxarm@openeuler.org > >> Subject: Re: [PATCH 1/5] hisi_acc_vfio_pci: Fixes a memory leak bug > >> > >> On Tue, Sep 20, 2022 at 10:34:43AM -0600, Alex Williamson wrote: > >>> On Thu, 15 Sep 2022 09:31:53 +0800 > >>> Longfang Liu wrote: > >>> > >>>> During the stop copy phase of live migration, the driver allocates a > >>>> memory for the migrated data to save the data. > >>>> > >>>> When an exception occurs when the driver reads device data, the > >>>> driver will report an error to qemu and exit the current migration state. > >>>> But this memory is not released, which will lead to a memory leak > >>>> problem. > >> > >> Why isn't it released? The fput() releases it: > >> > >> static int hisi_acc_vf_release_file(struct inode *inode, struct file *filp) { > >> struct hisi_acc_vf_migration_file *migf = filp->private_data; > >> > >> hisi_acc_vf_disable_fd(migf); > >> mutex_destroy(&migf->lock); > >> kfree(migf); > >> ^^^^^^^^^^ > >> > >> This patch looks wrong to me. > > > > That's right. Missed that. Sorry of the oversight. > > > Yes, fput will call release in ops of file, here will call hisi_acc_vf_release_file > to complete the release operation of migf, so this patch is unnecessary. > > But there is another place that needs to be modified: > hisi_acc_vf_disable_fd in hisi_acc_vf_disable_fds is not needed, > because it will have an fput next. Is this correct? I don't think that is correct either. fput() decrements ref count and will only call release() if the count is zero. We have an explicit get_file() for the hisi_acc_vf_disable_fds(). Isn't it? Thanks, Shameer > > Thanks, > > Shameer > > > > . > Thanks, > Longfang. > >