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

vm/mman: handle properly munmap of chunks larger than SIZE_PAGE #578

Merged
merged 1 commit into from
Sep 26, 2024

Conversation

badochov
Copy link
Contributor

@badochov badochov commented Aug 20, 2024

JIRA: RTOS-893

Description

Munmap handled badly segments bigger that SIZE_PAGE, after it the rb tree was in corrupted state.

Motivation and Context

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Chore (refactoring, style fixes, git/CI config, submodule management, no code logic changes)

How Has This Been Tested?

  • Already covered by automatic testing.
  • New test added: (add PR link here).
  • Tested by hand on: ia-32

Checklist:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing linter checks and tests passed.
  • My changes generate no new compilation warnings for any of the targets.

Special treatment

@badochov badochov requested a review from Darchiv August 20, 2024 16:03
Copy link

github-actions bot commented Aug 20, 2024

Unit Test Results

7 723 tests  +23   7 008 ✅ +23   37m 41s ⏱️ +24s
  443 suites + 7     715 💤 ± 0 
    1 files   ± 0       0 ❌ ± 0 

Results for commit 7fab743. ± Comparison against base commit 1f9ea40.

This pull request removes 1 and adds 24 tests. Note that renamed tests count towards both.
phoenix-rtos-tests/psh/touch ‑ armv7m7-imxrt117x-evk:phoenix-rtos-tests/psh/touch
phoenix-rtos-tests/mem/mmap ‑ armv7a7-imx6ull-evk:phoenix-rtos-tests/mem/mmap.test_mmap.len__not_page_aligned
phoenix-rtos-tests/mem/mmap ‑ armv7a7-imx6ull-evk:phoenix-rtos-tests/mem/mmap.test_mmap.len__not_page_aligned_file
phoenix-rtos-tests/mem/mmap ‑ armv7a7-imx6ull-evk:phoenix-rtos-tests/mem/mmap.test_mmap.len__zero
phoenix-rtos-tests/mem/mmap ‑ armv7a9-zynq7000-qemu:phoenix-rtos-tests/mem/mmap.test_mmap.len__not_page_aligned
phoenix-rtos-tests/mem/mmap ‑ armv7a9-zynq7000-qemu:phoenix-rtos-tests/mem/mmap.test_mmap.len__not_page_aligned_file
phoenix-rtos-tests/mem/mmap ‑ armv7a9-zynq7000-qemu:phoenix-rtos-tests/mem/mmap.test_mmap.len__zero
phoenix-rtos-tests/mem/mmap ‑ armv7a9-zynq7000-zedboard:phoenix-rtos-tests/mem/mmap.test_mmap.len__not_page_aligned
phoenix-rtos-tests/mem/mmap ‑ armv7a9-zynq7000-zedboard:phoenix-rtos-tests/mem/mmap.test_mmap.len__not_page_aligned_file
phoenix-rtos-tests/mem/mmap ‑ armv7a9-zynq7000-zedboard:phoenix-rtos-tests/mem/mmap.test_mmap.len__zero
phoenix-rtos-tests/mem/mmap ‑ armv7m4-stm32l4x6-nucleo:phoenix-rtos-tests/mem/mmap.test_mmap.len__not_page_aligned
…

♻️ This comment has been updated with latest results.

vm/map.c Outdated Show resolved Hide resolved
@badochov badochov marked this pull request as draft August 21, 2024 12:23
vm/map.c Outdated Show resolved Hide resolved
@badochov badochov changed the title fix(vm/munmap): handle munmap of chunks larger than SIZE_PAGE properly fix(vm/mman): handle memory entry chunks splitting properly and munmap Aug 21, 2024
@badochov badochov changed the title fix(vm/mman): handle memory entry chunks splitting properly and munmap fix(vm/mman): handle memory entry chunks splitting properly and munmap of larger chunks Aug 21, 2024
@badochov badochov force-pushed the badochov/munmap-fix branch 2 times, most recently from 836e921 to 5d5ec9e Compare August 21, 2024 13:17
@badochov badochov changed the title fix(vm/mman): handle memory entry chunks splitting properly and munmap of larger chunks fix(vm/mman): handle properly munmap of chunks larger than SIZE_PAGE Aug 21, 2024
@badochov badochov force-pushed the badochov/munmap-fix branch 2 times, most recently from 3729873 to 57a576f Compare August 22, 2024 11:38
@badochov badochov marked this pull request as ready for review August 22, 2024 11:54
Copy link
Member

@agkaminski agkaminski left a comment

Choose a reason for hiding this comment

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

Perhaps we could use vm_mapEntrySplit in case of the "in the middle" munmap

@badochov
Copy link
Contributor Author

Perhaps we could use vm_mapEntrySplit in case of the "in the middle" munmap

Only thing that comes to my mind is changing this part to

			s = map_alloc();
			/* This case if only possible if an unmapped region is in the middle of a single entry,
			 * so there is no possibility of partially unmapping. */
			if (s == NULL) {
				return -ENOMEM;
			}
			vm_mapEntrySplit(proc, map, e, s, overlapStart);
			continue; /* Process in next iteration. */

What do you think about it?

@badochov badochov changed the title fix(vm/mman): handle properly munmap of chunks larger than SIZE_PAGE vm/mman: handle properly munmap of chunks larger than SIZE_PAGE Sep 26, 2024
@agkaminski
Copy link
Member

Perhaps we could use vm_mapEntrySplit in case of the "in the middle" munmap

Only thing that comes to my mind is changing this part to

			s = map_alloc();
			/* This case if only possible if an unmapped region is in the middle of a single entry,
			 * so there is no possibility of partially unmapping. */
			if (s == NULL) {
				return -ENOMEM;
			}
			vm_mapEntrySplit(proc, map, e, s, overlapStart);
			continue; /* Process in next iteration. */

What do you think about it?

Looks nice!

Copy link
Member

@agkaminski agkaminski left a comment

Choose a reason for hiding this comment

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

LGTM

@badochov
Copy link
Contributor Author

badochov commented Sep 26, 2024

@agkaminski @damianloew
unix-socket test failed on CI on armv7a-qemu due to timeout 358ms instead of 350ms, should I be concerned?
Munmap changes should change this test, as in poll and gettime theres no munmap

https://github.com/phoenix-rtos/phoenix-rtos-kernel/actions/runs/11050286361/job/30697841405?pr=578

@agkaminski
Copy link
Member

@agkaminski @damianloew unix-socket test failed on CI on armv7a-qemu due to timeout 358ms instead of 350ms, should I be concerned? Munmap changes should change this test, as in poll and gettime theres no munmap

https://github.com/phoenix-rtos/phoenix-rtos-kernel/actions/runs/11050286361/job/30697841405?pr=578

I guess it did pass on the rerun. @damianloew perhaps this timeout is somewhat on the edge?

@damianloew
Copy link
Contributor

@agkaminski @damianloew unix-socket test failed on CI on armv7a-qemu due to timeout 358ms instead of 350ms, should I be concerned? Munmap changes should change this test, as in poll and gettime theres no munmap
https://github.com/phoenix-rtos/phoenix-rtos-kernel/actions/runs/11050286361/job/30697841405?pr=578

I guess it did pass on the rerun. @damianloew perhaps this timeout is somewhat on the edge?

Yeah, we had a similar problem some time ago and changed the value to 350 from 310:
phoenix-rtos/phoenix-rtos-tests#350

We will consider increasing the value more - probably we will check 400. However I am not sure whether higher values are caused by our system or by the gh machine on which the tests are executed

@badochov badochov merged commit 52e5cf1 into master Sep 26, 2024
30 checks passed
@badochov badochov deleted the badochov/munmap-fix branch September 26, 2024 11:50
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