Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp4265227pxu; Tue, 20 Oct 2020 12:18:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx23EPcfUHazFE5KqM8TGtDpgk0/jSWX9NbtSjExZiNJvQCVTWm1RRxSBXwfQh8uluDtK0V X-Received: by 2002:a17:906:2b83:: with SMTP id m3mr4653977ejg.456.1603221499319; Tue, 20 Oct 2020 12:18:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603221499; cv=none; d=google.com; s=arc-20160816; b=Vrmt/eC7hmql2iElrXVevVfm7PDDSeXrdIkNDtYxMsYBp3NRQxcSwVZki6TTDJ05V+ NW/6Q3J4Gz72/b8w0SuC8UsU5w+6373PEpytQZ0uHy69bZ/s07I41SyKpafy/Kc5DIfq R8BpaZtj/B5LWra8Rb2itB0twl13SpoIBHOvSokxSz08ECtRYwPCtvjpIY7OgiWel74a MLu2487A7FW8bqUJxK5KkrbIxDSoWB+9uj1InPB7oVc4nf84alh06YPUREReI3h7E4Cq 7NY4+DN/vk3QYnl0cgtMf8WYgn30kEv4h+Xbye0cggXuPGHg6k27L6SmHL7yCa+ZgHCN CgIQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=lRPCIqgVp7JxtQIwMiyZjjVI3vzOaxsFkudHQAakCTE=; b=BziKnqPbXym69CKBQnsa2An7cB6OKwbNFFbL09JuQciJtkRohX3gk6TWW7+06rberI 1TiD4Ve9qKln37X/EdizkgaTsbjttRZiSudzCVLJ56VH85sIrz81HAXaBzjkdRz9TgOd EvJkGMMDZJakCdSEmCN5DQXD7uu4kgR1dcZkkQYsYrEXGDqSDbaDIjXtWHeuOkYJ9O/5 RU+Qh2Jn31icuYrUv+zHy9MaEF6X1ZL8KXJUORIRYPkk9yyu0nnrm0RuMenNzEiTdDCi wOWQ0ojo7ouhH54qzbQ2KDkW6Mu4tvSntbZL3sVyJpHS/yI027vtZuTE+vHfQW2KOS0T lngg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@jms.id.au header.s=google header.b=CfVX7lB8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t3si1783397edw.568.2020.10.20.12.17.55; Tue, 20 Oct 2020 12:18:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@jms.id.au header.s=google header.b=CfVX7lB8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391348AbgJTEOE (ORCPT + 99 others); Tue, 20 Oct 2020 00:14:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57620 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726090AbgJTEOD (ORCPT ); Tue, 20 Oct 2020 00:14:03 -0400 Received: from mail-qt1-x842.google.com (mail-qt1-x842.google.com [IPv6:2607:f8b0:4864:20::842]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 95F5BC0613CE; Mon, 19 Oct 2020 21:14:03 -0700 (PDT) Received: by mail-qt1-x842.google.com with SMTP id m65so215042qte.11; Mon, 19 Oct 2020 21:14:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jms.id.au; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=lRPCIqgVp7JxtQIwMiyZjjVI3vzOaxsFkudHQAakCTE=; b=CfVX7lB8vevBGCqExwTh3APKc1v2ezK78tU6+t1yX1lK9mrdPWEcTaJoUOE7QoFs8p GJ7Ri9qfdszlYlCd3pUwR3z8S97ruE2/106lhkHvPIw+vCqbKWayS+atwy8X/gkS2SQ4 /mOsaA24Kj7yBhJXUdi69luiVxNI7XhEu6UME= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=lRPCIqgVp7JxtQIwMiyZjjVI3vzOaxsFkudHQAakCTE=; b=QB0HSyMCCknty/UzatZpfUH3NRAUu+rDEl9nFTyN2GUbz5yiVb7O+PvNqTbehk7zCX D7ONL3ZXjGbX6zBsF987l9LMbi9jK9oBgR0i3j/Oa+BJMK5sMCIDXd65oRJuorSOv21S gGpPQzfzfB6tiKt9NKUqgU2J0inaYJ3R7pb7a58buv/JnsMj6YC7Int+yHS0KOo8j9LD myS++XbrtWFXfZ36Ju9axUduOKgzHBofrvkDOOwkHMzmGB5toaMU4Iw2qUYTF/fLMbXP lyEy9EgX5ODkaLaaTV8IZ8mePQ8XDNCa9t2ns2ItLAzkb6uz4eAlopp3fZUaZZ6mmKbw O2Ng== X-Gm-Message-State: AOAM530lI7Y9oQsmlt2WrNrQb8caH3lKCEJ7/mY4SausYBDFZAJJRMmB wVlTERxVljoY4uswjB3oym6gd84mACd4kIdan8mjo8q4TBoYQw== X-Received: by 2002:aed:3325:: with SMTP id u34mr826567qtd.263.1603167242677; Mon, 19 Oct 2020 21:14:02 -0700 (PDT) MIME-Version: 1.0 References: <20201019085717.32413-1-dylan_hung@aspeedtech.com> <20201019085717.32413-2-dylan_hung@aspeedtech.com> In-Reply-To: From: Joel Stanley Date: Tue, 20 Oct 2020 04:13:49 +0000 Message-ID: Subject: Re: [PATCH 1/4] ftgmac100: Fix race issue on TX descriptor[0] To: Benjamin Herrenschmidt Cc: Dylan Hung , "David S . Miller" , Jakub Kicinski , netdev@vger.kernel.org, Linux Kernel Mailing List , Po-Yu Chuang , linux-aspeed , OpenBMC Maillist , BMC-SW Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 19 Oct 2020 at 23:20, Benjamin Herrenschmidt wrote: > > On Mon, 2020-10-19 at 16:57 +0800, Dylan Hung wrote: > > These rules must be followed when accessing the TX descriptor: > > > > 1. A TX descriptor is "cleanable" only when its value is non-zero > > and the owner bit is set to "software" > > Can you elaborate ? What is the point of that change ? The owner bit > should be sufficient, why do we need to check other fields ? I would like Dylan to clarify too. The datasheet has a footnote below the descriptor layout: - TXDES#0: Bits 27 ~ 14 are valid only when FTS = 1 - TXDES#1: Bits 31 ~ 0 are valid only when FTS = 1 So the ownership bit (31) is not valid unless FTS is set. However, this isn't what his patch does. It adds checks for EDOTR. > > > 2. A TX descriptor is "writable" only when its value is zero > > regardless the edotr mask. > > Again, why is that ? Can you elaborate ? What race are you trying to > address here ? > > Cheers, > Ben. > > > Fixes: 52c0cae87465 ("ftgmac100: Remove tx descriptor accessors") > > Signed-off-by: Dylan Hung > > Signed-off-by: Joel Stanley > > --- > > drivers/net/ethernet/faraday/ftgmac100.c | 10 ++++++++++ > > 1 file changed, 10 insertions(+) > > > > diff --git a/drivers/net/ethernet/faraday/ftgmac100.c > > b/drivers/net/ethernet/faraday/ftgmac100.c > > index 00024dd41147..7cacbe4aecb7 100644 > > --- a/drivers/net/ethernet/faraday/ftgmac100.c > > +++ b/drivers/net/ethernet/faraday/ftgmac100.c > > @@ -647,6 +647,9 @@ static bool ftgmac100_tx_complete_packet(struct > > ftgmac100 *priv) > > if (ctl_stat & FTGMAC100_TXDES0_TXDMA_OWN) > > return false; > > > > + if ((ctl_stat & ~(priv->txdes0_edotr_mask)) == 0) > > + return false; > > + > > skb = priv->tx_skbs[pointer]; > > netdev->stats.tx_packets++; > > netdev->stats.tx_bytes += skb->len; > > @@ -756,6 +759,9 @@ static netdev_tx_t > > ftgmac100_hard_start_xmit(struct sk_buff *skb, > > pointer = priv->tx_pointer; > > txdes = first = &priv->txdes[pointer]; > > > > + if (le32_to_cpu(txdes->txdes0) & ~priv->txdes0_edotr_mask) > > + goto drop; > > + > > /* Setup it up with the packet head. Don't write the head to > > the > > * ring just yet > > */ > > @@ -787,6 +793,10 @@ static netdev_tx_t > > ftgmac100_hard_start_xmit(struct sk_buff *skb, > > /* Setup descriptor */ > > priv->tx_skbs[pointer] = skb; > > txdes = &priv->txdes[pointer]; > > + > > + if (le32_to_cpu(txdes->txdes0) & ~priv- > > >txdes0_edotr_mask) > > + goto dma_err; > > + > > ctl_stat = ftgmac100_base_tx_ctlstat(priv, pointer); > > ctl_stat |= FTGMAC100_TXDES0_TXDMA_OWN; > > ctl_stat |= FTGMAC100_TXDES0_TXBUF_SIZE(len); >