Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp2721306ybk; Mon, 18 May 2020 06:28:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyX/D/LrCh4Oo1c3Ing2XpafM953mQXoZdyjOqakk8n6LKwm+Jw38/UJIathje44Cds10vM X-Received: by 2002:a50:fd0c:: with SMTP id i12mr2010282eds.48.1589808528899; Mon, 18 May 2020 06:28:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589808528; cv=none; d=google.com; s=arc-20160816; b=jD00mw0dsGmvQpU8IgtmV05p2Vl/JySF1NEpXiOYu+PY3GyhnyCZJXhBuMJRu5ItzY oPaxenwVEodyZPVdv5WeDJNWzPtUkv6FFUWwWcJNtpYGX7k48b06N3IrI8VmSlZwpCRi 2lmnrPpVkX4bZnc9thwhphLlMOUTiq5yzYmUuq5LFvAlKzBzkNZKnK7lptl8DYzP6+Uo T4hHs8qAdBElg4KBHSPy/FN5lmWOM62w4hEJuAbnr9ulsO8p+JASa6jXwLqP/SPmNdx5 dTRkrSGwSoCKIJOoETA9oInzwAmnwTjSiL4X+ewgBZuXTctWskQBkFGnzCGGVoYIYByT WpcA== 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=WfKP3zM55d4FKvy+K3yDzBnGJvoHz9AfP3b0dwrv3WE=; b=b1j5Dyj7leRvG4uIhy19arIcl7R4PWHHSXXb9zzLX0vm1gPqp8eLuF8eLh7oWcVi8a XIjERZBICl6LnKhz/tTRt6qUDYSTZ+rVxYPUqV8KdpV11/2j9Ra5mL/RklNydzqRiiBk au9BV2YIZKYdkwa+yRVfatkXI055O6+EGpAXFbPyZq9Lo5eRddxALmuSII0Sgfnsxzyu Q5oL9DRJwp4LVse6UtGlzBWOhkxsJoI8ojWlQNQDyKEQI3DUB4CoX04ON+stvAnjwff7 5RcOTCqiAhBEGISWC9amr8oDbpHNgZErWLC4+36Hxjex0LLoxFI3aCs/B5OrDIMC9BSN L/rg== 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 h14si1286407eji.323.2020.05.18.06.28.24; Mon, 18 May 2020 06:28:48 -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 S1727782AbgERN1A (ORCPT + 99 others); Mon, 18 May 2020 09:27:00 -0400 Received: from mx2.suse.de ([195.135.220.15]:60948 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726726AbgERN1A (ORCPT ); Mon, 18 May 2020 09:27:00 -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 4DDB2ACE3; Mon, 18 May 2020 13:27:01 +0000 (UTC) Date: Mon, 18 May 2020 15:26:56 +0200 From: Joerg Roedel To: Robin Murphy Cc: iommu@lists.linux-foundation.org, Tom Murphy , linux-kernel@vger.kernel.org Subject: Re: [PATCH] iommu: Implement deferred domain attachment Message-ID: <20200518132656.GL8135@suse.de> References: <20200515094519.20338-1-joro@8bytes.org> <20200515161400.GZ18353@8bytes.org> <20200515182600.GJ8135@suse.de> 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 08:23:13PM +0100, Robin Murphy wrote: > But that's not what this is; this is (supposed to be) the exact same "don't > actually perform the attach yet" logic as before, just restricting it to > default domains in the one place that it actually needs to be, so as not to > fundamentally bugger up iommu_attach_device() in a way that prevents it from > working as expected at the correct point later. You are right, that is better. I tested it and it seems to work. Updated diff attached, with a minor cleanup included. Mind sending it as a proper patch I can send upstream? Thanks, Joerg diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index 7b375421afba..a9d02bc3ab5b 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -693,6 +693,15 @@ static int iommu_group_create_direct_mappings(struct iommu_group *group, return ret; } +static bool iommu_is_attach_deferred(struct iommu_domain *domain, + struct device *dev) +{ + if (domain->ops->is_attach_deferred) + return domain->ops->is_attach_deferred(domain, dev); + + return false; +} + /** * iommu_group_add_device - add a device to an iommu group * @group: the group into which to add the device (reference should be held) @@ -705,6 +714,7 @@ int iommu_group_add_device(struct iommu_group *group, struct device *dev) { int ret, i = 0; struct group_device *device; + struct iommu_domain *domain; device = kzalloc(sizeof(*device), GFP_KERNEL); if (!device) @@ -747,7 +757,8 @@ 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) + domain = group->domain; + if (domain && !iommu_is_attach_deferred(domain, dev)) ret = __iommu_attach_device(group->domain, dev); mutex_unlock(&group->mutex); if (ret) @@ -1653,9 +1664,6 @@ static int __iommu_attach_device(struct iommu_domain *domain, struct device *dev) { int ret; - if ((domain->ops->is_attach_deferred != NULL) && - domain->ops->is_attach_deferred(domain, dev)) - return 0; if (unlikely(domain->ops->attach_dev == NULL)) return -ENODEV; @@ -1727,8 +1735,7 @@ EXPORT_SYMBOL_GPL(iommu_sva_unbind_gpasid); static void __iommu_detach_device(struct iommu_domain *domain, struct device *dev) { - if ((domain->ops->is_attach_deferred != NULL) && - domain->ops->is_attach_deferred(domain, dev)) + if (iommu_is_attach_deferred(domain, dev)) return; if (unlikely(domain->ops->detach_dev == NULL))