From patchwork Wed Dec 6 00:02:48 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julia Cartwright X-Patchwork-Id: 844972 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3yrzMt3gXDz9s82 for ; Wed, 6 Dec 2017 11:03:06 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753221AbdLFADA (ORCPT ); Tue, 5 Dec 2017 19:03:00 -0500 Received: from mx0a-00010702.pphosted.com ([148.163.156.75]:51278 "EHLO mx0b-00010702.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752981AbdLFAC4 (ORCPT ); Tue, 5 Dec 2017 19:02:56 -0500 Received: from pps.filterd (m0098780.ppops.net [127.0.0.1]) by mx0a-00010702.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id vB600dV5025752; Tue, 5 Dec 2017 18:02:51 -0600 Received: from ni.com (skprod3.natinst.com [130.164.80.24]) by mx0a-00010702.pphosted.com with ESMTP id 2empdbtn25-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 05 Dec 2017 18:02:51 -0600 Received: from us-aus-exch1.ni.corp.natinst.com (us-aus-exch1.ni.corp.natinst.com [130.164.68.11]) by us-aus-skprod3.natinst.com (8.16.0.21/8.16.0.21) with ESMTPS id vB602oVe014332 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Tue, 5 Dec 2017 18:02:50 -0600 Received: from us-aus-exhub2.ni.corp.natinst.com (130.164.68.32) by us-aus-exch1.ni.corp.natinst.com (130.164.68.11) with Microsoft SMTP Server (TLS) id 15.0.1156.6; Tue, 5 Dec 2017 18:02:50 -0600 Received: from jcartwri.amer.corp.natinst.com (130.164.49.7) by us-aus-exhub2.ni.corp.natinst.com (130.164.68.32) with Microsoft SMTP Server id 15.0.1156.6 via Frontend Transport; Tue, 5 Dec 2017 18:02:50 -0600 Received: by jcartwri.amer.corp.natinst.com (Postfix, from userid 1000) id 804CB30154D; Tue, 5 Dec 2017 18:02:50 -0600 (CST) From: Julia Cartwright To: David Miller CC: , , , , , Subject: [PATCH v2 1/3] net: macb: kill useless use of list_empty() Date: Tue, 5 Dec 2017 18:02:48 -0600 Message-ID: <9efd418d0e93ff8e3396fdce2ebfdcd576c257e6.1512518311.git.julia@ni.com> X-Mailer: git-send-email 2.14.2 In-Reply-To: References: <20171205.180031.935589370339834625.davem@davemloft.net> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-12-05_08:, , signatures=0 X-Proofpoint-Spam-Details: rule=inbound_policy_notspam policy=inbound_policy score=30 priorityscore=1501 malwarescore=0 suspectscore=2 phishscore=0 bulkscore=0 spamscore=0 clxscore=1011 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=30 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1712050340 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org The list_for_each_entry() macro already handles the case where the list is empty (by not executing the loop body). It's not necessary to handle this case specially, so stop doing so. Cc: Rafal Ozieblo Acked-by: Nicolas Ferre Signed-off-by: Julia Cartwright --- drivers/net/ethernet/cadence/macb_main.c | 31 ++++++++++++------------------- 1 file changed, 12 insertions(+), 19 deletions(-) diff --git a/drivers/net/ethernet/cadence/macb_main.c b/drivers/net/ethernet/cadence/macb_main.c index ebfeab853bf4..b7644836aba1 100644 --- a/drivers/net/ethernet/cadence/macb_main.c +++ b/drivers/net/ethernet/cadence/macb_main.c @@ -2812,24 +2812,20 @@ static int gem_add_flow_filter(struct net_device *netdev, htons(fs->h_u.tcp_ip4_spec.psrc), htons(fs->h_u.tcp_ip4_spec.pdst)); /* find correct place to add in list */ - if (list_empty(&bp->rx_fs_list.list)) - list_add(&newfs->list, &bp->rx_fs_list.list); - else { - list_for_each_entry(item, &bp->rx_fs_list.list, list) { - if (item->fs.location > newfs->fs.location) { - list_add_tail(&newfs->list, &item->list); - added = true; - break; - } else if (item->fs.location == fs->location) { - netdev_err(netdev, "Rule not added: location %d not free!\n", - fs->location); - ret = -EBUSY; - goto err; - } + list_for_each_entry(item, &bp->rx_fs_list.list, list) { + if (item->fs.location > newfs->fs.location) { + list_add_tail(&newfs->list, &item->list); + added = true; + break; + } else if (item->fs.location == fs->location) { + netdev_err(netdev, "Rule not added: location %d not free!\n", + fs->location); + ret = -EBUSY; + goto err; } - if (!added) - list_add_tail(&newfs->list, &bp->rx_fs_list.list); } + if (!added) + list_add_tail(&newfs->list, &bp->rx_fs_list.list); gem_prog_cmp_regs(bp, fs); bp->rx_fs_list.count++; @@ -2851,9 +2847,6 @@ static int gem_del_flow_filter(struct net_device *netdev, struct ethtool_rx_fs_item *item; struct ethtool_rx_flow_spec *fs; - if (list_empty(&bp->rx_fs_list.list)) - return -EINVAL; - list_for_each_entry(item, &bp->rx_fs_list.list, list) { if (item->fs.location == cmd->fs.location) { /* disable screener regs for the flow entry */ From patchwork Wed Dec 6 00:02:49 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julia Cartwright X-Patchwork-Id: 844976 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3yrzNs6F9Wz9s7v for ; Wed, 6 Dec 2017 11:03:57 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753299AbdLFADp (ORCPT ); Tue, 5 Dec 2017 19:03:45 -0500 Received: from mx0a-00010702.pphosted.com ([148.163.156.75]:56428 "EHLO mx0b-00010702.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753132AbdLFAC6 (ORCPT ); Tue, 5 Dec 2017 19:02:58 -0500 Received: from pps.filterd (m0098781.ppops.net [127.0.0.1]) by mx0a-00010702.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id vB600eSB009322; Tue, 5 Dec 2017 18:02:52 -0600 Received: from ni.com (skprod2.natinst.com [130.164.80.23]) by mx0a-00010702.pphosted.com with ESMTP id 2emnjmaq1s-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 05 Dec 2017 18:02:51 -0600 Received: from us-aus-exch2.ni.corp.natinst.com (us-aus-exch2.ni.corp.natinst.com [130.164.68.12]) by us-aus-skprod2.natinst.com (8.16.0.21/8.16.0.21) with ESMTPS id vB602oSv018692 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Tue, 5 Dec 2017 18:02:50 -0600 Received: from us-aus-exch7.ni.corp.natinst.com (130.164.68.17) by us-aus-exch2.ni.corp.natinst.com (130.164.68.12) with Microsoft SMTP Server (TLS) id 15.0.1156.6; Tue, 5 Dec 2017 18:02:50 -0600 Received: from us-aus-exhub2.ni.corp.natinst.com (130.164.68.32) by us-aus-exch7.ni.corp.natinst.com (130.164.68.17) with Microsoft SMTP Server (TLS) id 15.0.1156.6; Tue, 5 Dec 2017 18:02:50 -0600 Received: from jcartwri.amer.corp.natinst.com (130.164.49.7) by us-aus-exhub2.ni.corp.natinst.com (130.164.68.32) with Microsoft SMTP Server id 15.0.1156.6 via Frontend Transport; Tue, 5 Dec 2017 18:02:50 -0600 Received: by jcartwri.amer.corp.natinst.com (Postfix, from userid 1000) id 83BE7302697; Tue, 5 Dec 2017 18:02:50 -0600 (CST) From: Julia Cartwright To: David Miller CC: , , , , , Subject: [PATCH v2 2/3] net: macb: reduce scope of rx_fs_lock-protected regions Date: Tue, 5 Dec 2017 18:02:49 -0600 Message-ID: <5a7697aa7d271405cb7b9476d592053c12364bd7.1512518311.git.julia@ni.com> X-Mailer: git-send-email 2.14.2 In-Reply-To: References: <20171205.180031.935589370339834625.davem@davemloft.net> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-12-05_08:, , signatures=0 X-Proofpoint-Spam-Details: rule=inbound_policy_notspam policy=inbound_policy score=30 priorityscore=1501 malwarescore=0 suspectscore=2 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=30 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1712050340 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Commit ae8223de3df5 ("net: macb: Added support for RX filtering") introduces a lock, rx_fs_lock which is intended to protect the list of rx_flow items and synchronize access to the hardware rx filtering registers. However, the region protected by this lock is overscoped, unnecessarily including things like slab allocation. Reduce this lock scope to only include operations which must be performed atomically: list traversal, addition, and removal, and hitting the macb filtering registers. This fixes the use of kmalloc w/ GFP_KERNEL in atomic context. Fixes: ae8223de3df5 ("net: macb: Added support for RX filtering") Cc: Rafal Ozieblo Cc: Julia Lawall Acked-by: Nicolas Ferre Signed-off-by: Julia Cartwright --- drivers/net/ethernet/cadence/macb_main.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/drivers/net/ethernet/cadence/macb_main.c b/drivers/net/ethernet/cadence/macb_main.c index b7644836aba1..758e8b3042b2 100644 --- a/drivers/net/ethernet/cadence/macb_main.c +++ b/drivers/net/ethernet/cadence/macb_main.c @@ -2796,6 +2796,7 @@ static int gem_add_flow_filter(struct net_device *netdev, struct macb *bp = netdev_priv(netdev); struct ethtool_rx_flow_spec *fs = &cmd->fs; struct ethtool_rx_fs_item *item, *newfs; + unsigned long flags; int ret = -EINVAL; bool added = false; @@ -2811,6 +2812,8 @@ static int gem_add_flow_filter(struct net_device *netdev, htonl(fs->h_u.tcp_ip4_spec.ip4dst), htons(fs->h_u.tcp_ip4_spec.psrc), htons(fs->h_u.tcp_ip4_spec.pdst)); + spin_lock_irqsave(&bp->rx_fs_lock, flags); + /* find correct place to add in list */ list_for_each_entry(item, &bp->rx_fs_list.list, list) { if (item->fs.location > newfs->fs.location) { @@ -2833,9 +2836,11 @@ static int gem_add_flow_filter(struct net_device *netdev, if (netdev->features & NETIF_F_NTUPLE) gem_enable_flow_filters(bp, 1); + spin_unlock_irqrestore(&bp->rx_fs_lock, flags); return 0; err: + spin_unlock_irqrestore(&bp->rx_fs_lock, flags); kfree(newfs); return ret; } @@ -2846,6 +2851,9 @@ static int gem_del_flow_filter(struct net_device *netdev, struct macb *bp = netdev_priv(netdev); struct ethtool_rx_fs_item *item; struct ethtool_rx_flow_spec *fs; + unsigned long flags; + + spin_lock_irqsave(&bp->rx_fs_lock, flags); list_for_each_entry(item, &bp->rx_fs_list.list, list) { if (item->fs.location == cmd->fs.location) { @@ -2862,12 +2870,14 @@ static int gem_del_flow_filter(struct net_device *netdev, gem_writel_n(bp, SCRT2, fs->location, 0); list_del(&item->list); - kfree(item); bp->rx_fs_list.count--; + spin_unlock_irqrestore(&bp->rx_fs_lock, flags); + kfree(item); return 0; } } + spin_unlock_irqrestore(&bp->rx_fs_lock, flags); return -EINVAL; } @@ -2936,11 +2946,8 @@ static int gem_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd, static int gem_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd) { struct macb *bp = netdev_priv(netdev); - unsigned long flags; int ret; - spin_lock_irqsave(&bp->rx_fs_lock, flags); - switch (cmd->cmd) { case ETHTOOL_SRXCLSRLINS: if ((cmd->fs.location >= bp->max_tuples) @@ -2959,7 +2966,6 @@ static int gem_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd) ret = -EOPNOTSUPP; } - spin_unlock_irqrestore(&bp->rx_fs_lock, flags); return ret; } From patchwork Wed Dec 6 00:02:50 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julia Cartwright X-Patchwork-Id: 844973 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3yrzNH4q9Jz9s7v for ; Wed, 6 Dec 2017 11:03:27 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753242AbdLFADB (ORCPT ); Tue, 5 Dec 2017 19:03:01 -0500 Received: from mx0a-00010702.pphosted.com ([148.163.156.75]:56424 "EHLO mx0b-00010702.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753055AbdLFAC5 (ORCPT ); Tue, 5 Dec 2017 19:02:57 -0500 Received: from pps.filterd (m0098781.ppops.net [127.0.0.1]) by mx0a-00010702.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id vB600eWF009317; Tue, 5 Dec 2017 18:02:52 -0600 Received: from ni.com (skprod2.natinst.com [130.164.80.23]) by mx0a-00010702.pphosted.com with ESMTP id 2emnjmaq1r-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 05 Dec 2017 18:02:51 -0600 Received: from us-aus-exch1.ni.corp.natinst.com (us-aus-exch1.ni.corp.natinst.com [130.164.68.11]) by us-aus-skprod2.natinst.com (8.16.0.21/8.16.0.21) with ESMTPS id vB602oAX018689 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Tue, 5 Dec 2017 18:02:50 -0600 Received: from us-aus-exch3.ni.corp.natinst.com (130.164.68.13) by us-aus-exch1.ni.corp.natinst.com (130.164.68.11) with Microsoft SMTP Server (TLS) id 15.0.1156.6; Tue, 5 Dec 2017 18:02:50 -0600 Received: from us-aus-exhub2.ni.corp.natinst.com (130.164.68.32) by us-aus-exch3.ni.corp.natinst.com (130.164.68.13) with Microsoft SMTP Server (TLS) id 15.0.1156.6; Tue, 5 Dec 2017 18:02:50 -0600 Received: from jcartwri.amer.corp.natinst.com (130.164.49.7) by us-aus-exhub2.ni.corp.natinst.com (130.164.68.32) with Microsoft SMTP Server id 15.0.1156.6 via Frontend Transport; Tue, 5 Dec 2017 18:02:50 -0600 Received: by jcartwri.amer.corp.natinst.com (Postfix, from userid 1000) id 87E9D3026A1; Tue, 5 Dec 2017 18:02:50 -0600 (CST) From: Julia Cartwright To: David Miller CC: , , , , , Subject: [PATCH v2 3/3] net: macb: change GFP_ATOMIC to GFP_KERNEL Date: Tue, 5 Dec 2017 18:02:50 -0600 Message-ID: X-Mailer: git-send-email 2.14.2 In-Reply-To: References: <20171205.180031.935589370339834625.davem@davemloft.net> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-12-05_08:, , signatures=0 X-Proofpoint-Spam-Details: rule=inbound_policy_notspam policy=inbound_policy score=30 priorityscore=1501 malwarescore=0 suspectscore=2 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=30 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1712050340 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Now that the rx_fs_lock is no longer held across allocation, it's safe to use GFP_KERNEL for allocating new entries. This reverts commit 81da3bf6e3f88 ("net: macb: change GFP_KERNEL to GFP_ATOMIC"). Cc: Julia Lawall Signed-off-by: Julia Cartwright Acked-by: Julia Lawall --- drivers/net/ethernet/cadence/macb_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/ethernet/cadence/macb_main.c b/drivers/net/ethernet/cadence/macb_main.c index 758e8b3042b2..234667eaaa92 100644 --- a/drivers/net/ethernet/cadence/macb_main.c +++ b/drivers/net/ethernet/cadence/macb_main.c @@ -2800,7 +2800,7 @@ static int gem_add_flow_filter(struct net_device *netdev, int ret = -EINVAL; bool added = false; - newfs = kmalloc(sizeof(*newfs), GFP_ATOMIC); + newfs = kmalloc(sizeof(*newfs), GFP_KERNEL); if (newfs == NULL) return -ENOMEM; memcpy(&newfs->fs, fs, sizeof(newfs->fs));