From patchwork Mon Jan 16 19:37:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Halaney X-Patchwork-Id: 13103626 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C71ABC54EBE for ; Mon, 16 Jan 2023 19:43:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=VfDNTQoTr/JkF65SnKtADMdm0TePhRJBwZsNekG+vjI=; b=zXPhmqGOrg9+Pg /3W5/N3NYkbtEfUFRWeLy9LC6jkUyTtcNnGo4EElaoqy6hMWBDZYsVMQLy5GZ8+6CW1Vq0SJnzyBh Idg00ygkINAxhziZw0Kp3OeCHdcK07FAXcXT3n7TqmXti4bkuJzfOuL97gRagzjkTtPJfuguPQuzw SI9v2y4dDdNSjfdqMD7A41hxlfEw7q1yEnmjwUkOFWm/GjT+NkOmVnpuXuCK6dC75Y5C2YAGfVLQE y4EoEve2V87ck9KLZ0dP5X67BuJTbhruOkVquaCnY9qUww3BdfWqWML5Zp8EC4o0wul09KOWTaRaK bBuITQyCvRKuoCH74+7A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pHVMt-00Btbk-GV; Mon, 16 Jan 2023 19:42:07 +0000 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pHVMp-00BtbJ-LP for linux-arm-kernel@lists.infradead.org; Mon, 16 Jan 2023 19:42:05 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1673898121; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=J03AEUyMs2O4Zc0M/YmOn8FNZhulZOm8FyrWoJOTpuA=; b=N5ARlCMV2gVafOfb22/dkt91eDCjbT/NZmq5Z+jkNbi52mzKg8IsPZ8j8yfPBfDR4wVLsW T1fBRZaBKygKS2Y4WRRdsbqXY3CydUfpMoCY1rXf14IAlrrlyWDgSgSdFVV55kzgBTcMeR 3QY64GXKjL4u7drwmE+NC5cFCIMRBdE= Received: from mail-oo1-f70.google.com (mail-oo1-f70.google.com [209.85.161.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-76-mKyuMu8lNkSABa_pcuIr0g-1; Mon, 16 Jan 2023 14:39:17 -0500 X-MC-Unique: mKyuMu8lNkSABa_pcuIr0g-1 Received: by mail-oo1-f70.google.com with SMTP id k19-20020a4a3113000000b004f52d8ea37cso384209ooa.5 for ; Mon, 16 Jan 2023 11:39:17 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=J03AEUyMs2O4Zc0M/YmOn8FNZhulZOm8FyrWoJOTpuA=; b=YkQZlAw2HX9M56d3DhgsXHzG8sad7UHj9crLd7L++NIagDhUW/z/mzQzZx7vTDPT34 16kB2NSPVktQmu/4Q+8Kal43IAlxLet14Kkm9aRlhJ+jWcpa8gc5LV0kv+A3IwvOJ59R fxpT8lOPhQqCDRiaWSDSg5ew+tl0iU125NANwyGb/sSjOG6mkSQvVxT1kLyLbpEGa3GE BzvnI1Ffu4pvN55OSfcRQJhZvKU3rcxcSU0/bVpY9Sv16Raw2U26MhX2jbzoLCf3wueO Sz2R6oBsjz/nspybL1dTVL/kVRaQSq0ewkQh6L/A5cNP59wyFvlCTxRSNKBFH0aTie0X K+lw== X-Gm-Message-State: AFqh2kp16DEBMrrrhZc/eSVWWsJxnvx1t51p8r3dep/6+Ighkr3f4tiQ 7dhQR/j8aj1LxQg4kwKFvXEPwwETsI/lFBaphNl5FaW5Gsu3JO8LJ0W2LDwYGzWpWHpIUaRwkya 2quljuL2T2hC7Zp3WrEu0dMQbQSfdBDHAqMw= X-Received: by 2002:a05:6830:26d2:b0:684:caea:9c31 with SMTP id m18-20020a05683026d200b00684caea9c31mr118633otu.10.1673897955374; Mon, 16 Jan 2023 11:39:15 -0800 (PST) X-Google-Smtp-Source: AMrXdXsX2N0Apwx3DHeky1VV10IuJQ27Ivl7LmWlww76FSqkIMW9xCKbWrhuMqI/2iSweJvWyX3YtQ== X-Received: by 2002:a05:6830:26d2:b0:684:caea:9c31 with SMTP id m18-20020a05683026d200b00684caea9c31mr118619otu.10.1673897955126; Mon, 16 Jan 2023 11:39:15 -0800 (PST) Received: from halaney-x13s.attlocal.net ([2600:1700:1ff0:d0e0::21]) by smtp.gmail.com with ESMTPSA id o15-20020a9d764f000000b0066b9a6bf3bcsm15234392otl.12.2023.01.16.11.39.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Jan 2023 11:39:14 -0800 (PST) From: Andrew Halaney To: davem@davemloft.net Cc: peppe.cavallaro@st.com, alexandre.torgue@foss.st.com, joabreu@synopsys.com, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, mcoquelin.stm32@gmail.com, richardcochran@gmail.com, netdev@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Andrew Halaney , Ning Cai Subject: [PATCH net] net: stmmac: enable all safety features by default Date: Mon, 16 Jan 2023 13:37:23 -0600 Message-Id: <20230116193722.50360-1-ahalaney@redhat.com> X-Mailer: git-send-email 2.39.0 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230116_114203_820199_7FBB4A79 X-CRM114-Status: GOOD ( 19.71 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org In the original implementation of dwmac5 commit 8bf993a5877e ("net: stmmac: Add support for DWMAC5 and implement Safety Features") all safety features were enabled by default. Later it seems some implementations didn't have support for all the features, so in commit 5ac712dcdfef ("net: stmmac: enable platform specific safety features") the safety_feat_cfg structure was added to the callback and defined for some platforms to selectively enable these safety features. The problem is that only certain platforms were given that software support. If the automotive safety package bit is set in the hardware features register the safety feature callback is called for the platform, and for platforms that didn't get a safety_feat_cfg defined this results in the following NULL pointer dereference: [ 7.933303] Call trace: [ 7.935812] dwmac5_safety_feat_config+0x20/0x170 [stmmac] [ 7.941455] __stmmac_open+0x16c/0x474 [stmmac] [ 7.946117] stmmac_open+0x38/0x70 [stmmac] [ 7.950414] __dev_open+0x100/0x1dc [ 7.954006] __dev_change_flags+0x18c/0x204 [ 7.958297] dev_change_flags+0x24/0x6c [ 7.962237] do_setlink+0x2b8/0xfa4 [ 7.965827] __rtnl_newlink+0x4ec/0x840 [ 7.969766] rtnl_newlink+0x50/0x80 [ 7.973353] rtnetlink_rcv_msg+0x12c/0x374 [ 7.977557] netlink_rcv_skb+0x5c/0x130 [ 7.981500] rtnetlink_rcv+0x18/0x2c [ 7.985172] netlink_unicast+0x2e8/0x340 [ 7.989197] netlink_sendmsg+0x1a8/0x420 [ 7.993222] ____sys_sendmsg+0x218/0x280 [ 7.997249] ___sys_sendmsg+0xac/0x100 [ 8.001103] __sys_sendmsg+0x84/0xe0 [ 8.004776] __arm64_sys_sendmsg+0x24/0x30 [ 8.008983] invoke_syscall+0x48/0x114 [ 8.012840] el0_svc_common.constprop.0+0xcc/0xec [ 8.017665] do_el0_svc+0x38/0xb0 [ 8.021071] el0_svc+0x2c/0x84 [ 8.024212] el0t_64_sync_handler+0xf4/0x120 [ 8.028598] el0t_64_sync+0x190/0x194 Go back to the original behavior, if the automotive safety package is found to be supported in hardware enable all the features unless safety_feat_cfg is passed in saying this particular platform only supports a subset of the features. Fixes: 5ac712dcdfef ("net: stmmac: enable platform specific safety features") Reported-by: Ning Cai Signed-off-by: Andrew Halaney --- I've been working on a newer Qualcomm platform (sa8540p-ride) which has a variant of dwmac5 in it. This patch is something Ning stumbled on when adding some support for it downstream, and has been in my queue as I try and get some support ready for review on list upstream. Since it isn't really related to the particular hardware I decided to pop it on list now. Please let me know if instead of enabling by default (which the original implementation did and is why I went that route) a message like "Safety features detected but not enabled in software" is preferred and platforms are skipped unless they opt-in for enablement. Thanks, Andrew drivers/net/ethernet/stmicro/stmmac/dwmac5.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac5.c b/drivers/net/ethernet/stmicro/stmmac/dwmac5.c index 9c2d40f853ed..413f66017219 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac5.c +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac5.c @@ -186,11 +186,25 @@ static void dwmac5_handle_dma_err(struct net_device *ndev, int dwmac5_safety_feat_config(void __iomem *ioaddr, unsigned int asp, struct stmmac_safety_feature_cfg *safety_feat_cfg) { + struct stmmac_safety_feature_cfg all_safety_feats = { + .tsoee = 1, + .mrxpee = 1, + .mestee = 1, + .mrxee = 1, + .mtxee = 1, + .epsi = 1, + .edpp = 1, + .prtyen = 1, + .tmouten = 1, + }; u32 value; if (!asp) return -EINVAL; + if (!safety_feat_cfg) + safety_feat_cfg = &all_safety_feats; + /* 1. Enable Safety Features */ value = readl(ioaddr + MTL_ECC_CONTROL); value |= MEEAO; /* MTL ECC Error Addr Status Override */