From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 6B089C021B6 for ; Mon, 24 Feb 2025 23:55:54 +0000 (UTC) Received: from boromir.ozlabs.org (localhost [127.0.0.1]) by lists.ozlabs.org (Postfix) with ESMTP id 4Z1yL030Hnz30Ns; Tue, 25 Feb 2025 10:55:52 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; arc=none smtp.remote-ip="2607:f8b0:4864:20::1049" ARC-Seal: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1740441352; cv=none; b=Gnp6LwYo+yvJHEUlD8QF/rh8oUjL5+fn7O2uaUFRADfVE/j9aMG5XQapxmEK6KmONuV49Zgp3EzfzCB9G8zrfMLggIx3psuSz8QCtLVkUvZA8t9uzrONBts5vWt60TrRga1mMaGqjWkdUq7sPq+DhCuPcndor6tI37MIBEWKpxgXvHyO3Oiu5sz6vvF8Jft/DkiBxZIvLB2f2AfMaak1svZXXiSinax7lMppUE4W6VGHTqCX8RCBCVYnToNUXHytfDCMh89piUW0z+qdPIbl57JU8TX+cewriKA9VSEEBfNSBipH5cMaxl9dPqpDFbPbXCzfVTKXsOm+uBldYcEotg== ARC-Message-Signature: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1740441352; c=relaxed/relaxed; bh=G4yv5E3Df19Io1ieaPGo0Ai9BtJpUzyQSBdyF3aMs18=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=ki+QPFJTkHRGkPMxSehPBPmoGvsCFJ4e25bLt1Ow7OJRx+5OzCiDh2iSSObesTNpLnIr9ZcCg66gkzKbLJRTw7XMJi4RnIVcQEDocKCyOLs+feQyoH+/iayv6Vlbkp2GYmwKxoZe8X5EGrHmg8sdc96HrFcKN8eZteOGnxHkKGcW5FQAZ/Lew/8n25vQ4C7EArRj33dXQWh4Rb6x/GpRRRlp5UTtbXz+dnsYSSpzyq+r1G1TnTGWRcujJyJSp7gQWgW7XlRS05gpqY6swDJ61NhPkJ7is6A4vAjv5Q1epmbfzYf3Z8FE9azA4hSVBtgqnvPczDnRFhHW8essk2OEow== ARC-Authentication-Results: i=1; lists.ozlabs.org; dmarc=pass (p=reject dis=none) header.from=google.com; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20230601 header.b=doQjWl2/; dkim-atps=neutral; spf=pass (client-ip=2607:f8b0:4864:20::1049; helo=mail-pj1-x1049.google.com; envelope-from=3aqe9zwykdeg2okxtmqyyqvo.mywvsx47zzm-no5vs232.y9vkl2.y1q@flex--seanjc.bounces.google.com; receiver=lists.ozlabs.org) smtp.mailfrom=flex--seanjc.bounces.google.com Authentication-Results: lists.ozlabs.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20230601 header.b=doQjWl2/; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=flex--seanjc.bounces.google.com (client-ip=2607:f8b0:4864:20::1049; helo=mail-pj1-x1049.google.com; envelope-from=3aqe9zwykdeg2okxtmqyyqvo.mywvsx47zzm-no5vs232.y9vkl2.y1q@flex--seanjc.bounces.google.com; receiver=lists.ozlabs.org) Received: from mail-pj1-x1049.google.com (mail-pj1-x1049.google.com [IPv6:2607:f8b0:4864:20::1049]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4Z1yKy5tgJz2yRd for ; Tue, 25 Feb 2025 10:55:50 +1100 (AEDT) Received: by mail-pj1-x1049.google.com with SMTP id 98e67ed59e1d1-2fc2b258e82so10783367a91.0 for ; Mon, 24 Feb 2025 15:55:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1740441345; x=1741046145; darn=lists.ozlabs.org; h=cc:to:from:subject:message-id:mime-version:date:reply-to:from:to:cc :subject:date:message-id:reply-to; bh=G4yv5E3Df19Io1ieaPGo0Ai9BtJpUzyQSBdyF3aMs18=; b=doQjWl2/VGNUqD/T21Oa06j+DG6tX6y4LvKxfuyBhbCuEZrbvzmgvgu9Vy+ZcnfWoR +qP/xiHpz+gtXA/vtlY/yImkVJR4afbsAxHTBJzkH2YvZNTYh26XiSrgMtu+Nnr4YL+x F63FmOiiIsHpt4hFR3/B7QKB2mgLWLOHNsbnzR/ci7irkEZPP5h8amMP3UpPEkvxl66k DAhZQXEhk0RzjZ2T8lT7i0diqSpJ4JZcgp1OFfjylh4Vy9NxxfE3MNbocvrfAG5UAEUE S+IXrUELuQwk7wnTzek33jnAomWwxd2+lbNtDWCCxT4N1NAT5Bs2692VFdd4vIiMSrmV LqTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740441345; x=1741046145; h=cc:to:from:subject:message-id:mime-version:date:reply-to :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=G4yv5E3Df19Io1ieaPGo0Ai9BtJpUzyQSBdyF3aMs18=; b=dCAdcCNGaaQXlbhFmR5en69iXb1SPUEoPvA9GCUxXuNJp5rI58UN3VEPCuvJhsp0dw caNA21E+RgxfOPXhkBudn+mNla/4lgPFH2jMRha2BWCnNv5AIgQIgKTXIW0aaIRDg/li zdtHci+wGa0epLJDDRfQyTKGuKdlPJK3ks2/e8PMjvYlCFtpWdr04w21pQerDZFUlUkT 0smK6jViJ78hQovxrGcTZLcpJhDDx6jcB5diCE1BcQvuQFGr/hx9xkZIcVjoXYu2K5g4 uU36LGqMgSFll0t5ydD2Y3txQRVrIvqJp0Js2Jcl877ULXkjkJrkXviWIG7B7jKQQV93 SHrQ== X-Forwarded-Encrypted: i=1; AJvYcCXPjIO+1B6SzmfLGTGf3AoCabO1AABjLwFF8eyTlYJmzLLfhuvUYBlUfoVf8453qbx9G6VtJI16ms39pMg=@lists.ozlabs.org X-Gm-Message-State: AOJu0Ywxg9u0tNjd0yO7LmL48U0VtuZH4MaMfG0LfkHLE38GetYUaGR0 JvlcdVYsPc/rBl/cMlo6QRw7kJigBY1kQ4Oqr3btlc03RFExQ2faodf9I2emWaqIpL11WodkF1x 4Qw== X-Google-Smtp-Source: AGHT+IF6C3DtzvfIloHEkiuLmfsYJNF5ywoI3G+Dg7xZ6ws28dsFaD6h16rXeHiPC/2N2WbxQdNYNz9BqGc= X-Received: from pjbsd8.prod.google.com ([2002:a17:90b:5148:b0:2ea:5613:4d5d]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:5292:b0:2ee:7c65:ae8e with SMTP id 98e67ed59e1d1-2fce77a638fmr26853663a91.11.1740441345356; Mon, 24 Feb 2025 15:55:45 -0800 (PST) Reply-To: Sean Christopherson Date: Mon, 24 Feb 2025 15:55:35 -0800 X-Mailing-List: linuxppc-dev@lists.ozlabs.org List-Id: List-Help: List-Owner: List-Post: List-Archive: , List-Subscribe: , , List-Unsubscribe: Mime-Version: 1.0 X-Mailer: git-send-email 2.48.1.658.g4767266eb4-goog Message-ID: <20250224235542.2562848-1-seanjc@google.com> Subject: [PATCH 0/7] KVM: x86: nVMX IRQ fix and VM teardown cleanups From: Sean Christopherson To: Marc Zyngier , Oliver Upton , Tianrui Zhao , Bibo Mao , Huacai Chen , Madhavan Srinivasan , Anup Patel , Paul Walmsley , Palmer Dabbelt , Albert Ou , Christian Borntraeger , Janosch Frank , Claudio Imbrenda , Sean Christopherson , Paolo Bonzini Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, kvm@vger.kernel.org, loongarch@lists.linux.dev, linux-mips@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Aaron Lewis , Jim Mattson , Yan Zhao , Rick P Edgecombe , Kai Huang , Isaku Yamahata Content-Type: text/plain; charset="UTF-8" This was _supposed_ to be a tiny one-off patch to fix a nVMX bug where KVM fails to detect that, after nested VM-Exit, L1 has a pending IRQ (or NMI). But because x86's nested teardown flows are garbage (KVM simply forces a nested VM-Exit to put the vCPU back into L1), that simple fix snowballed. The immediate issue is that checking for a pending interrupt accesses the legacy PIC, and x86's kvm_arch_destroy_vm() currently frees the PIC before destroying vCPUs, i.e. checking for IRQs during the forced nested VM-Exit results in a NULL pointer deref (or use-after-free if KVM didn't nullify the PIC pointer). That's patch 1. Patch 2 is the original nVMX fix. The remaining patches attempt to bring a bit of sanity to x86's VM teardown code, which has accumulated a lot of cruft over the years. E.g. KVM currently unloads each vCPU's MMUs in a separate operation from destroying vCPUs, all because when guest SMP support was added, KVM had a kludgy MMU teardown flow that broken when a VM had more than one 1 vCPU. And that oddity lived on, for 18 years... Sean Christopherson (7): KVM: x86: Free vCPUs before freeing VM state KVM: nVMX: Process events on nested VM-Exit if injectable IRQ or NMI is pending KVM: Assert that a destroyed/freed vCPU is no longer visible KVM: x86: Don't load/put vCPU when unloading its MMU during teardown KVM: x86: Unload MMUs during vCPU destruction, not before KVM: x86: Fold guts of kvm_arch_sync_events() into kvm_arch_pre_destroy_vm() KVM: Drop kvm_arch_sync_events() now that all implementations are nops arch/arm64/include/asm/kvm_host.h | 2 -- arch/loongarch/include/asm/kvm_host.h | 1 - arch/mips/include/asm/kvm_host.h | 1 - arch/powerpc/include/asm/kvm_host.h | 1 - arch/riscv/include/asm/kvm_host.h | 2 -- arch/s390/include/asm/kvm_host.h | 1 - arch/x86/kvm/vmx/nested.c | 11 +++++++ arch/x86/kvm/x86.c | 42 ++++++++++----------------- include/linux/kvm_host.h | 1 - virt/kvm/kvm_main.c | 9 +++++- 10 files changed, 34 insertions(+), 37 deletions(-) base-commit: fed48e2967f402f561d80075a20c5c9e16866e53 -- 2.48.1.658.g4767266eb4-goog