From patchwork Wed Oct 13 01:42:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jinyoung Choi X-Patchwork-Id: 12554247 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 109C8C433EF for ; Wed, 13 Oct 2021 01:43:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D7BC660BD3 for ; Wed, 13 Oct 2021 01:43:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234119AbhJMBpR (ORCPT ); Tue, 12 Oct 2021 21:45:17 -0400 Received: from mailout3.samsung.com ([203.254.224.33]:64266 "EHLO mailout3.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229580AbhJMBpQ (ORCPT ); Tue, 12 Oct 2021 21:45:16 -0400 Received: from epcas2p4.samsung.com (unknown [182.195.41.56]) by mailout3.samsung.com (KnoxPortal) with ESMTP id 20211013014312epoutp0393f949396cfa33eb34ecc0bc674cfc64~tc6Uac7bD2073020730epoutp03c for ; Wed, 13 Oct 2021 01:43:12 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout3.samsung.com 20211013014312epoutp0393f949396cfa33eb34ecc0bc674cfc64~tc6Uac7bD2073020730epoutp03c DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1634089392; bh=5hgsZMnyHmMQuJ17+DuONfTtOtgQHJQx6uixMnpyb9w=; h=Subject:Reply-To:From:To:Date:References:From; b=IMdhHaT6sgaJdi8SaLkAKpO4pbXlzdY/zpwFcBk98u5jf83t2VMRNtQqyGXn+uXB0 a2nf+a/ZyqqDeAjkgkKdde14dQgLwGn5KWPfiho4RhOVTj67jNDP4Ou1TDiQZV0Zuj rzCND24TzEGtsvDjLeWiGmbv5/LzXfQAeWQdlRto= Received: from epsnrtp3.localdomain (unknown [182.195.42.164]) by epcas2p1.samsung.com (KnoxPortal) with ESMTP id 20211013014309epcas2p15f019c6c8a12ef5633d9f87784e9de70~tc6Rchuyl0925409254epcas2p1E; Wed, 13 Oct 2021 01:43:09 +0000 (GMT) Received: from epsmges2p4.samsung.com (unknown [182.195.36.102]) by epsnrtp3.localdomain (Postfix) with ESMTP id 4HTZzn5PtYz4x9QF; Wed, 13 Oct 2021 01:43:01 +0000 (GMT) X-AuditID: b6c32a48-d75ff70000002500-7e-616639a135d6 Received: from epcas2p4.samsung.com ( [182.195.41.56]) by epsmges2p4.samsung.com (Symantec Messaging Gateway) with SMTP id 4C.F4.09472.1A936616; Wed, 13 Oct 2021 10:42:57 +0900 (KST) Mime-Version: 1.0 Subject: [PATCH v2] block-map: added error handling for bio_copy_kern() Reply-To: j-young.choi@samsung.com Sender: Jinyoung CHOI From: Jinyoung CHOI To: "axboe@kernel.dk" , "linux-block@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "hch@infradead.org" X-Priority: 3 X-Content-Kind-Code: NORMAL X-CPGS-Detection: blocking_info_exchange X-Drm-Type: N,general X-Msg-Generator: Mail X-Msg-Type: PERSONAL X-Reply-Demand: N Message-ID: <20211013014256epcms2p5485187a369a9f8c74c2b3ab925df88fb@epcms2p5> Date: Wed, 13 Oct 2021 10:42:56 +0900 X-CMS-MailID: 20211013014256epcms2p5485187a369a9f8c74c2b3ab925df88fb X-Sendblock-Type: AUTO_CONFIDENTIAL X-CPGSPASS: Y X-CPGSPASS: Y CMS-TYPE: 102P X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrGKsWRmVeSWpSXmKPExsWy7bCmhe5Cy7REgxe3eCxW3+1ns3h5SNPi 9IRFTBa9/VvZLPbe0ra4vGsOmwObx+YVWh6Xz5Z69G1ZxejxeZNcAEtUtk1GamJ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Ipzkg01GIuKk4EAFaElbsJ BAAA DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20211013014256epcms2p5485187a369a9f8c74c2b3ab925df88fb References: Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org When new pages are allocated to bio through alloc_page() in bio_copy_kern(), the pages must be freed in error handling after that. There is little chance of an error occurring in blk_rq_append_bio(), but in the code flow, pages additionally allocated to bio must be released. V2:         - As pointed out by Christoph, replace int with bool Signed-off-by: Jinyoung Choi ---  block/blk-map.c | 11 ++++++++---  1 file changed, 8 insertions(+), 3 deletions(-)         if (!len || !kbuf)                 return -EINVAL; -       if (!blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf) || -           blk_queue_may_bounce(q)) +       do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf) || +               blk_queue_may_bounce(q); +       if (do_copy)                 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);         else                 bio = bio_map_kern(q, kbuf, len, gfp_mask); @@ -648,8 +650,11 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,         bio->bi_opf |= req_op(rq);         ret = blk_rq_append_bio(rq, bio); -       if (unlikely(ret)) +       if (unlikely(ret)) { +               if (do_copy) +                       bio_free_pages(bio);                 bio_put(bio); +       }         return ret;  }  EXPORT_SYMBOL(blk_rq_map_kern); -- 2.25.1 diff --git a/block/blk-map.c b/block/blk-map.c index 4526adde0156..b137a2f569f8 100644 --- a/block/blk-map.c +++ b/block/blk-map.c @@ -628,6 +628,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,         int reading = rq_data_dir(rq) == READ;         unsigned long addr = (unsigned long) kbuf;         struct bio *bio; +       bool do_copy;         int ret;         if (len > (queue_max_hw_sectors(q) << 9)) @@ -635,8 +636,9 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,