linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: Christophe Leroy <christophe.leroy@csgroup.eu>
To: Benjamin Gray <bgray@linux.ibm.com>,
	"linuxppc-dev@lists.ozlabs.org" <linuxppc-dev@lists.ozlabs.org>,
	"mpe@ellerman.id.au" <mpe@ellerman.id.au>
Subject: Re: [PATCH v1 1/3] powerpc/code-patching: Test patch_instructions() during boot
Date: Fri, 15 Mar 2024 07:14:47 +0000	[thread overview]
Message-ID: <701ee036-c32e-4c75-98d1-a46582012eb1@csgroup.eu> (raw)
In-Reply-To: <20240315025736.404867-1-bgray@linux.ibm.com>



Le 15/03/2024 à 03:57, Benjamin Gray a écrit :
> patch_instructions() introduces new behaviour with a couple of
> variations. Test each case of
> 
>    * a repeated 32-bit instruction,
>    * a repeated 64-bit instruction (ppc64), and
>    * a copied sequence of instructions
> 
> for both on a single page and when it crosses a page boundary.
> 
> Signed-off-by: Benjamin Gray <bgray@linux.ibm.com>
> ---
>   arch/powerpc/lib/test-code-patching.c | 92 +++++++++++++++++++++++++++
>   1 file changed, 92 insertions(+)
> 
> diff --git a/arch/powerpc/lib/test-code-patching.c b/arch/powerpc/lib/test-code-patching.c
> index c44823292f73..35a3756272df 100644
> --- a/arch/powerpc/lib/test-code-patching.c
> +++ b/arch/powerpc/lib/test-code-patching.c
> @@ -347,6 +347,97 @@ static void __init test_prefixed_patching(void)
>   	check(!memcmp(iptr, expected, sizeof(expected)));
>   }
>   
> +static void __init test_multi_instruction_patching(void)
> +{
> +	u32 code[256];

Build failure:

   CC      arch/powerpc/lib/test-code-patching.o
arch/powerpc/lib/test-code-patching.c: In function 
'test_multi_instruction_patching':
arch/powerpc/lib/test-code-patching.c:439:1: error: the frame size of 
1040 bytes is larger than 1024 bytes [-Werror=frame-larger-than=]
   439 | }
       | ^
cc1: all warnings being treated as errors
make[4]: *** [scripts/Makefile.build:243: 
arch/powerpc/lib/test-code-patching.o] Error 1


I have to avoid big arrays on the stack.


> +	void *buf;
> +	u32 *addr32;
> +	u64 *addr64;
> +	ppc_inst_t inst64 = ppc_inst_prefix(OP_PREFIX << 26 | 3UL << 24, PPC_RAW_TRAP());
> +	u32 inst32 = PPC_RAW_NOP();
> +
> +	buf = vzalloc(PAGE_SIZE * 8);
> +	check(buf);
> +	if (!buf)
> +		return;
> +
> +	/* Test single page 32-bit repeated instruction */
> +	addr32 = buf + PAGE_SIZE;
> +	check(!patch_instructions(addr32 + 1, &inst32, 12, true));
> +
> +	check(addr32[0] == 0);
> +	check(addr32[1] == inst32);
> +	check(addr32[2] == inst32);
> +	check(addr32[3] == inst32);
> +	check(addr32[4] == 0);
> +
> +	/* Test single page 64-bit repeated instruction */
> +	if (IS_ENABLED(CONFIG_PPC64)) {
> +		check(ppc_inst_prefixed(inst64));
> +
> +		addr64 = buf + PAGE_SIZE * 2;
> +		ppc_inst_write(code, inst64);
> +		check(!patch_instructions((u32 *)(addr64 + 1), code, 24, true));
> +
> +		check(addr64[0] == 0);
> +		check(ppc_inst_equal(ppc_inst_read((u32 *)&addr64[1]), inst64));
> +		check(ppc_inst_equal(ppc_inst_read((u32 *)&addr64[2]), inst64));
> +		check(ppc_inst_equal(ppc_inst_read((u32 *)&addr64[3]), inst64));
> +		check(addr64[4] == 0);
> +	}
> +
> +	/* Test single page memcpy */
> +	addr32 = buf + PAGE_SIZE * 3;
> +
> +	for (int i = 0; i < ARRAY_SIZE(code); i++)
> +		code[i] = i + 1;
> +
> +	check(!patch_instructions(addr32 + 1, code, sizeof(code), false));
> +
> +	check(addr32[0] == 0);
> +	check(!memcmp(&addr32[1], code, sizeof(code)));
> +	check(addr32[ARRAY_SIZE(code) + 1] == 0);
> +
> +	/* Test multipage 32-bit repeated instruction */
> +	addr32 = buf + PAGE_SIZE * 4 - 8;
> +	check(!patch_instructions(addr32 + 1, &inst32, 12, true));
> +
> +	check(addr32[0] == 0);
> +	check(addr32[1] == inst32);
> +	check(addr32[2] == inst32);
> +	check(addr32[3] == inst32);
> +	check(addr32[4] == 0);
> +
> +	/* Test multipage 64-bit repeated instruction */
> +	if (IS_ENABLED(CONFIG_PPC64)) {
> +		check(ppc_inst_prefixed(inst64));
> +
> +		addr64 = buf + PAGE_SIZE * 5 - 8;
> +		ppc_inst_write(code, inst64);
> +		check(!patch_instructions((u32 *)(addr64 + 1), code, 24, true));
> +
> +		check(addr64[0] == 0);
> +		check(ppc_inst_equal(ppc_inst_read((u32 *)&addr64[1]), inst64));
> +		check(ppc_inst_equal(ppc_inst_read((u32 *)&addr64[2]), inst64));
> +		check(ppc_inst_equal(ppc_inst_read((u32 *)&addr64[3]), inst64));
> +		check(addr64[4] == 0);
> +	}
> +
> +	/* Test multipage memcpy */
> +	addr32 = buf + PAGE_SIZE * 6 - 12;
> +
> +	for (int i = 0; i < ARRAY_SIZE(code); i++)
> +		code[i] = i + 1;
> +
> +	check(!patch_instructions(addr32 + 1, code, sizeof(code), false));
> +
> +	check(addr32[0] == 0);
> +	check(!memcmp(&addr32[1], code, sizeof(code)));
> +	check(addr32[ARRAY_SIZE(code) + 1] == 0);
> +
> +	vfree(buf);
> +}
> +
>   static int __init test_code_patching(void)
>   {
>   	pr_info("Running code patching self-tests ...\n");
> @@ -356,6 +447,7 @@ static int __init test_code_patching(void)
>   	test_create_function_call();
>   	test_translate_branch();
>   	test_prefixed_patching();
> +	test_multi_instruction_patching();
>   
>   	return 0;
>   }

  parent reply	other threads:[~2024-03-15  7:15 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-15  2:57 [PATCH v1 1/3] powerpc/code-patching: Test patch_instructions() during boot Benjamin Gray
2024-03-15  2:57 ` [PATCH v1 2/3] powerpc/code-patching: Use dedicated memory routines for patching Benjamin Gray
2024-03-15  3:17   ` Benjamin Gray
2024-03-15  6:36   ` Christophe Leroy
2024-03-17 21:42     ` Benjamin Gray
2024-03-15  2:57 ` [PATCH v1 3/3] powerpc/code-patching: Optimise patch_memcpy() to 4 byte chunks Benjamin Gray
2024-03-15  6:39   ` Christophe Leroy
2024-03-17 21:44     ` Benjamin Gray
2024-03-15  7:14 ` Christophe Leroy [this message]
2024-03-17 21:38   ` [PATCH v1 1/3] powerpc/code-patching: Test patch_instructions() during boot Benjamin Gray
2024-03-17 22:23     ` Benjamin Gray
2024-03-18  2:25       ` Michael Ellerman
2024-03-17 22:24     ` Benjamin Gray

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=701ee036-c32e-4c75-98d1-a46582012eb1@csgroup.eu \
    --to=christophe.leroy@csgroup.eu \
    --cc=bgray@linux.ibm.com \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=mpe@ellerman.id.au \
    /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).