From mboxrd@z Thu Jan 1 00:00:00 1970 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 5B0ECC27C53 for ; Fri, 7 Jun 2024 07:11:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D23606B009C; Fri, 7 Jun 2024 03:11:25 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CD3686B009D; Fri, 7 Jun 2024 03:11:25 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B741E6B009E; Fri, 7 Jun 2024 03:11:25 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 959B86B009C for ; Fri, 7 Jun 2024 03:11:25 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id A5706A26A0 for ; Fri, 7 Jun 2024 07:11:24 +0000 (UTC) X-FDA: 82203221688.04.D0278AF Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf24.hostedemail.com (Postfix) with ESMTP id 56F2E180006 for ; Fri, 7 Jun 2024 07:11:22 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=C7ho5kEP; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf24.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1717744282; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=/IPbyezJNkYY0ZyM6lla2UrO3UC3w9Y+ditdjI45IwA=; b=5TSF/j1HHJkpQp9sEDwaB3pZzEjcKht49IRDEw0TZ/yzBdQwWIFuxyEWw9NBx7q6CfVACy W7v54l0TGyO3TmBEGLPGxLxC31UyHNpTtXjp8p6MQ7nCFeqKlbFc22pca0kQ6yujVna/kQ JIdrTj7PtzjSr8cMWq8FcazXNMLW1uM= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=C7ho5kEP; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf24.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1717744282; a=rsa-sha256; cv=none; b=FjyR0VVCtwYeyVB8gfE/m0+r6j9uWZwYQL2/xzI37sru+dHb8wcwiJTouIxYPUtDZkdhVU 7qgPd/OZuiLlggTqXSUSZffj97ZoB7aKkAdu3SUMPZm2ElAzsDLfwaDdjbpooFYm7ZxCyT FghmLVVuLwIAcB9Rq8/Jn2bs0jp91XI= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1717744281; h=from:from: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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:autocrypt:autocrypt; bh=/IPbyezJNkYY0ZyM6lla2UrO3UC3w9Y+ditdjI45IwA=; b=C7ho5kEPEdR5X1ijSv3eBRB6SCXx1X2KI1VmCEe5DPMS1gLvtUMiWWxd9MvgqWuirDqycj lJnMsT/t34GjZjK77dC8Hyig4/tc9E31kO+H8kTinXAt4/tATFR5kf0Lkb/5gS2PFYwnQj vx60Al2tHms+6hAiaVeNWVcTfcx2LKM= Received: from mail-lf1-f69.google.com (mail-lf1-f69.google.com [209.85.167.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-378-p0uWPQcdM9qpRr_NWDIU-g-1; Fri, 07 Jun 2024 03:11:20 -0400 X-MC-Unique: p0uWPQcdM9qpRr_NWDIU-g-1 Received: by mail-lf1-f69.google.com with SMTP id 2adb3069b0e04-52b84359026so1446050e87.0 for ; Fri, 07 Jun 2024 00:11:19 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717744278; x=1718349078; h=content-transfer-encoding:in-reply-to:organization:autocrypt :content-language:from:references:cc:to:subject:user-agent :mime-version:date:message-id:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=/IPbyezJNkYY0ZyM6lla2UrO3UC3w9Y+ditdjI45IwA=; b=FhbZAd8ryy9uw7dOvUObklbEb1jZXrsE75iJug2bTTdIopN4hE/Guc9qWgrXEwuuRo uAst9Y0Gpju6WP3hMQek7iwFdFmIDVN6JwAuh4B0jnG63HBF3zQ6qJJhzP7U+ST0LM9F tVrXQF4sdjA721pMNpyolcDfboMhmiLnSCGrxHdOqdCAE35Ya0j85bZ8JI36diS9HB8m E4fnzU5rJ6LNtjeEMXKJC88WRAZQe5Jzflowsam9gjkYZ0Ugre6c2y41i1s0wp1+fJKU YDVk2O5mNrzVwa0sp26fMzdddjxlmdh8MqdD/CS5yhtoU69vgbscB9yVs1VfqZRocsBE LJDg== X-Forwarded-Encrypted: i=1; AJvYcCUc1duHHrRWbodK/xMaPRD4VrgThJ+6umPtg9sJYCfVP1gvh8sO2aLhG8vIKJOtH4WXekc4Z6OodRV6Ly8M1dz1LwA= X-Gm-Message-State: AOJu0Yx3KYwP00pFYu1j9GwO4nUFbN9KGJyM7SzeYjtV6mZTqgN9K+sQ fL4+ttuZ0B6jzai3WB5J0xynir7W93WmdwccSEwZuDIRKoaEPyZIE71MQInytBF27NF4mwllbd5 oPTfiLatFYzk8HWwDNOPoG0eu88rZrx9W4xgNCUwx6tp/hQ9p X-Received: by 2002:a05:6512:3f21:b0:524:43b2:d326 with SMTP id 2adb3069b0e04-52bb9f83689mr1140338e87.37.1717744278537; Fri, 07 Jun 2024 00:11:18 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFtANSv/XFCsz5zpSZso0sxMbeHu1aGTkbhTsb+r18aRfSNA7ix1MrAeYMIqe4FbpC0xPcI/A== X-Received: by 2002:a05:6512:3f21:b0:524:43b2:d326 with SMTP id 2adb3069b0e04-52bb9f83689mr1140309e87.37.1717744277919; Fri, 07 Jun 2024 00:11:17 -0700 (PDT) Received: from ?IPV6:2003:cb:c71a:2200:31c4:4d18:1bdd:fb7a? (p200300cbc71a220031c44d181bddfb7a.dip0.t-ipconnect.de. [2003:cb:c71a:2200:31c4:4d18:1bdd:fb7a]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-35ef5d4a827sm3333498f8f.36.2024.06.07.00.11.16 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 07 Jun 2024 00:11:17 -0700 (PDT) Message-ID: <9374758d-9f81-4e4f-8405-1f972234173e@redhat.com> Date: Fri, 7 Jun 2024 09:11:16 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] mm: zswap: add VM_BUG_ON() if large folio swapin is attempted To: Barry Song <21cnbao@gmail.com>, Yosry Ahmed Cc: Andrew Morton , Johannes Weiner , Nhat Pham , Chengming Zhou , Baolin Wang , Chris Li , Ryan Roberts , Matthew Wilcox , linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <20240606184818.1566920-1-yosryahmed@google.com> <84d78362-e75c-40c8-b6c2-56d5d5292aa7@redhat.com> <7507d075-9f4d-4a9b-836c-1fbb2fbd2257@redhat.com> From: David Hildenbrand Autocrypt: addr=david@redhat.com; keydata= xsFNBFXLn5EBEAC+zYvAFJxCBY9Tr1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kv AxBQXWeXhJI9XQssfrf4Gusdqx8nPEpfOqCtbbwJMATbHyqLt7/oz/5deGuwxgb65pWIzufa N7eop7uh+6bezi+rugUI+w6DABEBAAHCwXwEGAEIACYCGwwWIQQb2cqtc1xMOkYN/MpN3hD3 AP+DWgUCXw7HsgUJEqkpoQAKCRBN3hD3AP+DWrrpD/4qS3dyVRxDcDHIlmguXjC1Q5tZTwNB boaBTPHSy/Nksu0eY7x6HfQJ3xajVH32Ms6t1trDQmPx2iP5+7iDsb7OKAb5eOS8h+BEBDeq 3ecsQDv0fFJOA9ag5O3LLNk+3x3q7e0uo06XMaY7UHS341ozXUUI7wC7iKfoUTv03iO9El5f XpNMx/YrIMduZ2+nd9Di7o5+KIwlb2mAB9sTNHdMrXesX8eBL6T9b+MZJk+mZuPxKNVfEQMQ a5SxUEADIPQTPNvBewdeI80yeOCrN+Zzwy/Mrx9EPeu59Y5vSJOx/z6OUImD/GhX7Xvkt3kq Er5KTrJz3++B6SH9pum9PuoE/k+nntJkNMmQpR4MCBaV/J9gIOPGodDKnjdng+mXliF3Ptu6 3oxc2RCyGzTlxyMwuc2U5Q7KtUNTdDe8T0uE+9b8BLMVQDDfJjqY0VVqSUwImzTDLX9S4g/8 kC4HRcclk8hpyhY2jKGluZO0awwTIMgVEzmTyBphDg/Gx7dZU1Xf8HFuE+UZ5UDHDTnwgv7E th6RC9+WrhDNspZ9fJjKWRbveQgUFCpe1sa77LAw+XFrKmBHXp9ZVIe90RMe2tRL06BGiRZr jPrnvUsUUsjRoRNJjKKA/REq+sAnhkNPPZ/NNMjaZ5b8Tovi8C0tmxiCHaQYqj7G2rgnT0kt WNyWQQ== Organization: Red Hat In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 56F2E180006 X-Stat-Signature: 6mpnbjehhn64dcdr7nte33aq8unj7u4w X-Rspam-User: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SoAUGKWFCHhPgRsIiRbw9EsKFtoPSAPyV7mVXmxBVehE3Dz4MRvh+uGEi0M5vNUzrtuMDrAEZDMBMNW+HJ2ZcvVrw38cUhuDN1wI4KB24d4A55rH9XxRlF+hawxcFos9XTSpJVrrOpgFcZEaPtcs3gVDn6hf+11PlfZDg97bDHH31QpbNKu+U2L2B+/+dolF7s6pcBuRzKcBwdE5uUM7MrNyXFectVd/ZQucCqZLFSJWN2e7PPxWbTo1GUzXO12Ir0tv3yMm56TdmumpGHl8TveOaM5EaCIAHP3/2FFmnlik65sC6SqwkdW9XwwNkeFYIaTLngQjtKJxyfpG7d7umHmwuqnGccQvnwHBWfF3Cylm81dfiVE9ndOWEvcKbgD9Y9r9krFEvccOGf2GdQE3IsZFoaiJxolNYnTTdhgDr2NMOxxjQmg+GKELgnr4ls+9u35NCy9+Dq02T5aeCeEXuzvDnZ70UwDJEkgqCzYOftMX4/EXMR5hSLO3H1xBLz2aFsRjTfEYe0+lMPAK/Y1UJuggu4oQP7/yPO5/pjyvbxKbE9iRWIeaZLbZRQMDJpsTLo= 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: On 06.06.24 23:53, Barry Song wrote: > On Fri, Jun 7, 2024 at 9:37 AM Yosry Ahmed wrote: >> >> On Thu, Jun 6, 2024 at 2:30 PM Barry Song <21cnbao@gmail.com> wrote: >>> >>> On Fri, Jun 7, 2024 at 9:17 AM David Hildenbrand wrote: >>>> >>>> On 06.06.24 22:31, Yosry Ahmed wrote: >>>>> On Thu, Jun 6, 2024 at 1:22 PM David Hildenbrand wrote: >>>>>> >>>>>> On 06.06.24 20:48, Yosry Ahmed wrote: >>>>>>> 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)); >>>>>>> + >>>>>> >>>>>> There is no way we could have a WARN_ON_ONCE() and recover, right? >>>>> >>>>> Not without making more fundamental changes to the surrounding swap >>>>> code. Currently zswap_load() returns either true (folio was loaded >>>>> from zswap) or false (folio is not in zswap). >>>>> >>>>> To handle this correctly zswap_load() would need to tell >>>>> swap_read_folio() which subpages are in zswap and have been loaded, >>>>> and then swap_read_folio() would need to read the remaining subpages >>>>> from disk. This of course assumes that the caller of swap_read_folio() >>>>> made sure that the entire folio is swapped out and protected against >>>>> races with other swapins. >>>>> >>>>> Also, because swap_read_folio() cannot split the folio itself, other >>>>> swap_read_folio_*() functions that are called from it should be >>>>> updated to handle swapping in tail subpages, which may be questionable >>>>> in its own right. >>>>> >>>>> An alternative would be that zswap_load() (or a separate interface) >>>>> could tell swap_read_folio() that the folio is partially in zswap, >>>>> then we can just bail and tell the caller that it cannot read the >>>>> large folio and that it should be split. >>>>> >>>>> There may be other options as well, but the bottom line is that it is >>>>> possible, but probably not something that we want to do right now. >>>>> >>>>> A stronger protection method would be to introduce a config option or >>>>> boot parameter for large folio swapin, and then make CONFIG_ZSWAP >>>>> depend on it being disabled, or have zswap check it at boot and refuse >>>>> to be enabled if it is on. >>>> >>>> Right, sounds like the VM_BUG_ON() really is not that easily avoidable. >>>> >>>> I was wondering, if we could WARN_ON_ONCE and make the swap code detect >>>> this like a read-error from disk. >>>> >>>> I think do_swap_page() detects that by checking if the folio is not >>>> uptodate: >>>> >>>> if (unlikely(!folio_test_uptodate(folio))) { >>>> ret = VM_FAULT_SIGBUS; >>>> goto out_nomap; >>>> } >>>> >>>> So maybe WARN_ON_ONCE() + triggering that might be a bit nicer to the >>>> system (but the app would crash either way, there is no way around it). >>>> >>> >>> I'd rather fallback to small folios swapin instead crashing apps till we fix >>> the large folio swapin in zswap :-) >> >> I think David is referring to catching the buggy cases that do not >> properly fallback to small folios with zswap, not as an alternative to >> the fallback. This is at least what I had in mind with the patch. > > Cool. Thanks for the clarification. I'm fine with keeping the fallback, > whether it's the current VM_BUG_ON or David's recommended > SIGBUS. > > Currently, mainline doesn't support large folios swap-in, so I see > your patch as a helpful warning for those attempting large folio > swap-in to avoid making mistakes like loading large folios from > zswap. > > In fact, I spent a week trying to figure out why my app was crashing > before I added 'if (zswap_is_enabled()) goto fallback'. If your patch > had come earlier, it would have saved me that week of work :-) > > To me, a direct crash seems like a more straightforward way to > prompt people to fallback when attempting large folio swap-ins. > So, I am slightly in favor of your current patch. BUG_ON and friends are frowned-upon, in particular in scenarios where we can recover or that are so unexpected that they can be found during early testing. I have no strong opinion on this one, but likely a VM_WARN_ON would also be sufficient to find such issues early during testing. No need to crash the machine. -- Cheers, David / dhildenb