Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp417585pxb; Wed, 3 Mar 2021 06:36:46 -0800 (PST) X-Google-Smtp-Source: ABdhPJz31LHes00fKvOhFH4XrJmFNCTBMlq/pc65ihpUkfRo/o4x3zFP4FOtQ9clFS47OZygzyni X-Received: by 2002:a17:906:8a6e:: with SMTP id hy14mr8980817ejc.356.1614782206750; Wed, 03 Mar 2021 06:36:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614782206; cv=none; d=google.com; s=arc-20160816; b=wf+dV/k5opaFvJ/+mGgoNBSapvV2DigQQ+ny+ZS1XLqDy4c+gC5Lp/chrkyMPWTtMn sCGZthIipZ/Oion2/KP6odGPxO1rWuS9yeEdXEa6e6V55MOi1h65Eykove5Qw1FHew8S yFOdIFUSIgGyUa2lQMuq/xklQ0w5/75JAtSXMPTIq7E0EmLXM2qKq5U4wwvqkF89w5OC Q2/hOUCWnB9x7UMxkC6OoPho7pjPX/kMYljbzRyBJlm5EpDpIlhYzTZHC2vGVLxLD4+4 CKdXaZ0Rus8XZjhFZgsjjE4LucbyHCbvNRiznWX8pZJEnB0qSk8vG7aaPmRQoGAyXp/t sPOQ== 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=74ZZ35tR9bOiazRVaOLiIh7nGKfdJ+bHk/FTUulXZZ8=; b=wz+d5yYDcCi0/T7B0I2xtMZCVgS8wJDJhgK27vTXXLxraK9edKRPY9YTMhzIS713Sw mQFczM/l/c3CDGNuK0UFwHetEPHUd4hWiiMJuV6ObIbx3qlBtfSr3ZRK5HzHI6W4BKUC TZv1ON20twgPcbig204jHSLqYTpwB/DkwsCgXLIk85lF7ew2R6BZ+gKr0orHfCGiUjIp gbZ3j/EzmCdF7H51+opkVUl1LYMULLXtKorrSwdVpYLNRS+OQ02O6HDIlIN6TSLU2z+/ KlMhyVSBcEtQJ0Bi9jjb1/uP+Gw4v8Vs6IrWLgYbFNenSVi8PKsQF0R9clOPfm/H+6m8 4y8Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=qSKnTvBo; 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 a42si17336772edf.287.2021.03.03.06.35.46; Wed, 03 Mar 2021 06:36:46 -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=qSKnTvBo; 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 S244648AbhCAVYq (ORCPT + 99 others); Mon, 1 Mar 2021 16:24:46 -0500 Received: from mail.kernel.org ([198.145.29.99]:52650 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237345AbhCARQc (ORCPT ); Mon, 1 Mar 2021 12:16:32 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id B257B60241; Mon, 1 Mar 2021 16:46:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1614617197; bh=/HHHEAURaIWnwAXG4Ir+ZuS7Q8itwrj9biVWrqa6Vg0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qSKnTvBoL+kUjHFcWa/yvTVrGFiZWvuqCE4bF73bNMFXmRuhqyrzgUek7kfISgSOq xcI4SlhBOr4khcynoVlYkKYL7JMrHpXXnhxMPzmN6U3fe9WOjaxQiXQaO/4UymKLnL hTjqpZ46aQL0sv9MMt7gysIJ9PPP6S79jye3+hVw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Nikos Tsironis , Mike Snitzer Subject: [PATCH 4.19 237/247] dm era: Reinitialize bitset cache before digesting a new writeset Date: Mon, 1 Mar 2021 17:14:17 +0100 Message-Id: <20210301161043.306315749@linuxfoundation.org> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210301161031.684018251@linuxfoundation.org> References: <20210301161031.684018251@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: Nikos Tsironis commit 2524933307fd0036d5c32357c693c021ab09a0b0 upstream. In case of devices with at most 64 blocks, the digestion of consecutive eras uses the writeset of the first era as the writeset of all eras to digest, leading to lost writes. That is, we lose the information about what blocks were written during the affected eras. The digestion code uses a dm_disk_bitset object to access the archived writesets. This structure includes a one word (64-bit) cache to reduce the number of array lookups. This structure is initialized only once, in metadata_digest_start(), when we kick off digestion. But, when we insert a new writeset into the writeset tree, before the digestion of the previous writeset is done, or equivalently when there are multiple writesets in the writeset tree to digest, then all these writesets are digested using the same cache and the cache is not re-initialized when moving from one writeset to the next. For devices with more than 64 blocks, i.e., the size of the cache, the cache is indirectly invalidated when we move to a next set of blocks, so we avoid the bug. But for devices with at most 64 blocks we end up using the same cached data for digesting all archived writesets, i.e., the cache is loaded when digesting the first writeset and it never gets reloaded, until the digestion is done. As a result, the writeset of the first era to digest is used as the writeset of all the following archived eras, leading to lost writes. Fix this by reinitializing the dm_disk_bitset structure, and thus invalidating the cache, every time the digestion code starts digesting a new writeset. Fixes: eec40579d84873 ("dm: add era target") Cc: stable@vger.kernel.org # v3.15+ Signed-off-by: Nikos Tsironis Signed-off-by: Mike Snitzer Signed-off-by: Greg Kroah-Hartman --- drivers/md/dm-era-target.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) --- a/drivers/md/dm-era-target.c +++ b/drivers/md/dm-era-target.c @@ -755,6 +755,12 @@ static int metadata_digest_lookup_writes ws_unpack(&disk, &d->writeset); d->value = cpu_to_le32(key); + /* + * We initialise another bitset info to avoid any caching side effects + * with the previous one. + */ + dm_disk_bitset_init(md->tm, &d->info); + d->nr_bits = min(d->writeset.nr_bits, md->nr_blocks); d->current_bit = 0; d->step = metadata_digest_transcribe_writeset; @@ -768,12 +774,6 @@ static int metadata_digest_start(struct return 0; memset(d, 0, sizeof(*d)); - - /* - * We initialise another bitset info to avoid any caching side - * effects with the previous one. - */ - dm_disk_bitset_init(md->tm, &d->info); d->step = metadata_digest_lookup_writeset; return 0;