[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v6 1/3] evtchn: slightly defer lock acquire where possible


  • To: Julien Grall <julien@xxxxxxx>
  • From: Roger Pau Monné <roger.pau@xxxxxxxxxx>
  • Date: Fri, 28 May 2021 15:31:37 +0200
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=5GYo8kOOcdZRaw88SL3GvBsnx9iPp+rZg/kwed91s5g=; b=aABXR9SzHfwID4yhyg0akga9jwgVyNIFMJ67EIBgFqR3qnVG4TD5XmmJz4eqauXZrfVhv72uRJY9ErqegcqbcSi4TQ0RGj1cp/PJp4FLttdim3ks4sqlZSKh5ACKqDI8JrVHEA667d1j8iahGW4aidWWWQl0v1+xeURzMGJE12L1mMX9tG6INGQPODtLb6kUmRyce57xUr6EAzDXzf3YQ/+a9g+dXb7QXTZWhzkdNLPOpC138US6iEPsyb+saj6skid8IjuHi3k6qsNzK2/bcv0V9GMzuxi7jpf6rKsZ+LV359YrWdQxPalSXwc0jGm9tlz0nvARKx1pSHyOALbCnQ==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Hc/ySrG0N7SzpgmEn6NKszuQ+5stpGvCQG6hXhx29a/+c21Nd4QnY3B8MU9YMqtTGXX5RvycYY+UILRldsItPu1eVP0SflqdxwV8WZvhMZmZXs+gHm+oWax3vtE+00Qj25gFRrOMCcC2QPjYn1EFSTMzgkiqCsP5sMHi7rs8GwqgwEc14rjM9P2/pO4xSscoQyjAaLfUC8jaO5TN4joC3ZSQ5OGO/S/C/6svt/TlOqr0Vxhnw9LQwZ8SGskrpzf7hCilT9HaMthXHGK50541Mn8ju/934oTerpU1YAGbBzwblXLMiuvqAJCbdEwX1atShbcEpK/9gVpiWJSrQ+CjGg==
  • Authentication-results: esa5.hc3370-68.iphmx.com; dkim=pass (signature verified) header.i=@citrix.onmicrosoft.com
  • Cc: Jan Beulich <jbeulich@xxxxxxxx>, "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, George Dunlap <George.Dunlap@xxxxxxxxxxxxx>, Ian Jackson <iwj@xxxxxxxxxxxxxx>, Wei Liu <wl@xxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>
  • Delivery-date: Fri, 28 May 2021 13:31:51 +0000
  • Ironport-hdrordr: A9a23:tC4+Va+irC95sM3rqetuk+E3d71zdoMgy1knxilNoENuH/Bwxv rFoB1E73TJYVYqOU3IXOrwXZVoIEmsi6KdhLNhW8baYOCIghrSEGgP1/qZ/9SYIVyOygcF79 YRT0EcMqyOMbEZt7eD3ODQKb9Jr7f3k9HL9IOuqEuBVTsLV0gH1XYFNu5gencbeOAvP+t7KH P23LsIm9PPQwVqUixubkN1LdQq4bfw5d3biXltPW9q1OGQ5QnYo4ITAnCjr2Qjuy0m+8ZWzY HwqX262k3C28vLjyM03VWjp6i+1eGRmeeqQ6e3+5MoAwSprjztSJVqWrWEsjxwivqo8kwSi9 XJow0tJYBa7G7QZHi8pV/W0QHm+jAo9nPy1Daj8FveiP28YAh/J9tKhIpffBecwVEnpstEy6 5O33iUrd5+EQ7AtD6V3annazha0m6P5VYym+8aiHJSFaEEbqVKlJcS+ENOHI1FND7m6bogDP JlAKjnldlrWGLfS0qcknhkwdSqUHh2NAyBWFI6ocCQ0yJbhjRQ01Yf68oFgH8a+Z4xIqM0xt jsA+BNrvVjX8UWZaVyCKMqWs2sEFXXTRbNKm6JZXXmDrwAIGKlke/T3JwFoMWRPLAYxpo7n5 rMFHlCs3QpQlnjDc2V0IcO1AvMTmW7VTHGz8FT4IVYg5XwSaHmKzfrciECr+KQ59EkRuHLUf e6P5xbR9X5K3H1IJ1E2w3lV4MXEGIZWsEOoNo3H3mf5uHMNpbsvunad/i7HsvOLR8UHkfERl cTVjn6I8tNqmqxXGXjuQPcX3P2dla6x7hUeZKq3NQ7+cwoDMlhowIVgVO26oWgMjtZqJUscE 9/Or/81p6hrW6t5GDS8lhzMhVTDkxp8KztOkk6iTMiAgfRS/Iuqt+fcWdd0D+sPRlkVf7bFw ZZuhBe5b+3B4b4/1ELN/uXdkahy1cDrnODSJkR3oeZ493+R58+BpE6HIRsCATwEQBvkwoCkh ZrVOY9fD71KtrSs9TysHVUPpCJSzBEunb+HSYTwkiv8nl14qkUNykmtz3Ha7/Ive5iLAAkwm GZvZVvqoZpNF6UWDECad8DQQRxgVKsce175TS+FcNpc4/QCVlNpB+x9EinYjEICzvXHhYp9z zcxRP9Q4CXPnNt/lYDjfrNzG4cTBTAQ6vbUAFfjWQ6LxWShl9DldaRYKy9ym2QbUZH7N08HV j+EHYvCzIr/suw0hGNnjaECDEB/bUBesLgLJlLScCY5puKQLf41Z3u28UkvaqMabjVw5g2uf r2QX7iENviY9lZkjComg==
  • Ironport-sdr: KQsVnlpdedQbr0Pdykprs09289PnzOa5nqUyFGy9XfzvibrsiVvlKMHR0CeOykEMLS9nzk52sA oB05VajYgnZUU7oNUXLzoDeQrKgoQUa65fUgU18p2u5gEiz4asHO6kP5VidtYc1c7ZAqUTkTzw UaW/KNAau99Ewm7bxe4F8Qzj2Bb0cCnYIion0wOrJCBY+fBpmNQsz6PsRUM0q+xXE9e/XKKj1w 9dzyFdOp5/eQnfLYtqus/tHhQsucStOVzxz8whGoaTPy4MORBpjWYbwQFEbgK625s8i8FgQBlr Tio=
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On Fri, May 28, 2021 at 11:48:51AM +0100, Julien Grall wrote:
> Hi Jan,
> 
> On 28/05/2021 11:23, Jan Beulich wrote:
> > On 28.05.2021 10:30, Roger Pau Monné wrote:
> > > On Thu, May 27, 2021 at 07:48:41PM +0100, Julien Grall wrote:
> > > > On 27/05/2021 12:28, Jan Beulich wrote:
> > > > > port_is_valid() and evtchn_from_port() are fine to use without holding
> > > > > any locks. Accordingly acquire the per-domain lock slightly later in
> > > > > evtchn_close() and evtchn_bind_vcpu().
> > > > 
> > > > So I agree that port_is_valid() and evtchn_from_port() are fine to use
> > > > without holding any locks in evtchn_bind_vcpu(). However, this is 
> > > > misleading
> > > > to say there is no problem with evtchn_close().
> > > > 
> > > > evtchn_close() can be called with current != d and therefore, there is a
> > > 
> > > The only instances evtchn_close is called with current != d and the
> > > domain could be unpaused is in free_xen_event_channel AFAICT.
> > 
> > As long as the domain is not paused, ->valid_evtchns can't ever
> > decrease: The only point where this gets done is in evtchn_destroy().
> > Hence ...
> > 
> > > > risk that port_is_valid() may be valid and then invalid because
> > > > d->valid_evtchns is decremented in evtchn_destroy().
> > > 
> > > Hm, I guess you could indeed have parallel calls to
> > > free_xen_event_channel and evtchn_destroy in a way that
> > > free_xen_event_channel could race with valid_evtchns getting
> > > decreased?
> > 
> > ... I don't see this as relevant.
> > 
> > > > Thankfully the memory is still there. So the current code is okayish 
> > > > and I
> > > > could reluctantly accept this behavior to be spread. However, I don't 
> > > > think
> > > > this should be left uncommented in both the code (maybe on top of
> > > > port_is_valid()?) and the commit message.
> > > 
> > > Indeed, I think we need some expansion of the comment in port_is_valid
> > > to clarify all this. I'm not sure I understand it properly myself when
> > > it's fine to use port_is_valid without holding the per domain event
> > > lock.
> > 
> > Because of the above property plus the fact that even if
> > ->valid_evtchns decreases, the underlying struct evtchn instance
> > will remain valid (i.e. won't get de-allocated, which happens only
> > in evtchn_destroy_final()), it is always fine to use it without
> > lock. With this I'm having trouble seeing what would need adding
> > to port_is_valid()'s commentary.
> 
> Lets take the example of free_xen_event_channel(). The function is checking
> if the port is valid. If it is, then evtchn_close() will be called.
> 
> At this point, it would be fair for a developper to assume that
> port_is_valid() will also return true in event_close().
> 
> To push to the extreme, if free_xen_event_channel() was the only caller of
> evtchn_close(), one could argue that the check in evtchn_close() could be a
> BUG_ON().
> 
> However, this can't be because this would sooner or later turn to an XSA.
> 
> Effectively, it means that is_port_valid() *cannot* be used in an
> ASSERT()/BUG_ON() and every caller should check the return even if the port
> was previously validated.

We already have cases of is_port_valid being used in ASSERTs (in the
shim) and a BUG_ON (with the domain event lock held in evtchn_close).

> So I think a comment on top of is_port_valid() would be really useful before
> someone rediscover it the hard way.

I think I'm being extremely dull here, sorry. From your text I
understand that the value returned by is_port_valid could be stale by
the time the user reads it?

I think there's some condition that makes this value stale, and it's
not the common case?

Thanks, Roger.



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.