From: "Roger Pau Monné" <roger.pau@citrix.com>
To: Tamas K Lengyel <tamas@tklengyel.com>
Cc: Petre Pircalabu <ppircalabu@bitdefender.com>,
Stefano Stabellini <sstabellini@kernel.org>,
Julien Grall <julien@xen.org>, Wei Liu <wl@xen.org>,
Andrew Cooper <andrew.cooper3@citrix.com>,
Jan Beulich <jbeulich@suse.com>,
Alexandru Isaila <aisaila@bitdefender.com>,
xen-devel@lists.xenproject.org,
Volodymyr Babchuk <Volodymyr_Babchuk@epam.com>
Subject: Re: [PATCH v2 for-4.14 2/3] xen/vm_event: add vm_event_check_pending_op
Date: Tue, 2 Jun 2020 13:47:22 +0200 [thread overview]
Message-ID: <20200602114722.GX1195@Air-de-Roger> (raw)
In-Reply-To: <52492e7b44f311b09e9a433f2e5a2ba607a85c78.1590028160.git.tamas@tklengyel.com>
On Wed, May 20, 2020 at 08:31:53PM -0600, Tamas K Lengyel wrote:
> Perform sanity checking when shutting vm_event down to determine whether
> it is safe to do so. Error out with -EAGAIN in case pending operations
> have been found for the domain.
>
> Signed-off-by: Tamas K Lengyel <tamas@tklengyel.com>
> ---
> xen/arch/x86/vm_event.c | 23 +++++++++++++++++++++++
> xen/common/vm_event.c | 17 ++++++++++++++---
> xen/include/asm-arm/vm_event.h | 7 +++++++
> xen/include/asm-x86/vm_event.h | 2 ++
> 4 files changed, 46 insertions(+), 3 deletions(-)
>
> diff --git a/xen/arch/x86/vm_event.c b/xen/arch/x86/vm_event.c
> index 848d69c1b0..a23aadc112 100644
> --- a/xen/arch/x86/vm_event.c
> +++ b/xen/arch/x86/vm_event.c
> @@ -297,6 +297,29 @@ void vm_event_emulate_check(struct vcpu *v, vm_event_response_t *rsp)
> };
> }
>
> +bool vm_event_check_pending_op(const struct vcpu *v)
> +{
> + struct monitor_write_data *w = &v->arch.vm_event->write_data;
const
> +
> + if ( !v->arch.vm_event->sync_event )
> + return false;
> +
> + if ( w->do_write.cr0 )
> + return true;
> + if ( w->do_write.cr3 )
> + return true;
> + if ( w->do_write.cr4 )
> + return true;
> + if ( w->do_write.msr )
> + return true;
> + if ( v->arch.vm_event->set_gprs )
> + return true;
> + if ( v->arch.vm_event->emulate_flags )
> + return true;
Can you please group this into a single if, ie:
if ( w->do_write.cr0 || w->do_write.cr3 || ... )
return true;
> +
> + return false;
> +}
> +
> /*
> * Local variables:
> * mode: C
> diff --git a/xen/common/vm_event.c b/xen/common/vm_event.c
> index 127f2d58f1..2df327a42c 100644
> --- a/xen/common/vm_event.c
> +++ b/xen/common/vm_event.c
> @@ -183,6 +183,7 @@ static int vm_event_disable(struct domain *d, struct vm_event_domain **p_ved)
> if ( vm_event_check_ring(ved) )
> {
> struct vcpu *v;
> + bool pending_op = false;
>
> spin_lock(&ved->lock);
>
> @@ -192,9 +193,6 @@ static int vm_event_disable(struct domain *d, struct vm_event_domain **p_ved)
> return -EBUSY;
> }
>
> - /* Free domU's event channel and leave the other one unbound */
> - free_xen_event_channel(d, ved->xen_port);
> -
> /* Unblock all vCPUs */
> for_each_vcpu ( d, v )
> {
> @@ -203,8 +201,21 @@ static int vm_event_disable(struct domain *d, struct vm_event_domain **p_ved)
> vcpu_unpause(v);
> ved->blocked--;
> }
> +
> + if ( vm_event_check_pending_op(v) )
> + pending_op = true;
You could just do:
pending_op |= vm_event_check_pending_op(v);
and avoid the initialization of pending_op above. Or alternatively:
if ( !pending_op && vm_event_check_pending_op(v) )
pending_op = true;
Which avoid repeated calls to vm_event_check_pending_op when at least
one vCPU is known to be busy.
> }
>
> + /* vm_event ops are still pending until vCPUs get scheduled */
> + if ( pending_op )
> + {
> + spin_unlock(&ved->lock);
> + return -EAGAIN;
What happens when this gets called from vm_event_cleanup?
AFAICT the result there is ignored, and could leak the vm_event
allocated memory?
Thanks, Roger.
next prev parent reply other threads:[~2020-06-02 11:47 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-21 2:31 [PATCH v2 for-4.14 0/3] vm_event: fix race-condition when disabling monitor events Tamas K Lengyel
2020-05-21 2:31 ` [PATCH v2 for-4.14 1/3] xen/monitor: Control register values Tamas K Lengyel
2020-06-02 11:08 ` Roger Pau Monné
2020-06-02 12:40 ` Tamas K Lengyel
2020-06-02 12:47 ` Jan Beulich
2020-06-02 12:51 ` Tamas K Lengyel
2020-06-02 13:00 ` Jan Beulich
2020-06-02 13:10 ` Tamas K Lengyel
2020-06-03 8:04 ` Roger Pau Monné
2020-06-02 13:01 ` Roger Pau Monné
2020-06-02 13:04 ` Jan Beulich
2020-06-02 13:07 ` Tamas K Lengyel
2020-06-02 13:09 ` Tamas K Lengyel
2020-05-21 2:31 ` [PATCH v2 for-4.14 2/3] xen/vm_event: add vm_event_check_pending_op Tamas K Lengyel
2020-06-02 11:47 ` Roger Pau Monné [this message]
2020-06-02 11:50 ` Jan Beulich
2020-06-02 12:43 ` Tamas K Lengyel
2020-05-21 2:31 ` [PATCH v2 for-4.14 3/3] xen/vm_event: Add safe to disable vm_event Tamas K Lengyel
2020-06-02 12:54 ` Roger Pau Monné
2020-06-02 13:06 ` Tamas K Lengyel
2020-06-01 18:58 ` [PATCH v2 for-4.14 0/3] vm_event: fix race-condition when disabling monitor events Tamas K Lengyel
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=20200602114722.GX1195@Air-de-Roger \
--to=roger.pau@citrix.com \
--cc=Volodymyr_Babchuk@epam.com \
--cc=aisaila@bitdefender.com \
--cc=andrew.cooper3@citrix.com \
--cc=jbeulich@suse.com \
--cc=julien@xen.org \
--cc=ppircalabu@bitdefender.com \
--cc=sstabellini@kernel.org \
--cc=tamas@tklengyel.com \
--cc=wl@xen.org \
--cc=xen-devel@lists.xenproject.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).