From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f74.google.com (mail-pj1-f74.google.com [209.85.216.74]) (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 1D9AC1A23B0 for ; Fri, 10 Jan 2025 16:59:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.74 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736528349; cv=none; b=i0ylSq2pEiqLKyEgNllCC0EY6xW8nMfilMjxRVMUO1+JlTDAy6VI/408Enk3RPYivWw/wKpUE25F2rScyHmTmuAE+k0g3mYjlrr9S/hchE4NDo6SB4mcK4/HrUwrPCVeQgeexExCrWdDlwDACT4y1wYKGESDLEeNh6D1S0b3BGI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736528349; c=relaxed/simple; bh=9Z1K25VbM4DY5Yf1x0p2LE3XAODNBgcoJZibrHNEko4=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=j90V1sufKacccHNanG5zLcp5xT55VdpbzHqvA+eV2XZm9h/7ZrBezZl2FJuOO9x6Iqnkezyo1sWAo9Hi5pRieANHLVDWLKQ0BGAN5WTzpH6y4wn+uA/wXP3+wP3BpXqCpO0wC4HWBmL0zp5x3w9gj5rkXP6t1v5KFtTl4pInKHE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--isaacmanjarres.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=colq0vWr; arc=none smtp.client-ip=209.85.216.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--isaacmanjarres.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="colq0vWr" Received: by mail-pj1-f74.google.com with SMTP id 98e67ed59e1d1-2ef6ef9ba3fso4271023a91.2 for ; Fri, 10 Jan 2025 08:59:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1736528347; x=1737133147; darn=vger.kernel.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=colq0vWri0DipQfRH/IlnCVPB3arzJh+w8g2Zjm7M5ocBV5/h5i2muWsuGI0JqvHnO OswkM1rIUmEkZF6ZrCDui1h0H2fuc6ui/1tXHI8pbRQsHlHfFOx7Nuk5cxb7A/e2kYRn ebJIldTyRlzEXVvSfk5T/zNUHyQvpBlVMmfNiVXCyIKfVV7dmpTjmNyXqdGdHnghk9Zk R+Wu0Sw9JkrIsUyWmU31TJPQiY6qEQ5apg7+V3Dp0HpODM83+BLLRPmowzoci5OR3dq1 mLBY1aU2HIpuwxgGfRPe2sVFO+IR/RKXTEqAaxgVd3fP0Zwe9jjhQfZPQe0H8eoYPRmD TMBQ== 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=HliGNFHX93vLy9BVueyaWpyVDlceRkeQilkKKKeFOWI3kkL6wolUu+kxqkM6ORh39p 0bPE3Qw+ZVFbdMrsETrl6QiMDWvaoHKwnffx5vLJrf0Oe6/pUZWaVB3dSQHvP7tV3hgD NkEzM89tDfj4MmPv1E9CgO1jdbDkWqO44K3eRJLargotoaBbUvzW0aEIcRG/GkEuYEgh bk7rDc9KpKUbzKCX8sJoq9pJj4B+3ItP762xv8UkXtDNI4b0du79+v1Z2fiMeVmR5Hs+ APGiI5stq7TEn0gHcYQPAika3W5nwDdJPTzfidCI0bebGANcYy1Dwsm30UZ7s6ZbBlRk z24Q== X-Forwarded-Encrypted: i=1; AJvYcCXHd97cmRVpM2thrsstWag0lvfBFs0PHTaE0n4pUj0xl5ZF5DHRoru2DcB8XT9sw748LnxY0/6Ljplxflk=@vger.kernel.org X-Gm-Message-State: AOJu0YwiCKAu03pXJJC7k/3wwtO2hLymKtKf3kAJfGy6vh6PU5Wgnscl 1mPrGLSumBlxdSKLqTaUtT31ON82aijEIVOnnSG9FBWDIoZAg67ak9fWXfEck1eJbTiYNLqFH/x pFsVp0pNjAsjHRLDd0B49eDeBN277s/MvZA== 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 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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 Content-Type: text/plain; charset="UTF-8" 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(-) -- 2.47.1.613.gc27f4b7a9f-goog