xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: David Vrabel <david.vrabel@citrix.com>
To: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Cc: Wei Liu <wei.liu2@citrix.com>,
	Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>,
	"Keir (Xen.org)" <keir@xen.org>,
	"xen-devel@lists.xen.org" <xen-devel@lists.xen.org>
Subject: Re: [PATCH 01/12] xen/events: avoid race with raising an event in unmask_evtchn()
Date: Wed, 20 Mar 2013 12:20:00 +0000	[thread overview]
Message-ID: <5149A970.3090804@citrix.com> (raw)
In-Reply-To: <alpine.DEB.2.02.1303201052280.17662@kaball.uk.xensource.com>

On 20/03/13 11:00, Stefano Stabellini wrote:
> On Tue, 19 Mar 2013, David Vrabel wrote:
>> From: David Vrabel <david.vrabel@citrix.com>
>>
>> In unmask_evtchn(), when the mask bit is cleared after testing for
>> pending and the event becomes pending between the test and clear, then
>> the upcall will not become pending and the event may be lost or
>> delayed.
>>
>> Avoid this by always clearing the mask bit before checking for
>> pending.
>>
>> This fixes a regression introduced in 3.7 by
>> b5e579232d635b79a3da052964cb357ccda8d9ea (xen/events: fix
>> unmask_evtchn for PV on HVM guests) which reordered the clear mask and
>> check pending operations.
> 
> The race you are trying to fix is real, but the fix you are proposing
> breaks PV on HVM and ARM guests again.
> 
> From the description of b5e579232d635b79a3da052964cb357ccda8d9ea, it's
> clear that the reason to call EVTCHNOP_unmask is to trigger an event
> notification injection again.
> But if you clear the evtchn_mask bit *before* calling EVTCHNOP_unmask,
> EVTCHNOP_unmask won't reinject the event.
> From evtchn_unmask:
> 
>     if ( test_and_clear_bit(port, &shared_info(d, evtchn_mask)) &&
>          test_bit          (port, &shared_info(d, evtchn_pending)) &&
>          !test_and_set_bit (port / BITS_PER_EVTCHN_WORD(d),
>                             &vcpu_info(v, evtchn_pending_sel)) )
>     {
>         vcpu_mark_events_pending(v);
>     }
> 
> The first condition for reinjection would fail.

I missed this.  The only way I can think of fixing this is to set the
mask bit before call the unmask hypercall.

The FIFO-based ABI doesn't have this problem as it always tries to
relink the event whatever the previous state of the mask bit was.

David

>> Signed-off-by: David Vrabel <david.vrabel@citrix.com>
>> Cc: stable@vger.kernel.org
>> Cc: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
>> ---
>>  drivers/xen/events.c |   10 +++++-----
>>  1 files changed, 5 insertions(+), 5 deletions(-)
>>
>> diff --git a/drivers/xen/events.c b/drivers/xen/events.c
>> index d17aa41..4bdd0a5 100644
>> --- a/drivers/xen/events.c
>> +++ b/drivers/xen/events.c
>> @@ -403,11 +403,13 @@ static void unmask_evtchn(int port)
>>  
>>  	if (unlikely((cpu != cpu_from_evtchn(port))))
>>  		do_hypercall = 1;
>> -	else
>> +	else {
>> +		sync_clear_bit(port, BM(&s->evtchn_mask[0]));
>>  		evtchn_pending = sync_test_bit(port, BM(&s->evtchn_pending[0]));
>>  
>> -	if (unlikely(evtchn_pending && xen_hvm_domain()))
>> -		do_hypercall = 1;
>> +		if (unlikely(evtchn_pending && xen_hvm_domain()))
>> +			do_hypercall = 1;
>> +	}
>>  
>>  	/* Slow path (hypercall) if this is a non-local port or if this is
>>  	 * an hvm domain and an event is pending (hvm domains don't have
>> @@ -418,8 +420,6 @@ static void unmask_evtchn(int port)
>>  	} else {
>>  		struct vcpu_info *vcpu_info = __this_cpu_read(xen_vcpu);
>>  
>> -		sync_clear_bit(port, BM(&s->evtchn_mask[0]));
>> -
>>  		/*
>>  		 * The following is basically the equivalent of
>>  		 * 'hw_resend_irq'. Just like a real IO-APIC we 'lose
>> -- 
>> 1.7.2.5
>>

  parent reply	other threads:[~2013-03-20 12:20 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-19 21:04 [PATCH RFC 0/12] Linux: FIFO-based event channel ABI David Vrabel
2013-03-19 21:04 ` [PATCH 01/12] xen/events: avoid race with raising an event in unmask_evtchn() David Vrabel
2013-03-19 21:04 ` [PATCH 02/12] xen/events: refactor retrigger_dynirq() and resend_irq_on_evtchn() David Vrabel
2013-03-20 11:06   ` Jan Beulich
2013-03-19 21:04 ` [PATCH 03/12] xen/events: remove unnecessary init_evtchn_cpu_bindings() David Vrabel
2013-03-20 11:09   ` Jan Beulich
2013-03-20 13:20     ` David Vrabel
2013-03-20 13:40       ` Jan Beulich
2013-03-19 21:04 ` [PATCH 04/12] xen/events: introduce test_and_set_mask David Vrabel
2013-03-19 21:04 ` [PATCH 05/12] xen/events: replace raw bit ops with functions David Vrabel
2013-03-19 21:04 ` [PATCH 06/12] xen/events: move drivers/xen/events.c into drivers/xen/events/ David Vrabel
2013-03-19 21:04 ` [PATCH 07/12] xen/events: move 2-level specific code into its own file David Vrabel
2013-03-19 21:04 ` [PATCH 08/12] xen/events: add struct evtchn_ops for the low-level port operations David Vrabel
2013-03-20 11:12   ` Jan Beulich
2013-03-19 21:04 ` [PATCH 09/12] xen/events: allow setup of irq_info to fail David Vrabel
2013-03-19 21:04 ` [PATCH 10/12] xen/events: add a evtchn_op for port setup David Vrabel
2013-03-19 21:04 ` [PATCH 11/12] xen/events: Add the hypervisor interface for the FIFO-based event channels David Vrabel
2013-03-20 14:03   ` Wei Liu
2013-03-20 14:18     ` David Vrabel
2013-03-20 14:36       ` Wei Liu
2013-03-19 21:04 ` [PATCH 12/12] xen/events: use the FIFO-based ABI if available David Vrabel
2013-03-20  9:38   ` Roger Pau Monné
     [not found] ` <1363727099-25519-2-git-send-email-david.vrabel@citrix.com>
2013-03-20 11:00   ` [PATCH 01/12] xen/events: avoid race with raising an event in unmask_evtchn() Stefano Stabellini
     [not found]   ` <alpine.DEB.2.02.1303201052280.17662@kaball.uk.xensource.com>
2013-03-20 12:20     ` David Vrabel [this message]
2013-03-20 12:21       ` Stefano Stabellini
2013-05-06 19:51 ` [PATCH RFC 0/12] Linux: FIFO-based event channel ABI Konrad Rzeszutek Wilk
2013-05-07 12:26   ` David Vrabel

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=5149A970.3090804@citrix.com \
    --to=david.vrabel@citrix.com \
    --cc=keir@xen.org \
    --cc=konrad.wilk@oracle.com \
    --cc=stefano.stabellini@eu.citrix.com \
    --cc=wei.liu2@citrix.com \
    --cc=xen-devel@lists.xen.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).