mailing list of musl libc
 help / color / mirror / code / Atom feed
* [musl] preadv2/pwritev2
@ 2021-10-20  2:24 enh
  2021-10-20 18:18 ` Rich Felker
  0 siblings, 1 reply; 4+ messages in thread
From: enh @ 2021-10-20  2:24 UTC (permalink / raw)
  To: musl

[-- Attachment #1: Type: text/plain, Size: 1502 bytes --]

i've recently added preadv2(2) and pwritev2(2) wrappers to bionic, since we
had our first real prospective user come along, and they're mildly annoying
to use via syscall(3). unfortunately, this particular user also wants to be
able to compile for the host, and our glibc is years out of date, and our
current plan is to move to musl for the host[1].

anyway ... musl doesn't have preadv2/pwritev2. i couldn't see any
discussion on the mailing list, so i thought i'd ask whether this is just
because no-one's got round to it yet, or there's some policy[2] i'm not
aware of, or what? happy to send a patch if it's just a case of "we haven't
got round to/had a need for it yet".

____
1. TL;DR: being able to statically link without worrying about licensing is
very enticing, and gets us out of a lot of the compatibility issues we have
that made our last glibc update more trouble than it was worth, and means i
have no intention of getting us embroiled in another glibc update.
2. i've been maintaining bionic for years now, and don't think i've written
down our policy explicitly. this was definitely a borderline case from the
"number of users" perspective, but for me the "annoying to use with
syscall(2)" tipped me over the edge into adding them. amusingly [or not,
depending on how you feel about "bugs you get away with"], it also made me
realize that our pread/pwrite implementations for LP64 were wrong in that
they weren't zeroing the unused half of the register pair. so that was a
bonus :-)

[-- Attachment #2: Type: text/html, Size: 1710 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [musl] preadv2/pwritev2
  2021-10-20  2:24 [musl] preadv2/pwritev2 enh
@ 2021-10-20 18:18 ` Rich Felker
  2024-01-17 14:08   ` Leah Neukirchen
  0 siblings, 1 reply; 4+ messages in thread
From: Rich Felker @ 2021-10-20 18:18 UTC (permalink / raw)
  To: enh; +Cc: musl

On Tue, Oct 19, 2021 at 07:24:26PM -0700, enh wrote:
> i've recently added preadv2(2) and pwritev2(2) wrappers to bionic, since we
> had our first real prospective user come along, and they're mildly annoying
> to use via syscall(3). unfortunately, this particular user also wants to be
> able to compile for the host, and our glibc is years out of date, and our
> current plan is to move to musl for the host[1].
> 
> anyway ... musl doesn't have preadv2/pwritev2. i couldn't see any
> discussion on the mailing list, so i thought i'd ask whether this is just
> because no-one's got round to it yet, or there's some policy[2] i'm not
> aware of, or what? happy to send a patch if it's just a case of "we haven't
> got round to/had a need for it yet".
> 
> ____
> 1. TL;DR: being able to statically link without worrying about licensing is
> very enticing, and gets us out of a lot of the compatibility issues we have
> that made our last glibc update more trouble than it was worth, and means i
> have no intention of getting us embroiled in another glibc update.
> 2. i've been maintaining bionic for years now, and don't think i've written
> down our policy explicitly. this was definitely a borderline case from the
> "number of users" perspective, but for me the "annoying to use with
> syscall(2)" tipped me over the edge into adding them. amusingly [or not,
> depending on how you feel about "bugs you get away with"], it also made me
> realize that our pread/pwrite implementations for LP64 were wrong in that
> they weren't zeroing the unused half of the register pair. so that was a
> bonus :-)

There is high level policy for decision-making process for
inclusion/exclusion. For new sycalls that are "safe" to use directly
via syscall() it's not terribly urgent to take any action, but some
like these would benefit from being cancellation points, which makes
them somewhat compelling. If we do add them, I want to make sure we
don't conflict with glibc's way of exposing them to applications (if
they have one yet) -- things like the function signatures and how the
flags are exposed. None of this looks hard to get right though. So I
think it should be pretty straightforward to add these.

Rich

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [musl] preadv2/pwritev2
  2021-10-20 18:18 ` Rich Felker
@ 2024-01-17 14:08   ` Leah Neukirchen
  2024-01-18 15:54     ` Rich Felker
  0 siblings, 1 reply; 4+ messages in thread
From: Leah Neukirchen @ 2024-01-17 14:08 UTC (permalink / raw)
  To: musl; +Cc: enh

Rich Felker <dalias@libc.org> wrote:
> On Tue, Oct 19, 2021 at 07:24:26PM -0700, enh wrote:
> > i've recently added preadv2(2) and pwritev2(2) wrappers to bionic, since we
> > had our first real prospective user come along, and they're mildly annoying
> > to use via syscall(3). unfortunately, this particular user also wants to be
> > able to compile for the host, and our glibc is years out of date, and our
> > current plan is to move to musl for the host[1].
> > 
> > anyway ... musl doesn't have preadv2/pwritev2. i couldn't see any
> > discussion on the mailing list, so i thought i'd ask whether this is just
> > because no-one's got round to it yet, or there's some policy[2] i'm not
> > aware of, or what? happy to send a patch if it's just a case of "we haven't
> > got round to/had a need for it yet".
> > 
> > ____
> > 1. TL;DR: being able to statically link without worrying about licensing is
> > very enticing, and gets us out of a lot of the compatibility issues we have
> > that made our last glibc update more trouble than it was worth, and means i
> > have no intention of getting us embroiled in another glibc update.
> > 2. i've been maintaining bionic for years now, and don't think i've written
> > down our policy explicitly. this was definitely a borderline case from the
> > "number of users" perspective, but for me the "annoying to use with
> > syscall(2)" tipped me over the edge into adding them. amusingly [or not,
> > depending on how you feel about "bugs you get away with"], it also made me
> > realize that our pread/pwrite implementations for LP64 were wrong in that
> > they weren't zeroing the unused half of the register pair. so that was a
> > bonus :-)
> 
> There is high level policy for decision-making process for
> inclusion/exclusion. For new sycalls that are "safe" to use directly
> via syscall() it's not terribly urgent to take any action, but some
> like these would benefit from being cancellation points, which makes
> them somewhat compelling. If we do add them, I want to make sure we
> don't conflict with glibc's way of exposing them to applications (if
> they have one yet) -- things like the function signatures and how the
> flags are exposed. None of this looks hard to get right though. So I
> think it should be pretty straightforward to add these.

Bumping this, as bcachefs-tools now uses pwritev2.

glibc wraps the syscall with a cancellation point and also tries to
fall back to pwritev/writev when flags is zero and the original call
failed with ENOSYS.  Vice versa for preadv2.

I didn't bother with the fallback since the call is there since Linux 4.6:

ssize_t pwritev2(int fd, const struct iovec *iov, int count, off_t ofs, int flags)
{
	return syscall_cp(SYS_pwritev2, fd, iov, count,
		(long)(ofs), (long)(ofs>>32), flags);
}

-- 
Leah Neukirchen  <leah@vuxu.org>  https://leahneukirchen.org/

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [musl] preadv2/pwritev2
  2024-01-17 14:08   ` Leah Neukirchen
@ 2024-01-18 15:54     ` Rich Felker
  0 siblings, 0 replies; 4+ messages in thread
From: Rich Felker @ 2024-01-18 15:54 UTC (permalink / raw)
  To: Leah Neukirchen; +Cc: musl, enh

On Wed, Jan 17, 2024 at 03:08:29PM +0100, Leah Neukirchen wrote:
> Rich Felker <dalias@libc.org> wrote:
> > On Tue, Oct 19, 2021 at 07:24:26PM -0700, enh wrote:
> > > i've recently added preadv2(2) and pwritev2(2) wrappers to bionic, since we
> > > had our first real prospective user come along, and they're mildly annoying
> > > to use via syscall(3). unfortunately, this particular user also wants to be
> > > able to compile for the host, and our glibc is years out of date, and our
> > > current plan is to move to musl for the host[1].
> > > 
> > > anyway ... musl doesn't have preadv2/pwritev2. i couldn't see any
> > > discussion on the mailing list, so i thought i'd ask whether this is just
> > > because no-one's got round to it yet, or there's some policy[2] i'm not
> > > aware of, or what? happy to send a patch if it's just a case of "we haven't
> > > got round to/had a need for it yet".
> > > 
> > > ____
> > > 1. TL;DR: being able to statically link without worrying about licensing is
> > > very enticing, and gets us out of a lot of the compatibility issues we have
> > > that made our last glibc update more trouble than it was worth, and means i
> > > have no intention of getting us embroiled in another glibc update.
> > > 2. i've been maintaining bionic for years now, and don't think i've written
> > > down our policy explicitly. this was definitely a borderline case from the
> > > "number of users" perspective, but for me the "annoying to use with
> > > syscall(2)" tipped me over the edge into adding them. amusingly [or not,
> > > depending on how you feel about "bugs you get away with"], it also made me
> > > realize that our pread/pwrite implementations for LP64 were wrong in that
> > > they weren't zeroing the unused half of the register pair. so that was a
> > > bonus :-)
> > 
> > There is high level policy for decision-making process for
> > inclusion/exclusion. For new sycalls that are "safe" to use directly
> > via syscall() it's not terribly urgent to take any action, but some
> > like these would benefit from being cancellation points, which makes
> > them somewhat compelling. If we do add them, I want to make sure we
> > don't conflict with glibc's way of exposing them to applications (if
> > they have one yet) -- things like the function signatures and how the
> > flags are exposed. None of this looks hard to get right though. So I
> > think it should be pretty straightforward to add these.
> 
> Bumping this, as bcachefs-tools now uses pwritev2.
> 
> glibc wraps the syscall with a cancellation point and also tries to
> fall back to pwritev/writev when flags is zero and the original call
> failed with ENOSYS.  Vice versa for preadv2.
> 
> I didn't bother with the fallback since the call is there since Linux 4.6:
> 
> ssize_t pwritev2(int fd, const struct iovec *iov, int count, off_t ofs, int flags)
> {
> 	return syscall_cp(SYS_pwritev2, fd, iov, count,
> 		(long)(ofs), (long)(ofs>>32), flags);
> }

"Since Linux 4.6" isn't really an indication for not needing fallback.

Normally I'd say check !flags first and just use the old syscall, but
here I'm not really sure. Eventually it's going to be the other way
around -- pwrite() needs to be implemented in terms of SYS_pwritev2
once my patch "vfs: add RWF_NOAPPEND flag for pwritev2" is upstream,
because currently it's dangerously misbehaving. At that point I'm not
sure what the right thing to do with the Linux-specific pwritev()
would be, but my leaning would be that it should behave like
flags==RWF_NOAPPEND rather than flags==0.

When that's done, plain pwrite() (and possibly pwritev?) will have to
probe for O_APPEND flag in the fallback case if SYS_pwritev2 returns
-ENOSYS, and issue some kind of error in that case (which it really
should already be doing), so there's a mess of stuff to be done here.

I'm not saying we have to solve all this now, just as context. I think
it will be future-proof if we just use the raw SYS_pwritev syscall in
the !flags case either before or after attempting SYS_pwritev2.

Rich

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-01-18 15:54 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-20  2:24 [musl] preadv2/pwritev2 enh
2021-10-20 18:18 ` Rich Felker
2024-01-17 14:08   ` Leah Neukirchen
2024-01-18 15:54     ` Rich Felker

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).