From patchwork Tue Jul 23 15:00:17 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlos Maiolino X-Patchwork-Id: 11054639 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 76156912 for ; Tue, 23 Jul 2019 15:00:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 663EE285F0 for ; Tue, 23 Jul 2019 15:00:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5A6C528609; Tue, 23 Jul 2019 15:00:23 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0D002285F2 for ; Tue, 23 Jul 2019 15:00:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730814AbfGWPAW (ORCPT ); Tue, 23 Jul 2019 11:00:22 -0400 Received: from mx1.redhat.com ([209.132.183.28]:47016 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730674AbfGWPAW (ORCPT ); Tue, 23 Jul 2019 11:00:22 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id F1A4C307D9CE for ; Tue, 23 Jul 2019 15:00:21 +0000 (UTC) Received: from pegasus.maiolino.com (ovpn-204-213.brq.redhat.com [10.40.204.213]) by smtp.corp.redhat.com (Postfix) with ESMTP id 60BD8104B4FC for ; Tue, 23 Jul 2019 15:00:21 +0000 (UTC) From: Carlos Maiolino To: linux-xfs@vger.kernel.org Subject: [PATCH] xfs: Do not free xfs_extent_busy from inside a spinlock Date: Tue, 23 Jul 2019 17:00:17 +0200 Message-Id: <20190723150017.31891-1-cmaiolino@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Tue, 23 Jul 2019 15:00:22 +0000 (UTC) Sender: linux-xfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP xfs_extent_busy_clear_one() calls kmem_free() with the pag spinlock locked. Fix this by adding a new temporary list, and, make xfs_extent_busy_clear_one() to move the extent_busy items to this new list, instead of freeing them. Free the objects in the temporary list after we drop the pagb_lock Reported-by: Jeff Layton Signed-off-by: Carlos Maiolino --- fs/xfs/xfs_extent_busy.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/fs/xfs/xfs_extent_busy.c b/fs/xfs/xfs_extent_busy.c index 0ed68379e551..0a7dcf03340b 100644 --- a/fs/xfs/xfs_extent_busy.c +++ b/fs/xfs/xfs_extent_busy.c @@ -523,7 +523,8 @@ STATIC void xfs_extent_busy_clear_one( struct xfs_mount *mp, struct xfs_perag *pag, - struct xfs_extent_busy *busyp) + struct xfs_extent_busy *busyp, + struct list_head *list) { if (busyp->length) { trace_xfs_extent_busy_clear(mp, busyp->agno, busyp->bno, @@ -531,8 +532,7 @@ xfs_extent_busy_clear_one( rb_erase(&busyp->rb_node, &pag->pagb_tree); } - list_del_init(&busyp->list); - kmem_free(busyp); + list_move(&busyp->list, list); } static void @@ -565,6 +565,7 @@ xfs_extent_busy_clear( struct xfs_perag *pag = NULL; xfs_agnumber_t agno = NULLAGNUMBER; bool wakeup = false; + LIST_HEAD(busy_list); list_for_each_entry_safe(busyp, n, list, list) { if (busyp->agno != agno) { @@ -580,13 +581,18 @@ xfs_extent_busy_clear( !(busyp->flags & XFS_EXTENT_BUSY_SKIP_DISCARD)) { busyp->flags = XFS_EXTENT_BUSY_DISCARDED; } else { - xfs_extent_busy_clear_one(mp, pag, busyp); + xfs_extent_busy_clear_one(mp, pag, busyp, &busy_list); wakeup = true; } } if (pag) xfs_extent_busy_put_pag(pag, wakeup); + + list_for_each_entry_safe(busyp, n, &busy_list, list) { + list_del_init(&busyp->list); + kmem_free(busyp); + } } /*