From: Marcelo Tosatti <mtosatti@redhat.com>
To: Takuya Yoshikawa <takuya.yoshikawa@gmail.com>
Cc: avi@redhat.com, kvm@vger.kernel.org,
yoshikawa.takuya@oss.ntt.co.jp, mingo@elte.hu
Subject: Re: [PATCH v3 1/3] KVM: MMU: Clean up the error handling of walk_addr_generic()
Date: Wed, 22 Jun 2011 13:46:58 -0300 [thread overview]
Message-ID: <20110622164658.GA23842@amt.cnet> (raw)
In-Reply-To: <20110620232947.83d016d3.takuya.yoshikawa@gmail.com>
On Mon, Jun 20, 2011 at 11:29:47PM +0900, Takuya Yoshikawa wrote:
> From: Takuya Yoshikawa <yoshikawa.takuya@oss.ntt.co.jp>
>
> Avoid two step jump to the error handling part. This eliminates the use
> of the variables present and rsvd_fault.
>
> We also use the const type qualifier to show that write/user/fetch_fault
> do not change in the function.
>
> Both of these were suggested by Ingo Molnar.
>
> Cc: Ingo Molnar <mingo@elte.hu>
> Signed-off-by: Takuya Yoshikawa <yoshikawa.takuya@oss.ntt.co.jp>
> ---
> v2-v3: only changelog update
>
> arch/x86/kvm/paging_tmpl.h | 64 +++++++++++++++++++------------------------
> 1 files changed, 28 insertions(+), 36 deletions(-)
>
> diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
> index 1caeb4d..137aa45 100644
> --- a/arch/x86/kvm/paging_tmpl.h
> +++ b/arch/x86/kvm/paging_tmpl.h
> @@ -125,18 +125,17 @@ static int FNAME(walk_addr_generic)(struct guest_walker *walker,
> gfn_t table_gfn;
> unsigned index, pt_access, uninitialized_var(pte_access);
> gpa_t pte_gpa;
> - bool eperm, present, rsvd_fault;
> - int offset, write_fault, user_fault, fetch_fault;
> -
> - write_fault = access & PFERR_WRITE_MASK;
> - user_fault = access & PFERR_USER_MASK;
> - fetch_fault = access & PFERR_FETCH_MASK;
> + bool eperm;
> + int offset;
> + const int write_fault = access & PFERR_WRITE_MASK;
> + const int user_fault = access & PFERR_USER_MASK;
> + const int fetch_fault = access & PFERR_FETCH_MASK;
> + u16 errcode = 0;
>
> trace_kvm_mmu_pagetable_walk(addr, write_fault, user_fault,
> fetch_fault);
> walk:
> - present = true;
> - eperm = rsvd_fault = false;
> + eperm = false;
> walker->level = mmu->root_level;
> pte = mmu->get_cr3(vcpu);
>
> @@ -145,7 +144,7 @@ walk:
> pte = kvm_pdptr_read_mmu(vcpu, mmu, (addr >> 30) & 3);
> trace_kvm_mmu_paging_element(pte, walker->level);
> if (!is_present_gpte(pte)) {
> - present = false;
> + errcode |= PFERR_PRESENT_MASK;
> goto error;
> }
> --walker->level;
> @@ -171,34 +170,34 @@ walk:
> real_gfn = mmu->translate_gpa(vcpu, gfn_to_gpa(table_gfn),
> PFERR_USER_MASK|PFERR_WRITE_MASK);
> if (unlikely(real_gfn == UNMAPPED_GVA)) {
> - present = false;
> - break;
> + errcode |= PFERR_PRESENT_MASK;
> + goto error;
> }
> real_gfn = gpa_to_gfn(real_gfn);
>
> host_addr = gfn_to_hva(vcpu->kvm, real_gfn);
> if (unlikely(kvm_is_error_hva(host_addr))) {
> - present = false;
> - break;
> + errcode |= PFERR_PRESENT_MASK;
> + goto error;
> }
>
> ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
> if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte)))) {
> - present = false;
> - break;
> + errcode |= PFERR_PRESENT_MASK;
> + goto error;
> }
>
> trace_kvm_mmu_paging_element(pte, walker->level);
>
> if (unlikely(!is_present_gpte(pte))) {
> - present = false;
> - break;
> + errcode |= PFERR_PRESENT_MASK;
> + goto error;
> }
Assignment of PFERR_PRESENT_MASK is inverted.
next prev parent reply other threads:[~2011-06-22 16:49 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-06-20 14:29 [PATCH v3 1/3] KVM: MMU: Clean up the error handling of walk_addr_generic() Takuya Yoshikawa
2011-06-20 14:31 ` [PATCH v3 2/3] KVM: MMU: Rename the walk label in walk_addr_generic() Takuya Yoshikawa
2011-06-20 14:34 ` [PATCH v3 3/3] KVM: MMU: Introduce is_last_gpte() to clean up walk_addr_generic() Takuya Yoshikawa
2011-06-22 16:46 ` Marcelo Tosatti [this message]
2011-06-22 17:05 ` [PATCH v3 1/3] KVM: MMU: Clean up the error handling of walk_addr_generic() 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=20110622164658.GA23842@amt.cnet \
--to=mtosatti@redhat.com \
--cc=avi@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=mingo@elte.hu \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox