From owner-svn-src-all@freebsd.org Tue Jul 17 10:20:02 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 833261035E16; Tue, 17 Jul 2018 10:20:02 +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 38AA1818CB; Tue, 17 Jul 2018 10:20:02 +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 1B0D11FCE; Tue, 17 Jul 2018 10:20:02 +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 w6HAK1rk045662; Tue, 17 Jul 2018 10:20:01 GMT (envelope-from hselasky@FreeBSD.org) Received: (from hselasky@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w6HAK1IT045660; Tue, 17 Jul 2018 10:20:01 GMT (envelope-from hselasky@FreeBSD.org) Message-Id: <201807171020.w6HAK1IT045660@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: hselasky set sender to hselasky@FreeBSD.org using -f From: Hans Petter Selasky Date: Tue, 17 Jul 2018 10:20:01 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r336398 - head/sys/dev/mlx5/mlx5_core X-SVN-Group: head X-SVN-Commit-Author: hselasky X-SVN-Commit-Paths: head/sys/dev/mlx5/mlx5_core X-SVN-Commit-Revision: 336398 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: Tue, 17 Jul 2018 10:20:02 -0000 Author: hselasky Date: Tue Jul 17 10:20:01 2018 New Revision: 336398 URL: https://svnweb.freebsd.org/changeset/base/336398 Log: 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. MFC after: 1 week Sponsored by: Mellanox Technologies Modified: head/sys/dev/mlx5/mlx5_core/mlx5_health.c Modified: head/sys/dev/mlx5/mlx5_core/mlx5_health.c ============================================================================== --- head/sys/dev/mlx5/mlx5_core/mlx5_health.c Tue Jul 17 10:16:32 2018 (r336397) +++ head/sys/dev/mlx5/mlx5_core/mlx5_health.c Tue Jul 17 10:20:01 2018 (r336398) @@ -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); }