Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp190785imm; Tue, 25 Sep 2018 19:15:03 -0700 (PDT) X-Google-Smtp-Source: ACcGV62G2429uYftknZaJIZP3p2AowKzBYrGU4oslTX73TEMB4BEAsy45YxF4/k3QJzcE/N6Kh+M X-Received: by 2002:a17:902:7246:: with SMTP id c6-v6mr3789555pll.304.1537928103450; Tue, 25 Sep 2018 19:15:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537928103; cv=none; d=google.com; s=arc-20160816; b=t1PTdfCFAtXppyXN24tYH6FSnBC91t+/bqU6OXFHxC1Ddfb3cDtdEtIb1iNh+fXC7V TeHLruQLCT0xXCUWxlEmpoAs2dZ6WSewGysf7tU1fmOULim2Tt6VA/GwrKzN5QSFW/Vd ANa/AG0QsoSLuj6hYbb1w1Rm9Kv80EOXPbeKT0lGxvozExqOfyndaYIomtpQdimSFEmy SLTUTlVpXDXxh6q7GQyGeNFW4L4IcI2fbGS6NY+94Iw4gtb+3FpG6gxN6gfUGEAHlvkw uZS+lf91av6zKRuuPiXsbj2TpU26Z2Kos03032/iZrLVweqWgZVTcvifgbVyi+SdUxd7 VYmQ== 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:to:subject:cc; bh=ROeWtgBZsAx9JXsEvon01mQ4fDY7c8qPnNwXg+HiOu0=; b=KH+5y2+jzNctIRrikX0NZOSQwT1ZVa/wevFau+dG/5Fxf+Tv/Y177Q4oxJKAsQIpuT q2fJE36r4E4BJFRhPxZNWaqskL3hyh2vr49V9Nx9E7nMPa+o/z0VukxbwzQTD3b8zdoe ooVs6P5WnaLX6weHVOyfe05gtkcmXq8s9qivUDcvHWPSUivtOm6vbGW/EXcGe1r1ejQe 9zFdpodz7Qo50S9t6u1sG5+tkLwA3k4ByS5XYksCP8Efs7izyjhtMTxJHmFBvCMfDRCM 75ti1Z6r2sfS5+WBs2rxQ0WM2Mx9v3z27+KVOPp/HJRQaX7/H9lfoIqh79THJYRGH/IY gQKQ== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o11-v6si4048753pls.76.2018.09.25.19.14.46; Tue, 25 Sep 2018 19:15:03 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726947AbeIZIZO (ORCPT + 99 others); Wed, 26 Sep 2018 04:25:14 -0400 Received: from mga06.intel.com ([134.134.136.31]:49705 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726321AbeIZIZO (ORCPT ); Wed, 26 Sep 2018 04:25:14 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 25 Sep 2018 19:14:41 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.54,304,1534834800"; d="scan'208";a="89373734" Received: from allen-box.sh.intel.com (HELO [10.239.161.122]) ([10.239.161.122]) by fmsmga002.fm.intel.com with ESMTP; 25 Sep 2018 19:12:34 -0700 Cc: baolu.lu@linux.intel.com, "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" Subject: Re: [RFC PATCH v2 08/10] vfio/type1: Add domain at(de)taching group helpers To: Jean-Philippe Brucker , "Tian, Kevin" , Joerg Roedel , David Woodhouse , Alex Williamson , Kirti Wankhede References: <20180830040922.30426-1-baolu.lu@linux.intel.com> <20180830040922.30426-9-baolu.lu@linux.intel.com> <04f5dc9d-71b1-37ec-402b-fae5f9e08664@arm.com> <75517c87-6ffd-2023-a541-3c69ae52ef4b@arm.com> From: Lu Baolu Message-ID: <1b4c12c3-1dc2-d9ba-9ba4-5220db3e2302@linux.intel.com> Date: Wed, 26 Sep 2018 10:11:03 +0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <75517c87-6ffd-2023-a541-3c69ae52ef4b@arm.com> Content-Type: text/plain; charset=utf-8; format=flowed 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 Hi, On 09/26/2018 01:55 AM, Jean-Philippe Brucker wrote: > 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 > This looks good to me. Just a minor change to make it more readable. __iommu_detach_group(grp, unmanaged_domain) if (ops->detach_dev) ops->detach_dev(dev, unmanaged_domain) if (default_domain) ops->attach_dev(dev, default_domain) Best regards, Lu Baolu > 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 >