85.218.54]) (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 43CDB2EC547 for ; Sun, 9 Nov 2025 12:49:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.54 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762692584; cv=none; b=tx6liS6ME173pCSHM01I1ynEty2SdCyKYMWPmoS2v8+hf9OAeLQOZFkF+GF2CZ1V+bE8RCuLRHyJ/QGU+/LvcWOO2w0W6KLzmQJ3zzm/2tXnNcc5wInQrFY9SgN85LysOk1OUhB/XqNKtVoc0z1MbUuXSew9Ah6HfEj5Jbumnxw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762692584; c=relaxed/simple; bh=JF2q7sTKzYiIVusFfVQ6qlbWbep+D+t1c3S+sk6voF0=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=h/lvGsfzPkwFjOZubeHnTPHm+4p28sqJKoHnfIvKQIWaaccKoh60htQrntztX3iuyMvkBOg8CnbspWHE4MtksZV0Kzx9r9kdg+w6qYnW9zr5tZgo5qcIrR64RWu32lqNQQJ1r3cx8UlX1AIthtBOMyAH9F/34UPk8ctHICdZaiU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=LzHOoyiv; arc=none smtp.client-ip=209.85.218.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ej1-f54.google.com with SMTP id a640c23a62f3a-b626a4cd9d6so337130366b.3 for ; Sun, 09 Nov 2025 04:49:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1762692580; x=1763297380; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=hDZ3xafdhT/YtTTUoql25uDvUJxupIOBYIVvt5riwwA=; b=LzHOoyivCN7TqrVfs1SH/3010EEQXneCel/Ht1s9wzDAO1cnvcIyTpK2UdcYVNApqa q25lILxkcWkPxpQr/dhAlLS5LlLEDblcQEBnC26OboyeBzstSHW25/RLcHe39JF8PsPU BI2tSJVuK4x6m6eU1+nkp8exx+tMYQ2cwRCQqxiz3JIKBsDD2h6RGoIL7EUKcRVU+i2y 1joXruWP0YGD91Fh2DVL1q3udqu5o9lwfk01Pf1+viEW5zkhdhhEPtZTtOKsQgJ4tEqa +svApird7KA/5RKFOLNEI3g7UJuVHUbZKvxEPjKuqTyF9ob0qHQteX2Wx+cP7ecPlX2x qm1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1762692580; x=1763297380; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=hDZ3xafdhT/YtTTUoql25uDvUJxupIOBYIVvt5riwwA=; b=oy44T3twtyic0qznMR6BKrdYwTAm2T0vLTkxKhPTSR2vJgbmoRmtDwxinqafLsL/C4 vuAJTF7+Is3ULllSsqzm7AXISzWQncDQdYFgPr7eoMmpOX80/QNQdc2h73e9TDXuTlpT /HxQFSm1HrZBlwnwnQWwQSRblo110sGMmVz5YQeAsu+M09d4Qc2+oAxkT/V4zju7DNVs yjN/dvgsLY5JCu3huXzSBa9PAKx4+9vykOgQqWRxMSL0QG/AktgPtEvqGlz7lhOH6QHJ lmFaGGHwJIGCiJHZq9Q6ZJ2hUVMp8XRBA6feqX9Qg6qwIqFGWLM7lt9lIjt8xcgys4KW 27Mw== X-Forwarded-Encrypted: i=1; AJvYcCU3gLT9VclgOHsNyRkJM1fbGP4MDlOlg0suTAJtxB+Ia6UCpHL/FPAGJHsuWWNPg5FOrfawxrOI0oDP@vger.kernel.org X-Gm-Message-State: AOJu0Yxv/axdz/pTkwhUeL6kjJnzfcTsU51Qcw+i1djYuFPL7i1jJtOm mv2SAj+udT3vKlN8pRbv6g7bVmVoqFj8DCAxQzN4SBziG260qHjnNTH7FIw/I9t4ZphjTD/DGTt Z/Bb4OIrxAJ6bePaMf4aWCugRGRfoJ4I= X-Gm-Gg: ASbGncu4gr6Xy1azLy7pQBaRXsNNhnqSQuplFBS6PDAizBhw3fa45/ZoSxDFwCWYsaJ E5i9vPOmJtzsNzZ94+XKaZ8GqP/ySJ8ufoonbAkPRqo1A554Fp66Lj3b3+YRmoClpgc0o6q1oCT RynkH5zUL0jc5MvgYmEB5HgdqATakaLo2Tg2kH3a1VwYkIj3zmV2FfEr2LLXMcvik69g/mjqeox evBegRA5NF4m4PEABZ4mniorwB4CYAbyLQvMF5NxKCpj+6IshKihkjmMrww X-Google-Smtp-Source: AGHT+IHNVHcrPcoXcfMQAdrM6mfxVNIvqirPfSk4ZwLH/WJQN1X+/EwZuiwM1z9Tvembh+GaQUpS/PpKFfhnQ7ESKbE= X-Received: by 2002:a17:907:869f:b0:b33:a2ef:c7 with SMTP id a640c23a62f3a-b72e058a781mr441932566b.55.1762692579280; Sun, 09 Nov 2025 04:49:39 -0800 (PST) Precedence: bulk X-Mailing-List: linux-s390@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <75c2e8fa38de383757a49bcc3f5c081be1e27a40.1762621568.git.lorenzo.stoakes@oracle.com> In-Reply-To: <75c2e8fa38de383757a49bcc3f5c081be1e27a40.1762621568.git.lorenzo.stoakes@oracle.com> From: Kairui Song Date: Sun, 9 Nov 2025 20:49:02 +0800 X-Gm-Features: AWmQ_bm7gm65mOXTd2rtxZ-2sSA2POMXyYBKPT6giX8icbqtDuQMmyxTTsU5nEc Message-ID: Subject: Re: [PATCH v2 04/16] mm: eliminate is_swap_pte() when softleaf_from_pte() suffices To: Lorenzo Stoakes Cc: Andrew Morton , Christian Borntraeger , Janosch Frank , Claudio Imbrenda , David Hildenbrand , Alexander Gordeev , Gerald Schaefer , Heiko Carstens , Vasily Gorbik , Sven Schnelle , Peter Xu , Alexander Viro , Christian Brauner , Jan Kara , Arnd Bergmann , Zi Yan , Baolin Wang , "Liam R . Howlett" , Nico Pache , Ryan Roberts , Dev Jain , Barry Song , Lance Yang , Muchun Song , Oscar Salvador , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , Matthew Brost , Joshua Hahn , Rakie Kim , Byungchul Park , Gregory Price , Ying Huang , Alistair Popple , Axel Rasmussen , Yuanchu Xie , Wei Xu , Kemeng Shi , Nhat Pham , Baoquan He , Chris Li , SeongJae Park , Matthew Wilcox , Jason Gunthorpe , Leon Romanovsky , Xu Xin , Chengming Zhou , Jann Horn , Miaohe Lin , Naoya Horiguchi , Pedro Falcato , Pasha Tatashin , Rik van Riel , Harry Yoo , Hugh Dickins , linux-kernel@vger.kernel.org, kvm@vger.kernel.org, linux-s390@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-arch@vger.kernel.org, damon@lists.linux.dev Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-DKIM: signer='gmail.com' status='pass' reason='' DKIMCheck: Server passes DKIM test, 0 Spam score X-Spam-Score: 0.4 (/) X-Spam-Report: Spam detection software, running on the system "witcher.mxrouting.net", has performed the tests listed below against this email. Information: https://mxroutedocs.com/directadmin/spamfilters/ --- Content analysis details: (0.4 points) --- pts rule name description ---- ---------------------- ----------------------------------------- 0.0 RCVD_IN_DNSWL_BLOCKED RBL: ADMINISTRATOR NOTICE: The query to DNSWL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#DnsBlocklists-dnsbl-block for more information. [147.75.80.249 listed in list.dnswl.org] 1.5 HEADER_FROM_DIFFERENT_DOMAINS From and EnvelopeFrom 2nd level mail domains are different 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [ryncsn[at]gmail.com] -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid 0.0 FREEMAIL_FORGED_FROMDOMAIN 2nd level domains in From and EnvelopeFrom freemail headers are different -1.0 MAILING_LIST_MULTI Multiple indicators imply a widely-seen list manager SpamTally: Final spam score: 4 On Sun, Nov 9, 2025 at 2:16=E2=80=AFAM Lorenzo Stoakes wrote: > > In cases where we can simply utilise the fact that softleaf_from_pte() > treats present entries as if they were none entries and thus eliminate > spurious uses of is_swap_pte(), do so. > > No functional change intended. > > Signed-off-by: Lorenzo Stoakes > --- > mm/internal.h | 7 +++---- > mm/madvise.c | 8 +++----- > mm/swap_state.c | 12 ++++++------ > mm/swapfile.c | 9 ++++----- > 4 files changed, 16 insertions(+), 20 deletions(-) > > diff --git a/mm/internal.h b/mm/internal.h > index 9465129367a4..f0c7461bb02c 100644 > --- a/mm/internal.h > +++ b/mm/internal.h > @@ -15,7 +15,7 @@ > #include > #include > #include > -#include > +#include > #include > #include > > @@ -380,13 +380,12 @@ static inline int swap_pte_batch(pte_t *start_ptep,= int max_nr, pte_t pte) > { > pte_t expected_pte =3D pte_next_swp_offset(pte); > const pte_t *end_ptep =3D start_ptep + max_nr; > - swp_entry_t entry =3D pte_to_swp_entry(pte); > + const softleaf_t entry =3D softleaf_from_pte(pte); > pte_t *ptep =3D start_ptep + 1; > unsigned short cgroup_id; > > VM_WARN_ON(max_nr < 1); > - VM_WARN_ON(!is_swap_pte(pte)); > - VM_WARN_ON(non_swap_entry(entry)); > + VM_WARN_ON(!softleaf_is_swap(entry)); > > cgroup_id =3D lookup_swap_cgroup_id(entry); > while (ptep < end_ptep) { > diff --git a/mm/madvise.c b/mm/madvise.c > index 2d5ad3cb37bb..58d82495b6c6 100644 > --- a/mm/madvise.c > +++ b/mm/madvise.c > @@ -195,7 +195,7 @@ static int swapin_walk_pmd_entry(pmd_t *pmd, unsigned= long start, > > for (addr =3D start; addr < end; addr +=3D PAGE_SIZE) { > pte_t pte; > - swp_entry_t entry; > + softleaf_t entry; > struct folio *folio; > > if (!ptep++) { > @@ -205,10 +205,8 @@ static int swapin_walk_pmd_entry(pmd_t *pmd, unsigne= d long start, > } > > pte =3D ptep_get(ptep); > - if (!is_swap_pte(pte)) > - continue; > - entry =3D pte_to_swp_entry(pte); > - if (unlikely(non_swap_entry(entry))) > + entry =3D softleaf_from_pte(pte); > + if (unlikely(!softleaf_is_swap(entry))) > continue; > > pte_unmap_unlock(ptep, ptl); > diff --git a/mm/swap_state.c b/mm/swap_state.c > index d20d238109f9..8881a79f200c 100644 > --- a/mm/swap_state.c > +++ b/mm/swap_state.c > @@ -12,7 +12,7 @@ > #include > #include > #include > -#include > +#include > #include > #include > #include > @@ -732,7 +732,6 @@ static struct folio *swap_vma_readahead(swp_entry_t t= arg_entry, gfp_t gfp_mask, > pte_t *pte =3D NULL, pentry; > int win; > unsigned long start, end, addr; > - swp_entry_t entry; > pgoff_t ilx; > bool page_allocated; > > @@ -744,16 +743,17 @@ static struct folio *swap_vma_readahead(swp_entry_t= targ_entry, gfp_t gfp_mask, > > blk_start_plug(&plug); > for (addr =3D start; addr < end; ilx++, addr +=3D PAGE_SIZE) { > + softleaf_t entry; > + > if (!pte++) { > pte =3D pte_offset_map(vmf->pmd, addr); > if (!pte) > break; > } > pentry =3D ptep_get_lockless(pte); > - if (!is_swap_pte(pentry)) > - continue; > - entry =3D pte_to_swp_entry(pentry); > - if (unlikely(non_swap_entry(entry))) > + entry =3D softleaf_from_pte(pentry); > + > + if (!softleaf_is_swap(entry)) Hi Lorenzo, This part isn't right, is_swap_pte excludes present PTE and non PTE, but softleaf_from_pte returns a invalid swap entry from a non PTE. This may lead to a kernel panic as the invalid swap value will be 0x3ffffffffffff on x86_64 (pte_to_swp_entry(0)), the offset value will cause out of border access. We might need something like this on top of patch 2: diff --git a/include/linux/leafops.h b/include/linux/leafops.h index 1376589d94b0..49de62f96835 100644 --- a/include/linux/leafops.h +++ b/include/linux/leafops.h @@ -54,7 +54,7 @@ static inline softleaf_t softleaf_mk_none(void) */ static inline softleaf_t softleaf_from_pte(pte_t pte) { - if (pte_present(pte)) + if (pte_present(pte) || pte_none(pte)) return softleaf_mk_none(); /* Temporary until swp_entry_t eliminated. */ From - Sun Nov 09 12:51:43 2025 X-Mozilla-Status: 0001 X-Mozilla-Status2: 00000000 Return-Path: Delivered-To: hi@josie.lol Received: from witcher.mxrouting.net by witcher.mxrouting.net with LMTP id oIa9NFqOEGn4fCsAYBR5ng (envelope-from ) for ; Sun, 09 Nov 2025 12:51:38 +0000 Return-path: Envelope-to: hi@josie.lol Delivery-date: Sun, 09 Nov 2025 12:51:39 +0000 Received: from dfw.mirrors.kernel.org ([142.0.200.124]) by witcher.mxrouting.net with esmtps (TLS1.3) tls TLS_AES_256_GCM_SHA384 (Exim 4.98) (envelope-from ) id 1vI4tO-0000000E9Ku-0cZg for hi@josie.lol; Sun, 09 Nov 2025 12:51:38 +0000 Received: from smtp.subspace.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.mirrors.kernel.org (Postfix) with ESMTPS id 419234E5A4F for ; Sun, 9 Nov 2025 12:51:15 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5927A2F068A; Sun, 9 Nov 2025 12:50:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (4096-bit key) header.d=alien8.de header.i=@alien8.de header.b="dHgEs1xz" X-Original-To: stable@vger.kernel.org Received: from mail.alien8.de (mail.alien8.de [65.109.113.108]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4EAA8200C2 for ; Sun, 9 Nov 2025 12:50:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=65.109.113.108 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762692653; cv=none; b=RcVneCb9S05dk38Rvrc+eQtgt4cjc3xzvlSNI