Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp4078968imm; Tue, 25 Sep 2018 10:57:46 -0700 (PDT) X-Google-Smtp-Source: ACcGV618uFAJ4Wt3/dOG0p45rtA4JgrpjzpGX26QoVrMiJNUd1qRzuiHf3BKUAHKY5U2WDf22Y+G X-Received: by 2002:a62:56d9:: with SMTP id h86-v6mr2223028pfj.229.1537898266395; Tue, 25 Sep 2018 10:57:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537898266; cv=none; d=google.com; s=arc-20160816; b=MePwF9RUsiIv77zdWhcvkq5ftlxO4QntfHijFz6GMm9otd/eV/IWtHDZC73sKnrdHq X44sjC9/KvU5tjwOZ/Pdk9Im7KmplAX+l3Fvoxr1XkjmDmFhD66NUvKSa635UHSBKROr VdSQsx+ceaJuNgDgZ3KLEsoBkEl/B+0GOOiqRjgyowd16vxHwsyf+Ipk7+I7BAzNMez1 eNAVjiI4FJVKDMalKOlV/y2GCGODO/avMjG8wxLgVeHKkdBpxG6csCs1ElyEi5Vf4Y6R 1+RcMDELaB/mZwTYcdgQ+B9S49artzj3E7CGTqAykjStY0ddoOtmleqdbfL+sIqfOXrQ F8mQ== 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=x4IPkluTh++t4+gs9xoRq0m3biogwzc6+5haopd0BOI=; b=gakkOR67LgBYP0ryTmQrBjfxd8KRWAch2QTvkfMhYhmKw8k+G+frv2CILr9aYv4Efx iBP47SZyuKKorseVWECqhzhMdYmBteXWtQaVQoeYIIQY2k9Wt1JMa3g0Jj83wQuHcNOB JgdFNh1TiLf+oArr3gji200zwWD+1eAKgqzfODO8siOD0B5jRU57GWQp9apGi/kvQz+W pTIuUX/GLAHbDAVf+1yCVXkywr31XuJIbDqeVZeSG6YUHYdiyAdCL8BDF5qSilz5mVoj hjm+B5sO5hCapyRscUnLwBEqyNhX722usEw1SFE6ZfQAuhJJsXSYwoyvqLnf4YRUTUAT mMDA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o14-v6si2907669pgi.668.2018.09.25.10.57.30; Tue, 25 Sep 2018 10:57:46 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727049AbeIZAEj (ORCPT + 99 others); Tue, 25 Sep 2018 20:04:39 -0400 Received: from foss.arm.com ([217.140.101.70]:56216 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726304AbeIZAEi (ORCPT ); Tue, 25 Sep 2018 20:04:38 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 03F3118A; Tue, 25 Sep 2018 10:56:00 -0700 (PDT) Received: from [10.4.12.111] (ostrya.Emea.Arm.com [10.4.12.111]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id BA9DC3F5BD; Tue, 25 Sep 2018 10:55:57 -0700 (PDT) Subject: Re: [RFC PATCH v2 08/10] vfio/type1: Add domain at(de)taching group helpers To: "Tian, Kevin" , Lu Baolu , Joerg Roedel , David Woodhouse , Alex Williamson , Kirti Wankhede Cc: "Raj, Ashok" , "Bie, Tiwei" , "Kumar, Sanjay K" , "iommu@lists.linux-foundation.org" , "linux-kernel@vger.kernel.org" , "Sun, Yi Y" , "Pan, Jacob jun" , "kvm@vger.kernel.org" References: <20180830040922.30426-1-baolu.lu@linux.intel.com> <20180830040922.30426-9-baolu.lu@linux.intel.com> <04f5dc9d-71b1-37ec-402b-fae5f9e08664@arm.com> From: Jean-Philippe Brucker Message-ID: <75517c87-6ffd-2023-a541-3c69ae52ef4b@arm.com> Date: Tue, 25 Sep 2018 18:55:41 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 19/09/2018 00:26, Tian, Kevin wrote: >> If the core actually calls it, we can implement detach_dev :) The >> problem is that the core never calls detach_dev when default_domain is >> present (affects any IOMMU driver that relies on default_domain, >> including AMD), and even in case 4) the default_domain is present for >> the parent device > > Then can we change that core logic so detach_dev is invoked in all > cases? yes there will be some changes in vendor drivers, but I expect > this change trivial (especially considering the gain in IOMMU API > simplicity side as described below). Thinking more about this, there might be a way that doesn't require too much rewriting of IOMMU drivers. When VFIO calls iommu_detach_group to detach a vfio-pci device from its domain, it could do detach_dev(dev, old_domain) followed by attach_dev(dev, default_domain) instead of only attach_dev(dev, default_domain), so: __iommu_attach_group(grp, unmanaged_domain) ops->attach_dev(dev, unmanaged_domain) -> IOMMU driver detaches from default_domain only if the dev isn't in auxiliary mode __iommu_detach_group(grp, unmanaged_domain) if (ops->detach_dev) ops->detach_dev(dev, unmanaged_domain) ops->attach_dev(dev, default_domain) -> IOMMU driver ignores this if still attached to default_domain It's not trivial: since half the IOMMU drivers seem to be using default domain now, their detach_dev callback might have been dead code for a while (I can't find a path where it still gets called), so re-enabling it requires some attention. However, since most of them won't care about aux domains, maybe we could just remove their detach_dev pointer. The resulting logic of attach/detach_dev in IOMMU drivers that do use aux domains still seems unnecessarily convoluted. It could as well be done with separate attach_aux/detach_aux functions. If you want to keep it that way though, I think the above could work for us and I'll try to write an RFC. Thanks, Jean