All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/4] VPHN parsing fixes
@ 2014-12-17  9:40 Greg Kurz
  2014-12-17  9:41 ` [PATCH v2 1/4] powerpc/vphn: clarify the H_HOME_NODE_ASSOCIATIVITY API Greg Kurz
                   ` (4 more replies)
  0 siblings, 5 replies; 9+ messages in thread
From: Greg Kurz @ 2014-12-17  9:40 UTC (permalink / raw)
  To: linuxppc-dev

Hi,

This series addresses remarks from Ben and Michael (see individual patches).
The most notable changes are:
- the parsing code being pull out into a separate file in patch 3/4. This
  allows to write userland tests like the one below.
- a full rewrite of the parsing logic in patch 4/4

--
#include <stdio.h>
#include <byteswap.h>

typedef unsigned long u64;
typedef unsigned int u32;
typedef unsigned short u16;
typedef enum { false = 0, true } bool;

#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
#define cpu_to_be32(x)		bswap_32(x)
#define be32_to_cpu(x)		bswap_32(x)
#define be16_to_cpup(x)		bswap_16(*x)
#define cpu_to_be64(x)		bswap_64(x)
#else
#define cpu_to_be32(x)		(x)
#define be32_to_cpu(x)		(x)
#define be16_to_cpup(x)		(*x)
#define cpu_to_be64(x)		(x)
#endif

#define pr_debug(...) printf(__VA_ARGS__)

#include "vphn.c"

void print_packed(const long *packed)
{
	char *p = (char*) packed;
	int i;

	printf("\nRegisters:\n");
	for (i = 0; i < VPHN_REGISTER_COUNT; i++)
		printf("0x%016lx\n", packed[i]);

	printf("\nMemory layout:\n");
	for (i = 0; i < 6; i++) {
		printf("0x %02hhx %02hhx %02hhx %02hhx"
		       " %02hhx %02hhx %02hhx %02hhx\n",
		       *(p + 0), *(p + 1), *(p + 2), *(p + 3),
		       *(p + 4), *(p + 5), *(p + 6), *(p + 7));
		p += 8;
	}

	putchar('\n');
}

void print_unpacked(const __be32 *unpacked)
{
	int i;

	printf("\nVPHN associativity:\n");
	for (i = 0; i <= be32_to_cpu(unpacked[0]); i++)
		printf("0x%08x\n", be32_to_cpu(unpacked[i]));

	putchar('\n');
}

int main(int argc, char **argv)
{
	int i;
	struct {
		const char *descr;
		long packed[VPHN_REGISTER_COUNT];
	} data[] = {
		{
			"16-bit and 32-bit",
			0x8001800280038004,
			0x8005800680078008,
			0x000000090000000a,
			0x0000000b0000000c,
			0xffffffffffffffff,
			0xffffffffffffffff
		},
		{
			"filled with 16-bit",
			0x8001800280038004,
			0x8005800680078008,
			0x8009800a800b800c,
			0x800d800e800f8010,
			0x8011801280138014,
			0x8015801680178018,
		},
		{
			"filled with 32-bit",
			0x0000000100000002,
			0x0000000300000004,
			0x0000000500000006,
			0x0000000700000008,
			0x000000090000000a,
			0x0000000b0000000c,
		},
		{
			"32-bit has all ones in 16 lower bits",
			0x0001ffff80028003,
			0xffffffffffffffff,
			0xffffffffffffffff,
			0xffffffffffffffff,
			0xffffffffffffffff,
			0xffffffffffffffff,
		},
		{
			"32-bit accross two 64-bit registers",
			0x8001000000020000,
			0x0003000000048005,
			0xffffffffffffffff,
			0xffffffffffffffff,
			0xffffffffffffffff,
			0xffffffffffffffff,
		},
		{
			"Truncated last 32-bit",
			0x0000000100000002,
			0x0000000300000004,
			0x0000000500000006,
			0x0000000700000008,
			0x000000090000000a,
			0x0000000b800c0bad,
		},
	};

	for (i = 0; i < sizeof(data) / sizeof(data[0]); i++) {
		__be32 unpacked[VPHN_ASSOC_BUFSIZE] = { 0 };
		printf("\n==================================================\n");
		printf("\nSet #%d: %s\n", i, data[i].descr);
		printf("\n==================================================\n");
		print_packed(data[i].packed);
		vphn_unpack_associativity(data[i].packed, unpacked);
		print_unpacked(unpacked);
	}

	return 0;
}

---

Greg Kurz (4):
      powerpc/vphn: clarify the H_HOME_NODE_ASSOCIATIVITY API
      powerpc/vphn: move endianness fixing to vphn_unpack_associativity()
      powerpc/vphn: move VPHN parsing logic to a separate file
      powerpc/vphn: parsing code rewrite


 arch/powerpc/mm/Makefile |    1 +
 arch/powerpc/mm/numa.c   |   55 ++----------------------------------
 arch/powerpc/mm/vphn.c   |   70 ++++++++++++++++++++++++++++++++++++++++++++++
 arch/powerpc/mm/vphn.h   |   16 +++++++++++
 4 files changed, 90 insertions(+), 52 deletions(-)
 create mode 100644 arch/powerpc/mm/vphn.c
 create mode 100644 arch/powerpc/mm/vphn.h

--
Greg

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH v2 1/4] powerpc/vphn: clarify the H_HOME_NODE_ASSOCIATIVITY API
  2014-12-17  9:40 [PATCH v2 0/4] VPHN parsing fixes Greg Kurz
@ 2014-12-17  9:41 ` Greg Kurz
  2014-12-17  9:42 ` [PATCH v2 2/4] powerpc/vphn: move endianness fixing to vphn_unpack_associativity() Greg Kurz
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 9+ messages in thread
From: Greg Kurz @ 2014-12-17  9:41 UTC (permalink / raw)
  To: linuxppc-dev

The number of values returned by the H_HOME_NODE_ASSOCIATIVITY h_call deserves
to be explicitly defined, for a better understanding of the code.

Signed-off-by: Greg Kurz <gkurz@linux.vnet.ibm.com>
---

 No changes in v2.

 arch/powerpc/mm/numa.c |    8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/mm/numa.c b/arch/powerpc/mm/numa.c
index 417b0a5..2a83e48 100644
--- a/arch/powerpc/mm/numa.c
+++ b/arch/powerpc/mm/numa.c
@@ -1247,11 +1247,15 @@ static int update_cpu_associativity_changes_mask(void)
 	return cpumask_weight(changes);
 }
 
+/* The H_HOME_NODE_ASSOCIATIVITY h_call returns 6 64-bit registers.
+ */
+#define VPHN_REGISTER_COUNT 6
+
 /*
  * 6 64-bit registers unpacked into 12 32-bit associativity values. To form
  * the complete property we have to add the length in the first cell.
  */
-#define VPHN_ASSOC_BUFSIZE (6*sizeof(u64)/sizeof(u32) + 1)
+#define VPHN_ASSOC_BUFSIZE (VPHN_REGISTER_COUNT*sizeof(u64)/sizeof(u32) + 1)
 
 /*
  * Convert the associativity domain numbers returned from the hypervisor
@@ -1309,7 +1313,7 @@ static long hcall_vphn(unsigned long cpu, __be32 *associativity)
 	int i;
 
 	rc = plpar_hcall9(H_HOME_NODE_ASSOCIATIVITY, retbuf, flags, hwcpu);
-	for (i = 0; i < 6; i++)
+	for (i = 0; i < VPHN_REGISTER_COUNT; i++)
 		retbuf[i] = cpu_to_be64(retbuf[i]);
 	vphn_unpack_associativity(retbuf, associativity);
 

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH v2 2/4] powerpc/vphn: move endianness fixing to vphn_unpack_associativity()
  2014-12-17  9:40 [PATCH v2 0/4] VPHN parsing fixes Greg Kurz
  2014-12-17  9:41 ` [PATCH v2 1/4] powerpc/vphn: clarify the H_HOME_NODE_ASSOCIATIVITY API Greg Kurz
@ 2014-12-17  9:42 ` Greg Kurz
  2014-12-17  9:42 ` [PATCH v2 3/4] powerpc/vphn: move VPHN parsing logic to a separate file Greg Kurz
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 9+ messages in thread
From: Greg Kurz @ 2014-12-17  9:42 UTC (permalink / raw)
  To: linuxppc-dev

The first argument to vphn_unpack_associativity() is a const long *, but the
parsing code expects __be64 values actually. Let's move the endian fixing
down for consistency.

Signed-off-by: Greg Kurz <gkurz@linux.vnet.ibm.com>
---

 v2: only move the endian fixing. The logic is reworked in another patch.

 arch/powerpc/mm/numa.c |   10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/arch/powerpc/mm/numa.c b/arch/powerpc/mm/numa.c
index 2a83e48..2e36a6f 100644
--- a/arch/powerpc/mm/numa.c
+++ b/arch/powerpc/mm/numa.c
@@ -1263,13 +1263,18 @@ static int update_cpu_associativity_changes_mask(void)
  */
 static int vphn_unpack_associativity(const long *packed, __be32 *unpacked)
 {
+	__be64 be_packed[VPHN_REGISTER_COUNT];
 	int i, nr_assoc_doms = 0;
-	const __be16 *field = (const __be16 *) packed;
+	const __be16 *field = (const __be16 *) be_packed;
 
 #define VPHN_FIELD_UNUSED	(0xffff)
 #define VPHN_FIELD_MSB		(0x8000)
 #define VPHN_FIELD_MASK		(~VPHN_FIELD_MSB)
 
+	/* Let's recreate the original stream. */
+	for (i = 0; i < VPHN_REGISTER_COUNT; i++)
+		be_packed[i] = cpu_to_be64(packed[i]);
+
 	for (i = 1; i < VPHN_ASSOC_BUFSIZE; i++) {
 		if (be16_to_cpup(field) == VPHN_FIELD_UNUSED) {
 			/* All significant fields processed, and remaining
@@ -1310,11 +1315,8 @@ static long hcall_vphn(unsigned long cpu, __be32 *associativity)
 	long retbuf[PLPAR_HCALL9_BUFSIZE] = {0};
 	u64 flags = 1;
 	int hwcpu = get_hard_smp_processor_id(cpu);
-	int i;
 
 	rc = plpar_hcall9(H_HOME_NODE_ASSOCIATIVITY, retbuf, flags, hwcpu);
-	for (i = 0; i < VPHN_REGISTER_COUNT; i++)
-		retbuf[i] = cpu_to_be64(retbuf[i]);
 	vphn_unpack_associativity(retbuf, associativity);
 
 	return rc;

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH v2 3/4] powerpc/vphn: move VPHN parsing logic to a separate file
  2014-12-17  9:40 [PATCH v2 0/4] VPHN parsing fixes Greg Kurz
  2014-12-17  9:41 ` [PATCH v2 1/4] powerpc/vphn: clarify the H_HOME_NODE_ASSOCIATIVITY API Greg Kurz
  2014-12-17  9:42 ` [PATCH v2 2/4] powerpc/vphn: move endianness fixing to vphn_unpack_associativity() Greg Kurz
@ 2014-12-17  9:42 ` Greg Kurz
  2014-12-17  9:43 ` [PATCH v2 4/4] powerpc/vphn: parsing code rewrite Greg Kurz
  2015-01-29 18:03 ` [PATCH v2 0/4] VPHN parsing fixes Greg Kurz
  4 siblings, 0 replies; 9+ messages in thread
From: Greg Kurz @ 2014-12-17  9:42 UTC (permalink / raw)
  To: linuxppc-dev

The goal behind this patch is to be able to write userland tests for the
VPHN parsing code.

Suggested-by: Michael Ellerman <mpe@ellerman.id.au>
Signed-off-by: Greg Kurz <gkurz@linux.vnet.ibm.com>
---
 arch/powerpc/mm/Makefile |    1 +
 arch/powerpc/mm/numa.c   |   61 ++--------------------------------------------
 arch/powerpc/mm/vphn.c   |   50 ++++++++++++++++++++++++++++++++++++++
 arch/powerpc/mm/vphn.h   |   16 ++++++++++++
 4 files changed, 70 insertions(+), 58 deletions(-)
 create mode 100644 arch/powerpc/mm/vphn.c
 create mode 100644 arch/powerpc/mm/vphn.h

diff --git a/arch/powerpc/mm/Makefile b/arch/powerpc/mm/Makefile
index 438dcd3..9c8770b 100644
--- a/arch/powerpc/mm/Makefile
+++ b/arch/powerpc/mm/Makefile
@@ -24,6 +24,7 @@ obj-$(CONFIG_40x)		+= 40x_mmu.o
 obj-$(CONFIG_44x)		+= 44x_mmu.o
 obj-$(CONFIG_PPC_FSL_BOOK3E)	+= fsl_booke_mmu.o
 obj-$(CONFIG_NEED_MULTIPLE_NODES) += numa.o
+obj-$(CONFIG_PPC_SPLPAR)	+= vphn.o
 obj-$(CONFIG_PPC_MM_SLICES)	+= slice.o
 obj-y				+= hugetlbpage.o
 ifeq ($(CONFIG_HUGETLB_PAGE),y)
diff --git a/arch/powerpc/mm/numa.c b/arch/powerpc/mm/numa.c
index 2e36a6f..008af17 100644
--- a/arch/powerpc/mm/numa.c
+++ b/arch/powerpc/mm/numa.c
@@ -1177,6 +1177,9 @@ u64 memory_hotplug_max(void)
 
 /* Virtual Processor Home Node (VPHN) support */
 #ifdef CONFIG_PPC_SPLPAR
+
+#include "vphn.h"
+
 struct topology_update_data {
 	struct topology_update_data *next;
 	unsigned int cpu;
@@ -1247,64 +1250,6 @@ static int update_cpu_associativity_changes_mask(void)
 	return cpumask_weight(changes);
 }
 
-/* The H_HOME_NODE_ASSOCIATIVITY h_call returns 6 64-bit registers.
- */
-#define VPHN_REGISTER_COUNT 6
-
-/*
- * 6 64-bit registers unpacked into 12 32-bit associativity values. To form
- * the complete property we have to add the length in the first cell.
- */
-#define VPHN_ASSOC_BUFSIZE (VPHN_REGISTER_COUNT*sizeof(u64)/sizeof(u32) + 1)
-
-/*
- * Convert the associativity domain numbers returned from the hypervisor
- * to the sequence they would appear in the ibm,associativity property.
- */
-static int vphn_unpack_associativity(const long *packed, __be32 *unpacked)
-{
-	__be64 be_packed[VPHN_REGISTER_COUNT];
-	int i, nr_assoc_doms = 0;
-	const __be16 *field = (const __be16 *) be_packed;
-
-#define VPHN_FIELD_UNUSED	(0xffff)
-#define VPHN_FIELD_MSB		(0x8000)
-#define VPHN_FIELD_MASK		(~VPHN_FIELD_MSB)
-
-	/* Let's recreate the original stream. */
-	for (i = 0; i < VPHN_REGISTER_COUNT; i++)
-		be_packed[i] = cpu_to_be64(packed[i]);
-
-	for (i = 1; i < VPHN_ASSOC_BUFSIZE; i++) {
-		if (be16_to_cpup(field) == VPHN_FIELD_UNUSED) {
-			/* All significant fields processed, and remaining
-			 * fields contain the reserved value of all 1's.
-			 * Just store them.
-			 */
-			unpacked[i] = *((__be32 *)field);
-			field += 2;
-		} else if (be16_to_cpup(field) & VPHN_FIELD_MSB) {
-			/* Data is in the lower 15 bits of this field */
-			unpacked[i] = cpu_to_be32(
-				be16_to_cpup(field) & VPHN_FIELD_MASK);
-			field++;
-			nr_assoc_doms++;
-		} else {
-			/* Data is in the lower 15 bits of this field
-			 * concatenated with the next 16 bit field
-			 */
-			unpacked[i] = *((__be32 *)field);
-			field += 2;
-			nr_assoc_doms++;
-		}
-	}
-
-	/* The first cell contains the length of the property */
-	unpacked[0] = cpu_to_be32(nr_assoc_doms);
-
-	return nr_assoc_doms;
-}
-
 /*
  * Retrieve the new associativity information for a virtual processor's
  * home node.
diff --git a/arch/powerpc/mm/vphn.c b/arch/powerpc/mm/vphn.c
new file mode 100644
index 0000000..c49ed51
--- /dev/null
+++ b/arch/powerpc/mm/vphn.c
@@ -0,0 +1,50 @@
+#include <asm/byteorder.h>
+#include "vphn.h"
+
+/*
+ * Convert the associativity domain numbers returned from the hypervisor
+ * to the sequence they would appear in the ibm,associativity property.
+ */
+int vphn_unpack_associativity(const long *packed, __be32 *unpacked)
+{
+	__be64 be_packed[VPHN_REGISTER_COUNT];
+	int i, nr_assoc_doms = 0;
+	const __be16 *field = (const __be16 *) be_packed;
+
+#define VPHN_FIELD_UNUSED	(0xffff)
+#define VPHN_FIELD_MSB		(0x8000)
+#define VPHN_FIELD_MASK		(~VPHN_FIELD_MSB)
+
+	/* Let's recreate the original stream. */
+	for (i = 0; i < VPHN_REGISTER_COUNT; i++)
+		be_packed[i] = cpu_to_be64(packed[i]);
+
+	for (i = 1; i < VPHN_ASSOC_BUFSIZE; i++) {
+		if (be16_to_cpup(field) == VPHN_FIELD_UNUSED) {
+			/* All significant fields processed, and remaining
+			 * fields contain the reserved value of all 1's.
+			 * Just store them.
+			 */
+			unpacked[i] = *((__be32 *)field);
+			field += 2;
+		} else if (be16_to_cpup(field) & VPHN_FIELD_MSB) {
+			/* Data is in the lower 15 bits of this field */
+			unpacked[i] = cpu_to_be32(
+				be16_to_cpup(field) & VPHN_FIELD_MASK);
+			field++;
+			nr_assoc_doms++;
+		} else {
+			/* Data is in the lower 15 bits of this field
+			 * concatenated with the next 16 bit field
+			 */
+			unpacked[i] = *((__be32 *)field);
+			field += 2;
+			nr_assoc_doms++;
+		}
+	}
+
+	/* The first cell contains the length of the property */
+	unpacked[0] = cpu_to_be32(nr_assoc_doms);
+
+	return nr_assoc_doms;
+}
diff --git a/arch/powerpc/mm/vphn.h b/arch/powerpc/mm/vphn.h
new file mode 100644
index 0000000..96af9a4
--- /dev/null
+++ b/arch/powerpc/mm/vphn.h
@@ -0,0 +1,16 @@
+#ifndef _ARCH_POWERPC_MM_VPHN_H_
+#define _ARCH_POWERPC_MM_VPHN_H_
+
+/* The H_HOME_NODE_ASSOCIATIVITY h_call returns 6 64-bit registers.
+ */
+#define VPHN_REGISTER_COUNT 6
+
+/*
+ * 6 64-bit registers unpacked into 12 32-bit associativity values. To form
+ * the complete property we have to add the length in the first cell.
+ */
+#define VPHN_ASSOC_BUFSIZE (VPHN_REGISTER_COUNT*sizeof(u64)/sizeof(u32) + 1)
+
+extern int vphn_unpack_associativity(const long *packed, __be32 *unpacked);
+
+#endif

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH v2 4/4] powerpc/vphn: parsing code rewrite
  2014-12-17  9:40 [PATCH v2 0/4] VPHN parsing fixes Greg Kurz
                   ` (2 preceding siblings ...)
  2014-12-17  9:42 ` [PATCH v2 3/4] powerpc/vphn: move VPHN parsing logic to a separate file Greg Kurz
@ 2014-12-17  9:43 ` Greg Kurz
  2015-01-29 18:03 ` [PATCH v2 0/4] VPHN parsing fixes Greg Kurz
  4 siblings, 0 replies; 9+ messages in thread
From: Greg Kurz @ 2014-12-17  9:43 UTC (permalink / raw)
  To: linuxppc-dev

The current VPHN parsing logic has some flaws that this patch aims to fix:

1) when the value 0xffff is read, the value 0xffffffff gets added to the
   the output list and its element count isn't incremented. This is wrong.
   According to PAPR+ the domain identifiers are packed into a sequence
   terminated by the "reserved value of all ones". This means that 0xffff
   is a stream terminator.

2) the combination of byteswaps and casts make the code hardly readable.
   Let's parse the stream one 16-bit field at a time instead.

3) it is assumed that the hypercall returns 12 32-bit values packed into
   6 64-bit registers. According to PAPR+, the domain identifiers may be
   streamed as 16-bit values. Let's increase the number of expected numbers
   to 24.

Signed-off-by: Greg Kurz <gkurz@linux.vnet.ibm.com>
---
 arch/powerpc/mm/vphn.c |   54 +++++++++++++++++++++++++++++++++---------------
 arch/powerpc/mm/vphn.h |    6 +++--
 2 files changed, 40 insertions(+), 20 deletions(-)

diff --git a/arch/powerpc/mm/vphn.c b/arch/powerpc/mm/vphn.c
index c49ed51..5f8ef50 100644
--- a/arch/powerpc/mm/vphn.c
+++ b/arch/powerpc/mm/vphn.c
@@ -2,44 +2,64 @@
 #include "vphn.h"
 
 /*
- * Convert the associativity domain numbers returned from the hypervisor
- * to the sequence they would appear in the ibm,associativity property.
+ * The associativity domain numbers are returned from the hypervisor as a
+ * stream of mixed 16-bit and 32-bit fields. The stream is terminated by the
+ * special value of "all ones" (aka. 0xffff) and its size may not exceed 48
+ * bytes.
+ *
+ *    --- 16-bit fields -->
+ *  _________________________
+ *  |  0  |  1  |  2  |  3  |   be_packed[0]
+ *  ------+-----+-----+------
+ *  _________________________
+ *  |  4  |  5  |  6  |  7  |   be_packed[1]
+ *  -------------------------
+ *            ...
+ *  _________________________
+ *  | 20  | 21  | 22  | 23  |   be_packed[5]
+ *  -------------------------
+ *
+ * Convert to the sequence they would appear in the ibm,associativity property.
  */
 int vphn_unpack_associativity(const long *packed, __be32 *unpacked)
 {
 	__be64 be_packed[VPHN_REGISTER_COUNT];
 	int i, nr_assoc_doms = 0;
 	const __be16 *field = (const __be16 *) be_packed;
+	u16 last = 0;
+	bool is_32bit = false;
 
 #define VPHN_FIELD_UNUSED	(0xffff)
 #define VPHN_FIELD_MSB		(0x8000)
 #define VPHN_FIELD_MASK		(~VPHN_FIELD_MSB)
 
-	/* Let's recreate the original stream. */
+	/* Let's fix the values returned by plpar_hcall9() */
 	for (i = 0; i < VPHN_REGISTER_COUNT; i++)
 		be_packed[i] = cpu_to_be64(packed[i]);
 
 	for (i = 1; i < VPHN_ASSOC_BUFSIZE; i++) {
-		if (be16_to_cpup(field) == VPHN_FIELD_UNUSED) {
-			/* All significant fields processed, and remaining
-			 * fields contain the reserved value of all 1's.
-			 * Just store them.
+		u16 new = be16_to_cpup(field++);
+
+		if (is_32bit) {
+			/* Let's concatenate the 16 bits of this field to the
+			 * 15 lower bits of the previous field
 			 */
-			unpacked[i] = *((__be32 *)field);
-			field += 2;
-		} else if (be16_to_cpup(field) & VPHN_FIELD_MSB) {
+			unpacked[++nr_assoc_doms] =
+				cpu_to_be32(last << 16 | new);
+			is_32bit = false;
+		} else if (new == VPHN_FIELD_UNUSED)
+			/* This is the list terminator */
+			break;
+		else if (new & VPHN_FIELD_MSB) {
 			/* Data is in the lower 15 bits of this field */
-			unpacked[i] = cpu_to_be32(
-				be16_to_cpup(field) & VPHN_FIELD_MASK);
-			field++;
-			nr_assoc_doms++;
+			unpacked[++nr_assoc_doms] =
+				cpu_to_be32(new & VPHN_FIELD_MASK);
 		} else {
 			/* Data is in the lower 15 bits of this field
 			 * concatenated with the next 16 bit field
 			 */
-			unpacked[i] = *((__be32 *)field);
-			field += 2;
-			nr_assoc_doms++;
+			last = new;
+			is_32bit = true;
 		}
 	}
 
diff --git a/arch/powerpc/mm/vphn.h b/arch/powerpc/mm/vphn.h
index 96af9a4..fe8b780 100644
--- a/arch/powerpc/mm/vphn.h
+++ b/arch/powerpc/mm/vphn.h
@@ -6,10 +6,10 @@
 #define VPHN_REGISTER_COUNT 6
 
 /*
- * 6 64-bit registers unpacked into 12 32-bit associativity values. To form
- * the complete property we have to add the length in the first cell.
+ * 6 64-bit registers unpacked into up to 24 be32 associativity values. To
+ * form the complete property we have to add the length in the first cell.
  */
-#define VPHN_ASSOC_BUFSIZE (VPHN_REGISTER_COUNT*sizeof(u64)/sizeof(u32) + 1)
+#define VPHN_ASSOC_BUFSIZE (VPHN_REGISTER_COUNT*sizeof(u64)/sizeof(u16) + 1)
 
 extern int vphn_unpack_associativity(const long *packed, __be32 *unpacked);
 

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH v2 0/4] VPHN parsing fixes
  2014-12-17  9:40 [PATCH v2 0/4] VPHN parsing fixes Greg Kurz
                   ` (3 preceding siblings ...)
  2014-12-17  9:43 ` [PATCH v2 4/4] powerpc/vphn: parsing code rewrite Greg Kurz
@ 2015-01-29 18:03 ` Greg Kurz
  2015-02-03  2:47   ` Michael Ellerman
  4 siblings, 1 reply; 9+ messages in thread
From: Greg Kurz @ 2015-01-29 18:03 UTC (permalink / raw)
  To: linuxppc-dev

On Wed, 17 Dec 2014 10:40:46 +0100
Greg Kurz <gkurz@linux.vnet.ibm.com> wrote:
> Hi,
> 
> This series addresses remarks from Ben and Michael (see individual patches).
> The most notable changes are:
> - the parsing code being pull out into a separate file in patch 3/4. This
>   allows to write userland tests like the one below.
> - a full rewrite of the parsing logic in patch 4/4
> 

Ping ?

> --
> #include <stdio.h>
> #include <byteswap.h>
> 
> typedef unsigned long u64;
> typedef unsigned int u32;
> typedef unsigned short u16;
> typedef enum { false = 0, true } bool;
> 
> #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
> #define cpu_to_be32(x)		bswap_32(x)
> #define be32_to_cpu(x)		bswap_32(x)
> #define be16_to_cpup(x)		bswap_16(*x)
> #define cpu_to_be64(x)		bswap_64(x)
> #else
> #define cpu_to_be32(x)		(x)
> #define be32_to_cpu(x)		(x)
> #define be16_to_cpup(x)		(*x)
> #define cpu_to_be64(x)		(x)
> #endif
> 
> #define pr_debug(...) printf(__VA_ARGS__)
> 
> #include "vphn.c"
> 
> void print_packed(const long *packed)
> {
> 	char *p = (char*) packed;
> 	int i;
> 
> 	printf("\nRegisters:\n");
> 	for (i = 0; i < VPHN_REGISTER_COUNT; i++)
> 		printf("0x%016lx\n", packed[i]);
> 
> 	printf("\nMemory layout:\n");
> 	for (i = 0; i < 6; i++) {
> 		printf("0x %02hhx %02hhx %02hhx %02hhx"
> 		       " %02hhx %02hhx %02hhx %02hhx\n",
> 		       *(p + 0), *(p + 1), *(p + 2), *(p + 3),
> 		       *(p + 4), *(p + 5), *(p + 6), *(p + 7));
> 		p += 8;
> 	}
> 
> 	putchar('\n');
> }
> 
> void print_unpacked(const __be32 *unpacked)
> {
> 	int i;
> 
> 	printf("\nVPHN associativity:\n");
> 	for (i = 0; i <= be32_to_cpu(unpacked[0]); i++)
> 		printf("0x%08x\n", be32_to_cpu(unpacked[i]));
> 
> 	putchar('\n');
> }
> 
> int main(int argc, char **argv)
> {
> 	int i;
> 	struct {
> 		const char *descr;
> 		long packed[VPHN_REGISTER_COUNT];
> 	} data[] = {
> 		{
> 			"16-bit and 32-bit",
> 			0x8001800280038004,
> 			0x8005800680078008,
> 			0x000000090000000a,
> 			0x0000000b0000000c,
> 			0xffffffffffffffff,
> 			0xffffffffffffffff
> 		},
> 		{
> 			"filled with 16-bit",
> 			0x8001800280038004,
> 			0x8005800680078008,
> 			0x8009800a800b800c,
> 			0x800d800e800f8010,
> 			0x8011801280138014,
> 			0x8015801680178018,
> 		},
> 		{
> 			"filled with 32-bit",
> 			0x0000000100000002,
> 			0x0000000300000004,
> 			0x0000000500000006,
> 			0x0000000700000008,
> 			0x000000090000000a,
> 			0x0000000b0000000c,
> 		},
> 		{
> 			"32-bit has all ones in 16 lower bits",
> 			0x0001ffff80028003,
> 			0xffffffffffffffff,
> 			0xffffffffffffffff,
> 			0xffffffffffffffff,
> 			0xffffffffffffffff,
> 			0xffffffffffffffff,
> 		},
> 		{
> 			"32-bit accross two 64-bit registers",
> 			0x8001000000020000,
> 			0x0003000000048005,
> 			0xffffffffffffffff,
> 			0xffffffffffffffff,
> 			0xffffffffffffffff,
> 			0xffffffffffffffff,
> 		},
> 		{
> 			"Truncated last 32-bit",
> 			0x0000000100000002,
> 			0x0000000300000004,
> 			0x0000000500000006,
> 			0x0000000700000008,
> 			0x000000090000000a,
> 			0x0000000b800c0bad,
> 		},
> 	};
> 
> 	for (i = 0; i < sizeof(data) / sizeof(data[0]); i++) {
> 		__be32 unpacked[VPHN_ASSOC_BUFSIZE] = { 0 };
> 		printf("\n==================================================\n");
> 		printf("\nSet #%d: %s\n", i, data[i].descr);
> 		printf("\n==================================================\n");
> 		print_packed(data[i].packed);
> 		vphn_unpack_associativity(data[i].packed, unpacked);
> 		print_unpacked(unpacked);
> 	}
> 
> 	return 0;
> }
> 
> ---
> 
> Greg Kurz (4):
>       powerpc/vphn: clarify the H_HOME_NODE_ASSOCIATIVITY API
>       powerpc/vphn: move endianness fixing to vphn_unpack_associativity()
>       powerpc/vphn: move VPHN parsing logic to a separate file
>       powerpc/vphn: parsing code rewrite
> 
> 
>  arch/powerpc/mm/Makefile |    1 +
>  arch/powerpc/mm/numa.c   |   55 ++----------------------------------
>  arch/powerpc/mm/vphn.c   |   70 ++++++++++++++++++++++++++++++++++++++++++++++
>  arch/powerpc/mm/vphn.h   |   16 +++++++++++
>  4 files changed, 90 insertions(+), 52 deletions(-)
>  create mode 100644 arch/powerpc/mm/vphn.c
>  create mode 100644 arch/powerpc/mm/vphn.h
> 
> --
> Greg
> 
> _______________________________________________
> Linuxppc-dev mailing list
> Linuxppc-dev@lists.ozlabs.org
> https://lists.ozlabs.org/listinfo/linuxppc-dev

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v2 0/4] VPHN parsing fixes
  2015-01-29 18:03 ` [PATCH v2 0/4] VPHN parsing fixes Greg Kurz
@ 2015-02-03  2:47   ` Michael Ellerman
  2015-02-03  7:46     ` Greg Kurz
  0 siblings, 1 reply; 9+ messages in thread
From: Michael Ellerman @ 2015-02-03  2:47 UTC (permalink / raw)
  To: Greg Kurz; +Cc: linuxppc-dev

On Thu, 2015-01-29 at 19:03 +0100, Greg Kurz wrote:
> On Wed, 17 Dec 2014 10:40:46 +0100
> Greg Kurz <gkurz@linux.vnet.ibm.com> wrote:
> > Hi,
> > 
> > This series addresses remarks from Ben and Michael (see individual patches).
> > The most notable changes are:
> > - the parsing code being pull out into a separate file in patch 3/4. This
> >   allows to write userland tests like the one below.
> > - a full rewrite of the parsing logic in patch 4/4
> > 
> 
> Ping ?

Sorry, lots of patches needing review.

This looks pretty good at a glance, but did you actually write a userspace test
for it? If so please send it. I'm happy to rework it into something that can go
in selftests.

cheers

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v2 0/4] VPHN parsing fixes
  2015-02-03  2:47   ` Michael Ellerman
@ 2015-02-03  7:46     ` Greg Kurz
  2015-02-04  0:42       ` Michael Ellerman
  0 siblings, 1 reply; 9+ messages in thread
From: Greg Kurz @ 2015-02-03  7:46 UTC (permalink / raw)
  To: Michael Ellerman; +Cc: linuxppc-dev

On Tue, 03 Feb 2015 13:47:35 +1100
Michael Ellerman <mpe@ellerman.id.au> wrote:

> On Thu, 2015-01-29 at 19:03 +0100, Greg Kurz wrote:
> > On Wed, 17 Dec 2014 10:40:46 +0100
> > Greg Kurz <gkurz@linux.vnet.ibm.com> wrote:
> > > Hi,
> > > 
> > > This series addresses remarks from Ben and Michael (see individual patches).
> > > The most notable changes are:
> > > - the parsing code being pull out into a separate file in patch 3/4. This
> > >   allows to write userland tests like the one below.
> > > - a full rewrite of the parsing logic in patch 4/4
> > > 
> > 
> > Ping ?
> 
> Sorry, lots of patches needing review.
> 

Heh, no problem. :) Since this isn't bugfix, I can even repost later, when
the review pressure is lower.

> This looks pretty good at a glance, but did you actually write a userspace test
> for it? If so please send it. I'm happy to rework it into something that can go
> in selftests.
> 

Yes, I wrote the premise of a test program. You can find it in the cover mail of
this series:

https://lists.ozlabs.org/pipermail/linuxppc-dev/2014-December/123601.html

I'll have a look at selftests.

> cheers
> 
> 

Thanks.

--
Greg

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v2 0/4] VPHN parsing fixes
  2015-02-03  7:46     ` Greg Kurz
@ 2015-02-04  0:42       ` Michael Ellerman
  0 siblings, 0 replies; 9+ messages in thread
From: Michael Ellerman @ 2015-02-04  0:42 UTC (permalink / raw)
  To: Greg Kurz; +Cc: linuxppc-dev

On Tue, 2015-02-03 at 08:46 +0100, Greg Kurz wrote:
> On Tue, 03 Feb 2015 13:47:35 +1100
> Michael Ellerman <mpe@ellerman.id.au> wrote:
> 
> > On Thu, 2015-01-29 at 19:03 +0100, Greg Kurz wrote:
> > > On Wed, 17 Dec 2014 10:40:46 +0100
> > > Greg Kurz <gkurz@linux.vnet.ibm.com> wrote:
> > > > Hi,
> > > > 
> > > > This series addresses remarks from Ben and Michael (see individual patches).
> > > > The most notable changes are:
> > > > - the parsing code being pull out into a separate file in patch 3/4. This
> > > >   allows to write userland tests like the one below.
> > > > - a full rewrite of the parsing logic in patch 4/4
> > > > 
> > > 
> > > Ping ?
> > 
> > Sorry, lots of patches needing review.
> 
> Heh, no problem. :) Since this isn't bugfix, I can even repost later, when
> the review pressure is lower.

Yeah if you can repost in ~2 weeks that would be perfect.
 
> > This looks pretty good at a glance, but did you actually write a userspace test
> > for it? If so please send it. I'm happy to rework it into something that can go
> > in selftests.
> > 
> 
> Yes, I wrote the premise of a test program. You can find it in the cover mail of
> this series:
> 
> https://lists.ozlabs.org/pipermail/linuxppc-dev/2014-December/123601.html
> 
> I'll have a look at selftests.

Thanks. That test looks like a good start, there might be some more cases to
test though?

If you just copy the tools/testing/selftests/powerpc/tm directory and rename to
vhpn, you can probably work out the rest.

cheers

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2015-02-04  0:42 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-12-17  9:40 [PATCH v2 0/4] VPHN parsing fixes Greg Kurz
2014-12-17  9:41 ` [PATCH v2 1/4] powerpc/vphn: clarify the H_HOME_NODE_ASSOCIATIVITY API Greg Kurz
2014-12-17  9:42 ` [PATCH v2 2/4] powerpc/vphn: move endianness fixing to vphn_unpack_associativity() Greg Kurz
2014-12-17  9:42 ` [PATCH v2 3/4] powerpc/vphn: move VPHN parsing logic to a separate file Greg Kurz
2014-12-17  9:43 ` [PATCH v2 4/4] powerpc/vphn: parsing code rewrite Greg Kurz
2015-01-29 18:03 ` [PATCH v2 0/4] VPHN parsing fixes Greg Kurz
2015-02-03  2:47   ` Michael Ellerman
2015-02-03  7:46     ` Greg Kurz
2015-02-04  0:42       ` Michael Ellerman

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.