Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp2835277pxb; Mon, 1 Nov 2021 02:51:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwPdEWE0IjigqOoR/48O0T3F9FeLFwEJPf2NKQU0peDj2/QDIJW4GHhApX1KRoP3JzX8dMr X-Received: by 2002:a5d:8884:: with SMTP id d4mr20177696ioo.137.1635760295714; Mon, 01 Nov 2021 02:51:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635760295; cv=none; d=google.com; s=arc-20160816; b=ouSsT2K4M0apVAxSFifuu99PywPVc6BJzoassFd9g0uwqhUd2pYR5KmdPpo8opsAwa gLz3h4Cf0ddb5vYEHCBk6aZ2XEEji37EaEVnHg/YQIMHKZQaOqaRgMFkbm5kNkL/XNUv xmzk7xw87Ogqzo0cKOfRDtgW8kraYAs2/nkLxAI/wkICskHPZiOnsQoDUn8HKnB7RyOw cP8JAYxWZMrXy37935a8sTeNiAG666XWEtlUlkKYJ9sRO/HdOHQKp1rFPqRHhL6GpJgs FwK0TpJbdppoG835OILL+BGw/9VkHPFocC6Rj67T/lCg08EB5aW+Gg9UR6+SufglFfqz Zfcw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=/d++k1OBQWLSCgtS1vrdv6Du25hSOHu4H4Ya/iDWp3s=; b=v6qsw8uIq8a+8yJuqczizbZ1His1VlEK2b2zPn1DlaaG+5tdCyQaO8IhYA9cBB7OmI GF4nxP5GywoTFK7nr6Z/4VTb99dCmYkDAz8s9f0Cy/8wqbiT+MTVmuRYw+QPepKX25Sg NnY0uUBB9PR82fi+7ODerNmhjP+NV3RN5zDuGxDs0v3U98gHr0KvpvXguL7lVoAJB/z2 vngEz2xOpOdK9+zPHILeb3m9PPEayIqtZA/mu9MEtt7Zw8qzgOmbr/c+puwJnwBjlsKR IJfxtDPKUpBaHs/z4hmWVZxS8nTAEV8F1JLUpiG5aA53pTndcuFTAAP6T4le62t6yRQe JFvg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=u1eQOzRb; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b69si15285793jab.32.2021.11.01.02.51.22; Mon, 01 Nov 2021 02:51:35 -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=@linuxfoundation.org header.s=korg header.b=u1eQOzRb; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233361AbhKAJvV (ORCPT + 99 others); Mon, 1 Nov 2021 05:51:21 -0400 Received: from mail.kernel.org ([198.145.29.99]:51436 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234133AbhKAJrW (ORCPT ); Mon, 1 Nov 2021 05:47:22 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 968D2613D5; Mon, 1 Nov 2021 09:30:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1635759054; bh=QLN1NfppkSWzVDuYNxx1VFzeAylfpOOQObfwOAeHt5k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=u1eQOzRbFstdvY8UvyEFXasE+XDXDkmwiedmC1icB7nG+OhEvW2Nae+oFQTtOb4+O 7H2IjLcyATLHP8tcdnEPK9doK5RpohMzohE00t9LgJy96MIJKXYiKDod+MrMpUlXUP u6FXQ+VWvk+Upi3K/kq0z4z/s+APWcifegGcgwU8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Walter Stoll , Andrew Lunn , "David S. Miller" Subject: [PATCH 5.14 095/125] phy: phy_ethtool_ksettings_set: Lock the PHY while changing settings Date: Mon, 1 Nov 2021 10:17:48 +0100 Message-Id: <20211101082551.144238316@linuxfoundation.org> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211101082533.618411490@linuxfoundation.org> References: <20211101082533.618411490@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Andrew Lunn commit af1a02aa23c37045e6adfcf074cf7dbac167a403 upstream. There is a race condition where the PHY state machine can change members of the phydev structure at the same time userspace requests a change via ethtool. To prevent this, have phy_ethtool_ksettings_set take the PHY lock. Fixes: 2d55173e71b0 ("phy: add generic function to support ksetting support") Reported-by: Walter Stoll Suggested-by: Walter Stoll Tested-by: Walter Stoll Signed-off-by: Andrew Lunn Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- drivers/net/phy/phy.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) --- a/drivers/net/phy/phy.c +++ b/drivers/net/phy/phy.c @@ -798,6 +798,7 @@ int phy_ethtool_ksettings_set(struct phy duplex != DUPLEX_FULL))) return -EINVAL; + mutex_lock(&phydev->lock); phydev->autoneg = autoneg; if (autoneg == AUTONEG_DISABLE) { @@ -814,8 +815,9 @@ int phy_ethtool_ksettings_set(struct phy phydev->mdix_ctrl = cmd->base.eth_tp_mdix_ctrl; /* Restart the PHY */ - phy_start_aneg(phydev); + _phy_start_aneg(phydev); + mutex_unlock(&phydev->lock); return 0; } EXPORT_SYMBOL(phy_ethtool_ksettings_set);