From patchwork Wed Jul 14 15:06:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 476772 Delivered-To: patch@linaro.org Received: by 2002:a02:c94a:0:0:0:0:0 with SMTP id u10csp659830jao; Wed, 14 Jul 2021 08:11:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyLjf+1grrGJVSgQ9EATvhlo7xkSOgCRyUb7368E+rT48Dc3j/RGQHfI4I6H7121XAfFbr7 X-Received: by 2002:a17:906:a18b:: with SMTP id s11mr13097525ejy.8.1626275505803; Wed, 14 Jul 2021 08:11:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626275505; cv=none; d=google.com; s=arc-20160816; b=V+gP5uNZgdjvH3HTkSa8/+rzBjBN44Ak4jte8g+4+VQRwaNCdbV2mkVxPyvvvvbO5f d34oxfSlhjW55bMOYrPhX2Xu2e6b+9KG6l6kb4QnTgfISk8g4HwWZQ3f1VjplDdeHrlE 3Bl+OlxIlEXBeoTtbGubH2IQ6eftkPTGJrHNaqwoqnJVO+56NRmuxkermtAfPUzhO6bX /5uEkP0yQlhsN3Zj4TUqPUdFpLpeB7kky9NaAqVbILRynD6DQZo8qSI195cASkkC0fNc vjqZqMSFCVdANgT/AVUveniFkrs56N2CtlH/IuoR9dwkvKZuKhUXDA8qZC7qai+J1NKj LizQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from; bh=tOUfeCcafsa96j5n0mssMo3v/7zUKcZl3lOld/0sjZM=; b=ZY+w9ZZ/1BUMMZJo+xt2G9zVN7kCiUSUlpRJTzqmGpUyRrt6z22X3khHPtaj+6t6ft f7Zf/EPIgI661ji5tuUm3HlIFVj5KOua4At9cgTG3RA/wBLAgGxyrA436m7xdBC1SZsZ PYVXgFM80QgR6PQsmG/cycLKDyECt9pqj4ojs9rsnHlJ9VN6gxkA8sGVYFHTayud1jv6 ipUI2Lznf1JukzuEBJUUB0/wlTAymNLFw+BrfA/mSqmBPeT+kXQUQKIqyTSR6D2rCWbr gISgz0l5jPxIeIvrZw6CmiAi/lvzaSyrFDJF6k9Ov9qkefw7pxmFhtTzxzSNKtfCQHVE RLcw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-scsi-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-scsi-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id eb13si3535737edb.290.2021.07.14.08.11.45 for ; Wed, 14 Jul 2021 08:11:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-scsi-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-scsi-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-scsi-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239731AbhGNPOb (ORCPT ); Wed, 14 Jul 2021 11:14:31 -0400 Received: from frasgout.his.huawei.com ([185.176.79.56]:3412 "EHLO frasgout.his.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239686AbhGNPOZ (ORCPT ); Wed, 14 Jul 2021 11:14:25 -0400 Received: from fraeml739-chm.china.huawei.com (unknown [172.18.147.226]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4GQ0w14vGsz6D97R; Wed, 14 Jul 2021 22:57:05 +0800 (CST) Received: from lhreml724-chm.china.huawei.com (10.201.108.75) by fraeml739-chm.china.huawei.com (10.206.15.220) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Wed, 14 Jul 2021 17:11:32 +0200 Received: from localhost.localdomain (10.69.192.58) by lhreml724-chm.china.huawei.com (10.201.108.75) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Wed, 14 Jul 2021 16:11:30 +0100 From: John Garry To: CC: , , , , , , John Garry Subject: [PATCH 9/9] blk-mq: Clear mappings for shared sbitmap sched static rqs Date: Wed, 14 Jul 2021 23:06:35 +0800 Message-ID: <1626275195-215652-10-git-send-email-john.garry@huawei.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1626275195-215652-1-git-send-email-john.garry@huawei.com> References: <1626275195-215652-1-git-send-email-john.garry@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.69.192.58] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To lhreml724-chm.china.huawei.com (10.201.108.75) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org To avoid use-after-free in accessing stale requests in the driver tags rqs[], clear the mappings for the request queue static rqs. Signed-off-by: John Garry --- block/blk-mq-sched.c | 1 + block/blk-mq.h | 2 ++ 2 files changed, 3 insertions(+) -- 2.26.2 diff --git a/block/blk-mq-sched.c b/block/blk-mq-sched.c index 7b5c46647820..f1cea7f3bc68 100644 --- a/block/blk-mq-sched.c +++ b/block/blk-mq-sched.c @@ -711,6 +711,7 @@ void blk_mq_sched_free_requests(struct request_queue *q) queue_for_each_hw_ctx(q, hctx, i) { if (hctx->sched_tags) { if (blk_mq_is_sbitmap_shared(q->tag_set->flags)) { + blk_mq_clear_rq_mapping(q->tag_set, i, &q->page_list); } else { blk_mq_free_rqs(q->tag_set, hctx->sched_tags, i); } diff --git a/block/blk-mq.h b/block/blk-mq.h index 1e0fbb06412b..a5b7aa7a07b9 100644 --- a/block/blk-mq.h +++ b/block/blk-mq.h @@ -69,6 +69,8 @@ int blk_mq_alloc_rqs(struct blk_mq_tag_set *set, struct blk_mq_tags *tags, int __blk_mq_alloc_rqs(struct blk_mq_tag_set *set, unsigned int hctx_idx, unsigned int depth, struct list_head *page_list, struct request **static_rqs); +void blk_mq_clear_rq_mapping(struct blk_mq_tag_set *set, unsigned int hctx_idx, + struct list_head *page_list); /* * Internal helpers for request insertion into sw queues