All of lore.kernel.org
 help / color / mirror / Atom feed
From: Julien Grall <julien.grall@citrix.com>
To: Chen Baozi <cbz@baozis.org>, xen-devel@lists.xenproject.org
Cc: Julien Grall <julien.grall@citrix.com>,
	Chen Baozi <baozich@gmail.com>,
	Ian Campbell <ian.campbell@citrix.com>
Subject: Re: [PATCH V2 4/8] xen/arm: Use the new mapping relations between vCPUID and vMPIDR
Date: Sun, 24 May 2015 13:51:21 +0100	[thread overview]
Message-ID: <5561C949.5010609@citrix.com> (raw)
In-Reply-To: <1432389153-28207-5-git-send-email-cbz@baozis.org>

Hi Chen,

On 23/05/2015 14:52, Chen Baozi wrote:
> From: Chen Baozi <baozich@gmail.com>
>
> There are 3 places to change:
>
> * Initialise vMPIDR value in vcpu_initialise()
> * Find the vCPU from vMPIDR affinity information when accessing GICD
>    registers in vGIC
> * Find the vCPU from vMPIRR affinity information when booting with vPSCI

s/VMPIRR/vMPIDR/

>    in vGIC
>
> Signed-off-by: Chen Baozi <baozich@gmail.com>
> ---
>   xen/arch/arm/domain.c  |  6 +-----
>   xen/arch/arm/vgic-v3.c | 22 +++++++---------------
>   xen/arch/arm/vpsci.c   |  2 +-
>   3 files changed, 9 insertions(+), 21 deletions(-)
>
> diff --git a/xen/arch/arm/domain.c b/xen/arch/arm/domain.c
> index 2bde26e..0cf147c 100644
> --- a/xen/arch/arm/domain.c
> +++ b/xen/arch/arm/domain.c
> @@ -501,11 +501,7 @@ int vcpu_initialise(struct vcpu *v)
>
>       v->arch.sctlr = SCTLR_GUEST_INIT;
>
> -    /*
> -     * By default exposes an SMP system with AFF0 set to the VCPU ID
> -     * TODO: Handle multi-threading processor and cluster
> -     */
> -    v->arch.vmpidr = MPIDR_SMP | (v->vcpu_id << MPIDR_AFF0_SHIFT);
> +    v->arch.vmpidr = MPIDR_SMP | vcpuid_to_vaffinity(v->vcpu_id);
>
>       v->arch.actlr = READ_SYSREG32(ACTLR_EL1);
>
> diff --git a/xen/arch/arm/vgic-v3.c b/xen/arch/arm/vgic-v3.c
> index 40e1892..12007d8 100644
> --- a/xen/arch/arm/vgic-v3.c
> +++ b/xen/arch/arm/vgic-v3.c
> @@ -50,14 +50,6 @@
>    */
>   #define VGICD_CTLR_DEFAULT  (GICD_CTLR_ARE_NS)
>
> -static struct vcpu *vgic_v3_irouter_to_vcpu(struct vcpu *v, uint64_t irouter)
> -{
> -    irouter &= ~(GICD_IROUTER_SPI_MODE_ANY);
> -    irouter = irouter & MPIDR_AFF0_MASK;
> -
> -    return v->domain->vcpu[irouter];
> -}
> -
>   static uint64_t vgic_v3_vcpu_to_irouter(struct vcpu *v,
>                                           unsigned int vcpu_id)
>   {
> @@ -80,9 +72,7 @@ static struct vcpu *vgic_v3_get_target_vcpu(struct vcpu *v, unsigned int irq)
>
>       ASSERT(spin_is_locked(&rank->lock));
>
> -    target = rank->v3.irouter[irq % 32];
> -    target &= ~(GICD_IROUTER_SPI_MODE_ANY);
> -    target &= MPIDR_AFF0_MASK;
> +    target = vaffinity_to_vcpuid(rank->v3.irouter[irq % 32]);

When irouter.IRM  = 1 (i.e any processor can be used for SPIs), the 
affinity may be unknown.

Although, when this register is saved we make sure to have AFF0 and AFF1 
set to 0.

This change, as the current wasn't clear about it. I would be tempt to 
add a specific case for irouter.IRM = 1. But I don't mind if you only 
add a comment.

>       ASSERT(target >= 0 && target < v->domain->max_vcpus);
>
>       return v->domain->vcpu[target];
> @@ -751,7 +741,7 @@ static int vgic_v3_distr_mmio_read(struct vcpu *v, mmio_info_t *info)
>               vgic_unlock_rank(v, rank, flags);
>               return 1;
>           }
> -        vcpu_id = irouter;
> +        vcpu_id = vaffinity_to_vcpuid(irouter);
>           *r = vgic_v3_vcpu_to_irouter(v, vcpu_id);

The current code is very pointless, irouter contains the value to 
return. vgic_v3_vcpu_to_irouter is just an identity function.

The read emulation for IROUTER can be simplify a lot to only returns the 
value irouter which is already valid.

I can send a patch to apply before your series to clean up this IROUTER 
code. I would make unnecessary some of your changes.

>           vgic_unlock_rank(v, rank, flags);
>           return 1;
> @@ -841,6 +831,7 @@ static int vgic_v3_distr_mmio_write(struct vcpu *v, mmio_info_t *info)
>       uint64_t new_irouter, new_target, old_target;
>       struct vcpu *old_vcpu, *new_vcpu;
>       int gicd_reg = (int)(info->gpa - v->domain->arch.vgic.dbase);
> +    uint32_t vcpu_id;
>
>       perfc_incr(vgicd_writes);
>
> @@ -925,8 +916,9 @@ static int vgic_v3_distr_mmio_write(struct vcpu *v, mmio_info_t *info)
>           }
>           else
>           {
> -            new_target = new_irouter & MPIDR_AFF0_MASK;
> -            if ( new_target >= v->domain->max_vcpus )
> +            new_target = new_irouter & MPIDR_HWID_MASK;
> +            vcpu_id = vaffinity_to_vcpuid(new_irouter);
> +            if ( vcpu_id >= v->domain->max_vcpus )
>               {
>                   printk(XENLOG_G_DEBUG
>                          "%pv: vGICD: wrong irouter at offset %#08x\n val 0x%lx vcpu %x",
> @@ -934,7 +926,7 @@ static int vgic_v3_distr_mmio_write(struct vcpu *v, mmio_info_t *info)
>                   vgic_unlock_rank(v, rank, flags);
>                   return 0;
>               }
> -            new_vcpu = vgic_v3_irouter_to_vcpu(v, new_irouter);

I would prefer to keep vgic_v3_irouter_to_vcpu and return NULL if the 
VCPU ID is too high.

The emulation code would be:

      new_vcpu = vgic_v3_irouter_to_vcpu(v, new_irouter);
      if ( !new_vcpu )
      {
         printk(.....);
      }

Although the current emulation is wrong, if the guest is passing a wrong 
MPIDR, we should just ignore the setting and let the interrupt going 
pending. Anyway, I think it would require more work in Xen so I'm okay 
with the current behavior.

> +            new_vcpu = v->domain->vcpu[vcpu_id];
>           }
>
>           rank->v3.irouter[REG_RANK_INDEX(64, (gicd_reg - GICD_IROUTER),
> diff --git a/xen/arch/arm/vpsci.c b/xen/arch/arm/vpsci.c
> index 5d899be..1c1e7de 100644
> --- a/xen/arch/arm/vpsci.c
> +++ b/xen/arch/arm/vpsci.c
> @@ -33,7 +33,7 @@ static int do_common_cpu_on(register_t target_cpu, register_t entry_point,
>       register_t vcpuid;
>
>       if( ver == XEN_PSCI_V_0_2 )
> -        vcpuid = (target_cpu & MPIDR_HWID_MASK);
> +        vcpuid = vaffinity_to_vcpuid(target_cpu);
>       else
>           vcpuid = target_cpu;

AFAICT in PSCI 0.1, target_cpu is a CPUID which is a MPIDR-like value. 
If so, I think we may need to call vaffinity_to_vcpuid.

But, I wasn't able to confirm with the spec. I guessed it from the Linux 
usage. Maybe there is limit of number of CPU used with PSCI 0.1?

Regards,

-- 
Julien Grall

  reply	other threads:[~2015-05-24 15:37 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-23 13:52 [PATCH V2 0/8] Support more than 8 vcpus on arm64 with GICv3 Chen Baozi
2015-05-23 13:52 ` [PATCH V2 1/8] xen/arm64: increase MAX_VIRT_CPUS to 128 on arm64 Chen Baozi
2015-05-23 14:46   ` Julien Grall
2015-05-25  1:01     ` Chen Baozi
2015-05-25  9:46       ` Julien Grall
2015-05-23 13:52 ` [PATCH V2 2/8] xen/arm: gic-v3: Increase the size of GICR in address space for guest Chen Baozi
2015-05-23 14:48   ` Julien Grall
2015-05-23 13:52 ` [PATCH V2 3/8] xen/arm: Add funtions of mapping between vCPUID and vMPIDR Chen Baozi
2015-05-23 18:36   ` Julien Grall
2015-05-23 13:52 ` [PATCH V2 4/8] xen/arm: Use the new mapping relations " Chen Baozi
2015-05-24 12:51   ` Julien Grall [this message]
2015-05-25  2:34     ` Chen Baozi
2015-05-25  9:53       ` Julien Grall
2015-05-23 13:52 ` [PATCH V2 5/8] xen/arm: vGIC: Consider AFF1 when injecting SGI Chen Baozi
2015-05-26 14:36   ` Julien Grall
2015-05-23 13:52 ` [PATCH V2 6/8] tools/libxl: Make DT node of GICv3 according to max_vcpus Chen Baozi
2015-05-26 14:40   ` Julien Grall
2015-05-23 13:52 ` [PATCH V2 7/8] tools/libxl: Set logical CPUID in DT node equal to MPIDR for domU Chen Baozi
2015-05-26 14:48   ` Julien Grall
2015-05-23 13:52 ` [PATCH V2 8/8] xen/arm: Set logical CPUID in DT node for dom0 the same as MPIDR Chen Baozi
2015-05-26 14:50   ` Julien Grall

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=5561C949.5010609@citrix.com \
    --to=julien.grall@citrix.com \
    --cc=baozich@gmail.com \
    --cc=cbz@baozis.org \
    --cc=ian.campbell@citrix.com \
    --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.