From: Takashi Iwai <tiwai@suse.de>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Christoph Hellwig <hch@lst.de>, Takashi Iwai <tiwai@suse.de>,
linux-kernel@vger.kernel.org,
Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
Mark Brown <broonie@kernel.org>,
netdev@vger.kernel.org
Subject: Re: [PATCH RFC] Introduce uniptr_t as a generic "universal" pointer
Date: Wed, 09 Aug 2023 18:05:50 +0200 [thread overview]
Message-ID: <87wmy4ciap.wl-tiwai@suse.de> (raw)
In-Reply-To: <CAHk-=wiyWOaPtOJ1PTdERswXV9m7W_UkPV-HE0kbpr48mbnrEA@mail.gmail.com>
On Wed, 09 Aug 2023 17:48:11 +0200,
Linus Torvalds wrote:
>
> On Wed, 9 Aug 2023 at 07:38, Christoph Hellwig <hch@lst.de> wrote:
> >
> > The original set_fs removal series did that as uptr_t, and Linus
> > hated it with passion. I somehow doubt he's going to like it more now.
>
> Christoph is right. I do hate this. The whole "pass a pointer that is
> either user or kernel" concept is wrong.
>
> Now, if it was some kind of extended pointer that also included the
> length of the area and had a way to deal with updating the pointer
> sanely, maybe that would be a different thing.
>
> And it should guarantee that in the case of a user pointer it had gone
> through access_ok().
>
> And it also allowed the other common cases like having a raw page
> array, along with a unified interface to copy and update this kind of
> pointer either as a source or a destination, that would be a different
> thing.
>
> But this kind of "if (uniptr_is_kernel(src))" special case thing is
> just garbage and *not* acceptable.
>
> And oh, btw, we already *have* that extended kind of unipointer thing.
>
> It's called "struct iov_iter".
>
> And yes, it's a very complicated thing, exactly because it handles way
> more cases than that uniptr_t. It's a *real* unified pointer of many
> different types.
>
> Those iov_iter things are often so complicated that you really don't
> want to use them, but if you really want a uniptr, that is what you
> should do. It comes with a real cost, but it does come with real
> advantages, one of which is "this is extensively tested
> nfrastructure".
Hmm. In one side, I tend to agree that it can go wrong easily.
OTOH, it simplifies the code well for us; as of now, we have two
callbacks for copying PCM memory from/to the device, distinct for
kernel and user pointers. It's basically either copy_from_user() or
memcpy() of the given size depending on the caller. The sockptr_t or
its variant would allow us to unify those to a single callback.
Of course, we can create yet another local type that is just for the
specific code -- or just (ab)use sockptr_t as is. The fact is that it
can simplify the code well, which in turn make more maintainable.
Though, I have no strong opinion about this topic. If you believe
this kind of code is way too dangerous, fine, we can go with the
current code. OTOH, if the limited use is acceptable (as already seen
with sockptr_t), we can either re-use it or have own one.
(And yeah, iov_iter is there, but it's definitely overkill for the
purpose.)
Takashi
next prev parent reply other threads:[~2023-08-09 16:05 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-09 14:35 [PATCH RFC] Introduce uniptr_t as a generic "universal" pointer Takashi Iwai
2023-08-09 14:38 ` Christoph Hellwig
2023-08-09 14:44 ` Takashi Iwai
2023-08-09 15:59 ` Linus Torvalds
2023-08-09 16:08 ` Takashi Iwai
2023-08-14 16:06 ` David Laight
2023-08-09 15:48 ` Linus Torvalds
2023-08-09 16:05 ` Takashi Iwai [this message]
2023-08-09 17:01 ` Linus Torvalds
2023-08-09 17:21 ` Linus Torvalds
2023-08-09 18:08 ` Takashi Iwai
2023-08-10 14:48 ` Andy Shevchenko
2023-08-11 13:54 ` Takashi Iwai
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87wmy4ciap.wl-tiwai@suse.de \
--to=tiwai@suse.de \
--cc=andriy.shevchenko@linux.intel.com \
--cc=broonie@kernel.org \
--cc=hch@lst.de \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=torvalds@linux-foundation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).