From patchwork Tue Dec 10 21:30:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brian Geffon X-Patchwork-Id: 13902095 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 2573FE7717F for ; Tue, 10 Dec 2024 21:31:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 515618D0014; Tue, 10 Dec 2024 16:31:05 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 4A0568D000B; Tue, 10 Dec 2024 16:31:05 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2F2988D0014; Tue, 10 Dec 2024 16:31:05 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 0BE678D000B for ; Tue, 10 Dec 2024 16:31:05 -0500 (EST) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id A7B21120EF1 for ; Tue, 10 Dec 2024 21:31:04 +0000 (UTC) X-FDA: 82880344302.15.B47D6C4 Received: from mail-qt1-f201.google.com (mail-qt1-f201.google.com [209.85.160.201]) by imf26.hostedemail.com (Postfix) with ESMTP id A5CE4140007 for ; Tue, 10 Dec 2024 21:30:45 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b="BXS5c/pG"; spf=pass (imf26.hostedemail.com: domain of 3FbNYZwcKCCA7CABBKJCKKCHA.8KIHEJQT-IIGR68G.KNC@flex--bgeffon.bounces.google.com designates 209.85.160.201 as permitted sender) smtp.mailfrom=3FbNYZwcKCCA7CABBKJCKKCHA.8KIHEJQT-IIGR68G.KNC@flex--bgeffon.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=1733866247; 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:in-reply-to:references:references:dkim-signature; bh=G32JxFMabBUDQi+52by10jYMucvOr3O4hJ3hDDPHLcQ=; b=fcy6LCuyg7gwa+XtjXRMHHWA3uoPGxsid5Q32w5lvCr4XM94MkCrXP73m+fhrI9fX63ST5 Oyf37sR95lb+2A3z/mXhbbvCRMrtXcpgkr9pjp3U0byhJ7Y4ZCL9FCJjSl+gUFBvysuoTl Cor/pP+87KlQV2ykuHJOUQfCdI3Ytss= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1733866247; a=rsa-sha256; cv=none; b=Zzy2V//TQOgM8QQbpXvV/TxfdV+54ep5kjhQJGH3hfP5m/by9aKGUf4xf41zn7gl1xIHkP vlTS0zxLX3oQPY/YyM1J+blZkWVxxAwtWg68ZeU1HpPUSI6nC6ywn12Pz2Esnv+diBV/Ec Y+CXJyQo/nKW/VH3A8EJ/lhofWher5k= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b="BXS5c/pG"; spf=pass (imf26.hostedemail.com: domain of 3FbNYZwcKCCA7CABBKJCKKCHA.8KIHEJQT-IIGR68G.KNC@flex--bgeffon.bounces.google.com designates 209.85.160.201 as permitted sender) smtp.mailfrom=3FbNYZwcKCCA7CABBKJCKKCHA.8KIHEJQT-IIGR68G.KNC@flex--bgeffon.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com Received: by mail-qt1-f201.google.com with SMTP id d75a77b69052e-46752894cb6so70963081cf.1 for ; Tue, 10 Dec 2024 13:31:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1733866262; x=1734471062; darn=kvack.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=G32JxFMabBUDQi+52by10jYMucvOr3O4hJ3hDDPHLcQ=; b=BXS5c/pGRyy2sFfBBQBywhWRnBEvDpHmQaSuWyxyU69R2s9rN+d8Yqh33ZuVh9fSKT ZoS+pJB+AbvAjMOWSvX2YSY5DKEJRsNwtYe939jVFwVL69sQ5OupSyOso2VrweAZr0yw dHawsqPr7cITSdMiLOSEhzu3a9J36QDmnm5fdWXFo8hUy34PR+oT944sUa4UiWJ/Jgzh SBO9HEQH0+cnKzVvOxStAabvkAeiAI4se3qIlAb28/+cijAQK84xTUfUoLjreE7mkiYs ObWJp8+j6OtnKEkI/TJU2CvI8kyOjF01h+bApZAzc/tXLTaf//84yA1Uv/7oz9HVPimo Xh6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733866262; x=1734471062; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=G32JxFMabBUDQi+52by10jYMucvOr3O4hJ3hDDPHLcQ=; b=ma8ArjCwPx+usT5jiH+6myhLWXltvBNlRZJd5DHgnsun8xpIcrFMyGy2niyjsP00nB KtbP5qIuhfpwRjA0BMB7OzePIXN1pXfzUW2ZhsdC9z5R0dJQ6c4j+IAiO0Ma9Vxq3iTc 9c7uSosxX5xvsItB4IJiChpVjVU5iF+EW9ChK1L48h5AOHbq573aYm4ldCiEjGnqRuwS GlA9dvpzxUfce21drZXL3LNGfXrKJZlII/jasKqGVtfmUbi/bRaIxrCwjzjvFL30NKrx XURGGpsjk9BG4hgRSRVuP5RFkP1goyTRkXrzR8iXCwax2YCX8LpnNcQCTf3T97vi3dwL akDQ== X-Forwarded-Encrypted: i=1; AJvYcCXwJfGTidr3mmtmWllhRcg5smxD6WBUEGaF9w8KvGmWQzKMt/mObssBxU9EPDzbJrMEYHFWowXtow==@kvack.org X-Gm-Message-State: AOJu0YyDLHVMRnTXncsphvsz7kffRw3OkY3myC6RE8hCn9BpAILV6YUk TmTXkv7WZqWS8E+FDGz2wN2iA9gRN0dWEZtoRag82S3BWurKXgDqd7wi/WT+CwbCnxD1ZYBkLR6 BOuDu2w== X-Google-Smtp-Source: AGHT+IEpCtrL8H1FFUbminr4KvNlPmZTmCfZCaR3pkbbEKhlEMHUlCB45RdOMbWWkvCARQTAtmkhm4ng8J34 X-Received: from qtbbn6.prod.google.com ([2002:a05:622a:1dc6:b0:467:7fcc:751e]) (user=bgeffon job=prod-delivery.src-stubby-dispatcher) by 2002:ac8:7f93:0:b0:466:b1fb:3028 with SMTP id d75a77b69052e-467892e9a98mr7952001cf.4.1733866261754; Tue, 10 Dec 2024 13:31:01 -0800 (PST) Date: Tue, 10 Dec 2024 16:30:47 -0500 In-Reply-To: <20241210213050.2839638-1-bgeffon@google.com> Mime-Version: 1.0 References: <20241210213050.2839638-1-bgeffon@google.com> X-Mailer: git-send-email 2.47.0.338.g60cca15819-goog Message-ID: <20241210213050.2839638-3-bgeffon@google.com> Subject: [RFC PATCH 2/5] mm: mremap: Use round_hint_to_min() for new_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-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: A5CE4140007 X-Stat-Signature: 8jgzd8bbn48crwq57crtei9rthfmh89q X-Rspam-User: X-HE-Tag: 1733866245-762033 X-HE-Meta: U2FsdGVkX18Aqn++MlUG3Ec0SZom5tbDPmzG72bKINTfzTxOVorDRP/1yggynPDeXTdu6fc9Ffb96PS+eHugIgIRYuHCTh9UEEOS4fcCx55Y9bRB84LlFwezVMv0ktpEuqBn8yxEdi9l3FwCDUoHnC74VuTCM1L1FsN/BbjazVKSLxvPGr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sE/IWz4HnXfMvO4J3vZIw7R6cNV6wzvQRctuqXq/lpMA5xzNaaVZbrTpiuJZgm0OT1kII3kJguA/ifpeOJZ9ASaT2TsgCJndz85aqNznNJjXP8KE9yrKoSubSEp5vaTOY/nCPj7fizIoMcLpSvLqCxhSnBnVbhJGPCyPVX2g5pVMyhx+Sk+wL50UcR5UzjSrq7Ts+rW/NznA3NfPyPyK7XcQ/8rf/kd9FkYy116b0BYZKXrtfaVOsp8b2NFKKKIYDYOnqx0e4Vf7gg3XZ7Aq2w3wpBxDxfyIGsRHYDiyxXjpB/X7pndp/Q7RN2vhoKr+YVCgPhJCqfYJiERPSQ9b1OVrwl X-Bogosity: Ham, tests=bogofilter, spamicity=0.009608, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: MREMAP_DONTUNMAP allows for a get_unmapped_area() hint when used without MREMAP_FIXED. This was behavior was introduced inadvertently and should be rounded to the mmap_min_address like in mmap(2). Signed-off-by: Brian Geffon --- include/linux/mm_inline.h | 14 ++++++++++++++ mm/mmap.c | 13 ------------- mm/mremap.c | 3 +++ 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/include/linux/mm_inline.h b/include/linux/mm_inline.h index 1b6a917fffa4..863143ec5bb0 100644 --- a/include/linux/mm_inline.h +++ b/include/linux/mm_inline.h @@ -9,6 +9,7 @@ #include #include #include +#include /** * folio_is_file_lru - Should the folio be on a file LRU or anon LRU? @@ -613,4 +614,17 @@ static inline bool vma_has_recency(struct vm_area_struct *vma) return true; } +/* + * If a hint addr is less than mmap_min_addr change hint to be as + * low as possible but still greater than mmap_min_addr + */ +static inline unsigned long round_hint_to_min(unsigned long hint) +{ + hint &= PAGE_MASK; + if (((void *)hint != NULL) && + (hint < mmap_min_addr)) + return PAGE_ALIGN(mmap_min_addr); + return hint; +} + #endif diff --git a/mm/mmap.c b/mm/mmap.c index d32b7e701058..04952ac21d58 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -215,19 +215,6 @@ SYSCALL_DEFINE1(brk, unsigned long, brk) return origbrk; } -/* - * If a hint addr is less than mmap_min_addr change hint to be as - * low as possible but still greater than mmap_min_addr - */ -static inline unsigned long round_hint_to_min(unsigned long hint) -{ - hint &= PAGE_MASK; - if (((void *)hint != NULL) && - (hint < mmap_min_addr)) - return PAGE_ALIGN(mmap_min_addr); - return hint; -} - bool mlock_future_ok(struct mm_struct *mm, unsigned long flags, unsigned long bytes) { diff --git a/mm/mremap.c b/mm/mremap.c index 62aec72bbe42..fdc1b0f1b38e 100644 --- a/mm/mremap.c +++ b/mm/mremap.c @@ -1109,6 +1109,9 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len, goto out; } + if (!(flags & MREMAP_FIXED)) + new_addr = round_hint_to_min(new_addr); + if (flags & (MREMAP_FIXED | MREMAP_DONTUNMAP)) { ret = mremap_to(addr, old_len, new_addr, new_len, &locked, flags, &uf, &uf_unmap_early,