From patchwork Fri Jan 27 15:07:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Philippe Brucker X-Patchwork-Id: 647497 Delivered-To: patch@linaro.org Received: by 2002:a17:522:b9de:b0:4b9:b062:db3b with SMTP id fj30csp875193pvb; Fri, 27 Jan 2023 07:17:16 -0800 (PST) X-Google-Smtp-Source: AMrXdXuimCeeLvGFllBKJLYDwB/mwcVfOf80Z6OWsDtzvE3mcNON0pwRofl11zOFNH7QWbZqQYKQ X-Received: by 2002:a0c:c3ce:0:b0:532:23a5:8271 with SMTP id p14-20020a0cc3ce000000b0053223a58271mr60192379qvi.8.1674832635873; Fri, 27 Jan 2023 07:17:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674832635; cv=none; d=google.com; s=arc-20160816; b=qb601PUHY1uQ4213kQh0mLpAGs9n74VU37dgc+jLFQLtSV6hl4S/s/7z+xveFzB0WP p8F5nD2XTQRk9CmaGfpTxsf5QlB7rUV6F/KOEpt0t+H1jc1WVUFSQHPYno0FTCnOH8yP VmVtB1EqM4sEEwiMdZTen9X0QwasZJ8nGvh7eP+waZUZNLyNI/TcTrkRrZ7vWJX9Pxsr L6z0DNXVKv2Cx+KaV2w/5bMlqULxpEfqJu6jQ6dY2meMU8l/EAu+w2sc7EHgZT3TiBhg RFlgLeHbz5o+FOD8zLMHjDH42fNribc2vfnf6gvgxQTG1Lv4V/xRHRnPIXGZyKeHDMgX narA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=bbNu19WMzaLjGCFMUQxiaofERC3jNZB3M13lh/rHhCc=; b=qMLXGHjlIKYdxesP280NKBSgs+UEEQ8rtNJO8VgM1MWw2IjK3FqEe006mMCuufXS+k CV73JqQ79NGaDqfTvZqFCOuUXtLRovChocxat48Dl3kk4+b0f/aVUDA8sX6pYT6s5RRd n6X5LYbA/sGZaDALUsPpqq/2O3ml52RBb+xfmGv4oGUL4ngEV8hjLYrgDr3n2KjUCStF 9iaHdZv3sRggQUs8QKBqMSqNAEiVVZxY9z82cW1/3MXF/Lzvy1XqLZTwcPoZ2riz7gKh Qre5uRKrYu32xwLoNWyV1G7dGjavNw1BHbBhcOEDwXAEjCrC7yxeOnKIaqNdX6hDNmcG fR+A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=vDHzIbbu; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id p17-20020a0cc3d1000000b00531d6b0b38asi2516155qvi.268.2023.01.27.07.17.15 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 27 Jan 2023 07:17:15 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=vDHzIbbu; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pLQSi-0006Zo-82; Fri, 27 Jan 2023 10:16:20 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pLQSX-0006Ld-5V for qemu-devel@nongnu.org; Fri, 27 Jan 2023 10:16:09 -0500 Received: from mail-wm1-x32d.google.com ([2a00:1450:4864:20::32d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pLQSU-0007fg-1L for qemu-devel@nongnu.org; Fri, 27 Jan 2023 10:16:08 -0500 Received: by mail-wm1-x32d.google.com with SMTP id f19-20020a1c6a13000000b003db0ef4dedcso5622205wmc.4 for ; Fri, 27 Jan 2023 07:16:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=bbNu19WMzaLjGCFMUQxiaofERC3jNZB3M13lh/rHhCc=; b=vDHzIbbuzPY93SJqQ9+D1zj6THNjFE1vI5VlQp8/B6ZdwPY4v/VTMav34LqWWspTT7 8zc9ZQ/wsV5LG5aUByL4MPYDTDsAxe/hw5PIrArUWs0USenyEQ2hKpToh4G27Xm3yf5a /6C+7aWL0ndySonLO9cOxjTBY98cK1mMEhQRbynORjLyNV4umS1I2aIpslp20SgUFGOB t9Ks65xBBgiR2VRjwPTHNmEkUVtrKmtAUm+jkAM4kU+HQAGhZIY8ETk+YAWFzwGOtre1 93j28ER1xvvWFXI87o3oEmI28qAf0f2aeI473xtOhxccc80jyD10y5QibYZe37rmrcg5 8gDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=bbNu19WMzaLjGCFMUQxiaofERC3jNZB3M13lh/rHhCc=; b=wBLCCvqij2wmkrbNaNBzGrWM7rGr2LEYxkPZmOvW4C/tAhk2YpKGxRt8vT33P3iMKu CWAXICO5dsdOal68Y4U5UlEBbIb9XTW+QaIf+IcBb/Ci8Zy/8uue2HCWDwTmO+g0vsxK mcyXAR3HBsKll6pMnsagTzMIyMtaX/FgNXQkw4r7OiB7Wme2tOkfefLvVtYnODgNQmlG r/SupFjZKOKUMWBavHsJy5hb4WE09Yl2tyccv9wnI56R/GbFYEpLNHFkM/15tFkkITj6 eeGQ5P7mVUkmbENzBzlTZh1VwFFGJ3/KR+Rmgt/iz7ytfAUaHkwQz8InE51VHVAv+if0 8H3w== X-Gm-Message-State: AFqh2ko+2OSo4vbe07vYITUhLHySSaM63nbfH1j/KEFDcLXjnI2nyogv 3f98TwVYcISkwaBSrNZbpDObLdZSeEWyn4NRf+0aBQ== X-Received: by 2002:a05:600c:43d3:b0:3da:fbcd:cdd2 with SMTP id f19-20020a05600c43d300b003dafbcdcdd2mr40652021wmn.9.1674832563598; Fri, 27 Jan 2023 07:16:03 -0800 (PST) Received: from localhost.localdomain (054592b0.skybroadband.com. [5.69.146.176]) by smtp.gmail.com with ESMTPSA id l7-20020a05600c47c700b003dc3bbdf518sm1656628wmo.21.2023.01.27.07.16.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Jan 2023 07:16:03 -0800 (PST) From: Jean-Philippe Brucker To: peter.maydell@linaro.org Cc: qemu-devel@nongnu.org, qemu-arm@nongnu.org, pbonzini@redhat.com, eblake@redhat.com, armbru@redhat.com, berrange@redhat.com, eduardo@habkost.net, alex.bennee@linaro.org, richard.henderson@linaro.org, Jean-Philippe Brucker Subject: [RFC PATCH 10/16] target/arm/kvm-rme: Add measurement algorithm property Date: Fri, 27 Jan 2023 15:07:23 +0000 Message-Id: <20230127150727.612594-11-jean-philippe@linaro.org> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230127150727.612594-1-jean-philippe@linaro.org> References: <20230127150727.612594-1-jean-philippe@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32d; envelope-from=jean-philippe@linaro.org; helo=mail-wm1-x32d.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org This option selects which measurement algorithm to use for attestation. Supported values are sha256 and sha512. Signed-off-by: Jean-Philippe Brucker --- qapi/qom.json | 14 ++++++++- target/arm/kvm-rme.c | 71 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 84 insertions(+), 1 deletion(-) diff --git a/qapi/qom.json b/qapi/qom.json index 7ca27bb86c..87fe7c31fe 100644 --- a/qapi/qom.json +++ b/qapi/qom.json @@ -855,6 +855,17 @@ 'data': { '*cpu-affinity': ['uint16'], '*node-affinity': ['uint16'] } } +## +# @RmeGuestProperties: +# +# Properties for rme-guest objects. +# +# @measurement-algo: Realm measurement algorithm (default: RMM default) +# +# Since: FIXME +## +{ 'struct': 'RmeGuestProperties', + 'data': { '*measurement-algo': 'str' } } ## # @ObjectType: @@ -985,7 +996,8 @@ 'tls-creds-x509': 'TlsCredsX509Properties', 'tls-cipher-suites': 'TlsCredsProperties', 'x-remote-object': 'RemoteObjectProperties', - 'x-vfio-user-server': 'VfioUserServerProperties' + 'x-vfio-user-server': 'VfioUserServerProperties', + 'rme-guest': 'RmeGuestProperties' } } ## diff --git a/target/arm/kvm-rme.c b/target/arm/kvm-rme.c index c8c019f78a..3929b941ae 100644 --- a/target/arm/kvm-rme.c +++ b/target/arm/kvm-rme.c @@ -22,10 +22,13 @@ OBJECT_DECLARE_SIMPLE_TYPE(RmeGuest, RME_GUEST) #define RME_PAGE_SIZE qemu_real_host_page_size() +#define RME_MAX_CFG 1 + typedef struct RmeGuest RmeGuest; struct RmeGuest { ConfidentialGuestSupport parent_obj; + char *measurement_algo; }; struct RmeImage { @@ -62,6 +65,40 @@ static int rme_create_rd(RmeGuest *guest, Error **errp) return ret; } +static int rme_configure_one(RmeGuest *guest, uint32_t cfg, Error **errp) +{ + int ret; + const char *cfg_str; + struct kvm_cap_arm_rme_config_item args = { + .cfg = cfg, + }; + + switch (cfg) { + case KVM_CAP_ARM_RME_CFG_HASH_ALGO: + if (!guest->measurement_algo) { + return 0; + } + if (!strcmp(guest->measurement_algo, "sha256")) { + args.hash_algo = KVM_CAP_ARM_RME_MEASUREMENT_ALGO_SHA256; + } else if (!strcmp(guest->measurement_algo, "sha512")) { + args.hash_algo = KVM_CAP_ARM_RME_MEASUREMENT_ALGO_SHA512; + } else { + g_assert_not_reached(); + } + cfg_str = "hash algorithm"; + break; + default: + g_assert_not_reached(); + } + + ret = kvm_vm_enable_cap(kvm_state, KVM_CAP_ARM_RME, 0, + KVM_CAP_ARM_RME_CONFIG_REALM, (intptr_t)&args); + if (ret) { + error_setg_errno(errp, -ret, "RME: failed to configure %s", cfg_str); + } + return ret; +} + static void rme_populate_realm(gpointer data, gpointer user_data) { int ret; @@ -128,6 +165,7 @@ static void rme_vm_state_change(void *opaque, bool running, RunState state) int kvm_arm_rme_init(ConfidentialGuestSupport *cgs, Error **errp) { int ret; + int cfg; static Error *rme_mig_blocker; RmeGuest *guest = cgs_to_rme(cgs); @@ -146,6 +184,13 @@ int kvm_arm_rme_init(ConfidentialGuestSupport *cgs, Error **errp) return -ENODEV; } + for (cfg = 0; cfg < RME_MAX_CFG; cfg++) { + ret = rme_configure_one(guest, cfg, errp); + if (ret) { + return ret; + } + } + ret = rme_create_rd(guest, errp); if (ret) { return ret; @@ -215,8 +260,34 @@ int kvm_arm_rme_vm_type(MachineState *ms) return 0; } +static char *rme_get_measurement_algo(Object *obj, Error **errp) +{ + RmeGuest *guest = RME_GUEST(obj); + + return g_strdup(guest->measurement_algo); +} + +static void rme_set_measurement_algo(Object *obj, const char *value, + Error **errp) +{ + RmeGuest *guest = RME_GUEST(obj); + + if (strncmp(value, "sha256", 6) && + strncmp(value, "sha512", 6)) { + error_setg(errp, "invalid Realm measurement algorithm '%s'", value); + return; + } + g_free(guest->measurement_algo); + guest->measurement_algo = g_strdup(value); +} + static void rme_guest_class_init(ObjectClass *oc, void *data) { + object_class_property_add_str(oc, "measurement-algo", + rme_get_measurement_algo, + rme_set_measurement_algo); + object_class_property_set_description(oc, "measurement-algo", + "Realm measurement algorithm ('sha256', 'sha512')"); } static const TypeInfo rme_guest_info = {