From patchwork Fri Jan 19 06:51:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andre Werner X-Patchwork-Id: 13523361 X-Patchwork-Delegate: kuba@kernel.org Received: from mail.systec-electronic.com (mail.systec-electronic.com [77.220.239.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 61ECE3C17; Fri, 19 Jan 2024 06:55:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=77.220.239.22 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705647356; cv=none; b=A2Q7BpbwodUO3fJPxSLzcWNf/IQQetk9jkTbxjXn9hdfQAEuccaOLkXRFlGbSnjMdIPSlNo4dM5G1Z++dVP4OBuTir6vufDvhW224930jZ/R2kQGhsK7/3HDZXsIAy9uUIkDPRzFJte3N7pUBVlRtkS4LAI52qtDBV68CPgEKz8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705647356; c=relaxed/simple; bh=EzdJOK/zJZATzSg79oEE1SrvYSP+J0rhqwg1XzobUgc=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=kXyc5jB/crTlcSOp/L3taLLrTNy8OHAi8Siriv5N7NQ4i7SHrA4y/M1pw09oCJlZvX+hA4N2T8dPa2MVd6tyHxQYBaLu+8RuJCUpzfuFVg1oCggCETKTH/+hRz7xQ7mhJyDlUhDRQJS/VZhEFeoGI1tHzIrBW8bA7Ggq7RNF1zo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=systec-electronic.com; spf=pass smtp.mailfrom=systec-electronic.com; dkim=pass (2048-bit key) header.d=systec-electronic.com header.i=@systec-electronic.com header.b=O7qv4Ew5; arc=none smtp.client-ip=77.220.239.22 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=systec-electronic.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=systec-electronic.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=systec-electronic.com header.i=@systec-electronic.com header.b="O7qv4Ew5" Received: from localhost (localhost.localdomain [127.0.0.1]) by mail.systec-electronic.com (Postfix) with ESMTP id 995539400107; Fri, 19 Jan 2024 07:55:52 +0100 (CET) Received: from mail.systec-electronic.com ([127.0.0.1]) by localhost (mail.systec-electronic.com [127.0.0.1]) (amavis, port 10032) with ESMTP id NI2KU7HkxeRZ; Fri, 19 Jan 2024 07:55:52 +0100 (CET) Received: from localhost (localhost.localdomain [127.0.0.1]) by mail.systec-electronic.com (Postfix) with ESMTP id 681EF940010D; Fri, 19 Jan 2024 07:55:52 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.10.3 mail.systec-electronic.com 681EF940010D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=systec-electronic.com; s=B34D3B04-5DC7-11EE-83E3-4D8CAB78E8CD; t=1705647352; bh=1bp2JHVqKgh6eV2IyrM4+ZNotlv2F+x5CxIeVH2IOsE=; h=From:To:Date:Message-ID:MIME-Version; b=O7qv4Ew521oxlL4dPIzgD2fJ00EIUXUZpOtTBtAwgLrp90Wv972QV3KCnR3rZKOdq M6XA/Z5GJ3Q8q/8uFVie/VDg1hAIRwYKyzaTRvWzBzRssFygL4hXCoVAwlDC0TxlNW 9+NHqfQwQzYZBiz4bg/P/YC85LJhHIWWCfjy5n2ICtHpojlx6SAyPM+gUFUx8ipSjB aHckHevMEhlWL+NjLAmsj1DkniwZ+pE/6NyhTFZfyCSBkHIz5w7O/dEcJIEMx8H2fd s66N1lDndC2c9LlbedgBwiaPUFWJyHP45OUeiuq1nP667wxdwrssou0h4UVZw9Y/+L Jt59zDeihlG4g== X-Virus-Scanned: amavis at systec-electronic.com Received: from mail.systec-electronic.com ([127.0.0.1]) by localhost (mail.systec-electronic.com [127.0.0.1]) (amavis, port 10026) with ESMTP id 71MDglRghmsS; Fri, 19 Jan 2024 07:55:52 +0100 (CET) Received: from ws-565760.systec.local (unknown [212.185.67.148]) by mail.systec-electronic.com (Postfix) with ESMTPSA id 0C5879400107; Fri, 19 Jan 2024 07:55:52 +0100 (CET) From: Andre Werner To: andrew@lunn.ch, hkallweit1@gmail.com, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com Cc: linux@armlinux.org.uk, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Andre Werner Subject: [RFC net-next v2 1/2] net: phy: phy_device Prevent nullptr exceptions on ISR Date: Fri, 19 Jan 2024 07:51:13 +0100 Message-ID: <20240119065542.30279-1-andre.werner@systec-electronic.com> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC If phydev->irq is set unconditionally by MAC drivers, check for valid interrupt handler or fall back to polling mode to prevent nullptr exceptions. Signed-off-by: Andre Werner --- It was exact the way described by Heiner Kallweit. The Kernel Oops looked as follows: [ +0.004455] smsc95xx v2.0.0 [ +0.578343] ADIN1100 usb-001:007:00: attached PHY driver (mii_bus:phy_addr=usb-001:007:00, irq=149) [ +0.000526] smsc95xx 1-4:1.0 eth0: register 'smsc95xx' at usb-0000:00:14.0-4, smsc95xx USB 2.0 Ethernet, 44:d5:f2:a0:4d:bc [ +0.027107] smsc95xx 1-4:1.0 enp0s20f0u4: renamed from eth0 [ +0.073992] smsc95xx 1-4:1.0 enp0s20f0u4: Link is Down [ +9.559260] BUG: kernel NULL pointer dereference, address: 0000000000000000 [ +0.000020] #PF: supervisor instruction fetch in kernel mode [ +0.000008] #PF: error_code(0x0010) - not-present page [ +0.000009] PGD 0 P4D 0 [ +0.000011] Oops: 0010 [#1] PREEMPT SMP NOPTI [ +0.000013] CPU: 4 PID: 2073 Comm: irq/149-usb-001 Tainted: G OE 6.5.5-arch1-1 #1 d82a0f532dd8cfe67d5795c1738d9c01059a0c62 [ +0.000014] Hardware name: LENOVO 20RD001CGE/20RD001CGE, BIOS R16ET29W (1.15 ) 12/03/2020 [ +0.000006] RIP: 0010:0x0 [ +0.000100] Code: Unable to access opcode bytes at 0xffffffffffffffd6. [ +0.000007] RSP: 0018:ffffb3b8c35b3e58 EFLAGS: 00010246 [ +0.000011] RAX: 0000000000000000 RBX: ffff8e5a84d10800 RCX: 0000000000000002 [ +0.000007] RDX: ffff8e5aeba52100 RSI: ffff8e5a84d10800 RDI: ffff8e5a84d10800 [ +0.000007] RBP: ffff8e5a84d10d48 R08: 0000000000000000 R09: 0000000000000000 [ +0.000007] R10: 0000000000000001 R11: 0000000000000100 R12: ffffffffc22720a0 [ +0.000007] R13: ffff8e5a8a0a0c80 R14: ffffffff983505e0 R15: ffff8e5aed177940 [ +0.000006] FS: 0000000000000000(0000) GS:ffff8e5dd1500000(0000) knlGS:0000000000000000 [ +0.000009] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ +0.000007] CR2: ffffffffffffffd6 CR3: 000000025b020004 CR4: 00000000003706e0 [ +0.000007] Call Trace: [ +0.000006] [ +0.000008] ? __die+0x23/0x70 [ +0.000018] ? page_fault_oops+0x171/0x4e0 [ +0.000017] ? sched_clock+0x10/0x30 [ +0.000010] ? sched_clock_cpu+0xf/0x190 [ +0.000015] ? exc_page_fault+0x7f/0x180 [ +0.000018] ? asm_exc_page_fault+0x26/0x30 [ +0.000014] ? __pfx_irq_thread_fn+0x10/0x10 [ +0.000031] phy_interrupt+0xac/0xf0 [libphy 6d44c9178d1bba7d6a381c1347a9242562ba5983] [ +0.000097] irq_thread_fn+0x20/0x60 [ +0.000014] irq_thread+0xfb/0x1c0 [ +0.000012] ? __pfx_irq_thread_dtor+0x10/0x10 [ +0.000013] ? __pfx_irq_thread+0x10/0x10 [ +0.000011] kthread+0xe5/0x120 [ +0.000013] ? __pfx_kthread+0x10/0x10 [ +0.000012] ret_from_fork+0x31/0x50 [ +0.000010] ? __pfx_kthread+0x10/0x10 [ +0.000011] ret_from_fork_asm+0x1b/0x30 [ +0.000022] [ +0.000005] Modules linked in: adin1100 smsc95xx selftests usbnet [..] [ +0.000082] CR2: 0000000000000000 [ +0.000007] ---[ end trace 0000000000000000 ]--- v2: - Added the workaround to phy_attach_direct as discussed in first patch submission. TODO: Make phy_device->irq private and add access function that proves availability of interrupt handler in phy driver. --- drivers/net/phy/phy_device.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index 3611ea64875e..3986e103d25e 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -1413,6 +1413,11 @@ int phy_sfp_probe(struct phy_device *phydev, } EXPORT_SYMBOL(phy_sfp_probe); +static bool phy_drv_supports_irq(struct phy_driver *phydrv) +{ + return phydrv->config_intr && phydrv->handle_interrupt; +} + /** * phy_attach_direct - attach a network device to a given PHY device pointer * @dev: network device to attach @@ -1527,6 +1532,18 @@ int phy_attach_direct(struct net_device *dev, struct phy_device *phydev, if (phydev->dev_flags & PHY_F_NO_IRQ) phydev->irq = PHY_POLL; + /* + * Some drivers may add IRQ numbers unconditionally to a phy device that does + * not implement an interrupt handler after phy_probe is already done. + * Reset to PHY_POLL to prevent nullptr exceptions in that case. + */ + if (!phy_drv_supports_irq(phydev->drv) && phy_interrupt_is_valid(phydev)) { + phydev_warn(phydev, + "No handler for IRQ=%d available. Falling back to polling mode\n", + phydev->irq); + phydev->irq = PHY_POLL; + } + /* Port is set to PORT_TP by default and the actual PHY driver will set * it to different value depending on the PHY configuration. If we have * the generic PHY driver we can't figure it out, thus set the old @@ -2992,11 +3009,6 @@ s32 phy_get_internal_delay(struct phy_device *phydev, struct device *dev, } EXPORT_SYMBOL(phy_get_internal_delay); -static bool phy_drv_supports_irq(struct phy_driver *phydrv) -{ - return phydrv->config_intr && phydrv->handle_interrupt; -} - static int phy_led_set_brightness(struct led_classdev *led_cdev, enum led_brightness value) { From patchwork Fri Jan 19 06:51:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andre Werner X-Patchwork-Id: 13523362 X-Patchwork-Delegate: kuba@kernel.org Received: from mail.systec-electronic.com (mail.systec-electronic.com [77.220.239.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C37A6184E; Fri, 19 Jan 2024 06:55:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=77.220.239.22 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705647358; cv=none; b=Rsbm4lV0ZKtCxkCpZRC4i3w3nUogEkaX1t6wSvXbRBgL00F95TN1ZAvgbjjAxlEqeBgwkO/f83lxyFpTVhGpHCz0wpJakY6nUFFdZsHtZLQbE8owDwS9wRho1+fpqspEyUhSOyZ7i3TJhKsY505fXV7fMrGpJuQu58JJVBIhgjY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705647358; c=relaxed/simple; bh=fzZ9PqYrfw2bV7Rfs2G/n0BHJjQaonVjoKgOKh5vznc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=F0tAFVSkwtjziy0J5GR/R8prgUR5k+XMF10kFkQQFEuFhGZy0FYf+6dTsG5SXZW0/RjCjLobbZ41NxuN2ws1bEZEP//l9x9JivMR6hR44ri2sW7qE+8q/6m/j8ppvN4wSMAqpzhg2YHkL6X3FNX7NVtyCDBQ2GwYa4QyGCO24fI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=systec-electronic.com; spf=pass smtp.mailfrom=systec-electronic.com; dkim=pass (2048-bit key) header.d=systec-electronic.com header.i=@systec-electronic.com header.b=iM314C9W; arc=none smtp.client-ip=77.220.239.22 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=systec-electronic.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=systec-electronic.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=systec-electronic.com header.i=@systec-electronic.com header.b="iM314C9W" Received: from localhost (localhost.localdomain [127.0.0.1]) by mail.systec-electronic.com (Postfix) with ESMTP id 01CCF940010D; Fri, 19 Jan 2024 07:55:55 +0100 (CET) Received: from mail.systec-electronic.com ([127.0.0.1]) by localhost (mail.systec-electronic.com [127.0.0.1]) (amavis, port 10032) with ESMTP id Q8OpYxjlMZbe; Fri, 19 Jan 2024 07:55:54 +0100 (CET) Received: from localhost (localhost.localdomain [127.0.0.1]) by mail.systec-electronic.com (Postfix) with ESMTP id BDA089400115; Fri, 19 Jan 2024 07:55:54 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.10.3 mail.systec-electronic.com BDA089400115 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=systec-electronic.com; s=B34D3B04-5DC7-11EE-83E3-4D8CAB78E8CD; t=1705647354; bh=R2H+wxpHRJ7ij8BQv9/AjquxQAEYGY9PEXxh3X7nW18=; h=From:To:Date:Message-ID:MIME-Version; b=iM314C9WPLk/qprc7zek/T3vwG/ee4kK4VD4Q7avuTkfBvoHAFhH+3OSGE3ttQGxh zPj3QEh0pcNeBs5GUmVAO5lQff7Idtq+5Kv40kb5GFhJxsV5cDYh396OCgA8Ju8j1v UnJPVK9Qq4/L6reEqVhyd4SvbRVwMubpnZI0nfjWpxUqPGvtIzMel3587UzK6m12yY XmYAe033xaLMPNSAPRk+c5bdhtRecjEoPhC/2M0AhN+kJNEk4M8zUDHTZKEkjQ52uT d5XqJKhxMnKX4k9VpumoG3cRYsdfTcfGaDPQxrnt237MtZP6lASbQ+gzsmLsbyA4Zc x9bNEfRTSqzPg== X-Virus-Scanned: amavis at systec-electronic.com Received: from mail.systec-electronic.com ([127.0.0.1]) by localhost (mail.systec-electronic.com [127.0.0.1]) (amavis, port 10026) with ESMTP id XjM1_v4EJDbj; Fri, 19 Jan 2024 07:55:54 +0100 (CET) Received: from ws-565760.systec.local (unknown [212.185.67.148]) by mail.systec-electronic.com (Postfix) with ESMTPSA id 724CF940010D; Fri, 19 Jan 2024 07:55:54 +0100 (CET) From: Andre Werner To: andrew@lunn.ch, hkallweit1@gmail.com, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com Cc: linux@armlinux.org.uk, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Andre Werner Subject: [RFC net-next v2 2/2] net: phy: adin1100: Add interrupt support for link change Date: Fri, 19 Jan 2024 07:51:14 +0100 Message-ID: <20240119065542.30279-2-andre.werner@systec-electronic.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240119065542.30279-1-andre.werner@systec-electronic.com> References: <20240119065542.30279-1-andre.werner@systec-electronic.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC An interrupt handler was added to the driver as well as functions to enable interrupts at the phy. There are several interrupts maskable at the phy, but only link change interrupts are handled by the driver yet. Signed-off-by: Andre Werner --- v2: - Clean format and reword commit message as suggested by reviewer of first patch submission --- drivers/net/phy/adin1100.c | 61 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/drivers/net/phy/adin1100.c b/drivers/net/phy/adin1100.c index 7619d6185801..fb1146cf881a 100644 --- a/drivers/net/phy/adin1100.c +++ b/drivers/net/phy/adin1100.c @@ -18,6 +18,12 @@ #define PHY_ID_ADIN1110 0x0283bc91 #define PHY_ID_ADIN2111 0x0283bca1 +#define ADIN_PHY_SUBSYS_IRQ_MASK 0x0021 +#define ADIN_LINK_STAT_CHNG_IRQ_EN BIT(1) + +#define ADIN_PHY_SUBSYS_IRQ_STATUS 0x0011 +#define ADIN_LINK_STAT_CHNG BIT(1) + #define ADIN_FORCED_MODE 0x8000 #define ADIN_FORCED_MODE_EN BIT(0) @@ -136,6 +142,59 @@ static int adin_config_aneg(struct phy_device *phydev) return genphy_c45_config_aneg(phydev); } +static int adin_phy_ack_intr(struct phy_device *phydev) +{ + /* Clear pending interrupts */ + int rc = phy_read_mmd(phydev, MDIO_MMD_VEND2, + ADIN_PHY_SUBSYS_IRQ_STATUS); + + return rc < 0 ? rc : 0; +} + +static int adin_config_intr(struct phy_device *phydev) +{ + int ret, regval; + + ret = adin_phy_ack_intr(phydev); + + if (ret) + return ret; + + regval = phy_read_mmd(phydev, MDIO_MMD_VEND2, + ADIN_PHY_SUBSYS_IRQ_MASK); + if (regval < 0) + return regval; + + if (phydev->interrupts == PHY_INTERRUPT_ENABLED) + regval |= ADIN_LINK_STAT_CHNG_IRQ_EN; + else + regval &= ~ADIN_LINK_STAT_CHNG_IRQ_EN; + + ret = phy_write_mmd(phydev, MDIO_MMD_VEND2, + ADIN_PHY_SUBSYS_IRQ_MASK, + regval); + return ret; +} + +static irqreturn_t adin_phy_handle_interrupt(struct phy_device *phydev) +{ + int irq_status; + + irq_status = phy_read_mmd(phydev, MDIO_MMD_VEND2, + ADIN_PHY_SUBSYS_IRQ_STATUS); + if (irq_status < 0) { + phy_error(phydev); + return IRQ_NONE; + } + + if (!(irq_status & ADIN_LINK_STAT_CHNG)) + return IRQ_NONE; + + phy_trigger_machine(phydev); + + return IRQ_HANDLED; +} + static int adin_set_powerdown_mode(struct phy_device *phydev, bool en) { int ret; @@ -275,6 +334,8 @@ static struct phy_driver adin_driver[] = { .probe = adin_probe, .config_aneg = adin_config_aneg, .read_status = adin_read_status, + .config_intr = adin_config_intr, + .handle_interrupt = adin_phy_handle_interrupt, .set_loopback = adin_set_loopback, .suspend = adin_suspend, .resume = adin_resume,