Received: by 2002:a17:90a:bc8d:0:0:0:0 with SMTP id x13csp1809254pjr; Tue, 19 May 2020 00:11:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxdA0SeqfVnZIIOJl+yNTwefQcuHo+df4+Cu8tdUrg6ER6s2V0479J8B2sfK9ViTAx7+Te/ X-Received: by 2002:a17:906:5615:: with SMTP id f21mr17619179ejq.372.1589872313431; Tue, 19 May 2020 00:11:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589872313; cv=none; d=google.com; s=arc-20160816; b=0UQ1N1gwO4/MN7VReUFmenEdG5LYd+37/O5E7mei4kBCZ86lAOOf+JUvKV9GpUo0xK NojEgK9vY7jijB3ZL8B575v1edhl0PPowQ6JbfcV2kWc5czX4pc6Uw7PEJtkI9HHxayl y6yglQ4Kar+md+OyucyqJWouRQx97gXqtr7z+mKnfIKHvsWrPGpIIWI+ZuvMm/fullN6 dDog00Sr7oIpArgPsp+95fJEfqaW9E4xz0oDuNLal+0qnMcbbVdNbUbo9OkHZbN9CCSy d+Jq8B4TbgwsfuPUYEZzY4EE3qiRvNgY/6EhALwlPmEV1mjA+Fj1JbNNzQZ14mBeHkPH QxNw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:mail-followup-to:reply-to:message-id :subject:cc:to:from:date:dkim-signature; bh=X/KmdOdFxUdbyg6uVeDwn3rmdrmoPPzdKKlBwCaZDW8=; b=NmeG/dB7bonCgf7xfg3KVo1HVnZKuGxfNbAdTAlR+dK1k/0WPJ00cLbUI0FyhOS/dN DcjCKGIORkKk8EvCxmc57RNoPRSYKDb1YaJ2YdFe4/7AjXsILogZSomCPY+R/ehgsvtB 9+7ShTbjHVx8T3LNDA8oQy5/giP+VNLltj6htl2MlSPpf0aT+CKzPP2u+SbjGSjw+ATa 5oSbAZ7CEjzqq2cT9Lwej+P3+s5JI6J5om/0nATcqSeQ3sRCMHcZlh/CXbmRkkvTKSbX n+FQeiVVj6acqy2roIzQFCJvaBOlzRkglrmu237+GCak3gPcOJ3CZ2leXcentC4QKVt7 aGvQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="WNjmuoW/"; 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 l6si7572300edr.243.2020.05.19.00.11.27; Tue, 19 May 2020 00:11: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; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="WNjmuoW/"; 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 S1728336AbgESHKD (ORCPT + 99 others); Tue, 19 May 2020 03:10:03 -0400 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:55744 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726893AbgESHKD (ORCPT ); Tue, 19 May 2020 03:10:03 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1589872201; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:in-reply-to:in-reply-to: references:references; bh=X/KmdOdFxUdbyg6uVeDwn3rmdrmoPPzdKKlBwCaZDW8=; b=WNjmuoW/PIJ1hRvYgLOlGXSIEnUUHJPCFf16hhkOQmcoCtimpUZrNHmQtFV1FfDcG/5cSY E3aF7mENkE5nfsXds8KKUucHy8YYJKdqpCv2LeO/Z1iCocOK9keiRklxgZoaLIrzgyF/0R 6bDzH21+jKCEEGTnwLDLPo0Zv3qRHCU= Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-374-XcNjyHlMNnmQIc9_pP9iwA-1; Tue, 19 May 2020 03:09:57 -0400 X-MC-Unique: XcNjyHlMNnmQIc9_pP9iwA-1 Received: by mail-qk1-f199.google.com with SMTP id y64so13713450qkc.19 for ; Tue, 19 May 2020 00:09:57 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:reply-to :mail-followup-to:references:mime-version:content-disposition :in-reply-to; bh=X/KmdOdFxUdbyg6uVeDwn3rmdrmoPPzdKKlBwCaZDW8=; b=fuynEO2q4omzBIwA6x27RXeFRYFQRE/sVp8vKAZDT8TGFeKzhbqO+R6VglJhNFpnQF FX9TwTWW6aKDCsOHBDSMQ+5UYbn4UVBy5oceofGQsVqsA57cbSEnphq+enh0adn8UdgC WwZ5vkzl4zqvBWOd6M+wL7U1LDVhveGTAcDgUgvFU2oArecicg/t4bm1xFM5NxY/KNC/ x75nHTpTTbxexrr1ulveibVU8RysDcBVbqw7VqSqMCBVOg/6rMmsFZVb/YFoClFq/BA7 L68qdTQNby1CcojpIqb1mLIoSn9iTg4vj5hBsZI0z9ubFnpcz4pMz1B6fEtfIleKvCsH hPNw== X-Gm-Message-State: AOAM531E84uXGGqlNUHtVFMVL1gT5A44+4nC9wUfHFVJm8O5p2IsB2RJ BDZv+gCaYIUx+oh6qKps06BmITHQI8OMX2Hj7VUaRWNFbTdBX0rGQfsl/1PjDup90B8Ki2mI+ye E0RGVWW01LspeS17GB8Q68sMk X-Received: by 2002:ac8:1416:: with SMTP id k22mr20425544qtj.205.1589872196663; Tue, 19 May 2020 00:09:56 -0700 (PDT) X-Received: by 2002:ac8:1416:: with SMTP id k22mr20425523qtj.205.1589872196359; Tue, 19 May 2020 00:09:56 -0700 (PDT) Received: from localhost (ip70-163-223-149.ph.ph.cox.net. [70.163.223.149]) by smtp.gmail.com with ESMTPSA id t88sm11138889qtd.5.2020.05.19.00.09.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 May 2020 00:09:55 -0700 (PDT) Date: Tue, 19 May 2020 00:09:53 -0700 From: Jerry Snitselaar To: Joerg Roedel Cc: Robin Murphy , iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org, Tom Murphy Subject: Re: [PATCH] iommu: Implement deferred domain attachment Message-ID: <20200519070953.dj46pvdqvqdglr4p@cantor> Reply-To: Jerry Snitselaar Mail-Followup-To: Joerg Roedel , Robin Murphy , iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org, Tom Murphy References: <20200515094519.20338-1-joro@8bytes.org> <20200515161400.GZ18353@8bytes.org> <20200515182600.GJ8135@suse.de> <20200518132656.GL8135@suse.de> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Disposition: inline In-Reply-To: <20200518132656.GL8135@suse.de> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon May 18 20, Joerg Roedel wrote: >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)) >_______________________________________________ >iommu mailing list >iommu@lists.linux-foundation.org >https://lists.linuxfoundation.org/mailman/listinfo/iommu > This worked for me as well.