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 161E4C433EF for ; Sun, 9 Jan 2022 04:39:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9DAF76B0072; Sat, 8 Jan 2022 23:39:30 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 9632E6B0073; Sat, 8 Jan 2022 23:39:30 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 82B436B0074; Sat, 8 Jan 2022 23:39:30 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0019.hostedemail.com [216.40.44.19]) by kanga.kvack.org (Postfix) with ESMTP id 7343F6B0072 for ; Sat, 8 Jan 2022 23:39:30 -0500 (EST) Received: from smtpin23.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 1EF988102AEB for ; Sun, 9 Jan 2022 04:39:30 +0000 (UTC) X-FDA: 79009494900.23.F1DC2A1 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf05.hostedemail.com (Postfix) with ESMTP id 3D8FB100007 for ; Sun, 9 Jan 2022 04:39:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=lwoCikCgRo6xoxJeKz7PMb6pQN91U7lg3wemSqtopR0=; b=czl9ugGUBqLJB2cUmGdfZ2EXtn gahObYsIq7JWbTWB8mmzY12Ne1kDPscNDYqyjYJwreYhWescuGKUac5NLdwX1AZpH2MRwGVGpt23Y UdENtn7CiqGgH/7UlROl//ocDMcLJZoBsR+6J631v2qub8wzR7TSkkarRTj1tK23DhLkZ0SzUiMpJ cEef7iD0g5dGPK7bd+AsYNrZ/fYiYV3BtJUZoqhJG43pzIZwspwvUg5tcpf3p9tEVyg6IW8jWu7us /PQgs1gIaGorr9Matu+OcUrO/ERbAO+tNTEGxqjwRfnH3DxWZE4ksTIxHKXVJS3pJkD1ANVH+GDt4 zrhEzW+Q==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1n6PzI-0019BM-5Q; Sun, 09 Jan 2022 04:39:24 +0000 Date: Sun, 9 Jan 2022 04:39:24 +0000 From: Matthew Wilcox To: John Hubbard Cc: linux-mm@kvack.org, Andrew Morton Subject: Re: [PATCH 14/17] gup: Convert for_each_compound_head() to gup_for_each_folio() Message-ID: References: <20220102215729.2943705-1-willy@infradead.org> <20220102215729.2943705-15-willy@infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 3D8FB100007 X-Stat-Signature: zq1n9xfkih659fs5e44ixwb3rdxcfzpg Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=czl9ugGU; dmarc=none; spf=none (imf05.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org X-HE-Tag: 1641703169-389311 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Wed, Jan 05, 2022 at 12:17:46AM -0800, John Hubbard wrote: > > + if (!folio_test_dirty(folio)) { > > + folio_lock(folio); > > + folio_mark_dirty(folio); > > + folio_unlock(folio); > > At some point, maybe even here, I suspect that creating the folio > version of set_page_dirty_lock() would help. I'm sure you have > a better feel for whether it helps, after doing all of this conversion > work, but it just sort of jumped out at me as surprising to see it > in this form. I really hate set_page_dirty_lock(). It smacks of "there is a locking rule here which we're violating, so we'll just take the lock to fix it" without understanding why there's a locking problem here. As far as I can tell, originally, the intent was that you would lock the page before modifying any of the data in the page. ie you would do: gup() lock_page() addr = kmap_page() *addr = 1; kunmap_page() set_page_dirty() unlock_page() put_page() and that would prevent races between modifying the page and (starting) writeback, not to mention truncate() and various other operations. Clearly we can't do that for DMA-pinned pages. There's only one lock bit. But do we even need to take the lock if we have the page pinned? What are we protecting against? If it's truncate(), I think we must already have protection against that as we could easily have: pup() truncate() lock_page() set_page_dirty() unlock_page() unpin