From nobody Sun May 19 00:17:17 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1572945584; cv=none; d=zoho.com; s=zohoarc; b=AQzbMzT+EbLUDEL6dMEdlTajN0O0GlRd4C4xGGeUj3aiu4bmgzP9dPu6yxR14KCs0nwYKt9BfYTwnTH2GoCsSIxug0JpxQTO4qgxbWnHUAJPMkkWwDNxQut1GK8bvEym0SNpwhkgkGfwGq1CtTUmH5wkOGKo46DUJL07MqpsGi8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1572945584; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=HaDh1Lkk5wWvque+0+6n69lAUXEE1vtkeICtVpRKW7U=; b=CzchLM/Ym1JLtEXBG0BokZHnobhhjvw2yqDOqadXNFKrJ0wc/YYCOiaSBlh4pWaycgpRNOQDhLMfVsIFWIa7FrUOxUhH1gCL7SrKNn9tjTYa19gqp3hfOCSeD9bO8ytyfTyEOExikv0cE+xJ62m7gvwcoFy9iE84FDL0MwoWhFs= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.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 1572945584177582.363393079234; Tue, 5 Nov 2019 01:19:44 -0800 (PST) Received: from localhost ([::1]:41900 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iRv02-0004lt-QO for importer@patchew.org; Tue, 05 Nov 2019 04:19:42 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:43170) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iRut0-00055g-34 for qemu-devel@nongnu.org; Tue, 05 Nov 2019 04:12:27 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iRusy-0007p6-Mb for qemu-devel@nongnu.org; Tue, 05 Nov 2019 04:12:25 -0500 Received: from szxga04-in.huawei.com ([45.249.212.190]:2194 helo=huawei.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iRusv-0007kQ-F9; Tue, 05 Nov 2019 04:12:21 -0500 Received: from DGGEMS404-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 3DE9C4B90D39FE19A161; Tue, 5 Nov 2019 17:12:13 +0800 (CST) Received: from linux-OtBuvb.huawei.com (10.175.104.212) by DGGEMS404-HUB.china.huawei.com (10.3.19.204) with Microsoft SMTP Server id 14.3.439.0; Tue, 5 Nov 2019 17:12:02 +0800 From: Heyi Guo To: , Subject: [RFC v2 01/14] update-linux-headers.sh: import linux/arm_sdei.h to standard-headers Date: Tue, 5 Nov 2019 17:10:43 +0800 Message-ID: <20191105091056.9541-2-guoheyi@huawei.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20191105091056.9541-1-guoheyi@huawei.com> References: <20191105091056.9541-1-guoheyi@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.104.212] X-CFilter-Loop: Reflected Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 45.249.212.190 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , Peter Maydell , "Michael S. Tsirkin" , Marc Zyngier , Cornelia Huck , James Morse , Paolo Bonzini , Heyi Guo , wanghaibin.wang@huawei.com, Dave Martin Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" This is to prepare for qemu SDEI emulation. Signed-off-by: Heyi Guo Cc: Peter Maydell Cc: Dave Martin Cc: Marc Zyngier Cc: Mark Rutland Cc: James Morse Cc: "Michael S. Tsirkin" Cc: Cornelia Huck Cc: Paolo Bonzini --- Notes: v2: - Update update-linux-headers.sh first and then import the header file - Import arm_sdei.h to include/standard-headers/linux/ scripts/update-linux-headers.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/update-linux-headers.sh b/scripts/update-linux-headers= .sh index f76d77363b..84d15c18f2 100755 --- a/scripts/update-linux-headers.sh +++ b/scripts/update-linux-headers.sh @@ -191,6 +191,7 @@ for i in "$tmpdir"/include/linux/*virtio*.h \ "$tmpdir/include/linux/pci_regs.h" \ "$tmpdir/include/linux/ethtool.h" "$tmpdir/include/linux/kernel.h= " \ "$tmpdir/include/linux/vhost_types.h" \ + "$tmpdir/include/linux/arm_sdei.h" \ "$tmpdir/include/linux/sysinfo.h"; do cp_portable "$i" "$output/include/standard-headers/linux" done --=20 2.19.1 From nobody Sun May 19 00:17:17 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1572945742; cv=none; d=zoho.com; s=zohoarc; b=Odg6jaccUZc8AgQbHSmNsRnvX2ilYXxr3z6VMm4hrO0nfhZp3dFz6AmRLD23pzUN/2YCSGsLDSms8NRmoQla6qVlaPxOHzslZyZBtV/8Wd9DiW+G0m5aCKYfHihA4TyqVmPkipn7t85FjwZ8vvrpQmhI06P6Tt4cziYY48d9LnM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1572945742; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=wxImGTqOKDCP8fOmSl7CUORgjLvMp2wj8JQl+LWyBkU=; b=Ylw4vUloNYMX3xy9JEzv/a8ESY6yxm7Jf3B/kFL0zDK1fv54ORq7E2dd7KpG4p7RJyyDhz40J87mqY+lfaIn7OjnVN6kApt3kKr9tUv7tASfZCfbDbQKexCIDdWZkAyFOTaTw1Q025BRFf7isUU6WQW7joZ1jzuwytr+NGVw05U= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.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 1572945742235887.3520577498194; Tue, 5 Nov 2019 01:22:22 -0800 (PST) Received: from localhost ([::1]:41932 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iRv2a-00009j-Qe for importer@patchew.org; Tue, 05 Nov 2019 04:22:20 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:43191) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iRut0-00057E-Ry for qemu-devel@nongnu.org; Tue, 05 Nov 2019 04:12:28 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iRusz-0007pY-9j for qemu-devel@nongnu.org; Tue, 05 Nov 2019 04:12:26 -0500 Received: from szxga04-in.huawei.com ([45.249.212.190]:2196 helo=huawei.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iRusv-0007kO-Do; Tue, 05 Nov 2019 04:12:21 -0500 Received: from DGGEMS404-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 4C2F3E89D1355151C65C; Tue, 5 Nov 2019 17:12:13 +0800 (CST) Received: from linux-OtBuvb.huawei.com (10.175.104.212) by DGGEMS404-HUB.china.huawei.com (10.3.19.204) with Microsoft SMTP Server id 14.3.439.0; Tue, 5 Nov 2019 17:12:03 +0800 From: Heyi Guo To: , Subject: [RFC v2 02/14] standard-headers: import arm_sdei.h Date: Tue, 5 Nov 2019 17:10:44 +0800 Message-ID: <20191105091056.9541-3-guoheyi@huawei.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20191105091056.9541-1-guoheyi@huawei.com> References: <20191105091056.9541-1-guoheyi@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.104.212] X-CFilter-Loop: Reflected Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 45.249.212.190 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , Peter Maydell , "Michael S. Tsirkin" , Marc Zyngier , Cornelia Huck , James Morse , Paolo Bonzini , Heyi Guo , wanghaibin.wang@huawei.com, Dave Martin Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Import Linux header file include/uapi/linux/arm_sdei.h from kernel v5.4-rc5. This is to prepare for qemu SDEI emulation. Signed-off-by: Heyi Guo Cc: Peter Maydell Cc: Dave Martin Cc: Marc Zyngier Cc: Mark Rutland Cc: James Morse Cc: "Michael S. Tsirkin" Cc: Cornelia Huck Cc: Paolo Bonzini --- Notes: v2: - Import arm_sdei.h by running update-linux-headers.sh include/standard-headers/linux/arm_sdei.h | 73 +++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 include/standard-headers/linux/arm_sdei.h diff --git a/include/standard-headers/linux/arm_sdei.h b/include/standard-h= eaders/linux/arm_sdei.h new file mode 100644 index 0000000000..568d971915 --- /dev/null +++ b/include/standard-headers/linux/arm_sdei.h @@ -0,0 +1,73 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ +/* Copyright (C) 2017 Arm Ltd. */ +#ifndef _LINUX_ARM_SDEI_H +#define _LINUX_ARM_SDEI_H + +#define SDEI_1_0_FN_BASE 0xC4000020 +#define SDEI_1_0_MASK 0xFFFFFFE0 +#define SDEI_1_0_FN(n) (SDEI_1_0_FN_BASE + (n)) + +#define SDEI_1_0_FN_SDEI_VERSION SDEI_1_0_FN(0x00) +#define SDEI_1_0_FN_SDEI_EVENT_REGISTER SDEI_1_0_FN(0x01) +#define SDEI_1_0_FN_SDEI_EVENT_ENABLE SDEI_1_0_FN(0x02) +#define SDEI_1_0_FN_SDEI_EVENT_DISABLE SDEI_1_0_FN(0x03) +#define SDEI_1_0_FN_SDEI_EVENT_CONTEXT SDEI_1_0_FN(0x04) +#define SDEI_1_0_FN_SDEI_EVENT_COMPLETE SDEI_1_0_FN(0x05) +#define SDEI_1_0_FN_SDEI_EVENT_COMPLETE_AND_RESUME SDEI_1_0_FN(0x06) +#define SDEI_1_0_FN_SDEI_EVENT_UNREGISTER SDEI_1_0_FN(0x07) +#define SDEI_1_0_FN_SDEI_EVENT_STATUS SDEI_1_0_FN(0x08) +#define SDEI_1_0_FN_SDEI_EVENT_GET_INFO SDEI_1_0_FN(0x09) +#define SDEI_1_0_FN_SDEI_EVENT_ROUTING_SET SDEI_1_0_FN(0x0A) +#define SDEI_1_0_FN_SDEI_PE_MASK SDEI_1_0_FN(0x0B) +#define SDEI_1_0_FN_SDEI_PE_UNMASK SDEI_1_0_FN(0x0C) +#define SDEI_1_0_FN_SDEI_INTERRUPT_BIND SDEI_1_0_FN(0x0D) +#define SDEI_1_0_FN_SDEI_INTERRUPT_RELEASE SDEI_1_0_FN(0x0E) +#define SDEI_1_0_FN_SDEI_PRIVATE_RESET SDEI_1_0_FN(0x11) +#define SDEI_1_0_FN_SDEI_SHARED_RESET SDEI_1_0_FN(0x12) + +#define SDEI_VERSION_MAJOR_SHIFT 48 +#define SDEI_VERSION_MAJOR_MASK 0x7fff +#define SDEI_VERSION_MINOR_SHIFT 32 +#define SDEI_VERSION_MINOR_MASK 0xffff +#define SDEI_VERSION_VENDOR_SHIFT 0 +#define SDEI_VERSION_VENDOR_MASK 0xffffffff + +#define SDEI_VERSION_MAJOR(x) (x>>SDEI_VERSION_MAJOR_SHIFT & SDEI_VERSION_= MAJOR_MASK) +#define SDEI_VERSION_MINOR(x) (x>>SDEI_VERSION_MINOR_SHIFT & SDEI_VERSION_= MINOR_MASK) +#define SDEI_VERSION_VENDOR(x) (x>>SDEI_VERSION_VENDOR_SHIFT & SDEI_VERSIO= N_VENDOR_MASK) + +/* SDEI return values */ +#define SDEI_SUCCESS 0 +#define SDEI_NOT_SUPPORTED -1 +#define SDEI_INVALID_PARAMETERS -2 +#define SDEI_DENIED -3 +#define SDEI_PENDING -5 +#define SDEI_OUT_OF_RESOURCE -10 + +/* EVENT_REGISTER flags */ +#define SDEI_EVENT_REGISTER_RM_ANY 0 +#define SDEI_EVENT_REGISTER_RM_PE 1 + +/* EVENT_STATUS return value bits */ +#define SDEI_EVENT_STATUS_RUNNING 2 +#define SDEI_EVENT_STATUS_ENABLED 1 +#define SDEI_EVENT_STATUS_REGISTERED 0 + +/* EVENT_COMPLETE status values */ +#define SDEI_EV_HANDLED 0 +#define SDEI_EV_FAILED 1 + +/* GET_INFO values */ +#define SDEI_EVENT_INFO_EV_TYPE 0 +#define SDEI_EVENT_INFO_EV_SIGNALED 1 +#define SDEI_EVENT_INFO_EV_PRIORITY 2 +#define SDEI_EVENT_INFO_EV_ROUTING_MODE 3 +#define SDEI_EVENT_INFO_EV_ROUTING_AFF 4 + +/* and their results */ +#define SDEI_EVENT_TYPE_PRIVATE 0 +#define SDEI_EVENT_TYPE_SHARED 1 +#define SDEI_EVENT_PRIORITY_NORMAL 0 +#define SDEI_EVENT_PRIORITY_CRITICAL 1 + +#endif /* _LINUX_ARM_SDEI_H */ --=20 2.19.1 From nobody Sun May 19 00:17:17 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1572946129; cv=none; d=zoho.com; s=zohoarc; b=a4vX3lKy3EoMmnlFd8NCNV0rxLqSBeMf2SwpGZEIbM9dnW4buV2eQNvg3u+vIswpW2byTBxFY9mV72WWiq2hW/9yfB9aL6/SYUR9Sec65fZ6ZDFdm7wpO2bomvFt2E891LKNOG6Nw2VefybZYb4dKvZBGiYFtnRuAgvzbEfM/KI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1572946129; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=02Y1EZMgl6LF52uyC9B5UwjGA50gaZu1BePudc7ellw=; b=X7yTSQl+3XMRq52FTugURaTNtiYl/6LGsI4uKYhi9FxpSUC8E4BUkEmakc19nRqGjdgzSwfDzAkB58GXxX9GLgCqmNcfJqFoHFpk0wptQRAVbWiEP+f54TGppzvOBcu9OtCuG4XpDhk2iPHpOeaOhj7QhqcF8S1Y0bTi+6VfoXQ= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.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 1572946129587669.6636413679543; Tue, 5 Nov 2019 01:28:49 -0800 (PST) Received: from localhost ([::1]:42064 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iRv8p-0008HC-KJ for importer@patchew.org; Tue, 05 Nov 2019 04:28:47 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:43259) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iRut5-0005FC-2N for qemu-devel@nongnu.org; Tue, 05 Nov 2019 04:12:33 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iRut2-0007vI-HN for qemu-devel@nongnu.org; Tue, 05 Nov 2019 04:12:30 -0500 Received: from szxga04-in.huawei.com ([45.249.212.190]:2197 helo=huawei.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iRusv-0007kT-Fy; Tue, 05 Nov 2019 04:12:22 -0500 Received: from DGGEMS404-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 45015584A918BF356752; Tue, 5 Nov 2019 17:12:13 +0800 (CST) Received: from linux-OtBuvb.huawei.com (10.175.104.212) by DGGEMS404-HUB.china.huawei.com (10.3.19.204) with Microsoft SMTP Server id 14.3.439.0; Tue, 5 Nov 2019 17:12:04 +0800 From: Heyi Guo To: , Subject: [RFC v2 03/14] arm/sdei: add virtual device framework Date: Tue, 5 Nov 2019 17:10:45 +0800 Message-ID: <20191105091056.9541-4-guoheyi@huawei.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20191105091056.9541-1-guoheyi@huawei.com> References: <20191105091056.9541-1-guoheyi@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.104.212] X-CFilter-Loop: Reflected Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 45.249.212.190 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , Peter Maydell , James Morse , Marc Zyngier , Jingyi Wang , Heyi Guo , wanghaibin.wang@huawei.com, Dave Martin Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" SDEI is useful to emulate NMI on arm64 platforms. To support SDEI in virtual machine with KVM enabled, we choose to implement SDEI interfaces in qemu. It is targeted for KVM mode only, for the full user space emulation can also emulate secure world and have ARM Trusted Firmware to run on emulated EL3. - We create a logical SDEI device to hold the states of SDEI services, to support VM migration. - Only one SDEI virtual device is allowed in the whole VM to provide SDEI services. - We create struct QemuSDE to hold states of each SDEI event, and private events with the same ID on different CPUs have their own QemuSDE instance. - We create struct QemuSDEProp to hold properties of each SDEI event, so all private instances with the same ID will pointed to the same QemuSDEProp. - We create struct QemuSDECpu to hold CPU/PE states, including the interrupted CPU context. - Slot numbers for private and shared event are fixed, for guests cannot request more interrupt binds than BIND_SLOTS in SDEI_FEATURES call. - The first PRIVATE_SLOT_COUNT slots in property array are for private events, and the next SHARED_SLOT_COUNT slots are for shared events. - We use property slot index as lower bit for each allocated event number, so that we can get property easily from valid input event number, as well as the QemuSDE instance. Signed-off-by: Heyi Guo Signed-off-by: Jingyi Wang Cc: Peter Maydell Cc: Dave Martin Cc: Marc Zyngier Cc: Mark Rutland Cc: James Morse --- target/arm/sdei.c | 344 ++++++++++++++++++++++++++++++++++++++++++ target/arm/sdei_int.h | 118 +++++++++++++++ 2 files changed, 462 insertions(+) create mode 100644 target/arm/sdei.c create mode 100644 target/arm/sdei_int.h diff --git a/target/arm/sdei.c b/target/arm/sdei.c new file mode 100644 index 0000000000..931e46923a --- /dev/null +++ b/target/arm/sdei.c @@ -0,0 +1,344 @@ +/* + * ARM SDEI emulation for ARM64 virtual machine with KVM + * + * Copyright (c) Huawei Technologies Co., Ltd. 2019. All rights reserved. + * + * Authors: + * Heyi Guo + * Jingyi Wang + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2 or later, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License f= or + * more details. + * + * You should have received a copy of the GNU General Public License along= with + * this program. If not, see . + */ + +#include "qemu/osdep.h" +#include "qapi/error.h" +#include "arm-powerctl.h" +#include "qemu/timer.h" +#include "sysemu/kvm.h" +#include "sysemu/kvm_int.h" +#include "sysemu/sysemu.h" +#include "sysemu/reset.h" +#include "qemu/error-report.h" +#include "sdei_int.h" +#include "internals.h" +#include "hw/boards.h" +#include "hw/intc/arm_gicv3.h" +#include "hw/intc/arm_gic.h" +#include "hw/irq.h" +#include "hw/sysbus.h" +#include "migration/vmstate.h" +#include "qom/object.h" + +#define TYPE_ARM_SDEI "arm_sdei" +#define QEMU_SDEI(obj) OBJECT_CHECK(QemuSDEState, (obj), TYPE_ARM_SDEI) + +static QemuSDEState *sde_state; + +static void qemu_sde_prop_init(QemuSDEState *s) +{ + QemuSDEProp *sde_props =3D s->sde_props_state; + int i; + for (i =3D 0; i < ARRAY_SIZE(s->sde_props_state); i++) { + sde_props[i].event_id =3D SDEI_INVALID_EVENT_ID; + sde_props[i].interrupt =3D SDEI_INVALID_INTERRUPT; + sde_props[i].sde_index =3D i >=3D PRIVATE_SLOT_COUNT ? + i - PRIVATE_SLOT_COUNT : i; + + qemu_mutex_init(&(sde_props[i].lock)); + sde_props[i].refcount =3D 0; + } + sde_props[0].event_id =3D SDEI_STD_EVT_SOFTWARE_SIGNAL; + sde_props[0].interrupt =3D SDEI_INVALID_INTERRUPT; + sde_props[0].is_shared =3D false; + sde_props[0].is_critical =3D false; + + for (i =3D 0; i < ARRAY_SIZE(s->irq_map); i++) { + s->irq_map[i] =3D SDEI_INVALID_EVENT_ID; + } + + qemu_mutex_init(&s->sdei_interrupt_bind_lock); +} + +static void qemu_sde_cpu_init(QemuSDEState *s) +{ + int i; + QemuSDECpu *sde_cpus; + + s->sdei_max_cpus =3D current_machine->smp.max_cpus; + s->sde_cpus =3D g_new0(QemuSDECpu, s->sdei_max_cpus); + sde_cpus =3D s->sde_cpus; + for (i =3D 0; i < s->sdei_max_cpus; i++) { + sde_cpus[i].masked =3D true; + sde_cpus[i].critical_running_event =3D SDEI_INVALID_EVENT_ID; + sde_cpus[i].normal_running_event =3D SDEI_INVALID_EVENT_ID; + } +} + +static bool is_valid_event_number(int32_t event) +{ + int32_t slot_id; + + if (event < 0 || (event & 0x3F000000)) { + return false; + } + + slot_id =3D SDEI_EVENT_TO_SLOT(event); + if (slot_id >=3D PRIVATE_SLOT_COUNT + SHARED_SLOT_COUNT) { + return false; + } + + return true; +} + +static bool is_valid_event(QemuSDEState *s, int32_t event) +{ + if (!is_valid_event_number(event)) { + return false; + } + + if (s->sde_props_state[SDEI_EVENT_TO_SLOT(event)].event_id !=3D event)= { + return false; + } + + return true; +} + +static QemuSDEProp *get_sde_prop_no_lock(QemuSDEState *s, int32_t event) +{ + if (!is_valid_event(s, event)) { + return NULL; + } + + return &s->sde_props_state[SDEI_EVENT_TO_SLOT(event)]; +} + +static void sde_array_init(QemuSDE **array, int count) +{ + int i; + + for (i =3D 0; i < count; i++) { + QemuSDE *sde; + sde =3D array[i]; + if (!sde) { + sde =3D g_new0(QemuSDE, 1); + } + sde->event_id =3D SDEI_INVALID_EVENT_ID; + sde->enabled =3D false; + sde->running =3D false; + sde->pending =3D false; + sde->unregister_pending =3D false; + qemu_mutex_init(&sde->lock); + array[i] =3D sde; + } +} + +static void qemu_shared_sde_init(QemuSDEState *s) +{ + sde_array_init(s->shared_sde_array, SHARED_SLOT_COUNT); +} + +static void qemu_private_sde_init(QemuSDEState *s) +{ + int i; + + for (i =3D 0; i < s->sdei_max_cpus; i++) { + sde_array_init(s->sde_cpus[i].private_sde_array, PRIVATE_SLOT_COUN= T); + } +} + +static void qemu_sde_init(QemuSDEState *s) +{ + qemu_sde_prop_init(s); + qemu_sde_cpu_init(s); + + qemu_shared_sde_init(s); + qemu_private_sde_init(s); +} + +static void sde_array_save(QemuSDE **array, int count) +{ + int i; + + for (i =3D 0; i < count; i++) { + QemuSDE *sde =3D array[i]; + if (sde->event_id !=3D SDEI_INVALID_EVENT_ID) { + sde->event_id =3D sde->prop->event_id; + sde->cpu_affinity =3D ARM_CPU(sde->target_cpu)->mp_affinity; + } + } +} + +static int qemu_sdei_pre_save(void *opaque) +{ + QemuSDEState *s =3D opaque; + int i; + + for (i =3D 0; i < s->sdei_max_cpus; i++) { + sde_array_save(s->sde_cpus[i].private_sde_array, PRIVATE_SLOT_COUN= T); + } + + sde_array_save(s->shared_sde_array, SHARED_SLOT_COUNT); + + return 0; +} + + +static int qemu_sdei_post_load(void *opaque, int version_id) +{ + QemuSDEState *s =3D opaque; + QemuSDEProp *sde_props =3D s->sde_props_state; + QemuSDE **array; + int i, j; + + for (i =3D 0; i < s->sdei_max_cpus; i++) { + array =3D s->sde_cpus[i].private_sde_array; + for (j =3D 0; j < PRIVATE_SLOT_COUNT; j++) { + QemuSDE *sde =3D array[j]; + if (sde->event_id !=3D SDEI_INVALID_EVENT_ID) { + sde->prop =3D get_sde_prop_no_lock(s, sde->event_id); + sde->target_cpu =3D arm_get_cpu_by_id(sde->cpu_affinity); + } + } + } + + array =3D s->shared_sde_array; + for (j =3D 0; j < SHARED_SLOT_COUNT; j++) { + QemuSDE *sde =3D array[j]; + if (sde->event_id !=3D SDEI_INVALID_EVENT_ID) { + sde->prop =3D get_sde_prop_no_lock(s, sde->event_id); + sde->target_cpu =3D arm_get_cpu_by_id(sde->cpu_affinity); + } + } + + for (i =3D 0; i < PRIVATE_SLOT_COUNT + SHARED_SLOT_COUNT; i++) { + int intid =3D sde_props[i].interrupt; + + if (intid !=3D SDEI_INVALID_INTERRUPT) { + s->irq_map[intid] =3D sde_props[i].event_id; + } + } + + return 0; +} + +static const VMStateDescription vmstate_sdes =3D { + .name =3D "qemu_sdei/sdes", + .version_id =3D 1, + .minimum_version_id =3D 1, + .fields =3D (VMStateField[]) { + VMSTATE_BOOL(enabled, QemuSDE), + VMSTATE_BOOL(running, QemuSDE), + VMSTATE_BOOL(pending, QemuSDE), + VMSTATE_BOOL(unregister_pending, QemuSDE), + VMSTATE_UINT64(ep_address, QemuSDE), + VMSTATE_UINT64(ep_argument, QemuSDE), + VMSTATE_UINT64(routing_mode, QemuSDE), + VMSTATE_INT32(event_id, QemuSDE), + VMSTATE_UINT64(cpu_affinity, QemuSDE), + VMSTATE_END_OF_LIST() + } +}; + +static const VMStateDescription vmstate_sde_props =3D { + .name =3D "qemu_sdei/sde_props", + .version_id =3D 1, + .minimum_version_id =3D 1, + .fields =3D (VMStateField[]) { + VMSTATE_INT32(event_id, QemuSDEProp), + VMSTATE_INT32(interrupt, QemuSDEProp), + VMSTATE_BOOL(is_shared, QemuSDEProp), + VMSTATE_BOOL(is_critical, QemuSDEProp), + VMSTATE_INT32(sde_index, QemuSDEProp), + VMSTATE_INT32(refcount, QemuSDEProp), + VMSTATE_END_OF_LIST() + } +}; + +static const VMStateDescription vmstate_sde_cpu =3D { + .name =3D "qemu_sdei/sde_cpu", + .version_id =3D 1, + .minimum_version_id =3D 1, + .fields =3D (VMStateField[]) { + VMSTATE_ARRAY_OF_POINTER_TO_STRUCT(private_sde_array, QemuSDECpu, + PRIVATE_SLOT_COUNT, 1, + vmstate_sdes, QemuSDE), + VMSTATE_UINT64_ARRAY(ctx[0].xregs, QemuSDECpu, SAVED_GP_NUM), + VMSTATE_UINT64_ARRAY(ctx[1].xregs, QemuSDECpu, SAVED_GP_NUM), + VMSTATE_UINT64(ctx[0].pc, QemuSDECpu), + VMSTATE_UINT64(ctx[1].pc, QemuSDECpu), + VMSTATE_UINT32(ctx[0].pstate, QemuSDECpu), + VMSTATE_UINT32(ctx[1].pstate, QemuSDECpu), + VMSTATE_INT32(critical_running_event, QemuSDECpu), + VMSTATE_INT32(normal_running_event, QemuSDECpu), + VMSTATE_BOOL(masked, QemuSDECpu), + VMSTATE_END_OF_LIST() + } +}; + +static const VMStateDescription vmstate_sde_state =3D { + .name =3D "qemu_sdei", + .version_id =3D 1, + .minimum_version_id =3D 1, + .pre_save =3D qemu_sdei_pre_save, + .post_load =3D qemu_sdei_post_load, + .fields =3D (VMStateField[]) { + VMSTATE_STRUCT_ARRAY(sde_props_state, QemuSDEState, + PRIVATE_SLOT_COUNT + SHARED_SLOT_COUNT, 1, + vmstate_sde_props, QemuSDEProp), + VMSTATE_ARRAY_OF_POINTER_TO_STRUCT(shared_sde_array, QemuSDEState, + SHARED_SLOT_COUNT, 1, + vmstate_sdes, QemuSDE), + VMSTATE_STRUCT_VARRAY_POINTER_INT32(sde_cpus, QemuSDEState, + sdei_max_cpus, + vmstate_sde_cpu, QemuSDECpu), + VMSTATE_END_OF_LIST() + } +}; + + +static void sdei_initfn(Object *obj) +{ + QemuSDEState *s =3D QEMU_SDEI(obj); + + if (sde_state) { + error_report("Only one SDEI dispatcher is allowed!"); + abort(); + } + sde_state =3D s; + + qemu_sde_init(s); +} + +static void qemu_sde_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(klass); + + dc->desc =3D "SDEI_QEMU"; + dc->vmsd =3D &vmstate_sde_state; + dc->user_creatable =3D true; +} + +static const TypeInfo sde_qemu_info =3D { + .name =3D TYPE_ARM_SDEI, + .parent =3D TYPE_DEVICE, + .instance_size =3D sizeof(QemuSDEState), + .instance_init =3D sdei_initfn, + .class_init =3D qemu_sde_class_init, +}; + +static void register_types(void) +{ + type_register_static(&sde_qemu_info); +} + +type_init(register_types); diff --git a/target/arm/sdei_int.h b/target/arm/sdei_int.h new file mode 100644 index 0000000000..d3fd7cbc10 --- /dev/null +++ b/target/arm/sdei_int.h @@ -0,0 +1,118 @@ +/* + * ARM SDEI emulation internal interfaces + * + * Copyright (c) Huawei Technologies Co., Ltd. 2019. All rights reserved. + * + * Authors: + * Heyi Guo + * Jingyi Wang + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2 or later, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License f= or + * more details. + * + * You should have received a copy of the GNU General Public License along= with + * this program. If not, see . + */ + +#ifndef QEMU_SDEI_INT_H +#define QEMU_SDEI_INT_H + +#include +#include +#include +#include "hw/intc/arm_gic_common.h" +#include "qemu/thread.h" + +#define SDEI_STD_EVT_SOFTWARE_SIGNAL 0 +#define SDEI_FEATURE_BIND_SLOTS 0 +#define SDEI_PARAM_MAX 18 + +#define PRIVATE_SLOT_COUNT 16 +#define PLAT_PRIVATE_SLOT_COUNT 8 +#define SHARED_SLOT_COUNT 32 +#define PLAT_SHARED_SLOT_COUNT 16 +#define SDEI_INVALID_INTERRUPT -1 +#define SDEI_INVALID_EVENT_ID -1 + +#define SDEI_EVENT_TO_SLOT(event) ((event) & 0xFFFFFF) +#define SDEI_IS_SHARED_EVENT(event) \ + (SDEI_EVENT_TO_SLOT(event) >=3D PRIVATE_SLOT_COUNT) + +typedef enum { + SDEI_PRIO_NORMAL =3D 0, + SDEI_PRIO_CRITICAL =3D 1, +} QemuSDEIPriority; + +typedef struct QemuSDEProp { + QemuMutex lock; + int32_t event_id; + int interrupt; + bool is_shared; + bool is_critical; + /* This is the internal index for private or shared SDE */ + int sde_index; + int refcount; +} QemuSDEProp; + +typedef struct QemuSDE { + QemuSDEProp *prop; + CPUState *target_cpu; + QemuMutex lock; + bool enabled; + bool running; + bool pending; + bool unregister_pending; + uint64_t ep_address; + uint64_t ep_argument; + uint64_t routing_mode; + int32_t event_id; + /* + * For it is not easy to save the pointer target_cpu during migration,= we + * add below field to save the corresponding numerical values. + */ + uint64_t cpu_affinity; +} QemuSDE; + +/* + * GP registers x0~x17 may be modified by client, so they must be saved by + * dispatcher. + */ +#define SAVED_GP_NUM 18 + +typedef struct QemuSDECpuCtx { + uint64_t xregs[SAVED_GP_NUM]; + uint64_t pc; + uint32_t pstate; +} QemuSDECpuCtx; + +typedef enum { + SDEI_EVENT_PRIO_NORMAL =3D 0, + SDEI_EVENT_PRIO_CRITICAL, + SDEI_EVENT_PRIO_COUNT, +} SdeiEventPriority; + +typedef struct QemuSDECpu { + QemuSDE *private_sde_array[PRIVATE_SLOT_COUNT]; + QemuSDECpuCtx ctx[SDEI_EVENT_PRIO_COUNT]; + bool masked; + int32_t critical_running_event; + int32_t normal_running_event; +} QemuSDECpu; + +typedef struct QemuSDEState { + DeviceState parent_obj; + QemuSDEProp sde_props_state[PRIVATE_SLOT_COUNT + SHARED_SLOT_COUNT= ]; + QemuSDECpu *sde_cpus; + int sdei_max_cpus; + QemuSDE *shared_sde_array[SHARED_SLOT_COUNT]; + int32_t irq_map[GIC_MAXIRQ]; + QemuMutex sdei_interrupt_bind_lock; +} QemuSDEState; + +#endif --=20 2.19.1 From nobody Sun May 19 00:17:17 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1572945261; cv=none; d=zoho.com; s=zohoarc; b=mh320nOu5b4KmAREj/lvm3/3jcZU3YMqT3COmNKUaP3ykSPTZbFKeHyCCaETWZhXlm8PDD6nZMJPGZ86g/O83XP9+bgLPuwrakLWZzVM+Hg9RwXNGEsAUFjykbj8OxU+xBSUo/zyAUcE1WyKlr00PyW6sdFVj4adMWen5hlQoYI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1572945261; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=0z1sV+nrIiXCF7X5ZyGodvqk5mKYFCX8yNrUGVPDSZQ=; b=bkwuM88oTIsRrpno/an9Tu/JrHMvnMqi+S6EkeqGsmlNE57fyEmI7S3pDhH21IgSiWvBbkxunewquBmpMxhQFuvsNTIgyBTZC0bUvsa/+kFlKJrLTROeRDyaLNqzr/HF+rYr1/jjQxUKOch8rK8I1M6oD4zMhEy8BgwD8PgP5gA= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.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 1572945261132295.2852487730961; Tue, 5 Nov 2019 01:14:21 -0800 (PST) Received: from localhost ([::1]:41822 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iRuun-0007Cn-Ba for importer@patchew.org; Tue, 05 Nov 2019 04:14:17 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:43043) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iRusx-00051w-Bg for qemu-devel@nongnu.org; Tue, 05 Nov 2019 04:12:24 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iRusv-0007m0-Oi for qemu-devel@nongnu.org; Tue, 05 Nov 2019 04:12:23 -0500 Received: from szxga04-in.huawei.com ([45.249.212.190]:2193 helo=huawei.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iRuss-0007ho-VA; Tue, 05 Nov 2019 04:12:19 -0500 Received: from DGGEMS404-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 30E169802AA03F54722A; Tue, 5 Nov 2019 17:12:13 +0800 (CST) Received: from linux-OtBuvb.huawei.com (10.175.104.212) by DGGEMS404-HUB.china.huawei.com (10.3.19.204) with Microsoft SMTP Server id 14.3.439.0; Tue, 5 Nov 2019 17:12:04 +0800 From: Heyi Guo To: , Subject: [RFC v2 04/14] arm: add CONFIG_SDEI build flag Date: Tue, 5 Nov 2019 17:10:46 +0800 Message-ID: <20191105091056.9541-5-guoheyi@huawei.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20191105091056.9541-1-guoheyi@huawei.com> References: <20191105091056.9541-1-guoheyi@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.104.212] X-CFilter-Loop: Reflected Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 45.249.212.190 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , Peter Maydell , Marc Zyngier , James Morse , Heyi Guo , wanghaibin.wang@huawei.com, Dave Martin Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Integrate SDEI support for arm/aarch64 targets by default, if KVM is enabled. Signed-off-by: Heyi Guo Cc: Peter Maydell Cc: Dave Martin Cc: Marc Zyngier Cc: Mark Rutland Cc: James Morse --- default-configs/arm-softmmu.mak | 1 + hw/arm/Kconfig | 4 ++++ target/arm/Makefile.objs | 2 ++ 3 files changed, 7 insertions(+) diff --git a/default-configs/arm-softmmu.mak b/default-configs/arm-softmmu.= mak index 1f2e0e7fde..fc1f2b2ead 100644 --- a/default-configs/arm-softmmu.mak +++ b/default-configs/arm-softmmu.mak @@ -40,3 +40,4 @@ CONFIG_FSL_IMX25=3Dy CONFIG_FSL_IMX7=3Dy CONFIG_FSL_IMX6UL=3Dy CONFIG_SEMIHOSTING=3Dy +CONFIG_SDEI=3Dy diff --git a/hw/arm/Kconfig b/hw/arm/Kconfig index c6e7782580..472bc3a75b 100644 --- a/hw/arm/Kconfig +++ b/hw/arm/Kconfig @@ -469,3 +469,7 @@ config ARMSSE_CPUID =20 config ARMSSE_MHU bool + +config SDEI + bool + depends on KVM diff --git a/target/arm/Makefile.objs b/target/arm/Makefile.objs index cf26c16f5f..72e01d08dc 100644 --- a/target/arm/Makefile.objs +++ b/target/arm/Makefile.objs @@ -11,6 +11,8 @@ obj-$(call land,$(CONFIG_KVM),$(call lnot,$(TARGET_AARCH6= 4))) +=3D kvm32.o obj-$(call land,$(CONFIG_KVM),$(TARGET_AARCH64)) +=3D kvm64.o obj-$(call lnot,$(CONFIG_KVM)) +=3D kvm-stub.o =20 +obj-$(CONFIG_SDEI) +=3D sdei.o + DECODETREE =3D $(SRC_PATH)/scripts/decodetree.py =20 target/arm/decode-sve.inc.c: $(SRC_PATH)/target/arm/sve.decode $(DECODETRE= E) --=20 2.19.1 From nobody Sun May 19 00:17:17 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1572945508; cv=none; d=zoho.com; s=zohoarc; b=V2qpvgxl8cfATi0E38JMF8i0wlX/PipZjyBsyiBzJ/1xd2usndFIj5SrlJeGeK0N/on3d4SK6cafgLs4GHbkcWwsbGh2YnTrMh6Ilu3eqQt0zCAxLnKBYvI6zjzFDD41H88dRHQTK9v2+TU8bcEeO9atwLQna6vxQTGXOzqXIys= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1572945508; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=rVnHbFwcw+fNdGKBLya39/zFdoX6TxBt6nZGlunfeLI=; b=ELGZXLrK21I4zwpRNBlUf8UnCxoONj9kUtgC0xifL78AqntNK3IZbt//r3BUt8Q9viI9Cis6X+jtadXj/UvBAWSfwtKd/To+RDqSejUXsAEDmzZXz7izgrv7hV3dSNWb1jtxqzRT7Acc0EN0LV8JU+QDRKWOtsQfUVbF2zeb5MQ= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.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 1572945508511526.4235408493279; Tue, 5 Nov 2019 01:18:28 -0800 (PST) Received: from localhost ([::1]:41888 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iRuyp-0003Oh-0B for importer@patchew.org; Tue, 05 Nov 2019 04:18:27 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:43300) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iRutB-0005RE-NI for qemu-devel@nongnu.org; Tue, 05 Nov 2019 04:12:41 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iRut8-00080L-9Q for qemu-devel@nongnu.org; Tue, 05 Nov 2019 04:12:37 -0500 Received: from szxga04-in.huawei.com ([45.249.212.190]:2195 helo=huawei.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iRusv-0007kR-HT; Tue, 05 Nov 2019 04:12:22 -0500 Received: from DGGEMS404-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 365032FF892605EB11AF; Tue, 5 Nov 2019 17:12:13 +0800 (CST) Received: from linux-OtBuvb.huawei.com (10.175.104.212) by DGGEMS404-HUB.china.huawei.com (10.3.19.204) with Microsoft SMTP Server id 14.3.439.0; Tue, 5 Nov 2019 17:12:05 +0800 From: Heyi Guo To: , Subject: [RFC v2 05/14] arm/sdei: add support to handle SDEI requests from guest Date: Tue, 5 Nov 2019 17:10:47 +0800 Message-ID: <20191105091056.9541-6-guoheyi@huawei.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20191105091056.9541-1-guoheyi@huawei.com> References: <20191105091056.9541-1-guoheyi@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.104.212] X-CFilter-Loop: Reflected Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 45.249.212.190 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , Peter Maydell , James Morse , Marc Zyngier , Jingyi Wang , Heyi Guo , wanghaibin.wang@huawei.com, Dave Martin Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Add support for all interfaces defined in ARM SDEI 1.0 spec. http://infocenter.arm.com/help/topic/com.arm.doc.den0054a/ARM_DEN0054A_Soft= ware_Delegated_Exception_Interface.pdf The exit reason KVM_EXIT_HYPERCALL is used to indicate it is an HVC/SMC forward, and the structure kvm_run->hypercall is used to pass arguments and return values between KVM and qemu: Input: nr: the immediate value of SMC/HVC calls; not really used today. args[6]: x0..x5 (This is not fully conform with SMCCC which requires x6 as argument as well, but we can use GET_ONE_REG ioctl for such rare case). Return: args[0..3]: x0..x3 as defined in SMCCC. We rely on KVM to extract args[0..3] and write them to x0..x3 when hypercall exit returns. Signed-off-by: Heyi Guo Signed-off-by: Jingyi Wang Cc: Peter Maydell Cc: Dave Martin Cc: Marc Zyngier Cc: Mark Rutland Cc: James Morse --- target/arm/sdei.c | 982 ++++++++++++++++++++++++++++++++++++++++++++++ target/arm/sdei.h | 34 ++ 2 files changed, 1016 insertions(+) create mode 100644 target/arm/sdei.h diff --git a/target/arm/sdei.c b/target/arm/sdei.c index 931e46923a..0c0212bfa8 100644 --- a/target/arm/sdei.c +++ b/target/arm/sdei.c @@ -29,6 +29,7 @@ #include "sysemu/sysemu.h" #include "sysemu/reset.h" #include "qemu/error-report.h" +#include "sdei.h" #include "sdei_int.h" #include "internals.h" #include "hw/boards.h" @@ -42,6 +43,9 @@ #define TYPE_ARM_SDEI "arm_sdei" #define QEMU_SDEI(obj) OBJECT_CHECK(QemuSDEState, (obj), TYPE_ARM_SDEI) =20 +#define SMCCC_RETURN_REG_COUNT 4 +#define PSTATE_M_EL_SHIFT 2 + static QemuSDEState *sde_state; =20 static void qemu_sde_prop_init(QemuSDEState *s) @@ -84,6 +88,16 @@ static void qemu_sde_cpu_init(QemuSDEState *s) } } =20 +static inline QemuSDECpu *get_sde_cpu(QemuSDEState *s, CPUState *cs) +{ + if (cs->cpu_index >=3D s->sdei_max_cpus) { + error_report("BUG: cpu index %d >=3D max_cpus %d", + cs->cpu_index, s->sdei_max_cpus); + return NULL; + } + return &s->sde_cpus[cs->cpu_index]; +} + static bool is_valid_event_number(int32_t event) { int32_t slot_id; @@ -122,6 +136,974 @@ static QemuSDEProp *get_sde_prop_no_lock(QemuSDEState= *s, int32_t event) return &s->sde_props_state[SDEI_EVENT_TO_SLOT(event)]; } =20 +static QemuSDEProp *get_sde_prop(QemuSDEState *s, int32_t event) +{ + QemuSDEProp *sde_props =3D s->sde_props_state; + + if (!is_valid_event_number(event)) { + return NULL; + } + + event =3D SDEI_EVENT_TO_SLOT(event); + + qemu_mutex_lock(&sde_props[event].lock); + if (sde_props[event].event_id < 0) { + qemu_mutex_unlock(&sde_props[event].lock); + return NULL; + } + return &sde_props[event]; +} + +static void put_sde_prop(QemuSDEProp *prop) +{ + qemu_mutex_unlock(&prop->lock); +} + +static void sde_slot_lock(QemuSDE *sde, CPUState *cs) +{ + qemu_mutex_lock(&sde->lock); +} + +static void sde_slot_unlock(QemuSDE *sde, CPUState *cs) +{ + qemu_mutex_unlock(&sde->lock); +} + +/* + * It will always return a pointer to a preallocated sde; event number mus= t be + * validated before calling this function. + */ +static QemuSDE *get_sde_no_check(QemuSDEState *s, int32_t event, CPUState = *cs) +{ + QemuSDE **array =3D s->sde_cpus[cs->cpu_index].private_sde_array; + int32_t sde_index =3D SDEI_EVENT_TO_SLOT(event); + QemuSDE *sde; + + if (SDEI_IS_SHARED_EVENT(event)) { + array =3D s->shared_sde_array; + sde_index -=3D PRIVATE_SLOT_COUNT; + } + + sde =3D array[sde_index]; + sde_slot_lock(sde, cs); + return sde; +} + +static void put_sde(QemuSDE *sde, CPUState *cs) +{ + sde_slot_unlock(sde, cs); +} + +static inline bool is_sde_nested(QemuSDECpu *sde_cpu) +{ + return sde_cpu->critical_running_event >=3D 0 && + sde_cpu->normal_running_event >=3D 0; +} + +static int32_t get_running_sde(QemuSDEState *s, CPUState *cs) +{ + QemuSDECpu *sde_cpu =3D get_sde_cpu(s, cs); + + if (!sde_cpu) { + return SDEI_INVALID_EVENT_ID; + } + + if (sde_cpu->critical_running_event >=3D 0) { + return sde_cpu->critical_running_event; + } + return sde_cpu->normal_running_event; +} + +static void override_return_value(CPUState *cs, uint64_t *args) +{ + CPUARMState *env =3D &ARM_CPU(cs)->env; + int i; + + for (i =3D 0; i < SMCCC_RETURN_REG_COUNT; i++) { + args[i] =3D env->xregs[i]; + } +} + +static void sde_save_cpu_ctx(CPUState *cs, QemuSDECpu *sde_cpu, bool criti= cal) +{ + CPUARMState *env =3D &ARM_CPU(cs)->env; + QemuSDECpuCtx *ctx =3D &sde_cpu->ctx[critical ? 1 : 0]; + + memcpy(ctx->xregs, env->xregs, sizeof(ctx->xregs)); + ctx->pc =3D env->pc; + ctx->pstate =3D pstate_read(env); +} + +static void sde_restore_cpu_ctx(QemuSDEState *s, CPUState *cs, bool critic= al) +{ + CPUARMState *env =3D &ARM_CPU(cs)->env; + QemuSDECpu *sde_cpu =3D get_sde_cpu(s, cs); + QemuSDECpuCtx *ctx; + + if (!sde_cpu) { + return; + } + + ctx =3D &sde_cpu->ctx[critical ? 1 : 0]; + + /* + * TODO: we need to optimize to only restore affected registers by cal= ling + * ioctl individialy + */ + kvm_arch_get_registers(cs); + + env->aarch64 =3D ((ctx->pstate & PSTATE_nRW) =3D=3D 0); + memcpy(env->xregs, ctx->xregs, sizeof(ctx->xregs)); + env->pc =3D ctx->pc; + pstate_write(env, ctx->pstate); + aarch64_restore_sp(env, (env->pstate & PSTATE_M) >> PSTATE_M_EL_SHIFT); +} + +static void sde_restore_cpu_ctx_for_resume(QemuSDEState *s, + CPUState *cs, + bool critical, + uint64_t resume_addr) +{ + CPUARMState *env =3D &ARM_CPU(cs)->env; + QemuSDECpu *sde_cpu =3D get_sde_cpu(s, cs); + QemuSDECpuCtx *ctx; + + if (!sde_cpu) { + return; + } + + ctx =3D &sde_cpu->ctx[critical ? 1 : 0]; + + /* + * TODO: we need to optimize to only restore affected registers by cal= ling + * ioctl individialy + */ + kvm_arch_get_registers(cs); + + memcpy(env->xregs, ctx->xregs, sizeof(ctx->xregs)); + env->pc =3D resume_addr; + env->aarch64 =3D 1; + /* Constructe pstate in pstate_read() */ + env->daif =3D PSTATE_D | PSTATE_A | PSTATE_I | PSTATE_F; + /* Clear nRW/M[4] and M[3:0] */ + env->pstate &=3D ~(PSTATE_nRW | PSTATE_M); + /* Set exception mode to EL1h */ + env->pstate |=3D PSTATE_MODE_EL1h; + env->elr_el[1] =3D ctx->pc; + env->banked_spsr[KVM_SPSR_EL1 + 1] =3D ctx->pstate; + aarch64_restore_sp(env, 1); +} + +static void sde_build_cpu_ctx(CPUState *cs, QemuSDECpu *sde_cpu, QemuSDE *= sde) +{ + CPUARMState *env =3D &ARM_CPU(cs)->env; + + env->xregs[0] =3D sde->prop->event_id; + env->xregs[1] =3D sde->ep_argument; + env->xregs[2] =3D env->pc; + env->xregs[3] =3D pstate_read(env); + env->pc =3D sde->ep_address; + env->aarch64 =3D 1; + /* Constructe pstate in pstate_read() */ + env->daif =3D PSTATE_D | PSTATE_A | PSTATE_I | PSTATE_F; + /* Clear nRW/M[4] and M[3:0] */ + env->pstate &=3D ~(PSTATE_nRW | PSTATE_M); + /* Set exception mode to EL1h */ + env->pstate |=3D PSTATE_MODE_EL1h; + aarch64_restore_sp(env, 1); +} + +static void trigger_sde(CPUState *cs, run_on_cpu_data data) +{ + QemuSDEState *s =3D sde_state; + QemuSDECpu *sde_cpu =3D get_sde_cpu(s, cs); + int32_t event =3D data.host_int; + QemuSDE *sde; + + if (!sde_cpu) { + return; + } + + if (sde_cpu->masked || sde_cpu->critical_running_event >=3D 0) { + return; + } + + sde =3D get_sde_no_check(s, event, cs); + if (sde->event_id =3D=3D SDEI_INVALID_EVENT_ID) { + /* Some race condition happens! */ + put_sde(sde, cs); + return; + } + + if (sde_cpu->normal_running_event >=3D 0 && !sde->prop->is_critical) { + put_sde(sde, cs); + return; + } + + if (!sde->enabled || !sde->pending || sde->running) { + /* Some race condition happens! */ + put_sde(sde, cs); + return; + } + + sde->pending =3D false; + sde->running =3D true; + + if (sde->prop->is_critical) { + sde_cpu->critical_running_event =3D sde->prop->event_id; + } else { + sde_cpu->normal_running_event =3D sde->prop->event_id; + } + + kvm_arch_get_registers(cs); + sde_save_cpu_ctx(cs, sde_cpu, sde->prop->is_critical); + sde_build_cpu_ctx(cs, sde_cpu, sde); + kvm_arch_put_registers(cs, 1); + put_sde(sde, cs); +} + +static void dispatch_single(QemuSDEState *s, QemuSDE *sde, CPUState *cs) +{ + int32_t event =3D sde->prop->event_id; + bool pending =3D sde->pending; + bool enabled =3D sde->enabled; + CPUState *target =3D sde->target_cpu; + put_sde(sde, cs); + + if (pending && enabled) { + /* + * TODO: we need to find a free-unmasked PE to trigger for shared + * unpinned event + */ + async_run_on_cpu(target, trigger_sde, + RUN_ON_CPU_HOST_INT(event)); + } +} + +static bool sde_ready_to_trigger(QemuSDE *sde, CPUState *cs, bool is_criti= cal) +{ + if (sde->event_id =3D=3D SDEI_INVALID_EVENT_ID) { + return false; + } + if (sde->prop->is_critical !=3D is_critical) { + return false; + } + if (!sde->enabled || !sde->pending || sde->running || + sde->target_cpu !=3D cs) { + return false; + } + return true; +} + +static void dispatch_cpu(QemuSDEState *s, CPUState *cs, bool is_critical) +{ + QemuSDE *sde; + int i; + + for (i =3D 0; i < PRIVATE_SLOT_COUNT + SHARED_SLOT_COUNT; i++) { + sde =3D get_sde_no_check(s, i, cs); + if (!sde_ready_to_trigger(sde, cs, is_critical)) { + put_sde(sde, cs); + continue; + } + dispatch_single(s, sde, cs); + } +} + +static int32_t sdei_alloc_event_num(QemuSDEState *s, bool is_critical, + bool is_shared, int intid) +{ + int index; + int start =3D 0; + int count =3D PRIVATE_SLOT_COUNT; + int32_t event; + QemuSDEProp *sde_props =3D s->sde_props_state; + + if (is_shared) { + start =3D PRIVATE_SLOT_COUNT; + count =3D PRIVATE_SLOT_COUNT + SHARED_SLOT_COUNT; + } + + qemu_mutex_lock(&s->sdei_interrupt_bind_lock); + for (index =3D start; index < count; index++) { + qemu_mutex_lock(&sde_props[index].lock); + if (sde_props[index].interrupt =3D=3D intid) { + event =3D sde_props[index].event_id; + qemu_mutex_unlock(&sde_props[index].lock); + qemu_mutex_unlock(&s->sdei_interrupt_bind_lock); + return event; + } + qemu_mutex_unlock(&sde_props[index].lock); + } + + for (index =3D start; index < count; index++) { + qemu_mutex_lock(&sde_props[index].lock); + if (sde_props[index].event_id < 0) { + event =3D sde_props[index].event_id =3D 0x40000000 | index; + sde_props[index].interrupt =3D intid; + sde_props[index].is_shared =3D is_shared; + sde_props[index].is_critical =3D is_critical; + s->irq_map[intid] =3D event; + qemu_mutex_unlock(&sde_props[index].lock); + qemu_mutex_unlock(&s->sdei_interrupt_bind_lock); + return event; + } + qemu_mutex_unlock(&sde_props[index].lock); + } + qemu_mutex_unlock(&s->sdei_interrupt_bind_lock); + return SDEI_OUT_OF_RESOURCE; +} + +static int32_t sdei_free_event_num_locked(QemuSDEState *s, QemuSDEProp *pr= op) +{ + if (atomic_read(&prop->refcount) > 0) { + return SDEI_DENIED; + } + + s->irq_map[prop->interrupt] =3D SDEI_INVALID_EVENT_ID; + prop->event_id =3D SDEI_INVALID_EVENT_ID; + prop->interrupt =3D SDEI_INVALID_INTERRUPT; + return SDEI_SUCCESS; +} + +typedef int64_t (*sdei_single_function)(QemuSDEState *s, + CPUState *cs, + struct kvm_run *run); + +static int64_t sdei_version(QemuSDEState *s, CPUState *cs, struct kvm_run = *run) +{ + return (1ULL << SDEI_VERSION_MAJOR_SHIFT) | + (0ULL << SDEI_VERSION_MINOR_SHIFT); +} + +static int64_t unregister_single_sde(QemuSDEState *s, int32_t event, + CPUState *cs, bool force) +{ + QemuSDE *sde; + QemuSDEProp *prop; + int ret =3D 0; + + prop =3D get_sde_prop(s, event); + if (!prop) { + return SDEI_INVALID_PARAMETERS; + } + + sde =3D get_sde_no_check(s, event, cs); + if (sde->event_id =3D=3D SDEI_INVALID_EVENT_ID) { + put_sde(sde, cs); + put_sde_prop(prop); + return SDEI_DENIED; + } + + if (sde->running && !force) { + sde->unregister_pending =3D true; + ret =3D SDEI_PENDING; + } else { + atomic_dec(&prop->refcount); + sde->event_id =3D SDEI_INVALID_EVENT_ID; + sde->enabled =3D false; + sde->running =3D false; + sde->pending =3D false; + sde->unregister_pending =3D false; + } + put_sde(sde, cs); + put_sde_prop(prop); + return ret; +} + +static int64_t sdei_private_reset_common(QemuSDEState *s, CPUState *cs, + bool force) +{ + int64_t ret =3D SDEI_SUCCESS; + int i; + + for (i =3D 0; i < PRIVATE_SLOT_COUNT; i++) { + int64_t ret1; + ret1 =3D unregister_single_sde(s, i, cs, force); + /* Ignore other return values in reset interface */ + if (ret1 =3D=3D SDEI_PENDING) { + ret =3D SDEI_DENIED; + } + } + + return ret; +} + +static int64_t sdei_shared_reset_common(QemuSDEState *s, CPUState *cs, + bool force) +{ + int i; + QemuSDEProp *prop; + int32_t start_event =3D PRIVATE_SLOT_COUNT; + int64_t ret =3D SDEI_SUCCESS; + + for (i =3D start_event; i < PRIVATE_SLOT_COUNT + SHARED_SLOT_COUNT; i+= +) { + int64_t ret1 =3D unregister_single_sde(s, i, cs, force); + /* Ignore other return values in reset interface */ + if (ret1 =3D=3D SDEI_PENDING) { + ret =3D SDEI_DENIED; + } + } + if (ret) { + return ret; + } + + qemu_mutex_lock(&s->sdei_interrupt_bind_lock); + for (i =3D 0; i < PRIVATE_SLOT_COUNT + SHARED_SLOT_COUNT; i++) { + prop =3D get_sde_prop(s, i); + if (!prop || prop->interrupt =3D=3D SDEI_INVALID_INTERRUPT) { + if (prop) { + put_sde_prop(prop); + } + continue; + } + ret |=3D sdei_free_event_num_locked(s, prop); + put_sde_prop(prop); + } + qemu_mutex_unlock(&s->sdei_interrupt_bind_lock); + + return ret ? SDEI_DENIED : SDEI_SUCCESS; +} + +#define SDEI_EV_REGISTER_RM_MASK 1ULL + +static int64_t sdei_event_register(QemuSDEState *s, CPUState *cs, + struct kvm_run *run) +{ + QemuSDE *sde; + QemuSDEProp *prop; + CPUState *target =3D cs; + uint64_t *args =3D (uint64_t *)run->hypercall.args; + int32_t event =3D args[1]; + uint64_t rm_mode =3D SDEI_EVENT_REGISTER_RM_PE; + + prop =3D get_sde_prop(s, event); + if (!prop) { + return SDEI_INVALID_PARAMETERS; + } + + sde =3D get_sde_no_check(s, event, cs); + if (sde->event_id !=3D SDEI_INVALID_EVENT_ID) { + put_sde(sde, cs); + put_sde_prop(prop); + return SDEI_DENIED; + } + + if (prop->is_shared) { + rm_mode =3D args[4] & SDEI_EV_REGISTER_RM_MASK; + if (rm_mode =3D=3D SDEI_EVENT_REGISTER_RM_PE) { + target =3D arm_get_cpu_by_id(args[5]); + if (!target) { + put_sde_prop(prop); + return SDEI_INVALID_PARAMETERS; + } + } + } + + sde->target_cpu =3D target; + sde->ep_address =3D args[2]; + sde->ep_argument =3D args[3]; + sde->prop =3D prop; + sde->routing_mode =3D rm_mode; + sde->event_id =3D prop->event_id; + + put_sde(sde, cs); + atomic_inc(&prop->refcount); + put_sde_prop(prop); + + return SDEI_SUCCESS; +} + +static int64_t sdei_event_enable(QemuSDEState *s, CPUState *cs, + struct kvm_run *run) +{ + QemuSDE *sde; + uint64_t *args =3D (uint64_t *)(run->hypercall.args); + int32_t event =3D args[1]; + + if (!is_valid_event_number(event)) { + return SDEI_INVALID_PARAMETERS; + } + sde =3D get_sde_no_check(s, event, cs); + if (sde->event_id =3D=3D SDEI_INVALID_EVENT_ID) { + put_sde(sde, cs); + return SDEI_INVALID_PARAMETERS; + } + + sde->enabled =3D true; + dispatch_single(s, sde, cs); + return SDEI_SUCCESS; +} + +static int64_t sdei_event_disable(QemuSDEState *s, CPUState *cs, + struct kvm_run *run) +{ + QemuSDE *sde; + uint64_t *args =3D (uint64_t *)run->hypercall.args; + int32_t event =3D args[1]; + + if (!is_valid_event_number(event)) { + return SDEI_INVALID_PARAMETERS; + } + sde =3D get_sde_no_check(s, event, cs); + if (sde->event_id =3D=3D SDEI_INVALID_EVENT_ID) { + put_sde(sde, cs); + return SDEI_INVALID_PARAMETERS; + } + + sde->enabled =3D false; + put_sde(sde, cs); + return SDEI_SUCCESS; +} + +static int64_t sdei_event_context(QemuSDEState *s, CPUState *cs, + struct kvm_run *run) +{ + QemuSDECpu *sde_cpu =3D get_sde_cpu(s, cs); + uint64_t *args =3D (uint64_t *)(run->hypercall.args); + uint32_t param_id =3D args[1]; + int critical; + QemuSDECpuCtx *ctx; + + if (param_id >=3D SDEI_PARAM_MAX) { + return SDEI_INVALID_PARAMETERS; + } + + if (!sde_cpu) { + return SDEI_DENIED; + } + + if (sde_cpu->critical_running_event >=3D 0) { + critical =3D 1; + } else if (sde_cpu->normal_running_event >=3D 0) { + critical =3D 0; + } else { + return SDEI_DENIED; + } + + ctx =3D &sde_cpu->ctx[critical]; + return ctx->xregs[param_id]; +} + +static int64_t sdei_event_complete(QemuSDEState *s, CPUState *cs, + struct kvm_run *run) +{ + QemuSDE *sde; + QemuSDECpu *cpu =3D get_sde_cpu(s, cs); + int32_t event; + uint64_t *args =3D (uint64_t *)(run->hypercall.args); + bool is_critical; + + if (!cpu) { + return SDEI_DENIED; + } + + event =3D get_running_sde(s, cs); + if (event < 0) { + return SDEI_DENIED; + } + + if (!is_valid_event_number(event)) { + error_report("BUG: running event number 0x%x is invalid!", + event); + return SDEI_DENIED; + } + sde =3D get_sde_no_check(s, event, cs); + if (sde->event_id !=3D event) { + error_report("BUG: sde event id 0x%x !=3D running event 0x%x!", + sde->event_id, event); + put_sde(sde, cs); + return SDEI_DENIED; + } + + sde->running =3D false; + is_critical =3D sde->prop->is_critical; + if (sde->unregister_pending) { + atomic_dec(&sde->prop->refcount); + sde->event_id =3D SDEI_INVALID_EVENT_ID; + sde->unregister_pending =3D false; + } + put_sde(sde, cs); + + sde_restore_cpu_ctx(s, cs, is_critical); + + kvm_arch_put_registers(cs, 1); + override_return_value(cs, args); + if (cpu->critical_running_event >=3D 0) { + cpu->critical_running_event =3D SDEI_INVALID_EVENT_ID; + } else { + cpu->normal_running_event =3D SDEI_INVALID_EVENT_ID; + } + + /* TODO: we should not queue more than one sde in work queue */ + dispatch_cpu(s, cs, true); + if (cpu->critical_running_event < 0 && cpu->normal_running_event < 0) { + dispatch_cpu(s, cs, false); + } + return args[0]; +} + +static int64_t sdei_event_complete_and_resume(QemuSDEState *s, CPUState *c= s, + struct kvm_run *run) +{ + QemuSDE *sde; + QemuSDECpu *cpu =3D get_sde_cpu(s, cs); + int32_t event; + uint64_t *args =3D (uint64_t *)(run->hypercall.args); + bool is_critical; + uint64_t resume_addr =3D args[1]; + + if (!cpu) { + return SDEI_DENIED; + } + + event =3D get_running_sde(s, cs); + if (event < 0) { + return SDEI_DENIED; + } + + if (!is_valid_event_number(event)) { + error_report("BUG: running event number 0x%x is invalid!", + event); + return SDEI_DENIED; + } + + sde =3D get_sde_no_check(s, event, cs); + if (sde->event_id !=3D event) { + error_report("BUG: sde event id 0x%x !=3D running event 0x%x!", + sde->event_id, event); + put_sde(sde, cs); + return SDEI_DENIED; + } + + sde->running =3D false; + is_critical =3D sde->prop->is_critical; + + if (sde->unregister_pending) { + atomic_dec(&sde->prop->refcount); + sde->event_id =3D SDEI_INVALID_EVENT_ID; + sde->unregister_pending =3D false; + } + put_sde(sde, cs); + + sde_restore_cpu_ctx_for_resume(s, cs, is_critical, resume_addr); + kvm_arch_put_registers(cs, 1); + + override_return_value(cs, args); + if (cpu->critical_running_event >=3D 0) { + cpu->critical_running_event =3D SDEI_INVALID_EVENT_ID; + } else { + cpu->normal_running_event =3D SDEI_INVALID_EVENT_ID; + } + + dispatch_cpu(s, cs, true); + if (cpu->critical_running_event < 0 && cpu->normal_running_event < 0) { + dispatch_cpu(s, cs, false); + } + return args[0]; +} + +static int64_t sdei_event_unregister(QemuSDEState *s, CPUState *cs, + struct kvm_run *run) +{ + uint64_t *args =3D (uint64_t *)(run->hypercall.args); + int32_t event =3D args[1]; + + return unregister_single_sde(s, event, cs, false); +} + +static int64_t sdei_event_status(QemuSDEState *s, CPUState *cs, + struct kvm_run *run) +{ + QemuSDE *sde; + uint64_t *args =3D (uint64_t *)(run->hypercall.args); + int32_t event =3D args[1]; + int64_t status =3D 0; + + if (!is_valid_event(s, event)) { + return SDEI_INVALID_PARAMETERS; + } + + sde =3D get_sde_no_check(s, event, cs); + if (sde->event_id =3D=3D SDEI_INVALID_EVENT_ID) { + put_sde(sde, cs); + return status; + } + + status |=3D SDEI_EVENT_STATUS_REGISTERED; + if (sde->enabled) { + status |=3D SDEI_EVENT_STATUS_ENABLED; + } + if (sde->running) { + status |=3D SDEI_EVENT_STATUS_RUNNING; + } + put_sde(sde, cs); + return status; +} + +static int64_t sdei_event_get_info(QemuSDEState *s, CPUState *cs, + struct kvm_run *run) +{ + QemuSDEProp *prop; + QemuSDE *sde; + uint64_t *args =3D (uint64_t *)(run->hypercall.args); + int32_t event =3D args[1]; + uint32_t info =3D args[2]; + int64_t ret =3D SDEI_INVALID_PARAMETERS; + + if (info > SDEI_EVENT_INFO_EV_ROUTING_AFF) { + return SDEI_INVALID_PARAMETERS; + } + + prop =3D get_sde_prop(s, event); + if (!prop) { + return SDEI_INVALID_PARAMETERS; + } + + switch (info) { + case SDEI_EVENT_INFO_EV_TYPE: + ret =3D prop->is_shared; + break; + case SDEI_EVENT_INFO_EV_SIGNALED: + ret =3D (event =3D=3D SDEI_STD_EVT_SOFTWARE_SIGNAL) ? 1 : 0; + break; + case SDEI_EVENT_INFO_EV_PRIORITY: + ret =3D prop->is_critical; + break; + case SDEI_EVENT_INFO_EV_ROUTING_MODE: + case SDEI_EVENT_INFO_EV_ROUTING_AFF: + if (!prop->is_shared) { + break; + } + sde =3D get_sde_no_check(s, event, cs); + if (sde->event_id =3D=3D SDEI_INVALID_EVENT_ID) { + put_sde(sde, cs); + ret =3D SDEI_DENIED; + break; + } + if (info =3D=3D SDEI_EVENT_INFO_EV_ROUTING_MODE) { + ret =3D sde->routing_mode; + } else if (sde->routing_mode =3D=3D SDEI_EVENT_REGISTER_RM_PE) { + ret =3D ARM_CPU(sde->target_cpu)->mp_affinity; + } + put_sde(sde, cs); + break; + default: + ret =3D SDEI_NOT_SUPPORTED; + } + put_sde_prop(prop); + return ret; +} + +static int64_t sdei_event_routing_set(QemuSDEState *s, CPUState *cs, + struct kvm_run *run) +{ + QemuSDE *sde; + CPUState *target =3D cs; + uint64_t *args =3D (uint64_t *)run->hypercall.args; + int32_t event =3D args[1]; + uint64_t mode =3D args[2]; + uint64_t affinity =3D args[3]; + + if (mode & ~1ULL) { + return SDEI_INVALID_PARAMETERS; + } + if (mode =3D=3D SDEI_EVENT_REGISTER_RM_PE) { + target =3D arm_get_cpu_by_id(affinity); + if (!target) { + return SDEI_INVALID_PARAMETERS; + } + } + + if (!is_valid_event(s, event) || !SDEI_IS_SHARED_EVENT(event)) { + return SDEI_INVALID_PARAMETERS; + } + + sde =3D get_sde_no_check(s, event, cs); + if (sde->event_id =3D=3D SDEI_INVALID_EVENT_ID) { + put_sde(sde, cs); + return SDEI_DENIED; + } + if (sde->enabled || sde->running || + sde->pending || sde->unregister_pending) { + put_sde(sde, cs); + return SDEI_DENIED; + } + + sde->target_cpu =3D target; + sde->routing_mode =3D mode; + put_sde(sde, cs); + + return SDEI_SUCCESS; +} + +static int64_t sdei_event_pe_mask(QemuSDEState *s, CPUState *cs, + struct kvm_run *run) +{ + QemuSDECpu *sde_cpu; + + sde_cpu =3D get_sde_cpu(s, cs); + if (!sde_cpu) { + return SDEI_DENIED; + } + + if (sde_cpu->masked) { + return 0; + } + sde_cpu->masked =3D true; + return 1; +} + +static int64_t sdei_event_pe_unmask(QemuSDEState *s, CPUState *cs, + struct kvm_run *run) +{ + QemuSDECpu *sde_cpu; + + sde_cpu =3D get_sde_cpu(s, cs); + if (!sde_cpu) { + return SDEI_DENIED; + } + + sde_cpu->masked =3D false; + dispatch_cpu(s, cs, true); + dispatch_cpu(s, cs, false); + return SDEI_SUCCESS; +} + +static int64_t sdei_event_interrupt_bind(QemuSDEState *s, CPUState *cs, + struct kvm_run *run) +{ + uint64_t *args =3D (uint64_t *)(run->hypercall.args); + uint32_t intid =3D args[1]; + + if (intid < GIC_NR_SGIS || intid >=3D GIC_MAXIRQ) { + return SDEI_INVALID_PARAMETERS; + } + return sdei_alloc_event_num(s, false, intid >=3D GIC_INTERNAL, intid); +} + +static int64_t sdei_event_interrupt_release(QemuSDEState *s, CPUState *cs, + struct kvm_run *run) +{ + QemuSDEProp *prop; + uint64_t *args =3D (uint64_t *)(run->hypercall.args); + int32_t event =3D args[1]; + int32_t ret; + + qemu_mutex_lock(&s->sdei_interrupt_bind_lock); + prop =3D get_sde_prop(s, event); + if (!prop) { + qemu_mutex_unlock(&s->sdei_interrupt_bind_lock); + return SDEI_INVALID_PARAMETERS; + } + + ret =3D sdei_free_event_num_locked(s, prop); + put_sde_prop(prop); + qemu_mutex_unlock(&s->sdei_interrupt_bind_lock); + return ret; +} + +static int64_t sdei_event_signal(QemuSDEState *s, CPUState *cs, + struct kvm_run *run) +{ + QemuSDE *sde; + CPUState *target_cpu; + uint64_t *args =3D (uint64_t *)(run->hypercall.args); + int32_t event =3D args[1]; + + if (event !=3D SDEI_STD_EVT_SOFTWARE_SIGNAL) { + return SDEI_INVALID_PARAMETERS; + } + + target_cpu =3D arm_get_cpu_by_id(args[2]); + if (!target_cpu) { + return SDEI_INVALID_PARAMETERS; + } + + sde =3D get_sde_no_check(s, event, target_cpu); + if (sde->event_id =3D=3D SDEI_INVALID_EVENT_ID) { + put_sde(sde, cs); + return SDEI_INVALID_PARAMETERS; + } + + sde->pending =3D true; + dispatch_single(s, sde, target_cpu); + return SDEI_SUCCESS; +} + +#define SDEI_FEATURES_SHARED_SLOTS_SHIFT 16 +static int64_t sdei_features(QemuSDEState *s, CPUState *cs, struct kvm_run= *run) +{ + uint64_t *args =3D (uint64_t *)(run->hypercall.args); + uint32_t feature =3D args[1]; + + switch (feature) { + case SDEI_FEATURE_BIND_SLOTS: + return ((SHARED_SLOT_COUNT - PLAT_SHARED_SLOT_COUNT) << + SDEI_FEATURES_SHARED_SLOTS_SHIFT) | + (PRIVATE_SLOT_COUNT - PLAT_PRIVATE_SLOT_COUNT); + default: + return SDEI_INVALID_PARAMETERS; + } +} + +static int64_t sdei_private_reset(QemuSDEState *s, CPUState *cs, + struct kvm_run *run) +{ + return sdei_private_reset_common(s, cs, false); +} + +static int64_t sdei_shared_reset(QemuSDEState *s, CPUState *cs, + struct kvm_run *run) +{ + return sdei_shared_reset_common(s, cs, false); +} + +static sdei_single_function sdei_functions[] =3D { + sdei_version, + sdei_event_register, + sdei_event_enable, + sdei_event_disable, + sdei_event_context, + sdei_event_complete, + sdei_event_complete_and_resume, + sdei_event_unregister, + sdei_event_status, + sdei_event_get_info, + sdei_event_routing_set, + sdei_event_pe_mask, + sdei_event_pe_unmask, + sdei_event_interrupt_bind, + sdei_event_interrupt_release, + sdei_event_signal, + sdei_features, + sdei_private_reset, + sdei_shared_reset, +}; + +void sdei_handle_request(CPUState *cs, struct kvm_run *run) +{ + uint32_t func_id =3D run->hypercall.args[0]; + + if (!sde_state) { + run->hypercall.args[0] =3D SDEI_NOT_SUPPORTED; + return; + } + + if (func_id < SDEI_1_0_FN_BASE || func_id > SDEI_MAX_REQ) { + error_report("Invalid SDEI function ID: 0x%x", func_id); + run->hypercall.args[0] =3D SDEI_INVALID_PARAMETERS; + return; + } + + func_id -=3D SDEI_1_0_FN_BASE; + if (func_id < ARRAY_SIZE(sdei_functions) && sdei_functions[func_id]) { + run->hypercall.args[0] =3D sdei_functions[func_id](sde_state, cs, = run); + } else { + run->hypercall.args[0] =3D SDEI_NOT_SUPPORTED; + } +} + static void sde_array_init(QemuSDE **array, int count) { int i; diff --git a/target/arm/sdei.h b/target/arm/sdei.h new file mode 100644 index 0000000000..828f70bbf1 --- /dev/null +++ b/target/arm/sdei.h @@ -0,0 +1,34 @@ +/* + * ARM SDEI emulation external interfaces + * + * Copyright (c) Huawei Technologies Co., Ltd. 2019. All rights reserved. + * + * Authors: + * Heyi Guo + * Jingyi Wang + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2 or later, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License f= or + * more details. + * + * You should have received a copy of the GNU General Public License along= with + * this program. If not, see . + */ + +#ifndef QEMU_SDEI_H +#define QEMU_SDEI_H + +#include +#include +#include "hw/core/cpu.h" + +#define SDEI_MAX_REQ SDEI_1_0_FN(0x12) + +void sdei_handle_request(CPUState *cs, struct kvm_run *run); + +#endif --=20 2.19.1 From nobody Sun May 19 00:17:17 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1572945301; cv=none; d=zoho.com; s=zohoarc; b=hOUS5lwnmAsAkiZVyKPpne6lLSjXR1Z5JUHW0djUNhzAQY+ZMp81CCncClOTUZajjYN5rX5s+dY6Z5j2cG1Dsqhz2XCe4RmpTWSwC02OYW9Em5JpC7xH/WPfOutkhlMq32SohIahBjiI/8IN8RmKDnqv1iAGm8nITQS3OFJk4VQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1572945301; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=HiQhAh7UIjCJgydyktuYcRZzmdI10XrZEkZmT8+V1+o=; b=EIugwX85ZyM0cS9Yp6N31D+UZ4lfI7nFxDwHO9Raym9Rpcr6bCvBDtAR2FYqpGQ4fvvD3KIxVymUjCA9w3oBmNIAEZl+Jt0Y8PIlUa/soz5AuToea/8KkSOTowya8iHmjKoemT6OmFkBWuRcpnb84fA+oycqhtBIMgK+3KdkqMU= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.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 1572945301374561.7967653302969; Tue, 5 Nov 2019 01:15:01 -0800 (PST) Received: from localhost ([::1]:41828 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iRuvT-0008GC-RU for importer@patchew.org; Tue, 05 Nov 2019 04:14:59 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:43047) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iRusx-000520-Ca for qemu-devel@nongnu.org; Tue, 05 Nov 2019 04:12:24 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iRusv-0007mY-Sy for qemu-devel@nongnu.org; Tue, 05 Nov 2019 04:12:23 -0500 Received: from szxga04-in.huawei.com ([45.249.212.190]:2190 helo=huawei.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iRuss-0007he-V8; Tue, 05 Nov 2019 04:12:19 -0500 Received: from DGGEMS404-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 1FE66EE9B26D8FE4F05B; Tue, 5 Nov 2019 17:12:13 +0800 (CST) Received: from linux-OtBuvb.huawei.com (10.175.104.212) by DGGEMS404-HUB.china.huawei.com (10.3.19.204) with Microsoft SMTP Server id 14.3.439.0; Tue, 5 Nov 2019 17:12:06 +0800 From: Heyi Guo To: , Subject: [RFC v2 06/14] arm/sdei: add system reset callback Date: Tue, 5 Nov 2019 17:10:48 +0800 Message-ID: <20191105091056.9541-7-guoheyi@huawei.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20191105091056.9541-1-guoheyi@huawei.com> References: <20191105091056.9541-1-guoheyi@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.104.212] X-CFilter-Loop: Reflected Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 45.249.212.190 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , Peter Maydell , James Morse , Marc Zyngier , Jingyi Wang , Heyi Guo , wanghaibin.wang@huawei.com, Dave Martin Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" For this is a logical device which is not attached to system bus, we cannot use DeviceClass->reset interface directly. Instead we register our own reset callback to reset SDEI services when system resets. Signed-off-by: Heyi Guo Signed-off-by: Jingyi Wang Cc: Peter Maydell Cc: Dave Martin Cc: Marc Zyngier Cc: Mark Rutland Cc: James Morse --- target/arm/sdei.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/target/arm/sdei.c b/target/arm/sdei.c index 0c0212bfa8..6af4a9044b 100644 --- a/target/arm/sdei.c +++ b/target/arm/sdei.c @@ -1147,6 +1147,26 @@ static void qemu_sde_init(QemuSDEState *s) qemu_private_sde_init(s); } =20 +static void qemu_sde_reset(void *opaque) +{ + int64_t ret =3D 0; + CPUState *cs; + QemuSDEState *s =3D opaque; + + CPU_FOREACH(cs) { + QemuSDECpu *sde_cpu =3D get_sde_cpu(s, cs); + ret |=3D sdei_private_reset_common(s, cs, true); + sde_cpu->masked =3D true; + sde_cpu->critical_running_event =3D SDEI_INVALID_EVENT_ID; + sde_cpu->normal_running_event =3D SDEI_INVALID_EVENT_ID; + } + + ret |=3D sdei_shared_reset_common(s, first_cpu, true); + if (ret) { + error_report("SDEI system reset failed: 0x%lx", ret); + } +} + static void sde_array_save(QemuSDE **array, int count) { int i; @@ -1299,6 +1319,7 @@ static void sdei_initfn(Object *obj) sde_state =3D s; =20 qemu_sde_init(s); + qemu_register_reset(qemu_sde_reset, s); } =20 static void qemu_sde_class_init(ObjectClass *klass, void *data) --=20 2.19.1 From nobody Sun May 19 00:17:17 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1572945250; cv=none; d=zoho.com; s=zohoarc; b=T7aoYiphahKo6tCCfVRU4GB2gmZdozyV8UDo8EJ6XV3AAKVKl823P4jYOn5vbsr0pcloqxys9Q2GNOjRSaqasWhHSYSfQZC7+DFdmdpf6Q2o93kEJT406w2XuyzAKkAE8+hI3NiY7LH6I+AbjD+HppLtsjwvVZ6TWEjeJMVi+O4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1572945250; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=N5aYYvxLUorAL+XkTxYm0sixUVv1o6wyOafZcsj7tCQ=; b=OTf9y5wnauMNEh8vHctOsXzc7qppgb8ZiTycC0IQPhGDGOXxaFOXr8l7ioABQwnLBxrQ7DGNvM6xNs7sFsf0k7ht6vl1UUQKR5OBed7OcBPayDdzB/fmobDCab5Xj6EnDX+HwSOa5fy0cnaKTTxTJLUyjSikdCwI17iiKhm3sAY= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.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 1572945250372730.411809372246; Tue, 5 Nov 2019 01:14:10 -0800 (PST) Received: from localhost ([::1]:41820 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iRuub-0006w0-KS for importer@patchew.org; Tue, 05 Nov 2019 04:14:05 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:43039) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iRusx-00051t-AF for qemu-devel@nongnu.org; Tue, 05 Nov 2019 04:12:24 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iRusw-0007mn-35 for qemu-devel@nongnu.org; Tue, 05 Nov 2019 04:12:23 -0500 Received: from szxga04-in.huawei.com ([45.249.212.190]:2192 helo=huawei.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iRuss-0007hm-V6; Tue, 05 Nov 2019 04:12:19 -0500 Received: from DGGEMS404-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 2B7146A7B79F7F75ACDF; Tue, 5 Nov 2019 17:12:13 +0800 (CST) Received: from linux-OtBuvb.huawei.com (10.175.104.212) by DGGEMS404-HUB.china.huawei.com (10.3.19.204) with Microsoft SMTP Server id 14.3.439.0; Tue, 5 Nov 2019 17:12:06 +0800 From: Heyi Guo To: , Subject: [RFC v2 07/14] arm/sdei: add support to trigger event by GIC interrupt ID Date: Tue, 5 Nov 2019 17:10:49 +0800 Message-ID: <20191105091056.9541-8-guoheyi@huawei.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20191105091056.9541-1-guoheyi@huawei.com> References: <20191105091056.9541-1-guoheyi@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.104.212] X-CFilter-Loop: Reflected Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 45.249.212.190 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , Peter Maydell , Marc Zyngier , James Morse , Heyi Guo , wanghaibin.wang@huawei.com, Dave Martin Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Add an external interface to trigger an SDEI event bound to an interrupt by providing GIC interrupt ID. Signed-off-by: Heyi Guo Cc: Peter Maydell Cc: Dave Martin Cc: Marc Zyngier Cc: Mark Rutland Cc: James Morse --- target/arm/sdei.c | 37 +++++++++++++++++++++++++++++++++++++ target/arm/sdei.h | 7 +++++++ 2 files changed, 44 insertions(+) diff --git a/target/arm/sdei.c b/target/arm/sdei.c index 6af4a9044b..713ac97775 100644 --- a/target/arm/sdei.c +++ b/target/arm/sdei.c @@ -476,6 +476,28 @@ static int64_t sdei_version(QemuSDEState *s, CPUState = *cs, struct kvm_run *run) (0ULL << SDEI_VERSION_MINOR_SHIFT); } =20 +static bool inject_event(QemuSDEState *s, CPUState *cs, int32_t event, int= irq) +{ + QemuSDE *sde; + + if (event < 0) { + return false; + } + sde =3D get_sde_no_check(s, event, cs); + if (sde->event_id =3D=3D SDEI_INVALID_EVENT_ID) { + put_sde(sde, cs); + return false; + } + if (irq > 0 && sde->prop->interrupt !=3D irq) { + /* Someone unbinds the interrupt! */ + put_sde(sde, cs); + return false; + } + sde->pending =3D true; + dispatch_single(s, sde, cs); + return true; +} + static int64_t unregister_single_sde(QemuSDEState *s, int32_t event, CPUState *cs, bool force) { @@ -1104,6 +1126,21 @@ void sdei_handle_request(CPUState *cs, struct kvm_ru= n *run) } } =20 +bool trigger_sdei_by_irq(int cpu, int irq) +{ + QemuSDEState *s =3D sde_state; + + if (!s || irq >=3D ARRAY_SIZE(s->irq_map)) { + return false; + } + + if (s->irq_map[irq] =3D=3D SDEI_INVALID_EVENT_ID) { + return false; + } + + return inject_event(s, qemu_get_cpu(cpu), s->irq_map[irq], irq); +} + static void sde_array_init(QemuSDE **array, int count) { int i; diff --git a/target/arm/sdei.h b/target/arm/sdei.h index 828f70bbf1..5ecc32d667 100644 --- a/target/arm/sdei.h +++ b/target/arm/sdei.h @@ -31,4 +31,11 @@ =20 void sdei_handle_request(CPUState *cs, struct kvm_run *run); =20 +/* + * Trigger an SDEI event bound to an interrupt. + * Return true if event has been triggered successfully. + * Return false if event has not been triggered for some reason. + */ +bool trigger_sdei_by_irq(int cpu, int irq); + #endif --=20 2.19.1 From nobody Sun May 19 00:17:17 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1572945450; cv=none; d=zoho.com; s=zohoarc; b=mIZyvA1lGUMpEuLMoUMzH8r8aDw2D3L1kkk8Ni50whQ1vgTfuSr0gdG+C72vsGp+yX15daDKr7HeqOXtDQcaMITC1FO1PLqscKFEPy62FGIYbNBewrWWLpJe0noPROQfVefaWtdT48ss7va71hJfh5aXytCVgAXIvTaeUzpjjwE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1572945450; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=AU9jnjhnzVC601YSebITylchpDete/uNAu0dhW2S5J4=; b=X4/sDhmq2DTTkvJHuEBLaWCHYh4AHrU8fzKm/E2mgumpgigCbwF3yuoRaHDzKjnuxfn7OYd/c33IlPdusTyquIouQpSVWSFbneatZ+x0PG2S0v33wA3k+lkhfaAQreLs9JBsqFOFXx/lruAwV+lgnNGZnvTbOBTJ6QURIhxn6ZU= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.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 1572945450416316.48116397178353; Tue, 5 Nov 2019 01:17:30 -0800 (PST) Received: from localhost ([::1]:41874 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iRuxq-0002B6-4F for importer@patchew.org; Tue, 05 Nov 2019 04:17:26 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:43045) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iRusx-00051x-Bx for qemu-devel@nongnu.org; Tue, 05 Nov 2019 04:12:24 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iRusv-0007mM-Sk for qemu-devel@nongnu.org; Tue, 05 Nov 2019 04:12:23 -0500 Received: from szxga04-in.huawei.com ([45.249.212.190]:2191 helo=huawei.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iRuss-0007hi-V5; Tue, 05 Nov 2019 04:12:19 -0500 Received: from DGGEMS404-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 25CF166D1E71EF4D29B8; Tue, 5 Nov 2019 17:12:13 +0800 (CST) Received: from linux-OtBuvb.huawei.com (10.175.104.212) by DGGEMS404-HUB.china.huawei.com (10.3.19.204) with Microsoft SMTP Server id 14.3.439.0; Tue, 5 Nov 2019 17:12:07 +0800 From: Heyi Guo To: , Subject: [RFC v2 08/14] core/irq: add qemu_irq_remove_intercept interface Date: Tue, 5 Nov 2019 17:10:50 +0800 Message-ID: <20191105091056.9541-9-guoheyi@huawei.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20191105091056.9541-1-guoheyi@huawei.com> References: <20191105091056.9541-1-guoheyi@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.104.212] X-CFilter-Loop: Reflected Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 45.249.212.190 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , Peter Maydell , Marc Zyngier , James Morse , Heyi Guo , wanghaibin.wang@huawei.com, Dave Martin Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" We use qemu_irq as the bridge for other qemu modules to switch from irq injection to SDEI event trigger after VM binds the interrupt to SDEI event. We use qemu_irq_intercept_in() to override qemu_irq handler with SDEI event trigger, so we also need a corresponding interface to restore the handler to default one (i.e. ARM GIC). qemu_irq_remove_intercept() is the new interface to do the above job. Signed-off-by: Heyi Guo Cc: Peter Maydell Cc: Dave Martin Cc: Marc Zyngier Cc: Mark Rutland Cc: James Morse --- hw/core/irq.c | 11 +++++++++++ include/hw/irq.h | 8 ++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/hw/core/irq.c b/hw/core/irq.c index 7cc0295d0e..114bce6c21 100644 --- a/hw/core/irq.c +++ b/hw/core/irq.c @@ -145,6 +145,17 @@ void qemu_irq_intercept_in(qemu_irq *gpio_in, qemu_irq= _handler handler, int n) } } =20 +void qemu_irq_remove_intercept(qemu_irq *gpio_in, int n) +{ + int i; + qemu_irq *old_irqs =3D gpio_in[0]->opaque; + for (i =3D 0; i < n; i++) { + gpio_in[i]->handler =3D old_irqs[i]->handler; + gpio_in[i]->opaque =3D old_irqs[i]->opaque; + } + qemu_free_irqs(old_irqs, n); +} + static const TypeInfo irq_type_info =3D { .name =3D TYPE_IRQ, .parent =3D TYPE_OBJECT, diff --git a/include/hw/irq.h b/include/hw/irq.h index fe527f6f51..1af1db93bb 100644 --- a/include/hw/irq.h +++ b/include/hw/irq.h @@ -56,8 +56,12 @@ qemu_irq qemu_irq_split(qemu_irq irq1, qemu_irq irq2); */ qemu_irq *qemu_irq_proxy(qemu_irq **target, int n); =20 -/* For internal use in qtest. Similar to qemu_irq_split, but operating - on an existing vector of qemu_irq. */ +/* + * Similar to qemu_irq_split, but operating on an existing vector of qemu_= irq. + */ void qemu_irq_intercept_in(qemu_irq *gpio_in, qemu_irq_handler handler, in= t n); =20 +/* Restore the irq handler intercepted by qemu_irq_intercept_in() */ +void qemu_irq_remove_intercept(qemu_irq *gpio_in, int n); + #endif --=20 2.19.1 From nobody Sun May 19 00:17:17 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1572945835; cv=none; d=zoho.com; s=zohoarc; b=etWyXy+FtlfZ/Vr2uZ1ig5Q6wQYoZzABDJ3iL21i2sxO4biHyzKbDMbOKrn8EyRHqnrT57EF3UYGA+3pJsIg7fZJir8YkoxRmR2Lb20vN1UpAmCvZGy2mLxwxjuq0su5IA9inuZFFY3VB8TJhW60ukZyxFfuSaCjsE6V8jtN4Sc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1572945835; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=m83ydIVkXTuqODZkul2Ull8iN8M7KLYAE8nT87WFXVc=; b=eaVmBpeMTMuJJKCDr925urbBFvzeebZK/A3os9C1TSl2AiVQh5USx0IwSiSnOBBKfLqpB8aWh42R9487BbrRe+q9+h+qQhVoepdsTmJd2ytzmyJ+PerNi2Urvi1yPC1InOWszcstVZgCggBagyUQU9ldyw6BuZnT5Ky8I2Of7Vk= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.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 1572945835982475.4061738659767; Tue, 5 Nov 2019 01:23:55 -0800 (PST) Received: from localhost ([::1]:41968 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iRv46-0002ZN-Ks for importer@patchew.org; Tue, 05 Nov 2019 04:23:54 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:43224) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iRut1-00059W-UW for qemu-devel@nongnu.org; Tue, 05 Nov 2019 04:12:29 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iRusz-0007q8-WE for qemu-devel@nongnu.org; Tue, 05 Nov 2019 04:12:27 -0500 Received: from szxga07-in.huawei.com ([45.249.212.35]:52158 helo=huawei.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iRusv-0007j7-4L; Tue, 05 Nov 2019 04:12:21 -0500 Received: from DGGEMS404-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 3842331F2AAD5394DB38; Tue, 5 Nov 2019 17:12:18 +0800 (CST) Received: from linux-OtBuvb.huawei.com (10.175.104.212) by DGGEMS404-HUB.china.huawei.com (10.3.19.204) with Microsoft SMTP Server id 14.3.439.0; Tue, 5 Nov 2019 17:12:07 +0800 From: Heyi Guo To: , Subject: [RFC v2 09/14] arm/sdei: override qemu_irq handler when binding interrupt Date: Tue, 5 Nov 2019 17:10:51 +0800 Message-ID: <20191105091056.9541-10-guoheyi@huawei.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20191105091056.9541-1-guoheyi@huawei.com> References: <20191105091056.9541-1-guoheyi@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.104.212] X-CFilter-Loop: Reflected Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 45.249.212.35 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , Peter Maydell , Marc Zyngier , James Morse , Heyi Guo , wanghaibin.wang@huawei.com, Dave Martin Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Override qemu_irq handler to support trigger SDEI event transparently after guest binds interrupt to SDEI event. We don't have good way to get GIC device and to guarantee SDEI device is initialized after GIC, so we search GIC in system bus when the first SDEI request happens or in VMSTATE post_load(). Signed-off-by: Heyi Guo Cc: Peter Maydell Cc: Dave Martin Cc: Marc Zyngier Cc: Mark Rutland Cc: James Morse --- target/arm/sdei.c | 130 +++++++++++++++++++++++++++++++++++++++++- target/arm/sdei_int.h | 3 + 2 files changed, 132 insertions(+), 1 deletion(-) diff --git a/target/arm/sdei.c b/target/arm/sdei.c index 713ac97775..529a06c1f6 100644 --- a/target/arm/sdei.c +++ b/target/arm/sdei.c @@ -88,6 +88,24 @@ static void qemu_sde_cpu_init(QemuSDEState *s) } } =20 +static int gic_int_to_irq(int num_irq, int intid, int cpu) +{ + if (intid >=3D GIC_INTERNAL) { + return intid - GIC_INTERNAL; + } + return num_irq - GIC_INTERNAL + cpu * GIC_INTERNAL + intid; +} + +static int irq_to_gic_int(int num_irq, int irq, int *cpu) +{ + if (irq < num_irq - GIC_INTERNAL) { + return irq + GIC_INTERNAL; + } + irq -=3D num_irq - GIC_INTERNAL; + *cpu =3D irq / GIC_INTERNAL; + return irq % GIC_INTERNAL; +} + static inline QemuSDECpu *get_sde_cpu(QemuSDEState *s, CPUState *cs) { if (cs->cpu_index >=3D s->sdei_max_cpus) { @@ -410,6 +428,74 @@ static void dispatch_cpu(QemuSDEState *s, CPUState *cs= , bool is_critical) } } =20 +static void qemu_sdei_irq_handler(void *opaque, int irq, int level) +{ + int cpu =3D 0; + + irq =3D irq_to_gic_int(sde_state->num_irq, irq, &cpu); + trigger_sdei_by_irq(cpu, irq); +} + +static void override_qemu_irq(QemuSDEState *s, int32_t event, uint32_t int= id) +{ + qemu_irq irq; + QemuSDE *sde; + CPUState *cs; + + /* SPI */ + if (intid >=3D GIC_INTERNAL) { + cs =3D first_cpu; + irq =3D qdev_get_gpio_in(s->gic_dev, + gic_int_to_irq(s->num_irq, intid, 0)); + if (irq) { + qemu_irq_intercept_in(&irq, qemu_sdei_irq_handler, 1); + } + sde =3D get_sde_no_check(s, event, cs); + sde->irq =3D irq; + put_sde(sde, cs); + return; + } + /* PPI */ + CPU_FOREACH(cs) { + irq =3D qdev_get_gpio_in( + s->gic_dev, + gic_int_to_irq(s->num_irq, intid, cs->cpu_index)); + if (irq) { + qemu_irq_intercept_in(&irq, qemu_sdei_irq_handler, 1); + } + sde =3D get_sde_no_check(s, event, cs); + sde->irq =3D irq; + put_sde(sde, cs); + } +} + +static void restore_qemu_irq(QemuSDEState *s, int32_t event, uint32_t inti= d) +{ + QemuSDE *sde; + CPUState *cs; + + /* SPI */ + if (intid >=3D GIC_INTERNAL) { + cs =3D first_cpu; + sde =3D get_sde_no_check(s, event, cs); + if (sde->irq) { + qemu_irq_remove_intercept(&sde->irq, 1); + sde->irq =3D NULL; + } + put_sde(sde, cs); + return; + } + /* PPI */ + CPU_FOREACH(cs) { + sde =3D get_sde_no_check(s, event, cs); + if (sde->irq) { + qemu_irq_remove_intercept(&sde->irq, 1); + sde->irq =3D NULL; + } + put_sde(sde, cs); + } +} + static int32_t sdei_alloc_event_num(QemuSDEState *s, bool is_critical, bool is_shared, int intid) { @@ -443,6 +529,7 @@ static int32_t sdei_alloc_event_num(QemuSDEState *s, bo= ol is_critical, sde_props[index].interrupt =3D intid; sde_props[index].is_shared =3D is_shared; sde_props[index].is_critical =3D is_critical; + override_qemu_irq(s, event, intid); s->irq_map[intid] =3D event; qemu_mutex_unlock(&sde_props[index].lock); qemu_mutex_unlock(&s->sdei_interrupt_bind_lock); @@ -460,6 +547,7 @@ static int32_t sdei_free_event_num_locked(QemuSDEState = *s, QemuSDEProp *prop) return SDEI_DENIED; } =20 + restore_qemu_irq(s, prop->event_id, prop->interrupt); s->irq_map[prop->interrupt] =3D SDEI_INVALID_EVENT_ID; prop->event_id =3D SDEI_INVALID_EVENT_ID; prop->interrupt =3D SDEI_INVALID_INTERRUPT; @@ -992,13 +1080,33 @@ static int64_t sdei_event_pe_unmask(QemuSDEState *s,= CPUState *cs, return SDEI_SUCCESS; } =20 +static int dev_walkerfn(DeviceState *dev, void *opaque) +{ + QemuSDEState *s =3D opaque; + + if (object_dynamic_cast(OBJECT(dev), TYPE_ARM_GICV3_COMMON)) { + GICv3State *gic =3D ARM_GICV3_COMMON(dev); + s->num_irq =3D gic->num_irq; + s->gic_dev =3D dev; + return -1; + } + + if (object_dynamic_cast(OBJECT(dev), TYPE_ARM_GIC_COMMON)) { + GICState *gic =3D ARM_GIC_COMMON(dev); + s->num_irq =3D gic->num_irq; + s->gic_dev =3D dev; + return -1; + } + return 0; +} + static int64_t sdei_event_interrupt_bind(QemuSDEState *s, CPUState *cs, struct kvm_run *run) { uint64_t *args =3D (uint64_t *)(run->hypercall.args); uint32_t intid =3D args[1]; =20 - if (intid < GIC_NR_SGIS || intid >=3D GIC_MAXIRQ) { + if (intid < GIC_NR_SGIS || intid >=3D s->num_irq) { return SDEI_INVALID_PARAMETERS; } return sdei_alloc_event_num(s, false, intid >=3D GIC_INTERNAL, intid); @@ -1112,6 +1220,17 @@ void sdei_handle_request(CPUState *cs, struct kvm_ru= n *run) return; } =20 + if (!sde_state->gic_dev) { + /* Search for ARM GIC device */ + qbus_walk_children(sysbus_get_default(), dev_walkerfn, + NULL, NULL, NULL, sde_state); + if (!sde_state->gic_dev) { + error_report("Cannot find ARM GIC device!"); + run->hypercall.args[0] =3D SDEI_NOT_SUPPORTED; + return; + } + } + if (func_id < SDEI_1_0_FN_BASE || func_id > SDEI_MAX_REQ) { error_report("Invalid SDEI function ID: 0x%x", func_id); run->hypercall.args[0] =3D SDEI_INVALID_PARAMETERS; @@ -1259,11 +1378,20 @@ static int qemu_sdei_post_load(void *opaque, int ve= rsion_id) } } =20 + /* Search for ARM GIC device */ + qbus_walk_children(sysbus_get_default(), dev_walkerfn, + NULL, NULL, NULL, s); + if (!s->gic_dev) { + error_report("Cannot find ARM GIC device!"); + return 0; + } + for (i =3D 0; i < PRIVATE_SLOT_COUNT + SHARED_SLOT_COUNT; i++) { int intid =3D sde_props[i].interrupt; =20 if (intid !=3D SDEI_INVALID_INTERRUPT) { s->irq_map[intid] =3D sde_props[i].event_id; + override_qemu_irq(s, sde_props[i].event_id, intid); } } =20 diff --git a/target/arm/sdei_int.h b/target/arm/sdei_int.h index d3fd7cbc10..a251b04ab5 100644 --- a/target/arm/sdei_int.h +++ b/target/arm/sdei_int.h @@ -63,6 +63,7 @@ typedef struct QemuSDEProp { typedef struct QemuSDE { QemuSDEProp *prop; CPUState *target_cpu; + qemu_irq irq; QemuMutex lock; bool enabled; bool running; @@ -107,9 +108,11 @@ typedef struct QemuSDECpu { =20 typedef struct QemuSDEState { DeviceState parent_obj; + DeviceState *gic_dev; QemuSDEProp sde_props_state[PRIVATE_SLOT_COUNT + SHARED_SLOT_COUNT= ]; QemuSDECpu *sde_cpus; int sdei_max_cpus; + int num_irq; QemuSDE *shared_sde_array[SHARED_SLOT_COUNT]; int32_t irq_map[GIC_MAXIRQ]; QemuMutex sdei_interrupt_bind_lock; --=20 2.19.1 From nobody Sun May 19 00:17:17 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1572945665; cv=none; d=zoho.com; s=zohoarc; b=BMc9yZVzqi2UYq7DBsJKnXM9pW35xEtvwP7KX6enju9Egavnb+EpOrieAR2+qLNNbQUlnA/JYJ2nILnoLUgxtlTER8xx9R4cjqpqls8hgfVEuEtl+vxI05ywYnJfHs3nS+aIBpyk2lX23EYV1Hdj0b7V/bVPAyXc45cAu7PN2Lg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1572945665; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=SjoE/EMlYSagZk96zKDXRypA5wqOc+x9KghfWfGsXlI=; b=crnrSOuLxAjVuZmxks5Q12jUSLKuVcuVfvd9kuvf+YH89y6n12CNTKvrQ2/XezPHNIFCsmzHVTh0nSIikuliLNbu1DHlYyel4CoeyPWI5yfq0obR3+6kcBJBCNbI5K5OW/RoJ7yHO++AOkxUnv/IdJ1FStIMPf2gO6zUr8c9q8E= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.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 1572945665038127.42832093486322; Tue, 5 Nov 2019 01:21:05 -0800 (PST) Received: from localhost ([::1]:41908 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iRv1H-0006Vs-1h for importer@patchew.org; Tue, 05 Nov 2019 04:20:59 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:43160) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iRusz-00055N-Qy for qemu-devel@nongnu.org; Tue, 05 Nov 2019 04:12:27 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iRusy-0007ol-9S for qemu-devel@nongnu.org; Tue, 05 Nov 2019 04:12:25 -0500 Received: from szxga07-in.huawei.com ([45.249.212.35]:52082 helo=huawei.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iRusv-0007j4-1U; Tue, 05 Nov 2019 04:12:21 -0500 Received: from DGGEMS404-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 2C00798C75144E635ABB; Tue, 5 Nov 2019 17:12:18 +0800 (CST) Received: from linux-OtBuvb.huawei.com (10.175.104.212) by DGGEMS404-HUB.china.huawei.com (10.3.19.204) with Microsoft SMTP Server id 14.3.439.0; Tue, 5 Nov 2019 17:12:08 +0800 From: Heyi Guo To: , Subject: [RFC v2 10/14] arm/sdei: add support to register interrupt bind notifier Date: Tue, 5 Nov 2019 17:10:52 +0800 Message-ID: <20191105091056.9541-11-guoheyi@huawei.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20191105091056.9541-1-guoheyi@huawei.com> References: <20191105091056.9541-1-guoheyi@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.104.212] X-CFilter-Loop: Reflected Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 45.249.212.35 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , Peter Maydell , Marc Zyngier , James Morse , Heyi Guo , wanghaibin.wang@huawei.com, Dave Martin Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Other qemu modules related with the interrupt bind operation may want to be notified when guest requests to bind interrupt to sdei event, so we add register and unregister interfaces. Signed-off-by: Heyi Guo Cc: Peter Maydell Cc: Dave Martin Cc: Marc Zyngier Cc: Mark Rutland Cc: James Morse --- target/arm/sdei.c | 48 +++++++++++++++++++++++++++++++++++++++++++++++ target/arm/sdei.h | 17 +++++++++++++++++ 2 files changed, 65 insertions(+) diff --git a/target/arm/sdei.c b/target/arm/sdei.c index 529a06c1f6..4cc68e4acf 100644 --- a/target/arm/sdei.c +++ b/target/arm/sdei.c @@ -48,6 +48,52 @@ =20 static QemuSDEState *sde_state; =20 +typedef struct QemuSDEIBindNotifyEntry { + QTAILQ_ENTRY(QemuSDEIBindNotifyEntry) entry; + QemuSDEIBindNotify *func; + void *opaque; + int irq; +} QemuSDEIBindNotifyEntry; + +static QTAILQ_HEAD(, QemuSDEIBindNotifyEntry) bind_notifiers =3D + QTAILQ_HEAD_INITIALIZER(bind_notifiers); + +void qemu_register_sdei_bind_notifier(QemuSDEIBindNotify *func, + void *opaque, int irq) +{ + QemuSDEIBindNotifyEntry *be =3D g_new0(QemuSDEIBindNotifyEntry, 1); + + be->func =3D func; + be->opaque =3D opaque; + be->irq =3D irq; + QTAILQ_INSERT_TAIL(&bind_notifiers, be, entry); +} + +void qemu_unregister_sdei_bind_notifier(QemuSDEIBindNotify *func, + void *opaque, int irq) +{ + QemuSDEIBindNotifyEntry *be; + + QTAILQ_FOREACH(be, &bind_notifiers, entry) { + if (be->func =3D=3D func && be->opaque =3D=3D opaque && be->irq = =3D=3D irq) { + QTAILQ_REMOVE(&bind_notifiers, be, entry); + g_free(be); + return; + } + } +} + +static void sdei_notify_bind(int irq, int32_t event, bool bind) +{ + QemuSDEIBindNotifyEntry *be, *nbe; + + QTAILQ_FOREACH_SAFE(be, &bind_notifiers, entry, nbe) { + if (be->irq =3D=3D irq) { + be->func(be->opaque, irq, event, bind); + } + } +} + static void qemu_sde_prop_init(QemuSDEState *s) { QemuSDEProp *sde_props =3D s->sde_props_state; @@ -529,6 +575,7 @@ static int32_t sdei_alloc_event_num(QemuSDEState *s, bo= ol is_critical, sde_props[index].interrupt =3D intid; sde_props[index].is_shared =3D is_shared; sde_props[index].is_critical =3D is_critical; + sdei_notify_bind(intid, event, true); override_qemu_irq(s, event, intid); s->irq_map[intid] =3D event; qemu_mutex_unlock(&sde_props[index].lock); @@ -547,6 +594,7 @@ static int32_t sdei_free_event_num_locked(QemuSDEState = *s, QemuSDEProp *prop) return SDEI_DENIED; } =20 + sdei_notify_bind(prop->interrupt, prop->event_id, false); restore_qemu_irq(s, prop->event_id, prop->interrupt); s->irq_map[prop->interrupt] =3D SDEI_INVALID_EVENT_ID; prop->event_id =3D SDEI_INVALID_EVENT_ID; diff --git a/target/arm/sdei.h b/target/arm/sdei.h index 5ecc32d667..9c15cf3186 100644 --- a/target/arm/sdei.h +++ b/target/arm/sdei.h @@ -38,4 +38,21 @@ void sdei_handle_request(CPUState *cs, struct kvm_run *r= un); */ bool trigger_sdei_by_irq(int cpu, int irq); =20 +/* + * Notify callback prototype; the argument "bind" tells whether it is a bi= nd + * operation or unbind one. + */ +typedef void QemuSDEIBindNotify(void *opaque, int irq, + int32_t event, bool bind); +/* + * Register a notify callback for a specific interrupt bind operation; the + * client will be both notified by bind and unbind operation. + */ +void qemu_register_sdei_bind_notifier(QemuSDEIBindNotify *func, + void *opaque, int irq); +/* + * Unregister a notify callback for a specific interrupt bind operation. + */ +void qemu_unregister_sdei_bind_notifier(QemuSDEIBindNotify *func, + void *opaque, int irq); #endif --=20 2.19.1 From nobody Sun May 19 00:17:17 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1572945801; cv=none; d=zoho.com; s=zohoarc; b=ZXbdUpwgj0NvKx5QNycwqbS6I9KmWci7qa/97EdqtWCib/5JTOnHE9/NqEuIhFIUuocjUiquJOq+gePl9BA+/7N1rBN57hN9J8S5ZQOagg+drNDXD2aUs2LZN2AB/KQ0no5jpFa0iWSmBBD8IpgLU/1bwDAnr4QEvnzyeVz6I0U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1572945801; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=rhN7RIY4X+CHO3JXVG3arImRdBdmn07zki4ql/ojqMc=; b=ixV0n/G/0iQAXMxDPAzMdehYsz3OtUPFLz871fyo6rPu2jASxZpJm4uAoWRwOPR7uBpBuijPuV6yKu/nJc83FUeva01eQdzSmv6iLO3A+q0a2mw0i3w7dkjE9+1eDpzxHnmpCWRITOxR269dGTR57uTtzpnlgK4Ia12UrIYoks4= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.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 1572945801605802.3854201539162; Tue, 5 Nov 2019 01:23:21 -0800 (PST) Received: from localhost ([::1]:41954 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iRv3X-0001xi-6j for importer@patchew.org; Tue, 05 Nov 2019 04:23:19 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:43186) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iRut0-00056Y-Fq for qemu-devel@nongnu.org; Tue, 05 Nov 2019 04:12:27 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iRusz-0007pK-0S for qemu-devel@nongnu.org; Tue, 05 Nov 2019 04:12:26 -0500 Received: from szxga07-in.huawei.com ([45.249.212.35]:52212 helo=huawei.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iRusv-0007jC-6m; Tue, 05 Nov 2019 04:12:21 -0500 Received: from DGGEMS404-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 45AA184DA50D9691C0CB; Tue, 5 Nov 2019 17:12:18 +0800 (CST) Received: from linux-OtBuvb.huawei.com (10.175.104.212) by DGGEMS404-HUB.china.huawei.com (10.3.19.204) with Microsoft SMTP Server id 14.3.439.0; Tue, 5 Nov 2019 17:12:09 +0800 From: Heyi Guo To: , Subject: [RFC v2 11/14] linux-headers/kvm.h: add capability to forward hypercall Date: Tue, 5 Nov 2019 17:10:53 +0800 Message-ID: <20191105091056.9541-12-guoheyi@huawei.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20191105091056.9541-1-guoheyi@huawei.com> References: <20191105091056.9541-1-guoheyi@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.104.212] X-CFilter-Loop: Reflected Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 45.249.212.35 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , Peter Maydell , "Michael S. Tsirkin" , Marc Zyngier , Cornelia Huck , James Morse , Paolo Bonzini , Heyi Guo , wanghaibin.wang@huawei.com, Dave Martin Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" To keep backward compatibility, we add new KVM capability "KVM_CAP_FORWARD_HYPERCALL" to probe whether KVM supports forwarding hypercall to userspace. The capability should be enabled explicitly, for we don't want user space application to deal with unexpected hypercall exits. After enabling this cap, all HVC calls unhandled by kvm will be forwarded to user space. Signed-off-by: Heyi Guo Cc: Peter Maydell Cc: "Michael S. Tsirkin" Cc: Cornelia Huck Cc: Paolo Bonzini Cc: Dave Martin Cc: Marc Zyngier Cc: Mark Rutland Cc: James Morse --- linux-headers/linux/kvm.h | 1 + target/arm/sdei.c | 16 ++++++++++++++++ target/arm/sdei.h | 2 ++ 3 files changed, 19 insertions(+) diff --git a/linux-headers/linux/kvm.h b/linux-headers/linux/kvm.h index 3d9b18f7f8..36c9b3859f 100644 --- a/linux-headers/linux/kvm.h +++ b/linux-headers/linux/kvm.h @@ -1000,6 +1000,7 @@ struct kvm_ppc_resize_hpt { #define KVM_CAP_PMU_EVENT_FILTER 173 #define KVM_CAP_ARM_IRQ_LINE_LAYOUT_2 174 #define KVM_CAP_HYPERV_DIRECT_TLBFLUSH 175 +#define KVM_CAP_FORWARD_HYPERCALL 176 =20 #ifdef KVM_CAP_IRQ_ROUTING =20 diff --git a/target/arm/sdei.c b/target/arm/sdei.c index 4cc68e4acf..56e6874f6f 100644 --- a/target/arm/sdei.c +++ b/target/arm/sdei.c @@ -46,6 +46,7 @@ #define SMCCC_RETURN_REG_COUNT 4 #define PSTATE_M_EL_SHIFT 2 =20 +bool sdei_enabled; static QemuSDEState *sde_state; =20 typedef struct QemuSDEIBindNotifyEntry { @@ -1524,6 +1525,7 @@ static const VMStateDescription vmstate_sde_state =3D= { static void sdei_initfn(Object *obj) { QemuSDEState *s =3D QEMU_SDEI(obj); + KVMState *kvm =3D KVM_STATE(current_machine->accelerator); =20 if (sde_state) { error_report("Only one SDEI dispatcher is allowed!"); @@ -1533,6 +1535,20 @@ static void sdei_initfn(Object *obj) =20 qemu_sde_init(s); qemu_register_reset(qemu_sde_reset, s); + + if (kvm_check_extension(kvm, KVM_CAP_FORWARD_HYPERCALL)) { + int ret; + ret =3D kvm_vm_enable_cap(kvm, KVM_CAP_FORWARD_HYPERCALL, 0, 0); + if (ret < 0) { + error_report("Enable hypercall forwarding failed: %s", + strerror(-ret)); + abort(); + } + sdei_enabled =3D true; + info_report("qemu sdei enabled"); + } else { + info_report("KVM does not support forwarding hypercall."); + } } =20 static void qemu_sde_class_init(ObjectClass *klass, void *data) diff --git a/target/arm/sdei.h b/target/arm/sdei.h index 9c15cf3186..9f683ca2a0 100644 --- a/target/arm/sdei.h +++ b/target/arm/sdei.h @@ -29,6 +29,8 @@ =20 #define SDEI_MAX_REQ SDEI_1_0_FN(0x12) =20 +extern bool sdei_enabled; + void sdei_handle_request(CPUState *cs, struct kvm_run *run); =20 /* --=20 2.19.1 From nobody Sun May 19 00:17:17 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1572945984; cv=none; d=zoho.com; s=zohoarc; b=I7XoH65bNd6IhA5AfsSb97iq/rqND+XV50w93WYNVJoI+DXoFmWKi357rdcn55WNmzruAS733XnQRT3waJMp2ef5NLwWBGB//7bvhwJTIGGpDDyZB5ZEFfQN7w2PLbM+5fs9kCdDEbV0++WBd6e9GpzhXMfCJ4gfPWBzuyPjoIo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1572945984; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=QggT4Lqbfgtos4BbLAvhexjK4dWeaFSxUO6Fvy6V1Z0=; b=Xvi9Udu1S0DKK4CXhwn0H0Om4aEY06Sy6CIzZJ4kTDAGlhpUMv246gLHuOgS2m58feB3PX4bczFEXE52auvllNCGMcYVtUNoMr6A1n6k9PU11OETOql7ELvvS/NR0TtKPmrp09a2VCimSluHmO2bY3JVQNpoi8A6Wv53m7zi5KQ= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.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 1572945984582939.4575062626116; Tue, 5 Nov 2019 01:26:24 -0800 (PST) Received: from localhost ([::1]:42052 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iRv6R-0006QM-4S for importer@patchew.org; Tue, 05 Nov 2019 04:26:19 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:43243) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iRut4-0005Di-4c for qemu-devel@nongnu.org; Tue, 05 Nov 2019 04:12:31 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iRut3-0007vS-07 for qemu-devel@nongnu.org; Tue, 05 Nov 2019 04:12:30 -0500 Received: from szxga06-in.huawei.com ([45.249.212.32]:46998 helo=huawei.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iRusv-0007jH-EP; Tue, 05 Nov 2019 04:12:21 -0500 Received: from DGGEMS404-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 5C10D599D2752F64CED6; Tue, 5 Nov 2019 17:12:18 +0800 (CST) Received: from linux-OtBuvb.huawei.com (10.175.104.212) by DGGEMS404-HUB.china.huawei.com (10.3.19.204) with Microsoft SMTP Server id 14.3.439.0; Tue, 5 Nov 2019 17:12:10 +0800 From: Heyi Guo To: , Subject: [RFC v2 12/14] arm/sdei: add stub to fix build failure when SDEI is not enabled Date: Tue, 5 Nov 2019 17:10:54 +0800 Message-ID: <20191105091056.9541-13-guoheyi@huawei.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20191105091056.9541-1-guoheyi@huawei.com> References: <20191105091056.9541-1-guoheyi@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.104.212] X-CFilter-Loop: Reflected Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 45.249.212.32 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , Peter Maydell , Marc Zyngier , James Morse , Heyi Guo , wanghaibin.wang@huawei.com, Dave Martin Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Signed-off-by: Heyi Guo Cc: Peter Maydell Cc: Dave Martin Cc: Marc Zyngier Cc: Mark Rutland Cc: James Morse --- target/arm/Makefile.objs | 2 ++ target/arm/sdei-stub.c | 49 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 target/arm/sdei-stub.c diff --git a/target/arm/Makefile.objs b/target/arm/Makefile.objs index 72e01d08dc..90235af8ec 100644 --- a/target/arm/Makefile.objs +++ b/target/arm/Makefile.objs @@ -12,6 +12,8 @@ obj-$(call land,$(CONFIG_KVM),$(TARGET_AARCH64)) +=3D kvm= 64.o obj-$(call lnot,$(CONFIG_KVM)) +=3D kvm-stub.o =20 obj-$(CONFIG_SDEI) +=3D sdei.o +obj-$(call lnot,$(CONFIG_SDEI)) +=3D sdei-stub.o + =20 DECODETREE =3D $(SRC_PATH)/scripts/decodetree.py =20 diff --git a/target/arm/sdei-stub.c b/target/arm/sdei-stub.c new file mode 100644 index 0000000000..4eaf365de7 --- /dev/null +++ b/target/arm/sdei-stub.c @@ -0,0 +1,49 @@ +/* + * QEMU ARM SDEI specific function stubs + * + * Copyright (c) Huawei Technologies Co., Ltd. 2019. All rights reserved. + * + * Author: Heyi Guo + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + * + */ + +#include "qemu/osdep.h" +#include "sdei.h" + +bool sdei_enabled; + +void sdei_handle_request(CPUState *cs, struct kvm_run *run) +{ + run->hypercall.args[0] =3D SDEI_NOT_SUPPORTED; + return; +} + +/* + * Trigger an SDEI event bound to an interrupt. + * Return true if event has been triggered successfully. + * Return false if event has not been triggered for some reason. + */ +bool trigger_sdei_by_irq(int cpu, int irq) +{ + return false; +} + +/* + * Register a notify callback for a specific interrupt bind operation; the + * client will be both notified by bind and unbind operation. + */ +void qemu_register_sdei_bind_notifier(QemuSDEIBindNotify *func, + void *opaque, int irq) +{ +} + +/* + * Unregister a notify callback for a specific interrupt bind operation. + */ +void qemu_unregister_sdei_bind_notifier(QemuSDEIBindNotify *func, + void *opaque, int irq) +{ +} --=20 2.19.1 From nobody Sun May 19 00:17:17 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1572945672; cv=none; d=zoho.com; s=zohoarc; b=HIPNVuZthM1i72j3n93EjsB2UGMReNnZwIN2RDU9zdxix/nglOsx+q818ab7aqaRyGV0qEZMhw+k4PttQ4C6H6g52upuMPjeU2riVH8COnnejEMym+CaSDHhlmqSN9Gm/5QcV4+boRrFN470TINmUB+1QuGN6NoxrGNu1OsRaMc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1572945672; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=4+uEM3DIa1rW1u97g/gZy2oMIMYGNDAXHAc0JkDtiZM=; b=Ri/NfbuMYFXk+/BqO0SuRP0Uki+nfSitrz/kWH66aCu8dBENokr3Kw4ZFk2dGqzNHXyGv3wu1nrbyRVLvj2CyIS1Zgha7j9uPXpzgH7t86tyBYrg05w1xmty+xGP4I1AAq5GjHPKTBw+Oz9LkbmCYfG6R0EkTHzMqacdY5bfDuc= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.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 1572945672131287.2701691198878; Tue, 5 Nov 2019 01:21:12 -0800 (PST) Received: from localhost ([::1]:41912 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iRv1R-0006mn-MB for importer@patchew.org; Tue, 05 Nov 2019 04:21:09 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:43179) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iRut0-000568-5p for qemu-devel@nongnu.org; Tue, 05 Nov 2019 04:12:27 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iRusz-0007pP-0s for qemu-devel@nongnu.org; Tue, 05 Nov 2019 04:12:26 -0500 Received: from szxga07-in.huawei.com ([45.249.212.35]:52116 helo=huawei.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iRusv-0007j8-79; Tue, 05 Nov 2019 04:12:21 -0500 Received: from DGGEMS404-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 3294EB169FFE9A49559A; Tue, 5 Nov 2019 17:12:18 +0800 (CST) Received: from linux-OtBuvb.huawei.com (10.175.104.212) by DGGEMS404-HUB.china.huawei.com (10.3.19.204) with Microsoft SMTP Server id 14.3.439.0; Tue, 5 Nov 2019 17:12:10 +0800 From: Heyi Guo To: , Subject: [RFC v2 13/14] arm/kvm: handle guest exit of hypercall Date: Tue, 5 Nov 2019 17:10:55 +0800 Message-ID: <20191105091056.9541-14-guoheyi@huawei.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20191105091056.9541-1-guoheyi@huawei.com> References: <20191105091056.9541-1-guoheyi@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.104.212] X-CFilter-Loop: Reflected Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 45.249.212.35 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , Peter Maydell , Marc Zyngier , James Morse , Heyi Guo , wanghaibin.wang@huawei.com, Dave Martin Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Add support to handle guest exit of hypercall, and forward to SDEI dispatcher if SDEI is enabled and it is an SDEI request. Signed-off-by: Heyi Guo Cc: Peter Maydell Cc: Dave Martin Cc: Marc Zyngier Cc: Mark Rutland Cc: James Morse --- target/arm/kvm.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/target/arm/kvm.c b/target/arm/kvm.c index b473c63edb..035a39e49f 100644 --- a/target/arm/kvm.c +++ b/target/arm/kvm.c @@ -30,6 +30,7 @@ #include "hw/boards.h" #include "hw/irq.h" #include "qemu/log.h" +#include "sdei.h" =20 const KVMCapabilityInfo kvm_arch_required_capabilities[] =3D { KVM_CAP_LAST_INFO @@ -676,6 +677,19 @@ MemTxAttrs kvm_arch_post_run(CPUState *cs, struct kvm_= run *run) } =20 =20 +static void kvm_arm_handle_hypercall(CPUState *cs, struct kvm_run *run) +{ + uint32_t func_id =3D run->hypercall.args[0]; + + if (sdei_enabled && + func_id >=3D SDEI_1_0_FN_BASE && func_id <=3D SDEI_MAX_REQ) { + sdei_handle_request(cs, run); + return; + } + + run->hypercall.args[0] =3D -1; +} + int kvm_arch_handle_exit(CPUState *cs, struct kvm_run *run) { int ret =3D 0; @@ -686,6 +700,9 @@ int kvm_arch_handle_exit(CPUState *cs, struct kvm_run *= run) ret =3D EXCP_DEBUG; } /* otherwise return to guest */ break; + case KVM_EXIT_HYPERCALL: + kvm_arm_handle_hypercall(cs, run); + break; default: qemu_log_mask(LOG_UNIMP, "%s: un-handled exit reason %d\n", __func__, run->exit_reason); --=20 2.19.1 From nobody Sun May 19 00:17:17 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1572945273; cv=none; d=zoho.com; s=zohoarc; b=ArG4pxzNTn3VwpemdI/RryAuVxaMxBpuP9K9/Cjgpwabat31UpGbsmdx5oLmfT0iHG2nQoPA42VuAbbISkT9Vx0jY0mBsa9c+xuq/TlrSjX35L5fOdm6JYCzp8X6VzQC/Ki79guX92mom3FCzCArEeEMy7ocOHhfo7B6q0FuJaE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1572945273; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Hg7fHwdSTHIuAU2yB8E8nYFrDn7wpuBhej4NYXlrNe4=; b=NLlQaSBggXwjkRb6vJWy9frIhPDT+KiKUF4Pbq+2w8y/uXjOuIMlkmI0Qs/u+cUr0l/gzFFIoUKi441pT68I71GRuv5pT04Dg1GTwGFx00uVutFyw2VaZDB8SudasJfHrA103bws96+1xg6lBRAnoOMBxKaZrgcyKyz/0h3a4GY= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.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 15729452731491018.6694767645361; Tue, 5 Nov 2019 01:14:33 -0800 (PST) Received: from localhost ([::1]:41824 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iRuv1-0007bj-PE for importer@patchew.org; Tue, 05 Nov 2019 04:14:31 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:43182) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iRut0-00056M-BU for qemu-devel@nongnu.org; Tue, 05 Nov 2019 04:12:27 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iRusy-0007pB-Ni for qemu-devel@nongnu.org; Tue, 05 Nov 2019 04:12:26 -0500 Received: from szxga07-in.huawei.com ([45.249.212.35]:52204 helo=huawei.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iRusv-0007j9-6e; Tue, 05 Nov 2019 04:12:21 -0500 Received: from DGGEMS404-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 3F328DAA120616D688B8; Tue, 5 Nov 2019 17:12:18 +0800 (CST) Received: from linux-OtBuvb.huawei.com (10.175.104.212) by DGGEMS404-HUB.china.huawei.com (10.3.19.204) with Microsoft SMTP Server id 14.3.439.0; Tue, 5 Nov 2019 17:12:11 +0800 From: Heyi Guo To: , Subject: [RFC v2 14/14] virt/acpi: add SDEI table if SDEI is enabled Date: Tue, 5 Nov 2019 17:10:56 +0800 Message-ID: <20191105091056.9541-15-guoheyi@huawei.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20191105091056.9541-1-guoheyi@huawei.com> References: <20191105091056.9541-1-guoheyi@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.104.212] X-CFilter-Loop: Reflected Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 45.249.212.35 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , Peter Maydell , "Michael S. Tsirkin" , Marc Zyngier , Shannon Zhao , James Morse , Igor Mammedov , Heyi Guo , wanghaibin.wang@huawei.com, Dave Martin Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Add SDEI table if SDEI is enabled, so that guest OS can get aware and utilize the interfaces. Signed-off-by: Heyi Guo Cc: Peter Maydell Cc: Dave Martin Cc: Marc Zyngier Cc: Mark Rutland Cc: James Morse Cc: Shannon Zhao Cc: "Michael S. Tsirkin" Cc: Igor Mammedov --- Notes: v2: - Drop SDEI table definition and add comments hw/arm/virt-acpi-build.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/hw/arm/virt-acpi-build.c b/hw/arm/virt-acpi-build.c index 4cd50175e0..73d3f8cd15 100644 --- a/hw/arm/virt-acpi-build.c +++ b/hw/arm/virt-acpi-build.c @@ -32,6 +32,7 @@ #include "trace.h" #include "hw/core/cpu.h" #include "target/arm/cpu.h" +#include "target/arm/sdei.h" #include "hw/acpi/acpi-defs.h" #include "hw/acpi/acpi.h" #include "hw/nvram/fw_cfg.h" @@ -475,6 +476,26 @@ build_iort(GArray *table_data, BIOSLinker *linker, Vir= tMachineState *vms) "IORT", table_data->len - iort_start, 0, NULL, NULL); } =20 +/* + * ACPI spec 6.2 Software Delegated Exception Interface (SDEI). + * (Revision 1.0) + * "SDEI" was reserved in ACPI 6.2. See "Links to ACPI-Related Documents" + * (http://uefi.org/acpi) under the heading "Software + * Delegated Exceptions Interface." The definition is under + * "10 Appendix C: ACPI table definitions for SDEI" in the linked document. + * + * This is a dummy table to expose platform SDEI capbility to OS. + */ +static void +build_sdei(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms) +{ + int sdei_start =3D table_data->len; + + (void)acpi_data_push(table_data, sizeof(AcpiTableHeader)); + build_header(linker, table_data, (void *)(table_data->data + sdei_star= t), + "SDEI", table_data->len - sdei_start, 1, NULL, NULL); +} + static void build_spcr(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms) { @@ -825,6 +846,11 @@ void virt_acpi_build(VirtMachineState *vms, AcpiBuildT= ables *tables) acpi_add_table(table_offsets, tables_blob); build_spcr(tables_blob, tables->linker, vms); =20 + if (sdei_enabled) { + acpi_add_table(table_offsets, tables_blob); + build_sdei(tables_blob, tables->linker, vms); + } + if (ms->numa_state->num_nodes > 0) { acpi_add_table(table_offsets, tables_blob); build_srat(tables_blob, tables->linker, vms); --=20 2.19.1