Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752265AbdLSPt6 (ORCPT ); Tue, 19 Dec 2017 10:49:58 -0500 Received: from mail-lf0-f43.google.com ([209.85.215.43]:44098 "EHLO mail-lf0-f43.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751297AbdLSPtw (ORCPT ); Tue, 19 Dec 2017 10:49:52 -0500 X-Google-Smtp-Source: ACJfBotiPtuh9DwwCxcfK3iQuyV/dAhDwxOl6YbKrAQcI6lMJv8TkQFf9Vb18jJuHVYIssS2NnbxeA== Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 9.3 \(3124\)) Subject: Re: [PATCH] net: arc_emac: fix arc_emac_rx() error paths From: Alexander Kochetkov In-Reply-To: <20171219.102254.1959679351283055093.davem@davemloft.net> Date: Tue, 19 Dec 2017 18:49:48 +0300 Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, f.fainelli@gmail.com, edumazet@google.com Message-Id: References: <1513358406-32503-1-git-send-email-al.kochet@gmail.com> <20171219.102254.1959679351283055093.davem@davemloft.net> To: David Miller X-Mailer: Apple Mail (2.3124) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from quoted-printable to 8bit by nfs id vBJFo6nt001982 Content-Length: 1987 Lines: 53 > 19 дек. 2017 г., в 18:22, David Miller написал(а): > > From: Alexander Kochetkov > Date: Fri, 15 Dec 2017 20:20:06 +0300 > >> 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 > > This patch adds quite a few bugs, here is one which shows this is not > functionally tested: May be I don’t understand correctly, but I don’t see bug here. Wrong dma mapping usage should immediately manifest itself (kernel instability, koops and so on). The patch was tested on rk3188 and work fine for me. Also I did simulations of netdev_alloc_skb_ip_align() and dma_map_single() faults and can confirm that new error handling work. Could someone else with ARC EMAC test the patch? I would be very grateful for the help. Florian or Eric, can you test it on your hardware? >> + >> + /* unmap previosly mapped skb */ >> + dma_unmap_single(&ndev->dev, dma_unmap_addr(rx_buff, addr), >> + dma_unmap_len(rx_buff, len), DMA_FROM_DEVICE); > > And then you unmap it. "addr" is the new DMA mapping, not the old one. The old mapping should be unmapped here. It refer to old skb what contains already received packet. Because buffer doesn’t belong to EMAC anymore. That old mapping point to old skb buffer. And netif_receive_skb() will be called for old skb after that. The new mapping «addr" will be unmapped then EMAC receive new packet. Later by the code (after netif_receive_skb()) there are lines for saving «addr» value: rx_buff->skb = skb; dma_unmap_addr_set(rx_buff, addr, addr); dma_unmap_len_set(rx_buff, len, EMAC_BUFFER_SIZE); Regards, Alexander.