From nobody Fri May 17 09:01:33 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=quicinc.com ARC-Seal: i=1; a=rsa-sha256; t=1697043237; cv=none; d=zohomail.com; s=zohoarc; b=ajlTUNZTx0ufTN75SN+6LdtVew+U+GHbuRopoY7g06WfH6o66QeV+0HgQFcNZwtGMTEhYAh06p/M+aQrshfbIwUUScanhxAaoN/AwLhN4sMoWQS45YFdAPeEnM43daWayiP4hUtolxOzJE4+GOTEni5qdZ9NaqKo/ZwmZ+Zck8c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1697043237; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=48LMkArQrrk8xV0fYkkJ1i/85hu8dWonlWcx7vH/4DQ=; b=Jd5V0nN/bubav0qqIex5iWDu15DCHslonArWnTzyqz3NPWYJJy2tqs3KFzgLHLSlkh1K/DT+2nJzhw+eaYkrepHRy+AXsL+kAF5On7HX9FJ1Qppk0L9SmvVkhRiqBecOwCu3Ndj0ow9n2+6QUj7kI6dh1jNpfLG7YFGTBqqeqP4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1697043237798501.17619290854543; Wed, 11 Oct 2023 09:53:57 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qqcSF-0008WO-IG; Wed, 11 Oct 2023 12:53:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qqcSD-0008Vw-5B; Wed, 11 Oct 2023 12:53:01 -0400 Received: from mx0a-0031df01.pphosted.com ([205.220.168.131]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qqcSB-00010A-Av; Wed, 11 Oct 2023 12:53:00 -0400 Received: from pps.filterd (m0279863.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39BCKirn002889; Wed, 11 Oct 2023 16:52:53 GMT Received: from nalasppmta03.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3tnqh1hbbk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 11 Oct 2023 16:52:53 +0000 Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA03.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 39BGqqco005632 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 11 Oct 2023 16:52:52 GMT Received: from blr-ubuntu-31.qualcomm.com (10.80.80.8) by nalasex01b.na.qualcomm.com (10.47.209.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.36; Wed, 11 Oct 2023 09:52:48 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=qcppdkim1; bh=48LMkArQrrk8xV0fYkkJ1i/85hu8dWonlWcx7vH/4DQ=; b=kheVdQn9uxN0cFs1mQeHLT2ALg4x+gWCvC+RF6pguzXcQyvbszI+OZfmyxy/Ed7lnmgu NqBrnh9W16UFAU6dn1N9A+5YgfzJ36nGkRmnU1dcbyQBsLzx+tN2fmySpH5DWFdja6CL xT5Kg9DFhCaqJE7/M9jIrfqJN+OCH3nkzZiNGdJqqlAHrd3dgVI4H3fW5JlDsmH6x2wb 6dZ+sG5YWxuvi6AwzIB65Jek3Tnqz2WSzPx85uTK+sj2VpBsQNc4toNVSPkK23CTBlhC yD2r+Jy1/qRKCdr2ZEyL2v4hTqk4QfcMtJ8zCsiJOphbJxOOzh71h39fAhCvMOTAtzvv Qg== From: Srivatsa Vaddagiri To: , , , CC: , , , , , , Subject: [RFC/PATCH v0 01/12] hw/arm/virt: Avoid NULL pointer de-reference Date: Wed, 11 Oct 2023 16:52:23 +0000 Message-ID: <20231011165234.1323725-2-quic_svaddagi@quicinc.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231011165234.1323725-1-quic_svaddagi@quicinc.com> References: <20231011165234.1323725-1-quic_svaddagi@quicinc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.80.80.8] X-ClientProxiedBy: nasanex01a.na.qualcomm.com (10.52.223.231) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: U8w0dNK3NP7TWlZx3ktvX9aTNd9d9kIf X-Proofpoint-ORIG-GUID: U8w0dNK3NP7TWlZx3ktvX9aTNd9d9kIf X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-11_12,2023-10-11_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 phishscore=0 spamscore=0 bulkscore=0 clxscore=1015 lowpriorityscore=0 mlxlogscore=692 mlxscore=0 priorityscore=1501 adultscore=0 malwarescore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310110148 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=205.220.168.131; envelope-from=quic_svaddagi@quicinc.com; helo=mx0a-0031df01.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @quicinc.com) X-ZM-MESSAGEID: 1697043239232100007 Content-Type: text/plain; charset="utf-8" Avoid dereferencing a NULL pointer that its_class_name() could return. Signed-off-by: Srivatsa Vaddagiri --- hw/arm/virt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/arm/virt.c b/hw/arm/virt.c index a13c658bbf..b55d5c7282 100644 --- a/hw/arm/virt.c +++ b/hw/arm/virt.c @@ -661,7 +661,7 @@ static void create_its(VirtMachineState *vms) const char *itsclass =3D its_class_name(); DeviceState *dev; =20 - if (!strcmp(itsclass, "arm-gicv3-its")) { + if (itsclass && !strcmp(itsclass, "arm-gicv3-its")) { if (!vms->tcg_its) { itsclass =3D NULL; } --=20 2.25.1 From nobody Fri May 17 09:01:33 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=quicinc.com ARC-Seal: i=1; a=rsa-sha256; t=1697043237; cv=none; d=zohomail.com; s=zohoarc; b=HqUPQDG5j/f766eUV8xd5DpYn4OfTEF1+jsz/yZt+zFxzYgChHPJAce2RaIIlBcrwm5S0/fwV8veiXAwDq8StcPuKrDS/5vkVIh0dM/fRzySgz04LOgPjff7Pn9v0X0Tlm3YP9EVLbI0AKc8T7lr4loMV5074KlYPYYH9bI5D0o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1697043237; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=2JSokJnhuWURT+69RXdic8xep5tE2/ofwS5+aAyzZU4=; b=RQAiJZ7ffTyx6gCiB+8fVmWmEcQU2uq5K6uiQoUXlrPt24/Rj/mlOIpI85nJ8OL+Mo5UqKSX5XsOrzWpsvAA/jFexppRJqTbYopaxpQ6EoPydBKEznCxhSnUV3JgHIq2wAyOtXF0f8PSgiCu1pNpP0MNcaP1bJrvl0G8j+tB84k= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1697043237527971.6371051389914; Wed, 11 Oct 2023 09:53:57 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qqcSH-000059-H5; Wed, 11 Oct 2023 12:53:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qqcSD-0008Vv-1k; Wed, 11 Oct 2023 12:53:01 -0400 Received: from mx0b-0031df01.pphosted.com ([205.220.180.131]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qqcSB-00010E-6S; Wed, 11 Oct 2023 12:53:00 -0400 Received: from pps.filterd (m0279870.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39BFrAjL032370; Wed, 11 Oct 2023 16:52:57 GMT Received: from nalasppmta02.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3tnsmq13np-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 11 Oct 2023 16:52:57 +0000 Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA02.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 39BGquIN007793 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 11 Oct 2023 16:52:56 GMT Received: from blr-ubuntu-31.qualcomm.com (10.80.80.8) by nalasex01b.na.qualcomm.com (10.47.209.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.36; Wed, 11 Oct 2023 09:52:52 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=qcppdkim1; bh=2JSokJnhuWURT+69RXdic8xep5tE2/ofwS5+aAyzZU4=; b=jEMHShzfrDk+wnb55pobYuophUxp3QSri5PLBZIEMYkAp5OdO45uaa63iR3s2HnGEUhv mzwYeXNGHFxO2Qu6AXiEmZHe13dfnUbhBTxsGJlYpOkFLBr9qlkdGY4q1WX7cJ985D0m 4GVIYKsTqmxfzgXYlkAtyzmx3QESWl9LHQdliiU65DsI20BcLwyjEHrgkEZBBnhWh6J8 MLTR6rwt7yik/h/jC3aIHGTswOWko2/P/7LYJo/7S0jMKc0vBKbrzUMCDtp7fZk5rHAG 84WtPBGf+RO9WxUDEtAvuR/G9lmVRjJbUEApdUQKDs6v9hYEeiRTKAbctNVk98NThvvD 0g== From: Srivatsa Vaddagiri To: , , , CC: , , , , , , Subject: [RFC/PATCH v0 02/12] update-linux-headers: Include gunyah.h Date: Wed, 11 Oct 2023 16:52:24 +0000 Message-ID: <20231011165234.1323725-3-quic_svaddagi@quicinc.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231011165234.1323725-1-quic_svaddagi@quicinc.com> References: <20231011165234.1323725-1-quic_svaddagi@quicinc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.80.80.8] X-ClientProxiedBy: nasanex01a.na.qualcomm.com (10.52.223.231) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: BqnsfLi9u9yYt7hIm4s6X9wmoCJ7PmTP X-Proofpoint-ORIG-GUID: BqnsfLi9u9yYt7hIm4s6X9wmoCJ7PmTP X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-11_12,2023-10-11_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 phishscore=0 mlxlogscore=999 lowpriorityscore=0 adultscore=0 priorityscore=1501 impostorscore=0 spamscore=0 bulkscore=0 clxscore=1015 mlxscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310110148 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=205.220.180.131; envelope-from=quic_svaddagi@quicinc.com; helo=mx0b-0031df01.pphosted.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @quicinc.com) X-ZM-MESSAGEID: 1697043239133100005 Content-Type: text/plain; charset="utf-8" gunyah.h containts UAPI definitions exported by Gunyah Linux kernel driver. This file will be referenced by Gunyah accelerator driver in Qemu. Note: Gunyah Linux kernel driver is not yet merged in Linux kernel. v14 of the patch series has been posted on mailing lists. https://lore.kernel.org/lkml/20230613172054.3959700-1-quic_eberman@quicinc.= com/ One of the subsequent versions of the patch is expected to be merged upstream soon, after this this change to 'update-linux-headers' can be run against the main Linux kernel source repository from kernel.org. In the meantime, a version of Gunyah kernel driver is available in Android kernel repository, against which this change can be run. https://android.googlesource.com/kernel/common Branch: android14-6.1 Signed-off-by: Srivatsa Vaddagiri Reviewed-by: Alex Benn=C3=A9e --- scripts/update-linux-headers.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/update-linux-headers.sh b/scripts/update-linux-headers= .sh index 35a64bb501..3f3608bcbe 100755 --- a/scripts/update-linux-headers.sh +++ b/scripts/update-linux-headers.sh @@ -161,7 +161,8 @@ done rm -rf "$output/linux-headers/linux" mkdir -p "$output/linux-headers/linux" for header in const.h stddef.h kvm.h vfio.h vfio_ccw.h vfio_zdev.h vhost.h= \ - psci.h psp-sev.h userfaultfd.h memfd.h mman.h nvme_ioctl.h v= duse.h; do + psci.h psp-sev.h userfaultfd.h memfd.h mman.h nvme_ioctl.h \ + vduse.h gunyah.h; do cp "$tmpdir/include/linux/$header" "$output/linux-headers/linux" done =20 --=20 2.25.1 From nobody Fri May 17 09:01:33 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=quicinc.com ARC-Seal: i=1; a=rsa-sha256; t=1697043249; cv=none; d=zohomail.com; s=zohoarc; b=OdcGZZ6t6hXpTOs+fhx5+/T8LBXQrGEiONHSJkY3t2AHUIxlBrN/15xjwv3ybw4Cg8B+PWBTr5fGsqw9I2IiaIicId+Ygovg56N4Bl5OrRyCbzK36FCVNOuBzSN+SNRWQHnJFF5P2giT0HC7NosxouH3qkaFmj5+/WT+H0u3g6k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1697043249; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=vIY9iQmVxOtCnb003WgKAaSquLhSf0MtJNj5vG0N7VE=; b=HqjgUKVUljPpOI/0fuwNeQo2qxYkdgKIr/LKQbTo6YRqaJSmszBJ/4p8eGNXCCIaaldUGucfFvEwDyFk20CBJfR7Mx/5yvnnNDmhZnSSN0I8HoA6lpUca4441XwjgPW+UooHmu4/8Y/TF/s7IMseSgLWnDoFonSv0qBT/CgJGS8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1697043249767713.2821277639118; Wed, 11 Oct 2023 09:54:09 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qqcSN-00005p-Db; Wed, 11 Oct 2023 12:53:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qqcSI-00005M-9t; Wed, 11 Oct 2023 12:53:06 -0400 Received: from mx0b-0031df01.pphosted.com ([205.220.180.131]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qqcSG-000117-2o; Wed, 11 Oct 2023 12:53:06 -0400 Received: from pps.filterd (m0279869.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39BFrMNf011672; Wed, 11 Oct 2023 16:53:02 GMT Received: from nalasppmta01.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3tnnvw9hh5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 11 Oct 2023 16:53:02 +0000 Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA01.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 39BGr1Zv008046 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 11 Oct 2023 16:53:01 GMT Received: from blr-ubuntu-31.qualcomm.com (10.80.80.8) by nalasex01b.na.qualcomm.com (10.47.209.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.36; Wed, 11 Oct 2023 09:52:56 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=qcppdkim1; bh=vIY9iQmVxOtCnb003WgKAaSquLhSf0MtJNj5vG0N7VE=; b=p1Oo5wYMbkVsnWjd0BC1EiIFaq76eX2f/I7taboChpIfnMHPYOB/Jk7s1TCWBpyO50sT yNi1iJbOZIc/WO6B5Y/g8kG4afCQoBoi6dODkHanxqxAAi8by5rR6Dh/KPy4oUN9mP7x AzEVJAM66lrin2yZUv2G2Ur9BywARQhs6G/jXnVO5PEqpucg3n0i2VrpFweJoB2jM9vN ITyrPPfGa8xuTXzw7RSZpyU1SvlNk1fDnHmFDZI1kPlXOkzzPvaitLtzVswCjhqZkmTB 5e8PvFlOULUGUMXen36M/ImZ7TbT/UVokxL8KJd/qAomULg2QNa3dMPHmxxriY5fQmjY mg== From: Srivatsa Vaddagiri To: , , , CC: , , , , , , Subject: [RFC/PATCH v0 03/12] gunyah: Basic support Date: Wed, 11 Oct 2023 16:52:25 +0000 Message-ID: <20231011165234.1323725-4-quic_svaddagi@quicinc.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231011165234.1323725-1-quic_svaddagi@quicinc.com> References: <20231011165234.1323725-1-quic_svaddagi@quicinc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.80.80.8] X-ClientProxiedBy: nasanex01a.na.qualcomm.com (10.52.223.231) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: NdtPMWSgDDw8rm-VAoSjw4l1_FzRvfOM X-Proofpoint-GUID: NdtPMWSgDDw8rm-VAoSjw4l1_FzRvfOM X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-11_12,2023-10-11_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 mlxscore=0 impostorscore=0 mlxlogscore=939 bulkscore=0 adultscore=0 phishscore=0 clxscore=1015 spamscore=0 priorityscore=1501 malwarescore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310110148 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=205.220.180.131; envelope-from=quic_svaddagi@quicinc.com; helo=mx0b-0031df01.pphosted.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @quicinc.com) X-ZM-MESSAGEID: 1697043251211100006 Content-Type: text/plain; charset="utf-8" Add a new accelerator, gunyah, with basic functionality of creating a VM. Subsequent patches will add support for other functions required to run a VM. Signed-off-by: Srivatsa Vaddagiri --- MAINTAINERS | 7 +++ accel/Kconfig | 3 + accel/gunyah/gunyah-accel-ops.c | 102 ++++++++++++++++++++++++++++++++ accel/gunyah/gunyah-all.c | 70 ++++++++++++++++++++++ accel/gunyah/meson.build | 7 +++ accel/meson.build | 1 + accel/stubs/gunyah-stub.c | 13 ++++ accel/stubs/meson.build | 1 + docs/about/build-platforms.rst | 2 +- hw/arm/virt.c | 3 + include/sysemu/gunyah.h | 43 ++++++++++++++ include/sysemu/gunyah_int.h | 27 +++++++++ meson.build | 9 +++ meson_options.txt | 2 + scripts/meson-buildoptions.sh | 3 + target/arm/cpu64.c | 5 +- 16 files changed, 295 insertions(+), 3 deletions(-) create mode 100644 accel/gunyah/gunyah-accel-ops.c create mode 100644 accel/gunyah/gunyah-all.c create mode 100644 accel/gunyah/meson.build create mode 100644 accel/stubs/gunyah-stub.c create mode 100644 include/sysemu/gunyah.h create mode 100644 include/sysemu/gunyah_int.h diff --git a/MAINTAINERS b/MAINTAINERS index 6111b6b4d9..0e76dda91d 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -510,6 +510,13 @@ F: accel/hvf/ F: include/sysemu/hvf.h F: include/sysemu/hvf_int.h =20 +GUNYAH +M: Srivatsa Vaddagiri +S: Maintained +F: accel/gunyah +F: include/sysemu/gunyah.h +F: include/sysemu/gunyah_int.h + WHPX CPUs M: Sunil Muthuswamy S: Supported diff --git a/accel/Kconfig b/accel/Kconfig index 8bdedb7d15..bab1edebf4 100644 --- a/accel/Kconfig +++ b/accel/Kconfig @@ -19,3 +19,6 @@ config KVM config XEN bool select FSDEV_9P if VIRTFS + +config GUNYAH + bool diff --git a/accel/gunyah/gunyah-accel-ops.c b/accel/gunyah/gunyah-accel-op= s.c new file mode 100644 index 0000000000..1c1c20abf1 --- /dev/null +++ b/accel/gunyah/gunyah-accel-ops.c @@ -0,0 +1,102 @@ +/* + * QEMU Gunyah hypervisor support + * + * (based on KVM accelerator code structure) + * + * Copyright 2008 IBM Corporation + * 2008 Red Hat, Inc. + * + * Copyright(c) 2023 Qualcomm Innovation Center, Inc. All Rights Reserved. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" +#include "qemu/thread.h" +#include "hw/boards.h" +#include "hw/core/cpu.h" +#include "sysemu/accel-ops.h" +#include "sysemu/cpus.h" +#include "sysemu/gunyah.h" +#include "sysemu/gunyah_int.h" +#include "qapi/visitor.h" +#include "qapi/error.h" + +bool gunyah_allowed; + +static int gunyah_init(MachineState *ms) +{ + return gunyah_create_vm(); +} + +static void gunyah_accel_instance_init(Object *obj) +{ + GUNYAHState *s =3D GUNYAH_STATE(obj); + + s->fd =3D -1; + s->vmfd =3D -1; +} + +static void gunyah_accel_class_init(ObjectClass *oc, void *data) +{ + AccelClass *ac =3D ACCEL_CLASS(oc); + + ac->name =3D "GUNYAH"; + ac->init_machine =3D gunyah_init; + ac->allowed =3D &gunyah_allowed; +} + +static const TypeInfo gunyah_accel_type =3D { + .name =3D TYPE_GUNYAH_ACCEL, + .parent =3D TYPE_ACCEL, + .instance_init =3D gunyah_accel_instance_init, + .class_init =3D gunyah_accel_class_init, + .instance_size =3D sizeof(GUNYAHState), +}; + +static void gunyah_type_init(void) +{ + type_register_static(&gunyah_accel_type); +} +type_init(gunyah_type_init); + +static void gunyah_start_vcpu_thread(CPUState *cpu) +{ + char thread_name[VCPU_THREAD_NAME_SIZE]; + + cpu->thread =3D g_malloc0(sizeof(QemuThread)); + cpu->halt_cond =3D g_malloc0(sizeof(QemuCond)); + qemu_cond_init(cpu->halt_cond); + + snprintf(thread_name, VCPU_THREAD_NAME_SIZE, "CPU %d/Gunyah", + cpu->cpu_index); + qemu_thread_create(cpu->thread, thread_name, gunyah_cpu_thread_fn, + cpu, QEMU_THREAD_JOINABLE); +} + +static void gunyah_kick_vcpu_thread(CPUState *cpu) +{ + cpus_kick_thread(cpu); +} + +static void gunyah_accel_ops_class_init(ObjectClass *oc, void *data) +{ + AccelOpsClass *ops =3D ACCEL_OPS_CLASS(oc); + + ops->create_vcpu_thread =3D gunyah_start_vcpu_thread; + ops->kick_vcpu_thread =3D gunyah_kick_vcpu_thread; +}; + +static const TypeInfo gunyah_accel_ops_type =3D { + .name =3D ACCEL_OPS_NAME("gunyah"), + .parent =3D TYPE_ACCEL_OPS, + .class_init =3D gunyah_accel_ops_class_init, + .abstract =3D true, +}; + +static void gunyah_accel_ops_register_types(void) +{ + type_register_static(&gunyah_accel_ops_type); +} + +type_init(gunyah_accel_ops_register_types); diff --git a/accel/gunyah/gunyah-all.c b/accel/gunyah/gunyah-all.c new file mode 100644 index 0000000000..370add75f9 --- /dev/null +++ b/accel/gunyah/gunyah-all.c @@ -0,0 +1,70 @@ +/* + * QEMU Gunyah hypervisor support + * + * (based on KVM accelerator code structure) + * + * Copyright 2008 IBM Corporation + * 2008 Red Hat, Inc. + * + * Copyright(c) 2023 Qualcomm Innovation Center, Inc. All Rights Reserved. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include +#include "qemu/osdep.h" +#include "qemu/typedefs.h" +#include "hw/core/cpu.h" +#include "sysemu/cpus.h" +#include "sysemu/gunyah.h" +#include "sysemu/gunyah_int.h" +#include "linux-headers/linux/gunyah.h" +#include "qemu/error-report.h" + +static int gunyah_ioctl(int type, ...) +{ + void *arg; + va_list ap; + GUNYAHState *s =3D GUNYAH_STATE(current_accel()); + + assert(s->fd); + + va_start(ap, type); + arg =3D va_arg(ap, void *); + va_end(ap); + + return ioctl(s->fd, type, arg); +} + +int gunyah_create_vm(void) +{ + GUNYAHState *s; + + s =3D GUNYAH_STATE(current_accel()); + + s->fd =3D qemu_open_old("/dev/gunyah", O_RDWR); + if (s->fd =3D=3D -1) { + error_report("Could not access Gunyah kernel module at /dev/gunyah= : %s", + strerror(errno)); + exit(1); + } + + s->vmfd =3D gunyah_ioctl(GH_CREATE_VM, 0); + if (s->vmfd < 0) { + error_report("Could not create VM: %s", strerror(errno)); + exit(1); + } + + return 0; +} + +void *gunyah_cpu_thread_fn(void *arg) +{ + CPUState *cpu =3D arg; + + do { + /* Do nothing */ + } while (!cpu->unplug || cpu_can_run(cpu)); + + return NULL; +} diff --git a/accel/gunyah/meson.build b/accel/gunyah/meson.build new file mode 100644 index 0000000000..226eea0f2c --- /dev/null +++ b/accel/gunyah/meson.build @@ -0,0 +1,7 @@ +gunyah_ss =3D ss.source_set() +gunyah_ss.add(files( + 'gunyah-all.c', + 'gunyah-accel-ops.c', +)) + +specific_ss.add_all(when: 'CONFIG_GUNYAH', if_true: gunyah_ss) diff --git a/accel/meson.build b/accel/meson.build index 638a9a03ba..e2b87f74b0 100644 --- a/accel/meson.build +++ b/accel/meson.build @@ -9,6 +9,7 @@ if have_system subdir('kvm') subdir('xen') subdir('stubs') + subdir('gunyah') endif =20 # qtest diff --git a/accel/stubs/gunyah-stub.c b/accel/stubs/gunyah-stub.c new file mode 100644 index 0000000000..d515469c01 --- /dev/null +++ b/accel/stubs/gunyah-stub.c @@ -0,0 +1,13 @@ +/* + * QEMU Gunyah stub + * + * Copyright(c) 2023 Qualcomm Innovation Center, Inc. All Rights Reserved. + * + * SPDX-License-Identifier: GPL-2.0-or-later + * + */ + +#include "sysemu/gunyah.h" +#include "sysemu/gunyah_int.h" + +bool gunyah_allowed; diff --git a/accel/stubs/meson.build b/accel/stubs/meson.build index f7a9486e06..4f594e09de 100644 --- a/accel/stubs/meson.build +++ b/accel/stubs/meson.build @@ -3,5 +3,6 @@ sysemu_stubs_ss.add(when: 'CONFIG_HAX', if_false: files('ha= x-stub.c')) sysemu_stubs_ss.add(when: 'CONFIG_XEN', if_false: files('xen-stub.c')) sysemu_stubs_ss.add(when: 'CONFIG_KVM', if_false: files('kvm-stub.c')) sysemu_stubs_ss.add(when: 'CONFIG_TCG', if_false: files('tcg-stub.c')) +sysemu_stubs_ss.add(when: 'CONFIG_GUNYAH', if_false: files('gunyah-stub.c'= )) =20 specific_ss.add_all(when: ['CONFIG_SYSTEM_ONLY'], if_true: sysemu_stubs_ss) diff --git a/docs/about/build-platforms.rst b/docs/about/build-platforms.rst index 0e2cb9e770..5a3e241f1a 100644 --- a/docs/about/build-platforms.rst +++ b/docs/about/build-platforms.rst @@ -40,7 +40,7 @@ Those hosts are officially supported, with various accele= rators: * - CPU Architecture - Accelerators * - Arm - - kvm (64 bit only), tcg, xen + - kvm (64 bit only), tcg, xen, gunyah (64 bit only) * - MIPS (little endian only) - kvm, tcg * - PPC diff --git a/hw/arm/virt.c b/hw/arm/virt.c index b55d5c7282..4222183eb5 100644 --- a/hw/arm/virt.c +++ b/hw/arm/virt.c @@ -80,6 +80,7 @@ #include "hw/virtio/virtio-iommu.h" #include "hw/char/pl011.h" #include "qemu/guest-random.h" +#include "sysemu/gunyah.h" =20 #define DEFINE_VIRT_MACHINE_LATEST(major, minor, latest) \ static void virt_##major##_##minor##_class_init(ObjectClass *oc, \ @@ -1623,6 +1624,8 @@ static void virt_build_smbios(VirtMachineState *vms) =20 if (kvm_enabled()) { product =3D "KVM Virtual Machine"; + } else if (gunyah_enabled()) { + product =3D "Gunyah Virtual Machine"; } =20 smbios_set_defaults("QEMU", product, diff --git a/include/sysemu/gunyah.h b/include/sysemu/gunyah.h new file mode 100644 index 0000000000..aded49cdf6 --- /dev/null +++ b/include/sysemu/gunyah.h @@ -0,0 +1,43 @@ +/* + * QEMU Gunyah hypervisor support + * + * Copyright(c) 2023 Qualcomm Innovation Center, Inc. All Rights Reserved. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +/* header to be included in non-Gunyah-specific code */ + +#ifndef QEMU_GUNYAH_H +#define QEMU_GUNYAH_H + +#include "qemu/accel.h" +#include "qom/object.h" + +#ifdef NEED_CPU_H +#include "cpu.h" +#ifdef CONFIG_GUNYAH +# define CONFIG_GUNYAH_IS_POSSIBLE +#endif +#else +# define CONFIG_GUNYAH_IS_POSSIBLE +#endif + +#ifdef CONFIG_GUNYAH_IS_POSSIBLE + +extern bool gunyah_allowed; + +#define gunyah_enabled() (gunyah_allowed) + +#define TYPE_GUNYAH_ACCEL ACCEL_CLASS_NAME("gunyah") +typedef struct GUNYAHState GUNYAHState; +DECLARE_INSTANCE_CHECKER(GUNYAHState, GUNYAH_STATE, + TYPE_GUNYAH_ACCEL) + +#else /* CONFIG_GUNYAH_IS_POSSIBLE */ + +#define gunyah_enabled() 0 + +#endif /* CONFIG_GUNYAH_IS_POSSIBLE */ + +#endif /* QEMU_GUNYAH_H */ diff --git a/include/sysemu/gunyah_int.h b/include/sysemu/gunyah_int.h new file mode 100644 index 0000000000..37de628b37 --- /dev/null +++ b/include/sysemu/gunyah_int.h @@ -0,0 +1,27 @@ +/* + * QEMU Gunyah hypervisor support + * + * Copyright(c) 2023 Qualcomm Innovation Center, Inc. All Rights Reserved. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +/* header to be included in Gunyah-specific code */ + +#ifndef GUNYAH_INT_H +#define GUNYAH_INT_H + +#include "qemu/accel.h" +#include "qemu/typedefs.h" + +struct GUNYAHState { + AccelState parent_obj; + + int fd; + int vmfd; +}; + +int gunyah_create_vm(void); +void *gunyah_cpu_thread_fn(void *arg); + +#endif /* GUNYAH_INT_H */ diff --git a/meson.build b/meson.build index 98e68ef0b1..ca46b51c55 100644 --- a/meson.build +++ b/meson.build @@ -136,6 +136,7 @@ if cpu in ['x86', 'x86_64', 'arm', 'aarch64'] # i386 emulator provides xenpv machine type for multiple architectures accelerator_targets +=3D { 'CONFIG_XEN': ['i386-softmmu', 'x86_64-softmmu', 'aarch64-softmmu'], + 'CONFIG_GUNYAH': ['aarch64-softmmu'] } endif if cpu in ['x86', 'x86_64'] @@ -608,6 +609,7 @@ iokit =3D [] emulator_link_args =3D [] nvmm =3Dnot_found hvf =3D not_found +gunyah =3D not_found midl =3D not_found widl =3D not_found pathcch =3D not_found @@ -668,6 +670,9 @@ if get_option('hax').allowed() accelerators +=3D 'CONFIG_HAX' endif endif +if get_option('gunyah').allowed() + accelerators +=3D 'CONFIG_GUNYAH' +endif if targetos =3D=3D 'netbsd' nvmm =3D cc.find_library('nvmm', required: get_option('nvmm')) if nvmm.found() @@ -718,6 +723,9 @@ endif if 'CONFIG_WHPX' not in accelerators and get_option('whpx').enabled() error('WHPX not available on this platform') endif +if 'CONFIG_GUNYAH' not in accelerators and get_option('gunyah').enabled() + error('Gunyah not available on this platform') +endif =20 ################ # Dependencies # @@ -4149,6 +4157,7 @@ if have_system summary_info +=3D {'xen ctrl version': xen.version()} endif summary_info +=3D {'Xen emulation': config_all.has_key('CONFIG_XEN_E= MU')} + summary_info +=3D {'Gunyah support': config_all.has_key('CONFIG_GUNYA= H')} endif summary_info +=3D {'TCG support': config_all.has_key('CONFIG_TCG')} if config_all.has_key('CONFIG_TCG') diff --git a/meson_options.txt b/meson_options.txt index aaea5ddd77..b914f0e853 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -105,6 +105,8 @@ option('dbus_display', type: 'feature', value: 'auto', description: '-display dbus support') option('tpm', type : 'feature', value : 'auto', description: 'TPM support') +option('gunyah', type: 'feature', value: 'auto', + description: 'Gunyah acceleration support') =20 # Do not enable it by default even for Mingw32, because it doesn't # work on Wine. diff --git a/scripts/meson-buildoptions.sh b/scripts/meson-buildoptions.sh index 9da3fe299b..0c95f79645 100644 --- a/scripts/meson-buildoptions.sh +++ b/scripts/meson-buildoptions.sh @@ -112,6 +112,7 @@ meson_options_help() { printf "%s\n" ' guest-agent-msi Build MSI package for the QEMU Guest Ag= ent' printf "%s\n" ' hax HAX acceleration support' printf "%s\n" ' hvf HVF acceleration support' + printf "%s\n" ' gunyah Gunyah acceleration support' printf "%s\n" ' iconv Font glyph conversion support' printf "%s\n" ' jack JACK sound support' printf "%s\n" ' keyring Linux keyring support' @@ -312,6 +313,8 @@ _meson_option_parse() { --disable-guest-agent) printf "%s" -Dguest_agent=3Ddisabled ;; --enable-guest-agent-msi) printf "%s" -Dguest_agent_msi=3Denabled ;; --disable-guest-agent-msi) printf "%s" -Dguest_agent_msi=3Ddisabled ;; + --enable-gunyah) printf "%s" -Dgunyah=3Denabled ;; + --disable-gunyah) printf "%s" -Dgunyah=3Ddisabled ;; --enable-hax) printf "%s" -Dhax=3Denabled ;; --disable-hax) printf "%s" -Dhax=3Ddisabled ;; --enable-hexagon-idef-parser) printf "%s" -Dhexagon_idef_parser=3Dtrue= ;; diff --git a/target/arm/cpu64.c b/target/arm/cpu64.c index 96158093cc..a712f1a3b3 100644 --- a/target/arm/cpu64.c +++ b/target/arm/cpu64.c @@ -33,6 +33,7 @@ #include "hw/qdev-properties.h" #include "internals.h" #include "cpregs.h" +#include "sysemu/gunyah.h" =20 void arm_cpu_sve_finalize(ARMCPU *cpu, Error **errp) { @@ -686,7 +687,7 @@ static void aarch64_host_initfn(Object *obj) =20 static void aarch64_max_initfn(Object *obj) { - if (kvm_enabled() || hvf_enabled()) { + if (kvm_enabled() || hvf_enabled() || gunyah_enabled()) { /* With KVM or HVF, '-cpu max' is identical to '-cpu host' */ aarch64_host_initfn(obj); return; @@ -706,7 +707,7 @@ static const ARMCPUInfo aarch64_cpus[] =3D { { .name =3D "cortex-a57", .initfn =3D aarch64_a57_initfn }, { .name =3D "cortex-a53", .initfn =3D aarch64_a53_initfn }, { .name =3D "max", .initfn =3D aarch64_max_initfn }, -#if defined(CONFIG_KVM) || defined(CONFIG_HVF) +#if defined(CONFIG_KVM) || defined(CONFIG_HVF) || defined(CONFIG_GUNYAH) { .name =3D "host", .initfn =3D aarch64_host_initfn }, #endif }; --=20 2.25.1 From nobody Fri May 17 09:01:33 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=quicinc.com ARC-Seal: i=1; a=rsa-sha256; t=1697043289; cv=none; d=zohomail.com; s=zohoarc; b=Opvz7kkY03M2/dI7g8HzpIqbiPMFaunohFr/ql6vm4j4BnHGWPUJzPW2G4N4yVzVIHoIRWgfw6uPRGhWIHqSFBmny/IdSYRt3WD+Q3LyeXIGFvVRn8xACIHDsHaQI1f01AwwMEexlyunFd2QMO1388nA50h3553Swg+vq4v04uU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1697043289; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=aKCik6loT2tDTTKOP+RQkmj+QfmfOkUlBUcFV9MK+s8=; b=M1KJq27p0yyOZVLJaTV2esyEcGqCV+NGJSrZcbPeuRWXfToAsZxmVxqySe0we9c+UGNiDc+Ga2Rcua/GMcNldrRFW2cHkn8XvJuoKfgwjKPWdaEGDsjgLq7rTspRs080Vl/wiaoKPLGwLzdirphn4CCp4TfBt0r02F97yr+CxoQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1697043289091336.96197204813154; Wed, 11 Oct 2023 09:54:49 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qqcSQ-00006B-3X; Wed, 11 Oct 2023 12:53:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qqcSM-00005i-7H; Wed, 11 Oct 2023 12:53:11 -0400 Received: from mx0b-0031df01.pphosted.com ([205.220.180.131]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qqcSK-00011u-9J; Wed, 11 Oct 2023 12:53:09 -0400 Received: from pps.filterd (m0279868.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39BFqO4R018254; Wed, 11 Oct 2023 16:53:06 GMT Received: from nalasppmta05.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3tnn1gsk70-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 11 Oct 2023 16:53:06 +0000 Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA05.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 39BGr5H7002055 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 11 Oct 2023 16:53:05 GMT Received: from blr-ubuntu-31.qualcomm.com (10.80.80.8) by nalasex01b.na.qualcomm.com (10.47.209.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.36; Wed, 11 Oct 2023 09:53:01 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=qcppdkim1; bh=aKCik6loT2tDTTKOP+RQkmj+QfmfOkUlBUcFV9MK+s8=; b=luhnnf16F7VgiAZm31pQMY6xPT37XzVORo2Q69wPgDO9oxtRgtO8BUmJo6b7n3PQmLU1 zcSfzqsyoOrEO0D5S6+UJ3akTgpPibslb13EvBUo+3qegDqndRaXdInsEHeCJJcvI5Em 4TMjKbiUcbXNMt4dAAXATOML+6xPVbeUygbVctFnL3c1Ac1JnvAE5MKDxagW+BkDgFB6 ngfDRtONeoe2MEgubWGVJNlkKBHRaLnBGpJmioJ1F6BFozxO1h4Xu/zEyPRZIKU/dJeH j2o4cK/fm+2ohlwmKC6/SQiBTEgf6H/lLjqf49i/jhFOuOBseoHd0D/ihz6jfWoMzT5u ZQ== From: Srivatsa Vaddagiri To: , , , CC: , , , , , , Subject: [RFC/PATCH v0 04/12] gunyah: Add VM properties Date: Wed, 11 Oct 2023 16:52:26 +0000 Message-ID: <20231011165234.1323725-5-quic_svaddagi@quicinc.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231011165234.1323725-1-quic_svaddagi@quicinc.com> References: <20231011165234.1323725-1-quic_svaddagi@quicinc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.80.80.8] X-ClientProxiedBy: nasanex01a.na.qualcomm.com (10.52.223.231) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: WuCR72cGOGkJL-ITG09u2xXC6wcirWtI X-Proofpoint-ORIG-GUID: WuCR72cGOGkJL-ITG09u2xXC6wcirWtI X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-11_12,2023-10-11_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 spamscore=0 mlxlogscore=999 lowpriorityscore=0 suspectscore=0 phishscore=0 impostorscore=0 mlxscore=0 priorityscore=1501 clxscore=1015 bulkscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310110148 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=205.220.180.131; envelope-from=quic_svaddagi@quicinc.com; helo=mx0b-0031df01.pphosted.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @quicinc.com) X-ZM-MESSAGEID: 1697043289328100001 Content-Type: text/plain; charset="utf-8" Add 'protected-vm' and 'preshmem-size' properties that can be specified for a VM. Protected VMs are those that have 'protected-vm' property set. Their memory cannot be accessed by their (potentially untrusted) host. They are useful to run secure applications whose data should remain private to the VM. Since a protected VM may need some memory shared with its host, for exchange of information, 'preshmem-size' specifies what portion of a protected VM's memory should be shared with its host, with the remaining portion being private to it. Signed-off-by: Srivatsa Vaddagiri --- accel/gunyah/gunyah-accel-ops.c | 65 +++++++++++++++++++++++++++++++++ include/sysemu/gunyah_int.h | 2 + 2 files changed, 67 insertions(+) diff --git a/accel/gunyah/gunyah-accel-ops.c b/accel/gunyah/gunyah-accel-op= s.c index 1c1c20abf1..77089c4f36 100644 --- a/accel/gunyah/gunyah-accel-ops.c +++ b/accel/gunyah/gunyah-accel-ops.c @@ -37,6 +37,60 @@ static void gunyah_accel_instance_init(Object *obj) s->vmfd =3D -1; } =20 +static void gunyah_get_preshmem_size(Object *obj, Visitor *v, + const char *name, void *opaque, + Error **errp) +{ + GUNYAHState *s =3D GUNYAH_STATE(obj); + uint32_t value =3D s->preshmem_size; + + visit_type_uint32(v, name, &value, errp); +} + +static void gunyah_set_preshmem_size(Object *obj, Visitor *v, + const char *name, void *opaque, + Error **errp) +{ + GUNYAHState *s =3D GUNYAH_STATE(obj); + uint32_t value; + + if (s->fd !=3D -1) { + error_setg(errp, "Cannot set properties after VM is created"); + return; + } + + if (!visit_type_uint32(v, name, &value, errp)) { + error_setg(errp, "preshmem-size must be an unsigned integer"); + return; + } + + if (value & (value - 1)) { + error_setg(errp, "preshmem-size must be a power of two"); + return; + } + + if (!s->is_protected_vm) { + error_setg(errp, "preshmem-size is applicable only for protected V= Ms"); + return; + } + + s->preshmem_size =3D value; +} + +static bool gunyah_get_protected_vm(Object *obj, Error **errp) +{ + GUNYAHState *s =3D GUNYAH_STATE(obj); + + return s->is_protected_vm; +} + +static void gunyah_set_protected_vm(Object *obj, bool value, Error **errp) +{ + GUNYAHState *s =3D GUNYAH_STATE(obj); + + s->is_protected_vm =3D value; +} + static void gunyah_accel_class_init(ObjectClass *oc, void *data) { AccelClass *ac =3D ACCEL_CLASS(oc); @@ -44,6 +98,17 @@ static void gunyah_accel_class_init(ObjectClass *oc, voi= d *data) ac->name =3D "GUNYAH"; ac->init_machine =3D gunyah_init; ac->allowed =3D &gunyah_allowed; + + object_class_property_add_bool(oc, "protected-vm", + gunyah_get_protected_vm, gunyah_set_protected_vm); + object_class_property_set_description(oc, "protected-vm", + "Launch a VM of protected type"); + + object_class_property_add(oc, "preshmem-size", "uint32", + gunyah_get_preshmem_size, gunyah_set_preshmem_size, NULL, = NULL); + object_class_property_set_description(oc, "preshmem-size", + "This property is applicable for protected VMs and indicates " + "the portion of VM's memory that should be shared with its host"); } =20 static const TypeInfo gunyah_accel_type =3D { diff --git a/include/sysemu/gunyah_int.h b/include/sysemu/gunyah_int.h index 37de628b37..b1fd7f9ea2 100644 --- a/include/sysemu/gunyah_int.h +++ b/include/sysemu/gunyah_int.h @@ -19,6 +19,8 @@ struct GUNYAHState { =20 int fd; int vmfd; + bool is_protected_vm; + uint32_t preshmem_size; }; =20 int gunyah_create_vm(void); --=20 2.25.1 From nobody Fri May 17 09:01:33 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=quicinc.com ARC-Seal: i=1; a=rsa-sha256; t=1697043245; cv=none; d=zohomail.com; s=zohoarc; b=DzYwRfTKm0YYJQSOnEAIAsaJwBeG1VlRadX2Aji6fYPr70s2UEsDjH27eZuTARe2cT/ZHLUBh6Sd/T7x7GKdbI5HfxKcp2Y3w92J/C3fndIiMKTqrraeXPT/AyKYrx94Spr4syoZF/lk3T44EqjTz6qtDBu6XEjrkCXhKf9iXxs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1697043245; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=oThyAbJxRikTx8bW0Rmk/HLQEBrjOUtZCmyXYBscj3Q=; b=Cfvgo+WZlpH8bA1QnGTgMQmsh9s2vlsOwTpi8svK8oFNmI0RXyCbMrzp0DWRnbYNDY8CeHQvsbQujtmSxQufdn1Dd7s/lhMTDMSXVJktWJ87yOGe7TDP+71+966OfhxQ3wwzi8X65wmJtXbkRGkjtVsv5DmNPfqW3uyxUJjjMj8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1697043245636805.088993191086; Wed, 11 Oct 2023 09:54:05 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qqcST-000071-43; Wed, 11 Oct 2023 12:53:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qqcSQ-00006N-Kv; Wed, 11 Oct 2023 12:53:14 -0400 Received: from mx0b-0031df01.pphosted.com ([205.220.180.131]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qqcSO-00016e-HM; Wed, 11 Oct 2023 12:53:14 -0400 Received: from pps.filterd (m0279868.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39BFqJBQ017966; Wed, 11 Oct 2023 16:53:11 GMT Received: from nalasppmta04.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3tnn1gsk74-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 11 Oct 2023 16:53:10 +0000 Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA04.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 39BGr9nw030942 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 11 Oct 2023 16:53:09 GMT Received: from blr-ubuntu-31.qualcomm.com (10.80.80.8) by nalasex01b.na.qualcomm.com (10.47.209.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.36; Wed, 11 Oct 2023 09:53:05 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=qcppdkim1; bh=oThyAbJxRikTx8bW0Rmk/HLQEBrjOUtZCmyXYBscj3Q=; b=Lf0beDmfCk0MV8/ULBc8QWsGO1aSz/hcgYg2wGAbKhgYyfWGvlLsww3ZnHYjBDs3TW4I BQKWCLm4aEF7xtQRlEVd3SmKb5aMLOOb5yTkznvIrjsRqY+CvGNAQOkcRnWrWoAOiUUI 59bDAZmoYCq3yUmyWVTOGqHcAVfOj5tNqyNcIhnxyWvNIeJj1rETnefQXYGsG+6kkSlM 8Esusl3wT+I6XqWJDZPfzqDmOYpJF2ZIgUJwaeJjoB8aJIt+chcL4/Vy0bqJEyEdf88l fID16Zn/3Y+qzYnrrCADRP7yWFKNdymUGPnEV2Lm3DmxihGKoYbM9XVnU71QOHsnj5sz hA== From: Srivatsa Vaddagiri To: , , , CC: , , , , , , Subject: [RFC/PATCH v0 05/12] gunyah: Support memory assignment Date: Wed, 11 Oct 2023 16:52:27 +0000 Message-ID: <20231011165234.1323725-6-quic_svaddagi@quicinc.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231011165234.1323725-1-quic_svaddagi@quicinc.com> References: <20231011165234.1323725-1-quic_svaddagi@quicinc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.80.80.8] X-ClientProxiedBy: nasanex01a.na.qualcomm.com (10.52.223.231) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: 2EXbD4XEiCJij4D_PLgGc6yn-KO4gZCy X-Proofpoint-ORIG-GUID: 2EXbD4XEiCJij4D_PLgGc6yn-KO4gZCy X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-11_12,2023-10-11_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 spamscore=0 mlxlogscore=999 lowpriorityscore=0 suspectscore=0 phishscore=0 impostorscore=0 mlxscore=0 priorityscore=1501 clxscore=1015 bulkscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310110148 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=205.220.180.131; envelope-from=quic_svaddagi@quicinc.com; helo=mx0b-0031df01.pphosted.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @quicinc.com) X-ZM-MESSAGEID: 1697043247229100006 Content-Type: text/plain; charset="utf-8" Gunyah hypervisor supports several APIs for a host VM to assign some of its memory to the VM being created. Lend - assigned memory is made private to VM (host loses access) Share - assigned memory is shared between host and guest VM No APIs exist however, at this time, for a protected VM to share some of its (private) memory with host at runtime. Since, in practice, even a protected VM may need some shared memory to exchange information with its host, we split VM's memory into two portions - one that is kept private (via Lend API) and other that is shared with host (via Share API). Shared portion size is specified via 'preshmem-size' property of VM. Note: Gunyah kernel driver from Android common kernel repository exposes two separate ioctls for lend and share operations [1]. A subsequent version of kernel driver that will be merged in Linux kernel repository will combine the two ioctls into one, when this patch will be updated. 1. Refer GH_VM_ANDROID_LEND_USER_MEM and GH_VM_SET_USER_MEM_REGION in https://android.googlesource.com/kernel/common/+/refs/heads/android14-6.1/d= rivers/virt/gunyah/vm_mgr.c Signed-off-by: Srivatsa Vaddagiri --- accel/gunyah/gunyah-all.c | 248 ++++++++++++++++++++++++++++++++++++ include/sysemu/gunyah_int.h | 25 ++++ 2 files changed, 273 insertions(+) diff --git a/accel/gunyah/gunyah-all.c b/accel/gunyah/gunyah-all.c index 370add75f9..38d0a52b7f 100644 --- a/accel/gunyah/gunyah-all.c +++ b/accel/gunyah/gunyah-all.c @@ -14,12 +14,20 @@ #include #include "qemu/osdep.h" #include "qemu/typedefs.h" +#include "qemu/units.h" #include "hw/core/cpu.h" #include "sysemu/cpus.h" #include "sysemu/gunyah.h" #include "sysemu/gunyah_int.h" #include "linux-headers/linux/gunyah.h" +#include "exec/memory.h" #include "qemu/error-report.h" +#include "exec/address-spaces.h" + +static void gunyah_region_add(MemoryListener *listener, + MemoryRegionSection *section); +static void gunyah_region_del(MemoryListener *listener, + MemoryRegionSection *section); =20 static int gunyah_ioctl(int type, ...) { @@ -36,9 +44,32 @@ static int gunyah_ioctl(int type, ...) return ioctl(s->fd, type, arg); } =20 +int gunyah_vm_ioctl(int type, ...) +{ + void *arg; + va_list ap; + GUNYAHState *s =3D GUNYAH_STATE(current_accel()); + + assert(s->vmfd); + + va_start(ap, type); + arg =3D va_arg(ap, void *); + va_end(ap); + + return ioctl(s->vmfd, type, arg); +} + +static MemoryListener gunyah_memory_listener =3D { + .name =3D "gunyah", + .priority =3D MEMORY_LISTENER_PRIORITY_ACCEL, + .region_add =3D gunyah_region_add, + .region_del =3D gunyah_region_del, +}; + int gunyah_create_vm(void) { GUNYAHState *s; + int i; =20 s =3D GUNYAH_STATE(current_accel()); =20 @@ -55,6 +86,15 @@ int gunyah_create_vm(void) exit(1); } =20 + qemu_mutex_init(&s->slots_lock); + s->nr_slots =3D GUNYAH_MAX_MEM_SLOTS; + for (i =3D 0; i < s->nr_slots; ++i) { + s->slots[i].start =3D 0; + s->slots[i].size =3D 0; + s->slots[i].id =3D i; + } + + memory_listener_register(&gunyah_memory_listener, &address_space_memor= y); return 0; } =20 @@ -68,3 +108,211 @@ void *gunyah_cpu_thread_fn(void *arg) =20 return NULL; } + +#define gunyah_slots_lock(s) qemu_mutex_lock(&s->slots_lock) +#define gunyah_slots_unlock(s) qemu_mutex_unlock(&s->slots_lock) + +static gunyah_slot *gunyah_find_overlap_slot(GUNYAHState *s, + uint64_t start, uint64_t size) +{ + gunyah_slot *slot; + int i; + + for (i =3D 0; i < s->nr_slots; ++i) { + slot =3D &s->slots[i]; + if (slot->size && start < (slot->start + slot->size) && + (start + size) > slot->start) { + return slot; + } + } + + return NULL; +} + +/* Called with s->slots_lock held */ +static gunyah_slot *gunyah_get_free_slot(GUNYAHState *s) +{ + int i; + + for (i =3D 0; i < s->nr_slots; i++) { + if (s->slots[i].size =3D=3D 0) { + return &s->slots[i]; + } + } + + return NULL; +} + +static void gunyah_add_mem(GUNYAHState *s, MemoryRegionSection *section, + bool lend, enum gh_mem_flags flags) +{ + gunyah_slot *slot; + MemoryRegion *area =3D section->mr; + struct gh_userspace_memory_region gumr; + int ret; + + slot =3D gunyah_get_free_slot(s); + if (!slot) { + error_report("No free slots to add memory!"); + exit(1); + } + + slot->size =3D int128_get64(section->size); + slot->mem =3D memory_region_get_ram_ptr(area) + section->offset_within= _region; + slot->start =3D section->offset_within_address_space; + slot->lend =3D lend; + + gumr.label =3D slot->id; + gumr.flags =3D flags; + gumr.guest_phys_addr =3D slot->start; + gumr.memory_size =3D slot->size; + gumr.userspace_addr =3D (__u64) slot->mem; + + /* + * GH_VM_ANDROID_LEND_USER_MEM is temporary, until + * GH_VM_SET_USER_MEM_REGION is enhanced to support lend option also. + */ + if (lend) { + ret =3D gunyah_vm_ioctl(GH_VM_ANDROID_LEND_USER_MEM, &gumr); + } else { + ret =3D gunyah_vm_ioctl(GH_VM_SET_USER_MEM_REGION, &gumr); + } + + if (ret) { + error_report("failed to add mem (%s)", strerror(errno)); + exit(1); + } +} + +/* + * Check if memory of a protected VM needs to be split into two portions -= one + * private to it and other shared with host. + */ +static bool split_mem(GUNYAHState *s, + MemoryRegion *area, MemoryRegionSection *section) +{ + bool writeable =3D !area->readonly && !area->rom_device; + + /* + * Do not split if its not a protected VM OR if the shared mem size is= not + * specified. + */ + if (!s->is_protected_vm || !s->preshmem_size) { + return false; + } + + /* Split only memory that can be written to by guest */ + if (!memory_region_is_ram(area) || !writeable) { + return false; + } + + /* Have we reserved already? */ + if (qatomic_read(&s->preshmem_reserved)) { + return false; + } + + /* Do we have enough available memory? */ + if (section->size <=3D s->preshmem_size) { + return false; + } + + return true; +} + +static void gunyah_set_phys_mem(GUNYAHState *s, + MemoryRegionSection *section, bool add) +{ + MemoryRegion *area =3D section->mr; + bool writable =3D !area->readonly && !area->rom_device; + enum gh_mem_flags flags =3D 0; + uint64_t page_size =3D qemu_real_host_page_size(); + MemoryRegionSection mrs =3D *section; + bool lend =3D s->is_protected_vm, split =3D false; + struct gunyah_slot *slot; + + /* + * Gunyah hypervisor, at this time, does not support mapping memory + * at low address (< 1GiB). Below code will be updated once + * that limitation is addressed. + */ + if (section->offset_within_address_space < GiB) { + return; + } + + if (!memory_region_is_ram(area)) { + if (writable) { + return; + } else if (!memory_region_is_romd(area)) { + /* + * If the memory device is not in romd_mode, then we actually = want + * to remove the gunyah memory slot so all accesses will trap. + */ + add =3D false; + } + } + + if (!QEMU_IS_ALIGNED(int128_get64(section->size), page_size) || + !QEMU_IS_ALIGNED(section->offset_within_address_space, page_size))= { + error_report("Not page aligned"); + add =3D false; + } + + gunyah_slots_lock(s); + + slot =3D gunyah_find_overlap_slot(s, + section->offset_within_address_space, + int128_get64(section->size)); + + if (!add) { + if (slot) { + error_report("Memory slot removal not yet supported!"); + exit(1); + } + /* Nothing to be done as address range was not previously register= ed */ + goto done; + } else { + if (slot) { + error_report("Overlapping slot registration not supported!"); + exit(1); + } + } + + if (area->readonly || + (!memory_region_is_ram(area) && memory_region_is_romd(area))) { + flags =3D GH_MEM_ALLOW_READ | GH_MEM_ALLOW_EXEC; + } else { + flags =3D GH_MEM_ALLOW_READ | GH_MEM_ALLOW_WRITE | GH_MEM_ALLOW_EX= EC; + } + + split =3D split_mem(s, area, &mrs); + if (split) { + mrs.size -=3D s->preshmem_size; + gunyah_add_mem(s, &mrs, true, flags); + lend =3D false; + mrs.offset_within_region +=3D mrs.size; + mrs.offset_within_address_space +=3D mrs.size; + mrs.size =3D s->preshmem_size; + qatomic_set(&s->preshmem_reserved, true); + } + + gunyah_add_mem(s, &mrs, lend, flags); + +done: + gunyah_slots_unlock(s); +} + +static void gunyah_region_add(MemoryListener *listener, + MemoryRegionSection *section) +{ + GUNYAHState *s =3D GUNYAH_STATE(current_accel()); + + gunyah_set_phys_mem(s, section, true); +} + +static void gunyah_region_del(MemoryListener *listener, + MemoryRegionSection *section) +{ + GUNYAHState *s =3D GUNYAH_STATE(current_accel()); + + gunyah_set_phys_mem(s, section, false); +} diff --git a/include/sysemu/gunyah_int.h b/include/sysemu/gunyah_int.h index b1fd7f9ea2..17b4ef9920 100644 --- a/include/sysemu/gunyah_int.h +++ b/include/sysemu/gunyah_int.h @@ -13,17 +13,42 @@ =20 #include "qemu/accel.h" #include "qemu/typedefs.h" +#include "qemu/thread.h" + +typedef struct gunyah_slot { + uint64_t start; + uint64_t size; + uint8_t *mem; + uint32_t id; + uint32_t flags; + + /* + * @lend indicates if memory was lent. + * + * This flag is temporarily used until the upstream Gunyah kernel driv= er + * patches are updated to support indication of lend vs share via flags + * field of GH_SET_USER_MEM_API interface. + */ + bool lend; +} gunyah_slot; + +#define GUNYAH_MAX_MEM_SLOTS 32 =20 struct GUNYAHState { AccelState parent_obj; =20 + QemuMutex slots_lock; + gunyah_slot slots[GUNYAH_MAX_MEM_SLOTS]; + uint32_t nr_slots; int fd; int vmfd; bool is_protected_vm; + bool preshmem_reserved; uint32_t preshmem_size; }; =20 int gunyah_create_vm(void); +int gunyah_vm_ioctl(int type, ...); void *gunyah_cpu_thread_fn(void *arg); =20 #endif /* GUNYAH_INT_H */ --=20 2.25.1 From nobody Fri May 17 09:01:33 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=quicinc.com ARC-Seal: i=1; a=rsa-sha256; t=1697043272; cv=none; d=zohomail.com; s=zohoarc; b=l6AcnHW8FMxNUViyZUjyREpjsLA0JX2xdI9xhjohn99+fX0sjOZa/L+eezVRYawYhHdcIFf4p8LH3lShTE2JLgppFwslSEilZJt1kW+v9bu3cfF/1N1k0gfkqd6IuVyameugqWgMmY502oERoClsk/A+0F4gQ56Eu9w/+RY278c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1697043272; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=zDvbt+k9krB0i+A+ICzkaDSaljC3RarYq7UNK++Je90=; b=jcEbJek3Chtvj8TvoJ8mb/gQxiNpvb11KMCqSnCgpKPQN6n8FVoIrLa5qZA1u852TyAYSuaHNmkfjJmRROLxVYf5wc1kjIk4sbh9mYJYyAjmZaYqV6x4P2Vs+coXDgaC3rzxhuGsLTfLXm7XPHW0coFoDoAywaCkZ1y5S7Kk3OY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1697043272427828.7561753952409; Wed, 11 Oct 2023 09:54:32 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qqcSY-00008J-L6; Wed, 11 Oct 2023 12:53:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qqcSW-00007g-N7; Wed, 11 Oct 2023 12:53:20 -0400 Received: from mx0b-0031df01.pphosted.com ([205.220.180.131]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qqcSS-00019N-Gd; Wed, 11 Oct 2023 12:53:19 -0400 Received: from pps.filterd (m0279869.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39BGmRgv032365; Wed, 11 Oct 2023 16:53:15 GMT Received: from nalasppmta05.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3tnnvw9hhg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 11 Oct 2023 16:53:14 +0000 Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA05.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 39BGrERu002132 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 11 Oct 2023 16:53:14 GMT Received: from blr-ubuntu-31.qualcomm.com (10.80.80.8) by nalasex01b.na.qualcomm.com (10.47.209.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.36; Wed, 11 Oct 2023 09:53:09 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=qcppdkim1; bh=zDvbt+k9krB0i+A+ICzkaDSaljC3RarYq7UNK++Je90=; b=Ad+asRBuwTy3EE1TTGpOfbz7CUO+QOx5ckFr3MPqnCgY41UxW0+/2ktIjITiMZWXR4Ub CrgiZY1dW4CnCvp4TpqqbWASM3Ro+Jq85+DKDQy0HlVzFhDwb5d50j5+dTvWKGPxgX+D jExXf/mNjxy4ekn/NYTvmPrf3BMPJToXjH9GyB6HRM8ujkbydyegkKESFXcsFr4cZ52i 89SlTnoeZ6wqCGx2PW9eVB+e+EFXSz28ntAdXfLe/goKAf8HUZk8Hg2tRBWygzieG02L 5eipZ9jL709E0Rou2ST7aU1yHlFcXQ0BHBTPotnsk6NhWzQpCVU650RNpoaGqqYmYP2U sQ== From: Srivatsa Vaddagiri To: , , , CC: , , , , , , Subject: [RFC/PATCH v0 06/12] gunyah: Add IRQFD and IOEVENTFD functions Date: Wed, 11 Oct 2023 16:52:28 +0000 Message-ID: <20231011165234.1323725-7-quic_svaddagi@quicinc.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231011165234.1323725-1-quic_svaddagi@quicinc.com> References: <20231011165234.1323725-1-quic_svaddagi@quicinc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.80.80.8] X-ClientProxiedBy: nasanex01a.na.qualcomm.com (10.52.223.231) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: p-uxFust5u8GDY9p8ZavubnM7nac40HH X-Proofpoint-GUID: p-uxFust5u8GDY9p8ZavubnM7nac40HH X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-11_12,2023-10-11_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 bulkscore=0 adultscore=0 phishscore=0 clxscore=1015 spamscore=0 priorityscore=1501 malwarescore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310110148 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=205.220.180.131; envelope-from=quic_svaddagi@quicinc.com; helo=mx0b-0031df01.pphosted.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @quicinc.com) X-ZM-MESSAGEID: 1697043273273100002 Content-Type: text/plain; charset="utf-8" IRQFD function allows registering of an @eventfd and @irq. @irq will be injected inside guest when @eventfd is written into. IOEVENTFD function allows registering an @eventfd and a guest physical address, @addr, along with optional data. A poll() on @eventfd will be woken up when guest attempts to access @addr. Signed-off-by: Srivatsa Vaddagiri --- accel/gunyah/gunyah-all.c | 94 +++++++++++++++++++++++++++++++++++++ include/sysemu/gunyah_int.h | 1 + 2 files changed, 95 insertions(+) diff --git a/accel/gunyah/gunyah-all.c b/accel/gunyah/gunyah-all.c index 38d0a52b7f..6ec60aa8e8 100644 --- a/accel/gunyah/gunyah-all.c +++ b/accel/gunyah/gunyah-all.c @@ -23,11 +23,21 @@ #include "exec/memory.h" #include "qemu/error-report.h" #include "exec/address-spaces.h" +#include "qapi/error.h" +#include "qemu/event_notifier.h" =20 static void gunyah_region_add(MemoryListener *listener, MemoryRegionSection *section); static void gunyah_region_del(MemoryListener *listener, MemoryRegionSection *section); +static void gunyah_mem_ioeventfd_add(MemoryListener *listener, + MemoryRegionSection *section, + bool match_data, uint64_t data, + EventNotifier *e); +static void gunyah_mem_ioeventfd_del(MemoryListener *listener, + MemoryRegionSection *section, + bool match_data, uint64_t data, + EventNotifier *e); =20 static int gunyah_ioctl(int type, ...) { @@ -64,6 +74,8 @@ static MemoryListener gunyah_memory_listener =3D { .priority =3D MEMORY_LISTENER_PRIORITY_ACCEL, .region_add =3D gunyah_region_add, .region_del =3D gunyah_region_del, + .eventfd_add =3D gunyah_mem_ioeventfd_add, + .eventfd_del =3D gunyah_mem_ioeventfd_del, }; =20 int gunyah_create_vm(void) @@ -316,3 +328,85 @@ static void gunyah_region_del(MemoryListener *listener, =20 gunyah_set_phys_mem(s, section, false); } + +int gunyah_add_irqfd(int irqfd, int label, Error **errp) +{ + int ret; + struct gh_fn_desc fdesc; + struct gh_fn_irqfd_arg ghirqfd; + + fdesc.type =3D GH_FN_IRQFD; + fdesc.arg_size =3D sizeof(struct gh_fn_irqfd_arg); + fdesc.arg =3D (__u64)(&ghirqfd); + + ghirqfd.fd =3D irqfd; + ghirqfd.label =3D label; + ghirqfd.flags =3D GH_IRQFD_FLAGS_LEVEL; + + ret =3D gunyah_vm_ioctl(GH_VM_ADD_FUNCTION, &fdesc); + if (ret) { + error_setg_errno(errp, errno, "GH_FN_IRQFD failed"); + } + + return ret; +} + +static int gunyah_set_ioeventfd_mmio(int fd, hwaddr addr, + uint32_t size, uint32_t data, bool datamatch, bool assign) +{ + int ret; + struct gh_fn_ioeventfd_arg io; + struct gh_fn_desc fdesc; + + io.fd =3D fd; + io.datamatch =3D datamatch ? data : 0; + io.len =3D size; + io.addr =3D addr; + io.flags =3D 0; + + fdesc.type =3D GH_FN_IOEVENTFD; + fdesc.arg_size =3D sizeof(struct gh_fn_ioeventfd_arg); + fdesc.arg =3D (__u64)(&io); + + if (assign) { + ret =3D gunyah_vm_ioctl(GH_VM_ADD_FUNCTION, &fdesc); + } else { + ret =3D gunyah_vm_ioctl(GH_VM_REMOVE_FUNCTION, &fdesc); + } + + return ret; +} + +static void gunyah_mem_ioeventfd_add(MemoryListener *listener, + MemoryRegionSection *section, + bool match_data, uint64_t data, + EventNotifier *e) +{ + int fd =3D event_notifier_get_fd(e); + int r; + + r =3D gunyah_set_ioeventfd_mmio(fd, section->offset_within_address_spa= ce, + int128_get64(section->size), data, match_da= ta, + true); + if (r < 0) { + error_report("error adding ioeventfd: %s", strerror(errno)); + exit(1); + } +} + +static void gunyah_mem_ioeventfd_del(MemoryListener *listener, + MemoryRegionSection *section, + bool match_data, uint64_t data, + EventNotifier *e) +{ + int fd =3D event_notifier_get_fd(e); + int r; + + r =3D gunyah_set_ioeventfd_mmio(fd, section->offset_within_address_spa= ce, + int128_get64(section->size), data, match_da= ta, + false); + if (r < 0) { + error_report("error deleting ioeventfd: %s", strerror(errno)); + exit(1); + } +} diff --git a/include/sysemu/gunyah_int.h b/include/sysemu/gunyah_int.h index 17b4ef9920..011b5a072c 100644 --- a/include/sysemu/gunyah_int.h +++ b/include/sysemu/gunyah_int.h @@ -50,5 +50,6 @@ struct GUNYAHState { int gunyah_create_vm(void); int gunyah_vm_ioctl(int type, ...); void *gunyah_cpu_thread_fn(void *arg); +int gunyah_add_irqfd(int irqfd, int label, Error **errp); =20 #endif /* GUNYAH_INT_H */ --=20 2.25.1 From nobody Fri May 17 09:01:33 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=quicinc.com ARC-Seal: i=1; a=rsa-sha256; t=1697043301; cv=none; d=zohomail.com; s=zohoarc; b=PYBl1zCIkHoapS60VayQKDKQ7KdwWmxE7yPa3Y+z49FUftegJwB7xpMTQXJT9Yb8IRpvfl0Sm250JsEnYFWXeUUHkC/RKxOaU9aCc1YopB1/EyfpItFRtpfpgsnI8pk53Y0VFXYQ/OyBB3KkfNQPxA2wRCv2mh/lXLW1pWvxS5U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1697043301; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=D8ZX6LZuRYc6nni5b88hoSIqLdJHmcONqWQXqoXKxdM=; b=aWxAponyYCJOYNToNKGaRLGqRYmB+ubUzCNQ44Jhqksx5J/e/p0QBqZRBQhjDvYe2vGDe+Jau7fqgkkGedgYR+8i5DVRBP+lsrYRaqneN5goPobcEpduLbcM2QGDT9VxzqPpfdhm/6JS51rwvGLvpfxeXZqqeOe30dcYnQvgbrQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1697043301515796.1981830010626; Wed, 11 Oct 2023 09:55:01 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qqcSf-0000Gr-7V; Wed, 11 Oct 2023 12:53:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qqcSd-0000GX-O4; Wed, 11 Oct 2023 12:53:27 -0400 Received: from mx0a-0031df01.pphosted.com ([205.220.168.131]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qqcSa-0001AB-I6; Wed, 11 Oct 2023 12:53:27 -0400 Received: from pps.filterd (m0279865.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39BCPlIi021200; Wed, 11 Oct 2023 16:53:19 GMT Received: from nalasppmta02.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3tnstyryst-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 11 Oct 2023 16:53:18 +0000 Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA02.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 39BGrIVQ008078 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 11 Oct 2023 16:53:18 GMT Received: from blr-ubuntu-31.qualcomm.com (10.80.80.8) by nalasex01b.na.qualcomm.com (10.47.209.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.36; Wed, 11 Oct 2023 09:53:14 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=qcppdkim1; bh=D8ZX6LZuRYc6nni5b88hoSIqLdJHmcONqWQXqoXKxdM=; b=oYs7ehwqOUDHNvVMCGautD/cxLKGUZJ7fS146azXdNdgCnwpESoNwgXugXF+B1QFOmAm f2j7SDwH87VweDX/zYH/UT8D6NoY68/wPHvqoZGBLhTfiKyk5I64OQF/h2yz8GycBebY KQKGNqtgU+LUUskAtaY3r+jrMYjqaehKX4RpFM5y9zi+hg0XLYcLS4jFYpqUOIy4sZyh 9DQX+6RQ68jxovqG23v58tc/tWX3jCp5W77nUwb/3oCUhCP8GuEvEp6JIJXWHLn5fttI KNQ/2oH94u/1V7SAJ+5pMZ28iEBhCKwjkGJAmkCtODiXv04jv68XFjUMqPY4AwvXrECe XA== From: Srivatsa Vaddagiri To: , , , CC: , , , , , , Subject: [RFC/PATCH v0 07/12] gunyah: Add gicv3 interrupt controller Date: Wed, 11 Oct 2023 16:52:29 +0000 Message-ID: <20231011165234.1323725-8-quic_svaddagi@quicinc.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231011165234.1323725-1-quic_svaddagi@quicinc.com> References: <20231011165234.1323725-1-quic_svaddagi@quicinc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.80.80.8] X-ClientProxiedBy: nasanex01a.na.qualcomm.com (10.52.223.231) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: wfMibsDxk4aOFtJvi7tvicepRX4S5G4P X-Proofpoint-GUID: wfMibsDxk4aOFtJvi7tvicepRX4S5G4P X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-11_12,2023-10-11_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 mlxscore=0 bulkscore=0 malwarescore=0 suspectscore=0 priorityscore=1501 impostorscore=0 mlxlogscore=999 lowpriorityscore=0 clxscore=1015 spamscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310110148 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=205.220.168.131; envelope-from=quic_svaddagi@quicinc.com; helo=mx0a-0031df01.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @quicinc.com) X-ZM-MESSAGEID: 1697043303406100001 Content-Type: text/plain; charset="utf-8" Gunyah hypervisor supports emulation of a GICv3 compatible interrupt controller. Emulation is handled by hypervisor itself, with Qemu being allowed to specify some of the properties such as IO address at which GICv3 should be mapped in guest address space. These properties are conveyed to hypervisor via the device-tree, which is parsed by hypervisor (or more specifically Resource Manager VM, which is the trusted agent of hypervisor), before VM begins execution. Injection of interrupts inside guest is supported by doorbell API of Gunyah hypervisor. Each doorbell is associated with a specific interrupt. An eventfd is created and associated with each doorbell/irq. Injection of a specific irq is accomplished by writing to the eventfd associated with that irq. Signed-off-by: Srivatsa Vaddagiri --- MAINTAINERS | 1 + accel/gunyah/gunyah-all.c | 5 ++ hw/arm/virt.c | 2 + hw/intc/arm_gicv3_common.c | 3 + hw/intc/arm_gicv3_gunyah.c | 106 +++++++++++++++++++++++++++++++++ hw/intc/arm_gicv3_its_common.c | 4 ++ hw/intc/meson.build | 1 + include/sysemu/gunyah_int.h | 2 + 8 files changed, 124 insertions(+) create mode 100644 hw/intc/arm_gicv3_gunyah.c diff --git a/MAINTAINERS b/MAINTAINERS index 0e76dda91d..368ba02dce 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -515,6 +515,7 @@ M: Srivatsa Vaddagiri S: Maintained F: accel/gunyah F: include/sysemu/gunyah.h +F: target/arm/arm_gicv3_gunyah.c F: include/sysemu/gunyah_int.h =20 WHPX CPUs diff --git a/accel/gunyah/gunyah-all.c b/accel/gunyah/gunyah-all.c index 6ec60aa8e8..ea6c74fdc6 100644 --- a/accel/gunyah/gunyah-all.c +++ b/accel/gunyah/gunyah-all.c @@ -410,3 +410,8 @@ static void gunyah_mem_ioeventfd_del(MemoryListener *li= stener, exit(1); } } + +GUNYAHState *get_gunyah_state(void) +{ + return GUNYAH_STATE(current_accel()); +} diff --git a/hw/arm/virt.c b/hw/arm/virt.c index 4222183eb5..0d4c5aa819 100644 --- a/hw/arm/virt.c +++ b/hw/arm/virt.c @@ -1937,6 +1937,8 @@ static void finalize_gic_version(VirtMachineState *vm= s) gics_supported |=3D VIRT_GIC_VERSION_4_MASK; } } + } else if (gunyah_enabled()) { + gics_supported |=3D VIRT_GIC_VERSION_3_MASK; } else { error_report("Unsupported accelerator, can not determine GIC suppo= rt"); exit(1); diff --git a/hw/intc/arm_gicv3_common.c b/hw/intc/arm_gicv3_common.c index 2ebf880ead..74c7117b89 100644 --- a/hw/intc/arm_gicv3_common.c +++ b/hw/intc/arm_gicv3_common.c @@ -32,6 +32,7 @@ #include "gicv3_internal.h" #include "hw/arm/linux-boot-if.h" #include "sysemu/kvm.h" +#include "sysemu/gunyah.h" =20 =20 static void gicv3_gicd_no_migration_shift_bug_post_load(GICv3State *cs) @@ -614,6 +615,8 @@ const char *gicv3_class_name(void) { if (kvm_irqchip_in_kernel()) { return "kvm-arm-gicv3"; + } else if (gunyah_enabled()) { + return "gunyah-arm-gicv3"; } else { if (kvm_enabled()) { error_report("Userspace GICv3 is not supported with KVM"); diff --git a/hw/intc/arm_gicv3_gunyah.c b/hw/intc/arm_gicv3_gunyah.c new file mode 100644 index 0000000000..f52e82bf9a --- /dev/null +++ b/hw/intc/arm_gicv3_gunyah.c @@ -0,0 +1,106 @@ +/* + * QEMU Gunyah hypervisor support + * + * Copyright(c) 2023 Qualcomm Innovation Center, Inc. All Rights Reserved. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" +#include "qapi/error.h" +#include "cpu.h" +#include "hw/intc/arm_gicv3_common.h" +#include "qemu/error-report.h" +#include "qemu/module.h" +#include "sysemu/gunyah.h" +#include "sysemu/gunyah_int.h" +#include "sysemu/runstate.h" +#include "gicv3_internal.h" +#include "vgic_common.h" +#include "migration/blocker.h" +#include "qom/object.h" +#include "target/arm/cpregs.h" +#include "qemu/event_notifier.h" + +struct GUNYAHARMGICv3Class { + ARMGICv3CommonClass parent_class; + DeviceRealize parent_realize; + ResettablePhases parent_phases; +}; + +#define TYPE_GUNYAH_ARM_GICV3 "gunyah-arm-gicv3" +typedef struct GUNYAHARMGICv3Class GUNYAHARMGICv3Class; + +/* This is reusing the GICv3State typedef from ARM_GICV3_ITS_COMMON */ +DECLARE_OBJ_CHECKERS(GICv3State, GUNYAHARMGICv3Class, + GUNYAH_ARM_GICV3, TYPE_GUNYAH_ARM_GICV3) + +static EventNotifier *irq_notify; + +static void gunyah_arm_gicv3_set_irq(void *opaque, int irq, int level) +{ + GICv3State *s =3D (GICv3State *)opaque; + + if (irq < s->num_irq - GIC_INTERNAL) { + event_notifier_set(&irq_notify[irq]); + } +} + +static void gunyah_arm_gicv3_realize(DeviceState *dev, Error **errp) +{ + GICv3State *s =3D GUNYAH_ARM_GICV3(dev); + GUNYAHARMGICv3Class *ggc =3D GUNYAH_ARM_GICV3_GET_CLASS(s); + Error *local_err =3D NULL; + int i; + GUNYAHState *state =3D get_gunyah_state(); + + ggc->parent_realize(dev, &local_err); + if (local_err) { + error_propagate(errp, local_err); + return; + } + + if (s->revision !=3D 3) { + error_setg(errp, "unsupported GIC revision %d for in-kernel GIC", + s->revision); + return; + } + + gicv3_init_irqs_and_mmio(s, gunyah_arm_gicv3_set_irq, NULL); + + irq_notify =3D g_malloc_n(s->num_irq - GIC_INTERNAL, sizeof(EventNotif= ier)); + + for (i =3D 0; i < s->num_irq - GIC_INTERNAL; ++i) { + event_notifier_init(&irq_notify[i], 0); + gunyah_add_irqfd(irq_notify[i].wfd, i, errp); + } + + state->nr_irqs =3D s->num_irq - GIC_INTERNAL; +} + +static void gunyah_arm_gicv3_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(klass); + ResettableClass *rc =3D RESETTABLE_CLASS(klass); + GUNYAHARMGICv3Class *ggc =3D GUNYAH_ARM_GICV3_CLASS(klass); + + device_class_set_parent_realize(dc, gunyah_arm_gicv3_realize, + &ggc->parent_realize); + resettable_class_set_parent_phases(rc, NULL, NULL, NULL, + &ggc->parent_phases); +} + +static const TypeInfo gunyah_arm_gicv3_info =3D { + .name =3D TYPE_GUNYAH_ARM_GICV3, + .parent =3D TYPE_ARM_GICV3_COMMON, + .instance_size =3D sizeof(GICv3State), + .class_init =3D gunyah_arm_gicv3_class_init, + .class_size =3D sizeof(GUNYAHARMGICv3Class), +}; + +static void gunyah_arm_gicv3_register_types(void) +{ + type_register_static(&gunyah_arm_gicv3_info); +} + +type_init(gunyah_arm_gicv3_register_types) diff --git a/hw/intc/arm_gicv3_its_common.c b/hw/intc/arm_gicv3_its_common.c index abaf77057e..c225c601ab 100644 --- a/hw/intc/arm_gicv3_its_common.c +++ b/hw/intc/arm_gicv3_its_common.c @@ -25,6 +25,7 @@ #include "qemu/log.h" #include "qemu/module.h" #include "sysemu/kvm.h" +#include "sysemu/gunyah.h" =20 static int gicv3_its_pre_save(void *opaque) { @@ -165,6 +166,9 @@ const char *its_class_name(void) if (kvm_irqchip_in_kernel()) { /* KVM implementation requires this capability */ return kvm_direct_msi_enabled() ? "arm-its-kvm" : NULL; + } else if (gunyah_enabled()) { + /* ITS is not yet supported */ + return NULL; } else { /* Software emulation based model */ return "arm-gicv3-its"; diff --git a/hw/intc/meson.build b/hw/intc/meson.build index ed355941d1..6e680cf0f2 100644 --- a/hw/intc/meson.build +++ b/hw/intc/meson.build @@ -73,3 +73,4 @@ specific_ss.add(when: 'CONFIG_LOONGARCH_IPI', if_true: fi= les('loongarch_ipi.c')) specific_ss.add(when: 'CONFIG_LOONGARCH_PCH_PIC', if_true: files('loongarc= h_pch_pic.c')) specific_ss.add(when: 'CONFIG_LOONGARCH_PCH_MSI', if_true: files('loongarc= h_pch_msi.c')) specific_ss.add(when: 'CONFIG_LOONGARCH_EXTIOI', if_true: files('loongarch= _extioi.c')) +specific_ss.add(when: ['CONFIG_ARM_GIC', 'CONFIG_GUNYAH', 'TARGET_AARCH64'= ], if_true: files('arm_gicv3_gunyah.c')) diff --git a/include/sysemu/gunyah_int.h b/include/sysemu/gunyah_int.h index 011b5a072c..dc5b4847a9 100644 --- a/include/sysemu/gunyah_int.h +++ b/include/sysemu/gunyah_int.h @@ -45,11 +45,13 @@ struct GUNYAHState { bool is_protected_vm; bool preshmem_reserved; uint32_t preshmem_size; + uint32_t nr_irqs; }; =20 int gunyah_create_vm(void); int gunyah_vm_ioctl(int type, ...); void *gunyah_cpu_thread_fn(void *arg); int gunyah_add_irqfd(int irqfd, int label, Error **errp); +GUNYAHState *get_gunyah_state(void); =20 #endif /* GUNYAH_INT_H */ --=20 2.25.1 From nobody Fri May 17 09:01:33 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=quicinc.com ARC-Seal: i=1; a=rsa-sha256; t=1697043245; cv=none; d=zohomail.com; s=zohoarc; b=dEFnw+PSkOrM/zduFYzSsjaJGmOpZ0x/V/TIPus0UVi5FP2lUBpC8khwFEx+RC7r7UYQQjyRWQyv2SuB6V4UHnsp2IsAqAra/FM6E9sXwM+vSPEJmtCl4nMEH1NtjKnFJZIimlY98jYfW2CGavmQYl6use1yMw5vCUmfLHBTDk4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1697043245; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=YC8WJoHv3EEAPm/gyIVIf4+UPhjtjeW1AWLoEKJUZE0=; b=JnVDRh2q2JXM9HsstFZ+L8mcBYKTR53GI83FCN0WZ45SZWYU8zBqdO0OcaHaPbac1584SVgRv+Be99Gq8sctGGavhiQTZU3qqEjrRO/47UyYzKa1qMLMJymuphNTxQugTeAFTAtY0VnblKwDOJYp2XUnlfsvhl2cnnVUjBc9uFU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1697043245850172.88351737876712; Wed, 11 Oct 2023 09:54:05 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qqcSj-0000IF-SJ; Wed, 11 Oct 2023 12:53:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qqcSh-0000HD-6F; Wed, 11 Oct 2023 12:53:31 -0400 Received: from mx0a-0031df01.pphosted.com ([205.220.168.131]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qqcSe-0001Ab-Pu; Wed, 11 Oct 2023 12:53:30 -0400 Received: from pps.filterd (m0279866.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39BFOUoX021103; Wed, 11 Oct 2023 16:53:23 GMT Received: from nalasppmta02.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3tngtpa1rq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 11 Oct 2023 16:53:23 +0000 Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA02.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 39BGrMnK008355 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 11 Oct 2023 16:53:22 GMT Received: from blr-ubuntu-31.qualcomm.com (10.80.80.8) by nalasex01b.na.qualcomm.com (10.47.209.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.36; Wed, 11 Oct 2023 09:53:18 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=qcppdkim1; bh=YC8WJoHv3EEAPm/gyIVIf4+UPhjtjeW1AWLoEKJUZE0=; b=QKgwEJtV9U+G/640sAYpLuJ9lrvIXTFZZyhsFtonNTbMUf2YrhWLiYL6KJ4OR+fIKRDD djKqK24WkG9SOnC6D4A2XKLVboyBEmZba8isZuTka2+SEWaoSQ+Fab4B1GrrDfHZRGxk T/Ql1MSvNCYuc3pQ26QhWfwI+N6JtAW9BOLMkz1aqYaIvPisLk703n2Qp4PrXxHs+7Ur Vuhrf3vBDhyLDLmWZLg63MvNImXdfsvGyXmc2kZ9EpbH3cnxlbdBhDgsVBoEWV9g5+nn TCxjEJPWVhR9SZ2//XbQd6llTmp576cyQ6lvraam2y1PkyAneMCyLZDaSBuAz78vXly8 7w== From: Srivatsa Vaddagiri To: , , , CC: , , , , , , Subject: [RFC/PATCH v0 08/12] gunyah: Specific device-tree location Date: Wed, 11 Oct 2023 16:52:30 +0000 Message-ID: <20231011165234.1323725-9-quic_svaddagi@quicinc.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231011165234.1323725-1-quic_svaddagi@quicinc.com> References: <20231011165234.1323725-1-quic_svaddagi@quicinc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.80.80.8] X-ClientProxiedBy: nasanex01a.na.qualcomm.com (10.52.223.231) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: SrTUJc0BlPIy-IGoXwL9pKfa_q2rvLzi X-Proofpoint-GUID: SrTUJc0BlPIy-IGoXwL9pKfa_q2rvLzi X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-11_12,2023-10-11_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 adultscore=0 lowpriorityscore=0 clxscore=1015 phishscore=0 mlxlogscore=701 priorityscore=1501 bulkscore=0 impostorscore=0 mlxscore=0 malwarescore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310110148 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=205.220.168.131; envelope-from=quic_svaddagi@quicinc.com; helo=mx0a-0031df01.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @quicinc.com) X-ZM-MESSAGEID: 1697043247199100005 Content-Type: text/plain; charset="utf-8" Specify the location of device-tree and its size, as Gunyah requires the device-tree to be parsed before VM can begin its execution. Signed-off-by: Srivatsa Vaddagiri --- MAINTAINERS | 1 + hw/arm/virt.c | 6 ++++++ include/sysemu/gunyah.h | 7 +++++++ target/arm/gunyah.c | 45 +++++++++++++++++++++++++++++++++++++++++ target/arm/meson.build | 4 ++++ 5 files changed, 63 insertions(+) create mode 100644 target/arm/gunyah.c diff --git a/MAINTAINERS b/MAINTAINERS index 368ba02dce..5a51633d11 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -514,6 +514,7 @@ GUNYAH M: Srivatsa Vaddagiri S: Maintained F: accel/gunyah +F: target/arm/gunyah.c F: include/sysemu/gunyah.h F: target/arm/arm_gicv3_gunyah.c F: include/sysemu/gunyah_int.h diff --git a/hw/arm/virt.c b/hw/arm/virt.c index 0d4c5aa819..4293e01383 100644 --- a/hw/arm/virt.c +++ b/hw/arm/virt.c @@ -1676,6 +1676,12 @@ void virt_machine_done(Notifier *notifier, void *dat= a) exit(1); } =20 + if (gunyah_enabled()) { + if (gunyah_arm_set_dtb(info->dtb_start, vms->fdt_size)) { + exit(1); + } + } + fw_cfg_add_extra_pci_roots(vms->bus, vms->fw_cfg); =20 virt_acpi_setup(vms); diff --git a/include/sysemu/gunyah.h b/include/sysemu/gunyah.h index aded49cdf6..101e190619 100644 --- a/include/sysemu/gunyah.h +++ b/include/sysemu/gunyah.h @@ -34,10 +34,17 @@ typedef struct GUNYAHState GUNYAHState; DECLARE_INSTANCE_CHECKER(GUNYAHState, GUNYAH_STATE, TYPE_GUNYAH_ACCEL) =20 +int gunyah_arm_set_dtb(__u64 dtb_start, __u64 dtb_size); + #else /* CONFIG_GUNYAH_IS_POSSIBLE */ =20 #define gunyah_enabled() 0 =20 +static inline int gunyah_arm_set_dtb(__u64 dtb_start, __u64 dtb_size) +{ + return -1; +} + #endif /* CONFIG_GUNYAH_IS_POSSIBLE */ =20 #endif /* QEMU_GUNYAH_H */ diff --git a/target/arm/gunyah.c b/target/arm/gunyah.c new file mode 100644 index 0000000000..73c1c2a88a --- /dev/null +++ b/target/arm/gunyah.c @@ -0,0 +1,45 @@ +/* + * QEMU Gunyah hypervisor support + * + * Copyright(c) 2023 Qualcomm Innovation Center, Inc. All Rights Reserved. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" +#include "qemu/error-report.h" +#include "sysemu/gunyah.h" +#include "sysemu/gunyah_int.h" +#include "linux-headers/linux/gunyah.h" + +/* + * Specify location of device-tree in guest address space. + * + * @dtb_start - Guest physical address where VM's device-tree is found + * @dtb_size - Size of device-tree (and any free space after it). + * + * RM or Resource Manager VM is a trusted and privileged VM that works in + * collaboration with Gunyah hypevisor to setup resources for a VM before = it can + * begin execution. One of its functions includes inspection/modification = of a + * VM's device-tree before VM begins its execution. Modification can + * include specification of runtime resources allocated by hypervisor, + * details of which needs to be visible to VM. VM's device-tree is modifi= ed + * "inline" making use of "free" space that could exist at the end of devi= ce + * tree. + */ +int gunyah_arm_set_dtb(__u64 dtb_start, __u64 dtb_size) +{ + int ret; + struct gh_vm_dtb_config dtb; + + dtb.guest_phys_addr =3D dtb_start; + dtb.size =3D dtb_size; + + ret =3D gunyah_vm_ioctl(GH_VM_SET_DTB_CONFIG, &dtb); + if (ret !=3D 0) { + error_report("GH_VM_SET_DTB_CONFIG failed: %s", strerror(errno)); + exit(1); + } + + return 0; +} diff --git a/target/arm/meson.build b/target/arm/meson.build index e645e456da..c7da15ca89 100644 --- a/target/arm/meson.build +++ b/target/arm/meson.build @@ -36,3 +36,7 @@ endif =20 target_arch +=3D {'arm': arm_ss} target_softmmu_arch +=3D {'arm': arm_system_ss} + +arm_system_ss.add(when: 'CONFIG_GUNYAH', if_true: files( + 'gunyah.c', +)) --=20 2.25.1 From nobody Fri May 17 09:01:33 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=quicinc.com ARC-Seal: i=1; a=rsa-sha256; t=1697043249; cv=none; d=zohomail.com; s=zohoarc; b=R5Pyo+gbN6lf9TNwgZnhiSCrY5CLhvvjv+QBWE4hFEfPR+aW7U8DsJAk+F60AuoyYrY8vhn6jMZofuTq/+BNNrfiAGCU1nPJj6eWHpTpy+CW8ehnTRkEasX5dzy5AM78/6jE/HCQqnvB8y5sw8rHkZbOhmqhBR/oHw+BL+BOD/U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1697043249; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=OYCj5FL3OV5QlxZRwhcgh3ou9oCfEtGrdS4IoYFnXsQ=; b=OoZQVtR38pqZ3jRsG0mivgL7yUGA5b1XnRcD7eKs6oHVZwCIhbsD3j3OpqkT8/4DZypfAVEUjC36VcdbzsQBmGS9PhL6BTBWNcmj6iY103PfKiq9TEb/qihH/z5l0OFzhZ76tKSFtgPBb+ehWAah9R1uOlfvHJurbFhXMTZgZQM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 169704324995486.65950270668702; Wed, 11 Oct 2023 09:54:09 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qqcSk-0000IU-Ou; Wed, 11 Oct 2023 12:53:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qqcSh-0000HE-87; Wed, 11 Oct 2023 12:53:31 -0400 Received: from mx0b-0031df01.pphosted.com ([205.220.180.131]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qqcSf-0001At-He; Wed, 11 Oct 2023 12:53:30 -0400 Received: from pps.filterd (m0279869.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39BFrLb1011628; Wed, 11 Oct 2023 16:53:28 GMT Received: from nalasppmta04.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3tnnvw9hhy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 11 Oct 2023 16:53:27 +0000 Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA04.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 39BGrRj6031404 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 11 Oct 2023 16:53:27 GMT Received: from blr-ubuntu-31.qualcomm.com (10.80.80.8) by nalasex01b.na.qualcomm.com (10.47.209.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.36; Wed, 11 Oct 2023 09:53:22 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=qcppdkim1; bh=OYCj5FL3OV5QlxZRwhcgh3ou9oCfEtGrdS4IoYFnXsQ=; b=B16G3WT69vCdcuOdnZ+55pX8mB1KUEFubHSYZEJifQ0ACnQvEtVYF+Hz0lqfTsbr7C12 dE8K2JNW1MeVZIRShiypq37jKtns14wtPd8uSmDBg+lxgKd11H1w3qHmwhjc+38n8Cz4 hnD33+Fakydhpyzb0j8Kd9AjXFnRCJuKyFJNJdVbBwQbkjLqjmiBNvlJ/PGFW/wvI5w0 jd9u1kFRJv/JhcXGaiLH2v8osSTUP89M5DjUiTVpt8Nvk1/Rnr2gW2WCei0BNeNrhxEx +wGPVycmrO704mZr9EHoaqn2bTPJpN7jgS5gY15eVYajowWSyhHYlOBWXO7nkUTBP2DU Hw== From: Srivatsa Vaddagiri To: , , , CC: , , , , , , Subject: [RFC/PATCH v0 09/12] gunyah: Customize device-tree Date: Wed, 11 Oct 2023 16:52:31 +0000 Message-ID: <20231011165234.1323725-10-quic_svaddagi@quicinc.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231011165234.1323725-1-quic_svaddagi@quicinc.com> References: <20231011165234.1323725-1-quic_svaddagi@quicinc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.80.80.8] X-ClientProxiedBy: nasanex01a.na.qualcomm.com (10.52.223.231) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: _F8R9LE1Fet3-AZiB_Sn7-fXrO-ZHsmh X-Proofpoint-GUID: _F8R9LE1Fet3-AZiB_Sn7-fXrO-ZHsmh X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-11_12,2023-10-11_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 bulkscore=0 adultscore=0 phishscore=0 clxscore=1015 spamscore=0 priorityscore=1501 malwarescore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310110148 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=205.220.180.131; envelope-from=quic_svaddagi@quicinc.com; helo=mx0b-0031df01.pphosted.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @quicinc.com) X-ZM-MESSAGEID: 1697043251178100004 Content-Type: text/plain; charset="utf-8" Customize device-tree with Gunyah specific properties. Some of these properties include specification of doorbells that need to be created and associated with various interrupts. Signed-off-by: Srivatsa Vaddagiri --- hw/arm/virt.c | 11 ++++++ include/sysemu/gunyah.h | 7 ++++ target/arm/gunyah.c | 79 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 97 insertions(+) diff --git a/hw/arm/virt.c b/hw/arm/virt.c index 4293e01383..15fdf7be05 100644 --- a/hw/arm/virt.c +++ b/hw/arm/virt.c @@ -2024,6 +2024,14 @@ static void virt_cpu_post_init(VirtMachineState *vms= , MemoryRegion *sysmem) } } =20 +static void virt_modify_dtb(const struct arm_boot_info *binfo, void *fdt) +{ + const VirtMachineState *vms =3D container_of(binfo, VirtMachineState, + bootinfo); + + gunyah_arm_fdt_customize(fdt, vms->memmap[VIRT_MEM].base, vms->gic_pha= ndle); +} + static void machvirt_init(MachineState *machine) { VirtMachineState *vms =3D VIRT_MACHINE(machine); @@ -2335,6 +2343,9 @@ static void machvirt_init(MachineState *machine) vms->bootinfo.skip_dtb_autoload =3D true; vms->bootinfo.firmware_loaded =3D firmware_loaded; vms->bootinfo.psci_conduit =3D vms->psci_conduit; + if (gunyah_enabled()) { + vms->bootinfo.modify_dtb =3D virt_modify_dtb; + } arm_load_kernel(ARM_CPU(first_cpu), machine, &vms->bootinfo); =20 vms->machine_done.notify =3D virt_machine_done; diff --git a/include/sysemu/gunyah.h b/include/sysemu/gunyah.h index 101e190619..f077837437 100644 --- a/include/sysemu/gunyah.h +++ b/include/sysemu/gunyah.h @@ -35,6 +35,8 @@ DECLARE_INSTANCE_CHECKER(GUNYAHState, GUNYAH_STATE, TYPE_GUNYAH_ACCEL) =20 int gunyah_arm_set_dtb(__u64 dtb_start, __u64 dtb_size); +void gunyah_arm_fdt_customize(void *fdt, uint64_t mem_base, + uint32_t gic_phandle); =20 #else /* CONFIG_GUNYAH_IS_POSSIBLE */ =20 @@ -45,6 +47,11 @@ static inline int gunyah_arm_set_dtb(__u64 dtb_start, __= u64 dtb_size) return -1; } =20 +static inline void gunyah_arm_fdt_customize(void *fdt, uint64_t mem_base, + uint32_t gic_phandle) +{ +} + #endif /* CONFIG_GUNYAH_IS_POSSIBLE */ =20 #endif /* QEMU_GUNYAH_H */ diff --git a/target/arm/gunyah.c b/target/arm/gunyah.c index 73c1c2a88a..1521f2d414 100644 --- a/target/arm/gunyah.c +++ b/target/arm/gunyah.c @@ -11,6 +11,9 @@ #include "sysemu/gunyah.h" #include "sysemu/gunyah_int.h" #include "linux-headers/linux/gunyah.h" +#include "exec/memory.h" +#include "sysemu/device_tree.h" +#include "hw/arm/fdt.h" =20 /* * Specify location of device-tree in guest address space. @@ -43,3 +46,79 @@ int gunyah_arm_set_dtb(__u64 dtb_start, __u64 dtb_size) =20 return 0; } + +void gunyah_arm_fdt_customize(void *fdt, uint64_t mem_base, + uint32_t gic_phandle) +{ + char *nodename; + int i; + GUNYAHState *state =3D get_gunyah_state(); + + qemu_fdt_add_subnode(fdt, "/gunyah-vm-config"); + qemu_fdt_setprop_string(fdt, "/gunyah-vm-config", + "image-name", "qemu-vm"); + qemu_fdt_setprop_string(fdt, "/gunyah-vm-config", "os-type", "linux"); + + nodename =3D g_strdup_printf("/gunyah-vm-config/memory"); + qemu_fdt_add_subnode(fdt, nodename); + qemu_fdt_setprop_cell(fdt, nodename, "#address-cells", 2); + qemu_fdt_setprop_cell(fdt, nodename, "#size-cells", 2); + qemu_fdt_setprop_u64(fdt, nodename, "base-address", mem_base); + + g_free(nodename); + + nodename =3D g_strdup_printf("/gunyah-vm-config/interrupts"); + qemu_fdt_add_subnode(fdt, nodename); + qemu_fdt_setprop_cell(fdt, nodename, "config", gic_phandle); + g_free(nodename); + + nodename =3D g_strdup_printf("/gunyah-vm-config/vcpus"); + qemu_fdt_add_subnode(fdt, nodename); + qemu_fdt_setprop_string(fdt, nodename, "affinity", "proxy"); + g_free(nodename); + + nodename =3D g_strdup_printf("/gunyah-vm-config/vdevices"); + qemu_fdt_add_subnode(fdt, nodename); + qemu_fdt_setprop_string(fdt, nodename, "generate", "/hypervisor"); + g_free(nodename); + + for (i =3D 0; i < state->nr_slots; ++i) { + if (!state->slots[i].start || state->slots[i].lend || + state->slots[i].start =3D=3D mem_base) { + continue; + } + + nodename =3D g_strdup_printf("/gunyah-vm-config/vdevices/shm-%x", = i); + qemu_fdt_add_subnode(fdt, nodename); + qemu_fdt_setprop_string(fdt, nodename, "vdevice-type", "shm"); + qemu_fdt_setprop_string(fdt, nodename, "push-compatible", "dma"); + qemu_fdt_setprop(fdt, nodename, "peer-default", NULL, 0); + qemu_fdt_setprop_u64(fdt, nodename, "dma_base", 0); + g_free(nodename); + + nodename =3D g_strdup_printf("/gunyah-vm-config/vdevices/shm-%x/me= mory", + i); + qemu_fdt_add_subnode(fdt, nodename); + qemu_fdt_setprop_cell(fdt, nodename, "label", i); + qemu_fdt_setprop_cell(fdt, nodename, "#address-cells", 2); + qemu_fdt_setprop_u64(fdt, nodename, "base", state->slots[i].start); + g_free(nodename); + } + + for (i =3D 0; i < state->nr_irqs; ++i) { + nodename =3D g_strdup_printf("/gunyah-vm-config/vdevices/bell-%x",= i); + qemu_fdt_add_subnode(fdt, nodename); + qemu_fdt_setprop_string(fdt, nodename, "vdevice-type", "doorbell"); + char *p =3D g_strdup_printf("/hypervisor/bell-%x", i); + qemu_fdt_setprop_string(fdt, nodename, "generate", p); + g_free(p); + qemu_fdt_setprop_cell(fdt, nodename, "label", i); + qemu_fdt_setprop(fdt, nodename, "peer-default", NULL, 0); + qemu_fdt_setprop(fdt, nodename, "source-can-clear", NULL, 0); + + qemu_fdt_setprop_cells(fdt, nodename, "interrupts", + GIC_FDT_IRQ_TYPE_SPI, i, GIC_FDT_IRQ_FLAGS_LEVEL_HI); + + g_free(nodename); + } +} --=20 2.25.1 From nobody Fri May 17 09:01:33 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=quicinc.com ARC-Seal: i=1; a=rsa-sha256; t=1697043284; cv=none; d=zohomail.com; s=zohoarc; b=cEIIpRdpUbHdFJj1EF4zxBMYnf1WyWD8z1epCKT9JKaq5ysciDFsCPyjOAWs4V9h2fD94LE3u9/0wIjZG4kexIAuf6SkvxB7hvFDqe30hFQQlalKdwVPE1tARjrmk/R7HEJaEEqQJZrQ8bJECLZwjSIt+xYcizky/FXkgB15NuY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1697043284; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=qUyIFkwbd6e1etfK764hgND3mEq0yYMReIGpdrOoXWg=; b=R70+/R/X/Ybx1k6hKOeD12zjggYp67OpTf88MROlmcRh8wwWSVQNAUu3HrYCkpCqmQbPG+0EfgcDtDCoKqPCoN6HT1H/LDVTy8jeKso8nTEbaSwGBcM5uxQw0G3ErEGqjfLd/tm2imaHH7Z9qF882LmOPQiv/kvYVPKg3bKrOcE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1697043284370769.1821837323697; Wed, 11 Oct 2023 09:54:44 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qqcSr-0000ls-T8; Wed, 11 Oct 2023 12:53:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qqcSp-0000jV-JK; Wed, 11 Oct 2023 12:53:39 -0400 Received: from mx0a-0031df01.pphosted.com ([205.220.168.131]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qqcSn-0001Br-FP; Wed, 11 Oct 2023 12:53:39 -0400 Received: from pps.filterd (m0279862.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39BFNPnK020958; Wed, 11 Oct 2023 16:53:32 GMT Received: from nalasppmta05.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3tnmds9pv5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 11 Oct 2023 16:53:31 +0000 Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA05.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 39BGrVGJ002389 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 11 Oct 2023 16:53:31 GMT Received: from blr-ubuntu-31.qualcomm.com (10.80.80.8) by nalasex01b.na.qualcomm.com (10.47.209.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.36; Wed, 11 Oct 2023 09:53:27 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=qcppdkim1; bh=qUyIFkwbd6e1etfK764hgND3mEq0yYMReIGpdrOoXWg=; b=UpvQo1CcXrABu7JftsLSZhYWRzKXugi2I+mcjQyun4UhwOQV45v9PSHCfjGn2ZZ11PeK x8/gQog78dd/HDWFb1cEZdIYfhCJtW+OA3AzNMtmJGZ3YRwZoFDT8wWa+CdLVARVCPlG tcHgpaCjxqqeJhVH0H/9zLS6zMJg08z5G+/QSQp00zJdDwvnXVORYVO1gh2qLS4tk/Oe vDjghVQ8TJyi4Jz6MREKLfFImUs3gD82fMmEiKNowuKqBW1YSLcH0vmEjwTc2sXpKrdN HeJqTw/l8qqBP5AaHHDs0kS4HukO94mOysU1TDC8xqB0xl/3qNXnJ0rEALBiUGaNziV8 SQ== From: Srivatsa Vaddagiri To: , , , CC: , , , , , , Subject: [RFC/PATCH v0 10/12] gunyah: CPU execution loop Date: Wed, 11 Oct 2023 16:52:32 +0000 Message-ID: <20231011165234.1323725-11-quic_svaddagi@quicinc.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231011165234.1323725-1-quic_svaddagi@quicinc.com> References: <20231011165234.1323725-1-quic_svaddagi@quicinc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.80.80.8] X-ClientProxiedBy: nasanex01a.na.qualcomm.com (10.52.223.231) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: HwJ4O6HliuwYfX50nFFjCbnD3XfZh3Yi X-Proofpoint-GUID: HwJ4O6HliuwYfX50nFFjCbnD3XfZh3Yi X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-11_12,2023-10-11_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 bulkscore=0 lowpriorityscore=0 adultscore=0 suspectscore=0 clxscore=1015 spamscore=0 phishscore=0 impostorscore=0 mlxlogscore=973 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310110148 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=205.220.168.131; envelope-from=quic_svaddagi@quicinc.com; helo=mx0a-0031df01.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @quicinc.com) X-ZM-MESSAGEID: 1697043285432100002 Content-Type: text/plain; charset="utf-8" Complete the cpu execution loop. At this time, we recognize exits associated with only MMIO access. Future patches will add support for recognizing other exit reasons, such as PSCI calls made by guest. Signed-off-by: Srivatsa Vaddagiri --- accel/gunyah/gunyah-accel-ops.c | 1 + accel/gunyah/gunyah-all.c | 216 ++++++++++++++++++++++++++++++-- include/hw/core/cpu.h | 6 + include/sysemu/gunyah.h | 1 + include/sysemu/gunyah_int.h | 3 + target/arm/gunyah.c | 13 ++ 6 files changed, 229 insertions(+), 11 deletions(-) diff --git a/accel/gunyah/gunyah-accel-ops.c b/accel/gunyah/gunyah-accel-op= s.c index 77089c4f36..32727e7bf2 100644 --- a/accel/gunyah/gunyah-accel-ops.c +++ b/accel/gunyah/gunyah-accel-ops.c @@ -150,6 +150,7 @@ static void gunyah_accel_ops_class_init(ObjectClass *oc= , void *data) =20 ops->create_vcpu_thread =3D gunyah_start_vcpu_thread; ops->kick_vcpu_thread =3D gunyah_kick_vcpu_thread; + ops->synchronize_post_reset =3D gunyah_cpu_synchronize_post_reset; }; =20 static const TypeInfo gunyah_accel_ops_type =3D { diff --git a/accel/gunyah/gunyah-all.c b/accel/gunyah/gunyah-all.c index ea6c74fdc6..edc61e542b 100644 --- a/accel/gunyah/gunyah-all.c +++ b/accel/gunyah/gunyah-all.c @@ -25,6 +25,9 @@ #include "exec/address-spaces.h" #include "qapi/error.h" #include "qemu/event_notifier.h" +#include "qemu/main-loop.h" +#include "sysemu/runstate.h" +#include "qemu/guest-random.h" =20 static void gunyah_region_add(MemoryListener *listener, MemoryRegionSection *section); @@ -69,6 +72,18 @@ int gunyah_vm_ioctl(int type, ...) return ioctl(s->vmfd, type, arg); } =20 +static int gunyah_vcpu_ioctl(CPUState *cpu, int type, ...) +{ + void *arg; + va_list ap; + + va_start(ap, type); + arg =3D va_arg(ap, void *); + va_end(ap); + + return ioctl(cpu->gunyah.fd, type, arg); +} + static MemoryListener gunyah_memory_listener =3D { .name =3D "gunyah", .priority =3D MEMORY_LISTENER_PRIORITY_ACCEL, @@ -110,17 +125,6 @@ int gunyah_create_vm(void) return 0; } =20 -void *gunyah_cpu_thread_fn(void *arg) -{ - CPUState *cpu =3D arg; - - do { - /* Do nothing */ - } while (!cpu->unplug || cpu_can_run(cpu)); - - return NULL; -} - #define gunyah_slots_lock(s) qemu_mutex_lock(&s->slots_lock) #define gunyah_slots_unlock(s) qemu_mutex_unlock(&s->slots_lock) =20 @@ -287,6 +291,11 @@ static void gunyah_set_phys_mem(GUNYAHState *s, error_report("Overlapping slot registration not supported!"); exit(1); } + + if (qatomic_read(&s->vm_started)) { + error_report("Memory map changes after VM start not supported!= "); + exit(1); + } } =20 if (area->readonly || @@ -415,3 +424,188 @@ GUNYAHState *get_gunyah_state(void) { return GUNYAH_STATE(current_accel()); } + +static void gunyah_ipi_signal(int sig) +{ + if (current_cpu) { + qatomic_set(¤t_cpu->gunyah.run->immediate_exit, 1); + } +} + +static void gunyah_cpu_kick_self(void) +{ + qatomic_set(¤t_cpu->gunyah.run->immediate_exit, 1); +} + +static int gunyah_init_vcpu(CPUState *cpu, Error **errp) +{ + int ret; + struct gh_fn_desc fdesc; + struct gh_fn_vcpu_arg vcpu; + struct sigaction sigact; + sigset_t set; + + /* init cpu signals */ + memset(&sigact, 0, sizeof(sigact)); + sigact.sa_handler =3D gunyah_ipi_signal; + sigaction(SIG_IPI, &sigact, NULL); + + pthread_sigmask(SIG_BLOCK, NULL, &set); + sigdelset(&set, SIG_IPI); + + ret =3D pthread_sigmask(SIG_SETMASK, &set, NULL); + if (ret) { + error_report("pthread_sigmask: %s", strerror(ret)); + exit(1); + } + + vcpu.id =3D cpu->cpu_index; + fdesc.type =3D GH_FN_VCPU; + fdesc.arg_size =3D sizeof(struct gh_fn_vcpu_arg); + fdesc.arg =3D (__u64)(&vcpu); + + ret =3D gunyah_vm_ioctl(GH_VM_ADD_FUNCTION, &fdesc); + if (ret < 0) { + error_report("could not create VCPU %d: %s", vcpu.id, strerror(err= no)); + exit(1); + } + + cpu->gunyah.fd =3D ret; + cpu->gunyah.run =3D mmap(0, 4096, PROT_READ | PROT_WRITE, MAP_SHARED, = ret, 0); + if (cpu->gunyah.run =3D=3D MAP_FAILED) { + error_report("mmap of vcpu run structure failed : %s", strerror(er= rno)); + exit(1); + } + + return 0; +} + +static void gunyah_vcpu_destroy(CPUState *cpu) +{ + int ret; + + ret =3D munmap(cpu->gunyah.run, 4096); + if (ret < 0) { + error_report("munmap of vcpu run structure failed: %s", + strerror(errno)); + exit(1); + } + + close(cpu->gunyah.fd); +} + +static int gunyah_vcpu_exec(CPUState *cpu) +{ + int ret; + GUNYAHState *s =3D GUNYAH_STATE(current_accel()); + + ret =3D qatomic_cmpxchg(&s->vm_started, 0, 1); + if (!ret) { + ret =3D gunyah_vm_ioctl(GH_VM_START); + if (ret !=3D 0) { + error_report("Failed to start VM: %s", strerror(errno)); + exit(1); + } + qatomic_set(&s->vm_started, 1); + } + + qemu_mutex_unlock_iothread(); + cpu_exec_start(cpu); + + do { + struct gh_vcpu_run *run =3D cpu->gunyah.run; + int exit_reason, ret; + + if (qatomic_read(&cpu->exit_request)) { + gunyah_cpu_kick_self(); + } + + /* Todo: Check need for smp_rmb() here */ + + ret =3D gunyah_vcpu_ioctl(cpu, GH_VCPU_RUN); + if (ret < 0) { + if (errno =3D=3D EINTR || errno =3D=3D EAGAIN) { + qatomic_set(&run->immediate_exit, 0); + /* Todo: Check need for smp_wmb() here */ + ret =3D EXCP_INTERRUPT; + break; + } + + error_report("GH_VCPU_RUN: %s", strerror(errno)); + ret =3D -1; + break; + } + + exit_reason =3D run->exit_reason; + switch (exit_reason) { + case GH_VCPU_EXIT_MMIO: + address_space_rw(&address_space_memory, + run->mmio.phys_addr, MEMTXATTRS_UNSPECIFIED, + run->mmio.data, + run->mmio.len, + run->mmio.is_write); + break; + + /* Todo: Handle VM shutdown */ + default: + error_report("unhandled exit %d", exit_reason); + } + } while (ret =3D=3D 0); + + cpu_exec_end(cpu); + qemu_mutex_lock_iothread(); + + if (ret < 0) { + cpu_dump_state(cpu, stderr, CPU_DUMP_CODE); + vm_stop(RUN_STATE_INTERNAL_ERROR); + } + + qatomic_set(&cpu->exit_request, 0); + + return ret; +} + +void *gunyah_cpu_thread_fn(void *arg) +{ + CPUState *cpu =3D arg; + + rcu_register_thread(); + + qemu_mutex_lock_iothread(); + qemu_thread_get_self(cpu->thread); + + cpu->thread_id =3D qemu_get_thread_id(); + cpu->can_do_io =3D 1; + current_cpu =3D cpu; + + gunyah_init_vcpu(cpu, &error_fatal); + + /* signal CPU creation */ + cpu_thread_signal_created(cpu); + qemu_guest_random_seed_thread_part2(cpu->random_seed); + + do { + if (cpu_can_run(cpu)) { + gunyah_vcpu_exec(cpu); + } + qemu_wait_io_event(cpu); + } while (!cpu->unplug || cpu_can_run(cpu)); + + gunyah_vcpu_destroy(cpu); + cpu_thread_signal_destroyed(cpu); + qemu_mutex_unlock_iothread(); + rcu_unregister_thread(); + return NULL; +} + +static void do_gunyah_cpu_synchronize_post_reset(CPUState *cpu, + run_on_cpu_data arg) +{ + gunyah_arch_put_registers(cpu, 0); + cpu->vcpu_dirty =3D false; +} + +void gunyah_cpu_synchronize_post_reset(CPUState *cpu) +{ + run_on_cpu(cpu, do_gunyah_cpu_synchronize_post_reset, RUN_ON_CPU_NULL); +} diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h index fdcbe87352..b3901e134d 100644 --- a/include/hw/core/cpu.h +++ b/include/hw/core/cpu.h @@ -240,6 +240,7 @@ typedef struct SavedIOTLB { =20 struct KVMState; struct kvm_run; +struct gh_vcpu_run; =20 /* work queue */ =20 @@ -443,6 +444,11 @@ struct CPUState { =20 /* track IOMMUs whose translations we've cached in the TCG TLB */ GArray *iommu_notifiers; + + struct { + int fd; + struct gh_vcpu_run *run; + } gunyah; }; =20 typedef QTAILQ_HEAD(CPUTailQ, CPUState) CPUTailQ; diff --git a/include/sysemu/gunyah.h b/include/sysemu/gunyah.h index f077837437..c96334502b 100644 --- a/include/sysemu/gunyah.h +++ b/include/sysemu/gunyah.h @@ -16,6 +16,7 @@ =20 #ifdef NEED_CPU_H #include "cpu.h" + #ifdef CONFIG_GUNYAH # define CONFIG_GUNYAH_IS_POSSIBLE #endif diff --git a/include/sysemu/gunyah_int.h b/include/sysemu/gunyah_int.h index dc5b4847a9..92ba0bc9f0 100644 --- a/include/sysemu/gunyah_int.h +++ b/include/sysemu/gunyah_int.h @@ -46,6 +46,7 @@ struct GUNYAHState { bool preshmem_reserved; uint32_t preshmem_size; uint32_t nr_irqs; + uint32_t vm_started; }; =20 int gunyah_create_vm(void); @@ -53,5 +54,7 @@ int gunyah_vm_ioctl(int type, ...); void *gunyah_cpu_thread_fn(void *arg); int gunyah_add_irqfd(int irqfd, int label, Error **errp); GUNYAHState *get_gunyah_state(void); +int gunyah_arch_put_registers(CPUState *cs, int level); +void gunyah_cpu_synchronize_post_reset(CPUState *cpu); =20 #endif /* GUNYAH_INT_H */ diff --git a/target/arm/gunyah.c b/target/arm/gunyah.c index 1521f2d414..06600dbdb7 100644 --- a/target/arm/gunyah.c +++ b/target/arm/gunyah.c @@ -122,3 +122,16 @@ void gunyah_arm_fdt_customize(void *fdt, uint64_t mem_= base, g_free(nodename); } } + +int gunyah_arch_put_registers(CPUState *cs, int level) +{ + /* + * No support (yet) to set/get vCPU registers. We specify device-tree + * location, which is passed on to VM via X0. Image entry point is ass= umed + * to be the beginning of slot containing device-tree, which seems to = be + * true currently. In future, Gunyah could add API to set boot CPU's + * register context. + */ + + return 0; +} --=20 2.25.1 From nobody Fri May 17 09:01:33 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=quicinc.com ARC-Seal: i=1; a=rsa-sha256; t=1697043280; cv=none; d=zohomail.com; s=zohoarc; b=Ws9LgsrTiqn6/sML5FPsAZEvXFSQM4ktvb7zKEiSKfhVa+lPTw9xAcvqHTKR2C9oXot6Hjl0KYXI//ekOFr305jTII7CtEM5d6VA2Kwj8IyRcHzHZByXor5h+X5OqdndC+yh8rFffXPMcsqcw4vbgyJIiFAvl5XRTeaWeroI7nA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1697043280; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=gxTPe4ZLnmFoG/qiRs43qjCVYHKakkRyEADD4TrcpAs=; b=mAXjvblVf4p6/WKu7abG22ChS7gGN2khj9zwdk3xJ1DYSgeWq/rvgH6qTT7u1DCiKPCTog23fWOs9rBjjFlA5x3k2f9AY9jsfODr+GK6DiQbgAYam73VVmwJQTa+mW9SAJ/Rm50ku7afjsBYtxQ+f4IC5bjiFSYKTCyiq4UaULQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1697043280069839.2668741814917; Wed, 11 Oct 2023 09:54:40 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qqcSx-0000nb-8C; Wed, 11 Oct 2023 12:53:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qqcSu-0000mU-DZ; Wed, 11 Oct 2023 12:53:44 -0400 Received: from mx0a-0031df01.pphosted.com ([205.220.168.131]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qqcSr-0001CS-GM; Wed, 11 Oct 2023 12:53:43 -0400 Received: from pps.filterd (m0279863.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39BFRv30025175; Wed, 11 Oct 2023 16:53:36 GMT Received: from nalasppmta01.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3tnqh1hbd5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 11 Oct 2023 16:53:36 +0000 Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA01.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 39BGrZsK008718 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 11 Oct 2023 16:53:35 GMT Received: from blr-ubuntu-31.qualcomm.com (10.80.80.8) by nalasex01b.na.qualcomm.com (10.47.209.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.36; Wed, 11 Oct 2023 09:53:31 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=qcppdkim1; bh=gxTPe4ZLnmFoG/qiRs43qjCVYHKakkRyEADD4TrcpAs=; b=QDUm7EQMRCL1FrtbHX5897/oslVo3Py8E8bi4MhW7z63Eu/r1UYPvocZ7ucKJOMJdKbP IiQJXvaHiWG1xPadF30CM9WpsALvGzy/hLk+j43DGCB9E62RfnXbtFQKOMyoCZGAQ9ui a4MFI27Lf71HE/1AwzJB6JBZ+qq8PFWDURLOwJt7bQY1TZng4hZq8zNeRxoYRqq8uHAk 6vEthprwTRRLitwQbtblL92BPCOPxB4upLxj02351/Q8PZiWgw1CtrAmk/xfmBNufKK8 RNpk8cvLvo2lzrP8gKw7fcK206KQgqDLdNS6htc7vCTT0NuRlWEr2SQFhJ7svbgkNw+l 4Q== From: Srivatsa Vaddagiri To: , , , CC: , , , , , , Subject: [RFC/PATCH v0 11/12] gunyah: Workarounds (NOT FOR MERGE) Date: Wed, 11 Oct 2023 16:52:33 +0000 Message-ID: <20231011165234.1323725-12-quic_svaddagi@quicinc.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231011165234.1323725-1-quic_svaddagi@quicinc.com> References: <20231011165234.1323725-1-quic_svaddagi@quicinc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.80.80.8] X-ClientProxiedBy: nasanex01a.na.qualcomm.com (10.52.223.231) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: Cl2TGlX5l3MEg-uHm7A_p_fRACtbhyRo X-Proofpoint-ORIG-GUID: Cl2TGlX5l3MEg-uHm7A_p_fRACtbhyRo X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-11_12,2023-10-11_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 phishscore=0 spamscore=0 bulkscore=0 clxscore=1015 lowpriorityscore=0 mlxlogscore=999 mlxscore=0 priorityscore=1501 adultscore=0 malwarescore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310110148 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=205.220.168.131; envelope-from=quic_svaddagi@quicinc.com; helo=mx0a-0031df01.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @quicinc.com) X-ZM-MESSAGEID: 1697043281284100001 Content-Type: text/plain; charset="utf-8" These are some work-arounds required temporarily until some limitations with Gunyah hypervisor are addressed. Signed-off-by: Srivatsa Vaddagiri --- accel/gunyah/gunyah-all.c | 18 ++++++++++++++++++ hw/arm/boot.c | 3 ++- hw/arm/virt.c | 3 ++- include/sysemu/gunyah_int.h | 1 + target/arm/gunyah.c | 7 +++++++ 5 files changed, 30 insertions(+), 2 deletions(-) diff --git a/accel/gunyah/gunyah-all.c b/accel/gunyah/gunyah-all.c index edc61e542b..67372a3a82 100644 --- a/accel/gunyah/gunyah-all.c +++ b/accel/gunyah/gunyah-all.c @@ -145,6 +145,24 @@ static gunyah_slot *gunyah_find_overlap_slot(GUNYAHSta= te *s, return NULL; } =20 +gunyah_slot *gunyah_find_slot_by_addr(uint64_t addr) +{ + GUNYAHState *s =3D GUNYAH_STATE(current_accel()); + int i; + gunyah_slot *slot =3D NULL; + + gunyah_slots_lock(s); + for (i =3D 0; i < s->nr_slots; ++i) { + slot =3D &s->slots[i]; + if (slot->size && + (addr >=3D slot->start && addr <=3D slot->start + slot->size)) + break; + } + gunyah_slots_unlock(s); + + return slot; +} + /* Called with s->slots_lock held */ static gunyah_slot *gunyah_get_free_slot(GUNYAHState *s) { diff --git a/hw/arm/boot.c b/hw/arm/boot.c index 720f22531a..72a22c191f 100644 --- a/hw/arm/boot.c +++ b/hw/arm/boot.c @@ -413,7 +413,8 @@ static int fdt_add_memory_node(void *fdt, uint32_t acel= ls, hwaddr mem_base, char *nodename; int ret; =20 - nodename =3D g_strdup_printf("/memory@%" PRIx64, mem_base); + /* Workaround until RM can parse memory nodes of type memory@XYZ. */ + nodename =3D g_strdup_printf("/memory"); qemu_fdt_add_subnode(fdt, nodename); qemu_fdt_setprop_string(fdt, nodename, "device_type", "memory"); ret =3D qemu_fdt_setprop_sized_cells(fdt, nodename, "reg", acells, mem= _base, diff --git a/hw/arm/virt.c b/hw/arm/virt.c index 15fdf7be05..ab4811a785 100644 --- a/hw/arm/virt.c +++ b/hw/arm/virt.c @@ -164,7 +164,8 @@ static const MemMapEntry base_memmap[] =3D { [VIRT_PCIE_PIO] =3D { 0x3eff0000, 0x00010000 }, [VIRT_PCIE_ECAM] =3D { 0x3f000000, 0x01000000 }, /* Actual RAM size depends on initial RAM and device memory settings */ - [VIRT_MEM] =3D { GiB, LEGACY_RAMLIMIT_BYTES }, + /* Workaround until Gunyah can accept mapping that starts from GiB */ + [VIRT_MEM] =3D { 2 * GiB, LEGACY_RAMLIMIT_BYTES }, }; =20 /* diff --git a/include/sysemu/gunyah_int.h b/include/sysemu/gunyah_int.h index 92ba0bc9f0..1880a578b3 100644 --- a/include/sysemu/gunyah_int.h +++ b/include/sysemu/gunyah_int.h @@ -56,5 +56,6 @@ int gunyah_add_irqfd(int irqfd, int label, Error **errp); GUNYAHState *get_gunyah_state(void); int gunyah_arch_put_registers(CPUState *cs, int level); void gunyah_cpu_synchronize_post_reset(CPUState *cpu); +gunyah_slot *gunyah_find_slot_by_addr(uint64_t addr); =20 #endif /* GUNYAH_INT_H */ diff --git a/target/arm/gunyah.c b/target/arm/gunyah.c index 06600dbdb7..55d5ccc2a4 100644 --- a/target/arm/gunyah.c +++ b/target/arm/gunyah.c @@ -34,6 +34,13 @@ int gunyah_arm_set_dtb(__u64 dtb_start, __u64 dtb_size) { int ret; struct gh_vm_dtb_config dtb; + gunyah_slot *slot =3D gunyah_find_slot_by_addr(dtb_start); + + /* + * RM should consider 'totalsize' field to be inclusive of free space.= Use + * this workaround until RM is fixed. + */ + dtb_size =3D slot->start + slot->size - dtb_start; =20 dtb.guest_phys_addr =3D dtb_start; dtb.size =3D dtb_size; --=20 2.25.1 From nobody Fri May 17 09:01:33 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=quicinc.com ARC-Seal: i=1; a=rsa-sha256; t=1697043280; cv=none; d=zohomail.com; s=zohoarc; b=IEh/jH3qtooQpURzHUyhbPy3v437qbVUu7jpVswAHmjWg0nB0s5xoVpRC7fdEe2VNPLTkBjhz7hyz0dQXsyduIA4hQatQ9BhCQSbHmGLLps6QsURYwTrJ4N81jsGvAiyxFXGUHfH6NaePt6gsNL5jkTFuQ+SwHGdYKAHnuIZ+bA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1697043280; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=TD0IcuYXOGyDTAmfb8Jp1TAH7LH850Q/b2N2pnmRMWg=; b=aEZW2KvDrDxlU6MqCfFgzadLETyH7LOpqDwZpcVNqGUNmqEBStx42jlzqOPYoF152SW6Ax8Nkuw6bml3+rENdcwzKNv64/FyhIWHfhv4XAZ1fjSo+apD/ZOnOd+be0BFjcIRwPNL8R1UVxLxleIH9mIrd6PMUik/uuzG3MrJ8hM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1697043280352634.1753251744256; Wed, 11 Oct 2023 09:54:40 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qqcT3-0000wy-2J; Wed, 11 Oct 2023 12:53:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qqcSy-0000ra-3I; Wed, 11 Oct 2023 12:53:48 -0400 Received: from mx0a-0031df01.pphosted.com ([205.220.168.131]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qqcSv-0001Cw-SS; Wed, 11 Oct 2023 12:53:47 -0400 Received: from pps.filterd (m0279862.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39BCOvo0024483; Wed, 11 Oct 2023 16:53:40 GMT Received: from nalasppmta04.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3tnmds9pvf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 11 Oct 2023 16:53:40 +0000 Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA04.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 39BGrdUT031925 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 11 Oct 2023 16:53:39 GMT Received: from blr-ubuntu-31.qualcomm.com (10.80.80.8) by nalasex01b.na.qualcomm.com (10.47.209.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.36; Wed, 11 Oct 2023 09:53:35 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=qcppdkim1; bh=TD0IcuYXOGyDTAmfb8Jp1TAH7LH850Q/b2N2pnmRMWg=; b=TlDgh+HcWmB4iBrgP04L/ZR6mUmAB5+ctGF+229urxro6/1d+fOGCekb5R1ZPD9d2hsd 7ykatZQKJvbaN7FaptMl/WP/euZI01YVBdxCPQwzmS4KC9v7AeXf5PDClEQ9/9HGKQ6V /85eK2EMVMUGKM/G/ccibVu6QjT/eRA8jmPCpyLHYfc+8+wp36OZF4p5GQBfCX1fG247 Zn9uiisQDhQTA76WOYE8E7M1Whe5QqZwPNPLbqPgUjRW0GQqnd2znNGbVPIQWGKp/YuH ZRuCCwELIlxk3U4uROK2f2kxnfYApHmYXTpkhR5hzNTSfHNJ1fzb+75zLZU3aGRyZSSe DQ== From: Srivatsa Vaddagiri To: , , , CC: , , , , , , Subject: [RFC/PATCH v0 12/12] gunyah: Documentation Date: Wed, 11 Oct 2023 16:52:34 +0000 Message-ID: <20231011165234.1323725-13-quic_svaddagi@quicinc.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231011165234.1323725-1-quic_svaddagi@quicinc.com> References: <20231011165234.1323725-1-quic_svaddagi@quicinc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.80.80.8] X-ClientProxiedBy: nasanex01a.na.qualcomm.com (10.52.223.231) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: ML7z_9-ZyQqFAEOIqF5QI6CbEMGFGWgL X-Proofpoint-GUID: ML7z_9-ZyQqFAEOIqF5QI6CbEMGFGWgL X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-11_12,2023-10-11_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 bulkscore=0 lowpriorityscore=0 adultscore=0 suspectscore=0 clxscore=1015 spamscore=0 phishscore=0 impostorscore=0 mlxlogscore=999 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310110148 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=205.220.168.131; envelope-from=quic_svaddagi@quicinc.com; helo=mx0a-0031df01.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @quicinc.com) X-ZM-MESSAGEID: 1697043281331100002 Content-Type: text/plain; charset="utf-8" Add gunyah.rst that provide some informaiton on how to build and test 'gunyah' accelerator with open-source Gunyah hypervisor. Signed-off-by: Srivatsa Vaddagiri --- MAINTAINERS | 1 + docs/system/arm/gunyah.rst | 214 +++++++++++++++++++++++++++++++++++++ 2 files changed, 215 insertions(+) create mode 100644 docs/system/arm/gunyah.rst diff --git a/MAINTAINERS b/MAINTAINERS index 5a51633d11..f2933a3683 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -518,6 +518,7 @@ F: target/arm/gunyah.c F: include/sysemu/gunyah.h F: target/arm/arm_gicv3_gunyah.c F: include/sysemu/gunyah_int.h +F: docs/system/arm/gunyah.rst =20 WHPX CPUs M: Sunil Muthuswamy diff --git a/docs/system/arm/gunyah.rst b/docs/system/arm/gunyah.rst new file mode 100644 index 0000000000..4b3a792310 --- /dev/null +++ b/docs/system/arm/gunyah.rst @@ -0,0 +1,214 @@ +'gunyah' accelerator (``gunyah``) +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D + +Gunyah is a high performance, scalable and flexible hypervisor built for +demanding battery powered, real-time, safety and security use cases. + +The Gunyah Hypervisor open source project provides a reference Type-1 hype= rvisor +configuration suitable for general purpose hosting of multiple trusted and +dependent VMs. Further information on open-source version of Gunyah Hyperv= isor +can be obtained from: + +https://github.com/quic/gunyah-hypervisor + +To get started with open-source version of Gunyah Hypervisor, refer to the +instructions available at: + +https://github.com/quic/gunyah-support-scripts + +Build and testing +----------------- + +Patch and build Gunyah hypervisor +````````````````````````````````` + +Refer to the information present in **Quick Start** guide to get sources f= or +Gunyah open-source hypervisor: + +https://github.com/quic/gunyah-support-scripts/blob/develop/quickstart.md + +Resource Manager VM (RM) is a privileged VM that acts as an extension of G= unyah +hypervisor. It assists the hypervisor in various tasks related to creation= and +management of VMs. More information on RM is provided at: + +https://github.com/quic/gunyah-resource-manager + +Instructions provided in **Quick Start** guide will include cloning the so= urces +for RM (under 'resource-manager' directory) and hypervisor (under 'hyp' +directory). These directories will be found inside the docker image create= d as +part of steps provided under **Building the Docker Image**. + +Before building hypervisor, as described under **Building a Gunyah Hypervi= sor +image** section of **Quick Start** guide, apply below changes to hyperviso= r and +RM on which 'gunyah' accelerator currently depends. These changes are being +discussed with maintainers and if accepted this document will be modified +appropriately. + +RM patch (in 'resource-manager' directory): + +.. code-block:: bash + + diff --git a/src/vm_creation/vm_creation.c b/src/vm_creation/vm_creation.c + index df8edfb..b73b37e 100644 + --- a/src/vm_creation/vm_creation.c + +++ b/src/vm_creation/vm_creation.c + @@ -510,7 +510,10 @@ process_dtb(vm_t *vm) + // Estimate a final dtb size after applying the overlay. + size_t original_dtb_size =3D + util_balign_up(fdt_totalsize(temp_addr), sizeof(uint32_t)= ); + - size_t final_dtb_size =3D original_dtb_size + dtbo_ret.size; + + size_t final_dtb_size =3D util_balign_up(original_dtb_size + dtbo= _ret.size, 8); + + +Hypervisor patch (in 'hyp' directory): + +.. code-block:: bash + + diff --git a/config/platform/qemu.conf b/config/platform/qemu.conf + index bc612f2..9a292a4 100644 + --- a/config/platform/qemu.conf + +++ b/config/platform/qemu.conf + @@ -35,7 +35,7 @@ configs HLOS_RAM_FS_BASE=3D0x40800000 + configs PLATFORM_HEAP_PRIVATE_SIZE=3D0x200000 + configs PLATFORM_RW_DATA_SIZE=3D0x200000 + configs PLATFORM_ROOTVM_LMA_BASE=3D0x80480000U + -configs PLATFORM_ROOTVM_LMA_SIZE=3D0xa0000U + +configs PLATFORM_ROOTVM_LMA_SIZE=3D0x100000U + configs PLATFORM_PHYS_ADDRESS_BITS=3D36 + configs PLATFORM_VM_ADDRESS_SPACE_BITS=3D36 + configs PLATFORM_PGTABLE_4K_GRANULE=3D1 + +Build Gunyah hypervisor (including RM) as per the instructions provided in +**Quick Start** guide, viz: + +.. code-block:: bash + + cd ~/share + build-gunyah.sh qemu + + +Patch and build Linux kernel +```````````````````````````` + +**Building the Docker Image** step of **Quick Start** guide would have clo= ned +the sources for Linux kernel (under '~/linux/src/linux' directory in docker +image) and also applied below patches. + +https://lore.kernel.org/lkml/20230613172054.3959700-1-quic_eberman@quicinc= .com/ + +Above patches provide a kernel driver that interacts with Gunyah hyperviso= r and +assists a VMM (like Qemu) in creation and management of a VM. Apply below = patch +to Linux kernel, as the 'gunyah' accelerator in Qemu depends on it. + +.. code-block:: bash + + diff --git a/drivers/virt/gunyah/gunyah_ioeventfd.c b/drivers/virt/gunyah= /gunyah_ioeventfd.c + index 5b1b9fd9a..7bfb67800 100644 + --- a/drivers/virt/gunyah/gunyah_ioeventfd.c + +++ b/drivers/virt/gunyah/gunyah_ioeventfd.c + @@ -88,6 +88,7 @@ static long gh_ioeventfd_bind(struct gh_vm_function_ins= tance *f) + } + iofd->io_handler.addr =3D args->addr; + iofd->io_handler.ops =3D &io_ops; + + iofd->io_handler.fd =3D args->fd; + + ret =3D gh_vm_add_io_handler(f->ghvm, &iofd->io_handler); + if (ret) + @@ -120,7 +121,7 @@ static bool gh_ioevent_compare(const struct gh_vm_fun= ction_instance *f, + if (sizeof(*other) !=3D size) + return false; + + - return instance->addr =3D=3D other->addr; + + return instance->addr =3D=3D other->addr && instance->fd =3D=3D o= ther->fd; + } + + DECLARE_GH_VM_FUNCTION_INIT(ioeventfd, GH_FN_IOEVENTFD, 3, + diff --git a/drivers/virt/gunyah/vm_mgr.c b/drivers/virt/gunyah/vm_mgr.c + index afea49238..c4604d4e9 100644 + --- a/drivers/virt/gunyah/vm_mgr.c + +++ b/drivers/virt/gunyah/vm_mgr.c + @@ -291,6 +291,10 @@ static int _gh_vm_io_handler_compare(const struct rb= _node *node, const struct rb + return -1; + if (n->len > p->len) + return 1; + + if (n->fd > p->fd) + + return 1; + + if (n->fd < p->fd) + + return -1; + /* one of the io handlers doesn't have datamatch and the other do= es. + * For purposes of comparison, that makes them identical since the + * one that doesn't have datamatch will cover the same handler th= at + diff --git a/include/linux/gunyah_vm_mgr.h b/include/linux/gunyah_vm_mgr.h + index 527e94624..b2e95d02c 100644 + --- a/include/linux/gunyah_vm_mgr.h + +++ b/include/linux/gunyah_vm_mgr.h + @@ -136,6 +136,7 @@ struct gh_vm_io_handler { + bool datamatch; + u8 len; + u64 data; + + int fd; + struct gh_vm_io_handler_ops *ops; + }; + +Run 'build-linux.sh' inside the docker container to build Linux kernel, wh= ich +provides the image for host kernel. + +.. code-block:: bash + + $ cd ~/ + $ build-linux.sh + + +This will result in Linux kernel binary (Image) and an initrd image (initr= d.img) +being created and copied to '~/tools/qemu/imgs' directory. Those images ca= n be +used for both host kernel as well as for a VM. + + +Configure and build Qemu +```````````````````````` + +Apply the proposed patches for 'gunyah' accelerator support in Qemu and bu= ild +it. + +.. code-block:: bash + + $ ./configure --target-list=3Daarch64-softmmu --enable-debug --ena= ble-gunyah --static + $ make -j4 + +Incorporate Qemu image in root disk +``````````````````````````````````` + +Copy over the resulting Qemu static binary ('qemu-system-aarch64') into the +docker image. In addition, copy 'efi-virtio.rom' and 'en-us' (from Qemu +repository) into the docker image. + +Follow the instructions under **SVM booting Linux** to prepare a virtual d= isk +that can host the required images. Since Qemu is going to be used in place= of +CrosVM, ignore the CrosVM related steps, and instead copy these files to +'~/share/docker-share/rootfs/usr/gunyah' folder before running +'~/utils/bldextfs.sh' script to build root image. + +qemu-system-aarch64, efi-virtio.rom, en-us, Image, initrd.img + +The root disk created ('rootfs-extfs-disk.img') will have above files under +/usr/gunyah folder. + +Running VM +`````````` + +.. code-block:: bash + + $ cd /usr/gunyah + $ ./qemu-system-aarch64 -cpu cortex-a57 -nographic -m 256M --accel= gunyah \ + -machine virt,highmem=3Doff -initrd ./initrd.img -append \ + "rw root=3D/dev/ram rdinit=3D/sbin/init earlyprintk=3Dserial panic= =3D0" + -kernel ./Image + +Limitations +----------- + +Below features are not yet supported. + +* SMP (PSCI support needs to be added) +* virtio-pci (support for which in Qemu seems to rely heavily on KVM, which + needs to be made multi-hypervisor friendly). --=20 2.25.1