From 04bda0bf102f605605d77ce71bbc3144ffafb0a4 Mon Sep 17 00:00:00 2001 From: MacRimi Date: Thu, 9 Apr 2026 21:42:44 +0200 Subject: [PATCH] update switch_gpu_mode_direct.sh --- AppImage/components/script-terminal-modal.tsx | 2 - scripts/gpu_tpu/switch_gpu_mode_direct.sh | 89 ++++++++++++++++--- 2 files changed, 77 insertions(+), 14 deletions(-) diff --git a/AppImage/components/script-terminal-modal.tsx b/AppImage/components/script-terminal-modal.tsx index 6571a436..f2b6eea5 100644 --- a/AppImage/components/script-terminal-modal.tsx +++ b/AppImage/components/script-terminal-modal.tsx @@ -126,7 +126,6 @@ const initMessage = { script_path: scriptPath, params: paramsRef.current, } - console.log("[v0] Sending initMessage with params:", paramsRef.current) ws.send(JSON.stringify(initMessage)) setTimeout(() => { @@ -289,7 +288,6 @@ const initMessage = { script_path: scriptPath, params: paramsRef.current, } - console.log("[v0] WS onopen - Sending params:", paramsRef.current) ws.send(JSON.stringify(initMessage)) }, 50) diff --git a/scripts/gpu_tpu/switch_gpu_mode_direct.sh b/scripts/gpu_tpu/switch_gpu_mode_direct.sh index d110c3cb..d3e6d3fb 100644 --- a/scripts/gpu_tpu/switch_gpu_mode_direct.sh +++ b/scripts/gpu_tpu/switch_gpu_mode_direct.sh @@ -359,6 +359,44 @@ _remove_amd_softdep() { $changed } +_add_vfio_modules() { + local modules=("vfio" "vfio_iommu_type1" "vfio_pci") + local kernel_major kernel_minor + kernel_major=$(uname -r | cut -d. -f1) + kernel_minor=$(uname -r | cut -d. -f2) + if (( kernel_major < 6 || ( kernel_major == 6 && kernel_minor < 2 ) )); then + modules+=("vfio_virqfd") + fi + local mod + for mod in "${modules[@]}"; do + _add_line_if_missing "$mod" /etc/modules + done +} + +_remove_vfio_modules_if_unused() { + local vfio_count + vfio_count=$(_read_vfio_ids | wc -l | tr -d '[:space:]') + [[ "$vfio_count" != "0" ]] && return 1 + local modules_file="/etc/modules" + [[ ! -f "$modules_file" ]] && return 1 + local had_any=false + grep -qE '^vfio$|^vfio_iommu_type1$|^vfio_pci$|^vfio_virqfd$' "$modules_file" 2>/dev/null && had_any=true + sed -i '/^vfio$/d' "$modules_file" + sed -i '/^vfio_iommu_type1$/d' "$modules_file" + sed -i '/^vfio_pci$/d' "$modules_file" + sed -i '/^vfio_virqfd$/d' "$modules_file" + if $had_any; then + HOST_CONFIG_CHANGED=true + return 0 + fi + return 1 +} + +_configure_iommu_options() { + _add_line_if_missing "options vfio_iommu_type1 allow_unsafe_interrupts=1" /etc/modprobe.d/iommu_unsafe_interrupts.conf + _add_line_if_missing "options kvm ignore_msrs=1" /etc/modprobe.d/kvm.conf +} + _selected_types_unique() { local idx t local -a seen=() @@ -431,6 +469,40 @@ find_gpu_by_slot() { return 1 } +validate_vm_mode_blocked_ids() { + [[ "$TARGET_MODE" != "vm" ]] && return 0 + + local -a blocked_lines=() + local idx viddid name pci + for idx in "${SELECTED_GPU_IDX[@]}"; do + viddid="${ALL_GPU_VIDDID[$idx]}" + name="${ALL_GPU_NAMES[$idx]}" + pci="${ALL_GPU_PCIS[$idx]}" + + case "$viddid" in + 8086:5a84|8086:5a85) + blocked_lines+=(" - ${name} (${pci}) [ID: ${viddid}]") + ;; + esac + done + + [[ ${#blocked_lines[@]} -eq 0 ]] && return 0 + + local msg + msg="
$(translate 'Blocked GPU ID for VM Mode')
" + msg+="

$(translate 'At least one selected GPU is blocked by policy for GPU -> VM mode due to passthrough instability risk.')

" + msg+="

$(translate 'Blocked device(s)'):

" + msg+="

$(translate 'Recommended: use GPU -> LXC mode for these devices.')

" + + hybrid_msgbox "$(translate 'GPU Switch Mode Blocked')" "$msg" + return 1 +} + collect_selected_iommu_ids() { SELECTED_IOMMU_IDS=() SELECTED_PCI_SLOTS=() @@ -913,20 +985,8 @@ main() { : >"$LOG_FILE" : >"$screen_capture" - # Debug: Show received environment variables - echo "[DEBUG] Environment variables received:" - echo "[DEBUG] GPU_SWITCH_PARAMS='$GPU_SWITCH_PARAMS'" - echo "[DEBUG] EXECUTION_MODE='$EXECUTION_MODE'" - echo "" - parse_arguments "$@" - # Debug: Show parsed parameters - echo "[DEBUG] After parsing:" - echo "[DEBUG] PARAM_GPU_SLOT='$PARAM_GPU_SLOT'" - echo "[DEBUG] PARAM_TARGET_MODE='$PARAM_TARGET_MODE'" - echo "" - # Validate required parameters if [[ -z "$PARAM_GPU_SLOT" ]]; then msg_error "$(translate 'Missing required parameter'): --gpu-slot" @@ -955,6 +1015,11 @@ main() { exit 1 fi + # Validate if GPU is blocked for VM mode (certain Intel GPUs) + if ! validate_vm_mode_blocked_ids; then + exit 1 + fi + # Show info about selected GPU local gpu_idx="${SELECTED_GPU_IDX[0]}" msg_info "$(translate 'GPU selected'): ${ALL_GPU_NAMES[$gpu_idx]} (${ALL_GPU_PCIS[$gpu_idx]})"