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

Allocator test #375

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

Conversation

sleffler
Copy link
Contributor

I have a target platform where the heap is 32KB. I want to run the test suite but the allocator test fails because the current (fixed) BigAllocSize is too big. This change calculates BigAllocSize from the heap size. The change works for the sail board config but not my target w/ 32KB of heap:

19:19:30.9381 [INFO] uart5: [output] [35mallocator-test.cc:376[31m Invariant failure[35m in test_claims[36m
19:19:30.9400 [INFO] uart5: [output] Heap capability still valid after releasing last claim: 0x50078200 (v:1 0x50078200-0x50078280 l:0x80 o:0x0 p: G RWcgm- -- ---)

Don't immediately see the problem so looking for help...

@sleffler
Copy link
Contributor Author

Hmm, didn't expect it to pull all my private commits in, sorry.

@davidchisnall
Copy link
Collaborator

If you cherry pick the commit you want to a new branch and then force push the result to the branch this PR is from it should do the right thing.

@nwf
Copy link
Member

nwf commented Dec 12, 2024

That ("Heap capability still valid after releasing last claim") at a glance could be the first time the RTOS tests depend on agreement between the RTOS heap allocator's understanding of the revocation bitmap's location and corresponding base address and the load barrier's understanding of the same things (in the core implementation; see cheriot-sail's for example).

While it is entirely possible that there is a bug in the allocator -- it's big, less carefully audited than the switcher (so far), and there have been quarantine/revocation related bugs before -- it'd be good to check that your target's board definition file has the right values.

FWIW, if I tweak the sail board definition so that the heap is a hair over 32K in size fails later, in test_revoke(), because its allocations are too big. Further patches to follow.

@sleffler
Copy link
Contributor Author

sleffler commented Dec 12, 2024 via email

@davidchisnall
Copy link
Collaborator

I was under the impression the heap should not overlap code memory; how
does that work? (e.g. does the allocator find the end of pre-allocated
memory?)

There is a symbol in the linker script for the start of the heap, which is usually just at the end of the static things. The revocable memory start marker is for the range that includes read-write globals and stacks as well as the heap. We have three kinds of memory with respect to temporal safety:

  • Code / read-only memory, which cannot be written to after the allocator starts and so cannot contain pointers to heap objects. Does not need to be scanned.
  • Globals and stacks. Needs to be scanned, but does not contain heap objects and so may be allocated somewhere not backed by revocation bits.
  • Heap. Needs revocation bitmap coverage to ensure that the load filter and revoker can delete pointers to it. May also contain pointers to other heap memory and so must be scanned by the revoker.

Small heaps (e.g. 32KB) cause test failures because the size of a
"big allocation" is fixed. Use the heap size to do a better job.

Change-Id: I24ad172f71c6c91c975a7cae94d29e3d7b43775f
nwf added 3 commits December 13, 2024 02:45
This test wants to ensure that it cycles the heap, but it doesn't need
to allocate huge objects to do so in all cases.  Scale the size of the
objects used with the total heap.
@nwf
Copy link
Member

nwf commented Dec 13, 2024

@sleffler With these four changes, the test (and, indeed, the full test suite) passes on a sail target reconfigured into having a 33216-byte heap (release build) or even a 20224-byte one (debug build). Please advise.

@nwf nwf requested a review from davidchisnall December 13, 2024 02:51
@sleffler
Copy link
Contributor Author

With your changes (and cheriot-rtos @ c633c64) I'm now failing in test_claims:

09:49:31.6357 [INFO] uart5: [output] [35mAllocator test[0m: Heap size is 0x8000 bytes
09:49:31.6364 [INFO] uart5: [output] [35mAllocator test[0m: Testing token allocation
09:49:31.6375 [INFO] uart5: [output] [35mAllocator test[0m: Testing (expected valid) token size 0x80
09:49:31.6405 [INFO] uart5: [output] [35mAllocator test[0m: Testing (expected valid) token size 0xfe9                                                                                                                                                      
09:49:31.6500 [INFO] uart5: [output] [35mAllocator test[0m: Testing (expected valid) token size 0x2001                                                                                                                                                     
09:49:31.6692 [INFO] uart5: [output] [35mAllocator test[0m: Testing (expected valid) token size 0x1ff                                                                                                                                                      
09:49:31.6832 [INFO] uart5: [output] [35mAllocator test[0m: Testing (expected valid) token size 0x3fe      
09:49:31.6977 [INFO] uart5: [output] [35mAllocator test[0m: Testing (expected valid) token size 0x7fc                                                                                                                                                      
09:49:31.7081 [INFO] uart5: [output] [35mAllocator test[0m: Testing (expected valid) token size 0xff8               
09:49:31.7269 [INFO] uart5: [output] [35mAllocator test[0m: Testing (expected invalid) token size 0x0
09:49:31.7280 [INFO] uart5: [output] [35mAllocator[0m: Requested size 0x0 is not representable
09:49:31.7291 [INFO] uart5: [output] [35mAllocator test[0m: Testing (expected invalid) token size 0xffffffff
09:49:31.7301 [INFO] uart5: [output] [35mAllocator[0m: Requested size 0xffffffff is not representable
09:49:31.7378 [INFO] uart5: [output] [35mAllocator[0m: Trying to drop claim with 0x8 (0x50021fe0 (v:1 0x50021fe0-0x50021ff8 l:0x18 o:0x0 p: G RWcgm- -- ---)) (2)
09:49:31.7389 [INFO] uart5: [output] [35mAllocator test[0m: Before heap free all, quota left: 880
09:49:31.7912 [INFO] uart5: [output] [35mAllocator[0m: Trying to drop claim with 0x9 (0x50022000 (v:1 0x50022000-0x50022018 l:0x18 o:0x0 p: G RWcgm- -- ---)) (25)
09:49:31.7927 [INFO] uart5: [output] [35mAllocator test[0m: After heap free all, quota left: 880
09:49:31.7959 [INFO] uart5: [output] [35mAllocator test[0m: Before allocating, quota left: 1024
09:49:31.8000 [INFO] uart5: [output] [35mAllocator test[0m: After allocating, quota left: 976
09:49:31.8021 [INFO] uart5: [output] [35mAllocator[0m: Allocated sealing capability: 0xffffffed (v:1 0xffffffed-0xffffffee l:0x1 o:0x0 p: G ------ -- SU-)
09:49:31.9374 [INFO] uart5: [output] [35mAllocator test[0m: Before freeing, quota left: 976                     
09:49:31.9400 [INFO] uart5: [output] [35mAllocator[0m: Found hazard pointer for 0x5007c798 (v:1 0x5007c798-0x5007c7a8 l:0x10 o:0x0 p: G RWcgm- -- ---) (thread: 0x3)
09:49:31.9412 [INFO] uart5: [output] [35mAllocator test[0m: After free 1, quota left: 1000
09:49:31.9437 [INFO] uart5: [output] [35mAllocator[0m: Found hazard pointer for 0x5007c798 (v:1 0x5007c798-0x5007c7a8 l:0x10 o:0x0 p: G RWcgm- -- ---) (thread: 0x3)
09:49:31.9458 [INFO] uart5: [output] [35mAllocator[0m: Found hazard pointer for 0x50079188 (v:1 0x50079188-0x50079198 l:0x10 o:0x0 p: G RWcgm- -- ---) (thread: 0x3)
09:49:31.9489 [INFO] uart5: [output] [35mAllocator test[0m: After free 2, quota left: 1024
09:49:31.9501 [INFO] uart5: [output] [35mAllocator test[0m: Releasing hazard pointers
09:49:31.9529 [INFO] uart5: [output] [35mAllocator[0m: Trying to drop claim with 0x9 (0x50022000 (v:1 0x50022000-0x50022018 l:0x18 o:0x0 p: G RWcgm- -- ---))
09:49:31.9564 [INFO] uart5: [output] [35mAllocator[0m: Found safe-to-free object in hazard list: 0x5007c798 (v:1 0x5007c798-0x5007c7a8 l:0x10 o:0x0 p: G RWcgm- -- ---)
09:49:31.9597 [INFO] uart5: [output] [35mAllocator[0m: Found safe-to-free object in hazard list: 0x50079188 (v:1 0x50079188-0x50079198 l:0x10 o:0x0 p: G RWcgm- -- ---)
09:49:31.9709 [INFO] uart5: [output] [35mAllocator test[0m: Hazard pointer tests done
09:49:31.9719 [INFO] uart5: [output] [35mAllocator test[0m: Quota left before allocating: 1024
09:49:31.9867 [INFO] uart5: [output] [35mAllocator test[0m: Quota left after allocating 240 bytes: 752
09:49:31.9931 [INFO] uart5: [output] [35mAllocator[0m: Trying to drop claim with 0x9 (0x50022000 (v:1 0x50022000-0x50022018 l:0x18 o:0x0 p: G RWcgm- -- ---)) (3)
09:49:31.9963 [INFO] uart5: [output] [35mAllocator[0m: Trying to drop claim with 0x8 (0x50021fe0 (v:1 0x50021fe0-0x50021ff8 l:0x18 o:0x0 p: G RWcgm- -- ---))
09:49:31.9979 [INFO] uart5: [output] [35mAllocator test[0m: Beginning tests on claims
09:49:32.0004 [INFO] uart5: [output] [35mAllocator[0m: Adding claim for 0x9
09:49:32.0016 [INFO] uart5: [output] [35mAllocator[0m: Allocated new claim
09:49:32.0041 [INFO] uart5: [output] [35mAllocator[0m: Trying to drop claim with 0x9 (0x50022000 (v:1 0x50022000-0x50022018 l:0x18 o:0x0 p: G RWcgm- -- ---))
09:49:32.0089 [INFO] uart5: [output] [35mAllocator[0m: Dropped last claim, refunding 0x88-byte quota for 0x500781b8 (v:1 0x50078000-0x50080000 l:0x8000 o:0x0 p: G RWcgm- -- ---)
09:49:32.0100 [INFO] uart5: [output] [35mAllocator[0m: Adding claim for 0x9
09:49:32.0107 [INFO] uart5: [output] [35mAllocator[0m: Allocated new claim
09:49:32.0117 [INFO] uart5: [output] [35mAllocator[0m: Adding claim for 0x9
09:49:32.0122 [INFO] uart5: [output] [35mAllocator[0m: Adding second claim
09:49:32.0146 [INFO] uart5: [output] [35mAllocator test[0m: Freeing object on malloc capability: 0x500781b8 (v:1 0x500781b8-0x50078238 l:0x80 o:0x0 p: G RWcgm- -- ---)
09:49:32.0194 [INFO] uart5: [output] [35mAllocator[0m: Trying to drop claim with 0x9 (0x50022000 (v:1 0x50022000-0x50022018 l:0x18 o:0x0 p: G RWcgm- -- ---)) (2)
09:49:32.0216 [INFO] uart5: [output] [35mAllocator[0m: Dropped last claim, refunding 0x88-byte quota for 0x500781b8 (v:1 0x50078000-0x50080000 l:0x8000 o:0x0 p: G RWcgm- -- ---)
09:49:32.0238 [INFO] uart5: [output] [35mallocator-test.cc:385[31m Invariant failure[35m in test_claims[36m
09:49:32.0257 [INFO] uart5: [output] Heap capability still valid after releasing last claim: 0x500781b8 (v:1 0x500781b8-0x50078238 l:0x80 o:0x0 p: G RWcgm- -- ---)

Board config (w/ 32KB heap) is here: https://opensecura.googlesource.com/3p/cheriot-rtos/+/refs/heads/master/sdk/boards/sencha.json.

You talked about wanting a full instruction trace. Lmk if that's still the case.

I don't think it matters but testing was with mpact-cheriot (+renode).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants