Received: by 2002:a05:6602:2086:0:0:0:0 with SMTP id a6csp3149976ioa; Mon, 25 Apr 2022 19:25:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyp+oPFW8DS3Emd1xYTiDNPz97v1PndcodwFzWYO/hl6gIxBCrRG9yhQIEGfv0jplbz2Yd3 X-Received: by 2002:a05:6a02:206:b0:399:3c9:f465 with SMTP id bh6-20020a056a02020600b0039903c9f465mr17882432pgb.388.1650939950694; Mon, 25 Apr 2022 19:25:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650939950; cv=none; d=google.com; s=arc-20160816; b=VuNJbnp0GFQSHx+z4hlW6raQnx8X8Dw+KIw58dQceRU0lYCgb4KYT85LFPM9hyTRzY ZwkYpRqd/KzRg4bGJEwa2R6X/xNsq+EAODzOcfpv3vgQSDCipvcoY9vAHVPFth8Ce8ty f+d/lIxfsMouQRw11mu+ElTjorIPfLSuNEgg/iYEaM/xfyze4VaI89UcVzRj99dzUShP pw/6nN4Ci/3t4O670N4ms22rYdDlPZ2XI+mBs7DH9zWXwpTaqQNCmQu4ZYFFnWfti6li XfDeK+nfgKnnLMPYKuzPOLtEr+tk0PRaEt7hp6BVnx9VLQRxDc4rksFG7JKnCB7SjlAu GCnw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=zFVXbK88HMZ7irS1EV3QbO6i92VJWq/msMeGHj6PNxc=; b=CAVx1UNdwOYZ39CMfli8PDRRF2ttaVusdXnqgOndJJHfCTAJ6ztbF2N5+bC4btZRHu 5+VRDjJJROTVYG+c1qWZycEyG/NX1ZvZyjAAN4x+Bb5LrNzGKIoQCpMpRjkM8CrKby6p LG96/7DJSzr1b5ILPyqKqa7CUKZ/nR+KcmwPLKk70YGI2OOEpsUrl7Dlv9OrO7YSb6NV 8CsFhPN7i2NgJwfh/1Jopm3riG6VFCkFvsJCWd8pMDbx1rs8qNaFjOR/WHVOawglFEZV hrwrO5spyCIhYtcS/cTUPM1aDQjYYAU13SAOENwtyBJUXIeD3XrIg7jRihX0EE5tacbu VSYA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=bUVEaQ2w; 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 t196-20020a6378cd000000b003a9fd4424a3si18967069pgc.666.2022.04.25.19.25.34; Mon, 25 Apr 2022 19:25:50 -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=bUVEaQ2w; 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 S229557AbiDYQzR (ORCPT + 99 others); Mon, 25 Apr 2022 12:55:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55888 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241922AbiDYQzO (ORCPT ); Mon, 25 Apr 2022 12:55:14 -0400 Received: from mail-yw1-x1132.google.com (mail-yw1-x1132.google.com [IPv6:2607:f8b0:4864:20::1132]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AD60D1A064 for ; Mon, 25 Apr 2022 09:52:08 -0700 (PDT) Received: by mail-yw1-x1132.google.com with SMTP id 00721157ae682-2ec42eae76bso154890477b3.10 for ; Mon, 25 Apr 2022 09:52:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=zFVXbK88HMZ7irS1EV3QbO6i92VJWq/msMeGHj6PNxc=; b=bUVEaQ2wIuKybo7kKQmoFYoEvIZ5UirP/KvquexNzuYtWoi/ArniVP0TSRhp/xPvF4 pjO88yRVQp/fFable34gX1YDVyJpMA9C9G2vEf8Kz486GPzw+RzufdXY/0jM7gTVCCsg PidMDRcF1CNXJn+3SjKJOWvA3RIB/cb9JqrhsFBu+iWytoAeilSrA/RMTgGjycGiMs+r 5N3rDehjoLGsJNyxZeUrYK3zFPcD2g2ZEbJpTAcnk8wQD7D/F/BZsTof8SScGzFdqDS7 6k9Kc58dLAu+v9oHuXu7fYVxWXbc48epu/owuKJq0cWH+V02p84jlw6M/HppCcWvNYzi MMOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=zFVXbK88HMZ7irS1EV3QbO6i92VJWq/msMeGHj6PNxc=; b=J1hhXiN7VSxLzMGO6qR51mRURvKqG6Ctg93kRJN3Xfu1d1eubA+/Y+1jLayfPYm6FP nv4xEgGc107hEH5/x/lLccwL1OqhBgyWjcdjPY0X3LWrEOCwL4qvtBf1drbSwW4LozZ2 4VWI7GD7PMk5hZ/yPYdCUGXkQL5EjCgjMjGstUCtykQpnK9clyHEf9Dant9wqvwVlzQJ 1ZAxu1Z6symp/RWEARkdklvx6ATMTXj8cc5ThcYGPsTdR2QrHWJjfwSKzmkEd4WQ0bIE OfbnT1h0ajJW/9yC7Cv7WyHI0b1pl31OX6kWdx+NqFPzanCsgbCZZbSDGHiFEgdgSh1G /QqA== X-Gm-Message-State: AOAM531GW5CY5zmYiiD7dN5PplzYUNJsvrwoWQqbiogxr0IcGl3i4b3o vVX7/xsQu1yMVdoU2fllTCHS7pw83KJB5QyyIUvQlQ== X-Received: by 2002:a0d:f007:0:b0:2f4:ce96:514b with SMTP id z7-20020a0df007000000b002f4ce96514bmr17915775ywe.148.1650905527631; Mon, 25 Apr 2022 09:52:07 -0700 (PDT) MIME-Version: 1.0 References: <20220423000328.2103733-1-rananta@google.com> <20220423000328.2103733-5-rananta@google.com> In-Reply-To: From: Raghavendra Rao Ananta Date: Mon, 25 Apr 2022 09:51:56 -0700 Message-ID: Subject: Re: [PATCH v6 4/9] KVM: arm64: Add vendor hypervisor firmware register To: Reiji Watanabe Cc: Marc Zyngier , Andrew Jones , James Morse , Alexandru Elisei , Suzuki K Poulose , Paolo Bonzini , Catalin Marinas , Will Deacon , Peter Shier , Ricardo Koller , Oliver Upton , Jing Zhang , Linux ARM , 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=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL 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 Hi Reiji, On Sun, Apr 24, 2022 at 11:22 PM Reiji Watanabe wrote: > > Hi Raghu, > > On Fri, Apr 22, 2022 at 5:03 PM Raghavendra Rao Ananta > wrote: > > > > 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 > > Nit: IMHO perhaps it might be more convenient to define the MAX macro > in arch/arm64/include/uapi/asm/kvm.h like below for maintenance ? > (The same comments are applied to other KVM_REG_ARM_*_BMAP_BIT_MAX) > > #define KVM_REG_ARM_VENDOR_HYP_BIT_MAX KVM_REG_ARM_VENDOR_HYP_BIT_PTP > We have been going back and forth on this :) It made sense for me to keep it in uapi as well, but I took Oliver's suggestion of keeping it outside of uapi since this is something that could be constantly changing [1]. Thank you. Raghavendra [1]: https://lore.kernel.org/lkml/CAJHc60wz5WsZWTn66i41+G4-dsjCFuFkthXU_Vf6QeXHkgzrZg@mail.gmail.com/ > Thanks, > Reiji > > > > > > #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 > >