Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp746752ybk; Fri, 15 May 2020 12:25:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzuWjkuJ+24gaLsuJqBgGQuNHGRaadR7L+KBGeUdhkqZ/3jLcg0EdU0jSmAxhe0ZU3ngSXm X-Received: by 2002:a17:906:3605:: with SMTP id q5mr4410114ejb.363.1589570725990; Fri, 15 May 2020 12:25:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589570725; cv=none; d=google.com; s=arc-20160816; b=FD+JMM8nXHyqaHialhQCzcvMSXZhdKWUvfkOKrDSCsylPsG9eBjO+jknZHLhlSXBjm geHVFNg4Sczv+8NR3xxFrDVM+wnxX1vB79iCFRr7Ld8fifrjjUUhiTbqeTBwD7VvFlEw Yta/jq7iifdD8KbqKUwgtgTu10RPYZ7pJNH3+46PkSNYln7fP/X5dDYk9L/njLNvHwzM f2gFECCjug+l4qrqDSNORaKnRQ3Hmwv9cXCJ02liwH8bzeWpBL+KbdzDKi7E0/kHqND1 K8wfUSzEC7BF1uMvODrmKdh4lEr/yzs8nKhLp4x5cMnlWL+vyrkIBqgc7vl7l20dFsDp J6Ig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=9bOfkSi6ePBJ7983PuKiiaTYT6uJ3fpbNlR4G1ptYhA=; b=jcVChFPpVHnWWylgxXAaSwO9S1QU2nEfcGJBIH5WahhMY/iw0gkpqxo5iU8RD8CKjj Ek2OFHoFNG/2KaAWhpL93xvp1tGCqDTgY8TqifmDhf3Hyuv02sXkHMEnAXUj8jc8bcvm 7JWiwcsagfipCH/3djY1z1GyWfqXmKgdqqJRdYc71ucwwz4qZX5YhOEDwY8XxeuGDBnl uhkOs+sGdh7KIt7uHqA5fDzOwArI98hFKsm20CXlsmnfH+Yjz7MQlyZ+ibipha3WBuwf 0Ei5XAtfWaTSvDbNoi2pwa9EKI7zFiP1lH5LD68Q0TjxeuHUqEniiBsgFc0k12lmNjEF BYEA== 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 x61si1830866ede.604.2020.05.15.12.25.03; Fri, 15 May 2020 12:25:25 -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 S1726385AbgEOTXP (ORCPT + 99 others); Fri, 15 May 2020 15:23:15 -0400 Received: from foss.arm.com ([217.140.110.172]:33078 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726168AbgEOTXP (ORCPT ); Fri, 15 May 2020 15:23:15 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id ADD392F; Fri, 15 May 2020 12:23:14 -0700 (PDT) Received: from [10.57.27.64] (unknown [10.57.27.64]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id F16A43F71E; Fri, 15 May 2020 12:23:13 -0700 (PDT) Subject: Re: [PATCH] iommu: Implement deferred domain attachment To: Joerg Roedel Cc: iommu@lists.linux-foundation.org, Tom Murphy , linux-kernel@vger.kernel.org References: <20200515094519.20338-1-joro@8bytes.org> <20200515161400.GZ18353@8bytes.org> <20200515182600.GJ8135@suse.de> From: Robin Murphy Message-ID: Date: Fri, 15 May 2020 20:23:13 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; rv:68.0) Gecko/20100101 Thunderbird/68.8.0 MIME-Version: 1.0 In-Reply-To: <20200515182600.GJ8135@suse.de> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-GB Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2020-05-15 19:26, Joerg Roedel wrote: > 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. Sure, checking the pointer before calling was implied, but the tracepoint is a good argument, I'd forgotten about that :) >> @@ -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. 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. Thinking a bit more, consider if the driver resets the device then attaches it straight to its own unmanaged domain rather than calling any DMA ops (e.g. VFIO?) - it looks like that would also be totally broken right now, and no amount of bodges in iommu-dma is going to help there. Robin.