Re: [PATCH RFC] uaccess: user_access_begin_after_access_ok()

2020-06-06 Thread Michael S. Tsirkin
On Fri, Jun 05, 2020 at 06:03:38PM +0800, Jason Wang wrote: > > On 2020/6/5 上午12:49, Michael S. Tsirkin wrote: > > > > 2. Second argument to translate_desc is a GPA, isn't it? > > > No, it's IOVA, this function will be called only when IOTLB is enabled. > > > > > > Thanks > > Right IOVA. Point st

Re: [PATCH RFC] uaccess: user_access_begin_after_access_ok()

2020-06-05 Thread Jason Wang
On 2020/6/5 上午12:49, Michael S. Tsirkin wrote: 2. Second argument to translate_desc is a GPA, isn't it? No, it's IOVA, this function will be called only when IOTLB is enabled. Thanks Right IOVA. Point stands how does it make sense to cast a userspace pointer to an IOVA? I guess it's just bec

Re: [PATCH RFC] uaccess: user_access_begin_after_access_ok()

2020-06-04 Thread Michael S. Tsirkin
On Wed, Jun 03, 2020 at 02:36:46PM +0800, Jason Wang wrote: > > On 2020/6/3 下午2:30, Michael S. Tsirkin wrote: > > On Wed, Jun 03, 2020 at 02:23:08PM +0800, Jason Wang wrote: > > > > BTW now I re-read it I don't understand __vhost_get_user_slow: > > > > > > > > > > > > static void __user *__vhost

Re: [PATCH RFC] uaccess: user_access_begin_after_access_ok()

2020-06-04 Thread Michael S. Tsirkin
On Thu, Jun 04, 2020 at 04:03:35PM +0100, Al Viro wrote: > On Thu, Jun 04, 2020 at 06:10:23AM -0400, Michael S. Tsirkin wrote: > > > stac() > > for (i = 0; i < 64; ++i) { > > get_user(flags, desc[i].flags) > unsafe_get_user(), please. > > smp_rmb() > > if (!(flags & VALID))

Re: [PATCH RFC] uaccess: user_access_begin_after_access_ok()

2020-06-04 Thread Michael S. Tsirkin
On Thu, Jun 04, 2020 at 03:59:24PM +0100, Al Viro wrote: > On Thu, Jun 04, 2020 at 02:10:27PM +0800, Jason Wang wrote: > > > > > get_user(flags, desc->flags) > > > > smp_rmb() > > > > if (flags & VALID) > > > > copy_from_user(&adesc, desc, sizeof adesc); > > > > > > > > this would be a good candi

Re: [PATCH RFC] uaccess: user_access_begin_after_access_ok()

2020-06-04 Thread Al Viro
On Thu, Jun 04, 2020 at 06:10:23AM -0400, Michael S. Tsirkin wrote: > stac() > for (i = 0; i < 64; ++i) { >get_user(flags, desc[i].flags) unsafe_get_user(), please. >smp_rmb() >if (!(flags & VALID)) > break; >copy_from_user(&adesc[i], desc

Re: [PATCH RFC] uaccess: user_access_begin_after_access_ok()

2020-06-04 Thread Al Viro
On Thu, Jun 04, 2020 at 02:10:27PM +0800, Jason Wang wrote: > > > get_user(flags, desc->flags) > > > smp_rmb() > > > if (flags & VALID) > > > copy_from_user(&adesc, desc, sizeof adesc); > > > > > > this would be a good candidate I think. > > Perhaps, once we get stac/clac out of raw_copy_from_use

Re: [PATCH RFC] uaccess: user_access_begin_after_access_ok()

2020-06-04 Thread Michael S. Tsirkin
On Wed, Jun 03, 2020 at 05:52:05PM +0100, Al Viro wrote: > On Wed, Jun 03, 2020 at 01:29:00AM -0400, Michael S. Tsirkin wrote: > > On Wed, Jun 03, 2020 at 02:48:15AM +0100, Al Viro wrote: > > > On Tue, Jun 02, 2020 at 04:45:05AM -0400, Michael S. Tsirkin wrote: > > > > So vhost needs to poke at use

Re: [PATCH RFC] uaccess: user_access_begin_after_access_ok()

2020-06-03 Thread Jason Wang
On 2020/6/4 上午12:52, Al Viro wrote: On Wed, Jun 03, 2020 at 01:29:00AM -0400, Michael S. Tsirkin wrote: On Wed, Jun 03, 2020 at 02:48:15AM +0100, Al Viro wrote: On Tue, Jun 02, 2020 at 04:45:05AM -0400, Michael S. Tsirkin wrote: So vhost needs to poke at userspace *a lot* in a quick successi

Re: [PATCH RFC] uaccess: user_access_begin_after_access_ok()

2020-06-03 Thread Linus Torvalds
[ Just a re-send without html and a few fixes for mobile editing, since that email got eaten by the mailing list Gods ] On Tue, Jun 2, 2020, 23:02 Michael S. Tsirkin wrote: > > Right and we do that, but that still sets the segment according to the > current thread's flags, right? But that should

Re: [PATCH RFC] uaccess: user_access_begin_after_access_ok()

2020-06-03 Thread Al Viro
On Wed, Jun 03, 2020 at 01:29:00AM -0400, Michael S. Tsirkin wrote: > On Wed, Jun 03, 2020 at 02:48:15AM +0100, Al Viro wrote: > > On Tue, Jun 02, 2020 at 04:45:05AM -0400, Michael S. Tsirkin wrote: > > > So vhost needs to poke at userspace *a lot* in a quick succession. It > > > is thus benefitia

RE: [PATCH RFC] uaccess: user_access_begin_after_access_ok()

2020-06-03 Thread David Laight
From: Al Viro On Behalf Of Al Viro > Sent: 02 June 2020 22:58 > On Tue, Jun 02, 2020 at 08:41:38PM +, David Laight wrote: > > > In which case you need a 'user_access_begin' that takes the mm > > as an additional parameter. > > What does any of that have to do with mm? Details, please.

Re: [PATCH RFC] uaccess: user_access_begin_after_access_ok()

2020-06-02 Thread Jason Wang
On 2020/6/3 下午2:30, Michael S. Tsirkin wrote: On Wed, Jun 03, 2020 at 02:23:08PM +0800, Jason Wang wrote: BTW now I re-read it I don't understand __vhost_get_user_slow: static void __user *__vhost_get_user_slow(struct vhost_virtqueue *vq, void __us

Re: [PATCH RFC] uaccess: user_access_begin_after_access_ok()

2020-06-02 Thread Michael S. Tsirkin
On Wed, Jun 03, 2020 at 02:23:08PM +0800, Jason Wang wrote: > > > > BTW now I re-read it I don't understand __vhost_get_user_slow: > > > > > > static void __user *__vhost_get_user_slow(struct vhost_virtqueue *vq, > >void __user *addr, unsigned int > >

Re: [PATCH RFC] uaccess: user_access_begin_after_access_ok()

2020-06-02 Thread Michael S. Tsirkin
On Wed, Jun 03, 2020 at 05:18:49AM +0100, Al Viro wrote: > On Wed, Jun 03, 2020 at 11:57:11AM +0800, Jason Wang wrote: > > > > How widely do you hope to stretch the user_access areas, anyway? > > > > > > To have best performance for small packets like 64B, if possible, we want to > > disable STA

Re: [PATCH RFC] uaccess: user_access_begin_after_access_ok()

2020-06-02 Thread Jason Wang
On 2020/6/3 下午1:46, Michael S. Tsirkin wrote: On Wed, Jun 03, 2020 at 01:18:54PM +0800, Jason Wang wrote: On 2020/6/3 下午12:18, Al Viro wrote: On Wed, Jun 03, 2020 at 11:57:11AM +0800, Jason Wang wrote: How widely do you hope to stretch the user_access areas, anyway? To have best performanc

Re: [PATCH RFC] uaccess: user_access_begin_after_access_ok()

2020-06-02 Thread Michael S. Tsirkin
On Tue, Jun 02, 2020 at 01:43:20PM -0700, Linus Torvalds wrote: > On Tue, Jun 2, 2020 at 1:33 PM Michael S. Tsirkin wrote: > > > > Hmm are you sure we can drop it? access_ok is done in the context > > of the process. Access itself in the context of a kernel thread > > that borrows the same mm. IIU

Re: [PATCH RFC] uaccess: user_access_begin_after_access_ok()

2020-06-02 Thread Michael S. Tsirkin
On Wed, Jun 03, 2020 at 01:18:54PM +0800, Jason Wang wrote: > > On 2020/6/3 下午12:18, Al Viro wrote: > > On Wed, Jun 03, 2020 at 11:57:11AM +0800, Jason Wang wrote: > > > > > > How widely do you hope to stretch the user_access areas, anyway? > > > > > > To have best performance for small packets

Re: [PATCH RFC] uaccess: user_access_begin_after_access_ok()

2020-06-02 Thread Michael S. Tsirkin
On Wed, Jun 03, 2020 at 02:48:15AM +0100, Al Viro wrote: > On Tue, Jun 02, 2020 at 04:45:05AM -0400, Michael S. Tsirkin wrote: > > So vhost needs to poke at userspace *a lot* in a quick succession. It > > is thus benefitial to enable userspace access, do our thing, then > > disable. Except access_

Re: [PATCH RFC] uaccess: user_access_begin_after_access_ok()

2020-06-02 Thread Jason Wang
On 2020/6/3 下午12:18, Al Viro wrote: On Wed, Jun 03, 2020 at 11:57:11AM +0800, Jason Wang wrote: How widely do you hope to stretch the user_access areas, anyway? To have best performance for small packets like 64B, if possible, we want to disable STAC not only for the metadata access done by

Re: [PATCH RFC] uaccess: user_access_begin_after_access_ok()

2020-06-02 Thread Michael S. Tsirkin
On Tue, Jun 02, 2020 at 11:10:57PM +0100, Al Viro wrote: > On Tue, Jun 02, 2020 at 04:42:03PM -0400, Michael S. Tsirkin wrote: > > On Tue, Jun 02, 2020 at 05:30:48PM +0100, Al Viro wrote: > > > On Tue, Jun 02, 2020 at 04:45:05AM -0400, Michael S. Tsirkin wrote: > > > > So vhost needs to poke at use

Re: [PATCH RFC] uaccess: user_access_begin_after_access_ok()

2020-06-02 Thread Al Viro
On Wed, Jun 03, 2020 at 11:57:11AM +0800, Jason Wang wrote: > > How widely do you hope to stretch the user_access areas, anyway? > > > To have best performance for small packets like 64B, if possible, we want to > disable STAC not only for the metadata access done by vhost accessors but > also t

Re: [PATCH RFC] uaccess: user_access_begin_after_access_ok()

2020-06-02 Thread Jason Wang
On 2020/6/3 上午9:48, Al Viro wrote: On Tue, Jun 02, 2020 at 04:45:05AM -0400, Michael S. Tsirkin wrote: So vhost needs to poke at userspace *a lot* in a quick succession. It is thus benefitial to enable userspace access, do our thing, then disable. Except access_ok has already been pre-validat

Re: [PATCH RFC] uaccess: user_access_begin_after_access_ok()

2020-06-02 Thread Al Viro
On Tue, Jun 02, 2020 at 04:45:05AM -0400, Michael S. Tsirkin wrote: > So vhost needs to poke at userspace *a lot* in a quick succession. It > is thus benefitial to enable userspace access, do our thing, then > disable. Except access_ok has already been pre-validated with all the > relevant nospec

Re: [PATCH RFC] uaccess: user_access_begin_after_access_ok()

2020-06-02 Thread Al Viro
On Tue, Jun 02, 2020 at 04:42:03PM -0400, Michael S. Tsirkin wrote: > On Tue, Jun 02, 2020 at 05:30:48PM +0100, Al Viro wrote: > > On Tue, Jun 02, 2020 at 04:45:05AM -0400, Michael S. Tsirkin wrote: > > > So vhost needs to poke at userspace *a lot* in a quick succession. It > > > is thus benefitia

Re: [PATCH RFC] uaccess: user_access_begin_after_access_ok()

2020-06-02 Thread Al Viro
On Tue, Jun 02, 2020 at 08:41:38PM +, David Laight wrote: > In which case you need a 'user_access_begin' that takes the mm > as an additional parameter. What does any of that have to do with mm? Details, please.

Re: [PATCH RFC] uaccess: user_access_begin_after_access_ok()

2020-06-02 Thread Linus Torvalds
On Tue, Jun 2, 2020 at 1:33 PM Michael S. Tsirkin wrote: > > Hmm are you sure we can drop it? access_ok is done in the context > of the process. Access itself in the context of a kernel thread > that borrows the same mm. IIUC if the process can be 32 bit > while the kernel is 64 bit, access_ok in

Re: [PATCH RFC] uaccess: user_access_begin_after_access_ok()

2020-06-02 Thread Michael S. Tsirkin
On Tue, Jun 02, 2020 at 05:30:48PM +0100, Al Viro wrote: > On Tue, Jun 02, 2020 at 04:45:05AM -0400, Michael S. Tsirkin wrote: > > So vhost needs to poke at userspace *a lot* in a quick succession. It > > is thus benefitial to enable userspace access, do our thing, then > > disable. Except access_

RE: [PATCH RFC] uaccess: user_access_begin_after_access_ok()

2020-06-02 Thread David Laight
From: Michael S. Tsirkin > Sent: 02 June 2020 21:33 > On Tue, Jun 02, 2020 at 10:18:09AM -0700, Linus Torvalds wrote: > > On Tue, Jun 2, 2020 at 9:33 AM Al Viro wrote: > > > > > > > > > > > It's not clear whether we need a new API, I think __uaccess_being() has > > > > the > > > > assumption that

Re: [PATCH RFC] uaccess: user_access_begin_after_access_ok()

2020-06-02 Thread Michael S. Tsirkin
On Tue, Jun 02, 2020 at 10:18:09AM -0700, Linus Torvalds wrote: > On Tue, Jun 2, 2020 at 9:33 AM Al Viro wrote: > > > > > > > > It's not clear whether we need a new API, I think __uaccess_being() has > > > the > > > assumption that the address has been validated by access_ok(). > > > > __uaccess_

Re: [PATCH RFC] uaccess: user_access_begin_after_access_ok()

2020-06-02 Thread Al Viro
On Tue, Jun 02, 2020 at 06:44:30PM +0100, Al Viro wrote: > On Tue, Jun 02, 2020 at 10:18:09AM -0700, Linus Torvalds wrote: > > > > You have exactly two cases: > > > > (a) the access_ok() would be right above the code and can't be missed > > > > (b) not > >(c) what you really want is not

Re: [PATCH RFC] uaccess: user_access_begin_after_access_ok()

2020-06-02 Thread Al Viro
On Tue, Jun 02, 2020 at 10:18:09AM -0700, Linus Torvalds wrote: > You have exactly two cases: > > (a) the access_ok() would be right above the code and can't be missed > > (b) not (c) what you really want is not quite access_ok(). Again, that "not quite access_ok()" should be right next

Re: [PATCH RFC] uaccess: user_access_begin_after_access_ok()

2020-06-02 Thread Linus Torvalds
On Tue, Jun 2, 2020 at 9:33 AM Al Viro wrote: > > > > > It's not clear whether we need a new API, I think __uaccess_being() has the > > assumption that the address has been validated by access_ok(). > > __uaccess_begin() is a stopgap, not a public API. Correct. It's just an x86 implementation det

Re: [PATCH RFC] uaccess: user_access_begin_after_access_ok()

2020-06-02 Thread Al Viro
On Tue, Jun 02, 2020 at 06:15:57PM +0800, Jason Wang wrote: > > On 2020/6/2 下午4:45, Michael S. Tsirkin wrote: > > So vhost needs to poke at userspace *a lot* in a quick succession. It > > is thus benefitial to enable userspace access, do our thing, then > > disable. Except access_ok has already b

Re: [PATCH RFC] uaccess: user_access_begin_after_access_ok()

2020-06-02 Thread Al Viro
On Tue, Jun 02, 2020 at 04:45:05AM -0400, Michael S. Tsirkin wrote: > So vhost needs to poke at userspace *a lot* in a quick succession. It > is thus benefitial to enable userspace access, do our thing, then > disable. Except access_ok has already been pre-validated with all the > relevant nospec

Re: [PATCH RFC] uaccess: user_access_begin_after_access_ok()

2020-06-02 Thread Jason Wang
On 2020/6/2 下午4:45, Michael S. Tsirkin wrote: So vhost needs to poke at userspace *a lot* in a quick succession. It is thus benefitial to enable userspace access, do our thing, then disable. Except access_ok has already been pre-validated with all the relevant nospec checks, so we don't need t

[PATCH RFC] uaccess: user_access_begin_after_access_ok()

2020-06-02 Thread Michael S. Tsirkin
So vhost needs to poke at userspace *a lot* in a quick succession. It is thus benefitial to enable userspace access, do our thing, then disable. Except access_ok has already been pre-validated with all the relevant nospec checks, so we don't need that. Add an API to allow userspace access after a