From nobody Sun Nov 24 02:52:41 2024 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 A92A6213156; Thu, 7 Nov 2024 18:46:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731005170; cv=none; b=l/hZgZLRDCruniRn9f9No55OqEbAENQBEhfJRrXKfVK+Ubu57A79Fle4egtaLN3qTJlrY/buofUfDR0MyfaAp6ESXeF2RVLS6RCM41s/AikN3ecxhNyCcMT003Jm2U5XSF4Ka7oBeyyH6gP3dlFc8qkJhjb/fhv51FvMxsfh/Ow= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731005170; c=relaxed/simple; bh=d+HVZ96dhySnPtdPKaN66DmxuRSAf/tCHLCu3pd+Pkk=; h=Date:From:To:Subject:Cc:MIME-Version:Message-ID:Content-Type; b=mjFU8OF71Rm/n/8bVy7WU74yl5fFTaR0OIuHkKpsxQsHKeVg1Ha8x+qvGcR4brnF8+XkdhN7HeY8YzfDeUvMwDUod5hBJ7CuOlPNbeJycadUiWLRBGyl1SltKSnHq8w4KnJg1f/o+MWumW/6XGSGc+qtMFDgEoltKOgbFHVR+II= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=o7plm+36; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=W05UvKOM; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="o7plm+36"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="W05UvKOM" Date: Thu, 07 Nov 2024 18:46:05 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1731005167; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=hh7+0f0/rl+C+8WYDELUsLbzYn+wV8qBDMcStm6x+7o=; b=o7plm+360Q9g4fwpCENj1tDjOXs7hlhIDT4YSfr5tCfvbTsd8uD//B4GDakb0zgkrs/ZQF COgXO/ubmjGN8DWLwPh/QbFO3DE2wcJPKCBsxYOP9b0HdT6JyatTgG8STKvYIzxt46X4j8 /8TcWEUTaWpDdzx3C9jydJxbBbHDsmLDAk8VMa47zIR2jBHCbnqA+UvZb3u/I5HMwi9ruP QV5S8Lp7G/E3O9P0D+qweKD3AA4HvDIBJYmug2tsR9wDQFTLczIG4cVlU24+OTgKWChJb6 lTWCQBXDwFq3wRPn9p/Z9BqNoVZ+wmcfBElf4I1LNJ/sVAQuZzGa8E5B3ahsYQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1731005167; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=hh7+0f0/rl+C+8WYDELUsLbzYn+wV8qBDMcStm6x+7o=; b=W05UvKOMlqnOJV0VmwwnKG8t9qOeCpSAcZPOu1fcyp3u8BiQIYm7d8XUjhD/TZbod40+a2 vrQIvWLROWQh/+Cg== From: "tip-bot2 for Kirill A. Shutemov" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/tdx] x86/tdx: Introduce wrappers to read and write TD metadata Cc: "Kirill A. Shutemov" , Dave Hansen , Kai Huang , Kuppuswamy Sathyanarayanan , x86@kernel.org, linux-kernel@vger.kernel.org Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-ID: <173100516590.32228.8006951654724476248.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Precedence: bulk Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable The following commit has been merged into the x86/tdx branch of tip: Commit-ID: 5081e8fadb809253c911b349b01d87c5b4e3fec5 Gitweb: https://git.kernel.org/tip/5081e8fadb809253c911b349b01d87c5b= 4e3fec5 Author: Kirill A. Shutemov AuthorDate: Mon, 04 Nov 2024 12:38:00 +02:00 Committer: Dave Hansen CommitterDate: Thu, 07 Nov 2024 10:26:16 -08:00 x86/tdx: Introduce wrappers to read and write TD metadata The TDG_VM_WR TDCALL is used to ask the TDX module to change some TD-specific VM configuration. There is currently only one user in the kernel of this TDCALL leaf. More will be added shortly. Refactor to make way for more users of TDG_VM_WR who will need to modify other TD configuration values. Add a wrapper for the TDG_VM_RD TDCALL that requests TD-specific metadata from the TDX module. There are currently no users for TDG_VM_RD. Mark it as __maybe_unused until the first user appears. This is preparation for enumeration and enabling optional TD features. Signed-off-by: Kirill A. Shutemov Signed-off-by: Dave Hansen Reviewed-by: Kai Huang Reviewed-by: Kuppuswamy Sathyanarayanan Link: https://lore.kernel.org/all/20241104103803.195705-2-kirill.shutemov%4= 0linux.intel.com --- arch/x86/coco/tdx/tdx.c | 32 +++++++++++++++++++++++++----- arch/x86/include/asm/shared/tdx.h | 1 +- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/arch/x86/coco/tdx/tdx.c b/arch/x86/coco/tdx/tdx.c index 327c45c..c74bb9e 100644 --- a/arch/x86/coco/tdx/tdx.c +++ b/arch/x86/coco/tdx/tdx.c @@ -78,6 +78,32 @@ static inline void tdcall(u64 fn, struct tdx_module_args= *args) panic("TDCALL %lld failed (Buggy TDX module!)\n", fn); } =20 +/* Read TD-scoped metadata */ +static inline u64 __maybe_unused tdg_vm_rd(u64 field, u64 *value) +{ + struct tdx_module_args args =3D { + .rdx =3D field, + }; + u64 ret; + + ret =3D __tdcall_ret(TDG_VM_RD, &args); + *value =3D args.r8; + + return ret; +} + +/* Write TD-scoped metadata */ +static inline u64 tdg_vm_wr(u64 field, u64 value, u64 mask) +{ + struct tdx_module_args args =3D { + .rdx =3D field, + .r8 =3D value, + .r9 =3D mask, + }; + + return __tdcall(TDG_VM_WR, &args); +} + /** * tdx_mcall_get_report0() - Wrapper to get TDREPORT0 (a.k.a. TDREPORT * subtype 0) using TDG.MR.REPORT TDCALL. @@ -929,10 +955,6 @@ static void tdx_kexec_finish(void) =20 void __init tdx_early_init(void) { - struct tdx_module_args args =3D { - .rdx =3D TDCS_NOTIFY_ENABLES, - .r9 =3D -1ULL, - }; u64 cc_mask; u32 eax, sig[3]; =20 @@ -951,7 +973,7 @@ void __init tdx_early_init(void) cc_set_mask(cc_mask); =20 /* Kernel does not use NOTIFY_ENABLES and does not need random #VEs */ - tdcall(TDG_VM_WR, &args); + tdg_vm_wr(TDCS_NOTIFY_ENABLES, 0, -1ULL); =20 /* * All bits above GPA width are reserved and kernel treats shared bit diff --git a/arch/x86/include/asm/shared/tdx.h b/arch/x86/include/asm/share= d/tdx.h index fdfd415..7e12cfa 100644 --- a/arch/x86/include/asm/shared/tdx.h +++ b/arch/x86/include/asm/shared/tdx.h @@ -16,6 +16,7 @@ #define TDG_VP_VEINFO_GET 3 #define TDG_MR_REPORT 4 #define TDG_MEM_PAGE_ACCEPT 6 +#define TDG_VM_RD 7 #define TDG_VM_WR 8 =20 /* TDCS fields. To be used by TDG.VM.WR and TDG.VM.RD module calls */