2010-06-30 17:18:45 +04:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2010 SUSE Linux Products GmbH. All rights reserved.
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Alexander Graf <agraf@suse.de>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License, version 2, as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/kvm_host.h>
|
|
|
|
#include <linux/hash.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
|
|
|
|
#include <asm/kvm_ppc.h>
|
|
|
|
#include <asm/kvm_book3s.h>
|
|
|
|
#include <asm/machdep.h>
|
|
|
|
#include <asm/mmu_context.h>
|
|
|
|
#include <asm/hw_irq.h>
|
|
|
|
|
2013-10-07 20:47:57 +04:00
|
|
|
#include "trace_pr.h"
|
2011-06-29 04:17:33 +04:00
|
|
|
|
2010-06-30 17:18:45 +04:00
|
|
|
#define PTE_SIZE 12
|
|
|
|
|
|
|
|
static struct kmem_cache *hpte_cache;
|
|
|
|
|
|
|
|
static inline u64 kvmppc_mmu_hash_pte(u64 eaddr)
|
|
|
|
{
|
|
|
|
return hash_64(eaddr >> PTE_SIZE, HPTEG_HASH_BITS_PTE);
|
|
|
|
}
|
|
|
|
|
2010-07-29 17:04:19 +04:00
|
|
|
static inline u64 kvmppc_mmu_hash_pte_long(u64 eaddr)
|
|
|
|
{
|
|
|
|
return hash_64((eaddr & 0x0ffff000) >> PTE_SIZE,
|
|
|
|
HPTEG_HASH_BITS_PTE_LONG);
|
|
|
|
}
|
|
|
|
|
2010-06-30 17:18:45 +04:00
|
|
|
static inline u64 kvmppc_mmu_hash_vpte(u64 vpage)
|
|
|
|
{
|
|
|
|
return hash_64(vpage & 0xfffffffffULL, HPTEG_HASH_BITS_VPTE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline u64 kvmppc_mmu_hash_vpte_long(u64 vpage)
|
|
|
|
{
|
|
|
|
return hash_64((vpage & 0xffffff000ULL) >> 12,
|
|
|
|
HPTEG_HASH_BITS_VPTE_LONG);
|
|
|
|
}
|
|
|
|
|
2013-09-20 08:52:44 +04:00
|
|
|
#ifdef CONFIG_PPC_BOOK3S_64
|
|
|
|
static inline u64 kvmppc_mmu_hash_vpte_64k(u64 vpage)
|
|
|
|
{
|
|
|
|
return hash_64((vpage & 0xffffffff0ULL) >> 4,
|
|
|
|
HPTEG_HASH_BITS_VPTE_64K);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-06-30 17:18:45 +04:00
|
|
|
void kvmppc_mmu_hpte_cache_map(struct kvm_vcpu *vcpu, struct hpte_cache *pte)
|
|
|
|
{
|
|
|
|
u64 index;
|
2011-06-29 04:17:33 +04:00
|
|
|
struct kvmppc_vcpu_book3s *vcpu3s = to_book3s(vcpu);
|
2010-06-30 17:18:45 +04:00
|
|
|
|
2010-08-02 14:51:07 +04:00
|
|
|
trace_kvm_book3s_mmu_map(pte);
|
|
|
|
|
2011-06-29 04:17:33 +04:00
|
|
|
spin_lock(&vcpu3s->mmu_lock);
|
2010-07-29 17:04:17 +04:00
|
|
|
|
2010-06-30 17:18:45 +04:00
|
|
|
/* Add to ePTE list */
|
|
|
|
index = kvmppc_mmu_hash_pte(pte->pte.eaddr);
|
2011-06-29 04:17:33 +04:00
|
|
|
hlist_add_head_rcu(&pte->list_pte, &vcpu3s->hpte_hash_pte[index]);
|
2010-06-30 17:18:45 +04:00
|
|
|
|
2010-07-29 17:04:19 +04:00
|
|
|
/* Add to ePTE_long list */
|
|
|
|
index = kvmppc_mmu_hash_pte_long(pte->pte.eaddr);
|
|
|
|
hlist_add_head_rcu(&pte->list_pte_long,
|
2011-06-29 04:17:33 +04:00
|
|
|
&vcpu3s->hpte_hash_pte_long[index]);
|
2010-07-29 17:04:19 +04:00
|
|
|
|
2010-06-30 17:18:45 +04:00
|
|
|
/* Add to vPTE list */
|
|
|
|
index = kvmppc_mmu_hash_vpte(pte->pte.vpage);
|
2011-06-29 04:17:33 +04:00
|
|
|
hlist_add_head_rcu(&pte->list_vpte, &vcpu3s->hpte_hash_vpte[index]);
|
2010-06-30 17:18:45 +04:00
|
|
|
|
|
|
|
/* Add to vPTE_long list */
|
|
|
|
index = kvmppc_mmu_hash_vpte_long(pte->pte.vpage);
|
2010-07-29 17:04:17 +04:00
|
|
|
hlist_add_head_rcu(&pte->list_vpte_long,
|
2011-06-29 04:17:33 +04:00
|
|
|
&vcpu3s->hpte_hash_vpte_long[index]);
|
2010-07-29 17:04:17 +04:00
|
|
|
|
2013-09-20 08:52:44 +04:00
|
|
|
#ifdef CONFIG_PPC_BOOK3S_64
|
|
|
|
/* Add to vPTE_64k list */
|
|
|
|
index = kvmppc_mmu_hash_vpte_64k(pte->pte.vpage);
|
|
|
|
hlist_add_head_rcu(&pte->list_vpte_64k,
|
|
|
|
&vcpu3s->hpte_hash_vpte_64k[index]);
|
|
|
|
#endif
|
|
|
|
|
KVM: PPC: Book3S PR: Use mmu_notifier_retry() in kvmppc_mmu_map_page()
When the MM code is invalidating a range of pages, it calls the KVM
kvm_mmu_notifier_invalidate_range_start() notifier function, which calls
kvm_unmap_hva_range(), which arranges to flush all the existing host
HPTEs for guest pages. However, the Linux PTEs for the range being
flushed are still valid at that point. We are not supposed to establish
any new references to pages in the range until the ...range_end()
notifier gets called. The PPC-specific KVM code doesn't get any
explicit notification of that; instead, we are supposed to use
mmu_notifier_retry() to test whether we are or have been inside a
range flush notifier pair while we have been getting a page and
instantiating a host HPTE for the page.
This therefore adds a call to mmu_notifier_retry inside
kvmppc_mmu_map_page(). This call is inside a region locked with
kvm->mmu_lock, which is the same lock that is called by the KVM
MMU notifier functions, thus ensuring that no new notification can
proceed while we are in the locked region. Inside this region we
also create the host HPTE and link the corresponding hpte_cache
structure into the lists used to find it later. We cannot allocate
the hpte_cache structure inside this locked region because that can
lead to deadlock, so we allocate it outside the region and free it
if we end up not using it.
This also moves the updates of vcpu3s->hpte_cache_count inside the
regions locked with vcpu3s->mmu_lock, and does the increment in
kvmppc_mmu_hpte_cache_map() when the pte is added to the cache
rather than when it is allocated, in order that the hpte_cache_count
is accurate.
Signed-off-by: Paul Mackerras <paulus@samba.org>
Signed-off-by: Alexander Graf <agraf@suse.de>
2013-09-20 08:52:52 +04:00
|
|
|
vcpu3s->hpte_cache_count++;
|
|
|
|
|
2011-06-29 04:17:33 +04:00
|
|
|
spin_unlock(&vcpu3s->mmu_lock);
|
2010-07-29 17:04:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void free_pte_rcu(struct rcu_head *head)
|
|
|
|
{
|
|
|
|
struct hpte_cache *pte = container_of(head, struct hpte_cache, rcu_head);
|
|
|
|
kmem_cache_free(hpte_cache, pte);
|
2010-06-30 17:18:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void invalidate_pte(struct kvm_vcpu *vcpu, struct hpte_cache *pte)
|
|
|
|
{
|
2011-06-29 04:17:33 +04:00
|
|
|
struct kvmppc_vcpu_book3s *vcpu3s = to_book3s(vcpu);
|
|
|
|
|
2010-08-02 14:55:19 +04:00
|
|
|
trace_kvm_book3s_mmu_invalidate(pte);
|
2010-06-30 17:18:45 +04:00
|
|
|
|
|
|
|
/* Different for 32 and 64 bit */
|
|
|
|
kvmppc_mmu_invalidate_pte(vcpu, pte);
|
|
|
|
|
2011-06-29 04:17:33 +04:00
|
|
|
spin_lock(&vcpu3s->mmu_lock);
|
2010-07-29 17:04:17 +04:00
|
|
|
|
2010-08-02 23:24:48 +04:00
|
|
|
/* pte already invalidated in between? */
|
|
|
|
if (hlist_unhashed(&pte->list_pte)) {
|
2011-06-29 04:17:33 +04:00
|
|
|
spin_unlock(&vcpu3s->mmu_lock);
|
2010-08-02 23:24:48 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-07-29 17:04:17 +04:00
|
|
|
hlist_del_init_rcu(&pte->list_pte);
|
2010-07-29 17:04:19 +04:00
|
|
|
hlist_del_init_rcu(&pte->list_pte_long);
|
2010-07-29 17:04:17 +04:00
|
|
|
hlist_del_init_rcu(&pte->list_vpte);
|
|
|
|
hlist_del_init_rcu(&pte->list_vpte_long);
|
2013-09-20 08:52:44 +04:00
|
|
|
#ifdef CONFIG_PPC_BOOK3S_64
|
|
|
|
hlist_del_init_rcu(&pte->list_vpte_64k);
|
|
|
|
#endif
|
KVM: PPC: Book3S PR: Use mmu_notifier_retry() in kvmppc_mmu_map_page()
When the MM code is invalidating a range of pages, it calls the KVM
kvm_mmu_notifier_invalidate_range_start() notifier function, which calls
kvm_unmap_hva_range(), which arranges to flush all the existing host
HPTEs for guest pages. However, the Linux PTEs for the range being
flushed are still valid at that point. We are not supposed to establish
any new references to pages in the range until the ...range_end()
notifier gets called. The PPC-specific KVM code doesn't get any
explicit notification of that; instead, we are supposed to use
mmu_notifier_retry() to test whether we are or have been inside a
range flush notifier pair while we have been getting a page and
instantiating a host HPTE for the page.
This therefore adds a call to mmu_notifier_retry inside
kvmppc_mmu_map_page(). This call is inside a region locked with
kvm->mmu_lock, which is the same lock that is called by the KVM
MMU notifier functions, thus ensuring that no new notification can
proceed while we are in the locked region. Inside this region we
also create the host HPTE and link the corresponding hpte_cache
structure into the lists used to find it later. We cannot allocate
the hpte_cache structure inside this locked region because that can
lead to deadlock, so we allocate it outside the region and free it
if we end up not using it.
This also moves the updates of vcpu3s->hpte_cache_count inside the
regions locked with vcpu3s->mmu_lock, and does the increment in
kvmppc_mmu_hpte_cache_map() when the pte is added to the cache
rather than when it is allocated, in order that the hpte_cache_count
is accurate.
Signed-off-by: Paul Mackerras <paulus@samba.org>
Signed-off-by: Alexander Graf <agraf@suse.de>
2013-09-20 08:52:52 +04:00
|
|
|
vcpu3s->hpte_cache_count--;
|
2010-07-29 17:04:17 +04:00
|
|
|
|
2011-06-29 04:17:33 +04:00
|
|
|
spin_unlock(&vcpu3s->mmu_lock);
|
2010-08-02 23:24:48 +04:00
|
|
|
|
2010-07-29 17:04:17 +04:00
|
|
|
call_rcu(&pte->rcu_head, free_pte_rcu);
|
2010-06-30 17:18:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void kvmppc_mmu_pte_flush_all(struct kvm_vcpu *vcpu)
|
|
|
|
{
|
2011-06-29 04:17:33 +04:00
|
|
|
struct kvmppc_vcpu_book3s *vcpu3s = to_book3s(vcpu);
|
2010-06-30 17:18:45 +04:00
|
|
|
struct hpte_cache *pte;
|
|
|
|
int i;
|
|
|
|
|
2010-07-29 17:04:17 +04:00
|
|
|
rcu_read_lock();
|
|
|
|
|
2010-06-30 17:18:45 +04:00
|
|
|
for (i = 0; i < HPTEG_HASH_NUM_VPTE_LONG; i++) {
|
2011-06-29 04:17:33 +04:00
|
|
|
struct hlist_head *list = &vcpu3s->hpte_hash_vpte_long[i];
|
2010-06-30 17:18:45 +04:00
|
|
|
|
hlist: drop the node parameter from iterators
I'm not sure why, but the hlist for each entry iterators were conceived
list_for_each_entry(pos, head, member)
The hlist ones were greedy and wanted an extra parameter:
hlist_for_each_entry(tpos, pos, head, member)
Why did they need an extra pos parameter? I'm not quite sure. Not only
they don't really need it, it also prevents the iterator from looking
exactly like the list iterator, which is unfortunate.
Besides the semantic patch, there was some manual work required:
- Fix up the actual hlist iterators in linux/list.h
- Fix up the declaration of other iterators based on the hlist ones.
- A very small amount of places were using the 'node' parameter, this
was modified to use 'obj->member' instead.
- Coccinelle didn't handle the hlist_for_each_entry_safe iterator
properly, so those had to be fixed up manually.
The semantic patch which is mostly the work of Peter Senna Tschudin is here:
@@
iterator name hlist_for_each_entry, hlist_for_each_entry_continue, hlist_for_each_entry_from, hlist_for_each_entry_rcu, hlist_for_each_entry_rcu_bh, hlist_for_each_entry_continue_rcu_bh, for_each_busy_worker, ax25_uid_for_each, ax25_for_each, inet_bind_bucket_for_each, sctp_for_each_hentry, sk_for_each, sk_for_each_rcu, sk_for_each_from, sk_for_each_safe, sk_for_each_bound, hlist_for_each_entry_safe, hlist_for_each_entry_continue_rcu, nr_neigh_for_each, nr_neigh_for_each_safe, nr_node_for_each, nr_node_for_each_safe, for_each_gfn_indirect_valid_sp, for_each_gfn_sp, for_each_host;
type T;
expression a,c,d,e;
identifier b;
statement S;
@@
-T b;
<+... when != b
(
hlist_for_each_entry(a,
- b,
c, d) S
|
hlist_for_each_entry_continue(a,
- b,
c) S
|
hlist_for_each_entry_from(a,
- b,
c) S
|
hlist_for_each_entry_rcu(a,
- b,
c, d) S
|
hlist_for_each_entry_rcu_bh(a,
- b,
c, d) S
|
hlist_for_each_entry_continue_rcu_bh(a,
- b,
c) S
|
for_each_busy_worker(a, c,
- b,
d) S
|
ax25_uid_for_each(a,
- b,
c) S
|
ax25_for_each(a,
- b,
c) S
|
inet_bind_bucket_for_each(a,
- b,
c) S
|
sctp_for_each_hentry(a,
- b,
c) S
|
sk_for_each(a,
- b,
c) S
|
sk_for_each_rcu(a,
- b,
c) S
|
sk_for_each_from
-(a, b)
+(a)
S
+ sk_for_each_from(a) S
|
sk_for_each_safe(a,
- b,
c, d) S
|
sk_for_each_bound(a,
- b,
c) S
|
hlist_for_each_entry_safe(a,
- b,
c, d, e) S
|
hlist_for_each_entry_continue_rcu(a,
- b,
c) S
|
nr_neigh_for_each(a,
- b,
c) S
|
nr_neigh_for_each_safe(a,
- b,
c, d) S
|
nr_node_for_each(a,
- b,
c) S
|
nr_node_for_each_safe(a,
- b,
c, d) S
|
- for_each_gfn_sp(a, c, d, b) S
+ for_each_gfn_sp(a, c, d) S
|
- for_each_gfn_indirect_valid_sp(a, c, d, b) S
+ for_each_gfn_indirect_valid_sp(a, c, d) S
|
for_each_host(a,
- b,
c) S
|
for_each_host_safe(a,
- b,
c, d) S
|
for_each_mesh_entry(a,
- b,
c, d) S
)
...+>
[akpm@linux-foundation.org: drop bogus change from net/ipv4/raw.c]
[akpm@linux-foundation.org: drop bogus hunk from net/ipv6/raw.c]
[akpm@linux-foundation.org: checkpatch fixes]
[akpm@linux-foundation.org: fix warnings]
[akpm@linux-foudnation.org: redo intrusive kvm changes]
Tested-by: Peter Senna Tschudin <peter.senna@gmail.com>
Acked-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Signed-off-by: Sasha Levin <sasha.levin@oracle.com>
Cc: Wu Fengguang <fengguang.wu@intel.com>
Cc: Marcelo Tosatti <mtosatti@redhat.com>
Cc: Gleb Natapov <gleb@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2013-02-28 05:06:00 +04:00
|
|
|
hlist_for_each_entry_rcu(pte, list, list_vpte_long)
|
2010-06-30 17:18:45 +04:00
|
|
|
invalidate_pte(vcpu, pte);
|
|
|
|
}
|
2010-07-29 17:04:17 +04:00
|
|
|
|
|
|
|
rcu_read_unlock();
|
2010-06-30 17:18:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void kvmppc_mmu_pte_flush_page(struct kvm_vcpu *vcpu, ulong guest_ea)
|
|
|
|
{
|
2011-06-29 04:17:33 +04:00
|
|
|
struct kvmppc_vcpu_book3s *vcpu3s = to_book3s(vcpu);
|
2010-06-30 17:18:45 +04:00
|
|
|
struct hlist_head *list;
|
|
|
|
struct hpte_cache *pte;
|
|
|
|
|
|
|
|
/* Find the list of entries in the map */
|
2011-06-29 04:17:33 +04:00
|
|
|
list = &vcpu3s->hpte_hash_pte[kvmppc_mmu_hash_pte(guest_ea)];
|
2010-06-30 17:18:45 +04:00
|
|
|
|
2010-07-29 17:04:17 +04:00
|
|
|
rcu_read_lock();
|
|
|
|
|
2010-06-30 17:18:45 +04:00
|
|
|
/* Check the list for matching entries and invalidate */
|
hlist: drop the node parameter from iterators
I'm not sure why, but the hlist for each entry iterators were conceived
list_for_each_entry(pos, head, member)
The hlist ones were greedy and wanted an extra parameter:
hlist_for_each_entry(tpos, pos, head, member)
Why did they need an extra pos parameter? I'm not quite sure. Not only
they don't really need it, it also prevents the iterator from looking
exactly like the list iterator, which is unfortunate.
Besides the semantic patch, there was some manual work required:
- Fix up the actual hlist iterators in linux/list.h
- Fix up the declaration of other iterators based on the hlist ones.
- A very small amount of places were using the 'node' parameter, this
was modified to use 'obj->member' instead.
- Coccinelle didn't handle the hlist_for_each_entry_safe iterator
properly, so those had to be fixed up manually.
The semantic patch which is mostly the work of Peter Senna Tschudin is here:
@@
iterator name hlist_for_each_entry, hlist_for_each_entry_continue, hlist_for_each_entry_from, hlist_for_each_entry_rcu, hlist_for_each_entry_rcu_bh, hlist_for_each_entry_continue_rcu_bh, for_each_busy_worker, ax25_uid_for_each, ax25_for_each, inet_bind_bucket_for_each, sctp_for_each_hentry, sk_for_each, sk_for_each_rcu, sk_for_each_from, sk_for_each_safe, sk_for_each_bound, hlist_for_each_entry_safe, hlist_for_each_entry_continue_rcu, nr_neigh_for_each, nr_neigh_for_each_safe, nr_node_for_each, nr_node_for_each_safe, for_each_gfn_indirect_valid_sp, for_each_gfn_sp, for_each_host;
type T;
expression a,c,d,e;
identifier b;
statement S;
@@
-T b;
<+... when != b
(
hlist_for_each_entry(a,
- b,
c, d) S
|
hlist_for_each_entry_continue(a,
- b,
c) S
|
hlist_for_each_entry_from(a,
- b,
c) S
|
hlist_for_each_entry_rcu(a,
- b,
c, d) S
|
hlist_for_each_entry_rcu_bh(a,
- b,
c, d) S
|
hlist_for_each_entry_continue_rcu_bh(a,
- b,
c) S
|
for_each_busy_worker(a, c,
- b,
d) S
|
ax25_uid_for_each(a,
- b,
c) S
|
ax25_for_each(a,
- b,
c) S
|
inet_bind_bucket_for_each(a,
- b,
c) S
|
sctp_for_each_hentry(a,
- b,
c) S
|
sk_for_each(a,
- b,
c) S
|
sk_for_each_rcu(a,
- b,
c) S
|
sk_for_each_from
-(a, b)
+(a)
S
+ sk_for_each_from(a) S
|
sk_for_each_safe(a,
- b,
c, d) S
|
sk_for_each_bound(a,
- b,
c) S
|
hlist_for_each_entry_safe(a,
- b,
c, d, e) S
|
hlist_for_each_entry_continue_rcu(a,
- b,
c) S
|
nr_neigh_for_each(a,
- b,
c) S
|
nr_neigh_for_each_safe(a,
- b,
c, d) S
|
nr_node_for_each(a,
- b,
c) S
|
nr_node_for_each_safe(a,
- b,
c, d) S
|
- for_each_gfn_sp(a, c, d, b) S
+ for_each_gfn_sp(a, c, d) S
|
- for_each_gfn_indirect_valid_sp(a, c, d, b) S
+ for_each_gfn_indirect_valid_sp(a, c, d) S
|
for_each_host(a,
- b,
c) S
|
for_each_host_safe(a,
- b,
c, d) S
|
for_each_mesh_entry(a,
- b,
c, d) S
)
...+>
[akpm@linux-foundation.org: drop bogus change from net/ipv4/raw.c]
[akpm@linux-foundation.org: drop bogus hunk from net/ipv6/raw.c]
[akpm@linux-foundation.org: checkpatch fixes]
[akpm@linux-foundation.org: fix warnings]
[akpm@linux-foudnation.org: redo intrusive kvm changes]
Tested-by: Peter Senna Tschudin <peter.senna@gmail.com>
Acked-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Signed-off-by: Sasha Levin <sasha.levin@oracle.com>
Cc: Wu Fengguang <fengguang.wu@intel.com>
Cc: Marcelo Tosatti <mtosatti@redhat.com>
Cc: Gleb Natapov <gleb@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2013-02-28 05:06:00 +04:00
|
|
|
hlist_for_each_entry_rcu(pte, list, list_pte)
|
2010-06-30 17:18:45 +04:00
|
|
|
if ((pte->pte.eaddr & ~0xfffUL) == guest_ea)
|
|
|
|
invalidate_pte(vcpu, pte);
|
2010-07-29 17:04:17 +04:00
|
|
|
|
|
|
|
rcu_read_unlock();
|
2010-06-30 17:18:45 +04:00
|
|
|
}
|
|
|
|
|
2010-07-29 17:04:19 +04:00
|
|
|
static void kvmppc_mmu_pte_flush_long(struct kvm_vcpu *vcpu, ulong guest_ea)
|
2010-06-30 17:18:45 +04:00
|
|
|
{
|
2011-06-29 04:17:33 +04:00
|
|
|
struct kvmppc_vcpu_book3s *vcpu3s = to_book3s(vcpu);
|
2010-07-29 17:04:19 +04:00
|
|
|
struct hlist_head *list;
|
|
|
|
struct hpte_cache *pte;
|
|
|
|
|
|
|
|
/* Find the list of entries in the map */
|
2011-06-29 04:17:33 +04:00
|
|
|
list = &vcpu3s->hpte_hash_pte_long[
|
2010-07-29 17:04:19 +04:00
|
|
|
kvmppc_mmu_hash_pte_long(guest_ea)];
|
2010-06-30 17:18:45 +04:00
|
|
|
|
2010-07-29 17:04:19 +04:00
|
|
|
rcu_read_lock();
|
|
|
|
|
|
|
|
/* Check the list for matching entries and invalidate */
|
hlist: drop the node parameter from iterators
I'm not sure why, but the hlist for each entry iterators were conceived
list_for_each_entry(pos, head, member)
The hlist ones were greedy and wanted an extra parameter:
hlist_for_each_entry(tpos, pos, head, member)
Why did they need an extra pos parameter? I'm not quite sure. Not only
they don't really need it, it also prevents the iterator from looking
exactly like the list iterator, which is unfortunate.
Besides the semantic patch, there was some manual work required:
- Fix up the actual hlist iterators in linux/list.h
- Fix up the declaration of other iterators based on the hlist ones.
- A very small amount of places were using the 'node' parameter, this
was modified to use 'obj->member' instead.
- Coccinelle didn't handle the hlist_for_each_entry_safe iterator
properly, so those had to be fixed up manually.
The semantic patch which is mostly the work of Peter Senna Tschudin is here:
@@
iterator name hlist_for_each_entry, hlist_for_each_entry_continue, hlist_for_each_entry_from, hlist_for_each_entry_rcu, hlist_for_each_entry_rcu_bh, hlist_for_each_entry_continue_rcu_bh, for_each_busy_worker, ax25_uid_for_each, ax25_for_each, inet_bind_bucket_for_each, sctp_for_each_hentry, sk_for_each, sk_for_each_rcu, sk_for_each_from, sk_for_each_safe, sk_for_each_bound, hlist_for_each_entry_safe, hlist_for_each_entry_continue_rcu, nr_neigh_for_each, nr_neigh_for_each_safe, nr_node_for_each, nr_node_for_each_safe, for_each_gfn_indirect_valid_sp, for_each_gfn_sp, for_each_host;
type T;
expression a,c,d,e;
identifier b;
statement S;
@@
-T b;
<+... when != b
(
hlist_for_each_entry(a,
- b,
c, d) S
|
hlist_for_each_entry_continue(a,
- b,
c) S
|
hlist_for_each_entry_from(a,
- b,
c) S
|
hlist_for_each_entry_rcu(a,
- b,
c, d) S
|
hlist_for_each_entry_rcu_bh(a,
- b,
c, d) S
|
hlist_for_each_entry_continue_rcu_bh(a,
- b,
c) S
|
for_each_busy_worker(a, c,
- b,
d) S
|
ax25_uid_for_each(a,
- b,
c) S
|
ax25_for_each(a,
- b,
c) S
|
inet_bind_bucket_for_each(a,
- b,
c) S
|
sctp_for_each_hentry(a,
- b,
c) S
|
sk_for_each(a,
- b,
c) S
|
sk_for_each_rcu(a,
- b,
c) S
|
sk_for_each_from
-(a, b)
+(a)
S
+ sk_for_each_from(a) S
|
sk_for_each_safe(a,
- b,
c, d) S
|
sk_for_each_bound(a,
- b,
c) S
|
hlist_for_each_entry_safe(a,
- b,
c, d, e) S
|
hlist_for_each_entry_continue_rcu(a,
- b,
c) S
|
nr_neigh_for_each(a,
- b,
c) S
|
nr_neigh_for_each_safe(a,
- b,
c, d) S
|
nr_node_for_each(a,
- b,
c) S
|
nr_node_for_each_safe(a,
- b,
c, d) S
|
- for_each_gfn_sp(a, c, d, b) S
+ for_each_gfn_sp(a, c, d) S
|
- for_each_gfn_indirect_valid_sp(a, c, d, b) S
+ for_each_gfn_indirect_valid_sp(a, c, d) S
|
for_each_host(a,
- b,
c) S
|
for_each_host_safe(a,
- b,
c, d) S
|
for_each_mesh_entry(a,
- b,
c, d) S
)
...+>
[akpm@linux-foundation.org: drop bogus change from net/ipv4/raw.c]
[akpm@linux-foundation.org: drop bogus hunk from net/ipv6/raw.c]
[akpm@linux-foundation.org: checkpatch fixes]
[akpm@linux-foundation.org: fix warnings]
[akpm@linux-foudnation.org: redo intrusive kvm changes]
Tested-by: Peter Senna Tschudin <peter.senna@gmail.com>
Acked-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Signed-off-by: Sasha Levin <sasha.levin@oracle.com>
Cc: Wu Fengguang <fengguang.wu@intel.com>
Cc: Marcelo Tosatti <mtosatti@redhat.com>
Cc: Gleb Natapov <gleb@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2013-02-28 05:06:00 +04:00
|
|
|
hlist_for_each_entry_rcu(pte, list, list_pte_long)
|
2010-07-29 17:04:19 +04:00
|
|
|
if ((pte->pte.eaddr & 0x0ffff000UL) == guest_ea)
|
|
|
|
invalidate_pte(vcpu, pte);
|
|
|
|
|
|
|
|
rcu_read_unlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
void kvmppc_mmu_pte_flush(struct kvm_vcpu *vcpu, ulong guest_ea, ulong ea_mask)
|
|
|
|
{
|
2010-08-02 15:40:30 +04:00
|
|
|
trace_kvm_book3s_mmu_flush("", vcpu, guest_ea, ea_mask);
|
2010-06-30 17:18:45 +04:00
|
|
|
guest_ea &= ea_mask;
|
|
|
|
|
|
|
|
switch (ea_mask) {
|
|
|
|
case ~0xfffUL:
|
|
|
|
kvmppc_mmu_pte_flush_page(vcpu, guest_ea);
|
|
|
|
break;
|
|
|
|
case 0x0ffff000:
|
2010-07-29 17:04:19 +04:00
|
|
|
kvmppc_mmu_pte_flush_long(vcpu, guest_ea);
|
2010-06-30 17:18:45 +04:00
|
|
|
break;
|
|
|
|
case 0:
|
|
|
|
/* Doing a complete flush -> start from scratch */
|
|
|
|
kvmppc_mmu_pte_flush_all(vcpu);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
WARN_ON(1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Flush with mask 0xfffffffff */
|
|
|
|
static void kvmppc_mmu_pte_vflush_short(struct kvm_vcpu *vcpu, u64 guest_vp)
|
|
|
|
{
|
2011-06-29 04:17:33 +04:00
|
|
|
struct kvmppc_vcpu_book3s *vcpu3s = to_book3s(vcpu);
|
2010-06-30 17:18:45 +04:00
|
|
|
struct hlist_head *list;
|
|
|
|
struct hpte_cache *pte;
|
|
|
|
u64 vp_mask = 0xfffffffffULL;
|
|
|
|
|
2011-06-29 04:17:33 +04:00
|
|
|
list = &vcpu3s->hpte_hash_vpte[kvmppc_mmu_hash_vpte(guest_vp)];
|
2010-06-30 17:18:45 +04:00
|
|
|
|
2010-07-29 17:04:17 +04:00
|
|
|
rcu_read_lock();
|
|
|
|
|
2010-06-30 17:18:45 +04:00
|
|
|
/* Check the list for matching entries and invalidate */
|
hlist: drop the node parameter from iterators
I'm not sure why, but the hlist for each entry iterators were conceived
list_for_each_entry(pos, head, member)
The hlist ones were greedy and wanted an extra parameter:
hlist_for_each_entry(tpos, pos, head, member)
Why did they need an extra pos parameter? I'm not quite sure. Not only
they don't really need it, it also prevents the iterator from looking
exactly like the list iterator, which is unfortunate.
Besides the semantic patch, there was some manual work required:
- Fix up the actual hlist iterators in linux/list.h
- Fix up the declaration of other iterators based on the hlist ones.
- A very small amount of places were using the 'node' parameter, this
was modified to use 'obj->member' instead.
- Coccinelle didn't handle the hlist_for_each_entry_safe iterator
properly, so those had to be fixed up manually.
The semantic patch which is mostly the work of Peter Senna Tschudin is here:
@@
iterator name hlist_for_each_entry, hlist_for_each_entry_continue, hlist_for_each_entry_from, hlist_for_each_entry_rcu, hlist_for_each_entry_rcu_bh, hlist_for_each_entry_continue_rcu_bh, for_each_busy_worker, ax25_uid_for_each, ax25_for_each, inet_bind_bucket_for_each, sctp_for_each_hentry, sk_for_each, sk_for_each_rcu, sk_for_each_from, sk_for_each_safe, sk_for_each_bound, hlist_for_each_entry_safe, hlist_for_each_entry_continue_rcu, nr_neigh_for_each, nr_neigh_for_each_safe, nr_node_for_each, nr_node_for_each_safe, for_each_gfn_indirect_valid_sp, for_each_gfn_sp, for_each_host;
type T;
expression a,c,d,e;
identifier b;
statement S;
@@
-T b;
<+... when != b
(
hlist_for_each_entry(a,
- b,
c, d) S
|
hlist_for_each_entry_continue(a,
- b,
c) S
|
hlist_for_each_entry_from(a,
- b,
c) S
|
hlist_for_each_entry_rcu(a,
- b,
c, d) S
|
hlist_for_each_entry_rcu_bh(a,
- b,
c, d) S
|
hlist_for_each_entry_continue_rcu_bh(a,
- b,
c) S
|
for_each_busy_worker(a, c,
- b,
d) S
|
ax25_uid_for_each(a,
- b,
c) S
|
ax25_for_each(a,
- b,
c) S
|
inet_bind_bucket_for_each(a,
- b,
c) S
|
sctp_for_each_hentry(a,
- b,
c) S
|
sk_for_each(a,
- b,
c) S
|
sk_for_each_rcu(a,
- b,
c) S
|
sk_for_each_from
-(a, b)
+(a)
S
+ sk_for_each_from(a) S
|
sk_for_each_safe(a,
- b,
c, d) S
|
sk_for_each_bound(a,
- b,
c) S
|
hlist_for_each_entry_safe(a,
- b,
c, d, e) S
|
hlist_for_each_entry_continue_rcu(a,
- b,
c) S
|
nr_neigh_for_each(a,
- b,
c) S
|
nr_neigh_for_each_safe(a,
- b,
c, d) S
|
nr_node_for_each(a,
- b,
c) S
|
nr_node_for_each_safe(a,
- b,
c, d) S
|
- for_each_gfn_sp(a, c, d, b) S
+ for_each_gfn_sp(a, c, d) S
|
- for_each_gfn_indirect_valid_sp(a, c, d, b) S
+ for_each_gfn_indirect_valid_sp(a, c, d) S
|
for_each_host(a,
- b,
c) S
|
for_each_host_safe(a,
- b,
c, d) S
|
for_each_mesh_entry(a,
- b,
c, d) S
)
...+>
[akpm@linux-foundation.org: drop bogus change from net/ipv4/raw.c]
[akpm@linux-foundation.org: drop bogus hunk from net/ipv6/raw.c]
[akpm@linux-foundation.org: checkpatch fixes]
[akpm@linux-foundation.org: fix warnings]
[akpm@linux-foudnation.org: redo intrusive kvm changes]
Tested-by: Peter Senna Tschudin <peter.senna@gmail.com>
Acked-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Signed-off-by: Sasha Levin <sasha.levin@oracle.com>
Cc: Wu Fengguang <fengguang.wu@intel.com>
Cc: Marcelo Tosatti <mtosatti@redhat.com>
Cc: Gleb Natapov <gleb@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2013-02-28 05:06:00 +04:00
|
|
|
hlist_for_each_entry_rcu(pte, list, list_vpte)
|
2010-06-30 17:18:45 +04:00
|
|
|
if ((pte->pte.vpage & vp_mask) == guest_vp)
|
|
|
|
invalidate_pte(vcpu, pte);
|
2010-07-29 17:04:17 +04:00
|
|
|
|
|
|
|
rcu_read_unlock();
|
2010-06-30 17:18:45 +04:00
|
|
|
}
|
|
|
|
|
2013-09-20 08:52:44 +04:00
|
|
|
#ifdef CONFIG_PPC_BOOK3S_64
|
|
|
|
/* Flush with mask 0xffffffff0 */
|
|
|
|
static void kvmppc_mmu_pte_vflush_64k(struct kvm_vcpu *vcpu, u64 guest_vp)
|
|
|
|
{
|
|
|
|
struct kvmppc_vcpu_book3s *vcpu3s = to_book3s(vcpu);
|
|
|
|
struct hlist_head *list;
|
|
|
|
struct hpte_cache *pte;
|
|
|
|
u64 vp_mask = 0xffffffff0ULL;
|
|
|
|
|
|
|
|
list = &vcpu3s->hpte_hash_vpte_64k[
|
|
|
|
kvmppc_mmu_hash_vpte_64k(guest_vp)];
|
|
|
|
|
|
|
|
rcu_read_lock();
|
|
|
|
|
|
|
|
/* Check the list for matching entries and invalidate */
|
|
|
|
hlist_for_each_entry_rcu(pte, list, list_vpte_64k)
|
|
|
|
if ((pte->pte.vpage & vp_mask) == guest_vp)
|
|
|
|
invalidate_pte(vcpu, pte);
|
|
|
|
|
|
|
|
rcu_read_unlock();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-06-30 17:18:45 +04:00
|
|
|
/* Flush with mask 0xffffff000 */
|
|
|
|
static void kvmppc_mmu_pte_vflush_long(struct kvm_vcpu *vcpu, u64 guest_vp)
|
|
|
|
{
|
2011-06-29 04:17:33 +04:00
|
|
|
struct kvmppc_vcpu_book3s *vcpu3s = to_book3s(vcpu);
|
2010-06-30 17:18:45 +04:00
|
|
|
struct hlist_head *list;
|
|
|
|
struct hpte_cache *pte;
|
|
|
|
u64 vp_mask = 0xffffff000ULL;
|
|
|
|
|
2011-06-29 04:17:33 +04:00
|
|
|
list = &vcpu3s->hpte_hash_vpte_long[
|
2010-06-30 17:18:45 +04:00
|
|
|
kvmppc_mmu_hash_vpte_long(guest_vp)];
|
|
|
|
|
2010-07-29 17:04:17 +04:00
|
|
|
rcu_read_lock();
|
|
|
|
|
2010-06-30 17:18:45 +04:00
|
|
|
/* Check the list for matching entries and invalidate */
|
hlist: drop the node parameter from iterators
I'm not sure why, but the hlist for each entry iterators were conceived
list_for_each_entry(pos, head, member)
The hlist ones were greedy and wanted an extra parameter:
hlist_for_each_entry(tpos, pos, head, member)
Why did they need an extra pos parameter? I'm not quite sure. Not only
they don't really need it, it also prevents the iterator from looking
exactly like the list iterator, which is unfortunate.
Besides the semantic patch, there was some manual work required:
- Fix up the actual hlist iterators in linux/list.h
- Fix up the declaration of other iterators based on the hlist ones.
- A very small amount of places were using the 'node' parameter, this
was modified to use 'obj->member' instead.
- Coccinelle didn't handle the hlist_for_each_entry_safe iterator
properly, so those had to be fixed up manually.
The semantic patch which is mostly the work of Peter Senna Tschudin is here:
@@
iterator name hlist_for_each_entry, hlist_for_each_entry_continue, hlist_for_each_entry_from, hlist_for_each_entry_rcu, hlist_for_each_entry_rcu_bh, hlist_for_each_entry_continue_rcu_bh, for_each_busy_worker, ax25_uid_for_each, ax25_for_each, inet_bind_bucket_for_each, sctp_for_each_hentry, sk_for_each, sk_for_each_rcu, sk_for_each_from, sk_for_each_safe, sk_for_each_bound, hlist_for_each_entry_safe, hlist_for_each_entry_continue_rcu, nr_neigh_for_each, nr_neigh_for_each_safe, nr_node_for_each, nr_node_for_each_safe, for_each_gfn_indirect_valid_sp, for_each_gfn_sp, for_each_host;
type T;
expression a,c,d,e;
identifier b;
statement S;
@@
-T b;
<+... when != b
(
hlist_for_each_entry(a,
- b,
c, d) S
|
hlist_for_each_entry_continue(a,
- b,
c) S
|
hlist_for_each_entry_from(a,
- b,
c) S
|
hlist_for_each_entry_rcu(a,
- b,
c, d) S
|
hlist_for_each_entry_rcu_bh(a,
- b,
c, d) S
|
hlist_for_each_entry_continue_rcu_bh(a,
- b,
c) S
|
for_each_busy_worker(a, c,
- b,
d) S
|
ax25_uid_for_each(a,
- b,
c) S
|
ax25_for_each(a,
- b,
c) S
|
inet_bind_bucket_for_each(a,
- b,
c) S
|
sctp_for_each_hentry(a,
- b,
c) S
|
sk_for_each(a,
- b,
c) S
|
sk_for_each_rcu(a,
- b,
c) S
|
sk_for_each_from
-(a, b)
+(a)
S
+ sk_for_each_from(a) S
|
sk_for_each_safe(a,
- b,
c, d) S
|
sk_for_each_bound(a,
- b,
c) S
|
hlist_for_each_entry_safe(a,
- b,
c, d, e) S
|
hlist_for_each_entry_continue_rcu(a,
- b,
c) S
|
nr_neigh_for_each(a,
- b,
c) S
|
nr_neigh_for_each_safe(a,
- b,
c, d) S
|
nr_node_for_each(a,
- b,
c) S
|
nr_node_for_each_safe(a,
- b,
c, d) S
|
- for_each_gfn_sp(a, c, d, b) S
+ for_each_gfn_sp(a, c, d) S
|
- for_each_gfn_indirect_valid_sp(a, c, d, b) S
+ for_each_gfn_indirect_valid_sp(a, c, d) S
|
for_each_host(a,
- b,
c) S
|
for_each_host_safe(a,
- b,
c, d) S
|
for_each_mesh_entry(a,
- b,
c, d) S
)
...+>
[akpm@linux-foundation.org: drop bogus change from net/ipv4/raw.c]
[akpm@linux-foundation.org: drop bogus hunk from net/ipv6/raw.c]
[akpm@linux-foundation.org: checkpatch fixes]
[akpm@linux-foundation.org: fix warnings]
[akpm@linux-foudnation.org: redo intrusive kvm changes]
Tested-by: Peter Senna Tschudin <peter.senna@gmail.com>
Acked-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Signed-off-by: Sasha Levin <sasha.levin@oracle.com>
Cc: Wu Fengguang <fengguang.wu@intel.com>
Cc: Marcelo Tosatti <mtosatti@redhat.com>
Cc: Gleb Natapov <gleb@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2013-02-28 05:06:00 +04:00
|
|
|
hlist_for_each_entry_rcu(pte, list, list_vpte_long)
|
2010-06-30 17:18:45 +04:00
|
|
|
if ((pte->pte.vpage & vp_mask) == guest_vp)
|
|
|
|
invalidate_pte(vcpu, pte);
|
2010-07-29 17:04:17 +04:00
|
|
|
|
|
|
|
rcu_read_unlock();
|
2010-06-30 17:18:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void kvmppc_mmu_pte_vflush(struct kvm_vcpu *vcpu, u64 guest_vp, u64 vp_mask)
|
|
|
|
{
|
2010-08-02 15:40:30 +04:00
|
|
|
trace_kvm_book3s_mmu_flush("v", vcpu, guest_vp, vp_mask);
|
2010-06-30 17:18:45 +04:00
|
|
|
guest_vp &= vp_mask;
|
|
|
|
|
|
|
|
switch(vp_mask) {
|
|
|
|
case 0xfffffffffULL:
|
|
|
|
kvmppc_mmu_pte_vflush_short(vcpu, guest_vp);
|
|
|
|
break;
|
2013-09-20 08:52:44 +04:00
|
|
|
#ifdef CONFIG_PPC_BOOK3S_64
|
|
|
|
case 0xffffffff0ULL:
|
|
|
|
kvmppc_mmu_pte_vflush_64k(vcpu, guest_vp);
|
|
|
|
break;
|
|
|
|
#endif
|
2010-06-30 17:18:45 +04:00
|
|
|
case 0xffffff000ULL:
|
|
|
|
kvmppc_mmu_pte_vflush_long(vcpu, guest_vp);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
WARN_ON(1);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void kvmppc_mmu_pte_pflush(struct kvm_vcpu *vcpu, ulong pa_start, ulong pa_end)
|
|
|
|
{
|
2011-06-29 04:17:33 +04:00
|
|
|
struct kvmppc_vcpu_book3s *vcpu3s = to_book3s(vcpu);
|
2010-06-30 17:18:45 +04:00
|
|
|
struct hpte_cache *pte;
|
|
|
|
int i;
|
|
|
|
|
2010-08-02 15:40:30 +04:00
|
|
|
trace_kvm_book3s_mmu_flush("p", vcpu, pa_start, pa_end);
|
2010-06-30 17:18:45 +04:00
|
|
|
|
2010-07-29 17:04:17 +04:00
|
|
|
rcu_read_lock();
|
|
|
|
|
2010-06-30 17:18:45 +04:00
|
|
|
for (i = 0; i < HPTEG_HASH_NUM_VPTE_LONG; i++) {
|
2011-06-29 04:17:33 +04:00
|
|
|
struct hlist_head *list = &vcpu3s->hpte_hash_vpte_long[i];
|
2010-06-30 17:18:45 +04:00
|
|
|
|
hlist: drop the node parameter from iterators
I'm not sure why, but the hlist for each entry iterators were conceived
list_for_each_entry(pos, head, member)
The hlist ones were greedy and wanted an extra parameter:
hlist_for_each_entry(tpos, pos, head, member)
Why did they need an extra pos parameter? I'm not quite sure. Not only
they don't really need it, it also prevents the iterator from looking
exactly like the list iterator, which is unfortunate.
Besides the semantic patch, there was some manual work required:
- Fix up the actual hlist iterators in linux/list.h
- Fix up the declaration of other iterators based on the hlist ones.
- A very small amount of places were using the 'node' parameter, this
was modified to use 'obj->member' instead.
- Coccinelle didn't handle the hlist_for_each_entry_safe iterator
properly, so those had to be fixed up manually.
The semantic patch which is mostly the work of Peter Senna Tschudin is here:
@@
iterator name hlist_for_each_entry, hlist_for_each_entry_continue, hlist_for_each_entry_from, hlist_for_each_entry_rcu, hlist_for_each_entry_rcu_bh, hlist_for_each_entry_continue_rcu_bh, for_each_busy_worker, ax25_uid_for_each, ax25_for_each, inet_bind_bucket_for_each, sctp_for_each_hentry, sk_for_each, sk_for_each_rcu, sk_for_each_from, sk_for_each_safe, sk_for_each_bound, hlist_for_each_entry_safe, hlist_for_each_entry_continue_rcu, nr_neigh_for_each, nr_neigh_for_each_safe, nr_node_for_each, nr_node_for_each_safe, for_each_gfn_indirect_valid_sp, for_each_gfn_sp, for_each_host;
type T;
expression a,c,d,e;
identifier b;
statement S;
@@
-T b;
<+... when != b
(
hlist_for_each_entry(a,
- b,
c, d) S
|
hlist_for_each_entry_continue(a,
- b,
c) S
|
hlist_for_each_entry_from(a,
- b,
c) S
|
hlist_for_each_entry_rcu(a,
- b,
c, d) S
|
hlist_for_each_entry_rcu_bh(a,
- b,
c, d) S
|
hlist_for_each_entry_continue_rcu_bh(a,
- b,
c) S
|
for_each_busy_worker(a, c,
- b,
d) S
|
ax25_uid_for_each(a,
- b,
c) S
|
ax25_for_each(a,
- b,
c) S
|
inet_bind_bucket_for_each(a,
- b,
c) S
|
sctp_for_each_hentry(a,
- b,
c) S
|
sk_for_each(a,
- b,
c) S
|
sk_for_each_rcu(a,
- b,
c) S
|
sk_for_each_from
-(a, b)
+(a)
S
+ sk_for_each_from(a) S
|
sk_for_each_safe(a,
- b,
c, d) S
|
sk_for_each_bound(a,
- b,
c) S
|
hlist_for_each_entry_safe(a,
- b,
c, d, e) S
|
hlist_for_each_entry_continue_rcu(a,
- b,
c) S
|
nr_neigh_for_each(a,
- b,
c) S
|
nr_neigh_for_each_safe(a,
- b,
c, d) S
|
nr_node_for_each(a,
- b,
c) S
|
nr_node_for_each_safe(a,
- b,
c, d) S
|
- for_each_gfn_sp(a, c, d, b) S
+ for_each_gfn_sp(a, c, d) S
|
- for_each_gfn_indirect_valid_sp(a, c, d, b) S
+ for_each_gfn_indirect_valid_sp(a, c, d) S
|
for_each_host(a,
- b,
c) S
|
for_each_host_safe(a,
- b,
c, d) S
|
for_each_mesh_entry(a,
- b,
c, d) S
)
...+>
[akpm@linux-foundation.org: drop bogus change from net/ipv4/raw.c]
[akpm@linux-foundation.org: drop bogus hunk from net/ipv6/raw.c]
[akpm@linux-foundation.org: checkpatch fixes]
[akpm@linux-foundation.org: fix warnings]
[akpm@linux-foudnation.org: redo intrusive kvm changes]
Tested-by: Peter Senna Tschudin <peter.senna@gmail.com>
Acked-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Signed-off-by: Sasha Levin <sasha.levin@oracle.com>
Cc: Wu Fengguang <fengguang.wu@intel.com>
Cc: Marcelo Tosatti <mtosatti@redhat.com>
Cc: Gleb Natapov <gleb@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2013-02-28 05:06:00 +04:00
|
|
|
hlist_for_each_entry_rcu(pte, list, list_vpte_long)
|
2010-06-30 17:18:45 +04:00
|
|
|
if ((pte->pte.raddr >= pa_start) &&
|
|
|
|
(pte->pte.raddr < pa_end))
|
|
|
|
invalidate_pte(vcpu, pte);
|
|
|
|
}
|
2010-07-29 17:04:17 +04:00
|
|
|
|
|
|
|
rcu_read_unlock();
|
2010-06-30 17:18:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
struct hpte_cache *kvmppc_mmu_hpte_cache_next(struct kvm_vcpu *vcpu)
|
|
|
|
{
|
2011-06-29 04:17:33 +04:00
|
|
|
struct kvmppc_vcpu_book3s *vcpu3s = to_book3s(vcpu);
|
2010-06-30 17:18:45 +04:00
|
|
|
struct hpte_cache *pte;
|
|
|
|
|
2011-06-29 04:17:33 +04:00
|
|
|
if (vcpu3s->hpte_cache_count == HPTEG_CACHE_NUM)
|
2010-06-30 17:18:45 +04:00
|
|
|
kvmppc_mmu_pte_flush_all(vcpu);
|
|
|
|
|
KVM: PPC: Book3S PR: Use mmu_notifier_retry() in kvmppc_mmu_map_page()
When the MM code is invalidating a range of pages, it calls the KVM
kvm_mmu_notifier_invalidate_range_start() notifier function, which calls
kvm_unmap_hva_range(), which arranges to flush all the existing host
HPTEs for guest pages. However, the Linux PTEs for the range being
flushed are still valid at that point. We are not supposed to establish
any new references to pages in the range until the ...range_end()
notifier gets called. The PPC-specific KVM code doesn't get any
explicit notification of that; instead, we are supposed to use
mmu_notifier_retry() to test whether we are or have been inside a
range flush notifier pair while we have been getting a page and
instantiating a host HPTE for the page.
This therefore adds a call to mmu_notifier_retry inside
kvmppc_mmu_map_page(). This call is inside a region locked with
kvm->mmu_lock, which is the same lock that is called by the KVM
MMU notifier functions, thus ensuring that no new notification can
proceed while we are in the locked region. Inside this region we
also create the host HPTE and link the corresponding hpte_cache
structure into the lists used to find it later. We cannot allocate
the hpte_cache structure inside this locked region because that can
lead to deadlock, so we allocate it outside the region and free it
if we end up not using it.
This also moves the updates of vcpu3s->hpte_cache_count inside the
regions locked with vcpu3s->mmu_lock, and does the increment in
kvmppc_mmu_hpte_cache_map() when the pte is added to the cache
rather than when it is allocated, in order that the hpte_cache_count
is accurate.
Signed-off-by: Paul Mackerras <paulus@samba.org>
Signed-off-by: Alexander Graf <agraf@suse.de>
2013-09-20 08:52:52 +04:00
|
|
|
pte = kmem_cache_zalloc(hpte_cache, GFP_KERNEL);
|
|
|
|
|
2010-06-30 17:18:45 +04:00
|
|
|
return pte;
|
|
|
|
}
|
|
|
|
|
KVM: PPC: Book3S PR: Use mmu_notifier_retry() in kvmppc_mmu_map_page()
When the MM code is invalidating a range of pages, it calls the KVM
kvm_mmu_notifier_invalidate_range_start() notifier function, which calls
kvm_unmap_hva_range(), which arranges to flush all the existing host
HPTEs for guest pages. However, the Linux PTEs for the range being
flushed are still valid at that point. We are not supposed to establish
any new references to pages in the range until the ...range_end()
notifier gets called. The PPC-specific KVM code doesn't get any
explicit notification of that; instead, we are supposed to use
mmu_notifier_retry() to test whether we are or have been inside a
range flush notifier pair while we have been getting a page and
instantiating a host HPTE for the page.
This therefore adds a call to mmu_notifier_retry inside
kvmppc_mmu_map_page(). This call is inside a region locked with
kvm->mmu_lock, which is the same lock that is called by the KVM
MMU notifier functions, thus ensuring that no new notification can
proceed while we are in the locked region. Inside this region we
also create the host HPTE and link the corresponding hpte_cache
structure into the lists used to find it later. We cannot allocate
the hpte_cache structure inside this locked region because that can
lead to deadlock, so we allocate it outside the region and free it
if we end up not using it.
This also moves the updates of vcpu3s->hpte_cache_count inside the
regions locked with vcpu3s->mmu_lock, and does the increment in
kvmppc_mmu_hpte_cache_map() when the pte is added to the cache
rather than when it is allocated, in order that the hpte_cache_count
is accurate.
Signed-off-by: Paul Mackerras <paulus@samba.org>
Signed-off-by: Alexander Graf <agraf@suse.de>
2013-09-20 08:52:52 +04:00
|
|
|
void kvmppc_mmu_hpte_cache_free(struct hpte_cache *pte)
|
|
|
|
{
|
|
|
|
kmem_cache_free(hpte_cache, pte);
|
|
|
|
}
|
|
|
|
|
2010-06-30 17:18:45 +04:00
|
|
|
void kvmppc_mmu_hpte_destroy(struct kvm_vcpu *vcpu)
|
|
|
|
{
|
|
|
|
kvmppc_mmu_pte_flush(vcpu, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void kvmppc_mmu_hpte_init_hash(struct hlist_head *hash_list, int len)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < len; i++)
|
|
|
|
INIT_HLIST_HEAD(&hash_list[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
int kvmppc_mmu_hpte_init(struct kvm_vcpu *vcpu)
|
|
|
|
{
|
2011-06-29 04:17:33 +04:00
|
|
|
struct kvmppc_vcpu_book3s *vcpu3s = to_book3s(vcpu);
|
|
|
|
|
2010-06-30 17:18:45 +04:00
|
|
|
/* init hpte lookup hashes */
|
2011-06-29 04:17:33 +04:00
|
|
|
kvmppc_mmu_hpte_init_hash(vcpu3s->hpte_hash_pte,
|
|
|
|
ARRAY_SIZE(vcpu3s->hpte_hash_pte));
|
|
|
|
kvmppc_mmu_hpte_init_hash(vcpu3s->hpte_hash_pte_long,
|
|
|
|
ARRAY_SIZE(vcpu3s->hpte_hash_pte_long));
|
|
|
|
kvmppc_mmu_hpte_init_hash(vcpu3s->hpte_hash_vpte,
|
|
|
|
ARRAY_SIZE(vcpu3s->hpte_hash_vpte));
|
|
|
|
kvmppc_mmu_hpte_init_hash(vcpu3s->hpte_hash_vpte_long,
|
|
|
|
ARRAY_SIZE(vcpu3s->hpte_hash_vpte_long));
|
2013-09-20 08:52:44 +04:00
|
|
|
#ifdef CONFIG_PPC_BOOK3S_64
|
|
|
|
kvmppc_mmu_hpte_init_hash(vcpu3s->hpte_hash_vpte_64k,
|
|
|
|
ARRAY_SIZE(vcpu3s->hpte_hash_vpte_64k));
|
|
|
|
#endif
|
2011-06-29 04:17:33 +04:00
|
|
|
|
|
|
|
spin_lock_init(&vcpu3s->mmu_lock);
|
2010-07-29 17:04:17 +04:00
|
|
|
|
2010-06-30 17:18:45 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int kvmppc_mmu_hpte_sysinit(void)
|
|
|
|
{
|
|
|
|
/* init hpte slab cache */
|
|
|
|
hpte_cache = kmem_cache_create("kvm-spt", sizeof(struct hpte_cache),
|
|
|
|
sizeof(struct hpte_cache), 0, NULL);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void kvmppc_mmu_hpte_sysexit(void)
|
|
|
|
{
|
|
|
|
kmem_cache_destroy(hpte_cache);
|
|
|
|
}
|