Received: by 2002:a05:7412:5112:b0:fa:6e18:a558 with SMTP id fm18csp176834rdb; Mon, 22 Jan 2024 16:31:02 -0800 (PST) X-Google-Smtp-Source: AGHT+IHoQmH5HTSA6al60hRlFe0dFVFRV0df5Q2xaUFCaJHEBocZbsNsqGJDePeHrpz1QlLsKL9a X-Received: by 2002:a05:622a:1055:b0:42a:1ece:5640 with SMTP id f21-20020a05622a105500b0042a1ece5640mr79022qte.85.1705969862205; Mon, 22 Jan 2024 16:31:02 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705969862; cv=pass; d=google.com; s=arc-20160816; b=wglYvyav+vNcVfu40PRTw1xDaGXRy4Qt8Tkn5setkhdNOj4EAMmy8LHYN0mDja0TV+ RNDg/RCPzuJ9hRyY5gMEHT9l///1qaXtDmpxal8wz2hlaCpD7GnhfI5hh/hKvfdsd36e 9M5NoINBo1CXuIPL3OCEEy9XKjEYDkcXMzbLqNMz0oX9NCOTD3Ll326BkRWs2CAimQPI MPteL8Xrj2YtX/xQqYHIrdUuBsn/MzbeevrGnCXdjYMy5sECxiFHR8RaBUH6e6io71E2 ocBJ2Hbj98t5XCT4pFSkFWyFRI7nUJl96sOL5nBWsqLk78nLBX/BMyHgXV/Ly96S0j2d 8bzw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=jcs6z8gjyoCTkUGm9MQv4rNdOgqj+4G1dvQBvMjQoMQ=; fh=Itbyk7CEvizIrzGEESCqq3I2tZgG1kc/GkVOa3S7Hsg=; b=NIwqoSNB3s+PDL/e1QOCJr7x3VMSIs1NhIq+2hj+Z5m55yRll2g6598XZAreXLBI+8 6+44Jf+oKS4wKD2jiipAU0ygcHfB2O4/DB8oDukPYZHaWVScGB0Ku5lXKrKMv9jjh+rD 9OrlES5N6Q73kanM6RZTQobN1Bx1sxfC73CycUfp7PM6Be4unYWyWd1SM6CZ3Z0jk0cf bOhcHU+oqKzEJFWXsKtizJaaXLpFRfrXu2kg/XfINgUZ/npIDqMmyHnGvEfDpsdklshn 53b9DBhr1Dkk2qZjph7B5aq2Pfrup10ZLMzJQnX+ykbCMo917AIF3x3OUgIKvaTBYqaz K2xw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=hY5mcFvT; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-34326-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-34326-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id l16-20020a05622a175000b00429d2dfdfe5si6740306qtk.3.2024.01.22.16.31.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jan 2024 16:31:02 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-34326-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=hY5mcFvT; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-34326-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-34326-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 75FDD1C28409 for ; Tue, 23 Jan 2024 00:30:49 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4002058AA7; Mon, 22 Jan 2024 23:55:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="hY5mcFvT" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.15]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C2CCD57316; Mon, 22 Jan 2024 23:55:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.15 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705967708; cv=none; b=E1L0O4SYfNcaJ3tXc88+mgWvB67snUulhtZDr9oBhOplFg59qm1tpzbh97ylTFENVpHcoT7Yl6BF0GGKgxEnsIRHUeOAOV7Zwx2OuKzFTc3E8Ji11ZiIj5dwQjWK1EPXbYfAoNGLXrpTdcN7CPnXr2hvaGz4IDyiQk0gzUhYVZs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705967708; c=relaxed/simple; bh=ZF11mj6dOid+ewMs/d+5wakaEsG23KEAuAapce9+K/k=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=nTzrxzS32I8nMI91cKiVFDAH4TBxJ07dgWDkgZs56I6SxU9mzMZa3ZXqFWNgcW0OlNfP0aATDcq4+c4OZ459fhuLI7isr1hXtpL+w192rS6zNwo7/H1eC02uRPFhFyQXwEvgKpXKAaEUJ8yRL8iUkln6ubbADt4jcxocngsWIts= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=hY5mcFvT; arc=none smtp.client-ip=198.175.65.15 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1705967707; x=1737503707; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ZF11mj6dOid+ewMs/d+5wakaEsG23KEAuAapce9+K/k=; b=hY5mcFvTgVwcJiNb8lKNsk8o289uakYuexavwyOpk/U/EXTLJ3+xyOlA k3wH7syqTipHSSGmzXe0HMF0wewJvwdoYD08ViMqOYxDqFhZvf3Scznxd ITnEN6AUfoqFzuQTehTfp3+jGN8BebeQG0BOey14yPVkebkX4EeofVEPL 1pQWU0F9LAoO0QRm1h1V1uBDOK1xMzLZBcnFfqUtt8tWrQGT9Tb61uTbZ tBjPW2Q17lq5y5oA42lR4DkKpi7Mtk7j3JJJYfrEO3cTS/cVZKXNeim9B tsgON9Ijd7XstkLZYQ+CJO9E+rAWroRhd1XPjI0DSxio84cDmtE78fX6h g==; X-IronPort-AV: E=McAfee;i="6600,9927,10961"; a="1243775" X-IronPort-AV: E=Sophos;i="6.05,212,1701158400"; d="scan'208";a="1243775" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orvoesa107.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Jan 2024 15:55:06 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10961"; a="819888459" X-IronPort-AV: E=Sophos;i="6.05,212,1701158400"; d="scan'208";a="819888459" Received: from ls.sc.intel.com (HELO localhost) ([172.25.112.31]) by orsmga001-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Jan 2024 15:55:05 -0800 From: isaku.yamahata@intel.com To: kvm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: isaku.yamahata@intel.com, isaku.yamahata@gmail.com, Paolo Bonzini , erdemaktas@google.com, Sean Christopherson , Sagi Shahar , Kai Huang , chen.bo@intel.com, hang.yuan@intel.com, tina.zhang@intel.com Subject: [PATCH v18 019/121] KVM: TDX: Add helper function to read TDX metadata in array Date: Mon, 22 Jan 2024 15:52:55 -0800 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Isaku Yamahata To read meta data in series, use table. Instead of metadata_read(fid0, &data0); metadata_read(...); ... table = { {fid0, &data0}, ...}; metadata-read(tables). TODO: Once the TDX host code introduces its framework to read TDX metadata, drop this patch and convert the code that uses this. Signed-off-by: Isaku Yamahata --- v18: - newly added --- arch/x86/kvm/vmx/tdx.c | 45 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/arch/x86/kvm/vmx/tdx.c b/arch/x86/kvm/vmx/tdx.c index ee9d6a687d93..1608bdf2381d 100644 --- a/arch/x86/kvm/vmx/tdx.c +++ b/arch/x86/kvm/vmx/tdx.c @@ -6,6 +6,7 @@ #include "capabilities.h" #include "x86_ops.h" #include "x86.h" +#include "tdx_arch.h" #include "tdx.h" #undef pr_fmt @@ -40,6 +41,50 @@ static void __used tdx_guest_keyid_free(int keyid) ida_free(&tdx_guest_keyid_pool, keyid); } +#define TDX_MD_MAP(_fid, _ptr) \ + { .fid = MD_FIELD_ID_##_fid, \ + .ptr = (_ptr), } + +struct tdx_md_map { + u64 fid; + void *ptr; +}; + +static size_t tdx_md_element_size(u64 fid) +{ + switch (TDX_MD_ELEMENT_SIZE_CODE(fid)) { + case TDX_MD_ELEMENT_SIZE_8BITS: + return 1; + case TDX_MD_ELEMENT_SIZE_16BITS: + return 2; + case TDX_MD_ELEMENT_SIZE_32BITS: + return 4; + case TDX_MD_ELEMENT_SIZE_64BITS: + return 8; + default: + WARN_ON_ONCE(1); + return 0; + } +} + +int tdx_md_read(struct tdx_md_map *maps, int nr_maps) +{ + struct tdx_md_map *m; + int ret, i; + u64 tmp; + + for (i = 0; i < nr_maps; i++) { + m = &maps[i]; + ret = tdx_sys_metadata_field_read(m->fid, &tmp); + if (ret) + return ret; + + memcpy(m->ptr, &tmp, tdx_md_element_size(m->fid)); + } + + return 0; +} + static int __init tdx_module_setup(void) { int ret; -- 2.25.1