zephyr/kernel
Martí Bolívar a627666e06 device: add fudge factor for handle padding
When CONFIG_USERSPACE is enabled, the ELF file from linker pass 1 is
used to create a hash table that identifies kernel objects by address.
We therefore can't allow the size of any object in the pass 2 ELF to
change in a way that would change those addresses, or we would create
a garbage hash table.

Simultaneously (and regardless of CONFIG_USERSPACE's value),
gen_handles.py must transform arrays of handles from their pass 1
values to their pass 2 values; see the file's docstring for more
details on that transformation.

The way this works is that gen_handles.py just pads out each pass 2
array so its length is the same as its pass 1 value. The padding value
is a repeated run of DEVICE_HANDLE_ENDS values. This value is the
terminator which we look for at runtime in places like
device_required_handles_get(), so there must be at least one, and we
error out in gen_handles.py if there's no room in the pass 2 array for
at least one such value. (If there is extra room, we just keep
inserting extra DEVICE_HANDLE_ENDS values to pad the array to its
original length.)

However, it is possible that a device has more direct dependencies in
the pass 2 handles array than its corresponding devicetree node had in
the pass 1 array. When this happens, users have no recourse, so that's
a potential showstopper.

To work around this possibility for now, add a new config option,
CONFIG_DEVICE_HANDLE_PADDING, whose value defaults to 0.

When nonzero, it is a count of padding handles that are inserted into
each device handles array. When gen_handles.py errors out due to lack
of room, its error message now tells the user how much to increase
CONFIG_DEVICE_HANDLE_PADDING by to work around the problem.

It looks like a real fix for this is to allocate kernel objects whose
addresses are required for hash tables in CONFIG_USERSPACE=y
configurations *before* the handle arrays. The handle arrays could
then be resized as needed in pass 2, which saves ROM by avoiding
unnecessary padding, and would avoid the need for
CONFIG_DEVICE_HANDLE_PADDING altogether.

However, this 'real fix' is not available and we are facing a deadline
to get a temporary solution in for Zephyr v2.7.0, so this is a good
enough workaround for now.

Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
2021-09-30 21:37:59 -04:00
..
include kernel/sched: Add CONFIG_CPU_MASK_PIN_ONLY 2021-09-28 20:15:05 -04:00
paging kernel: mmu: z_backing_store* to k_mem_paging_backing_store* 2021-05-28 11:33:22 -04:00
atomic_c.c kernel: atomic: consistently use named type for atomic pointer values 2021-04-19 15:22:13 +02:00
banner.c kernel: init: move banner handling 2020-11-27 20:08:14 -05:00
cache_handlers.c cache: Rename sys_{dcache,icache}_* to sys_{data,instr}_cache_* 2021-05-08 07:00:33 +02:00
CMakeLists.txt kernel: extract __weak main() into independent file 2021-08-28 08:48:03 -04:00
compiler_stack_protect.c tests: coverage: exclude the CODE UNREACHABLE of code coverage 2021-01-15 12:42:00 -05:00
condvar.c Tracing: Conditional variable tracing 2021-05-07 22:10:21 -04:00
device.c Revert "device: supported devices visitor API" 2021-09-30 21:37:59 -04:00
errno.c kernel: support using thread local storage for errno 2020-10-24 10:52:00 -07:00
fatal.c kernel: fatal: Avoid thread api access when no multithreading 2021-04-29 14:50:35 +02:00
futex.c futex: Avoid unnecessary lock 2021-07-30 20:21:04 -04:00
idle.c kernel/sched: Remove "cooperative scheduling only" special cases 2021-05-24 23:38:16 -04:00
init.c kernel: init: remove empty lcov exclusion 2021-09-06 08:18:15 -04:00
Kconfig device: add fudge factor for handle padding 2021-09-30 21:37:59 -04:00
kheap.c kernel: kheap: make init work with demand paging 2021-08-26 21:16:22 -04:00
mailbox.c kernel: remove object tracing 2021-05-07 22:10:21 -04:00
main_weak.c kernel: extract __weak main() into independent file 2021-08-28 08:48:03 -04:00
mem_domain.c kernel: Make both operands of operators of same essential type category 2021-04-01 05:34:17 -04:00
mem_slab.c toolchain: migrate iterable sections calls to the external API 2021-08-12 17:47:04 -04:00
mempool.c Tracing: Memory Heap tracing 2021-05-07 22:10:21 -04:00
mmu.c kernel: demand_paging: allow reserving page frames 2021-08-26 21:16:22 -04:00
msg_q.c kernel: remove object tracing 2021-05-07 22:10:21 -04:00
mutex.c kernel: Fix negative mutex lock_count value 2021-07-06 19:19:41 -04:00
pipes.c kernel: remove object tracing 2021-05-07 22:10:21 -04:00
poll.c kernel: poll: fix coding guideline 15.7 missing comment 2021-06-04 16:22:50 -05:00
queue.c kernel: remove object tracing 2021-05-07 22:10:21 -04:00
sched.c kernel/sched: Add CONFIG_CPU_MASK_PIN_ONLY 2021-09-28 20:15:05 -04:00
sem.c kernel: remove object tracing 2021-05-07 22:10:21 -04:00
smp.c soc: intel_adsp/cavs_v25: Add CPU halt and relaunch APIs 2021-09-03 07:19:34 -04:00
stack.c kernel: remove object tracing 2021-05-07 22:10:21 -04:00
system_work_q.c kernel: remove old work queue implementation 2021-03-03 20:06:00 -05:00
thread.c kernel/sched: Add CONFIG_CPU_MASK_PIN_ONLY 2021-09-28 20:15:05 -04:00
timeout.c kernel: fix several typos in a comment in timeout.c 2021-07-23 16:06:54 -04:00
timer.c timer: mask interrupts in timer's timeout handler. 2021-09-29 09:18:12 -04:00
userspace.c kernel: app_smem: allowing pinning memory partitions 2021-08-26 21:16:22 -04:00
userspace_handler.c userspace: update k_object API to support immutable objects 2020-09-02 13:48:13 +02:00
version.c zephyr: replace zephyr integer types with C99 types 2020-06-08 08:23:57 -05:00
work.c kernel: work_q: Add an init function 2021-08-25 22:07:04 -04:00
xip.c linker: align __itcm_load_start / __dtcm_data_load_start linker symbols 2021-08-28 08:48:03 -04:00