From nobody Mon Sep 28 14:47:58 2026 Received: from mail-pj1-f51.google.com (mail-pj1-f51.google.com [209.85.216.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 136F245DF63 for ; Thu, 20 Aug 2026 14:30:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787236207; cv=none; b=bncvwie/oYQ2+HH3UUTlsv/+vkm8TmMhrKG75AM+usLbzTwN1GDtguyDh3t5F27wiG1AIqRr2qEpedksfMw/bCS+rZijNzg2QY8Oo2hfe9s/R2QvxHmdCzjEa326dOFCmysFfjRhIVnSBFMYpyhMy6hONIIOzHJmUHkRFThVQKE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787236207; c=relaxed/simple; bh=3Ycqs740UmpuwtFIi1z1jCcBP48DTkncFAGT3S8Vglo=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=om47TPZ/MQBCc/vep8ojW9eZhBwQOheQzXj3eJd2KbCxYGs7nJnam8bNbK2X+/LpcT0HYbYqUqhRm//71NVTKMP1if+KDrkGFAzMQLBujQ+lMw6lSBp+hozECVDpU6EQDD34i4Fs7Y6ICPHFqnpth5hU/IiRH4DIl5gTMI3ul/o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=pP1GQ6bl; arc=none smtp.client-ip=209.85.216.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="pP1GQ6bl" Received: by mail-pj1-f51.google.com with SMTP id 98e67ed59e1d1-38759bcd877so2818839a91.2 for ; Thu, 20 Aug 2026 07:30:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1787236205; x=1787841005; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=CwOwRzT4HLDPVaiVOwZWwo/iTTnMhyol3+iVtiyVzuY=; b=pP1GQ6bl+qD+9cn9z8I/W3YWIGkiewJlC59EbyEk0I7GCfgrBYr8GFRUlK9c2Kce3s B7o1FyqsO8csy1ocEk9r8nHJOBDxnZUzGEIb6GhBYGWhdHurX7MfMdrc/na2nKo/pLLQ TTOHhoDhfkH4TEnPAxoK5ckRVXLo1SGQSeSIm53vGsUF49h+aNbBtjPRkD6VtkdUMxC2 5DzYUu6RYDTKCppu2b1VXUCab5ZvCr4WqjCf+HbYu9Ofo5nXTvjYMgLaoMWUSHkSDSm4 zx0au0JkKSMGaXEmrxS3+ooJpwZyB5Q3FcABjrFxMnEOCeYeiUPxrRvdgBCi3maTXL28 bpYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787236205; x=1787841005; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=CwOwRzT4HLDPVaiVOwZWwo/iTTnMhyol3+iVtiyVzuY=; b=FfzdDNl9LAqnn7mpInEUtrrML3P0LpDxjcyRhmoo1V+DOkkmDydQCGn3C3QMXbWnFw /eD2/yHCrx3uU8GS8a/C3lT6vVbwAZm63Qe1prAHcYoTjONZwm7A0iiaSFWf7FasgsJ3 K8Gyz2jIuR0bKj7fe/5ooznfrM5rGBgo2FBUGFgbvozIluS/T+ryrk6h+Bf5NwyIj41m LzvLUj1RnUm+gdS236y2s1tC8qjG4G5LZXBN8tZaSDDbi0NipeUAKwi3B1NGfSEe4exY cvVh6V3XUhu+GxzbJws4vp9py0ESSg5AScL6EW7oO5waBvZYY/tcd5uVfQvRLaOFi1Jf Gfcg== X-Forwarded-Encrypted: i=1; AHgh+RqSsB+UkhFwjmWkfRuUJB5+lgKtoMeeT+DYlvymw/fs49Uh+dXRbeZtLk1wAB3ExhdhPkYEKaTTv7Dgat8=@vger.kernel.org X-Gm-Message-State: AFuF++nsfkdT+zgxw7ZqYGV/kB7PDiq5JLMDR5rRjkz+bX+Hlhr/hjo4 Z25hVOZm2unskLGIr1WajfhzIAWh9ixA8ZH/GYOotq4suZ9RV0O8W3g3 X-Gm-Gg: AR+sD10nc4y8wQ4e5p2JsDooTn8nLZisb17tJMMfugXouVcd5mfwapUkwpkoDUEhAgd AEvZO0/GgPr2dMMrsUxrSdYgNAGBwB2tETdEB8S49mkKZQbz2YyAqUsGFIFiI+u+dx/whYzOXDz i8aSjhXrLgMz7I46Fh2Nd04u2+73LChNwoya/+PohGcgjQ/dx6OmBnkOzoRNptQkJazvvpLXW95 PZjIBTH72mT/DveAdBVAJsEA0svqM/hBEyCdBGrVI8bvnkLLddC+cjK5WZpNjHMUFdphMIIfxSB Wf6Ww+fzU69QWLgIQX+nmFmC0y9s/4/IyYzaANlwM4UtiIpfEMLAi4t9gFT9/9wYg9A1rqMU7p+ aEzca/5/B5qqly0CpYN6FJAfzjdQq9pjOO7ZXBEsDETO4Lyk5JeIG3pNM5ApA/kfFaZpK0KiVPF 5allOjbEPDQ2Xe1FEyfrHqbgBuPANSWvZIEDHUZc0aab95GeJtRAxzxA/OwYXLn+nKr0/Cv9/NB Qou8OpkSarxrowaOl5ptNczMw== X-Received: by 2002:a17:90b:2b8e:b0:38e:75f3:ad4d with SMTP id 98e67ed59e1d1-39580f03c97mr25649224a91.7.1787236205247; Thu, 20 Aug 2026 07:30:05 -0700 (PDT) Received: from qiwenjie-ThinkCentre-M760t.mioffice.cn ([43.224.245.241]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-395a9bc47ffsm1036780a91.0.2026.08.20.07.30.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Aug 2026 07:30:04 -0700 (PDT) From: Wenjie Qi X-Google-Original-From: Wenjie Qi To: akpm@linux-foundation.org Cc: willy@infradead.org, jack@suse.cz, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, baohua@kernel.org, Wenjie Qi Subject: [PATCH] mm: filemap: tighten dropbehind completion context check Date: Thu, 20 Aug 2026 22:29:56 +0800 Message-ID: <20260820142956.1414337-1-qiwenjie@xiaomi.com> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" folio_end_dropbehind() uses in_task() to keep folio invalidation out of interrupt context. Task context alone is not sufficient: preemption can still be disabled, or the task can be in a preemptible RCU read-side critical section, while filemap_end_dropbehind() may reach folio_unmap_invalidate() and sleep. Use the established conservative three-part atomic-context test: reject preemptible RCU read-side sections, reject configurations without PREEMPT_COUNT, and otherwise require a preemptible context. Unsafe completions retain the existing best-effort behavior and skip invalidation. Signed-off-by: Wenjie Qi --- mm/filemap.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/mm/filemap.c b/mm/filemap.c index 6afec6368..0616057e6 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -45,6 +45,7 @@ #include #include #include +#include #include #include #include @@ -1620,6 +1621,15 @@ static void filemap_end_dropbehind(struct folio *fol= io) folio_unmap_invalidate(mapping, folio, 0); } =20 +static bool folio_dropbehind_in_atomic(void) +{ + if (IS_ENABLED(CONFIG_PREEMPTION) && rcu_preempt_depth()) + return true; + if (!IS_ENABLED(CONFIG_PREEMPT_COUNT)) + return true; + return !preemptible(); +} + /* * If folio was marked as dropbehind, then pages should be dropped when wr= iteback * completes. Do that now. If we fail, it's likely because of a big folio - @@ -1631,13 +1641,12 @@ void folio_end_dropbehind(struct folio *folio) return; =20 /* - * Hitting !in_task() should not happen off RWF_DONTCACHE writeback, - * but can happen if normal writeback just happens to find dirty folios - * that were created as part of uncached writeback, and that writeback - * would otherwise not need non-IRQ handling. Just skip the + * Hitting an atomic context should not happen from RWF_DONTCACHE + * writeback, but can happen if normal writeback just happens to find + * dirty folios created as part of uncached writeback. Just skip the * invalidation in that case. */ - if (in_task() && folio_trylock(folio)) { + if (!folio_dropbehind_in_atomic() && folio_trylock(folio)) { filemap_end_dropbehind(folio); folio_unlock(folio); } --=20 2.43.0