From patchwork Fri Jun 4 15:17:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Jason A. Donenfeld" X-Patchwork-Id: 454043 Delivered-To: patch@linaro.org Received: by 2002:a02:735a:0:0:0:0:0 with SMTP id a26csp508364jae; Fri, 4 Jun 2021 08:18:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzYg3ql+z4/BdjfLibPXQbg3CAfoGAkMPYnONdtuRqi1KBXK4hCYstj5y8UkRNDrz7Slnuc X-Received: by 2002:a17:906:fc4:: with SMTP id c4mr4916643ejk.111.1622819930240; Fri, 04 Jun 2021 08:18:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622819930; cv=none; d=google.com; s=arc-20160816; b=dpzxAPgY3ASt04qvqqrftP0L0WWtOwExmzMV5DOMNG7r/RJtRB2A780TmacI2ea+zx bkKR2pF6xd8KrXAjN6aTmIGalHAFYzAhIq4XfMmSNo6XYxGxnBeCp17Yg6W28k0ac+PR wZRfNsLGelCg164BbECE2frSozjRD6SdF5r+PZzT85M4D+PWmO2Edq6AygyK0OCexl1x US4qE3bVNIrH9tz/cM92vTyRfzlOJFCgs2kcTIPw90Z8GH5YHFBDevhr6r5an1b+NjRJ roalMZmCNEOP/m5XM5KSZz+CQ4hsKgROso3bX73VpBA2Y5CkwnV7F6fSsb1iH4iJgDy/ IFoQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Ew2oDN9uOXatxBQ4LLdwymBBFALjUrTav2zPF6ydiF4=; b=TGjeV5ZMHoC6BxkJaWtKlwwMnZIYw1gfeUrsFYeh/EfmvdpC/AB6LwydGMlT/BgNbj 6gROWZ+nYIx570MSkf0rSuSGxUcKR27cnKbRN7P9KyPGI5liksFXaAxiIL2OiExgRQdR RmuOvKoTKzSQHw18/8dqoQmUw+S2WUQzbKZvHQ/UdTFcoDhTVP/VNCgM79IU1MWwM9DK CZwzvjF/53xyhZJUI+CUugroskqgXbg7daTFU+548tgzKk4fQKe8mtFKzWbDCN4VmA9+ 6n8bLPeBMYZxWG6S2yyxyRkpDe/Q177a8T9trZqRno5FsJCDtjBO4+j3EYH4LdwWD9EZ /CCg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@zx2c4.com header.s=20210105 header.b=PmPYj8u0; spf=pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=zx2c4.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l15si4894987ejc.521.2021.06.04.08.18.50; Fri, 04 Jun 2021 08:18:50 -0700 (PDT) Received-SPF: pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@zx2c4.com header.s=20210105 header.b=PmPYj8u0; spf=pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=zx2c4.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230382AbhFDPTy (ORCPT + 12 others); Fri, 4 Jun 2021 11:19:54 -0400 Received: from mail.zx2c4.com ([104.131.123.232]:54948 "EHLO mail.zx2c4.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230374AbhFDPTv (ORCPT ); Fri, 4 Jun 2021 11:19:51 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zx2c4.com; s=20210105; t=1622819883; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Ew2oDN9uOXatxBQ4LLdwymBBFALjUrTav2zPF6ydiF4=; b=PmPYj8u0I9/Jb6nV0nhvQM7LjqfR7bq9lxX7zTnhZHhMkyubPvdzy+EMF+hynlNGcv/Fuo zcovG6a7Yq2pzDIEXORUFL11CPyeytXXV9il1zLCbQ6VfTFLMjJNjTWfteVfbzuft7xoo6 EV2am2nIb2c+AMTVyvHXkonV+SCS66w= Received: by mail.zx2c4.com (ZX2C4 Mail Server) with ESMTPSA id a67f05fe (TLSv1.3:AEAD-AES256-GCM-SHA384:256:NO); Fri, 4 Jun 2021 15:18:03 +0000 (UTC) From: "Jason A. Donenfeld" To: netdev@vger.kernel.org, davem@davemloft.net, kuba@kernel.org Cc: "Jason A. Donenfeld" , stable@vger.kernel.org Subject: [PATCH net 4/9] wireguard: use synchronize_net rather than synchronize_rcu Date: Fri, 4 Jun 2021 17:17:33 +0200 Message-Id: <20210604151738.220232-5-Jason@zx2c4.com> In-Reply-To: <20210604151738.220232-1-Jason@zx2c4.com> References: <20210604151738.220232-1-Jason@zx2c4.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org Many of the synchronization points are sometimes called under the rtnl lock, which means we should use synchronize_net rather than synchronize_rcu. Under the hood, this expands to using the expedited flavor of function in the event that rtnl is held, in order to not stall other concurrent changes. This fixes some very, very long delays when removing multiple peers at once, which would cause some operations to take several minutes. Fixes: e7096c131e51 ("net: WireGuard secure network tunnel") Cc: stable@vger.kernel.org Signed-off-by: Jason A. Donenfeld --- drivers/net/wireguard/peer.c | 6 +++--- drivers/net/wireguard/socket.c | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) -- 2.31.1 diff --git a/drivers/net/wireguard/peer.c b/drivers/net/wireguard/peer.c index cd5cb0292cb6..3a042d28eb2e 100644 --- a/drivers/net/wireguard/peer.c +++ b/drivers/net/wireguard/peer.c @@ -88,7 +88,7 @@ static void peer_make_dead(struct wg_peer *peer) /* Mark as dead, so that we don't allow jumping contexts after. */ WRITE_ONCE(peer->is_dead, true); - /* The caller must now synchronize_rcu() for this to take effect. */ + /* The caller must now synchronize_net() for this to take effect. */ } static void peer_remove_after_dead(struct wg_peer *peer) @@ -160,7 +160,7 @@ void wg_peer_remove(struct wg_peer *peer) lockdep_assert_held(&peer->device->device_update_lock); peer_make_dead(peer); - synchronize_rcu(); + synchronize_net(); peer_remove_after_dead(peer); } @@ -178,7 +178,7 @@ void wg_peer_remove_all(struct wg_device *wg) peer_make_dead(peer); list_add_tail(&peer->peer_list, &dead_peers); } - synchronize_rcu(); + synchronize_net(); list_for_each_entry_safe(peer, temp, &dead_peers, peer_list) peer_remove_after_dead(peer); } diff --git a/drivers/net/wireguard/socket.c b/drivers/net/wireguard/socket.c index d9ad850daa79..8c496b747108 100644 --- a/drivers/net/wireguard/socket.c +++ b/drivers/net/wireguard/socket.c @@ -430,7 +430,7 @@ void wg_socket_reinit(struct wg_device *wg, struct sock *new4, if (new4) wg->incoming_port = ntohs(inet_sk(new4)->inet_sport); mutex_unlock(&wg->socket_update_lock); - synchronize_rcu(); + synchronize_net(); sock_free(old4); sock_free(old6); }