From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr0-f179.google.com (mail-wr0-f179.google.com [209.85.128.179]) by dpdk.org (Postfix) with ESMTP id BCBF81B210 for ; Fri, 20 Oct 2017 12:35:31 +0200 (CEST) Received: by mail-wr0-f179.google.com with SMTP id l1so10965638wrc.3 for ; Fri, 20 Oct 2017 03:35:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=6wind-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=DpJio0x6J6SJpBINjMXFGQo4OIJu47Q1CSJTMvQ0dJI=; b=CVOZGkDpSkVU7QuEEui7CVhGdO4uPEhFvSiYA40CitKY3lVQ0VxHjrta/Yhir58mTP OWZhr4MY9Th8IR5zitg+S+pAxqbO6mELgUVdDyBYX8mYHFwhREcTOZVhVDnQLPFID+TJ p4Fu47motAoN6+zBSQGykzrluYdnt/a4D4+9o5UuAnqw0+mxtvxQHN7bz6n3w6yCiZ80 7qSJHyJ+Ib67k39iShOfBmGxXDtFh26rzvoJVb5thS4nA6X6qYgk2fllxpL76ULgY0pS UUGwPD9sfOnYyzLNIcYhNLPkOl3a1xZm70rmmp4s3XI0uM8//Xcw1kBVaedLOGnHPmv6 s10w== 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:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to:user-agent; bh=DpJio0x6J6SJpBINjMXFGQo4OIJu47Q1CSJTMvQ0dJI=; b=OO3Y5dEA8HxoKIKtOwddocWyLAdrAkWPfrTiex4DTSo60MKVj+Ik0w7qzZBKiypJrG ymvAv91HxBd7AMgfHpKZXVL+bkVibX8QNnV8kZaku/sXnlBpRJG0L5VWV9YSpQO41J66 SjXBEsdE0fQePf7xz5mjWWdtSjyygqQSsr7FzYP9WJDcuOZiASMIbHyXrL9cOKcbOETp 92jWc9DfPybN5qhkFUBDhPinDN5WBMGFTTc8RQieKhyVPYCzX79XwystJgBttvLlA9+3 WOOVjG6wLYOimCQnsfq0U9Zb1Dt0h9ZBFt2nqAUzFsV80MtJKgvNUu0LsKckImX3bMMs 98qQ== X-Gm-Message-State: AMCzsaUT1zJUvBtjQedHTlZfDiptfdNVtrN42zsrUl3TXsJjQmXgqOOI XTn7Bg/uBl/TOgX8TpOvm+xMcA== X-Google-Smtp-Source: ABhQp+QYEnaIodNlYH/D2DfpZ3I/lBh4pR1WsG0FoXwcVq3oDGRtOllg+/xPKpz1a7Pi5+3D1AX0Zg== X-Received: by 10.223.157.136 with SMTP id p8mr4397652wre.28.1508495730939; Fri, 20 Oct 2017 03:35:30 -0700 (PDT) Received: from bidouze.vm.6wind.com (host.78.145.23.62.rev.coltfrance.com. [62.23.145.78]) by smtp.gmail.com with ESMTPSA id d129sm1519104wmf.34.2017.10.20.03.35.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 20 Oct 2017 03:35:29 -0700 (PDT) Date: Fri, 20 Oct 2017 12:35:18 +0200 From: =?iso-8859-1?Q?Ga=EBtan?= Rivet To: Ophir Munk Cc: dev@dpdk.org, Thomas Monjalon , Olga Shern , stable@dpdk.org Message-ID: <20171020103518.GH3596@bidouze.vm.6wind.com> References: <1506203877-2090-1-git-send-email-ophirmu@mellanox.com> <1507243328-11287-1-git-send-email-ophirmu@mellanox.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <1507243328-11287-1-git-send-email-ophirmu@mellanox.com> User-Agent: Mutt/1.5.23 (2014-03-12) Subject: Re: [dpdk-dev] [PATCH v3] net/failsafe: fix calling device during RMV events X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 20 Oct 2017 10:35:32 -0000 Hi Ophir, Sorry about the delay, I have a few remarks, I think this patch could be simpler. First, about the commit logline: "calling device" is not descriptive enough. I'd suggest net/failsafe: fix device configuration during RMV events But I'm not a native speaker either, so use it if you think it is better, or don't, it's only a suggestion :). On Thu, Oct 05, 2017 at 10:42:08PM +0000, Ophir Munk wrote: > This commit prevents control path operations from failing after a sub > device removal. > > Following are the failure steps: > 1. The physical device is removed due to change in one of PF parameters > (e.g. MTU) > 2. The interrupt thread flags the device > 3. Within 2 seconds Interrupt thread initializes the actual device removal, > then every 2 seconds it tries to re-sync (plug in) the device. The trials > fail as long as VF parameter mismatches the PF parameter. > 4. A control thread initiates a control operation on failsafe which > initiates this operation on the device. > 5. A race condition occurs between the control thread and interrupt thread > when accessing the device data structures. > > This commit prevents the race condition in step 5. Before this commit if a > device was removed and then a control thread operation was initiated on > failsafe - in some cases failsafe called the sub device operation instead > of avoiding it. Such cases could lead to operations failures. > This is a nitpick, but as said earlier, this is not preventing the race condition. This race is still present and can still wreak havok on unsuspecting users. If an application has a weak threading model, it will be subject to this race condition still. It is possible to prevent it fully with proper care from the application standpoint, but this is not specific to fail-safe and does not concern us here. Anyway, it's really a nitpick, I just wanted to point it out. This is not too important for this patch. > This commit fixes failsafe criteria to determine when the device is removed > such that it will avoid calling the sub device operations during that time > and will only call them otherwise. > > Fixes: a46f8d584eb8 ("net/failsafe: add fail-safe PMD") > Cc: stable@dpdk.org > > Signed-off-by: Ophir Munk > --- > v3: > 1. Rebase v2 > > 2. Please ignore checkpatch checks on arguments re-usage - they are confirmed. > CHECK:MACRO_ARG_REUSE: Macro argument reuse ... possible side-effects? > #217: FILE: drivers/net/failsafe/failsafe_private.h:241: > > 3. Add rationales (copy from an email which accompanied v2): > > On Monday, September 11, 2017 11:31 AM, Gaetan Rivet wrote: > > > > Hi Ophir, > > > > On Sat, Sep 09, 2017 at 07:27:11PM +0000, Ophir Munk wrote: > > > This commit prevents control path operations from failing after a > > > sub device has informed failsafe it has been removed. > > > > > > Before this commit if a device was removed and then a control path > > > > Here are the steps if I understood correctly: > > > > 0. The physical device is removed > > 1. The interrupt thread flags the device 2. A control lcore initiates > > a control operation 3. The alarm triggers, waking up the eal-intr-thread, > > initiating the actual device removal. > > 4. Race condition occurs between control lcore and interrupt thread. > > > > "if a device was removed" is ambiguous I think (are we speaking about > > the physical port? Is it only flagged? Is it after the removal of the device itself?). > > From the context I gather that you mean the device is flagged to be > > removed, but it won't be as clear in a few month when we revisit this bug :) . > > > > Could you please rephrase this so that the whole context of the issue > > is available? > > > > Done. Commit message was rephrased based on your comments > > > > operations was initiated on failsafe - in some cases failsafe called > > > the sub device operation instead of avoiding it. Such cases could > > > lead to operations failures. > > > > > > This commit fixes failsafe criteria to determine when the device is > > > removed such that it will avoid calling the sub device operations > > > during that time and will only call them otherwise. > > > > > > > This commit mitigates the race condition, reducing the probability for > > it to have an effect. It does not, however, remove this race > > condition, which is inherent to the DPDK architecture at the moment. > > > > A proper fix, a more detailed workaround and additional documentation > > warning users writing applications to mind their threads could be interesting. > > > > The race condition occurs in the last step and may lead to segmentation faults (accessing data structures > of the same device by 2 threads) The previous steps ("the physical device is removed", etc) were not > recreated and tested but probably cannot lead to segmentation fault. > > > But let's focus on this patch for the time being. > > > > > Fixes: a46f8d584eb8 ("net/failsafe: add fail-safe PMD") > > > Cc: stable@dpdk.org > > > > > > Signed-off-by: Ophir Munk > > > --- > > > drivers/net/failsafe/failsafe_ether.c | 1 + > > > drivers/net/failsafe/failsafe_ops.c | 52 > > +++++++++++++++++++++++++++++------ > > > 2 files changed, 45 insertions(+), 8 deletions(-) > > > > > > diff --git a/drivers/net/failsafe/failsafe_ether.c > > > b/drivers/net/failsafe/failsafe_ether.c > > > index a3a8cce..1def110 100644 > > > --- a/drivers/net/failsafe/failsafe_ether.c > > > +++ b/drivers/net/failsafe/failsafe_ether.c > > > @@ -378,6 +378,7 @@ > > > > Could you please generate your patches with the function name in the diff? > > Done > > > > > > i); > > > goto err_remove; > > > } > > > + sdev->remove = 0; > > > > You are adding this here, within failsafe_eth_dev_state_sync, and > > removing it from the dev_configure ops. > > > > 10 lines above, the call to dev_configure is done, meaning that the > > remove flag was resetted at this point. > > > > Can you explain why you prefer resetting the flag here? > > > > The position of this flag reset will be dependent upon my subsequent > > remarks anyway, so hold that thought :) . > > > > The motivation for resetting the "remove" flag within failsafe_eth_dev_state_sync is as follows: > Previously to this patch the "remove" flag was designed to signal the need to remove the sub device. > Once the sub device was removed and before being reconfigured the "remove" flag was reset. > > After this patch the scope of the "remove" flag was *extended* to indicate the sub device status as > being "plugged out" by resetting this flag only after a successful call to failsafe_eth_dev_state_sync(). > The "plug out" status could last a very long time (seconds, minutes, days, weeks, ...). > > Previously to this patch failsafe based the "plugged out" status on the sub device state as being below > ACTIVE however every 2 seconds dev_configure() was called where the sub device was assigned sdev- > >state = DEV_ACTIVE; therefore the sub device state became ACTIVE for some time every 2 seconds. > This is where the race condition occurred: failsafe considered the sub device as "Plugged in" for some > time every 2 seconds (based on its ACTIVE state) while it was actually plugged out. > > After this patch the "Plugged out" status is based on the "remove" flag. > Sorry, I do not agree with this semantical change on the "remove" flag. You are essentially adding a new device state, which could be fine per se, but should not be done here. The enum dev_state is there for this purpose. The flag dev->remove, calls for an operation to be done upon the concerned device. It is not meant to become a new device state. A point about the work methodoly here: if you wanted to change this semantic, which could be legitimate and sometimes called for, you should have proposed it either during a discussion in a response to my previous email, or introducing the change as a separate patch. This point is important enough for it to have its own patch, meaning we would have a whole thread dedicated to it instead of having to interleave commentaries between related-but-separate diffs on the code. But anyway, if you think you need to express a PLUGOUT state, I'd suggest adding a state between DEV_UNDEFINED and DEV_PARSED. DEV_UNDEFINED means that the device is in limbo and has no existence per se (its parsing failed for example, it is not clear whether the parameters are correct, etc...). DEV_PLUGOUT could mean then that the device has been successfully probed at least once, meaning that it could possibly have residuals from this probing still there, or specific care to be taken when manipulating it. However, I'm not yet convinced that this new state is necessary. I think you can mitigate this race condition without having to add it. If you insist in introducing this state, please do so in a separate patch, with proper definition about the meaning of this state: + When it should be valid for a device to be in this state. + Which operation corresponds to getting into and out of this state. + Why this state is interesting and what could not be expressed before that is thus being fixed by introducing this state. But please verify twice whether you absolutely need to complexify the current fail-safe internals before going all in and basing your work upon it :) > > > } > > > } > > > /* > > > diff --git a/drivers/net/failsafe/failsafe_ops.c > > > b/drivers/net/failsafe/failsafe_ops.c > > > index ff9ad15..314d53d 100644 > > > --- a/drivers/net/failsafe/failsafe_ops.c > > > +++ b/drivers/net/failsafe/failsafe_ops.c > > > @@ -232,7 +232,6 @@ > > > dev->data->dev_conf.intr_conf.lsc = 0; > > > } > > > DEBUG("Configuring sub-device %d", i); > > > - sdev->remove = 0; > > > ret = rte_eth_dev_configure(PORT_ID(sdev), > > > dev->data->nb_rx_queues, > > > dev->data->nb_tx_queues, > > > @@ -311,6 +310,8 @@ > > > int ret; > > > > > > FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) { > > > + if (sdev->remove) > > > + continue; > > > DEBUG("Calling rte_eth_dev_set_link_up on sub_device %d", > > i); > > > ret = rte_eth_dev_set_link_up(PORT_ID(sdev)); > > > if (ret) { > > > @@ -330,6 +331,8 @@ > > > int ret; > > > > > > FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) { > > > + if (sdev->remove) > > > + continue; > > > > For this change and all the others: > > > > I think it might be best to have this check added to fs_find_next directly. > > > > Most of the call to the iterators are done within dev_ops, so it makes > > sense I think to have it there. > > > > But then there'd be an issue with the sub-EAL iterations done on > > previously- removed ports, as the removed flag is precisely resetted > > too late. The function failsafe_dev_remove would also need to have a > > manual iteration upon the sub-devices instead of using the macro. > > > > I think you can actually reset this flag within fs_dev_remove, instead > > of the next plug-in, then having this check within fs_find_next > > *should* not be a problem. > > > > With the new scope of "remove" flag (remaining set to 1 as long as the sub device is "plugged out" > which may last for a very long time) we cannot reset it in fs_dev_remove which is called every 2 > seconds. > With the remove flag staying as it is, I think it should thus be resetted within fs_dev_remove. Actually I think it both helps you write you fix, and clarify the meaning and intended purpose of this flag. > > I think you should break up those changes in two: first move the flag > > reset to fs_dev_remove instead of fs_dev_configure, then add this > > check to the iterator. > > Please, do this fix this way. I think moving the dev->remove flag can have subtile consequences, and I'd like to have a specific commit to trace back which one is responsible. > > This way, a git bisect should allow us to pinpoint more easily any new > > bug as both changes have the potential to introduce subtle ones. > > Well, like I said :). > > I suggest defining a new macro > > FOREACH_SUBDEV_ACTIVE(sdev, i, dev) { ... > > that will replace all cases of: > > FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) { > if (sdev->remove) > continue; > > In order to support the new macro I added a "check_remove" flag to fs_find_next (which is based on > your idea above: "I think it might be best to have this check added to fs_find_next directly"). > I'd prefer avoiding multiplying the macros. There are already two iterators. You add one, which now means that there are two ways of iterating upon active devices: using you new macro, and using the old one. The difference between the two would be difficult to know, without profound knowledge of the rest of the code: that in one place the flag is checked, and in the other it is not. As such, I suggest you check in all cases that the flag is not set. This simplifies the use of these macros and the conditions in which their use is correct. This means that you have to manually iterate in places where this flag should be ignored. I listed these places in my previous email, but I may have missed some, please be careful. Thanks, -- Gaëtan Rivet 6WIND