From patchwork Mon Jul 10 18:40:17 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shaohua Li X-Patchwork-Id: 9833683 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 0CAFB60318 for ; Mon, 10 Jul 2017 18:59:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E89EC28591 for ; Mon, 10 Jul 2017 18:59:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DBD7A285E4; Mon, 10 Jul 2017 18:59:32 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5438C28591 for ; Mon, 10 Jul 2017 18:59:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752158AbdGJS7b (ORCPT ); Mon, 10 Jul 2017 14:59:31 -0400 Received: from mx0a-00082601.pphosted.com ([67.231.145.42]:48826 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751817AbdGJS7b (ORCPT ); Mon, 10 Jul 2017 14:59:31 -0400 Received: from pps.filterd (m0044008.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id v6AIwq5B030162 for ; Mon, 10 Jul 2017 11:59:30 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : cc : subject : date : message-id : mime-version : content-type; s=facebook; bh=g5o+h9G2JsIy73seOBXzAOV1RTbzNSdk3s19gEFpIAU=; b=cMUrJFNBOs6JUMIMysU3m/MKQmd4jN0RdNQfrSYa96fdGKfcP1AmV/flpnYfj6UCqUNZ ys4UsSsB3hUJQyq2ZxelJp4IXgel2cnMnUx38o4NktjgA9BVCOzra13jj1zJ62cT3GmJ ZAzMhcDdfbWLvyacsdEa0h7MZj/MfSTCUyk= Received: from mail.thefacebook.com ([199.201.64.23]) by mx0a-00082601.pphosted.com with ESMTP id 2bmb1090ra-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT) for ; Mon, 10 Jul 2017 11:59:30 -0700 Received: from mx-out.facebook.com (192.168.52.123) by PRN-CHUB06.TheFacebook.com (192.168.16.16) with Microsoft SMTP Server (TLS) id 14.3.319.2; Mon, 10 Jul 2017 11:59:30 -0700 Received: from facebook.com (2401:db00:21:603d:face:0:19:0) by mx-out.facebook.com (2401:db00:2050:5102:face:0000:003b:0000) with ESMTP id 3894b4ae659f11e79db0ade1b876fb2a-9c9e0150 for ; Mon, 10 Jul 2017 11:40:18 -0700 Received: by devbig638.prn2.facebook.com (Postfix, from userid 11222) id A1D124A436D8; Mon, 10 Jul 2017 11:40:17 -0700 (PDT) Smtp-Origin-Hostprefix: devbig From: Shaohua Li Smtp-Origin-Hostname: devbig638.prn2.facebook.com To: CC: , Christoph Hellwig Smtp-Origin-Cluster: prn2c22 Subject: [PATCH V2] block: call bio_uninit in bio_endio Date: Mon, 10 Jul 2017 11:40:17 -0700 Message-ID: X-Mailer: git-send-email 2.9.3 X-FB-Internal: Safe MIME-Version: 1.0 X-Proofpoint-Spam-Reason: safe X-FB-Internal: Safe X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-07-10_08:, , signatures=0 Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP bio_free isn't a good place to free cgroup info. There are a lot of cases bio is allocated in special way (for example, in stack) and never gets called by bio_put hence bio_free, we are leaking memory. This patch moves the free to bio endio, which should be called anyway. The bio_uninit call in bio_free is kept, in case the bio never gets called bio endio. This assumes ->bi_end_io() doesn't access cgroup info, which seems true in my audit. This along with Christoph's integrity patch should fix the memory leak issue. Cc: Christoph Hellwig Signed-off-by: Shaohua Li --- block/bio.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/block/bio.c b/block/bio.c index 9cabf5d..9a63597 100644 --- a/block/bio.c +++ b/block/bio.c @@ -1833,6 +1833,8 @@ void bio_endio(struct bio *bio) } blk_throtl_bio_endio(bio); + /* release cgroup info */ + bio_uninit(bio); if (bio->bi_end_io) bio->bi_end_io(bio); }