From nobody Wed Nov 27 12:34:49 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1699267247; cv=none; d=zohomail.com; s=zohoarc; b=ZVbTZ5/Iqjjh3UJP4ffVzghJhqNG+arbBZ9dfoDpSQTmpgng3Am5OEicaL3hTmYMacPIlkwPOkEBtSlafXethwtHjZBLdhpQb3luSFReIUbvAEp3CgVB7nDKWm6hT/9kbTCjWcdkTv8PutqYx31PV8fj3Td73PH7vFywnnInu6E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1699267247; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=8y74Lolq5T0LDv+PFoxvm3kC9HGA3LQOfihqJijE5SE=; b=lHxhjKn/u7GJBzK68MWkRHq/WBM3PXZuk0JCirEpeqK6Pf5NIkMszmo41btrq25k5KbZ+VJZSKbtHvo/xGsMuUyRgB75JjZAyi05MpmaEguVzqitpTrIZs6hxjgpbsqN3lEb5Dwh/r2gz8P333GEI2WPfxJ/QqujfkjPB+kFmOE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1699267247041824.0751188959108; Mon, 6 Nov 2023 02:40:47 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.627883.978805 (Exim 4.92) (envelope-from ) id 1qzx1p-0002xW-78; Mon, 06 Nov 2023 10:40:21 +0000 Received: by outflank-mailman (output) from mailman id 627883.978805; Mon, 06 Nov 2023 10:40:21 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qzx1p-0002xM-3R; Mon, 06 Nov 2023 10:40:21 +0000 Received: by outflank-mailman (input) for mailman id 627883; Mon, 06 Nov 2023 10:40:19 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qzx1n-00010s-Da for xen-devel@lists.xenproject.org; Mon, 06 Nov 2023 10:40:19 +0000 Received: from desiato.infradead.org (desiato.infradead.org [2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id dfb94609-7c90-11ee-9b0e-b553b5be7939; Mon, 06 Nov 2023 11:40:16 +0100 (CET) Received: from [2001:8b0:10b:1::ebe] (helo=i7.infradead.org) by desiato.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1qzx1R-00ARzv-0U; Mon, 06 Nov 2023 10:39:57 +0000 Received: from dwoodhou by i7.infradead.org with local (Exim 4.96.2 #2 (Red Hat Linux)) id 1qzx1P-000qG5-39; Mon, 06 Nov 2023 10:39:55 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list X-Inumbo-ID: dfb94609-7c90-11ee-9b0e-b553b5be7939 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description; bh=8y74Lolq5T0LDv+PFoxvm3kC9HGA3LQOfihqJijE5SE=; b=FSFn3mS59GJdfRIIZe12qeoM/o IUERkSlLtCLvpnlYwLH6az4jVaFuBqFZkAJYtUxAo0HgeY2vOdA36i6m6Xj4q+yrSvHLLL2j8Pw/W NKOSTnOExI8mA2isNjoZuF5apu2cXNSLP8kzai1deGgZD2IZD/Hrz3+3NwSZR3IeJob91PC3k4AWQ B0BKwsh538eW76PLt8gjOJLhI1itgLev1mjgpKRRzza9kuDHtICG5LUlsQ3jRZCw1cSrtTAMPmoiY Hv6JfsUoHvVQIlRmEQ3q/UaaKJ/SA99AcAd9/0uipDjNbLGPP+viqyvqV/EeKhZ8uTATdsoiArTSz 7O0eEqyw==; From: David Woodhouse To: qemu-devel@nongnu.org, qemu-stable@nongnu.org Cc: Stefano Stabellini , Anthony Perard , Paul Durrant , Kevin Wolf , Hanna Reitz , "Michael S. Tsirkin" , Marcel Apfelbaum , Paolo Bonzini , Richard Henderson , Eduardo Habkost , Marcelo Tosatti , xen-devel@lists.xenproject.org, qemu-block@nongnu.org, kvm@vger.kernel.org Subject: [PULL 3/7] hw/xen: select kernel mode for per-vCPU event channel upcall vector Date: Mon, 6 Nov 2023 10:39:51 +0000 Message-ID: <20231106103955.200867-4-dwmw2@infradead.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231106103955.200867-1-dwmw2@infradead.org> References: <20231106103955.200867-1-dwmw2@infradead.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: David Woodhouse X-SRS-Rewrite: SMTP reverse-path rewritten from by desiato.infradead.org. See http://www.infradead.org/rpr.html X-ZohoMail-DKIM: pass (identity @infradead.org) X-ZM-MESSAGEID: 1699267248659100019 Content-Type: text/plain; charset="utf-8" From: David Woodhouse A guest which has configured the per-vCPU upcall vector may set the HVM_PARAM_CALLBACK_IRQ param to fairly much anything other than zero. For example, Linux v6.0+ after commit b1c3497e604 ("x86/xen: Add support for HVMOP_set_evtchn_upcall_vector") will just do this after setting the vector: /* Trick toolstack to think we are enlightened. */ if (!cpu) rc =3D xen_set_callback_via(1); That's explicitly setting the delivery to GSI#1, but it's supposed to be overridden by the per-vCPU vector setting. This mostly works in Qemu *except* for the logic to enable the in-kernel handling of event channels, which falsely determines that the kernel cannot accelerate GSI delivery in this case. Add a kvm_xen_has_vcpu_callback_vector() to report whether vCPU#0 has the vector set, and use that in xen_evtchn_set_callback_param() to enable the kernel acceleration features even when the param *appears* to be set to target a GSI. Preserve the Xen behaviour that when HVM_PARAM_CALLBACK_IRQ is set to *zero* the event channel delivery is disabled completely. (Which is what that bizarre guest behaviour is working round in the first place.) Cc: qemu-stable@nongnu.org Fixes: 91cce756179 ("hw/xen: Add xen_evtchn device for event channel emulat= ion") Signed-off-by: David Woodhouse Reviewed-by: Paul Durrant --- hw/i386/kvm/xen_evtchn.c | 6 ++++++ include/sysemu/kvm_xen.h | 1 + target/i386/kvm/xen-emu.c | 7 +++++++ 3 files changed, 14 insertions(+) diff --git a/hw/i386/kvm/xen_evtchn.c b/hw/i386/kvm/xen_evtchn.c index a731738411..3d6f4b4a0a 100644 --- a/hw/i386/kvm/xen_evtchn.c +++ b/hw/i386/kvm/xen_evtchn.c @@ -490,6 +490,12 @@ int xen_evtchn_set_callback_param(uint64_t param) break; } =20 + /* If the guest has set a per-vCPU callback vector, prefer that. */ + if (gsi && kvm_xen_has_vcpu_callback_vector()) { + in_kernel =3D kvm_xen_has_cap(EVTCHN_SEND); + gsi =3D 0; + } + if (!ret) { /* If vector delivery was turned *off* then tell the kernel */ if ((s->callback_param >> CALLBACK_VIA_TYPE_SHIFT) =3D=3D diff --git a/include/sysemu/kvm_xen.h b/include/sysemu/kvm_xen.h index 595abfbe40..961c702c4e 100644 --- a/include/sysemu/kvm_xen.h +++ b/include/sysemu/kvm_xen.h @@ -22,6 +22,7 @@ int kvm_xen_soft_reset(void); uint32_t kvm_xen_get_caps(void); void *kvm_xen_get_vcpu_info_hva(uint32_t vcpu_id); +bool kvm_xen_has_vcpu_callback_vector(void); void kvm_xen_inject_vcpu_callback_vector(uint32_t vcpu_id, int type); void kvm_xen_set_callback_asserted(void); int kvm_xen_set_vcpu_virq(uint32_t vcpu_id, uint16_t virq, uint16_t port); diff --git a/target/i386/kvm/xen-emu.c b/target/i386/kvm/xen-emu.c index 7c504d9fa4..75b2c557b9 100644 --- a/target/i386/kvm/xen-emu.c +++ b/target/i386/kvm/xen-emu.c @@ -424,6 +424,13 @@ void kvm_xen_set_callback_asserted(void) } } =20 +bool kvm_xen_has_vcpu_callback_vector(void) +{ + CPUState *cs =3D qemu_get_cpu(0); + + return cs && !!X86_CPU(cs)->env.xen_vcpu_callback_vector; +} + void kvm_xen_inject_vcpu_callback_vector(uint32_t vcpu_id, int type) { CPUState *cs =3D qemu_get_cpu(vcpu_id); --=20 2.41.0