public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: "Nicholas Piggin" <npiggin@gmail.com>
To: "Jordan Niethe" <jniethe5@gmail.com>, <linuxppc-dev@lists.ozlabs.org>
Cc: <kvm@vger.kernel.org>, <kvm-ppc@vger.kernel.org>,
	<mikey@neuling.org>, <paulus@ozlabs.org>, <vaibhav@linux.ibm.com>,
	<sbhat@linux.ibm.com>, <gautam@linux.ibm.com>,
	<kconsul@linux.vnet.ibm.com>, <amachhiw@linux.vnet.ibm.com>
Subject: Re: [PATCH v3 1/6] KVM: PPC: Use getters and setters for vcpu register state
Date: Mon, 14 Aug 2023 18:08:52 +1000	[thread overview]
Message-ID: <CUS44PQRFL72.28PFLWO36FYAO@wheely> (raw)
In-Reply-To: <20230807014553.1168699-2-jniethe5@gmail.com>

On Mon Aug 7, 2023 at 11:45 AM AEST, Jordan Niethe wrote:
> There are already some getter and setter functions used for accessing
> vcpu register state, e.g. kvmppc_get_pc(). There are also more
> complicated examples that are generated by macros like
> kvmppc_get_sprg0() which are generated by the SHARED_SPRNG_WRAPPER()
> macro.
>
> In the new PAPR "Nestedv2" API for nested guest partitions the L1 is
> required to communicate with the L0 to modify and read nested guest
> state.
>
> Prepare to support this by replacing direct accesses to vcpu register
> state with wrapper functions. Follow the existing pattern of using
> macros to generate individual wrappers. These wrappers will
> be augmented for supporting Nestedv2 guests later.
>
> Signed-off-by: Gautam Menghani <gautam@linux.ibm.com>
> Signed-off-by: Jordan Niethe <jniethe5@gmail.com>
> ---
> v3:
>   - Do not add a helper for pvr
>   - Use an expression when declaring variable in case
>   - Squash in all getters and setters
>   - Guatam: Pass vector registers by reference
> ---
>  arch/powerpc/include/asm/kvm_book3s.h  | 123 +++++++++++++-
>  arch/powerpc/include/asm/kvm_booke.h   |  10 ++
>  arch/powerpc/kvm/book3s.c              |  38 ++---
>  arch/powerpc/kvm/book3s_64_mmu_hv.c    |   4 +-
>  arch/powerpc/kvm/book3s_64_mmu_radix.c |   9 +-
>  arch/powerpc/kvm/book3s_64_vio.c       |   4 +-
>  arch/powerpc/kvm/book3s_hv.c           | 220 +++++++++++++------------
>  arch/powerpc/kvm/book3s_hv.h           |  58 +++++++
>  arch/powerpc/kvm/book3s_hv_builtin.c   |  10 +-
>  arch/powerpc/kvm/book3s_hv_p9_entry.c  |   4 +-
>  arch/powerpc/kvm/book3s_hv_ras.c       |   5 +-
>  arch/powerpc/kvm/book3s_hv_rm_mmu.c    |   8 +-
>  arch/powerpc/kvm/book3s_hv_rm_xics.c   |   4 +-
>  arch/powerpc/kvm/book3s_xive.c         |   9 +-
>  arch/powerpc/kvm/emulate_loadstore.c   |   2 +-
>  arch/powerpc/kvm/powerpc.c             |  76 ++++-----
>  16 files changed, 395 insertions(+), 189 deletions(-)
>

[snip]

> +
>  /* Expiry time of vcpu DEC relative to host TB */
>  static inline u64 kvmppc_dec_expires_host_tb(struct kvm_vcpu *vcpu)
>  {
> -	return vcpu->arch.dec_expires - vcpu->arch.vcore->tb_offset;
> +	return kvmppc_get_dec_expires(vcpu) - kvmppc_get_tb_offset_hv(vcpu);
>  }

I don't see kvmppc_get_tb_offset_hv in this patch.

> diff --git a/arch/powerpc/kvm/book3s_64_mmu_hv.c b/arch/powerpc/kvm/book3s_64_mmu_hv.c
> index 7f765d5ad436..738f2ecbe9b9 100644
> --- a/arch/powerpc/kvm/book3s_64_mmu_hv.c
> +++ b/arch/powerpc/kvm/book3s_64_mmu_hv.c
> @@ -347,7 +347,7 @@ static int kvmppc_mmu_book3s_64_hv_xlate(struct kvm_vcpu *vcpu, gva_t eaddr,
>  	unsigned long v, orig_v, gr;
>  	__be64 *hptep;
>  	long int index;
> -	int virtmode = vcpu->arch.shregs.msr & (data ? MSR_DR : MSR_IR);
> +	int virtmode = kvmppc_get_msr(vcpu) & (data ? MSR_DR : MSR_IR);
>  
>  	if (kvm_is_radix(vcpu->kvm))
>  		return kvmppc_mmu_radix_xlate(vcpu, eaddr, gpte, data, iswrite);

So this isn't _only_ adding new accessors. This should be functionally a
noop, but I think it introduces a branch if PR is defined.

Shared page is a slight annoyance for HV, I'd like to get rid of it...
but that's another story. I think the pattern here would be to add a
kvmppc_get_msr_hv() accessor.

And as a nitpick, for anywhere employing existing access functions, gprs
and such, could that be split into its own patch?

Looks pretty good aside from those little things.

Thanks,
Nick

  reply	other threads:[~2023-08-14  8:10 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-07  1:45 [PATCH v3 0/6] KVM: PPC: Nested APIv2 guest support Jordan Niethe
2023-08-07  1:45 ` [PATCH v3 1/6] KVM: PPC: Use getters and setters for vcpu register state Jordan Niethe
2023-08-14  8:08   ` Nicholas Piggin [this message]
2023-08-16  3:11     ` Jordan Niethe
2023-08-17  3:25   ` Michael Ellerman
2023-08-07  1:45 ` [PATCH v3 2/6] KVM: PPC: Rename accessor generator macros Jordan Niethe
2023-08-14  8:27   ` Nicholas Piggin
2023-08-16  3:20     ` Jordan Niethe
2023-08-07  1:45 ` [PATCH v3 3/6] KVM: PPC: Add helper library for Guest State Buffers Jordan Niethe
2023-08-07  1:45 ` [PATCH v3 4/6] KVM: PPC: Book3s HV: Hold LPIDs in an unsigned long Jordan Niethe
2023-08-14  8:12   ` Nicholas Piggin
2023-08-15 10:45     ` Michael Ellerman
2023-08-16  3:21       ` Jordan Niethe
2023-08-16  3:14     ` Jordan Niethe
2023-08-14  8:15   ` David Laight
2023-08-16  3:19     ` Jordan Niethe
2023-08-17 12:21   ` Michael Ellerman
2023-08-07  1:45 ` [PATCH v3 5/6] KVM: PPC: Add support for nestedv2 guests Jordan Niethe
2023-08-17  4:19   ` Michael Ellerman
2023-08-17 12:23   ` Michael Ellerman
2023-08-07  1:45 ` [PATCH v3 6/6] docs: powerpc: Document nested KVM on POWER Jordan Niethe

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=CUS44PQRFL72.28PFLWO36FYAO@wheely \
    --to=npiggin@gmail.com \
    --cc=amachhiw@linux.vnet.ibm.com \
    --cc=gautam@linux.ibm.com \
    --cc=jniethe5@gmail.com \
    --cc=kconsul@linux.vnet.ibm.com \
    --cc=kvm-ppc@vger.kernel.org \
    --cc=kvm@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=mikey@neuling.org \
    --cc=paulus@ozlabs.org \
    --cc=sbhat@linux.ibm.com \
    --cc=vaibhav@linux.ibm.com \
    /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