Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp793474rwb; Mon, 26 Sep 2022 06:03:46 -0700 (PDT) X-Google-Smtp-Source: AMsMyM60f485MVKvvm7nNPXSX++6yRwPhZbndVzlmlPJ2nwH0UyL4vMShmWJ6dDcDMpPsojLzR7W X-Received: by 2002:a62:d403:0:b0:54b:a7e4:909c with SMTP id a3-20020a62d403000000b0054ba7e4909cmr23257970pfh.61.1664197426241; Mon, 26 Sep 2022 06:03:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664197426; cv=none; d=google.com; s=arc-20160816; b=OC7FZRhV8RRbbuNK6HPM6uwZcEciITtd2AdzZ4TJFYcu1ZdxJbyi4MIgptiyN1H77z mlkxUZqkss6bT62ujsXN0g9MhXLgR3Pq8+NSA7H4WkU0uAP/94RsOrnBgGrfHmxQLdrI bhlPe+PdfkseQVY8LWRpsxtN7mxKmNDchSApjSFp329S3ZlZNNSVl+O7Zuzzu4BEctLu qvONtAnS/ydO9KeppOn2yOr5tQyF9cNFK4gc6ws1POdBWJ9UjOfbBUFvIAfj/qm7xyB+ 6iJOcvAbQ3cRd+ERfw0royV971f1sedNsuUYyCPG8cpqBaj6pAydMThLQXXb6//Z2iBO WJeg== 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=F7O6zJroiC0LCOyZJOGAl4h3T3Rmch1H3M6VrHDSwrg=; b=hvPXF4UmeZUBp2XB9GR2lAsCNsOHpq5oT2Jy5Vp5tn31Qvxw7wkOfZnoiv+yaJqRs8 8w3xV7VUgrGo+pjfA61u07ItzjS9JQAInq+7XUtum9cXzJsKsA+MZj1v/wRyfBe3G66A Xdtv1/NGhr5sT6D5GV179a9GYtNjEfKV2jOE3urxqF5nReQzVurbh7H2NHi5CRlbfont Vo5+qBLFq+CHcvGO0nAOVT+TLHRFs+DENOF/Uuk62/zrBH/DALAM8nh4CMnyJXwxZ91k p6QJ3SJnOqYFcvBRfSEaTM1oDd0lJPdSCrwY6b1GSPZgyjs7HlNwVBzNHfqA6HhXvkHX 4zTA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=KUWNpBeX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n7-20020a170902d2c700b0017555e9de54si11785897plc.427.2022.09.26.06.03.34; Mon, 26 Sep 2022 06:03:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=KUWNpBeX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S235999AbiIZKgK (ORCPT + 99 others); Mon, 26 Sep 2022 06:36:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37446 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235978AbiIZKdp (ORCPT ); Mon, 26 Sep 2022 06:33:45 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C5A664F6BC; Mon, 26 Sep 2022 03:20:46 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 947CAB80835; Mon, 26 Sep 2022 10:20:44 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 066B5C433C1; Mon, 26 Sep 2022 10:20:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1664187643; bh=/qy+wl376VZ2Qn1ipDOjXipIVOsRHSCbVcNW+nRvVyM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KUWNpBeXVweOCgruM9wZuLLJXtZcErx7fl91quTFbHo+8RB6+qVlM0EQR6QL8Ycwz n/jXZTrVnPGBFfGbhYgiCGgz2YbNOvQcHlu9ixuP7b108a0jqAVPtp3hEQsfT2Zk2t KwOVUSdOwS67XLderFVYJcXiRbSxmhcwcDmllpLg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dave Chinner , Christoph Hellwig , "Darrick J. Wong" , "Darrick J. Wong" , Chandan Babu R Subject: [PATCH 5.4 015/120] iomap: iomap that extends beyond EOF should be marked dirty Date: Mon, 26 Sep 2022 12:10:48 +0200 Message-Id: <20220926100751.145723992@linuxfoundation.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220926100750.519221159@linuxfoundation.org> References: <20220926100750.519221159@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Chandan Babu R From: Dave Chinner commit 7684e2c4384d5d1f884b01ab8bff2369e4db0bff upstream. When doing a direct IO that spans the current EOF, and there are written blocks beyond EOF that extend beyond the current write, the only metadata update that needs to be done is a file size extension. However, we don't mark such iomaps as IOMAP_F_DIRTY to indicate that there is IO completion metadata updates required, and hence we may fail to correctly sync file size extensions made in IO completion when O_DSYNC writes are being used and the hardware supports FUA. Hence when setting IOMAP_F_DIRTY, we need to also take into account whether the iomap spans the current EOF. If it does, then we need to mark it dirty so that IO completion will call generic_write_sync() to flush the inode size update to stable storage correctly. Fixes: 3460cac1ca76 ("iomap: Use FUA for pure data O_DSYNC DIO writes") Signed-off-by: Dave Chinner Signed-off-by: Christoph Hellwig Reviewed-by: Darrick J. Wong [darrick: removed the ext4 part; they'll handle it separately] Signed-off-by: Darrick J. Wong Acked-by: Darrick J. Wong Signed-off-by: Chandan Babu R Signed-off-by: Greg Kroah-Hartman --- fs/xfs/xfs_iomap.c | 7 +++++++ include/linux/iomap.h | 2 ++ 2 files changed, 9 insertions(+) --- a/fs/xfs/xfs_iomap.c +++ b/fs/xfs/xfs_iomap.c @@ -1055,6 +1055,13 @@ xfs_file_iomap_begin( trace_xfs_iomap_alloc(ip, offset, length, XFS_DATA_FORK, &imap); out_finish: + /* + * Writes that span EOF might trigger an IO size update on completion, + * so consider them to be dirty for the purposes of O_DSYNC even if + * there is no other metadata changes pending or have been made here. + */ + if ((flags & IOMAP_WRITE) && offset + length > i_size_read(inode)) + iomap->flags |= IOMAP_F_DIRTY; return xfs_bmbt_to_iomap(ip, iomap, &imap, shared); out_found: --- a/include/linux/iomap.h +++ b/include/linux/iomap.h @@ -32,6 +32,8 @@ struct vm_fault; * * IOMAP_F_DIRTY indicates the inode has uncommitted metadata needed to access * written data and requires fdatasync to commit them to persistent storage. + * This needs to take into account metadata changes that *may* be made at IO + * completion, such as file size updates from direct IO. */ #define IOMAP_F_NEW 0x01 /* blocks have been newly allocated */ #define IOMAP_F_DIRTY 0x02 /* uncommitted metadata */