qemu-ppc
[Top][All Lists]
Advanced

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

Re: [PATCH v2 11/14] spapr: nested: Use correct source for parttbl info


From: Nicholas Piggin
Subject: Re: [PATCH v2 11/14] spapr: nested: Use correct source for parttbl info for nested PAPR API.
Date: Wed, 29 Nov 2023 14:15:17 +1000

On Thu Oct 12, 2023 at 8:49 PM AEST, Harsh Prateek Bora wrote:
> For nested PAPR API, we use SpaprMachineStateNestedGuest struct to store
> partition table info, use the same in spapr_get_pate_nested() as well.
>
> Signed-off-by: Michael Neuling <mikey@neuling.org>
> Signed-off-by: Harsh Prateek Bora <harshpb@linux.ibm.com>
> ---
>  hw/ppc/spapr.c                |  5 +---
>  hw/ppc/spapr_nested.c         | 49 +++++++++++++++++++++++------------
>  include/hw/ppc/spapr_nested.h |  3 +++
>  3 files changed, 36 insertions(+), 21 deletions(-)
>
> diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
> index 14196fdd11..e1f7b29842 100644
> --- a/hw/ppc/spapr.c
> +++ b/hw/ppc/spapr.c
> @@ -1356,10 +1356,7 @@ static bool spapr_get_pate(PPCVirtualHypervisor *vhyp, 
> PowerPCCPU *cpu,
>          return true;
>      } else {
>          assert(spapr->nested.api);
> -        if (spapr->nested.api == NESTED_API_KVM_HV) {
> -            return spapr_get_pate_nested(spapr, cpu, lpid, entry);
> -        }
> -        return false;
> +        return spapr_get_pate_nested(spapr, cpu, lpid, entry);

If you don't permit the api to be changed to PAPR at the start, then you
don't need to juggle this back and forth.

>      }
>  }
>  
> diff --git a/hw/ppc/spapr_nested.c b/hw/ppc/spapr_nested.c
> index f41b0c0944..1917d8bb13 100644
> --- a/hw/ppc/spapr_nested.c
> +++ b/hw/ppc/spapr_nested.c
> @@ -19,29 +19,45 @@ void spapr_nested_init(SpaprMachineState *spapr)
>  bool spapr_get_pate_nested(SpaprMachineState *spapr, PowerPCCPU *cpu,
>                             target_ulong lpid, ppc_v3_pate_t *entry)
>  {
> -    uint64_t patb, pats;
> +    if (spapr->nested.api == NESTED_API_KVM_HV) {

Maybe split out the implementations into two functions?

And actually instead of open coding the API test, I'm thinking
maybe you should add a helper function

spapr_cpu_nested_api(cpu) which returns NESTED_API_... and you
can just hard code it to return spapr->nested.api for now.
That should avoid a bunch of churn when we permit guests to
run with different APIs.

> +        uint64_t patb, pats;
>  
> -    assert(lpid != 0);
> +        assert(lpid != 0);
>  
> -    patb = spapr->nested.ptcr & PTCR_PATB;
> -    pats = spapr->nested.ptcr & PTCR_PATS;
> +        patb = spapr->nested.ptcr & PTCR_PATB;
> +        pats = spapr->nested.ptcr & PTCR_PATS;
>  
> -    /* Check if partition table is properly aligned */
> -    if (patb & MAKE_64BIT_MASK(0, pats + 12)) {
> -        return false;
> -    }
> +        /* Check if partition table is properly aligned */
> +        if (patb & MAKE_64BIT_MASK(0, pats + 12)) {
> +            return false;
> +        }
>  
> -    /* Calculate number of entries */
> -    pats = 1ull << (pats + 12 - 4);
> -    if (pats <= lpid) {
> -        return false;
> +        /* Calculate number of entries */
> +        pats = 1ull << (pats + 12 - 4);
> +        if (pats <= lpid) {
> +            return false;
> +        }
> +
> +        /* Grab entry */
> +        patb += 16 * lpid;
> +        entry->dw0 = ldq_phys(CPU(cpu)->as, patb);
> +        entry->dw1 = ldq_phys(CPU(cpu)->as, patb + 8);
> +        return true;
>      }
> +#ifdef CONFIG_TCG

Nested spapr is entirely TCG, no? If we're not properly guarding the
nested code with CONFIG_TCG, that should go as an initial prep patch.

Thanks,
Nick

> +    /* Nested PAPR API */
> +    SpaprMachineStateNestedGuest *guest;
> +    assert(lpid != 0);
> +    guest = spapr_get_nested_guest(spapr, lpid);
> +    assert(guest != NULL);
> +
> +    entry->dw0 = guest->parttbl[0];
> +    entry->dw1 = guest->parttbl[1];
>  
> -    /* Grab entry */
> -    patb += 16 * lpid;
> -    entry->dw0 = ldq_phys(CPU(cpu)->as, patb);
> -    entry->dw1 = ldq_phys(CPU(cpu)->as, patb + 8);
>      return true;
> +#else
> +    return false;
> +#endif
>  }
>  
>  #ifdef CONFIG_TCG
> @@ -412,7 +428,6 @@ void spapr_exit_nested(PowerPCCPU *cpu, int excp)
>      address_space_unmap(CPU(cpu)->as, regs, len, len, true);
>  }
>  
> -static
>  SpaprMachineStateNestedGuest *spapr_get_nested_guest(SpaprMachineState 
> *spapr,
>                                                       target_ulong guestid)
>  {
> diff --git a/include/hw/ppc/spapr_nested.h b/include/hw/ppc/spapr_nested.h
> index d27688b1b8..e04202ecb4 100644
> --- a/include/hw/ppc/spapr_nested.h
> +++ b/include/hw/ppc/spapr_nested.h
> @@ -457,4 +457,7 @@ bool spapr_get_pate_nested(SpaprMachineState *spapr, 
> PowerPCCPU *cpu,
>  void spapr_register_nested_papr(void);
>  void spapr_nested_init(SpaprMachineState *spapr);
>  void spapr_nested_gsb_init(void);
> +SpaprMachineStateNestedGuest *spapr_get_nested_guest(SpaprMachineState 
> *spapr,
> +                                                     target_ulong lpid);
> +
>  #endif /* HW_SPAPR_NESTED_H */




reply via email to

[Prev in Thread] Current Thread [Next in Thread]