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: 446821 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 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: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: 446820 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 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: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: 446819 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 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) {