Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp172789pxu; Thu, 7 Jan 2021 01:33:06 -0800 (PST) X-Google-Smtp-Source: ABdhPJxtq8YpTvDCVZBVoNS5Y7BLTKwJHsTKq/li+V0tYmnSS3oEZTphm+N3W2x7Wlkbbf3uuSUg X-Received: by 2002:a17:906:7c49:: with SMTP id g9mr5796339ejp.185.1610011986449; Thu, 07 Jan 2021 01:33:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610011986; cv=none; d=google.com; s=arc-20160816; b=0FULbGem3GNf5O/74/+Yz+TrtTCZfGRzUieR7cP4fsXFv/BxbM7pS7Vl0r/53eShgI 2ish9BJ/TosxKOMpu4F8oGWPly/MSFSIym9GFeqO7LFyUGgl9/NsYOUyxAWoJ1JNI1TB RnoMOQB0jkadXOEhYmAvf99EWQIMIup/3Ux7IbrVHY5boKgOcawFWzm6APtM1xyRn1CV 8RqF0btn8Do10p9pnh1l9NXhrG7azBSTyaURtV1OjzokZ28d1ELo+PlSjBhIUuUj3D8f Ptp+pmRM/jJvmikhf7sbfPmGMr8nEiE3vaDg2VjM2PHia0GNw/65RiKUuFuRgdq9fUxW cumA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from; bh=VssZrRDjZZfJTt4UZI6PdJIn6AJy7vpWTmo8lmfA2Ok=; b=mfwu3FT14gH3NY/yvBMU8A7hU40C0QXYXeZ+0y+82+Jhq8DlNIFGRqC2qWJJAL360B WnWVPpE380RJAf9vbn35I0wX7InJq14BcJbWMpR9BgQKgl5VhzyDlAhOIiHbMEuM1Qa3 HKiPhkl3Em/wVVho0GFLXrt/8yJiWyd1uiQR83aaCRiH0otUcfi84hiy6VCPEVOGworV woDh5eXTao90zoXvD3Rbx7pQwxVPJgzRdzXZn7VkZy6CgZfmJELJgbUWZftYSdYF7F4P lhq9P8g3qXdkQSOYZ+XsXmC30X9FcWwBHdLTdnGEHbZBSOeqjUJdDdAspNH/u0fag/cY jpBQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id mf27si1934734ejb.129.2021.01.07.01.32.43; Thu, 07 Jan 2021 01:33:06 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727831AbhAGJa1 (ORCPT + 99 others); Thu, 7 Jan 2021 04:30:27 -0500 Received: from szxga05-in.huawei.com ([45.249.212.191]:10557 "EHLO szxga05-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727329AbhAGJaW (ORCPT ); Thu, 7 Jan 2021 04:30:22 -0500 Received: from DGGEMS404-HUB.china.huawei.com (unknown [172.30.72.60]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4DBLWb6mFDzMGT6; Thu, 7 Jan 2021 17:28:27 +0800 (CST) Received: from DESKTOP-5IS4806.china.huawei.com (10.174.184.42) by DGGEMS404-HUB.china.huawei.com (10.3.19.204) with Microsoft SMTP Server id 14.3.498.0; Thu, 7 Jan 2021 17:29:32 +0800 From: Keqian Zhu To: , , , , , Alex Williamson , Kirti Wankhede , Cornelia Huck , Will Deacon , Marc Zyngier , Catalin Marinas CC: Mark Rutland , James Morse , Robin Murphy , Joerg Roedel , "Daniel Lezcano" , Thomas Gleixner , Suzuki K Poulose , Julien Thierry , Andrew Morton , Alexios Zavras , , Subject: [PATCH 4/5] vfio/iommu_type1: Carefully use unmap_unpin_all during dirty tracking Date: Thu, 7 Jan 2021 17:29:00 +0800 Message-ID: <20210107092901.19712-5-zhukeqian1@huawei.com> X-Mailer: git-send-email 2.8.4.windows.1 In-Reply-To: <20210107092901.19712-1-zhukeqian1@huawei.com> References: <20210107092901.19712-1-zhukeqian1@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.174.184.42] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org If we detach group during dirty page tracking, we shouldn't remove vfio_dma, because dirty log will lose. But we don't prevent unmap_unpin_all in vfio_iommu_release, because under normal procedure, dirty tracking has been stopped. Fixes: d6a4c185660c ("vfio iommu: Implementation of ioctl for dirty pages tracking") Signed-off-by: Keqian Zhu --- drivers/vfio/vfio_iommu_type1.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c index 26b7eb2a5cfc..9776a059904d 100644 --- a/drivers/vfio/vfio_iommu_type1.c +++ b/drivers/vfio/vfio_iommu_type1.c @@ -2373,7 +2373,12 @@ static void vfio_iommu_type1_detach_group(void *iommu_data, if (list_empty(&iommu->external_domain->group_list)) { vfio_sanity_check_pfn_list(iommu); - if (!IS_IOMMU_CAP_DOMAIN_IN_CONTAINER(iommu)) + /* + * During dirty page tracking, we can't remove + * vfio_dma because dirty log will lose. + */ + if (!IS_IOMMU_CAP_DOMAIN_IN_CONTAINER(iommu) && + !iommu->dirty_page_tracking) vfio_iommu_unmap_unpin_all(iommu); kfree(iommu->external_domain); @@ -2406,10 +2411,15 @@ static void vfio_iommu_type1_detach_group(void *iommu_data, * iommu and external domain doesn't exist, then all the * mappings go away too. If it's the last domain with iommu and * external domain exist, update accounting + * + * Note: During dirty page tracking, we can't remove vfio_dma + * because dirty log will lose. Just update accounting is a good + * choice. */ if (list_empty(&domain->group_list)) { if (list_is_singular(&iommu->domain_list)) { - if (!iommu->external_domain) + if (!iommu->external_domain && + !iommu->dirty_page_tracking) vfio_iommu_unmap_unpin_all(iommu); else vfio_iommu_unmap_unpin_reaccount(iommu); -- 2.19.1