Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751378AbdFFHfd convert rfc822-to-8bit (ORCPT ); Tue, 6 Jun 2017 03:35:33 -0400 Received: from mx1.redhat.com ([209.132.183.28]:40102 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750881AbdFFHfc (ORCPT ); Tue, 6 Jun 2017 03:35:32 -0400 DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com A51DAC049D5B Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kraxel@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com A51DAC049D5B Message-ID: <1496734528.15129.2.camel@redhat.com> Subject: Re: [PATCH v6 6/6] drm/i915/gvt: Adding interface so user space can get the dma-buf From: Gerd Hoffmann To: "Chen, Xiaoguang" , Alex Williamson Cc: "Tian, Kevin" , "intel-gfx@lists.freedesktop.org" , "linux-kernel@vger.kernel.org" , "zhenyuw@linux.intel.com" , "chris@chris-wilson.co.uk" , "Lv, Zhiyuan" , "intel-gvt-dev@lists.freedesktop.org" , "Wang, Zhi A" Date: Tue, 06 Jun 2017 09:35:28 +0200 In-Reply-To: References: <1495874332-2851-1-git-send-email-xiaoguang.chen@intel.com> <1495874332-2851-7-git-send-email-xiaoguang.chen@intel.com> <20170601120820.3358f7dd@w520.home> <20170601213459.461ecf36@w520.home> <20170602085831.41454a1f@t450s.home> <1496417038.16895.7.camel@redhat.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8BIT Mime-Version: 1.0 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Tue, 06 Jun 2017 07:35:31 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 694 Lines: 18 Hi, > > Why the ref count is one?   > > The gem object is created by us while creating the dma-buf(the ref > count of the gem object is initialized to 1). > Later when user import the dma-buf the ref count of the gem object > associate with the dma-buf will increased. Creating the dma-buf should increase the gem object reference count too. So you should be able to unref the gem object after creating the dma-buf. That way the dma-buf is the only instance holding a reference to the gem object, and when the dma-buf goes away (due to userspace closing all file handles referring to it) the gem object will be released too because the refcount goes down to zero then. cheers, Gerd