From 4b0590415d20a068d612507f51f69fce22f09a4e Mon Sep 17 00:00:00 2001 From: Yonghua Huang Date: Tue, 8 Feb 2022 14:45:20 +0300 Subject: [PATCH] dm: disable TCC strict CPU affinity check By default, pCPU is allowed to request software SRAM buffer from given region in TCC buffer driver only if this pCPU is set in the target region's CPU affinity configuration. This check shall be disabled for software SRAM virtualization usage in ACRN service VM, because software SRAM buffers are requested by ACRN DM on behalf of user VM, but ACRN DM and user VM may run on different CPUs while the target software SRAM region may be configured only for pCPUs that user VM runs on. This patch turns off such affinity check in TCC driver when initializing vSSRAM for user VM. Tracked-On: #7010 Signed-off-by: Yonghua Huang Reviewed-by: Geoffroy Van Cutsem Acked-by: Yu Wang --- devicemodel/hw/platform/vssram/vssram.c | 46 +++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/devicemodel/hw/platform/vssram/vssram.c b/devicemodel/hw/platform/vssram/vssram.c index 74d857e66..ae50aa1d0 100644 --- a/devicemodel/hw/platform/vssram/vssram.c +++ b/devicemodel/hw/platform/vssram/vssram.c @@ -235,6 +235,38 @@ static int tcc_driver_init_buffer_fd(void) return 0; } +/** + * @brief Disable CPU affinity check in TCC driver. + * + * @param void. + * + * @return 0 on success and -1 on fail. + */ +static int disable_tcc_strict_affinity_check(void) +{ +#define AFFINITY_CHECK_PARAM "/sys/module/tcc_buffer/parameters/strict_affinity_check" + int fd, ret = 0U; + + fd = open(AFFINITY_CHECK_PARAM, O_WRONLY); + if (fd < 0) { + pr_err("%s: Failed to open %s: %s(%i), please check its availability.\n", + __func__, AFFINITY_CHECK_PARAM, strerror(errno), errno); + return -1; + } + + /* Value of 0 means turning off CPU affinity check. */ + if (write(fd, "0", 1) < 0) { + pr_err("%s: Failed to turn off affinity checking in the TCC driver" + "(could not write to: %s: %s(%i)", __func__, + AFFINITY_CHECK_PARAM, strerror(errno), errno); + ret = -1; + } + + close(fd); + return ret; +} + + /** * @brief Get count of TCC software SRAM regions. * @@ -1232,6 +1264,20 @@ int init_vssram(struct vmctx *ctx) if (tcc_driver_init_buffer_fd() < 0) return -1; + /* + * By default, pCPU is allowed to request software SRAM buffer + * from given region in TCC buffer driver only if this pCPU is + * set in the target region's CPU affinity configuration. + * + * This check shall be disabled for software SRAM virtualization + * usage in ACRN service VM, because software SRAM buffers are + * requested by ACRN DM on behalf of user VM, but ACRN DM and + * user VM may run on different CPUs while the target software + * SRAM region may be configured only for pCPUs that user VM runs on. + */ + if (disable_tcc_strict_affinity_check() < 0) + return -1; + if (vssram_init_buffers() < 0) { pr_err("%s, initialize vssram buffer description failed.\n", __func__); return -1;