From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.9]) (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 9155923392D for ; Tue, 13 Oct 2026 07:01:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.9 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791874864; cv=none; b=ChUvHX1p1k853fZtsuhUG6CgaNK/ZE8GIP7QyDJ5N3P4+pwwLXSAH5bE01TEFUu7TmwPFk/xCP6lkq6dJ+XLdoW9AsKth697m08fsTeVQZ5ykdCxfYqSJaEn0dAi16tHsvsHUDRGC2ltzUDBBt5MNqQZ0NORI/3ZJ+4l2ljC94Y= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791874864; c=relaxed/simple; bh=nHwSERJsT6WQQkrnp27DBccwlr2EGr/h0ZD74kUAGC8=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=c1YmJ2GUz28bVjsEMC5E7kkKPUjfgX/MpgR2nQzmZ5dHHXFu/5mEQ9m5Y/ibbuq1z0XKQI0QFeMcr+FimbeBAyFJwv9r6hgFV692vRhjP7M52FgrR+yc5Wx5MPH5IJooTEKZy+K4l1GESd8G92ufC22SVBhBn32PLLnWBnDOOHA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=pass smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=I7siIriO; arc=none smtp.client-ip=192.198.163.9 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="I7siIriO" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1791874863; x=1823410863; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=nHwSERJsT6WQQkrnp27DBccwlr2EGr/h0ZD74kUAGC8=; b=I7siIriOMgygrG+J3SR9ESPU8SpFEzXQLIhFib31+gXalvPjRCGtTcHt Bc3vgDbxuputZH6H+oNAx4UcdfjCPUDRLu7+0V70+LWfeGIvf4c1F6SIh 84vTmwuxfrXXefa8hhYoBKfdgmHWsQjwBQyWNFCaUewVxf7p7Y+UamjwD LJmmnwp4oaSlgoslhEREorsiZ23IYEyXV5sEdpbeySFLzsC+waeuz9Qp9 KtbGrQiyIiVHetSKbnS7PRIWNyKGeA9eJNsmC+zBiKZXgHbt3idcCaeIX zr1eu1QaeOs5qQTdvMguh9NItxQDRn1Dv+AQTDs0I3U5M/gpXnsXSSMtz w==; X-CSE-ConnectionGUID: rAbbv3NwQ3yCBpSnguUefQ== X-CSE-MsgGUID: aBoaux5qS+ONwWnfBsAo4w== X-IronPort-AV: E=McAfee;i="6800,10657,11933"; a="485840" X-IronPort-AV: E=Sophos;i="6.27,155,1787036400"; d="scan'208";a="485840" Received: from orviesa007.jf.intel.com ([10.64.159.147]) by fmvoesa103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Oct 2026 00:01:02 -0700 X-CSE-ConnectionGUID: 6KC7tvomQmKzCZESbFkwbw== X-CSE-MsgGUID: 1bYSzrRgSU24r03BSXEcSQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,155,1787036400"; d="scan'208";a="989803" Received: from unknown (HELO [10.238.2.98]) ([10.238.2.98]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Oct 2026 00:00:58 -0700 Message-ID: Date: Tue, 13 Oct 2026 15:00:56 +0800 Precedence: bulk X-Mailing-List: linux-coco@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v4 01/10] x86/virt/tdx: Add a helper to read a table of metadata fields To: Chao Gao Cc: linux-kernel@vger.kernel.org, linux-coco@lists.linux.dev, kvm@vger.kernel.org, yilun.xu@linux.intel.com, tony.lindgren@linux.intel.com, rick.p.edgecombe@intel.com, nik.borisov@suse.com, Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Kiryl Shutsemau References: <20261012094754.27702-1-chao.gao@intel.com> <20261012094754.27702-2-chao.gao@intel.com> Content-Language: en-US From: Binbin Wu In-Reply-To: <20261012094754.27702-2-chao.gao@intel.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 10/12/2026 5:47 PM, Chao Gao wrote: > The metadata field readers get_tdx_sys_info_() in > tdx_global_metadata.c were generated by an out-of-tree script. That has > not worked out: the JSON file they were generated from is neither stable > nor authoritative enough [1]. The goal now is to maintain the readers by > hand and to establish one standard way of adding a metadata field. > > Take get_tdx_sys_info_version() as an example: > > if (!ret && !(ret = read_sys_metadata_field(0x0800000100000003, &val))) > sysinfo_version->minor_version = val; > if (!ret && !(ret = read_sys_metadata_field(0x0800000100000004, &val))) > sysinfo_version->major_version = val; > if (!ret && !(ret = read_sys_metadata_field(0x0800000100000005, &val))) > sysinfo_version->update_version = val; > > Two patterns stand out: the read-check-store sequence repeats once per > field, and the error of each read is chained into the reads that follow. > Neither is common in hand-written code. > > Prepare to eliminate both with a loop that reads each field, stores the > value into its structure member, and returns on the first error. > > Add 'struct field_mapping' to describe one field as its ID plus the offset > and size of the member that receives its value. Add FIELD_MAP() to > build such an entry from a field ID, a structure type and a member name. > Add __read_sys_metadata_table() helper to read every field in a table. > Annotate that helper __maybe_unused as there is no caller right now. > > Following changes will convert the existing readers to use the new helper. > > AI was used under supervision to review code and workshop logs. It > suggested adding read_sys_metadata_table() macro, which avoids repeating > the table name when passing both the table and its size. > > Signed-off-by: Chao Gao > Reviewed-by: Nikolay Borisov > Reviewed-by: Rick Edgecombe > Link: https://lore.kernel.org/kvm/1e7bcbad-eb26-44b7-97ca-88ab53467212@intel.com/ # [1] Reviewed-by: Binbin Wu