From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755554AbcEZX4q (ORCPT ); Thu, 26 May 2016 19:56:46 -0400 Received: from smtprelay0176.hostedemail.com ([216.40.44.176]:41221 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1755162AbcEZX4p (ORCPT ); Thu, 26 May 2016 19:56:45 -0400 X-Session-Marker: 726F737465647440676F6F646D69732E6F7267 X-Spam-Summary: 2,0,0,,d41d8cd98f00b204,rostedt@goodmis.org,:::::::::::::::::,RULES_HIT:41:355:379:541:800:960:973:988:989:1260:1277:1311:1313:1314:1345:1437:1515:1516:1518:1534:1543:1593:1594:1711:1730:1747:1777:1792:1801:2194:2199:2393:2553:2559:2562:2693:2899:2904:3138:3139:3140:3141:3142:3354:3865:3867:3868:3870:3871:3872:3873:3874:4250:4321:4605:5007:6119:6261:7875:7903:8660:10004:10400:10848:11026:11473:11658:11914:12043:12291:12296:12438:12517:12519:12555:12679:12683:12740:13148:13161:13229:13230:13439:14093:14096:14097:14181:14394:14659:14721:21080:21433:30012:30045:30054:30070:30090,0,RBL:none,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fn,MSBL:0,DNSBL:none,Custom_rules:0:0:0,LFtime:3,LUA_SUMMARY:none X-HE-Tag: toad24_654da5e1b38 X-Filterd-Recvd-Size: 4482 Date: Thu, 26 May 2016 19:56:41 -0400 From: Steven Rostedt To: LKML , linux-rt-users , netdev Cc: Thomas Gleixner , Peter Zijlstra , Clark Williams , Eric Dumazet , David Miller , alison@peloton-tech.com Subject: [PATCH][RT] netpoll: Always take poll_lock when doing polling Message-ID: <20160526195641.6c26e979@gandalf.local.home> X-Mailer: Claws Mail 3.13.2 (GTK+ 2.24.30; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [ Alison, can you try this patch ] This uses netpoll_poll_lock()/unlock() to synchronize netpoll and napi poll operations. Without this method, the synchronization is done by looping on NAPI_STATE_SCHED 'bitset'. This method works fine on a non-rt kernel because a softirq can not be preempted, and the thread poll is called with local_bh_disable() which prevents softirqs from running and preempting it. But on rt, this code can be preempted. Thus, the code may be preempted out while holding the NAPI_STATE_SCHED 'bitset', opening a window for a livelock. For example: napi_schedule_prep() test_and_set_bit(NAPI_STATE_SCHED, &n->state) sk_busy_loop() do { rc = busy_poll() ret = napi_schedule_prep() return !test_and_set_bit(NAPI_STATE_SCHED, &n->state) if (!ret) return 0 } while (...) /* for ever */ This isn't a problem in non PREEMPT_RT because the napi_schedule_prep() can not be preempted. But because it can in PREEMPT_RT, we need to add some extra locking. The netpoll_poll_lock() works well here, but they need to be added around any call to busy_poll(). Using IS_ENABLED(CONFIG_PREEMPT_RT_FULL) will allow gcc to optimize out the extra calls to poll_lock. Tested-by: "Luis Claudio R. Goncalves" Reviewed-by: Daniel Bristot de Oliveira Signed-off-by: Steven Rostedt --- include/linux/netpoll.h | 2 +- include/net/busy_poll.h | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) Index: linux-rt.git/include/linux/netpoll.h =================================================================== --- linux-rt.git.orig/include/linux/netpoll.h 2016-05-26 18:31:09.183150389 -0400 +++ linux-rt.git/include/linux/netpoll.h 2016-05-26 18:52:02.657014280 -0400 @@ -77,7 +77,7 @@ static inline void *netpoll_poll_lock(st { struct net_device *dev = napi->dev; - if (dev && dev->npinfo) { + if (dev && (IS_ENABLED(CONFIG_PREEMPT_RT_FULL) || dev->npinfo)) { spin_lock(&napi->poll_lock); napi->poll_owner = smp_processor_id(); return napi; Index: linux-rt.git/include/net/busy_poll.h =================================================================== --- linux-rt.git.orig/include/net/busy_poll.h 2016-05-26 18:31:09.183150389 -0400 +++ linux-rt.git/include/net/busy_poll.h 2016-05-26 19:10:12.134266713 -0400 @@ -25,6 +25,7 @@ #define _LINUX_NET_BUSY_POLL_H #include +#include #include #ifdef CONFIG_NET_RX_BUSY_POLL @@ -97,7 +98,18 @@ static inline bool sk_busy_loop(struct s goto out; do { - rc = ops->ndo_busy_poll(napi); + /* When RT is enabled, napi_schedule_prep() can be preempted + * with NAPI_STATE_SCHED set, causing the busy_poll() function + * to always return zero, and this loop may never exit. + * In that case, we must always take the netpoll_poll_lock. + */ + if (IS_ENABLED(CONFIG_PREEMPT_RT_FULL)) { + void *have = netpoll_poll_lock(napi); + rc = ops->ndo_busy_poll(napi); + netpoll_poll_unlock(have); + } else { + rc = ops->ndo_busy_poll(napi); + } if (rc == LL_FLUSH_FAILED) break; /* permanent failure */