From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f201.google.com (mail-pl1-f201.google.com [209.85.214.201]) (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 85EEF1A83F0 for ; Thu, 9 Jan 2025 18:59:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736449155; cv=none; b=LR/SekKyZ4UoEY6VXc6skXXzhtKAb5U+AI+v52B7PDPt+Ll2PTvU9yNLJL+AN6RuUjMqN24ChbMWEIEGU5vtgc2UF5vYvZqH1BTo0qwRnssvgMeIfM4cnE8Zf2MB8HXcQ5cR0HkDLK+nITKpf9KRmC3Fe/is+DXboPtVrtfo4Ao= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736449155; c=relaxed/simple; bh=hfRVV8cd2Kfu2XXPBx9yplmPGWm6RZnWLdzqycZohU0=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=U06/z0xCu9c23uYtYxkNOOiLNAtaSWt0Wx2yTCAxtSlr8M2Uh5wPl864NM02H06JCQs0t/leQnOcQackFFzaqNQrYDTQnPp5R/+EoLDw2o8rr1RMROuQ8mkfUe55RUduHmiPLjXA6VigaubmD/Sh3CsdXZFbxezrPFWVFmbhFrw= 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=L8W8apWp; arc=none smtp.client-ip=209.85.214.201 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="L8W8apWp" Received: by mail-pl1-f201.google.com with SMTP id d9443c01a7336-21640607349so25882225ad.0 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=vger.kernel.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=L8W8apWp+KwDaUyljgQqFh6dtuvIIYavNBzcZRzIs3MZu2kiUdPJYmM7Cje5maOZ8R NISbI8OEO1R4ckRaUgQTX9b9T+nZM2KAcWNGXOrZsNDdsA1EysoqH85isfQkARH2vzOB 1GTWZjhGmhNRL3DJTLIj2ol0aOnuN8q3ktZaEpUxe+nwfVhRU5Jvav4EdNZ2Xk1z1jkW fYQ+aqaD3Rja327scDH4rKx2c9bi2PNp68KSZ/pHH9wBGJku3boKJQCb6XL/CL0yUnd6 OMBmhpw2+2mLZa9O2md95XtkoFSl176nRoF36v5CIsvCa59SthU6Zd+YLg31zVzdjpv2 rGSA== 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=r/igJHiaWOu4TvGjoOLTFg1T3dpBNRvuWF8NIeuCMlaUNypGLimqTFysS5yMs4YxFX 7+ikFLS8/VShoKqNCqmTgZzghESy8nO3G2LOH308nlcYDp+8v0lTmpED605ydGtV69fp kwNgo7NQKNCZRW0ywIS9JN+Yz7RE94mvUZB+8qQl4Zv948ikVdR/Rt6JpQJTX5T0VwbE 8OJNyT2U7jngUY6SL+hH3ZLdizIPaWscML1p2QrbO8lSHKiwtcbl6fOIlUfHoZI56tBF RHykzjktFxHueMtvG4ZTF2NHrcWEyKi5lYyMeRrPEubO89gr8MLyq+hkceMQEvzaYiuH A4wA== X-Forwarded-Encrypted: i=1; AJvYcCXvgvYFGFkpyAHrWXBZPzewdXCx4cgMGwv2158ckbl0e2tuAQZ5ubfWqXaQt7UhOEFslU29SlYfKojEbq0=@vger.kernel.org X-Gm-Message-State: AOJu0YwQEF2QNR4JVIhm/tJFzmtgpkHSum5e1mjTuFHaMkE/lx+wLZuM n3FjoKfFOoFobdlvAuqalLZ2JgrxxZ04/OXGTFglmkjw8ikgWnFzd7DbPKT53T7/rv4CA08+fhi SMZfoUl7aNbKCIl0RtAxAGpluVzwkPGxlPA== 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 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: <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 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 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(-) -- 2.47.1.613.gc27f4b7a9f-goog