From patchwork Mon Jul 4 07:40:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Muchun Song X-Patchwork-Id: 12904847 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 54E63C433EF for ; Mon, 4 Jul 2022 08:43:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4F1256B0072; Mon, 4 Jul 2022 04:43:07 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4A1366B0073; Mon, 4 Jul 2022 04:43:07 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 390006B0074; Mon, 4 Jul 2022 04:43:07 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 2AF7C6B0072 for ; Mon, 4 Jul 2022 04:43:07 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay13.hostedemail.com (Postfix) with ESMTP id 7957977705 for ; Mon, 4 Jul 2022 08:18:18 +0000 (UTC) X-FDA: 79648715118.18.44D2B57 Received: from mail-pg1-f173.google.com (mail-pg1-f173.google.com [209.85.215.173]) by imf30.hostedemail.com (Postfix) with ESMTP id 3968282239 for ; Mon, 4 Jul 2022 08:03:40 +0000 (UTC) Received: by mail-pg1-f173.google.com with SMTP id o18so7076256pgu.9 for ; Mon, 04 Jul 2022 01:03:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=f9ptmB3XGt31Pq8FBcI5MbA2yBypm+2JGBZYReeKeY8=; b=Q9uOsaM9gkzoT9XZMryjeJeF4CqBEe4f122QMdyvIZ9OW46Gs7GZNeNtv9XtFxnCJJ fJqRhw9DxUt5HANWF5eFN4LhPRwVHx/FispChp8KKIr9C6S/zq1dZ9KG9pK2KmbLIap8 uS3E0XSoWiw8KERhpzJsdlrcOYmCZE9mIS152hhNij8jcjSAnsvF0v726taSw+Dj8qt6 2pGaOxOcxT5Q98YX++uFB1kri4Vpa1ZLOLSXgZR6PtXp0jdOhRjRdMI8kPpt3zrDBKDe Vy3YfYkRNeVmXc3niV/aK3gvgb6va+fJXbTRWgmK+kKE3xJvF326absJFF6oeeKY+VSS cCvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=f9ptmB3XGt31Pq8FBcI5MbA2yBypm+2JGBZYReeKeY8=; b=qXB51gaBp8UIE/zTTkG3ZB9F/FjTJUFmRH37ba6p17vizgdNcTj+Pvz08oaC0V21ly RZr9Oo4lEahAN51sVN+u92kICloH+hAJgOgawwXLQyR4ZpDdk9rvFxkbSLGudeaB1CAB qBpYlYWY2uZQCt0TaL8BKlNpke4/T620n96zxiHeZZPg6gAPk1j8Q1mcs9Lon5yIwzow VP42vugFMr+RqALWfSaD5s7RshpcQmIqJJY7h/Ec/6m2DFgvCRt2oCWEtWn86NFw0YCJ Wtu5dfYtb/P38U2HUVWa0ZsfcTwIhgLFKdAEbPtRJGocPHZ0BHDKExOBLP/Urcojy60b QfXA== X-Gm-Message-State: AJIora8e1hhxo9GxK4qNvkIsgymmfLCPt2Wy+Eoma8xNEzDR6XWd8TNb PEICM60NLlKbC8sGHIHeqno+OQ== X-Google-Smtp-Source: AGRyM1svsqJoBsj5Q1XvMG+PjZFAD50xTrVz1dkapvyAi5JFA6rZcft884USVJUlz+5c+8OcIXlzng== X-Received: by 2002:a65:640e:0:b0:412:2906:bb25 with SMTP id a14-20020a65640e000000b004122906bb25mr6567449pgv.82.1656921818983; Mon, 04 Jul 2022 01:03:38 -0700 (PDT) Received: from FVFYT0MHHV2J.bytedance.net ([139.177.225.229]) by smtp.gmail.com with ESMTPSA id s8-20020aa78d48000000b0052089e1b88esm20352965pfe.192.2022.07.04.01.03.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Jul 2022 01:03:38 -0700 (PDT) From: Muchun Song To: akpm@linux-foundation.org, willy@infradead.org, jgg@ziepe.ca, jhubbard@nvidia.com, william.kucharski@oracle.com, dan.j.williams@intel.com, jack@suse.cz Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, nvdimm@lists.linux.dev, Muchun Song Subject: [PATCH] mm: fix missing wake-up event for FSDAX pages Date: Mon, 4 Jul 2022 15:40:54 +0800 Message-Id: <20220704074054.32310-1-songmuchun@bytedance.com> X-Mailer: git-send-email 2.32.1 (Apple Git-133) MIME-Version: 1.0 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1656921820; 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=f9ptmB3XGt31Pq8FBcI5MbA2yBypm+2JGBZYReeKeY8=; b=sR4fGJQ5XjZ9KZnGJeaX+8n1xW8DlSpI0sBbXj+K7BfuP900CZY95Eg1lM0x2DSdfFLbRp 4/XN6Xa9LHR8p+V0u3zeAEbxp4dzpcHRQ6r3SuEin6MusevNVixuY6YAlvitISNIRKKdXs 6FEsYvQ70dmSxfkR4w3lLME71L5wYAc= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=Q9uOsaM9; dmarc=pass (policy=none) header.from=bytedance.com; spf=pass (imf30.hostedemail.com: domain of songmuchun@bytedance.com designates 209.85.215.173 as permitted sender) smtp.mailfrom=songmuchun@bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1656921820; a=rsa-sha256; cv=none; b=UzNbloiXIC+jDSmVb/GOlcknGKSgkX2drwl7ETGx/XrLbDPoQmu4IaieVcMR8K/jKmLbCR MU9BPoM4bY3E9ZpEMEXc6BXvY3ImcUUFf8Mk8K079IRz8xbDJAMzXQzCxQwN4nxCBN+hpU VrLPnSyjG0AxPhQtoGOBU39LJjBGLC4= X-Rspam-User: X-Rspamd-Queue-Id: 3968282239 Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=Q9uOsaM9; dmarc=pass (policy=none) header.from=bytedance.com; spf=pass (imf30.hostedemail.com: domain of songmuchun@bytedance.com designates 209.85.215.173 as permitted sender) smtp.mailfrom=songmuchun@bytedance.com X-Stat-Signature: hkjfwymtbsmbojxs6k1jcg1hsirbgo1g X-Rspamd-Server: rspam08 X-HE-Tag: 1656921820-883510 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: FSDAX page refcounts are 1-based, rather than 0-based: if refcount is 1, then the page is freed. The FSDAX pages can be pinned through GUP, then they will be unpinned via unpin_user_page() using a folio variant to put the page, however, folio variants did not consider this special case, the result will be to miss a wakeup event (like the user of __fuse_dax_break_layouts()). Fixes: d8ddc099c6b3 ("mm/gup: Add gup_put_folio()") Signed-off-by: Muchun Song --- include/linux/mm.h | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index 517f9deba56f..32aaa7b06f5a 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -1223,6 +1223,9 @@ static inline __must_check bool try_get_page(struct page *page) */ static inline void folio_put(struct folio *folio) { + if (put_devmap_managed_page(&folio->page)) + return; + if (folio_put_testzero(folio)) __folio_put(folio); } @@ -1243,8 +1246,13 @@ static inline void folio_put(struct folio *folio) */ static inline void folio_put_refs(struct folio *folio, int refs) { - if (folio_ref_sub_and_test(folio, refs)) - __folio_put(folio); + /* + * For fsdax managed pages we need to catch refcount transition + * from 2 to 1: + */ + if (refs > 1) + folio_ref_sub(folio, refs - 1); + folio_put(folio); } void release_pages(struct page **pages, int nr); @@ -1268,15 +1276,7 @@ static inline void folios_put(struct folio **folios, unsigned int nr) static inline void put_page(struct page *page) { - struct folio *folio = page_folio(page); - - /* - * For some devmap managed pages we need to catch refcount transition - * from 2 to 1: - */ - if (put_devmap_managed_page(&folio->page)) - return; - folio_put(folio); + folio_put(page_folio(page)); } /*