Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp107900ybg; Mon, 8 Jun 2020 17:48:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwZVH7pYU4YdkpouPdd2wjc2HXVNo+LN5liRQPHhsW65+CzdCxmAdkNtinhteIPkea+7hWO X-Received: by 2002:a17:906:6b8e:: with SMTP id l14mr23977962ejr.32.1591663737272; Mon, 08 Jun 2020 17:48:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591663737; cv=none; d=google.com; s=arc-20160816; b=JKChoj7DNX8f7b1zPwIhL7eXcjpFFBwz5hMrxrMN8qGnHhaY66/ZRV5gJZxqUyd9Jc jCZ3bJx2apkahs+cWkI9aw4NzoAR9IUl30QvWzjOleEKd9lHBYz7Qn0xQHKnfsy/JtE6 6mQxGUuk8Y+y6BL6iJI5Rws6S9XZPXM2WsHR7WwCEiVf+sRVI+qi5t2LQcSnwUT62FzO eJ0pcFlAJlbCaxHhRrPVqZilo6+n/j1ud9vjXOKUZbsfnMJUHvzdsQJ0b7LODrBcgqNl fDxs/zAF0w5FNJUY0CrL+GtoVymUp6XplHuCFkzcetURHZbu0UyY00keJ1SFpOr0VNy+ +sJw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=jh3pG/a2jbsWhJR4dFWxDA2aIxxtDoZnGHr79xBai8o=; b=JtakgCB22PuAzf1M1LkedHr+KdHqfGCUysWFf3KldA4qTfDVwj3R7gIx8xhyenrdTz si+9vv57hPwRqYdUV+nzE/3NKWxdnweAYiBqnEoN0wG0TLcDIJNCBFUFlFG7Zp6dDvHR I7CfX5/h0iIHpntaGpSC3chDyxVgGuhoQRkQzBK04y+RSUpHEPK36O/iUHWYGwYCTEET cUXgIJkQ25gEeMITbuADbQr3xTDPsRD6vk90VnvlqPUWB20hhz973TjaatLE1w8usAgt BTTqnfECwM9JwQTr/iDyl9AK/MWuC4Y/fnv5joD5nycZZopeDHyqR3ZLeHjW7en1bpUW K6Mg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=lDxyYuoo; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f22si158880edt.167.2020.06.08.17.48.33; Mon, 08 Jun 2020 17:48:57 -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=@kernel.org header.s=default header.b=lDxyYuoo; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729770AbgFIAqv (ORCPT + 99 others); Mon, 8 Jun 2020 20:46:51 -0400 Received: from mail.kernel.org ([198.145.29.99]:58368 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727865AbgFHXL3 (ORCPT ); Mon, 8 Jun 2020 19:11:29 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id D12D120E65; Mon, 8 Jun 2020 23:11:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1591657888; bh=ccKiDK3evDF3ELMAGfBKIcswpEkX5T9uPmZmUMJvvZo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lDxyYuoobH/7VMXroh5HSlWA6BzBLsKRsdrnzBzgft+m6is/QX8VtaF8WvyYVgW09 vlfrp02zTtgf3SUfj8QQQjLwg2Z18mqT0QkTW7YViI1wKeJQmY9nC0/WO89N6dhC6x rtuTOlgyIA2YxQk9IGCFtvs6+pDy0K4XDqHMS+bM= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: "Darrick J. Wong" , Christoph Hellwig , Brian Foster , Sasha Levin , linux-xfs@vger.kernel.org Subject: [PATCH AUTOSEL 5.7 244/274] xfs: force writes to delalloc regions to unwritten Date: Mon, 8 Jun 2020 19:05:37 -0400 Message-Id: <20200608230607.3361041-244-sashal@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200608230607.3361041-1-sashal@kernel.org> References: <20200608230607.3361041-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: "Darrick J. Wong" [ Upstream commit a5949d3faedf492fa7863b914da408047ab46eb0 ] When writing to a delalloc region in the data fork, commit the new allocations (of the da reservation) as unwritten so that the mappings are only marked written once writeback completes successfully. This fixes the problem of stale data exposure if the system goes down during targeted writeback of a specific region of a file, as tested by generic/042. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig Reviewed-by: Brian Foster Signed-off-by: Sasha Levin --- fs/xfs/libxfs/xfs_bmap.c | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c index fda13cd7add0..f8fe83c9348d 100644 --- a/fs/xfs/libxfs/xfs_bmap.c +++ b/fs/xfs/libxfs/xfs_bmap.c @@ -4193,17 +4193,7 @@ xfs_bmapi_allocate( bma->got.br_blockcount = bma->length; bma->got.br_state = XFS_EXT_NORM; - /* - * In the data fork, a wasdelay extent has been initialized, so - * shouldn't be flagged as unwritten. - * - * For the cow fork, however, we convert delalloc reservations - * (extents allocated for speculative preallocation) to - * allocated unwritten extents, and only convert the unwritten - * extents to real extents when we're about to write the data. - */ - if ((!bma->wasdel || (bma->flags & XFS_BMAPI_COWFORK)) && - (bma->flags & XFS_BMAPI_PREALLOC)) + if (bma->flags & XFS_BMAPI_PREALLOC) bma->got.br_state = XFS_EXT_UNWRITTEN; if (bma->wasdel) @@ -4611,8 +4601,23 @@ xfs_bmapi_convert_delalloc( bma.offset = bma.got.br_startoff; bma.length = max_t(xfs_filblks_t, bma.got.br_blockcount, MAXEXTLEN); bma.minleft = xfs_bmapi_minleft(tp, ip, whichfork); + + /* + * When we're converting the delalloc reservations backing dirty pages + * in the page cache, we must be careful about how we create the new + * extents: + * + * New CoW fork extents are created unwritten, turned into real extents + * when we're about to write the data to disk, and mapped into the data + * fork after the write finishes. End of story. + * + * New data fork extents must be mapped in as unwritten and converted + * to real extents after the write succeeds to avoid exposing stale + * disk contents if we crash. + */ + bma.flags = XFS_BMAPI_PREALLOC; if (whichfork == XFS_COW_FORK) - bma.flags = XFS_BMAPI_COWFORK | XFS_BMAPI_PREALLOC; + bma.flags |= XFS_BMAPI_COWFORK; if (!xfs_iext_peek_prev_extent(ifp, &bma.icur, &bma.prev)) bma.prev.br_startoff = NULLFILEOFF; -- 2.25.1