Received: by 10.192.165.148 with SMTP id m20csp3136315imm; Mon, 7 May 2018 07:16:07 -0700 (PDT) X-Google-Smtp-Source: AB8JxZoQQ7pax/tqqmQHYIY2zDIkQHE8+51GC3FRQVgGuFr3NNrCPvHSrt1OLAFOJH4KfldSJzIW X-Received: by 2002:a17:902:294a:: with SMTP id g68-v6mr38606112plb.110.1525702567039; Mon, 07 May 2018 07:16:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525702567; cv=none; d=google.com; s=arc-20160816; b=zCvZpwz5aurJkcj+Gkv76Ev4UY9X/ldxT74SVNooAMpzvtmVM6Vu650exF9g/1klZL cE8yDs8VgM9vYquuhsb8N2fAY7UFic36lgeknkypl62Q7fy5TMVkbRCEOuMG7CtLM9Yy OU71gpG6dnQp430T2Yxvi3O6RxexZl2ZscZ874jmX0HIBKKtlMcdvNi99cW9ihFvzZeL ly/wrQmVaFGOxSKASh0Tsk1/BEswMfw1PtOQBmq2kcfD4udgC4s3aT+xqU8sSYLXsHAr 8SV1n1TLbG+pLYlbepchHchwUyJSuNasjQ1vCwBupqMAfEPmHooEisdA8X2ahl+nx7sC ZLMA== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature :arc-authentication-results; bh=WAes0y02uVzuoniOLusUkLGwkjDSBhcGbI8P0OSRQ5s=; b=C/IyxLk5hwBfqNpuWJnY+0ABAuh5U1Qn7QQtZi1sy64/jrPOk6yov5NKAUAfeIyLAU aY5ZlCvPGRS5Lx/zSDE9KeraLvakm4v63M3QZBeWBpe8GVZGlUMitjLcFfSNmcCmlSlE XDMu9Dxujgtr1edfmd6oscOycLUNSE5mcGpdaWRUdzuDy8U3O7NzRPvBnrSZbKv8u/z2 ShXu/AUNIMfxPDINfTitotcHIUE2XDEyLbz5EbgEFv50GT3G3vUm8V+twoe2Rou49H3l kioPzvB1cO7HQnYKH6Netwe7JK3ORRQSH5WlvcIx/qFolVguX57etCA9TzJ+CzdGU/nF /dMw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Sv5HRYzt; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v5-v6si17760631pgs.87.2018.05.07.07.15.52; Mon, 07 May 2018 07:16:06 -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=@gmail.com header.s=20161025 header.b=Sv5HRYzt; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752659AbeEGOPR (ORCPT + 99 others); Mon, 7 May 2018 10:15:17 -0400 Received: from mail-it0-f68.google.com ([209.85.214.68]:51787 "EHLO mail-it0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752622AbeEGOPJ (ORCPT ); Mon, 7 May 2018 10:15:09 -0400 Received: by mail-it0-f68.google.com with SMTP id n202-v6so11642479ita.1; Mon, 07 May 2018 07:15:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=WAes0y02uVzuoniOLusUkLGwkjDSBhcGbI8P0OSRQ5s=; b=Sv5HRYztqIU+sQAruVxjFacxIpCuHXYTa7abUTnUo9971rrhtgjBK21lsPHCnLMiDn 3Lpq3hSBU07OYInXLDw4kMFVoKpIjCbcYU3HR0eX15/xmDL5OrR809i7WGvPwKi+es7H QtIl94IPsXAqf+Irz5SXBAEO38WwvFQQQrrQ/JXiPR0oFkaAdudsIkFIPm3saGOqN7DW Lh3i4ujA8g2mMbPsQBjcLUuziMNAJ7MT2nreB7Byqki6owboUNSwdRpm2oK2NnUZFINk h7SZ7UT3zEVsObHjLoBBzRknSpXUtcOwlnHweRGJZ526jHk2yiXrS+ebujmxrgFQqgDF h9mg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=WAes0y02uVzuoniOLusUkLGwkjDSBhcGbI8P0OSRQ5s=; b=gNpIY5J8JPSKiTIfslolJyscOG0nbdUBjN4KjCqUQ8nh3Vcvz+JxGmJ4maMD9ueVtp brJ+BV9S5NHs0EKg/2KFOsI2/gtpQyxPzHtYH1fb0jULChgWc6A677BIReDWS1cr/PPK GQ7XWwcmF1tY5WJ2qsmmWdj74olpaCddBPSRk4cSMMpMYpW6zK76G1CohYKGH83xd5+S ORRBUgWCu16jJxDDmJr5Q897gscwxYDDaKkhKlj5amh7lAtIGk35+lIQNporAWIvYHgu VG8YTw/tsZ+wKjScImBLogflb8jXP6W9p6KRe0CdDGdYa9EUrQtke49EeDaF2idcROqA pTsQ== X-Gm-Message-State: ALQs6tCc7P35MC6vvu4G33GeUXxcwbyJD58zhZcQM4KLaUG5D+fpdktk XvXykfK085SSTi+sCHSHIC83ENKa X-Received: by 2002:a17:902:144:: with SMTP id 62-v6mr38371701plb.202.1525702509000; Mon, 07 May 2018 07:15:09 -0700 (PDT) Received: from [192.168.86.235] (c-67-180-167-114.hsd1.ca.comcast.net. [67.180.167.114]) by smtp.gmail.com with ESMTPSA id q22sm8137257pfk.4.2018.05.07.07.15.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 07 May 2018 07:15:08 -0700 (PDT) Subject: Re: [PATCH] net: 8390: Fix possible data races in __ei_get_stats To: Jia-Ju Bai , davem@davemloft.net, fthain@telegraphics.com.au, joe@perches.com Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org References: <20180507140809.28847-1-baijiaju1990@gmail.com> From: Eric Dumazet Message-ID: Date: Mon, 7 May 2018 07:15:07 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 In-Reply-To: <20180507140809.28847-1-baijiaju1990@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 05/07/2018 07:08 AM, Jia-Ju Bai wrote: > The write operations to "dev->stats" are protected by > the spinlock on line 862-864, but the read operations to > this data on line 858 and 867 are not protected by the spinlock. > Thus, there may exist data races for "dev->stats". > > To fix the data races, the read operations to "dev->stats" are > protected by the spinlock, and a local variable is used for return. > > Signed-off-by: Jia-Ju Bai > --- > drivers/net/ethernet/8390/lib8390.c | 14 ++++++++++---- > 1 file changed, 10 insertions(+), 4 deletions(-) > > diff --git a/drivers/net/ethernet/8390/lib8390.c b/drivers/net/ethernet/8390/lib8390.c > index c9c55c9eab9f..198952247d30 100644 > --- a/drivers/net/ethernet/8390/lib8390.c > +++ b/drivers/net/ethernet/8390/lib8390.c > @@ -852,19 +852,25 @@ static struct net_device_stats *__ei_get_stats(struct net_device *dev) > unsigned long ioaddr = dev->base_addr; > struct ei_device *ei_local = netdev_priv(dev); > unsigned long flags; > + struct net_device_stats *stats; > + > + spin_lock_irqsave(&ei_local->page_lock, flags); > > /* If the card is stopped, just return the present stats. */ > - if (!netif_running(dev)) > - return &dev->stats; > + if (!netif_running(dev)) { > + stats = &dev->stats; > + spin_unlock_irqrestore(&ei_local->page_lock, flags); > + return stats; > + } > > - spin_lock_irqsave(&ei_local->page_lock, flags); > /* Read the counter registers, assuming we are in page 0. */ > dev->stats.rx_frame_errors += ei_inb_p(ioaddr + EN0_COUNTER0); > dev->stats.rx_crc_errors += ei_inb_p(ioaddr + EN0_COUNTER1); > dev->stats.rx_missed_errors += ei_inb_p(ioaddr + EN0_COUNTER2); > + stats = &dev->stats; > spin_unlock_irqrestore(&ei_local->page_lock, flags); > > - return &dev->stats; > + return stats; > } > > /* > dev->stats is not a pointer, it is an array embedded in the struct net_device So this patch is not needed, since dev->stats can not change.