linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: Anup Patel <anup@brainfault.org>
To: Sean Christopherson <seanjc@google.com>
Cc: x86@kernel.org, kvm@vger.kernel.org,
	Peter Zijlstra <peterz@infradead.org>,
	Catalin Marinas <catalin.marinas@arm.com>,
	Dave Hansen <dave.hansen@linux.intel.com>,
	linux-kernel@vger.kernel.org,
	Alexander Gordeev <agordeev@linux.ibm.com>,
	Claudio Imbrenda <imbrenda@linux.ibm.com>,
	Will Deacon <will@kernel.org>,
	linux-riscv@lists.infradead.org, linux-s390@vger.kernel.org,
	Janosch Frank <frankja@linux.ibm.com>,
	Harald Freudenberger <freude@linux.ibm.com>,
	Marc Zyngier <maz@kernel.org>,
	Huacai Chen <chenhuacai@kernel.org>,
	Halil Pasic <pasic@linux.ibm.com>,
	Andrew Thornton <andrewth@google.com>,
	Ingo Molnar <mingo@redhat.com>,
	Christian Borntraeger <borntraeger@linux.ibm.com>,
	Jason Herne <jjherne@linux.ibm.com>,
	Albert Ou <aou@eecs.berkeley.edu>,
	Vasily Gorbik <gor@linux.ibm.com>,
	Venkatesh Srinivas <venkateshs@chromium.org>,
	Heiko Carstens <hca@linux.ibm.com>,
	Arnaldo Carvalho de Melo <acme@kernel.org>,
	Alex Williamson <alex.williamson@redhat.com>,
	Borislav Petkov <bp@alien8.de>,
	And y Lutomirski <luto@kernel.org>,
	Paul Walmsley <paul.walmsley@sifive.com>,
	kvmarm@lists.linux.dev, Thomas Gleixner <tglx@linutronix.de>,
	linux-arm-kernel@lists.infradead.org,
	Tony Krowiak <akrowiak@linux.ibm.com>,
	Anish Ghulati <aghulati@google.com>,
	linux-mips@vger.kernel.org, Oliver Upton <oliver.upton@linux.dev>,
	linux-perf-users@vger.kernel.org,
	Palmer Dabbelt <palmer@dabbelt.com>,
	kvm-riscv@lists.infradead.org,
	Paolo Bonzini <pbonzini@redhat.com>,
	linuxppc-dev@lists.ozlabs.org
Subject: Re: [PATCH 22/26] entry/kvm: KVM: Move KVM details related to signal/-EINTR into KVM proper
Date: Thu, 14 Dec 2023 11:43:50 +0530	[thread overview]
Message-ID: <CAAhSdy2N8PmP2+-8sFVpgduED0HU9D3dqg7sk3+R9f2wRgZ7KA@mail.gmail.com> (raw)
In-Reply-To: <20230916003118.2540661-23-seanjc@google.com>

On Sat, Sep 16, 2023 at 6:02 AM Sean Christopherson <seanjc@google.com> wrote:
>
> Move KVM's morphing of pending signals into exits to userspace into KVM
> proper, and drop the @vcpu param from xfer_to_guest_mode_handle_work().
> How KVM responds to -EINTR is a detail that really belongs in KVM itself,
> and removing the non-KVM call to kvm_handle_signal_exit() will allow
> hiding said API and the definition of "struct kvm_vcpu" from the kernel.
>
> Alternatively, entry/kvm.c could be treated as part of KVM, i.e. be given
> access to KVM internals, but that's not obviously better than having KVM
> react to -EINTR (though it's not obviously worse either).
>
> Signed-off-by: Sean Christopherson <seanjc@google.com>

For KVM RISC-V:
Anup Patel <anup@brainfault.org>

Regards,
Anup

> ---
>  arch/arm64/kvm/arm.c      |  3 +--
>  arch/riscv/kvm/vcpu.c     |  2 +-
>  arch/x86/kvm/vmx/vmx.c    |  1 -
>  arch/x86/kvm/x86.c        |  3 +--
>  include/linux/entry-kvm.h |  3 +--
>  include/linux/kvm_host.h  | 13 ++++++++++++-
>  kernel/entry/kvm.c        | 11 ++++-------
>  7 files changed, 20 insertions(+), 16 deletions(-)
>
> diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c
> index 6480628197b4..641df091e46b 100644
> --- a/arch/arm64/kvm/arm.c
> +++ b/arch/arm64/kvm/arm.c
> @@ -6,7 +6,6 @@
>
>  #include <linux/bug.h>
>  #include <linux/cpu_pm.h>
> -#include <linux/entry-kvm.h>
>  #include <linux/errno.h>
>  #include <linux/err.h>
>  #include <linux/kvm_host.h>
> @@ -929,7 +928,7 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu)
>                 /*
>                  * Check conditions before entering the guest
>                  */
> -               ret = xfer_to_guest_mode_handle_work(vcpu);
> +               ret = kvm_xfer_to_guest_mode_handle_work(vcpu);
>                 if (!ret)
>                         ret = 1;
>
> diff --git a/arch/riscv/kvm/vcpu.c b/arch/riscv/kvm/vcpu.c
> index 82229db1ce73..c313f4e90e70 100644
> --- a/arch/riscv/kvm/vcpu.c
> +++ b/arch/riscv/kvm/vcpu.c
> @@ -667,7 +667,7 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu)
>         run->exit_reason = KVM_EXIT_UNKNOWN;
>         while (ret > 0) {
>                 /* Check conditions before entering the guest */
> -               ret = xfer_to_guest_mode_handle_work(vcpu);
> +               ret = kvm_xfer_to_guest_mode_handle_work(vcpu);
>                 if (ret)
>                         continue;
>                 ret = 1;
> diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c
> index faf0071566ef..43b87ad5fde8 100644
> --- a/arch/x86/kvm/vmx/vmx.c
> +++ b/arch/x86/kvm/vmx/vmx.c
> @@ -28,7 +28,6 @@
>  #include <linux/slab.h>
>  #include <linux/tboot.h>
>  #include <linux/trace_events.h>
> -#include <linux/entry-kvm.h>
>
>  #include <asm/apic.h>
>  #include <asm/asm.h>
> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> index 6c9c81e82e65..aab095f89d9e 100644
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -59,7 +59,6 @@
>  #include <linux/sched/stat.h>
>  #include <linux/sched/isolation.h>
>  #include <linux/mem_encrypt.h>
> -#include <linux/entry-kvm.h>
>  #include <linux/suspend.h>
>  #include <linux/smp.h>
>
> @@ -10987,7 +10986,7 @@ static int vcpu_run(struct kvm_vcpu *vcpu)
>
>                 if (__xfer_to_guest_mode_work_pending()) {
>                         kvm_vcpu_srcu_read_unlock(vcpu);
> -                       r = xfer_to_guest_mode_handle_work(vcpu);
> +                       r = kvm_xfer_to_guest_mode_handle_work(vcpu);
>                         kvm_vcpu_srcu_read_lock(vcpu);
>                         if (r)
>                                 return r;
> diff --git a/include/linux/entry-kvm.h b/include/linux/entry-kvm.h
> index e7d90d06e566..e235a91d28fc 100644
> --- a/include/linux/entry-kvm.h
> +++ b/include/linux/entry-kvm.h
> @@ -42,11 +42,10 @@ static inline int arch_xfer_to_guest_mode_handle_work(unsigned long ti_work)
>  /**
>   * xfer_to_guest_mode_handle_work - Check and handle pending work which needs
>   *                                 to be handled before going to guest mode
> - * @vcpu:      Pointer to current's VCPU data
>   *
>   * Returns: 0 or an error code
>   */
> -int xfer_to_guest_mode_handle_work(struct kvm_vcpu *vcpu);
> +int xfer_to_guest_mode_handle_work(void);
>
>  /**
>   * xfer_to_guest_mode_prepare - Perform last minute preparation work that
> diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
> index fb6c6109fdca..d520d6801070 100644
> --- a/include/linux/kvm_host.h
> +++ b/include/linux/kvm_host.h
> @@ -2,7 +2,7 @@
>  #ifndef __KVM_HOST_H
>  #define __KVM_HOST_H
>
> -
> +#include <linux/entry-kvm.h>
>  #include <linux/types.h>
>  #include <linux/hardirq.h>
>  #include <linux/list.h>
> @@ -2293,6 +2293,17 @@ static inline void kvm_handle_signal_exit(struct kvm_vcpu *vcpu)
>         vcpu->run->exit_reason = KVM_EXIT_INTR;
>         vcpu->stat.signal_exits++;
>  }
> +
> +static inline int kvm_xfer_to_guest_mode_handle_work(struct kvm_vcpu *vcpu)
> +{
> +       int r = xfer_to_guest_mode_handle_work();
> +
> +       if (r) {
> +               WARN_ON_ONCE(r != -EINTR);
> +               kvm_handle_signal_exit(vcpu);
> +       }
> +       return r;
> +}
>  #endif /* CONFIG_KVM_XFER_TO_GUEST_WORK */
>
>  /*
> diff --git a/kernel/entry/kvm.c b/kernel/entry/kvm.c
> index c2fc39824157..872617468b4a 100644
> --- a/kernel/entry/kvm.c
> +++ b/kernel/entry/kvm.c
> @@ -1,17 +1,14 @@
>  // SPDX-License-Identifier: GPL-2.0
>
>  #include <linux/entry-kvm.h>
> -#include <linux/kvm_host.h>
>
> -static int xfer_to_guest_mode_work(struct kvm_vcpu *vcpu, unsigned long ti_work)
> +static int xfer_to_guest_mode_work(unsigned long ti_work)
>  {
>         do {
>                 int ret;
>
> -               if (ti_work & (_TIF_SIGPENDING | _TIF_NOTIFY_SIGNAL)) {
> -                       kvm_handle_signal_exit(vcpu);
> +               if (ti_work & (_TIF_SIGPENDING | _TIF_NOTIFY_SIGNAL))
>                         return -EINTR;
> -               }
>
>                 if (ti_work & _TIF_NEED_RESCHED)
>                         schedule();
> @@ -28,7 +25,7 @@ static int xfer_to_guest_mode_work(struct kvm_vcpu *vcpu, unsigned long ti_work)
>         return 0;
>  }
>
> -int xfer_to_guest_mode_handle_work(struct kvm_vcpu *vcpu)
> +int xfer_to_guest_mode_handle_work(void)
>  {
>         unsigned long ti_work;
>
> @@ -44,6 +41,6 @@ int xfer_to_guest_mode_handle_work(struct kvm_vcpu *vcpu)
>         if (!(ti_work & XFER_TO_GUEST_MODE_WORK))
>                 return 0;
>
> -       return xfer_to_guest_mode_work(vcpu, ti_work);
> +       return xfer_to_guest_mode_work(ti_work);
>  }
>  EXPORT_SYMBOL_GPL(xfer_to_guest_mode_handle_work);
> --
> 2.42.0.459.ge4e396fd5e-goog
>

  reply	other threads:[~2023-12-14  6:14 UTC|newest]

Thread overview: 55+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-16  0:30 [PATCH 00/26] KVM: vfio: Hide KVM internals from others Sean Christopherson
2023-09-16  0:30 ` [PATCH 01/26] vfio: Wrap KVM helpers with CONFIG_KVM instead of CONFIG_HAVE_KVM Sean Christopherson
2023-09-18 15:16   ` Jason Gunthorpe
2023-09-28 22:21   ` Alex Williamson
2023-09-16  0:30 ` [PATCH 02/26] vfio: Move KVM get/put helpers to colocate it with other KVM related code Sean Christopherson
2023-09-18 15:17   ` Jason Gunthorpe
2023-09-28 22:21   ` Alex Williamson
2023-09-16  0:30 ` [PATCH 03/26] virt: Declare and define vfio_file_set_kvm() iff CONFIG_KVM is enabled Sean Christopherson
2023-09-18 15:18   ` Jason Gunthorpe
2023-09-28 22:21   ` Alex Williamson
2023-09-16  0:30 ` [PATCH 04/26] vfio: Add struct to hold KVM assets and dedup group vs. iommufd code Sean Christopherson
2023-09-28 22:21   ` Alex Williamson
2023-09-16  0:30 ` [PATCH 05/26] vfio: KVM: Pass get/put helpers from KVM to VFIO, don't do circular lookup Sean Christopherson
2023-09-18 15:21   ` Jason Gunthorpe
2023-09-18 15:49     ` Sean Christopherson
2023-09-18 16:02       ` Jason Gunthorpe
2023-12-02  0:51         ` Sean Christopherson
2023-12-03 14:07           ` Jason Gunthorpe
2023-12-13  2:22             ` Sean Christopherson
2023-09-28 22:21   ` Alex Williamson
2023-09-16  0:30 ` [PATCH 06/26] KVM: Drop CONFIG_KVM_VFIO and just look at KVM+VFIO Sean Christopherson
2023-09-18 15:29   ` Jason Gunthorpe
2023-09-18 15:52     ` Sean Christopherson
2023-09-18 16:17       ` Jason Gunthorpe
2023-09-28 22:21   ` Alex Williamson
2023-09-16  0:30 ` [PATCH 07/26] x86/idt: Wrap KVM logic with CONFIG_KVM instead of CONFIG_HAVE_KVM Sean Christopherson
2023-09-16  0:31 ` [PATCH 08/26] KVM: x86: Stop selecting and depending on HAVE_KVM Sean Christopherson
2023-09-16  0:31 ` [PATCH 09/26] KVM: arm64: " Sean Christopherson
2023-09-16  0:31 ` [PATCH 10/26] KVM: s390: " Sean Christopherson
2023-09-18 13:38   ` Claudio Imbrenda
2023-09-16  0:31 ` [PATCH 11/26] KVM: MIPS: Make HAVE_KVM a MIPS-only Kconfig Sean Christopherson
2023-09-16  0:31 ` [PATCH 12/26] KVM: arm64: Move arm_{psci,hypercalls}.h to an internal KVM path Sean Christopherson
2023-09-16  0:31 ` [PATCH 13/26] KVM: arm64: Include KVM headers to get forward declarations Sean Christopherson
2023-09-16  0:31 ` [PATCH 14/26] KVM: arm64: Move ARM specific headers in include/kvm to arch directory Sean Christopherson
2023-09-16  0:31 ` [PATCH 15/26] KVM: Move include/kvm/iodev.h to include/linux as kvm_iodev.h Sean Christopherson
2023-12-14  6:02   ` Anup Patel
2023-09-16  0:31 ` [PATCH 16/26] KVM: MIPS: Stop adding virt/kvm to the arch include path Sean Christopherson
2023-09-16  0:31 ` [PATCH 17/26] KVM: PPC: " Sean Christopherson
2023-09-16  0:31 ` [PATCH 18/26] KVM: s390: " Sean Christopherson
2023-09-18  6:56   ` Thomas Huth
2023-09-18 13:38   ` Claudio Imbrenda
2023-09-16  0:31 ` [PATCH 19/26] KVM: Standardize include paths across all architectures Sean Christopherson
2023-12-14  6:04   ` Anup Patel
2023-09-16  0:31 ` [PATCH 20/26] perf/x86: KVM: Have perf define a dedicated struct for getting guest PEBS data Sean Christopherson
2023-09-16  0:31 ` [PATCH 21/26] entry/kvm: Drop @vcpu param from arch_xfer_to_guest_mode_handle_work() Sean Christopherson
2023-09-16  0:31 ` [PATCH 22/26] entry/kvm: KVM: Move KVM details related to signal/-EINTR into KVM proper Sean Christopherson
2023-12-14  6:13   ` Anup Patel [this message]
2023-09-16  0:31 ` [PATCH 23/26] KVM: arm64: Move and consolidate "public" functions in asm/kvm_host.h Sean Christopherson
2023-09-16  0:31 ` [PATCH 24/26] powerpc/xics: Move declaration of xics_wake_cpu() out of kvm_ppc.h Sean Christopherson
2023-09-16  0:31 ` [PATCH 25/26] KVM: PPC: Rearrange code in kvm_ppc.h to isolate "public" information Sean Christopherson
2023-09-16  0:31 ` [PATCH 26/26] KVM: Hide KVM internal data structures and values from kernel at-large Sean Christopherson
2023-12-14  6:20   ` Anup Patel
2024-06-20 10:10 ` [PATCH 00/26] KVM: vfio: Hide KVM internals from others Shameerali Kolothum Thodi
2024-06-24 15:32   ` Sean Christopherson
2024-06-24 19:21     ` Shameerali Kolothum Thodi

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=CAAhSdy2N8PmP2+-8sFVpgduED0HU9D3dqg7sk3+R9f2wRgZ7KA@mail.gmail.com \
    --to=anup@brainfault.org \
    --cc=acme@kernel.org \
    --cc=aghulati@google.com \
    --cc=agordeev@linux.ibm.com \
    --cc=akrowiak@linux.ibm.com \
    --cc=alex.williamson@redhat.com \
    --cc=andrewth@google.com \
    --cc=aou@eecs.berkeley.edu \
    --cc=borntraeger@linux.ibm.com \
    --cc=bp@alien8.de \
    --cc=catalin.marinas@arm.com \
    --cc=chenhuacai@kernel.org \
    --cc=dave.hansen@linux.intel.com \
    --cc=frankja@linux.ibm.com \
    --cc=freude@linux.ibm.com \
    --cc=gor@linux.ibm.com \
    --cc=hca@linux.ibm.com \
    --cc=imbrenda@linux.ibm.com \
    --cc=jjherne@linux.ibm.com \
    --cc=kvm-riscv@lists.infradead.org \
    --cc=kvm@vger.kernel.org \
    --cc=kvmarm@lists.linux.dev \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mips@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=linux-riscv@lists.infradead.org \
    --cc=linux-s390@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=luto@kernel.org \
    --cc=maz@kernel.org \
    --cc=mingo@redhat.com \
    --cc=oliver.upton@linux.dev \
    --cc=palmer@dabbelt.com \
    --cc=pasic@linux.ibm.com \
    --cc=paul.walmsley@sifive.com \
    --cc=pbonzini@redhat.com \
    --cc=peterz@infradead.org \
    --cc=seanjc@google.com \
    --cc=tglx@linutronix.de \
    --cc=venkateshs@chromium.org \
    --cc=will@kernel.org \
    --cc=x86@kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).