Received: by 2002:a05:6a10:a841:0:0:0:0 with SMTP id d1csp1332041pxy; Fri, 23 Apr 2021 05:54:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzVZVQnrTdZUYFcwoGbHGJ5r6CA79ztKPkd/Yrnet1B4L5+wJ4DBgJG57i07mpxy4HK4qlt X-Received: by 2002:a62:be16:0:b029:25a:e1b4:5deb with SMTP id l22-20020a62be160000b029025ae1b45debmr3652788pff.66.1619182457311; Fri, 23 Apr 2021 05:54:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619182457; cv=none; d=google.com; s=arc-20160816; b=JK6G98Hmg/arzLxGj2RT9B5V7+g/WB4aVMxfRrW4XUVywvaisrodkiFhZhyRrbM+th o2/+MZkJmvrlMr25KmKHpLz0dZDbG82vQEfkYs84j40gHEEJc0E+fNQX2gITHMafo608 ibJwL6cwnwGBJ6MpG62x1nc+JLNXf+mQ497B/C1A6CTY223JjanJfxPL2CffVhnfiuY1 8+MsjDrWyVJ44JPm6lrfcXvRkpmzlo+W+6aT6O2Mz+cHo7MB1Gtx4uHhJuEvlegzb/RL CGPDOUA1rYOdNZfzILB3k5WuavRMqE/ff0/pvFequPSQMt1W/dGtJ9/fq8r27lNVoaA2 Ce8A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=66rFgD+hPrx9RGANAwK0PDDvv4JcbgjMbW32RbNjh5w=; b=PHZeL+JDuAiFsB4+nG05TOMMlESPMjYgK/zUR7/jotExg34U8VHcNtoHdvbug4mci7 bFHdpbM1kgn85JSxLqK9axUaYOGRQMdKwUhBL4KGG8WNWRXl2IQWCxoTMj7ur+ngZ3YF TenVCtG6SshR+4zS3SL7C43rEWna9ga+G/Q1TwDIHN6A5TDLvNICrjExrUXvKHAnjeQd P5wMlWkmcIDlXNqYRU/qgAArRyEOVUrCb66tvntyYMyHXdaganiyizw3QUZtmAK86/+o yOMPBzKj8QJ0PQlbmu/03+fGNIKaNQtxN17RCNfcjqdeUNxAKa9UwrFu9xK4E+YgARjz +yaw== ARC-Authentication-Results: i=1; mx.google.com; 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 f15si6540922pfn.152.2021.04.23.05.54.01; Fri, 23 Apr 2021 05:54:17 -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; 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 S242436AbhDWMxy (ORCPT + 99 others); Fri, 23 Apr 2021 08:53:54 -0400 Received: from vps0.lunn.ch ([185.16.172.187]:37942 "EHLO vps0.lunn.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230305AbhDWMxy (ORCPT ); Fri, 23 Apr 2021 08:53:54 -0400 Received: from andrew by vps0.lunn.ch with local (Exim 4.94) (envelope-from ) id 1lZvJ3-000eY8-KB; Fri, 23 Apr 2021 14:53:13 +0200 Date: Fri, 23 Apr 2021 14:53:13 +0200 From: Andrew Lunn To: Ansuel Smith Cc: Florian Fainelli , Vivien Didelot , Vladimir Oltean , "David S. Miller" , Jakub Kicinski , Rob Herring , Heiner Kallweit , Russell King , netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 13/14] drivers: net: dsa: qca8k: protect MASTER busy_wait with mdio mutex Message-ID: References: <20210423014741.11858-1-ansuelsmth@gmail.com> <20210423014741.11858-14-ansuelsmth@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210423014741.11858-14-ansuelsmth@gmail.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Apr 23, 2021 at 03:47:39AM +0200, Ansuel Smith wrote: > MDIO_MASTER operation have a dedicated busy wait that is not protected > by the mdio mutex. This can cause situation where the MASTER operation > is done and a normal operation is executed between the MASTER read/write > and the MASTER busy_wait. Rework the qca8k_mdio_read/write function to > address this issue by binding the lock for the whole MASTER operation > and not only the mdio read/write common operation. > > Signed-off-by: Ansuel Smith > --- > drivers/net/dsa/qca8k.c | 59 ++++++++++++++++++++++++++++++++++------- > 1 file changed, 50 insertions(+), 9 deletions(-) > > diff --git a/drivers/net/dsa/qca8k.c b/drivers/net/dsa/qca8k.c > index 88a0234f1a7b..d2f5e0b1c721 100644 > --- a/drivers/net/dsa/qca8k.c > +++ b/drivers/net/dsa/qca8k.c > @@ -609,9 +609,33 @@ qca8k_port_to_phy(int port) > return port - 1; > } > > +static int > +qca8k_mdio_busy_wait(struct qca8k_priv *priv, u32 reg, u32 mask) > +{ > + unsigned long timeout; > + u16 r1, r2, page; > + > + qca8k_split_addr(reg, &r1, &r2, &page); > + > + timeout = jiffies + msecs_to_jiffies(20); > + > + /* loop until the busy flag has cleared */ > + do { > + u32 val = qca8k_mii_read32(priv->bus, 0x10 | r2, r1); > + int busy = val & mask; > + > + if (!busy) > + break; > + cond_resched(); > + } while (!time_after_eq(jiffies, timeout)); > + > + return time_after_eq(jiffies, timeout); You should really be returning -ETIMEDOUT here on error. Andrew