From patchwork Tue Sep 12 06:50:53 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 812703 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=resnulli-us.20150623.gappssmtp.com header.i=@resnulli-us.20150623.gappssmtp.com header.b="ZSXFJ+1Y"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3xrwRn07PWz9s7M for ; Tue, 12 Sep 2017 16:51:01 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751317AbdILGu6 (ORCPT ); Tue, 12 Sep 2017 02:50:58 -0400 Received: from mail-wr0-f196.google.com ([209.85.128.196]:37061 "EHLO mail-wr0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751089AbdILGu5 (ORCPT ); Tue, 12 Sep 2017 02:50:57 -0400 Received: by mail-wr0-f196.google.com with SMTP id u48so5406079wrf.4 for ; Mon, 11 Sep 2017 23:50:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=resnulli-us.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id; bh=nE/Vf4W6zQuOO/e41hr1/yEAaJnHtpNenyQZ65ONx9k=; b=ZSXFJ+1YsNArDm81mMm0dfc81T8nBb2cjnZLjOrd2FvuRPA8F0Nn1Zl9mOIQ8Fwy7n YL737uoDEmxV3MXhLVtDk1RqC334kAD06jv87NFO2dO0ay2DD3I3IP8yS39iIl8tAF3d x9Ti3k0UlDUq0PRXW9TD5iis9iJjrIuXQom3qMGocUliRvIe2CGHgq1JrlWJ2k0TVNcX XYT5RnnFxJDQkpzkrzW7vrpcPEIMtHnzPvVfx91y1K5z8Upjv7xMniFzgb08hbz5FEaT t5oSMm67UMNhf53kWzyqXEE4uN4QhelwUZzKrBuEOghjRG1csxM8wRv04jFa1zn7KJhe jlMw== 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; bh=nE/Vf4W6zQuOO/e41hr1/yEAaJnHtpNenyQZ65ONx9k=; b=Oziq4SlcoGtP+tlr4KkzUMKq9jlxzLZhgkHA/kLZIyTozgfIKYmZE6sxlrPAX3tq/9 i994/cuHvmZMK6QApfTi1NofQIMsdSSrKRcyqO4Gs9iNfxGFyiaNYsdFok3/sWG9EhyQ MNOLxWKzRTfIFs0cHeHT+EOZP3bB2dtk7SUz5rqF+dmg6if4D6BQ1BlGvKAt0/V2qIGj E4A4VFUjHDMGHIanQ4vibGt2zjpJ8BhSzrE0duoF5JBfQhGGMXUNi+Og53XgfEtFmWnT DaRo0YvQRhJ6n93YSVB5azvXEsB9o6UJdKQehcgwCirFdUsxYYS6ylGxnKybhCr338la rC/g== X-Gm-Message-State: AHPjjUioc7ZnczkMg4qVwryNW7BJxjMnoyBG24OkuLefED3Kn4/oMrW7 Eqr7yhWrDIQZI/PJxr4= X-Google-Smtp-Source: ADKCNb4+wkejuZxJj7IvhVkPaPQyHlQKlo7xbMjGhJS9GnwW2nn5VXOtTow7ICUKKsGsKVW1/k/hag== X-Received: by 10.223.142.6 with SMTP id n6mr9776295wrb.140.1505199055836; Mon, 11 Sep 2017 23:50:55 -0700 (PDT) Received: from localhost (ip-89-177-125-82.net.upcbroadband.cz. [89.177.125.82]) by smtp.gmail.com with ESMTPSA id 77sm16984846wmx.10.2017.09.11.23.50.54 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 11 Sep 2017 23:50:54 -0700 (PDT) From: Jiri Pirko To: netdev@vger.kernel.org Cc: davem@davemloft.net, yuvalm@mellanox.com, idosch@mellanox.com, flokli@flokli.de, mlxsw@mellanox.com Subject: [patch net] mlxsw: spectrum: Prevent mirred-related crash on removal Date: Tue, 12 Sep 2017 08:50:53 +0200 Message-Id: <20170912065053.1392-1-jiri@resnulli.us> X-Mailer: git-send-email 2.9.3 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Yuval Mintz When removing the offloading of mirred actions under matchall classifiers, mlxsw would find the destination port associated with the offloaded action and utilize it for undoing the configuration. Depending on the order by which ports are removed, it's possible that the destination port would get removed before the source port. In such a scenario, when actions would be flushed for the source port mlxsw would perform an illegal dereference as the destination port is no longer listed. Since the only item necessary for undoing the configuration on the destination side is the port-id and that in turn is already maintained by mlxsw on the source-port, simply stop trying to access the destination port and use the port-id directly instead. Fixes: 763b4b70af ("mlxsw: spectrum: Add support in matchall mirror TC offloading") Signed-off-by: Yuval Mintz Signed-off-by: Jiri Pirko --- drivers/net/ethernet/mellanox/mlxsw/spectrum.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum.c index e080459..696b99e 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/spectrum.c +++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum.c @@ -575,15 +575,14 @@ static void mlxsw_sp_span_entry_destroy(struct mlxsw_sp *mlxsw_sp, } static struct mlxsw_sp_span_entry * -mlxsw_sp_span_entry_find(struct mlxsw_sp_port *port) +mlxsw_sp_span_entry_find(struct mlxsw_sp *mlxsw_sp, u8 local_port) { - struct mlxsw_sp *mlxsw_sp = port->mlxsw_sp; int i; for (i = 0; i < mlxsw_sp->span.entries_count; i++) { struct mlxsw_sp_span_entry *curr = &mlxsw_sp->span.entries[i]; - if (curr->used && curr->local_port == port->local_port) + if (curr->used && curr->local_port == local_port) return curr; } return NULL; @@ -594,7 +593,8 @@ static struct mlxsw_sp_span_entry { struct mlxsw_sp_span_entry *span_entry; - span_entry = mlxsw_sp_span_entry_find(port); + span_entry = mlxsw_sp_span_entry_find(port->mlxsw_sp, + port->local_port); if (span_entry) { /* Already exists, just take a reference */ span_entry->ref_count++; @@ -783,12 +783,13 @@ static int mlxsw_sp_span_mirror_add(struct mlxsw_sp_port *from, } static void mlxsw_sp_span_mirror_remove(struct mlxsw_sp_port *from, - struct mlxsw_sp_port *to, + u8 destination_port, enum mlxsw_sp_span_type type) { struct mlxsw_sp_span_entry *span_entry; - span_entry = mlxsw_sp_span_entry_find(to); + span_entry = mlxsw_sp_span_entry_find(from->mlxsw_sp, + destination_port); if (!span_entry) { netdev_err(from->dev, "no span entry found\n"); return; @@ -1563,14 +1564,12 @@ static void mlxsw_sp_port_del_cls_matchall_mirror(struct mlxsw_sp_port *mlxsw_sp_port, struct mlxsw_sp_port_mall_mirror_tc_entry *mirror) { - struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp; enum mlxsw_sp_span_type span_type; - struct mlxsw_sp_port *to_port; - to_port = mlxsw_sp->ports[mirror->to_local_port]; span_type = mirror->ingress ? MLXSW_SP_SPAN_INGRESS : MLXSW_SP_SPAN_EGRESS; - mlxsw_sp_span_mirror_remove(mlxsw_sp_port, to_port, span_type); + mlxsw_sp_span_mirror_remove(mlxsw_sp_port, mirror->to_local_port, + span_type); } static int