From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5AA19606A322 for ; Fri, 4 Dec 2026 16:48:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=dMf1I9nH Received: by kanga.kvack.org (Postfix) id A26D56B05BE; Fri, 4 Dec 2026 11:48:27 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 9FE486B05BF; Fri, 4 Dec 2026 11:48:27 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 93AD56B05C0; Fri, 4 Dec 2026 11:48:27 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 679C86B05BE for ; Fri, 4 Dec 2026 11:48:27 -0500 (EST) Received: from smtpin08.hostedemail.com (lb01a-stub [10.200.18.249]) by unirelay05.hostedemail.com (Postfix) with ESMTP id E0DC8404B2 for ; Fri, 4 Dec 2026 16:48:26 +0000 (UTC) X-FDA: 85506883812.08.90C064C Received: from tor.source.kernel.org (tor.source.kernel.org [172.105.4.254]) by imf12.hostedemail.com (Postfix) with ESMTP id 4AAB74000F for ; Fri, 4 Dec 2026 16:48:25 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20260515 header.b=dMf1I9nH; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf12.hostedemail.com: domain of sashiko-bot@kernel.org designates 172.105.4.254 as permitted sender) smtp.mailfrom=sashiko-bot@kernel.org ARC-Seal: i=1; a=rsa-sha256; d=hostedemail.com; s=arc-20220608; cv=none; t=1796402905; b=xe0ujzrS/YEjNO5DL6QIkd8QArRkS7ZuQ4YhaREezukSCkCLu1eYK0AJA8MWAF5BbgNhNp WStUBFxi9ZsMrKumLS7AMnAFG12jiWUXzcivnMnIl+C9vGrjxKpuzk1EEUZrwS6Gm+nJm2 8RVVhVn1PtOfdmO0q8cM5BlvkAZP1lw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1796402905; h=from:from:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=/r+XfpQEdZSQoXnwSGtDqL21uSIUmg1dOXht5J/UJjc=; b=7UFwMCMh1JlNfnhc5U/rP/3+7KWI4UPtJQYy+m+1vys38URKXZITjefT/4vrjfA6u4jbPh Vn5wz3bW00Z2NK5fNr0x/T+2WJ/H5FUPnKXUcVqvfp/OtnnpbZGHN0yIwGt7H1Uz1fRtIL y3idwW1WEKdoNq5sAbYRPdDIQEES3Ms= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20260515 header.b=dMf1I9nH; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf12.hostedemail.com: domain of sashiko-bot@kernel.org designates 172.105.4.254 as permitted sender) smtp.mailfrom=sashiko-bot@kernel.org Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by tor.source.kernel.org (Postfix) with ESMTP id E342A623D3; Fri, 4 Dec 2026 16:48:24 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9DDDA1F000CE; Fri, 4 Dec 2026 16:48:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796402904; bh=/r+XfpQEdZSQoXnwSGtDqL21uSIUmg1dOXht5J/UJjc=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=dMf1I9nH0sxXt/hUBHzceXGNP1sykyvEPpRM6qoeIvXV3/clzfXjqOL7TbJfmdKKO 7T0PIxMP81aZVcmlV5ZdB1UpcJtYYKyP/6LEwlo8ur6zZFQIiATIsCY3iZNwNGClMR VzF+Q2rjY8gjVnnDLtu3aDIgzKPBP5Jz0XavEXJLl+KrKM+I68e5fVHC3GNf45G+9P HmX/ZV81atjdc80/rb8oJ2+a5FM6eXDesAEGntdE87tBHef4FpCxjCucPXdxjvb7Tf E0m7sDUYjwBMdArE128VqpYq3oIcFT5r9xomHOUz/plsoTx1t6ZP7VMMWx9gBmypIW O6zdCBEnAvqfQ== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v8 09/14] mm, swap: let the command line set the xswap device size Reply-To: sashiko-reviews@lists.linux.dev To: "Baoquan He" , linux-mm@kvack.org Cc: akpm@linux-foundation.org, david@kernel.org, corbet@lwn.net, chrisl@kernel.org, kasong@tencent.com, urezki@gmail.com, hannes@cmpxchg.org, yosry@kernel.org, nphamcs@gmail.com, baohua@kernel.org, youngjun.park@lge.com, kunwu.chan@gmail.com, klarasmodin@gmail.com, "Baoquan He" In-Reply-To: <20261203164336.864691-10-baoquan.he@linux.dev> References: <20261203164336.864691-1-baoquan.he@linux.dev> <20261203164336.864691-10-baoquan.he@linux.dev> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Fri, 04 Dec 2026 16:48:23 +0000 X-Stat-Signature: jxhtaaefz88fuet38xafrzb9daweh9ry X-Spam-Status: No, score=-11.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=4.0.1 X-Rspam-User: X-Rspamd-Queue-Id: 4AAB74000F X-Rspamd-Server: rspam07 X-HE-Tag: 1796402905-804504 X-HE-Meta: U2FsdGVkX1/36SRPGmc+Ldt486pfwNnGo3AzE8HyhDLVY5WW1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zV7ZLHJwwa7OcXf+1wHhXYpouXySqkZAG3BQ7GqX3XpGpY4ITEkpiU3zQB/afBwPUlOb3CO1gy1YzVL4pCH/F0vv1ZtTKEBMhset72n0aH2lalzHB2AqFy7XUrrHDUC9LxMk44lX9g6U1bQE+8+oqGUQjIwWlUhR39uLBeZ6x61OhQpEgALpx5LKvviSP8K6GnQYbmn2EoBPuByv+npxWEwEJmDDiRvzQhnSYbNe6n1I4d24Spfz48LihT/69gSxPyKlVXq5gFDWnlj3ZBqz6abj1ib5eJuT9vedNkRSKYtlVpIbuZb/xFctkb6nKTr+Q+O9z0DvjGejDMyha2TZauWNic7QgLA11PHEbAo5eGiVUS7VRYXljwPEsziIwpg7joRiXyiWzM6ifDNc7EDrnQXggSj4hjco1jlgfUGenFGlfXvXqhiKExrV7wKLD+mNW2EeyeRnifynduouSxMVq6wAz08YbaHjs4normJjgJml8ilvyzcaATQLvPCqsaXD2U3Q2Pp35/14JJ32yBY2Bl8P+5slMGsPt2a8m0yr/G/RPxKsJq54PuiyckPHVZiXKgUUlnjlmaUh7FfVKfHuNNIKuYKeHYtxj1k8KVjDj++X87HSOlrO6KO3nvPK+gsCxHYdfzoYghcqT9usT8CNv3vZmxJ8EL1Z1xdHKO+1NO/gmwtcwM0WHPbkW7sGy+NMmpOhgJ6ZftDPIcWmzhoDOFGhgOZmrXk6iAg= Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 X-Archived-By: Thank you for your contribution! Sashiko AI review found 3 potential issues to consider: - [Medium] mm, swap: xswap.max=3Dmax exceeds kvmalloc INT_MAX limit in zswap_swapon() - [Low] mm, swap: xswap_parse_size() parses percentages with base 0 instead of 10 - [Low] mm, swap: sub-PAGE_SIZE xswap.max=3D falls back to 200% instead of refusing -- commit 5bc278987251bcc1f79b53f20a43d0a5be1540cc Author: Baoquan He mm, swap: let the command line set the xswap device size This commit adds the xswap.max=3D kernel command-line parameter so users can configure the size of a new xswap device as a byte size, a percentage of RAM, or "max". The size is resolved in xswap_create(), refusing explicit sizes that exceed the device limit or fall below one cluster. > diff --git a/mm/swapfile.c b/mm/swapfile.c > index ba899e349e992..6ce5dbb3b1035 100644 > --- a/mm/swapfile.c > +++ b/mm/swapfile.c [ ... ] > @@ -74,6 +75,102 @@ static int xswap_destroy_by_name(const char *name); [ ... ] > +static int __init xswap_parse_size(const char *str, const char *what) > +{ > + const char *pct; > + char buf[16]; > + unsigned int pct_val; > + unsigned long bytes; > + char *end; > + > + pct =3D strchr(str, '%'); > + if (!strcmp(str, "max")) { > + xswap_size_max =3D true; > + xswap_size_pct =3D 0; > + xswap_size_bytes =3D 0; > + } else if (pct) { > + size_t len =3D pct - str; > + > + if (pct[1] || !len || len >=3D sizeof(buf)) > + goto bad; > + memcpy(buf, str, len); > + buf[len] =3D '\0'; > + if (kstrtouint(buf, 0, &pct_val) || !pct_val) > + goto bad; [Severity: Low] Should kstrtouint() use base 10 here instead of 0? With base 0, a leading zero triggers octal parsing, so xswap.max=3D050% is silently parsed as 40%, while xswap.max=3D080% fails as invalid octal and falls back to the 200% default. > + xswap_size_pct =3D pct_val; > + xswap_size_bytes =3D 0; > + xswap_size_max =3D false; > + } else { > + bytes =3D memparse(str, &end); > + if (*end || bytes < PAGE_SIZE) > + goto bad; [Severity: Low] Does rejecting bytes < PAGE_SIZE here cause sub-page sizes to fall back to the 200% default instead of being refused as documented? xswap_max_setup() discards the error from xswap_parse_size(), leaving xswap_size_pct at 200 and xswap_size_set false. A parameter such as xswap.max=3D32K is refused by xswap_create() on a 4 KiB page kernel, but on a 64 KiB page kernel it logs a parse error and silently creates a 200%-of-RAM device on swapon(2). [ ... ] > +static unsigned long xswap_size_limit(void) > +{ > + unsigned long limit =3D swapfile_maximum_size; > + > + /* A cluster index is an unsigned int. */ > + if (limit / SWAPFILE_CLUSTER > UINT_MAX) > + limit =3D (unsigned long)UINT_MAX * SWAPFILE_CLUSTER; > + > + return limit; > +} > + > +static unsigned long xswap_size_pages(void) > +{ > + unsigned long long pages; > + > + if (xswap_size_max) > + return xswap_size_limit(); [Severity: Medium] Can xswap.max=3Dmax exceed kvmalloc's INT_MAX limit in zswap_swapon() and trigger a WARN_ON_ONCE? On 64-bit kernels with CONFIG_THP_SWAP=3Dy (SWAPFILE_CLUSTER =3D 512 on 4 K= iB pages), xswap_size_limit() returns 0xffffffffUL * 512 (~8 PiB). xswap_create() passes the full si->max to zswap_swapon(): mm/zswap.c:zswap_swapon() { ... nr =3D DIV_ROUND_UP(nr_pages, ZSWAP_ADDRESS_SPACE_PAGES); trees =3D kvzalloc_objs(*tree, nr); ... } With ZSWAP_ADDRESS_SPACE_PAGES =3D 16384 and sizeof(struct xarray) >=3D 16, nr is 2^27, so kvzalloc_objs() requests at least INT_MAX + 1 bytes without __GFP_NOWARN. __kvmalloc_node_noprof() hits WARN_ON_ONCE and returns NULL, causing swapon(2) to fail with -ENOMEM (or panic if panic_on_warn). Even for large sizes below INT_MAX, zswap_swapon() eagerly pins up to 1-2 GiB of unswappable memory and both zswap_swapon() and zswap_swapoff() iterate over all trees without cond_resched(). In addition, setup_swap_clusters_info() reserves ~192-224+ GiB of vmalloc space for UINT_MAX clusters, exceeding vmalloc space on 39-bit VA 64-bit kernels (e.g., arm64 39-bit VA, riscv64 Sv39). Adding petabytes of swap to total_swap_pages also distorts oom_badness() and vm_commit_limit(). --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261203164336.8646= 91-1-baoquan.he@linux.dev?part=3D9