From: Xiao Guangrong <xiaoguangrong@cn.fujitsu.com>
To: Avi Kivity <avi@redhat.com>
Cc: Marcelo Tosatti <mtosatti@redhat.com>,
LKML <linux-kernel@vger.kernel.org>,
KVM list <kvm@vger.kernel.org>
Subject: Re: [PATCH 1/5] KVM: MMU: introduce some macros to cleanup hlist traverseing
Date: Mon, 31 May 2010 10:00:37 +0800 [thread overview]
Message-ID: <4C031845.7040208@cn.fujitsu.com> (raw)
In-Reply-To: <4C026433.50602@redhat.com>
Avi Kivity wrote:
> On 05/30/2010 03:36 PM, Xiao Guangrong wrote:
>> Introduce for_each_gfn_sp(), for_each_gfn_indirect_sp() and
>> for_each_gfn_indirect_valid_sp() to cleanup hlist traverseing
>>
>> Signed-off-by: Xiao Guangrong<xiaoguangrong@cn.fujitsu.com>
>> ---
>> arch/x86/kvm/mmu.c | 129
>> ++++++++++++++++++++++------------------------------
>> 1 files changed, 54 insertions(+), 75 deletions(-)
>>
>> diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c
>> index 56f8c3c..84c705e 100644
>> --- a/arch/x86/kvm/mmu.c
>> +++ b/arch/x86/kvm/mmu.c
>> @@ -1200,6 +1200,22 @@ static void kvm_unlink_unsync_page(struct kvm
>> *kvm, struct kvm_mmu_page *sp)
>>
>> static int kvm_mmu_zap_page(struct kvm *kvm, struct kvm_mmu_page *sp);
>>
>> +#define for_each_gfn_sp(kvm, sp, gfn, pos, n) \
>> + hlist_for_each_entry_safe(sp, pos, n, \
>> + &kvm->arch.mmu_page_hash[kvm_page_table_hashfn(gfn)], hash_link)\
>> + if (sp->gfn == gfn)
>>
Avi,
Thanks for your review.
>
>
> if (...)
> for_each_gfn_sp(...)
> blah();
> else
> BUG();
>
> will break. Can do 'if ((sp)->gfn != (gfn)) ; else'.
>
> Or call functions from the for (;;) parameters to advance the cursor.
>
> (also use parentheses to protect macro arguments)
>
Yeah, it's my mistake, i'll fix it in the next version.
>
>
>> +
>> +#define for_each_gfn_indirect_sp(kvm, sp, gfn, pos, n) \
>> + hlist_for_each_entry_safe(sp, pos, n, \
>> + &kvm->arch.mmu_page_hash[kvm_page_table_hashfn(gfn)], hash_link)\
>> + if (sp->gfn == gfn&& !sp->role.direct)
>> +
>> +#define for_each_gfn_indirect_valid_sp(kvm, sp, gfn, pos, n) \
>> + hlist_for_each_entry_safe(sp, pos, n, \
>> + &kvm->arch.mmu_page_hash[kvm_page_table_hashfn(gfn)], hash_link)\
>> + if (sp->gfn == gfn&& !sp->role.direct&& \
>> + !sp->role.invalid)
>>
>
> Shouldn't we always skip invalid gfns?
Actually, in kvm_mmu_unprotect_page() function, it need find out
invalid shadow pages:
| hlist_for_each_entry_safe(sp, node, n, bucket, hash_link)
| if (sp->gfn == gfn && !sp->role.direct) {
| pgprintk("%s: gfn %lx role %x\n", __func__, gfn,
| sp->role.word);
| r = 1;
| if (kvm_mmu_zap_page(kvm, sp))
| goto restart;
| }
I'm not sure whether we can skip invalid sp here, since it can change this
function's return value. :-(
> What about providing both gfn and role to the macro?
>
In current code, no code simply use role and gfn to find sp,
in kvm_mmu_get_page(), we need do other work for
'sp->gfn == gfn && sp->role != role' sp, and other functions only need compare
some members in role, but not all members.
Xiao
next prev parent reply other threads:[~2010-05-31 2:04 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-05-30 12:36 [PATCH 1/5] KVM: MMU: introduce some macros to cleanup hlist traverseing Xiao Guangrong
2010-05-30 12:37 ` [PATCH 2/5] KVM: MMU: split the operations of kvm_mmu_zap_page() Xiao Guangrong
2010-05-30 13:16 ` Avi Kivity
2010-05-31 2:13 ` Xiao Guangrong
2010-05-31 11:05 ` Avi Kivity
2010-06-01 2:29 ` Xiao Guangrong
2010-06-01 8:08 ` Avi Kivity
2010-05-30 12:39 ` [PATCH 3/5] KVM: MMU: gather remote tlb flush which occurs during page zapped Xiao Guangrong
2010-05-30 12:40 ` [PATCH 4/5] KVM: MMU: traverse sp hlish safely Xiao Guangrong
2010-05-30 12:42 ` [PATCH 5/5] KVM: MMU: reduce remote tlb flush in kvm_mmu_pte_write() Xiao Guangrong
2010-05-30 13:12 ` [PATCH 1/5] KVM: MMU: introduce some macros to cleanup hlist traverseing Avi Kivity
2010-05-31 2:00 ` Xiao Guangrong [this message]
2010-05-31 11:14 ` Avi Kivity
2010-06-01 2:38 ` Xiao Guangrong
2010-06-01 8:09 ` 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=4C031845.7040208@cn.fujitsu.com \
--to=xiaoguangrong@cn.fujitsu.com \
--cc=avi@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mtosatti@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