Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp712493pxv; Thu, 15 Jul 2021 14:10:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwOBFgmNPPc08ZDjcpT+ufuqyXepsk14zFya8YorPAmXyHx/xyNOk44u4cLAcZL6pcRi9Ws X-Received: by 2002:a17:906:9c84:: with SMTP id fj4mr7443931ejc.264.1626383456035; Thu, 15 Jul 2021 14:10:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626383456; cv=none; d=google.com; s=arc-20160816; b=CK0xjIkj35QcqvPO0n76CsqWW7uxQx915pcI1OvYFfBz/zVqDd24H4ATdpzLE3VG1N F3ZuYWzDWMtKDLl4+XluaaYksDK+Ikn66UBsVzwtIgW6DixH51AJSqjSEkffnahGbUQs EUmYHvEDRICCEhPQbCFsyBiBWCCsryO4rZCTYc5gg3ieDXq7B0XMDFt65gpkoXYb0xp1 5d+83uqKYZIjrONlQQTuEE0yho/mzzIw46zB6LrGbxgyghHamnhITGHZwrLn7fzrTQjJ U+DUGD4yV04A0/LzYOsSM3tnjbogZru58wX6KYFKWx1X9dGpXnY9/40KjScOuWl+Ehn/ K6fA== 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=gJlAz8/uAAhVvVKLB6Af5UdTiCkxSVS3vZ2SQXmWQCQ=; b=y3cqHRcREqqIk8NK0iKpt2pYvQhJoclDvpZOJGH9oxaYiHrYhcrwtj9QAfmxJfKnTq RvesL8USWMbA1JqbdPQ1TJlmCYb+M5PTwegtwW+6ISeXujXApqyD8PFwl+qt15mVp5XO eGRvhG2xapQPXlT4pEBK1PH4dmQVoXLbqNn2aD2gvIKS6gFEIDWGHh5k00nAjLPeTeSa ukUHU1POVBJZFHSKhWXULOrRrdh4K3vuTiL1F0zClodaP04Wr4gYp3rCGMLm2/LNsSdm ENWjsDJVwzd8l3NRlWka5SjEzKifDrxYMAk533jeg0kRGXFkVPnCE39DNiwKM3baMsWg wGHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=lTRu+E4C; 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 hq29si8386592ejc.133.2021.07.15.14.10.32; Thu, 15 Jul 2021 14:10:56 -0700 (PDT) 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=lTRu+E4C; 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 S241545AbhGOTV6 (ORCPT + 99 others); Thu, 15 Jul 2021 15:21:58 -0400 Received: from mail.kernel.org ([198.145.29.99]:39758 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241646AbhGOTFv (ORCPT ); Thu, 15 Jul 2021 15:05:51 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 4A709613E7; Thu, 15 Jul 2021 19:02:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626375738; bh=TywS3+8OR6jJVRM/MIr9EVIcjLg13f71Y5+XN6BhK9g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lTRu+E4CJDtNj67AainxPP2FRiUKB78H6zwQVkHMdQoLIKUYa4Cj+WGkIjvAZjwJj SAFP3oTGnbuPA43E6vNpZxqM8Xt4YBxE+YCowmJSkBL56cTd5ZsSmVjhGoS4CwUAWs nI7YT8dn9feHZQaCNkk0RicZKAkskhzQV52zPNnU= 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.12 216/242] dm writecache: flush origin device when writing and cache is full Date: Thu, 15 Jul 2021 20:39:38 +0200 Message-Id: <20210715182631.135048546@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210715182551.731989182@linuxfoundation.org> References: <20210715182551.731989182@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 ee55b92a7391bf871939330f662651b54be51b73 upstream. Commit d53f1fafec9d086f1c5166436abefdaef30e0363 ("dm writecache: do direct write if the cache is full") changed dm-writecache, so that it writes directly to the origin device if the cache is full. Unfortunately, it doesn't forward flush requests to the origin device, so that there is a bug where flushes are being ignored. Fix this by adding missing flush forwarding. For PMEM mode, we fix this bug by disabling direct writes to the origin device, because it performs better. Signed-off-by: Mikulas Patocka Fixes: d53f1fafec9d ("dm writecache: do direct write if the cache is full") Cc: stable@vger.kernel.org # v5.7+ Signed-off-by: Mike Snitzer Signed-off-by: Greg Kroah-Hartman --- drivers/md/dm-writecache.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) --- a/drivers/md/dm-writecache.c +++ b/drivers/md/dm-writecache.c @@ -1297,8 +1297,12 @@ static int writecache_map(struct dm_targ writecache_flush(wc); if (writecache_has_error(wc)) goto unlock_error; + if (unlikely(wc->cleaner)) + goto unlock_remap_origin; goto unlock_submit; } else { + if (dm_bio_get_target_bio_nr(bio)) + goto unlock_remap_origin; writecache_offload_bio(wc, bio); goto unlock_return; } @@ -1377,7 +1381,7 @@ read_next_block: } e = writecache_pop_from_freelist(wc, (sector_t)-1); if (unlikely(!e)) { - if (!found_entry) { + if (!WC_MODE_PMEM(wc) && !found_entry) { direct_write: e = writecache_find_entry(wc, bio->bi_iter.bi_sector, WFE_RETURN_FOLLOWING); if (e) { @@ -2481,7 +2485,7 @@ overflow: goto bad; } - ti->num_flush_bios = 1; + ti->num_flush_bios = WC_MODE_PMEM(wc) ? 1 : 2; ti->flush_supported = true; ti->num_discard_bios = 1;