From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-11.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5B3A5C433E0 for ; Wed, 17 Mar 2021 18:59:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2FDAB64F5E for ; Wed, 17 Mar 2021 18:59:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231322AbhCQS7R (ORCPT ); Wed, 17 Mar 2021 14:59:17 -0400 Received: from mail.kernel.org ([198.145.29.99]:41472 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232388AbhCQS6x (ORCPT ); Wed, 17 Mar 2021 14:58:53 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id F3B9864DDF; Wed, 17 Mar 2021 18:58:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1616007531; bh=2X7hZf7Mbj3I22kgp5FFUCDj9EdssAgFUaQuqjj5aaU=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=WoegWE2R/sejIAtKJvR1N7u7JJcx26LLNGMidIEUO6KfXl2luhCihSJLIGSC4dlME iXcfYsOsjoEY312/mG1zIpu9QXbe7qmAw/K18rxxzTqE7eIRNRy3vpDzlQlun6fHyW gMGMtd6Akq6rLlZT72OunzQscGXpSshgi/werx3kxlDD7yW4eJDaIztYDSvy4Gvwlg aav1BixfDRg8YCNeN+WVPhGm6XSPsA+3TXWlezJd0jTyeQUhStrBmr6XOnBkMR1PZe z9fnC5MFXDoRwW/ynTJKoDB412t2ni3JQ04lfY+Bnq+A3lYRhiUNpEv7jHuYO8o3YX U+TpTmxS9PdkA== Date: Wed, 17 Mar 2021 11:58:49 -0700 From: Jakub Kicinski To: Wei Wang Cc: "David S . Miller" , netdev@vger.kernel.org, Martin Zaharinov , Alexander Duyck , Eric Dumazet , Paolo Abeni , Hannes Frederic Sowa Subject: Re: [PATCH net v4] net: fix race between napi kthread mode and busy poll Message-ID: <20210317115849.36d915ec@kicinski-fedora-pc1c0hjn.dhcp.thefacebook.com> In-Reply-To: <20210316223647.4080796-1-weiwan@google.com> References: <20210316223647.4080796-1-weiwan@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org On Tue, 16 Mar 2021 15:36:47 -0700 Wei Wang wrote: > Currently, napi_thread_wait() checks for NAPI_STATE_SCHED bit to > determine if the kthread owns this napi and could call napi->poll() on > it. However, if socket busy poll is enabled, it is possible that the > busy poll thread grabs this SCHED bit (after the previous napi->poll() > invokes napi_complete_done() and clears SCHED bit) and tries to poll > on the same napi. napi_disable() could grab the SCHED bit as well. > This patch tries to fix this race by adding a new bit > NAPI_STATE_SCHED_THREADED in napi->state. This bit gets set in > ____napi_schedule() if the threaded mode is enabled, and gets cleared > in napi_complete_done(), and we only poll the napi in kthread if this > bit is set. This helps distinguish the ownership of the napi between > kthread and other scenarios and fixes the race issue. > > Fixes: 29863d41bb6e ("net: implement threaded-able napi poll loop support") > Reported-by: Martin Zaharinov > Suggested-by: Jakub Kicinski > Signed-off-by: Wei Wang > Cc: Alexander Duyck > Cc: Eric Dumazet > Cc: Paolo Abeni > Cc: Hannes Frederic Sowa Signed-off-by: Jakub Kicinski