Received: by 10.223.176.5 with SMTP id f5csp810120wra; Sat, 3 Feb 2018 10:48:13 -0800 (PST) X-Google-Smtp-Source: AH8x224fuKGo3P8sAY4dox15aV1oi44nNLW7YDs4E1kQHkLZi1U4vBYQyA0UByxABA0a77Y7h7iQ X-Received: by 2002:a17:902:43:: with SMTP id 61-v6mr38623312pla.73.1517683693325; Sat, 03 Feb 2018 10:48:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517683693; cv=none; d=google.com; s=arc-20160816; b=khWeJu+0Lyg5odtCbNPBCdk96scmTkDHXAa8KcbXK6+28QZBtC4YAoodvSNyZIEJP7 wqN64xLsvpdql+X2q2RgPV41+bF1iWMZjk8bohGjECDTbSAP3fgIvgmSUNee/5DT8HaP Y2Y2jMRJSOrjBW7tPBRlkrtoyDP8Y4Eneh2mJHNvAVdgkr1bSZYVxUzl+QJlklwTPSBB R+kiwexy1fU8L3oxQliDLx465jEM4rwPx6IOWjVNFI+nlC1gq/fHKY01+ZVD+9EydTIg G8X1HqnZyyPnsTiWW/ZU4sPYrqyVK98CbDr4aOX0/swveZtCvxV08WAkAqKMbrE20TuW k9Rw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :spamdiagnosticmetadata:spamdiagnosticoutput:content-language :accept-language:in-reply-to:references:message-id:date:thread-index :thread-topic:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=kRhL6pj3hAF/XWqKNQyI9xUY7NYD7gcswjnqYg2v+yw=; b=FU+NvRswAJf8MsCsH29cPFXatesqUlPHwouYptq6gyeBjuwPmNTNL9C/xsGqh1Rb4L e2Zcud77lFH3ChBfel1r2fzJwIvx7ulmhOf18jYfZzNLQU2gSUnjZVWVMawcKfi3L6LI Bn76rfIy3S7AGBOC1I9Xzs97pmO1BUJZGamBz2J4d2G/aBZYumpl+cMg5mPQdVjp/Ywd e8fup62uhnyUjuv1ylT4jsy/nmNvIzPtPLwOuQCA51oyvAs1Bbol1tyhwk7knvCCjNE+ RXP76IamNbm0tQzjQi/BoDVq+InX342xUnr9MXYjurub9F4stEKe+hl3rH9IU4UPGc0+ 6uxg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=EaX+7cJ6; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k189si1586345pgc.505.2018.02.03.10.47.58; Sat, 03 Feb 2018 10:48:13 -0800 (PST) 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=@microsoft.com header.s=selector1 header.b=EaX+7cJ6; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755392AbeBCSqr (ORCPT + 99 others); Sat, 3 Feb 2018 13:46:47 -0500 Received: from mail-cys01nam02on0123.outbound.protection.outlook.com ([104.47.37.123]:2624 "EHLO NAM02-CY1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753097AbeBCSC0 (ORCPT ); Sat, 3 Feb 2018 13:02:26 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=kRhL6pj3hAF/XWqKNQyI9xUY7NYD7gcswjnqYg2v+yw=; b=EaX+7cJ6rTo44c4QytOhGFSzh0uFCUHF6qEyzpUSMVKT1/xzWYiioko7cwgyO/FqSYYem+iH1Va8j/dNRwXSzkQi2tyCDXr6ZwfeBi+15YfVInVXa0Dk5FlTtv04LQ/vp62F0dek7ftb+IQjudSuhwZWomC0MqtvlZ9nKy16rPI= Received: from BL0PR2101MB1027.namprd21.prod.outlook.com (52.132.20.161) by BL0PR2101MB1090.namprd21.prod.outlook.com (52.132.24.24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.506.1; Sat, 3 Feb 2018 18:01:17 +0000 Received: from BL0PR2101MB1027.namprd21.prod.outlook.com ([fe80::a8da:b5d9:d710:9bf9]) by BL0PR2101MB1027.namprd21.prod.outlook.com ([fe80::a8da:b5d9:d710:9bf9%3]) with mapi id 15.20.0485.006; Sat, 3 Feb 2018 18:01:17 +0000 From: Sasha Levin To: "linux-kernel@vger.kernel.org" , "stable@vger.kernel.org" CC: Alexander Kochetkov , "David S . Miller" , Sasha Levin Subject: [PATCH AUTOSEL for 4.14 034/110] net: arc_emac: fix arc_emac_rx() error paths Thread-Topic: [PATCH AUTOSEL for 4.14 034/110] net: arc_emac: fix arc_emac_rx() error paths Thread-Index: AQHTnRjpJzytNTIQpUS9xMb0DAx68g== Date: Sat, 3 Feb 2018 18:00:45 +0000 Message-ID: <20180203180015.29073-34-alexander.levin@microsoft.com> References: <20180203180015.29073-1-alexander.levin@microsoft.com> In-Reply-To: <20180203180015.29073-1-alexander.levin@microsoft.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [52.168.54.252] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;BL0PR2101MB1090;7:xbiyI36e/TUp+MVnbGilYMQORg/V5UoF8JPMUHAChVO/l+5v6HLCzF/Cq2Q+6ZuEqtmzAtXUUzWAYTkVqYtuMv4FlYSgrIgm8U5mEBVl6gupCb5705xYe8ULFe+hWrI9JwMPw7Se/3dyyD9OGDRD5YEMq+KuxDNebUbDo8fQY0QiDn+BhEniN8ND94OLnHfKKkOgqBRhvCjhuga2/GDXtyvUh5wsiS5T0u1sfNkk8XylgJMxt1pIeHUHkeElq4Pd x-ms-office365-filtering-ht: Tenant x-ms-office365-filtering-correlation-id: f870c82e-90a6-453e-9120-08d56b301fbc x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(48565401081)(4534165)(4627221)(201703031133081)(201702281549075)(5600026)(4604075)(3008032)(2017052603307)(7193020);SRVR:BL0PR2101MB1090; x-ms-traffictypediagnostic: BL0PR2101MB1090: x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(28532068793085)(60795455431006)(89211679590171)(85827821059158); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(61425038)(6040501)(2401047)(5005006)(8121501046)(3002001)(10201501046)(3231101)(2400082)(944501161)(93006095)(93001095)(6055026)(61426038)(61427038)(6041288)(20161123562045)(20161123560045)(20161123558120)(20161123564045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(6072148)(201708071742011);SRVR:BL0PR2101MB1090;BCL:0;PCL:0;RULEID:;SRVR:BL0PR2101MB1090; x-forefront-prvs: 05724A8921 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(376002)(366004)(396003)(39380400002)(39860400002)(346002)(199004)(189003)(2900100001)(5660300001)(316002)(25786009)(4326008)(14454004)(2950100002)(478600001)(575784001)(39060400002)(107886003)(72206003)(6666003)(22452003)(10290500003)(186003)(3660700001)(86612001)(76176011)(86362001)(53936002)(3280700002)(106356001)(6436002)(6486002)(59450400001)(81166006)(81156014)(2501003)(6506007)(97736004)(26005)(7736002)(6512007)(6346003)(102836004)(105586002)(68736007)(8936002)(5250100002)(305945005)(36756003)(1076002)(6116002)(3846002)(8676002)(110136005)(66066001)(54906003)(2906002)(10090500001)(99286004)(22906009)(217873001);DIR:OUT;SFP:1102;SCL:1;SRVR:BL0PR2101MB1090;H:BL0PR2101MB1027.namprd21.prod.outlook.com;FPR:;SPF:None;PTR:InfoNoRecords;A:1;MX:1;LANG:en; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) authentication-results: spf=none (sender IP is ) smtp.mailfrom=Alexander.Levin@microsoft.com; x-microsoft-antispam-message-info: kCoh/AZC2+8HZkvP9By3NEiL5MQ8x5y7L24DQBUOty4x3PVLg0vd1uyA32yEkJ0ZdHy4RR5xdK3wEOeeOd6lgQ== spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: f870c82e-90a6-453e-9120-08d56b301fbc X-MS-Exchange-CrossTenant-originalarrivaltime: 03 Feb 2018 18:00:45.2065 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL0PR2101MB1090 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Alexander Kochetkov [ Upstream commit e688822d035b494071ecbadcccbd6f3325fb0f59 ] arc_emac_rx() has some issues found by code review. In case netdev_alloc_skb_ip_align() or dma_map_single() failure rx fifo entry will not be returned to EMAC. In case dma_map_single() failure previously allocated skb became lost to driver. At the same time address of newly allocated skb will not be provided to EMAC. Signed-off-by: Alexander Kochetkov Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- drivers/net/ethernet/arc/emac_main.c | 53 +++++++++++++++++++++-----------= ---- 1 file changed, 31 insertions(+), 22 deletions(-) diff --git a/drivers/net/ethernet/arc/emac_main.c b/drivers/net/ethernet/ar= c/emac_main.c index 3241af1ce718..5b422be56165 100644 --- a/drivers/net/ethernet/arc/emac_main.c +++ b/drivers/net/ethernet/arc/emac_main.c @@ -210,39 +210,48 @@ static int arc_emac_rx(struct net_device *ndev, int b= udget) continue; } =20 - pktlen =3D info & LEN_MASK; - stats->rx_packets++; - stats->rx_bytes +=3D pktlen; - skb =3D rx_buff->skb; - skb_put(skb, pktlen); - skb->dev =3D ndev; - skb->protocol =3D eth_type_trans(skb, ndev); - - dma_unmap_single(&ndev->dev, dma_unmap_addr(rx_buff, addr), - dma_unmap_len(rx_buff, len), DMA_FROM_DEVICE); - - /* Prepare the BD for next cycle */ - rx_buff->skb =3D netdev_alloc_skb_ip_align(ndev, - EMAC_BUFFER_SIZE); - if (unlikely(!rx_buff->skb)) { + /* Prepare the BD for next cycle. netif_receive_skb() + * only if new skb was allocated and mapped to avoid holes + * in the RX fifo. + */ + skb =3D netdev_alloc_skb_ip_align(ndev, EMAC_BUFFER_SIZE); + if (unlikely(!skb)) { + if (net_ratelimit()) + netdev_err(ndev, "cannot allocate skb\n"); + /* Return ownership to EMAC */ + rxbd->info =3D cpu_to_le32(FOR_EMAC | EMAC_BUFFER_SIZE); stats->rx_errors++; - /* Because receive_skb is below, increment rx_dropped */ stats->rx_dropped++; continue; } =20 - /* receive_skb only if new skb was allocated to avoid holes */ - netif_receive_skb(skb); - - addr =3D dma_map_single(&ndev->dev, (void *)rx_buff->skb->data, + addr =3D dma_map_single(&ndev->dev, (void *)skb->data, EMAC_BUFFER_SIZE, DMA_FROM_DEVICE); if (dma_mapping_error(&ndev->dev, addr)) { if (net_ratelimit()) - netdev_err(ndev, "cannot dma map\n"); - dev_kfree_skb(rx_buff->skb); + netdev_err(ndev, "cannot map dma buffer\n"); + dev_kfree_skb(skb); + /* Return ownership to EMAC */ + rxbd->info =3D cpu_to_le32(FOR_EMAC | EMAC_BUFFER_SIZE); stats->rx_errors++; + stats->rx_dropped++; continue; } + + /* unmap previosly mapped skb */ + dma_unmap_single(&ndev->dev, dma_unmap_addr(rx_buff, addr), + dma_unmap_len(rx_buff, len), DMA_FROM_DEVICE); + + pktlen =3D info & LEN_MASK; + stats->rx_packets++; + stats->rx_bytes +=3D pktlen; + skb_put(rx_buff->skb, pktlen); + rx_buff->skb->dev =3D ndev; + rx_buff->skb->protocol =3D eth_type_trans(rx_buff->skb, ndev); + + netif_receive_skb(rx_buff->skb); + + rx_buff->skb =3D skb; dma_unmap_addr_set(rx_buff, addr, addr); dma_unmap_len_set(rx_buff, len, EMAC_BUFFER_SIZE); =20 --=20 2.11.0