Received: by 2002:a05:6a10:83d0:0:0:0:0 with SMTP id o16csp33607pxh; Thu, 7 Apr 2022 13:07:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyJHX9rw4ruTdFDGbfrevCUKBsNJnuBd7M6JAGVIgL+j1NG0cn8p/mtD00yEyOyEAsN+1Q4 X-Received: by 2002:a63:1f55:0:b0:382:65eb:3073 with SMTP id q21-20020a631f55000000b0038265eb3073mr12859189pgm.624.1649362075257; Thu, 07 Apr 2022 13:07:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649362075; cv=none; d=google.com; s=arc-20160816; b=WVqIgCym0hn/7M4JxVbMST73R2s8akQOuYaaoQX/BtIhQXyG0plF2lIU0YItxSIdvm MKYFv2QSHTen4FxKQLLOLZyeKQeWiZagRsZDA8Z5ia/6e7iDInFMM14dhpLBqu92gpMU rvxgIjn3Jlq7xBv+OrVzyFw0JurBbz2WNBlcIgULZ4NFtere73YYY2L1z+U1DOt0AhJd jp+b154+YoRNsFBcLiHajlT1+LQIIkhx0y6cEbHGCdiXZ05Q1a6gsvWDhYDHfZ9GSeVj 9WS0sJ4S+mlqX6vADLG3deBWJ/QKlihfPMMMJXOyoKvTjlqfghRsgtxGNirgI/wMwLI2 MIBA== 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:date:cc:to:from:subject :message-id:dkim-signature; bh=prmvCyWVA1YJQ+1/pYGXUtQzqS/MAxIh3m8e4pA+yis=; b=Oa2TfcgOtSmYanEcYh+zOS8VwNnjet4lb2eUEye3O4Bva26IbKyHafpMd34//wSPdE ome2zEyjX0GyQ6RItthmQNIdXb4jWFv1wN79pz94oy+0UrTThlBRJMkG+Awl4Frp0Jip ydTKuCEN53xk+UizZfyqQcQXOu8myfSgjawQScIxBa7WC+R5dTiO+waQ7LM5mxjbmxvM aH7FF1sXy+U+d8sRmHe22aJvBjQEWRC7kznRCCaVt086aRvcwIejY8JTBCVRPJzqPUl0 hLRcg6n3wft5EuBZuJ3J/afR+uKzMRbiBqE/h5IClcQzckD8gR9VJ+MZU7As9jn8/vgT xG9g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=cppC84rQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1: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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id g184-20020a636bc1000000b0039cd17a62aesi2054597pgc.508.2022.04.07.13.07.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Apr 2022 13:07:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=cppC84rQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1: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: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id DA2312AE9EE; Thu, 7 Apr 2022 12:31:21 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344198AbiDGOpE (ORCPT + 99 others); Thu, 7 Apr 2022 10:45:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39266 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344192AbiDGOpC (ORCPT ); Thu, 7 Apr 2022 10:45:02 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8093FE9B; Thu, 7 Apr 2022 07:43:02 -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 30DA2B81D07; Thu, 7 Apr 2022 14:43:01 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4DA35C385A0; Thu, 7 Apr 2022 14:42:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1649342579; bh=MBOJXf3iG0OF4r/zC3Hvr0kP73zPBPUMWPKN3AlyNfE=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=cppC84rQQ/Ih5J6TuGWd9/cxhE0YJiSAO4pNT+Syse4TsRcpmYlnqaJiZyPphlosi VcvsX73zSPCy/2FH6TxeTlVfpjc/PT8rfl7IRsOsykEndxABjGAmUGp0El2GkDqk8P 6gjkP4AWW1Naz05sW8q24L1+HJ+OMAJgLTq2CwksvKNrj+BM7VA20Qs3iqrWGplyPK 9OpbnqG8F18z4wjTJeM+jXYIAyHO3EHqwbaTmOFoH8ZIDwNqaNW8K70QgiRVovMMCQ SdkU6Z/3u8otGAAdBJ4BWqPWIg94FiiqadGhegh10FsixBNGyBCOuZl/xLO1L0aI1s 7zg/isiP9sm+g== Message-ID: <96a44a4224b67b9ec36198bc0586064df5c4ad2a.camel@kernel.org> Subject: Re: [PATCH v3] ceph: invalidate pages when doing direct/sync writes From: Jeff Layton To: =?ISO-8859-1?Q?Lu=EDs?= Henriques , Xiubo Li , Ilya Dryomov Cc: ceph-devel@vger.kernel.org, linux-kernel@vger.kernel.org Date: Thu, 07 Apr 2022 10:42:57 -0400 In-Reply-To: <20220407143834.7516-1-lhenriques@suse.de> References: <20220407143834.7516-1-lhenriques@suse.de> Content-Type: text/plain; charset="ISO-8859-15" User-Agent: Evolution 3.42.4 (3.42.4-1.fc35) MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 On Thu, 2022-04-07 at 15:38 +0100, Lu?s Henriques wrote: > When doing a direct/sync write, we need to invalidate the page cache in > the range being written to. If we don't do this, the cache will include > invalid data as we just did a write that avoided the page cache. > > Signed-off-by: Lu?s Henriques > --- > fs/ceph/file.c | 9 +++++++++ > 1 file changed, 9 insertions(+) > > Ok, here's a new attempt. After discussion in this thread and on IRC, I > think this is the right fix. generic/647 now passes with and without > encryption. Thanks! > > Changes since v2: > - Invalidation needs to be done after a write > > Changes since v1: > - Replaced truncate_inode_pages_range() by invalidate_inode_pages2_range > - Call fscache_invalidate with FSCACHE_INVAL_DIO_WRITE if we're doing DIO > > diff --git a/fs/ceph/file.c b/fs/ceph/file.c > index 5072570c2203..63e67eb60310 100644 > --- a/fs/ceph/file.c > +++ b/fs/ceph/file.c > @@ -1938,6 +1938,15 @@ ceph_sync_write(struct kiocb *iocb, struct iov_iter *from, loff_t pos, > break; > } > ceph_clear_error_write(ci); > + ret = invalidate_inode_pages2_range( > + inode->i_mapping, > + pos >> PAGE_SHIFT, > + (pos + len - 1) >> PAGE_SHIFT); > + if (ret < 0) { > + dout("invalidate_inode_pages2_range returned %d\n", > + ret); > + ret = 0; > + } > pos += len; > written += len; > dout("sync_write written %d\n", written); Looks good. I suspect we can also remove the invalidate_indode_pages2_range call earlier in this function too. I may roll that into this patch. I'll give this an xfstests run with fscrypt enabled and see how it does. Thanks! -- Jeff Layton