From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.0 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9B3C8C43441 for ; Mon, 26 Nov 2018 03:12:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5997E2086B for ; Mon, 26 Nov 2018 03:12:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5997E2086B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.intel.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726200AbeKZOEk (ORCPT ); Mon, 26 Nov 2018 09:04:40 -0500 Received: from mga01.intel.com ([192.55.52.88]:57905 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726087AbeKZOEk (ORCPT ); Mon, 26 Nov 2018 09:04:40 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 25 Nov 2018 19:11:58 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,280,1539673200"; d="scan'208";a="98987382" Received: from allen-box.sh.intel.com (HELO [10.239.161.122]) ([10.239.161.122]) by FMSMGA003.fm.intel.com with ESMTP; 25 Nov 2018 19:11:55 -0800 Cc: baolu.lu@linux.intel.com, 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 Subject: Re: [PATCH v4 8/8] vfio/type1: Handle different mdev isolation type To: Auger Eric , Joerg Roedel , David Woodhouse , Alex Williamson , Kirti Wankhede References: <20181105073408.21815-1-baolu.lu@linux.intel.com> <20181105073408.21815-9-baolu.lu@linux.intel.com> From: Lu Baolu Message-ID: <0b951425-ea7f-3596-b4b5-f8e56072c765@linux.intel.com> Date: Mon, 26 Nov 2018 11:09:00 +0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.2.1 MIME-Version: 1.0 In-Reply-To: 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 11/23/18 10:23 PM, Auger Eric wrote: > 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? Yes, good catch. >> + 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 Yes. >> return 0; >> } >> - symbol_put(mdev_bus_type); >> + >> + bus = iommu_device->bus; >> } >> >> domain->domain = iommu_domain_alloc(bus); >> > Thanks > > Eric > Best regards, Lu Baolu