From patchwork Wed Mar 21 18:47:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 10300021 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 37DA66055B for ; Wed, 21 Mar 2018 18:47:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3499329898 for ; Wed, 21 Mar 2018 18:47:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2988C298A0; Wed, 21 Mar 2018 18:47:09 +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=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=unavailable 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 CB81229899 for ; Wed, 21 Mar 2018 18:47:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752725AbeCUSrH (ORCPT ); Wed, 21 Mar 2018 14:47:07 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:56736 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752614AbeCUSrG (ORCPT ); Wed, 21 Mar 2018 14:47:06 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=IutfX4ITU4ADazYVVFkwr8cJX05E3jVeQx/IO1+UPOA=; b=Nhj+HTygJkXGKK03kSXaqK6+4 JlCwrcX0aSaUpsxmp8zjtoyldqQEaVpykP2hSBARIlDuAE8EDCrGiq1cQrKaSjLqFQXETgSQW9xF4 6RLPivkLo+tLay3lojbQzsPvxCmzeIbeYBAWuurKMxkLSZSg2SYSNRFPuug8PKYl4XERycH5WRYYW zKp39uCUWFgdTAaA0N4o6FCQtanPdnNKC/LhlCCWAryHSBY3oDQWOzEeFJLeWAud/d2ywcJ9Zh2KO mrenSf0aT169wnIEOZa6m3OpeM7bNaPsCvHqZk7Ghp0uBwaBhj77yNqsBdEsw9NtvzlA6Cj+luB+E MkRK4SPBQ==; Received: from hch by bombadil.infradead.org with local (Exim 4.90_1 #2 (Red Hat Linux)) id 1eyilK-0006hv-O0; Wed, 21 Mar 2018 18:47:02 +0000 Date: Wed, 21 Mar 2018 11:47:02 -0700 From: Christoph Hellwig To: Andrei Vagin Cc: Christoph Hellwig , Andrei Vagin , "Nicholas A. Bellinger" , linux-scsi@vger.kernel.org, target-devel@vger.kernel.org, shli@fb.com, axboe@kernel.dk Subject: Re: [PATCH] [RFC] target/file: add support of direct and async I/O Message-ID: <20180321184702.GA11249@infradead.org> References: <20180309004259.16052-1-avagin@openvz.org> <20180316075027.GA19192@infradead.org> <20180320075456.GA11151@outlook.office365.com> <20180320084701.GA4241@infradead.org> <20180320204100.GA31300@outlook.office365.com> <20180321072340.GA29587@infradead.org> <20180321181608.GA8446@outlook.office365.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20180321181608.GA8446@outlook.office365.com> User-Agent: Mutt/1.9.2 (2017-12-15) X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On Wed, Mar 21, 2018 at 11:16:09AM -0700, Andrei Vagin wrote: > If we look at lo_rw_aio, we can find that bvec can be allocated or got > from bio. I think the problem with the second case. > > static int lo_rw_aio(struct loop_device *lo, struct loop_cmd *cmd, > loff_t pos, bool rw) > { > ... > if (rq->bio != rq->biotail) { > ... > bvec = kmalloc(sizeof(struct bio_vec) * segments, > GFP_NOIO); > ... > } else { > ... > bvec = __bvec_iter_bvec(bio->bi_io_vec, > bio->bi_iter); That is the local 'bvec' variable, not cmd->bvec which is only assigned to the kmalloc return value. > BTW: I tried your patch and I still get the same kasan warning. Strange, as the trace can't really happen with the patch applied. In fact the ->bvec field isn't even needed, e.g. we should do something like this on top of the previous patch: diff --git a/drivers/block/loop.c b/drivers/block/loop.c index 9cb6078cd4f0..0401fade3d60 100644 --- a/drivers/block/loop.c +++ b/drivers/block/loop.c @@ -477,7 +477,7 @@ static int lo_rw_aio(struct loop_device *lo, struct loop_cmd *cmd, loff_t pos, bool rw) { struct iov_iter iter; - struct bio_vec *bvec; + struct bio_vec *bvec, *alloc_bvec = NULL; struct request *rq = cmd->rq; struct bio *bio = rq->bio; struct file *file = lo->lo_backing_file; @@ -491,10 +491,10 @@ static int lo_rw_aio(struct loop_device *lo, struct loop_cmd *cmd, __rq_for_each_bio(bio, rq) segments += bio_segments(bio); - bvec = kmalloc(sizeof(struct bio_vec) * segments, GFP_NOIO); - if (!bvec) + alloc_bvec = kmalloc_array(segments, + sizeof(struct bio_vec), GFP_NOIO); + if (!alloc_bvec) return -EIO; - cmd->bvec = bvec; /* * The bios of the request may be started from the middle of @@ -502,11 +502,12 @@ static int lo_rw_aio(struct loop_device *lo, struct loop_cmd *cmd, * copy bio->bi_iov_vec to new bvec. The rq_for_each_segment * API will take care of all details for us. */ + bvec = alloc_bvec; rq_for_each_segment(tmp, rq, iter) { *bvec = tmp; bvec++; } - bvec = cmd->bvec; + bvec = alloc_bvec; offset = 0; } else { /* @@ -535,12 +536,7 @@ static int lo_rw_aio(struct loop_device *lo, struct loop_cmd *cmd, else ret = call_read_iter(file, &cmd->iocb, &iter); - /* - * Clear bvec to NULL as lo_rw_aio only allocates and sets it for - * the multiple bios per request case and we want a clean slate here. - */ - kfree(cmd->bvec); - cmd->bvec = NULL; + kfree(alloc_bvec); kthread_associate_blkcg(NULL); if (ret != -EIOCBQUEUED) diff --git a/drivers/block/loop.h b/drivers/block/loop.h index ba65848c7c33..b8eef1977f64 100644 --- a/drivers/block/loop.h +++ b/drivers/block/loop.h @@ -70,7 +70,6 @@ struct loop_cmd { bool use_aio; /* use AIO interface to handle I/O */ long ret; struct kiocb iocb; - struct bio_vec *bvec; struct cgroup_subsys_state *css; };