From patchwork Mon Dec 19 22:58:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elliot Berman X-Patchwork-Id: 34810 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:e747:0:0:0:0:0 with SMTP id c7csp2661300wrn; Mon, 19 Dec 2022 15:02:59 -0800 (PST) X-Google-Smtp-Source: AA0mqf63g6RSEFrMYOMYQkh6VR6XxLYWkmkkule8KNOy2mcZKXRh+/4QF7PKtH5/txoswcc+hQP5 X-Received: by 2002:a05:6a21:1586:b0:a3:94cd:1435 with SMTP id nr6-20020a056a21158600b000a394cd1435mr46942318pzb.38.1671490979644; Mon, 19 Dec 2022 15:02:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671490979; cv=none; d=google.com; s=arc-20160816; b=JNjmM55vRYUpmjRYaB6rK7UXxAEtSJmJGCJyHu5vp2YSvvIcv2etPWajX0sbvFKC70 /+tus+p7CRsy4hWodS+hh7fzS4tuC0Y3As0gYz6i5h0YP/b9nFzgImlSKZcadKcs6i+h DPcPsGvg4oR9hoMAe+4OMWf2EEyh2P9NwTeCShX9L2CT3iwugGzqarl9yRW0lSS4fdPB NQLfaUkEc5wlWMuIwR/UfjW9O2fuihA8MO3fkfBstq89qE8WsB0RQbAwxW1DlpRtkZ2E saA1pZtEgmB4LzbRJ0p9a/DqrSw70BUPvfU+wQ/C1tzQLd+ksr/Jt3hVxqBHBxthuCHL 4KUQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=HF4iBQ+cZRuNQfUCG3QLF2FXAPRplCw3XpMEge6HY8k=; b=WPTSwn5IUlCxcteyQIUJb4RC4h4t6oM6Q9zhrp3RXHAmsQQZ/zG2xDSpY2aNN4Dt8/ z0a89tvHMk6rnfqjoq7k+rsgS8ataWbjmJRdgRMLNyGuLZex/+djjpunZzHu8wr9Skoi Xq6ZbsMoGXIP+Hy55tOil2f8RUGSckPIEVyJ+szfFEY2S+QvHa8iUCxJ3evPP1I5NP9j ErAglOhK5mNLpKfnuVFS/1xBaB/Sz5UN/Y6THcviBSfWMyUXC02RklNpBEL/YmoOsVdo 1ySoV5iCVpjct6L4vmoe/Q5qAV+zHAy8szGuVMz4Z/bajh9fGnXq8XxK/d3wdHqkIUcl Uiog== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b="O/p1DlSW"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a17-20020a056a000c9100b005788695bef5si12177822pfv.154.2022.12.19.15.02.46; Mon, 19 Dec 2022 15:02:59 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b="O/p1DlSW"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232931AbiLSXCJ (ORCPT + 99 others); Mon, 19 Dec 2022 18:02:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53944 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232935AbiLSXBa (ORCPT ); Mon, 19 Dec 2022 18:01:30 -0500 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 62F30E51; Mon, 19 Dec 2022 15:00:40 -0800 (PST) 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 2BJKfAMd022223; Mon, 19 Dec 2022 23:00:23 GMT 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=HF4iBQ+cZRuNQfUCG3QLF2FXAPRplCw3XpMEge6HY8k=; b=O/p1DlSW7Ob467RQVAx6SbgS7/tlRvNwumhPFfgLecQhEwlG1S068RgB9FldOlsb9FyU NtEzl5LYjLm4dZJ6eNzu8gzcdjbCebv+XX289LZNrH+MBrieVI6ir4/BK0p8FWke/LgC cQJZ4SMYNr5k+shNZNvtG2ZyzBjXrcvNFesmZ/cSqA3mxRyWm6BVdGBnO6CKz0gRurOd C4drtdBZjLURlzSdx36JEhb3kQGrj4qj/9EuomE6BxfE6oQqbg6bgAPREGD7EEAKMkq0 OBX68z7UdsQz8LM3Dnj+yT9SlafiB4d9QErRJcljkbQ8Yw7m8+pB5jU1CPVDcCAvIZca iA== Received: from nasanppmta04.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3mjkwqsk6w-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 19 Dec 2022 23:00:23 +0000 Received: from nasanex01b.na.qualcomm.com (nasanex01b.na.qualcomm.com [10.46.141.250]) by NASANPPMTA04.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 2BJN0MZL018881 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 19 Dec 2022 23:00:22 GMT Received: from hu-eberman-lv.qualcomm.com (10.49.16.6) by nasanex01b.na.qualcomm.com (10.46.141.250) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.36; Mon, 19 Dec 2022 15:00:21 -0800 From: Elliot Berman To: Bjorn Andersson , Elliot Berman , Murali Nalajala CC: Trilok Soni , Srivatsa Vaddagiri , Carl van Schaik , Prakruthi Deepak Heragu , Arnd Bergmann , Greg Kroah-Hartman , Rob Herring , Krzysztof Kozlowski , Jonathan Corbet , "Bagas Sanjaya" , Catalin Marinas , Will Deacon , Jassi Brar , "Sudeep Holla" , Mark Rutland , "Lorenzo Pieralisi" , Dmitry Baryshkov , , , , , , Subject: [PATCH v8 06/28] virt: gunyah: Identify hypervisor version Date: Mon, 19 Dec 2022 14:58:27 -0800 Message-ID: <20221219225850.2397345-7-quic_eberman@quicinc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221219225850.2397345-1-quic_eberman@quicinc.com> References: <20221219225850.2397345-1-quic_eberman@quicinc.com> MIME-Version: 1.0 X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01c.na.qualcomm.com (10.47.97.35) To nasanex01b.na.qualcomm.com (10.46.141.250) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: j84v7y38ynZzjec5L9VK6_j-hh90Hx4t X-Proofpoint-ORIG-GUID: j84v7y38ynZzjec5L9VK6_j-hh90Hx4t X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.923,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2022-12-19_01,2022-12-15_02,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 mlxscore=0 priorityscore=1501 spamscore=0 mlxlogscore=999 lowpriorityscore=0 suspectscore=0 impostorscore=0 phishscore=0 bulkscore=0 adultscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2212190202 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1752685325364911541?= X-GMAIL-MSGID: =?utf-8?q?1752685325364911541?= Export the version of Gunyah which is reported via the hyp_identify hypercall. Increments of the major API version indicate possibly backwards incompatible changes. Export the hypervisor identity so that Gunyah drivers can act according to the major API version. Signed-off-by: Elliot Berman --- drivers/virt/Makefile | 1 + drivers/virt/gunyah/Makefile | 1 + drivers/virt/gunyah/gunyah.c | 46 ++++++++++++++++++++++++++++++++++++ include/linux/gunyah.h | 6 +++++ 4 files changed, 54 insertions(+) create mode 100644 drivers/virt/gunyah/Makefile create mode 100644 drivers/virt/gunyah/gunyah.c diff --git a/drivers/virt/Makefile b/drivers/virt/Makefile index 093674e05c40..92b7e5311548 100644 --- a/drivers/virt/Makefile +++ b/drivers/virt/Makefile @@ -11,3 +11,4 @@ obj-$(CONFIG_NITRO_ENCLAVES) += nitro_enclaves/ obj-$(CONFIG_ACRN_HSM) += acrn/ obj-$(CONFIG_EFI_SECRET) += coco/efi_secret/ obj-$(CONFIG_SEV_GUEST) += coco/sev-guest/ +obj-y += gunyah/ diff --git a/drivers/virt/gunyah/Makefile b/drivers/virt/gunyah/Makefile new file mode 100644 index 000000000000..2ac4ee64b89d --- /dev/null +++ b/drivers/virt/gunyah/Makefile @@ -0,0 +1 @@ +obj-$(CONFIG_GUNYAH) += gunyah.o diff --git a/drivers/virt/gunyah/gunyah.c b/drivers/virt/gunyah/gunyah.c new file mode 100644 index 000000000000..c34c9046fc08 --- /dev/null +++ b/drivers/virt/gunyah/gunyah.c @@ -0,0 +1,46 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved. + */ + +#define pr_fmt(fmt) "gunyah: " fmt + +#include +#include +#include +#include + +struct gh_hypercall_hyp_identify_resp gunyah_api; +EXPORT_SYMBOL_GPL(gunyah_api); + +static const uint32_t gunyah_known_uuids[][4] = { + {0x19bd54bd, 0x0b37571b, 0x946f609b, 0x54539de6}, /* QC_HYP (Qualcomm's build) */ + {0x673d5f14, 0x9265ce36, 0xa4535fdb, 0xc1d58fcd}, /* GUNYAH (open source build) */ +}; + +static int __init gunyah_init(void) +{ + u32 uid[4]; + int i; + + gh_hypercall_get_uid(uid); + + for (i = 0; i < ARRAY_SIZE(gunyah_known_uuids); i++) + if (!memcmp(uid, gunyah_known_uuids[i], sizeof(uid))) + break; + + if (i == ARRAY_SIZE(gunyah_known_uuids)) + return -ENODEV; + + gh_hypercall_hyp_identify(&gunyah_api); + + pr_info("Running under Gunyah hypervisor %llx/v%u\n", + FIELD_GET(GH_API_INFO_VARIANT_MASK, gunyah_api.api_info), + gh_api_version()); + + return 0; +} +arch_initcall(gunyah_init); + +MODULE_LICENSE("GPL"); +MODULE_DESCRIPTION("Gunyah Hypervisor Driver"); diff --git a/include/linux/gunyah.h b/include/linux/gunyah.h index 2765d2b40198..166156f69df9 100644 --- a/include/linux/gunyah.h +++ b/include/linux/gunyah.h @@ -92,6 +92,12 @@ struct gh_hypercall_hyp_identify_resp { u64 api_info; u64 flags[3]; }; +extern struct gh_hypercall_hyp_identify_resp gunyah_api; + +static inline u16 gh_api_version(void) +{ + return FIELD_GET(GH_API_INFO_API_VERSION_MASK, gunyah_api.api_info); +} void gh_hypercall_get_uid(u32 uid[4]); void gh_hypercall_hyp_identify(struct gh_hypercall_hyp_identify_resp *hyp_identity);