Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp1998189pxu; Fri, 9 Oct 2020 05:31:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxIiZneSmUd4GDIBFr4Pb1x4pN7NY58OqyEkCbZ6efALRr+0dxq52aC94nxX8BjNM/NkR3B X-Received: by 2002:a17:906:5488:: with SMTP id r8mr13835397ejo.483.1602246688673; Fri, 09 Oct 2020 05:31:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1602246688; cv=none; d=google.com; s=arc-20160816; b=G8an0CeDdYHiEHoQc+QDU/RounFLv3c5O1tbWvWeEffwulV5/bOeYrKJV6B+ibgJg+ eR2DpHpIVqFIQabJfRpAMFqk35jfGyY8kGMCQw2Yr2CU7y6NFHzBCeL5Ix8jIVTpxTOy Q1qBjVx/GyCgkKSWibNd62L7T4jL3DdgbXMEk7+kIgOv2OvEn6ekFFgeuTCdV/99bWN1 ise8PdAZgfLVtpg9B4z57wGszbGQEbQOuwagLCxHEML+sqQM7A/VPeZ9BffhjIMbZBpY eFmvkYLFYv0yrlHHCGe1DhFPmb/iCzxaYc18+q3c+BbkJAoYNevtHD3/kDBdXjXeBIQH OpxQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=a4XUeXXmXlqIj+XqwTZZwDnHthCD+pdCzaZWs+qGYP4=; b=hT202nA6GJtSQm8snqr3i0VUOrQKlwsY4zunoirNCio1E6aMORd1VJhK7risqzg2lI po+uwfHEZ0UGk7RtsP1DXn2kZpME183nmnuMj230wrTqGnIlgSBdB3B8RQF5PaHsUAIy r7x1Du1tfWr4LqV4SfbLyPjk+sf8T3Z5itl/shYP+cJQ2BiiUZm3fCf7dZpUWcp4FXhB XlOiUYUYzhQqbjZkXVcyZs55hwISB/crnPoxkeqsG1r9VSCHpE6XN92vcVNGaIlKBUL+ 2qhdqpWBPh2Ux+Odx/dHDbjPVGyDm0ATziXvuu1tefgVUtJmhogHwdRinjvLAijU7job 88qw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=DNbByV2x; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bz16si5753047ejc.325.2020.10.09.05.31.05; Fri, 09 Oct 2020 05:31:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=DNbByV2x; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1733222AbgJIJq5 (ORCPT + 99 others); Fri, 9 Oct 2020 05:46:57 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:45239 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725917AbgJIJq5 (ORCPT ); Fri, 9 Oct 2020 05:46:57 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602236816; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=a4XUeXXmXlqIj+XqwTZZwDnHthCD+pdCzaZWs+qGYP4=; b=DNbByV2x8FPdM1ORiRHFF3HJ6vhN2WFNWSeAGyf6niy/GnYnpFDz4fLy+tzLaXZcHNncXX 7Zu358wBcethdBxuI9GccZbnvYhsAMRuuM9mdDWK7zH815fu4U/eeKDGb1gFsIPOS/8gCz eyxOt/aJpoIKHhHp0S75GcvCMS6U7Bc= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-103-S4eEBrtrOdWvJ9wbhG3QQA-1; Fri, 09 Oct 2020 05:46:52 -0400 X-MC-Unique: S4eEBrtrOdWvJ9wbhG3QQA-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id BC6271007465; Fri, 9 Oct 2020 09:46:50 +0000 (UTC) Received: from T590 (ovpn-13-88.pek2.redhat.com [10.72.13.88]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6006B6266E; Fri, 9 Oct 2020 09:46:43 +0000 (UTC) Date: Fri, 9 Oct 2020 17:46:40 +0800 From: Ming Lei To: Yang Yang Cc: Jens Axboe , Bart Van Assche , Hannes Reinecke , linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, onlyfever@icloud.com Subject: Re: [PATCH] blk-mq: move cancel of hctx->run_work to the front of blk_exit_queue Message-ID: <20201009094640.GA53552@T590> References: <20201009080015.3217-1-yang.yang@vivo.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20201009080015.3217-1-yang.yang@vivo.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Oct 09, 2020 at 01:00:14AM -0700, Yang Yang wrote: > blk_exit_queue will free elevator_data, while blk_mq_run_work_fn > will access it. Move cancel of hctx->run_work to the front of > blk_exit_queue to avoid use-after-free. > > Fixes: 1b97871b501f ("blk-mq: move cancel of hctx->run_work into blk_mq_hw_sysfs_release") > Signed-off-by: Yang Yang > --- > block/blk-mq-sysfs.c | 2 -- > block/blk-sysfs.c | 9 ++++++++- > 2 files changed, 8 insertions(+), 3 deletions(-) > > diff --git a/block/blk-mq-sysfs.c b/block/blk-mq-sysfs.c > index 062229395a50..7b52e7657b2d 100644 > --- a/block/blk-mq-sysfs.c > +++ b/block/blk-mq-sysfs.c > @@ -36,8 +36,6 @@ static void blk_mq_hw_sysfs_release(struct kobject *kobj) > struct blk_mq_hw_ctx *hctx = container_of(kobj, struct blk_mq_hw_ctx, > kobj); > > - cancel_delayed_work_sync(&hctx->run_work); > - > if (hctx->flags & BLK_MQ_F_BLOCKING) > cleanup_srcu_struct(hctx->srcu); > blk_free_flush_queue(hctx->fq); > diff --git a/block/blk-sysfs.c b/block/blk-sysfs.c > index 7dda709f3ccb..8c6bafc801dd 100644 > --- a/block/blk-sysfs.c > +++ b/block/blk-sysfs.c > @@ -934,9 +934,16 @@ static void blk_release_queue(struct kobject *kobj) > > blk_free_queue_stats(q->stats); > > - if (queue_is_mq(q)) > + if (queue_is_mq(q)) { > + struct blk_mq_hw_ctx *hctx; > + int i; > + > cancel_delayed_work_sync(&q->requeue_work); > > + queue_for_each_hw_ctx(q, hctx, i) > + cancel_delayed_work_sync(&hctx->run_work); > + } > + Looks fine: Reviewed-by: Ming Lei Thanks, Ming