From owner-svn-src-all@freebsd.org Thu Aug 2 08:43:55 2018 Return-Path: Delivered-To: svn-src-all@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 E76E2105EF16; Thu, 2 Aug 2018 08:43:54 +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.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 976797D23C; Thu, 2 Aug 2018 08:43:54 +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 7830375D2; Thu, 2 Aug 2018 08:43:54 +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 w728hsHS056189; Thu, 2 Aug 2018 08:43:54 GMT (envelope-from hselasky@FreeBSD.org) Received: (from hselasky@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w728hsCa056188; Thu, 2 Aug 2018 08:43:54 GMT (envelope-from hselasky@FreeBSD.org) Message-Id: <201808020843.w728hsCa056188@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: hselasky set sender to hselasky@FreeBSD.org using -f From: Hans Petter Selasky Date: Thu, 2 Aug 2018 08:43:54 +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: r337104 - stable/11/sys/dev/mlx5/mlx5_core X-SVN-Group: stable-11 X-SVN-Commit-Author: hselasky X-SVN-Commit-Paths: stable/11/sys/dev/mlx5/mlx5_core X-SVN-Commit-Revision: 337104 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 02 Aug 2018 08:43:55 -0000 Author: hselasky Date: Thu Aug 2 08:43:54 2018 New Revision: 337104 URL: https://svnweb.freebsd.org/changeset/base/337104 Log: MFC r336398: Make sure the state variable is set atomically instead of using a mutex in mlx5core. Device detach and setting error state may deadlock over the interface mutex like this: a) Detach code in mlx5en waits until error state is set while the interface mutex is locked. b) The set error handler needs to lock the interface mutex before it can set the error state. The solution is to use atomics to set the error state. Sponsored by: Mellanox Technologies Modified: stable/11/sys/dev/mlx5/mlx5_core/mlx5_health.c Directory Properties: stable/11/ (props changed) Modified: stable/11/sys/dev/mlx5/mlx5_core/mlx5_health.c ============================================================================== --- stable/11/sys/dev/mlx5/mlx5_core/mlx5_health.c Thu Aug 2 08:42:40 2018 (r337103) +++ stable/11/sys/dev/mlx5/mlx5_core/mlx5_health.c Thu Aug 2 08:43:54 2018 (r337104) @@ -219,21 +219,19 @@ void mlx5_enter_error_state(struct mlx5_core_dev *dev, u32 fatal_error; int lock = -EBUSY; - mutex_lock(&dev->intf_state_mutex); - if (dev->state == MLX5_DEVICE_STATE_INTERNAL_ERROR) { - goto unlock; - return; - } - fatal_error = check_fatal_sensors(dev); if (fatal_error || force) { + if (xchg(&dev->state, MLX5_DEVICE_STATE_INTERNAL_ERROR) == + MLX5_DEVICE_STATE_INTERNAL_ERROR) + return; if (!force) mlx5_core_err(dev, "internal state error detected\n"); - dev->state = MLX5_DEVICE_STATE_INTERNAL_ERROR; mlx5_trigger_cmd_completions(dev); } + mutex_lock(&dev->intf_state_mutex); + if (force) goto err_state_done; @@ -272,7 +270,6 @@ void mlx5_enter_error_state(struct mlx5_core_dev *dev, err_state_done: mlx5_core_event(dev, MLX5_DEV_EVENT_SYS_ERROR, 0); -unlock: mutex_unlock(&dev->intf_state_mutex); }