Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp4534977imm; Mon, 17 Sep 2018 16:02:58 -0700 (PDT) X-Google-Smtp-Source: ANB0VdauQwBFejMy9xDplQt5muvy38PiiRbMfFlo5MrLzSA8utpi5UOpgIh+QfU56vLRwTB3/CVJ X-Received: by 2002:a17:902:2e01:: with SMTP id q1-v6mr26952641plb.40.1537225377996; Mon, 17 Sep 2018 16:02:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537225377; cv=none; d=google.com; s=arc-20160816; b=mH7q4mbeUwCdkZnBjM6+tRYe9w/ODoKERozYHnfAWSzOhUge0rMJZTPo3YtJYFL1oX X/CenQL4/+7r5vmZWK1bKPOlV/mHsTvPx/LcZ5Gtej2CF6zi+0ub6EX3z/YYjZtxVcpJ 0WvJayFXpkghzQKtruPzzulfRDQjFqDxLgaFSrA3cUyMB5dwIX5P8ZP7wMvty2+oXlUK oJQEzfI2vcWAZSpkBnF1/dHNBgLVmhCv40i1Q9G6qQ8DuYYqbWiM0G8CcYRNJvUyLZJB i0R2XuRL91eIYDOmLP0ov+5LgMSo8SRclGN6qB0UqHTCQZHdbypk+ueWAdx8CsDVskJN ht3Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from; bh=mUxLB73b+a2eyyFReODDVlzbI1Osndo5vxyrrfWQz1Q=; b=HRp5K8ZUep39d731uA2oQuGAbN+4IAzArcfHf8g6B9+CFzbobceUAkdT9Qtwjwc21t 4snyK9l1eFKehmM6aobHvKOcFLmZpg8uYzJC4P10D6gAjMUGo3gnDfTU2u+CwSheVcAo fGwGWG+h7w5j2rI/dZMCSDgYDlIq89RJKLEmfOaGjWf5W6uXt5k/qFcDjhWEqHGumm2f YALWLefvstFgUPsOCs2/FFAfQXYzEDToIDN0ZlR8dblSWHamv1ng1boyxcrcy1Ya52sQ BpEEiKaQhJPaJ7P9JIipHSYEmMejKxRT1UbLZkRBP0CPOD2fNaW4S/JKOh2NvpW0D3gL E+Eg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d81-v6si18019962pfm.226.2018.09.17.16.02.43; Mon, 17 Sep 2018 16:02:57 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730160AbeIREam (ORCPT + 99 others); Tue, 18 Sep 2018 00:30:42 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:48236 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729660AbeIREal (ORCPT ); Tue, 18 Sep 2018 00:30:41 -0400 Received: from localhost (li1825-44.members.linode.com [172.104.248.44]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 601F1C7D; Mon, 17 Sep 2018 23:01:13 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Ewan D. Milne" , Christoph Hellwig , Bart Van Assche , Omar Sandoval , Ming Lei , Jens Axboe , Sasha Levin Subject: [PATCH 4.14 032/126] blk-mq: fix updating tags depth Date: Tue, 18 Sep 2018 00:41:20 +0200 Message-Id: <20180917211706.886465300@linuxfoundation.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20180917211703.481236999@linuxfoundation.org> References: <20180917211703.481236999@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Ming Lei [ Upstream commit 75d6e175fc511e95ae3eb8f708680133bc211ed3 ] The passed 'nr' from userspace represents the total depth, meantime inside 'struct blk_mq_tags', 'nr_tags' stores the total tag depth, and 'nr_reserved_tags' stores the reserved part. There are two issues in blk_mq_tag_update_depth() now: 1) for growing tags, we should have used the passed 'nr', and keep the number of reserved tags not changed. 2) the passed 'nr' should have been used for checking against 'tags->nr_tags', instead of number of the normal part. This patch fixes the above two cases, and avoids kernel crash caused by wrong resizing sbitmap queue. Cc: "Ewan D. Milne" Cc: Christoph Hellwig Cc: Bart Van Assche Cc: Omar Sandoval Tested by: Marco Patalano Signed-off-by: Ming Lei Signed-off-by: Jens Axboe Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- block/blk-mq-tag.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) --- a/block/blk-mq-tag.c +++ b/block/blk-mq-tag.c @@ -416,8 +416,6 @@ int blk_mq_tag_update_depth(struct blk_m if (tdepth <= tags->nr_reserved_tags) return -EINVAL; - tdepth -= tags->nr_reserved_tags; - /* * If we are allowed to grow beyond the original size, allocate * a new set of tags before freeing the old one. @@ -437,7 +435,8 @@ int blk_mq_tag_update_depth(struct blk_m if (tdepth > 16 * BLKDEV_MAX_RQ) return -EINVAL; - new = blk_mq_alloc_rq_map(set, hctx->queue_num, tdepth, 0); + new = blk_mq_alloc_rq_map(set, hctx->queue_num, tdepth, + tags->nr_reserved_tags); if (!new) return -ENOMEM; ret = blk_mq_alloc_rqs(set, new, hctx->queue_num, tdepth); @@ -454,7 +453,8 @@ int blk_mq_tag_update_depth(struct blk_m * Don't need (or can't) update reserved tags here, they * remain static and should never need resizing. */ - sbitmap_queue_resize(&tags->bitmap_tags, tdepth); + sbitmap_queue_resize(&tags->bitmap_tags, + tdepth - tags->nr_reserved_tags); } return 0;