Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp707676iob; Wed, 4 May 2022 06:30:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzuXlZMO0t/HrlLcU9MPpkQ3ciXNEtJenIuXFuRBzDA/RgMg5vXQZrTYLQIfmBKQEPBrGPx X-Received: by 2002:a17:906:2001:b0:6f3:bd7f:d878 with SMTP id 1-20020a170906200100b006f3bd7fd878mr20821020ejo.133.1651671008363; Wed, 04 May 2022 06:30:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651671008; cv=none; d=google.com; s=arc-20160816; b=mEeY8rsjbHOt9NlrjyNEB0dvDBsSk29VUtxNiaWgBfocLfm/0f+D27rBtAvZY0f7j+ a+u52WIDLC68qlljSGNrCVEJ2DXWpP98reSW1OXAAqbPm5kKxsPCl7dUyocvQgY1yRT6 URldVANK+h5leTjkQ7IcGAZWdKpQomg/fq8hQn/4xhjXs06D0LVAjTUG5QSHgj0RG1W5 sgyc810oV7VDLAyZVfZwxWKskypjVCj8YEECNUrZN1GQZH9R3YcEJiGtBsRhk5kbkpSl XRyIK6H3m6WfyTLxMHvQmjdggP/lrXODnccmji1xhe9rSlz7XVEdBRG5C/ZE2ONy7DnJ y+1Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=pahes7C/tmc6/DL1WldFW1GN6sPT/c4aOjyuB4GyOjo=; b=KePwYZo2Tt7+KzuwJaVWHTbI056dlftxTWIeu4gnuniHP7yqbGuRoDG1KaMubvyRG4 Pmmn9LJxWMllQ0/+I1SvlT76mTOWRMf4ldlGANWB98nzto33kGDurjgtuMIoFk18v3Yg AjxqBM10fwcBAdUILIs6HpjGP5Nz9VvK8YBwZ7ypGPYqdP+mpNnmurxA37JQgsIt2ZMC Zz6DOgOENTPUb3Nx2akomvJohBP/9W/tq1f4t/k7riqiFjn8Bmc0wct5zLBB2lZpEJIi QmU6oqtV6wopMrvDnyyzzQaCztT0sQqEOw6eU0ZL5y7YMakLipod6rYeP9Z4FpuGHNQE VGsw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=dIXyraVR; 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=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id dz11-20020a0564021d4b00b00427c7749b84si7468569edb.228.2022.05.04.06.29.43; Wed, 04 May 2022 06:30:08 -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=@redhat.com header.s=mimecast20190719 header.b=dIXyraVR; 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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239677AbiECQpH (ORCPT + 99 others); Tue, 3 May 2022 12:45:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37458 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231324AbiECQpG (ORCPT ); Tue, 3 May 2022 12:45:06 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 4E5DF1A07B for ; Tue, 3 May 2022 09:41:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1651596092; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=pahes7C/tmc6/DL1WldFW1GN6sPT/c4aOjyuB4GyOjo=; b=dIXyraVRoTPf01vJm5a1/gQ32dATrVAeJ1E/KDvwq1DRYaFWa38mN4CdrxW6feIIK8L+ZS Dxe5gEiwthNwlSLLntHo4keLDKaAAsVt1KPOJZkBsRqD+LvYiJ7O7r2MWVWB6Cv0896wxQ ilGKtv2iUx/tL70GuCaiGmlM+k+qMeg= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-491-WQkx191tM5KaVMuB7t7ogw-1; Tue, 03 May 2022 12:41:30 -0400 X-MC-Unique: WQkx191tM5KaVMuB7t7ogw-1 Received: by mail-wm1-f72.google.com with SMTP id c125-20020a1c3583000000b0038e3f6e871aso6077795wma.8 for ; Tue, 03 May 2022 09:41:29 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=pahes7C/tmc6/DL1WldFW1GN6sPT/c4aOjyuB4GyOjo=; b=IU8ENrQbHRrsc/Jfb3b8tVwZQpx7aGNqxpMSaBBMtwFrzfA3Dx9iXSfDn4atKVGOxT jiSPuTcCnhh8+toKfKXfLDduGvbCkkv/GN/xFAQanJNGoWwojySrNNbgQHAbqAYSQzS7 Veab3nBdC01f07vCtKsNvjJ4yeXoUAmIh8dNibpb9s0/WiHVZPyei0PTAUynAUZWXizH ClIN+Fc+6X5vFCWZFmg942heAdn29Au12vMDAko4e0FUhgU/g5E58WR/e2szUpRIZt2C hSGAP31/upnm3/aaFdIlk+QzEff95Tb5Kk/Td74sbbpyutUHeoUXixFvsxH8cVvTfXKH gCLQ== X-Gm-Message-State: AOAM531FHz/dY0z0rNM/LQX6R75dSs2R0MwpRXnxeGNclB+Ro10qZPAJ O7FFVKRvICAI/o5fB9yVFNx/p4TbXsIhYWywXH4/lZQvatzhV0BUzUwItFZcbSsBpxHWQmr80PQ b0ZLrTI3epHm+dJaBP2/YdY0xJRXWcVNiEeuzLYSU X-Received: by 2002:a05:6000:1848:b0:20c:713b:8e1e with SMTP id c8-20020a056000184800b0020c713b8e1emr4687686wri.640.1651596088858; Tue, 03 May 2022 09:41:28 -0700 (PDT) X-Received: by 2002:a05:6000:1848:b0:20c:713b:8e1e with SMTP id c8-20020a056000184800b0020c713b8e1emr4687668wri.640.1651596088626; Tue, 03 May 2022 09:41:28 -0700 (PDT) MIME-Version: 1.0 References: <20220426145445.2282274-1-agruenba@redhat.com> In-Reply-To: From: Andreas Gruenbacher Date: Tue, 3 May 2022 18:41:17 +0200 Message-ID: Subject: Re: [GIT PULL] gfs2 fix To: Linus Torvalds Cc: Christoph Hellwig , "Darrick J. Wong" , Dave Chinner , cluster-devel , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-3.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE 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 On Tue, May 3, 2022 at 6:19 PM Linus Torvalds wrote: > > On Tue, May 3, 2022 at 1:56 AM Andreas Gruenbacher wrote: > > > > We still get data corruption with the patch applied. The > > WARN_ON_ONCE(!bytes) doesn't trigger. > > Oh well. I was so sure that I'd finally found something.. That partial > write case has had bugs before. > > > As an additional experiment, I've added code to check the iterator > > position that iomap_file_buffered_write() returns, and it's all > > looking good as well: an iov_iter_advance(orig_from, written) from the > > original position always gets us to the same iterator. > > Yeah, I've looked at the iterator parts (and iov_iter_revert() in > particular) multiple times, because that too is an area where we've > had bugs before. > > That too may be easy to get wrong, but I couldn't for the life of me > see any issues there. > > > This points at gfs2 getting things wrong after a short write, for > > example, marking a page / folio uptodate that isn't. But the uptodate > > handling happens at the iomap layer, so this doesn't leave me with an > > immediate suspect. > > Yeah, the uptodate setting looked safe, particularly with that "if we > copied less than we thought we would, and it wasn't uptodate, just > claim we didn't do anything at all". > > That said, I now have a *new* suspect: the 'iter->pos' handling in > iomap_write_iter(). > > In particular, let's look at iomap_file_buffered_write(), which does: > > while ((ret = iomap_iter(&iter, ops)) > 0) > iter.processed = iomap_write_iter(&iter, i); > > and then look at what happens to iter.pos here. > > iomap_write_iter() does this: > > loff_t pos = iter->pos; > ... > pos += status; > > but it never seems to write the updated position back to the iterator. > > So what happens next time iomap_write_iter() gets called? > > This looks like such a huge bug that I'm probably missing something, > but I wonder if this is normally hidden by the fact that usually > iomap_write_iter() consumes the whole 'iter', so despite the 'while()' > loop, it's actually effectively only called once. > > Except if it gets a short write due to an unhandled page fault.. > > Am I entirely blind, and that 'iter.pos' is updated somewhere and I > just missed it? That's happening in iomap_file_buffered_write() and iomap_iter(): while ((ret = iomap_iter(&iter, ops)) > 0) iter.processed = iomap_write_iter(&iter, i); Here, iomap_write_iter() returns how much progress it has made, which is stored in iter.processed, and iomap_iter() -> iomap_iter_advance() then updates iter.pos and iter.len based on iter.processed. Andreas