From: Jason Wang <jasowang@redhat.com>
To: Christoph Hellwig <hch@infradead.org>
Cc: Andrea Arcangeli <aarcange@redhat.com>,
kvm@vger.kernel.org, mst@redhat.com,
Peter Zijlstra <peterz@infradead.org>,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
virtualization@lists.linux-foundation.org,
James Bottomley <James.Bottomley@HansenPartnership.com>,
Ingo Molnar <mingo@redhat.com>,
Darren Hart <dvhart@infradead.org>,
Thomas Gleixner <tglx@linutronix.de>
Subject: Re: [PATCH RFC] vhost: don't use kmap() to log dirty pages
Date: Tue, 7 May 2019 23:43:24 -0400 (EDT) [thread overview]
Message-ID: <1430527294.27174562.1557287004441.JavaMail.zimbra@redhat.com> (raw)
In-Reply-To: <20190507154753.GA8809@infradead.org>
On 2019/5/7 下午11:47, Christoph Hellwig wrote:
> On Mon, May 06, 2019 at 10:23:29PM -0400, Jason Wang wrote:
>> Note: there're archs (few non popular ones) that don't implement
>> futex helper, we can't log dirty pages. We can fix them on top or
>> simply disable LOG_ALL features of vhost.
>
> That means vhost now has to depend on HAVE_FUTEX_CMPXCHG to make
> sure we have a working implementation.
I found HAVE_FUTEX_CMPXCHG is not a must for arch that has the
implementation and futex does some kind of runtime detection like:
static void __init futex_detect_cmpxchg(void)
{
#ifndef CONFIG_HAVE_FUTEX_CMPXCHG
u32 curval;
/*
* This will fail and we want it. Some arch implementations do
* runtime detection of the futex_atomic_cmpxchg_inatomic()
* functionality. We want to know that before we call in any
* of the complex code paths. Also we want to prevent
* registration of robust lists in that case. NULL is
* guaranteed to fault and we get -EFAULT on functional
* implementation, the non-functional ones will return
* -ENOSYS.
*/
if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
futex_cmpxchg_enabled = 1;
#endif
}
>
>
>> #include <linux/sched/signal.h>
>> #include <linux/interval_tree_generic.h>
>> #include <linux/nospec.h>
>> +#include <asm/futex.h>
>
> Also please include the futex maintainers to make sure they are fine
> with this first usage of <asm/futex.h> outside of kernel/futex.c.
>
Thanks for ccing them. Will do for next version.
If we decide to go this way, we probably need to move it to uaccess
for a more generic helper.
>
>> +static int set_bit_to_user(int nr, u32 __user *addr)
>> {
>> unsigned long log = (unsigned long)addr;
>> struct page *page;
>> + u32 old_log;
>> int r;
>>
>> r = get_user_pages_fast(log, 1, 1, &page);
>> if (r < 0)
>> return r;
>> BUG_ON(r != 1);
>> +
>> + r = futex_atomic_cmpxchg_inatomic(&old_log, addr, 0, 0);
>> + if (r < 0)
>> + return r;
>> +
>> + old_log |= 1 << nr;
>> + r = put_user(old_log, addr);
>> + if (r < 0)
>> + return r;
>
> And this just looks odd to me. Why do we need the futex call to
> replace a 0 value with 0? Why does it still duplicate the
> put_user? This doesn't look like actually working code to me.
Yes, this is a bug. Should be something like:
static int set_bit_to_user(int nr, u32 __user *addr)
{
unsigned long log = (unsigned long)addr;
struct page *page;
u32 old_log, new_log, l;
int r;
r = get_user_pages_fast(log, 1, 1, &page);
if (r < 0)
return r;
BUG_ON(r != 1);
do {
r = get_user(old_log, addr);
if (r < 0)
return r;
new_log = old_log | (1 << nr);
r = futex_atomic_cmpxchg_inatomic(&l, addr, old_log, new_log);
if (r < 0)
return r;
} while(l != new_log);
set_page_dirty_lock(page);
put_page(page);
return 0;
}
>
> Also don't we need a pagefault_disable() around
> futex_atomic_cmpxchg_inatomic?
Since we don't want to deal with pagefault, so the page has been
pinned before futex_atomic_cmpxchg_inatomic().
Thanks
_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
WARNING: multiple messages have this Message-ID (diff)
From: Jason Wang <jasowang@redhat.com>
To: Christoph Hellwig <hch@infradead.org>
Cc: mst@redhat.com, kvm@vger.kernel.org,
virtualization@lists.linux-foundation.org,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
James Bottomley <James.Bottomley@HansenPartnership.com>,
Andrea Arcangeli <aarcange@redhat.com>,
Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@redhat.com>,
Peter Zijlstra <peterz@infradead.org>,
Darren Hart <dvhart@infradead.org>
Subject: Re: [PATCH RFC] vhost: don't use kmap() to log dirty pages
Date: Tue, 7 May 2019 23:43:24 -0400 (EDT) [thread overview]
Message-ID: <1430527294.27174562.1557287004441.JavaMail.zimbra@redhat.com> (raw)
In-Reply-To: <20190507154753.GA8809@infradead.org>
On 2019/5/7 下午11:47, Christoph Hellwig wrote:
> On Mon, May 06, 2019 at 10:23:29PM -0400, Jason Wang wrote:
>> Note: there're archs (few non popular ones) that don't implement
>> futex helper, we can't log dirty pages. We can fix them on top or
>> simply disable LOG_ALL features of vhost.
>
> That means vhost now has to depend on HAVE_FUTEX_CMPXCHG to make
> sure we have a working implementation.
I found HAVE_FUTEX_CMPXCHG is not a must for arch that has the
implementation and futex does some kind of runtime detection like:
static void __init futex_detect_cmpxchg(void)
{
#ifndef CONFIG_HAVE_FUTEX_CMPXCHG
u32 curval;
/*
* This will fail and we want it. Some arch implementations do
* runtime detection of the futex_atomic_cmpxchg_inatomic()
* functionality. We want to know that before we call in any
* of the complex code paths. Also we want to prevent
* registration of robust lists in that case. NULL is
* guaranteed to fault and we get -EFAULT on functional
* implementation, the non-functional ones will return
* -ENOSYS.
*/
if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
futex_cmpxchg_enabled = 1;
#endif
}
>
>
>> #include <linux/sched/signal.h>
>> #include <linux/interval_tree_generic.h>
>> #include <linux/nospec.h>
>> +#include <asm/futex.h>
>
> Also please include the futex maintainers to make sure they are fine
> with this first usage of <asm/futex.h> outside of kernel/futex.c.
>
Thanks for ccing them. Will do for next version.
If we decide to go this way, we probably need to move it to uaccess
for a more generic helper.
>
>> +static int set_bit_to_user(int nr, u32 __user *addr)
>> {
>> unsigned long log = (unsigned long)addr;
>> struct page *page;
>> + u32 old_log;
>> int r;
>>
>> r = get_user_pages_fast(log, 1, 1, &page);
>> if (r < 0)
>> return r;
>> BUG_ON(r != 1);
>> +
>> + r = futex_atomic_cmpxchg_inatomic(&old_log, addr, 0, 0);
>> + if (r < 0)
>> + return r;
>> +
>> + old_log |= 1 << nr;
>> + r = put_user(old_log, addr);
>> + if (r < 0)
>> + return r;
>
> And this just looks odd to me. Why do we need the futex call to
> replace a 0 value with 0? Why does it still duplicate the
> put_user? This doesn't look like actually working code to me.
Yes, this is a bug. Should be something like:
static int set_bit_to_user(int nr, u32 __user *addr)
{
unsigned long log = (unsigned long)addr;
struct page *page;
u32 old_log, new_log, l;
int r;
r = get_user_pages_fast(log, 1, 1, &page);
if (r < 0)
return r;
BUG_ON(r != 1);
do {
r = get_user(old_log, addr);
if (r < 0)
return r;
new_log = old_log | (1 << nr);
r = futex_atomic_cmpxchg_inatomic(&l, addr, old_log, new_log);
if (r < 0)
return r;
} while(l != new_log);
set_page_dirty_lock(page);
put_page(page);
return 0;
}
>
> Also don't we need a pagefault_disable() around
> futex_atomic_cmpxchg_inatomic?
Since we don't want to deal with pagefault, so the page has been
pinned before futex_atomic_cmpxchg_inatomic().
Thanks
next prev parent reply other threads:[~2019-05-08 3:43 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-05-07 2:23 [PATCH RFC] vhost: don't use kmap() to log dirty pages Jason Wang
2019-05-07 15:47 ` Christoph Hellwig
2019-05-08 3:43 ` Jason Wang [this message]
2019-05-08 3:43 ` Jason Wang
2019-05-07 15:47 ` Christoph Hellwig
2019-05-08 4:12 ` Michael S. Tsirkin
2019-05-08 4:12 ` Michael S. Tsirkin
2019-05-08 4:28 ` Jason Wang
2019-05-08 4:28 ` Jason Wang
-- strict thread matches above, loose matches on Subject: below --
2019-05-07 2:23 Jason Wang
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=1430527294.27174562.1557287004441.JavaMail.zimbra@redhat.com \
--to=jasowang@redhat.com \
--cc=James.Bottomley@HansenPartnership.com \
--cc=aarcange@redhat.com \
--cc=dvhart@infradead.org \
--cc=hch@infradead.org \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=mst@redhat.com \
--cc=netdev@vger.kernel.org \
--cc=peterz@infradead.org \
--cc=tglx@linutronix.de \
--cc=virtualization@lists.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.