From nobody Tue Dec 2 03:03:19 2025 Received: from mail-pf1-f170.google.com (mail-pf1-f170.google.com [209.85.210.170]) (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 AB3E3309F0A for ; Mon, 17 Nov 2025 17:37:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763401052; cv=none; b=eRtSFPcZqa/8d5BL8t94+m9wLx6k2lcHomk8VVTeL+ko7tEYW0NZgaiwXBMEjltWLy7IWTx5tBYatFsCSf/qElAtCUiIbd2O2K7knapwA4bj3O05pWahvtIWMxOJwcetL/j0o+RG8YJYz6VzZLi9MP35IVQdLA7OpnRfCtk+vDA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763401052; c=relaxed/simple; bh=htcPVRXuXe+qY1d+V7D5BEon8d1BbotVn+VtDCIaEHA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cxoxZnMplWNtDNdFPLn7HSMBi3tbFyeRfFFN9ziCRdcjqkaKAgD04MFVeWA007zSWehHXQD4j2qDrbPRakFHhf4LYRgzkB9bwa/2Z/jA/zyYuB5hEzDY1od2dnyBzx2MCLw1xZe2YVXgkP9lakNjNxFeYwuY4yIGHYw+iujkxVQ= 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=Fi8Kv4rr; arc=none smtp.client-ip=209.85.210.170 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Fi8Kv4rr" Received: by mail-pf1-f170.google.com with SMTP id d2e1a72fcca58-7b7828bf7bcso4606450b3a.2 for ; Mon, 17 Nov 2025 09:37:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1763401049; x=1764005849; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=5C9LjYYrJflrSHBkOuvUe5rS+MjPzFDPPc1TMJZwtTo=; b=Fi8Kv4rr38a6U3YqQ/kOpmdqgF5WYttZMhUKGv+qdNMCGOSwd+iAkBe7Z2kZYKJ4DL Y46v/owTERKyLO1XHXjT6FfyGIKrpnGrQ4VuFlp5AXHXP6Jc8K9296ixcmYu6deOZy4G KlVP5YFCXfL4YFquGQBudjXfRELzf67rgWHedXcs/UjhyTu1nKkFSmZD1COxstVsVn5s MfRxOR0jaQHoJnq+Ao0AgZ7IdoK5Yfq2tpm0Xoc8pUtXXe+NqL1z859VZvmIOmr9D6eq vfs93Y5kWDjupCo9qFZW6CyP7ZVneK39ygiKv8t2Zk3I6m6uL59RQi42o1tlwqdTWzFO GlQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763401049; x=1764005849; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=5C9LjYYrJflrSHBkOuvUe5rS+MjPzFDPPc1TMJZwtTo=; b=i2GUvwg+eviR6Cz0n3c5C/4kCVNzhO1xyylGTJETHGCZr6zJ+f7giPkkBfoaX//92U 3B0sR7Ys0aY5zyBaklSoac6noWVX++witBlliSepq1IE9tQMwAczBbFqRpTk9gOyISHq bGkc/aDKiwJpHbc7eJRQ2PlmT8LnrqT5EJ1rKhdGaN0Rm0uUkucLnAa3iCEuh0CTpcpI ALDbXx+WGz65B0Ff440dK0vdZ/HmshDarR1htuYBvcSNAIcqcxohwf47ZOeP8VUKIRij cnQ99fZ3iff5n3tKdwO8K7ld2s+iWQ+etaiEvp7oyFfJ4kWaueT2e0C/IeGGvnzcCAcL BL8w== X-Gm-Message-State: AOJu0YyBkLETReWnkm8UqPhvhHfbRUrkCcXdl/7tvq8cz13/n05rjf4d QgOfd2P9171GDHhijX/RDX/vj2iacYP9jhWEHn8TAs0+Cd8rg70UMREPJzl+Ng== X-Gm-Gg: ASbGnctShXL7m2S5SO47/9Y+l1ivuHtWw8Tj5HKImekuUziBJqpi1tsC7FG2tn2P09Q O15hp2mTXiNuNbVfoeZoaR4kjPm5vm3UAnbysonigLbkTKoVj893d4zbEU7+LjIHdZ/sGs0K/o2 OhuJMVSwkzVuSFmZpC9tBkXGAwHlUDq2OJLFJ1wCXfV1kqXScQY885iENUT49EmdYWch//DlC5k n2AiD8kDLEyHbHpcdvg9MQhrA0ZunoJz9GHB/NJd5DpRm2PGc211iZVcuqerZNwTF92Op/EL3D8 y6U5SyogDrjW8jY71cBEivM9AEuSiCHn/cJobzUctIMwKsvk6L6RuSkcUL28gTlBHKEhzTBwmgU UTTxYqkFxoFUlU9YMQNYQYEeTvl6gxMUHn4Bk61pfpvUfY4nFZ4WEju01vlLvEtGoAWSZ8EJYof mToj5U+Ft5QHMDAXPfoKV8p6S56cf+RDrj4Q4xUt8JvBk= X-Google-Smtp-Source: AGHT+IEtmyLNGF6+QflVUQjGtJXEUw+OJH0XXFljr1HmNZzIfgfyYe60Ql4OLIvcBVf84mkOlBoDZQ== X-Received: by 2002:a05:7022:b90d:b0:11b:8fc9:9f5d with SMTP id a92af1059eb24-11b8fc9ae93mr2387442c88.30.1763401049333; Mon, 17 Nov 2025 09:37:29 -0800 (PST) Received: from fedora (c-67-164-59-41.hsd1.ca.comcast.net. [67.164.59.41]) by smtp.googlemail.com with ESMTPSA id a92af1059eb24-11bf23d6967sm17190077c88.3.2025.11.17.09.37.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Nov 2025 09:37:26 -0800 (PST) From: "Vishal Moola (Oracle)" To: linux-kernel@vger.kernel.org, linux-mm@kvack.org, bpf@vger.kernel.org Cc: Uladzislau Rezki , Christoph Hellwig , Andrew Morton , "Vishal Moola (Oracle)" , Christoph Hellwig Subject: [PATCH v3 1/4] mm/vmalloc: warn on invalid vmalloc gfp flags Date: Mon, 17 Nov 2025 09:35:27 -0800 Message-ID: <20251117173530.43293-2-vishal.moola@gmail.com> X-Mailer: git-send-email 2.51.1 In-Reply-To: <20251117173530.43293-1-vishal.moola@gmail.com> References: <20251117173530.43293-1-vishal.moola@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Vmalloc explicitly supports a list of flags, but we never enforce them. vmalloc has been trying to handle unsupported flags by clearing and setting flags wherever necessary. This is messy and makes the code harder to understand, when we could simply check for a supported input immediately instead. Define a helper mask and function telling callers they have passed in invalid flags, and clear those unsupported vmalloc flags. Suggested-by: Christoph Hellwig Signed-off-by: Vishal Moola (Oracle) Reviewed-by: Christoph Hellwig Reviewed-by: "Uladzislau Rezki (Sony)" --- mm/vmalloc.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/mm/vmalloc.c b/mm/vmalloc.c index 0832f944544c..5dc467c6cab4 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -3911,6 +3911,28 @@ static void *__vmalloc_area_node(struct vm_struct *a= rea, gfp_t gfp_mask, return NULL; } =20 +/* + * See __vmalloc_node_range() for a clear list of supported vmalloc flags. + * This gfp lists all flags currently passed through vmalloc. Currently, + * __GFP_ZERO is used by BPF and __GFP_NORETRY is used by percpu. Both drm + * and BPF also use GFP_USER. Additionally, various users pass + * GFP_KERNEL_ACCOUNT. + */ +#define GFP_VMALLOC_SUPPORTED (GFP_KERNEL | GFP_ATOMIC | GFP_NOWAIT |\ + __GFP_NOFAIL | __GFP_ZERO | __GFP_NORETRY |\ + GFP_NOFS | GFP_NOIO | GFP_KERNEL_ACCOUNT |\ + GFP_USER) + +static gfp_t vmalloc_fix_flags(gfp_t flags) +{ + gfp_t invalid_mask =3D flags & ~GFP_VMALLOC_SUPPORTED; + + flags &=3D GFP_VMALLOC_SUPPORTED; + WARN(1, "Unexpected gfp: %#x (%pGg). Fixing up to gfp: %#x (%pGg). Fix yo= ur code!\n", + invalid_mask, &invalid_mask, flags, &flags); + return flags; +} + /** * __vmalloc_node_range - allocate virtually contiguous memory * @size: allocation size @@ -4092,6 +4114,8 @@ EXPORT_SYMBOL_GPL(__vmalloc_node_noprof); =20 void *__vmalloc_noprof(unsigned long size, gfp_t gfp_mask) { + if (unlikely(gfp_mask & ~GFP_VMALLOC_SUPPORTED)) + gfp_mask =3D vmalloc_fix_flags(gfp_mask); return __vmalloc_node_noprof(size, 1, gfp_mask, NUMA_NO_NODE, __builtin_return_address(0)); } @@ -4131,6 +4155,8 @@ EXPORT_SYMBOL(vmalloc_noprof); */ void *vmalloc_huge_node_noprof(unsigned long size, gfp_t gfp_mask, int nod= e) { + if (unlikely(gfp_mask & ~GFP_VMALLOC_SUPPORTED)) + gfp_mask =3D vmalloc_fix_flags(gfp_mask); return __vmalloc_node_range_noprof(size, 1, VMALLOC_START, VMALLOC_END, gfp_mask, PAGE_KERNEL, VM_ALLOW_HUGE_VMAP, node, __builtin_return_address(0)); --=20 2.51.1