Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752161AbcKCEaH (ORCPT ); Thu, 3 Nov 2016 00:30:07 -0400 Received: from mail-pf0-f194.google.com ([209.85.192.194]:36141 "EHLO mail-pf0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751056AbcKCEaF (ORCPT ); Thu, 3 Nov 2016 00:30:05 -0400 Subject: Re: [Qemu-devel] [PATCH v9 04/12] vfio iommu: Add support for mediated devices To: Kirti Wankhede , Jike Song References: <1476739332-4911-1-git-send-email-kwankhede@nvidia.com> <1476739332-4911-5-git-send-email-kwankhede@nvidia.com> <62ade373-6edc-c7f3-c205-200cf4fd211f@nvidia.com> <45b517de-3766-e96b-fec0-2b77da4dcf8d@nvidia.com> <695ca09f-b332-d33a-22fb-073f03dfaebf@ozlabs.ru> <5819DA45.9000200@intel.com> <64066f1a-3d25-fede-f383-078b5f8f0fa0@nvidia.com> <5819E358.4080706@intel.com> <4918e17b-b586-1e6e-aa47-f3fcdd3c660d@nvidia.com> Cc: alex.williamson@redhat.com, pbonzini@redhat.com, kraxel@redhat.com, cjia@nvidia.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, kevin.tian@intel.com, qemu-devel@nongnu.org, bjsdjshi@linux.vnet.ibm.com From: Alexey Kardashevskiy Message-ID: Date: Thu, 3 Nov 2016 15:29:54 +1100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 MIME-Version: 1.0 In-Reply-To: <4918e17b-b586-1e6e-aa47-f3fcdd3c660d@nvidia.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="J692Obim36hrERjOIEFvI6MAPn5DqWF1U" Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 4585 Lines: 122 This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --J692Obim36hrERjOIEFvI6MAPn5DqWF1U Content-Type: multipart/mixed; boundary="L91RrLlXU908TcCPBEDABWpi1x644t9TM"; protected-headers="v1" From: Alexey Kardashevskiy To: Kirti Wankhede , Jike Song Cc: alex.williamson@redhat.com, pbonzini@redhat.com, kraxel@redhat.com, cjia@nvidia.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, kevin.tian@intel.com, qemu-devel@nongnu.org, bjsdjshi@linux.vnet.ibm.com Message-ID: Subject: Re: [Qemu-devel] [PATCH v9 04/12] vfio iommu: Add support for mediated devices References: <1476739332-4911-1-git-send-email-kwankhede@nvidia.com> <1476739332-4911-5-git-send-email-kwankhede@nvidia.com> <62ade373-6edc-c7f3-c205-200cf4fd211f@nvidia.com> <45b517de-3766-e96b-fec0-2b77da4dcf8d@nvidia.com> <695ca09f-b332-d33a-22fb-073f03dfaebf@ozlabs.ru> <5819DA45.9000200@intel.com> <64066f1a-3d25-fede-f383-078b5f8f0fa0@nvidia.com> <5819E358.4080706@intel.com> <4918e17b-b586-1e6e-aa47-f3fcdd3c660d@nvidia.com> In-Reply-To: <4918e17b-b586-1e6e-aa47-f3fcdd3c660d@nvidia.com> --L91RrLlXU908TcCPBEDABWpi1x644t9TM Content-Type: text/plain; charset=koi8-r Content-Transfer-Encoding: quoted-printable On 03/11/16 00:18, Kirti Wankhede wrote: >=20 >=20 > On 11/2/2016 6:30 PM, Jike Song wrote: >> On 11/02/2016 08:41 PM, Kirti Wankhede wrote: >>> On 11/2/2016 5:51 PM, Jike Song wrote: >>>> On 11/02/2016 12:09 PM, Alexey Kardashevskiy wrote: >>>>> Or you could just reference and use @mm as KVM and others do. Or th= ere is >>>>> anything else you need from @current than just @mm? >>>>> >>>> >>>> I agree. If @mm is the only thing needed, there is really no reason = to >>>> refer to the @task :-) >>>> >>> >>> In vfio_lock_acct(), that is for page accounting, if mm->mmap_sem is >>> already held then page accounting is deferred, where task structure i= s >>> used to get mm and work is deferred only if mm exist: >>> mm =3D get_task_mm(task); get_task_mm() increments mm_users which is basically a number of userspac= es holding the reference to mm. As this case it is not a userspace, mm_count= needs to be incremented imho. >>> >>> That is where this module need task structure. >> >> Kirti, >> >> By calling get_task_mm you hold a ref on @mm and save it in iommu, >> whenever you want to do something like vfio_lock_acct(), use that mm >> (as you said, if mmap_sem not accessible then defer it to a work, but >> still @mm is the whole information), and put it after the usage. >> >> I still can't see any reason that the @task have to be saved. It's >> always the @mm all the time. Did I miss anything? >> >=20 > If the process is terminated by SIGKILL, as Alexey mentioned in this > mail thread earlier exit_mm() is called first and then all files are > closed. From exit_mm(), task->mm is set to NULL. So from teardown path,= > we should call get_task_mm(task) =2E.. which will return NULL, no? > to get current status intsead of using > stale pointer. If you increment either mm_users or mm_count at the exact place where you= want to cache task pointer, why would mm pointer become stale until you d= o mmdrop() or mmput()? --=20 Alexey --L91RrLlXU908TcCPBEDABWpi1x644t9TM-- --J692Obim36hrERjOIEFvI6MAPn5DqWF1U Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQIrBAEBCAAVBQJYGr1CDhxhaWtAb3psYWJzLnJ1AAoJEIYTPdgrwSC5FDAP/2sf x+QI0IvdNunzpLSrCJumTUTlO+4M7TdPcmuTsALxUFZKxETHjvIjNS+UFlxI/Ilf +e1bxqGX17sXgI9dEb49EC1IAOx8Lcl67DV4/vrC9z0lvDeMiP6q38fMsv3ocD3y PKuEp+S6BDygFKn6BX2ikWnUkoDSFx5IgxXSzvGnp9evIl3C8ny2K2Ij59Jhkuig N00k/aLJHJbtGFbhBSaq2F0Nu7E9QZ3DPfsHvY2iDOFUlg51IGykcZhblg3is+Jh fDNewnSJJoKqUhKtmpY4AXk6r8EDdU10LxyXLGLqA+nZfghn+wR1is4rMDcdmGQG n9cR9bObn2pKhueHsUkHMveZHV7aYkcRi5CjBBITPiJP8BbpLOQUq+BNKJj7YnyX ufUrxpl/F0N3uMmxTGKa+awiNosrdtheUZDC1d2F/79lA/6rYTOMcB0o9X5ob8JE CM9BZVtAxj1E3YtDR6k7h6Q7BnfNctatlhQR9v2elDzZVrvNwVFU7WoX3V7vLyc4 6C56KUWjVMf9ctfjpXrWIBkemHzTnhCXZwz15+h5ORlu47sh6KW+oNwpkCdcYlPO ZWr2RLZsV+sgmyNWMjf5BcnNDYAgmZD4BMrGLV6tPky7iUYARpySnRSlQB8o/WLF CM9E/RgrOEOrYvKK7yITHINSFaE36umqb/9zsWTB =ZJnG -----END PGP SIGNATURE----- --J692Obim36hrERjOIEFvI6MAPn5DqWF1U--