From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1DD4FC48BE0 for ; Fri, 11 Jun 2021 19:59:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EFFA0613DD for ; Fri, 11 Jun 2021 19:59:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229572AbhFKUBE (ORCPT ); Fri, 11 Jun 2021 16:01:04 -0400 Received: from mail.kernel.org ([198.145.29.99]:56540 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229517AbhFKUBE (ORCPT ); Fri, 11 Jun 2021 16:01:04 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 588DC60E0C; Fri, 11 Jun 2021 19:59:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1623441546; bh=zGLh6jjFNwduHrvlKfYX7nEfbowtDvQIo4yr7fHtgfM=; h=From:To:Cc:Subject:Date:From; b=sU3elu28L0bjmBGcO7+SCnRLj6EPjqXtrLVKseGDVl0A/yO7ATrR9/oZ4hP97elQp f+biToqPmuysamBkyCkFosg9WjwCRM4U1GCc4PeG3YgumKNtQx5dpCYgLpdVz1t8ec XlTxTac9LVPf8kLnlCjF4r4ww8fNp50aFEOhq0wRSiP/hP7wOq+YoCw3h+2G8PH453 OtczX6SZrBzpnKWXNJmbKvfpgxcGv1HgpgTxA4ZC1smQ3lXrJyKmEdbIM+KhsknRVw HofwM36cndfw/qmFBqGqwYu/A9FmLWTzAAsAU6o5U9tuW5Bz337IDEZtDc2sqgYvTd 01TzmIgLUQkew== From: Jeff Layton To: ceph-devel@vger.kernel.org Cc: linux-cachefs@redhat.com, pfmeec@rit.edu, willy@infradead.org, dhowells@redhat.com, idryomov@gmail.com, stable@vger.kernel.org, Andrew W Elble Subject: [PATCH] ceph: fix write_begin optimization when write is beyond EOF Date: Fri, 11 Jun 2021 15:59:04 -0400 Message-Id: <20210611195904.160416-1-jlayton@kernel.org> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org It's not sufficient to skip reading when the pos is beyond the EOF. There may be data at the head of the page that we need to fill in before the write. Only elide the read if the pos is beyond the last page in the file. Cc: # v5.10 .. v5.12 Fixes: 1cc1699070bd ("ceph: fold ceph_update_writeable_page into ceph_write_begin") Reported-by: Andrew W Elble Signed-off-by: Jeff Layton --- fs/ceph/addr.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) Note to stable maintainers: This is needed in v5.10.z - v5.12.z. In v5.13, we've moved to using the new netfs_read_helper code so this isn't necessary there. I also now have a simple testcase for this that I'll submit to xfstests early next week. diff --git a/fs/ceph/addr.c b/fs/ceph/addr.c index 26e66436f005..e636fb8275e1 100644 --- a/fs/ceph/addr.c +++ b/fs/ceph/addr.c @@ -1353,11 +1353,11 @@ static int ceph_write_begin(struct file *file, struct address_space *mapping, /* * In some cases we don't need to read at all: * - full page write - * - write that lies completely beyond EOF + * - write that lies in a page that is completely beyond EOF * - write that covers the the page from start to EOF or beyond it */ if ((pos_in_page == 0 && len == PAGE_SIZE) || - (pos >= i_size_read(inode)) || + (index > (i_size_read(inode) / PAGE_SIZE)) || (pos_in_page == 0 && (pos + len) >= i_size_read(inode))) { zero_user_segments(page, 0, pos_in_page, pos_in_page + len, PAGE_SIZE); -- 2.31.1