From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <stephen@networkplumber.org>
Received: from mail-pg0-f67.google.com (mail-pg0-f67.google.com [74.125.83.67])
 by dpdk.org (Postfix) with ESMTP id 7AF13201
 for <dev@dpdk.org>; Tue, 12 Dec 2017 02:38:59 +0100 (CET)
Received: by mail-pg0-f67.google.com with SMTP id e14so12287505pgr.9
 for <dev@dpdk.org>; Mon, 11 Dec 2017 17:38:59 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=networkplumber-org.20150623.gappssmtp.com; s=20150623;
 h=date:from:to:cc:subject:message-id:in-reply-to:references
 :mime-version:content-transfer-encoding;
 bh=E5EvYCwaUsFHJsf+PDwTqAW0gj7Ga3PknMqkGDQx+4E=;
 b=Nj38vYdyTO9EgRtBxtnTfajw9Hp3VZ3RtZN5bQyfSSAiwt7OK7EC8Z7BVH+Gur/ZXm
 ulNHGh3K9OdvF5nxJl7LBfTmX8LZWRUwFupWuD8vxiezegCH/KBokiV/Sl+gPm2PhAGV
 SyTr2Nwkpc0zzitXFmV+Kub126/L/VkiuP3EQ4lUjd/G62Lyzk3PUmS+gL3tflnEgrxo
 EqlDJ38k0+gsM8D4IO/HOegdGDZk/WVBCfRknD4iM9LgjM7DFFRBvG1rYVmX4IdlK9F/
 ODxwSOKtGxEhl8N+eZuH7fVrYXfC4WbptivY9MBkbhZ6MZZHqEORFPw68GVv4bgyN0Ll
 Hi3w==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20161025;
 h=x-gm-message-state:date:from:to:cc:subject:message-id:in-reply-to
 :references:mime-version:content-transfer-encoding;
 bh=E5EvYCwaUsFHJsf+PDwTqAW0gj7Ga3PknMqkGDQx+4E=;
 b=F870jLQU0gbCeorx06LezWmbUtWJErycrh1e095ZYrTl1To7EMypx6J8gW5s0MUdIV
 5fgo5/Jn4O2ZfsYHiJIhmIs0XrsnluCYOozTY1g4PFuoesEEQ69+Dk0erelM05qhDElb
 SlZesBavDZk0292ncMKUQAYkRQ6W5zUCLgErA0bfsAMIevrTgkfdTWqLe63cy+AXY2Tg
 sK9URxXXFoOx9ya73z0OMJJDKXZy2R3jIiyEKiJonZqNdV/3wUDftPYBMLR8w4K3/Jve
 R566V+IyTwin8ZJ0a65qv6xD/VUxNyDMrX+s8woJI5pElpfao6F9lB0ooIuacyH0E9BB
 8ZiQ==
X-Gm-Message-State: AKGB3mLa4ebHkn8rVZagylGGkE+nZYk2sq7QAcUPvXnuBhudt+ThACXt
 /aXjyyAyoxVZz1Sy4MEs/2+N+pJeBQA=
X-Google-Smtp-Source: ACJfBotOlfGCI86QdlVMaomDZ7Mr+C6Ed+ESmaxr5isn2wJ/HxSk1RpED8EGJOaDXyws4sSMyh6EGQ==
X-Received: by 10.99.115.79 with SMTP id d15mr497059pgn.340.1513042738519;
 Mon, 11 Dec 2017 17:38:58 -0800 (PST)
Received: from xeon-e3 (76-14-207-240.or.wavecable.com. [76.14.207.240])
 by smtp.gmail.com with ESMTPSA id s73sm29215191pfi.167.2017.12.11.17.38.58
 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256);
 Mon, 11 Dec 2017 17:38:58 -0800 (PST)
Date: Mon, 11 Dec 2017 17:38:55 -0800
From: Stephen Hemminger <stephen@networkplumber.org>
To: Xiao Wang <xiao.w.wang@intel.com>
Cc: ferruh.yigit@intel.com, dev@dpdk.org
Message-ID: <20171211173855.3eed4623@xeon-e3>
In-Reply-To: <1512784653-128951-1-git-send-email-xiao.w.wang@intel.com>
References: <1512784653-128951-1-git-send-email-xiao.w.wang@intel.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Subject: Re: [dpdk-dev] [PATCH] igb_uio: allow multi-process access
X-BeenThere: dev@dpdk.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: DPDK patches and discussions <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: Tue, 12 Dec 2017 01:38:59 -0000

On Fri,  8 Dec 2017 17:57:33 -0800
Xiao Wang <xiao.w.wang@intel.com> wrote:

> In some case, one device are accessed by different processes via
> different BARs, so one uio device may be opened by more than one
> process, for this case we just need to enable interrupt once, and
> pci_clear_master only when the last process closed.
> 
> Fixes: 5f6ff30dc507 ("igb_uio: fix interrupt enablement after FLR in VM")


Yes, this makes sense.

> 
> Signed-off-by: Xiao Wang <xiao.w.wang@intel.com>
> ---
>  lib/librte_eal/linuxapp/igb_uio/igb_uio.c | 7 +++++++
>  1 file changed, 7 insertions(+)
> 
> diff --git a/lib/librte_eal/linuxapp/igb_uio/igb_uio.c b/lib/librte_eal/linuxapp/igb_uio/igb_uio.c
> index a3a98c1..c239d98 100644
> --- a/lib/librte_eal/linuxapp/igb_uio/igb_uio.c
> +++ b/lib/librte_eal/linuxapp/igb_uio/igb_uio.c
> @@ -45,6 +45,7 @@ struct rte_uio_pci_dev {
>  	struct uio_info info;
>  	struct pci_dev *pdev;
>  	enum rte_intr_mode mode;
> +	uint32_t ref_cnt;

Simple unsigned reference count is not SMP safe on all architectures.
In kernel it is recommended to use refcount_t and associated API's.
Note: refcount_t was introduced in last 2 years and some DPDK users
still have ancient kernels.

>  };
>  
>  static char *intr_mode;
> @@ -336,6 +337,9 @@ struct rte_uio_pci_dev {
>  	struct pci_dev *dev = udev->pdev;
>  	int err;
>  
> +	if (++(udev->ref_cnt) > 1)
> +		return 0;

Do not use (unnecessary) parenthesis. C precedence order is well defined.


>  	/* set bus master, which was cleared by the reset function */
>  	pci_set_master(dev);
>  
> @@ -354,6 +358,9 @@ struct rte_uio_pci_dev {
>  	struct rte_uio_pci_dev *udev = info->priv;
>  	struct pci_dev *dev = udev->pdev;
>  
> +	if (--(udev->ref_cnt) > 0)
> +		return 0;
> +
>  	/* disable interrupts */
>  	igbuio_pci_disable_interrupts(udev);
>