From: Ingo Molnar <mingo@elte.hu>
To: Takuya Yoshikawa <takuya.yoshikawa@gmail.com>
Cc: avi@redhat.com, mtosatti@redhat.com, kvm@vger.kernel.org,
yoshikawa.takuya@oss.ntt.co.jp
Subject: Re: [PATCH 4/4] KVM: MMU: Split out the main body of walk_addr_generic()
Date: Thu, 9 Jun 2011 16:18:01 +0200 [thread overview]
Message-ID: <20110609141801.GE21100@elte.hu> (raw)
In-Reply-To: <20110609230524.346b3d1c.takuya.yoshikawa@gmail.com>
* Takuya Yoshikawa <takuya.yoshikawa@gmail.com> wrote:
> +/*
> + * do_walk() returns one of these.
> + *
> + * WALK_NEXT: Continue the walk loop.
> + * WALK_DONE: Break from the walk loop.
> + * WALK_RETRY: Retry walk.
> + * WALK_NOT_PRESENT: Set PFERR_PRESENT_MASK and goto error.
> + * WALK_RSVD_FAULT: Set PFERR_RSVD_MASK and goto error.
> + * WALK_ERROR: Goto error.
> + * WALK_ABORT: Return immediately.
hm, this iterator turned out to be more complex than i thought it
would become. Avi, are you still happy with that?
> + if (!*eperm && unlikely(!(*pte & PT_ACCESSED_MASK))) {
> + int ret;
> +
> + trace_kvm_mmu_set_accessed_bit(table_gfn, index, sizeof(*pte));
> + ret = FNAME(cmpxchg_gpte)(vcpu, mmu, *ptep_user, index,
> + *pte, *pte|PT_ACCESSED_MASK);
> + if (unlikely(ret < 0))
> + return WALK_NOT_PRESENT;
> + else if (ret)
> + return WALK_RETRY;
> +
> + mark_page_dirty(vcpu->kvm, table_gfn);
> + *pte |= PT_ACCESSED_MASK;
> + }
This wants to move into a set-accessed-bit helper inline.
> + if ((walker->level == PT_PAGE_TABLE_LEVEL) ||
> + ((walker->level == PT_DIRECTORY_LEVEL) && is_large_pte(*pte) &&
> + (PTTYPE == 64 || is_pse(vcpu))) ||
> + ((walker->level == PT_PDPE_LEVEL) && is_large_pte(*pte) &&
> + (mmu->root_level == PT64_ROOT_LEVEL))) {
This condition wants to move into a is-pte-large inline function.
> + gpa_t real_gpa;
> + gfn_t gfn;
> + u32 ac;
> +
> + gfn = gpte_to_gfn_lvl(*pte, walker->level);
> + gfn += (addr & PT_LVL_OFFSET_MASK(walker->level)) >> PAGE_SHIFT;
> +
> + if (PTTYPE == 32 && (walker->level == PT_DIRECTORY_LEVEL) &&
> + is_cpuid_PSE36())
> + gfn += pse36_gfn_delta(*pte);
> +
> + ac = write_fault | fetch_fault | user_fault;
> +
> + real_gpa = mmu->translate_gpa(vcpu, gfn_to_gpa(gfn), ac);
> + if (real_gpa == UNMAPPED_GVA)
> + return WALK_ABORT;
> +
> + walker->gfn = real_gpa >> PAGE_SHIFT;
> +
> + return WALK_DONE;
And this would look cleaner if it was in a handle-large-pte inline function?
> + ret = FNAME(do_walk)(walker, vcpu, mmu, addr, access,
> + &eperm, &pte, &ptep_user);
> + switch (ret) {
> + case WALK_NEXT:
> + break;
> + case WALK_DONE:
> + goto walk_done;
> + case WALK_RETRY:
> + goto walk_retry;
> + case WALK_NOT_PRESENT:
> errcode |= PFERR_PRESENT_MASK;
> goto error;
> + case WALK_RSVD_FAULT:
> errcode |= PFERR_RSVD_MASK;
> goto error;
> + case WALK_ERROR:
> + goto error;
> + case WALK_ABORT:
> + return 0;
Btw., there's a stylistic trick you could use here to make the
iteration logic even clearer:
switch (ret) {
case WALK_NEXT: break;
case WALK_DONE: goto walk_done;
case WALK_RETRY: goto walk_retry;
case WALK_NOT_PRESENT: errcode |= PFERR_PRESENT_MASK; goto error;
case WALK_RSVD_FAULT: errcode |= PFERR_RSVD_MASK; goto error;
case WALK_ERROR: goto error;
case WALK_ABORT: return 0;
}
But it's a pure matter of taste - it might not really fit into KVM
code. Avi's call :-)
Thanks,
Ingo
next prev parent reply other threads:[~2011-06-09 14:18 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-06-09 13:59 [PATCH 0/4] KVM: MMU: Clean up walk_addr_generic() Takuya Yoshikawa
2011-06-09 14:01 ` [PATCH 1/4] KVM: MMU: Clean up the error handling of walk_addr_generic() Takuya Yoshikawa
2011-06-12 15:45 ` Avi Kivity
2011-06-09 14:02 ` [PATCH 2/4] KVM: MMU: Move some variables into the walk loop Takuya Yoshikawa
2011-06-09 14:03 ` [PATCH 3/4] KVM: MMU: Update walker->pt/pte_access directly Takuya Yoshikawa
2011-06-09 14:05 ` [PATCH 4/4] KVM: MMU: Split out the main body of walk_addr_generic() Takuya Yoshikawa
2011-06-09 14:18 ` Ingo Molnar [this message]
2011-06-12 15:47 ` 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=20110609141801.GE21100@elte.hu \
--to=mingo@elte.hu \
--cc=avi@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=mtosatti@redhat.com \
--cc=takuya.yoshikawa@gmail.com \
--cc=yoshikawa.takuya@oss.ntt.co.jp \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.