From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f171.google.com (mail-pf1-f171.google.com [209.85.210.171]) (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 D2F45304972 for ; Sun, 12 Apr 2026 08:04:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.171 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775981089; cv=none; b=Y5V/InUZo0KuTwms62qXiFBsuPUipZixuj+buIgfBfRh8noVWvmtuI3YRNEHyFJmeotgjNmx4y5VDxQfwTHp56cVewH6VBEinJ1c0RRw62eHZo85h10A/JpwnBiSnR/VPvtaJpY4Hn3QNCPTwtWsLp5QepZWVRU0D6No8Ep1bgI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775981089; c=relaxed/simple; bh=1+M/LxRWc86eWq4cNRHT0yrYfUE6yViWD9TbxaM0v0k=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=VLENbyLLRyEKoI9na8uYT9zzwUfeWIqaR93KObiCML3+A7qttDUeoK1PpVEx3MoiRwJyqBDla+i9rCEEkmf1JZ42UxZb7BXbFalkTZFIPXufImKfeaJqp6PVAyEIbSEFys2rHFxI1qerc2G7T+xynCxkVlJh37mhAzzVpPjDbpA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=RCTHlhHk; arc=none smtp.client-ip=209.85.210.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="RCTHlhHk" Received: by mail-pf1-f171.google.com with SMTP id d2e1a72fcca58-82f2385724aso615395b3a.0 for ; Sun, 12 Apr 2026 01:04:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1775981087; x=1776585887; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=2hKpQKRb1doRhCbODxXOkqcma9DZMRnM3wlvxT1Nafs=; b=RCTHlhHkf4OjLbHL3UUrCRZgnFBAq49bi+vLjdz7ia48gpSBimozLcdIFB7Y0B9Z9D 8drHDKNN8Fxir/Xkl9K4ACqBTD+94G8GdU08NoX9fXJvKz8hhWc7XBE4KdLiZIBXW29y jgvEJalVtL1n7cST4jSSWNvYCDeaUSc/EiOdhYsa11znYqXsEx9dlqUCazFnOybC/7Th wVTqgNJ+qWwnOQShh0yAi9Sg+1YnZbMd8BjIV8OwVnoxHlhi8JwuMGUGweNY2N7C2yHx Q0RUNQuZtHcRhkixl0AvloyO20/s29Gw+rW1PEdIuwVagwGlkSTez6ct2GnV+4lWfifx yGvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775981087; x=1776585887; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=2hKpQKRb1doRhCbODxXOkqcma9DZMRnM3wlvxT1Nafs=; b=FJANQxudddy0jftoOe+fcfn+jeAVACa+syoiIxgZeUbnBPFtpx1sbzmAjFTAbdDx5R SbINT4NSOQZCfzDWsQYAnN4SxKAznfbukQiJePvG/k7Auw3ayrzB70FHv3jD4PS6hsSn 6K3/Zls1sHmHjoaFDScX6Z2kddwRskb9R1zIVeyG5+eHB77WGNi76ZMsyDYpbg3NGqCv YcIQQKAmM4K7sQmeT0KgMuNNmIOUKLmSOE7m05LFFmmPVDz1XXmwCB4L1UffdWiuIBX3 ftWRpHy8n5Ny7b5UohwQ1kzHnWsubDgtIgUfSpmG4XNJGQx7XjQ5/XpUdhVx/UE0RAHY 0F2w== X-Forwarded-Encrypted: i=1; AJvYcCVwkn1dRd/rg9tH1lsdYvP9JsojrsVZWhd81PEzOXdaUORughLKIlsHr5kO2sCdEjRmWHhsAVvJx4KZSPE=@vger.kernel.org X-Gm-Message-State: AOJu0YwMoa7WIDvYz+cVxU+ya86n76ZnulaT+wyHhJtx7PAqc+MWiv/z xPUP646sSTwoczfp/0AwVJrF+gO+NPByelkgXF5VrkiZjhu7IOIb+DAs X-Gm-Gg: AeBDiesqqOdzO3OMl/R0Bbb4xEcyJGSHvhmGDtc89grn+g/IG3hkXatuHN8r1zDrL16 a64qNaYnz4F2aLA5rbHHtOaFtxaAnipYOVOwqtSm3/LzicYBclvj/zaNw0CmdKzuArrh6rNoxAS IUn1/y5loammJNUCyaDmkn6q3AUNyo+p6hQoPVmhqSV3YfCORGGpO2wZ8Cvy9VhYlQg0Cs06/nX fIjKG36JbqM5XnrIJTxoNn/mozs9wCA8J6KjA/O6gsf1giGBLj7yO97WNOrRIa4RHhJjxv/Dwb7 CXK/NDtlk5UqkKjJ4Oo4Mrt+BrTuSVSH6GQKF8UTx8Z3LopN1bnAE90ZwEgLngeID45AgvYVW1C jBa9e622SVVt3R2u+CRXKVJw9oSihFyGa5E44P4R4TxNhPPJrfITwNqqVBvolAEeQxsO5J7fQDq 5UO6YhADpj9YkyJh0vcLNN/tvphTl8VUPuGyDGWdM+flonJwHHXnxBwlY6WXbYC/zhLUTW+2OGK ily6A== X-Received: by 2002:a05:6a00:1f03:b0:82c:9f73:a2f with SMTP id d2e1a72fcca58-82f0c2c8bfbmr10079288b3a.40.1775981087078; Sun, 12 Apr 2026 01:04:47 -0700 (PDT) Received: from deepanshu-kernel-hacker.. ([2405:201:682f:383f:142c:c389:4a2:63cd]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-82f0c33de57sm7389959b3a.21.2026.04.12.01.04.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 12 Apr 2026 01:04:46 -0700 (PDT) From: Deepanshu Kartikey To: maz@kernel.org, oupton@kernel.org, joey.gouly@arm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com, catalin.marinas@arm.com, will@kernel.org Cc: drjones@redhat.com, christoffer.dall@arm.com, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org, Deepanshu Kartikey , syzbot+12b178b7c756664d2518@syzkaller.appspotmail.com Subject: [PATCH] arm64: KVM: Initialize vGIC before preempt-disabled section in kvm_reset_vcpu() Date: Sun, 12 Apr 2026 13:34:37 +0530 Message-ID: <20260412080437.38782-1-kartikey406@gmail.com> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit kvm_reset_vcpu() calls kvm_timer_vcpu_reset() inside a preempt-disabled section to avoid races with preempt notifiers that also call vcpu put/load. However, kvm_timer_vcpu_reset() eventually calls kvm_vgic_inject_irq() which triggers vgic_lazy_init() if the vGIC has not been initialized yet. vgic_lazy_init() acquires a mutex and calls vgic_init() which invokes synchronize_srcu_expedited() -- both of which may sleep. Sleeping inside a preempt-disabled section is illegal and causes: BUG: scheduling while atomic: syz.1.49/3699/0x00000002 Fix this by calling vgic_lazy_init() before preempt_disable(). On the second call inside kvm_vgic_inject_irq(), vgic_initialized() will return true and vgic_lazy_init() will return immediately without sleeping. Fixes: e761a927bc9a ("KVM: arm/arm64: Reset the VCPU without preemption and vcpu state loaded") Reported-by: syzbot+12b178b7c756664d2518@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=12b178b7c756664d2518 Tested-by: syzbot+12b178b7c756664d2518@syzkaller.appspotmail.com Signed-off-by: Deepanshu Kartikey --- arch/arm64/kvm/reset.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/arch/arm64/kvm/reset.c b/arch/arm64/kvm/reset.c index b963fd975aac..4ee16b4a37b5 100644 --- a/arch/arm64/kvm/reset.c +++ b/arch/arm64/kvm/reset.c @@ -25,6 +25,7 @@ #include #include #include +#include "vgic/vgic.h" #include #include #include @@ -198,6 +199,14 @@ void kvm_reset_vcpu(struct kvm_vcpu *vcpu) vcpu->arch.reset_state.reset = false; spin_unlock(&vcpu->arch.mp_state_lock); + + /* + * Initialize vGIC before entering preempt-disabled section. + * vgic_lazy_init() may sleep via mutex_lock, which is illegal + * inside preempt_disable(). Second call inside kvm_vgic_inject_irq + * will find vGIC already initialized and return immediately. + */ + vgic_lazy_init(vcpu->kvm); preempt_disable(); loaded = (vcpu->cpu != -1); if (loaded) -- 2.43.0