From: Gleb Natapov <gleb@redhat.com>
To: Chris Metcalf <cmetcalf@tilera.com>
Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org,
Paolo Bonzini <pbonzini@redhat.com>,
Jan Kiszka <jan.kiszka@siemens.com>
Subject: Re: [PATCH v3 1/3] tile: support KVM host mode
Date: Tue, 1 Oct 2013 18:21:26 +0300 [thread overview]
Message-ID: <20131001152126.GP11993@redhat.com> (raw)
In-Reply-To: <5249DAE6.5030808@tilera.com>
On Mon, Sep 30, 2013 at 04:11:18PM -0400, Chris Metcalf wrote:
> On 9/10/2013 6:53 AM, Gleb Natapov wrote:
> > On Wed, Aug 28, 2013 at 03:45:50PM -0400, Chris Metcalf wrote:
> >> This commit enables the host side of KVM support for tilegx.
> >>
> >> [...]
> >>
> >> The commit adds a KVM_EXIT_xxx code, KVM_EXIT_AGAIN, which is used to
> >> exit out to the host kernel, but not all the way out to qemu. This is
> >> helpful if we are trying to handle resched, sigpending, etc., but don't
> >> need to end up back in userspace first.
> >>
> > I think there is a confusion here on how things suppose to work.
> > KVM_EXIT_xxx defines are only meant to be meaningful to userspace, they
> > are never used internally by KVM. So KVM_EXIT_AGAIN, as defined above,
> > does not make sense.
>
> Fair enough; we can certainly arrange for the same semantics without
> exposing a magic value in the user API.
>
>
> > Looking at the code I see that you've reused those
> > defines for vmexit codes too and this is incorrect. On platform with HW
> > virt support vmexit codes are defined by CPU architecture (and there are
> > much more of vmexit codes that userspace exit codes), PV define their own
> > interface.
>
> I'm not clear on what you're suggesting with this comment. We do have a
> kvm_trigger_vmexit() function that takes a KVM_EXIT_xxx value and stuffs
> it into kvm_run.exit_reason. But since we are PV and don't have separate
> hardware-defined values, this seems like the right approach. We effectively
> borrow the KVM_EXIT_xxx codes for our vmexit codes. Why not?
>
Experience shows that there are much more reasons for vmexits than
reasons to exit to userspace. Even with your initial implementation here
you found that you need KVM_EXIT_AGAIN, but going forward you may find
out you need more and more vmexit reasons and we will not define new
KVM_EXIT_xxx for that. The main loop logic usually looks like that:
while (r != exit_user) {
enter_guest_mode();
vmexit = get_vmexit_reason();
switch (vmexit) {
case A:
break;
case B:
break;
case C:
if (need_userspace_attention())
kvm_run.exit_reason = KVM_EXIT_xxx;
r = exit_user;
break;
}
}
> >> +void kvm_arch_commit_memory_region(struct kvm *kvm,
> >> + struct kvm_userspace_memory_region *mem,
> >> + const struct kvm_memory_slot *old,
> >> + enum kvm_mr_change change)
> >> +{
> >> + unsigned long gpa, address, pfn, i;
> >> + struct page *page[1];
> >> + pte_t *ptep, *vptep;
> >> +
> >> + gpa = mem->guest_phys_addr;
> >> + address = mem->userspace_addr;
> >> + for (i = 0; i < mem->memory_size;
> >> + i += PAGE_SIZE, gpa += PAGE_SIZE, address += PAGE_SIZE) {
> >> + vptep = get_vpgd_pte(kvm, gpa);
> >> + BUG_ON(vptep == NULL);
> >> + get_user_pages_fast(address, 1, 1, page);
> > get_user_pages_fast() can fail and you do not handle an error. Do I
> > understand correctly that all guest memory is pinned here? Where is it
> > unpinned? I do not see put_page anywhere.
>
> Yes, we're pinning all of user memory here; this deserves more of
> a comment than is in the code (i.e. none), but was done to simplify
> our initial implementation of fast page faulting from the Tilera
> hypervisor. I'll review this all more closely for the next version
> of the patch set.
OK. Pinning pages is OK, what puzzled me is that I haven't found where
they unpinned.
>
> > +int kvm_arch_vcpu_ioctl_set_sregs(struct kvm_vcpu *vcpu,
> > + struct kvm_sregs *sregs)
> > +{
> > + vcpu->arch.sregs = *sregs;
> > + return 0;
> > +}
> > Most arches prefer to use KVM_GET_ONE_REG/KVM_SET_ONE_REG interface
> > to get/set all vcpu registers since the interface is more flexible, but
> > the way you are doing it is OK too.
>
> We can certainly provide both interfaces. For the time being,
> the way we're using it from qemu works best with SET_SREGS since we
> just set a bunch of SPRs at once. Or maybe we just don't care in
> the kernel until we have a client that actually wants the ONE_REG APIs?
>
Fine with me, just pointed out the alternative.
> >> +int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu)
> >> +{
> >> + int i;
> >> + unsigned long resv_gfn_start;
> >> + struct kvm_memory_slot *s;
> >> + struct kvm *kvm = vcpu->kvm;
> >> +
> >> + if (!kvm->arch.resv_gpa_start) {
> >> + resv_gfn_start = 0;
> >> +
> >> + for (i = 0; i < KVM_USER_MEM_SLOTS; i++) {
> >> + s = &kvm->memslots->memslots[i];
> > Slots can be added or removed after vcpu is created. And of course
> > kvm->srcu comment applies. Memslot can be KVM_MEMSLOT_INVALID if it is
> > in the process of been deleted, so you have to check this too, but
> > probably it is better for userspace to set resv_gpa_start instead of
> > kernel trying to figure it out here.
>
> We are really just trying to get an illegal PA here. We could probably
> just use PA values starting at the highest legal value and work down
> from there intead.
>
OK. But making userspace configuring it may be even easier. After all
userspace is the one who defines memory layout. X86 has similar things
where userspace configures available PA address for KVM to use.
--
Gleb.
next prev parent reply other threads:[~2013-10-01 15:21 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-08-12 15:24 [PATCH] tile: support KVM for tilegx Chris Metcalf
2013-08-12 17:08 ` Jan Kiszka
2013-08-12 20:24 ` [PATCH v2] " Chris Metcalf
2013-08-25 11:39 ` Gleb Natapov
2013-08-26 1:26 ` Chris Metcalf
2013-08-26 12:04 ` Gleb Natapov
2013-08-28 19:45 ` [PATCH v3 1/3] tile: support KVM host mode Chris Metcalf
2013-09-10 10:53 ` Gleb Natapov
2013-09-10 11:59 ` Paolo Bonzini
2013-09-30 20:11 ` Chris Metcalf
2013-10-01 15:21 ` Gleb Natapov [this message]
2013-08-28 20:57 ` [PATCH v3 2/3] tile: enable building as a paravirtualized KVM_GUEST Chris Metcalf
2013-08-28 20:58 ` [PATCH v3 3/3] tile: enable VIRTIO support for KVM Chris Metcalf
2013-09-10 12:47 ` Paolo Bonzini
2013-09-30 20:11 ` Chris Metcalf
2013-10-01 6:39 ` Paolo Bonzini
2013-08-29 0:26 ` [PATCH v2] tile: support KVM for tilegx Chris Metcalf
2013-09-03 17:32 ` Chris Metcalf
2013-09-03 17:39 ` Gleb Natapov
2013-09-03 17:46 ` Chris Metcalf
2013-09-03 18:13 ` [PATCH 1/3] tile: clean up relocate_kernel_64 debug code Chris Metcalf
2013-09-03 18:41 ` [PATCH 3/3] tile: parameterize VA and PA space more cleanly Chris Metcalf
2013-09-03 18:45 ` [PATCH 2/3] tile: don't assume user privilege is zero Chris Metcalf
2013-09-03 19:09 ` [PATCH 0/3] tile prerequisites for KVM support Chris Metcalf
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=20131001152126.GP11993@redhat.com \
--to=gleb@redhat.com \
--cc=cmetcalf@tilera.com \
--cc=jan.kiszka@siemens.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pbonzini@redhat.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).