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 E59BCC71155 for ; Mon, 16 Jun 2025 14:10:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 54AFE6B00B6; Mon, 16 Jun 2025 10:10:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4FB986B00B7; Mon, 16 Jun 2025 10:10:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3C4196B00B8; Mon, 16 Jun 2025 10:10:17 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 29E346B00B6 for ; Mon, 16 Jun 2025 10:10:17 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id CAEFA1CC6C6 for ; Mon, 16 Jun 2025 14:10:16 +0000 (UTC) X-FDA: 83561448432.10.B042556 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by imf25.hostedemail.com (Postfix) with ESMTP id 8AB37A000F for ; Mon, 16 Jun 2025 14:10:14 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=FfE3qqOd; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=GaimmJA3; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=FfE3qqOd; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=GaimmJA3; spf=pass (imf25.hostedemail.com: domain of osalvador@suse.de designates 195.135.223.131 as permitted sender) smtp.mailfrom=osalvador@suse.de; dmarc=pass (policy=none) header.from=suse.de ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1750083014; 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=pjbZJaffVvP6vuBZvxM6g9mqSeMEhj0RjSxyuqax+yM=; b=CFjEAYpSVYZ/DzPnIAzADfBXQR1gyDy6R36S31m22tdnocE8Tz+dxoR2q2wZsK49r9FpAE 2rMASQDpL9EIq34wYUbg6/ygHxeI8YJ23EjX6nZQ8zfw3igHXkARmbkZpNtI4kGODscHNz iaC9xRXfmmN/ztlFFXBbpVvhjZhlemA= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=FfE3qqOd; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=GaimmJA3; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=FfE3qqOd; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=GaimmJA3; spf=pass (imf25.hostedemail.com: domain of osalvador@suse.de designates 195.135.223.131 as permitted sender) smtp.mailfrom=osalvador@suse.de; dmarc=pass (policy=none) header.from=suse.de ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1750083014; a=rsa-sha256; cv=none; b=hQRsOrQf1By/U5DH07x0cGpbr5xCMDSF8pKBYlyedYrJsGZz88FarurJVdz0J/UJyrMui4 tj1OMZp01ZHlT1KdF/xuzACx+Zz6zs7huzvg7pTjO1zyk6+yiGYA+R8ZBWz0NWoG7VcYf6 rK3/5Oh4U8y0UN7hfpvKMuZfFYqTMEk= Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id E1D641F74A; Mon, 16 Jun 2025 14:10:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1750083012; h=from:from:reply-to: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=pjbZJaffVvP6vuBZvxM6g9mqSeMEhj0RjSxyuqax+yM=; b=FfE3qqOdPMtM0nEACqjOdSJ/1V4ckmGIOhu1d5aYdsNFn6fKKVdl+ETe/QJYsWZvy+yecS 1oQ81cb/l4FZLTktYRnKbbNc45L6Q13UAhp6i/pHdxZuEOsGEUnfFSJGfmJy8lj7rXyk/W 8TH9YE1y2rhdI6eEqvPaLgVylJV5YLA= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1750083012; h=from:from:reply-to: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=pjbZJaffVvP6vuBZvxM6g9mqSeMEhj0RjSxyuqax+yM=; b=GaimmJA3hGx3BbuHMjADldom51FNmjZZ7B48/hqQNjxvz3DaCiejmLIujrOxQO9RxiqY0q rchSEgGVgze38lDQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1750083012; h=from:from:reply-to: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=pjbZJaffVvP6vuBZvxM6g9mqSeMEhj0RjSxyuqax+yM=; b=FfE3qqOdPMtM0nEACqjOdSJ/1V4ckmGIOhu1d5aYdsNFn6fKKVdl+ETe/QJYsWZvy+yecS 1oQ81cb/l4FZLTktYRnKbbNc45L6Q13UAhp6i/pHdxZuEOsGEUnfFSJGfmJy8lj7rXyk/W 8TH9YE1y2rhdI6eEqvPaLgVylJV5YLA= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1750083012; h=from:from:reply-to: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=pjbZJaffVvP6vuBZvxM6g9mqSeMEhj0RjSxyuqax+yM=; b=GaimmJA3hGx3BbuHMjADldom51FNmjZZ7B48/hqQNjxvz3DaCiejmLIujrOxQO9RxiqY0q rchSEgGVgze38lDQ== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 6FFE013A6D; Mon, 16 Jun 2025 14:10:12 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id J++TF8QlUGi9TAAAD6G6ig (envelope-from ); Mon, 16 Jun 2025 14:10:12 +0000 Date: Mon, 16 Jun 2025 16:10:02 +0200 From: Oscar Salvador To: David Hildenbrand Cc: Andrew Morton , Muchun Song , James Houghton , Peter Xu , Gavin Guo , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 2/5] mm,hugetlb: Document the reason to lock the folio in the faulting path Message-ID: References: <20250612134701.377855-1-osalvador@suse.de> <20250612134701.377855-3-osalvador@suse.de> <44f0f1cc-307a-46e3-9e73-8b2061e4e938@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Stat-Signature: m7kyup7szpaey4qcpb9xhefujra3sfop X-Rspamd-Queue-Id: 8AB37A000F X-Rspam-User: X-Rspamd-Server: rspam09 X-HE-Tag: 1750083014-932565 X-HE-Meta: U2FsdGVkX18IboKv75GfKZtlAUQ6kEaVRtL0WTW8Qii4Xl1/f1MVCb7+6VpZI5+UWZNP8lPTNJ3FWzRwhHkM8vvH30FcJqj1a9QgzUvvYWKemFdm5MB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jOIIKjC01Ao2w8CLLRbwjEhvFw3gCQiKZbUbCW6jhr8yVNu0aFV9aqIcQB3JSn4m9AKFbzyxNauFyg9T/Ac+xXfETs+7 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: List-Subscribe: List-Unsubscribe: On Mon, Jun 16, 2025 at 11:22:43AM +0200, David Hildenbrand wrote: > hugetlb_fault->hugetlb_no_page->hugetlb_wp > > already *mapped* the pagecache page into the page table. > > See > if (anon_rmap) > hugetlb_add_new_anon_rmap(folio, vma, vmf->address); > else > hugetlb_add_file_rmap(folio); > > So at that point it would be "stable" unless I am missing something? > > So once we are in hugetlb_wp(), that path much rather corresponds to > do_wp_page()->wp_page_copy. Yes, that's right. That's something I've been thinking over the weekend. E.g: do_cow_fault, first copies the page from the pagecache to a new one and __then__ maps the that page into the page tables. While in hugetlb_no_page->hugetlb_wp, the workflow is a bit different. We first map it and then we copy it if we need to. What do you mean by stable? In the generic faulting path, we're not worried about the page going away because we hold a reference, so I guess the lock must be to keep content stable? I mean, yes, after we have mapped the page privately into the pagetables, we don't have business about content-integrity anymore, so given this rule, yes, I guess hugetlb_wp() wouldn't need the lock (for !anonymous) because we already have mapped it privately at that point. But there's something I don't fully understand and makes me feel uneasy. If the lock in the generic faultin path is to keep content stable till we have mapped it privately, wouldn't be more correct to also hold it during the copy in hugetlb_wp, to kinda emulate that? -- Oscar Salvador SUSE Labs