From patchwork Sun Oct 20 04:22:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yu Zhao X-Patchwork-Id: 13842971 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 5E6CAD3C927 for ; Sun, 20 Oct 2024 04:22:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4CDBF6B007B; Sun, 20 Oct 2024 00:22:21 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 47E526B0082; Sun, 20 Oct 2024 00:22:21 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3455D6B0083; Sun, 20 Oct 2024 00:22:21 -0400 (EDT) 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 10BBB6B007B for ; Sun, 20 Oct 2024 00:22:21 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 7FAC980FAE for ; Sun, 20 Oct 2024 04:22:08 +0000 (UTC) X-FDA: 82692683388.11.F85863B Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) by imf16.hostedemail.com (Postfix) with ESMTP id C39B718000A for ; Sun, 20 Oct 2024 04:22:05 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=BrBX4dLQ; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf16.hostedemail.com: domain of 3eYUUZwYKCBYKGL3wA2AA270.yA8749GJ-886Hwy6.AD2@flex--yuzhao.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3eYUUZwYKCBYKGL3wA2AA270.yA8749GJ-886Hwy6.AD2@flex--yuzhao.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1729398089; a=rsa-sha256; cv=none; b=TzitWJ0RlUOjhRfPplOUOOxFTtV9LnlQiGCYH7patJaV+VZdgZXwBPPrNAZNzquISws9kA 670H6rIbDdIGM6S1BuzgnH4TOPa5a1V6LgZ6y34C8JSmc6RV0EWe5t3MptyXjz70qoVoZS ai10BmxMomvsy8QMDEDwTizq/P99gvc= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=BrBX4dLQ; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf16.hostedemail.com: domain of 3eYUUZwYKCBYKGL3wA2AA270.yA8749GJ-886Hwy6.AD2@flex--yuzhao.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3eYUUZwYKCBYKGL3wA2AA270.yA8749GJ-886Hwy6.AD2@flex--yuzhao.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1729398089; 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: references:dkim-signature; bh=hunIrxaAZBKXG3dXiSGVda8Y0C34IOSFspIj4rrZhK0=; b=uaP4gpQ6pxqt+DP8gXdaztLG8ULOF0ay8tUSMZ2xWAC0mE5naO/9QYvEZS6dq3I78yUW0o oLTdcB65JGUpIhYr0gjGqtcSDOXW6ZuNhelpqj8VCiN8tfHTJufC6RPmuU5DjWg5XMfxNk MyqJqPL1by5aMHtarbokqUkGbK+3/gc= Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6e383ba6763so59409327b3.3 for ; Sat, 19 Oct 2024 21:22:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1729398138; x=1730002938; darn=kvack.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=hunIrxaAZBKXG3dXiSGVda8Y0C34IOSFspIj4rrZhK0=; b=BrBX4dLQsngN5pTL+U4pjfPmcHT2cYR3YvSVcWY/tDR9dtKj7x3Gz7+oZ4xEJnMXi2 tZJ52ruCR32dIKDjhKtHC4FNDIVLMmiN+GQSnYSH0YwB87r/fS6JOLVWoFwxJ9Cikvf5 lcS0xLv941NeCfKZmF9UgchACM7TeQ6ufik8C0CaRwQ6cR9OCampxEqbuVjOxjxLcfxc QBH4MqxcVr8cE1943j4Gxz0odvnXLu0NRohIafcWpxaFhniQiuSt9Q8R0+FQXUGMqZpD bWrxFa1iHgeJkTaiy5dLPqB5uCTbYpEATj7LOKsOd3ZBz6FZKfD/nOlZiU6ddwbS66r0 Qwkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729398138; x=1730002938; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=hunIrxaAZBKXG3dXiSGVda8Y0C34IOSFspIj4rrZhK0=; b=ctQ1+u63itaTOwi+L+l+XdlIN8MZ35QJD62xfl9D6/JrTCvYvhwrH8Q08yWLLiu/Yq dN/qUnji8kQM9bq/xQldX6vkHeqzUAtBhcvKCWzJDFXTzf1E5jOuwjbWGdOIuRp9DXtb lTRdxx0/XVX21qb8skmOQw17vNJuwn3pxMiGAAGrlwXG9O5rvswv0dqXj4jhTKDVIZXO a14ZxxLxo+wJAuSwOGnaetaPxCdG6UOwzKxG1QhX10i112q9e9GTlnclLMmpCaFOyide cefgPgintTcVcyGcw9qc32VHaEJHBBq+j9TlrfXs7YGsPeeWc72FGsETpLg0D34+mdrW vN9w== X-Forwarded-Encrypted: i=1; AJvYcCWC8IQpEA4KmHaLFsrt2w4eUCN833aUUy96ibVU1OS4O0G6n7FLfPNyuHlmJESwvS1EnXAGzTAczg==@kvack.org X-Gm-Message-State: AOJu0YwEaZNn+KHtVqBwWNlvEHhmIC3HaRHRcNduDviY6IBNu10JPtv7 x7atmJQ49ZwToByRN6et1yNuCBWznnSgAExhYdFcftfVlmHTqlgA8+lolJpZ17VPtgLBBdpSNpr kxQ== X-Google-Smtp-Source: AGHT+IFifeZ9dPCzrp2wsmyKhCEmFpT64OFwbRHZPKpAAxcfKYugj5DI1/4Uq3aosY7cj+7jHzLwU352+Fw= X-Received: from yuzhao2.bld.corp.google.com ([2a00:79e0:2e28:6:882f:cbc3:2127:9e93]) (user=yuzhao job=sendgmr) by 2002:a05:690c:7010:b0:6e3:1023:3645 with SMTP id 00721157ae682-6e5bfc56d11mr1792447b3.8.1729398137687; Sat, 19 Oct 2024 21:22:17 -0700 (PDT) Date: Sat, 19 Oct 2024 22:22:12 -0600 Mime-Version: 1.0 X-Mailer: git-send-email 2.47.0.rc1.288.g06298d1525-goog Message-ID: <20241020042212.296781-1-yuzhao@google.com> Subject: [PATCH mm-unstable v1] mm: allow set/clear page_type again From: Yu Zhao To: Andrew Morton , "Matthew Wilcox (Oracle)" Cc: Muchun Song , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Yu Zhao , stable@vger.kernel.org X-Rspam-User: X-Rspamd-Queue-Id: C39B718000A X-Rspamd-Server: rspam01 X-Stat-Signature: ajr4wkd5h5u7puyp4odmpg3rbyr1pqtx X-HE-Tag: 1729398125-818329 X-HE-Meta: U2FsdGVkX19WtCrwNBJJa/gRnlCwSMntQW15hG2ktL5Op/5EyrwHQAsbFLVbYQXSkr1Uac/Zy0U3G6ukmZxIh+107yiBKj40OzxrhI2zHVkMys6vDo4ETQ2R1PHUxarxhgy9N800chHpBKEAs9GN5vmlcxn8cpmv7xALe2gcc+JFSys6ky7h5pFFhGeDB9SgcKe/7RoWrCA8YK35RjFiZeTALAMIyYF1eKddW801pcMVE7qfTu6h9EDerATr37w0YNIsCES4OZ4AHFjqruS1KhoKDN+nz+VQTrqU9fNTVw/0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ra624NpXnFKtj+xu2NeeSQFXjRSNL3a01HhAlbnG96KpcOuVgcT6C4fEn1VbK0EHZJZi6zAYlirP1fWlG37zLRc+JZwmIIy79uMgAqs7s55Nl0P+LtgMijVrSbqex5MjbcEhOFY89p8B9nmkCeNpa4+VXEVkgyfeDGaiJ/HXaaHl1KhzZGKtQUKDA7Kx/T1W6WRj1JQn7ng13mwN0jqYozj1Jm47Z6LgudyzjKZyyh9KkM= 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: Some page flags (page->flags) were converted to page types (page->page_types). A recent example is PG_hugetlb. From the exclusive writer's perspective, e.g., a thread doing __folio_set_hugetlb(), there is a difference between the page flag and type APIs: the former allows the same non-atomic operation to be repeated whereas the latter does not. For example, calling __folio_set_hugetlb() twice triggers VM_BUG_ON_FOLIO(), since the second call expects the type (PG_hugetlb) not to be set previously. Using add_hugetlb_folio() as an example, it calls __folio_set_hugetlb() in the following error-handling path. And when that happens, it triggers the aforementioned VM_BUG_ON_FOLIO(). if (folio_test_hugetlb(folio)) { rc = hugetlb_vmemmap_restore_folio(h, folio); if (rc) { spin_lock_irq(&hugetlb_lock); add_hugetlb_folio(h, folio, false); ... It is possible to make hugeTLB comply with the new requirements from the page type API. However, a straightforward fix would be to just allow the same page type to be set or cleared again inside the API, to avoid any changes to its callers. Fixes: d99e3140a4d3 ("mm: turn folio_test_hugetlb into a PageType") Signed-off-by: Yu Zhao Cc: --- include/linux/page-flags.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/include/linux/page-flags.h b/include/linux/page-flags.h index ccf3c78faefc..e80665bc51fa 100644 --- a/include/linux/page-flags.h +++ b/include/linux/page-flags.h @@ -977,12 +977,16 @@ static __always_inline bool folio_test_##fname(const struct folio *folio) \ } \ static __always_inline void __folio_set_##fname(struct folio *folio) \ { \ + if (folio_test_##fname(folio)) \ + return; \ VM_BUG_ON_FOLIO(data_race(folio->page.page_type) != UINT_MAX, \ folio); \ folio->page.page_type = (unsigned int)PGTY_##lname << 24; \ } \ static __always_inline void __folio_clear_##fname(struct folio *folio) \ { \ + if (folio->page.page_type == UINT_MAX) \ + return; \ VM_BUG_ON_FOLIO(!folio_test_##fname(folio), folio); \ folio->page.page_type = UINT_MAX; \ } @@ -995,11 +999,15 @@ static __always_inline int Page##uname(const struct page *page) \ } \ static __always_inline void __SetPage##uname(struct page *page) \ { \ + if (Page##uname(page)) \ + return; \ VM_BUG_ON_PAGE(data_race(page->page_type) != UINT_MAX, page); \ page->page_type = (unsigned int)PGTY_##lname << 24; \ } \ static __always_inline void __ClearPage##uname(struct page *page) \ { \ + if (page->page_type == UINT_MAX) \ + return; \ VM_BUG_ON_PAGE(!Page##uname(page), page); \ page->page_type = UINT_MAX; \ }