From: "Mika Penttilä" <mika.penttila@nextfour.com>
To: Chao Peng <chao.p.peng@linux.intel.com>,
kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-mm@kvack.org, linux-fsdevel@vger.kernel.org,
qemu-devel@nongnu.org
Cc: Paolo Bonzini <pbonzini@redhat.com>,
Jonathan Corbet <corbet@lwn.net>,
Sean Christopherson <seanjc@google.com>,
Vitaly Kuznetsov <vkuznets@redhat.com>,
Wanpeng Li <wanpengli@tencent.com>,
Jim Mattson <jmattson@google.com>, Joerg Roedel <joro@8bytes.org>,
Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
x86@kernel.org, "H . Peter Anvin" <hpa@zytor.com>,
Hugh Dickins <hughd@google.com>, Jeff Layton <jlayton@kernel.org>,
"J . Bruce Fields" <bfields@fieldses.org>,
Andrew Morton <akpm@linux-foundation.org>,
Yu Zhang <yu.c.zhang@linux.intel.com>,
"Kirill A . Shutemov" <kirill.shutemov@linux.intel.com>,
luto@kernel.org, john.ji@intel.com, susie.li@intel.com,
jun.nakajima@intel.com, dave.hansen@intel.com,
ak@linux.intel.com, david@redhat.com
Subject: Re: [RFC PATCH 5/6] kvm: x86: add KVM_EXIT_MEMORY_ERROR exit
Date: Thu, 11 Nov 2021 17:08:47 +0200 [thread overview]
Message-ID: <f7155c5b-fc87-c1a6-9ee7-06f08a25bdb4@nextfour.com> (raw)
In-Reply-To: <20211111141352.26311-6-chao.p.peng@linux.intel.com>
On 11.11.2021 16.13, Chao Peng wrote:
> Currently support to exit to userspace for private/shared memory
> conversion.
>
> Signed-off-by: Sean Christopherson <seanjc@google.com>
> Signed-off-by: Yu Zhang <yu.c.zhang@linux.intel.com>
> Signed-off-by: Chao Peng <chao.p.peng@linux.intel.com>
> ---
> arch/x86/kvm/mmu/mmu.c | 20 ++++++++++++++++++++
> include/uapi/linux/kvm.h | 15 +++++++++++++++
> 2 files changed, 35 insertions(+)
>
> diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c
> index af5ecf4ef62a..780868888aa8 100644
> --- a/arch/x86/kvm/mmu/mmu.c
> +++ b/arch/x86/kvm/mmu/mmu.c
> @@ -3950,6 +3950,17 @@ static bool try_async_pf(struct kvm_vcpu *vcpu, bool prefault, gfn_t gfn,
>
> slot = __kvm_vcpu_gfn_to_memslot(vcpu, gfn, private);
>
> + /*
> + * Exit to userspace to map the requested private/shared memory region
> + * if there is no memslot and (a) the access is private or (b) there is
> + * an existing private memslot. Emulated MMIO must be accessed through
> + * shared GPAs, thus a memslot miss on a private GPA is always handled
> + * as an implicit conversion "request".
> + */
> + if (!slot &&
> + (private || __kvm_vcpu_gfn_to_memslot(vcpu, gfn, true)))
> + goto out_convert;
> +
> /* Don't expose aliases for no slot GFNs or private memslots */
> if ((cr2_or_gpa & vcpu_gpa_stolen_mask(vcpu)) &&
> !kvm_is_visible_memslot(slot)) {
> @@ -3994,6 +4005,15 @@ static bool try_async_pf(struct kvm_vcpu *vcpu, bool prefault, gfn_t gfn,
> *pfn = __gfn_to_pfn_memslot(slot, gfn, false, NULL,
> write, writable, hva);
> return false;
> +
> +out_convert:
> + vcpu->run->exit_reason = KVM_EXIT_MEMORY_ERROR;
> + vcpu->run->mem.type = private ? KVM_EXIT_MEM_MAP_PRIVATE
> + : KVM_EXIT_MEM_MAP_SHARE;
> + vcpu->run->mem.u.map.gpa = cr2_or_gpa;
> + vcpu->run->mem.u.map.size = PAGE_SIZE;
> + return true;
> +
>
I think this does just retry, no exit to user space?
> }
>
> static int direct_page_fault(struct kvm_vcpu *vcpu, gpa_t gpa, u32 error_code,
> diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h
> index 8d20caae9180..470c472a9451 100644
> --- a/include/uapi/linux/kvm.h
> +++ b/include/uapi/linux/kvm.h
> @@ -233,6 +233,18 @@ struct kvm_xen_exit {
> } u;
> };
>
> +struct kvm_memory_exit {
> +#define KVM_EXIT_MEM_MAP_SHARE 1
> +#define KVM_EXIT_MEM_MAP_PRIVATE 2
> + __u32 type;
> + union {
> + struct {
> + __u64 gpa;
> + __u64 size;
> + } map;
> + } u;
> +};
> +
> #define KVM_S390_GET_SKEYS_NONE 1
> #define KVM_S390_SKEYS_MAX 1048576
>
> @@ -272,6 +284,7 @@ struct kvm_xen_exit {
> #define KVM_EXIT_X86_BUS_LOCK 33
> #define KVM_EXIT_XEN 34
> #define KVM_EXIT_TDVMCALL 35
> +#define KVM_EXIT_MEMORY_ERROR 36
>
> /* For KVM_EXIT_INTERNAL_ERROR */
> /* Emulate instruction failed. */
> @@ -455,6 +468,8 @@ struct kvm_run {
> __u64 subfunc;
> __u64 param[4];
> } tdvmcall;
> + /* KVM_EXIT_MEMORY_ERROR */
> + struct kvm_memory_exit mem;
> /* Fix the size of the union. */
> char padding[256];
> };
next prev parent reply other threads:[~2021-11-11 15:08 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-11 14:13 [RFC PATCH 0/6] KVM: mm: fd-based approach for supporting KVM guest private memory Chao Peng
2021-11-11 14:13 ` [RFC PATCH 1/6] mm: Add F_SEAL_GUEST to shmem/memfd Chao Peng
2021-11-12 19:28 ` Kirill A. Shutemov
2021-11-11 14:13 ` [RFC PATCH 2/6] kvm: x86: Introduce guest private memory address space to memslot Chao Peng
2021-11-11 14:13 ` [RFC PATCH 3/6] kvm: x86: add private_ops " Chao Peng
2021-11-11 14:13 ` [RFC PATCH 4/6] kvm: x86: implement private_ops for memfd backing store Chao Peng
2021-11-11 14:13 ` [RFC PATCH 5/6] kvm: x86: add KVM_EXIT_MEMORY_ERROR exit Chao Peng
2021-11-11 15:08 ` Mika Penttilä [this message]
2021-11-12 5:50 ` Chao Peng
2021-11-11 14:13 ` [RFC PATCH 6/6] KVM: add KVM_SPLIT_MEMORY_REGION Chao Peng
2021-11-11 14:13 ` [RFC PATCH 07/13] linux-headers: Update Chao Peng
2021-11-11 14:13 ` [RFC PATCH 08/13] hostmem: Add guest private memory to memory backend Chao Peng
2021-11-11 14:13 ` [RFC PATCH 09/13] qmp: Include "guest-private" property for memory backends Chao Peng
2021-11-11 14:13 ` [RFC PATCH 10/13] softmmu/physmem: Add private memory address space Chao Peng
2022-01-18 9:41 ` Philippe Mathieu-Daudé
2021-11-11 14:13 ` [RFC PATCH 11/13] kvm: register private memory slots Chao Peng
2021-11-11 14:13 ` [RFC PATCH 12/13] kvm: handle private to shared memory conversion Chao Peng
2021-11-11 14:13 ` [RFC PATCH 13/13] machine: Add 'private-memory-backend' property Chao Peng
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=f7155c5b-fc87-c1a6-9ee7-06f08a25bdb4@nextfour.com \
--to=mika.penttila@nextfour.com \
--cc=ak@linux.intel.com \
--cc=akpm@linux-foundation.org \
--cc=bfields@fieldses.org \
--cc=bp@alien8.de \
--cc=chao.p.peng@linux.intel.com \
--cc=corbet@lwn.net \
--cc=dave.hansen@intel.com \
--cc=david@redhat.com \
--cc=hpa@zytor.com \
--cc=hughd@google.com \
--cc=jlayton@kernel.org \
--cc=jmattson@google.com \
--cc=john.ji@intel.com \
--cc=joro@8bytes.org \
--cc=jun.nakajima@intel.com \
--cc=kirill.shutemov@linux.intel.com \
--cc=kvm@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=luto@kernel.org \
--cc=mingo@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=seanjc@google.com \
--cc=susie.li@intel.com \
--cc=tglx@linutronix.de \
--cc=vkuznets@redhat.com \
--cc=wanpengli@tencent.com \
--cc=x86@kernel.org \
--cc=yu.c.zhang@linux.intel.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;
as well as URLs for NNTP newsgroup(s).