From nobody Mon May 25 20:31:50 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linux.alibaba.com ARC-Seal: i=1; a=rsa-sha256; t=1778294821; cv=none; d=zohomail.com; s=zohoarc; b=j7FmX2uN2fcYXYn+gb1UWFRksfxhX1ELYG0B4h++J0CAJqKcwj4ZzyVHKpq1xJAiFXw0JQfXw80CHJeABWHBMju8GEHAqacxaEyk3ILCScXdnMbKDRUlVabs27pbbSRYQOzMXx85N0KePKX0f3KjJPF2EqFcA5O4OtdAQMoAZPY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1778294821; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=6sbYWlJN+z4hkTQrsoN7IxSNEeSI4CJC1PosPUP5cnY=; b=axTssClmp5wrZcoXjID4wR/gDpZKl3TFbrjB1Kp8PZs7AuX2UDY/Htx7aLeY8QV9dSnsCVIGOqzpD91F0TDKwgOdv8Tiq6I7YaA9YAiESSU5Jn4ZMLIvY8H8Uy9gBJ9seyt2kt9yAxF5ltUAHV1DoknpPQOH6MvB8YDoWvqzJVY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1778294821742221.33086688316837; Fri, 8 May 2026 19:47:01 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wLXi0-0007tF-Dg; Fri, 08 May 2026 22:46:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wLXhj-0007sT-8O for qemu-devel@nongnu.org; Fri, 08 May 2026 22:46:16 -0400 Received: from out30-112.freemail.mail.aliyun.com ([115.124.30.112]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wLXhg-0003BE-LX for qemu-devel@nongnu.org; Fri, 08 May 2026 22:46:10 -0400 Received: from localhost(mailfrom:guobin@linux.alibaba.com fp:SMTPD_---0X2ZCFg-_1778294749 cluster:ay36) by smtp.aliyun-inc.com; Sat, 09 May 2026 10:45:54 +0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1778294755; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=6sbYWlJN+z4hkTQrsoN7IxSNEeSI4CJC1PosPUP5cnY=; b=ca/Dp5AaFaqk+Hhadttqx0NBoSLBGzJXAoCUOC76sSZTOE0R7JItXoZJq+0rDecG4zVpLxVvRoECV189BxUQLieUDt11AvIwnswd3/2i8xaaGCt8HI/YPgjn3ENhXUoqIGlUdRGDiEVkNk/RASVVjYTNCsRLyfMD8bSWsZ0+2Rc= X-Alimail-AntiSpam: AC=PASS; BC=-1|-1; BR=01201311R161e4; CH=green; DM=||false|; DS=||; FP=0|-1|-1|-1|0|-1|-1|-1; HT=maildocker-contentspam033037026112; MF=guobin@linux.alibaba.com; NM=1; PH=DS; RN=3; SR=0; TI=SMTPD_---0X2ZCFg-_1778294749; From: Bin Guo To: qemu-devel@nongnu.org Cc: pbonzini@redhat.com, kvm@vger.kernel.org Subject: [PATCH 1/2] kvm: remove redundant check in kvm_close Date: Sat, 9 May 2026 10:45:38 +0800 Message-ID: <20260509024539.90998-2-guobin@linux.alibaba.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260509024539.90998-1-guobin@linux.alibaba.com> References: <20260509024539.90998-1-guobin@linux.alibaba.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=115.124.30.112; envelope-from=guobin@linux.alibaba.com; helo=out30-112.freemail.mail.aliyun.com X-Spam_score_int: -174 X-Spam_score: -17.5 X-Spam_bar: ----------------- X-Spam_report: (-17.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, ENV_AND_HDR_SPF_MATCH=-0.5, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, UNPARSEABLE_RELAY=0.001, USER_IN_DEF_DKIM_WL=-7.5, USER_IN_DEF_SPF_WL=-7.5 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linux.alibaba.com) X-ZM-MESSAGEID: 1778294823763158500 Content-Type: text/plain; charset="utf-8" In kvm_close(), the condition `!kvm_state || kvm_state->fd =3D=3D -1` is checked at the function entry, causing an early return if either is true. Later in the function, the same condition is redundantly checked again before closing vmfd and fd. Remove the redundant second check since it can never be true at that point. Signed-off-by: Bin Guo --- accel/kvm/kvm-all.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index 92af42503b..70bc2c86a2 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -769,12 +769,11 @@ void kvm_close(void) cpu->kvm_vcpu_stats_fd =3D -1; } =20 - if (kvm_state && kvm_state->fd !=3D -1) { - close(kvm_state->vmfd); - kvm_state->vmfd =3D -1; - close(kvm_state->fd); - kvm_state->fd =3D -1; - } + close(kvm_state->vmfd); + kvm_state->vmfd =3D -1; + close(kvm_state->fd); + kvm_state->fd =3D -1; + kvm_state =3D NULL; } =20 --=20 2.50.1 (Apple Git-155) From nobody Mon May 25 20:31:50 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linux.alibaba.com ARC-Seal: i=1; a=rsa-sha256; t=1778294822; cv=none; d=zohomail.com; s=zohoarc; b=QjA4sgrfEKmUkCZe6qE6xOGhatuCwpzfRNw6Q3+w+U86u5ISmlxB5a4cTq5nOXMnHe12bLOGUKg6+l/N+dwTi2GJZdpl87LdUsKAoBQ+yDpIOEO40WgT7G7rOW/wwQbR58uZHtjQdoqYY7YgV1A12kAqztgq6Ck3954B4VuDcTY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1778294822; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=bOHocsDjBbGwePHYMHf0XP/MmULd8FxzUFtMETBjpTg=; b=X8DWh1hnIBIugjfwKKBixe9Wy7CAwOp5ZwQYhFEtj5xLstDLzB1KxPsI4QX30ZWsze3nqQ/p3XGVtGD18cg3cZC7ZTp2G+LLQSZAXNKksryrtO6UWxjRUluUqTH/KhgQcRCbgt5zWczx9lT7fBRSBO2nfEiN16YD5UP5Pm6DCOI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1778294822402492.9350328101391; Fri, 8 May 2026 19:47:02 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wLXi6-0007ti-9F; Fri, 08 May 2026 22:46:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wLXhj-0007sW-R8 for qemu-devel@nongnu.org; Fri, 08 May 2026 22:46:16 -0400 Received: from out30-97.freemail.mail.aliyun.com ([115.124.30.97]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wLXhg-0003Cp-T7 for qemu-devel@nongnu.org; Fri, 08 May 2026 22:46:11 -0400 Received: from localhost(mailfrom:guobin@linux.alibaba.com fp:SMTPD_---0X2Z4CJH_1778294755 cluster:ay36) by smtp.aliyun-inc.com; Sat, 09 May 2026 10:46:01 +0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1778294761; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=bOHocsDjBbGwePHYMHf0XP/MmULd8FxzUFtMETBjpTg=; b=mhlyFTt7mQJTflIDK6VsjxnLBHECPgoegRyHOayuazip2kIf2i01YWdl0gByYce3xJSdgbRigkPwCdNGXVPBJQxR2YGNsZWr68kNQqHhTXZGpeMBrF9pSKywddCB0wxivLblgzWFS7Ce4lf/NwVEREIvpBejhPAruqr0JEoZn/4= X-Alimail-AntiSpam: AC=PASS; BC=-1|-1; BR=01201311R101e4; CH=green; DM=||false|; DS=||; FP=0|-1|-1|-1|0|-1|-1|-1; HT=maildocker-contentspam033037033178; MF=guobin@linux.alibaba.com; NM=1; PH=DS; RN=3; SR=0; TI=SMTPD_---0X2Z4CJH_1778294755; From: Bin Guo To: qemu-devel@nongnu.org Cc: pbonzini@redhat.com, kvm@vger.kernel.org Subject: [PATCH 2/2] kvm: fix kvm_irqchip_release_virq loop after swap-remove Date: Sat, 9 May 2026 10:45:39 +0800 Message-ID: <20260509024539.90998-3-guobin@linux.alibaba.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260509024539.90998-1-guobin@linux.alibaba.com> References: <20260509024539.90998-1-guobin@linux.alibaba.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=115.124.30.97; envelope-from=guobin@linux.alibaba.com; helo=out30-97.freemail.mail.aliyun.com X-Spam_score_int: -174 X-Spam_score: -17.5 X-Spam_bar: ----------------- X-Spam_report: (-17.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, ENV_AND_HDR_SPF_MATCH=-0.5, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, UNPARSEABLE_RELAY=0.001, USER_IN_DEF_DKIM_WL=-7.5, USER_IN_DEF_SPF_WL=-7.5 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linux.alibaba.com) X-ZM-MESSAGEID: 1778294825240154100 Content-Type: text/plain; charset="utf-8" In kvm_irqchip_release_virq(), when an entry matching the target GSI is found, the code removes it by swapping in the last entry: s->irq_routes->nr--; *e =3D s->irq_routes->entries[s->irq_routes->nr]; However, the loop then increments `i` unconditionally, which means the newly-swapped entry at position `i` is never re-checked. If that entry also has `gsi =3D=3D virq`, it will be skipped and left in the routing table. Fix this by decrementing `i` after the swap, so the same index is re-examined in the next iteration. Signed-off-by: Bin Guo --- accel/kvm/kvm-all.c | 1 + 1 file changed, 1 insertion(+) diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index 70bc2c86a2..3c5b62c97e 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -2278,6 +2278,7 @@ void kvm_irqchip_release_virq(KVMState *s, int virq) if (e->gsi =3D=3D virq) { s->irq_routes->nr--; *e =3D s->irq_routes->entries[s->irq_routes->nr]; + i--; } } clear_gsi(s, virq); --=20 2.50.1 (Apple Git-155)