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

Arch arm mpu assert additions and fixes #8028

Merged

Conversation

ioannisg
Copy link
Member

@ioannisg ioannisg commented May 30, 2018

Addresses #7384.
Addresses an additional bug related to region out-of-bounds configuration (see relevant comment).
Adds some minor fixes to the code and comment enhancements.

@@ -273,8 +273,7 @@ void arm_core_mpu_configure(u8_t type, u32_t base, u32_t size)
u32_t region_index = _get_region_index_by_type(type);
u32_t region_attr = _get_region_attr_by_type(type, size);

/* ARM MPU supports up to 16 Regions */
if (region_index > _get_num_regions()) {
Copy link
Member Author

Choose a reason for hiding this comment

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

This looks like an out-of-bounds sanity-check bug, @agross-linaro, am I correct?

@ioannisg ioannisg added bug The issue is a bug, or the PR is fixing a bug Enhancement Changes/Updates/Additions to existing features area: ARM ARM (32-bit) Architecture area: Memory Protection labels May 30, 2018
@codecov-io
Copy link

codecov-io commented May 30, 2018

Codecov Report

Merging #8028 into master will increase coverage by <.01%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #8028      +/-   ##
==========================================
+ Coverage   64.54%   64.54%   +<.01%     
==========================================
  Files         420      420              
  Lines       40131    40131              
  Branches     6759     6759              
==========================================
+ Hits        25902    25903       +1     
  Misses      11106    11106              
+ Partials     3123     3122       -1
Impacted Files Coverage Δ
boards/posix/native_posix/timer_model.c 100% <0%> (+1.78%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 386b3e6...221c446. Read the comment docs.

@ioannisg ioannisg force-pushed the arch_arm_mpu_assert_additions branch from b406067 to cfb5167 Compare May 30, 2018 13:23
@ioannisg
Copy link
Member Author

FYI @andrewboie @agross-linaro @carlescufi .
I added the 1.12 milestone, so that we could try to get it in the release if possible; the region out-of-bounds bugs, which this PR attempts to fix, are not critical for the release, but I think they are "nice-to-have-fixed".

I think that this PR overlaps partially with #7902 .

@ioannisg ioannisg added the priority: medium Medium impact/importance bug label May 30, 2018
Copy link
Contributor

@andrewboie andrewboie left a comment

Choose a reason for hiding this comment

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

I think this code does too much.

It's sufficient to just make assertion checks, not try to prevent the system from crashing if assertions are off and people feed garbage data to the MPU driver. We only do this kind of rigorous runtime checking for drivers that we expose to user mode.

Copy link
Contributor

@andrewboie andrewboie left a comment

Choose a reason for hiding this comment

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

I think this is fine for 1.12

if (size > 0)
_region_init(index, (u32_t)&__app_ram_start, region_attr);
#endif
if (index < _get_num_regions())
Copy link
Contributor

Choose a reason for hiding this comment

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

missing braces

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks!

@ioannisg ioannisg force-pushed the arch_arm_mpu_assert_additions branch from cfb5167 to 12a3fb4 Compare May 30, 2018 14:30
@ioannisg ioannisg added this to the v1.12.0 milestone May 30, 2018
Copy link
Member

@MaureenHelm MaureenHelm left a comment

Choose a reason for hiding this comment

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

LGTM. Some of the comments you're fixing are also in the nxp mpu, could you please fix those too?

@@ -143,7 +143,7 @@ static inline u32_t _get_region_index_by_type(u32_t type)
}

/**
* This internal function check if region is enabled or not
* This internal function checks if region is enabled or not.
Copy link
Member

Choose a reason for hiding this comment

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

Can you please make the same comment fixes in the nxp mpu?

Copy link
Member Author

Choose a reason for hiding this comment

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

Will have a look now.

ioannisg added 5 commits May 31, 2018 10:01
This commit fixes some minor issues with coding style
and comment syntax in arm_mpu.c

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
This commit enhaces the documentation of internal functions
in arm_mpu.c by explicitly stating that the caller needs to
ensure the validity of the supplied MPU region index. The
warning is required as these functions modify the ARM MPU_RNR
register, without checking themselves the validity of the
provided region number.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
This commit adds an internal function to disable an MPU region.
The function includes an assert that the requested MPU region
number is a valid one. arm_mpu.c is refactor to use this
function in all cases where an MPU region needs to be disabled.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
This commit inserts sanity checks every time we are performing
a (re)-configuration of one or multiple MPU regions, ensuring
that we do not attempt to configure an invalid region number.

Particulary for arm_mpu_config(), called during pre-kernel
initialization phase, we add a system ASSERT if we attempt
to initialize more regions that what is supported by hardware.
We do this to ensure the misconfiguration is detected early and
the system boot is aborted.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
This commit fixes some minor function documentation issues
and comments' style in the NXP_MPU driver.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
@ioannisg ioannisg force-pushed the arch_arm_mpu_assert_additions branch from 12a3fb4 to 221c446 Compare May 31, 2018 08:01
@ioannisg
Copy link
Member Author

@MaureenHelm I pushed an additional commit that implements the comment&style fixes in NXP_MPU.

@nashif nashif merged commit e76ef30 into zephyrproject-rtos:master May 31, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: ARM ARM (32-bit) Architecture area: Memory Protection bug The issue is a bug, or the PR is fixing a bug Enhancement Changes/Updates/Additions to existing features priority: medium Medium impact/importance bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants