public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Christoffer Dall <cdall@cs.columbia.edu>
To: Avi Kivity <avi@redhat.com>
Cc: catalin.marinas@arm.com, android-virt@lists.cs.columbia.edu,
	s.raho@virtualopensystems.com, a.motakis@virtualopensystems.com,
	kvm@vger.kernel.org, a.costa@virtualopensystems.com
Subject: Re: [PATCH v3 7/8] ARM: KVM: Handle guest faults in KVM
Date: Sat, 11 Jun 2011 12:37:01 +0200	[thread overview]
Message-ID: <BANLkTimd2mCu2htV8aDZQGtkvLDTK5__ew@mail.gmail.com> (raw)
In-Reply-To: <4DEB7B10.2070304@redhat.com>

On Sun, Jun 5, 2011 at 2:48 PM, Avi Kivity <avi@redhat.com> wrote:
> On 06/03/2011 06:04 PM, Christoffer Dall wrote:
>>
>> Handles the guest faults in KVM by mapping in corresponding user pages
>> in the 2nd stage page tables.
>>
>>
>>
>> +static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa,
>> +                         gfn_t gfn, struct kvm_memory_slot *memslot)
>> +{
>> +       pfn_t pfn;
>> +       pgd_t *pgd;
>> +       pmd_t *pmd;
>> +       pte_t *pte, new_pte;
>> +
>> +       pfn = gfn_to_pfn(vcpu->kvm, gfn);
>> +
>> +       if (is_error_pfn(pfn)) {
>> +               kvm_err(-EFAULT, "Guest gfn %u (0x%08lx) does not have "
>> +                               "corresponding host mapping",
>> +                               gfn, gfn<<  PAGE_SHIFT);
>> +               return -EFAULT;
>> +       }
>> +
>> +       /* Create 2nd stage page table mapping - Level 1 */
>> +       pgd = vcpu->kvm->arch.pgd + pgd_index(fault_ipa);
>> +       if (pgd_none(*pgd)) {
>> +               pmd = pmd_alloc_one(NULL, fault_ipa);
>> +               if (!pmd) {
>> +                       kvm_err(-ENOMEM, "Cannot allocate 2nd stage pmd");
>> +                       return -ENOMEM;
>> +               }
>> +               pgd_populate(NULL, pgd, pmd);
>> +               pmd += pmd_index(fault_ipa);
>> +       } else
>> +               pmd = pmd_offset(pgd, fault_ipa);
>> +
>> +       /* Create 2nd stage page table mapping - Level 2 */
>> +       if (pmd_none(*pmd)) {
>> +               pte = pte_alloc_one_kernel(NULL, fault_ipa);
>> +               if (!pte) {
>> +                       kvm_err(-ENOMEM, "Cannot allocate 2nd stage pte");
>> +                       return -ENOMEM;
>> +               }
>> +               pmd_populate_kernel(NULL, pmd, pte);
>> +               pte += pte_index(fault_ipa);
>> +       } else
>> +               pte = pte_offset_kernel(pmd, fault_ipa);
>> +
>> +       /* Create 2nd stage page table mapping - Level 3 */
>> +       new_pte = pfn_pte(pfn, PAGE_KVM_GUEST);
>> +       set_pte_ext(pte, new_pte, 0);
>> +
>> +       return 0;
>> +}
>> +
>> +#define HSR_ABT_FS     (0x3f)
>> +#define HPFAR_MASK     (~0xf)
>>  int kvm_handle_guest_abort(struct kvm_vcpu *vcpu, struct kvm_run *run)
>>  {
>> +       unsigned long hsr_ec;
>> +       unsigned long fault_status;
>> +       phys_addr_t fault_ipa;
>> +       struct kvm_memory_slot *memslot = NULL;
>> +       bool is_iabt;
>> +       gfn_t gfn;
>> +
>> +       hsr_ec = vcpu->arch.hsr>>  HSR_EC_SHIFT;
>> +       is_iabt = (hsr_ec == HSR_EC_IABT);
>> +
>> +       /* Check that the second stage fault is a translation fault */
>> +       fault_status = vcpu->arch.hsr&  HSR_ABT_FS;
>> +       if ((fault_status&  0x3c) != 0x4) {
>> +               kvm_err(-EFAULT, "Unsupported fault status: %x",
>> +                               fault_status&  0x3c);
>> +               return -EFAULT;
>> +       }
>> +
>> +       fault_ipa = ((phys_addr_t)vcpu->arch.hpfar&  HPFAR_MASK)<<  8;
>> +
>> +       gfn = fault_ipa>>  PAGE_SHIFT;
>> +       if (!kvm_is_visible_gfn(vcpu->kvm, gfn))
>> +               goto io_mem_abort;
>> +
>> +       memslot = gfn_to_memslot(vcpu->kvm, gfn);
>> +       if (memslot->user_alloc)
>> +               return user_mem_abort(vcpu, fault_ipa, gfn, memslot);
>
> Non-user_alloc should not exist for ARM (and are not supported for x86 these
> days, except for a few implementation internal slots).

ok, I raise an error in when (!memslot->user_alloc) instead now. thanks.

>
>> +
>> +io_mem_abort:
>> +       if (is_iabt) {
>> +               kvm_err(-EFAULT, "Inst. abort on I/O address");
>> +               return -EFAULT;
>> +       }
>> +
>> +       kvm_msg("I/O address abort...");
>>        KVMARM_NOT_IMPLEMENTED();
>>        return -EINVAL;
>>  }
>
> Okay, this is about a zillion times simpler than x86.  Congratulations.

Well, I need to handle the I/O aborts, but it's quite simple. What
makes it much more complicated on x86?

>
> What are your thoughts about mmu notifier support?

For what purpose? There is no swapping on ARM, so only case that jumps
to my mind is for KSM. And I'm not quite there yet :)

  reply	other threads:[~2011-06-11 10:37 UTC|newest]

Thread overview: 58+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-06-03 15:03 [PATCH v3 1/8] ARM: KVM: Initial skeleton to compile KVM support Christoffer Dall
2011-06-03 15:03 ` [PATCH v3 2/8] ARM: KVM: Hypervisor identity mapping Christoffer Dall
2011-06-03 15:03 ` [PATCH v3 3/8] ARM: KVM: Add hypervisor inititalization Christoffer Dall
2011-06-03 15:03 ` [PATCH v3 4/8] ARM: KVM: Memory virtualization setup Christoffer Dall
2011-06-05 12:41   ` Avi Kivity
2011-06-05 14:50     ` Christoffer Dall
2011-06-05 14:53       ` Avi Kivity
2011-06-05 15:14         ` Avi Kivity
2011-06-05 15:27           ` Christoffer Dall
2011-06-05 16:02             ` Avi Kivity
2011-06-03 15:03 ` [PATCH v3 5/8] ARM: KVM: World-switch implementation Christoffer Dall
2011-06-03 15:04 ` [PATCH v3 6/8] ARM: KVM: Emulation framework and CP15 emulation Christoffer Dall
2011-06-03 15:04 ` [PATCH v3 7/8] ARM: KVM: Handle guest faults in KVM Christoffer Dall
2011-06-05 12:48   ` Avi Kivity
2011-06-11 10:37     ` Christoffer Dall [this message]
2011-06-12  8:24       ` Avi Kivity
2011-06-12  8:57         ` Christoffer Dall
2011-06-03 15:04 ` [PATCH v3 8/8] ARM: KVM: Handle I/O aborts Christoffer Dall
2011-06-03 15:31 ` [PATCH v3 1/8] ARM: KVM: Initial skeleton to compile KVM support Jan Kiszka
2011-06-03 15:53   ` Jan Kiszka
2011-06-03 16:19     ` Christoffer Dall
2011-06-03 16:31       ` [Android-virt] " Alexander Graf
2011-06-04 14:13     ` Alexander Graf
2011-06-05 12:21     ` Avi Kivity
2011-06-05 14:13       ` Jan Kiszka
2011-06-05 14:18         ` Avi Kivity
2011-06-05 14:58           ` Jan Kiszka
2011-06-05 15:10             ` Avi Kivity
2011-06-05 15:14               ` Jan Kiszka
2011-06-05 15:18                 ` Avi Kivity
2011-06-05 16:25                 ` Christoffer Dall
2011-06-05 16:28                   ` Avi Kivity
2011-06-05 16:30                     ` [Android-virt] " Alexander Graf
2011-06-05 16:33                       ` Avi Kivity
2011-06-05 17:19                         ` Alexander Graf
2011-06-05 17:48                           ` Jan Kiszka
2011-06-05 17:54                             ` Alexander Graf
2011-06-05 17:56                               ` Jan Kiszka
2011-06-05 18:00                                 ` Alexander Graf
2011-06-05 18:04                                   ` Jan Kiszka
2011-06-05 18:12                                     ` Alexander Graf
2011-06-05 18:19                                       ` Jan Kiszka
2011-06-06  7:42                               ` Avi Kivity
2011-06-06  7:41                           ` Avi Kivity
2011-06-05 16:24             ` Christoffer Dall
2011-06-05 16:31               ` Avi Kivity
2011-06-05 12:36 ` Avi Kivity
2011-06-05 16:03   ` Christoffer Dall
2011-06-05 16:06     ` Avi Kivity
     [not found]     ` <211B3F42-9B68-41BB-B1FA-348B5500C60A@suse.de>
2011-06-10  8:40       ` [Android-virt] " Christoffer Dall
2011-06-10  9:23         ` Catalin Marinas
2011-06-10  9:53           ` Alexander Graf
2011-06-10  9:58             ` Catalin Marinas
2011-06-10 11:56               ` Christoffer Dall
2011-06-05 12:52 ` Avi Kivity
2011-06-05 14:00   ` Avi Kivity
2011-06-05 14:13     ` Christoffer Dall
2011-06-05 14:18       ` Avi Kivity

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=BANLkTimd2mCu2htV8aDZQGtkvLDTK5__ew@mail.gmail.com \
    --to=cdall@cs.columbia.edu \
    --cc=a.costa@virtualopensystems.com \
    --cc=a.motakis@virtualopensystems.com \
    --cc=android-virt@lists.cs.columbia.edu \
    --cc=avi@redhat.com \
    --cc=catalin.marinas@arm.com \
    --cc=kvm@vger.kernel.org \
    --cc=s.raho@virtualopensystems.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