Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp709271ybk; Fri, 15 May 2020 11:27:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwkjpeeEhXdiq7+a9AkKU39WIz8kVp3kBIgRGx9RR23qybNngCjfNBSvG1YcB8wDuRjoZEk X-Received: by 2002:aa7:dc49:: with SMTP id g9mr4137217edu.167.1589567273165; Fri, 15 May 2020 11:27:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589567273; cv=none; d=google.com; s=arc-20160816; b=uHiptmcUarcEtszNSj+n0VhyQAH+UAFchyakCaZnhlE/gP0aY/w5YI0/w2wgAqqmPQ Mrn7AqilVR4TFDzXbXKpBwn3IkWDBf4YS58pNexQ0bCQtLIvWZWk88BFk4i4DpTSEKEv YvCkiyWgiPYBpCnfFTY6cLr6j2jdxXV2tfDICRPxRU/wbftREUhh6K5M5BCbnH3t829f T5VK2fnJwiyeJi5vho2qR/EillXB01XcEhb+PirTZY5Yyi1rjqo9J3PR85GDPYDzl36M 5Baj/ZYKC31FyfNM6Fdot52vS2EsPZIQXaKRpHySG591FbTtyqZ1QsV5SJBteWuxqpTq plnw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=2+1cWxkH8sIvR/hJ2D9MTb2HE+vW5o2+k8OZ2EXoL8c=; b=fHlIVssy/wmEnPbNd0nx/owXFM0WHqOlxi6/uUlaQ1TJrjX+lBoosH2Ff/lopDEl4v 7ay66uAJsWs33kLAQEJVmdnR5EifF3gdhX0u5YXwT6Cz3k22JADxCumCyKWb5Tc9ExqM l3BVmrTsZi2MDrBu9+yM+KY76JvL9dg0xEeolSAtb28sES5hxudmzMSV9FUCtZn81VQX DqqQ5+f9tpM7LBKuc4+2zeWI7ED6t+Y4u0PYbtlSEq5Oc3fd+2GBeoW36wJv1Huc1Kup mWJotQzaKODAMj6GTrKvw2Yjaz7G/ThWPQmSCrHIecq0ptVFZtYps8CeP85+e3Aw30Po D8+Q== 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 n21si1839968eja.402.2020.05.15.11.27.29; Fri, 15 May 2020 11:27:53 -0700 (PDT) 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 S1726248AbgEOS0E (ORCPT + 99 others); Fri, 15 May 2020 14:26:04 -0400 Received: from mx2.suse.de ([195.135.220.15]:46810 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726206AbgEOS0D (ORCPT ); Fri, 15 May 2020 14:26:03 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id C0E6FAD93; Fri, 15 May 2020 18:26:04 +0000 (UTC) Date: Fri, 15 May 2020 20:26:00 +0200 From: Joerg Roedel To: Robin Murphy Cc: Joerg Roedel , iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org, Tom Murphy , jsnitsel@redhat.com Subject: Re: [PATCH] iommu: Implement deferred domain attachment Message-ID: <20200515182600.GJ8135@suse.de> References: <20200515094519.20338-1-joro@8bytes.org> <20200515161400.GZ18353@8bytes.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, May 15, 2020 at 05:28:53PM +0100, Robin Murphy wrote: > On 2020-05-15 17:14, Joerg Roedel wrote: > > diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c > > index ba128d1cdaee..403fda04ea98 100644 > > --- a/drivers/iommu/dma-iommu.c > > +++ b/drivers/iommu/dma-iommu.c > > @@ -362,8 +362,8 @@ static int iommu_dma_deferred_attach(struct device *dev, > > return 0; > > if (unlikely(ops->is_attach_deferred && > > - ops->is_attach_deferred(domain, dev))) > > - return iommu_attach_device(domain, dev); > > + ops->is_attach_deferred(domain, dev))) > > + return iommu_attach_device_no_defer(domain, dev); > > Wouldn't it be simpler to just invoke ops->attach_dev directly and avoid > having to formalise a public interface that nobody else should ever use > anyway? That would omit the ops->attach_dev != NULL check and the trace-point on device attach. Besides that, it would be a layering violation. But the function is of course entirely internal to the iommu subsytem and is a good canditate to be moved to a header file in drivers/iommu. > @@ -746,8 +747,11 @@ int iommu_group_add_device(struct iommu_group *group, > struct device *dev) > > mutex_lock(&group->mutex); > list_add_tail(&device->list, &group->devices); > - if (group->domain) > - ret = __iommu_attach_device(group->domain, dev); > + domain = group->domain; > + if (domain && (!domain->ops->is_attach_deferred || > + !domain->ops->is_attach_deferred(domain, dev))) > + ret = __iommu_attach_device(domain, dev); > + } > mutex_unlock(&group->mutex); > if (ret) > goto err_put_group; No, doing this in iommu_group_add_device() doesn't solve the problem. The attach must not happen before a device driver took control of the device and silenced any DMA initiated by the old kernel. At probe time this isn't guaranteed. Joerg