Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hardware debug API: Extend to aarch64 and add single stepping test #111

Merged
merged 1 commit into from
Jan 23, 2024

Conversation

alwin-joshy
Copy link
Contributor

@alwin-joshy alwin-joshy commented Jan 15, 2024

seL4's hardware debug API is currently only implemented for ARMv7 and x86. I am currently implementing it for AARCH64 and as a part of this, have ported the software breakpoint test to AARCH64.

I have also implemented a new test to check that single stepping works on ARM. In doing so, I believe I have found a bug in the implementation which I will make another pull request for soon. This test is simpler than the existing x86 equivalent but I think it should be sufficient. If not, I can port the existing x86 test for single stepping to ARM.

Test with: seL4/seL4#1162

Copy link
Contributor

@Indanz Indanz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks.

seL4/seL4#1162 is about ARMv7, not ARMv8. Wrong pull?

Comment on lines 36 to 37
#define TEST_SS_LABEL_ONE label_one
#define TEST_SS_LABEL_TWO label_two
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure why this indirection is done, but anyway, I would call it TEST_SS_BREAKPOINT1 and 2.

Comment on lines 22 to 25
/* NOTHING BELOW SHOULD EVER BE REACHED */
int *ptr = NULL;
*ptr = 0xBEEF;
return 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe say something like: "Should not be reached, but if it does, it wakes up the handler thread".

Comment on lines 63 to 65
if (label == seL4_Fault_DebugException &&
fault_data.reason == seL4_SingleStep &&
fault_data.vaddr == (seL4_Word) &TEST_SS_LABEL_TWO) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could add this check for 'TEST_SS_LABEL_ONE' above too. If the test passes it doesn't matter, but if something went wrong with the initial breakpoint it would make debugging a lot easier.

/* Check that it is a breakpoint exception */
if (label != seL4_Fault_DebugException ||
seL4_GetMR(seL4_DebugException_ExceptionReason) != seL4_InstructionBreakpoint) {
ZF_LOGV("Received exception other than instruction breakpoint exception.\n");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe explicitly test for NULL and say that single stepping doesn't work.

@Indanz
Copy link
Contributor

Indanz commented Jan 19, 2024

With 1162 in mind, I think it would be good to test whether code actually gets executed instead of only checking if the instruction pointer advances, so instead of nops just add a value to a register and check if it's correct at the second label.

@alwin-joshy
Copy link
Contributor Author

With 1162 in mind, I think it would be good to test whether code actually gets executed instead of only checking if the instruction pointer advances, so instead of nops just add a value to a register and check if it's correct at the second label.

Good point. In that case, I'll port the equivalent x86 test, which seems to be more robust.

@Indanz
Copy link
Contributor

Indanz commented Jan 20, 2024

With 1162 in mind, I think it would be good to test whether code actually gets executed instead of only checking if the instruction pointer advances, so instead of nops just add a value to a register and check if it's correct at the second label.

Good point. In that case, I'll port the equivalent x86 test, which seems to be more robust.

At first glance I don't really see anything x86 specific in there, perhaps make that test cross-platform with some arch specific helper functions or defines to paper over the differences? That definitely seems to be the current intention. You'd need to move the test to some common place and make sure it still gets executed on x86.

@alwin-joshy
Copy link
Contributor Author

With 1162 in mind, I think it would be good to test whether code actually gets executed instead of only checking if the instruction pointer advances, so instead of nops just add a value to a register and check if it's correct at the second label.

Good point. In that case, I'll port the equivalent x86 test, which seems to be more robust.

At first glance I don't really see anything x86 specific in there, perhaps make that test cross-platform with some arch specific helper functions or defines to paper over the differences? That definitely seems to be the current intention. You'd need to move the test to some common place and make sure it still gets executed on x86.

Yeah, should be simple. I do recall seeing a comment somewhere in the code about something being missing or not ready in ARM, but I'll see if I run into any issues. Didn't spot anything that immediately stood out.

@alwin-joshy
Copy link
Contributor Author

alwin-joshy commented Jan 22, 2024

@Indanz I moved the x86 single-stepping test into the arch-independent breakpoints file and it just worked.

@Indanz Indanz added hw-build set to run all sel4test hardware builds on this PR hw-test set to run sel4test hardware test for this PR labels Jan 22, 2024
@lsf37
Copy link
Member

lsf37 commented Jan 23, 2024

It looks like the hw-test trigger isn't working properly on this repo. I'll investigate..

Edit: it doesn't seem to be working on the seL4 repo any more either. Looks like something changed in the infrastructure.

Edit 2: looking more closely, it did actually work. It's just not showing them in the PR summary panel. It is showing them in the "Check" tab of the PR.

@Indanz
Copy link
Contributor

Indanz commented Jan 23, 2024

The Sabre clang fails with:

   All is well in the universe
  
  
  
  console_run returned 0
  
  0.05user 0.02system 2:48.06elapsed 0%CPU (0avgtext+0avgdata 7936maxresident)k
  0inputs+336outputs (0major+8920minor)pagefaults 0swaps
  +++ python3 ../projects/seL4_libs/libsel4test/tools/extract_results.py -q results.xml parsed_results.xml
  No log to check boot failure on.
  +++ mq.sh sem -signal sabre2 -k seL4/sel4test-seL4Test HW-7619487774-hw-run-5
  Error parsing parsed_results.xml
  -----------[ end test SABRE_debug_MCS_clang_32 ]-----------
SABRE_debug_MCS_clang_32 FAILED

@Indanz
Copy link
Contributor

Indanz commented Jan 23, 2024

I verified that it still runs and passes on x86 and some 32 bit ARMs, it doesn't yet run on Aarch64 though. I think we should remove the lines around https://github.com/seL4/seL4/blob/cc3205ea486f6ce3da3a64d8a99e166f047b8419/src/arch/arm/config.cmake#L226.

@Indanz
Copy link
Contributor

Indanz commented Jan 23, 2024

So do we want to remove KernelHardwareDebugAPIUnsupported from aarch64 before merging this, as the aarch64 code isn't tested yet, or merge this first and remove the define later?

@alwin-joshy, did you test this on aarch64 yet?

@alwin-joshy
Copy link
Contributor Author

I verified that it still runs and passes on x86 and some 32 bit ARMs, it doesn't yet run on Aarch64 though. I think we should remove the lines around https://github.com/seL4/seL4/blob/cc3205ea486f6ce3da3a64d8a99e166f047b8419/src/arch/arm/config.cmake#L226.

Yep, that will be necessary for getting the test to run on AARCH64 eventually but there are other substantial changes required for this. I've been working on this and am close to done (alwin-joshy/seL4#7) but there are still a few problems related to ARMv8 32-bit and ARM hyp mode that I want to iron out before submitting a proper PR.

@alwin-joshy
Copy link
Contributor Author

So do we want to remove KernelHardwareDebugAPIUnsupported from aarch64 before merging this, as the aarch64 code isn't tested yet, or merge this first and remove the define later?

@alwin-joshy, did you test this on aarch64 yet?

I think to merge this first and remove the KernelHardwareDebugAPIUnsupported in the PR when I have the hardware debug API fully ported to aarch64

#define TEST_SOFTWARE_BREAK_ASM() \
asm volatile( \
".global sbreak, post_sbreak\n\t" \
".type post_sbreak, function\n\t" \
"sbreak:\n\t" \
"bkpt\n\t")
#else
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps make it an explicit check for AARCH64, to make it clearer what's happening.

Suggested change
#else
#elif CONFIG_ARCH_AARCH64

If you tested this assembly locally I'm happy to merge this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, the test passes with the changes I've made in alwin-joshy/seL4#7

Ported software breakpoint test to aarch64 and moved single
stepping test from x86-only to arch-independent.

Signed-off-by: Alwin Joshy <[email protected]>
@Indanz Indanz merged commit 0a488b9 into seL4:master Jan 23, 2024
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hw-build set to run all sel4test hardware builds on this PR hw-test set to run sel4test hardware test for this PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants