From patchwork Wed Aug 28 05:49:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charlie Jenkins X-Patchwork-Id: 13780622 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 BA2AFC5474E for ; Wed, 28 Aug 2024 05:49:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 32D0F6B0093; Wed, 28 Aug 2024 01:49:44 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2DCB16B0095; Wed, 28 Aug 2024 01:49:44 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 156E66B0096; Wed, 28 Aug 2024 01:49:44 -0400 (EDT) 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 ECE926B0093 for ; Wed, 28 Aug 2024 01:49:43 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 763FE141CF1 for ; Wed, 28 Aug 2024 05:49:43 +0000 (UTC) X-FDA: 82500577446.17.3E55809 Received: from mail-pf1-f176.google.com (mail-pf1-f176.google.com [209.85.210.176]) by imf11.hostedemail.com (Postfix) with ESMTP id 6BE9640006 for ; Wed, 28 Aug 2024 05:49:41 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=VwM0UOSr; spf=pass (imf11.hostedemail.com: domain of charlie@rivosinc.com designates 209.85.210.176 as permitted sender) smtp.mailfrom=charlie@rivosinc.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1724824094; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=g+f5iieqZfHqFwlVhHOpYZvOeyZcJe//7AT/XT4juc0=; b=vjRXd7rz0JM3s5YB0HRyxMx1Fv3BliF2ObYo7rKi0EsvdsSHtQaLBAQz3E9O9RMooeykFv Sofl5oluQOvAc2pBoGnGnpWp2acDUwmZzDuq+XfnhY67Q7EfCVfBwOzf7xiS402YMa7JvF N+Spq1q6zE2r03LP+8HwlVGVsrLagrs= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724824094; a=rsa-sha256; cv=none; b=O51P5i/JsjUKaiGiB5xPpKGNhbEkSFOjvQKRMpfj0hjp7OaSr909yX7I9PLbG8m7zgLDyF dK1zMT/eTKXrbGglRWr1P+aVJMPcFAr2i7ilVH68Ypl5fu1O1vg8Ou9yMSF3ghU3fXNShE c67MHK+QrWAINTXdDud1p8ly0MmtkIg= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=VwM0UOSr; spf=pass (imf11.hostedemail.com: domain of charlie@rivosinc.com designates 209.85.210.176 as permitted sender) smtp.mailfrom=charlie@rivosinc.com; dmarc=none Received: by mail-pf1-f176.google.com with SMTP id d2e1a72fcca58-7141d7b270dso4851312b3a.2 for ; Tue, 27 Aug 2024 22:49:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1724824180; x=1725428980; darn=kvack.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=g+f5iieqZfHqFwlVhHOpYZvOeyZcJe//7AT/XT4juc0=; b=VwM0UOSrbPhfyDksylqodnvRjlEj31NlduKkgxwBrMsyzoMvOvXN7gdDI4mzNNiyAo wixaHGTDstyigOITXATp//nNynAo4GT3cWyTIdRRvBGticMWuxjDQ+DgPCOyhQUW2XCP zL5o4ldnvTdMyzT+xuGedWvrdbIreiEYjKZ330UNmAZdek/VHZuzFM9UC26n4AvZ+bZH gvcs9tTXBOrzVlBCq47i8aJV1fAIcPHH96Elf4a1RT8C0cBMjc51zbwPAeCnPjghD/v1 4oaPTlHo93UxFtAY2qPyGkJsUjekkjYoD9r+ypGoo4oia7aJQ6rlBDixuez4orFDpE4L Bfqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724824180; x=1725428980; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=g+f5iieqZfHqFwlVhHOpYZvOeyZcJe//7AT/XT4juc0=; b=vqjzO9cQXwKMQe1fQoCeBLwxDvEACBC1ZUFVcSOx1mW3+xUkAM+iWByDNlaTeqwP/B VY4KlmS8xqXrkZrOfjaPbE0PF6HzOUqOU4BABygebP7YvZah8lucvkN+DlCAD92vzthN sCnWqAxuFoN2ssSPBXKM7SOtRvs63YqPkdP0JBUsWlHbGreueF8pjL9puMcnsN80BF/8 Ws9Gw6b4eF8na5Ra5epEgZlJEHmZncME1TG99X6vLgfly6P/bcVGMsHbPIQllxgYISxM HG37CN0Sm38PoKg7gUou3nioi+cs4XRKBl2vHEFVOi2v1F/7P6LLDUzMXpwe3KZIyuuH /MDg== X-Forwarded-Encrypted: i=1; AJvYcCWp6dwoKRegjehSBG2FTYIijYiEd4IiaNZ3JAqe+CdKl+9WTHhclfl2ciwVk1qX2jpzrF4Wne6wvA==@kvack.org X-Gm-Message-State: AOJu0Yw43lQgjVqnEh7z8iiL8iz1ziJq6bvdzKu+i26qN8seCDEmSMZE JG/RciEkiEs75qPjQnhA5PF8iVA9MrRPybyxJMcuLkfhIQKGfoyndIZoZn2oiww= X-Google-Smtp-Source: AGHT+IGKYEbmAbccdwLglj8Rtz7Ncms8BNc+Vjhrih2XUvI/cV2bfefpghFryVXCiPvCQUUiKdRNjQ== X-Received: by 2002:a05:6a21:3401:b0:1c6:a777:4cfa with SMTP id adf61e73a8af0-1cc8b475035mr13030363637.13.1724824179851; Tue, 27 Aug 2024 22:49:39 -0700 (PDT) Received: from charlie.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-203855df0c4sm92092495ad.157.2024.08.27.22.49.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Aug 2024 22:49:39 -0700 (PDT) From: Charlie Jenkins Date: Tue, 27 Aug 2024 22:49:10 -0700 Subject: [PATCH 04/16] mm: Add generic MAP_BELOW_HINT MIME-Version: 1.0 Message-Id: <20240827-patches-below_hint_mmap-v1-4-46ff2eb9022d@rivosinc.com> References: <20240827-patches-below_hint_mmap-v1-0-46ff2eb9022d@rivosinc.com> In-Reply-To: <20240827-patches-below_hint_mmap-v1-0-46ff2eb9022d@rivosinc.com> To: Arnd Bergmann , Paul Walmsley , Palmer Dabbelt , Albert Ou , Catalin Marinas , Will Deacon , Michael Ellerman , Nicholas Piggin , Christophe Leroy , Naveen N Rao , Muchun Song , Andrew Morton , "Liam R. Howlett" , Vlastimil Babka , Lorenzo Stoakes , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Huacai Chen , WANG Xuerui , Russell King , Thomas Bogendoerfer , "James E.J. Bottomley" , Helge Deller , Alexander Gordeev , Gerald Schaefer , Heiko Carstens , Vasily Gorbik , Christian Borntraeger , Sven Schnelle , Yoshinori Sato , Rich Felker , John Paul Adrian Glaubitz , "David S. Miller" , Andreas Larsson , Shuah Khan , Alexandre Ghiti Cc: linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, Palmer Dabbelt , linux-riscv@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linuxppc-dev@lists.ozlabs.org, linux-mm@kvack.org, loongarch@lists.linux.dev, linux-mips@vger.kernel.org, linux-parisc@vger.kernel.org, linux-s390@vger.kernel.org, linux-sh@vger.kernel.org, sparclinux@vger.kernel.org, linux-kselftest@vger.kernel.org, Charlie Jenkins X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2165; i=charlie@rivosinc.com; h=from:subject:message-id; bh=+G9/grHdHxL6H0Lnh65S6ISh5epJb2mrAov/AP0hs9c=; b=owGbwMvMwCHWx5hUnlvL8Y3xtFoSQ9q5XXGZXkeVtgeold2b3dqjkt+vEXMu6H6oc1bJNYtbJ 3aetlzTUcrCIMbBICumyMJzrYG59Y5+2VHRsgkwc1iZQIYwcHEKwERWFTEyNKap9S5rOHHkFBPT SkUp8yq1Cd/4ljyftDBFnmW663I5b4Z/RluSpK/6drw7JD8vOuPN75znwc73OQp/v/2R9GK2Tfl mPgA= X-Developer-Key: i=charlie@rivosinc.com; a=openpgp; fpr=7D834FF11B1D8387E61C776FFB10D1F27D6B1354 X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 6BE9640006 X-Stat-Signature: 9xrqjbyy85r3aisdt9uy4osrg56mpziw X-HE-Tag: 1724824181-658656 X-HE-Meta: U2FsdGVkX1+o7lvWxXlUdLhaDJLguY1SUPIi87DoHCkjTq1kcL+sTuVfSLt+Ths977UjwZGr/mAd8o6fuAiy5hg5DFXXutnJBfAGjkC+BSh25wSZjOSHGYNRoDGoS9TpGJ3Jh021Gbd02bb56WmkFY3466I4+6wCnQQ1aZjDs6fwgWmG7MSHNXBbI19sFdEE4Fj5dX5kapOS27poHaPnkrnDHhhVE+P42MwaRW3JnVqWuj3/PtX2zPj7SWEHP+Yhd7LXtu0pgWHFm/4gwaegyqMAFTAzu/rCSaMbmb1De5NnZ6CnUCnctiwMLyK49DtV1peXLBo/P3ubnRDmpu5xWsF2+sa/raq763CBAkJtmF7PDKkDIt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+zL0Cx+3vNA== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000001, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Make the generic implementation of arch_get_mmap_base() and arch_get_mmap_end() support MAP_BELOW_HINT. Signed-off-by: Charlie Jenkins --- include/linux/sched/mm.h | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/include/linux/sched/mm.h b/include/linux/sched/mm.h index 265b43855d0b..c350bb5ac0a2 100644 --- a/include/linux/sched/mm.h +++ b/include/linux/sched/mm.h @@ -9,6 +9,7 @@ #include #include #include +#include /* * Routines for handling mm_structs @@ -170,11 +171,40 @@ static inline void mm_update_next_owner(struct mm_struct *mm) #ifdef CONFIG_MMU #ifndef arch_get_mmap_end -#define arch_get_mmap_end(addr, len, flags) (TASK_SIZE) +#define arch_get_mmap_end(addr, len, flags) \ +({ \ + unsigned long mmap_end; \ + typeof(flags) _flags = (flags); \ + typeof(addr) _addr = (addr); \ + typeof(len) _len = (len); \ + mmap_end = TASK_SIZE; \ + if (_flags & MAP_BELOW_HINT && _addr != 0) \ + mmap_end = MIN(mmap_end, _addr + _len); \ + mmap_end; \ +}) #endif #ifndef arch_get_mmap_base -#define arch_get_mmap_base(addr, len, base, flags) (base) +/* + * rnd_gap is defined to be (STACK_TOP - _base) due to the definition of + * mmap_base in mm/util.c + * + * Assumes ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT, which all architectures that + * implement generic mmap use + */ +#define arch_get_mmap_base(addr, len, base, flags) \ +({ \ + unsigned long mmap_base; \ + typeof(flags) _flags = (flags); \ + typeof(addr) _addr = (addr); \ + typeof(base) _base = (base); \ + typeof(len) _len = (len); \ + unsigned long rnd_gap = STACK_TOP - _base; \ + mmap_base = _base; \ + if (_flags & MAP_BELOW_HINT && _addr != 0) \ + mmap_base = MIN(mmap_base, (_addr + _len) - rnd_gap); \ + mmap_base; \ +}) #endif extern void arch_pick_mmap_layout(struct mm_struct *mm,