Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp3615075ybi; Sun, 14 Jul 2019 18:26:35 -0700 (PDT) X-Google-Smtp-Source: APXvYqwXJB33CYA8fIUXboQZgL00K04VV8RDEGI+eFZ0CTjRszAd2npUZti5q41i6gqZ0NoMt7F2 X-Received: by 2002:a17:90a:23ce:: with SMTP id g72mr26412969pje.77.1563153995675; Sun, 14 Jul 2019 18:26:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563153995; cv=none; d=google.com; s=arc-20160816; b=c7/ecfgZOuM8iuYV0RAxWrR4idiIBAeirSwpP5XmlNnv1QQSHUvrYAAQx4acIBbwtw BBwGfweZbg+q0X5F5nBQ0JG/OG/QzRbh+E+/jsTgPo5ugFQHbtVjv3x0fuBasItT0za2 Q1kLIA54vtQhj40aM6t/UUt/apAiEW+KtqA+Oq+Wgq8BB07rJdqfsY78hakLOswBAYzT RIDvUG+jx4w/lS5N9xyck1dczVicAyx+Jv43RHjtOdomiG8x17p4SBpZhRnxE6LSea2s gmzUgH1AD/j6shylUruEtCXH6GP0qk38O5b67A9pwKQVoORcOK63NtW4QVZVasxMRS+X Zb3g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=MXtprjYX3LMZPcPvIkCQpHQOi7CXiEJzMLuO2MOHDFY=; b=UTL3szCEEToXt59aKTMgy58z57nhcgICKabq4xuwU99bfSbJBI7H45u+2gFpQxcolu O5WB2CiHkPna2E4Qn0PdcwaSEY2rKJ65ZR9AORgj1tM+Y9X7lXOpmmgi4aMahxKw+VOc 4fZI0nZZ+HLHYeDf7/bBzetH+vCyYoNzogKtqWq4ykBGUTYgPAkWG9AtrSVbfTRLIWyC Ro13C8LyCtZU7hTbC/ed6lo5HqG8zNvnV4+dClP1u8dK3y4ihnTHUk2ZKTA3OGYfn9wd LydrO9bqIF8wmvEeqyt/OYl9Xice+Rcz2e+V7lOCulwUZpU7YXRn6JZpfSZk02RSQo1h gCkg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=JFsY4oNs; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q9si15288487pfl.287.2019.07.14.18.26.19; Sun, 14 Jul 2019 18:26:35 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=JFsY4oNs; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729000AbfGOB0A (ORCPT + 99 others); Sun, 14 Jul 2019 21:26:00 -0400 Received: from mail-wm1-f65.google.com ([209.85.128.65]:37707 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727006AbfGOB0A (ORCPT ); Sun, 14 Jul 2019 21:26:00 -0400 Received: by mail-wm1-f65.google.com with SMTP id f17so13475785wme.2; Sun, 14 Jul 2019 18:25:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=MXtprjYX3LMZPcPvIkCQpHQOi7CXiEJzMLuO2MOHDFY=; b=JFsY4oNs0InJ0zKTLAT5/DNZA3GeQ5vUGlzj4vJoyukxjE9wh31D0X5E2dFcXBkuu9 5baYD+BB44bzldFblCMubnJYeJQHfm+bo8qvYWrq7FCoCCyNcEos9rL8vCxW80743jj4 djzYr+jT48v68VGOmXfKBu3szUoeqTYbIoQcYpMzOKVoMpyiZN+psoOl5RnCea+QznzW u/GrX5TTepNy2ZGNckHIRJWkEtOBfIPZsFJnVrI6VK85cFq90YQ0oV33WqMnvuGZRV4N 5HhfV9vrDA1aLeatn8qE221SvZsxUuJzvEFhzSgrEuapTnXcocerUWiLIDXfdgvxUkZJ VDfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=MXtprjYX3LMZPcPvIkCQpHQOi7CXiEJzMLuO2MOHDFY=; b=DNX1pTWBCiEWhroEWUAJRCDdNUOhXN1W+yKcYjiHdjqLr/ofhVIdnvYbbp6KB45nvK Fa/X+elZB5M5OcbpBWwRbdlSgJ6OadZX1Oq1+WT0+XIj6c/rSttW0yQaiBrz0wS3djrc agFYBZ7pzzLJ+DjxDfcYFKlQaiadbfxWzSoBR4uD2fgULti7SVue420lfPko1OiRKk2Y 7RuA/YrX7Oj72t/bGA1BtpbAx2yT4ogT6NwbMNlYoE1wubw6Pv1dhoo6MPv7ckFNbWak Z0cL7Xsfs87UZAog0j1UPBsMatbPts5c4eGTMywtTmv2TbxA8o9TDmBYjabCaoAGhHJ6 Qe5g== X-Gm-Message-State: APjAAAVenMoK/7whlCGPlyuAdFu40PH/BaUq/Lcv9YT/LPc85RO2oSps b1TZtTykqh3bDgsf1q478JHBQ1vEx2irAPyzfeg= X-Received: by 2002:a05:600c:204c:: with SMTP id p12mr20916333wmg.121.1563153957506; Sun, 14 Jul 2019 18:25:57 -0700 (PDT) MIME-Version: 1.0 References: <1563087801-7373-1-git-send-email-wang6495@umn.edu> In-Reply-To: <1563087801-7373-1-git-send-email-wang6495@umn.edu> From: Ming Lei Date: Mon, 15 Jul 2019 09:25:46 +0800 Message-ID: Subject: Re: [PATCH] blk-mq: fix a memory leak bug To: Wenwen Wang Cc: Wenwen Wang , Jens Axboe , "open list:BLOCK LAYER" , open list Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Jul 14, 2019 at 3:04 PM Wenwen Wang wrote: > > From: Wenwen Wang > > In blk_mq_init_allocated_queue(), a kernel buffer is allocated through > kcalloc_node() to hold hardware dispatch queues in the request queue 'q', > i.e., 'q->queue_hw_ctx'. Later on, if the blk-mq device has no scheduler > set, a scheduler will be initialized through elevator_init_mq(). If this > initialization fails, blk_mq_init_allocated_queue() needs to be terminated > with an error code returned to indicate this failure. However, the > allocated buffer is not freed on this execution path, leading to a memory > leak bug. Moreover, the required cleanup work is also missed on this path. > > To fix the above issues, free the allocated buffer and invoke the cleanup > functions. > > Signed-off-by: Wenwen Wang > --- > block/blk-mq.c | 8 ++++---- > 1 file changed, 4 insertions(+), 4 deletions(-) > > diff --git a/block/blk-mq.c b/block/blk-mq.c > index e5ef40c..04fe077 100644 > --- a/block/blk-mq.c > +++ b/block/blk-mq.c > @@ -2845,6 +2845,8 @@ static unsigned int nr_hw_queues(struct blk_mq_tag_set *set) > struct request_queue *blk_mq_init_allocated_queue(struct blk_mq_tag_set *set, > struct request_queue *q) > { > + int ret = -ENOMEM; > + The above isn't necessary because the function always returns ERR_PTR(-ENOMEM) in case of failure. > /* mark the queue as mq asap */ > q->mq_ops = set->ops; > > @@ -2906,11 +2908,9 @@ struct request_queue *blk_mq_init_allocated_queue(struct blk_mq_tag_set *set, > blk_mq_map_swqueue(q); > > if (!(set->flags & BLK_MQ_F_NO_SCHED)) { > - int ret; > - > ret = elevator_init_mq(q); > if (ret) > - return ERR_PTR(ret); > + goto err_hctxs; The above change itself is fine. However, elevator_init_mq() shouldn't return failure since none should work any time. That said 'none' should be fallback to in case that default mq-deadline can't be initialized. thanks, Ming Lei