Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DA6D6C433EF for ; Thu, 11 Nov 2021 01:44:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BF9566187A for ; Thu, 11 Nov 2021 01:44:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233140AbhKKBro (ORCPT ); Wed, 10 Nov 2021 20:47:44 -0500 Received: from mail.kernel.org ([198.145.29.99]:49984 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231312AbhKKBrm (ORCPT ); Wed, 10 Nov 2021 20:47:42 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 3EECB6152A; Thu, 11 Nov 2021 01:44:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1636595094; bh=NlZ2LprdXDO5Hwn424/uwgcaVgQOHgvTAdrucmqWuqA=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=J3E+8a4ndMmqVxp5n5J8PAWs6d+O9sjkZay5C6IO2MABfKIZorLHkvYczeYCfMEVi g4RfZ25SKcMHjkaxSndKXX7QdOBv7E4OGBghgJhhkTQMLxCfPrrojm3lfCPURaWNw7 mp0c2sMQmsNrIG1RemcFa6k85dsPUwYf3aL2oz9zLAmyst6QEa/6sqFmKAb9OOzUrQ lLDPqBKpEQpCe6iaBWMWZU0jewJgNFIurFefnwEa9dJI01euRzV9JSZ9Z09pAcEe/8 Xc9FzTH8zL03k8sbKq8BbuUIaLeb++HHVI5FYZRCOr8jBRA6W199digX4+QbHGI8uo rGFJyZD+FWq4w== Date: Wed, 10 Nov 2021 17:44:53 -0800 From: Jakub Kicinski To: Alexander Lobakin Cc: Eric Dumazet , "David S. Miller" , Jesse Brandeburg , Maciej Fijalkowski , Michal Swiatkowski , Xuan Zhuo , Antoine Tenart , Wei Wang , =?UTF-8?B?QmrDtnJuIFTDtnBlbA==?= , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH net] net: fix premature exit from NAPI state polling in napi_disable() Message-ID: <20211110174453.3cb33cde@kicinski-fedora-pc1c0hjn.dhcp.thefacebook.com> In-Reply-To: <20211110174407.2b9083a9@kicinski-fedora-pc1c0hjn.dhcp.thefacebook.com> References: <20211110191126.1214-1-alexandr.lobakin@intel.com> <20211110194337.179-1-alexandr.lobakin@intel.com> <20211110174407.2b9083a9@kicinski-fedora-pc1c0hjn.dhcp.thefacebook.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 10 Nov 2021 17:44:07 -0800 Jakub Kicinski wrote: > On Wed, 10 Nov 2021 20:43:37 +0100 Alexander Lobakin wrote: > > > What about replacing the error prone do {...} while (cmpxchg(..)) by > > > something less confusing ? > > > > > > This way, no need for a label. > > > > > > diff --git a/net/core/dev.c b/net/core/dev.c > > > index 5e37d6809317fb3c54686188a908bfcb0bfccdab..9327141892cdaaf0282e082e0c6746abae0f12a7 > > > 100644 > > > --- a/net/core/dev.c > > > +++ b/net/core/dev.c > > > @@ -6264,7 +6264,7 @@ void napi_disable(struct napi_struct *n) > > > might_sleep(); > > > set_bit(NAPI_STATE_DISABLE, &n->state); > > > > > > - do { > > > + for (;;) { > > > val = READ_ONCE(n->state); > > > if (val & (NAPIF_STATE_SCHED | NAPIF_STATE_NPSVC)) { > > > usleep_range(20, 200); > > > @@ -6273,7 +6273,9 @@ void napi_disable(struct napi_struct *n) > > > > > > new = val | NAPIF_STATE_SCHED | NAPIF_STATE_NPSVC; > > > new &= ~(NAPIF_STATE_THREADED | NAPIF_STATE_PREFER_BUSY_POLL); > > > - } while (cmpxchg(&n->state, val, new) != val); > > > + if (cmpxchg(&n->state, val, new) == val) > > > + break; > > > + } > > > > > > hrtimer_cancel(&n->timer); > > > > LFTM, I'l queue v2 in a moment with you in Suggested-by. > > Ouch. > > Feel free to put > > Acked-by: Jakub Kicinski Or I'll do it myself since it's already out...