From patchwork Mon May 24 09:25:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 12275751 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 67665C47080 for ; Mon, 24 May 2021 09:25:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 454F3611EE for ; Mon, 24 May 2021 09:25:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232494AbhEXJ1H (ORCPT ); Mon, 24 May 2021 05:27:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48152 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232397AbhEXJ1E (ORCPT ); Mon, 24 May 2021 05:27:04 -0400 Received: from mail-ej1-x629.google.com (mail-ej1-x629.google.com [IPv6:2a00:1450:4864:20::629]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 676DDC061756 for ; Mon, 24 May 2021 02:25:36 -0700 (PDT) Received: by mail-ej1-x629.google.com with SMTP id f18so10556705ejq.10 for ; Mon, 24 May 2021 02:25:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=gsjOsAbLjC1aLaqOCkLQq0Rt/VoD2lZoL8JXtd1CnAE=; b=AKFe5GxU4uUGKfB/O8+7cPTjlHa/9jQbwgP0m+hq4zNkTsRe/TuneNnMBG7FEwv8rF q1rdu9hUkD+ig1fvhk2yMnxUMTJa/mOYmr+eYhsl4gEJmr+8VcHMWDLyV0NJ2AS6WRwj HufmGE/3P8tGaeJKSpjl6mNcc02D/MjyWz7CrSif7Py2vBUy44HfCT5ZlSNUQgHwyPvc Aw3opAKcXafFETWBIgoTr31MXOIYpnUacgi7B2tIieX6EXX8rZxFnB037mV8ZlUEf2KK 7pQ0S0FNCBdrABT0lGXg2JTJk8Bb24xG4dYdmJte8enyalMZBlNbqc9W3nLTIe2pn9yG Fi0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=gsjOsAbLjC1aLaqOCkLQq0Rt/VoD2lZoL8JXtd1CnAE=; b=MKd08bLj/He/fK49AgT1J6X56JOG2+GY8zuDQE4qGyVwflz5OuxzSAgnQG/sITblPb bIqOIBvbjBrvRepdDly6DS6IpsuPL+8JUquV3sV5ZYpou4LqFDDabT49l2dj19qoDMn8 A2NwYlVpqY9E2bCxVVTMpOJxmu/AhvQ9Ij6ansf/vI7qolujt6T9/zBY5tu7xx4VrOAa FRsFSTDCAIi+02l+Yubts7IUA/5LH7qdnZHj8B3Rzq3Ec3KK8JSRtw2FqV1KigTwvjcQ 7Oy0zWq5PsbTUb8KFKlHCRrcvOiSqBuTzBxZQ8XEnq+hmo82iLuz0Yi8mNN0CKCK0xfl 65+g== X-Gm-Message-State: AOAM533ZiIDT7jpk1e7Ay8ctQuarlpRlto3XmnGC8GhDxlr5dqAMpqnX zzsilWnKW60ujbIQZgrlNWA= X-Google-Smtp-Source: ABdhPJyAohoTi/mGveqqmTaweC4jVUWS4TJoEWSbEFYutkoxxNuw2FTI0v7qhcRtrI9kiL6EDnaLgw== X-Received: by 2002:a17:906:4ece:: with SMTP id i14mr21713601ejv.249.1621848334941; Mon, 24 May 2021 02:25:34 -0700 (PDT) Received: from localhost.localdomain ([188.26.52.84]) by smtp.gmail.com with ESMTPSA id yw9sm7553007ejb.91.2021.05.24.02.25.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 May 2021 02:25:34 -0700 (PDT) From: Vladimir Oltean To: Jakub Kicinski , "David S. Miller" , netdev@vger.kernel.org Cc: Florian Fainelli , Andrew Lunn , Vivien Didelot , Vladimir Oltean Subject: [PATCH net 1/6] net: dsa: sja1105: fix VL lookup command packing for P/Q/R/S Date: Mon, 24 May 2021 12:25:22 +0300 Message-Id: <20210524092527.874479-2-olteanv@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210524092527.874479-1-olteanv@gmail.com> References: <20210524092527.874479-1-olteanv@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Vladimir Oltean At the beginning of the sja1105_dynamic_config.c file there is a diagram of the dynamic config interface layout: packed_buf | V +-----------------------------------------+------------------+ | ENTRY BUFFER | COMMAND BUFFER | +-----------------------------------------+------------------+ <----------------------- packed_size ------------------------> So in order to pack/unpack the command bits into the buffer, sja1105_vl_lookup_cmd_packing must first advance the buffer pointer by the length of the entry. This is similar to what the other *cmd_packing functions do. This bug exists because the command packing function for P/Q/R/S was copied from the E/T generation, and on E/T, the command was actually embedded within the entry buffer itself. Fixes: 94f94d4acfb2 ("net: dsa: sja1105: add static tables for virtual links") Signed-off-by: Vladimir Oltean --- .../net/dsa/sja1105/sja1105_dynamic_config.c | 23 +++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/drivers/net/dsa/sja1105/sja1105_dynamic_config.c b/drivers/net/dsa/sja1105/sja1105_dynamic_config.c index b777d3f37573..12cd04b56803 100644 --- a/drivers/net/dsa/sja1105/sja1105_dynamic_config.c +++ b/drivers/net/dsa/sja1105/sja1105_dynamic_config.c @@ -167,9 +167,10 @@ enum sja1105_hostcmd { SJA1105_HOSTCMD_INVALIDATE = 4, }; +/* Command and entry overlap */ static void -sja1105_vl_lookup_cmd_packing(void *buf, struct sja1105_dyn_cmd *cmd, - enum packing_op op) +sja1105et_vl_lookup_cmd_packing(void *buf, struct sja1105_dyn_cmd *cmd, + enum packing_op op) { const int size = SJA1105_SIZE_DYN_CMD; @@ -179,6 +180,20 @@ sja1105_vl_lookup_cmd_packing(void *buf, struct sja1105_dyn_cmd *cmd, sja1105_packing(buf, &cmd->index, 9, 0, size, op); } +/* Command and entry are separate */ +static void +sja1105pqrs_vl_lookup_cmd_packing(void *buf, struct sja1105_dyn_cmd *cmd, + enum packing_op op) +{ + u8 *p = buf + SJA1105_SIZE_VL_LOOKUP_ENTRY; + const int size = SJA1105_SIZE_DYN_CMD; + + sja1105_packing(p, &cmd->valid, 31, 31, size, op); + sja1105_packing(p, &cmd->errors, 30, 30, size, op); + sja1105_packing(p, &cmd->rdwrset, 29, 29, size, op); + sja1105_packing(p, &cmd->index, 9, 0, size, op); +} + static size_t sja1105et_vl_lookup_entry_packing(void *buf, void *entry_ptr, enum packing_op op) { @@ -641,7 +656,7 @@ static size_t sja1105pqrs_cbs_entry_packing(void *buf, void *entry_ptr, const struct sja1105_dynamic_table_ops sja1105et_dyn_ops[BLK_IDX_MAX_DYN] = { [BLK_IDX_VL_LOOKUP] = { .entry_packing = sja1105et_vl_lookup_entry_packing, - .cmd_packing = sja1105_vl_lookup_cmd_packing, + .cmd_packing = sja1105et_vl_lookup_cmd_packing, .access = OP_WRITE, .max_entry_count = SJA1105_MAX_VL_LOOKUP_COUNT, .packed_size = SJA1105ET_SIZE_VL_LOOKUP_DYN_CMD, @@ -725,7 +740,7 @@ const struct sja1105_dynamic_table_ops sja1105et_dyn_ops[BLK_IDX_MAX_DYN] = { const struct sja1105_dynamic_table_ops sja1105pqrs_dyn_ops[BLK_IDX_MAX_DYN] = { [BLK_IDX_VL_LOOKUP] = { .entry_packing = sja1105_vl_lookup_entry_packing, - .cmd_packing = sja1105_vl_lookup_cmd_packing, + .cmd_packing = sja1105pqrs_vl_lookup_cmd_packing, .access = (OP_READ | OP_WRITE), .max_entry_count = SJA1105_MAX_VL_LOOKUP_COUNT, .packed_size = SJA1105PQRS_SIZE_VL_LOOKUP_DYN_CMD, From patchwork Mon May 24 09:25:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 12275753 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8F3F4C47085 for ; Mon, 24 May 2021 09:25:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 74C9D6108E for ; Mon, 24 May 2021 09:25:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232508AbhEXJ1I (ORCPT ); Mon, 24 May 2021 05:27:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48158 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232471AbhEXJ1F (ORCPT ); Mon, 24 May 2021 05:27:05 -0400 Received: from mail-ed1-x52e.google.com (mail-ed1-x52e.google.com [IPv6:2a00:1450:4864:20::52e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 291D1C06138A for ; Mon, 24 May 2021 02:25:37 -0700 (PDT) Received: by mail-ed1-x52e.google.com with SMTP id r11so31048948edt.13 for ; Mon, 24 May 2021 02:25:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=rR70am4AsqwLDccH8qea+nzFbDBLYY7dCPQZwgCCRog=; b=sGZAdbyHGB9VNwTHW8rZTswNfkIq/6R3lWabD1lJiEmJNSB6SfjjKKjQK083gHIGvO sAcTjwZSlMtNb2qmms2AVmmoXveSvSlsiENnVY7tnDot5jI6iff2siu4T041GuAtluHX A5tj9sV5bGN+xT+pFMsJXFe9p0u07DvPbLIRsqk87sIO99Fjase24Tzd0dpy07i5bdKX pfXzDCwIpaUMjPWmPOVFkK7LKSBVrobBRE+iDPqqZ+LGEx6iiq5xyJFSp30xwOto1ezM zLGDkT5fYppFPZtqnXv1Kke0Ovz7s+RUqhy8azOR0HpPQZIbuDlKcnR/DIGsGvruOsfa g5uA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=rR70am4AsqwLDccH8qea+nzFbDBLYY7dCPQZwgCCRog=; b=NTuoPDHqDcIl86EkE5r9GEseccoSY+Ob0mTFVT7cm2nZe34GRWLmgi/1Y9gUKXr7WK PREUXCOj2+OhyGHEz2p6eUWHCyRvDsF2wHkiv+mm91Qtr/HqErxUubHF96HSS7vbnwT4 EFy5PVQs4BbC953N6fxq5WKLmUZKb0FksljULfKT7cFo1Dtk7SS2ad6bgWg0cLWwS6j1 ito083oCrdSssXECLuEFuhp4xDzdYqbJeK1hLtiTKU0NQeujSLzXj3T/hVDX39IIJeDo Ftb89ehxT4RDPsfiJfH1MufCIgjXD1E2HRUv1H6FMPZkstOGXf8+opWbS3UmJgU92JVZ oASw== X-Gm-Message-State: AOAM5326WjrCppqFt9bYbg4ZWbiFf6f3JD+vfuqLMOSfGqUZjM8jGy9R BWR4DePGO7o2tRt8BOXml34= X-Google-Smtp-Source: ABdhPJwEeVcj0yJz5NFAbLcqFMQndKekz2CtYGlOCO7N9K8k1M17K98cRGKTybnzCVUBspZ+MdLX5A== X-Received: by 2002:aa7:db48:: with SMTP id n8mr24744817edt.11.1621848335730; Mon, 24 May 2021 02:25:35 -0700 (PDT) Received: from localhost.localdomain ([188.26.52.84]) by smtp.gmail.com with ESMTPSA id yw9sm7553007ejb.91.2021.05.24.02.25.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 May 2021 02:25:35 -0700 (PDT) From: Vladimir Oltean To: Jakub Kicinski , "David S. Miller" , netdev@vger.kernel.org Cc: Florian Fainelli , Andrew Lunn , Vivien Didelot , Vladimir Oltean Subject: [PATCH net 2/6] net: dsa: sja1105: call dsa_unregister_switch when allocating memory fails Date: Mon, 24 May 2021 12:25:23 +0300 Message-Id: <20210524092527.874479-3-olteanv@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210524092527.874479-1-olteanv@gmail.com> References: <20210524092527.874479-1-olteanv@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Vladimir Oltean Unlike other drivers which pretty much end their .probe() execution with dsa_register_switch(), the sja1105 does some extra stuff. When that fails with -ENOMEM, the driver is quick to return that, forgetting to call dsa_unregister_switch(). Not critical, but a bug nonetheless. Fixes: 4d7525085a9b ("net: dsa: sja1105: offload the Credit-Based Shaper qdisc") Fixes: a68578c20a96 ("net: dsa: Make deferred_xmit private to sja1105") Signed-off-by: Vladimir Oltean --- drivers/net/dsa/sja1105/sja1105_main.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/drivers/net/dsa/sja1105/sja1105_main.c b/drivers/net/dsa/sja1105/sja1105_main.c index 405024b637d6..2248152b4836 100644 --- a/drivers/net/dsa/sja1105/sja1105_main.c +++ b/drivers/net/dsa/sja1105/sja1105_main.c @@ -3646,8 +3646,10 @@ static int sja1105_probe(struct spi_device *spi) priv->cbs = devm_kcalloc(dev, priv->info->num_cbs_shapers, sizeof(struct sja1105_cbs_entry), GFP_KERNEL); - if (!priv->cbs) - return -ENOMEM; + if (!priv->cbs) { + rc = -ENOMEM; + goto out_unregister_switch; + } } /* Connections between dsa_port and sja1105_port */ @@ -3672,7 +3674,7 @@ static int sja1105_probe(struct spi_device *spi) dev_err(ds->dev, "failed to create deferred xmit thread: %d\n", rc); - goto out; + goto out_destroy_workers; } skb_queue_head_init(&sp->xmit_queue); sp->xmit_tpid = ETH_P_SJA1105; @@ -3682,7 +3684,8 @@ static int sja1105_probe(struct spi_device *spi) } return 0; -out: + +out_destroy_workers: while (port-- > 0) { struct sja1105_port *sp = &priv->ports[port]; @@ -3691,6 +3694,10 @@ static int sja1105_probe(struct spi_device *spi) kthread_destroy_worker(sp->xmit_worker); } + +out_unregister_switch: + dsa_unregister_switch(ds); + return rc; } From patchwork Mon May 24 09:25:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 12275755 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DB174C04FF3 for ; Mon, 24 May 2021 09:25:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C05A0610C7 for ; Mon, 24 May 2021 09:25:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232513AbhEXJ1J (ORCPT ); Mon, 24 May 2021 05:27:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48168 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232318AbhEXJ1G (ORCPT ); Mon, 24 May 2021 05:27:06 -0400 Received: from mail-ej1-x631.google.com (mail-ej1-x631.google.com [IPv6:2a00:1450:4864:20::631]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EA8FCC061574 for ; Mon, 24 May 2021 02:25:37 -0700 (PDT) Received: by mail-ej1-x631.google.com with SMTP id et19so33691186ejc.4 for ; Mon, 24 May 2021 02:25:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=dXdt+KKKz9LU9KAG5nwot0k8iUG/uKRaRkjTzG5fIyM=; b=n++zvDNw0imYM5zA/E0v+hJfiP2gs64UQMAjm763xmO+HgOjn73w0L0kJwZJGA1L10 a5zxyKpxGbcePR5qc8spNoNQsgU8qqj7mG4bPGab9y0JVv23tA/Obf6+tSSJvCQDAMhz caUekjNXa09FCUXdbteG9iqzoqMvf6ZFB4Ujy+wQV4Pl8mNEuzcvdSAnYPyQUdbl9I2s qoRlrcXtsDLhcTnvh9GbDS+cUz4p571H8a52r9dFUV3RLOttlnygTmUOVQgWlWpAjh9S USL/NqwpWrmIGKpVRD40CfuCl9ogLXK2F5Oz8+3uKUxiOzWlpE4i5UQn8ibGU8oenS9/ uvEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=dXdt+KKKz9LU9KAG5nwot0k8iUG/uKRaRkjTzG5fIyM=; b=tlnUNxIt0v8Vs8Mk0/PMs0ZlenVehB8xKuxlg7jG+xKxuzySjoiexPL5fPte/csqQN WNVm6q3GuzqcTdtN0NCGYhKU/5kQH2GaGyz9eh5fIKLVgRtWFQhneVdCgISprdvKZGUY g7TPWeJqH0F48xwdzHD69AfNQmUk0Nki+ptd66iK1YyOkKh8bJ71n/T8Jx3Fefgjf+k4 PX/tH8QPzifbkomCy8GrSLExOkOelX4z0duxj9dc4iof1qzd7SR6ZwCd9QQx/q3Dl41U J30TyvRapROkMVkL7NL6v4y8vOPaQCniru7dkEvyXy9n7qWv4XejXK8POczQYQDbnYic qnUg== X-Gm-Message-State: AOAM533OBXO0Oy73g5DREDiGMRvB/8xomhUZ33hK0nCKbnSxOlSoUXUf DFrvUwN1hdt/gEQsMUZJ8qM118P+JSk= X-Google-Smtp-Source: ABdhPJwahzpBW5Cdas4VuQByTnyF27xcqAZQPT6m6uhjQf1ng5+6vI6iuF9WjJYLUZ8rI4/kNw9cNw== X-Received: by 2002:a17:906:c1d2:: with SMTP id bw18mr22281800ejb.123.1621848336547; Mon, 24 May 2021 02:25:36 -0700 (PDT) Received: from localhost.localdomain ([188.26.52.84]) by smtp.gmail.com with ESMTPSA id yw9sm7553007ejb.91.2021.05.24.02.25.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 May 2021 02:25:36 -0700 (PDT) From: Vladimir Oltean To: Jakub Kicinski , "David S. Miller" , netdev@vger.kernel.org Cc: Florian Fainelli , Andrew Lunn , Vivien Didelot , Vladimir Oltean Subject: [PATCH net 3/6] net: dsa: sja1105: add error handling in sja1105_setup() Date: Mon, 24 May 2021 12:25:24 +0300 Message-Id: <20210524092527.874479-4-olteanv@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210524092527.874479-1-olteanv@gmail.com> References: <20210524092527.874479-1-olteanv@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Vladimir Oltean If any of sja1105_static_config_load(), sja1105_clocking_setup() or sja1105_devlink_setup() fails, we can't just return in the middle of sja1105_setup() or memory will leak. Add a cleanup path. Fixes: 0a7bdbc23d8a ("net: dsa: sja1105: move devlink param code to sja1105_devlink.c") Fixes: 8aa9ebccae87 ("net: dsa: Introduce driver for NXP SJA1105 5-port L2 switch") Signed-off-by: Vladimir Oltean --- drivers/net/dsa/sja1105/sja1105_main.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/drivers/net/dsa/sja1105/sja1105_main.c b/drivers/net/dsa/sja1105/sja1105_main.c index 2248152b4836..c7a1be8bbddf 100644 --- a/drivers/net/dsa/sja1105/sja1105_main.c +++ b/drivers/net/dsa/sja1105/sja1105_main.c @@ -2976,13 +2976,13 @@ static int sja1105_setup(struct dsa_switch *ds) rc = sja1105_static_config_load(priv, ports); if (rc < 0) { dev_err(ds->dev, "Failed to load static config: %d\n", rc); - return rc; + goto out_ptp_clock_unregister; } /* Configure the CGU (PHY link modes and speeds) */ rc = sja1105_clocking_setup(priv); if (rc < 0) { dev_err(ds->dev, "Failed to configure MII clocking: %d\n", rc); - return rc; + goto out_static_config_free; } /* On SJA1105, VLAN filtering per se is always enabled in hardware. * The only thing we can do to disable it is lie about what the 802.1Q @@ -3003,7 +3003,7 @@ static int sja1105_setup(struct dsa_switch *ds) rc = sja1105_devlink_setup(ds); if (rc < 0) - return rc; + goto out_static_config_free; /* The DSA/switchdev model brings up switch ports in standalone mode by * default, and that means vlan_filtering is 0 since they're not under @@ -3012,6 +3012,17 @@ static int sja1105_setup(struct dsa_switch *ds) rtnl_lock(); rc = sja1105_setup_8021q_tagging(ds, true); rtnl_unlock(); + if (rc) + goto out_devlink_teardown; + + return 0; + +out_devlink_teardown: + sja1105_devlink_teardown(ds); +out_ptp_clock_unregister: + sja1105_ptp_clock_unregister(ds); +out_static_config_free: + sja1105_static_config_free(&priv->static_config); return rc; } From patchwork Mon May 24 09:25:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 12275757 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 09E83C47080 for ; Mon, 24 May 2021 09:25:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D7C8C610C7 for ; Mon, 24 May 2021 09:25:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232318AbhEXJ1L (ORCPT ); Mon, 24 May 2021 05:27:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48172 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232493AbhEXJ1H (ORCPT ); Mon, 24 May 2021 05:27:07 -0400 Received: from mail-ej1-x631.google.com (mail-ej1-x631.google.com [IPv6:2a00:1450:4864:20::631]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B39C0C061756 for ; Mon, 24 May 2021 02:25:38 -0700 (PDT) Received: by mail-ej1-x631.google.com with SMTP id lz27so40717881ejb.11 for ; Mon, 24 May 2021 02:25:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ZJiSmhLNmHbbXW7xoiDmjsjrpJavH5ubtWmLGqLBR4M=; b=BXB7VRudEzI8UO/b+QQvqiGAJad1C7KkxGFts0Z0VsU7mJfHSsFZx+g9s2RKYScyuU yfmqPNyUU1IlPE9IpINEpSAyWYl+HeemPJ0kbRnYUZvVEXUktPPNlo9pV5amzJVoTROo vAMsWya7n1BSEHw+vtxnDFF3dwqJMZ/H0yUrvRAWxQzKM/AIfOZ9pYNdLVI5aZ0XmwFJ ZtiPZbKv1APSPZn8lp07PAxVLP0+dwwHU38axJp0hzbAWNFzPevsPG1fsYZEt+eduq0M nifbtlVig5bcw1Y/2wKOLD6kgjLiojHmhFTSxrFUqAGt1SNGWtlIt5sXNxZpMn5kbckW EjDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ZJiSmhLNmHbbXW7xoiDmjsjrpJavH5ubtWmLGqLBR4M=; b=hh9qdNyRyrYuDiwNtaqByF5YTkoKwu+ais3Ty6wW0cUEJP8G7nMWCLHu5L0OFHM9FD G1zg18XqUMYdTWNg7ebDpMcB/AkVsOiiMFsu1FOKeGtfH8YRMYW6sTo7GMt+LI28LkTf Vz3scuhgSI4Ffh4Uq5kPmoTXTJy+9rVVR6oUAmmUSTdbPUK1qa9Z29ddVSNJImsNIHmT zTWkA1iFasek8dCfAOJjpK2zdZYYcZOcrv1DGVCQjq9EYVe1xSvndKsQma339uOTqo1k 6XCx7BSODZyV/p1/wc2zMEAyeQjLkMW8124i7ltmieHAyMt1KcoJeEZkumYqAd+oNM4H cnnA== X-Gm-Message-State: AOAM533Qp7uZYAth87eNyYG6xxwF4Dp4d+EsvnFDLBtYsqZceY7CzIi1 WrHi9qsIiJODT1a7nxMo2CDvMPMx9VM= X-Google-Smtp-Source: ABdhPJw8Bj+cxbMuVonpAP/Rrj5T/eXsUpcRXKoppvvdpvOpFJorXvZrqe2rZj2dt1UstjljscGvqw== X-Received: by 2002:a17:906:1806:: with SMTP id v6mr2392787eje.454.1621848337375; Mon, 24 May 2021 02:25:37 -0700 (PDT) Received: from localhost.localdomain ([188.26.52.84]) by smtp.gmail.com with ESMTPSA id yw9sm7553007ejb.91.2021.05.24.02.25.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 May 2021 02:25:37 -0700 (PDT) From: Vladimir Oltean To: Jakub Kicinski , "David S. Miller" , netdev@vger.kernel.org Cc: Florian Fainelli , Andrew Lunn , Vivien Didelot , Vladimir Oltean Subject: [PATCH net 4/6] net: dsa: sja1105: error out on unsupported PHY mode Date: Mon, 24 May 2021 12:25:25 +0300 Message-Id: <20210524092527.874479-5-olteanv@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210524092527.874479-1-olteanv@gmail.com> References: <20210524092527.874479-1-olteanv@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Vladimir Oltean The driver continues probing when a port is configured for an unsupported PHY interface type, instead it should stop. Fixes: 8aa9ebccae87 ("net: dsa: Introduce driver for NXP SJA1105 5-port L2 switch") Signed-off-by: Vladimir Oltean --- drivers/net/dsa/sja1105/sja1105_main.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/net/dsa/sja1105/sja1105_main.c b/drivers/net/dsa/sja1105/sja1105_main.c index c7a1be8bbddf..7f7e0424a442 100644 --- a/drivers/net/dsa/sja1105/sja1105_main.c +++ b/drivers/net/dsa/sja1105/sja1105_main.c @@ -207,6 +207,7 @@ static int sja1105_init_mii_settings(struct sja1105_private *priv, default: dev_err(dev, "Unsupported PHY mode %s!\n", phy_modes(ports[i].phy_mode)); + return -EINVAL; } /* Even though the SerDes port is able to drive SGMII autoneg From patchwork Mon May 24 09:25:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 12275761 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AE071C47080 for ; Mon, 24 May 2021 09:25:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 91148610C7 for ; Mon, 24 May 2021 09:25:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232517AbhEXJ1P (ORCPT ); Mon, 24 May 2021 05:27:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48178 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232506AbhEXJ1I (ORCPT ); Mon, 24 May 2021 05:27:08 -0400 Received: from mail-ed1-x52c.google.com (mail-ed1-x52c.google.com [IPv6:2a00:1450:4864:20::52c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A7AF3C061574 for ; Mon, 24 May 2021 02:25:39 -0700 (PDT) Received: by mail-ed1-x52c.google.com with SMTP id y7so13596182eda.2 for ; Mon, 24 May 2021 02:25:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=kPM2Bmxiyg1VQQ11mVmf4X94gf6YVjwYR2FU4cIFRQk=; b=NkAYdO5/I4LgIpliRzgp1KWtB9mukcxewLTjJJ3RQNOB7so/U1qSqnd3OP3Fi0D+/T EGOWp7CFqLHPOp75JtOMeN8C4prnituSPf+9Vm5JgiSv3N6xQL4ryObIs23oIVLHvAnx LUJE/9SUP2z7TWoaBr83xzlm50G1YpAW9BPUmJjVUtH6kAELpgYpDefA7NzLEgNxk/Kl UF/MAHh60e8VlAoOaSSsqdhhnJ8/I/XGgx90q6cyoL8ky5GfQsTb6Iv4dLlfEA3LVmLW 3VE9YdUjpLObHXxHPG/JaGbpHgSfHxbTx7Wt4pawsS5SZnspPVRgp1dXvWD+Ka/DfcD7 S/Ow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=kPM2Bmxiyg1VQQ11mVmf4X94gf6YVjwYR2FU4cIFRQk=; b=nxJWHA59FijWTQP+z3tbcutHejkirCN8peRH02IAEC8es7vvgZrMd1DY4zEv93/J0d 5xlWOHzZu+w+0scM6lPxlfaDUJ9hb7ZU8R4/lEU7pWQGTJg3OH5/otNzoXeBDC5qSY3a p5y+kyN20eM1tcVgUHT/85K8t7BPhrJ2reiKoPyzrJgTCYTDQO72zSNWQyGEo1M+ph2l dDaImpN2lE1+Z4BC9JAYV/h7XuWCvyMHuoSSTIHfrhQLOEXa7avggU5DpoOEOnyTRISy pxZBFXZ4Hi01Yb5vrv5BeYQCGnJ24s7fnjFQyYj6rb3Miema0H3aRhVg7hpxsj+aC63W Pi7A== X-Gm-Message-State: AOAM533LsnJKoRmNuRkcZ1B2FeXLtmsRUhaf2JqHmq5phi2vKckHGizL RAW453c001XZyKby/yZ4H5g= X-Google-Smtp-Source: ABdhPJzSHEseBlY56XvL6qwNhMRDxnvb+hgXBlgEym64d4XOWBDiIEuA3NDapZb2x+bDXwoepifudg== X-Received: by 2002:aa7:d413:: with SMTP id z19mr24717307edq.37.1621848338190; Mon, 24 May 2021 02:25:38 -0700 (PDT) Received: from localhost.localdomain ([188.26.52.84]) by smtp.gmail.com with ESMTPSA id yw9sm7553007ejb.91.2021.05.24.02.25.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 May 2021 02:25:37 -0700 (PDT) From: Vladimir Oltean To: Jakub Kicinski , "David S. Miller" , netdev@vger.kernel.org Cc: Florian Fainelli , Andrew Lunn , Vivien Didelot , Vladimir Oltean Subject: [PATCH net 5/6] net: dsa: sja1105: use 4095 as the private VLAN for untagged traffic Date: Mon, 24 May 2021 12:25:26 +0300 Message-Id: <20210524092527.874479-6-olteanv@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210524092527.874479-1-olteanv@gmail.com> References: <20210524092527.874479-1-olteanv@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Vladimir Oltean One thing became visible when writing the blamed commit, and that was that STP and PTP frames injected by net/dsa/tag_sja1105.c using the deferred xmit mechanism are always classified to the pvid of the CPU port, regardless of whatever VLAN there might be in these packets. So a decision needed to be taken regarding the mechanism through which we should ensure that delivery of STP and PTP traffic is possible when we are in a VLAN awareness mode that involves tag_8021q. This is because tag_8021q is not concerned with managing the pvid of the CPU port, since as far as tag_8021q is concerned, no traffic should be sent as untagged from the CPU port. So we end up not actually having a pvid on the CPU port if we only listen to tag_8021q, and unless we do something about it. The decision taken at the time was to keep VLAN 1 in the list of priv->dsa_8021q_vlans, and make it a pvid of the CPU port. This ensures that STP and PTP frames can always be sent to the outside world. However there is a problem. If we do the following while we are in the best_effort_vlan_filtering=true mode: ip link add br0 type bridge vlan_filtering 1 ip link set swp2 master br0 bridge vlan del dev swp2 vid 1 Then untagged and pvid-tagged frames should be dropped. But we observe that they aren't, and this is because of the precaution we took that VID 1 is always installed on all ports. So clearly VLAN 1 is not good for this purpose. What about VLAN 0? Well, VLAN 0 is managed by the 8021q module, and that module wants to ensure that 802.1p tagged frames are always received by a port, and are always transmitted as VLAN-tagged (with VLAN ID 0). Whereas we want our STP and PTP frames to be untagged if the stack sent them as untagged - we don't want the driver to just decide out of the blue that it adds VID 0 to some packets. So what to do? Well, there is one other VLAN that is reserved, and that is 4095: $ ip link add link swp2 name swp2.4095 type vlan id 4095 Error: 8021q: Invalid VLAN id. $ bridge vlan add dev swp2 vid 4095 Error: bridge: Vlan id is invalid. After we made this change, VLAN 1 is indeed forwarded and/or dropped according to the bridge VLAN table, there are no further alterations done by the sja1105 driver. Fixes: ec5ae61076d0 ("net: dsa: sja1105: save/restore VLANs using a delta commit method") Signed-off-by: Vladimir Oltean --- drivers/net/dsa/sja1105/sja1105_main.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/drivers/net/dsa/sja1105/sja1105_main.c b/drivers/net/dsa/sja1105/sja1105_main.c index 7f7e0424a442..dffa7dd83877 100644 --- a/drivers/net/dsa/sja1105/sja1105_main.c +++ b/drivers/net/dsa/sja1105/sja1105_main.c @@ -26,6 +26,7 @@ #include "sja1105_tas.h" #define SJA1105_UNKNOWN_MULTICAST 0x010000000000ull +#define SJA1105_DEFAULT_VLAN (VLAN_N_VID - 1) static const struct dsa_switch_ops sja1105_switch_ops; @@ -322,6 +323,13 @@ static int sja1105_init_l2_lookup_params(struct sja1105_private *priv) return 0; } +/* Set up a default VLAN for untagged traffic injected from the CPU + * using management routes (e.g. STP, PTP) as opposed to tag_8021q. + * All DT-defined ports are members of this VLAN, and there are no + * restrictions on forwarding (since the CPU selects the destination). + * Frames from this VLAN will always be transmitted as untagged, and + * neither the bridge nor the 8021q module cannot create this VLAN ID. + */ static int sja1105_init_static_vlan(struct sja1105_private *priv) { struct sja1105_table *table; @@ -331,17 +339,13 @@ static int sja1105_init_static_vlan(struct sja1105_private *priv) .vmemb_port = 0, .vlan_bc = 0, .tag_port = 0, - .vlanid = 1, + .vlanid = SJA1105_DEFAULT_VLAN, }; struct dsa_switch *ds = priv->ds; int port; table = &priv->static_config.tables[BLK_IDX_VLAN_LOOKUP]; - /* The static VLAN table will only contain the initial pvid of 1. - * All other VLANs are to be configured through dynamic entries, - * and kept in the static configuration table as backing memory. - */ if (table->entry_count) { kfree(table->entries); table->entry_count = 0; @@ -354,9 +358,6 @@ static int sja1105_init_static_vlan(struct sja1105_private *priv) table->entry_count = 1; - /* VLAN 1: all DT-defined ports are members; no restrictions on - * forwarding; always transmit as untagged. - */ for (port = 0; port < ds->num_ports; port++) { struct sja1105_bridge_vlan *v; @@ -367,15 +368,12 @@ static int sja1105_init_static_vlan(struct sja1105_private *priv) pvid.vlan_bc |= BIT(port); pvid.tag_port &= ~BIT(port); - /* Let traffic that don't need dsa_8021q (e.g. STP, PTP) be - * transmitted as untagged. - */ v = kzalloc(sizeof(*v), GFP_KERNEL); if (!v) return -ENOMEM; v->port = port; - v->vid = 1; + v->vid = SJA1105_DEFAULT_VLAN; v->untagged = true; if (dsa_is_cpu_port(ds, port)) v->pvid = true; From patchwork Mon May 24 09:25:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 12275759 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C8859C04FF3 for ; Mon, 24 May 2021 09:25:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AF11B610C7 for ; Mon, 24 May 2021 09:25:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232526AbhEXJ1N (ORCPT ); Mon, 24 May 2021 05:27:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48180 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232503AbhEXJ1I (ORCPT ); Mon, 24 May 2021 05:27:08 -0400 Received: from mail-ej1-x630.google.com (mail-ej1-x630.google.com [IPv6:2a00:1450:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5A2DCC06138A for ; Mon, 24 May 2021 02:25:40 -0700 (PDT) Received: by mail-ej1-x630.google.com with SMTP id lg14so40690727ejb.9 for ; Mon, 24 May 2021 02:25:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=9Ey66oyG3NLGwflZVAOjkSfU7hIbefDDtCAF1NvM2ck=; b=d17aT1kqJ5Wpa76U4u/5AmjIzEfOg136c6j2GVeD6BAjhXpmhxt/vzEqU2oxsTgDlX g38yhPJKG5vnxvh9OU04AiVe5vWyYNWYP7qNyHW7bWtw535Umtz8mrlYqViw3A7kR14d c+HiTxxRR4hEUV7iv3e8Pbom++3AA/atDNKT+y3aCxpRsZ9SVDjUAngKnx/461aIUZX4 OpYyhxhQ3muEbE+DF1rNvfhY7X9ui4Qi5lc3iRx1IQC+ADGGYRW2Mt8VQbvuu6XQ5CLh 50WCJg69H5eb8Hu0XMTg00k9FeYTpdUYiOF5SHqYBi2DnulujibnjjFX1IEdCAPNxM2I QD2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=9Ey66oyG3NLGwflZVAOjkSfU7hIbefDDtCAF1NvM2ck=; b=jlhnthspWQlhArrLpa8ScGcanOxVrHASglGRMVwjyE1jna5Qk/MaThshtVpMo318Ba HlQXzh/RsnLqJmUFNoL3uXMuDLz+xrOGLkeOu9agMp0UHG7YUn3U3RQ+tAWHHv0PA/vj R87kriagk+3v4hdpzTc1Eozpc3AxHZ0JgIW1KGTSsH/Zmu/idnhrssE2p1IPZ8i1Osr2 3hSm8rrbt12ILOb+TJtqxPOQyEHzRgP8VvWJvN7gOd9y4TMN16tShQPPguKD0U4lCl3h dazT7muUX/um0cNa3rTaxPBDyS7RWOoIZp8YTjtX1JXlvVlYPHbFdjSNtVgbRrACND55 lbSg== X-Gm-Message-State: AOAM531Ga8eQPWUo0mUHYNvXJa1zdIvP6sOShasABr0XQBIQvG8CMwuh NEZRXltdPG+LK8mPChVUd8E= X-Google-Smtp-Source: ABdhPJxi3fdQctA7c6g9mPXWilbOYvisuRGg952N33yDS7mp57IIWHyn8TbVNIH+7SOi+qbU4cL/ig== X-Received: by 2002:a17:907:161f:: with SMTP id hb31mr5622521ejc.278.1621848338991; Mon, 24 May 2021 02:25:38 -0700 (PDT) Received: from localhost.localdomain ([188.26.52.84]) by smtp.gmail.com with ESMTPSA id yw9sm7553007ejb.91.2021.05.24.02.25.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 May 2021 02:25:38 -0700 (PDT) From: Vladimir Oltean To: Jakub Kicinski , "David S. Miller" , netdev@vger.kernel.org Cc: Florian Fainelli , Andrew Lunn , Vivien Didelot , Vladimir Oltean Subject: [PATCH net 6/6] net: dsa: sja1105: update existing VLANs from the bridge VLAN list Date: Mon, 24 May 2021 12:25:27 +0300 Message-Id: <20210524092527.874479-7-olteanv@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210524092527.874479-1-olteanv@gmail.com> References: <20210524092527.874479-1-olteanv@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Vladimir Oltean When running this sequence of operations: ip link add br0 type bridge vlan_filtering 1 ip link set swp4 master br0 bridge vlan add dev swp4 vid 1 We observe the traffic sent on swp4 is still untagged, even though the bridge has overwritten the existing VLAN entry: port vlan ids swp4 1 PVID br0 1 PVID Egress Untagged This happens because we didn't consider that the 'bridge vlan add' command just overwrites VLANs like it's nothing. We treat the 'vid 1 pvid untagged' and the 'vid 1' as two separate VLANs, and the first still has precedence when calling sja1105_build_vlan_table. Obviously there is a disagreement regarding semantics, and we end up doing something unexpected from the PoV of the bridge. Let's actually consider an "existing VLAN" to be one which is on the same port, and has the same VLAN ID, as one we already have, and update it if it has different flags than we do. The first blamed commit is the one introducing the bug, the second one is the latest on top of which the bugfix still applies. Fixes: ec5ae61076d0 ("net: dsa: sja1105: save/restore VLANs using a delta commit method") Fixes: 5899ee367ab3 ("net: dsa: tag_8021q: add a context structure") Signed-off-by: Vladimir Oltean --- drivers/net/dsa/sja1105/sja1105_main.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/drivers/net/dsa/sja1105/sja1105_main.c b/drivers/net/dsa/sja1105/sja1105_main.c index dffa7dd83877..b88d9ef45a1f 100644 --- a/drivers/net/dsa/sja1105/sja1105_main.c +++ b/drivers/net/dsa/sja1105/sja1105_main.c @@ -2816,11 +2816,22 @@ static int sja1105_vlan_add_one(struct dsa_switch *ds, int port, u16 vid, bool pvid = flags & BRIDGE_VLAN_INFO_PVID; struct sja1105_bridge_vlan *v; - list_for_each_entry(v, vlan_list, list) - if (v->port == port && v->vid == vid && - v->untagged == untagged && v->pvid == pvid) + list_for_each_entry(v, vlan_list, list) { + if (v->port == port && v->vid == vid) { /* Already added */ - return 0; + if (v->untagged == untagged && v->pvid == pvid) + /* Nothing changed */ + return 0; + + /* It's the same VLAN, but some of the flags changed + * and the user did not bother to delete it first. + * Update it and trigger sja1105_build_vlan_table. + */ + v->untagged = untagged; + v->pvid = pvid; + return 1; + } + } v = kzalloc(sizeof(*v), GFP_KERNEL); if (!v) {