From patchwork Fri Jan 27 11:39:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suzuki K Poulose X-Patchwork-Id: 49351 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp808479wrn; Fri, 27 Jan 2023 04:34:18 -0800 (PST) X-Google-Smtp-Source: AK7set/newgxU8slGEQA9K3dBvQb/qavrn4KsJNooWTVsexRtyMBDx3ckjr+LB27Jpf6G6eO2cK8 X-Received: by 2002:a17:90b:38ca:b0:229:ee6d:4178 with SMTP id nn10-20020a17090b38ca00b00229ee6d4178mr6354937pjb.38.1674822858049; Fri, 27 Jan 2023 04:34:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674822858; cv=none; d=google.com; s=arc-20160816; b=FOkonZeXwgqmDyy5aZsCkDV0eJql8fiYhdG6Ing0kiZfG7UFZdidg72xP9lS4xiFkK v6MBWV2sANhL8PYDvHPHB68jojk92RYSoHceaWT3gzpkoPHd1V4OgucZ3jKHkvRlsHag qPCaclI2byMeHTNfvP/+VfYGVL/I+fPFAmt2P2+dfLV42bYDzuCnF8DOMUroE8RfPmB1 MkjqmODeNpGXhPe3DLmfan9w1cQmHhTrmPvhHOEAm4W3k2G1ylt5o33dG99eE2aLh1b9 W7haKIFYc5ux6mr/wEejMD+da/hL0it1Hhumx399H0HS8uY1EFD+96CW2cCtbM5zyPZL QFAA== 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; bh=OlKyCiUBlVLKfaW9BUDrCJzCFpXiBMb5iaEca12x1Uo=; b=vCHZKRISPcQ7fEGN4dU467BEhfiwfrLws2eHlWS9cIaYhpPpaEi0fF48gQGs0un+SZ ZHwB2GBapXO0AwuEeqOt/5F8z1tg+ogNuXcNer6SMN7ZZKu9+rYDePIOpgyMC3HOTf9l ndDx8Et8050UI6NMjzJ9i91BpVX6A7Qz58OuHZcZslZ9DwUN5xFb63iFjusXWlUC7e8q Qo/C4uyeg4BYughhsBEmz8P4F9vAlxz5kqrRdt+u1w2dXpE7J9ONhudBcTawurR/jpjQ SgH/p6029/YMganiQsddh/672rCRpB0f5ajToNBKefUOn+fxwoH82XIHfDTRy1zgh/CX kFpA== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i11-20020a63bf4b000000b004adff260cc0si3880900pgo.352.2023.01.27.04.34.05; Fri, 27 Jan 2023 04:34:18 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233446AbjA0MUC (ORCPT + 99 others); Fri, 27 Jan 2023 07:20:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52350 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233541AbjA0MT3 (ORCPT ); Fri, 27 Jan 2023 07:19:29 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 349088324C; Fri, 27 Jan 2023 04:16:08 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 95E9C175D; Fri, 27 Jan 2023 03:41:13 -0800 (PST) Received: from ewhatever.cambridge.arm.com (ewhatever.cambridge.arm.com [10.1.197.1]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 186843F64C; Fri, 27 Jan 2023 03:40:28 -0800 (PST) From: Suzuki K Poulose To: kvm@vger.kernel.org, kvmarm@lists.linux.dev Cc: suzuki.poulose@arm.com, Alexandru Elisei , Andrew Jones , Christoffer Dall , Fuad Tabba , Jean-Philippe Brucker , Joey Gouly , Marc Zyngier , Mark Rutland , Oliver Upton , Paolo Bonzini , Quentin Perret , Steven Price , Thomas Huth , Will Deacon , Zenghui Yu , linux-coco@lists.linux.dev, kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [RFC kvmtool 15/31] arm64: Add support for Realm Personalisation Value Date: Fri, 27 Jan 2023 11:39:16 +0000 Message-Id: <20230127113932.166089-16-suzuki.poulose@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230127113932.166089-1-suzuki.poulose@arm.com> References: <20230127112248.136810-1-suzuki.poulose@arm.com> <20230127113932.166089-1-suzuki.poulose@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE 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?1756179053200288796?= X-GMAIL-MSGID: =?utf-8?q?1756179053200288796?= Add option to specify Realm personalisation value Signed-off-by: Suzuki K Poulose --- arm/aarch64/include/kvm/kvm-config-arch.h | 6 +++++- arm/aarch64/kvm.c | 7 +++++++ arm/aarch64/realm.c | 23 +++++++++++++++++++++++ arm/include/arm-common/kvm-config-arch.h | 1 + 4 files changed, 36 insertions(+), 1 deletion(-) diff --git a/arm/aarch64/include/kvm/kvm-config-arch.h b/arm/aarch64/include/kvm/kvm-config-arch.h index b93999b6..f2e659ad 100644 --- a/arm/aarch64/include/kvm/kvm-config-arch.h +++ b/arm/aarch64/include/kvm/kvm-config-arch.h @@ -26,7 +26,11 @@ int vcpu_affinity_parser(const struct option *opt, const char *arg, int unset); "Create VM running in a realm using Arm RME"), \ OPT_STRING('\0', "measurement-algo", &(cfg)->measurement_algo, \ "sha256, sha512", \ - "Realm Measurement algorithm, default: sha256"), + "Realm Measurement algorithm, default: sha256"),\ + OPT_STRING('\0', "realm-pv", &(cfg)->realm_pv, \ + "personalisation value", \ + "Personalisation Value (only) for Realm VMs"), + #include "arm-common/kvm-config-arch.h" diff --git a/arm/aarch64/kvm.c b/arm/aarch64/kvm.c index a5a98b2e..4798e359 100644 --- a/arm/aarch64/kvm.c +++ b/arm/aarch64/kvm.c @@ -56,6 +56,8 @@ static void validate_realm_cfg(struct kvm *kvm) if (!kvm->cfg.arch.is_realm) { if (kvm->cfg.arch.measurement_algo) die("--measurement-algo valid only with --realm"); + if (kvm->cfg.arch.realm_pv) + die("--realm-pv valid only with --realm"); return; } @@ -74,6 +76,11 @@ static void validate_realm_cfg(struct kvm *kvm) kvm->arch.measurement_algo = KVM_CAP_ARM_RME_MEASUREMENT_ALGO_SHA256; } + if (kvm->cfg.arch.realm_pv) { + if (strlen(kvm->cfg.arch.realm_pv) > KVM_CAP_ARM_RME_RPV_SIZE) + die("Invalid size for Realm Personalization Value\n"); + } + die("Realms not supported"); } diff --git a/arm/aarch64/realm.c b/arm/aarch64/realm.c index 31543e55..2e0be982 100644 --- a/arm/aarch64/realm.c +++ b/arm/aarch64/realm.c @@ -20,9 +20,32 @@ static void realm_configure_hash_algo(struct kvm *kvm) die_perror("KVM_CAP_RME(KVM_CAP_ARM_RME_CONFIG_REALM) hash_algo"); } +static void realm_configure_rpv(struct kvm *kvm) +{ + struct kvm_cap_arm_rme_config_item rpv_cfg = { + .cfg = KVM_CAP_ARM_RME_CFG_RPV, + }; + + struct kvm_enable_cap rme_config = { + .cap = KVM_CAP_ARM_RME, + .args[0] = KVM_CAP_ARM_RME_CONFIG_REALM, + .args[1] = (u64)&rpv_cfg, + }; + + if (!kvm->cfg.arch.realm_pv) + return; + + memset(&rpv_cfg.rpv, 0, sizeof(rpv_cfg.rpv)); + memcpy(&rpv_cfg.rpv, kvm->cfg.arch.realm_pv, strlen(kvm->cfg.arch.realm_pv)); + + if (ioctl(kvm->vm_fd, KVM_ENABLE_CAP, &rme_config) < 0) + die_perror("KVM_CAP_RME(KVM_CAP_ARM_RME_CONFIG_REALM) RPV"); +} + static void realm_configure_parameters(struct kvm *kvm) { realm_configure_hash_algo(kvm); + realm_configure_rpv(kvm); } void kvm_arm_realm_create_realm_descriptor(struct kvm *kvm) diff --git a/arm/include/arm-common/kvm-config-arch.h b/arm/include/arm-common/kvm-config-arch.h index a2faa3af..80a3b18e 100644 --- a/arm/include/arm-common/kvm-config-arch.h +++ b/arm/include/arm-common/kvm-config-arch.h @@ -7,6 +7,7 @@ struct kvm_config_arch { const char *dump_dtb_filename; const char *vcpu_affinity; const char *measurement_algo; + const char *realm_pv; unsigned int force_cntfrq; bool virtio_trans_pci; bool aarch32_guest;