From patchwork Fri Jan 10 16:58:58 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: 13935155 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 B227CE77188 for ; Fri, 10 Jan 2025 16:59:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3BD478D0006; Fri, 10 Jan 2025 11:59:12 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 36BDF8D0003; Fri, 10 Jan 2025 11:59:12 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 233B18D0006; Fri, 10 Jan 2025 11:59:12 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 07DFD8D0003 for ; Fri, 10 Jan 2025 11:59:12 -0500 (EST) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 9A157A0C87 for ; Fri, 10 Jan 2025 16:59:11 +0000 (UTC) X-FDA: 82992152502.04.53AA941 Received: from mail-pj1-f74.google.com (mail-pj1-f74.google.com [209.85.216.74]) by imf12.hostedemail.com (Postfix) with ESMTP id C109A40015 for ; Fri, 10 Jan 2025 16:59:08 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=N5XWhCzs; spf=pass (imf12.hostedemail.com: domain of 321GBZw4KCMYu4mmoymzvm33q4s00sxq.o0yxuz69-yyw7mow.03s@flex--isaacmanjarres.bounces.google.com designates 209.85.216.74 as permitted sender) smtp.mailfrom=321GBZw4KCMYu4mmoymzvm33q4s00sxq.o0yxuz69-yyw7mow.03s@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=1736528348; 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=yHqB46uGd1sFV7Du/wpZ4tXPQOP+8mgqQiR+7ug19tw=; b=Pmb9G6xFGQILm9Z7HwIU7pipL1U3a5QiLAjIFLY9bKWgwUT88uxMjfuZk65yNo/EtAesUa DwYk4UyHKUcghs9O50iu4sKG6mehnANPbwRufxmFSPshtG/Ym/6bElFjVIbTP3XXLPWuKQ wqA5N7xP4FCEP12Jrq6bDI7HjlsKAb8= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1736528348; a=rsa-sha256; cv=none; b=ZGQCuYZLlhPWJixzvl7rWA2WfJsxzd/J/HGE586HEURYAKkzR0b/E4ru8R29LT2vomJsrl Hw+hATGGcRJcQ7/mTYpDoEtmPDMymZto+RazSUbcsCQa+0gN91mmNxY1IYgAcjZaSh/nVe kUPAGtlYv5QUKENH1PwKrgQ1zAGoyjw= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=N5XWhCzs; spf=pass (imf12.hostedemail.com: domain of 321GBZw4KCMYu4mmoymzvm33q4s00sxq.o0yxuz69-yyw7mow.03s@flex--isaacmanjarres.bounces.google.com designates 209.85.216.74 as permitted sender) smtp.mailfrom=321GBZw4KCMYu4mmoymzvm33q4s00sxq.o0yxuz69-yyw7mow.03s@flex--isaacmanjarres.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com Received: by mail-pj1-f74.google.com with SMTP id 98e67ed59e1d1-2eeeb5b7022so4299611a91.0 for ; Fri, 10 Jan 2025 08:59:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1736528347; x=1737133147; darn=kvack.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=yHqB46uGd1sFV7Du/wpZ4tXPQOP+8mgqQiR+7ug19tw=; b=N5XWhCzsizu4vJQq0tqe3MfFhWxOxyfh84JTKBJa4TAx8rL4rG2pdd5nWuyAs6vM+D OYllI2/lrgseuDz0ohikzCB37WSEDBQtH/2a5SGhcwlBcxW5SJo4pi1vaATmxVyU/8GM Qy+nfDbFFMxB3a6RJCeBfMhjnVgkuQ+gMbADhGnnWSVepheeThBj02I+cp5tk2MSkI0L ogNPNkvTWtANSz8Q5jGaBVlTX99eS7/sju+IS3Ow9PqDFozgXjelcSh+fBLq8ey1onTZ LYI3L8CKAAVZeW6SKUX1Q2g4fC6CamR5wCBkKh9KaLV5v96adYi16UbWwGTS4lPeOI7H 15dw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736528347; x=1737133147; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=yHqB46uGd1sFV7Du/wpZ4tXPQOP+8mgqQiR+7ug19tw=; b=NrikTGCeBNUO16ZkUH24/9nDI7+qJSh7JMDZaOf9XrJslKQIxVrvwR/8VhVry++CIW Py52vUna9VxQBsg1FYoyd1WpD9RgpoIwpFtzdtQTEJZ9iEChOkY7GexoH/4qolOkqaKl 1Vow+VgptdL+A7FD4+jpx9+TJ357Jip0BJu2FnxsAGqpabYdkVn7mpFt9zifamY/XHbj izYCHqYsQRER7NsZ8sLNT/pQLpz/NUYiP9ZF3Vtb/MX2GZkAciVPUgEa6CBRy+VQI8Q/ n14KfSePkLJUijtneJSuZUTs4mZgsJJRgAblrbK7tYgr7j17ECUqwg/WIw+CmCPXFnBe uk4Q== X-Forwarded-Encrypted: i=1; AJvYcCWhs6Z6dALYPlXmk1f9L7GfT2ykPdNupOgvn7WaD/FrGHhS2QjphThYby3fMzOUwfYNteVCkb37ig==@kvack.org X-Gm-Message-State: AOJu0YxHJHrtSiChfAELkEGj0T4Gq1HT5s+b0tnFLunI2M5FT86taDtx uHtYB7iFQrVovFl5pI0xEDGJlT8k7u1Un4Q87DnVpR/SAkivP62+JDwagUsTzeW7uk65Py5YXtA P36iF1+NnGpSEQ3UvuyhAxwv+9ejgeD2LVA== X-Google-Smtp-Source: AGHT+IFylj1qxhnYHJoV9k+8DR8NQAwLzxD6+5Uqwf+nMwGfgNngB1nKYBBDu4q3uNtIY0dN7uB3Y0Kl4mi0SOlkc+xcaA== X-Received: from pfbfm22.prod.google.com ([2002:a05:6a00:2f96:b0:725:c96b:b1db]) (user=isaacmanjarres job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:3910:b0:72a:a9d9:5a82 with SMTP id d2e1a72fcca58-72d21deb996mr18127392b3a.0.1736528347420; Fri, 10 Jan 2025 08:59:07 -0800 (PST) Date: Fri, 10 Jan 2025 08:58:58 -0800 Mime-Version: 1.0 X-Mailer: git-send-email 2.47.1.613.gc27f4b7a9f-goog Message-ID: <20250110165904.3437374-1-isaacmanjarres@google.com> Subject: [PATCH v4 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-Server: rspam10 X-Rspamd-Queue-Id: C109A40015 X-Stat-Signature: ez8rjnntfsxdkxkgebg4x81rexcwauhg X-Rspam-User: X-HE-Tag: 1736528348-570537 X-HE-Meta: U2FsdGVkX18PntDVCaKasrwiVXOCfOxDrJCRYNAU8rDJtn/0J42wCxhUY7XtJwH3uoowj6fz0UCgYHFvDDZQgsJOFeGseJGhcbecbIc0ID5emNEgV7MjxUv4qeg2cpxESq5nfyDlXYQilWwWL7lzslS+359qjPI96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pvOD5ut7n6znLr6S8dGnhvDdpQmjRx5fwvLYovhw10D5uKuesvez3zSUfV9sB5yJNyrGtBGoGfeb5IPW0WpliW3UCAlAVcgMY0vU8jwoydM4qsT4fDBFpQ/XRk7wBXkZDBmYlagNNTjDi8w5jGvqEYAqlLjVlTYhWlxC3Ajfg8pIeWQsews88pht99rXynYIEj2BEOvEBIUldJeTRqFfk/um05ZR3m91l4LJg0QbtiKWPTLr9+TpBvMvNEh8kdjWr6Q0PzsDj/vph2F29SKBXgNhUiDxszwWcXWxSW4OSG8Pc+rmEGqAHl9T565xIydkFvO+YP5sVJeLnZIWGZ7OEB8aYxv8nQ40c0dslylYvFMYYG0vTCi4SpZ8tE9JjeLsnodODBsiwB7qkjCjQuf3fSHUVA87xYFgh58Ee/hY333TWeOuYCNsyL9fMLvI= X-Bogosity: Ham, tests=bogofilter, spamicity=0.401168, 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 v3 of the series: commit 3147192ed457 ("mm/memfd: use strncpy_from_user() to read memfd name") commit 1212f60db000 ("mm/memfd: refactor and cleanup the logic in memfd_create()") The base commit from mm-unstable that I used was: commit 0703fa3785f1 ("mm: remove PageTransTail()") Thank you Alice and Lorenzo for reviewing v3 of this series and for your feedback! Changes from v3 ==> v4: - Removed an unnecessary comment at the end of memfd_create() that I added. - Added Alice and Lorenzo's "Reviewed-by" tags to both patches in the series. - Rebased on top of the latest commit of the mm-unstable branch as mentioned above. 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/ v3: https://lore.kernel.org/all/20250109185908.1006310-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 | 95 +++++++++++++++++++++++++++++++++++------------------- 1 file changed, 61 insertions(+), 34 deletions(-)