From patchwork Mon Oct 16 14:26:35 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 826318 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="Mz2wvQvz"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3yG0yG331cz9sP1 for ; Tue, 17 Oct 2017 01:27:02 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753211AbdJPO0p (ORCPT ); Mon, 16 Oct 2017 10:26:45 -0400 Received: from mail-wm0-f68.google.com ([74.125.82.68]:51754 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753199AbdJPO0n (ORCPT ); Mon, 16 Oct 2017 10:26:43 -0400 Received: by mail-wm0-f68.google.com with SMTP id f4so3958031wme.0 for ; Mon, 16 Oct 2017 07:26:42 -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:in-reply-to:references; bh=P1vpGzmWrj1CGRyGB6PnGV6YYpbtJMtHwP1XPQReCis=; b=Mz2wvQvzx8eTxZSCgun3iC3k9rltDNiVkztXK4FhVW+K9HSzNoInnbEKF7tVThh7BM 0ooujKnu9smw5cPlAjl+isKxL+rghIhpLWXNcgmBqww6souarVjYJuJh3VMSApYv64Wr eIChWtLMAeAACX1fo1jUGAAbT/0gm55Rv8qeU1VhyW2zAOO4QNf3VolG1WIIvtMjOPrM IcV+VahfCJNY28Rrw76IF29/bIo/qxjDzabBqrXGkyQUdKsvz/xtKlnIqP9yCX2cvdno 5xwyUFBGwYFOjE+TC8IPsYbeeD5mcgmHMk75EntsZwYqIHKwo2ZHvmrSrzw8gIbNA445 Elpw== 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; bh=P1vpGzmWrj1CGRyGB6PnGV6YYpbtJMtHwP1XPQReCis=; b=tfeerkyxbZsaKJ1kqy3YMYS3xl9CuaZEJzCDPDom+T9U6bAs4fXOki48TIJ/kgkTBo PdRBv7rXX1gf+VJXXVPvii8Rey7bblJCNvW5lqB1hSSv3al5nsAjE3//lIzrobK49L9p gDRIxn/545pFro71sb9t7atRplcEWHc1+CIecTpPQKHB6OgbgxNHzRdW4r50Sfrv+dtu n2dDungz7GhpZlA7bdDRN5dm5qSHve6o5PwZ7eZDtNIsj3EcsrenkAw4OD2WrmYD5uMW p24thOHjoKKXExK+vEbBGrir/sporgJroJoVvfNvgsgSr/f896kFDiL6QzQtVG285OXI KtTg== X-Gm-Message-State: AMCzsaXq0AhTQYa9jgmM3ZA12Qoo7hQT20mwdY9ivZgVCwOTSeWk2S0s jxcSjCznmdc3ZhrYf512H6BM3+Qi X-Google-Smtp-Source: ABhQp+TZaDw/QOP/rgHGT/OfHn0iWImtED8I5czzbfsq9yl1kIT3RKj57vmo7DW/wPw+E9avwHSTWA== X-Received: by 10.223.128.164 with SMTP id 33mr728936wrl.138.1508164001835; Mon, 16 Oct 2017 07:26:41 -0700 (PDT) Received: from localhost (ip-89-177-136-69.net.upcbroadband.cz. [89.177.136.69]) by smtp.gmail.com with ESMTPSA id u138sm11821377wmd.17.2017.10.16.07.26.41 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 16 Oct 2017 07:26:41 -0700 (PDT) From: Jiri Pirko To: netdev@vger.kernel.org Cc: davem@davemloft.net, petrm@mellanox.com, idosch@mellanox.com, mlxsw@mellanox.com Subject: [patch net-next 1/5] mlxsw: spectrum: Move netdevice NB to struct mlxsw_sp Date: Mon, 16 Oct 2017 16:26:35 +0200 Message-Id: <20171016142639.2453-2-jiri@resnulli.us> X-Mailer: git-send-email 2.9.5 In-Reply-To: <20171016142639.2453-1-jiri@resnulli.us> References: <20171016142639.2453-1-jiri@resnulli.us> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Petr Machata So far, all netdevice notifications that the driver cared about were related to its own ports, and mlxsw_sp could be retrieved from the netdevice's private data. For IP-in-IP offloading however, the driver cares about events on foreign netdevices, and getting at mlxsw_sp or router data structures from the handler is inconvenient. Therefore move the netdevice notifier blocks from global scope to struct mlxsw_sp to allow retrieval from the notifier block pointer itself. Signed-off-by: Petr Machata Reviewed-by: Ido Schimmel Signed-off-by: Jiri Pirko --- drivers/net/ethernet/mellanox/mlxsw/spectrum.c | 23 ++++++++++++++++------- drivers/net/ethernet/mellanox/mlxsw/spectrum.h | 1 + 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum.c index 321988a..83f9c25 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/spectrum.c +++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum.c @@ -3667,6 +3667,9 @@ static int mlxsw_sp_basic_trap_groups_set(struct mlxsw_core *mlxsw_core) return mlxsw_reg_write(mlxsw_core, MLXSW_REG(htgt), htgt_pl); } +static int mlxsw_sp_netdevice_event(struct notifier_block *unused, + unsigned long event, void *ptr); + static int mlxsw_sp_init(struct mlxsw_core *mlxsw_core, const struct mlxsw_bus_info *mlxsw_bus_info) { @@ -3736,6 +3739,16 @@ static int mlxsw_sp_init(struct mlxsw_core *mlxsw_core, goto err_router_init; } + /* Initialize netdevice notifier after router is initialized, so that + * the event handler can use router structures. + */ + mlxsw_sp->netdevice_nb.notifier_call = mlxsw_sp_netdevice_event; + err = register_netdevice_notifier(&mlxsw_sp->netdevice_nb); + if (err) { + dev_err(mlxsw_sp->bus_info->dev, "Failed to register netdev notifier\n"); + goto err_netdev_notifier; + } + err = mlxsw_sp_span_init(mlxsw_sp); if (err) { dev_err(mlxsw_sp->bus_info->dev, "Failed to init span system\n"); @@ -3769,6 +3782,8 @@ static int mlxsw_sp_init(struct mlxsw_core *mlxsw_core, err_acl_init: mlxsw_sp_span_fini(mlxsw_sp); err_span_init: + unregister_netdevice_notifier(&mlxsw_sp->netdevice_nb); +err_netdev_notifier: mlxsw_sp_router_fini(mlxsw_sp); err_router_init: mlxsw_sp_afa_fini(mlxsw_sp); @@ -3795,6 +3810,7 @@ static void mlxsw_sp_fini(struct mlxsw_core *mlxsw_core) mlxsw_sp_dpipe_fini(mlxsw_sp); mlxsw_sp_acl_fini(mlxsw_sp); mlxsw_sp_span_fini(mlxsw_sp); + unregister_netdevice_notifier(&mlxsw_sp->netdevice_nb); mlxsw_sp_router_fini(mlxsw_sp); mlxsw_sp_afa_fini(mlxsw_sp); mlxsw_sp_counter_pool_fini(mlxsw_sp); @@ -4501,10 +4517,6 @@ static int mlxsw_sp_netdevice_event(struct notifier_block *unused, return notifier_from_errno(err); } -static struct notifier_block mlxsw_sp_netdevice_nb __read_mostly = { - .notifier_call = mlxsw_sp_netdevice_event, -}; - static struct notifier_block mlxsw_sp_inetaddr_nb __read_mostly = { .notifier_call = mlxsw_sp_inetaddr_event, .priority = 10, /* Must be called before FIB notifier block */ @@ -4532,7 +4544,6 @@ static int __init mlxsw_sp_module_init(void) { int err; - register_netdevice_notifier(&mlxsw_sp_netdevice_nb); register_inetaddr_notifier(&mlxsw_sp_inetaddr_nb); register_inet6addr_notifier(&mlxsw_sp_inet6addr_nb); register_netevent_notifier(&mlxsw_sp_router_netevent_nb); @@ -4553,7 +4564,6 @@ static int __init mlxsw_sp_module_init(void) unregister_netevent_notifier(&mlxsw_sp_router_netevent_nb); unregister_inet6addr_notifier(&mlxsw_sp_inet6addr_nb); unregister_inetaddr_notifier(&mlxsw_sp_inetaddr_nb); - unregister_netdevice_notifier(&mlxsw_sp_netdevice_nb); return err; } @@ -4564,7 +4574,6 @@ static void __exit mlxsw_sp_module_exit(void) unregister_netevent_notifier(&mlxsw_sp_router_netevent_nb); unregister_inet6addr_notifier(&mlxsw_sp_inet6addr_nb); unregister_inetaddr_notifier(&mlxsw_sp_inetaddr_nb); - unregister_netdevice_notifier(&mlxsw_sp_netdevice_nb); } module_init(mlxsw_sp_module_init); diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum.h b/drivers/net/ethernet/mellanox/mlxsw/spectrum.h index 8e45183..e1a0157 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/spectrum.h +++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum.h @@ -161,6 +161,7 @@ struct mlxsw_sp { struct { DECLARE_BITMAP(usage, MLXSW_SP_KVD_LINEAR_SIZE); } kvdl; + struct notifier_block netdevice_nb; struct mlxsw_sp_counter_pool *counter_pool; struct { From patchwork Mon Oct 16 14:26:36 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 826315 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="SXtvoQc6"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3yG0y654Bsz9sP1 for ; Tue, 17 Oct 2017 01:26:54 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753216AbdJPO0q (ORCPT ); Mon, 16 Oct 2017 10:26:46 -0400 Received: from mail-wm0-f67.google.com ([74.125.82.67]:44483 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753198AbdJPO0o (ORCPT ); Mon, 16 Oct 2017 10:26:44 -0400 Received: by mail-wm0-f67.google.com with SMTP id 196so5331712wma.1 for ; Mon, 16 Oct 2017 07:26:43 -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:in-reply-to:references; bh=Ijcchw9uEG8VAzNUvelab30xNU/HXqtS4k4MI7B9qhY=; b=SXtvoQc6pn2nOYlAG2QPXWaU65dzC/qrfZGA/H7535a1KxUimCFccE/g/wVg3FNUx+ mAFbkgvzhyFXTM90wmzeByu1M84IJYjjMn+u0UHFgZ3rnncZJCBCGB9iKeWlYmLXNJiW i5zi4hraZg19fz6lp2NaiF4fyYtSrA7+RzZDPEms0lnpx1NamY8D4h86gpdI9NzbShKV N0d/RbsSFkUByxi2EZUO9KbEiDqdhYo+eOaWBtpPQSLLMtCX/7+5blK1o2PaI0SwTM9M oEYEh1V737snREngAiQVFmNGwgdLeo2w2rmz/YZ89iDJrl758b9QN0vvbP6NyFz6GxLR 1AUA== 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; bh=Ijcchw9uEG8VAzNUvelab30xNU/HXqtS4k4MI7B9qhY=; b=OoZ4DPKDtTST288MmYuQlfROmLhf1YpNh3Qji8o1oeJ3lLeE/GiokU6zwB8q3QUf2W ddSBwkCsFubAcrHp64BxCH+A6ppOgaZYfzJAPeO0lgHSdOKhvmVosSJUshiPOCycKApj KvTATE9YwhBSm5Rho+Rqke3UKlzzzYvi+wtW/mnLYpwSvM6UeAAxRA9eDJ6koRrU/FPN 6SRWEwPyWwMzXHX5dBfpk1xscRAZm9nUfXOXC1Z5ws/O3QLr2RWtFGDowWrQimr0Pglr zLx0Q5LT8MgzZeBlxVebOXW346V5E5+GllXMc70vIpvqDWC3pAj1iJuihMxPvyIN3DLV F+XQ== X-Gm-Message-State: AMCzsaUE7q3wEHiTAQfrTP9CxFqCzvF8DVh9mP9qv+5RPlaFl3UeSeky PSiBTwt1PtQGjMTJ9NqiWB/OOXb6 X-Google-Smtp-Source: ABhQp+SeBGu5BHLgQKOIudiPn3cd25xpJgl0Cg5CT7iI4Jih2Uxwgv19f1HmPKS7L81wLDSourfSvg== X-Received: by 10.223.145.41 with SMTP id j38mr716427wrj.133.1508164002845; Mon, 16 Oct 2017 07:26:42 -0700 (PDT) Received: from localhost (ip-89-177-136-69.net.upcbroadband.cz. [89.177.136.69]) by smtp.gmail.com with ESMTPSA id o76sm4877618wrb.48.2017.10.16.07.26.42 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 16 Oct 2017 07:26:42 -0700 (PDT) From: Jiri Pirko To: netdev@vger.kernel.org Cc: davem@davemloft.net, petrm@mellanox.com, idosch@mellanox.com, mlxsw@mellanox.com Subject: [patch net-next 2/5] mlxsw: spectrum_router: Move mlxsw_sp_netdev_ipip_type() Date: Mon, 16 Oct 2017 16:26:36 +0200 Message-Id: <20171016142639.2453-3-jiri@resnulli.us> X-Mailer: git-send-email 2.9.5 In-Reply-To: <20171016142639.2453-1-jiri@resnulli.us> References: <20171016142639.2453-1-jiri@resnulli.us> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Petr Machata Signed-off-by: Petr Machata Reviewed-by: Ido Schimmel Signed-off-by: Jiri Pirko --- .../net/ethernet/mellanox/mlxsw/spectrum_router.c | 38 +++++++++++----------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c index 6a356f4..c5e574b 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c +++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c @@ -1295,6 +1295,25 @@ mlxsw_sp_ipip_entry_find_by_decap(struct mlxsw_sp *mlxsw_sp, return NULL; } +static bool mlxsw_sp_netdev_ipip_type(const struct mlxsw_sp *mlxsw_sp, + const struct net_device *dev, + enum mlxsw_sp_ipip_type *p_type) +{ + struct mlxsw_sp_router *router = mlxsw_sp->router; + const struct mlxsw_sp_ipip_ops *ipip_ops; + enum mlxsw_sp_ipip_type ipipt; + + for (ipipt = 0; ipipt < MLXSW_SP_IPIP_TYPE_MAX; ++ipipt) { + ipip_ops = router->ipip_ops_arr[ipipt]; + if (dev->type == ipip_ops->dev_type) { + if (p_type) + *p_type = ipipt; + return true; + } + } + return false; +} + struct mlxsw_sp_neigh_key { struct neighbour *n; }; @@ -2785,25 +2804,6 @@ static void mlxsw_sp_nexthop_neigh_fini(struct mlxsw_sp *mlxsw_sp, neigh_release(n); } -static bool mlxsw_sp_netdev_ipip_type(const struct mlxsw_sp *mlxsw_sp, - const struct net_device *dev, - enum mlxsw_sp_ipip_type *p_type) -{ - struct mlxsw_sp_router *router = mlxsw_sp->router; - const struct mlxsw_sp_ipip_ops *ipip_ops; - enum mlxsw_sp_ipip_type ipipt; - - for (ipipt = 0; ipipt < MLXSW_SP_IPIP_TYPE_MAX; ++ipipt) { - ipip_ops = router->ipip_ops_arr[ipipt]; - if (dev->type == ipip_ops->dev_type) { - if (p_type) - *p_type = ipipt; - return true; - } - } - return false; -} - static int mlxsw_sp_nexthop_ipip_init(struct mlxsw_sp *mlxsw_sp, enum mlxsw_sp_ipip_type ipipt, struct mlxsw_sp_nexthop *nh, From patchwork Mon Oct 16 14:26:37 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 826314 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="mpFaKsOA"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3yG0y22kTxz9sP1 for ; Tue, 17 Oct 2017 01:26:50 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753221AbdJPO0s (ORCPT ); Mon, 16 Oct 2017 10:26:48 -0400 Received: from mail-wm0-f66.google.com ([74.125.82.66]:45158 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753205AbdJPO0p (ORCPT ); Mon, 16 Oct 2017 10:26:45 -0400 Received: by mail-wm0-f66.google.com with SMTP id q124so3945060wmb.0 for ; Mon, 16 Oct 2017 07:26:44 -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:in-reply-to:references; bh=uwwXZYY0aDIyNZnNBoDACVkAECmhoHOKmtTuHC538nU=; b=mpFaKsOAlXWqfXfUotRC9S+lyKJMrGNyNLzDHWIh0b/tgnFicM1HjkYpshvgqGEwoF 5gijxkZNYMye0eiHutK7TSUYT2ojIvISR2MH+mZVVtgTetKWW7PVyP96RfIbi6D9QCSh bEDekwOBm7wt0D2Xf9ysYGx9T5YuTOVx8I7uJn39tFTSuVQvF3IzU2SqO7MapQMQU96e SlcLZPn2whJ/wCAgokSfDYxcI5jI0jrHzwjB+f5GCT9onL1cXRSbf4lmcFecxdljxGd3 rC2ky67UthASoonU+SjyHBIz3cWUeA2GkHd9rjwnsdwQWCiHcqGbJFsQPtM8Dg+DyTmh 0rDw== 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; bh=uwwXZYY0aDIyNZnNBoDACVkAECmhoHOKmtTuHC538nU=; b=nMLVTQgCzYq5JQr44ZGxT1D4GbeiQKZt9bQedTP1jHjsQvcIxcs5Hdvb3D8FCi3iSJ 44SuKD8NrG89XP+SkIwy0RKjtfb7FnM2MNDHcr7Qwgk82ZKfFB5GiKOAu2NOc1ZA8dEl fZFn7sKYjHYiTPpbgXzdgbtLKyPY9bSaUDuOUGErH7w4R/IB4klZiAvQu1sGhSxeLJRD qOWBJ2bUH1CLD40j6Tja3Zu5RJzQVovLHozTJiUbGC5ZcvldTyY/ngrkl47eT5oQfUaf knKUTZg4/uPoHVWTmmtXalNqPVlG8j/ClemZl3MS66rE+d6RrgiG0LbtPa9/ZPGSvLh3 mviw== X-Gm-Message-State: AMCzsaVM3JI2k1Dgqyj2MbMB627fFIAN/eEwB7F5Iz4Fyzj1MhzbWDjO DT+6F4/cbD8hepqplQD20TiQIEie X-Google-Smtp-Source: ABhQp+QMhIKwwxd6dqHgYAK00Dvz0AUZRDy6kfUJalMrTxyEy/Yw3i+625vOzDyWSZ7Wz7BBucQzfQ== X-Received: by 10.223.186.201 with SMTP id w9mr770960wrg.230.1508164003683; Mon, 16 Oct 2017 07:26:43 -0700 (PDT) Received: from localhost (ip-89-177-136-69.net.upcbroadband.cz. [89.177.136.69]) by smtp.gmail.com with ESMTPSA id w14sm5950668wmf.13.2017.10.16.07.26.43 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 16 Oct 2017 07:26:43 -0700 (PDT) From: Jiri Pirko To: netdev@vger.kernel.org Cc: davem@davemloft.net, petrm@mellanox.com, idosch@mellanox.com, mlxsw@mellanox.com Subject: [patch net-next 3/5] mlxsw: spectrum: Support decap-only IP-in-IP tunnels Date: Mon, 16 Oct 2017 16:26:37 +0200 Message-Id: <20171016142639.2453-4-jiri@resnulli.us> X-Mailer: git-send-email 2.9.5 In-Reply-To: <20171016142639.2453-1-jiri@resnulli.us> References: <20171016142639.2453-1-jiri@resnulli.us> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Petr Machata Current code for offloading IP-in-IP tunneling assumes that there is no decap without encap. But that's never true for IPv6 overlays, and is not true for IPv4 ones either, if net.ipv4.conf.*.rp_filter is unset. To support decap-only tunnels, an IPIP entry is now created as soon as an offloadable tunneling device is created. When that netdevice is up'd, a decap route is looked up and possibly offloaded. Thus decap is not handled implicitly as part of mlxsw_sp_ipip_entry_get() call anymore, but needs to be done explicitly after the get, if desired. Signed-off-by: Petr Machata Reviewed-by: Ido Schimmel Signed-off-by: Jiri Pirko --- drivers/net/ethernet/mellanox/mlxsw/spectrum.c | 8 +- drivers/net/ethernet/mellanox/mlxsw/spectrum.h | 6 ++ .../net/ethernet/mellanox/mlxsw/spectrum_router.c | 105 +++++++++++++++++++-- 3 files changed, 109 insertions(+), 10 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum.c index 83f9c25..c3ae650 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/spectrum.c +++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum.c @@ -4497,13 +4497,17 @@ static bool mlxsw_sp_is_vrf_event(unsigned long event, void *ptr) return netif_is_l3_master(info->upper_dev); } -static int mlxsw_sp_netdevice_event(struct notifier_block *unused, +static int mlxsw_sp_netdevice_event(struct notifier_block *nb, unsigned long event, void *ptr) { struct net_device *dev = netdev_notifier_info_to_dev(ptr); + struct mlxsw_sp *mlxsw_sp; int err = 0; - if (event == NETDEV_CHANGEADDR || event == NETDEV_CHANGEMTU) + mlxsw_sp = container_of(nb, struct mlxsw_sp, netdevice_nb); + if (mlxsw_sp_netdev_is_ipip(mlxsw_sp, dev)) + err = mlxsw_sp_netdevice_ipip_event(mlxsw_sp, dev, event); + else if (event == NETDEV_CHANGEADDR || event == NETDEV_CHANGEMTU) err = mlxsw_sp_netdevice_router_port_event(dev); else if (mlxsw_sp_is_vrf_event(event, ptr)) err = mlxsw_sp_netdevice_vrf_event(dev, event, ptr); diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum.h b/drivers/net/ethernet/mellanox/mlxsw/spectrum.h index e1a0157..a4f21af 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/spectrum.h +++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum.h @@ -395,6 +395,12 @@ int mlxsw_sp_inet6addr_event(struct notifier_block *unused, unsigned long event, void *ptr); int mlxsw_sp_netdevice_vrf_event(struct net_device *l3_dev, unsigned long event, struct netdev_notifier_changeupper_info *info); +bool mlxsw_sp_netdev_is_ipip(const struct mlxsw_sp *mlxsw_sp, + const struct net_device *dev); +int +mlxsw_sp_netdevice_ipip_event(struct mlxsw_sp *mlxsw_sp, + struct net_device *l3_dev, + unsigned long event); void mlxsw_sp_port_vlan_router_leave(struct mlxsw_sp_port_vlan *mlxsw_sp_port_vlan); void mlxsw_sp_rif_destroy(struct mlxsw_sp_rif *rif); diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c index c5e574b..db83422 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c +++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c @@ -1206,7 +1206,6 @@ mlxsw_sp_ipip_entry_get(struct mlxsw_sp *mlxsw_sp, { u32 ul_tb_id = mlxsw_sp_ipip_dev_ul_tb_id(ol_dev); struct mlxsw_sp_router *router = mlxsw_sp->router; - struct mlxsw_sp_fib_entry *decap_fib_entry; struct mlxsw_sp_ipip_entry *ipip_entry; enum mlxsw_sp_l3proto ul_proto; union mlxsw_sp_l3addr saddr; @@ -1231,11 +1230,6 @@ mlxsw_sp_ipip_entry_get(struct mlxsw_sp *mlxsw_sp, if (IS_ERR(ipip_entry)) return ipip_entry; - decap_fib_entry = mlxsw_sp_ipip_entry_find_decap(mlxsw_sp, ipip_entry); - if (decap_fib_entry) - mlxsw_sp_ipip_entry_promote_decap(mlxsw_sp, ipip_entry, - decap_fib_entry); - list_add_tail(&ipip_entry->ipip_list_node, &mlxsw_sp->router->ipip_list); @@ -1250,8 +1244,6 @@ mlxsw_sp_ipip_entry_put(struct mlxsw_sp *mlxsw_sp, { if (--ipip_entry->ref_count == 0) { list_del(&ipip_entry->ipip_list_node); - if (ipip_entry->decap_fib_entry) - mlxsw_sp_ipip_entry_demote_decap(mlxsw_sp, ipip_entry); mlxsw_sp_ipip_entry_destroy(ipip_entry); } } @@ -1314,6 +1306,103 @@ static bool mlxsw_sp_netdev_ipip_type(const struct mlxsw_sp *mlxsw_sp, return false; } +bool mlxsw_sp_netdev_is_ipip(const struct mlxsw_sp *mlxsw_sp, + const struct net_device *dev) +{ + return mlxsw_sp_netdev_ipip_type(mlxsw_sp, dev, NULL); +} + +static struct mlxsw_sp_ipip_entry * +mlxsw_sp_ipip_entry_find_by_ol_dev(struct mlxsw_sp *mlxsw_sp, + const struct net_device *ol_dev) +{ + struct mlxsw_sp_ipip_entry *ipip_entry; + + list_for_each_entry(ipip_entry, &mlxsw_sp->router->ipip_list, + ipip_list_node) + if (ipip_entry->ol_dev == ol_dev) + return ipip_entry; + + return NULL; +} + +static int mlxsw_sp_netdevice_ipip_reg_event(struct mlxsw_sp *mlxsw_sp, + struct net_device *ol_dev) +{ + struct mlxsw_sp_router *router = mlxsw_sp->router; + struct mlxsw_sp_ipip_entry *ipip_entry; + enum mlxsw_sp_ipip_type ipipt; + + mlxsw_sp_netdev_ipip_type(mlxsw_sp, ol_dev, &ipipt); + if (router->ipip_ops_arr[ipipt]->can_offload(mlxsw_sp, ol_dev, + MLXSW_SP_L3_PROTO_IPV4) || + router->ipip_ops_arr[ipipt]->can_offload(mlxsw_sp, ol_dev, + MLXSW_SP_L3_PROTO_IPV6)) { + ipip_entry = mlxsw_sp_ipip_entry_get(mlxsw_sp, ipipt, ol_dev); + if (IS_ERR(ipip_entry)) + return PTR_ERR(ipip_entry); + } + + return 0; +} + +static void mlxsw_sp_netdevice_ipip_unreg_event(struct mlxsw_sp *mlxsw_sp, + struct net_device *ol_dev) +{ + struct mlxsw_sp_ipip_entry *ipip_entry; + + ipip_entry = mlxsw_sp_ipip_entry_find_by_ol_dev(mlxsw_sp, ol_dev); + if (ipip_entry) + mlxsw_sp_ipip_entry_put(mlxsw_sp, ipip_entry); +} + +static int mlxsw_sp_netdevice_ipip_up_event(struct mlxsw_sp *mlxsw_sp, + struct net_device *ol_dev) +{ + struct mlxsw_sp_fib_entry *decap_fib_entry; + struct mlxsw_sp_ipip_entry *ipip_entry; + + ipip_entry = mlxsw_sp_ipip_entry_find_by_ol_dev(mlxsw_sp, ol_dev); + if (ipip_entry) { + decap_fib_entry = mlxsw_sp_ipip_entry_find_decap(mlxsw_sp, + ipip_entry); + if (decap_fib_entry) + mlxsw_sp_ipip_entry_promote_decap(mlxsw_sp, ipip_entry, + decap_fib_entry); + } + + return 0; +} + +static void mlxsw_sp_netdevice_ipip_down_event(struct mlxsw_sp *mlxsw_sp, + struct net_device *ol_dev) +{ + struct mlxsw_sp_ipip_entry *ipip_entry; + + ipip_entry = mlxsw_sp_ipip_entry_find_by_ol_dev(mlxsw_sp, ol_dev); + if (ipip_entry && ipip_entry->decap_fib_entry) + mlxsw_sp_ipip_entry_demote_decap(mlxsw_sp, ipip_entry); +} + +int mlxsw_sp_netdevice_ipip_event(struct mlxsw_sp *mlxsw_sp, + struct net_device *ol_dev, + unsigned long event) +{ + switch (event) { + case NETDEV_REGISTER: + return mlxsw_sp_netdevice_ipip_reg_event(mlxsw_sp, ol_dev); + case NETDEV_UNREGISTER: + mlxsw_sp_netdevice_ipip_unreg_event(mlxsw_sp, ol_dev); + return 0; + case NETDEV_UP: + return mlxsw_sp_netdevice_ipip_up_event(mlxsw_sp, ol_dev); + case NETDEV_DOWN: + mlxsw_sp_netdevice_ipip_down_event(mlxsw_sp, ol_dev); + return 0; + } + return 0; +} + struct mlxsw_sp_neigh_key { struct neighbour *n; }; From patchwork Mon Oct 16 14:26:38 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 826319 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="YoYdm3gt"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3yG0yH2DYzz9sRW for ; Tue, 17 Oct 2017 01:27:03 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753229AbdJPO1B (ORCPT ); Mon, 16 Oct 2017 10:27:01 -0400 Received: from mail-wm0-f68.google.com ([74.125.82.68]:57006 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753208AbdJPO0p (ORCPT ); Mon, 16 Oct 2017 10:26:45 -0400 Received: by mail-wm0-f68.google.com with SMTP id l68so3893577wmd.5 for ; Mon, 16 Oct 2017 07:26:45 -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:in-reply-to:references; bh=K4BDwohYFR+tK2wGNgQ08anYtQOgCUP+uFF4mSr0baw=; b=YoYdm3gtbRdGkyydv81otYg322VL3sIlCtzNunvpqyPjitnqUmu+W5Bt7Kf0IOdMVc o3+LauH7CvbMi7q7qHotvomtsx5BkQaZZVuCtJqCrLecg25EOQvJgJHYxowkl3enPF5m +s+XuNrSx98TG+iTPqmH1I6D2pFCLAgTJNU2iJGpkHX4Rtd0vWRKfPkWg8H7YesMtJdw W4nxaedX+6cf85ZTkAa+IXJGg3XTs6BxZvSdgEnAIzCCaXpvMmaIT8oLwv4tEJQcjrv6 0AucwlQe1spDklFE+QAoRXq4Ja/MtZfFqO83KDgHXc/b7AY3VTWmCE1ssv0pb3E9GxyN 2xNQ== 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; bh=K4BDwohYFR+tK2wGNgQ08anYtQOgCUP+uFF4mSr0baw=; b=IhmnRWkoSEchR08vQzR0KzdqO762syGzbDiYB/SFLv+zil14jAG21ClEr9fD7CW/Rz dCfJ/Yb++yCFgpcGDirLqj4MdZLFR9v5ZBa+tDjEPAxkhOmK5C4kZz4WPjPdGzlF9ZLZ KkbSavvxJFYUtKrvaxOxx1Z3j2bUHDzLIG3cBHIv1SC42ckQvhznws7gaSpN1X7BqcQh rDF+NESoywY0adZNvllWwEfzZCf8HWPG1bp9xdP6GH8onMUd4RZZCscwyGVpOWZSa+Ld /uiGgiV9NsCKK7UluYtbl8Wi09oQj9nNhFej/7qUeeUEDU6CLimnRMxCo3/TdldEb1Lz zKDg== X-Gm-Message-State: AMCzsaV16qb/qMuaZITCD/58g5MH58Z4iP2wu9Txm2Yt7dudYhTB98fK DBf6NGwxqacqk+OLLnGJOEGK6F+2 X-Google-Smtp-Source: ABhQp+S1h6K0fnyQOfRnqjsh6krR7BeA5RGVEm4s9lMXgPpUHSfM/5I5/C8w4MfzDONOaVx0j27/Sw== X-Received: by 10.223.153.45 with SMTP id x42mr765773wrb.212.1508164004540; Mon, 16 Oct 2017 07:26:44 -0700 (PDT) Received: from localhost (ip-89-177-136-69.net.upcbroadband.cz. [89.177.136.69]) by smtp.gmail.com with ESMTPSA id v5sm4199049wme.5.2017.10.16.07.26.44 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 16 Oct 2017 07:26:44 -0700 (PDT) From: Jiri Pirko To: netdev@vger.kernel.org Cc: davem@davemloft.net, petrm@mellanox.com, idosch@mellanox.com, mlxsw@mellanox.com Subject: [patch net-next 4/5] mlxsw: spectrum: Support IPIP overlay VRF migration Date: Mon, 16 Oct 2017 16:26:38 +0200 Message-Id: <20171016142639.2453-5-jiri@resnulli.us> X-Mailer: git-send-email 2.9.5 In-Reply-To: <20171016142639.2453-1-jiri@resnulli.us> References: <20171016142639.2453-1-jiri@resnulli.us> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Petr Machata IPIP entries are created as soon as an offloadable device is created. That means that when such a device is later moved to a different VRF, the loopback device that backs the tunnel is wrong. Thus when an offloadable encapsulating netdevice moves from one VRF to another, make sure that the loopback is updated as necessary. Signed-off-by: Petr Machata Reviewed-by: Ido Schimmel Signed-off-by: Jiri Pirko --- drivers/net/ethernet/mellanox/mlxsw/spectrum.c | 2 +- drivers/net/ethernet/mellanox/mlxsw/spectrum.h | 3 +- .../net/ethernet/mellanox/mlxsw/spectrum_router.c | 47 +++++++++++++++++++++- 3 files changed, 49 insertions(+), 3 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum.c index c3ae650..e1e11c7 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/spectrum.c +++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum.c @@ -4506,7 +4506,7 @@ static int mlxsw_sp_netdevice_event(struct notifier_block *nb, mlxsw_sp = container_of(nb, struct mlxsw_sp, netdevice_nb); if (mlxsw_sp_netdev_is_ipip(mlxsw_sp, dev)) - err = mlxsw_sp_netdevice_ipip_event(mlxsw_sp, dev, event); + err = mlxsw_sp_netdevice_ipip_event(mlxsw_sp, dev, event, ptr); else if (event == NETDEV_CHANGEADDR || event == NETDEV_CHANGEMTU) err = mlxsw_sp_netdevice_router_port_event(dev); else if (mlxsw_sp_is_vrf_event(event, ptr)) diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum.h b/drivers/net/ethernet/mellanox/mlxsw/spectrum.h index a4f21af..28feb74 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/spectrum.h +++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum.h @@ -400,7 +400,8 @@ bool mlxsw_sp_netdev_is_ipip(const struct mlxsw_sp *mlxsw_sp, int mlxsw_sp_netdevice_ipip_event(struct mlxsw_sp *mlxsw_sp, struct net_device *l3_dev, - unsigned long event); + unsigned long event, + struct netdev_notifier_changeupper_info *info); void mlxsw_sp_port_vlan_router_leave(struct mlxsw_sp_port_vlan *mlxsw_sp_port_vlan); void mlxsw_sp_rif_destroy(struct mlxsw_sp_rif *rif); diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c index db83422..082cf00 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c +++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c @@ -1384,9 +1384,49 @@ static void mlxsw_sp_netdevice_ipip_down_event(struct mlxsw_sp *mlxsw_sp, mlxsw_sp_ipip_entry_demote_decap(mlxsw_sp, ipip_entry); } +static int mlxsw_sp_netdevice_ipip_vrf_event(struct mlxsw_sp *mlxsw_sp, + struct net_device *ol_dev) +{ + struct mlxsw_sp_fib_entry *decap_fib_entry; + struct mlxsw_sp_ipip_entry *ipip_entry; + struct mlxsw_sp_rif_ipip_lb *lb_rif; + + ipip_entry = mlxsw_sp_ipip_entry_find_by_ol_dev(mlxsw_sp, ol_dev); + if (!ipip_entry) + return 0; + + /* When a tunneling device is moved to a different VRF, we need to + * update the backing loopback. Since RIFs can't be edited, we need to + * destroy and recreate it. That might create a window of opportunity + * where RALUE and RATR registers end up referencing a RIF that's + * already gone. RATRs are handled by the RIF destroy, and to take care + * of RALUE, demote the decap route back. + */ + if (ipip_entry->decap_fib_entry) + mlxsw_sp_ipip_entry_demote_decap(mlxsw_sp, ipip_entry); + + lb_rif = mlxsw_sp_ipip_ol_ipip_lb_create(mlxsw_sp, ipip_entry->ipipt, + ol_dev); + if (IS_ERR(lb_rif)) + return PTR_ERR(lb_rif); + mlxsw_sp_rif_destroy(&ipip_entry->ol_lb->common); + ipip_entry->ol_lb = lb_rif; + + if (ol_dev->flags & IFF_UP) { + decap_fib_entry = mlxsw_sp_ipip_entry_find_decap(mlxsw_sp, + ipip_entry); + if (decap_fib_entry) + mlxsw_sp_ipip_entry_promote_decap(mlxsw_sp, ipip_entry, + decap_fib_entry); + } + + return 0; +} + int mlxsw_sp_netdevice_ipip_event(struct mlxsw_sp *mlxsw_sp, struct net_device *ol_dev, - unsigned long event) + unsigned long event, + struct netdev_notifier_changeupper_info *info) { switch (event) { case NETDEV_REGISTER: @@ -1399,6 +1439,11 @@ int mlxsw_sp_netdevice_ipip_event(struct mlxsw_sp *mlxsw_sp, case NETDEV_DOWN: mlxsw_sp_netdevice_ipip_down_event(mlxsw_sp, ol_dev); return 0; + case NETDEV_CHANGEUPPER: + if (netif_is_l3_master(info->upper_dev)) + return mlxsw_sp_netdevice_ipip_vrf_event(mlxsw_sp, + ol_dev); + return 0; } return 0; } From patchwork Mon Oct 16 14:26:39 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 826317 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="Lc3u7C0I"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3yG0y863jWz9sP1 for ; Tue, 17 Oct 2017 01:26:56 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753226AbdJPO0y (ORCPT ); Mon, 16 Oct 2017 10:26:54 -0400 Received: from mail-wm0-f66.google.com ([74.125.82.66]:49521 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753215AbdJPO0r (ORCPT ); Mon, 16 Oct 2017 10:26:47 -0400 Received: by mail-wm0-f66.google.com with SMTP id b189so3858151wmd.4 for ; Mon, 16 Oct 2017 07:26:46 -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:in-reply-to:references; bh=kQ/iRs0QKQajPf99S/4ScgYpe5fsnjNdSppctFrWGPg=; b=Lc3u7C0Il1yFCJxMz6IiqwkgQ9BQ3QCXskm3wHFgWcj/Xnx1QzQJDW8T/oBU6xl5TV Mu42jQOmy1dxn0hASlpFpj2p9S4NX7RxHIdhGna8k8HtEfgVY/JvkvTUVNW9SS25fe4N Ruk7oTOKqYU5p2vIT0Tj3kIAoGhFf5g0eoJkp0gUAF4CUXmZ+fyDjODYPEX2hywr6mqW Iaf1qAbTmRJSqP0laohT8xxjsWfnRKKCCiPP4cLMpf2nq5VDEliIXrVRDvRz73/h1ok8 mJa0yyQyOL/RbuGwIiWM7J4stiuVU/O9q1tSNbpEc5TCpV6Bqp4GDLYLTWqPVDVC0Tgh vJTQ== 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; bh=kQ/iRs0QKQajPf99S/4ScgYpe5fsnjNdSppctFrWGPg=; b=fTLFjaFLl5OzjQE+xTafZlgoVdL1m67bymq8CDGQphEMgKh09PQIMdpgCggzMV/caZ RTAGemoTN7FmcwcEvkvu2s+8wfP9QkABgymWEWAIXSrl/iYt5aZQQq/atuswAzyTuD74 Bt22J4KEQUYjAo0Tk1uwZIGfdlt8wLUYBiM9MRkTIuejFQIsnWeZf0EHhxb7C6GFs+EH U2UCAxCLSDuNvfJrycWs7ewZ9f5bhaTApjlokpY2EbH+SKpiQp2mzCWsak6BNOYtDG8S enIYk2dFSEb0fiY0lA7CYeDfay9irjDEiFXw5fScPuf/4AwBuYn2+hYHCObtO6V0NC8Y +cdg== X-Gm-Message-State: AMCzsaUgAfyWaI1PAwuj1F8zLTE0J4IS26WdCUW6Hwc2SidIh5w6HdMM Og+8o06jNaTb/6KpOKIdO3WFzhcV X-Google-Smtp-Source: ABhQp+RYP6u9kdYmAxkPeyHZoXMxjd4WfY5DTV03d9KpSP5IvXHxc+GUSa6HTyRMDmjeMyjTX5ZQbQ== X-Received: by 10.223.150.161 with SMTP id u30mr856285wrb.229.1508164005426; Mon, 16 Oct 2017 07:26:45 -0700 (PDT) Received: from localhost (ip-89-177-136-69.net.upcbroadband.cz. [89.177.136.69]) by smtp.gmail.com with ESMTPSA id f27sm14624661wrf.63.2017.10.16.07.26.45 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 16 Oct 2017 07:26:45 -0700 (PDT) From: Jiri Pirko To: netdev@vger.kernel.org Cc: davem@davemloft.net, petrm@mellanox.com, idosch@mellanox.com, mlxsw@mellanox.com Subject: [patch net-next 5/5] mlxsw: spectrum: Drop refcounting of IPIP entries Date: Mon, 16 Oct 2017 16:26:39 +0200 Message-Id: <20171016142639.2453-6-jiri@resnulli.us> X-Mailer: git-send-email 2.9.5 In-Reply-To: <20171016142639.2453-1-jiri@resnulli.us> References: <20171016142639.2453-1-jiri@resnulli.us> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Petr Machata Formerly, IPIP entries were created lazily by next hops that referenced an offloadable IP-in-IP netdevice. However now that they are created eagerly as a reaction to events on such netdevices, the reference counting is useless. Hence drop it. The routes whose next hops reference an offloaded IP-in-IP netdevice actually linger around a bit after their device is unregistered. However, mlxsw_sp_ipip_entry_destroy() also destroys the backing loopback, and mlxsw_sp_rif_destroy() transitively (via mlxsw_sp_nexthop_rif_gone_sync()) calls mlxsw_sp_nexthop_ipip_fini(), which unlinks the IPIP entry from a next hop. Thus no dangling pointers are left behind for the brief window after netdevice is gone, but routes not yet. Signed-off-by: Petr Machata Reviewed-by: Ido Schimmel Signed-off-by: Jiri Pirko --- .../net/ethernet/mellanox/mlxsw/spectrum_ipip.h | 1 - .../net/ethernet/mellanox/mlxsw/spectrum_router.c | 49 +++++++++------------- 2 files changed, 20 insertions(+), 30 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_ipip.h b/drivers/net/ethernet/mellanox/mlxsw/spectrum_ipip.h index 1c2db83..6fb4912 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_ipip.h +++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_ipip.h @@ -47,7 +47,6 @@ struct mlxsw_sp_ipip_entry { enum mlxsw_sp_ipip_type ipipt; struct net_device *ol_dev; /* Overlay. */ struct mlxsw_sp_rif_ipip_lb *ol_lb; - unsigned int ref_count; /* Number of next hops using the tunnel. */ struct mlxsw_sp_fib_entry *decap_fib_entry; struct list_head ipip_list_node; }; diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c index 082cf00..3330120 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c +++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c @@ -1002,9 +1002,8 @@ mlxsw_sp_ipip_entry_alloc(struct mlxsw_sp *mlxsw_sp, } static void -mlxsw_sp_ipip_entry_destroy(struct mlxsw_sp_ipip_entry *ipip_entry) +mlxsw_sp_ipip_entry_dealloc(struct mlxsw_sp_ipip_entry *ipip_entry) { - WARN_ON(ipip_entry->ref_count > 0); mlxsw_sp_rif_destroy(&ipip_entry->ol_lb->common); kfree(ipip_entry); } @@ -1200,9 +1199,9 @@ mlxsw_sp_ipip_entry_find_decap(struct mlxsw_sp *mlxsw_sp, } static struct mlxsw_sp_ipip_entry * -mlxsw_sp_ipip_entry_get(struct mlxsw_sp *mlxsw_sp, - enum mlxsw_sp_ipip_type ipipt, - struct net_device *ol_dev) +mlxsw_sp_ipip_entry_create(struct mlxsw_sp *mlxsw_sp, + enum mlxsw_sp_ipip_type ipipt, + struct net_device *ol_dev) { u32 ul_tb_id = mlxsw_sp_ipip_dev_ul_tb_id(ol_dev); struct mlxsw_sp_router *router = mlxsw_sp->router; @@ -1210,15 +1209,12 @@ mlxsw_sp_ipip_entry_get(struct mlxsw_sp *mlxsw_sp, enum mlxsw_sp_l3proto ul_proto; union mlxsw_sp_l3addr saddr; + /* The configuration where several tunnels have the same local address + * in the same underlay table needs special treatment in the HW. That is + * currently not implemented in the driver. + */ list_for_each_entry(ipip_entry, &mlxsw_sp->router->ipip_list, ipip_list_node) { - if (ipip_entry->ol_dev == ol_dev) - goto inc_ref_count; - - /* The configuration where several tunnels have the same local - * address in the same underlay table needs special treatment in - * the HW. That is currently not implemented in the driver. - */ ul_proto = router->ipip_ops_arr[ipip_entry->ipipt]->ul_proto; saddr = mlxsw_sp_ipip_netdev_saddr(ul_proto, ol_dev); if (mlxsw_sp_ipip_entry_saddr_matches(mlxsw_sp, ul_proto, saddr, @@ -1233,19 +1229,15 @@ mlxsw_sp_ipip_entry_get(struct mlxsw_sp *mlxsw_sp, list_add_tail(&ipip_entry->ipip_list_node, &mlxsw_sp->router->ipip_list); -inc_ref_count: - ++ipip_entry->ref_count; return ipip_entry; } static void -mlxsw_sp_ipip_entry_put(struct mlxsw_sp *mlxsw_sp, - struct mlxsw_sp_ipip_entry *ipip_entry) +mlxsw_sp_ipip_entry_destroy(struct mlxsw_sp *mlxsw_sp, + struct mlxsw_sp_ipip_entry *ipip_entry) { - if (--ipip_entry->ref_count == 0) { - list_del(&ipip_entry->ipip_list_node); - mlxsw_sp_ipip_entry_destroy(ipip_entry); - } + list_del(&ipip_entry->ipip_list_node); + mlxsw_sp_ipip_entry_dealloc(ipip_entry); } static bool @@ -1338,7 +1330,8 @@ static int mlxsw_sp_netdevice_ipip_reg_event(struct mlxsw_sp *mlxsw_sp, MLXSW_SP_L3_PROTO_IPV4) || router->ipip_ops_arr[ipipt]->can_offload(mlxsw_sp, ol_dev, MLXSW_SP_L3_PROTO_IPV6)) { - ipip_entry = mlxsw_sp_ipip_entry_get(mlxsw_sp, ipipt, ol_dev); + ipip_entry = mlxsw_sp_ipip_entry_create(mlxsw_sp, ipipt, + ol_dev); if (IS_ERR(ipip_entry)) return PTR_ERR(ipip_entry); } @@ -1353,7 +1346,7 @@ static void mlxsw_sp_netdevice_ipip_unreg_event(struct mlxsw_sp *mlxsw_sp, ipip_entry = mlxsw_sp_ipip_entry_find_by_ol_dev(mlxsw_sp, ol_dev); if (ipip_entry) - mlxsw_sp_ipip_entry_put(mlxsw_sp, ipip_entry); + mlxsw_sp_ipip_entry_destroy(mlxsw_sp, ipip_entry); } static int mlxsw_sp_netdevice_ipip_up_event(struct mlxsw_sp *mlxsw_sp, @@ -2939,16 +2932,15 @@ static void mlxsw_sp_nexthop_neigh_fini(struct mlxsw_sp *mlxsw_sp, } static int mlxsw_sp_nexthop_ipip_init(struct mlxsw_sp *mlxsw_sp, - enum mlxsw_sp_ipip_type ipipt, struct mlxsw_sp_nexthop *nh, struct net_device *ol_dev) { if (!nh->nh_grp->gateway || nh->ipip_entry) return 0; - nh->ipip_entry = mlxsw_sp_ipip_entry_get(mlxsw_sp, ipipt, ol_dev); - if (IS_ERR(nh->ipip_entry)) - return PTR_ERR(nh->ipip_entry); + nh->ipip_entry = mlxsw_sp_ipip_entry_find_by_ol_dev(mlxsw_sp, ol_dev); + if (!nh->ipip_entry) + return -ENOENT; __mlxsw_sp_nexthop_neigh_update(nh, false); return 0; @@ -2963,7 +2955,6 @@ static void mlxsw_sp_nexthop_ipip_fini(struct mlxsw_sp *mlxsw_sp, return; __mlxsw_sp_nexthop_neigh_update(nh, true); - mlxsw_sp_ipip_entry_put(mlxsw_sp, ipip_entry); nh->ipip_entry = NULL; } @@ -3007,7 +2998,7 @@ static int mlxsw_sp_nexthop4_type_init(struct mlxsw_sp *mlxsw_sp, router->ipip_ops_arr[ipipt]->can_offload(mlxsw_sp, dev, MLXSW_SP_L3_PROTO_IPV4)) { nh->type = MLXSW_SP_NEXTHOP_TYPE_IPIP; - err = mlxsw_sp_nexthop_ipip_init(mlxsw_sp, ipipt, nh, dev); + err = mlxsw_sp_nexthop_ipip_init(mlxsw_sp, nh, dev); if (err) return err; mlxsw_sp_nexthop_rif_init(nh, &nh->ipip_entry->ol_lb->common); @@ -4269,7 +4260,7 @@ static int mlxsw_sp_nexthop6_type_init(struct mlxsw_sp *mlxsw_sp, router->ipip_ops_arr[ipipt]->can_offload(mlxsw_sp, dev, MLXSW_SP_L3_PROTO_IPV6)) { nh->type = MLXSW_SP_NEXTHOP_TYPE_IPIP; - err = mlxsw_sp_nexthop_ipip_init(mlxsw_sp, ipipt, nh, dev); + err = mlxsw_sp_nexthop_ipip_init(mlxsw_sp, nh, dev); if (err) return err; mlxsw_sp_nexthop_rif_init(nh, &nh->ipip_entry->ol_lb->common);