Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp1273653pxu; Mon, 23 Nov 2020 16:43:06 -0800 (PST) X-Google-Smtp-Source: ABdhPJyAPlbFkIP6505rbv9bjTw1ihDauKarB89xG2NZWeyxYc5pDZbwkwLPePICGJVEE6oy2bXk X-Received: by 2002:aa7:d545:: with SMTP id u5mr1696510edr.113.1606178586232; Mon, 23 Nov 2020 16:43:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606178586; cv=none; d=google.com; s=arc-20160816; b=NM3NTkQMW7qg65QzCGBJvfdB5VI5uP3XEfq6xS9Tj4bMI4j0ayJ7czptZjR5aDqkeU YxJ0n3wEIKZDZ+kIz5iGfKgKgsfq9AHgBwvBfwxMpu5Ud8El4ndj7fYFMzr8Xo3pzycT yFvyd/uYI9Jqp3B1Ga3+hVY3OVMAXF8gSKC2mqWCOSEZr6Sycms6lJa8N74CH4vWoIit GX4Ksx64w796hOlYGI63Q6KfKu6cz9j3Y6DznptsQufLphXuEvxw7RAwbbkyraia87db lvPjcvwugl4Ga1Hj1xzaIXXiSEjGSBYNeJb8WhIoqIB1gswh4+A1rxK3KEPCkhSthmsB FPXQ== 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; bh=iC6D8/sl2ihZ01b7Fa50SWQPMJxbJZPwc7yRBlokxr0=; b=M2XdQUqgr6hWQHq4VaFACGuttWn1dlfW9gYLOm2zBIkmQi9saeGh+pYZ/n2QVtoYAZ Sm0KkWXLDFKoV7NjnM+svrqugjgFoQ9W80nG8ANHG5SJMiB+Sjc3AnnUxV7e2u9LUQFl RJh8oBW4gdYld0j8LK/xCfDqRvpT743ISDwFtWgiFQmp7wjWJeuXNWXMc9m6z//0CK3I ahLTfHRk9gauuXwVWHb00Na4XK5gzlq/MryzCbaznJ5+BmrKdkuNOLUU6c1rJD27tGhr E/sNGDmn0X1bLJo1/GXq7zKAxfMa/H+zd2UppMPssydad8bCMZQyxevm34byoBKYsBoC X1cw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=canonical.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p15si7554951edx.69.2020.11.23.16.42.43; Mon, 23 Nov 2020 16:43:06 -0800 (PST) Received-SPF: pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=canonical.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728567AbgKXADV (ORCPT + 99 others); Mon, 23 Nov 2020 19:03:21 -0500 Received: from youngberry.canonical.com ([91.189.89.112]:34035 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728035AbgKXADV (ORCPT ); Mon, 23 Nov 2020 19:03:21 -0500 Received: from mail-wr1-f72.google.com ([209.85.221.72]) by youngberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1khLni-0001X4-TY for linux-ext4@vger.kernel.org; Tue, 24 Nov 2020 00:03:18 +0000 Received: by mail-wr1-f72.google.com with SMTP id m2so2218086wro.1 for ; Mon, 23 Nov 2020 16:03:18 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=iC6D8/sl2ihZ01b7Fa50SWQPMJxbJZPwc7yRBlokxr0=; b=cSR5CIYFaAPPI1dLHc+BK6Rc0W3zZcXUsG2lKA7sGt0e4TFw2aGBZkktyz1IhCmJoH eOdpEKHGc6qLuPccGc4DxOMC3PyiHrE9HIS3K3ThJJVv6hG7EE20kTYAnBo2NW3n79// aVW876Fda6vsSzc/s/McP0ZSkZHmpoHP2rmQyTNvrjXSycfy0s+4wRqSJlnkNiPshfTY s7SwLmyrcBF8X9MAi5GBsa2uAp/58eSlkTZVNDWWGZpcHtAhzC89+IM9+XSxhnu875Zq i54lhN6H8gd+/KdtZDCtynl5eWGS3mMC6Skp80XNU6SXyWQQlhJOrg0VeklsR5QY6gT9 qdEg== X-Gm-Message-State: AOAM531lZc1HtSoK0PStLU9jhT43sqjc7Zw2B/qrRJoCWIi0LDWkrlI4 69Y2qnU4zqFFF7nlg1Jfps3zIdp2gKWwtn7awC5BvNgRjzExJ8mUxVy3ts2qkCfiBYwcG9Pj91C ZhkjlpYtM7aZ+dEvYy/HmcEQT2km7KDTxRXWkJ68n1fdOnUHu+W1v9uw= X-Received: by 2002:adf:ea47:: with SMTP id j7mr2151515wrn.126.1606176198114; Mon, 23 Nov 2020 16:03:18 -0800 (PST) X-Received: by 2002:adf:ea47:: with SMTP id j7mr2151506wrn.126.1606176197937; Mon, 23 Nov 2020 16:03:17 -0800 (PST) MIME-Version: 1.0 References: <20201027132751.29858-1-jack@suse.cz> <20201123093434.GA27294@quack2.suse.cz> In-Reply-To: <20201123093434.GA27294@quack2.suse.cz> From: Mauricio Faria de Oliveira Date: Mon, 23 Nov 2020 21:03:06 -0300 Message-ID: Subject: Re: [PATCH] ext4: Fix mmap write protection for data=journal mode To: Jan Kara Cc: Ted Tso , linux-ext4@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org Hey Jan, On Mon, Nov 23, 2020 at 6:34 AM Jan Kara wrote: > > ... > > > > The remaining checksum changes due to write-protect failures _seem_ to be > > a race between our write-protect with write_cache_pages() and writeback/sync. > > But I'm not exactly sure as it's been hard to find the timing/steps > > for both threads. > > The idea is, > > > > Our write_cache_pages() during commit / > > ext4_journalled_submit_inode_data_buffers() > > depends on PAGECACHE_TAG_DIRTY being set, for pagevec_lookup_range_tag() > > to put such pages in the array to be write-protected with > > clear_page_dirty_for_io(). > > > > With a debug patch to dump_stack() callers of > > __test_set_page_writeback(), that can > > xas_clear_mark() it, _while_ the page is still going in our call to > > write_cache_pages(), > > we see this: wb_workfn() -> ext4_writepage() -> ext4_ext4_bio_write_page(), > > I guess there was something between wb_workfn() and ext4_writepage(), > wasn't there? There should be write_cache_pages()... > Yes, you're right, I oversimplified the function path between the first two. :) (I'll use '...' in the future to make that clearer.) > > i.e., _not_ going through ext4_journalled_writepage(), which > > knows/waits on journal. > > The other leg of ext4_writepage() _doesn't_, and thus can clear the > > tag and prevent > > write-protect while the journal commit / our write_cache_pages() is running. > > So I don't think this is quite it. If there are two writebacks racing, > either of them will writeprotect the page which is enough for commit to be > safe (as the mapped write will then trigger ext4_page_mkwrite() which will > wait for the end of running commit in jbd2_journal_get_write_access()). Or > am I missing something? But there must be still some race as you can still > see occasional checksum changes... So I must be missing something. > Actually you're right, I missed that -- either writeback will writeprotect the page. There's still something else going on, but it's me not you who missed something. :) Thanks for pointing that out. > > Since the switch to either leg is PageChecked(), I guess this might be > > due to clearing it right away in ext4_journalled_writepage(), before > > write-protection. > > The write-protection happens in clear_page_dirty_for_io() call so that's > before our ->writepage() callback is even called. > Right, I meant write-protection by the other/racing writeback thread. But please nevermind, as this doesn't seem to be the corner case anymore. Thanks! > Honza > -- > Jan Kara > SUSE Labs, CR -- Mauricio Faria de Oliveira