linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: "Aneesh Kumar K.V" <aneesh.kumar@linux.vnet.ibm.com>
To: benh@kernel.crashing.org, paulus@samba.org, mpe@ellerman.id.au,
	Anton Blanchard <anton@ozlabs.org>
Cc: linuxppc-dev@lists.ozlabs.org,
	"Aneesh Kumar K.V" <aneesh.kumar@linux.vnet.ibm.com>
Subject: [RFC PATCH 01/17] powerpc/mm: Update native_hpte_find to return hash pte
Date: Wed,  2 Aug 2017 11:10:00 +0530	[thread overview]
Message-ID: <20170802054016.8927-2-aneesh.kumar@linux.vnet.ibm.com> (raw)
In-Reply-To: <20170802054016.8927-1-aneesh.kumar@linux.vnet.ibm.com>

The helper now also does a secondary hash search so that we can use this in other
functions.

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
---
 arch/powerpc/mm/hash_native_64.c | 70 +++++++++++++++++++++++-----------------
 1 file changed, 40 insertions(+), 30 deletions(-)

diff --git a/arch/powerpc/mm/hash_native_64.c b/arch/powerpc/mm/hash_native_64.c
index 3848af167df9..4b3f6d66e7f0 100644
--- a/arch/powerpc/mm/hash_native_64.c
+++ b/arch/powerpc/mm/hash_native_64.c
@@ -351,32 +351,44 @@ static long native_hpte_updatepp(unsigned long slot, unsigned long newpp,
 	return ret;
 }
 
-static long native_hpte_find(unsigned long vpn, int psize, int ssize)
+/* returns a locked hash pte */
+struct hash_pte *native_hpte_find(unsigned long hash, unsigned long vpn,
+				  unsigned long bpsize, unsigned long ssize)
 {
+	int i;
+	unsigned long hpte_v;
 	struct hash_pte *hptep;
-	unsigned long hash;
-	unsigned long i;
-	long slot;
-	unsigned long want_v, hpte_v;
-
-	hash = hpt_hash(vpn, mmu_psize_defs[psize].shift, ssize);
-	want_v = hpte_encode_avpn(vpn, psize, ssize);
+	unsigned long want_v, slot;
+	bool secondary_search = false;
 
-	/* Bolted mappings are only ever in the primary group */
+	want_v = hpte_encode_avpn(vpn, bpsize, ssize);
 	slot = (hash & htab_hash_mask) * HPTES_PER_GROUP;
-	for (i = 0; i < HPTES_PER_GROUP; i++) {
-		hptep = htab_address + slot;
+
+	/*
+	 * search for hpte in the primary group
+	 */
+search_again:
+	hptep = htab_address + slot;
+	for (i = 0; i < HPTES_PER_GROUP; i++, hptep++) {
+		/*
+		 * FIXME!! Should we check locklessly check first ?
+		 */
+		native_lock_hpte(hptep);
 		hpte_v = be64_to_cpu(hptep->v);
 		if (cpu_has_feature(CPU_FTR_ARCH_300))
 			hpte_v = hpte_new_to_old_v(hpte_v, be64_to_cpu(hptep->r));
-
-		if (HPTE_V_COMPARE(hpte_v, want_v) && (hpte_v & HPTE_V_VALID))
-			/* HPTE matches */
-			return slot;
-		++slot;
+		if (!HPTE_V_COMPARE(hpte_v, want_v) || !(hpte_v & HPTE_V_VALID))
+			native_unlock_hpte(hptep);
+		else
+			return hptep;
 	}
-
-	return -1;
+	if (!secondary_search) {
+		/* Search for hpte in the secondary group */
+		slot = (~hash & htab_hash_mask) * HPTES_PER_GROUP;
+		secondary_search = true;
+		goto search_again;
+	}
+	return NULL;
 }
 
 /*
@@ -389,23 +401,22 @@ static long native_hpte_find(unsigned long vpn, int psize, int ssize)
 static void native_hpte_updateboltedpp(unsigned long newpp, unsigned long ea,
 				       int psize, int ssize)
 {
-	unsigned long vpn;
-	unsigned long vsid;
-	long slot;
+	unsigned long hash;
+	unsigned long vpn, vsid;
 	struct hash_pte *hptep;
 
 	vsid = get_kernel_vsid(ea, ssize);
 	vpn = hpt_vpn(ea, vsid, ssize);
-
-	slot = native_hpte_find(vpn, psize, ssize);
-	if (slot == -1)
+	hash = hpt_hash(vpn, mmu_psize_defs[psize].shift, ssize);
+	hptep = native_hpte_find(hash, vpn, psize, ssize);
+	if (!hptep)
 		panic("could not find page to bolt\n");
-	hptep = htab_address + slot;
 
 	/* Update the HPTE */
 	hptep->r = cpu_to_be64((be64_to_cpu(hptep->r) &
 				~(HPTE_R_PPP | HPTE_R_N)) |
 			       (newpp & (HPTE_R_PPP | HPTE_R_N)));
+	native_unlock_hpte(hptep);
 	/*
 	 * Ensure it is out of the tlb too. Bolted entries base and
 	 * actual page size will be same.
@@ -422,18 +433,17 @@ static int native_hpte_removebolted(unsigned long ea, int psize, int ssize)
 {
 	unsigned long vpn;
 	unsigned long vsid;
-	long slot;
+	unsigned long hash;
 	struct hash_pte *hptep;
 
 	vsid = get_kernel_vsid(ea, ssize);
 	vpn = hpt_vpn(ea, vsid, ssize);
+	hash = hpt_hash(vpn, mmu_psize_defs[psize].shift, ssize);
 
-	slot = native_hpte_find(vpn, psize, ssize);
-	if (slot == -1)
+	hptep = native_hpte_find(hash, vpn, psize, ssize);
+	if (!hptep)
 		return -ENOENT;
 
-	hptep = htab_address + slot;
-
 	VM_WARN_ON(!(be64_to_cpu(hptep->v) & HPTE_V_BOLTED));
 
 	/* Invalidate the hpte */
-- 
2.13.3

  reply	other threads:[~2017-08-02  5:40 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-02  5:39 [RFC PATCH 00/17] Remove slot tracking from linux page table Aneesh Kumar K.V
2017-08-02  5:40 ` Aneesh Kumar K.V [this message]
2017-08-02  5:40 ` [RFC PATCH 02/17] powerpc/pseries: Update hpte find helper to take hash value Aneesh Kumar K.V
2017-08-02  5:40 ` [RFC PATCH 03/17] powerpc/ps3/mm: Add helper for finding hash pte slot using " Aneesh Kumar K.V
2017-08-02  5:40 ` [RFC PATCH 04/17] powerpc/mm: Add hash invalidate callback Aneesh Kumar K.V
2017-08-02  5:40 ` [RFC PATCH 05/17] powerpc/mm: use hash_invalidate for __kernel_map_pages() Aneesh Kumar K.V
2017-08-02  5:40 ` [RFC PATCH 06/17] powerpc/mm: Switch flush_hash_range to not use slot Aneesh Kumar K.V
2017-08-02  5:40 ` [RFC PATCH 07/17] powerpc/mm: Add hash updatepp callback Aneesh Kumar K.V
2017-08-02  5:40 ` [RFC PATCH 08/17] powerpc/mm/hash: Don't track hash pte slot number in linux page table Aneesh Kumar K.V
2017-08-02  5:40 ` [RFC PATCH 09/17] powerpc/mm: Remove unused flag arg in global_invalidates Aneesh Kumar K.V
2017-08-02  5:40 ` [RFC PATCH 10/17] powerpc/mm: Add new firmware feature HASH API Aneesh Kumar K.V
2017-08-02  5:40 ` [RFC PATCH 11/17] powerpc/kvm/hash: Implement HASH_REMOVE hcall Aneesh Kumar K.V
2017-08-02  5:40 ` [RFC PATCH 12/17] powerpc/kvm/hash: Implement HASH_PROTECT hcall Aneesh Kumar K.V
2017-08-02  5:40 ` [RFC PATCH 13/17] powerpc/kvm/hash: Implement HASH_BULK_REMOVE hcall Aneesh Kumar K.V
2017-08-02  5:40 ` [RFC PATCH 14/17] powerpc/mm/pseries: Use HASH_PROTECT hcall in guest Aneesh Kumar K.V
2017-08-02  5:40 ` [RFC PATCH 15/17] powerpc/mm/pseries: Use HASH_REMOVE " Aneesh Kumar K.V
2017-08-02  5:40 ` [RFC PATCH 16/17] powerpc/mm/pseries: Move slot based bulk remove to helper Aneesh Kumar K.V
2017-08-02 12:50   ` Segher Boessenkool
2017-08-02  5:40 ` [RFC PATCH 17/17] powerpc/mm/pseries: Use HASH_BULK_REMOVE hcall in guest Aneesh Kumar K.V

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=20170802054016.8927-2-aneesh.kumar@linux.vnet.ibm.com \
    --to=aneesh.kumar@linux.vnet.ibm.com \
    --cc=anton@ozlabs.org \
    --cc=benh@kernel.crashing.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=mpe@ellerman.id.au \
    --cc=paulus@samba.org \
    /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;
as well as URLs for NNTP newsgroup(s).