From patchwork Mon Jan 22 17:17:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13525841 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 068B8C47DD9 for ; Mon, 22 Jan 2024 17:18:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 88BEA6B0087; Mon, 22 Jan 2024 12:17:59 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 83B786B0089; Mon, 22 Jan 2024 12:17:59 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6DBAF6B008A; Mon, 22 Jan 2024 12:17:59 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 572806B0087 for ; Mon, 22 Jan 2024 12:17:59 -0500 (EST) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id F0AB8A0913 for ; Mon, 22 Jan 2024 17:17:58 +0000 (UTC) X-FDA: 81707604636.23.36CB6E6 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf27.hostedemail.com (Postfix) with ESMTP id 43C3340006 for ; Mon, 22 Jan 2024 17:17:57 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="A/KGN+Fk"; spf=pass (imf27.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1705943877; 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-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=XhLeC5Lfj4S0c9LG1F/fnKLVs62IL7U4zQ+n1ywYzhU=; b=upWomyG/DVeeo4jGiovIPTiHNEbw10YMrykSgxlvgrriRm8wMrNEXcfvgZvTa6eiOHx0CS A80DjIpECvcNWohCMSp24IhJCs1XzyQ4P+ozcptc4x65PgoFgESry5yM5ohUCmnVtiXNnF krpO0YaorSidPrKQGp/ZiHoZpk4X/MQ= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1705943877; a=rsa-sha256; cv=none; b=X4Q9CvF5OZCu2vUDrK54PdCNiAQ2s6VGRMcoWQdR0HMQR5lo3O3ziL7hOabFp2ABpXPty8 sGo/koNhgFO7n6D266BbSwkunkiHFe9O61/SUvMic+ON0X3+ExCw6Dcbz5+wCCvvbBze0R fOw0m92+zMMkEMon7flIzJQNcp3mmaY= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="A/KGN+Fk"; spf=pass (imf27.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1705943876; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=XhLeC5Lfj4S0c9LG1F/fnKLVs62IL7U4zQ+n1ywYzhU=; b=A/KGN+FkB7Bt/ua3ADs48foFUPXnPYZnCCz6IecUiLCzCoP1khNu9l/vrogcQMBatp4YP9 O/DK6AdwVDn4NvgQOrSeeBeTd9Dy+lrNzIBHsGYoWagJ3eBMIawTgWz7k1xZnHFP60uxiK 2v9eyRmGO5G8tW28a6Ns6n6RBScWRzE= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-350-9e0_w3lbNNu16t2quNW2Tw-1; Mon, 22 Jan 2024 12:17:54 -0500 X-MC-Unique: 9e0_w3lbNNu16t2quNW2Tw-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 48ED1185A785; Mon, 22 Jan 2024 17:17:54 +0000 (UTC) Received: from t14s.redhat.com (unknown [10.39.195.114]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9B323C0FDCA; Mon, 22 Jan 2024 17:17:52 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, David Hildenbrand , Ryan Roberts , Matthew Wilcox , Andrew Morton Subject: [PATCH v1] mm/memory: fix folio_set_dirty() vs. folio_mark_dirty() in zap_pte_range() Date: Mon, 22 Jan 2024 18:17:51 +0100 Message-ID: <20240122171751.272074-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.8 X-Rspamd-Queue-Id: 43C3340006 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: zewhug5ys61en83sogzis6mo9587ieyn X-HE-Tag: 1705943877-831876 X-HE-Meta: U2FsdGVkX18CsXZl0PuQUsnhWKOf7XH1awqQ6HyoI8T8Ak/aydfQTsBZbnA8HkUiu3LI3EH76nRDWEomSoyT8ZvEggOY3QAuehZHxq5TBr/VUc/PZURywOth9IPYHxQStheajV2IKDOHfNuu4jcIO0Nh7fTBuXIAQSa/jdv5eF4BD+7KC5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YiIi5Vl5aqRfjkanLayCgOwpjJFVjE+4woSPlAjYfXPmKQxLtscz8miPd/kaqpUM3+qteohP4zACUVoL/9UD5MDweP63hGtMhP2/rufOH1cje/60onBfiuXgrgIe6NAZwrxD03wqqoyPrDemOziDV3v+bgdOdw92VYVy54gEObTkeHuIpwUAx1ZYa8BxYwQCYySNHbY= 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: The correct folio replacement for "set_page_dirty()" is "folio_mark_dirty()", not "folio_set_dirty()". Using the latter won't properly inform the FS using the dirty_folio() callback. This has been found by code inspection, but likely this can result in some real trouble when zapping dirty PTEs that point at clean pagecache folios. Reported-by: Ryan Roberts Closes: https://lkml.kernel.org/r/2445cedb-61fb-422c-8bfb-caf0a2beed62@arm.com Fixes: c46265030b0f ("mm/memory: page_remove_rmap() -> folio_remove_rmap_pte()") Cc: Matthew Wilcox (Oracle) Cc: Andrew Morton Signed-off-by: David Hildenbrand Reviewed-by: Ryan Roberts Reviewed-by: Yuezhang Mo --- mm/memory.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/memory.c b/mm/memory.c index 7e1f4849463aa..89bcae0b224d6 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -1464,7 +1464,7 @@ static unsigned long zap_pte_range(struct mmu_gather *tlb, delay_rmap = 0; if (!folio_test_anon(folio)) { if (pte_dirty(ptent)) { - folio_set_dirty(folio); + folio_mark_dirty(folio); if (tlb_delay_rmap(tlb)) { delay_rmap = 1; force_flush = 1;