From patchwork Wed May 6 21:33:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Jason A. Donenfeld" X-Patchwork-Id: 219740 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=-6.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, 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 6CC1CC38A2A for ; Wed, 6 May 2020 21:33:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 40B642076D for ; Wed, 6 May 2020 21:33:29 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=zx2c4.com header.i=@zx2c4.com header.b="hAPSsmxq" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729947AbgEFVd2 (ORCPT ); Wed, 6 May 2020 17:33:28 -0400 Received: from mail.zx2c4.com ([192.95.5.64]:53575 "EHLO mail.zx2c4.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729199AbgEFVdY (ORCPT ); Wed, 6 May 2020 17:33:24 -0400 Received: by mail.zx2c4.com (ZX2C4 Mail Server) with ESMTP id d6bef07c; Wed, 6 May 2020 21:20:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=zx2c4.com; h=from:to:cc :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; s=mail; bh=kYi8KCe/dSke//200kwKYMPwC Ws=; b=hAPSsmxqfO8x9h3iAXlk7tm1bfYteu7CjlUzD/d4RzRQ2CY4lr/6UZTyW 2/j3U/J6CpFDzho4nHB1+lJ93YE2k2w3sk4J4pqtCj5b6A2ZxnIg7JBRat9On8b8 teVQoSy121G9ZLGIlds08OkGofss9C/mltHCTMmlDLUb0UjQ8MHYwFgs5SlRysdC eXftaIrtM03zltfmM62ifNtftuukgTsTzv3/W6y9GkesPsorx42WU1XSYkifUA6S RImB/EJNxvp7d1kJQ3oDyUBkw+U0Z8kMnkhM2U0yhI0aQAJ1EmvoDJpvi5mKHHsZ w3cE8TKGcVZxoJH4YWL741A3NkDfg== Received: by mail.zx2c4.com (ZX2C4 Mail Server) with ESMTPSA id 01b67c00 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Wed, 6 May 2020 21:20:39 +0000 (UTC) From: "Jason A. Donenfeld" To: davem@davemloft.net, netdev@vger.kernel.org Cc: "Jason A. Donenfeld" , Sultan Alsawaf , Wang Jian Subject: [PATCH net 3/5] wireguard: send/receive: cond_resched() when processing worker ringbuffers Date: Wed, 6 May 2020 15:33:04 -0600 Message-Id: <20200506213306.1344212-4-Jason@zx2c4.com> In-Reply-To: <20200506213306.1344212-1-Jason@zx2c4.com> References: <20200506213306.1344212-1-Jason@zx2c4.com> MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Users with pathological hardware reported CPU stalls on CONFIG_ PREEMPT_VOLUNTARY=y, because the ringbuffers would stay full, meaning these workers would never terminate. That turned out not to be okay on systems without forced preemption, which Sultan observed. This commit adds a cond_resched() to the bottom of each loop iteration, so that these workers don't hog the core. Note that we don't need this on the napi poll worker, since that terminates after its budget is expended. Suggested-by: Sultan Alsawaf Reported-by: Wang Jian Fixes: e7096c131e51 ("net: WireGuard secure network tunnel") Signed-off-by: Jason A. Donenfeld --- drivers/net/wireguard/receive.c | 2 ++ drivers/net/wireguard/send.c | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/drivers/net/wireguard/receive.c b/drivers/net/wireguard/receive.c index 267f202f1931..2566e13a292d 100644 --- a/drivers/net/wireguard/receive.c +++ b/drivers/net/wireguard/receive.c @@ -516,6 +516,8 @@ void wg_packet_decrypt_worker(struct work_struct *work) &PACKET_CB(skb)->keypair->receiving)) ? PACKET_STATE_CRYPTED : PACKET_STATE_DEAD; wg_queue_enqueue_per_peer_napi(skb, state); + if (need_resched()) + cond_resched(); } } diff --git a/drivers/net/wireguard/send.c b/drivers/net/wireguard/send.c index 3e030d614df5..dc3079e17c7f 100644 --- a/drivers/net/wireguard/send.c +++ b/drivers/net/wireguard/send.c @@ -281,6 +281,8 @@ void wg_packet_tx_worker(struct work_struct *work) wg_noise_keypair_put(keypair, false); wg_peer_put(peer); + if (need_resched()) + cond_resched(); } } @@ -304,6 +306,8 @@ void wg_packet_encrypt_worker(struct work_struct *work) } wg_queue_enqueue_per_peer(&PACKET_PEER(first)->tx_queue, first, state); + if (need_resched()) + cond_resched(); } }