All of lore.kernel.org
 help / color / mirror / Atom feed
From: Paul Durrant <xadimgnik@gmail.com>
To: "'Jan Beulich'" <jbeulich@suse.com>, <xen-devel@lists.xenproject.org>
Cc: "'Andrew Cooper'" <andrew.cooper3@citrix.com>,
	"'George Dunlap'" <George.Dunlap@eu.citrix.com>,
	"'Ian Jackson'" <iwj@xenproject.org>,
	"'Julien Grall'" <julien@xen.org>, "'Wei Liu'" <wl@xen.org>,
	"'Stefano Stabellini'" <sstabellini@kernel.org>
Subject: RE: [PATCH 11/12] evtchn: convert vIRQ lock to an r/w one
Date: Wed, 30 Sep 2020 08:58:19 +0100	[thread overview]
Message-ID: <004b01d696ff$76873e50$6395baf0$@xen.org> (raw)
In-Reply-To: <6e529147-2a76-bc28-ac16-21fc9a2c8f03@suse.com>

> -----Original Message-----
> From: Xen-devel <xen-devel-bounces@lists.xenproject.org> On Behalf Of Jan Beulich
> Sent: 28 September 2020 12:02
> To: xen-devel@lists.xenproject.org
> Cc: Andrew Cooper <andrew.cooper3@citrix.com>; George Dunlap <George.Dunlap@eu.citrix.com>; Ian
> Jackson <iwj@xenproject.org>; Julien Grall <julien@xen.org>; Wei Liu <wl@xen.org>; Stefano Stabellini
> <sstabellini@kernel.org>
> Subject: [PATCH 11/12] evtchn: convert vIRQ lock to an r/w one
> 
> There's no need to serialize all sending of vIRQ-s; all that's needed
> is serialization against the closing of the respective event channels
> (by means of a barrier). To facilitate the conversion, introduce a new
> rw_barrier().
> 
> Signed-off-by: Jan Beulich <jbeulich@suse.com>
> 
> --- a/xen/common/domain.c
> +++ b/xen/common/domain.c
> @@ -160,7 +160,7 @@ struct vcpu *vcpu_create(struct domain *
>      v->vcpu_id = vcpu_id;
>      v->dirty_cpu = VCPU_CPU_CLEAN;
> 
> -    spin_lock_init(&v->virq_lock);
> +    rwlock_init(&v->virq_lock);
> 
>      tasklet_init(&v->continue_hypercall_tasklet, NULL, NULL);
> 
> --- a/xen/common/event_channel.c
> +++ b/xen/common/event_channel.c
> @@ -640,7 +640,7 @@ int evtchn_close(struct domain *d1, int
>              if ( v->virq_to_evtchn[chn1->u.virq] != port1 )
>                  continue;
>              v->virq_to_evtchn[chn1->u.virq] = 0;
> -            spin_barrier(&v->virq_lock);
> +            rw_barrier(&v->virq_lock);
>          }
>          break;
> 
> @@ -794,7 +794,7 @@ void send_guest_vcpu_virq(struct vcpu *v
> 
>      ASSERT(!virq_is_global(virq));
> 
> -    spin_lock_irqsave(&v->virq_lock, flags);
> +    read_lock_irqsave(&v->virq_lock, flags);
> 
>      port = v->virq_to_evtchn[virq];
>      if ( unlikely(port == 0) )
> @@ -807,7 +807,7 @@ void send_guest_vcpu_virq(struct vcpu *v
>      spin_unlock(&chn->lock);
> 
>   out:
> -    spin_unlock_irqrestore(&v->virq_lock, flags);
> +    read_unlock_irqrestore(&v->virq_lock, flags);
>  }
> 
>  void send_guest_global_virq(struct domain *d, uint32_t virq)
> @@ -826,7 +826,7 @@ void send_guest_global_virq(struct domai
>      if ( unlikely(v == NULL) )
>          return;
> 
> -    spin_lock_irqsave(&v->virq_lock, flags);
> +    read_lock_irqsave(&v->virq_lock, flags);
> 
>      port = v->virq_to_evtchn[virq];
>      if ( unlikely(port == 0) )
> @@ -838,7 +838,7 @@ void send_guest_global_virq(struct domai
>      spin_unlock(&chn->lock);
> 
>   out:
> -    spin_unlock_irqrestore(&v->virq_lock, flags);
> +    read_unlock_irqrestore(&v->virq_lock, flags);
>  }
> 
>  void send_guest_pirq(struct domain *d, const struct pirq *pirq)
> --- a/xen/common/spinlock.c
> +++ b/xen/common/spinlock.c
> @@ -2,7 +2,7 @@
>  #include <xen/irq.h>
>  #include <xen/smp.h>
>  #include <xen/time.h>
> -#include <xen/spinlock.h>
> +#include <xen/rwlock.h>
>  #include <xen/guest_access.h>
>  #include <xen/preempt.h>
>  #include <public/sysctl.h>
> @@ -334,6 +334,12 @@ void _spin_unlock_recursive(spinlock_t *
>      }
>  }
> 
> +void _rw_barrier(rwlock_t *lock)
> +{
> +    check_barrier(&lock->lock.debug);
> +    do { smp_mb(); } while ( _rw_is_locked(lock) );
> +}

Should you not have a cpu_relax() somewhere in here?

TBH though, the fact this lock is never taken as a writer makes me wonder whether there needs to be a lock at all.

  Paul

> +
>  #ifdef CONFIG_DEBUG_LOCK_PROFILE
> 
>  struct lock_profile_anc {
> --- a/xen/include/xen/rwlock.h
> +++ b/xen/include/xen/rwlock.h
> @@ -237,6 +237,8 @@ static inline int _rw_is_write_locked(rw
>      return (atomic_read(&lock->cnts) & _QW_WMASK) == _QW_LOCKED;
>  }
> 
> +void _rw_barrier(rwlock_t *lock);
> +
>  #define read_lock(l)                  _read_lock(l)
>  #define read_lock_irq(l)              _read_lock_irq(l)
>  #define read_lock_irqsave(l, f)                                 \
> @@ -266,6 +268,7 @@ static inline int _rw_is_write_locked(rw
>  #define rw_is_locked(l)               _rw_is_locked(l)
>  #define rw_is_write_locked(l)         _rw_is_write_locked(l)
> 
> +#define rw_barrier(l)                 _rw_barrier(l)
> 
>  typedef struct percpu_rwlock percpu_rwlock_t;
> 
> --- a/xen/include/xen/sched.h
> +++ b/xen/include/xen/sched.h
> @@ -235,7 +235,7 @@ struct vcpu
> 
>      /* IRQ-safe virq_lock protects against delivering VIRQ to stale evtchn. */
>      evtchn_port_t    virq_to_evtchn[NR_VIRQS];
> -    spinlock_t       virq_lock;
> +    rwlock_t         virq_lock;
> 
>      /* Tasklet for continue_hypercall_on_cpu(). */
>      struct tasklet   continue_hypercall_tasklet;
> 




  parent reply	other threads:[~2020-09-30  7:58 UTC|newest]

Thread overview: 60+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-28 10:54 [PATCH 00/12] evtchn: recent XSAs follow-on Jan Beulich
2020-09-28 10:56 ` [PATCH 01/12] evtchn: refuse EVTCHNOP_status for Xen-bound event channels Jan Beulich
2020-09-29  8:49   ` Julien Grall
2020-09-29 15:39   ` Paul Durrant
2020-09-28 10:56 ` [PATCH 02/12] evtchn: avoid race in get_xen_consumer() Jan Beulich
2020-09-29  9:35   ` Julien Grall
2020-09-29 15:44   ` Paul Durrant
2020-09-29 15:58     ` Jan Beulich
2020-09-28 10:57 ` [PATCH 03/12] evtchn: don't call Xen consumer callback with per-channel lock held Jan Beulich
2020-09-29 10:16   ` Julien Grall
2020-09-29 10:54     ` Jan Beulich
2020-09-28 10:57 ` [PATCH 04/12] evtchn: evtchn_set_priority() needs to acquire the per-channel lock Jan Beulich
2020-09-29 10:21   ` Julien Grall
2020-09-29 11:49     ` Jan Beulich
2020-09-29 16:31   ` Paul Durrant
2020-09-30  6:29     ` Jan Beulich
2020-09-30  6:41     ` Jan Beulich
2020-09-30  7:31   ` Paul Durrant
2020-09-30  8:31     ` Jan Beulich
2020-09-30  8:36       ` Paul Durrant
2020-09-30  8:41         ` Jan Beulich
2020-09-28 10:58 ` [PATCH 05/12] evtchn/sched: reject poll requests for unusable ports Jan Beulich
2020-09-29 12:17   ` Julien Grall
2020-09-29 13:00   ` Dario Faggioli
2020-09-29 16:51   ` Paul Durrant
2020-09-28 10:59 ` [PATCH 06/12] evtchn: don't bypass unlinking pIRQ when closing port Jan Beulich
2020-09-29 17:07   ` Paul Durrant
2020-09-28 11:00 ` [PATCH 07/12] evtchn: cut short evtchn_reset()'s loop in the common case Jan Beulich
2020-09-29 17:16   ` Paul Durrant
2020-10-01 15:54   ` Julien Grall
2020-09-28 11:00 ` [PATCH 08/12] evtchn: ECS_CLOSED => ECS_FREE Jan Beulich
2020-09-29 12:19   ` Julien Grall
2020-09-29 16:56   ` Paul Durrant
2020-09-28 11:00 ` [PATCH 09/12] evtchn: move FIFO-private struct declarations Jan Beulich
2020-09-29 12:26   ` Julien Grall
2020-09-29 12:49     ` Jan Beulich
2020-09-30  8:43       ` Julien Grall
2020-09-30  7:37   ` Paul Durrant
2020-09-30  8:32     ` Jan Beulich
2020-09-28 11:01 ` [PATCH 10/12] evtchn/fifo: use stable fields when recording "last queue" information Jan Beulich
2020-09-29 12:29   ` Julien Grall
2020-09-30  7:35   ` Paul Durrant
2020-09-30  8:35     ` Jan Beulich
2020-09-30  8:38       ` Paul Durrant
2020-09-28 11:02 ` [PATCH 11/12] evtchn: convert vIRQ lock to an r/w one Jan Beulich
2020-09-29 13:03   ` Julien Grall
2020-09-29 13:37     ` Jan Beulich
2020-09-29 17:18       ` Julien Grall
2020-09-30  6:26         ` Jan Beulich
2020-09-30  9:09           ` Julien Grall
2020-09-30  7:58   ` Paul Durrant [this message]
2020-09-30  8:37     ` Jan Beulich
2020-09-30  8:52       ` Paul Durrant
2020-09-30 10:16         ` Jan Beulich
2020-10-01 16:21           ` Julien Grall
2020-10-02  6:12             ` Jan Beulich
2020-10-02  8:43               ` Julien Grall
2020-09-28 11:02 ` [PATCH 12/12] evtchn: convert domain event " Jan Beulich
2020-09-28 16:44   ` Roger Pau Monné
2020-09-29 14:32     ` Jan Beulich

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='004b01d696ff$76873e50$6395baf0$@xen.org' \
    --to=xadimgnik@gmail.com \
    --cc=George.Dunlap@eu.citrix.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=iwj@xenproject.org \
    --cc=jbeulich@suse.com \
    --cc=julien@xen.org \
    --cc=paul@xen.org \
    --cc=sstabellini@kernel.org \
    --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 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.