Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp2729860imj; Mon, 11 Feb 2019 07:37:55 -0800 (PST) X-Google-Smtp-Source: AHgI3Iayt/TLm4rsg9m2Ew02R0jrY5OlQ+lDCov08Rw+d3HQopiAXa4RRfEBeBELqaMfA6aVZ/Qh X-Received: by 2002:a63:fa51:: with SMTP id g17mr29227273pgk.66.1549899475542; Mon, 11 Feb 2019 07:37:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549899475; cv=none; d=google.com; s=arc-20160816; b=GUNy8Kmm5xvkqeAq+jvgYUX+dxlurlS+Dg4Vq9ZIyrlqR+fBA+NSDLdogO+3tIlkUZ pJZSPwNJSvip81A1JnUCdxHeV/QuRDXEVJNwI4ve/5cgTjCDotWRkaIWDtZ4mp9kyrrh /xrpmv2JaVQfgR887oghhTbdCR8KvKx4XGzZpvz3HpLY+54SLez1H9rgVFwjuQ562VW9 PgxMwuAp492IDWsU6mpevQKs8LA5jDOGBmBAnLfzNJKAl2GSrwS1PJfqGrXain85RXRp 0rt2ALoHlCXEUqbNR3qdN+BDYSc7unvX+xgpQLXsK93bnfGVW+cvSaOL6cQ5FZW5t0GJ 3fKA== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=9hnwj2DzYnT6VxM5Xu6UfCtOXb8SerVX7svmBtUwZFc=; b=hGj/3Kyj3ferBVNWzTec9GOoRA5Tvm4ih3+V3MlKb+ES2WdDOLQl0N0kI35u2MTZRz Kl3phnsiAupOu377GKnMs65cFrsgAfHtuUsszslewCPIYlC9IqlTd3ULhQk/SYuiy4y5 3aMcMdVMsCSNz4PWEDWH3PGi0xT6LQgIY0kADbzN0KyLAfDBy3IZYhCQOkFvPcnPD/nG 1ocNQ0z5fD1x4qdfRl7/+vZ6sHLIqr8x634sJBw2VH4NXcsFdX7Fmpa1D+2rONpqNWuu AHwcjLO+lhzP45dnZIP8r1cg5ckrsEJK9qffXEAbcs6kLCj3X/Bw5NQFTyppePqqGN6C Yrag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=z0ej70Zo; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g8si9317165pgb.128.2019.02.11.07.37.39; Mon, 11 Feb 2019 07:37:55 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=z0ej70Zo; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388440AbfBKOw3 (ORCPT + 99 others); Mon, 11 Feb 2019 09:52:29 -0500 Received: from mail.kernel.org ([198.145.29.99]:38700 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388433AbfBKOw1 (ORCPT ); Mon, 11 Feb 2019 09:52:27 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id DFCE42081B; Mon, 11 Feb 2019 14:52:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1549896746; bh=H+W83pPOWz7JISs4TurBJBvN+grw1a12Ol4WtJxt+0g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=z0ej70ZoatATxd/j0XOAAzAiDdWypk3klm2AN1/+bOMSux2df1x0M4a7xTWRaN0Da GtFvIh9BzGfZZyNDmTPoNe2j1beNfSBafwKH0aiyM2hItCLZkSrYEsH23UaEAVukTN vHqPolsYuwPx2iRMGjsDPhUESlrD4NaWSfzJB9dc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Darrick J. Wong" , Dave Chinner , Christoph Hellwig , Luis Chamberlain , Sasha Levin Subject: [PATCH 4.19 256/313] xfs: fix PAGE_MASK usage in xfs_free_file_space Date: Mon, 11 Feb 2019 15:18:56 +0100 Message-Id: <20190211141910.419927356@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190211141852.749630980@linuxfoundation.org> References: <20190211141852.749630980@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.19-stable review patch. If anyone has any objections, please let me know. ------------------ commit a579121f94aba4e8bad1a121a0fad050d6925296 upstream. In commit e53c4b598, I *tried* to teach xfs to force writeback when we fzero/fpunch right up to EOF so that if EOF is in the middle of a page, the post-EOF part of the page gets zeroed before we return to userspace. Unfortunately, I missed the part where PAGE_MASK is ~(PAGE_SIZE - 1), which means that we totally fail to zero if we're fpunching and EOF is within the first page. Worse yet, the same PAGE_MASK thinko plagues the filemap_write_and_wait_range call, so we'd initiate writeback of the entire file, which (mostly) masked the thinko. Drop the tricky PAGE_MASK and replace it with correct usage of PAGE_SIZE and the proper rounding macros. Fixes: e53c4b598 ("xfs: ensure post-EOF zeroing happens after zeroing part of a file") Signed-off-by: Darrick J. Wong Reviewed-by: Dave Chinner Reviewed-by: Christoph Hellwig Signed-off-by: Luis Chamberlain Signed-off-by: Sasha Levin --- fs/xfs/xfs_bmap_util.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fs/xfs/xfs_bmap_util.c b/fs/xfs/xfs_bmap_util.c index 9d1e5c3a661e..211b06e4702e 100644 --- a/fs/xfs/xfs_bmap_util.c +++ b/fs/xfs/xfs_bmap_util.c @@ -1175,9 +1175,9 @@ xfs_free_file_space( * page could be mmap'd and iomap_zero_range doesn't do that for us. * Writeback of the eof page will do this, albeit clumsily. */ - if (offset + len >= XFS_ISIZE(ip) && ((offset + len) & PAGE_MASK)) { + if (offset + len >= XFS_ISIZE(ip) && offset_in_page(offset + len) > 0) { error = filemap_write_and_wait_range(VFS_I(ip)->i_mapping, - (offset + len) & ~PAGE_MASK, LLONG_MAX); + round_down(offset + len, PAGE_SIZE), LLONG_MAX); } return error; -- 2.19.1