Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp2124732rwb; Wed, 30 Nov 2022 02:40:32 -0800 (PST) X-Google-Smtp-Source: AA0mqf6i2JCz2VEJSa2WWH6cM6HLl7TL9XfP8hmbxYYfQ8i4iZhvJsw7/W9lD177afFQlEKQRZ3z X-Received: by 2002:a05:6402:656:b0:469:f6e2:58de with SMTP id u22-20020a056402065600b00469f6e258demr35550014edx.308.1669804832666; Wed, 30 Nov 2022 02:40:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669804832; cv=none; d=google.com; s=arc-20160816; b=KQm1nzI8PZduxfB6mHwhSvftSAX96HmRMH+ROy3lHOh0lj8pdzVEmA2itnYxv0pXZg UvaZssko1P3zpSDb//ygcHmVqm7/TbGYBG6f/vNj+I3nsuDsDid12ZL4J5u7zbunmvAd Lifks4F8gvscfF7sUYD9XI3TBixC5fPiVgLQRGdkl05s8muGbUh4KRLJ1TS+aiRiWBVM LzTEvbHPWTt5tDvLhr8tRaKnHpn79lMe2vMqzivTwMkO2yRwuLOki5qTdzb1IsKiQAwJ hv25Mz1zO8aIKXx99UwdzjSyoYXw/HyFHjJZZjDwWIKkQV+KI5ASZHrX0AqxsfxI+mgK ZKiQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=GVLyEqnOyLgzZX9E6rEEaMWO0mcMUM4Ki3SNZTd8s3I=; b=S7kVKHDpx2FdG3h1JGsiL3+pX8s3FtcbUvx5oJGPtiEtXNFlSTktzORQGAQXpUnaC0 D0n+6ypfKurYkZ2ohMw8dHImY5sEzzn4LU/jxSuU5pr7WPpamPeF1X5xnEn3Xk1hASrm SFgI54l1fc2KaysJR/jkevL2w21/lxhNe39/AXBfRLSyTjMQJ+/FTJrCR0Euh97WXQTQ DHQ68ObtPhVtG4bUXdak72fSfBmsHP/7JYch3+ZZ6S8mTFgVh5biSXiGQ4mL3oxSqnjb TAxLwjQtgrTXyoq7Cz73d6e49M1/sBf62WoVshs0DhpIVO0kCpklzm84kvyV4TRRdRfc rxyA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail (test mode) header.i=@armlinux.org.uk header.s=pandora-2019 header.b=JoZ5+muE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=armlinux.org.uk Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o6-20020a50fd86000000b00469d569a4afsi855215edt.509.2022.11.30.02.40.10; Wed, 30 Nov 2022 02:40:32 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=fail (test mode) header.i=@armlinux.org.uk header.s=pandora-2019 header.b=JoZ5+muE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=armlinux.org.uk Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235057AbiK3J4N (ORCPT + 84 others); Wed, 30 Nov 2022 04:56:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56540 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234034AbiK3J4M (ORCPT ); Wed, 30 Nov 2022 04:56:12 -0500 Received: from pandora.armlinux.org.uk (pandora.armlinux.org.uk [IPv6:2001:4d48:ad52:32c8:5054:ff:fe00:142]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C897B2B18F; Wed, 30 Nov 2022 01:56:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=armlinux.org.uk; s=pandora-2019; h=Sender:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=GVLyEqnOyLgzZX9E6rEEaMWO0mcMUM4Ki3SNZTd8s3I=; b=JoZ5+muE9jhUXGIc1rOcWjW5N1 56AHpUVmIMNWFE/9Dup8JNBm+PRFGpqUH+ETJa0dGnOOJH1NKKXwdd1plcEpVW8t0zg3a9Kon+bEd Jm75Qb9h3X4YCrgSFeGzyqOY9Eg+dHqMT0w0cLYUkZAC2ARO9yjX24MFsg/QgdxN9JWRx3++IWZUH 6eTkX+bp2jDnH/DjCpA0PulUHoDKODkXpPa7gsUZ8/fW2CiKk9USYE2pRHrCTIbSfgypjC/ve1Eat ndKCwLxe1njB6jMzoB9kNqZqm0mnWd3CdIXGeTjhB+jo/gvQbxgD4uG+yBO5pDNkBuVrHy+QY9LDm 3Q15pC+w==; Received: from shell.armlinux.org.uk ([fd8f:7570:feb6:1:5054:ff:fe00:4ec]:35490) by pandora.armlinux.org.uk with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1p0Joo-0001Z9-13; Wed, 30 Nov 2022 09:55:54 +0000 Received: from linux by shell.armlinux.org.uk with local (Exim 4.94.2) (envelope-from ) id 1p0Jok-0002Oj-Et; Wed, 30 Nov 2022 09:55:50 +0000 Date: Wed, 30 Nov 2022 09:55:50 +0000 From: "Russell King (Oracle)" To: Frank Cc: Peter Geis , Andrew Lunn , Heiner Kallweit , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , yinghong.zhang@motor-comm.com, fei.zhang@motor-comm.com, hua.sun@motor-comm.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH net-next] net: phy: Add driver for Motorcomm yt8531 gigabit ethernet phy Message-ID: References: <20221130094928.14557-1-Frank.Sae@motor-comm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20221130094928.14557-1-Frank.Sae@motor-comm.com> Sender: Russell King (Oracle) X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Nov 30, 2022 at 05:49:28PM +0800, Frank wrote: > +/** > + * yt8531_set_wol() - turn wake-on-lan on or off > + * @phydev: a pointer to a &struct phy_device > + * @wol: a pointer to a &struct ethtool_wolinfo > + * > + * NOTE: YTPHY_WOL_CONFIG_REG, YTPHY_WOL_MACADDR2_REG, YTPHY_WOL_MACADDR1_REG > + * and YTPHY_WOL_MACADDR0_REG are common ext reg. > + * > + * returns 0 or negative errno code > + */ > +static int yt8531_set_wol(struct phy_device *phydev, > + struct ethtool_wolinfo *wol) > +{ So this is called from the .set_wol method directly, and won't have the MDIO bus lock taken... > + struct net_device *p_attached_dev; > + const u16 mac_addr_reg[] = { > + YTPHY_WOL_MACADDR2_REG, > + YTPHY_WOL_MACADDR1_REG, > + YTPHY_WOL_MACADDR0_REG, > + }; > + const u8 *mac_addr; > + u16 mask; > + u16 val; > + int ret; > + u8 i; > + > + if (wol->wolopts & WAKE_MAGIC) { > + p_attached_dev = phydev->attached_dev; > + if (!p_attached_dev) > + return -ENODEV; > + > + mac_addr = (const u8 *)p_attached_dev->dev_addr; > + if (!is_valid_ether_addr(mac_addr)) > + return -EINVAL; > + > + /* Store the device address for the magic packet */ > + for (i = 0; i < 3; i++) { > + ret = ytphy_write_ext(phydev, mac_addr_reg[i], > + ((mac_addr[i * 2] << 8)) | > + (mac_addr[i * 2 + 1])); This accesses the MDIO bus without taking the lock. > + if (ret < 0) > + return ret; > + } > + > + /* Enable WOL feature */ > + mask = YTPHY_WCR_PULSE_WIDTH_MASK | YTPHY_WCR_INTR_SEL; > + val = YTPHY_WCR_ENABLE | YTPHY_WCR_INTR_SEL; > + val |= YTPHY_WCR_TYPE_PULSE | YTPHY_WCR_PULSE_WIDTH_672MS; > + ret = ytphy_modify_ext(phydev, YTPHY_WOL_CONFIG_REG, mask, val); This accesses the MDIO bus without taking the lock. > + if (ret < 0) > + return ret; > + > + /* Enable WOL interrupt */ > + ret = __phy_modify(phydev, YTPHY_INTERRUPT_ENABLE_REG, 0, > + YTPHY_IER_WOL); This accesses the MDIO bus without taking the lock. > + if (ret < 0) > + return ret; > + } else { > + /* Disable WOL feature */ > + mask = YTPHY_WCR_ENABLE | YTPHY_WCR_INTR_SEL; > + ret = ytphy_modify_ext(phydev, YTPHY_WOL_CONFIG_REG, mask, 0); This accesses the MDIO bus without taking the lock. > + > + /* Disable WOL interrupt */ > + ret = __phy_modify(phydev, YTPHY_INTERRUPT_ENABLE_REG, > + YTPHY_IER_WOL, 0); This accesses the MDIO bus without taking the lock. > + if (ret < 0) > + return ret; > + } > + > + return 0; > +} Which makes this function entirely unsafe as another thread can change the YTPHY_PAGE_SELECT register between writing that register and accessing the YTPHY_PAGE_DATA register. -- RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last!