Received: by 2002:a05:6358:a55:b0:ec:fcf4:3ecf with SMTP id 21csp5386709rwb; Tue, 17 Jan 2023 13:04:01 -0800 (PST) X-Google-Smtp-Source: AMrXdXuR5VuqiPDI6TzRjOfB1IWl+KVn251HZwfY7eX6KVsLVn/9sH9ZadWZsHpX5hZKawDclxg/ X-Received: by 2002:a05:6a20:6698:b0:b8:701f:1d04 with SMTP id o24-20020a056a20669800b000b8701f1d04mr4232785pzh.11.1673989441124; Tue, 17 Jan 2023 13:04:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673989441; cv=none; d=google.com; s=arc-20160816; b=uKmXYWJz4W0MlcFBxC1XS7d5sHWnUJqBlosPUwMUtCEIyjSVtu8Tkim/PVjjosw4Wp zx/O1cRWEtJwjDTMGk4MYGwoa8zRPJVYcMDeiODtcTfhGP4yO4NwS6F/GwQ766heRwCR QhGExOtvj5G4Lioa73ck29mla4adgkeodSrAMnfPUjLpk3K/McWIijSkdYa+7rST+t85 fW0rmgcWY/Tj81PsllhSqQGh1ZqmWa4BJwvrT1bZt9TPhYUs/T+Pq+R0l/mbx4JcUWoo /sxQ5kLsugp+8wQnIpJsuxB2m8k+svuFj4wX87cJOwW98gBUQvtOJclYqPzov++WSfMc JwQg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to :content-language:references:cc:to:subject:from:user-agent :mime-version:date:message-id:dkim-signature; bh=vIhLbztM/35vA7EkIuAply1n/gr+A/gxbpqqXiig2iI=; b=NAHe5API0UtIPb/+Dv0GC1KbSfck3OVRT54U4BeX8nybH2Bu2tBprfn1w6CjfS7sfo Z4lAgMo0/Hly+ErG+XxPmnZN4a1AaZcf6ZBGv1QfsQGSxyJ5peP1gAbkzPgFTaxS2Zhj R7WU3a1cR/qjXkt27M6WoWT1b579A4SVFsty7lnrjkRZW5xtgTUPpwAw5ABjyASjG1bF tlIfDjMU6HPjqGWqIr55Zx4erymEqrGMrdIB8frak+UXjsx1Ob7NvxQiVfg/dklwQ5YX cElVIetWc0Rfkn2MAyxjKcIKNzlWNB6zSqfMjb3JiXkcGRCtVOVBTlxltfKdjMsCpyoE Leog== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=YP+80c+2; 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=linaro.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s10-20020a63214a000000b0047873dedf41si33812628pgm.415.2023.01.17.13.03.54; Tue, 17 Jan 2023 13:04:01 -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=@linaro.org header.s=google header.b=YP+80c+2; 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=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235465AbjAQUjT (ORCPT + 49 others); Tue, 17 Jan 2023 15:39:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53698 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235529AbjAQUfv (ORCPT ); Tue, 17 Jan 2023 15:35:51 -0500 Received: from mail-io1-xd34.google.com (mail-io1-xd34.google.com [IPv6:2607:f8b0:4864:20::d34]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 745269025 for ; Tue, 17 Jan 2023 11:21:06 -0800 (PST) Received: by mail-io1-xd34.google.com with SMTP id 203so4708150iou.13 for ; Tue, 17 Jan 2023 11:21:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:in-reply-to:content-language:references :cc:to:subject:from:user-agent:mime-version:date:message-id:from:to :cc:subject:date:message-id:reply-to; bh=vIhLbztM/35vA7EkIuAply1n/gr+A/gxbpqqXiig2iI=; b=YP+80c+2+bfoYeiZ+D1yzWG17y1TcDmCjHAYIhLZGs8SbY8IBQDmKipU/+qp4L/535 w0ROGb6RPVmzWDWi/e4YRTh3nc3BTTNaXGe2eaWAvdJ/PHhULvTEZRs8D2y9qpAgO6RU mPRbqTqErqmdMjrDB7L7RfjE1S3uxEAxLKj0D/uZRoJKyZWNZygUMbXecu5y1VEA8o9Z Iez6RU0Axj8nF/4Uph0kWRNrqBKKIWDENddHW5swPZc6yvVztB2uGSWtxtgfCWzcJxf7 7a9OZn4AHbKznPrxibwOSCZF0GxIV20YK5hDFlszP5A+3kJYLxGCnfIBlFf5kJhbZesl CDSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:content-language:references :cc:to:subject:from:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=vIhLbztM/35vA7EkIuAply1n/gr+A/gxbpqqXiig2iI=; b=xWa4QQx/M9AjPfZaXdL14336clD/23Zl19SEbdcD2uRxHCIB4HHhhs7cbxdRJl6ybc nHqcitKEvs+y2OjdbavDIz0FEYAQGSUE6g9w2WoPk2JilBsGBOJ0enhrbZCa/1wEqNhU /+j4vKsacIw9hn9Lnjow3CB9yvT4ZQoAj3EfFwCTUwruH2Z9HwkjEK+7Fqpj68/uOMx/ Sk1FcQ71qw05Lh0NiQoPg1nnUnLyffvIGTjnOEwx5R2AnL8ZRU9yNBTy0gexExeIi7cN Srp84QrVvYuhlBk75SpE1YElrfEhVra51/S6/Og68Ybgoed4s7ZppD6aUb/C4agJSSsO X2Lg== X-Gm-Message-State: AFqh2kpWFJ4+8JgaB966qv+1Cm2e6Ibrc6U+MrZTl9QM+sJ7q2ajff8B Myiln2DK+kpWW+ue+1+1YjmlDw== X-Received: by 2002:a5d:9d49:0:b0:704:ca73:1758 with SMTP id k9-20020a5d9d49000000b00704ca731758mr2808575iok.9.1673983265774; Tue, 17 Jan 2023 11:21:05 -0800 (PST) Received: from [172.22.22.4] ([98.61.227.136]) by smtp.googlemail.com with ESMTPSA id x20-20020a0566022c5400b006bc039e3224sm10641525iov.17.2023.01.17.11.21.04 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 17 Jan 2023 11:21:05 -0800 (PST) Message-ID: <9109de9d-17f2-f1b2-b758-c9df0e562a20@linaro.org> Date: Tue, 17 Jan 2023 13:21:04 -0600 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.2 From: Alex Elder Subject: Re: [PATCH v8 06/28] virt: gunyah: Identify hypervisor version To: Elliot Berman , Alex Elder , Bjorn Andersson , 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 , linux-arm-msm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-acpi@vger.kernel.org References: <20221219225850.2397345-1-quic_eberman@quicinc.com> <20221219225850.2397345-7-quic_eberman@quicinc.com> <51c36831-19c1-dd67-9e31-87733c190a9c@linaro.org> <7e64039a-55ce-d79d-8501-10de09269afb@quicinc.com> Content-Language: en-US In-Reply-To: <7e64039a-55ce-d79d-8501-10de09269afb@quicinc.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.2 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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 On 1/10/23 11:56 AM, Elliot Berman wrote: > > > On 1/9/2023 1:34 PM, Alex Elder wrote: >> On 12/19/22 4:58 PM, Elliot Berman wrote: >>> 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; >> >> Must this global variable be exposed?  Can't you hide it--as >> well as its interpretation--inside "gunyah.c"? >>  >> + >>> +static inline u16 gh_api_version(void) >>> +{ >>> +    return FIELD_GET(GH_API_INFO_API_VERSION_MASK, >>> gunyah_api.api_info); >>> +} >> >> If you don't make the above function inline, can you hide the >> definition of gunyah_api? >> > > This seems like a good idea to me. I'm thinking to have the following > functions: > > enum gh_api_feature { >     GH_API_FEATURE_DOORBELL, >     GH_API_FEATURE_MSGQUEUE, >     GH_API_FEATURE_VIC, >     GH_API_FEATURE_VPM, >     GH_API_FEATURE_VCPU, >     GH_API_FEATURE_MEMEXTENT, >     GH_API_FEATURE_TRACE_CTRL, > }; My point wasn't necessarily to expose all of that. Already "gunyah.h" defines the bit positions in which these things are recorded in the identify response. My main point was about (not) exposing that global variable. I support your suggestion of abstracting the feature interface that way, but I suggest waiting until it's actually needed before you add it. I don't see any code that uses GH_IDENTIFY_PARTITION_CSPACE (and the rest) currently. Oh, and interestingly enough I see GH_API_INFO_BIG_ENDIAN defined in the API info... -Alex > > u16 gh_api_version(void); > bool gh_api_has_feature(enum gh_api_feature feature); > > Thanks, > Elliot