Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp381011yba; Fri, 3 May 2019 03:45:09 -0700 (PDT) X-Google-Smtp-Source: APXvYqwd0hHBfojUCqglRaoh3XH9v7j2RXJKy5vrMp0lIzUfUwR6DR0sIh9C6ymBvRrnON62FYLW X-Received: by 2002:a63:1357:: with SMTP id 23mr1361761pgt.437.1556880309722; Fri, 03 May 2019 03:45:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556880309; cv=none; d=google.com; s=arc-20160816; b=HvjL/gmIwvPLGKdjGFPhofixMy8IJnmR94qHDnhtpGY336m1WSFTTjiO03yeZKKwUT VOVby39dZcxVciAqGyIhzS48HXTwZTMGjISgwo0MCjqYtc1XCWFMLH+6bP+xK7O1I2YR Q/8mQiICGiekJyvz9iDR4pQVDVVeTIG9Afzw6r+s8XrLySnzSq0C1ZHa1dIcZtNZ0w5h hWrrViWV9B46FXSo+vRs4Dx3kfsTeZ8QAi/rcbNHFbiDSKwHdw0NH1X5b7RL+tymzQlZ Nu97Tqbt19uC4UxyUD3EGLpx4daImhXYBh3R0QmBg3NJ/Wp0KeRNWlJBwk+XHYrP8nM1 MRJw== 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=kMsfO5bwv4fct0CXFpp+M6L+nA/SFqgtUnj/08mh3/M=; b=LAeJ8s5U0K2eahAKgZx1VCiptDoulN6i7b5saaku6czMXX7dRcUvk7TghtEvCFrqn2 7zAhxg5wAsR3JC4HmMXJNyd+VaDunhp8NfZzAJotTnYX/zUCgTd3n+S7BC7v+cXna6X0 fbcvJJ0B4+EwpXhxxwJLGlxeF84ARoCoQC67ea1K6lN5oN6u3zYARX648OKmpq5/EYmo y0UIZgedFBVN2eTm11VuJ7Jwtp7O9y+Wheb2pFkVQMplyayZiZgMapbWbxIoV0SRG3KG ODwLA1yhGTAATE80In15S04CECqbUxyxiR3AYQuddIG6BqpipAin5bCyCmEcOoGdP42H +LJw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=HUVVEC+m; 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=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c3si1936719plo.243.2019.05.03.03.44.54; Fri, 03 May 2019 03:45:09 -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=@linaro.org header.s=google header.b=HUVVEC+m; 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=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727457AbfECKHJ (ORCPT + 99 others); Fri, 3 May 2019 06:07:09 -0400 Received: from mail-ua1-f68.google.com ([209.85.222.68]:41987 "EHLO mail-ua1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727443AbfECKHJ (ORCPT ); Fri, 3 May 2019 06:07:09 -0400 Received: by mail-ua1-f68.google.com with SMTP id h4so1807888uaj.9 for ; Fri, 03 May 2019 03:07:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=kMsfO5bwv4fct0CXFpp+M6L+nA/SFqgtUnj/08mh3/M=; b=HUVVEC+mmY62Aby7AgNB3ndZ3gtUn897nDSRdcWPjGm37j62VZ06IlJ3sJp75XjKn4 vwsOUyvL4yd05V3PV92pWSwTB495C+E5MQwNz7WTtAHcE9nF/oWHgZBFxiExFNm8oGGs 8huLs+XM5ko0jgg62YHFpqZ9RplzgJEQpRsxZUrEGIxVVffb6vrlUMXqpD5M5nvPiPFc QpfSXjGfxrPIeICt/FVSCbokO8ACtxL9BHc7sUMrDRgfxhRixIuSof11KFh23tIaCV/o hcRMaESYVO0rZIVl1fXT0uVMxA038Tnnmun+ONcVZsXQDk41NjK+Q6kvygPxxWrsYcKl InUA== 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=kMsfO5bwv4fct0CXFpp+M6L+nA/SFqgtUnj/08mh3/M=; b=lOqOMBG4hOA6Q+IxlXOiR1Vq+9v27eA2NQWkczJ2xXr6gT4BfIo9nF49VEdyylprqw vfqlLDiuTGIgC1BrxWueTVLRutsWyPaCYg1T+SDNZ+BEPrZbGYfju9Q37qvgeGJRYs9U 7NC4CyOqRLASUri2/JMN3f7Ql7PsiSznGUqeYW5+/ZO5Qg0n2ByCONBDj00XVUsyJAfC 3lyWhcOPmDHIkFy7cG2Jweb8evbnRk7dbTOHHTX03eFqx4Xg58NT/g6jEqnzt57qyzL2 rEtyxrPwfBH5ISTrvZiRNCSePsq0/WYdYBmd2+g7DGn9TONGVy4i2H5PGxISwLQSuvQP r/dg== X-Gm-Message-State: APjAAAV8tQ0Qp/qdsERPmqYgbOX5sJghueTOyq9S7K9pADLR/jScqzOk vIkZ/TN9LPY0jHoKLNA5Ml66MlS4/bm2aeUIFZC67A== X-Received: by 2002:a9f:204a:: with SMTP id 68mr5000627uam.19.1556878028026; Fri, 03 May 2019 03:07:08 -0700 (PDT) MIME-Version: 1.0 References: <20190502190714.181664-1-rrangel@chromium.org> In-Reply-To: <20190502190714.181664-1-rrangel@chromium.org> From: Ulf Hansson Date: Fri, 3 May 2019 12:06:32 +0200 Message-ID: Subject: Re: [PATCH] mmc: Fix tag set memory leak To: Raul E Rangel Cc: "linux-mmc@vger.kernel.org" , Avri Altman , Daniel Kurtz , zwisler@chromium.org, Ming Lei , Adrian Hunter , Hannes Reinecke , Linux Kernel Mailing List , Jens Axboe , Omar Sandoval 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 Thu, 2 May 2019 at 21:07, Raul E Rangel wrote: > > The tag set is allocated in mmc_init_queue but never freed. This results > in a memory leak. This change makes sure we free the tag set when the > queue is also freed. > > Signed-off-by: Raul E Rangel Applied for fixes (it may not make it for v5.1 unless there is a rc8), thanks! I also dropped the white space fixup, for the reasons explained by Adrian. Kind regards Uffe > --- > I found this using kmemleak and plugging and unplugging an SD card in a > few times. > > Here is an example of the output of kmemleak: > unreferenced object 0xffff888125be4ce8 (size 8): > comm "kworker/1:0", pid 17, jiffies 4294901575 (age 204.773s) > hex dump (first 8 bytes): > 00 00 00 00 00 00 00 00 ........ > backtrace: > [<0000000061cb8887>] blk_mq_alloc_tag_set+0xe9/0x234 > [<00000000cf532a0f>] mmc_init_queue+0xa9/0x2f0 > [<000000001e085171>] mmc_blk_alloc_req+0x125/0x2f9 > [<00000000eae1bd01>] mmc_blk_probe+0x1e2/0x6c1 > [<00000000a0b4a87d>] really_probe+0x1bd/0x3b0 > [<00000000e58f3eb9>] driver_probe_device+0xe1/0x115 > [<00000000358f3b3c>] bus_for_each_drv+0x89/0xac > [<00000000ef52ccbe>] __device_attach+0xb0/0x14a > [<00000000c9daafa7>] bus_probe_device+0x33/0x9f > [<0000000008ac5779>] device_add+0x34b/0x5e2 > [<00000000b42623cc>] mmc_add_card+0x1f5/0x20d > [<00000000f114ebc3>] mmc_attach_sd+0xc5/0x14b > [<000000006e915e0d>] mmc_rescan+0x261/0x2b6 > [<00000000e5b49c26>] process_one_work+0x1d3/0x31f > [<0000000068c8cd3c>] worker_thread+0x1cd/0x2bf > [<00000000326e2e22>] kthread+0x14f/0x157 > > Once I applied this patch the leak went away. > > p.s., I included a small white space fix. Hope that's ok. > > drivers/mmc/core/queue.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/drivers/mmc/core/queue.c b/drivers/mmc/core/queue.c > index 7c364a9c4eeb..176a08748cf1 100644 > --- a/drivers/mmc/core/queue.c > +++ b/drivers/mmc/core/queue.c > @@ -402,7 +402,7 @@ int mmc_init_queue(struct mmc_queue *mq, struct mmc_card *card) > > mq->card = card; > mq->use_cqe = host->cqe_enabled; > - > + > spin_lock_init(&mq->lock); > > memset(&mq->tag_set, 0, sizeof(mq->tag_set)); > @@ -472,6 +472,7 @@ void mmc_cleanup_queue(struct mmc_queue *mq) > blk_mq_unquiesce_queue(q); > > blk_cleanup_queue(q); > + blk_mq_free_tag_set(&mq->tag_set); > > /* > * A request can be completed before the next request, potentially > -- > 2.21.0.593.g511ec345e18-goog >