Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3229969imu; Sat, 24 Nov 2018 00:37:29 -0800 (PST) X-Google-Smtp-Source: AFSGD/VwfZbG8vYdY1CmX2HVgm9wjxZ8AwfgZcCuuIKpybeqRiNKVIaC/VZUFMMlqhL2N7Xg5aiH X-Received: by 2002:a63:9a52:: with SMTP id e18mr17065400pgo.14.1543048649050; Sat, 24 Nov 2018 00:37:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543048649; cv=none; d=google.com; s=arc-20160816; b=CWkIj2piG+uVaBoHhsu5RCg4DZhN72zeO7+2CSsSiN/w8Ab8BP6N0jW8klzfenFNQl LJEUGymAM4Gi545YPZx4vc+2YzISkphoo6iMUdNg74T1t8BxcyfsOJXFUZFm14ArHoWw Pp3ybU9UnWmkxTTwy+E+JxXE2zEJ2pYu7n/i8FgAYF6zglP9DxOYGQrowyArOe4Uugy5 fJFNlq4on0cSWoDCV83muLhBtlUZPthhL7zyzjtjYmEcxKq4kr+DL9JP0LejgJP+rtsW tM6EYr6cGiR62qsqIY40pSsRiZDW3VmYN52mZTjdBJ4kVm0rUgaepKbzT6pCGxsh/tYN /l8g== 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=wn9CZK65u3sxAaemURkQRGiJAMfljgPTTIh5BMyCsVc=; b=kXDOFdTrNQh5LnKzDqYYpoIIByUm3ceYxpRegAK6B61BXwWQ+oe/70kvTKu6d68JXN +L7EPz0PBs18nZDpL140LPJzOBb1KSUA8l2Ax+fJrECyTlQInjysPr2WMhgviBuQbdEr O3oA/stwDRtKPy4XNvaU/BfbM5f5S0R148Ht+hQgpBPChHKs5RR7mVSYbn162RPqonIf cY+aciQilBhzpFWQ1O0MqDcMavr36lEpMqrXabiCzCaXn2VtH3Cbn8zN5h+gBjTCJMYY poBGnfuYqlH2Y/QZwefkTwSsOaneaa6aAd/DwyBICYVtVpLmhilKnEvPs3QfzgLLVG7H fIPg== 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=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e35si25855824pgb.548.2018.11.24.00.37.14; Sat, 24 Nov 2018 00:37:29 -0800 (PST) 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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391217AbeKXBH5 (ORCPT + 99 others); Fri, 23 Nov 2018 20:07:57 -0500 Received: from mx1.redhat.com ([209.132.183.28]:51630 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390959AbeKXBH5 (ORCPT ); Fri, 23 Nov 2018 20:07:57 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8639D5AFE9; Fri, 23 Nov 2018 14:23:33 +0000 (UTC) Received: from [10.36.117.189] (ovpn-117-189.ams2.redhat.com [10.36.117.189]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D36251836C; Fri, 23 Nov 2018 14:23:22 +0000 (UTC) Subject: Re: [PATCH v4 8/8] vfio/type1: Handle different mdev isolation type To: Lu Baolu , Joerg Roedel , David Woodhouse , Alex Williamson , Kirti Wankhede Cc: ashok.raj@intel.com, sanjay.k.kumar@intel.com, jacob.jun.pan@intel.com, kevin.tian@intel.com, Jean-Philippe Brucker , yi.l.liu@intel.com, yi.y.sun@intel.com, peterx@redhat.com, tiwei.bie@intel.com, Zeng Xin , iommu@lists.linux-foundation.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Jacob Pan References: <20181105073408.21815-1-baolu.lu@linux.intel.com> <20181105073408.21815-9-baolu.lu@linux.intel.com> From: Auger Eric Message-ID: Date: Fri, 23 Nov 2018 15:23:21 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.3.0 MIME-Version: 1.0 In-Reply-To: <20181105073408.21815-9-baolu.lu@linux.intel.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Fri, 23 Nov 2018 14:23:33 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Lu, On 11/5/18 8:34 AM, Lu Baolu wrote: > This adds the support to determine the isolation type > of a mediated device group by checking whether it has > an iommu device. If an iommu device exists, an iommu > domain will be allocated and then attached to the iommu > device. Otherwise, keep the same behavior as it is. > > Cc: Ashok Raj > Cc: Jacob Pan > Cc: Kevin Tian > Cc: Liu Yi L > Signed-off-by: Sanjay Kumar > Signed-off-by: Lu Baolu > Signed-off-by: Liu Yi L > --- > drivers/vfio/vfio_iommu_type1.c | 48 ++++++++++++++++++++++++++++----- > 1 file changed, 42 insertions(+), 6 deletions(-) > > diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c > index 178264b330e7..eed26129f58c 100644 > --- a/drivers/vfio/vfio_iommu_type1.c > +++ b/drivers/vfio/vfio_iommu_type1.c > @@ -1427,13 +1427,40 @@ static void vfio_iommu_detach_group(struct vfio_domain *domain, > iommu_detach_group(domain->domain, group->iommu_group); > } > > +static bool vfio_bus_is_mdev(struct bus_type *bus) > +{ > + struct bus_type *mdev_bus; > + bool ret = false; > + > + mdev_bus = symbol_get(mdev_bus_type); > + if (mdev_bus) { > + ret = (bus == mdev_bus); > + symbol_put(mdev_bus_type); > + } > + > + return ret; > +} > + > +static int vfio_mdev_iommu_device(struct device *dev, void *data) > +{ > + struct device **old = data, *new; > + > + new = vfio_mdev_get_iommu_device(dev); > + if (*old && *old != new) if !new can't you return -EINVAL as well? > + return -EINVAL; > + > + *old = new; > + > + return 0; > +} > + > static int vfio_iommu_type1_attach_group(void *iommu_data, > struct iommu_group *iommu_group) > { > struct vfio_iommu *iommu = iommu_data; > struct vfio_group *group; > struct vfio_domain *domain, *d; > - struct bus_type *bus = NULL, *mdev_bus; > + struct bus_type *bus = NULL; > int ret; > bool resv_msi, msi_remap; > phys_addr_t resv_msi_base; > @@ -1468,11 +1495,18 @@ static int vfio_iommu_type1_attach_group(void *iommu_data, > if (ret) > goto out_free; > > - mdev_bus = symbol_get(mdev_bus_type); > + if (vfio_bus_is_mdev(bus)) { > + struct device *iommu_device = NULL; > > - if (mdev_bus) { > - if ((bus == mdev_bus) && !iommu_present(bus)) { > - symbol_put(mdev_bus_type); > + group->mdev_group = true; > + > + /* Determine the isolation type */ > + ret = iommu_group_for_each_dev(iommu_group, &iommu_device, > + vfio_mdev_iommu_device); > + if (ret) > + goto out_free; > + > + if (!iommu_device) { > if (!iommu->external_domain) { > INIT_LIST_HEAD(&domain->group_list); > iommu->external_domain = domain; > @@ -1482,9 +1516,11 @@ static int vfio_iommu_type1_attach_group(void *iommu_data, > list_add(&group->next, > &iommu->external_domain->group_list); > mutex_unlock(&iommu->lock); > + extra new line > return 0; > } > - symbol_put(mdev_bus_type); > + > + bus = iommu_device->bus; > } > > domain->domain = iommu_domain_alloc(bus); > Thanks Eric