From patchwork Thu Jun 6 18:48:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yosry Ahmed X-Patchwork-Id: 13688894 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 0BFFEC27C52 for ; Thu, 6 Jun 2024 18:48:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 72DAE6B0082; Thu, 6 Jun 2024 14:48:24 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6B7896B008A; Thu, 6 Jun 2024 14:48:24 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 52FFF6B0092; Thu, 6 Jun 2024 14:48:24 -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 326E86B0082 for ; Thu, 6 Jun 2024 14:48:24 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 9EB3D120E66 for ; Thu, 6 Jun 2024 18:48:23 +0000 (UTC) X-FDA: 82201349286.01.8EBA64A Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) by imf08.hostedemail.com (Postfix) with ESMTP id E870616000A for ; Thu, 6 Jun 2024 18:48:21 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b="0rAH4q/Q"; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf08.hostedemail.com: domain of 3dARiZgoKCD8zptszbinfehpphmf.dpnmjovy-nnlwbdl.psh@flex--yosryahmed.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=3dARiZgoKCD8zptszbinfehpphmf.dpnmjovy-nnlwbdl.psh@flex--yosryahmed.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1717699702; 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=33EVY1gasG0xwBVR+VPpHnVgd2Suv88JpbujEvfP7pE=; b=hVzYau7mWpzby2+Y12jmz8ZpMRyXXViz2J7GFLaNVcRFfmwzAqfYxe/Kq1HAHMkSJpcYth /IVg+g8ABiKRePYRco2BoQwuWqsXtTQgx7gxb+CoDf+Rw9/tw2+7UjQt+cqnB3Kqmpc0Q4 dBIwWK/UZU4EuQIf5eTvt5s4RisthrM= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b="0rAH4q/Q"; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf08.hostedemail.com: domain of 3dARiZgoKCD8zptszbinfehpphmf.dpnmjovy-nnlwbdl.psh@flex--yosryahmed.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=3dARiZgoKCD8zptszbinfehpphmf.dpnmjovy-nnlwbdl.psh@flex--yosryahmed.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1717699702; a=rsa-sha256; cv=none; b=hUqq5/o610Df9tvBPY0KC40+oJ3RUt0nQZ00RGKWc2gSR32L2E/eQiPQGAiOOgWFs15MXa L1bl5uir90gQZqtsD4HKLDP6eahxldABzhZkvsp9TKWtQlKIqb9VWzJny3IR+SpB/X/qdc NZHWbQ+s2V1TuC3nLxCmrWxqKt2eG04= Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-62a2aec8521so20277267b3.0 for ; Thu, 06 Jun 2024 11:48:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1717699701; x=1718304501; darn=kvack.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=33EVY1gasG0xwBVR+VPpHnVgd2Suv88JpbujEvfP7pE=; b=0rAH4q/QGPVDVwGowNMFP28+ZXAzYTNHn97RtLPBUHVgO06imHLDbwyP+33XnFRTze GlFP16+R7mQir+wpFE5m8aSKFA0armg5WSiDX2HNNR9Yw0qs7ufbh/xX3qv+LqJCAxhy RnlxWFLz9YXMpkvVH0cYKIdvlY18HdGRgQUjoY1KZzvicFeRfhIzVFF8cwkKLCvm1hun Z7pmuG3Q/qo7QC3pvMqxzX3oGkyjqNpPscbCrjEjRJHJRjaIjFcRy8W8tqRLebMPvqf0 19+sQIhclD8KW68GESkT15034cd8Bls+CSkDnS71TW6a1fLAcDe3Z3edYQGIdfWqLCm/ 2vIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717699701; x=1718304501; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=33EVY1gasG0xwBVR+VPpHnVgd2Suv88JpbujEvfP7pE=; b=aLUcDe0YYiCW+eN7WiIkMnuqY5rNQmCUuFnsMd6fxRenArQLg5H1WJ2hjOd+R+nNKe YzYWZRRmW8U+GwCN4DuUyHRiIg3RS8+IZlo6trxWDdnEh074TN2mBDln4IIOpb1y6xHl l+R4QpAQfkQy90OX+uz6IdH/gBEBrmTovOMucGnxWBph1IPAJesN6LwdcdP92PazP5f5 MThwoex2cdQJ6bJE9iCeUYuNl3rf+QJiKr8Az9u44yoWKOI73nrNIkEXZbJ6nQpOyy/j 9x9I7P98i9J7D34k55Gd3ropd3WPhhdkMU2ISP5hZwPwt7Lmvi0Ql+Wb5cmIiTnb6Pkr WdNg== X-Forwarded-Encrypted: i=1; AJvYcCUZeFSW8lBT2oXeMyAZpyyJ2Ax74Tj/kwcL9+sP4QBAAFjJkGbh6KOetloI9ZGa3Glviep/dU6YQKx0DPmyeqp53YM= X-Gm-Message-State: AOJu0YwuYIstZI5m67tvfYLT2qoFYDkzLwRq1isKw+zEBMCrzv0Y4aSJ zC0v2beB8+Vb7bwst+2LoaWUjiIgkYB5RIei/lNhFXLyDMUhYT/kk90Or+Iv/sptapTrm5hrm8P RoAi/LtNaZ5NEwIa9Rg== X-Google-Smtp-Source: AGHT+IHzjxbN4O+eAC75lGOtNEstlxb/v3Bkbe/QNm3rRRhuZDaL36ej/IJ0lS6+ElHmlyMkLkNFtiANK5EcF5Y3 X-Received: from yosry.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:29b4]) (user=yosryahmed job=sendgmr) by 2002:a05:690c:6612:b0:627:96bd:b2b with SMTP id 00721157ae682-62cd5660eccmr571787b3.6.1717699700884; Thu, 06 Jun 2024 11:48:20 -0700 (PDT) Date: Thu, 6 Jun 2024 18:48:18 +0000 Mime-Version: 1.0 X-Mailer: git-send-email 2.45.2.505.gda0bf45e8d-goog Message-ID: <20240606184818.1566920-1-yosryahmed@google.com> Subject: [PATCH] mm: zswap: add VM_BUG_ON() if large folio swapin is attempted From: Yosry Ahmed To: Andrew Morton Cc: Johannes Weiner , Nhat Pham , Chengming Zhou , Baolin Wang , Barry Song <21cnbao@gmail.com>, Chris Li , Ryan Roberts , David Hildenbrand , Matthew Wilcox , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Yosry Ahmed X-Rspamd-Queue-Id: E870616000A X-Stat-Signature: pphfkfeqpwdqgthes5ecz4a1du3itg4h X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1717699701-272445 X-HE-Meta: U2FsdGVkX1+yqZlKGM3UNQ3PLZS4efgj2Z6OIAMei5GXcuZQHEU85OyznpQgxLoJC3NyNLHhKlV7dT2q9XHioplrs+1HaOpN33SxMbzRU3F85QISbXoxklSjAouDd7Y8Th3AaO6gQ++uEjNV0knzJxw3PIc2LEDCB2PP6bumLVgtsnO4XQ7mDTCRHw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ZGIvGOCcffLJk6FtqR/NvUpRV7Iw38RMYydDYGZz/5O+DL/BNr+cLtZyKTcEZEY6sjlmy2P4VCge1sqQFaU4wrJeLDNz0ern6OkMYYIrUMeEivFSH20U+6u8SUCZCzIdHgobObkNjRtd6L1Js1YPBElek9R/3sXEU+JuwwgFder2cLMUXUU/hP3S/fF0O+eEpgfoahCkFioQz8M9GdHVIv3Ofthj0DN7+xYThQbwxUE2rca6iRFih0p16JxEyOzyC3U4bb4ePO5r/OYF0rUJw8RJdpNk70CeBvOhPju3AHPsnP+GuszX1+UqsmUoenhdZWvSCCWfofuT1C8mIkav6k9FePxLWjS0CZcuuBGBUytjbgt/e4Cd8aWe0Oooif30tn/0mGlhIBA54Cf8DBzBCE8K6QAso4PLdLNGtN9YWl5TrRxXWZVY5yfDg== 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: With ongoing work to support large folio swapin, it is important to make sure we do not pass large folios to zswap_load() without implementing proper support. For example, if a swapin fault observes that contiguous PTEs are pointing to contiguous swap entries and tries to swap them in as a large folio, swap_read_folio() will pass in a large folio to zswap_load(), but zswap_load() will only effectively load the first page in the folio. If the first page is not in zswap, the folio will be read from disk, even though other pages may be in zswap. In both cases, this will lead to silent data corruption. Proper large folio swapin support needs to go into zswap before zswap can be enabled in a system that supports large folio swapin. Looking at callers of swap_read_folio(), it seems like they are either allocated from __read_swap_cache_async() or do_swap_page() in the SWP_SYNCHRONOUS_IO path. Both of which allocate order-0 folios, so we are fine for now. Add a VM_BUG_ON() in zswap_load() to make sure that we detect changes in the order of those allocations without proper handling of zswap. Alternatively, swap_read_folio() (or its callers) can be updated to have a fallback mechanism that splits large folios or reads subpages separately. Similar logic may be needed anyway in case part of a large folio is already in the swapcache and the rest of it is swapped out. Signed-off-by: Yosry Ahmed Acked-by: Barry Song --- Sorry for the long CC list, I just found myself repeatedly looking at new series that add swap support for mTHPs / large folios, making sure they do not break with zswap or make incorrect assumptions. This debug check should give us some peace of mind. Hopefully this patch will also raise awareness among people who are working on this. --- mm/zswap.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mm/zswap.c b/mm/zswap.c index b9b35ef86d9be..6007252429bb2 100644 --- a/mm/zswap.c +++ b/mm/zswap.c @@ -1577,6 +1577,9 @@ bool zswap_load(struct folio *folio) if (!entry) return false; + /* Zswap loads do not handle large folio swapins correctly yet */ + VM_BUG_ON(folio_test_large(folio)); + if (entry->length) zswap_decompress(entry, folio); else