From patchwork Thu Nov 30 04:16:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 1869965 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=tpfZjQF7; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ventanamicro.com header.i=@ventanamicro.com header.a=rsa-sha256 header.s=google header.b=C/7fB3ZY; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=kvm-riscv-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=patchwork.ozlabs.org) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4SgjZQ2kx3z1ySd for ; Thu, 30 Nov 2023 15:16:59 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=jfpe9/xqBc4YJR8xSKZN2JD2o87gDk3eJceGdtR3nNw=; b=tpfZjQF7id03xf kucSVCdSMdGNZKE5CLhBXwC/ncSX8VMHJG4CPX8FttMtLk08XNQU4OmYRI3umuJMF8dS/esaJrP3w bhp0Ge1ySrX423SW5ALIuDBApenIL17gBu0q3vvRJ4Y8we+VR4u5W56xU4uTX4Z8Mo4HTe/LPvxur 8rOs0LqprbddWfL+14woXInOZv105ft4E03BvsO9phJqfhiKHcEwEUmOvmY4eh51FpQohlndmW55A rAq+2nbTJz5ZGVD9AoY8DFR4dL6PZDPOcWx40WrSX+0Gm2Z4i/Ll9sSTzCYpw/InQmRKySh8EFgVT KsAC4Z68Ivl+cAqiccNQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1r8YTu-009te1-2L; Thu, 30 Nov 2023 04:16:54 +0000 Received: from mail-pf1-x435.google.com ([2607:f8b0:4864:20::435]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1r8YTp-009tdW-1q for kvm-riscv@lists.infradead.org; Thu, 30 Nov 2023 04:16:52 +0000 Received: by mail-pf1-x435.google.com with SMTP id d2e1a72fcca58-6cb55001124so1338524b3a.0 for ; Wed, 29 Nov 2023 20:16:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1701317807; x=1701922607; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=y6aGoq4wfRBMckJevg1vwOCIApJGZHlwnU+/MjsZGfY=; b=C/7fB3ZY5eg/2k2Xo9PDVGXcBExk4jbJtGWFCNpmyiyXWdWKG17Oq0/Sr7kDHJRTow B4o40KkQFhejOH865fu/fIOEulki3FOXTggXr0x1/x6nId7c8qpenEvu9OYLqLZxL7gf lT7vLH6Ss9J75sdmVuWkUcye2gXVS4tkiPHqPqhB7uvlL8YmlVdIb82o+IMbuYZRumDr L9SRd59IErbQBckCgdvAnV0wNid2nq0Y6THOJ58EQmcV85YV/QbD2WBytIJhoASIW2+B iuGHfivBPQ5k3ke+PrS6oIzej4aKV3M0tLfx+AlFKapnocsd533iHHwfmMHpQL+zPEpR 8n5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701317807; x=1701922607; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=y6aGoq4wfRBMckJevg1vwOCIApJGZHlwnU+/MjsZGfY=; b=F4so2ExwIN7CHVR+dXuvrl1GqCxqhWAHD35I44pAqf2coKYsC/sdWrVMqY3MhS1zrW pqTUh/kciHcDycUJ4QCJ0ZWIcsK5FTiRWQvXjNqn+zUv/1RcbiBkwKJuZBIsnuRu3vcu 0q/umwXJRwv/ZurRmd+Fo8mYnXSAtelGl6wGdRFL5xFEWp876HQEFsZr6fd/RJdsekAJ ucmNDQEnQHqjscG/s2MeLqBbSfZAV+JaT4Drg3+ViQjFmDkafr3lYRANzbuo7ssw/AQv rd6mjbhBgewsH5rfXEfUYnffchNRaJ0MsalqGhVAsr5IlTO9NsXlGad9HzFXDOFmmdVk 5ZPg== X-Gm-Message-State: AOJu0YwlHzd1a9ffMf5Cj2XRDXqTt3Ikodn28mXhYsuebAKXvZbjKVsl D6VbBfkGKRpzq7shYsi3HAvGgA== X-Google-Smtp-Source: AGHT+IHSQ2ILuSbOQgKkF5qVcwSBpaLZePV7ynQrDgiLrrdQHNoOu22QTGvs7K2QqdZEWhsxgu7QFw== X-Received: by 2002:a05:6a20:7d88:b0:18c:3199:7174 with SMTP id v8-20020a056a207d8800b0018c31997174mr27137856pzj.19.1701317806545; Wed, 29 Nov 2023 20:16:46 -0800 (PST) Received: from anup-ubuntu-vm.localdomain ([171.76.83.234]) by smtp.gmail.com with ESMTPSA id q1-20020a656841000000b00577d53c50f7sm196001pgt.75.2023.11.29.20.16.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Nov 2023 20:16:46 -0800 (PST) From: Anup Patel To: Will Deacon , julien.thierry.kdev@gmail.com, maz@kernel.org Cc: Paolo Bonzini , Atish Patra , Andrew Jones , Anup Patel , kvm@vger.kernel.org, kvm-riscv@lists.infradead.org, Anup Patel Subject: [kvmtool PATCH] riscv: Fix guest poweroff when using PLIC emulation Date: Thu, 30 Nov 2023 09:46:33 +0530 Message-Id: <20231130041633.78725-1-apatel@ventanamicro.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231129_201649_618083_AE0FCA6E X-CRM114-Status: GOOD ( 13.17 ) X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: Recently due to commit 74af1456dfa0, the virtio device emulation in KVMTOOL now calls irq__update_msix_route() upon guest poweroff which results in KVMTOOL crash when Guest uses PLIC emulation in user [...] Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:435 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain X-BeenThere: kvm-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "kvm-riscv" Errors-To: kvm-riscv-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Recently due to commit 74af1456dfa0, the virtio device emulation in KVMTOOL now calls irq__update_msix_route() upon guest poweroff which results in KVMTOOL crash when Guest uses PLIC emulation in user space. This is because irq__update_msix_route() expects the irq_routing table to be available but the KVMTOOL PLIC emulation does not populate any irq_routing entries. Fixes: 74af1456dfa0 ("virtio: Cancel and join threads when exiting devices devices") Signed-off-by: Anup Patel --- riscv/plic.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/riscv/plic.c b/riscv/plic.c index ab7c574..6bd13ac 100644 --- a/riscv/plic.c +++ b/riscv/plic.c @@ -95,6 +95,8 @@ #define REG_SIZE 0x1000000 +#define IRQCHIP_PLIC_NR 0 + struct plic_state; struct plic_context { @@ -500,6 +502,33 @@ static void plic__generate_fdt_node(void *fdt, struct kvm *kvm) free(irq_cells); } +static int plic__irq_routing_init(struct kvm *kvm) +{ + int r; + + /* + * This describes the default routing that the kernel uses without + * any routing explicitly set up via KVM_SET_GSI_ROUTING. So we + * don't need to commit these setting right now. The first actual + * user (MSI routing) will engage these mappings then. + */ + for (next_gsi = 0; next_gsi < MAX_DEVICES; next_gsi++) { + r = irq__allocate_routing_entry(); + if (r) + return r; + + irq_routing->entries[irq_routing->nr++] = + (struct kvm_irq_routing_entry) { + .gsi = next_gsi, + .type = KVM_IRQ_ROUTING_IRQCHIP, + .u.irqchip.irqchip = IRQCHIP_PLIC_NR, + .u.irqchip.pin = next_gsi, + }; + } + + return 0; +} + static int plic__init(struct kvm *kvm) { u32 i; @@ -535,6 +564,9 @@ static int plic__init(struct kvm *kvm) if (ret) return ret; + /* Setup default IRQ routing */ + plic__irq_routing_init(kvm); + plic.ready = true; return 0;