From patchwork Tue Sep 3 22:41:27 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergei Shtylyov X-Patchwork-Id: 2853436 Return-Path: X-Original-To: patchwork-linux-sh@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id B495E9F3DC for ; Tue, 3 Sep 2013 22:41:31 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id D23A02042B for ; Tue, 3 Sep 2013 22:41:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E21A22041C for ; Tue, 3 Sep 2013 22:41:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1761180Ab3ICWl3 (ORCPT ); Tue, 3 Sep 2013 18:41:29 -0400 Received: from mail-lb0-f178.google.com ([209.85.217.178]:60819 "EHLO mail-lb0-f178.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1760511Ab3ICWl2 (ORCPT ); Tue, 3 Sep 2013 18:41:28 -0400 Received: by mail-lb0-f178.google.com with SMTP id z5so5461196lbh.23 for ; Tue, 03 Sep 2013 15:41:27 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:to:subject:cc:from:organization:date :mime-version:content-type:content-transfer-encoding:message-id; bh=S8hjrC6oQiTazxjKoESfCL4x/th7XqzJsR7frvlZKzo=; b=IchNVU+9AU+0MIQU9xgl6a3lXm3/C7W/NL7MHqqFK2yAoZULsWrp2Sta24ccrev3un HS+A/W+4O3T5v3xdChBjTLTzvY7r+4LsWydRqF65dDCwPVZvIMBgCZuwFHEGj3P3oku7 BE5oz39llqe87wDnlUuudEaKH7jY6uQGOhsYsr7aqB8UNHTCMsKGdeBzj2RNtwFjokiU TbHtpsCVitUTrrSqpFJB2j6dZOZo9YZGG7DwDVTzCWbmdHEEJuAj2g1aT3taWU1vVbo3 xMvQ4dC3wI3AjyxOFWzPb4zm0pk2SCru+08NsGxz2ZtDRJWQ8Oq14dZJ3sEKct2yZ8TZ dbUg== X-Gm-Message-State: ALoCoQnrheYMUbNT+aHeS7rJM8RzwYz319jHyaIbiq9KDVIwNxYw0qehZ8+NkgQFTjN+SkPvG4gW X-Received: by 10.152.116.7 with SMTP id js7mr28350757lab.11.1378248087202; Tue, 03 Sep 2013 15:41:27 -0700 (PDT) Received: from wasted.dev.rtsoft.ru (ppp91-76-155-251.pppoe.mtu-net.ru. [91.76.155.251]) by mx.google.com with ESMTPSA id ac2sm9199495lbc.10.1969.12.31.16.00.00 (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 03 Sep 2013 15:41:26 -0700 (PDT) To: netdev@vger.kernel.org Subject: [PATCH] sh_eth: fix napi_{en|dis}able() calls racing against interrupts Cc: nobuhiro.iwamatsu.yj@renesas.com, linux-sh@vger.kernel.org From: Sergei Shtylyov Organization: Cogent Embedded Date: Wed, 4 Sep 2013 02:41:27 +0400 MIME-Version: 1.0 Message-Id: <201309040241.27834.sergei.shtylyov@cogentembedded.com> Sender: linux-sh-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sh@vger.kernel.org X-Spam-Status: No, score=-9.3 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP While implementing NAPI for the driver, I overlooked the race conditions where interrupt handler might have called napi_schedule_prep() before napi_enable() was called or after napi_disable() was called. If RX interrupt happens, this would cause the endless interrupts and messages like: sh-eth eth0: ignoring interrupt, status 0x00040000, mask 0x01ff009f. The interrupt wouldn't even be masked by the kernel eventually since the handler would return IRQ_HANDLED all the time. As a fix, move napi_enable() call before request_irq() call and napi_disable() call after free_irq() call. Signed-off-by: Sergei Shtylyov --- The patch is against Dave's 'net.git' repo. It should be applied to 3.11.y too. drivers/net/ethernet/renesas/sh_eth.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe linux-sh" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Index: net/drivers/net/ethernet/renesas/sh_eth.c =================================================================== --- net.orig/drivers/net/ethernet/renesas/sh_eth.c +++ net/drivers/net/ethernet/renesas/sh_eth.c @@ -1857,11 +1857,13 @@ static int sh_eth_open(struct net_device pm_runtime_get_sync(&mdp->pdev->dev); + napi_enable(&mdp->napi); + ret = request_irq(ndev->irq, sh_eth_interrupt, mdp->cd->irq_flags, ndev->name, ndev); if (ret) { dev_err(&ndev->dev, "Can not assign IRQ number\n"); - return ret; + goto out_napi_off; } /* Descriptor set */ @@ -1879,12 +1881,12 @@ static int sh_eth_open(struct net_device if (ret) goto out_free_irq; - napi_enable(&mdp->napi); - return ret; out_free_irq: free_irq(ndev->irq, ndev); +out_napi_off: + napi_disable(&mdp->napi); pm_runtime_put_sync(&mdp->pdev->dev); return ret; } @@ -1976,8 +1978,6 @@ static int sh_eth_close(struct net_devic { struct sh_eth_private *mdp = netdev_priv(ndev); - napi_disable(&mdp->napi); - netif_stop_queue(ndev); /* Disable interrupts by clearing the interrupt mask. */ @@ -1995,6 +1995,8 @@ static int sh_eth_close(struct net_devic free_irq(ndev->irq, ndev); + napi_disable(&mdp->napi); + /* Free all the skbuffs in the Rx queue. */ sh_eth_ring_free(ndev);