Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp2828077pxb; Mon, 1 Nov 2021 02:40:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx04TlujC9g7NjinzLEBU0F2xkG+QAYADlAotaveKUGq2RyG8FUsEWlIXiuX8dlvO1Cy/b+ X-Received: by 2002:a92:c541:: with SMTP id a1mr5080250ilj.5.1635759623276; Mon, 01 Nov 2021 02:40:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635759623; cv=none; d=google.com; s=arc-20160816; b=VcKnhDJ3akBbXCiwY+wr6U9b0/TF8pwLFJMSS5yO4MQFTj/oEr3xriGy1XdzJRNMyN hsVvAxyZTtc9ZxTPspF2rwzfto5zEmH8KwN8Q1eKhuXwFwqsuYhuDN9QD+PaRygP/dwC 8JrZIfsQbm5fXAKAPS71btYTcEW0aCUHhIUVQWL4Y7737pfE8k1a/VJsH/MxbjoQpLJ6 IIHG9km+CTnLop8nZtnrT6qxtgnwFZ8e/bcFqYduJ8SbM+uZBDgyVe75fZwXPKI5SU/1 FwBFEfd+0MKmkSOeVfe8n8HttQM5d98zOwIGESP0dLjbYyhfheHnGUHrfgG3FDcnKqY5 XpZg== 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=7lUN6H6VZ+8t/Z/pwZTJiHK5IQTUtmQNg1W8AcKIf/E=; b=hdKcP27a8H+WSsFys1ZB5sz5gFhoCi2JqtqmIjQ8Yl8YNziw2oGD+XO78QRyZFRzMH 47MfrwndWSvtC1CWkZPg//GPfLCLQ9SLOsqVTAaeiRPOkZmddzeq0mLSgoiXbVDiQVjv t9ReENKP6Tr3Efp7u/IX0U3um0rK2vfOTDQHMS234jdw6IIFSSLffv+AKO63F0SK9Y+Z 3mchbshecBuTXLa/zCR1Pm/jyZ4acYJH97+qaMQWvYtkAILg6zBUSdmeiuHxJF58tpQZ M7h/VFVj/j/Xjc2+qVZlMKhCyEx5KlqcKk/sq5lPbbPh7BljeJ6Usguaqf+T1IhDvmUN rD8g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=tBF6lM5J; 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 m3si22810891ilu.139.2021.11.01.02.40.12; Mon, 01 Nov 2021 02:40:23 -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=tBF6lM5J; 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 S232126AbhKAJk7 (ORCPT + 99 others); Mon, 1 Nov 2021 05:40:59 -0400 Received: from mail.kernel.org ([198.145.29.99]:43582 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233646AbhKAJhr (ORCPT ); Mon, 1 Nov 2021 05:37:47 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 4468C61353; Mon, 1 Nov 2021 09:26:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1635758802; bh=L0e9MjlUSI+T7GeM+QozspY/hywwhA4+PDtzbxM3ylQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tBF6lM5JSJr5Fv/DnVUdkmkPb5Bp7YHSKm+2PgzPN9Zdx5iANoU3ev4ub0nMoehHf FYkeDZOl4BUPEupTpuTbvjAakbl3PMOMjgOC7Oms+vo/QLbe74Wl3jkrwPgVzCyKit hptKno0Pr24Zb55SfxMjdGOTVl4WOI5VQ+JItiFc= 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.10 64/77] phy: phy_ethtool_ksettings_set: Lock the PHY while changing settings Date: Mon, 1 Nov 2021 10:17:52 +0100 Message-Id: <20211101082525.050743740@linuxfoundation.org> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211101082511.254155853@linuxfoundation.org> References: <20211101082511.254155853@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 @@ -814,6 +814,7 @@ int phy_ethtool_ksettings_set(struct phy duplex != DUPLEX_FULL))) return -EINVAL; + mutex_lock(&phydev->lock); phydev->autoneg = autoneg; if (autoneg == AUTONEG_DISABLE) { @@ -830,8 +831,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);