From nobody Tue Dec 23 14:24:09 2025 Received: from mail-wm1-f41.google.com (mail-wm1-f41.google.com [209.85.128.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EAC26232392 for ; Mon, 13 Jan 2025 08:49:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736758166; cv=none; b=Z41ZdbwxP71Fq7073vR9eVW/utF11w1mLrc/JcEt2Cj4ClX8PgMXKmjvF7ElxM9vRMM+RVkwokOEVGrOu800ZcVuCaThHQ8860+5ZA1LP7lzwAwKnjoifMLZcBAu9wobaJgXiSVSSpeKhIchVRd2ycGKllpOlQ4+sPsw1nv5W4I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736758166; c=relaxed/simple; bh=vCkDacTWZvcuafWH2kjulsf3aX2Vk3dmsFF092eXKBQ=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=n58IqXDUPvDkie46XthElUFmub6BP5SuvFs/zP0omAZLrSVAEnRXHq463w1fKN2OuwZVF+UlTgv45aeo7SuPFw13JknjP2H7YQjoiTmL2THj3UPolHkZs4NLP0vgY+AJ9RFStwWWkayxoK4XSXwTCHBXSr8PtdOOUw4BsouWwKo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sigma-star.at; spf=pass smtp.mailfrom=sigma-star.at; dkim=pass (2048-bit key) header.d=sigma-star.at header.i=@sigma-star.at header.b=LBs4KqeJ; arc=none smtp.client-ip=209.85.128.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sigma-star.at Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sigma-star.at Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sigma-star.at header.i=@sigma-star.at header.b="LBs4KqeJ" Received: by mail-wm1-f41.google.com with SMTP id 5b1f17b1804b1-4362f61757fso38413365e9.2 for ; Mon, 13 Jan 2025 00:49:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sigma-star.at; s=google; t=1736758162; x=1737362962; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=Gnnl0VwLJeV2gkqDwbC1b2CdoHjgb3H7tibMthkFU6U=; b=LBs4KqeJ9tbqT2QtgZWhL6WKL0qB0FRtypV1xtIWqkKypw4ZVN1fPR6UiUnC7UJasQ TQE9m32Wa+mW1OaO5dq4LmpcTHDm4B88vV74+Nw5vP6dGNFhfteKBXjXlYwsS88ILLTr qGxXGoYAcnbYWWpzTqwHIUqypQkz6lB9s5NVGKcCWHvQ0Df60+NKYhkFlwVauo1xo+HY IfFYEojY8qk7baKCbUlOb3N2N2xaE9T2TTnpr2mbI4wr3arO3s+c1EPfmHybferDw8E4 U/MY9z9qpQOZJ9NPgdVYe6hjOh2IJNe20v+AlNTjg6Q7nMp2Yigg/RgH4W6biV1kszbN OD8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736758162; x=1737362962; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Gnnl0VwLJeV2gkqDwbC1b2CdoHjgb3H7tibMthkFU6U=; b=plJrNrtMbDpcEA+jaT24/BMIy2+8zKnKkRMXBSRxGasyb2qWadGEt3aBUBsDHg0FNx A7ehcstv9iSfqk4OJ+F0cL75ZylGXyySWP/6c0QgYrUyRMsImxZ7s3vqCfbW7hGjoQcg FGIWls/YZ/vuUixdBjurz0Q7fJY9QY+iDUX98wGO21pTJ9nNmN+wYVuzIgI270TllATW JeXzieXmZc1BaYCQt2V1PjvxhcTIztTVu0WhYOez2+97Mbyx9fHAc9dY9s3IKxiKvVK2 6peKoO5XtYBvoBworI8wTYVeO2NyaOj/0Hm36MkHUU1CaRgaFllCn7zsKSkih9vERqBg OYtA== X-Forwarded-Encrypted: i=1; AJvYcCVExxmNH7onWwBhtCZbhC70XL5cvI8G+rOxnMqjv7uACIEWseW7OKCmqjTLA353L4u7WP/JHrU81uYz7to=@vger.kernel.org X-Gm-Message-State: AOJu0Yy8vv6P6ozUvPm9/luTnBpziuAHL4qUZbcsoreWf6iGF1mNZ0y/ UL3ek5dzqYWD2fK+hiUZep2RG98PoOZ1bn2FXrGt71VbVi1HXF9MW8dVUXqLXA8= X-Gm-Gg: ASbGnctp0eUgDrJ38AvsNeFt0KZI62Qnhngsfrxs/NrZzLl6zsyg2D/CKCqV2Wtqk4/ MeD58rUFTIf79hO8Er4klBdXqvxrSRUvKbbCkuU11PnrZj5YOfDX9hS8X4uQ/OQ7f0eqONEWJq8 UqY+rzr3PiJe+MYpPg5jlgFIKlIhOIHRaZQluV12t4rp5+E2f3e0nDpCiEgnynhvc65ftHj7C91 sYqgzm12D9zIa0XhAcT57JMD7BHtXkFvGDBh8apl8fxELMrUCyJfjk20R+7TKzW85guAhDbPkat NuOtcBDeVaYfPzoOMH77 X-Google-Smtp-Source: AGHT+IFBijnZ0WjmXifiseTgCnAunx2NxiPja28AwiOTHT/QqLpzFwAOQAkeKW+0V1Wumd0RGJ6NuQ== X-Received: by 2002:a05:600c:b55:b0:435:1b:65ee with SMTP id 5b1f17b1804b1-436e2707f2cmr148478835e9.24.1736758161975; Mon, 13 Jan 2025 00:49:21 -0800 (PST) Received: from localtoast.corp.sigma-star.at ([82.150.214.1]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-436e2df2faesm171830825e9.26.2025.01.13.00.49.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jan 2025 00:49:21 -0800 (PST) From: David Oberhollenzer To: netdev@vger.kernel.org, andrew@lunn.ch Cc: Julian.FRIEDRICH@frequentis.com, f.fainelli@gmail.com, olteanv@gmail.com, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, linux-kernel@vger.kernel.org, upstream+netdev@sigma-star.at, David Oberhollenzer Subject: [PATCH v3] net: dsa: mv88e6xxx: propperly shutdown PPU re-enable timer on destroy Date: Mon, 13 Jan 2025 09:49:12 +0100 Message-ID: <20250113084912.16245-1-david.oberhollenzer@sigma-star.at> X-Mailer: git-send-email 2.47.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The mv88e6xxx has an internal PPU that polls PHY state. If we want to access the internal PHYs, we need to disable it. Because enable/disable of the PPU is a slow operation, a 10ms timer is used to re-enable it, canceled with every access, so bulk operations effectively only disable it once and re-enable it some 10ms after the last access. If a PHY is accessed and then the mv88e6xxx module is removed before the 10ms are up, the PPU re-enable ends up accessing a dangling pointer. This especially affects probing during bootup. The MDIO bus and PHY registration may succeed, but registration with the DSA framework may fail later on (e.g. because the CPU port depends on another, very slow device that isn't done probing yet, returning -EPROBE_DEFER). In this case, probe() fails, but the MDIO subsystem may already have accessed the MIDO bus or PHYs, arming timer. This is fixed as follows: - If probe fails after mv88e6xxx_phy_init(), make sure we also call mv88e6xxx_phy_destroy() before returning - In mv88e6xxx_phy_destroy(), grab the ppu_mutex to make sure the work function either has already exited, or (should it run) cannot do anything, mutex_trylock() in the worker function fails to grab the mutex and returns. - In addition to destroying the timer, also destroy the work item, in case the timer has already fired. - Do all of this synchronously, to make sure timer & work item are destroyed and none of the callbacks are running. - Because of the nesting of the timer & work item, cancel_work_sync() alone is not sufficient and the order of the cancellation steps matters. Fixes: 2e5f032095ff ("dsa: add support for the Marvell 88E6131 switch chip") Signed-off-by: David Oberhollenzer --- FWIW, this is a forward port of a patch I'm using on v6.6. Thanks, David --- drivers/net/dsa/mv88e6xxx/chip.c | 8 +++++--- drivers/net/dsa/mv88e6xxx/phy.c | 3 +++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/drivers/net/dsa/mv88e6xxx/chip.c b/drivers/net/dsa/mv88e6xxx/c= hip.c index 284270a4ade1..c2af69bed660 100644 --- a/drivers/net/dsa/mv88e6xxx/chip.c +++ b/drivers/net/dsa/mv88e6xxx/chip.c @@ -7264,13 +7264,13 @@ static int mv88e6xxx_probe(struct mdio_device *mdio= dev) err =3D mv88e6xxx_switch_reset(chip); mv88e6xxx_reg_unlock(chip); if (err) - goto out; + goto out_phy; =20 if (np) { chip->irq =3D of_irq_get(np, 0); if (chip->irq =3D=3D -EPROBE_DEFER) { err =3D chip->irq; - goto out; + goto out_phy; } } =20 @@ -7289,7 +7289,7 @@ static int mv88e6xxx_probe(struct mdio_device *mdiode= v) mv88e6xxx_reg_unlock(chip); =20 if (err) - goto out; + goto out_phy; =20 if (chip->info->g2_irqs > 0) { err =3D mv88e6xxx_g2_irq_setup(chip); @@ -7323,6 +7323,8 @@ static int mv88e6xxx_probe(struct mdio_device *mdiode= v) mv88e6xxx_g1_irq_free(chip); else mv88e6xxx_irq_poll_free(chip); +out_phy: + mv88e6xxx_phy_destroy(chip); out: if (pdata) dev_put(pdata->netdev); diff --git a/drivers/net/dsa/mv88e6xxx/phy.c b/drivers/net/dsa/mv88e6xxx/ph= y.c index 8bb88b3d900d..ee9e5d7e5277 100644 --- a/drivers/net/dsa/mv88e6xxx/phy.c +++ b/drivers/net/dsa/mv88e6xxx/phy.c @@ -229,7 +229,10 @@ static void mv88e6xxx_phy_ppu_state_init(struct mv88e6= xxx_chip *chip) =20 static void mv88e6xxx_phy_ppu_state_destroy(struct mv88e6xxx_chip *chip) { + mutex_lock(&chip->ppu_mutex); del_timer_sync(&chip->ppu_timer); + cancel_work_sync(&chip->ppu_work); + mutex_unlock(&chip->ppu_mutex); } =20 int mv88e6185_phy_ppu_read(struct mv88e6xxx_chip *chip, struct mii_bus *bu= s, --=20 2.47.1