Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp636013pxv; Thu, 15 Jul 2021 12:06:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx44WCB3V2TAWvIYyaub6VqsE7RykZNgp7LwgrDi3q9ZTXdG2+3v9jl90y/IcsV45Qc/Zo3 X-Received: by 2002:a05:6402:22aa:: with SMTP id cx10mr9007650edb.0.1626375981174; Thu, 15 Jul 2021 12:06:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626375981; cv=none; d=google.com; s=arc-20160816; b=wVbjPo6SViT0LkFotphMF//09eaPUmrnhvLR/Xf3IEt0IzzHlaPwMyXoazEVf24cEq 3ivcfVN8bVm7BHN48KcRVpMLGKRzm+DhrbnmR50ckq8dYBgFiU4Cy4U8bZI744jRXfhE HBJ6hTP+QSV+COYdZXTK8/47mJhdkvLmwjTGvcZKJBWMGb1REDN1qGYL98qWj7rrGP+Z 0FX8hD3Zhon01w9PG/ZVxThPyt0pV12c+KuVRZG5+gtNtOuBvqbdfioEqzCJtNsd2NYj pRCwLkZZj1MqzF9ct/5fGHzIVVfDeTKytJaUnNBgo08qf2lcVZOwc5eLqjMPg1sV0j2P U0Sw== 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=s1UdKl6ggqVPXpRhpNN+xUD1eBPPBcZrHEeEFQ29KCI=; b=B4qb4vi8EeoaBaQuIZvaHsk1zVbxNJ7f1zMCAwp/U9rkjvk8wi8Om4KSTvU4ORsiXI HlmBoizYZY33VyjUje874koyy2GR4iW0LSgqhE7k5p2pry8VdByIIwrP4mTXkfNmBypo 7kCrVTShE+or5l3/mIvscpYxBLKTzr3DX/s2NdlumK9wEVB3cRFNpdiEv4y0Dq2bUtP9 IboHwvl+aZ5p+it/CCNMbQpOiT9Sy+P0VQD4qK4QWue2vCyPKtzEr9TCDvAXiYjsa1AG eX6TQzWLt3hteGWpe5mK7JmmbMfpKtzZy3dN0nYhIZcMUJtPmTt2xivcSTs/aH3AJLU2 vZ4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=nD+Yj6kO; 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 qx23si8273425ejb.137.2021.07.15.12.05.58; Thu, 15 Jul 2021 12:06:21 -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=nD+Yj6kO; 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 S243013AbhGOTHF (ORCPT + 99 others); Thu, 15 Jul 2021 15:07:05 -0400 Received: from mail.kernel.org ([198.145.29.99]:33728 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239976AbhGOS4v (ORCPT ); Thu, 15 Jul 2021 14:56:51 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 4295F613D9; Thu, 15 Jul 2021 18:53:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626375237; bh=sVhJ9Ua9XktMFt+Jrg29u7/0hwbuCGE/h+8ziQOROd8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nD+Yj6kO13zhtb7uRrjx5o4pDcCVv2iBm8VCowe3yArdQS/YqrnIR8etHB8A52k2U UmNBvF1RObmIzjUACR26oFxqtfiVdv/j91DKZOFqSd0dG783g2vqbAxqTpxkv08jrv PBcvK364RV2ENGLwiUXjhodK9ecvszX6Qtq7hkBw= 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 196/215] dm writecache: flush origin device when writing and cache is full Date: Thu, 15 Jul 2021 20:39:28 +0200 Message-Id: <20210715182633.802741131@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210715182558.381078833@linuxfoundation.org> References: <20210715182558.381078833@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) { @@ -2483,7 +2487,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;