From owner-svn-src-head@freebsd.org Tue Oct 23 04:37:30 2018 Return-Path: Delivered-To: svn-src-head@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 8FC9A1036421; Tue, 23 Oct 2018 04:37:30 +0000 (UTC) (envelope-from erj@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 418DC89014; Tue, 23 Oct 2018 04:37:30 +0000 (UTC) (envelope-from erj@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 216142BDF; Tue, 23 Oct 2018 04:37:30 +0000 (UTC) (envelope-from erj@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w9N4bUBF050791; Tue, 23 Oct 2018 04:37:30 GMT (envelope-from erj@FreeBSD.org) Received: (from erj@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w9N4bTxf050789; Tue, 23 Oct 2018 04:37:29 GMT (envelope-from erj@FreeBSD.org) Message-Id: <201810230437.w9N4bTxf050789@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: erj set sender to erj@FreeBSD.org using -f From: Eric Joyner Date: Tue, 23 Oct 2018 04:37:29 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r339634 - in head/sys: kern net X-SVN-Group: head X-SVN-Commit-Author: erj X-SVN-Commit-Paths: in head/sys: kern net X-SVN-Commit-Revision: 339634 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 23 Oct 2018 04:37:30 -0000 Author: erj Date: Tue Oct 23 04:37:29 2018 New Revision: 339634 URL: https://svnweb.freebsd.org/changeset/base/339634 Log: iflib: drain enqueued tasks before detaching from taskqgroup The taskqgroup_detach function does not check if task is already enqueued when detaching it. This may lead to kernel panic if enqueued task starts after context state lock is destroyed. Ensure that the already enqueued admin tasks are executed before detaching them. The issue was discovered during validation of D16429. Unloading of if_ixlv followed by immediate removal of VFs with iovctl -D may lead to panic on NODEBUG kernel. As well, check if iflib is in detach before enqueueing new admin or iov tasks, to prevent new tasks from executing while the taskqgroup tasks are being drained. Submitted by: Krzysztof Galazka Reviewed by: shurd@, erj@ Sponsored by: Intel Corporation Differential Revision: https://reviews.freebsd.org/D17404 Modified: head/sys/kern/subr_gtaskqueue.c head/sys/net/iflib.c Modified: head/sys/kern/subr_gtaskqueue.c ============================================================================== --- head/sys/kern/subr_gtaskqueue.c Tue Oct 23 03:30:14 2018 (r339633) +++ head/sys/kern/subr_gtaskqueue.c Tue Oct 23 04:37:29 2018 (r339634) @@ -812,6 +812,7 @@ taskqgroup_detach(struct taskqgroup *qgroup, struct gr qgroup->tqg_queue[i].tgc_cnt--; LIST_REMOVE(gtask, gt_list); mtx_unlock(&qgroup->tqg_lock); + gtaskqueue_drain(gtask->gt_taskqueue, >ask->gt_task); gtask->gt_taskqueue = NULL; } Modified: head/sys/net/iflib.c ============================================================================== --- head/sys/net/iflib.c Tue Oct 23 03:30:14 2018 (r339633) +++ head/sys/net/iflib.c Tue Oct 23 04:37:29 2018 (r339634) @@ -2279,8 +2279,8 @@ iflib_timer(void *arg) STATE_LOCK(ctx); if_setdrvflagbits(ctx->ifc_ifp, IFF_DRV_OACTIVE, IFF_DRV_RUNNING); ctx->ifc_flags |= (IFC_DO_WATCHDOG|IFC_DO_RESET); - iflib_admin_intr_deferred(ctx); STATE_UNLOCK(ctx); + iflib_admin_intr_deferred(ctx); } static void @@ -2802,8 +2802,8 @@ iflib_rxeof(iflib_rxq_t rxq, qidx_t budget) err: STATE_LOCK(ctx); ctx->ifc_flags |= IFC_DO_RESET; - iflib_admin_intr_deferred(ctx); STATE_UNLOCK(ctx); + iflib_admin_intr_deferred(ctx); return (false); } @@ -5973,7 +5973,10 @@ iflib_admin_intr_deferred(if_ctx_t ctx) { #ifdef INVARIANTS struct grouptask *gtask; - +#endif + if (iflib_in_detach(ctx)) + return; +#ifdef INVARIANTS gtask = &ctx->ifc_admin_task; MPASS(gtask != NULL && gtask->gt_taskqueue != NULL); #endif @@ -5984,6 +5987,8 @@ iflib_admin_intr_deferred(if_ctx_t ctx) void iflib_iov_intr_deferred(if_ctx_t ctx) { + if (iflib_in_detach(ctx)) + return; GROUPTASK_ENQUEUE(&ctx->ifc_vflr_task); }