From 4778b8c9ab8cc4bc2deb778a8ac6c4a816cefc7d Mon Sep 17 00:00:00 2001 From: Rodrigo Arias Date: Thu, 24 Jul 2025 14:48:16 +0200 Subject: [PATCH] Fix premature usage of loom_get_cpu() When loading CPUs for the loom, we cannot use loom_get_cpu() to access the CPUs of the loom by their logical index, as it is not yet populated. The check comes from load_cpus() which tries to prevent duplicated entries in CPU logical indices, but this check is already performed when building the cpus_array, so it is not needed. Tested-by: Arnau Cinca --- CHANGELOG.md | 4 ++++ src/emu/loom.c | 13 ++++--------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 85bf902..ae74f42 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Fixed + +- Fix a bug in ovniemu when loading loom CPUs from multiple threads. + ## [1.12.0] - 2025-05-08 ### Changed diff --git a/src/emu/loom.c b/src/emu/loom.c index 9c39221..10c7c44 100644 --- a/src/emu/loom.c +++ b/src/emu/loom.c @@ -1,4 +1,4 @@ -/* Copyright (c) 2021-2024 Barcelona Supercomputing Center (BSC) +/* Copyright (c) 2021-2025 Barcelona Supercomputing Center (BSC) * SPDX-License-Identifier: GPL-3.0-or-later */ #include "loom.h" @@ -117,14 +117,6 @@ load_cpus(struct loom *loom, JSON_Object *meta) continue; } - /* If we reach this point, there shouldn't be a CPU with the - * same index either, as otherwise the phyid should have matched - * before. So it is an error. */ - if (loom_get_cpu(loom, index) != NULL) { - err("cpu index %d redefined with another phyid", index); - return -1; - } - cpu = calloc(1, sizeof(struct cpu)); if (cpu == NULL) { err("calloc failed:"); @@ -189,6 +181,9 @@ loom_find_cpu(struct loom *loom, int phyid) struct cpu * loom_get_cpu(struct loom *loom, int index) { + if (loom->cpus_array == NULL) + die("cpus_array not yet populated"); + if (index == -1) return &loom->vcpu;