Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp520307yba; Mon, 1 Apr 2019 10:58:09 -0700 (PDT) X-Google-Smtp-Source: APXvYqzN26ym+g0COWpFbf4oXBBYj0rG1FS55OPxH8V14xISX87PVlt43kvCq7HZ40GvF/Kh6JDS X-Received: by 2002:a17:902:6b8a:: with SMTP id p10mr66095628plk.109.1554141489900; Mon, 01 Apr 2019 10:58:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554141489; cv=none; d=google.com; s=arc-20160816; b=OJ0rLRiwYlaPZO4dv9GQr7JVZLJDzR1alj7SwGBExzXxQCKE87dRaIh9KNZ+0n6cxV /u3loHyPRH1at7SDoSpzalf9cZmgzAuP4la4whGlBueL91B0iNvHfE2rn08D6i11l343 KvwZkELDueCsEXInToK87JOA7utgq6JOXkdXZh7ztOb4hVxT24DHq8/uUQJe77OiSWmG bB/TXizr/DurWHYjqAwVy5usBjYe0jRJfvRPs+vinxnMCpcBN411TXlNqkx06gcmAAlV Ao2oyGrWeupyzSg4Rqy8teZYZ01qMWcnClo0/48xnmJrn+nzxOi+keMO5T00H9oFnyDh D6sQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=zMp9BDHrggcE+jTSHLXDiX72s5WvFt/nY+uO2AfTdgg=; b=cAcMS8bpmHvv8BSKSz1DcCZv9ZoZMO+OpnphJMNyiOxS84rn5GogmkV21sqXD7sD2F X0JJVqeAHwz1CeBhLgzWNj45PecKNwuCDAhuyF9RPjmC4WoJEib8+DHeM77ECjRLMz6u +IODKHs/NOqo2FkBMNpDl7LdJGjznuwcWF498LJfqPLmpJhQFUEvAo7mMJCTH+U8cWWq XF7aM1M6Qs/1J5enjOLyTXeaptvuT63Y5miu3pVz4Mzjw2y52qaue9dw0Jbx3YbnMz5s OUFcvtlWeDwySEiwtZt3Y90v6fJ5GhPX1MwXWa9SS6bnOG/aJsqf7b+M7UEBit0octwL P6cw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=rLa8U5Ip; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h20si2674189pgv.352.2019.04.01.10.57.54; Mon, 01 Apr 2019 10:58:09 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=rLa8U5Ip; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731640AbfDARUZ (ORCPT + 99 others); Mon, 1 Apr 2019 13:20:25 -0400 Received: from mail.kernel.org ([198.145.29.99]:48520 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731630AbfDARUW (ORCPT ); Mon, 1 Apr 2019 13:20:22 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id C3B60206DD; Mon, 1 Apr 2019 17:20:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1554139221; bh=GHOgPrGOYX1REIZw7wKq7EofzCvD+5eBOEjr6BbJnGM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rLa8U5IpSXNbQhBbSfW4h65zr3YTnEWtiNKRTzba6vq3PRewaVCdQyx77IbiEg4rW EWCZO1LB8w5DwFF62Ja3nSC5Lpm+OwP+FL61WHQhKv7Ey/LzaDElfnk9AJWi/1O0bS TQo4/g+gUt1bUPiVrpgQw/FU2lQf2FrEumSuBprQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Maxime Chevallier , Willem de Bruijn , "David S. Miller" Subject: [PATCH 4.14 013/107] packets: Always register packet sk in the same order Date: Mon, 1 Apr 2019 19:01:28 +0200 Message-Id: <20190401170046.733093336@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190401170045.246405031@linuxfoundation.org> References: <20190401170045.246405031@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Maxime Chevallier [ Upstream commit a4dc6a49156b1f8d6e17251ffda17c9e6a5db78a ] When using fanouts with AF_PACKET, the demux functions such as fanout_demux_cpu will return an index in the fanout socket array, which corresponds to the selected socket. The ordering of this array depends on the order the sockets were added to a given fanout group, so for FANOUT_CPU this means sockets are bound to cpus in the order they are configured, which is OK. However, when stopping then restarting the interface these sockets are bound to, the sockets are reassigned to the fanout group in the reverse order, due to the fact that they were inserted at the head of the interface's AF_PACKET socket list. This means that traffic that was directed to the first socket in the fanout group is now directed to the last one after an interface restart. In the case of FANOUT_CPU, traffic from CPU0 will be directed to the socket that used to receive traffic from the last CPU after an interface restart. This commit introduces a helper to add a socket at the tail of a list, then uses it to register AF_PACKET sockets. Note that this changes the order in which sockets are listed in /proc and with sock_diag. Fixes: dc99f600698d ("packet: Add fanout support") Signed-off-by: Maxime Chevallier Acked-by: Willem de Bruijn Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- include/net/sock.h | 6 ++++++ net/packet/af_packet.c | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) --- a/include/net/sock.h +++ b/include/net/sock.h @@ -682,6 +682,12 @@ static inline void sk_add_node_rcu(struc hlist_add_head_rcu(&sk->sk_node, list); } +static inline void sk_add_node_tail_rcu(struct sock *sk, struct hlist_head *list) +{ + sock_hold(sk); + hlist_add_tail_rcu(&sk->sk_node, list); +} + static inline void __sk_nulls_add_node_rcu(struct sock *sk, struct hlist_nulls_head *list) { hlist_nulls_add_head_rcu(&sk->sk_nulls_node, list); --- a/net/packet/af_packet.c +++ b/net/packet/af_packet.c @@ -3281,7 +3281,7 @@ static int packet_create(struct net *net } mutex_lock(&net->packet.sklist_lock); - sk_add_node_rcu(sk, &net->packet.sklist); + sk_add_node_tail_rcu(sk, &net->packet.sklist); mutex_unlock(&net->packet.sklist_lock); preempt_disable();