From mboxrd@z Thu Jan 1 00:00:00 1970 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 46B55EE57FC for ; Thu, 12 Sep 2024 01:06:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A43E46B00B2; Wed, 11 Sep 2024 21:06:06 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9F54E6B00B4; Wed, 11 Sep 2024 21:06:06 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8BC8F6B00B6; Wed, 11 Sep 2024 21:06:06 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 690356B00B2 for ; Wed, 11 Sep 2024 21:06:06 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id BF68F402E1 for ; Thu, 12 Sep 2024 01:06:05 +0000 (UTC) X-FDA: 82554294690.02.66038F5 Received: from mail-ej1-f53.google.com (mail-ej1-f53.google.com [209.85.218.53]) by imf24.hostedemail.com (Postfix) with ESMTP id E2EAA180002 for ; Thu, 12 Sep 2024 01:06:03 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=aqioGMwk; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf24.hostedemail.com: domain of shy828301@gmail.com designates 209.85.218.53 as permitted sender) smtp.mailfrom=shy828301@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1726103047; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to: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=FrZwj4wQdjgaXXXSNnDTmsMPVIiHBnnCTDIjF/U8aa4=; b=eYd/H9FSRhlTDFShzp4g/m2AOofKkJhOrhCx3UrjtcUqOxFGNUFTALpy91gfPToFPlsBMc OsSkDc6ziy7zzeshpvPyM0qBya50uv2hQUIhpFKq7ON8mmWg+RhQCrzfmzG8Qh7YaJVK9m MYUrDglhiDsOmfRbPdU+3e7SO7cZyi8= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1726103047; a=rsa-sha256; cv=none; b=PNxy7MaS6KcHnXP+ya1GTATb5rxPlTMSrZ+HzirKz4y31wUxf9ce8aJBR3EbGKVF6I0UuI KK0goX4SCnWULxK1KSTYWwr9/T26y2pltBABUPNLuGtM3bcSkBh8KRJVRUtFWZc7eXZwwQ QkUJ+e6aBvOMm+GR0oP5TN5JTO9Hw2U= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=aqioGMwk; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf24.hostedemail.com: domain of shy828301@gmail.com designates 209.85.218.53 as permitted sender) smtp.mailfrom=shy828301@gmail.com Received: by mail-ej1-f53.google.com with SMTP id a640c23a62f3a-a8d2b24b7a8so289509466b.1 for ; Wed, 11 Sep 2024 18:06:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1726103162; x=1726707962; darn=kvack.org; h=content-transfer-encoding:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=FrZwj4wQdjgaXXXSNnDTmsMPVIiHBnnCTDIjF/U8aa4=; b=aqioGMwkZdK2fpIfTHepSvAz7xjP/4xm1XoZvba80/TZqurWDVfOMSNSJQLUX3tT+p 3CCR5uZijZTtdeFZ5CTslQyf2BwTEsY0p2IZI3a2wtwUN7yPHhKzQV4QCksNj4mtbu6r S+9KGmz0xBRC7NMYdM/xWvxdrfQVExNiSpDSl7tTRNlpo0x4jwxGzuSwW6mnKRZIa17R wg0nDuAWbyMqNRcCZpMlJuwpFlP4IiPMsD21H1aN35ukx/mBBnoxjc3IlMDyhMCc+QRZ lGvHljC6Fkm3iCbGJRggIFfnYtpQ3sHbDMbavqiHr3g/pJtt0UvTi+dGxDVmfUFYpyvv mk8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726103162; x=1726707962; h=content-transfer-encoding:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=FrZwj4wQdjgaXXXSNnDTmsMPVIiHBnnCTDIjF/U8aa4=; b=LQR29+5CRGO+mWm3ohPEMacLW7E1/Dc7gYNi9oysHXX5B5Kw/W80rVrvWV2+Rhf9SB DZlXiVQcYunYOqcDbs8g7RLENLTW7aYtUWVN3fgtD6woi8siVSPrYTDaNMDlWXlWwesw abjm0a6ZpwG8nIYoYCUsm/h4WPBWnJp+pnY7DGwv+UoxdqQiuGUY4usR6aQ9UhctCxsU UQFdZVhNToRstjDQWws6PlPr17DvlY4gPkduu0UyOPhFA5YRfMyOr3fMhLmIkrFa2bHS 5SUABht77leEWY8ISCua2M5YPf/gWBrBxRqT0PeA+hYbn1abSH/jlh4gyS0MxgTDZ1E0 PC9g== X-Forwarded-Encrypted: i=1; AJvYcCUSYvm4S1yIfAifPQojeDwNJYB5XwD6n/Y2W0c2WMcp9fjouGdFoZDRR67/YU0Lt7BBB5HmXpPlog==@kvack.org X-Gm-Message-State: AOJu0YwtEmCEGwqanGquPk06XDebsPZB6m3tscP614yfnc5AcIe9Z7ws FXnQDeal7gOy0/pn9FNyiChvHJa9ngYZ4yr4iLmKHZOlU7CtNZOcPPXm6Tt8KtO7wOpDgIXAwka 8xZFHM8WVuUPXUyNdS5Q9cdXjYnyjsA== X-Google-Smtp-Source: AGHT+IFU3z5geBinTSVxuibVuYzAD6NH0xoQrh/U/I2MD9xbSObBDDyYKTBsRbWAhk2LIf++Ez/EA1zfetUS77u2J8c= X-Received: by 2002:a17:906:6a19:b0:a8d:ee9:3888 with SMTP id a640c23a62f3a-a8ffae3b788mr568705366b.32.1726103162059; Wed, 11 Sep 2024 18:06:02 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Yang Shi Date: Wed, 11 Sep 2024 18:05:50 -0700 Message-ID: Subject: Re: [PATCH] [RFC] mm: mmap: Allow mmap(MAP_STACK) to map growable stack To: "Liam R. Howlett" , Yang Shi , Helge Deller , linux-kernel@vger.kernel.org, Andrew Morton , linux-mm@kvack.org, linux-parisc@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: E2EAA180002 X-Stat-Signature: siuhucogdt1o9f43fhxkqgri47ny49s6 X-Rspam-User: X-HE-Tag: 1726103163-202537 X-HE-Meta: U2FsdGVkX1/RfoqvIg6Jrk5uQdIVCzwodiMBOgcR8fGgF4CVB49IopkGzQXtmS68xycTiP+jWBIl/XHevssLuBcmToLtJyd6SLDxAEc+olsEMxQxLIZk8244PlAauwNVNBV9/fkWdFyy5LHWPBIjqW9+oWo7c7+XUZho09JxhfPTtm5lnwP3J5UNZWnd0bMtcFSygBdVubSI9hM6Ep8yIfjPwjnNUWcbyhVyDr53B11qCCu/U1aWy25u95cCgvkBBlUn2io3bN6V0ESj6zcSLYa9sjx5yJO845/ZcWqtepM0v8ol8K17iTYlIG/0WVX36z0GazzxygSvUTdiNdfLHSQS5AyNyOV1UEMQ/ZoTnkS4Oha74BR6knaG+Iy8PxQE9mZD8+fWQbhPYZxQDSIkCTI1LEXonHVjW6PaxMn6KKFrj/7eMwdLhu81EQEc20IWtf8+ZCEwq/5lml4aQCWsu3yevdX0CUlJt+xcTuyCJmy7U5BJrYLOk9jC0FL7yBRScGlJm4vJf+0M413ePOlvgaoGWpE7u3OFidio3iySgaZYVR+Dj3u8u2+6ctMUWBNIgF4fpWQY5rf7VbJIJhKhXKBiEN8S0CNs9cGI49fWpQ9nG3fcAR3ShjeXYtB7qDh0Gtw3Ept4G6tc2lstkDFcSddN92ryqQ35c10H78rEdvDLxNhWlTFVJuxdKpYoBQ298xc+wHNVV7a5xwFRj6HtQRiJL2+1uIknQMi9hp2VL0gjXJcldMWrwgLJNrwA+qpDyMBCpcgmkH34DHE6mm5vQmQmLMx/SJ7R6UaE+Ljp8q/UTHjMeBHcKKkuUm3sOTcz8uu93D3duuq0gQpltg/ybESr6/op0NIlt+69N0JI1g/StWW7WsX3/Ku3PnS6rcTrC7EmOSyYLPHXHa54TRTdsqQWwhhH0AmR3zsa6U+BUT7oUkL5uSlF3HZWeiWOgeCg8ykUsSUruZQlrHCY+NK BhT7AS23 oi/tnO4yd5MzRhmK73t5ib1sJhB7mUz+Nqbvt9/zuOgMle4XtQPg2eM9cov0jiy5Ouk5/nrPdNMVbKrkbCgTRTsdJxACSaw8ih++ijYb0zJwgAJZ2p3LHtraCONbEAp0+Mig6NhaW3vKPpqmPwElxnLyigGyy+l0FaDL8+g7tI7eA4e2RcHU8H8P8+JRmEiCx/8K8VDNorOvbRq1B1Vs03YMsdET6kslQK7gZ2Qc++wt5h/CDZ4gaITrmY9kIOyohMO39ltjk2aH9+K4zhye6uT7kzr3IiD3+qUNiNXOu19/6eF2OSMV8l8rVPvdk/CzCCqV01jorAZVelQB4Grq1C5BXBHWsXj9nga6PcvbkSQ9e/yqYf/Qf7j0gIEKPSbnWz0KkX7LdK+5rF2LC4yMfIhWbsPUdJ2aO8Sw6eOQlQiAgVnHWdKcgiPDnOQ== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Wed, Sep 11, 2024 at 4:05=E2=80=AFPM Liam R. Howlett wrote: > > * Yang Shi [240911 18:16]: > > On Wed, Sep 11, 2024 at 12:49=E2=80=AFPM Liam R. Howlett > > wrote: > > > > > > * Helge Deller [240911 15:20]: > > > > This is a RFC to change the behaviour of mmap(MAP_STACK) to be > > > > sufficient to map memory for usage as stack on all architectures. > > > > Currently MAP_STACK is a no-op on Linux, and instead MAP_GROWSDOWN > > > > has to be used. > > > > To clarify, here is the relevant info from the mmap() man page: > > > > > > > > MAP_GROWSDOWN > > > > This flag is used for stacks. It indicates to the kernel virtual > > > > memory system that the mapping should extend downward in memory.= The > > > > return address is one page lower than the memory area that is > > > > actually created in the process's virtual address space. Touchi= ng an > > > > address in the "guard" page below the mapping will cause the map= ping > > > > to grow by a page. This growth can be repeated until the mapping > > > > grows to within a page of the high end of the next lower mapping= , > > > > at which point touching the "guard" page will result in a SIGSEG= V > > > > signal. > > > > > > > > MAP_STACK (since Linux 2.6.27) > > > > Allocate the mapping at an address suitable for a process or thr= ead > > > > stack. > > > > > > > > This flag is currently a no-op on Linux. However, by employing t= his > > > > flag, applications can ensure that they transparently obtain sup= port > > > > if the flag is implemented in the future. Thus, it is used in th= e > > > > glibc threading implementation to allow for the fact that > > > > some architectures may (later) require special treatment for > > > > stack allocations. A further reason to employ this flag is > > > > portability: MAP_STACK exists (and has an effect) on some > > > > other systems (e.g., some of the BSDs). > > > > > > > > The reason to suggest this change is, that on the parisc architectu= re the > > > > stack grows upwards. As such, using solely the MAP_GROWSDOWN flag w= ill not > > > > work. Note that there exists no MAP_GROWSUP flag. > > > > By changing the behaviour of MAP_STACK to mark the memory area with= the > > > > VM_STACK bit (which is VM_GROWSUP or VM_GROWSDOWN depending on the > > > > architecture) the MAP_STACK flag does exactly what people would exp= ect on > > > > all platforms. > > > > > > > > This change should have no negative side-effect, as all code which > > > > used mmap(MAP_GROWSDOWN | MAP_STACK) still work as before. > > > > > > > > Signed-off-by: Helge Deller > > > > > > > > diff --git a/include/linux/mman.h b/include/linux/mman.h > > > > index bcb201ab7a41..66bc72a0cb19 100644 > > > > --- a/include/linux/mman.h > > > > +++ b/include/linux/mman.h > > > > @@ -156,6 +156,7 @@ calc_vm_flag_bits(unsigned long flags) > > > > return _calc_vm_trans(flags, MAP_GROWSDOWN, VM_GROWSDOWN ) | > > > > _calc_vm_trans(flags, MAP_LOCKED, VM_LOCKED ) | > > > > _calc_vm_trans(flags, MAP_SYNC, VM_SYNC ) | > > > > + _calc_vm_trans(flags, MAP_STACK, VM_STACK ) | > > > > > > Right now MAP_STACK can be used to set VM_NOHUGEPAGE, but this will > > > change the user interface to create a vma that will grow. I'm not > > > entirely sure this is okay? > > > > AFAICT, I don't see this is a problem. Currently huge page also skips > > the VMAs with VM_GROWS* flags set. See vma_is_temporary_stack(). > > __thp_vma_allowable_orders() returns 0 if the vma is a temporary > > stack. > > If someone is using MAP_STACK to avoid having a huge page, they will > also get a mapping that grows - which is different than what happens > today. Yes, I agree. My point is no huge page + grow is fine. > > I'm not saying that's right, but someone could be abusing the existing > flag and this will change the behaviour. If you mean we will have more grow mapping but they are actually unnecessary, then I agree someone could abuse the flag. > > > > > > > > > > > > That is mmap(MAP_STACK) would set VM_NOHUGEPAGE right now, with this > > > change you'd get VM_NOHUGEPAGE | VM_GROWS > > > > > > > _calc_vm_trans(flags, MAP_STACK, VM_NOHUGEPAGE) | > > > > arch_calc_vm_flag_bits(flags); > > > > } > > > > > > >