From nobody Sun Jan 14 17:41:46 2024 X-Original-To: freebsd-threads@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 4TCjJL1xNwz56kj2 for ; Sun, 14 Jan 2024 17:41:54 +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 4TCjJK5L5Hz4Xlj; Sun, 14 Jan 2024 17:41:53 +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.17.1/8.17.1) with ESMTP id 40EHfkic078560; Sun, 14 Jan 2024 19:41:49 +0200 (EET) (envelope-from kostikbel@gmail.com) DKIM-Filter: OpenDKIM Filter v2.10.3 kib.kiev.ua 40EHfkic078560 Received: (from kostik@localhost) by tom.home (8.17.1/8.17.1/Submit) id 40EHfk4l078559; Sun, 14 Jan 2024 19:41:46 +0200 (EET) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: tom.home: kostik set sender to kostikbel@gmail.com using -f Date: Sun, 14 Jan 2024 19:41:46 +0200 From: Konstantin Belousov To: Alan Somers Cc: =?utf-8?B?Vmluw61jaXVz?= dos Santos Oliveira , freebsd-threads@freebsd.org, Konstantin Belousov Subject: Re: aio_read2() and aio_write2() Message-ID: References: List-Id: Threading List-Archive: https://lists.freebsd.org/archives/freebsd-threads List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-threads@freebsd.org X-BeenThere: freebsd-threads@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit 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.0 X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-14) on tom.home X-Rspamd-Queue-Id: 4TCjJK5L5Hz4Xlj X-Spamd-Bar: ---- 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)[]; TAGGED_RCPT(0.00)[]; ASN(0.00)[asn:6939, ipnet:2001:470::/32, country:US] On Sun, Jan 14, 2024 at 10:13:43AM -0700, Alan Somers wrote: > On Sun, Jan 14, 2024 at 10:07 AM Vinícius dos Santos Oliveira > wrote: > > > > Em dom., 14 de jan. de 2024 às 13:30, Alan Somers > > escreveu: > > > I don't understand. What are you worried about that would block? > > > lseek never does. It never actually goes to disk; it just retrieves a > > > variable from within the kernel. So while the expense of a syscall is > > > non-zero, you don't have to worry about lseek blocking. > > > > Sorry, that was a lot of condensed information that I dumped together. > > > > We can use lseek to get the offset and use AIO specifying the offset > > we just queried. However the untrusted sandboxed process might > > actually send as a socket file descriptor (we don't control what we > > get from the untrusted sandboxed process), and lseek is then > > inappropriate. > > In that case, I believe lseek should return ESPIPE. You need seek cap rights to do lseek(2) on fd, which are specifically not included into cap rights needed for e.g. read(2) and write(2). > > >From what I've read from the source code, we can pass > > these bogus offsets to AIO, and it'll just work. However we're still > > paying an extra syscall (and code doesn't feel right anyway). > > > > Anyway, the kernel *already* has this thread pool (AIO daemons), and > > the only change required here is a flag that controls whether > > FOF_OFFSET is passed along. That's a pretty non-invasive change. What > > is the problem? Again, the model already works fine on Windows and > > Linux. > > The problem is that this flag would be almost impossible to use > correctly for the intended use cases of POSIX AIO. Your application > is actually pretty unusual in that it only has one operation in-flight > at a time. I think it would be better to use the lseek solution > rather than add a footgun to POSIX AIO. > > -Alan