Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp2589851pxb; Mon, 11 Jan 2021 13:53:44 -0800 (PST) X-Google-Smtp-Source: ABdhPJx+DzvPB6rP9v8guMON0kFiZlqMtc02j9Y6y9f/4qDWC9a5tjKmIGxNROzHLxenQ4qRHHP+ X-Received: by 2002:aa7:da8f:: with SMTP id q15mr967895eds.239.1610402024774; Mon, 11 Jan 2021 13:53:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610402024; cv=none; d=google.com; s=arc-20160816; b=WjQKEjowuK7KR7EBxN10GZ5800ul57yUJfG4j5RfDGH1SSULGByoLzb/EBG7tRCnTj C6AtWU8Ar0pytFIl0x94JUj4S+JzAN8bj3DG9+HdwYvTmPdEEXgkp1DDpjn5xPfpzoZj YG27RR8k9PShb0RY5uyUdZ7YPLmBEjmOOlwjxq/fQnxpfneU/AHneySYGZhUq/kHwXMP HaZagUXxeXNSACrNeO2yLYCmTEv1Hlma27vqq5bizyhsPPy+Qzk0UKRD5e8opkAz1wts lfDFm+GztCyvkyhF4Y6XBLC+JGDaw1Dorgee2RG55GjaTvwr58J2eY/skBlKE21VN7ti Mb9Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=YcHYs6OZqBWCMgb0rpCE3M6MXEuKUj2tsDDbqZh/79Q=; b=mDdn4ssP9SedDNM1Y/6OorHp3MzPDF6QpbhXIdNPpSRFd0/SoY/0yQy5r847GtKRuE NykK/1T7+Xn23eb8SYmLKW0w73MOHb/Tn0O/yaUQDPy4v5kOrqpDgNM7zhI9pItZnK+3 sN3YDoZ8PMSc6P9iGuvwcHeNJ3irNnJq8BNbhN8dx5CYNkxfEkZ4Ni5ghitrmQmOuMNZ fjADmnKr00NGApfgHIq+SfHBMy2p7A4d0R/WkpI00FV/X+w4ozX7SEeLFRG4NSz+nIND nq8H1qiD+d7zHsRhaGV6c806DVEkg/ky+FD25rinCK/gMtMLbfO4mZnvmwq5Kwnkw9Xo oC0Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=EyuIzZfE; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d20si250659ejd.409.2021.01.11.13.53.20; Mon, 11 Jan 2021 13:53:44 -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; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=EyuIzZfE; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732723AbhAKVus (ORCPT + 99 others); Mon, 11 Jan 2021 16:50:48 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:26602 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727380AbhAKVus (ORCPT ); Mon, 11 Jan 2021 16:50:48 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1610401761; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=YcHYs6OZqBWCMgb0rpCE3M6MXEuKUj2tsDDbqZh/79Q=; b=EyuIzZfELTbtMCf31PCMpwCiHsjcTbjKf5T7bWMEcJJ+h3+duCDVQor5GBr3rQcEixGtu9 OdS5sFVWokZEpD+/yH5kc/amqfK7/kzrIsSd/WIqiCcrfZ4F2/Lp8tsriG/fLfDJTmkCVj qtPCdfO/dKrPPcuAZbF02OHGNUjPHV0= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-70-ekx4pMUpPXWmh16-SihWQQ-1; Mon, 11 Jan 2021 16:49:19 -0500 X-MC-Unique: ekx4pMUpPXWmh16-SihWQQ-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8B8F1107ACF7; Mon, 11 Jan 2021 21:49:16 +0000 (UTC) Received: from omen.home.shazbot.org (ovpn-112-255.phx2.redhat.com [10.3.112.255]) by smtp.corp.redhat.com (Postfix) with ESMTP id 828CE60BE2; Mon, 11 Jan 2021 21:49:14 +0000 (UTC) Date: Mon, 11 Jan 2021 14:49:13 -0700 From: Alex Williamson To: Keqian Zhu Cc: , , , , , Kirti Wankhede , Cornelia Huck , Will Deacon , Marc Zyngier , Catalin Marinas , Mark Rutland , James Morse , Robin Murphy , Joerg Roedel , "Daniel Lezcano" , Thomas Gleixner , Suzuki K Poulose , Julien Thierry , Andrew Morton , Alexios Zavras , , Subject: Re: [PATCH 4/5] vfio/iommu_type1: Carefully use unmap_unpin_all during dirty tracking Message-ID: <20210111144913.3092b1b1@omen.home.shazbot.org> In-Reply-To: <20210107092901.19712-5-zhukeqian1@huawei.com> References: <20210107092901.19712-1-zhukeqian1@huawei.com> <20210107092901.19712-5-zhukeqian1@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 7 Jan 2021 17:29:00 +0800 Keqian Zhu wrote: > 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. This looks like it's creating a larger problem than it's fixing, it's not our job to maintain the dirty bitmap regardless of what the user does. If the user detaches the last group in a container causing the mappings within that container to be deconstructed before the user has collected dirty pages, that sounds like a user error. A container with no groups is de-privileged and therefore loses all state. Thanks, Alex > 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);