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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3E63DC25B4F for ; Wed, 16 Aug 2023 20:27:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B1C16280016; Wed, 16 Aug 2023 16:27:29 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id ACCCF280006; Wed, 16 Aug 2023 16:27:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 99424280016; Wed, 16 Aug 2023 16:27:29 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 86CDB280006 for ; Wed, 16 Aug 2023 16:27:29 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 52503A0FF0 for ; Wed, 16 Aug 2023 20:27:29 +0000 (UTC) X-FDA: 81131103018.03.F5FEF24 Received: from mail-yw1-f176.google.com (mail-yw1-f176.google.com [209.85.128.176]) by imf02.hostedemail.com (Postfix) with ESMTP id 9BF838002C for ; Wed, 16 Aug 2023 20:27:27 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=dveIXLQA; spf=pass (imf02.hostedemail.com: domain of hughd@google.com designates 209.85.128.176 as permitted sender) smtp.mailfrom=hughd@google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1692217647; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=o6nAd4B+hY09XKdSdHx5sCH4iOSgPQT2h6trGlM+vNA=; b=go4xhULG6BrVqDkt7HL5pm48tv5sJ1x42Pd0RQPXtvQdAeLLrpzD8N0YJpdD3om0VMO4UH /vMejO7zaWKqCPxbE0sw8yIUl7Uougz7WU264Jw52/JWBupEUGHm2KWQDtyoBi1gbxlQrE Ojdqvhr9MPkOp8G0lRfL/A/5fW3SvUQ= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1692217647; a=rsa-sha256; cv=none; b=kz2XN+Ipc40uinHAKgh1ph0/tkzb3tv4TLqUIKmZYjsn3agfiaxf98AayqVBNllkkQZMf8 yy1XgII058BSU9Lc4mthU+qk5cA2OPb8DnQzq3sWFVoRceuk9i0cfkCzkvGxJBEz0u1QiN fhl+53HLXDyuEJxpSxwAuTqEs5DwEi8= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=dveIXLQA; spf=pass (imf02.hostedemail.com: domain of hughd@google.com designates 209.85.128.176 as permitted sender) smtp.mailfrom=hughd@google.com; dmarc=pass (policy=reject) header.from=google.com Received: by mail-yw1-f176.google.com with SMTP id 00721157ae682-58dfe2d5b9aso682537b3.1 for ; Wed, 16 Aug 2023 13:27:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1692217646; x=1692822446; h=mime-version:references:message-id:in-reply-to:subject:cc:to:from :date:from:to:cc:subject:date:message-id:reply-to; bh=o6nAd4B+hY09XKdSdHx5sCH4iOSgPQT2h6trGlM+vNA=; b=dveIXLQA89ZUWYHabJVtI3oEEzpIr9fV/lirVBfekKiFOXn1lGgA2uPGEcOlkOZjBD a1aBpoGF8QaJMHqlLM0UKvL9kaKpzS6zyOvmB6Zbc1eS7EEJ6VlfQkXyzLpNQhfG3OEw eCGtvZNYLyrmkoj5+tJuw3HMFHCP3sqPuk8fbd3spP0mYw93n9H7+8N80JmbfIs4qiXv pYw7bvDGtSSGmN6GSey1TNwmTvBJC5JMT671NM0B4mgv/BXoWeH/4YzxKbh3yB570fS0 aJREuoDn9t0m4s+z3u9TOwbz2TQ5vLr7L5z9o4q0UsNVHdnnboFQwrHaMLNNgfIPCdb7 au3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692217646; x=1692822446; h=mime-version:references:message-id:in-reply-to:subject:cc:to:from :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=o6nAd4B+hY09XKdSdHx5sCH4iOSgPQT2h6trGlM+vNA=; b=JOiXlcmn6dcDOTboOfb2bzwDHrD61curQEEC6I2oTt5emuzX07zoNQjZDDPoglKTzM sYvXmSnXNjsq+ldNAvt/h1va1cvnqn4kEMdFXyO9tPZJb0I2fCllBNJCpM0ssAy0Ekvj /eAvaHuSOHlGxJFjSHoo9103egvbY2pGx+Bu7Zj/bIGFw6qAXlFk/2AOZeY+QnWvayrI LyU9N1z+QizADLqehGY+TJKckRXPbFc2fi5qr6DAOI+xOYaaFnd/u8dnSsPm+yDKewch GTYBxrw4n4chmm3iQN6lOOp5zIhSoCQ2efFv9+j0YuhL5Y6ZSTFbR5v7rRfI6qq0EPcy TGUQ== X-Gm-Message-State: AOJu0Yx20agykloarTSpq4Xo+Y4FvULteGCKJLlhnO2A+wsnqXuGN/Nq 9aajAdKm5xbBXJfZkipCFdcZmw== X-Google-Smtp-Source: AGHT+IEO5uc8CKDzvfrW8shdjb35Kp27HpuCfrFDLQV5dylLk8ofwbkbKcaFpgjeKtRhrvd/mx2svA== X-Received: by 2002:a0d:d641:0:b0:56c:e5a3:3e09 with SMTP id y62-20020a0dd641000000b0056ce5a33e09mr850661ywd.15.1692217646555; Wed, 16 Aug 2023 13:27:26 -0700 (PDT) Received: from ripple.attlocal.net (172-10-233-147.lightspeed.sntcca.sbcglobal.net. [172.10.233.147]) by smtp.gmail.com with ESMTPSA id z16-20020a81c210000000b005463e45458bsm4189762ywc.123.2023.08.16.13.27.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Aug 2023 13:27:25 -0700 (PDT) Date: Wed, 16 Aug 2023 13:27:17 -0700 (PDT) From: Hugh Dickins X-X-Sender: hugh@ripple.attlocal.net To: "Matthew Wilcox (Oracle)" cc: Jens Axboe , Andrew Morton , "Kirill A . Shutemov" , Hugh Dickins , Hannes Reineke , linux-mm@kvack.org, linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: Re: [PATCH] block: Remove special-casing of compound pages In-Reply-To: <20230814144100.596749-1-willy@infradead.org> Message-ID: <94635da5-ce28-a8fb-84e3-7a9f5240fe6a@google.com> References: <20230814144100.596749-1-willy@infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Stat-Signature: y3giqf7hattycfa855uxro3asqa54iic X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 9BF838002C X-Rspam-User: X-HE-Tag: 1692217647-790420 X-HE-Meta: U2FsdGVkX18MjKqnocrwhI6xCFAQHzDGM9PSl5wa3Ou33ONvYbkwm6RPMzYiGlWHiTl83PJiA7rXu19IJRVv87YpWaE8IGa4/EZ/17cfCrKXmxUZCjh7m6QnRxpD4RGRB7MYFW9UoXd+6vDf1ux5X5B5IslkjjTRmypXKp/5Ea6Y+YZRriCGrn0FotpF+hDqIkIVkwUVKxT2+mrGJ9iLLUBRvJA09a061X95OYDenXAdOfV4+bDHiv7jpzUB1mD5ruNF/RSaYLqAaqVFdMNahoFcHhX8IXnY7UOEM4a0oFydQRbLSDsVbnQB71CbTUn9CqATwY2UPw+ooy3uSlb3VKpm3jSN07fAgifA7J4tMZKTJSGf9w8xF7k9P7Kznsun9RLO5ns9nGnNDCPQd6LUAqkxJwTS8uzMQXCZfmr8b0+ig2RKbau9sBLXgwaeNEbSrMkK7sYmL75Rqgmy5mt07sP5yyA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=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: a.k.a "Fix rare user data corruption when using THP" :) On Mon, 14 Aug 2023, Matthew Wilcox (Oracle) wrote: > The special casing was originally added in pre-git history; reproducing > the commit log here: > > > commit a318a92567d77 > > Author: Andrew Morton > > Date: Sun Sep 21 01:42:22 2003 -0700 > > > > [PATCH] Speed up direct-io hugetlbpage handling > > > > This patch short-circuits all the direct-io page dirtying logic for > > higher-order pages. Without this, we pointlessly bounce BIOs up to > > keventd all the time. > > In the last twenty years, compound pages have become used for more than > just hugetlb. Rewrite these functions to operate on folios instead > of pages and remove the special case for hugetlbfs; I don't think > it's needed any more (and if it is, we can put it back in as a call > to folio_test_hugetlb()). > > This was found by inspection; as far as I can tell, this bug can lead > to pages used as the destination of a direct I/O read not being marked > as dirty. If those pages are then reclaimed by the MM without being > dirtied for some other reason, they won't be written out. Then when > they're faulted back in, they will not contain the data they should. > It'll take a pretty unusual setup to produce this problem with several > races all going the wrong way. > > This problem predates the folio work; it could for example have been > triggered by mmaping a THP in tmpfs and using that as the target of an > O_DIRECT read. > > Fixes: 800d8c63b2e98 ("shmem: add huge pages support") No. It's a good catch, but bug looks specific to the folio work to me. Almost all shmem pages are dirty from birth, even as soon as they are brought back from swap; so it is not necessary to re-mark them dirty. The exceptions are pages allocated to holes when faulted: so you did get me worried as to whether khugepaged could collapse a pmd-ful of those into a THP without marking the result as dirty. But no, in v6.5-rc6 the collapse_file() success path has if (is_shmem) folio_mark_dirty(folio); and in v5.10 the same appears as if (is_shmem) set_page_dirty(new_page); (IIRC, that or marking pmd dirty was missed from early shmem THP support, but fairly soon corrected, and backported to stable then. I have a faint memory of versions which assembled pmd_dirty from collected pte_dirtys.) And the !is_shmem case is for CONFIG_READ_ONLY_THP_FOR_FS: writing into those pages, by direct IO or whatever, is already prohibited. It's dem dirty (or not dirty) folios dat's the trouble! Hugh > Cc: stable@vger.kernel.org > Signed-off-by: Matthew Wilcox (Oracle) > --- > block/bio.c | 46 ++++++++++++++++++++++++---------------------- > 1 file changed, 24 insertions(+), 22 deletions(-)