Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp1027961pxb; Fri, 22 Apr 2022 17:14:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwoZi6p86Wj9ayLP01JP0cg4jGC/mMnwSGhedzN9x4hhb3pSq/oXZDAC6P4rE1C84jFnFav X-Received: by 2002:a05:6402:2388:b0:423:bdc7:26b6 with SMTP id j8-20020a056402238800b00423bdc726b6mr7579059eda.310.1650672841984; Fri, 22 Apr 2022 17:14:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650672841; cv=none; d=google.com; s=arc-20160816; b=Yo/sZiB2M02Tm5uHdMqQ9OpBGFWVhIZBzh0UAoShGdLDMvCU2ezQ+KQZlHwOpE3fpr 8hdq2jpEhczTbwZ0sugcweFoHCbY4XR2lf2peCrTnD5Je4TfgnDqRe5PhLsLSJMuF4tS s7QJPEiWzMmqqloIHV6gvbxBGI/Ijbqb39rdUP9IRSXfkqp8avYDFmXt9+YSuPWwZHPJ vZMogfkaDxsT1I38PtnsdRTTJ1+F104GmwyyeaHIbMcgCe5tksVYKgt6M67IFgPfE+bY 4ObwW/mNvBP/R1eLiXS7zuGlVcw6mxfMDG2Ndeg9RiPXOVcOgAAiEblSalM98AvL0MSk jkeQ== 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=X/58AOVcJZBuIqfxzeZygHghzuDoH3dJ9eSYKiEOz2g=; b=XPB5Iv/UuzQhBtyBOQK0aCw3o8v+AI5xYEfVJEeWbWFay/cKgbyWykYNrLVRclRzaw gzfaPGIUbdPjKWmIKVOOX0yXcw8+H3W7uNCRGiRuHoWOKoe5bY+Y3eXh/UmjaTIoUZfn 5PHHF4LXdXOtFcakrqTTQrlBmcXy6gkLx7wcAvoh1mX1yt9XgWGIEIZh1EYmNON2muWE 2+1pjGTfgeRPYoVFbYYGZrOh7Cj1fIjspU7iZqfn4bu6HKeVi0l/FyRVJzum8vNieAcW bXx4cNNB419xr27cwxVm+J9HhglQB3s+vGHv3s/eSBpSf2BcykIuAlE140AGOQ7wU9dD rxtA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=ZraGiuXs; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id mf23-20020a170906cb9700b006df85d83e7csi8540920ejb.226.2022.04.22.17.13.37; Fri, 22 Apr 2022 17:14:01 -0700 (PDT) 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=@google.com header.s=20210112 header.b=ZraGiuXs; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231402AbiDWAG5 (ORCPT + 99 others); Fri, 22 Apr 2022 20:06:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45532 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231307AbiDWAGq (ORCPT ); Fri, 22 Apr 2022 20:06:46 -0400 Received: from mail-pg1-x549.google.com (mail-pg1-x549.google.com [IPv6:2607:f8b0:4864:20::549]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 17B0120E496 for ; Fri, 22 Apr 2022 17:03:43 -0700 (PDT) Received: by mail-pg1-x549.google.com with SMTP id bj12-20020a056a02018c00b003a9eebaad34so5832937pgb.10 for ; Fri, 22 Apr 2022 17:03:43 -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=X/58AOVcJZBuIqfxzeZygHghzuDoH3dJ9eSYKiEOz2g=; b=ZraGiuXstCpSXkSyDbOK+UePTp4ddaFJZ6Xhue9ToYLy/B6su0aVTgtHIA5F+hzVKE qao9LxdR9vGNeefHgxKTuKSio09BV65qE6Tco5F9jn1Xiry222GiyCwzQcGdeao6RrZH FVe9goajXTtW3lSLTT8dkKxNPIu5t3eC8tOl2us0kwp7owu/pe48I1vkkl7krVGlZRZp AdU9lpgvcS1knso5pdkH4DDAfSamP4FDqSEXB+Lssy/eL83qoIn0xk62xXiJstL5yIMZ h9kI1tSN/MgLH53cbSpU95yavi8/XTYAiZ5LcMY9WxXaNvPEk7qDNUOY9A7wsToU8+wm 20KA== 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=X/58AOVcJZBuIqfxzeZygHghzuDoH3dJ9eSYKiEOz2g=; b=kNL+4QvMq8b127hTmhZsMMCgGR77rVmGtlPeLWtyNssFdh+xgkPZtKKglAGBBTOOEO q3K8eVm8EwsfbTynotZtw0naIZvD9Nu95kN7jLzFmbx+dwZ0kkobf0ybxInP/Y3KnHG9 lhcoChFBMN+FRoEWERrGPUf2UNzLv0idwLqegZbVbwBEN4VV2ReRhsYQZp5FH7o/UdgB Fbtg3twyfrYgt1rY5cMFyCLrHK230d87dN4fE93gYESU3GqJ0l2VXKkhz3xjge4d50Xi HALBYzGIJmUznzMrS8TIFuVBadUsRbpDLcfEi8OdBv1IC1Fu0FRN2gceIOCUjqfu9r7N k1TA== X-Gm-Message-State: AOAM530zI4SSHuSxM9inx4H0tqzPLIpqnc4z7OOy10kckhYJZtLZfjB2 IWDPg7dhe3MqGS18+dLijc6dNYgoyFvq X-Received: from rananta-virt.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1bcc]) (user=rananta job=sendgmr) by 2002:a17:90a:9105:b0:1d2:9e98:7e1e with SMTP id k5-20020a17090a910500b001d29e987e1emr662712pjo.0.1650672221976; Fri, 22 Apr 2022 17:03:41 -0700 (PDT) Date: Sat, 23 Apr 2022 00:03:23 +0000 In-Reply-To: <20220423000328.2103733-1-rananta@google.com> Message-Id: <20220423000328.2103733-5-rananta@google.com> Mime-Version: 1.0 References: <20220423000328.2103733-1-rananta@google.com> X-Mailer: git-send-email 2.36.0.rc2.479.g8af0fa9b8e-goog Subject: [PATCH v6 4/9] 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.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL 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 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 along with reading the UID, represented by bit-0, and Precision Time Protocol (PTP), represented by bit-1. 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 | 23 ++++++++++++++++++----- include/kvm/arm_hypercalls.h | 2 ++ 4 files changed, 26 insertions(+), 5 deletions(-) diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h index 27d4b2a7970e..a025c2ba012a 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 { unsigned long std_bmap; unsigned long std_hyp_bmap; + unsigned long 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 9eecc7ee8c14..e7d5ae222684 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 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 0 +#define KVM_REG_ARM_VENDOR_HYP_BIT_PTP 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 f097bebdad39..76e626d0e699 100644 --- a/arch/arm64/kvm/hypercalls.c +++ b/arch/arm64/kvm/hypercalls.c @@ -72,9 +72,6 @@ static bool kvm_hvc_call_default_allowed(struct kvm_vcpu *vcpu, u32 func_id) */ case ARM_SMCCC_VERSION_FUNC_ID: case ARM_SMCCC_ARCH_FEATURES_FUNC_ID: - case ARM_SMCCC_VENDOR_HYP_CALL_UID_FUNC_ID: - case ARM_SMCCC_VENDOR_HYP_KVM_FEATURES_FUNC_ID: - case ARM_SMCCC_VENDOR_HYP_KVM_PTP_FUNC_ID: return true; default: return kvm_psci_func_id_is_valid(vcpu, func_id); @@ -97,6 +94,13 @@ 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: + case ARM_SMCCC_VENDOR_HYP_CALL_UID_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); } @@ -189,8 +193,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); @@ -217,6 +220,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) @@ -225,6 +229,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) @@ -317,6 +322,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; } @@ -343,6 +351,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; } @@ -445,6 +457,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 aadd6ae3ab72..4ebfdd26e486 100644 --- a/include/kvm/arm_hypercalls.h +++ b/include/kvm/arm_hypercalls.h @@ -9,9 +9,11 @@ /* 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(KVM_REG_ARM_STD_BMAP_BIT_MAX, 0) #define KVM_ARM_SMCCC_STD_HYP_FEATURES GENMASK(KVM_REG_ARM_STD_HYP_BMAP_BIT_MAX, 0) +#define KVM_ARM_SMCCC_VENDOR_HYP_FEATURES GENMASK(KVM_REG_ARM_VENDOR_HYP_BMAP_BIT_MAX, 0) int kvm_hvc_call_handler(struct kvm_vcpu *vcpu); -- 2.36.0.rc2.479.g8af0fa9b8e-goog