* [PATCH v10.5 0/1] tests/tcg/aarch64: Add bti mmap smoke test
@ 2020-10-06 17:23 Richard Henderson
2020-10-06 17:23 ` [PATCH 1/1] " Richard Henderson
2020-10-06 17:30 ` [PATCH v10.5 0/1] " no-reply
0 siblings, 2 replies; 4+ messages in thread
From: Richard Henderson @ 2020-10-06 17:23 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell, qemu-arm, alex.bennee
Based-on: 20201002215955.254866-1-richard.henderson@linaro.org
(linux-user: User support for AArch64 BTI)
Adding a second smoke test, which both tests PROT_BTI via the
syscall, as opposed to the ELF NOTE.
r~
Richard Henderson (1):
tests/tcg/aarch64: Add bti mmap smoke test
tests/tcg/aarch64/bti-2.c | 108 ++++++++++++++++++++++++++++++
tests/tcg/aarch64/Makefile.target | 7 +-
2 files changed, 113 insertions(+), 2 deletions(-)
create mode 100644 tests/tcg/aarch64/bti-2.c
--
2.25.1
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 1/1] tests/tcg/aarch64: Add bti mmap smoke test
2020-10-06 17:23 [PATCH v10.5 0/1] tests/tcg/aarch64: Add bti mmap smoke test Richard Henderson
@ 2020-10-06 17:23 ` Richard Henderson
2020-10-07 15:05 ` Alex Bennée
2020-10-06 17:30 ` [PATCH v10.5 0/1] " no-reply
1 sibling, 1 reply; 4+ messages in thread
From: Richard Henderson @ 2020-10-06 17:23 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell, qemu-arm, alex.bennee
This tests PROT_BTI, and also does not require special
compiler support.
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
tests/tcg/aarch64/bti-2.c | 108 ++++++++++++++++++++++++++++++
tests/tcg/aarch64/Makefile.target | 7 +-
2 files changed, 113 insertions(+), 2 deletions(-)
create mode 100644 tests/tcg/aarch64/bti-2.c
diff --git a/tests/tcg/aarch64/bti-2.c b/tests/tcg/aarch64/bti-2.c
new file mode 100644
index 0000000000..6dc8908b5a
--- /dev/null
+++ b/tests/tcg/aarch64/bti-2.c
@@ -0,0 +1,108 @@
+/*
+ * Branch target identification, basic notskip cases.
+ */
+
+#include <stdio.h>
+#include <signal.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/mman.h>
+
+#ifndef PROT_BTI
+#define PROT_BTI 0x10
+#endif
+
+static void skip2_sigill(int sig, siginfo_t *info, void *vuc)
+{
+ ucontext_t *uc = vuc;
+ uc->uc_mcontext.pc += 8;
+ uc->uc_mcontext.pstate = 1;
+}
+
+#define NOP "nop"
+#define BTI_N "hint #32"
+#define BTI_C "hint #34"
+#define BTI_J "hint #36"
+#define BTI_JC "hint #38"
+
+#define BTYPE_1(DEST) \
+ "mov x1, #1\n\t" \
+ "adr x16, 1f\n\t" \
+ "br x16\n" \
+"1: " DEST "\n\t" \
+ "mov x1, #0"
+
+#define BTYPE_2(DEST) \
+ "mov x1, #1\n\t" \
+ "adr x16, 1f\n\t" \
+ "blr x16\n" \
+"1: " DEST "\n\t" \
+ "mov x1, #0"
+
+#define BTYPE_3(DEST) \
+ "mov x1, #1\n\t" \
+ "adr x15, 1f\n\t" \
+ "br x15\n" \
+"1: " DEST "\n\t" \
+ "mov x1, #0"
+
+#define TEST(WHICH, DEST, EXPECT) \
+ WHICH(DEST) "\n" \
+ ".if " #EXPECT "\n\t" \
+ "eor x1, x1," #EXPECT "\n" \
+ ".endif\n\t" \
+ "add x0, x0, x1\n\t"
+
+extern char test_begin[], test_end[];
+
+asm("\n"
+"test_begin:\n\t"
+ BTI_C "\n\t"
+ "mov x2, x30\n\t"
+ "mov x0, #0\n\t"
+
+ TEST(BTYPE_1, NOP, 1)
+ TEST(BTYPE_1, BTI_N, 1)
+ TEST(BTYPE_1, BTI_C, 0)
+ TEST(BTYPE_1, BTI_J, 0)
+ TEST(BTYPE_1, BTI_JC, 0)
+
+ TEST(BTYPE_2, NOP, 1)
+ TEST(BTYPE_2, BTI_N, 1)
+ TEST(BTYPE_2, BTI_C, 0)
+ TEST(BTYPE_2, BTI_J, 1)
+ TEST(BTYPE_2, BTI_JC, 0)
+
+ TEST(BTYPE_3, NOP, 1)
+ TEST(BTYPE_3, BTI_N, 1)
+ TEST(BTYPE_3, BTI_C, 1)
+ TEST(BTYPE_3, BTI_J, 0)
+ TEST(BTYPE_3, BTI_JC, 0)
+
+ "ret x2\n"
+"test_end:"
+);
+
+int main()
+{
+ struct sigaction sa;
+
+ void *p = mmap(0, getpagesize(),
+ PROT_EXEC | PROT_READ | PROT_WRITE | PROT_BTI,
+ MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
+ if (p == MAP_FAILED) {
+ perror("mmap");
+ return 1;
+ }
+
+ memset(&sa, 0, sizeof(sa));
+ sa.sa_sigaction = skip2_sigill;
+ sa.sa_flags = SA_SIGINFO;
+ if (sigaction(SIGILL, &sa, NULL) < 0) {
+ perror("sigaction");
+ return 1;
+ }
+
+ memcpy(p, test_begin, test_end - test_begin);
+ return ((int (*)(void))p)();
+}
diff --git a/tests/tcg/aarch64/Makefile.target b/tests/tcg/aarch64/Makefile.target
index 491683e91d..d7d33e293c 100644
--- a/tests/tcg/aarch64/Makefile.target
+++ b/tests/tcg/aarch64/Makefile.target
@@ -26,11 +26,14 @@ run-plugin-pauth-%: QEMU_OPTS += -cpu max
endif
# BTI Tests
+# bti-1 tests the elf notes, so we require special compiler support.
ifneq ($(DOCKER_IMAGE)$(CROSS_CC_HAS_ARMV8_BTI),)
AARCH64_TESTS += bti-1
-bti-%: CFLAGS += -mbranch-protection=standard
-bti-%: LDFLAGS += -nostdlib
+bti-1: CFLAGS += -mbranch-protection=standard
+bti-1: LDFLAGS += -nostdlib
endif
+# bti-2 tests PROT_BTI, so no special compiler support required.
+AARCH64_TESTS += bti-2
# Semihosting smoke test for linux-user
AARCH64_TESTS += semihosting
--
2.25.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v10.5 0/1] tests/tcg/aarch64: Add bti mmap smoke test
2020-10-06 17:23 [PATCH v10.5 0/1] tests/tcg/aarch64: Add bti mmap smoke test Richard Henderson
2020-10-06 17:23 ` [PATCH 1/1] " Richard Henderson
@ 2020-10-06 17:30 ` no-reply
1 sibling, 0 replies; 4+ messages in thread
From: no-reply @ 2020-10-06 17:30 UTC (permalink / raw)
To: richard.henderson; +Cc: peter.maydell, qemu-arm, alex.bennee, qemu-devel
Patchew URL: https://patchew.org/QEMU/20201006172359.2998-1-richard.henderson@linaro.org/
Hi,
This series seems to have some coding style problems. See output below for
more information:
Type: series
Message-id: 20201006172359.2998-1-richard.henderson@linaro.org
Subject: [PATCH v10.5 0/1] tests/tcg/aarch64: Add bti mmap smoke test
=== TEST SCRIPT BEGIN ===
#!/bin/bash
git rev-parse base > /dev/null || exit 0
git config --local diff.renamelimit 0
git config --local diff.renames True
git config --local diff.algorithm histogram
./scripts/checkpatch.pl --mailback base..
=== TEST SCRIPT END ===
Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
From https://github.com/patchew-project/qemu
- [tag update] patchew/20201005165147.526426-1-clg@kaod.org -> patchew/20201005165147.526426-1-clg@kaod.org
- [tag update] patchew/20201005205228.697463-1-ehabkost@redhat.com -> patchew/20201005205228.697463-1-ehabkost@redhat.com
- [tag update] patchew/20201006154256.17392-1-alex.bennee@linaro.org -> patchew/20201006154256.17392-1-alex.bennee@linaro.org
* [new tag] patchew/20201006172359.2998-1-richard.henderson@linaro.org -> patchew/20201006172359.2998-1-richard.henderson@linaro.org
Switched to a new branch 'test'
bef94f7 tests/tcg/aarch64: Add bti mmap smoke test
=== OUTPUT BEGIN ===
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating?
#36:
new file mode 100644
ERROR: externs should be avoided in .c files
#96: FILE: tests/tcg/aarch64/bti-2.c:56:
+extern char test_begin[], test_end[];
ERROR: use qemu_real_host_page_size instead of getpagesize()
#130: FILE: tests/tcg/aarch64/bti-2.c:90:
+ void *p = mmap(0, getpagesize(),
total: 2 errors, 1 warnings, 124 lines checked
Commit bef94f733a7f (tests/tcg/aarch64: Add bti mmap smoke test) has style problems, please review. If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
=== OUTPUT END ===
Test command exited with code: 1
The full log is available at
http://patchew.org/logs/20201006172359.2998-1-richard.henderson@linaro.org/testing.checkpatch/?type=message.
---
Email generated automatically by Patchew [https://patchew.org/].
Please send your feedback to patchew-devel@redhat.com
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 1/1] tests/tcg/aarch64: Add bti mmap smoke test
2020-10-06 17:23 ` [PATCH 1/1] " Richard Henderson
@ 2020-10-07 15:05 ` Alex Bennée
0 siblings, 0 replies; 4+ messages in thread
From: Alex Bennée @ 2020-10-07 15:05 UTC (permalink / raw)
To: Richard Henderson; +Cc: peter.maydell, qemu-arm, qemu-devel
Richard Henderson <richard.henderson@linaro.org> writes:
> This tests PROT_BTI, and also does not require special
> compiler support.
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
> tests/tcg/aarch64/bti-2.c | 108 ++++++++++++++++++++++++++++++
> tests/tcg/aarch64/Makefile.target | 7 +-
> 2 files changed, 113 insertions(+), 2 deletions(-)
> create mode 100644 tests/tcg/aarch64/bti-2.c
>
> diff --git a/tests/tcg/aarch64/bti-2.c b/tests/tcg/aarch64/bti-2.c
> new file mode 100644
> index 0000000000..6dc8908b5a
> --- /dev/null
> +++ b/tests/tcg/aarch64/bti-2.c
> @@ -0,0 +1,108 @@
> +/*
> + * Branch target identification, basic notskip cases.
> + */
> +
> +#include <stdio.h>
> +#include <signal.h>
> +#include <string.h>
> +#include <unistd.h>
> +#include <sys/mman.h>
> +
> +#ifndef PROT_BTI
> +#define PROT_BTI 0x10
> +#endif
> +
> +static void skip2_sigill(int sig, siginfo_t *info, void *vuc)
> +{
> + ucontext_t *uc = vuc;
> + uc->uc_mcontext.pc += 8;
> + uc->uc_mcontext.pstate = 1;
> +}
> +
> +#define NOP "nop"
> +#define BTI_N "hint #32"
> +#define BTI_C "hint #34"
> +#define BTI_J "hint #36"
> +#define BTI_JC "hint #38"
> +
> +#define BTYPE_1(DEST) \
> + "mov x1, #1\n\t" \
> + "adr x16, 1f\n\t" \
> + "br x16\n" \
> +"1: " DEST "\n\t" \
> + "mov x1, #0"
> +
> +#define BTYPE_2(DEST) \
> + "mov x1, #1\n\t" \
> + "adr x16, 1f\n\t" \
> + "blr x16\n" \
> +"1: " DEST "\n\t" \
> + "mov x1, #0"
> +
> +#define BTYPE_3(DEST) \
> + "mov x1, #1\n\t" \
> + "adr x15, 1f\n\t" \
> + "br x15\n" \
> +"1: " DEST "\n\t" \
> + "mov x1, #0"
> +
> +#define TEST(WHICH, DEST, EXPECT) \
> + WHICH(DEST) "\n" \
> + ".if " #EXPECT "\n\t" \
> + "eor x1, x1," #EXPECT "\n" \
> + ".endif\n\t" \
> + "add x0, x0, x1\n\t"
> +
> +extern char test_begin[], test_end[];
> +
> +asm("\n"
> +"test_begin:\n\t"
> + BTI_C "\n\t"
> + "mov x2, x30\n\t"
> + "mov x0, #0\n\t"
> +
> + TEST(BTYPE_1, NOP, 1)
> + TEST(BTYPE_1, BTI_N, 1)
> + TEST(BTYPE_1, BTI_C, 0)
> + TEST(BTYPE_1, BTI_J, 0)
> + TEST(BTYPE_1, BTI_JC, 0)
> +
> + TEST(BTYPE_2, NOP, 1)
> + TEST(BTYPE_2, BTI_N, 1)
> + TEST(BTYPE_2, BTI_C, 0)
> + TEST(BTYPE_2, BTI_J, 1)
> + TEST(BTYPE_2, BTI_JC, 0)
> +
> + TEST(BTYPE_3, NOP, 1)
> + TEST(BTYPE_3, BTI_N, 1)
> + TEST(BTYPE_3, BTI_C, 1)
> + TEST(BTYPE_3, BTI_J, 0)
> + TEST(BTYPE_3, BTI_JC, 0)
> +
> + "ret x2\n"
> +"test_end:"
> +);
> +
> +int main()
> +{
> + struct sigaction sa;
> +
> + void *p = mmap(0, getpagesize(),
> + PROT_EXEC | PROT_READ | PROT_WRITE | PROT_BTI,
> + MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
> + if (p == MAP_FAILED) {
> + perror("mmap");
> + return 1;
> + }
> +
> + memset(&sa, 0, sizeof(sa));
> + sa.sa_sigaction = skip2_sigill;
> + sa.sa_flags = SA_SIGINFO;
> + if (sigaction(SIGILL, &sa, NULL) < 0) {
> + perror("sigaction");
> + return 1;
> + }
> +
> + memcpy(p, test_begin, test_end - test_begin);
> + return ((int (*)(void))p)();
> +}
> diff --git a/tests/tcg/aarch64/Makefile.target b/tests/tcg/aarch64/Makefile.target
> index 491683e91d..d7d33e293c 100644
> --- a/tests/tcg/aarch64/Makefile.target
> +++ b/tests/tcg/aarch64/Makefile.target
> @@ -26,11 +26,14 @@ run-plugin-pauth-%: QEMU_OPTS += -cpu max
> endif
>
> # BTI Tests
> +# bti-1 tests the elf notes, so we require special compiler support.
> ifneq ($(DOCKER_IMAGE)$(CROSS_CC_HAS_ARMV8_BTI),)
> AARCH64_TESTS += bti-1
> -bti-%: CFLAGS += -mbranch-protection=standard
> -bti-%: LDFLAGS += -nostdlib
> +bti-1: CFLAGS += -mbranch-protection=standard
> +bti-1: LDFLAGS += -nostdlib
> endif
> +# bti-2 tests PROT_BTI, so no special compiler support required.
> +AARCH64_TESTS += bti-2
LGTM
Acked-by: Alex Bennée <alex.bennee@linaro.org>
(I assume this just rolls up with your existing BTI patches).
--
Alex Bennée
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2020-10-07 15:09 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-06 17:23 [PATCH v10.5 0/1] tests/tcg/aarch64: Add bti mmap smoke test Richard Henderson
2020-10-06 17:23 ` [PATCH 1/1] " Richard Henderson
2020-10-07 15:05 ` Alex Bennée
2020-10-06 17:30 ` [PATCH v10.5 0/1] " no-reply
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.