Skip to content

Conversation

@andrewboie
Copy link
Contributor

@andrewboie andrewboie commented Apr 3, 2019

  • Address an off-by-one in ARC MPU v2 driver when testing whether a thread has access to a particular memory range at the end of the MPU region (similar to a bug I recently fixed in the MPU v3 implementation)
  • Fix a definition problem with K_THREAD_STACK_MEMBER() on ARC
  • Drastically improve testing of stack objects to reduce future bit-rot

Fixes: #15130
Fixes: #15131

@andrewboie andrewboie requested review from a user, ceolin, dcpleung, ioannisg and vonhust April 3, 2019 01:24
@andrewboie andrewboie added the bug The issue is a bug, or the PR is fixing a bug label Apr 3, 2019
@andrewboie andrewboie modified the milestones: v1.14.1, v1.14.0 Apr 3, 2019
@andrewboie andrewboie requested review from agross-oss and galak April 3, 2019 01:24
Copy link
Member

Choose a reason for hiding this comment

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

Don't know what the best is, here. I would prefer : (start + size - 1) < r_addr_end
It's a style thing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

you've lost me.
they are the same.

Copy link
Member

Choose a reason for hiding this comment

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

I know, I said it is a style thing :) We usually have "something" -1 < "sthg else", not <=.
Just style, ignore at will.

Copy link
Member

Choose a reason for hiding this comment

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

my suggestion would be to directly compare sizes and not calculate end addresses: no need to add the start addresses, less risk for 1-off mistakes.

Copy link
Member

@ioannisg ioannisg left a comment

Choose a reason for hiding this comment

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

Looks ok
NACK - just until I test it in ARMv8-M

Copy link
Member

Choose a reason for hiding this comment

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

Could we simply use the Z_SYSCALL_MEMORY_WRITE macros here, too? Isn't it effectively the same?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

what is the advantage of doing that

Copy link
Member

Choose a reason for hiding this comment

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

Where does the name tls come from?

Copy link
Member

Choose a reason for hiding this comment

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

Isn't this a more generic thing, i.e. getting the pointer to the userspace local data?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it's not.
userspace local data is a poorly named implementation of thread-local storage.

Copy link
Member

Choose a reason for hiding this comment

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

Right! So tls is thread-local storage? I confused it to TLS, actually, remembering you did some mbedTLS stuff few days ago.

Yes, I have a task for 1.15 to rename that, actually.

Copy link
Member

Choose a reason for hiding this comment

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

Report interesting information ) :)

Copy link
Member

@ioannisg ioannisg Apr 3, 2019

Choose a reason for hiding this comment

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

Correct me if I am wrong, but I think this could be strickt equality, except for the case of ARMv7-M MPU. Right @andrewboie ?

Update: IMHO, for ARM builds, this should always be a strict equality check, if obj_size is the sizeof an object created by K_THREAD_STACK_DEFINE(obj, STEST_STACKSIZE), right? This is because the privileged stack for ARM is allocated elsewhere.

For ARC the obj_size is, trivially, larger than STEST_STACKSIZE, because we also allocate the privilege area in the same object, AFAIU. So this check has little value. Instead we should perhaps check whether the created stack object can hold a thread buffer of STEST_STACKSIZE excluding any priv stack size...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I need to work with the objects as they are currently defined.
I don't want to further iterate on this until after 1.14 is out.

Copy link
Member

Choose a reason for hiding this comment

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

Let's improve this in 1.15

Copy link
Member

Choose a reason for hiding this comment

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

Should we be more consistent on types for pos and val? E.g. char val and char *pos, or using u8_t...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

why is this change needed?

Copy link
Member

Choose a reason for hiding this comment

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

Just a style thing

Copy link
Member

Choose a reason for hiding this comment

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

Again, I suppose, we can't use a strict equality due to ARMv7-MPU, right?

Copy link
Member

Choose a reason for hiding this comment

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

I know, it might not be of great value, and would make the test case not so easy to read, but would it make sense to transform some of the inequalities to strict equality (whenever possible), in order to get higher coverage level?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

can we do this some other time?
I have very little bandwidth to further enhance this test until after 1.14 is out

Copy link
Member

Choose a reason for hiding this comment

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

Yeap, let's do this in 1.15

Copy link
Member

Choose a reason for hiding this comment

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

Can we repeat the test using k_thread_create with THREAD_STACK_SIZEOF, to confirm that that is also working?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

can we do this some other time?
I have very little bandwidth to further enhance this test until after 1.14 is out

Copy link
Member

Choose a reason for hiding this comment

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

Let's improve this in 1.15

Copy link
Member

@ioannisg ioannisg left a comment

Choose a reason for hiding this comment

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

The test as-is is passing on all ARM-based MPU architectures.
Left some feedback to be addressed.

@andrewboie andrewboie requested a review from ioannisg April 3, 2019 16:47
@andrewboie
Copy link
Contributor Author

@ioannisg it's not clear to me what items in your feedback are gating acceptance. I fixed the call to check both read and write permissions, and removed the TLS pointer syscall as I haven't written a test yet to use it. The other feedback seems to be either further enhancements you desire, or fall under the category of "six of one, half dozen of the other"

Andrew Boie added 3 commits April 3, 2019 09:56
Similar issue to what was fixed earlier in the MPUv3
code. start + size should be <= r_addr_end. Fixes
a problem where the last byte of an MPU region is
incorrectly reported as out-of-bounds.

Fixes: zephyrproject-rtos#15131

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
Unlike the others, this macro was not taking into
account minimum MPU region sizes by filtering through
STACK_SIZE_ALIGN().

Fixes: zephyrproject-rtos#15130

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
The stack information stored in the thread->stack_info
fields need to represent the actual writable area for
its associated thread. Perform various tests to ensure
that the various reported and specified values are in
agreement.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
@andrewboie andrewboie force-pushed the arc-fixes-stacks-test branch from 1e1b6d8 to c612522 Compare April 3, 2019 16:57
Copy link
Member

@ioannisg ioannisg left a comment

Choose a reason for hiding this comment

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

Good to go for ARM, thanks for the test - really helpful.

@nashif nashif merged commit 14db4ee into zephyrproject-rtos:master Apr 3, 2019
@andrewboie andrewboie deleted the arc-fixes-stacks-test branch April 10, 2019 14:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug The issue is a bug, or the PR is fixing a bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ARC: off-by-one in MPU V2 _is_in_region() ARC: Z_ARCH_THREAD_STACK_MEMBER defined incorrectly

6 participants