From patchwork Tue Dec 10 21:30:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brian Geffon X-Patchwork-Id: 13902093 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 03281E7717F for ; Tue, 10 Dec 2024 21:31:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 404358D0012; Tue, 10 Dec 2024 16:31:03 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 3B4028D000B; Tue, 10 Dec 2024 16:31:03 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 254CE8D0012; Tue, 10 Dec 2024 16:31:03 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 01CC78D000B for ; Tue, 10 Dec 2024 16:31:02 -0500 (EST) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 65150427DB for ; Tue, 10 Dec 2024 21:31:02 +0000 (UTC) X-FDA: 82880343714.08.59E5963 Received: from mail-qk1-f202.google.com (mail-qk1-f202.google.com [209.85.222.202]) by imf21.hostedemail.com (Postfix) with ESMTP id 321DF1C001D for ; Tue, 10 Dec 2024 21:30:17 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=b+0R6ej6; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf21.hostedemail.com: domain of 3E7NYZwcKCB45A899IHAIIAF8.6IGFCHOR-GGEP46E.ILA@flex--bgeffon.bounces.google.com designates 209.85.222.202 as permitted sender) smtp.mailfrom=3E7NYZwcKCB45A899IHAIIAF8.6IGFCHOR-GGEP46E.ILA@flex--bgeffon.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1733866239; a=rsa-sha256; cv=none; b=I+SLo+Jr+j1HuO/CV2IBcIObwSp9R6tv4cpORT+6a9Sc3WRWGd/hQDQY1kls9fAyegzC4Q 67Q3Y1mqCN8w6nT5raZMR99SAUNO1p2U2H9pR3XBTj2a5qZ8xfipj0yAVVmnirWIBCEoLH 5lT/2CO+A1jM+sFOJY5DcsJ3T6DUlYQ= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=b+0R6ej6; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf21.hostedemail.com: domain of 3E7NYZwcKCB45A899IHAIIAF8.6IGFCHOR-GGEP46E.ILA@flex--bgeffon.bounces.google.com designates 209.85.222.202 as permitted sender) smtp.mailfrom=3E7NYZwcKCB45A899IHAIIAF8.6IGFCHOR-GGEP46E.ILA@flex--bgeffon.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1733866239; 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=v7dIOJwpIK+DMFQ8hJv6bbV8boeHzOxcNBeXs7z7ZtQ=; b=h2VvOq3p9aTAnM57H4O9c0eUJxq4TNz8Tu5oItqnFKq4Z214xfXjwjKt/zErdsJXJzfEM+ KWYfjtXDK87PhAFWsputsY7D8sW8lhO4oFHRXkcoZ0p4ESIfaSpu8ffiJrunkyS/+jRX8V aSyTHNGQQa1mHf8jR8IZncrawHSBHqE= Received: by mail-qk1-f202.google.com with SMTP id af79cd13be357-7b6e1e65f2dso136201685a.1 for ; Tue, 10 Dec 2024 13:31:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1733866260; x=1734471060; darn=kvack.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=v7dIOJwpIK+DMFQ8hJv6bbV8boeHzOxcNBeXs7z7ZtQ=; b=b+0R6ej6RqzBNau6cCI/J4r+yCYN096o+DXDiJzo/LKVbgcInRCyoaotL8AKK9HdRR y5i9Z1M4I2mc1zgE2OX1rEEBHfJeFLamy6opwZ3Ml2M4WL0U6lmzQYBkM8d4QVPuCW7B Rw7BVr9jeUuNbBCzxBh9FgBw+EydI+bLNc3NMIMVzXqQDISrcOmfjN5KzLk/cYnuVFk0 dyjcM/SjqpGPv2IuNQpwZaLNfaL9VByYhfMLM7MHTAO51e7zzfCtQjPpxXeTV8tT6PBa 0vZT4Y75omIb+OJy27uNjPoUthnAX214ntBMu/kLEjFFAYsHiOARCsBaIuOjRkMbP7v5 POkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733866260; x=1734471060; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=v7dIOJwpIK+DMFQ8hJv6bbV8boeHzOxcNBeXs7z7ZtQ=; b=kXviDxVsF9qnxaMnO+G5OOCLfSCVcMVTgLuLW4hpszl4dbpg/f9pIYSkQQmrVA8FXV Z2ur7Myi8p8IRD6uNa9WQ+p0/D4TEHNDw/L/k1/JHxzN5A3xwnRxi9+BpEHI5k3vNDmB CkVYhJ7fr87smZC+txU44+OUKPf8K6y0LekO9XHnDVDnuFH/kbNFCT6w92JMeyt9S5cn kpV1FC/qKDWO2MA6qBl5sOQYz93rS5u0D6uCSgXSIrKrlTQd6WK2rkKICfPuQ3hDxtIf qdOj2FSni3jTVOo2z1fnA/ONrn3KqoGDRNYn24czt67wY6oGZS9XTNP4TH88rLZJIMyp +HAQ== X-Forwarded-Encrypted: i=1; AJvYcCWBM86czjJJYB6jCuTeEbtr15RtR7usTNXvi0EsacpHkZLJkPNBH/POusLcmKP8ZExQJr+EI0hGuA==@kvack.org X-Gm-Message-State: AOJu0Yyp8dNdo9IIPneJ98pdQDJVjULuEDuSBJ9qqEksNl4ty4DSm152 cZW0grwCILqpZ6TXtwjmpic9+GYcchrvb5mXd4ZNZfHdwXR40IVJ46hvxpozDig5lGna3dyLf72 VUpYDsA== X-Google-Smtp-Source: AGHT+IFAIU7f+wfqSacMneWm1FlqBYTn2gwv6AQPmqTyEeVFWqYtuzWyChRfemA5F0mctYYZSfHkc/RQodwH X-Received: from qkww8.prod.google.com ([2002:a05:620a:948:b0:7b6:ce2a:2b71]) (user=bgeffon job=prod-delivery.src-stubby-dispatcher) by 2002:a05:620a:4809:b0:7b1:161c:ef58 with SMTP id af79cd13be357-7b6eb487beemr98918985a.28.1733866259591; Tue, 10 Dec 2024 13:30:59 -0800 (PST) Date: Tue, 10 Dec 2024 16:30:45 -0500 Mime-Version: 1.0 X-Mailer: git-send-email 2.47.0.338.g60cca15819-goog Message-ID: <20241210213050.2839638-1-bgeffon@google.com> Subject: [RFC PATCH 0/5] mm: Fix mremap behavior when using addr hints From: Brian Geffon To: Andrew Morton Cc: Lorenzo Stoakes , Jann Horn , Vlastimil Babka , "Liam R. Howlett" , linux-mm@kvack.org, Marco Vanotti , linux-kernel@vger.kernel.org, Brian Geffon X-Stat-Signature: 4za9fy6bnyaswsh9kkksowkbzngmywek X-Rspam-User: X-Rspamd-Queue-Id: 321DF1C001D X-Rspamd-Server: rspam08 X-HE-Tag: 1733866217-959656 X-HE-Meta: U2FsdGVkX18PKJapc6f/NZ11UaOFNCBomVcXNh2tHvzGHjdGboTtZtY0KHWe72vzbtJOV5g5mq1R8gpKtqDLsQ5y5JQKYGa/E/XNQ5toXlbtJYMqEr+VKz4bVHwugE1aGRtclY1eOzLOnGyoj7wgTFIDa0sM7ZUIeynX4KwTQ4uFvZW3/VrTv9PhLs91Q8B+HvaaTHpyUvmbJUwBDiKph7IShUi2JrYxQ3GNS738TgORemDOBEGhxpm3DQ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Q1keegk0oR9q5NIOOBIhcl6aAr32uH3aEqZIgvUbbEfgjIiX8/1HqE8XEzenzw0c83f7exfL9BpDIqBLm2paJLhhwJWndGK7xf7Pkapmmd84CPvbkkV3rD70OV3FqmjAXG21eBnUnS/lF1YYoP/9jg0/Advbi3wpUIL/rc1RWpX9xQK2fYlYdBcu850OtgRM8mzHY1K5aR+ZXvQfApEKsJye43E3rcHKQp1KkJce9T5mIWVfj9WqkofdB+xdqU+cB15zLOog4R8lvB5igP1M+EGNqtSdZmTlpJ/TL8uORn7vaVFE3k7OqxiNaXjJQLu8= X-Bogosity: Ham, tests=bogofilter, spamicity=0.345645, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: When MREMAP_DONTUNMAP was added in e346b38 ("mm/mremap: add MREMAP_DONTUNMAP to mremap()") we inadvertently allows for an address hint to be specified when not using MREMAP_FIXED. This is because mremap(2) with MREMAP_DONTUNMAP it shares a code path with MREMAP_FIXED in mremap_to(), which means this function can be called in 3 different scenarios: MREMAP_FIXED only, MREMAP_DONTUNMAP only, or MREMAP_FIXED | MREMAP_DONTUNMAP. In the second case when only MREMAP_DONTUNMAP the new_addr is passed to get_unmapped_area() which behaves like a hint as it does with mmap(2). Glibc now expects this behavior so it would seem it probably cannot be removed [1]. Additionally, as Jann Horn pointed out Debian apparently has tests for this odd undocumented behavior [2]. This series attempts to reconcile this situation. Patch 1: Will fix the checks that should only apply to the MREMAP_FIXED case, so that they don't apply to just MREMAP_MAYMOVE. Patch 2: Addresses an actual bug where we can allow a hint which is lower than the mmap_min_addr. Patch 3: Since we're stuck with this behavior we might as well support it for mremap(2) when MREMAP_MAYMOVE is specified. Patch 4: Self tests for patch 1 Patch 5: Self tests for patch 3 I will mail man page updates once we finalize on the behavior for mremap(2). 1. https://sourceware.org/git/?p=glibc.git;a=commit;h=6c40cb0e9f893d49dc7caee580a055de53562206 2. https://sources.debian.org/src/glibc/2.40-4/debian/patches/git-updates.diff/?hl=22820#L22818 Brian Geffon (5): mm: mremap: Fix new_addr being used as a hint with MREMAP_DONTUNMAP mm: mremap: Use round_hint_to_min() for new_addr hints mm: mremap: Allow new_addr to be specified as a hint selftests: mm: Add a new MREMAP_DONTUNMAP self test selftests: mm: Add selftest for new_addr hint with MREMAP_MAYMOVE. include/linux/mm_inline.h | 14 +++ mm/mmap.c | 13 -- mm/mremap.c | 34 ++++-- tools/testing/selftests/mm/mremap_dontunmap.c | 41 ++++++- tools/testing/selftests/mm/mremap_test.c | 113 +++++++++++++++++- 5 files changed, 189 insertions(+), 26 deletions(-)