Received: by 2002:ab2:6309:0:b0:1fb:d597:ff75 with SMTP id s9csp584532lqt; Thu, 6 Jun 2024 11:56:22 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWde0IyJZDeunQi3Kt0O21TboDr6eE1qtpuMx79YKinVh5vnYFPJalhMsAuL+80tZvqW48b2hC7J7klLiThRU0s6cAeazXrqs816beRrg== X-Google-Smtp-Source: AGHT+IH9ZzYi2a8wmnVjAM4jxkmPUZYf9nZW/l2S7cUmErDfpV6KgPXwz71sQ41hg4bJxBjpIk4r X-Received: by 2002:a17:903:2283:b0:1f4:9474:e44d with SMTP id d9443c01a7336-1f6d02dd14cmr6196645ad.21.1717700181762; Thu, 06 Jun 2024 11:56:21 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717700181; cv=pass; d=google.com; s=arc-20160816; b=HAgUS2aBXKI8fmd6uain4yJOLc8CEmZho0Q1dKrxXC/AKNKfloLEP+X9JXnq29SWpm leR8J2h9xhQsnhBQjusG9rOefuid1d+9npvh0JwxVGR1ayxIXC9dc+KVSkZFOFYy8ItQ 9K6MiWN9ZUG33ZcIOQx0gRNYvfoNLHnUzgTo59w7uBGpQl2mHvvqwA9gVSpQZIATj+Zb J4bKhs7RJ3g57/Yn3YHpgwKVzjs5Mu7uXfYl1KkfDRqKW4fVEYFd4VDGYr/q2o1+D4Ry KU/j/MJmEXwm0phdJyPqH3j+SHE6KrQfl5kjglNl/DnglSjIY8uhwEXIYQfVc7C5ndaY SvrA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:dkim-signature; bh=33EVY1gasG0xwBVR+VPpHnVgd2Suv88JpbujEvfP7pE=; fh=59JSO7rXpCTu1C/ZZDYgU5XxpcPCO+QIWsfNapHoiGk=; b=xsDwOWw3m1nIWAr/zZXFgIkSlRFcFyDeYs9GYkLxMCsBi281Vrszl4LD+WZnzEn2Rk h/E/qJd9DzgDCjgHHahJVDClX/xCf+xVQxdov8xhrCGC3xnLDRRr3zwm/UKdIvNU6Rwe cF1Rn6U2cHcK85WbZWcHJGa3n/JLIk1ezLQoVBI3jV/wGBCUOv3pp7u7sVZWkpr/qO7x yFNry/DzCGjEjfH8Jm2hTWjVpJV9d2LT/zSpBVyKwid+RIf2R7CYRZITU+QewYWPP7A0 xdxGGs4PdjywdVbHSSzvI0PGnB7KCYPyvPTKPQaNnwvHh6+vTDR1XBAV1pJuHcRBUPMA VsOg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=IHdgpCYk; arc=pass (i=1 spf=pass spfdomain=flex--yosryahmed.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-204916-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-204916-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id d9443c01a7336-1f6bd7f43d1si16188735ad.512.2024.06.06.11.56.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Jun 2024 11:56:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-204916-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=IHdgpCYk; arc=pass (i=1 spf=pass spfdomain=flex--yosryahmed.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-204916-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-204916-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 3807B281C6E for ; Thu, 6 Jun 2024 18:49:26 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3487F4F1F2; Thu, 6 Jun 2024 18:48:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="IHdgpCYk" Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) (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 EC0414652D for ; Thu, 6 Jun 2024 18:48:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717699703; cv=none; b=jDwb9zav8NAK7+IySRU44aQI4JQ8J6YGPbPpTmBzvWLJAZ17o480Lel17Uz/P8xglDvBHRtu5cd3hBCTK/jxOLxn2znm36w+l2OQKLiU9w8xkih4Jj+LhNY3QGYSJY2bZ3mrwReV2HTOtpALC0QY2hdw7dWHg/7ADB263M3tz7w= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717699703; c=relaxed/simple; bh=swNbkUhJX85AnPQBSO1rHUAI4XL5FOuzWRYmH0ezyuU=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=FFY5+stOAb+42wGZeHIB8J0I8w7CwNrBvGz9p5lZtT2tisWoBqPmXvrf8/ZSqG3e2VdRCjbYpLjfRHSl2SKLLPIGEXYAQ5k/M+FN0uMiQkO/W87xZMWa9hjmq9qqZvAUMgPBHJLPqZ9Zf+mKTw48iLrYyPGCflwAaoSW9nR7BQQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--yosryahmed.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=IHdgpCYk; arc=none smtp.client-ip=209.85.128.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--yosryahmed.bounces.google.com Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-627e9a500faso20084777b3.1 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=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=33EVY1gasG0xwBVR+VPpHnVgd2Suv88JpbujEvfP7pE=; b=IHdgpCYkcZawEcgFxyIBsfDh61qQlwy7ozZJVqEc1GJ/Do0iapA0BmaKsvPGtZ6FeB 8s/woiGlV0q44hIsVvgWt8s+LWxKT+Dbg3BuYEE1iGN5cHvRNcS63YxHwqthplwxkbwK zJWGAYp5RhfTIy3XekduufIIDPOHZ927v5EHcvwE7BwgO8MGPM0ZW2v1b6eIWI/xhLdq Ot8Egt/ubJ6eNb/XqoWCvNoGyh4/INql0Wk1ymLjFY+CnRAN37eafvVZP+EEXwH8wL2m 3QYszQHWDv1uOxuz+C/C7wHoEImqNW4jZLDlzRHyjtu2noQMvmMlxfxsaXhtrJ60wdNC //7A== 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=RS0k2pA1/cTVkpL4t75Xp0MPtNrp1AuBaiuCHqnHL0VF6cWby9upkSXMEXUSQWVRa7 5WQtGsHgx3+ecxSazhk48Pmqv3wdXDIdoZjnX6AwlMRkBJimcoAGWHD66U5f7d2YHW+7 8Ep6ZTw53nSSqMVFuKU0qi/Rd29lkf1ZcKXmxWhrXt08W1hwbWfaWYSHjL86Rv2Da+Id QYLvhgGSj4E6/ZXWqoMZCdcAKdyBTVfIAz0XRWuKd2jblthZ67kxKSYcGUPJ8fiywWNF Lusrtdn57IenFx6KSvqjbAVlzOOJS8mi3jw794DexTHdipR/GYcqX/qEdFTJkae9n5H0 Xa0w== X-Forwarded-Encrypted: i=1; AJvYcCXu6648OyfcbWG1+8hJGth6HM9iTdfIpQo5qqBqnfZ1p8WSl5etC3aWmyafQtEcwc4Xeyq1DixJuy/SAOFYlaBsPyueO92CHZttFgYZ X-Gm-Message-State: AOJu0YwejxzOssC+T5NNGQE5IOlIhwjMp2dWe7BxPu3ZUR6q4qlb1zpW riV1neynILhxl/HXcQgn+Z753YNAKRwNtrgdjItI05wy3/yyvkFvrU+vnczqmd8yOUARCodeTrf PpI3dD61xjHu8sRW9MQ== 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 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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 Content-Type: text/plain; charset="UTF-8" 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 --- 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 -- 2.45.2.505.gda0bf45e8d-goog