Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2617949yba; Mon, 8 Apr 2019 00:34:19 -0700 (PDT) X-Google-Smtp-Source: APXvYqwceLQmfnCOygHYZplp4Kb5vCW1jFKFzlTrt2iuf6k6QheJ0rFwWutcy2HZRltRN2iRzE38 X-Received: by 2002:a17:902:1101:: with SMTP id d1mr11487222pla.16.1554708859438; Mon, 08 Apr 2019 00:34:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554708859; cv=none; d=google.com; s=arc-20160816; b=IGoKrnmSGMY2SU16cZvcxNBk5ipgRh9USxpmsEGUgBVEYZLMueSj4MogD5Q3qciGiD YFzlnLDi+bXoRJzig4AKQC0mWesz8+yug9Ju1hpf/cCdhvOdgWh9BmlcJTJMlZ8UGGoq CNiD3SYgX7JzuRERVCufTdkHE5efsb/dWj3kxlebsDV/yVlx81QVJDMH7EE0jejjdcWR kncaa5WWQLa3N78mSfQkm5kPgHT3QJAn03W2xnKufGQ7vrZt5OXCvW7xgjvpdwedwhi1 i98v1cOBOOtAPsGaNhdzoFGrANX9dsesbk+aK5kepKMBglx3CwVxERK5dKvxVUV0fYrq 2gXQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=t1PKzZaRhiqJLeho8v9j47dffEHuqgIyns02qb8Yva0=; b=qw0bbkneVlh3UGNC/MrCrkiEcvSwfbilmE9wuxZe+NFgV2QV51PXWtu9D+3S1dnH3m FYj5IUnz61I06nV3LaYFtr6ozxqGRdtRgvFp3WXZnzl9azAzwE5Kr54+iBxXfRi3AfIa fxTtbIrQh/0PHalNPY6kiM7Zu4yhNLcDHv60eVkqFOGPoLtN3p5Qfamf2n1pVFfWifA7 7v3vQYx976znuRgWRzBqPSBDaUjZ8BJrFnAfFfwVTqLSlDHJx0AoYd37jsG28Rg1NIuF KVMweoIbuyFOmA4g4AoG3b8UsZ0iUCh2+WWp5tRvYuAK9vAn+e1TShgggpKUf2Re+7nP ILbQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@owltronix-com.20150623.gappssmtp.com header.s=20150623 header.b=nIyDu4ge; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x14si25547566pfm.179.2019.04.08.00.34.04; Mon, 08 Apr 2019 00:34:19 -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=@owltronix-com.20150623.gappssmtp.com header.s=20150623 header.b=nIyDu4ge; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726826AbfDHHd3 (ORCPT + 99 others); Mon, 8 Apr 2019 03:33:29 -0400 Received: from mail-ed1-f66.google.com ([209.85.208.66]:36007 "EHLO mail-ed1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726387AbfDHHd0 (ORCPT ); Mon, 8 Apr 2019 03:33:26 -0400 Received: by mail-ed1-f66.google.com with SMTP id s16so10710884edr.3 for ; Mon, 08 Apr 2019 00:33:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=owltronix-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id; bh=t1PKzZaRhiqJLeho8v9j47dffEHuqgIyns02qb8Yva0=; b=nIyDu4ger7JrVRQZHKCARQmIqc3Kz/1dOc8jSrygjQ5hDwDBE5k5XTtdaE58/wFR7P SLqP4kFYAtnU2JG7kFUeqFAhzGsCNBStnPxyEoREyqF6YFdRM9v+ls1RFwq9gHKD+nkf ZQlMICnodxYfqwauL25aVK30vjkZszU4+d5mAqavwfQ6wWzgy50ThmMsFxHFUQM2Boqb 4JId33v6JQuq6m9IitFm1Yr6b4TMzwxIQRDkZajn5vcb1PzZBWzFt1Sv+6N7VebHcTHv k2hsGI2Du0NEoKd/n35ZzpJfjHRkobNGiRcNeZYqO0nICe/YCwPtKqkggzxohjHx7Xcw PHpg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=t1PKzZaRhiqJLeho8v9j47dffEHuqgIyns02qb8Yva0=; b=ntSgXcahsVzfqnjSg7k2qTVUdAmQQF6WiFNoKI1clJRE4X573uT4LU/0pBuq/FUjnh RV9nNYZ83yylbLEWA4geoFpq8SbMOr+QdwmpDjw5NVFZZo/NotqZWr/TN5KCHQ7CakoR 7sXCtcPMXnyGJn9gH5GND82uVfOdoZnwEEVR7wnDCvOTrmXAP0UyD6oatq4LVmHZ45HU SLmpHQhRFeTXRBe5yZrFkOyzBWxnFbPMoIj9gzk3lzlantIbVj+QtO7P6PcO+jEa9c4S AUmQ30fOAzym1JwqDEXbwOh8379h4BatNYA7ojrR5egAzCPfTGqOFEwMZoHx8Pe6iwT3 rsWg== X-Gm-Message-State: APjAAAVfevUFpRPYLSaJ3AeAk3GA0I/0KUlIon/yTSgtez/y6Vl69Obb syf7F6WkpnUxLB6gMjl3UvS1Ig== X-Received: by 2002:a17:906:3e8f:: with SMTP id a15mr16105976ejj.189.1554708804750; Mon, 08 Apr 2019 00:33:24 -0700 (PDT) Received: from ch-lap-hans.cnexlabs.com (soho-cph.cust-cnex.dsd101.net. [194.62.216.132]) by smtp.gmail.com with ESMTPSA id f5sm8630128ede.94.2019.04.08.00.33.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 08 Apr 2019 00:33:24 -0700 (PDT) From: hans@owltronix.com To: Matias Bjorling Cc: javier@javigon.com, Igor Konopko , Klaus Jensen , linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, Hans Holmberg Subject: [PATCH] lightnvm: pblk: fix crash in pblk_end_partial_read due to multipage bvecs Date: Mon, 8 Apr 2019 09:33:08 +0200 Message-Id: <20190408073308.3082-1-hans@owltronix.com> X-Mailer: git-send-email 2.17.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Hans Holmberg Ever since '07173c3ec276 ("block: enable multipage bvecs")' we need to handle bios with multipage bvecs in pblk. Currently, a multipage bvec results in a crash[1]. Fix this by using bvec iterators in stead of direct bvec indexing. Also add a dcache flush, for the same reasons as in: '6e6e811d747b ("block: Add missing flush_dcache_page() call")' [1] https://github.com/OpenChannelSSD/linux/issues/61 Reported-by: Klaus Jensen Signed-off-by: Hans Holmberg --- It ain't pretty, but let's fix the breakage while waiting for Igor's partial read cleanup to be ready. drivers/lightnvm/pblk-read.c | 50 ++++++++++++++++++++---------------- 1 file changed, 28 insertions(+), 22 deletions(-) diff --git a/drivers/lightnvm/pblk-read.c b/drivers/lightnvm/pblk-read.c index f08f7d9bd3be..27f8a76d8bd8 100644 --- a/drivers/lightnvm/pblk-read.c +++ b/drivers/lightnvm/pblk-read.c @@ -230,14 +230,14 @@ static void pblk_end_partial_read(struct nvm_rq *rqd) struct pblk_sec_meta *meta; struct bio *new_bio = rqd->bio; struct bio *bio = pr_ctx->orig_bio; - struct bio_vec src_bv, dst_bv; void *meta_list = rqd->meta_list; - int bio_init_idx = pr_ctx->bio_init_idx; unsigned long *read_bitmap = pr_ctx->bitmap; + struct bvec_iter orig_iter = BVEC_ITER_ALL_INIT; + struct bvec_iter new_iter = BVEC_ITER_ALL_INIT; int nr_secs = pr_ctx->orig_nr_secs; int nr_holes = nr_secs - bitmap_weight(read_bitmap, nr_secs); void *src_p, *dst_p; - int hole, i; + int bit, i; if (unlikely(nr_holes == 1)) { struct ppa_addr ppa; @@ -256,33 +256,39 @@ static void pblk_end_partial_read(struct nvm_rq *rqd) /* Fill the holes in the original bio */ i = 0; - hole = find_first_zero_bit(read_bitmap, nr_secs); - do { - struct pblk_line *line; + for (bit = 0; bit < nr_secs; bit++) { + if (!test_bit(bit, read_bitmap)) { + struct bio_vec dst_bv, src_bv; + struct pblk_line *line; - line = pblk_ppa_to_line(pblk, rqd->ppa_list[i]); - kref_put(&line->ref, pblk_line_put); + line = pblk_ppa_to_line(pblk, rqd->ppa_list[i]); + kref_put(&line->ref, pblk_line_put); - meta = pblk_get_meta(pblk, meta_list, hole); - meta->lba = cpu_to_le64(pr_ctx->lba_list_media[i]); + meta = pblk_get_meta(pblk, meta_list, bit); + meta->lba = cpu_to_le64(pr_ctx->lba_list_media[i]); - src_bv = new_bio->bi_io_vec[i++]; - dst_bv = bio->bi_io_vec[bio_init_idx + hole]; + dst_bv = bio_iter_iovec(bio, orig_iter); + src_bv = bio_iter_iovec(new_bio, new_iter); - src_p = kmap_atomic(src_bv.bv_page); - dst_p = kmap_atomic(dst_bv.bv_page); + src_p = kmap_atomic(src_bv.bv_page); + dst_p = kmap_atomic(dst_bv.bv_page); - memcpy(dst_p + dst_bv.bv_offset, - src_p + src_bv.bv_offset, - PBLK_EXPOSED_PAGE_SIZE); + memcpy(dst_p + dst_bv.bv_offset, + src_p + src_bv.bv_offset, + PBLK_EXPOSED_PAGE_SIZE); - kunmap_atomic(src_p); - kunmap_atomic(dst_p); + kunmap_atomic(src_p); + kunmap_atomic(dst_p); - mempool_free(src_bv.bv_page, &pblk->page_bio_pool); + flush_dcache_page(dst_bv.bv_page); + mempool_free(src_bv.bv_page, &pblk->page_bio_pool); - hole = find_next_zero_bit(read_bitmap, nr_secs, hole + 1); - } while (hole < nr_secs); + bio_advance_iter(new_bio, &new_iter, + PBLK_EXPOSED_PAGE_SIZE); + i++; + } + bio_advance_iter(bio, &orig_iter, PBLK_EXPOSED_PAGE_SIZE); + } bio_put(new_bio); kfree(pr_ctx); -- 2.17.1