public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Chao Gao <chao.gao@intel.com>
To: <isaku.yamahata@intel.com>
Cc: <kvm@vger.kernel.org>, <isaku.yamahata@gmail.com>,
	<linux-kernel@vger.kernel.org>,
	Sean Christopherson <seanjc@google.com>,
	Paolo Bonzini <pbonzini@redhat.com>,
	Michael Roth <michael.roth@amd.com>,
	David Matlack <dmatlack@google.com>,
	Federico Parola <federico.parola@polito.it>,
	Kai Huang <kai.huang@intel.com>
Subject: Re: [PATCH v2 06/10] KVM: x86: Implement kvm_arch_vcpu_map_memory()
Date: Wed, 17 Apr 2024 15:20:55 +0800	[thread overview]
Message-ID: <Zh94V8ochIXEkO17@chao-email> (raw)
In-Reply-To: <7138a3bc00ea8d3cbe0e59df15f8c22027005b59.1712785629.git.isaku.yamahata@intel.com>

On Wed, Apr 10, 2024 at 03:07:32PM -0700, isaku.yamahata@intel.com wrote:
>From: Isaku Yamahata <isaku.yamahata@intel.com>
>
>Wire KVM_MAP_MEMORY ioctl to kvm_mmu_map_tdp_page() to populate guest
>memory.  When KVM_CREATE_VCPU creates vCPU, it initializes the x86
>KVM MMU part by kvm_mmu_create() and kvm_init_mmu().  vCPU is ready to
>invoke the KVM page fault handler.
>
>Signed-off-by: Isaku Yamahata <isaku.yamahata@intel.com>
>---
>v2:
>- Catch up the change of struct kvm_memory_mapping. (Sean)
>- Removed mapping level check. Push it down into vendor code. (David, Sean)
>- Rename goal_level to level. (Sean)
>- Drop kvm_arch_pre_vcpu_map_memory(), directly call kvm_mmu_reload().
>  (David, Sean)
>- Fixed the update of mapping.
>---
> arch/x86/kvm/x86.c | 30 ++++++++++++++++++++++++++++++
> 1 file changed, 30 insertions(+)
>
>diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
>index 2d2619d3eee4..2c765de3531e 100644
>--- a/arch/x86/kvm/x86.c
>+++ b/arch/x86/kvm/x86.c
>@@ -4713,6 +4713,7 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext)
> 	case KVM_CAP_VM_DISABLE_NX_HUGE_PAGES:
> 	case KVM_CAP_IRQFD_RESAMPLE:
> 	case KVM_CAP_MEMORY_FAULT_INFO:
>+	case KVM_CAP_MAP_MEMORY:
> 		r = 1;
> 		break;
> 	case KVM_CAP_EXIT_HYPERCALL:
>@@ -5867,6 +5868,35 @@ static int kvm_vcpu_ioctl_enable_cap(struct kvm_vcpu *vcpu,
> 	}
> }
> 
>+int kvm_arch_vcpu_map_memory(struct kvm_vcpu *vcpu,
>+			     struct kvm_memory_mapping *mapping)
>+{
>+	u64 end, error_code = 0;
>+	u8 level = PG_LEVEL_4K;

IIUC, no need to initialize @level here.

>+	int r;
>+
>+	/*
>+	 * Shadow paging uses GVA for kvm page fault.  The first implementation
>+	 * supports GPA only to avoid confusion.
>+	 */
>+	if (!tdp_enabled)
>+		return -EOPNOTSUPP;

This check duplicates the one for vcpu->arch.mmu->page_fault() in patch 5.

>+
>+	/* reload is optimized for repeated call. */
>+	kvm_mmu_reload(vcpu);
>+
>+	r = kvm_tdp_map_page(vcpu, mapping->base_address, error_code, &level);
>+	if (r)
>+		return r;
>+
>+	/* mapping->base_address is not necessarily aligned to level-hugepage. */
>+	end = (mapping->base_address & KVM_HPAGE_MASK(level)) +
>+		KVM_HPAGE_SIZE(level);

maybe
	end = ALIGN(mapping->base_address, KVM_HPAGE_SIZE(level));

>+	mapping->size -= end - mapping->base_address;
>+	mapping->base_address = end;
>+	return r;
>+}
>+
> long kvm_arch_vcpu_ioctl(struct file *filp,
> 			 unsigned int ioctl, unsigned long arg)
> {
>-- 
>2.43.2
>
>

  parent reply	other threads:[~2024-04-17  7:21 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-10 22:07 [PATCH v2 00/10] KVM: Guest Memory Pre-Population API isaku.yamahata
2024-04-10 22:07 ` [PATCH v2 01/10] KVM: Document KVM_MAP_MEMORY ioctl isaku.yamahata
2024-04-15 23:27   ` Edgecombe, Rick P
2024-04-15 23:47     ` Isaku Yamahata
2024-04-17 11:56     ` Paolo Bonzini
2024-04-10 22:07 ` [PATCH v2 02/10] KVM: Add KVM_MAP_MEMORY vcpu ioctl to pre-populate guest memory isaku.yamahata
2024-04-16 14:20   ` Edgecombe, Rick P
2024-04-10 22:07 ` [PATCH v2 03/10] KVM: x86/mmu: Extract __kvm_mmu_do_page_fault() isaku.yamahata
2024-04-16  8:22   ` Chao Gao
2024-04-16 23:43     ` Isaku Yamahata
2024-04-16 14:36   ` Edgecombe, Rick P
2024-04-16 23:52     ` Isaku Yamahata
2024-04-17 15:41       ` Paolo Bonzini
2024-04-10 22:07 ` [PATCH v2 04/10] KVM: x86/mmu: Make __kvm_mmu_do_page_fault() return mapped level isaku.yamahata
2024-04-16 14:40   ` Edgecombe, Rick P
2024-04-16 23:59     ` Isaku Yamahata
2024-04-10 22:07 ` [PATCH v2 05/10] KVM: x86/mmu: Introduce kvm_tdp_map_page() to populate guest memory isaku.yamahata
2024-04-16 14:46   ` Edgecombe, Rick P
2024-04-17 18:39     ` Isaku Yamahata
2024-04-17  7:04   ` Chao Gao
2024-04-17 18:44     ` Isaku Yamahata
2024-04-10 22:07 ` [PATCH v2 06/10] KVM: x86: Implement kvm_arch_vcpu_map_memory() isaku.yamahata
2024-04-16 15:12   ` Edgecombe, Rick P
2024-04-17  7:20   ` Chao Gao [this message]
2024-04-17 12:18   ` Paolo Bonzini
2024-04-10 22:07 ` [PATCH v2 07/10] KVM: x86: Always populate L1 GPA for KVM_MAP_MEMORY isaku.yamahata
2024-04-15 19:12   ` Edgecombe, Rick P
2024-04-15 21:17     ` Sean Christopherson
2024-04-15 21:36       ` Edgecombe, Rick P
2024-04-15 22:59         ` Sean Christopherson
2024-04-16  1:49       ` Isaku Yamahata
2024-04-16 14:22         ` Sean Christopherson
2024-04-16 21:41       ` Paolo Bonzini
2024-04-16 23:00         ` Sean Christopherson
2024-04-17 10:28           ` Paolo Bonzini
2024-04-15 19:37   ` Edgecombe, Rick P
2024-04-16 17:11   ` Edgecombe, Rick P
2024-04-10 22:07 ` [PATCH v2 08/10] KVM: x86: Add a hook in kvm_arch_vcpu_map_memory() isaku.yamahata
2024-04-16 14:57   ` Edgecombe, Rick P
2024-04-17 12:26   ` Paolo Bonzini
2024-04-10 22:07 ` [PATCH v2 09/10] KVM: SVM: Implement pre_mmu_map_page() to refuse KVM_MAP_MEMORY isaku.yamahata
2024-04-10 22:07 ` [PATCH v2 10/10] KVM: selftests: x86: Add test for KVM_MAP_MEMORY isaku.yamahata

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=Zh94V8ochIXEkO17@chao-email \
    --to=chao.gao@intel.com \
    --cc=dmatlack@google.com \
    --cc=federico.parola@polito.it \
    --cc=isaku.yamahata@gmail.com \
    --cc=isaku.yamahata@intel.com \
    --cc=kai.huang@intel.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=michael.roth@amd.com \
    --cc=pbonzini@redhat.com \
    --cc=seanjc@google.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