From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <ferruh.yigit@intel.com>
Received: from mga01.intel.com (mga01.intel.com [192.55.52.88])
 by dpdk.org (Postfix) with ESMTP id AFE3F3794
 for <dev@dpdk.org>; Thu,  4 Aug 2016 13:33:43 +0200 (CEST)
Received: from orsmga002.jf.intel.com ([10.7.209.21])
 by fmsmga101.fm.intel.com with ESMTP; 04 Aug 2016 04:33:42 -0700
X-ExtLoop1: 1
X-IronPort-AV: E=Sophos;i="5.28,470,1464678000"; d="scan'208";a="1029620406"
Received: from fyigit-mobl1.ger.corp.intel.com (HELO [10.237.220.104])
 ([10.237.220.104])
 by orsmga002.jf.intel.com with ESMTP; 04 Aug 2016 04:33:41 -0700
To: Igor Ryzhov <iryzhov@nfware.com>, dev@dpdk.org
References: <E1025756-36BA-4BC3-AA5D-279AE1025530@nfware.com>
Cc: David Marchand <david.marchand@6wind.com>
From: Ferruh Yigit <ferruh.yigit@intel.com>
Message-ID: <57A32814.1000404@intel.com>
Date: Thu, 4 Aug 2016 12:33:40 +0100
User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:38.0) Gecko/20100101
 Thunderbird/38.7.2
MIME-Version: 1.0
In-Reply-To: <E1025756-36BA-4BC3-AA5D-279AE1025530@nfware.com>
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: 8bit
Subject: Re: [dpdk-dev] rte_eth_dev_attach returns 0,
 although device is not attached
X-BeenThere: dev@dpdk.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: patches and discussions about DPDK <dev.dpdk.org>
List-Unsubscribe: <http://dpdk.org/ml/options/dev>,
 <mailto:dev-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://dpdk.org/ml/archives/dev/>
List-Post: <mailto:dev@dpdk.org>
List-Help: <mailto:dev-request@dpdk.org?subject=help>
List-Subscribe: <http://dpdk.org/ml/listinfo/dev>,
 <mailto:dev-request@dpdk.org?subject=subscribe>
X-List-Received-Date: Thu, 04 Aug 2016 11:33:44 -0000

Hi Igor,

On 8/3/2016 5:58 PM, Igor Ryzhov wrote:
> Hello.
> 
> Function rte_eth_dev_attach can return false positive result.
> It happens because rte_eal_pci_probe_one returns zero if no driver is found for the device:
> ret = pci_probe_all_drivers(dev);
> if (ret < 0)
> 	goto err_return;
> return 0;
> (pci_probe_all_drivers returns 1 in that case)
> 
> For example, it can be easily reproduced by trying to attach virtio device, managed by kernel driver.

You are right, and I did able to reproduce this issue with virtio as you
suggest.

But I wonder why rte_eth_dev_get_port_by_addr() is not catching this.
Perhaps a dev->attached check needs to be added into this function.

> 
> I think it should be:
> ret = pci_probe_all_drivers(dev);
> if (ret)
> 	goto err_return;
> return 0;

Your proposal looks good to me. Will you send a patch?

> Best regards,
> Igor
>