From patchwork Tue Jun 8 18:27:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 455829 Delivered-To: patch@linaro.org Received: by 2002:a02:735a:0:0:0:0:0 with SMTP id a26csp4031794jae; Tue, 8 Jun 2021 12:13:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxTYTkXNy3tAab1/xtOFqPVcrgjqaXmjmP6OTl5EG1+0I0UHfc8L7dgTIsERHotk/HLResM X-Received: by 2002:a17:906:fcaa:: with SMTP id qw10mr24779540ejb.233.1623179612602; Tue, 08 Jun 2021 12:13:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623179612; cv=none; d=google.com; s=arc-20160816; b=gtP4xbURdq/pQqEPCm7fRcteIENtyXbC5i3SKdSk50bRIuBwWuRaY3Hbxbafd5kTIR UBKDGCTtnUy4B/9edskfMFO0uWPYA8xZIPnEzTdJPXvcbOWBN+0K4GGwFz41zFyCA2LC D6eZk0ZJvwk0XUeb/6tPB54NHtFEtOHaqzAIh51+izfr8YEbI8H13dltQ60WvkKY22ZM Zo04CNxU0NCpJQHBEuDQVTvt8f9Jti36zFyAA4fUQLO5MZUUYQU+OsarsvG1NB74jgVm nFdrQbTdQNxHsoGSbyDJh4RAXj/Fz3kfL6tQjE2T9mi5aBVDnABdUv/eHtFzbYggNhHC u6Bw== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Vx5ruifHqWPQSbcKsA7LFNHMw80tIj5rpIi1DlSvAnY=; b=cMB4fMsrbL7czNHt6wkoh6wbKyTBC28PsP1+Wp6H9tNw3OPNSG0kbnDq3Z1cUoC5x5 fyovmOhedLgjniBtdP9sxXnJIgTgFS6OTj4mVAG/iHLKs4sbzh2Rdt5Je1NcAWk0eBWZ nfjsohZKh+69LvRNDQOVA5mVuZB3WYwGdagQRQXP7EIC/Y0Uc7+QuVyKkJbJ0P5pbCEV R2L+G01dR6/UHN+dcfUWXH0/w3Eql0334sPQgNlG4Iqb+bHp9810YSn+pxH2/U8xMJp5 0+EqSvrVKzrVEG1TYa75THnzqdmXgYhmd21dTBinFTbNDc9uNCh8u2jsAKTvrQhNq1rO aQ+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=pAJOU7iS; 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=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l23si509825ejb.573.2021.06.08.12.13.32; Tue, 08 Jun 2021 12:13:32 -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=@linuxfoundation.org header.s=korg header.b=pAJOU7iS; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235256AbhFHTNr (ORCPT + 12 others); Tue, 8 Jun 2021 15:13:47 -0400 Received: from mail.kernel.org ([198.145.29.99]:58766 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236904AbhFHTLn (ORCPT ); Tue, 8 Jun 2021 15:11:43 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 22DAF61461; Tue, 8 Jun 2021 18:49:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1623178149; bh=Xd8sKBW52rGJ+PBUBAVrXHiFQyeJpduTKPcd2uOIiJs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pAJOU7iSjknaCjlqvXIUxBUQ3XWY5xiPnaRzLIwG6+HPsNcYbDmvrYHKogJq4iggB sDQC/kTahG01i5EVHF79Tso+Fxd4HquB0AezoP9tjWRbyXQHgy+NBEkBq72wcQXBnx tV1mY77tgyL9KZz7W74CuqsLW7P0fwF7UPdxcnoQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Jason A. Donenfeld" , "David S. Miller" Subject: [PATCH 5.12 096/161] wireguard: use synchronize_net rather than synchronize_rcu Date: Tue, 8 Jun 2021 20:27:06 +0200 Message-Id: <20210608175948.698136203@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210608175945.476074951@linuxfoundation.org> References: <20210608175945.476074951@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Jason A. Donenfeld commit 24b70eeeb4f46c09487f8155239ebfb1f875774a upstream. 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 Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- drivers/net/wireguard/peer.c | 6 +++--- drivers/net/wireguard/socket.c | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) --- a/drivers/net/wireguard/peer.c +++ b/drivers/net/wireguard/peer.c @@ -89,7 +89,7 @@ static void peer_make_dead(struct wg_pee /* 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) @@ -161,7 +161,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); } @@ -179,7 +179,7 @@ void wg_peer_remove_all(struct wg_device 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); } --- a/drivers/net/wireguard/socket.c +++ b/drivers/net/wireguard/socket.c @@ -430,7 +430,7 @@ void wg_socket_reinit(struct wg_device * 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); }