Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp363344pxb; Fri, 15 Jan 2021 15:28:50 -0800 (PST) X-Google-Smtp-Source: ABdhPJx+2/oY/7M6LIJh7mDs8qlN/iE/AzdMoyC9hQ3+HZMwHTntMh5xs1tm6MEt5/kgwEdMLNfD X-Received: by 2002:a50:bc15:: with SMTP id j21mr11390919edh.187.1610753330428; Fri, 15 Jan 2021 15:28:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610753330; cv=none; d=google.com; s=arc-20160816; b=K17SUXDiFfdtUxMC0UVSjWt5osst5b/tkFA7vSrJM+FPOq9pmynqOlGo+y/BEyZkLL xPO8+z6yjm9sWbeXjgoGyNFfr55oY2zG2U4X/Ev7kVgNbPmDVCcN1aXannwNJvVzQFOw XrnTtiGJhhtMaln2GbUkXEojh/TTA91e6R2YHcQaQJvjcObaSHDrEdAyArj3LFJR3Y+a q4yJIsyzyu0FR3IIDWBSW0YBS1lb1XUPZGOVVXld5OGe/vI+YoZF137aK2ET1aNrvAvz kf8qaVklYl2adT8WH15V2RTwYJ9nojkn6CLgActexTkgDFvhdp841Gs+8TDQ5PUHpbkd w0ZA== 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=Hi1wWTTxsSrh2eZC6d26sBLUQWgqiaGuZmJlj3AaGNk=; b=eRkIvV/ZqTDPjPsrXpjBCvp+9cFOgpg2LYK4tZeMk+UdjwSC4lCd1vKdjLuGJgc7Lb AIMv0Mr7XCFCRArNCARPCv3ZQNbRmLsTXyhHkMvf6bTbWD1j7L3BPRbmysA6j6OgO6kT g/Mo9LfFnsRg140UyrGN+asmSVTfoVx+lBOx9tBUvfS9KmAzuLBmQ0yNOuD0dYyZpr5/ cUmxTG2UROl/3zdcWK9yj5Nqm/NdDgvuS7tVOoq9hPYd/gAnwGoR/fvEZlW1JaeXEZXL PcVIDuTRMlCFXRAa4RaMuMawYXqkFzSfYCb5SBm0sGvzCtWe7fAjiXOwr99VB/EFMwLg fnyA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=dHg6MsaJ; 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 p17si4426683ejw.23.2021.01.15.15.28.26; Fri, 15 Jan 2021 15:28:50 -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=dHg6MsaJ; 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 S1726811AbhAOXZg (ORCPT + 99 others); Fri, 15 Jan 2021 18:25:36 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:39843 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725863AbhAOXZg (ORCPT ); Fri, 15 Jan 2021 18:25:36 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1610753049; 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=Hi1wWTTxsSrh2eZC6d26sBLUQWgqiaGuZmJlj3AaGNk=; b=dHg6MsaJOSBv9I+8I1bGWt8NdeC/VHQTWk7wvLOEa9kEeDSau4rj61DqamjfX7wBp0Tur6 5AcZ/e4QmUvH/5KDFGbWZJJyzzOTwlxLaVVPZ3GyDoip/qCi+z8o8O5ITHaYPaNsgG0Mtn hKne0mdKfR27r4O55zB9cqGdvqe+3Io= 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-245-uCbG_PrpNRm72u80Zfo6-w-1; Fri, 15 Jan 2021 18:24:05 -0500 X-MC-Unique: uCbG_PrpNRm72u80Zfo6-w-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5D174802B40; Fri, 15 Jan 2021 23:24:02 +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 CFC505D763; Fri, 15 Jan 2021 23:24:00 +0000 (UTC) Date: Fri, 15 Jan 2021 16:23:59 -0700 From: Alex Williamson To: Keqian Zhu Cc: , , , , , 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 2/6] vfio/iommu_type1: Ignore external domain when promote pinned_scope Message-ID: <20210115162359.749e8d0d@omen.home.shazbot.org> In-Reply-To: <20210107044401.19828-3-zhukeqian1@huawei.com> References: <20210107044401.19828-1-zhukeqian1@huawei.com> <20210107044401.19828-3-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.15 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 7 Jan 2021 12:43:57 +0800 Keqian Zhu wrote: > The pinned_scope of external domain's groups are always true, that's > to say we can safely ignore external domain when promote pinned_scope > status of vfio_iommu. > > Signed-off-by: Keqian Zhu > --- > drivers/vfio/vfio_iommu_type1.c | 14 +++----------- > 1 file changed, 3 insertions(+), 11 deletions(-) > > diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c > index 334a8240e1da..110ada24ee91 100644 > --- a/drivers/vfio/vfio_iommu_type1.c > +++ b/drivers/vfio/vfio_iommu_type1.c > @@ -1637,14 +1637,7 @@ static void promote_pinned_page_dirty_scope(struct vfio_iommu *iommu) > } > } > > - if (iommu->external_domain) { > - domain = iommu->external_domain; > - list_for_each_entry(group, &domain->group_list, next) { > - if (!group->pinned_page_dirty_scope) > - return; > - } > - } > - > + /* The external domain always passes check */ > iommu->pinned_page_dirty_scope = true; > } > > @@ -2347,7 +2340,6 @@ static void vfio_iommu_type1_detach_group(void *iommu_data, > if (iommu->external_domain) { > group = find_iommu_group(iommu->external_domain, iommu_group); > if (group) { > - promote_dirty_scope = !group->pinned_page_dirty_scope; With this, vfio_group.pinned_page_dirty_scope is effectively a dead field on the struct for groups on the external_domain group list and handled specially. That's not great. If you actually want to make more than a trivial improvement to scope tracking, what about making a counter on our struct vfio_iommu for all the non-pinned-page (ie. all-dma) scope groups attached to the container. Groups on the external domain would still set their group dirty scope to pinned pages, groups making use of an iommu domain would have an all-dma scope initially and increment that counter when attached. Groups that still have an all-dma scope on detach would decrement the counter. If a group changes from all-dma to pinned-page scope, the counter is also decremented. We'd never need to search across group lists. Thanks, Alex > list_del(&group->next); > kfree(group); > > @@ -2360,7 +2352,8 @@ static void vfio_iommu_type1_detach_group(void *iommu_data, > kfree(iommu->external_domain); > iommu->external_domain = NULL; > } > - goto detach_group_done; > + mutex_unlock(&iommu->lock); > + return; > } > } > > @@ -2408,7 +2401,6 @@ static void vfio_iommu_type1_detach_group(void *iommu_data, > else > vfio_iommu_iova_free(&iova_copy); > > -detach_group_done: > /* > * Removal of a group without dirty tracking may allow the iommu scope > * to be promoted.