From patchwork Thu Jan 9 18:59:03 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Isaac J. Manjarres" X-Patchwork-Id: 13933153 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 1EE63E77197 for ; Thu, 9 Jan 2025 18:59:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 80D9B6B00A5; Thu, 9 Jan 2025 13:59:16 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 7BD706B00AE; Thu, 9 Jan 2025 13:59:16 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4FE476B00BA; Thu, 9 Jan 2025 13:59:16 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 25A5C6B00A5 for ; Thu, 9 Jan 2025 13:59:16 -0500 (EST) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id DBF531C6D24 for ; Thu, 9 Jan 2025 18:59:15 +0000 (UTC) X-FDA: 82988826270.16.D810DAA Received: from mail-pl1-f201.google.com (mail-pl1-f201.google.com [209.85.214.201]) by imf01.hostedemail.com (Postfix) with ESMTP id 3314240006 for ; Thu, 9 Jan 2025 18:59:14 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=zK3TsheB; spf=pass (imf01.hostedemail.com: domain of 3gByAZw4KCPslvddfpdqmduuhvjrrjoh.frpolqx0-ppnydfn.ruj@flex--isaacmanjarres.bounces.google.com designates 209.85.214.201 as permitted sender) smtp.mailfrom=3gByAZw4KCPslvddfpdqmduuhvjrrjoh.frpolqx0-ppnydfn.ruj@flex--isaacmanjarres.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1736449154; 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:in-reply-to: references:dkim-signature; bh=6u8EPgBRFPqrwQxqtoSvUJvvTwyREH+m+xblwVBSNUA=; b=B24bHtDQySG/oGBxjCSkQCy/zdm0pG+RffAVu1kM1cT1Kq+StGl7vOqPRX92Ju8A+9rQ+n YvsA0gMJF36PDas3LgSOp4jsYS6VduioAxY+gnogTq8RUNxJakKOOi30uahrd54qRhvKYx OcG9RHPVOGPYFMS9EhHSWwiOKQjgoPQ= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=zK3TsheB; spf=pass (imf01.hostedemail.com: domain of 3gByAZw4KCPslvddfpdqmduuhvjrrjoh.frpolqx0-ppnydfn.ruj@flex--isaacmanjarres.bounces.google.com designates 209.85.214.201 as permitted sender) smtp.mailfrom=3gByAZw4KCPslvddfpdqmduuhvjrrjoh.frpolqx0-ppnydfn.ruj@flex--isaacmanjarres.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1736449154; a=rsa-sha256; cv=none; b=JdmRh4yrXFHMqtQnlI86Ro7w0HKgGtdoDrSCVvoS64RyuvZbOSliPsCrUiA977KwBYfjUr uQSNVoxbMsg9yTlGsufGuZeFg2YuVdJJkBbcj1Q4qfGWsfJYl8BDS89xqWWO5DbyJZ1mOl WCqJw40UV+gb+qUr4IDTZn5pb4ZI3eA= Received: by mail-pl1-f201.google.com with SMTP id d9443c01a7336-2163a2a1ec2so34173525ad.1 for ; Thu, 09 Jan 2025 10:59:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1736449153; x=1737053953; darn=kvack.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=6u8EPgBRFPqrwQxqtoSvUJvvTwyREH+m+xblwVBSNUA=; b=zK3TsheB1iaNEhQHaX3Oo5LKAAoojNEjPryDz5JaZAf6ZeVslZrbWU/25f0y6Us0UI Qdn3qUjXprBpyzG3XJkgxoD9HSwDK7PseAX+R+BJYb3kSh0lC3M0WQQEy8qeRhj3fLkE +pBqjcYuuwmOAVYrrFOuYH1Db5tqFyDyFwuZsUMjik7dFt8GN4FpEwDiC04NP0m0Ol55 x44om7hFr5DX8colKZA86qia3QN/DHiqH0VAgh+dyvO3rUdvN8pOh0BtPlN51ENacBLx vUL2b689+RszUGy2qAcTyBVtdQNjmN5JpCCZoMeuJzaoihAgixuDCatrK7EgXqTnk77M IIOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736449153; x=1737053953; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=6u8EPgBRFPqrwQxqtoSvUJvvTwyREH+m+xblwVBSNUA=; b=UGzO18m2USIYAZVXGK2Fy6/bGYRFhu2CQfKeswk/8LWcgVqdOz2WhSPD/ljbB0L+Ba 0eHgy399W91kRAv39EqGk6jmQXnlu4jOgdh3OnAYzsd/YnjyX7er/YvoBbBkUmaq3FlB E6GFVP/amB5iJTlEbJfZ3D+FLmVqYx2E5kAxuiFKwLRJTpNIUi64Ut4XpyobAi4nxgRA xxr3r5/8D5X1aT7A+FsiT8/MQ/MXIA0nLxvG0KV1bxlpxfmQuhRKjHox6IqJo7eYvnSB Y0stzsvM3Dyv+JCT8EXxuOiJ6GISqRx5Bxu5cwME0m5Wer3jrkduGrIKPazbmlsxXzms iKBQ== X-Forwarded-Encrypted: i=1; AJvYcCUenhiugq2jqhfbFrhTQu7F3RpgThLTjkRVE9dsxU2TmYVgfyJCck4k/KVtNCmHNb6wK1gFBbwNRg==@kvack.org X-Gm-Message-State: AOJu0Yx1srdCocdjCVxs+pD//bvq9rNtjf8Q5jAjvMwSL2xCsEUbMdIu m7D8kSt0kNkb3xfIoj+xmWj1h7edigeZUuPlDJgxQznYHTcqNh9yIH20ioPn08iEh/8BxohynF7 EyoNVJpwAiK1DBQ4BxaE3TL0OBeKLIXRvvw== X-Google-Smtp-Source: AGHT+IGV7uLct/UpM2X6pe8gTq+piMaLuQZvtabd+5Rz9OHuyvL6rNOQGgU+ZJwoFsxOOP6NKe/vj3Mt7tL5NzuU9dyv8Q== X-Received: from plbjy11.prod.google.com ([2002:a17:903:42cb:b0:215:ac55:d3ec]) (user=isaacmanjarres job=prod-delivery.src-stubby-dispatcher) by 2002:a17:902:e950:b0:216:4853:4c0b with SMTP id d9443c01a7336-21a83f92f64mr110873765ad.33.1736449152865; Thu, 09 Jan 2025 10:59:12 -0800 (PST) Date: Thu, 9 Jan 2025 10:59:03 -0800 Mime-Version: 1.0 X-Mailer: git-send-email 2.47.1.613.gc27f4b7a9f-goog Message-ID: <20250109185908.1006310-1-isaacmanjarres@google.com> Subject: [PATCH v3 0/2] Cleanup for memfd_create() From: "Isaac J. Manjarres" To: lorenzo.stoakes@oracle.com, Andrew Morton Cc: kaleshsingh@google.com, jstultz@google.com, aliceryhl@google.com, surenb@google.com, "Isaac J. Manjarres" , kernel-team@android.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org X-Rspamd-Queue-Id: 3314240006 X-Stat-Signature: 7hpqjaca6r1xwo4gn9czuu4azfz9qssp X-Rspam-User: X-Rspamd-Server: rspam11 X-HE-Tag: 1736449153-960039 X-HE-Meta: U2FsdGVkX1+mNSwyb+p+gqdF0XuZnXZv6xdkq489jltB/9p1RGEBSeUcz4tGfS9pdAPK6jCu50P2xN1QbleWCz99bXUCgicMYewwqFaNAvNG/48Oom7WJdNx0b1wS1JraO+VdfmxQnDj+682jf/TCY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Zc1aTZJrbchDp84VWklDKVeaRCUz6C4T26+YfZm27i5PG90R03s77jkRD5yYFh3nSNvoRhqouc4hSv+S4uV7rQ0+trWYqQMDA2/quQvUCBcTF8IX8t+DGajEpbiWOTZlR5k6RENwd1LRwIwEfIczdUULqhtrp4GSOtYIl1vjqDc1qfzvp64DvXS9jR1755lpR+Hs7tQEGOv3vlaa2wEYjITdZJSiKccM+I5GPsx6x7vvvt4MISlTJqmPdiWASnHd4vjrxgyEc7z7T8mEMriP1l/ghZVbdjYfqHgygM81A/o5gPxHSe6zcmeg6seFCEfBwZnV9eFlQU6LXKvYrR8sgbdPstkPbIjnRDucVL7nZqAg3eZimCrd6zTVVfuNBPF1qExmASZPDXq2myK/6XA3rGMdfEiV981t+DKGRdLhtc= X-Bogosity: Ham, tests=bogofilter, spamicity=0.013016, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: memfd_create() handles all of its logic in a single function. Some of the logic in the function is also somewhat contrived (i.e. copying the memfd name from userpace). This series aims to cleanup memfd_create() by splitting out the logic into helper functions, and simplifying the memfd name copying to make the code easier to follow. This has no intended functional changes. Note: to apply this series over mm-unstable, please revert v2 of the series: commit 729d8812ffd5 ("mm/memfd: Use strncpy_from_user() to read memfd name") commit 24847e33d746 ("mm/memfd: Refactor and cleanup the logic in memfd_create()") The base commit from mm-unstable that I used was: commit 1cdadc307463 ("mm: compaction: skip memory compaction when there are not enough migratable pages") Thank you Alice and Lorenzo for reviewing v2 of this series and for your feedback! Changes from v2 ==> v3: - Removed namespacing from the new helper functions names. - Updated names for helper functions to better describe what they do. - Changed the argument to the flags sanitization function to be a pointer to not discard changes to the flags. - Restored original ordering of how the fd and file structure were allocated. - Simplified the constant used for allocating the buffer for the memfd name to NAME_MAX. - Updated a comment about the return value of strncpy_from_user(). - Added Alice's "Reviewed-by" tag to the last patch in the series. Changes from v1 ==> v2: - Rebased on top of the mm-unstable branch instead of Linus' master branch. Base commit on mm-unstable: ca95745c20ad ("mm/memmap: prevent double scanning of memmap by kmemleak"). Links: v1: https://lore.kernel.org/all/20250102230658.1112261-1-isaacmanjarres@google.com/#t v2: https://lore.kernel.org/all/20250107184804.4074147-1-isaacmanjarres@google.com/ Isaac J. Manjarres (2): mm/memfd: Refactor and cleanup the logic in memfd_create() mm/memfd: Use strncpy_from_user() to read memfd name mm/memfd.c | 96 +++++++++++++++++++++++++++++++++++------------------- 1 file changed, 62 insertions(+), 34 deletions(-)