From a8027abd1e5538105de13906ae746493e3d19ffd Mon Sep 17 00:00:00 2001 From: Vincent Donnefort Date: Thu, 8 May 2025 15:52:11 +0100 Subject: [PATCH] ANDROID: KVM: arm64: Redirect modprobe to /dev/kmsg When using early loading for pKVM modules, redirect modprobe stdout/stderr to /dev/kmsg to get logs. This is handy in case of failure. Bug: 357781595 Bug: 254835242 Bug: 415374827 Change-Id: I9d435071f5ec7b47a702ce5e9802b882a4ea9cb4 Signed-off-by: Vincent Donnefort --- arch/arm64/kvm/pkvm.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/arch/arm64/kvm/pkvm.c b/arch/arm64/kvm/pkvm.c index c0955191e519..8da5299fd751 100644 --- a/arch/arm64/kvm/pkvm.c +++ b/arch/arm64/kvm/pkvm.c @@ -927,11 +927,28 @@ static int __init early_pkvm_modules_cfg(char *arg) } early_param("kvm-arm.protected_modules", early_pkvm_modules_cfg); -static void free_modprobe_argv(struct subprocess_info *info) +static void __init free_modprobe_argv(struct subprocess_info *info) { kfree(info->argv); } +static int __init init_modprobe(struct subprocess_info *info, struct cred *new) +{ + struct file *file = filp_open("/dev/kmsg", O_RDWR, 0); + + if (IS_ERR(file)) { + pr_warn("Warning: unable to open /dev/kmsg, modprobe will be silent.\n"); + return 0; + } + + init_dup(file); + init_dup(file); + init_dup(file); + fput(file); + + return 0; +} + /* * Heavily inspired by request_module(). The latest couldn't be reused though as * the feature can be disabled depending on umh configuration. Here some @@ -974,7 +991,7 @@ static int __init __pkvm_request_early_module(char *module_name, argv[idx++] = NULL; info = call_usermodehelper_setup(modprobe_path, argv, envp, GFP_KERNEL, - NULL, free_modprobe_argv, NULL); + init_modprobe, free_modprobe_argv, NULL); if (!info) goto err;