From owner-svn-src-stable@freebsd.org Wed Dec 12 13:05:47 2018 Return-Path: Delivered-To: svn-src-stable@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 0247E130E290; Wed, 12 Dec 2018 13:05:47 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 9D36593873; Wed, 12 Dec 2018 13:05:46 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 908F28571; Wed, 12 Dec 2018 13:05:46 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id wBCD5kn0004262; Wed, 12 Dec 2018 13:05:46 GMT (envelope-from hselasky@FreeBSD.org) Received: (from hselasky@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id wBCD5jub004259; Wed, 12 Dec 2018 13:05:45 GMT (envelope-from hselasky@FreeBSD.org) Message-Id: <201812121305.wBCD5jub004259@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: hselasky set sender to hselasky@FreeBSD.org using -f From: Hans Petter Selasky Date: Wed, 12 Dec 2018 13:05:45 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r341977 - stable/11/sys/dev/mlx5/mlx5_en X-SVN-Group: stable-11 X-SVN-Commit-Author: hselasky X-SVN-Commit-Paths: stable/11/sys/dev/mlx5/mlx5_en X-SVN-Commit-Revision: 341977 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 9D36593873 X-Spamd-Bar: / Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-0.61 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_SHORT(-0.61)[-0.608,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US] X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 12 Dec 2018 13:05:47 -0000 Author: hselasky Date: Wed Dec 12 13:05:45 2018 New Revision: 341977 URL: https://svnweb.freebsd.org/changeset/base/341977 Log: MFC r341582: mlx5en: Fix race in mlx5e_ethtool_debug_stats(). Writing to the debug stats variable must be locked, else serialization will be lost which might cause various kernel panics due to creating and destroying sysctls out of order. Make sure the sysctl context is initialized after freeing the sysctl nodes, else they can be freed twice. Sponsored by: Mellanox Technologies Modified: stable/11/sys/dev/mlx5/mlx5_en/en.h stable/11/sys/dev/mlx5/mlx5_en/mlx5_en_ethtool.c stable/11/sys/dev/mlx5/mlx5_en/mlx5_en_main.c Directory Properties: stable/11/ (props changed) Modified: stable/11/sys/dev/mlx5/mlx5_en/en.h ============================================================================== --- stable/11/sys/dev/mlx5/mlx5_en/en.h Wed Dec 12 13:04:53 2018 (r341976) +++ stable/11/sys/dev/mlx5/mlx5_en/en.h Wed Dec 12 13:05:45 2018 (r341977) @@ -779,7 +779,6 @@ struct mlx5e_priv { struct sysctl_oid *sysctl_hw; int sysctl_debug; struct mlx5e_stats stats; - struct sysctl_ctx_list sysctl_ctx_channel_debug; int counter_set_id; struct workqueue_struct *wq; Modified: stable/11/sys/dev/mlx5/mlx5_en/mlx5_en_ethtool.c ============================================================================== --- stable/11/sys/dev/mlx5/mlx5_en/mlx5_en_ethtool.c Wed Dec 12 13:04:53 2018 (r341976) +++ stable/11/sys/dev/mlx5/mlx5_en/mlx5_en_ethtool.c Wed Dec 12 13:05:45 2018 (r341977) @@ -1056,33 +1056,34 @@ static int mlx5e_ethtool_debug_stats(SYSCTL_HANDLER_ARGS) { struct mlx5e_priv *priv = arg1; - int error, sys_debug; + int sys_debug; + int error; + PRIV_LOCK(priv); sys_debug = priv->sysctl_debug; - error = sysctl_handle_int(oidp, &priv->sysctl_debug, 0, req); + error = sysctl_handle_int(oidp, &sys_debug, 0, req); if (error != 0 || !req->newptr) - return (error); - priv->sysctl_debug = priv->sysctl_debug != 0; + goto done; + sys_debug = sys_debug ? 1 : 0; if (sys_debug == priv->sysctl_debug) - return (0); + goto done; - PRIV_LOCK(priv); - if (priv->sysctl_debug) { + if ((priv->sysctl_debug = sys_debug)) { mlx5e_create_stats(&priv->stats.port_stats_debug.ctx, SYSCTL_CHILDREN(priv->sysctl_ifnet), "debug_stats", mlx5e_port_stats_debug_desc, MLX5E_PORT_STATS_DEBUG_NUM, priv->stats.port_stats_debug.arg); - SYSCTL_ADD_PROC(&priv->sysctl_ctx_channel_debug, + SYSCTL_ADD_PROC(&priv->stats.port_stats_debug.ctx, SYSCTL_CHILDREN(priv->sysctl_ifnet), OID_AUTO, "hw_ctx_debug", CTLFLAG_RD | CTLFLAG_MPSAFE | CTLTYPE_STRING, priv, 0, mlx5e_ethtool_debug_channel_info, "S", ""); } else { sysctl_ctx_free(&priv->stats.port_stats_debug.ctx); - sysctl_ctx_free(&priv->sysctl_ctx_channel_debug); } +done: PRIV_UNLOCK(priv); - return (0); + return (error); } static void Modified: stable/11/sys/dev/mlx5/mlx5_en/mlx5_en_main.c ============================================================================== --- stable/11/sys/dev/mlx5/mlx5_en/mlx5_en_main.c Wed Dec 12 13:04:53 2018 (r341976) +++ stable/11/sys/dev/mlx5/mlx5_en/mlx5_en_main.c Wed Dec 12 13:05:45 2018 (r341977) @@ -3512,8 +3512,6 @@ mlx5e_create_ifp(struct mlx5_core_dev *mdev) if (ifp->if_capenable & IFCAP_TXCSUM_IPV6) ifp->if_hwassist |= (CSUM_UDP_IPV6 | CSUM_TCP_IPV6); - sysctl_ctx_init(&priv->sysctl_ctx_channel_debug); - /* ifnet sysctl tree */ sysctl_ctx_init(&priv->sysctl_ctx); priv->sysctl_ifnet = SYSCTL_ADD_NODE(&priv->sysctl_ctx, SYSCTL_STATIC_CHILDREN(_dev), @@ -3685,8 +3683,8 @@ err_free_wq: err_free_sysctl: sysctl_ctx_free(&priv->sysctl_ctx); - sysctl_ctx_free(&priv->sysctl_ctx_channel_debug); - + if (priv->sysctl_debug) + sysctl_ctx_free(&priv->stats.port_stats_debug.ctx); if_free(ifp); err_free_priv: @@ -3726,13 +3724,11 @@ mlx5e_destroy_ifp(struct mlx5_core_dev *mdev, void *vp if_free(ifp); /* destroy all remaining sysctl nodes */ - if (priv->sysctl_debug) { - sysctl_ctx_free(&priv->sysctl_ctx_channel_debug); - sysctl_ctx_free(&priv->stats.port_stats_debug.ctx); - } sysctl_ctx_free(&priv->stats.vport.ctx); sysctl_ctx_free(&priv->stats.pport.ctx); sysctl_ctx_free(&priv->sysctl_ctx); + if (priv->sysctl_debug) + sysctl_ctx_free(&priv->stats.port_stats_debug.ctx); mlx5_core_destroy_mkey(priv->mdev, &priv->mr); mlx5_dealloc_transport_domain(priv->mdev, priv->tdn);