Re: [PATCH v2 09/13] KVM: x86: pass kvm_mmu_page to gfn_to_rmap

2015-06-17 Thread Xiao Guangrong



On 06/17/2015 04:15 PM, Paolo Bonzini wrote:



On 09/06/2015 05:28, Xiao Guangrong wrote:


-rmapp = gfn_to_rmap(kvm, sp->gfn, PT_PAGE_TABLE_LEVEL);
+slots = kvm_memslots(kvm);
+slot = __gfn_to_memslot(slots, sp->gfn);
+rmapp = __gfn_to_rmap(sp->gfn, PT_PAGE_TABLE_LEVEL, slot);



Why @sp is not available here?


Because the function forces the level to be PT_PAGE_TABLE_LEVEL rather
than sp->level.


Oh, right, thanks for your explanation. :)

Reviewed-by: Xiao Guangrong 
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v2 09/13] KVM: x86: pass kvm_mmu_page to gfn_to_rmap

2015-06-17 Thread Paolo Bonzini


On 09/06/2015 05:28, Xiao Guangrong wrote:
>>
>> -rmapp = gfn_to_rmap(kvm, sp->gfn, PT_PAGE_TABLE_LEVEL);
>> +slots = kvm_memslots(kvm);
>> +slot = __gfn_to_memslot(slots, sp->gfn);
>> +rmapp = __gfn_to_rmap(sp->gfn, PT_PAGE_TABLE_LEVEL, slot);
>>
> 
> Why @sp is not available here?

Because the function forces the level to be PT_PAGE_TABLE_LEVEL rather
than sp->level.

Paolo
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v2 09/13] KVM: x86: pass kvm_mmu_page to gfn_to_rmap

2015-06-08 Thread Xiao Guangrong



On 05/28/2015 01:05 AM, Paolo Bonzini wrote:

This is always available (with one exception in the auditing code).
Later we will also use the role to look up the right memslots array.



return;
@@ -191,11 +191,15 @@ static void audit_write_protection(struct kvm *kvm, 
struct kvm_mmu_page *sp)
unsigned long *rmapp;
u64 *sptep;
struct rmap_iterator iter;
+   struct kvm_memslots *slots;
+   struct kvm_memory_slot *slot;

if (sp->role.direct || sp->unsync || sp->role.invalid)
return;

-   rmapp = gfn_to_rmap(kvm, sp->gfn, PT_PAGE_TABLE_LEVEL);
+   slots = kvm_memslots(kvm);
+   slot = __gfn_to_memslot(slots, sp->gfn);
+   rmapp = __gfn_to_rmap(sp->gfn, PT_PAGE_TABLE_LEVEL, slot);



Why @sp is not available here?
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2 09/13] KVM: x86: pass kvm_mmu_page to gfn_to_rmap

2015-05-27 Thread Paolo Bonzini
This is always available (with one exception in the auditing code).
Later we will also use the role to look up the right memslots array.

Signed-off-by: Paolo Bonzini 
---
v1->v2: new

 arch/x86/kvm/mmu.c   | 10 +-
 arch/x86/kvm/mmu_audit.c |  8 ++--
 2 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c
index deb8862cfd54..6ea24812007a 100644
--- a/arch/x86/kvm/mmu.c
+++ b/arch/x86/kvm/mmu.c
@@ -1043,12 +1043,12 @@ static unsigned long *__gfn_to_rmap(gfn_t gfn, int 
level,
 /*
  * Take gfn and return the reverse mapping to it.
  */
-static unsigned long *gfn_to_rmap(struct kvm *kvm, gfn_t gfn, int level)
+static unsigned long *gfn_to_rmap(struct kvm *kvm, gfn_t gfn, struct 
kvm_mmu_page *sp)
 {
struct kvm_memory_slot *slot;
 
slot = gfn_to_memslot(kvm, gfn);
-   return __gfn_to_rmap(gfn, level, slot);
+   return __gfn_to_rmap(gfn, sp->role.level, slot);
 }
 
 static bool rmap_can_add(struct kvm_vcpu *vcpu)
@@ -1066,7 +1066,7 @@ static int rmap_add(struct kvm_vcpu *vcpu, u64 *spte, 
gfn_t gfn)
 
sp = page_header(__pa(spte));
kvm_mmu_page_set_gfn(sp, spte - sp->spt, gfn);
-   rmapp = gfn_to_rmap(vcpu->kvm, gfn, sp->role.level);
+   rmapp = gfn_to_rmap(vcpu->kvm, gfn, sp);
return pte_list_add(vcpu, spte, rmapp);
 }
 
@@ -1078,7 +1078,7 @@ static void rmap_remove(struct kvm *kvm, u64 *spte)
 
sp = page_header(__pa(spte));
gfn = kvm_mmu_page_get_gfn(sp, spte - sp->spt);
-   rmapp = gfn_to_rmap(kvm, gfn, sp->role.level);
+   rmapp = gfn_to_rmap(kvm, gfn, sp);
pte_list_remove(spte, rmapp);
 }
 
@@ -1612,7 +1612,7 @@ static void rmap_recycle(struct kvm_vcpu *vcpu, u64 
*spte, gfn_t gfn)
 
sp = page_header(__pa(spte));
 
-   rmapp = gfn_to_rmap(vcpu->kvm, gfn, sp->role.level);
+   rmapp = gfn_to_rmap(vcpu->kvm, gfn, sp);
 
kvm_unmap_rmapp(vcpu->kvm, rmapp, NULL, gfn, sp->role.level, 0);
kvm_flush_remote_tlbs(vcpu->kvm);
diff --git a/arch/x86/kvm/mmu_audit.c b/arch/x86/kvm/mmu_audit.c
index 368d53497314..9d99f17aa3be 100644
--- a/arch/x86/kvm/mmu_audit.c
+++ b/arch/x86/kvm/mmu_audit.c
@@ -146,7 +146,7 @@ static void inspect_spte_has_rmap(struct kvm *kvm, u64 
*sptep)
return;
}
 
-   rmapp = gfn_to_rmap(kvm, gfn, rev_sp->role.level);
+   rmapp = gfn_to_rmap(kvm, gfn, rev_sp);
if (!*rmapp) {
if (!__ratelimit(&ratelimit_state))
return;
@@ -191,11 +191,15 @@ static void audit_write_protection(struct kvm *kvm, 
struct kvm_mmu_page *sp)
unsigned long *rmapp;
u64 *sptep;
struct rmap_iterator iter;
+   struct kvm_memslots *slots;
+   struct kvm_memory_slot *slot;
 
if (sp->role.direct || sp->unsync || sp->role.invalid)
return;
 
-   rmapp = gfn_to_rmap(kvm, sp->gfn, PT_PAGE_TABLE_LEVEL);
+   slots = kvm_memslots(kvm);
+   slot = __gfn_to_memslot(slots, sp->gfn);
+   rmapp = __gfn_to_rmap(sp->gfn, PT_PAGE_TABLE_LEVEL, slot);
 
for_each_rmap_spte(rmapp, &iter, sptep)
if (is_writable_pte(*sptep))
-- 
1.8.3.1


--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html