From patchwork Thu May 18 20:41:47 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Ben Pfaff X-Patchwork-Id: 764188 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from mail.linuxfoundation.org (mail.linuxfoundation.org [140.211.169.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3wTNQf3Sb8z9s1h for ; Fri, 19 May 2017 06:42:02 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 4706CBFB; Thu, 18 May 2017 20:41:59 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@mail.linuxfoundation.org Received: from smtp1.linuxfoundation.org (smtp1.linux-foundation.org [172.17.192.35]) by mail.linuxfoundation.org (Postfix) with ESMTPS id B8EE5BCF for ; Thu, 18 May 2017 20:41:57 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from relay7-d.mail.gandi.net (relay7-d.mail.gandi.net [217.70.183.200]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 96C1014B for ; Thu, 18 May 2017 20:41:56 +0000 (UTC) Received: from relay3-d.mail.gandi.net (relay3-d.mail.gandi.net [217.70.183.195]) by relay7-d.mail.gandi.net (Postfix) with ESMTPS id 58EDD3D8; Thu, 18 May 2017 22:41:54 +0200 (CEST) Received: from mfilter16-d.gandi.net (mfilter16-d.gandi.net [217.70.178.144]) by relay3-d.mail.gandi.net (Postfix) with ESMTP id 5081DA80CB; Thu, 18 May 2017 22:41:54 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at mfilter16-d.gandi.net Received: from relay3-d.mail.gandi.net ([IPv6:::ffff:217.70.183.195]) by mfilter16-d.gandi.net (mfilter16-d.gandi.net [::ffff:10.0.15.180]) (amavisd-new, port 10024) with ESMTP id BCQS6MfUBnMt; Thu, 18 May 2017 22:41:52 +0200 (CEST) X-Originating-IP: 208.91.2.3 Received: from ovn.org (unknown [208.91.2.3]) (Authenticated sender: blp@ovn.org) by relay3-d.mail.gandi.net (Postfix) with ESMTPSA id 91575A80C7; Thu, 18 May 2017 22:41:50 +0200 (CEST) Date: Thu, 18 May 2017 13:41:47 -0700 From: Ben Pfaff To: Darrell Ball Message-ID: <20170518204147.GU32729@ovn.org> References: <1491222467-13040-1-git-send-email-przemyslawx.lal@intel.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.23 (2014-03-12) X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Cc: "dev@openvswitch.org" , "Lal, PrzemyslawX" Subject: Re: [ovs-dev] [PATCH v5] netdev-dpdk: fix ifindex assignment for DPDK ports X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org On Thu, May 18, 2017 at 06:09:21PM +0000, Darrell Ball wrote: > > > On 4/4/17, 5:47 PM, "Darrell Ball" wrote: > > > > On 4/4/17, 3:09 AM, "Lal, PrzemyslawX" wrote: > > On 04/04/2017 06:14, Darrell Ball wrote: > > > > > On 4/3/17, 5:27 AM, "ovs-dev-bounces@openvswitch.org on behalf of Przemyslaw Lal" wrote: > > > > In current implementation port_id is used as an ifindex for all netdev-dpdk > > interfaces. > > > > For physical DPDK interfaces using port_id as ifindex causes that '0' is set as > > ifindex for 'dpdk0' interface, '1' for 'dpdk1' and so on. For the DPDK vHost > > interfaces ifindexes are not even assigned (0 is used by default) due to the > > fact that vHost ports don't use port_id field from the DPDK library. > > > > This causes multiple negative side-effects. First of all 0 is an invalid > > ifindex value. The other issue is possible overlapping of 'dpdkX' interfaces > > ifindex values with the ifindexes of kernel space interfaces which may cause > > problems in any external tools that use those values. Neither 'dpdk0', nor any > > DPDK vHost interfaces are visible in sFlow collector tools, as all interfaces > > with ifindexes smaller than 1 are ignored. > > > > Proposed solution to these issues is to calculate a hash of interface's name > > and use calculated value as an ifindex. This way interfaces keep their > > ifindexes during OVS-DPDK restarts, ports re-initialization events, etc., show > > up in sFlow collectors and meet RFC 2863 specification regarding re-using > > ifindex values by the same virtual interfaces and maximum ifindex value. > > > > Signed-off-by: Przemyslaw Lal > > --- > > lib/netdev-dpdk.c | 6 +++++- > > 1 file changed, 5 insertions(+), 1 deletion(-) > > > > diff --git a/lib/netdev-dpdk.c b/lib/netdev-dpdk.c > > index ddc651b..687b0a5 100644 > > --- a/lib/netdev-dpdk.c > > +++ b/lib/netdev-dpdk.c > > @@ -2215,7 +2215,11 @@ netdev_dpdk_get_ifindex(const struct netdev *netdev) > > int ifindex; > > > > ovs_mutex_lock(&dev->mutex); > > - ifindex = dev->port_id; > > + /* Calculate hash from the netdev name. Ensure that ifindex is a 24-bit > > + * postive integer to meet RFC 2863 recommendations. > > + */ > > + uint32_t h = hash_string(netdev->name, 0); > > + ifindex = (int)(h % 0xfffffe + 1); > > > > > > If user configuration was supported, enforcing uniqueness would be the > > responsibility of the user. > > This was already discussed on this mailing list and outcome was that while hash is not perfect, it is the best solution for now. > Also, please keep in mind that names of the physical DPDK devices and dpdkvhostuser interfaces are configurable, so user can still enforce > uniqueness. > > I know uniqueness could be enforced by trial and error of name selection. > I saw the comment > “At some point, with vhost-pmd we will have port_ids also for vhost interfaces. > Maybe we can revisit this approach when that becomes available.” > > If others are fine, then so am I. > > The uniqueness issue is understood and there is a workaround capability to > address it. > > Let us just fold the patch in, since the patch has been out for long enough to > receive feedback. > > Acked by: Darrell Ball Thanks Przemyslaw and Darrell. I applied this to master. I simplified the code since the cast to int was a no-op (it does the same thing as the conversion implied by the assignment: --8<--------------------------cut here-------------------------->8-- From: Przemyslaw Lal Date: Mon, 3 Apr 2017 13:27:47 +0100 Subject: [PATCH] netdev-dpdk: fix ifindex assignment for DPDK ports In current implementation port_id is used as an ifindex for all netdev-dpdk interfaces. For physical DPDK interfaces using port_id as ifindex causes that '0' is set as ifindex for 'dpdk0' interface, '1' for 'dpdk1' and so on. For the DPDK vHost interfaces ifindexes are not even assigned (0 is used by default) due to the fact that vHost ports don't use port_id field from the DPDK library. This causes multiple negative side-effects. First of all 0 is an invalid ifindex value. The other issue is possible overlapping of 'dpdkX' interfaces ifindex values with the ifindexes of kernel space interfaces which may cause problems in any external tools that use those values. Neither 'dpdk0', nor any DPDK vHost interfaces are visible in sFlow collector tools, as all interfaces with ifindexes smaller than 1 are ignored. Proposed solution to these issues is to calculate a hash of interface's name and use calculated value as an ifindex. This way interfaces keep their ifindexes during OVS-DPDK restarts, ports re-initialization events, etc., show up in sFlow collectors and meet RFC 2863 specification regarding re-using ifindex values by the same virtual interfaces and maximum ifindex value. Signed-off-by: Przemyslaw Lal Signed-off-by: Ben Pfaff Acked by: Darrell Ball --- lib/netdev-dpdk.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/netdev-dpdk.c b/lib/netdev-dpdk.c index 609b8da33537..61bfe3499fe3 100644 --- a/lib/netdev-dpdk.c +++ b/lib/netdev-dpdk.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014, 2015, 2016 Nicira, Inc. + * Copyright (c) 2014, 2015, 2016, 2017 Nicira, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -2213,10 +2213,12 @@ static int netdev_dpdk_get_ifindex(const struct netdev *netdev) { struct netdev_dpdk *dev = netdev_dpdk_cast(netdev); - int ifindex; ovs_mutex_lock(&dev->mutex); - ifindex = dev->port_id; + /* Calculate hash from the netdev name. Ensure that ifindex is a 24-bit + * postive integer to meet RFC 2863 recommendations. + */ + int ifindex = hash_string(netdev->name, 0) % 0xfffffe + 1; ovs_mutex_unlock(&dev->mutex); return ifindex;