From nobody Thu May 22 05:04:19 2025 X-Original-To: freebsd-current@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 4b2x6V6Dplz5vrKj for ; Thu, 22 May 2025 05:04:34 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from kib.kiev.ua (kib.kiev.ua [IPv6:2001:470:d5e7:1::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 4b2x6V3PKKz41b4; Thu, 22 May 2025 05:04:34 +0000 (UTC) (envelope-from kostikbel@gmail.com) Authentication-Results: mx1.freebsd.org; none Received: from tom.home (kib@localhost [127.0.0.1] (may be forged)) by kib.kiev.ua (8.18.1/8.18.1) with ESMTP id 54M54JhL000279; Thu, 22 May 2025 08:04:22 +0300 (EEST) (envelope-from kostikbel@gmail.com) DKIM-Filter: OpenDKIM Filter v2.10.3 kib.kiev.ua 54M54JhL000279 Received: (from kostik@localhost) by tom.home (8.18.1/8.18.1/Submit) id 54M54JAV000278; Thu, 22 May 2025 08:04:19 +0300 (EEST) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: tom.home: kostik set sender to kostikbel@gmail.com using -f Date: Thu, 22 May 2025 08:04:19 +0300 From: Konstantin Belousov To: Brooks Davis Cc: Warner Losh , freebsd-current@freebsd.org Subject: Re: Un-sucking EINVAL Message-ID: References: <202505210722.54L7MTqw025632@critter.freebsd.dk> List-Id: Discussions about the use of FreeBSD-current List-Archive: https://lists.freebsd.org/archives/freebsd-current List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-current@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,BAYES_00, DKIM_ADSP_CUSTOM_MED,FORGED_GMAIL_RCVD,FREEMAIL_FROM, NML_ADSP_CUSTOM_MED autolearn=no autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on tom.home X-Rspamd-Queue-Id: 4b2x6V3PKKz41b4 X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Spamd-Result: default: False [-4.00 / 15.00]; REPLY(-4.00)[]; ASN(0.00)[asn:6939, ipnet:2001:470::/32, country:US] X-Spamd-Bar: ---- On Wed, May 21, 2025 at 11:23:12PM +0000, Brooks Davis wrote: > On Wed, May 21, 2025 at 11:07:09AM -0600, Warner Losh wrote: > > In short, I'd love to widen the interface, but there's a number of practical > > issues in the way. > > I think caching something in the kernel of later retrieval or adding a > new return path to the ABI is the wrong way around. Instead I think the > right solution is for each thread to register a userspace buffer. You > end up adding one or two entries to struct thread (pointer to a > structure or pointer to an buffer and length) and if the pointer is > non-NULL you copyout a string to the buffer. This avoids signficant > new storage in the kernel and means programs that won't use this data > don't see it. It also means that the debugger can access it without > needing a new PT_ argument. > > As a minor downside you would introduce some new error conditions if the > programmer messes up registration, but we'd probably just have libthr do > it in most cases (that would be more debugger friendly since you > could hang it off a known location in userspace). I mostly agree with this proposal, and can implement it. I strongly object against blowing the kernel with MBs of strings. Userspace can register per-thread extended errno location, and kernel can copyout the ext-errno when returning error. We already have a similar mechanism for fast signals blocking, so I am talking with relatively good experience about related machanism. There is no problem with userspace not registering or messing up the registration: after the first failure the mechanism stops working, until the next registration attempt. Since registration must be per-thread, some libc/libthr wrapper would be provided to fetch the value for C runtime. Go would handle it on its own, as it already does for vdso. I do not see a problem with Rust/Java/Nodejs, since they play well with C runtime. All this is quite doable, and the biggest work is to adjust kernel to record additional metadata to places where it identifies an error condition.