From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <anatoly.burakov@intel.com>
Received: from mga06.intel.com (mga06.intel.com [134.134.136.31])
 by dpdk.org (Postfix) with ESMTP id 74DAD5323;
 Mon, 21 Jan 2019 11:13:29 +0100 (CET)
X-Amp-Result: SKIPPED(no attachment in message)
X-Amp-File-Uploaded: False
Received: from orsmga006.jf.intel.com ([10.7.209.51])
 by orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384;
 21 Jan 2019 02:13:28 -0800
X-ExtLoop1: 1
X-IronPort-AV: E=Sophos;i="5.56,502,1539673200"; d="scan'208";a="109818370"
Received: from aburakov-mobl1.ger.corp.intel.com (HELO [10.237.220.84])
 ([10.237.220.84])
 by orsmga006.jf.intel.com with ESMTP; 21 Jan 2019 02:13:26 -0800
To: "Wang, Xiao W" <xiao.w.wang@intel.com>, "dev@dpdk.org" <dev@dpdk.org>
Cc: "Zhang, Qi Z" <qi.z.zhang@intel.com>,
 "qingfu.cqf@alibaba-inc.com" <qingfu.cqf@alibaba-inc.com>,
 "thomas@monjalon.net" <thomas@monjalon.net>,
 "Stojaczyk, Dariusz" <dariusz.stojaczyk@intel.com>,
 "stable@dpdk.org" <stable@dpdk.org>
References: <a306fe2084c9f99dc00d18309c730bdce1817e37.1547746215.git.anatoly.burakov@intel.com>
 <2101fda2f9030723c662419ec9b4a33d2dc7aded.1547807046.git.anatoly.burakov@intel.com>
 <B7F2E978279D1D49A3034B7786DACF407A4E2E72@SHSMSX101.ccr.corp.intel.com>
From: "Burakov, Anatoly" <anatoly.burakov@intel.com>
Message-ID: <1b5e395c-1d0e-ffd4-3eb5-8e1d4f77152d@intel.com>
Date: Mon, 21 Jan 2019 10:13:24 +0000
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101
 Thunderbird/60.4.0
MIME-Version: 1.0
In-Reply-To: <B7F2E978279D1D49A3034B7786DACF407A4E2E72@SHSMSX101.ccr.corp.intel.com>
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Language: en-US
Content-Transfer-Encoding: 7bit
Subject: Re: [dpdk-dev] [PATCH v2] vfio: allow secondary process to query
	IOMMU type
X-BeenThere: dev@dpdk.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: DPDK patches and discussions <dev.dpdk.org>
List-Unsubscribe: <https://mails.dpdk.org/options/dev>,
 <mailto:dev-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://mails.dpdk.org/archives/dev/>
List-Post: <mailto:dev@dpdk.org>
List-Help: <mailto:dev-request@dpdk.org?subject=help>
List-Subscribe: <https://mails.dpdk.org/listinfo/dev>,
 <mailto:dev-request@dpdk.org?subject=subscribe>
X-List-Received-Date: Mon, 21 Jan 2019 10:13:30 -0000

On 19-Jan-19 3:23 AM, Wang, Xiao W wrote:
> Hi Anatoly,
> 
>> -----Original Message-----
>> From: Burakov, Anatoly
>> Sent: Friday, January 18, 2019 6:25 PM
>> To: dev@dpdk.org
>> Cc: Wang, Xiao W <xiao.w.wang@intel.com>; Zhang, Qi Z
>> <qi.z.zhang@intel.com>; qingfu.cqf@alibaba-inc.com; thomas@monjalon.net;
>> Stojaczyk, Dariusz <dariusz.stojaczyk@intel.com>; stable@dpdk.org
>> Subject: [PATCH v2] vfio: allow secondary process to query IOMMU type
>>
>> It is only possible to know IOMMU type of a given VFIO container
>> by attempting to initialize it. Since secondary process never
>> attempts to set up VFIO container itself (because they're shared
>> between primary and secondary), it never knows which IOMMU type
>> the container is using, and never sets up the appropriate config
>> structures. This results in inability to perform DMA mappings in
>> secondary process.
>>
>> Fix this by allowing secondary process to query IOMMU type of
>> primary's default container at device initialization.
>>
>> Note that this fix is assuming we're only interested in default
>> container.
>>
>> Bugzilla ID: 174
>>
>> Fixes: 6bcb7c95fe14 ("vfio: share default container in multi-process")
>> Cc: dariusz.stojaczyk@intel.com
>> Cc: stable@dpdk.org
>>
>> Signed-off-by: Anatoly Burakov <anatoly.burakov@intel.com>
>> ---
>>
>> Notes:
>>      v2:
>>      - Check if we found our IOMMU type within list of IOMMU types
>>      - Don't request new default container fd as this should have
>>        been done during rte_vfio_enable()
>>
>>   lib/librte_eal/linuxapp/eal/eal_vfio.c        | 88 +++++++++++++++++++
>>   lib/librte_eal/linuxapp/eal/eal_vfio.h        | 12 ++-
>>   .../linuxapp/eal/eal_vfio_mp_sync.c           | 16 ++++
>>   3 files changed, 115 insertions(+), 1 deletion(-)
>>
>> diff --git a/lib/librte_eal/linuxapp/eal/eal_vfio.c
>> b/lib/librte_eal/linuxapp/eal/eal_vfio.c
>> index 72cc65151..c821e8382 100644
>> --- a/lib/librte_eal/linuxapp/eal/eal_vfio.c
>> +++ b/lib/librte_eal/linuxapp/eal/eal_vfio.c
>> @@ -549,6 +549,65 @@ vfio_mem_event_callback(enum rte_mem_event
>> type, const void *addr, size_t len,
>>   	}
>>   }
>>
>> +static int
>> +vfio_sync_default_container(void)
>> +{
>> +	struct rte_mp_msg mp_req, *mp_rep;
>> +	struct rte_mp_reply mp_reply;
>> +	struct timespec ts = {.tv_sec = 5, .tv_nsec = 0};
>> +	struct vfio_mp_param *p = (struct vfio_mp_param *)mp_req.param;
>> +	int iommu_type_id;
>> +	unsigned int i;
>> +
>> +	/* cannot be called from primary */
>> +	if (rte_eal_process_type() != RTE_PROC_SECONDARY)
>> +		return -1;
>> +
>> +	/* default container fd should have been opened in rte_vfio_enable()
>> */
>> +	if (!default_vfio_cfg->vfio_enabled ||
>> +			default_vfio_cfg->vfio_container_fd < 0) {
>> +		RTE_LOG(ERR, EAL, "VFIO support is not initialized\n");
>> +		return -1;
>> +	}
>> +
>> +	/* find default container's IOMMU type */
>> +	p->req = SOCKET_REQ_IOMMU_TYPE;
> 
> Since this function is to sync IOMMU type for the default container, should we make the req type as
> SOCKET_REQ_DEFAULT_IOMMU_TYPE?

Hi,

Sure, that can be done. However, i don't think it warrants a respin 
unless there's more important stuff to fix also. This patch is a 
stop-gap, and this stuff will be rewritten for 19.05, so getting this 
right is not that important :).

> 
> BRs,
> Xiao
> 


-- 
Thanks,
Anatoly