Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp3971970pxb; Tue, 2 Mar 2021 03:30:22 -0800 (PST) X-Google-Smtp-Source: ABdhPJx4O8cBEEPjPu0LFzQtfI5ueWOMPoOBIzmMo0UwJEIht7WywMkZK0rT5kzsVKRu4EjZ0FIo X-Received: by 2002:a17:906:25c4:: with SMTP id n4mr20557522ejb.359.1614684622266; Tue, 02 Mar 2021 03:30:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614684622; cv=none; d=google.com; s=arc-20160816; b=fmzqXkUVwQNzlKKqi3Q1scR+mjLexH6wx/40Pangd9tKZ6jaKboprC/pk0NBaHmKMu 14wSBQIgNQC83e3q3wRd51xyfqRZwkKM2Gi5DYvdylTGwuz7wWGiM4JU+Bbhvgpj+71i /BS1rTvrtgol7Zg1RjrxtUNle2tdbk/H8qqYir91JvUsv5NNH7Gk2u8be3b4G9B5Q/ZI o+8MVa3eKkGphC9+raL/+WvSWncX26RV1oKh6jQLqF+QSA6IVfHgwiKxQ0nGTkztQHqY JvZ06pgbnLLbTb7jiMJcaGK6Q7g3u58L6NZ7iKUvTBgsZ8Wp9UZEHAQ6K9K8Or3UHU9t soGQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=OnUUQhSwIO0N+SLxsYbo4QzXvg6LrQy5qjcsDX6j3vo=; b=KFdNB0z571YFtb1ufvj34WuxttW8h4wplcyMAdZVrsYgLZYEZvNUmUyL7UI2K7G+nD 4SiTRyglKFuW4InZbR0Z511H2FhURKicPsR0fX7giGOrE3y7ZJ91DvWRKYCdLsjbs5UC +up//dgojchBs8ivP2UUF7+jxHYZsST0pyeZKNJAzSJDtMJUaw35/jeT3JoPZNJE4QW3 CRdWfdO7FCtJpk0T+bR5qERfZc+411ORCNSZCCPVSfXZyXXOuMiwxFgx8aTlv5K59fqv S3W6X7le0vp0w7Ram+Q2v+fqyD4H2zTfDqH0DAPUTTSvx0dmHuZ8kxHlKUP6p+3RYFDZ fiTg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=aHWHnV5D; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i2si307372ejc.37.2021.03.02.03.29.58; Tue, 02 Mar 2021 03:30:22 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=aHWHnV5D; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1380760AbhCBBzV (ORCPT + 99 others); Mon, 1 Mar 2021 20:55:21 -0500 Received: from mail.kernel.org ([198.145.29.99]:48622 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241947AbhCATaA (ORCPT ); Mon, 1 Mar 2021 14:30:00 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id EB2F76529A; Mon, 1 Mar 2021 17:32:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1614619971; bh=Un2jYswws1ByDrwhtiyuuxeMrwd3O2Oegrx4yVkBNpI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aHWHnV5DtJRFEo7UJBwPhekjBgGBYafFu1zW0gVGhluqIqIh7NeX5HjW8Mks+QvFH 3LxU0YfrvSaI7jCQlHHD5WiURPUAZmdmR0nFgwiFbZLFbd0V1bG0S7ycL5GQqeGpmJ pQb8TFs8NsghVAJQpJc9pH+0SelTpERmxew6SYJo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Mikulas Patocka , Mike Snitzer Subject: [PATCH 5.10 647/663] dm writecache: fix writing beyond end of underlying device when shrinking Date: Mon, 1 Mar 2021 17:14:55 +0100 Message-Id: <20210301161213.863328176@linuxfoundation.org> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210301161141.760350206@linuxfoundation.org> References: <20210301161141.760350206@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Mikulas Patocka commit 4134455f2aafdfeab50cabb4cccb35e916034b93 upstream. Do not attempt to write any data beyond the end of the underlying data device while shrinking it. The DM writecache device must be suspended when the underlying data device is shrunk. Signed-off-by: Mikulas Patocka Cc: stable@vger.kernel.org Signed-off-by: Mike Snitzer Signed-off-by: Greg Kroah-Hartman --- drivers/md/dm-writecache.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) --- a/drivers/md/dm-writecache.c +++ b/drivers/md/dm-writecache.c @@ -148,6 +148,7 @@ struct dm_writecache { size_t metadata_sectors; size_t n_blocks; uint64_t seq_count; + sector_t data_device_sectors; void *block_start; struct wc_entry *entries; unsigned block_size; @@ -977,6 +978,8 @@ static void writecache_resume(struct dm_ wc_lock(wc); + wc->data_device_sectors = i_size_read(wc->dev->bdev->bd_inode) >> SECTOR_SHIFT; + if (WC_MODE_PMEM(wc)) { persistent_memory_invalidate_cache(wc->memory_map, wc->memory_map_size); } else { @@ -1646,6 +1649,10 @@ static bool wc_add_block(struct writebac void *address = memory_data(wc, e); persistent_memory_flush_cache(address, block_size); + + if (unlikely(bio_end_sector(&wb->bio) >= wc->data_device_sectors)) + return true; + return bio_add_page(&wb->bio, persistent_memory_page(address), block_size, persistent_memory_page_offset(address)) != 0; } @@ -1717,6 +1724,9 @@ static void __writecache_writeback_pmem( if (writecache_has_error(wc)) { bio->bi_status = BLK_STS_IOERR; bio_endio(bio); + } else if (unlikely(!bio_sectors(bio))) { + bio->bi_status = BLK_STS_OK; + bio_endio(bio); } else { submit_bio(bio); } @@ -1760,6 +1770,14 @@ static void __writecache_writeback_ssd(s e = f; } + if (unlikely(to.sector + to.count > wc->data_device_sectors)) { + if (to.sector >= wc->data_device_sectors) { + writecache_copy_endio(0, 0, c); + continue; + } + from.count = to.count = wc->data_device_sectors - to.sector; + } + dm_kcopyd_copy(wc->dm_kcopyd, &from, 1, &to, 0, writecache_copy_endio, c); __writeback_throttle(wc, wbl);