From patchwork Tue Mar 11 09:42:22 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Garzarella X-Patchwork-Id: 14011411 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (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 1BE9722F177 for ; Tue, 11 Mar 2025 09:42:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741686163; cv=none; b=tPcoa+VRlc2rt8moN8LRm9+7A/UBSZQHAD/lwF44yFmCFA+hSfYzhGST1DNCwjx78eCL6NIxBB2O+PwyFGTYTFWrGGwpeGjgW4FGtHxSeJ1OLRBZUZ+I052SgXlL+diz77XLScWELlsFlKAdHr/o8wQPzfOJV6ObIHSqH/NxuPE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741686163; c=relaxed/simple; bh=s48TuCB7hx4s0XQbfy+bStqom7rSsuzABfR49ZEXiRE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=IhPh6l2ClmC1CyfSDkpCCGUVfWNlmGHiMgRKTVJcJY+cQshvvlu/CpNBpVyY3Rf8nV+XxsVBKg9nKHCDI9gqnxUxkO7T2EKU+UdsETbRlb0NaBQIXwSXYhUCGCH5OB42UQL1K5hPyA0VsD/DZXuvB4VXixKsM08YUAVuDpvedwY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=NnQwczqG; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="NnQwczqG" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1741686161; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=gWbgBYfOGia6Jpo6dySuLR4cc3OA1mqpDszmSXqcblw=; b=NnQwczqGyvP5vvHiUDrWVQW8hszS5mteCIhlm2kXwgJDOLF0fcufUnnNGCNofMzIRYgAKw DYs8nh/ExDB1GYcd0hQZS0oW3cYFAsrUK3iuqm5IfQ/ztNwhDMpvQctoL4c4oZacOq5GAZ CymEnDUeVggnoqMZ0PvNePhaKUV04PI= Received: from mail-ej1-f71.google.com (mail-ej1-f71.google.com [209.85.218.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-569-lzDnYXFNNqCIx3iV7yB2pQ-1; Tue, 11 Mar 2025 05:42:39 -0400 X-MC-Unique: lzDnYXFNNqCIx3iV7yB2pQ-1 X-Mimecast-MFC-AGG-ID: lzDnYXFNNqCIx3iV7yB2pQ_1741686158 Received: by mail-ej1-f71.google.com with SMTP id a640c23a62f3a-ac27ea62032so221323066b.1 for ; Tue, 11 Mar 2025 02:42:39 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741686158; x=1742290958; 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=gWbgBYfOGia6Jpo6dySuLR4cc3OA1mqpDszmSXqcblw=; b=D1x9h4nA7y6Ap7A6esWg3zGRRj8dvMT0UQNRa9aoCzOG2LL3wAUy42KroyG10PVC1Z mKqtHWuDYJb9fz8WSUHV3UkgiAeYTc4M8+BihUq7E55qCRNjKeVq52hvDDgZffELzyU7 V05QoOZYm2X7Q/qD+QGvRN//SmBxIb5amft68MZTS996tn6B7Ei/CCGlhKdfFT7o1dfa O4ypFQCKqeKhXIK1kLJFus5wqxYO7PUX0UsZjfKaVdGIe3XthfGkkbwhAzLJYYo4bke3 PvhcwADq1dkqJMn8nfQd17by/CRoKqyu9TWyJrZqf+QvIE3a+SQ4gC1caKGkrTeOsfMv DReQ== X-Forwarded-Encrypted: i=1; AJvYcCW46JMifk4qZWN7Y0gUXs8dOwg12ttNJlzJgb/BKopPZog/zbe//hvSu71n3/0v+Wc2oz69v8ppx/UYKEiwtXg=@vger.kernel.org X-Gm-Message-State: AOJu0YznehqFf+8z+yo/YpVE+FsyOYSg1QZO0ZM2i7/PGolj6ECMJWNF HA/F71OWXF1ZgN+vmMb8PfK/ifC2MVjVTVMyPVoapY0TfFsApfLKfq9H9yzhLqnmPKAbzuxQngt NtjdP5fhJmlVmGKdlprbhBeGjdOZiIfjY7xVKp8QidhNkBNSr0tnQcHjtEPaRGT7jOw== X-Gm-Gg: ASbGncssm2BqXOoRvkdXV/aUZDDsQobjMnros+pvfYd8F7xv9OA8AiIJ6UBDM5IlkAl ofgKzcH9Lx65TTb9kvz3hc23gRCAPoisUVcYXGU+l6YqFCq/A1T9gEADfmDEwe7DJVFhjhXCQ+q H52yH+yrAUlph795rVbD8rYDqf+y7SJbj/jfKLd6OpFHvFfxy4yTpdykSWg0/I2VYtfQLM7vzcT kUA155lAjpMsd6lmZdqDIUfsVGaSqBq3RAifDKRiUMg1wa7cWGi+Lm99/dIdZ+8yjgoevYzzrTU UiwkU/j9id0pmmzSr+NL0m0UM3e0zuN4sZY0WAB0VrDa9gK6mm8s52qoRfSf/CBSP+/qR3Gf X-Received: by 2002:a05:6402:254a:b0:5e6:1602:bfbb with SMTP id 4fb4d7f45d1cf-5e75f984412mr3427187a12.27.1741686158199; Tue, 11 Mar 2025 02:42:38 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEPkM6rVc1QOWMePtECn1wZste/fTBV6MwarFwJ8JBd8XyGWLzR60WZC4WklV0jI8qfpX5GoA== X-Received: by 2002:a05:6402:254a:b0:5e6:1602:bfbb with SMTP id 4fb4d7f45d1cf-5e75f984412mr3427137a12.27.1741686157633; Tue, 11 Mar 2025 02:42:37 -0700 (PDT) Received: from localhost.localdomain (host-79-46-200-29.retail.telecomitalia.it. [79.46.200.29]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5e5c7472169sm8085277a12.24.2025.03.11.02.42.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Mar 2025 02:42:36 -0700 (PDT) From: Stefano Garzarella To: Jarkko Sakkinen Cc: Peter Huewe , Tom Lendacky , Jason Gunthorpe , x86@kernel.org, linux-kernel@vger.kernel.org, Borislav Petkov , linux-integrity@vger.kernel.org, Dov Murik , Dionna Glaze , linux-coco@lists.linux.dev, James Bottomley , Claudio Carvalho , Ingo Molnar , "H. Peter Anvin" , Thomas Gleixner , Dave Hansen , Joerg Roedel , Stefano Garzarella Subject: [PATCH v3 1/4] x86/sev: add SVSM vTPM probe/send_command functions Date: Tue, 11 Mar 2025 10:42:22 +0100 Message-ID: <20250311094225.35129-2-sgarzare@redhat.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250311094225.35129-1-sgarzare@redhat.com> References: <20250311094225.35129-1-sgarzare@redhat.com> Precedence: bulk X-Mailing-List: linux-integrity@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add two new functions to probe and send commands to the SVSM vTPM. They leverage the two calls defined by the AMD SVSM specification [1] for the vTPM protocol: SVSM_VTPM_QUERY and SVSM_VTPM_CMD. Expose these functions to be used by other modules such as a tpm driver. [1] "Secure VM Service Module for SEV-SNP Guests" Publication # 58019 Revision: 1.00 Co-developed-by: James Bottomley Signed-off-by: James Bottomley Co-developed-by: Claudio Carvalho Signed-off-by: Claudio Carvalho Signed-off-by: Stefano Garzarella Reviewed-by: Tom Lendacky --- v3: - removed link to the spec because those URLs are unstable [Borislav] - squashed "x86/sev: add SVSM call macros for the vTPM protocol" patch in this one [Borislav] - slimmed down snp_svsm_vtpm_probe() [Borislav] - removed features check and any print related [Tom] --- arch/x86/include/asm/sev.h | 7 +++++++ arch/x86/coco/sev/core.c | 31 +++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/arch/x86/include/asm/sev.h b/arch/x86/include/asm/sev.h index ba7999f66abe..09471d058ce5 100644 --- a/arch/x86/include/asm/sev.h +++ b/arch/x86/include/asm/sev.h @@ -384,6 +384,10 @@ struct svsm_call { #define SVSM_ATTEST_SERVICES 0 #define SVSM_ATTEST_SINGLE_SERVICE 1 +#define SVSM_VTPM_CALL(x) ((2ULL << 32) | (x)) +#define SVSM_VTPM_QUERY 0 +#define SVSM_VTPM_CMD 1 + #ifdef CONFIG_AMD_MEM_ENCRYPT extern u8 snp_vmpl; @@ -481,6 +485,9 @@ void snp_msg_free(struct snp_msg_desc *mdesc); int snp_send_guest_request(struct snp_msg_desc *mdesc, struct snp_guest_req *req, struct snp_guest_request_ioctl *rio); +bool snp_svsm_vtpm_probe(void); +int snp_svsm_vtpm_send_command(u8 *buffer); + void __init snp_secure_tsc_prepare(void); void __init snp_secure_tsc_init(void); diff --git a/arch/x86/coco/sev/core.c b/arch/x86/coco/sev/core.c index 96c7bc698e6b..2166bdff88b7 100644 --- a/arch/x86/coco/sev/core.c +++ b/arch/x86/coco/sev/core.c @@ -2628,6 +2628,37 @@ static int snp_issue_guest_request(struct snp_guest_req *req, struct snp_req_dat return ret; } +bool snp_svsm_vtpm_probe(void) +{ + struct svsm_call call = {}; + + /* The vTPM device is available only if a SVSM is present */ + if (!snp_vmpl) + return false; + + call.caa = svsm_get_caa(); + call.rax = SVSM_VTPM_CALL(SVSM_VTPM_QUERY); + + if (svsm_perform_call_protocol(&call)) + return false; + + /* Check platform commands contains TPM_SEND_COMMAND - platform command 8 */ + return (call.rcx_out & BIT_ULL(8)) == BIT_ULL(8); +} +EXPORT_SYMBOL_GPL(snp_svsm_vtpm_probe); + +int snp_svsm_vtpm_send_command(u8 *buffer) +{ + struct svsm_call call = {}; + + call.caa = svsm_get_caa(); + call.rax = SVSM_VTPM_CALL(SVSM_VTPM_CMD); + call.rcx = __pa(buffer); + + return svsm_perform_call_protocol(&call); +} +EXPORT_SYMBOL_GPL(snp_svsm_vtpm_send_command); + static struct platform_device sev_guest_device = { .name = "sev-guest", .id = -1, From patchwork Tue Mar 11 09:42:23 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Garzarella X-Patchwork-Id: 14011412 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (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 850C722F3A8 for ; Tue, 11 Mar 2025 09:42:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741686168; cv=none; b=DfgBks+lDpxRbbtEeKXl6f/Iu4699f6XcBMyu/ZVBMmtn4xsxMXXQOWMJuLnANFngLRYp4xtsFhzgAoxf6osjDpiJCRWK/ViQlNVdgwgCtznNJhsanAQ005bZPJpXsFKySv72c0UzH2blEuJeW+6+z5GrKh7VYbz2x4qxAdqGtc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741686168; c=relaxed/simple; bh=/A3bynKEsxmf0Y53DPDvuqNqTHcudnSVLkcL8DWcb4o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=N+naXa3PajvWfMjXkiqv5RTy6d6zMJ9j1RdGqCtNO6HUddTA/yJizuIrUg8vpKZHiJ8+LtW/V39In+TVlhhQDm6qsJ96SrhT+1K6zZR5uF74fUE6GDuBi0hu1g/yRrZWpWW29TEzWYyzE9jiYamk1VVunJIKdMUHR6SumLSuZ3I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=Rft2EjVv; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Rft2EjVv" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1741686165; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=diTiRQ4QEE+DrXrQrQ/ial0maPf28mPhXHy+LSWc3KI=; b=Rft2EjVv1f+fytBPC6VP+Xc3/gXraHKRimxCQUgxK6wrwUbBNtF52cM1HuhVE6/d7uW9Zc jsYBlj36Lp4Wzve6Gtc5V4czvEEpca2jL4Gnh9pwJyKuqZnCdnrJGdEJLihY8uCb5NzaCL TOoWJbXCwV6sg869iNHikZqo74qLUUU= Received: from mail-ej1-f71.google.com (mail-ej1-f71.google.com [209.85.218.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-136-9UJ58wDbPUmTKmxdHReZvA-1; Tue, 11 Mar 2025 05:42:43 -0400 X-MC-Unique: 9UJ58wDbPUmTKmxdHReZvA-1 X-Mimecast-MFC-AGG-ID: 9UJ58wDbPUmTKmxdHReZvA_1741686163 Received: by mail-ej1-f71.google.com with SMTP id a640c23a62f3a-abf597afe1fso517863566b.1 for ; Tue, 11 Mar 2025 02:42:43 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741686162; x=1742290962; 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=diTiRQ4QEE+DrXrQrQ/ial0maPf28mPhXHy+LSWc3KI=; b=FgULvd3O5bKkRNfOOuEhvy9sSOvQPcuxDLI8Ob5acLFRDLLikHbt/PkCbgh+XLT3dH b+QnVLlhGFIsiHc5hUZO+S1mpgK9Aaqr0OiK2L1C+C0FNvV8Uwsua1OrARUcpvP8MPTz 76NHt5+FtPjZncf9t2+XwNT7WD5gC2mMHdlfIh9XEEOHN/orwOPk2D2HClry+NgE74Ec QsEujUFaVNLFrEvGi6DJJtCe0mOu1LqWgkvdChhQcoT5yKFWAsmpQgOARVE9eGqeAEKh s9FTGtsksf9UhPX5DMgyQGu1TBwQgFdHRE+fNer90DqcXAs4+7xMHIKfvVYgdXIdOXfi /Mdw== X-Forwarded-Encrypted: i=1; AJvYcCVgnlA1b4tGS0ZXlbhUlbpJlNLSypqO0+skNDbn9YPZpd9TXnTt6JvixMACLlNhN06GHMGi+r1mgfhH8/bn788=@vger.kernel.org X-Gm-Message-State: AOJu0Yw8777JWMR6OXctTm0GkaBUdlvTUY5BDinfWk0XqEQojHr5Bfpq p6qWDrjfvspSYRCRtMa5fthW2MTbEKEnOTLZ++NHR68ImXe6XJAe1h3/M+D5QXdgLDTPLOoAXRy zCQD7j9kol08W6X2PWnY07K8mbRLqElrJVqnYqeTa2ua3vmgXAqwytX/XRcsDvoK/ww== X-Gm-Gg: ASbGncvlvH6IWPJEr2pfohS2PhT8nbS6XI2AgVeNQkA6lcDYt9Z96JEImgPrOb+Iotm R8qA74wnP0aEceZRcivp7Xmp6zZLIrpn0+bNNtuYgYi71SrFD/f3aXkhGwF73ex2GknjMrGTO5w enrkzW/EcZyl+30RF2nIbXI1OI+ELqQTnQlX7CGEyKhvBxMEYRF7Mjl6IC5VwG8Zq0MSt0og8lZ z838RuT6hI89QpXHqTPHqlundtfv9JFQj4QEA3QTOoBaPx8sqJIatYEkPjK5Acsi767Y6fDDz3A MaZgET4VbrxSIzlJf1Hp93nTL9KMRIB1brcsSJzXZHZ729QnhZ62DOLyWIOrPDeCShvGcb/y X-Received: by 2002:a17:907:7d9f:b0:ac2:97b2:1d3f with SMTP id a640c23a62f3a-ac297b22079mr1114323766b.33.1741686162495; Tue, 11 Mar 2025 02:42:42 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHUcxLn6TcACG5q0J+lrMTI7KwpBjie28By2PFquAKqewgotRjAJtSnPnu+qLJ4qo42XwLXVg== X-Received: by 2002:a17:907:7d9f:b0:ac2:97b2:1d3f with SMTP id a640c23a62f3a-ac297b22079mr1114316766b.33.1741686161827; Tue, 11 Mar 2025 02:42:41 -0700 (PDT) Received: from localhost.localdomain (host-79-46-200-29.retail.telecomitalia.it. [79.46.200.29]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ac2a27d2613sm298483166b.12.2025.03.11.02.42.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Mar 2025 02:42:41 -0700 (PDT) From: Stefano Garzarella To: Jarkko Sakkinen Cc: Peter Huewe , Tom Lendacky , Jason Gunthorpe , x86@kernel.org, linux-kernel@vger.kernel.org, Borislav Petkov , linux-integrity@vger.kernel.org, Dov Murik , Dionna Glaze , linux-coco@lists.linux.dev, James Bottomley , Claudio Carvalho , Ingo Molnar , "H. Peter Anvin" , Thomas Gleixner , Dave Hansen , Joerg Roedel , Stefano Garzarella Subject: [PATCH v3 2/4] svsm: add header with SVSM_VTPM_CMD helpers Date: Tue, 11 Mar 2025 10:42:23 +0100 Message-ID: <20250311094225.35129-3-sgarzare@redhat.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250311094225.35129-1-sgarzare@redhat.com> References: <20250311094225.35129-1-sgarzare@redhat.com> Precedence: bulk X-Mailing-List: linux-integrity@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Helpers for the SVSM_VTPM_CMD calls used by the vTPM protocol defined by the AMD SVSM spec [1]. The vTPM protocol follows the Official TPM 2.0 Reference Implementation (originally by Microsoft, now part of the TCG) simulator protocol. [1] "Secure VM Service Module for SEV-SNP Guests" Publication # 58019 Revision: 1.00 Co-developed-by: James Bottomley Signed-off-by: James Bottomley Co-developed-by: Claudio Carvalho Signed-off-by: Claudio Carvalho Signed-off-by: Stefano Garzarella --- v3: - renamed header and prefix to make clear it's related to the SVSM vTPM protocol - renamed fill/parse functions [Tom] - removed link to the spec because those URLs are unstable [Borislav] --- include/linux/svsm_vtpm.h | 141 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 141 insertions(+) create mode 100644 include/linux/svsm_vtpm.h diff --git a/include/linux/svsm_vtpm.h b/include/linux/svsm_vtpm.h new file mode 100644 index 000000000000..2ce9b1cb827e --- /dev/null +++ b/include/linux/svsm_vtpm.h @@ -0,0 +1,141 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Copyright (C) 2023 James.Bottomley@HansenPartnership.com + * Copyright (C) 2025 Red Hat, Inc. All Rights Reserved. + * + * Helpers for the SVSM_VTPM_CMD calls used by the vTPM protocol defined by the + * AMD SVSM spec [1]. + * + * The vTPM protocol follows the Official TPM 2.0 Reference Implementation + * (originally by Microsoft, now part of the TCG) simulator protocol. + * + * [1] "Secure VM Service Module for SEV-SNP Guests" + * Publication # 58019 Revision: 1.00 + */ +#ifndef _SVSM_VTPM_H_ +#define _SVSM_VTPM_H_ + +#include +#include +#include + +/* + * The current TCG Simulator TPM commands we support. The complete list is + * in the TcpTpmProtocol header: + * + * https://github.com/TrustedComputingGroup/TPM/blob/main/TPMCmd/Simulator/include/TpmTcpProtocol.h + */ + +#define TPM_SEND_COMMAND 8 +#define TPM_SIGNAL_CANCEL_ON 9 +#define TPM_SIGNAL_CANCEL_OFF 10 +/* + * Any platform specific commands should be placed here and should start + * at 0x8000 to avoid clashes with the TCG Simulator protocol. They should + * follow the same self describing buffer format below. + */ + +#define SVSM_VTPM_MAX_BUFFER 4096 /* max req/resp buffer size */ + +/** + * struct tpm_req - generic request header for single word command + * + * @cmd: The command to send + */ +struct tpm_req { + u32 cmd; +} __packed; + +/** + * struct tpm_resp - generic response header + * + * @size: The response size (zero if nothing follows) + * + * Note: most TCG Simulator commands simply return zero here with no indication + * of success or failure. + */ +struct tpm_resp { + u32 size; +} __packed; + +/** + * struct tpm_send_cmd_req - Structure for a TPM_SEND_COMMAND request + * + * @hdr: The request header whit the command (must be TPM_SEND_COMMAND) + * @locality: The locality + * @inbuf_size: The size of the input buffer following + * @inbuf: A buffer of size inbuf_size + * + * Note that TCG Simulator expects @inbuf_size to be equal to the size of the + * specific TPM command, otherwise an TPM_RC_COMMAND_SIZE error is + * returned. + */ +struct tpm_send_cmd_req { + struct tpm_req hdr; + u8 locality; + u32 inbuf_size; + u8 inbuf[]; +} __packed; + +/** + * struct tpm_send_cmd_req - Structure for a TPM_SEND_COMMAND response + * + * @hdr: The response header whit the following size + * @outbuf: A buffer of size hdr.size + */ +struct tpm_send_cmd_resp { + struct tpm_resp hdr; + u8 outbuf[]; +} __packed; + +/** + * svsm_vtpm_fill_cmd_req() - fill a struct tpm_send_cmd_req to be sent to SVSM + * @req: The struct tpm_send_cmd_req to fill + * @locality: The locality + * @buf: The buffer from where to copy the payload of the command + * @len: The size of the buffer + * + * Return: 0 on success, negative error code on failure. + */ +static inline int +svsm_vtpm_fill_cmd_req(struct tpm_send_cmd_req *req, u8 locality, + const u8 *buf, size_t len) +{ + if (len > SVSM_VTPM_MAX_BUFFER - sizeof(*req)) + return -EINVAL; + + req->hdr.cmd = TPM_SEND_COMMAND; + req->locality = locality; + req->inbuf_size = len; + + memcpy(req->inbuf, buf, len); + + return 0; +} + +/** + * svsm_vtpm_parse_cmd_resp() - Parse a struct tpm_send_cmd_resp received from + * SVSM + * @resp: The struct tpm_send_cmd_resp to parse + * @buf: The buffer where to copy the response + * @len: The size of the buffer + * + * Return: buffer size filled with the response on success, negative error + * code on failure. + */ +static inline int +svsm_vtpm_parse_cmd_resp(const struct tpm_send_cmd_resp *resp, u8 *buf, + size_t len) +{ + if (len < resp->hdr.size) + return -E2BIG; + + if (resp->hdr.size > SVSM_VTPM_MAX_BUFFER - sizeof(*resp)) + return -EINVAL; // Invalid response from the platform TPM + + memcpy(buf, resp->outbuf, resp->hdr.size); + + return resp->hdr.size; +} + +#endif /* _SVSM_VTPM_H_ */ From patchwork Tue Mar 11 09:42:24 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Garzarella X-Patchwork-Id: 14011413 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (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 84458232395 for ; Tue, 11 Mar 2025 09:42:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741686172; cv=none; b=Qyu218AQFW3phLM/BGRgbO09UrD4Y3gBhQVk8He1Pk5Yoa1P6MDB8ggoEZZvA3VZXm0h2apXUkxOWyz6zdFDVAy2Sfc9keE3HCCRn1DcYT8/YO2AiYzT2ZqolKJkw5xLjcdBNaQLhqB8zDHkQWOWbmaKfBq04XAuinCEMagp0x0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741686172; c=relaxed/simple; bh=Q+8vPxxDbfpg9fRYXDZlhPTHw0u84I0SSyU4Nc1rsy4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qFpnt4PkDuKktaoLVjap+NJ1oiV7owamRtEiTOGkUWG9emSx4x2tc7qDC7stx2gjS2uiR5xJ5jk328REX+mvEWDx55WpL96ziDA/CREORn/anaVSXsuIfMZAdlss+sg0v+/StazYnFTQXq+mAZoi5/dAgw1EyjzMwb03vbfBlvo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=Fa3+p/bB; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Fa3+p/bB" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1741686169; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2wb6+hQNYEWIXedIcFLeKnafG1DD76+LTwe3b4OwUzY=; b=Fa3+p/bBqiWbStzZ/OO1jL/aNdU+e4d6okFQZhuPLsPSxLa+emslQRaHo+onVUBuTrY0mf d7Gib7JnT8qWZbcTPCw1JCkUnJzw8PUjR2BgGVPC5KezUyVnqtLLSHQDPnTzf13IzVV7UA vZeyKX6p1vKF4vfCj59W/kUyuQ/BVqE= Received: from mail-ej1-f72.google.com (mail-ej1-f72.google.com [209.85.218.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-687-xRYg9i6UMECn-ls7j7vIhw-1; Tue, 11 Mar 2025 05:42:48 -0400 X-MC-Unique: xRYg9i6UMECn-ls7j7vIhw-1 X-Mimecast-MFC-AGG-ID: xRYg9i6UMECn-ls7j7vIhw_1741686167 Received: by mail-ej1-f72.google.com with SMTP id a640c23a62f3a-ac21697a8ebso433884566b.1 for ; Tue, 11 Mar 2025 02:42:48 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741686167; x=1742290967; 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=2wb6+hQNYEWIXedIcFLeKnafG1DD76+LTwe3b4OwUzY=; b=gkPyvcTESihiXG2886lu1Sl6h/s586gl6gclYwPv195g0hLfXelvOx0QXoAH0OAn0V poAOu/62fAUZj6Nzr8XNBQE+xciIurQ89g6nUf9QEaVYCHTlnU15ECxqftxTzKIyRTQk jbuQKXQjulQjuSgd11cRSQTT7ivPBB3g9oNlswJCZSkHF4KffcV+W+FhjqR4ti1pgrV5 ZXVLzMM4VElUh0nF1icAlM39pshkuSfuuhhpYXqjOjk7kqKAKbcb4dw5ltdidlCAKk9J 8ImIE6IIK63rEo9CaBfYfw5KqZ9mL0kld9q+tIaLeftqrQ51TIBWLdBfxoL2wJxFZ9ty ZdeQ== X-Forwarded-Encrypted: i=1; AJvYcCVIM4dgAKguMp7hZw7pnsehil6cuMMofcAkcVbBEtkgqNnKOu+rJab7BvtPxxlom2ErSaQ3VTPkGc+DJusYDeo=@vger.kernel.org X-Gm-Message-State: AOJu0YydHR+t59fQM/svuzqr7210Xbzq4/1LH8b0JED+aPGscn94r6NB ICEOUBbk/9nPhunJPjsaA+Ho2sa7pkev/GIDXu1i4hO8uclUFe9tzx2ahuwU60gER9/+r2bZBjf cha8ON31bZjJKh0+GN4wCnS40qZkUjSw/nteqwH1RC9NVNuHB5dNomNsS0WxLhb7KTA== X-Gm-Gg: ASbGncvWDlBUtREWlvdYFuPAn0OoN+m8PDpBV3lUX4fsoI7JF0+RBkQxyBAGIj44nzG XcF+Xs3rvuCe6/Y2ll/6B9BzHiCgTRa0TyfUTLiiCyx5l1xW/L92xzYI3bAf64yuufYkdAIvJ7c Wby8aj4LPmiLTgnnywlsa6TcC2wTyvNgHyJJzMnaDdvEoZO9eVPduI1UYakUhaQv84EEjDIoQRq JUfE6O+Ea5H9bGng3OUX7Ky7VSZxiJCtMeW6KKjtr/nNsDJ/bJ/t1ka9BTc1AeTramGoN7+KEWD YPxhayVjY19rnH5UEsv7ithz1u/PwCwAfwQr0v/wjmogQy4fa/VqYj2jGmon6IJt9CC2eNmE X-Received: by 2002:a17:907:268a:b0:ac2:1c64:b26 with SMTP id a640c23a62f3a-ac252b2354amr2037757166b.32.1741686166781; Tue, 11 Mar 2025 02:42:46 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFWmq7wXuMFVs0mGI08LvEZtWDeEa9Z/7uGOGcAtsq0hFXFdDMeo+Cdbl0Zx81eoMP5bl5BOw== X-Received: by 2002:a17:907:268a:b0:ac2:1c64:b26 with SMTP id a640c23a62f3a-ac252b2354amr2037753166b.32.1741686166106; Tue, 11 Mar 2025 02:42:46 -0700 (PDT) Received: from localhost.localdomain (host-79-46-200-29.retail.telecomitalia.it. [79.46.200.29]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ac25fae7d83sm701558766b.99.2025.03.11.02.42.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Mar 2025 02:42:45 -0700 (PDT) From: Stefano Garzarella To: Jarkko Sakkinen Cc: Peter Huewe , Tom Lendacky , Jason Gunthorpe , x86@kernel.org, linux-kernel@vger.kernel.org, Borislav Petkov , linux-integrity@vger.kernel.org, Dov Murik , Dionna Glaze , linux-coco@lists.linux.dev, James Bottomley , Claudio Carvalho , Ingo Molnar , "H. Peter Anvin" , Thomas Gleixner , Dave Hansen , Joerg Roedel , Stefano Garzarella Subject: [PATCH v3 3/4] tpm: add SNP SVSM vTPM driver Date: Tue, 11 Mar 2025 10:42:24 +0100 Message-ID: <20250311094225.35129-4-sgarzare@redhat.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250311094225.35129-1-sgarzare@redhat.com> References: <20250311094225.35129-1-sgarzare@redhat.com> Precedence: bulk X-Mailing-List: linux-integrity@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add driver for the vTPM defined by the AMD SVSM spec [1]. The specification defines a protocol that a SEV-SNP guest OS can use to discover and talk to a vTPM emulated by the Secure VM Service Module (SVSM) in the guest context, but at a more privileged level (VMPL0). The new tpm-svsm platform driver uses two functions exposed by x86/sev to verify that the device is actually emulated by the platform and to send commands and receive responses. The device cannot be hot-plugged/unplugged as it is emulated by the platform, so we can use module_platform_driver_probe(). The probe function will only check whether in the current runtime configuration, SVSM is present and provides a vTPM. This device does not support interrupts and sends responses to commands synchronously. In order to have .recv() called just after .send() in tpm_try_transmit(), the .status() callback returns 0, and both .req_complete_mask and .req_complete_val are set to 0. [1] "Secure VM Service Module for SEV-SNP Guests" Publication # 58019 Revision: 1.00 Signed-off-by: Stefano Garzarella --- v3: - removed send_recv() ops and followed the ftpm driver implementing .status, .req_complete_mask, .req_complete_val, etc. [Jarkko] - removed link to the spec because those URLs are unstable [Borislav] --- drivers/char/tpm/tpm_svsm.c | 148 ++++++++++++++++++++++++++++++++++++ drivers/char/tpm/Kconfig | 10 +++ drivers/char/tpm/Makefile | 1 + 3 files changed, 159 insertions(+) create mode 100644 drivers/char/tpm/tpm_svsm.c diff --git a/drivers/char/tpm/tpm_svsm.c b/drivers/char/tpm/tpm_svsm.c new file mode 100644 index 000000000000..5540d0227eed --- /dev/null +++ b/drivers/char/tpm/tpm_svsm.c @@ -0,0 +1,148 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright (C) 2025 Red Hat, Inc. All Rights Reserved. + * + * Driver for the vTPM defined by the AMD SVSM spec [1]. + * + * The specification defines a protocol that a SEV-SNP guest OS can use to + * discover and talk to a vTPM emulated by the Secure VM Service Module (SVSM) + * in the guest context, but at a more privileged level (usually VMPL0). + * + * [1] "Secure VM Service Module for SEV-SNP Guests" + * Publication # 58019 Revision: 1.00 + */ + +#include +#include +#include +#include +#include + +#include "tpm.h" + +struct tpm_svsm_priv { + u8 buffer[SVSM_VTPM_MAX_BUFFER]; + u8 locality; +}; + +static int tpm_svsm_send(struct tpm_chip *chip, u8 *buf, size_t len) +{ + struct tpm_svsm_priv *priv = dev_get_drvdata(&chip->dev); + int ret; + + ret = svsm_vtpm_fill_cmd_req((struct tpm_send_cmd_req *)priv->buffer, + priv->locality, buf, len); + if (ret) + return ret; + + /* + * The SVSM call uses the same buffer for the command and for the + * response, so after this call, the buffer will contain the response + * that can be used by .recv() op. + */ + return snp_svsm_vtpm_send_command(priv->buffer); +} + +static int tpm_svsm_recv(struct tpm_chip *chip, u8 *buf, size_t len) +{ + struct tpm_svsm_priv *priv = dev_get_drvdata(&chip->dev); + + /* + * The internal buffer contains the response after we send the command + * to SVSM. + */ + return svsm_vtpm_parse_cmd_resp((struct tpm_send_cmd_resp *)priv->buffer, + buf, len); +} + +static void tpm_svsm_cancel(struct tpm_chip *chip) +{ + /* not supported */ +} + +static u8 tpm_svsm_status(struct tpm_chip *chip) +{ + return 0; +} + +static bool tpm_svsm_req_canceled(struct tpm_chip *chip, u8 status) +{ + return false; +} + +static struct tpm_class_ops tpm_chip_ops = { + .flags = TPM_OPS_AUTO_STARTUP, + .recv = tpm_svsm_recv, + .send = tpm_svsm_send, + .cancel = tpm_svsm_cancel, + .status = tpm_svsm_status, + .req_complete_mask = 0, + .req_complete_val = 0, + .req_canceled = tpm_svsm_req_canceled, +}; + +static int __init tpm_svsm_probe(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct tpm_svsm_priv *priv; + struct tpm_chip *chip; + int err; + + if (!snp_svsm_vtpm_probe()) + return -ENODEV; + + priv = devm_kmalloc(dev, sizeof(*priv), GFP_KERNEL); + if (!priv) + return -ENOMEM; + + /* + * FIXME: before implementing locality we need to agree what it means + * for the SNP SVSM vTPM + */ + priv->locality = 0; + + chip = tpmm_chip_alloc(dev, &tpm_chip_ops); + if (IS_ERR(chip)) + return PTR_ERR(chip); + + dev_set_drvdata(&chip->dev, priv); + + err = tpm2_probe(chip); + if (err) + return err; + + err = tpm_chip_register(chip); + if (err) + return err; + + dev_info(dev, "SNP SVSM vTPM %s device\n", + (chip->flags & TPM_CHIP_FLAG_TPM2) ? "2.0" : "1.2"); + + return 0; +} + +static void __exit tpm_svsm_remove(struct platform_device *pdev) +{ + struct tpm_chip *chip = platform_get_drvdata(pdev); + + tpm_chip_unregister(chip); +} + +/* + * tpm_svsm_remove() lives in .exit.text. For drivers registered via + * module_platform_driver_probe() this is ok because they cannot get unbound + * at runtime. So mark the driver struct with __refdata to prevent modpost + * triggering a section mismatch warning. + */ +static struct platform_driver tpm_svsm_driver __refdata = { + .remove = __exit_p(tpm_svsm_remove), + .driver = { + .name = "tpm-svsm", + }, +}; + +module_platform_driver_probe(tpm_svsm_driver, tpm_svsm_probe); + +MODULE_DESCRIPTION("SNP SVSM vTPM Driver"); +MODULE_LICENSE("GPL"); +MODULE_ALIAS("platform:tpm-svsm"); diff --git a/drivers/char/tpm/Kconfig b/drivers/char/tpm/Kconfig index 0fc9a510e059..fc3f1d10d31d 100644 --- a/drivers/char/tpm/Kconfig +++ b/drivers/char/tpm/Kconfig @@ -225,5 +225,15 @@ config TCG_FTPM_TEE help This driver proxies for firmware TPM running in TEE. +config TCG_SVSM + tristate "SNP SVSM vTPM interface" + depends on AMD_MEM_ENCRYPT + help + This is a driver for the AMD SVSM vTPM protocol that a SEV-SNP guest + OS can use to discover and talk to a vTPM emulated by the Secure VM + Service Module (SVSM) in the guest context, but at a more privileged + level (usually VMPL0). To compile this driver as a module, choose M + here; the module will be called tpm_svsm. + source "drivers/char/tpm/st33zp24/Kconfig" endif # TCG_TPM diff --git a/drivers/char/tpm/Makefile b/drivers/char/tpm/Makefile index 9bb142c75243..52d9d80a0f56 100644 --- a/drivers/char/tpm/Makefile +++ b/drivers/char/tpm/Makefile @@ -44,3 +44,4 @@ obj-$(CONFIG_TCG_XEN) += xen-tpmfront.o obj-$(CONFIG_TCG_CRB) += tpm_crb.o obj-$(CONFIG_TCG_VTPM_PROXY) += tpm_vtpm_proxy.o obj-$(CONFIG_TCG_FTPM_TEE) += tpm_ftpm_tee.o +obj-$(CONFIG_TCG_SVSM) += tpm_svsm.o From patchwork Tue Mar 11 09:42:25 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Garzarella X-Patchwork-Id: 14011414 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (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 EB347233D99 for ; Tue, 11 Mar 2025 09:42:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741686176; cv=none; b=kXrbA92rP/4/3Iyc1Wf9y0IHcCPrFYcceK4iBBgb+VFjZf7CD3XJxhi0hNFgu3mNk/HElXVVwstXoEivELkQ4FVt2J0YywiRB7QK3xgkt6ZMOayj8NyigoOmFV+LW9CefO+rpkDE77wjihBh9slTLOT058ayduFxQ93qfOcW62o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741686176; c=relaxed/simple; bh=7ofinKFlIYAPL0uFGFVvSScK4HwNUlqf6CGOFX+txk4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lJfHY8cYBwbMjFM5Ck6OKnMnyyv9RJYhnPH2Z8ScvncEVvKW4JvWTovVm0qpDlJ2MlapgmAGcOtGW5seuSRl61Aop8jNalNgeR3278BcIbRc+8AjoXv0HM81BG1fbWZ9+8YUtOUYgVXBUDRMp3HkYMqDtbVQlcilTmImqc7g8g8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=eTLKMVqi; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="eTLKMVqi" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1741686174; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4Hg6I6nIDb7vIFIV7ygI8oxn0FMZLdQaKjCFJAirlRo=; b=eTLKMVqiEJ/uM3bfCPoNZuwLUwwX/9QlV2/PEbZNI61cVSlybAVmNOAZ6UqWdzwvpiN+An 2nuAu+8ezG8X5Z59uccVnhA8B4xdS2EHyI4xwBdROVCB3IrkzJ2P+OL3coFH1RuOHugJkT 9bZFQSmeAKVIQfipGf6MJrk3W1JtY50= Received: from mail-ej1-f70.google.com (mail-ej1-f70.google.com [209.85.218.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-44-sb3OvskeMfeVQpCax2Zmwg-1; Tue, 11 Mar 2025 05:42:52 -0400 X-MC-Unique: sb3OvskeMfeVQpCax2Zmwg-1 X-Mimecast-MFC-AGG-ID: sb3OvskeMfeVQpCax2Zmwg_1741686171 Received: by mail-ej1-f70.google.com with SMTP id a640c23a62f3a-abf4c4294b0so562780066b.0 for ; Tue, 11 Mar 2025 02:42:52 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741686171; x=1742290971; 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=4Hg6I6nIDb7vIFIV7ygI8oxn0FMZLdQaKjCFJAirlRo=; b=OHUILyCVhzGIqHB/a7JzFdrf9bJNTHbiGO6XQHNfKC6S+0i/nfP2D/Av6QzEfIuDJQ VMKcszq+S9XPaSxiUgd1i2tfjWQpSotfZtUXQtf8oqsCepiRiffWGs9r334tCTaZcI+c 7HI0aAgWmdn4sgx5S71eyz2WboHcYBCrIs/8LyM0uC3H+EMLrUirZh7yiN+ws4Y1H/+P 3cmjWalBt8NWGzAIxGqawV/PiCVAN7v6IlYJao+GWEPExEGwNINgn6aZQNGxuZ+zHf16 3dWzgswNtQ14hF929Ge7syh4HOds0XzAQ8HnNiVvAsYgsZ+foGi+1DXkuLHxWutwkuhb j7Dg== X-Forwarded-Encrypted: i=1; AJvYcCXuO7RIo80Yaqrj5kUzsNr6pd1n6W/b/cLszWiimoqkgiWi1svfiYBZbJDNbIVOMqxxZH+X7CzseLop6ydcw8I=@vger.kernel.org X-Gm-Message-State: AOJu0YyRQ3jBExgBYhxvKF4NmkGlENOrYQ8na7c/MaxPXZ8PKU9dWZJI C+IkzyaX7VPuSmAKN/rmDEJS+U8Gff2HQkqbND3cIWPHVeCd4Wp8QrVY368l2ZQFRmg+icdzTas trJCR5c5k7SAwfUjKK1PSdt00qJI0UXHlVplPUwqe/EW5C8LQy7VKYKEiiRl0rNpwpA== X-Gm-Gg: ASbGncsYvMaR97lr+2TypKOwZEBMO95ZQcN6JusRdgJf6PxN9tBzG97ee7bTPBIvZ2X vFkCJlOSn58qO9P78Jmumz062IG9InN24131K8/UOdHMAu0aZe6PY0IxrqgMbgO66FexxJR4QYM 59d43PCxLuXCOvdym2Ib7kSWW0eZaimbHPq9WtP1kd6h1jGIUaKw76IG8/LUgUTHtj4CpQavlYf Pa9zpzmzP2rABk0e8PiQixhFt9OfTjz24BLHrIPGquGh41NPg0N0wI2uZ0jnu46Teta7W2qjRzc eBRsnrqDS2e+bBuhGU2M99Tsjl0kvEl6OPr0UV4nA5c16P6mGS8uQT6uQoDEicDDkJx2tl4d X-Received: by 2002:a17:907:a310:b0:ac2:6fc6:b93d with SMTP id a640c23a62f3a-ac2ba473173mr370177866b.1.1741686171317; Tue, 11 Mar 2025 02:42:51 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGkmP0r13TRekW78HkAFefp5cjLkHl6Mq2Ghd/8jrWtGCOF1SbwGI8W62TAbwjYfxllk7Faww== X-Received: by 2002:a17:907:a310:b0:ac2:6fc6:b93d with SMTP id a640c23a62f3a-ac2ba473173mr370172766b.1.1741686170721; Tue, 11 Mar 2025 02:42:50 -0700 (PDT) Received: from localhost.localdomain (host-79-46-200-29.retail.telecomitalia.it. [79.46.200.29]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ac239485bf3sm903753666b.63.2025.03.11.02.42.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Mar 2025 02:42:49 -0700 (PDT) From: Stefano Garzarella To: Jarkko Sakkinen Cc: Peter Huewe , Tom Lendacky , Jason Gunthorpe , x86@kernel.org, linux-kernel@vger.kernel.org, Borislav Petkov , linux-integrity@vger.kernel.org, Dov Murik , Dionna Glaze , linux-coco@lists.linux.dev, James Bottomley , Claudio Carvalho , Ingo Molnar , "H. Peter Anvin" , Thomas Gleixner , Dave Hansen , Joerg Roedel , Stefano Garzarella Subject: [PATCH v3 4/4] x86/sev: register tpm-svsm platform device Date: Tue, 11 Mar 2025 10:42:25 +0100 Message-ID: <20250311094225.35129-5-sgarzare@redhat.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250311094225.35129-1-sgarzare@redhat.com> References: <20250311094225.35129-1-sgarzare@redhat.com> Precedence: bulk X-Mailing-List: linux-integrity@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 SNP platform can provide a vTPM device emulated by SVSM. The "tpm-svsm" device can be handled by the platform driver added by the previous commit in drivers/char/tpm/tpm_svsm.c The driver will call snp_svsm_vtpm_probe() to check if SVSM is present and if it's support the vTPM protocol. Signed-off-by: Stefano Garzarella --- arch/x86/coco/sev/core.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/arch/x86/coco/sev/core.c b/arch/x86/coco/sev/core.c index 2166bdff88b7..a2383457889e 100644 --- a/arch/x86/coco/sev/core.c +++ b/arch/x86/coco/sev/core.c @@ -2664,6 +2664,11 @@ static struct platform_device sev_guest_device = { .id = -1, }; +static struct platform_device tpm_svsm_device = { + .name = "tpm-svsm", + .id = -1, +}; + static int __init snp_init_platform_device(void) { if (!cc_platform_has(CC_ATTR_GUEST_SEV_SNP)) @@ -2672,6 +2677,9 @@ static int __init snp_init_platform_device(void) if (platform_device_register(&sev_guest_device)) return -ENODEV; + if (platform_device_register(&tpm_svsm_device)) + return -ENODEV; + pr_info("SNP guest platform device initialized.\n"); return 0; }