diff mbox series

[v3,5/5] powerpc/code-patching: Add boot selftest for data patching

Message ID 20240325055302.876434-6-bgray@linux.ibm.com (mailing list archive)
State New
Headers show
Series Add generic data patching functions | expand

Checks

Context Check Description
snowpatch_ozlabs/github-powerpc_selftests success Successfully ran 8 jobs.
snowpatch_ozlabs/github-powerpc_ppctests success Successfully ran 8 jobs.
snowpatch_ozlabs/github-powerpc_sparse success Successfully ran 4 jobs.
snowpatch_ozlabs/github-powerpc_clang success Successfully ran 6 jobs.
snowpatch_ozlabs/github-powerpc_kernel_qemu success Successfully ran 23 jobs.

Commit Message

Benjamin Gray March 25, 2024, 5:53 a.m. UTC
Extend the code patching selftests with some basic coverage of the new
data patching variants too.

Signed-off-by: Benjamin Gray <bgray@linux.ibm.com>

---

v3: * New in v3
---
 arch/powerpc/lib/test-code-patching.c | 36 +++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)

Comments

Naveen N Rao April 23, 2024, 9:25 a.m. UTC | #1
On Mon, Mar 25, 2024 at 04:53:02PM +1100, Benjamin Gray wrote:
> Extend the code patching selftests with some basic coverage of the new
> data patching variants too.
> 
> Signed-off-by: Benjamin Gray <bgray@linux.ibm.com>
> 
> ---
> 
> v3: * New in v3
> ---
>  arch/powerpc/lib/test-code-patching.c | 36 +++++++++++++++++++++++++++
>  1 file changed, 36 insertions(+)
> 
> diff --git a/arch/powerpc/lib/test-code-patching.c b/arch/powerpc/lib/test-code-patching.c
> index c44823292f73..e96c48fcd4db 100644
> --- a/arch/powerpc/lib/test-code-patching.c
> +++ b/arch/powerpc/lib/test-code-patching.c
> @@ -347,6 +347,41 @@ static void __init test_prefixed_patching(void)
>  	check(!memcmp(iptr, expected, sizeof(expected)));
>  }
>  
> +static void __init test_data_patching(void)
> +{
> +	void *buf;
> +	u32 *addr32;
> +
> +	buf = vzalloc(PAGE_SIZE);
> +	check(buf);
> +	if (!buf)
> +		return;
> +
> +	addr32 = buf + 128;
> +
> +	addr32[1] = 0xA0A1A2A3;
> +	addr32[2] = 0xB0B1B2B3;
> +
> +	patch_uint(&addr32[1], 0xC0C1C2C3);
> +
> +	check(addr32[0] == 0);
> +	check(addr32[1] == 0xC0C1C2C3);
> +	check(addr32[2] == 0xB0B1B2B3);
> +	check(addr32[3] == 0);
> +
> +	patch_ulong(&addr32[1], 0xD0D1D2D3);
> +
> +	check(addr32[0] == 0);
> +	*(unsigned long *)(&addr32[1]) = 0xD0D1D2D3;

Should that have been a check() instead?

- Naveen

> +
> +	if (!IS_ENABLED(CONFIG_PPC64))
> +		check(addr32[2] == 0xB0B1B2B3);
> +
> +	check(addr32[3] == 0);
> +
> +	vfree(buf);
> +}
> +
>  static int __init test_code_patching(void)
>  {
>  	pr_info("Running code patching self-tests ...\n");
> @@ -356,6 +391,7 @@ static int __init test_code_patching(void)
>  	test_create_function_call();
>  	test_translate_branch();
>  	test_prefixed_patching();
> +	test_data_patching();
>  
>  	return 0;
>  }
> -- 
> 2.44.0
>
diff mbox series

Patch

diff --git a/arch/powerpc/lib/test-code-patching.c b/arch/powerpc/lib/test-code-patching.c
index c44823292f73..e96c48fcd4db 100644
--- a/arch/powerpc/lib/test-code-patching.c
+++ b/arch/powerpc/lib/test-code-patching.c
@@ -347,6 +347,41 @@  static void __init test_prefixed_patching(void)
 	check(!memcmp(iptr, expected, sizeof(expected)));
 }
 
+static void __init test_data_patching(void)
+{
+	void *buf;
+	u32 *addr32;
+
+	buf = vzalloc(PAGE_SIZE);
+	check(buf);
+	if (!buf)
+		return;
+
+	addr32 = buf + 128;
+
+	addr32[1] = 0xA0A1A2A3;
+	addr32[2] = 0xB0B1B2B3;
+
+	patch_uint(&addr32[1], 0xC0C1C2C3);
+
+	check(addr32[0] == 0);
+	check(addr32[1] == 0xC0C1C2C3);
+	check(addr32[2] == 0xB0B1B2B3);
+	check(addr32[3] == 0);
+
+	patch_ulong(&addr32[1], 0xD0D1D2D3);
+
+	check(addr32[0] == 0);
+	*(unsigned long *)(&addr32[1]) = 0xD0D1D2D3;
+
+	if (!IS_ENABLED(CONFIG_PPC64))
+		check(addr32[2] == 0xB0B1B2B3);
+
+	check(addr32[3] == 0);
+
+	vfree(buf);
+}
+
 static int __init test_code_patching(void)
 {
 	pr_info("Running code patching self-tests ...\n");
@@ -356,6 +391,7 @@  static int __init test_code_patching(void)
 	test_create_function_call();
 	test_translate_branch();
 	test_prefixed_patching();
+	test_data_patching();
 
 	return 0;
 }