Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754231AbcKQGXZ (ORCPT ); Thu, 17 Nov 2016 01:23:25 -0500 Received: from hqemgate15.nvidia.com ([216.228.121.64]:1804 "EHLO hqemgate15.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753514AbcKQGXX (ORCPT ); Thu, 17 Nov 2016 01:23:23 -0500 X-PGP-Universal: processed; by hqpgpgate101.nvidia.com on Wed, 16 Nov 2016 22:23:21 -0800 Subject: Re: [PATCH v14 09/22] vfio iommu type1: Add task structure to vfio_dma To: Alexey Kardashevskiy , , , , References: <1479329194-10247-1-git-send-email-kwankhede@nvidia.com> <1479329194-10247-10-git-send-email-kwankhede@nvidia.com> <6d256aeb-cd3b-0827-667f-054cdacc45ca@ozlabs.ru> CC: , , , , , X-Nvconfidentiality: public From: Kirti Wankhede Message-ID: Date: Thu, 17 Nov 2016 11:53:09 +0530 MIME-Version: 1.0 In-Reply-To: <6d256aeb-cd3b-0827-667f-054cdacc45ca@ozlabs.ru> X-Originating-IP: [10.24.250.83] X-ClientProxiedBy: BGMAIL102.nvidia.com (10.25.59.11) To bgmail102.nvidia.com (10.25.59.11) Content-Type: text/plain; charset="koi8-r" Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2320 Lines: 52 On 11/17/2016 11:11 AM, Alexey Kardashevskiy wrote: > On 17/11/16 07:46, Kirti Wankhede wrote: >> Add task structure to vfio_dma structure. Task structure is used for: >> - During DMA_UNMAP, same task who mapped it or other task who shares same >> address space is allowed to unmap, otherwise unmap fails. >> QEMU maps few iova ranges initially, then fork threads and from the child >> thread calls DMA_UNMAP on previously mapped iova. Since child shares same >> address space, DMA_UNMAP is successful. >> - Avoid accessing struct mm while process is exiting by acquiring >> reference of task's mm during page accounting. >> - It is also used to get task mlock capability and rlimit for mlock. >> >> Signed-off-by: Kirti Wankhede >> Signed-off-by: Neo Jia >> Reviewed-by: Dong Jia Shi > > > I keep whinging that @mm should be referenced, not @current but you keep > referencing @current even if you only need @mm and you are not telling why > - and I am wondering what I am missing here? Something else will be used > from @task later, besides just @mm? > > Hey Alexey, I updated briefly in commit description. Let me try to explain it again in detail. Its true we need mm, but we also need task structure for 2 reasons: - Avoid accessing struct mm while process is exiting by acquiring reference of task's mm during page accounting. If you see vfio_lock_acct(), where reference to mm is taken from task structure, get_task_mm(task), to make sure that mm of this task is still valid and task not in exiting process. If process is exiting, mm would be NULL and we don't have to do page accounting. This patch is to re-org and prepare the code for next patch, 10/22. vfio_pin_pages()/ vfio_unpin_pages() for mediated devices would get called from vendor driver. Those could be initiated by other process, but for pin/unpin, these APIs should use the mm of the task who mapped it. So in these calls we should check that we get the valid reference of mm, that we would get from task structure. - It is also used to get task mlock capability and rlimit for mlock. These are again used for page accounting and page accounting should be done with reference to the task who mapped the iova range. We get these from task structure. Thanks, Kirti