From nobody Tue Feb 10 12:14:04 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1670261630474869.3916859006036; Mon, 5 Dec 2022 09:33:50 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p2FKd-00080n-Cv; Mon, 05 Dec 2022 12:32:43 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p2FKP-0007rg-7W for qemu-devel@nongnu.org; Mon, 05 Dec 2022 12:32:30 -0500 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p2FJx-0007PI-Ny for qemu-devel@nongnu.org; Mon, 05 Dec 2022 12:32:28 -0500 Received: from i7.infradead.org ([2001:8b0:10b:1:21e:67ff:fecb:7a92]) by desiato.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1p2FJo-007fzL-S0; Mon, 05 Dec 2022 17:31:52 +0000 Received: from dwoodhou by i7.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1p2FJo-002YKH-K5; Mon, 05 Dec 2022 17:31:52 +0000 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=pQy5uzYvVKgQgnyYM+49fV0wFOa4mD8rLIxjgXtTRWs=; b=SuFL33Ke4OOuEW8fvhuV9VhqHV /97t0CoBHDpjYSs9j3weflWpPxhrQhddkSOt8iGVDkiFzQyrrAyYtE1wqIceEJUgj5p+vpik6YYNd t+FQN57LugFZryyZ3KsNge8vc6OZsCVKVR7QXXkm1uCnwvAH5dC7xOxA3otmdtR8qg5m+ZQOKhqyS SwBl+VtxczHj6jsnFXTX8GF5Z7YtpO4I/UAymykYyGrXRHDfLzcnHAs8RRNBSQVxUAkQCu8m8An6r zQ1B/aM6z60g0egGdOGifEPYXu5JffGMuKNSxfQBY/M+flJ0F+Gg5YKKIcat6YJT+gpLjwfEA5dNt BGDaLbvw==; From: David Woodhouse To: qemu-devel@nongnu.org Cc: Paolo Bonzini , Paul Durrant , Joao Martins , Ankur Arora Subject: [RFC PATCH 10/21] i386/xen: handle guest hypercalls Date: Mon, 5 Dec 2022 17:31:26 +0000 Message-Id: <20221205173137.607044-11-dwmw2@infradead.org> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20221205173137.607044-1-dwmw2@infradead.org> References: <20221205173137.607044-1-dwmw2@infradead.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-SRS-Rewrite: SMTP reverse-path rewritten from by desiato.infradead.org. See http://www.infradead.org/rpr.html 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=lists.gnu.org; Received-SPF: none client-ip=2001:8b0:10b:1:d65d:64ff:fe57:4e05; envelope-from=BATV+0f5700dbc1736e95d806+7043+infradead.org+dwmw2@desiato.srs.infradead.org; helo=desiato.infradead.org X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_NONE=0.001 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: 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: fail (Header signature does not verify) X-ZM-MESSAGEID: 1670261631530100002 Content-Type: text/plain; charset="utf-8" From: Joao Martins This means handling the new exit reason for Xen but still crashing on purpose. As we implement each of the hypercalls we will then return the right return code. Signed-off-by: Joao Martins [dwmw2: Add CPL to hypercall tracing, disallow hypercalls from CPL > 0] Signed-off-by: David Woodhouse --- target/i386/kvm/kvm.c | 5 +++++ target/i386/trace-events | 3 +++ target/i386/xen.c | 45 ++++++++++++++++++++++++++++++++++++++++ target/i386/xen.h | 1 + 4 files changed, 54 insertions(+) diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c index 4b21d03250..6396d11f1e 100644 --- a/target/i386/kvm/kvm.c +++ b/target/i386/kvm/kvm.c @@ -5468,6 +5468,11 @@ int kvm_arch_handle_exit(CPUState *cs, struct kvm_ru= n *run) assert(run->msr.reason =3D=3D KVM_MSR_EXIT_REASON_FILTER); ret =3D kvm_handle_wrmsr(cpu, run); break; +#ifdef CONFIG_XEN + case KVM_EXIT_XEN: + ret =3D kvm_xen_handle_exit(cpu, &run->xen); + break; +#endif default: fprintf(stderr, "KVM: unknown exit reason %d\n", run->exit_reason); ret =3D -1; diff --git a/target/i386/trace-events b/target/i386/trace-events index 2cd8726eeb..3fb9ee3add 100644 --- a/target/i386/trace-events +++ b/target/i386/trace-events @@ -11,3 +11,6 @@ kvm_sev_launch_measurement(const char *value) "data %s" kvm_sev_launch_finish(void) "" kvm_sev_launch_secret(uint64_t hpa, uint64_t hva, uint64_t secret, int len= ) "hpa 0x%" PRIx64 " hva 0x%" PRIx64 " data 0x%" PRIx64 " len %d" kvm_sev_attestation_report(const char *mnonce, const char *data) "mnonce %= s data %s" + +# target/i386/xen.c +kvm_xen_hypercall(int cpu, uint8_t cpl, uint64_t input, uint64_t a0, uint6= 4_t a1, uint64_t a2, uint64_t ret) "xen_hypercall: cpu %d cpl %d input %" P= RIu64 " a0 0x%" PRIx64 " a1 0x%" PRIx64 " a2 0x%" PRIx64" ret 0x%" PRIu64 diff --git a/target/i386/xen.c b/target/i386/xen.c index bc183dce4e..d7e942289c 100644 --- a/target/i386/xen.c +++ b/target/i386/xen.c @@ -12,6 +12,17 @@ #include "qemu/osdep.h" #include "kvm/kvm_i386.h" #include "xen.h" +#include "trace.h" + +/* + * Unhandled hypercalls error: + * + * -1 crash and dump registers + * 0 no abort and guest handles -ENOSYS (default) + */ +#ifndef HCALL_ERR +#define HCALL_ERR 0 +#endif =20 int kvm_xen_init(KVMState *s, uint32_t xen_version) { @@ -47,3 +58,37 @@ int kvm_xen_init(KVMState *s, uint32_t xen_version) =20 return 0; } + +static int __kvm_xen_handle_exit(X86CPU *cpu, struct kvm_xen_exit *exit) +{ + uint16_t code =3D exit->u.hcall.input; + + if (exit->u.hcall.cpl > 0) { + exit->u.hcall.result =3D -EPERM; + return HCALL_ERR; + } + + switch (code) { + default: + exit->u.hcall.result =3D -ENOSYS; + return HCALL_ERR; + } +} + +int kvm_xen_handle_exit(X86CPU *cpu, struct kvm_xen_exit *exit) +{ + int ret =3D HCALL_ERR; + + switch (exit->type) { + case KVM_EXIT_XEN_HCALL: { + ret =3D __kvm_xen_handle_exit(cpu, exit); + trace_kvm_xen_hypercall(CPU(cpu)->cpu_index, exit->u.hcall.cpl, + exit->u.hcall.input, exit->u.hcall.params[0], + exit->u.hcall.params[1], exit->u.hcall.params[2= ], + exit->u.hcall.result); + return ret; + } + default: + return ret; + } +} diff --git a/target/i386/xen.h b/target/i386/xen.h index d4903ecfa1..3537415d31 100644 --- a/target/i386/xen.h +++ b/target/i386/xen.h @@ -23,5 +23,6 @@ #define XEN_VERSION(maj, min) ((maj) << 16 | (min)) =20 int kvm_xen_init(KVMState *s, uint32_t xen_version); +int kvm_xen_handle_exit(X86CPU *cpu, struct kvm_xen_exit *exit); =20 #endif /* QEMU_I386_XEN_H */ --=20 2.35.3