Panic on events when the thread is preempted

When the thread is not running on the CPU it shouldn't be able to emit
events. A new emulation test ensures the emulation fails if it happens.
This commit is contained in:
Rodrigo Arias 2024-03-20 15:51:20 +01:00
parent 31fa1508f7
commit 6aff4388eb
5 changed files with 56 additions and 1 deletions

View File

@ -555,6 +555,11 @@ process_ev(struct emu *emu)
return -1; return -1;
} }
if (emu->thread->is_out_of_cpu) {
err("current thread %d out of CPU", emu->thread->tid);
return -1;
}
switch (emu->ev->c) { switch (emu->ev->c) {
case 'S': case 'S':
case 'U': case 'U':

View File

@ -1,4 +1,4 @@
/* Copyright (c) 2021-2023 Barcelona Supercomputing Center (BSC) /* Copyright (c) 2021-2024 Barcelona Supercomputing Center (BSC)
* SPDX-License-Identifier: GPL-3.0-or-later */ * SPDX-License-Identifier: GPL-3.0-or-later */
#include "ovni_priv.h" #include "ovni_priv.h"
@ -458,6 +458,11 @@ model_ovni_event(struct emu *emu)
return -1; return -1;
} }
if (emu->thread->is_out_of_cpu) {
err("current thread %d out of CPU", emu->thread->tid);
return -1;
}
switch (emu->ev->c) { switch (emu->ev->c) {
case 'H': case 'H':
return pre_thread(emu); return pre_thread(emu);

View File

@ -0,0 +1,18 @@
/* Copyright (c) 2024 Barcelona Supercomputing Center (BSC)
* SPDX-License-Identifier: GPL-3.0-or-later */
#ifndef INSTR_KERNEL_H
#define INSTR_KERNEL_H
#include "instr.h"
static inline void
instr_kernel_init(void)
{
instr_require("kernel");
}
INSTR_0ARG(instr_kernel_cs_out, "KCO")
INSTR_0ARG(instr_kernel_cs_in, "KCI")
#endif /* INSTR_KERNEL_H */

View File

@ -31,3 +31,6 @@ test_emu(bad-pause-parallel.c SHOULD_FAIL
REGEX "body_pause: body(id=1,taskid=1) is not allowed to pause") REGEX "body_pause: body(id=1,taskid=1) is not allowed to pause")
test_emu(bad-nest-from-parallel.c SHOULD_FAIL test_emu(bad-nest-from-parallel.c SHOULD_FAIL
REGEX "body_execute: cannot nest body(id=2,taskid=2) over body(id=1,taskid=1) which is already running") REGEX "body_execute: cannot nest body(id=2,taskid=2) over body(id=1,taskid=1) which is already running")
test_emu(events-from-outside-cpu.c SHOULD_FAIL
REGEX "current thread .* out of CPU")

View File

@ -0,0 +1,24 @@
/* Copyright (c) 2024 Barcelona Supercomputing Center (BSC)
* SPDX-License-Identifier: GPL-3.0-or-later */
#include <ovni.h>
#include "instr_nosv.h"
#include "../kernel/instr_kernel.h"
int
main(void)
{
instr_start(0, 1);
instr_nosv_init();
instr_kernel_init();
/* Make the current thread out of CPU */
instr_kernel_cs_out();
/* Try to emit a nOS-V event: should fail */
instr_nosv_type_create(666);
instr_end();
return 0;
}