From nobody Mon Nov 25 15:23:27 2024 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 47795217F4C for ; Fri, 25 Oct 2024 22:12:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729894347; cv=none; b=szavFZymdqAhBVYf//gus82a5AvBFP2K4MN84eLHU04zWMSYlVY9mxmnHWNDDNlMNF+xgpQUq+SbZvOz6A/HnS4waA+t3YregQ6Y9A/6/1W2DITWlG1IQU/YhUUzcMJuvInEgonai5QdnxNlGhu0Ym8jpnZEL7vMBUKr+3rVY7Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729894347; c=relaxed/simple; bh=NK5OZSsxHrxv1wlh6RU3G8N57LyHfd3rgn7LtmDFZgs=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=fMYd9g2vDXIvNc3z5ud9euhkrsGE2zgE24XDHijUu9u2xfvvlJp1ywg6sRQ9DYNJshnRdVRtWTo2yK47tf4hJt0EXu4M2gR3219sun40nNN5y3EWO6PHp7DKiAwAnrqMkDIWgnMvxaH8eNFcWdQhJD+PrsF8sT761eawcBCXt4E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--rananta.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=LpW8zYBo; arc=none smtp.client-ip=209.85.219.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--rananta.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="LpW8zYBo" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-e02fff66a83so4700690276.0 for ; Fri, 25 Oct 2024 15:12:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1729894343; x=1730499143; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=kAitD5UlZ526DH4CXulhVwZM1+TjXuj2ZSzY1GKH9CI=; b=LpW8zYBoJGSJQz5HZxjoDc3iW/SxIU+zk/EYNBfmdJnoCSC1tqzNAvcA3dqe+Mnjf4 O6Ar8h9HbBPiQ5slo993rbHc+GZa2HI54b1/CKtJZyCl7I2M+MmBlAzr1Bw4+PrAgMOS sEGaRMfWOTi0w59EOPtFWuvE5VVBIS90XY4+gz9Tg+AbekjT4Vss/L7pD+GCyn7rfv9K QoxPFf2KmMAif1lKebMvqQG9ATXoO8nWLYmpkMJfimN/W63KmmBsTdiexH0COMcR08GR 1tLOPLCg3pHiIKOPZeHzuOu3JEZ33xlrejp+ZZwxcJWFTv6etw1H9lYzqtYHm+LY2T4x 3Bgg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729894343; x=1730499143; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=kAitD5UlZ526DH4CXulhVwZM1+TjXuj2ZSzY1GKH9CI=; b=u9OUgyoCfmh1rZ2lgxsZXRAoQwZaqYbE1QKC5NBK+7hbPTf0nUD7dotmyw9zFsrlg6 hFtXKMaJbzmjeSDzlqX1rkBY1D/AQ6kK+UevIJxWgauy7uSutnivMnultkxV3ZbdhDpe Zik4zCLqGmHoEIGyE2Tcb4uK4XoCYzo0Y5v+cdUcJ1DwQ97RtWUe463ZxM+uRJlCd8l2 o11DDsGhm1IW1LzcSHB0cD/tLxSdPghbqh/v5d8iZS5LxQ2ofm2l4TPr6Wn/JR9uyULr dhW/PlY4EmGohMWLGeYvwtPh+cgWBml0OxTiu3JJnHlMzAbi9SfkqFTnF78JPQ8e6aoc AJoQ== X-Forwarded-Encrypted: i=1; AJvYcCX4a/NQlErL6CB8ivs54Ybc9rkttPR/55JTxiUBBGMsQB+y2baQxM22kOEedg30MMPAljqaT29epLkK9pc=@vger.kernel.org X-Gm-Message-State: AOJu0YwCzB/9k0Rmj9g0jSVUcuc4VX4vbdNM6tE7o1ng1eZanLAhyrYH Qy+J4IJSSdJMMuOBMfG08Y8fMMbmv7l3oxupUSEiDfP0O9K14g1IVCYKDiGe9ovrMd0YaODPPMz KBii/kA== X-Google-Smtp-Source: AGHT+IG+6UAmoj1XD96N3OA7Nf/oOruad1eDYvy56vmbEa612keZSXmPriH5DCYyGrnCxORY2rVIPeM7z/tx X-Received: from rananta-linux.c.googlers.com ([fda3:e722:ac3:cc00:11b:3898:ac11:fac1]) (user=rananta job=sendgmr) by 2002:a25:ec0c:0:b0:e2b:d389:b35c with SMTP id 3f1490d57ef6-e3087bfc151mr497276.8.1729894343080; Fri, 25 Oct 2024 15:12:23 -0700 (PDT) Date: Fri, 25 Oct 2024 22:12:20 +0000 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-Mailer: git-send-email 2.47.0.163.g1226f6d8fa-goog Message-ID: <20241025221220.2985227-1-rananta@google.com> Subject: [PATCH] KVM: arm64: Mark the VM as dead for failed initializations From: Raghavendra Rao Ananta To: Oliver Upton , Marc Zyngier Cc: Raghavendra Rao Anata , linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, stable@vger.kernel.org, syzbot Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Syzbot hit the following WARN_ON() in kvm_timer_update_irq(): WARNING: CPU: 0 PID: 3281 at arch/arm64/kvm/arch_timer.c:459 kvm_timer_update_irq+0x21c/0x394 Call trace: kvm_timer_update_irq+0x21c/0x394 arch/arm64/kvm/arch_timer.c:459 kvm_timer_vcpu_reset+0x158/0x684 arch/arm64/kvm/arch_timer.c:968 kvm_reset_vcpu+0x3b4/0x560 arch/arm64/kvm/reset.c:264 kvm_vcpu_set_target arch/arm64/kvm/arm.c:1553 [inline] kvm_arch_vcpu_ioctl_vcpu_init arch/arm64/kvm/arm.c:1573 [inline] kvm_arch_vcpu_ioctl+0x112c/0x1b3c arch/arm64/kvm/arm.c:1695 kvm_vcpu_ioctl+0x4ec/0xf74 virt/kvm/kvm_main.c:4658 vfs_ioctl fs/ioctl.c:51 [inline] __do_sys_ioctl fs/ioctl.c:907 [inline] __se_sys_ioctl fs/ioctl.c:893 [inline] __arm64_sys_ioctl+0x108/0x184 fs/ioctl.c:893 __invoke_syscall arch/arm64/kernel/syscall.c:35 [inline] invoke_syscall+0x78/0x1b8 arch/arm64/kernel/syscall.c:49 el0_svc_common+0xe8/0x1b0 arch/arm64/kernel/syscall.c:132 do_el0_svc+0x40/0x50 arch/arm64/kernel/syscall.c:151 el0_svc+0x54/0x14c arch/arm64/kernel/entry-common.c:712 el0t_64_sync_handler+0x84/0xfc arch/arm64/kernel/entry-common.c:730 el0t_64_sync+0x190/0x194 arch/arm64/kernel/entry.S:598 The sequence that led to the report is when KVM_ARM_VCPU_INIT ioctl is invoked after a failed first KVM_RUN. In a general sense though, since kvm_arch_vcpu_run_pid_change() doesn't tear down any of the past initiatializations, it's possible that the VM's state could be left half-baked. Any upcoming ioctls could behave erroneously because of this. Since these late vCPU initializations is past the point of attributing the failures to any ioctl, instead of tearing down each of the previous setups, simply mark the VM as dead, gving an opportunity for the userspace to close and try again. Cc: Reported-by: syzbot Suggested-by: Oliver Upton Signed-off-by: Raghavendra Rao Ananta --- arch/arm64/kvm/arm.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c index a0d01c46e4084..ae3551bc98aeb 100644 --- a/arch/arm64/kvm/arm.c +++ b/arch/arm64/kvm/arm.c @@ -821,12 +821,12 @@ int kvm_arch_vcpu_run_pid_change(struct kvm_vcpu *vcp= u) */ ret =3D kvm_vgic_map_resources(kvm); if (ret) - return ret; + goto out_err; } =20 ret =3D kvm_finalize_sys_regs(vcpu); if (ret) - return ret; + goto out_err; =20 /* * This needs to happen after any restriction has been applied @@ -836,16 +836,16 @@ int kvm_arch_vcpu_run_pid_change(struct kvm_vcpu *vcp= u) =20 ret =3D kvm_timer_enable(vcpu); if (ret) - return ret; + goto out_err; =20 ret =3D kvm_arm_pmu_v3_enable(vcpu); if (ret) - return ret; + goto out_err; =20 if (is_protected_kvm_enabled()) { ret =3D pkvm_create_hyp_vm(kvm); if (ret) - return ret; + goto out_err; } =20 if (!irqchip_in_kernel(kvm)) { @@ -869,6 +869,10 @@ int kvm_arch_vcpu_run_pid_change(struct kvm_vcpu *vcpu) mutex_unlock(&kvm->arch.config_lock); =20 return ret; + +out_err: + kvm_vm_dead(kvm); + return ret; } =20 bool kvm_arch_intc_initialized(struct kvm *kvm) --=20 2.47.0.163.g1226f6d8fa-goog