From nobody Thu Jul 20 18:09:26 2023 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4R6LLK2DRLz4nhQ0; Thu, 20 Jul 2023 18:09:29 +0000 (UTC) (envelope-from cy.schubert@cschubert.com) Received: from omta001.cacentral1.a.cloudfilter.net (omta001.cacentral1.a.cloudfilter.net [3.97.99.32]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "Client", Issuer "CA" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4R6LLK1cXgz3mC4; Thu, 20 Jul 2023 18:09:29 +0000 (UTC) (envelope-from cy.schubert@cschubert.com) Authentication-Results: mx1.freebsd.org; none Received: from shw-obgw-4002a.ext.cloudfilter.net ([10.228.9.250]) by cmsmtp with ESMTP id MOdFqfnXuLAoIMY5gqcCod; Thu, 20 Jul 2023 18:09:28 +0000 Received: from spqr.komquats.com ([70.66.152.170]) by cmsmtp with ESMTPA id MY5eqHGq1yAOeMY5fq8GAY; Thu, 20 Jul 2023 18:09:28 +0000 X-Authority-Analysis: v=2.4 cv=e5oV9Il/ c=1 sm=1 tr=0 ts=64b97858 a=y8EK/9tc/U6QY+pUhnbtgQ==:117 a=y8EK/9tc/U6QY+pUhnbtgQ==:17 a=kj9zAlcOel0A:10 a=ws7JD89P4LkA:10 a=YxBL1-UpAAAA:8 a=6I5d2MoRAAAA:8 a=EkcXrb_YAAAA:8 a=VxmjJ2MpAAAA:8 a=NCkSDawCeJ8rtZbfAdsA:9 a=CjuIK1q_8ugA:10 a=MpzTSJa1xHYA:10 a=8k-k-Cn0ORkA:10 a=Ia-lj3WSrqcvXOmTRaiG:22 a=IjZwj45LgO3ly-622nXo:22 a=LK5xJRSDVpKd5WXXoEvA:22 a=7gXAzLPJhVmCkEl4_tsf:22 Received: from slippy.cwsent.com (slippy [10.1.1.91]) by spqr.komquats.com (Postfix) with ESMTP id 476DF173; Thu, 20 Jul 2023 11:09:26 -0700 (PDT) Received: by slippy.cwsent.com (Postfix, from userid 1000) id 29987BC; Thu, 20 Jul 2023 11:09:26 -0700 (PDT) X-Mailer: exmh version 2.9.0 11/07/2018 with nmh-1.8+dev Reply-to: Cy Schubert From: Cy Schubert X-os: FreeBSD X-Sender: cy@cwsent.com X-URL: http://www.cschubert.com/ To: Cy Schubert cc: Konstantin Belousov , src-committers@freebsd.org, dev-commits-src-all@freebsd.org, dev-commits-src-main@freebsd.org Subject: Re: git: 21e45c30c35c - main - mmap(MAP_STACK): on stack grow, use original protection In-reply-to: <20230720180230.18BDF11F@slippy.cwsent.com> References: <202307201412.36KECDSU084918@gitrepo.freebsd.org> <20230720163231.B1D4277@slippy.cwsent.com> <20230720164145.0CF1311F@slippy.cwsent.com> <20230720170624.B8F28DB@slippy.cwsent.com> <20230720180230.18BDF11F@slippy.cwsent.com> Comments: In-reply-to Cy Schubert message dated "Thu, 20 Jul 2023 11:02:30 -0700." List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Date: Thu, 20 Jul 2023 11:09:26 -0700 Message-Id: <20230720180926.29987BC@slippy.cwsent.com> X-CMAE-Envelope: MS4xfO4JWDjgG6K3S9M0e2kXt2B0vcbRCW/NXNiA0+nl9djz9zp3g6KypH0W5POqJG+SWkgUrUXMZRSX+9RNzvchjoBQZyyhRTP7Exi32GSQS1Unnv8B1rv2 qwQeVLaz48C04HKiO3fdSVSiy8usiScWm7UqdPaeXc2CeekznDb5ViR1Bk33Zh0wfvLrWxxMERyEYSGyjA6IRBS4LR24BCEFl3avu1yrkVdIH5H7U69+fXDh ADpV72wye5GHcocRaqYdrybLPE0Q5F14z4NyA6D/YHwdXJZ/gsv6G2XoCBZ5I2W29X7GgIgVXwS65LAS+B0SsBhpv9OsxSfO47p8JgzNz+0= X-Rspamd-Queue-Id: 4R6LLK1cXgz3mC4 X-Spamd-Bar: ---- X-Spamd-Result: default: False [-4.00 / 15.00]; REPLY(-4.00)[]; ASN(0.00)[asn:16509, ipnet:3.96.0.0/15, country:US] X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated This email appears truncated. My original reply was, Yes, this fixes the screen and pkg regressions. Thanks for the patch. -- Cheers, Cy Schubert FreeBSD UNIX: Web: https://FreeBSD.org NTP: Web: https://nwtime.org e^(i*pi)+1=0 In message <20230720180230.18BDF11F@slippy.cwsent.com>, Cy Schubert writes: > In message , Konstantin Belousov writes: > > On Thu, Jul 20, 2023 at 10:06:24AM -0700, Cy Schubert wrote: > > > In message <20230720164145.0CF1311F@slippy.cwsent.com>, Cy Schubert write > s: > > > > In message <20230720163231.B1D4277@slippy.cwsent.com>, Cy Schubert writ > es > > : > > > > > In message <202307201412.36KECDSU084918@gitrepo.freebsd.org>, Konstan > ti > > n > > > > > Belous > > > > > ov writes: > > > > > > The branch main has been updated by kib: > > > > > > > > > > > > URL: https://cgit.FreeBSD.org/src/commit/?id=21e45c30c35c9aa732073f > 72 > > 5924 > > > > ca > > > > > f5 > > > > > > 81c93460 > > > > > > > > > > > > commit 21e45c30c35c9aa732073f725924caf581c93460 > > > > > > Author: Konstantin Belousov > > > > > > AuthorDate: 2023-07-19 11:05:32 +0000 > > > > > > Commit: Konstantin Belousov > > > > > > CommitDate: 2023-07-20 14:11:42 +0000 > > > > > > > > > > > > mmap(MAP_STACK): on stack grow, use original protection > > > > > > > > > > > > If mprotect(2) changed protection in the bottom of the currentl > y > > grow > > > > n > > > > > > stack region, currently the changed protection would be used fo > r > > the > > > > > > stack grow on next fault. This is arguably unexpected. > > > > > > > > > > > > Store the original protection for the entry at mmap(2) time in > th > > e > > > > > > offset member of the gap vm_map_entry, and use it for protectio > n > > of t > > > > he > > > > > > grown stack region. > > > > > > > > > > > > PR: 272585 > > > > > > Reported by: John F. Carr > > > > > > Reviewed by: alc, markj > > > > > > Sponsored by: The FreeBSD Foundation > > > > > > MFC after: 1 week > > > > > > Differential revision: https://reviews.freebsd.org/D41089 > > > > > > --- > > > > > > sys/vm/vm_map.c | 24 ++++++++++++++++-------- > > > > > > sys/vm/vm_map.h | 4 ++++ > > > > > > 2 files changed, 20 insertions(+), 8 deletions(-) > > > > > > > > > > > > diff --git a/sys/vm/vm_map.c b/sys/vm/vm_map.c > > > > > > index a02107b5e64d..997a49111a59 100644 > > > > > > --- a/sys/vm/vm_map.c > > > > > > +++ b/sys/vm/vm_map.c > > > > > > @@ -4493,7 +4493,7 @@ static int > > > > > > vm_map_stack_locked(vm_map_t map, vm_offset_t addrbos, vm_size_t m > ax > > _ssi > > > > ze > > > > > , > > > > > > vm_size_t growsize, vm_prot_t prot, vm_prot_t max, int cow) > > > > > > { > > > > > > - vm_map_entry_t new_entry, prev_entry; > > > > > > + vm_map_entry_t gap_entry, new_entry, prev_entry; > > > > > > vm_offset_t bot, gap_bot, gap_top, top; > > > > > > vm_size_t init_ssize, sgp; > > > > > > int orient, rv; > > > > > > @@ -4575,11 +4575,14 @@ vm_map_stack_locked(vm_map_t map, vm_offset > _t > > add > > > > rb > > > > > os > > > > > > , vm_size_t max_ssize, > > > > > > * read-ahead logic is never used for it. Re-use > > > > > > * next_read of the gap entry to store > > > > > > * stack_guard_page for vm_map_growstack(). > > > > > > + * Similarly, since a gap cannot have a backing object, > > > > > > + * store the original stack protections in the > > > > > > + * object offset. > > > > > > */ > > > > > > - if (orient == MAP_STACK_GROWS_DOWN) > > > > > > - vm_map_entry_pred(new_entry)->next_read = sgp; > > > > > > - else > > > > > > - vm_map_entry_succ(new_entry)->next_read = sgp; > > > > > > + gap_entry = orient == MAP_STACK_GROWS_DOWN ? > > > > > > + vm_map_entry_pred(new_entry) : vm_map_entry_succ(ne > > w_entry) > > > > > > ; > > > > > > + gap_entry->next_read = sgp; > > > > > > + gap_entry->offset = prot; > > > > > > } else { > > > > > > (void)vm_map_delete(map, bot, top); > > > > > > } > > > > > > @@ -4599,6 +4602,7 @@ vm_map_growstack(vm_map_t map, vm_offset_t ad > dr > > , vm > > > > _m > > > > > ap > > > > > > _entry_t gap_entry) > > > > > > struct ucred *cred; > > > > > > vm_offset_t gap_end, gap_start, grow_start; > > > > > > vm_size_t grow_amount, guard, max_grow; > > > > > > + vm_prot_t prot; > > > > > > rlim_t lmemlim, stacklim, vmemlim; > > > > > > int rv, rv1 __diagused; > > > > > > bool gap_deleted, grow_down, is_procstack; > > > > > > @@ -4739,6 +4743,12 @@ retry: > > > > > > } > > > > > > > > > > > > if (grow_down) { > > > > > > + /* > > > > > > + * The gap_entry "offset" field is overloaded. See > > > > > > + * vm_map_stack_locked(). > > > > > > + */ > > > > > > + prot = gap_entry->offset; > > > > > > + > > > > > > grow_start = gap_entry->end - grow_amount; > > > > > > if (gap_entry->start + grow_amount == gap_entry->end) { > > > > > > gap_start = gap_entry->start; > > > > > > @@ -4751,9 +4761,7 @@ retry: > > > > > > gap_deleted = false; > > > > > > } > > > > > > rv = vm_map_insert(map, NULL, 0, grow_start, > > > > > > - grow_start + grow_amount, > > > > > > - stack_entry->protection, stack_entry->max_protectio > > n, > > > > > > - MAP_STACK_GROWS_DOWN); > > > > > > + grow_start + grow_amount, prot, prot, MAP_STACK_GRO > > WS_DOWN) > > > > > > ; > > > > > > if (rv != KERN_SUCCESS) { > > > > > > if (gap_deleted) { > > > > > > rv1 = vm_map_insert(map, NULL, 0, gap_s > > tart, > > > > > > diff --git a/sys/vm/vm_map.h b/sys/vm/vm_map.h > > > > > > index fd8b606e8ddc..c4ed36ce57ba 100644 > > > > > > --- a/sys/vm/vm_map.h > > > > > > +++ b/sys/vm/vm_map.h > > > > > > @@ -97,6 +97,10 @@ union vm_map_object { > > > > > > * a VM object (or sharing map) and offset into that object, > > > > > > * and user-exported inheritance and protection information. > > > > > > * Also included is control information for virtual copy operation > > > > s. > > > > > > + * > > > > > > + * For stack gap map entries (MAP_ENTRY_GUARD | MAP_ENTRY_GROWS_DO > > > > WN > > > > > > + * or UP), the next_read member is reused as the stack_guard_page > > > > > > + * storage, and offset is the stack protection. > > > > > > */ > > > > > > struct vm_map_entry { > > > > > > struct vm_map_entry *left; /* left child or previous entry > > */ > > > > > > > > > > > > > > > > This commit has caused screen (sysutils/screen) to display the follow > in > > g > > > > > error when opening a new screen window (ctrl-A c): > > > > > > > > > > pid 28473 comm screen-4.9.0 has trashed its stack, killing > > > > > > > > > > > > > > > -- > > > > > Cheers, > > > > > Cy Schubert > > > > > FreeBSD UNIX: Web: https://FreeBSD.org > > > > > NTP: Web: https://nwtime.org > > > > > > > > > > e^(i*pi)+1=0 > > > > > > > > > > > > > > > > > > I'm also seeing artifacts in emails by nmhτςς (mail/nmh) in my sent direct > or > > y > > > > and in the email cc'd to me. > > > > > > > > > > > > -- > > > > Cheers, > > > > Cy Schubert > > > > FreeBSD UNIX: Web: https://FreeBSD.org > > > > NTP: Web: https://nwtime.org > > > > > > > > e^(i*pi)+1=0 > > > > > > > > > > > > > > Sometimes this occurs at screen start. Then it hangs. > > > > > > slippy$ screen > > > pid 7275 comm screen-4.9.0 has trashed its stack, killing > > > > Can you check this? > > > > diff --git a/sys/vm/vm_map.c b/sys/vm/vm_map.c > > index 8c864c943f5d..4c5f1c08954d 100644 > > --- a/sys/vm/vm_map.c > > +++ b/sys/vm/vm_map.c > > @@ -4202,7 +4202,8 @@ vm_map_copy_entry( > > src_entry->start); > > } else { > > dst_entry->object.vm_object = NULL; > > - dst_entry->offset = 0; > > + if ((dst_entry->eflags &