Received: by 2002:a05:6a10:83d0:0:0:0:0 with SMTP id o16csp46251pxh; Thu, 7 Apr 2022 13:31:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwOXyeRf+9PRl2dYOurmAjrxI1WhzBIumncXej5QGnftOa5GW2YweiEHPCr5Lkf+rSUaDY0 X-Received: by 2002:a17:902:a98a:b0:155:fc0b:f1a with SMTP id bh10-20020a170902a98a00b00155fc0b0f1amr15540906plb.21.1649363517447; Thu, 07 Apr 2022 13:31:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649363517; cv=none; d=google.com; s=arc-20160816; b=uy+c5bq+uefRT5OqsiNLSb9cUuL3EvvYfJX9RA+z48aBABADbToiNcSS4HZP8vXf6H sxjyidcapojk0/ngFQb7z+DqzMRuAYPn4gVUjp7S2FVGoIIuh2xiyrCAL4wG9Eb7sWPv Nj7yroVhsAX3NgOWVSTSHzYCFIXQop3+oSiRJkKh4u/lIwaDKyfYpXirUg4MLSPmvTI8 JlotZWdwBswdGWICHcljDkqjuTGZDxpO/ycNVkJoW+GnTbK24wpQzHaJwGWUqU5S44iT 5h0Ub8JBT38deWjr4zFrtI8aZbQGnlMgoJJolZp9uFM2PNXZwJFpTbkhw10Z9KHEJzrc Zb4g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:references:mime-version :message-id:in-reply-to:date:dkim-signature; bh=uKF3LzEpbt0jcGyoq/1Xe6ZugarWRpxWPPyqjttx12c=; b=lDRwSmvuG0bSiwMcoTvUMUmTxyeg7V2ugY9p6VVYCwc8tGLQCivkDK93MTxpRxWORs Ub9rzsn1VovPlNBsfEsUnr7JwDxnJX5ZZA9dS2U82aJh6eSovrcyx3dUAyaXc/g+Hq6J BzILnNiFG/CRSiV/+o0jQUv9TIUf5ZtGpBy020V5NZqPMw+lDhh677RCze+uXb4191AC lWY8NVqNCSUSuHJQG7R4xpERZT5xV1UVGWDIfqWo/NUqTi5jK9Bwf5AV8ciDBoCB/sPr wg4kCEpAMVyi0YHXfIqc9QMbRcTUJZ6z00gpcCQMtdL3yZkYawrOYj4Mzb2JyCMnuYXA RaJA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=HM05i9xY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id f8-20020a170902684800b00153b2d16479si597692pln.129.2022.04.07.13.31.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Apr 2022 13:31:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=HM05i9xY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id AB9D0385F1D; Thu, 7 Apr 2022 12:45:30 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239227AbiDGB2H (ORCPT + 99 others); Wed, 6 Apr 2022 21:28:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32870 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240434AbiDGBUA (ORCPT ); Wed, 6 Apr 2022 21:20:00 -0400 Received: from mail-pl1-x649.google.com (mail-pl1-x649.google.com [IPv6:2607:f8b0:4864:20::649]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 07A391868B6 for ; Wed, 6 Apr 2022 18:16:20 -0700 (PDT) Received: by mail-pl1-x649.google.com with SMTP id z8-20020a170903018800b001566875e0f5so1938978plg.21 for ; Wed, 06 Apr 2022 18:16:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=uKF3LzEpbt0jcGyoq/1Xe6ZugarWRpxWPPyqjttx12c=; b=HM05i9xYqmF9YTZlktYDfk2oGC8DrHDBcY4XhwET5dVfw8LN4y0IMKOS1ytyeBj8Cw B/wBVDV66kxEe7mCNTi5PXpHQruPW8ePrvO8hkkzFwhNNhTkWTw3dBSL13pBojaT/ggB dhMU2E2GXe5p9geAbeSEqsG6Bf026kh91SwOsyaNZHE0DTtCorey8FKXNypvuZsJtoxr W2ec6Q0+9bZ6Eoqrj+shgeLEBouwJmsPfDHNu5f6oNjZa3dH2N4ATifv8AIPOrXmYvjX e4BXmNBCrIgJPm9lQ4QoBR/i/KWJu+PkQUWdvus429ZSK8xW60jcdBza69jIYxO2Elp7 Jm2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=uKF3LzEpbt0jcGyoq/1Xe6ZugarWRpxWPPyqjttx12c=; b=CFAd1yyIwN9QqidLtAE2nMq4pQaapD1kHLzJPulOAWUrq1hBz+B0XtfRQgo8KvI9HD +YTBAGkECOAk7O5h4Mz4hbfwEbtsr3jd1SIe30h6O0diPEtEt0XIePTUdzbGsHXudh+t UyVPUzePIwyEkemfX5qXTAMMWCTytzSlY6qaqK325fmtg7B70mQoZjkwiNYsBrhdrYo8 61TXN7V7Ij0rJM+UCMVGZK4Sp/DAcugOVvu299nrKCIXTuTrd0CBxzeHt4J8hnvk6/Hp CBOoWwLOckErJzEZoeey6tNtOmHct7rIlFP8l02OBKmao/3+4qSylEm5AkNCCIH5rlLw Jl9A== X-Gm-Message-State: AOAM530V4ujh7MFfaz1BlTyXCY1MmdxhHvHqbVI/z8kswe1CoQzeU5U1 fMLTXcxvT2ux62WQeJQBBXj6qTacFk5J X-Received: from rananta-virt.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1bcc]) (user=rananta job=sendgmr) by 2002:a05:6a00:23c1:b0:4fa:efcb:9c81 with SMTP id g1-20020a056a0023c100b004faefcb9c81mr11488095pfc.75.1649294179498; Wed, 06 Apr 2022 18:16:19 -0700 (PDT) Date: Thu, 7 Apr 2022 01:15:59 +0000 In-Reply-To: <20220407011605.1966778-1-rananta@google.com> Message-Id: <20220407011605.1966778-5-rananta@google.com> Mime-Version: 1.0 References: <20220407011605.1966778-1-rananta@google.com> X-Mailer: git-send-email 2.35.1.1094.g7c7d902a7c-goog Subject: [PATCH v5 04/10] KVM: arm64: Add vendor hypervisor firmware register From: Raghavendra Rao Ananta To: Marc Zyngier , Andrew Jones , James Morse , Alexandru Elisei , Suzuki K Poulose Cc: Paolo Bonzini , Catalin Marinas , Will Deacon , Peter Shier , Ricardo Koller , Oliver Upton , Reiji Watanabe , Jing Zhang , Raghavendra Rao Anata , linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, linux-kernel@vger.kernel.org, kvm@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.5 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=no 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 Introduce the firmware register to hold the vendor specific hypervisor service calls (owner value 6) as a bitmap. The bitmap represents the features that'll be enabled for the guest, as configured by the user-space. Currently, this includes support for KVM-vendor features, and Precision Time Protocol (PTP), represented by bit-0 and bit-1 respectively. Signed-off-by: Raghavendra Rao Ananta --- arch/arm64/include/asm/kvm_host.h | 2 ++ arch/arm64/include/uapi/asm/kvm.h | 4 ++++ arch/arm64/kvm/hypercalls.c | 21 +++++++++++++++++---- include/kvm/arm_hypercalls.h | 4 ++++ 4 files changed, 27 insertions(+), 4 deletions(-) diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h index 20165242ebd9..b79161bad69a 100644 --- a/arch/arm64/include/asm/kvm_host.h +++ b/arch/arm64/include/asm/kvm_host.h @@ -106,10 +106,12 @@ struct kvm_arch_memory_slot { * * @std_bmap: Bitmap of standard secure service calls * @std_hyp_bmap: Bitmap of standard hypervisor service calls + * @vendor_hyp_bmap: Bitmap of vendor specific hypervisor service calls */ struct kvm_smccc_features { u64 std_bmap; u64 std_hyp_bmap; + u64 vendor_hyp_bmap; }; struct kvm_arch { diff --git a/arch/arm64/include/uapi/asm/kvm.h b/arch/arm64/include/uapi/asm/kvm.h index 67353bf4e69d..9a5ac0ed4113 100644 --- a/arch/arm64/include/uapi/asm/kvm.h +++ b/arch/arm64/include/uapi/asm/kvm.h @@ -344,6 +344,10 @@ struct kvm_arm_copy_mte_tags { #define KVM_REG_ARM_STD_HYP_BMAP KVM_REG_ARM_FW_FEAT_BMAP_REG(1) #define KVM_REG_ARM_STD_HYP_BIT_PV_TIME BIT(0) +#define KVM_REG_ARM_VENDOR_HYP_BMAP KVM_REG_ARM_FW_FEAT_BMAP_REG(2) +#define KVM_REG_ARM_VENDOR_HYP_BIT_FUNC_FEAT BIT(0) +#define KVM_REG_ARM_VENDOR_HYP_BIT_PTP BIT(1) + /* Device Control API: ARM VGIC */ #define KVM_DEV_ARM_VGIC_GRP_ADDR 0 #define KVM_DEV_ARM_VGIC_GRP_DIST_REGS 1 diff --git a/arch/arm64/kvm/hypercalls.c b/arch/arm64/kvm/hypercalls.c index 64ae6c7e7145..80836c341fd3 100644 --- a/arch/arm64/kvm/hypercalls.c +++ b/arch/arm64/kvm/hypercalls.c @@ -66,8 +66,6 @@ static const u32 hvc_func_default_allowed_list[] = { ARM_SMCCC_VERSION_FUNC_ID, ARM_SMCCC_ARCH_FEATURES_FUNC_ID, ARM_SMCCC_VENDOR_HYP_CALL_UID_FUNC_ID, - ARM_SMCCC_VENDOR_HYP_KVM_FEATURES_FUNC_ID, - ARM_SMCCC_VENDOR_HYP_KVM_PTP_FUNC_ID, }; static bool kvm_hvc_call_default_allowed(struct kvm_vcpu *vcpu, u32 func_id) @@ -102,6 +100,12 @@ static bool kvm_hvc_call_allowed(struct kvm_vcpu *vcpu, u32 func_id) case ARM_SMCCC_HV_PV_TIME_ST: return kvm_arm_fw_reg_feat_enabled(smccc_feat->std_hyp_bmap, KVM_REG_ARM_STD_HYP_BIT_PV_TIME); + case ARM_SMCCC_VENDOR_HYP_KVM_FEATURES_FUNC_ID: + return kvm_arm_fw_reg_feat_enabled(smccc_feat->vendor_hyp_bmap, + KVM_REG_ARM_VENDOR_HYP_BIT_FUNC_FEAT); + case ARM_SMCCC_VENDOR_HYP_KVM_PTP_FUNC_ID: + return kvm_arm_fw_reg_feat_enabled(smccc_feat->vendor_hyp_bmap, + KVM_REG_ARM_VENDOR_HYP_BIT_PTP); default: return kvm_hvc_call_default_allowed(vcpu, func_id); } @@ -194,8 +198,7 @@ int kvm_hvc_call_handler(struct kvm_vcpu *vcpu) val[3] = ARM_SMCCC_VENDOR_HYP_UID_KVM_REG_3; break; case ARM_SMCCC_VENDOR_HYP_KVM_FEATURES_FUNC_ID: - val[0] = BIT(ARM_SMCCC_KVM_FUNC_FEATURES); - val[0] |= BIT(ARM_SMCCC_KVM_FUNC_PTP); + val[0] = smccc_feat->vendor_hyp_bmap; break; case ARM_SMCCC_VENDOR_HYP_KVM_PTP_FUNC_ID: kvm_ptp_get_time(vcpu, val); @@ -222,6 +225,7 @@ static const u64 kvm_arm_fw_reg_ids[] = { KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_3, KVM_REG_ARM_STD_BMAP, KVM_REG_ARM_STD_HYP_BMAP, + KVM_REG_ARM_VENDOR_HYP_BMAP, }; void kvm_arm_init_hypercalls(struct kvm *kvm) @@ -230,6 +234,7 @@ void kvm_arm_init_hypercalls(struct kvm *kvm) smccc_feat->std_bmap = KVM_ARM_SMCCC_STD_FEATURES; smccc_feat->std_hyp_bmap = KVM_ARM_SMCCC_STD_HYP_FEATURES; + smccc_feat->vendor_hyp_bmap = KVM_ARM_SMCCC_VENDOR_HYP_FEATURES; } int kvm_arm_get_fw_num_regs(struct kvm_vcpu *vcpu) @@ -322,6 +327,9 @@ int kvm_arm_get_fw_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg) case KVM_REG_ARM_STD_HYP_BMAP: val = READ_ONCE(smccc_feat->std_hyp_bmap); break; + case KVM_REG_ARM_VENDOR_HYP_BMAP: + val = READ_ONCE(smccc_feat->vendor_hyp_bmap); + break; default: return -ENOENT; } @@ -348,6 +356,10 @@ static int kvm_arm_set_fw_reg_bmap(struct kvm_vcpu *vcpu, u64 reg_id, u64 val) fw_reg_bmap = &smccc_feat->std_hyp_bmap; fw_reg_features = KVM_ARM_SMCCC_STD_HYP_FEATURES; break; + case KVM_REG_ARM_VENDOR_HYP_BMAP: + fw_reg_bmap = &smccc_feat->vendor_hyp_bmap; + fw_reg_features = KVM_ARM_SMCCC_VENDOR_HYP_FEATURES; + break; default: return -ENOENT; } @@ -453,6 +465,7 @@ int kvm_arm_set_fw_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg) return 0; case KVM_REG_ARM_STD_BMAP: case KVM_REG_ARM_STD_HYP_BMAP: + case KVM_REG_ARM_VENDOR_HYP_BMAP: return kvm_arm_set_fw_reg_bmap(vcpu, reg->id, val); default: return -ENOENT; diff --git a/include/kvm/arm_hypercalls.h b/include/kvm/arm_hypercalls.h index b0915d8c5b81..eaf4f6b318a8 100644 --- a/include/kvm/arm_hypercalls.h +++ b/include/kvm/arm_hypercalls.h @@ -9,6 +9,7 @@ /* Last valid bits of the bitmapped firmware registers */ #define KVM_REG_ARM_STD_BMAP_BIT_MAX 0 #define KVM_REG_ARM_STD_HYP_BMAP_BIT_MAX 0 +#define KVM_REG_ARM_VENDOR_HYP_BMAP_BIT_MAX 1 #define KVM_ARM_SMCCC_STD_FEATURES \ GENMASK_ULL(KVM_REG_ARM_STD_BMAP_BIT_MAX, 0) @@ -16,6 +17,9 @@ #define KVM_ARM_SMCCC_STD_HYP_FEATURES \ GENMASK_ULL(KVM_REG_ARM_STD_HYP_BMAP_BIT_MAX, 0) +#define KVM_ARM_SMCCC_VENDOR_HYP_FEATURES \ + GENMASK_ULL(KVM_REG_ARM_VENDOR_HYP_BMAP_BIT_MAX, 0) + int kvm_hvc_call_handler(struct kvm_vcpu *vcpu); static inline u32 smccc_get_function(struct kvm_vcpu *vcpu) -- 2.35.1.1094.g7c7d902a7c-goog