From patchwork Thu Apr 10 13:51:13 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Stefano Garzarella X-Patchwork-Id: 14046555 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 7E5E328C5AA for ; Thu, 10 Apr 2025 13:51:30 +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=1744293092; cv=none; b=BuwcR66GAZQSar6c3RrZzsUi1NC9P8UYlR5vnuKD7xmT7JZ90yy8xVDz1qAzJTaGem8dL76XTzExd+dWE4wzcx9W+wO7bK/aDbtkmjeMApcnPjFnwdfjXtNDT+6+1QcQvA+xVuW/gb4o4zHHHBhK+iL0tFMEBG3DzK9hMZKPH5I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744293092; c=relaxed/simple; bh=RqYMqp3Ujj1yablcXK4m8qctcMpdGLtxgb9YCEHWtfE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=juCNwbAlf1E4NRLKZ25PnCnyaD1AoNziWArGfftciMFJVLqUHMTne+U8os1kLxIVkgSneqnes6hbrIjGfu2sJ9Hi9sfuiPKbkJDs6s+ZFHTJWtI+G+sI2j444Eq2EeNZODct48ELpB6UOLnWoLM3r5IZuGGL48JNRup41eJI7/8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine 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=ZDfrvNTe; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine 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="ZDfrvNTe" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1744293089; h=from:from: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: in-reply-to:in-reply-to:references:references; bh=2hayB2itOF52swyYqnft2InIWkfIXl2u+4tuyLp7J20=; b=ZDfrvNTehm32kZ2cAkP0+A9VzODYpxIXD/ZsQAUX+AxdqkZVeo5pQtjrg+3aReLM8bJlJ4 aMDQvetEzAWm+AMjBPOd9cgtzm1DDy1PIqkQFIQWPYJghUqnzRkkzvdiq4kyYJm4DMs2HM DM6MIfVjuWmC2MI4xJUcKCrjhXhJ6oQ= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-622-fBbIgTbVN6-dBKA8W5TdnA-1; Thu, 10 Apr 2025 09:51:28 -0400 X-MC-Unique: fBbIgTbVN6-dBKA8W5TdnA-1 X-Mimecast-MFC-AGG-ID: fBbIgTbVN6-dBKA8W5TdnA_1744293087 Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-399744f742bso263509f8f.1 for ; Thu, 10 Apr 2025 06:51:28 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744293087; x=1744897887; 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=2hayB2itOF52swyYqnft2InIWkfIXl2u+4tuyLp7J20=; b=qw8DUbwkXficXOhnJp8a3VDF6NYAPpdeyDqDNhLGo2namwi+KL3Nh1otmNHsZpjDSD a1fuSw8svdmucpfBypK1f4w70yQxKKRCQIvu2XRhNlh5L5D3U8XlPI/wCB15IpNR0E5e sSyCA0n218LGW8XmshxLXcOL4C4afROiPpU1YUkd+WF0uRhPydHh1yxclWWq7S8eJJlq p9P9zeEkjDuSyREmf/C23vYwsH6LxXTyehmVrjLGP6cDfqjJCZfKzH5v63VJDmdAhCE4 L+a752vZHaIger/QvEs7+rZdy6KFZbTqeKP5ffdVbaxcXdGrUjm8rXkAsCxnYnDnvpDH MhSA== X-Forwarded-Encrypted: i=1; AJvYcCWK6rgysLDvoUdmxSJsExy6eMnSMaLElCwfPsh2Gwhpx9smw+TCkCP4t0NBLU3d8gSYi3tLRe9Yl88ym3Pz8dY=@vger.kernel.org X-Gm-Message-State: AOJu0YxPUGlCVF1grD3u3RTWHbiRhkrz1eR4X7DQgmf3Xz//38TgP34v k4f8fueVyQoLtqw0XREAUznf68s/4jbob+VAA+U9NzM5eHHC+DDbAhT42IVOZx5jJL9KD06gWCi jCX29wBfRtyKPdYpPp3ex8f5UvuPTPtnlQYstcLv/rCSH7+gXInYbjIVHb6WyIzxpJA== X-Gm-Gg: ASbGncuZva9FjPQ6kmtHnca/vX5A5uKlC1PVLyUmS4AUmF+4AC9kdLt4Gx81P3Y+Kp7 dFBL8nfdfFtahhGYubZ29vLjwO4RIQ/8R+Ousj9sb1Ne1UKmMxZ7Xp6KZ0ftSLWdhPtSYLM0nu2 stkdGKYz351/es3vPoMNyDLqRphefXVatwV4L6qKUDrUy1voxhpcgk9laQapkjdWCpnDs+v6Mck c4NPE1fLift7LVfi2C78sHWREpuEL/y2/RWYTxNurrdFaIMmkucM7m6PtfmrHSP+Qxzm7do0UVL yoaVmiZsKZdvDSZKn9lod9suGRLsjGs3iZxSfFVmBlU+PMmjnamZC4Ys0sSVFQ== X-Received: by 2002:a05:6000:2cd:b0:39a:ca04:3e4d with SMTP id ffacd0b85a97d-39d8f273573mr2757998f8f.7.1744293087098; Thu, 10 Apr 2025 06:51:27 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH74r2mCwQMz4b5b40UpkJVX/gWuuE0hyyRu8AvG8fHXAQ9RwrpeFNISL0qnwEahYkR49vqdg== X-Received: by 2002:a05:6000:2cd:b0:39a:ca04:3e4d with SMTP id ffacd0b85a97d-39d8f273573mr2757948f8f.7.1744293086504; Thu, 10 Apr 2025 06:51:26 -0700 (PDT) Received: from stex1.redhat.com (host-79-53-30-213.retail.telecomitalia.it. [79.53.30.213]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-39d8938a761sm4932104f8f.51.2025.04.10.06.51.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Apr 2025 06:51:25 -0700 (PDT) From: Stefano Garzarella To: Borislav Petkov , Jarkko Sakkinen Cc: Joerg Roedel , "H. Peter Anvin" , Dionna Glaze , Ingo Molnar , linux-kernel@vger.kernel.org, Dov Murik , linux-integrity@vger.kernel.org, Dave Hansen , Claudio Carvalho , Tom Lendacky , Thomas Gleixner , Peter Huewe , Jason Gunthorpe , x86@kernel.org, James Bottomley , linux-coco@lists.linux.dev, Stefano Garzarella Subject: [PATCH v7 1/4] x86/sev: add SVSM vTPM probe/send_command functions Date: Thu, 10 Apr 2025 15:51:13 +0200 Message-ID: <20250410135118.133240-2-sgarzare@redhat.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250410135118.133240-1-sgarzare@redhat.com> References: <20250410135118.133240-1-sgarzare@redhat.com> Precedence: bulk X-Mailing-List: linux-integrity@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Stefano Garzarella 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 snp_svsm_vtpm_send_command() to be used by 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 Reviewed-by: Tom Lendacky Reviewed-by: Jarkko Sakkinen Signed-off-by: Stefano Garzarella --- v7: - avoided exporting snp_svsm_vtpm_probe() because we will only use it internally v5: - added stubs when !CONFIG_AMD_MEM_ENCRYPT [Dionna] - added Jarkko's R-b v4: - added Tom's R-b - added functions documentation [Jarkko] - simplified TPM_SEND_COMMAND check [Tom/Jarkko] 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 | 58 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) diff --git a/arch/x86/include/asm/sev.h b/arch/x86/include/asm/sev.h index ba7999f66abe..d9ba035d8609 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,8 @@ 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); +int snp_svsm_vtpm_send_command(u8 *buffer); + void __init snp_secure_tsc_prepare(void); void __init snp_secure_tsc_init(void); @@ -524,6 +530,7 @@ static inline struct snp_msg_desc *snp_msg_alloc(void) { return NULL; } static inline void snp_msg_free(struct snp_msg_desc *mdesc) { } static inline int snp_send_guest_request(struct snp_msg_desc *mdesc, struct snp_guest_req *req, struct snp_guest_request_ioctl *rio) { return -ENODEV; } +static inline int snp_svsm_vtpm_send_command(u8 *buffer) { return -ENODEV; } static inline void __init snp_secure_tsc_prepare(void) { } static inline void __init snp_secure_tsc_init(void) { } diff --git a/arch/x86/coco/sev/core.c b/arch/x86/coco/sev/core.c index b0c1a7a57497..3bc5b47e7304 100644 --- a/arch/x86/coco/sev/core.c +++ b/arch/x86/coco/sev/core.c @@ -2625,6 +2625,64 @@ static int snp_issue_guest_request(struct snp_guest_req *req, struct snp_req_dat return ret; } +/** + * snp_svsm_vtpm_probe() - Probe if SVSM provides a vTPM device + * + * This function checks that there is SVSM and that it supports at least + * TPM_SEND_COMMAND which is the only request we use so far. + * + * Return: true if the platform provides a vTPM SVSM device, false otherwise. + */ +static 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); +} + +/** + * snp_svsm_vtpm_send_command() - execute a vTPM operation on SVSM + * @buffer: A buffer used to both send the command and receive the response. + * + * This function executes a SVSM_VTPM_CMD call as defined by + * "Secure VM Service Module for SEV-SNP Guests" Publication # 58019 Revision: 1.00 + * + * All command request/response buffers have a common structure as specified by + * the following table: + * Byte Size     In/Out    Description + * Offset    (Bytes) + * 0x000     4          In        Platform command + *                         Out       Platform command response size + * + * Each command can build upon this common request/response structure to create + * a structure specific to the command. + * See include/linux/tpm_svsm.h for more details. + * + * Return: 0 on success, -errno on failure + */ +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 Thu Apr 10 13:51:14 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Stefano Garzarella X-Patchwork-Id: 14046557 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 6541928C5C7 for ; Thu, 10 Apr 2025 13:51:35 +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=1744293097; cv=none; b=CkfIXgDtIylTTfExImCX/rbU49jQQX08lwoS8GmfRY8hkrfsDMj4SvC8UuapBxM9EOZEEnnA79PjXPpryJ7aEfF3uZQSl0S7TtcZStwU5wPmkrkoIoyPBuVrM53/KlABxXwHzj91TASTuPZ4poHV507GxjarojeBFKUsrxrC2Vw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744293097; c=relaxed/simple; bh=JanhuPR/iml68kEFk6VsdfPYwqYcdQYvtjajdTMi5bI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=N0IO+2V1nzuq5iwp4U1KfQWlDsFRJGnxbXoYza0mXbgJh3ZtQeEzXIEAjnjEciimhM7MUX3P/3rGtqr88RSV4ifjGGxu7rNdIZ796zvUwEmNIBYsSX6nEdmoY/QhUZR6q8Sg/yUDk8qTBCJWxlGVE1cAjUOpAkDzTu1J1YQfDHw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine 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=DE8ir8AY; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine 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="DE8ir8AY" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1744293094; h=from:from: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: in-reply-to:in-reply-to:references:references; bh=9cwx8PB++1jPTpqj+0lA5MhEHp2F2B5hQ/5H2FoJu9E=; b=DE8ir8AY4zQElribE6WB5jfExzlMGS5uqmFtOhh5T4YnapP3OJ0bTmAdmAGEbc6odJKO4L Pu9mqsZ+0oza17fLJkjBksGOZnus3RVSMtLV3CsCQTbT/YBxN6bbJeLOrw7n/AaSG+W5DB fupe+JntKdw/y59quwn8+O7s147GzDQ= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-108-u9zlIOIENYe_MF2RbxciqQ-1; Thu, 10 Apr 2025 09:51:33 -0400 X-MC-Unique: u9zlIOIENYe_MF2RbxciqQ-1 X-Mimecast-MFC-AGG-ID: u9zlIOIENYe_MF2RbxciqQ_1744293092 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-43e9b0fd00cso4283395e9.0 for ; Thu, 10 Apr 2025 06:51:33 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744293092; x=1744897892; 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=9cwx8PB++1jPTpqj+0lA5MhEHp2F2B5hQ/5H2FoJu9E=; b=CCKM3VwsQkHh3v+eJB9nvcMzZRcPUCcswB5isVDN7CvzMwJR6ICyTCKmV3s3qNj0pj TO385qG/qLSVmDu38SQR4n0h/4eLW76bxbCazMrsErUUocvXoi+UMBhsdomvqwVxKXhV jyrjKM+SgRReA6syNV/4SDCd4AZ1jwbYhJtbfhnuIMCUA+OTBjBPjVsLy+/tqOyXF7qG R1BGmIOWysYG1GPjpjbGuCWFyOstwSnrqzVkY4mM4DZpsHMS5bKxRNBTnx0x3o0B9zAD 5BUKXzzqNDczyxGZHxhvzNdIlg4f5iIeme91QevnU9SaG9xpyN9gzIlz8A3TcTeJnWUF oKQQ== X-Forwarded-Encrypted: i=1; AJvYcCXXCxb5l+bzZFI9VZzmFEGD/nVKagdYbmNS6mh+n/qsK9flz9j99L0jI5FA6k1bHnxoQka6Wxp+jrJ8qbqGNco=@vger.kernel.org X-Gm-Message-State: AOJu0YwMJV67dbL9cGmmW/Wfo8VbIYZWxosKo9TnlOxjuTScJeeemBhs n7W4ZMl24QgG57IzMH5Q/qyFXLk7e/hPUG+90uP5Z7KUdLiFVz3fLDU7wZUuqYrAW4Q2NBObE5U Q+IXHY3lEZrHqFFWvpO5zBYCf8T0OaY7PKH4bmO8xZ0ZMAHrkd29NNz3uMEluzhOL6A== X-Gm-Gg: ASbGnctnIgIMqPIrQt9cQW0BLb6aqGXHsjMtzNWqx0fiwsrU974NW0ZoEdr+bdxHFjZ pxlOxAjW908riqU+lI4Ed1wbab/YmL4FvynseXq1xqiQx4u3iwM/ZQ+OXc0Mpc6rmxEi+G+hQX0 5dgGniTETHQjpzV4Fjgjvtx6gIy+q/DUZKggeFAtv9J6LCURjg5kke8Nxf8zRgmviCBFH3CAU0S if5Xvhj5WerUddMVD5Zko271NVt1VyWH7r7M4mX3cVrYqqyYryDUO/ey+RW8Un/1ZK7kBHq+kCM ALcPYkaI1RDA+UR8puVnbDiHxUWcgaXWq7AxVRmmBVRsvveN7VdPiPcZXAghpw== X-Received: by 2002:a05:600c:1614:b0:43d:fa5f:7d04 with SMTP id 5b1f17b1804b1-43f2edc7c63mr20711435e9.16.1744293091878; Thu, 10 Apr 2025 06:51:31 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEuGhwEkIOIQmV9vyTTjh08E802YQY2NMK9rYdrO7U9thvFq8ZhNT2/VmlP/YCA83my8ZlkmQ== X-Received: by 2002:a05:600c:1614:b0:43d:fa5f:7d04 with SMTP id 5b1f17b1804b1-43f2edc7c63mr20711175e9.16.1744293091252; Thu, 10 Apr 2025 06:51:31 -0700 (PDT) Received: from stex1.redhat.com (host-79-53-30-213.retail.telecomitalia.it. [79.53.30.213]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-43f2075fc83sm57126385e9.26.2025.04.10.06.51.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Apr 2025 06:51:30 -0700 (PDT) From: Stefano Garzarella To: Borislav Petkov , Jarkko Sakkinen Cc: Joerg Roedel , "H. Peter Anvin" , Dionna Glaze , Ingo Molnar , linux-kernel@vger.kernel.org, Dov Murik , linux-integrity@vger.kernel.org, Dave Hansen , Claudio Carvalho , Tom Lendacky , Thomas Gleixner , Peter Huewe , Jason Gunthorpe , x86@kernel.org, James Bottomley , linux-coco@lists.linux.dev, Stefano Garzarella Subject: [PATCH v7 2/4] svsm: add header with SVSM_VTPM_CMD helpers Date: Thu, 10 Apr 2025 15:51:14 +0200 Message-ID: <20250410135118.133240-3-sgarzare@redhat.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250410135118.133240-1-sgarzare@redhat.com> References: <20250410135118.133240-1-sgarzare@redhat.com> Precedence: bulk X-Mailing-List: linux-integrity@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Stefano Garzarella 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 Reviewed-by: Jarkko Sakkinen Signed-off-by: Stefano Garzarella --- v5: - added Jarkko's R-b v4: - used svsm_vtpm_ prefix consistently [Jarkko] - removed __packed where not needed [Jarkko] - expanded headers to avoid obfuscation [Jarkko] - used `buf` instead of `inbuf`/`outbuf` [Jarkko] - added more documentation quoting the specification - removed TPM_* macros since we only use TPM_SEND_COMMAND in one place and don't want dependencies on external headers, but put the value directly as specified in the AMD SVSM specification - header renamed in tpm_svsm.h so it will fall under TPM DEVICE DRIVER section [Borislav, Jarkko] 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/tpm_svsm.h | 149 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 149 insertions(+) create mode 100644 include/linux/tpm_svsm.h diff --git a/include/linux/tpm_svsm.h b/include/linux/tpm_svsm.h new file mode 100644 index 000000000000..38e341f9761a --- /dev/null +++ b/include/linux/tpm_svsm.h @@ -0,0 +1,149 @@ +/* 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 _TPM_SVSM_H_ +#define _TPM_SVSM_H_ + +#include +#include +#include + +#define SVSM_VTPM_MAX_BUFFER 4096 /* max req/resp buffer size */ + +/** + * struct svsm_vtpm_request - Generic request for single word command + * @cmd: The command to send + * + * Defined by AMD SVSM spec [1] in section "8.2 SVSM_VTPM_CMD Call" - + * Table 15: vTPM Common Request/Response Structure + * Byte Size     In/Out    Description + * Offset    (Bytes) + * 0x000     4          In        Platform command + *                         Out       Platform command response size + */ +struct svsm_vtpm_request { + u32 cmd; +}; + +/** + * struct svsm_vtpm_response - Generic response + * @size: The response size (zero if nothing follows) + * + * Defined by AMD SVSM spec [1] in section "8.2 SVSM_VTPM_CMD Call" - + * Table 15: vTPM Common Request/Response Structure + * Byte Size     In/Out    Description + * Offset    (Bytes) + * 0x000     4          In        Platform command + *                         Out       Platform command response size + * + * Note: most TCG Simulator commands simply return zero here with no indication + * of success or failure. + */ +struct svsm_vtpm_response { + u32 size; +}; + +/** + * struct svsm_vtpm_cmd_request - Structure for a TPM_SEND_COMMAND request + * @cmd: The command to send (must be TPM_SEND_COMMAND) + * @locality: The locality + * @buf_size: The size of the input buffer following + * @buf: A buffer of size buf_size + * + * Defined by AMD SVSM spec [1] in section "8.2 SVSM_VTPM_CMD Call" - + * Table 16: TPM_SEND_COMMAND Request Structure + * Byte Size Meaning + * Offset    (Bytes) + * 0x000     4          Platform command (8) + * 0x004     1          Locality (must-be-0) + * 0x005     4          TPM Command size (in bytes) + * 0x009     Variable   TPM Command + * + * Note: the TCG Simulator expects @buf_size to be equal to the size of the + * specific TPM command, otherwise an TPM_RC_COMMAND_SIZE error is returned. + */ +struct svsm_vtpm_cmd_request { + u32 cmd; + u8 locality; + u32 buf_size; + u8 buf[]; +} __packed; + +/** + * struct svsm_vtpm_cmd_response - Structure for a TPM_SEND_COMMAND response + * @buf_size: The size of the output buffer following + * @buf: A buffer of size buf_size + * + * Defined by AMD SVSM spec [1] in section "8.2 SVSM_VTPM_CMD Call" - + * Table 17: TPM_SEND_COMMAND Response Structure + * Byte Size Meaning + * Offset    (Bytes) + * 0x000     4          Response size (in bytes) + * 0x004     Variable   Response + */ +struct svsm_vtpm_cmd_response { + u32 buf_size; + u8 buf[]; +}; + +/** + * svsm_vtpm_cmd_request_fill() - Fill a TPM_SEND_COMMAND request to be sent to SVSM + * @req: The struct svsm_vtpm_cmd_request 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_cmd_request_fill(struct svsm_vtpm_cmd_request *req, u8 locality, + const u8 *buf, size_t len) +{ + if (len > SVSM_VTPM_MAX_BUFFER - sizeof(*req)) + return -EINVAL; + + req->cmd = 8; /* TPM_SEND_COMMAND */ + req->locality = locality; + req->buf_size = len; + + memcpy(req->buf, buf, len); + + return 0; +} + +/** + * svsm_vtpm_cmd_response_parse() - Parse a TPM_SEND_COMMAND response received from SVSM + * @resp: The struct svsm_vtpm_cmd_response 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_cmd_response_parse(const struct svsm_vtpm_cmd_response *resp, u8 *buf, + size_t len) +{ + if (len < resp->buf_size) + return -E2BIG; + + if (resp->buf_size > SVSM_VTPM_MAX_BUFFER - sizeof(*resp)) + return -EINVAL; // Invalid response from the platform TPM + + memcpy(buf, resp->buf, resp->buf_size); + + return resp->buf_size; +} + +#endif /* _TPM_SVSM_H_ */ From patchwork Thu Apr 10 13:51:15 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Garzarella X-Patchwork-Id: 14046558 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 D6E9628C5D8 for ; Thu, 10 Apr 2025 13:51:41 +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=1744293103; cv=none; b=N7mWh5ciD/9uDn22HnddVUBV2vLqn39cBRKNDJZZk17z12vHep5BhbFzUpCq2fANjlRA1sU0GIMBbAGKXSbBpZMqX6GZH2oiuw7vk7vdV5FVpfRvStJa41ckg5wZELbd8Wi1kAa5YgwKK1YMmKPcy3+wOu94bprrYizKCkW6LxA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744293103; c=relaxed/simple; bh=BTUc9p0P7fj/IdeyhhIG8U1tRS0y26+L6mvGHy8buuU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GmyJvmwLuOL+Sy7nJCHyvox0StoFSrQgdABGERoRvMiM7au/IBmnXO/lCj71lr5xobZwK45eic2k3Ya+CSBNqDL2lXF82e808iYDYh1GA7sNcOI8WPcEer+ZtuyvpfB9YA3W2rwJHAwWgnz9nMelsQ9WLjHxCuMwCiCrgUDiurA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine 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=OZC7zY23; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine 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="OZC7zY23" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1744293101; 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=a/4sxX4zYlWzMuPRt3jzKJXuc3Oa7Ar74ewr3j43ie4=; b=OZC7zY23M7bWmd4fSItfRSaY0skSBw77YeySQcRmnXsw5S5sjfUvEbe2Y7tX0Xa/JeAc3j /6tJOZ1vYKAwaUV4bS12YSeieJkzq9kL07O4TSHAarG8/sOW2TYv4YXZboGpT0u8NiAoxH Ih8SkxI2AbgZGo1vhA/dsewo5EQxce4= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-14-yd7RjOj5MiqsukX_I7IXJA-1; Thu, 10 Apr 2025 09:51:38 -0400 X-MC-Unique: yd7RjOj5MiqsukX_I7IXJA-1 X-Mimecast-MFC-AGG-ID: yd7RjOj5MiqsukX_I7IXJA_1744293097 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-43941ad86d4so4980795e9.2 for ; Thu, 10 Apr 2025 06:51:37 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744293096; x=1744897896; 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=a/4sxX4zYlWzMuPRt3jzKJXuc3Oa7Ar74ewr3j43ie4=; b=Kz1mGcG6dVeqhe46Jn/RPoWtHFp1B5gwODiIPmQgHUVVbDK329hYIYkLW/gJ2hsNlS /OSN9fmRm/jB8H65bzGZ0i2GisX75ISqvb0hIFMtkqPir7kyELFtZvi+0VstYkT1pEQp bmwjvutjbTR5E9G75VWjITiD1I0gsIkY3le1kmKOf9KayPtzbhCD1QTAuxqo3a8LfXmq hsTel9EZ9zNv2Dbobs2NympeF2Jan60ZkAS83x+MZbWod4WRG7bVSLQ7jGJpNyhWycCl klXSYRwcJXx43QAeIze7pwvHJbJKoXRn+BWdX8w5sPfIb6eBdlYMTeXJM7wsiG5V+F/8 p62w== X-Forwarded-Encrypted: i=1; AJvYcCUd1/qnSIPH4yHlJjqFiG7kR+j2bh2AyfL/d/81YlqJbA6CaLtlhOFyTeN5vUe/r27PQeVsZgOB9vhmtUYBhek=@vger.kernel.org X-Gm-Message-State: AOJu0YxtKLVFfho5TzLgKbso3hwWlb3k9MZA3inITpaYQSXbhhbKJs3U oOOzRZNXUnwvSlJybffV6i8PyqBQPYFca3a5lQbjrz8kPwi32sWF0Y0OeDpD5YdPLxdRY0mJ7w6 m26QdKk2U/1d4JJgTXC8bMzy7odKG1GWhZqyzz73Ubloes75RftmiBe+gGIh4lZbhNA== X-Gm-Gg: ASbGncu6uksfD/EJmd88wEpo71aiD0ldnVOyYkuBc/WKQ9n278PZ+Kjb5ipPHDGcsks e/Ll5UOYtOt/8/xU867KcTTL52HDrOqMD1g9CCABJBfGAUFxBPlVIQNdRaJHALxQbJDWFfE9mCZ V8WxtKjeb/JgOohyUIQCIsvIXAHbOYV0QPhP2uyQTsftufHHXpSsGQbbwBpdxWEspnLYwCqHxpD aMBvPBdOBRgoy9YOWhMKkSPKhhQO3O6ACpBVsh4uG1IRFMFiwpuguyjJCDDMyoP8RaSns0Nc7EI /aaEd92mYZOthz3M0yU+ZWfujeocOk0+8u/5cqHF54rDhTLsILrhcmbCSsh4XA== X-Received: by 2002:a05:600c:1d10:b0:43d:42b:e186 with SMTP id 5b1f17b1804b1-43f2d7bbe9dmr25367825e9.8.1744293096540; Thu, 10 Apr 2025 06:51:36 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFBFkr3gV1YG3NMqGEsLFTmg6/59TSCe3mxGOyIVGTKktzJth53MhEnXCXkeFjtq7SaUo9uHw== X-Received: by 2002:a05:600c:1d10:b0:43d:42b:e186 with SMTP id 5b1f17b1804b1-43f2d7bbe9dmr25367365e9.8.1744293096036; Thu, 10 Apr 2025 06:51:36 -0700 (PDT) Received: from stex1.redhat.com (host-79-53-30-213.retail.telecomitalia.it. [79.53.30.213]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-39d8938a761sm4932483f8f.51.2025.04.10.06.51.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Apr 2025 06:51:35 -0700 (PDT) From: Stefano Garzarella To: Borislav Petkov , Jarkko Sakkinen Cc: Joerg Roedel , "H. Peter Anvin" , Dionna Glaze , Ingo Molnar , linux-kernel@vger.kernel.org, Dov Murik , linux-integrity@vger.kernel.org, Dave Hansen , Claudio Carvalho , Tom Lendacky , Thomas Gleixner , Peter Huewe , Jason Gunthorpe , x86@kernel.org, James Bottomley , linux-coco@lists.linux.dev, Stefano Garzarella Subject: [PATCH v7 3/4] tpm: add SNP SVSM vTPM driver Date: Thu, 10 Apr 2025 15:51:15 +0200 Message-ID: <20250410135118.133240-4-sgarzare@redhat.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250410135118.133240-1-sgarzare@redhat.com> References: <20250410135118.133240-1-sgarzare@redhat.com> Precedence: bulk X-Mailing-List: linux-integrity@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Stefano Garzarella 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 API exposed by x86/sev 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 device will be registered by the platform only when it's available, so the probe function just needs to setup the tpm_chip. 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 is not implemented as recently supported by commit 980a573621ea ("tpm: Make chip->{status,cancel,req_canceled} opt"). [1] "Secure VM Service Module for SEV-SNP Guests" Publication # 58019 Revision: 1.00 Reviewed-by: Jarkko Sakkinen Signed-off-by: Stefano Garzarella --- v7: - added Jarkko's R-b - avoided to call snp_svsm_vtpm_probe() since the device will be registered by SEV core only if the device is detected [Borislav] - updated commit description v6: - removed the `locality` field (set to 0) and the FIXME comment [Jarkko] v5: - removed cancel/status/req_* ops after rebase on master that cotains commit 980a573621ea ("tpm: Make chip->{status,cancel,req_canceled} opt") v4: - moved "asm" includes after the "linux" includes [Tom] - allocated buffer separately [Tom/Jarkko/Jason] 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 | 125 ++++++++++++++++++++++++++++++++++++ drivers/char/tpm/Kconfig | 10 +++ drivers/char/tpm/Makefile | 1 + 3 files changed, 136 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..4280edf427d6 --- /dev/null +++ b/drivers/char/tpm/tpm_svsm.c @@ -0,0 +1,125 @@ +// 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 { + void *buffer; +}; + +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_cmd_request_fill(priv->buffer, 0, 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_cmd_response_parse(priv->buffer, buf, len); +} + +static struct tpm_class_ops tpm_chip_ops = { + .flags = TPM_OPS_AUTO_STARTUP, + .recv = tpm_svsm_recv, + .send = tpm_svsm_send, +}; + +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; + + priv = devm_kmalloc(dev, sizeof(*priv), GFP_KERNEL); + if (!priv) + return -ENOMEM; + + /* + * The maximum buffer supported is one page (see SVSM_VTPM_MAX_BUFFER + * in tpm_svsm.h). + */ + priv->buffer = (void *)devm_get_free_pages(dev, GFP_KERNEL, 0); + if (!priv->buffer) + return -ENOMEM; + + 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 fe4f3a609934..dddd702b2454 100644 --- a/drivers/char/tpm/Kconfig +++ b/drivers/char/tpm/Kconfig @@ -234,5 +234,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 2b004df8c04b..9de1b3ea34a9 100644 --- a/drivers/char/tpm/Makefile +++ b/drivers/char/tpm/Makefile @@ -45,3 +45,4 @@ obj-$(CONFIG_TCG_CRB) += tpm_crb.o obj-$(CONFIG_TCG_ARM_CRB_FFA) += tpm_crb_ffa.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 Thu Apr 10 13:51:16 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Garzarella X-Patchwork-Id: 14046559 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 F3DFC28CF59 for ; Thu, 10 Apr 2025 13:51:44 +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=1744293106; cv=none; b=YVxf8lVKkSGn569/p5Ukp/786fdBigIfKZExG2L7SiHfhXhBd2Wlkvkpi/hy7YxR3drRpstKn3G10kyXD+stcPJQn9FwN+K/e0D6S8B3duagODucwIj1lvcPTmdx2FxH8r3GTHSoZw8Q62f+lY6f9LKOs+A4LrCY1VoQmxKEVcs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744293106; c=relaxed/simple; bh=jjdOFFgqlMZcJK0ENY0EeRcZvGY/PqG+Cg3KwCJxajM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LT+SkUwTtLi/m9pRKX42rJqvpZGDXOD0JP9ClqPOI9azNjTcU1FNJg3Oh8A6iy4Ur284RVMYsm7PUp6EmyBRIQNmUzjB5dIxWZmrkGasY7gCIPf6afTpCvoBFPwDDioHXyzRYM1Xl9zYYfI5C0Vat1VWMmS/bVSnCSnFFnMb+L4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine 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=Gfi3aRmW; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine 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="Gfi3aRmW" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1744293103; 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=hirGwPCk5S8fr8wcRk+QWxpexKbLzBx8zDafwqq8PVw=; b=Gfi3aRmWaU2PwbOF4asO/LZwJwQ3yoD6Ai2dh0rwLCpC+xBsFMcsrHHneAS2kG2GI11RIi +k+65vkXvROTYRENdNzbAisILkI4egOfSl2KC8J+xB4aQaBzOHcBGitgS/URgz3zdPBYaE BSzqUr+dC1W+DOFfBRbxwEslYuqfO1M= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-113-QMlbOU8lNzi_oVBk0iq7cA-1; Thu, 10 Apr 2025 09:51:42 -0400 X-MC-Unique: QMlbOU8lNzi_oVBk0iq7cA-1 X-Mimecast-MFC-AGG-ID: QMlbOU8lNzi_oVBk0iq7cA_1744293101 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-43d0830c3f7so7108965e9.2 for ; Thu, 10 Apr 2025 06:51:42 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744293101; x=1744897901; 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=hirGwPCk5S8fr8wcRk+QWxpexKbLzBx8zDafwqq8PVw=; b=kSjtjQ7V4qsvUfMbGLHzf6dTxRN+fLjScITF5JUoRpqYik+RFDLBieto2n9PWb+D1A w6FHTGfyTpjA+E49uANrDTpeKS1PdYsAJEBV7nwLMcKbHnwX9Bv8hKI2TRYzxO9X6dhR rFfiN/JmbF+NUGpRbxoHTbgV6XsCVzfYi6vUBIm5zuPt5XBdm7FeONb6yfoYaBCu17DD 0721IYpzVegnZ35DQUwObsDPqce9MDDQ7fajgAUpyxAqAPpoGsmEl9PiOq+LAY36XGpB e4hNTtwJlmecyNHr3sD8idGVjjLZQ/CuAkfzQQYrBXcwt/dBSglWd85sbGRZ5OdNxCVJ vUbA== X-Forwarded-Encrypted: i=1; AJvYcCVNVABqrbISVWVIonsIYc2dURMK5NmS+xA12tDatwhM8H6xZhE5uhlHGk1RYUWVdcy2CMVZFasWTAr1X4ZiRaU=@vger.kernel.org X-Gm-Message-State: AOJu0YxGMG01M5vaEeJ6gWBmfil2ueK2cLdLj5H+O/JtoLIFwdquBOb8 Q8+mLjkIFBTD9i4M7lL/vduFNasbz/li7Huu8ML6I/d/D8X0CyLY2veu9MOIZctMKFGFjJWAwOb aLBaq7p6UaqLUiyAU3U9Pv2ammRQUEr03lhXNR6UhtB2ZprKE7vPE3ArZQSvl8V3iNw== X-Gm-Gg: ASbGncv/BVqTubCSKJoJdgW9pQAikdsxbIhq4MzlphsNOj21nO1x1koYZp+BA6hi0xT gcA1bOavqf6DH4L7NQ4nT9Spwk3542GSG65VqJvQlxbmR7Dk+9p/ghKbPw7RjIU1LyQJR01DF5y NaPiLjTBE2KmKCucQWhLb/UMlu1LYvyQm5As12O3ALPdpkytrQkWrou6i+qcb+jqEAMVrqnMlD6 3QauYHZVQNWtwDiubyPBgAzBQgUspUWrdfZIGTpMqTYfca5yUR7TXKWjUKbiyWVH8pRrbtYRndi u88URiZuDzNUrX7HCBUderB13DZu9i3v77aTgqY1M+I+9HY9KmDVTGh+skTVQA== X-Received: by 2002:a05:600c:1e21:b0:43c:fa0e:471a with SMTP id 5b1f17b1804b1-43f2fdcece5mr23351915e9.5.1744293101427; Thu, 10 Apr 2025 06:51:41 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFW/+UygbSs3rimVhsZR25l1U5u5O39Yy7PeRlqUDpdrrg1Z1uyMNvSAu+c2o2wo8JQdf6sGQ== X-Received: by 2002:a05:600c:1e21:b0:43c:fa0e:471a with SMTP id 5b1f17b1804b1-43f2fdcece5mr23351565e9.5.1744293100851; Thu, 10 Apr 2025 06:51:40 -0700 (PDT) Received: from stex1.redhat.com (host-79-53-30-213.retail.telecomitalia.it. [79.53.30.213]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-39d893fdfbesm4768782f8f.88.2025.04.10.06.51.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Apr 2025 06:51:40 -0700 (PDT) From: Stefano Garzarella To: Borislav Petkov , Jarkko Sakkinen Cc: Joerg Roedel , "H. Peter Anvin" , Dionna Glaze , Ingo Molnar , linux-kernel@vger.kernel.org, Dov Murik , linux-integrity@vger.kernel.org, Dave Hansen , Claudio Carvalho , Tom Lendacky , Thomas Gleixner , Peter Huewe , Jason Gunthorpe , x86@kernel.org, James Bottomley , linux-coco@lists.linux.dev, Stefano Garzarella Subject: [PATCH v7 4/4] x86/sev: register tpm-svsm platform device Date: Thu, 10 Apr 2025 15:51:16 +0200 Message-ID: <20250410135118.133240-5-sgarzare@redhat.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250410135118.133240-1-sgarzare@redhat.com> References: <20250410135118.133240-1-sgarzare@redhat.com> Precedence: bulk X-Mailing-List: linux-integrity@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Stefano Garzarella 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 Register the platform device only when SVSM is available and it supports vTPM commands as checked by snp_svsm_vtpm_probe(). Reviewed-by: Tom Lendacky Reviewed-by: Jarkko Sakkinen Signed-off-by: Stefano Garzarella --- v7: - added Jarkko's R-b - call snp_svsm_vtpm_probe() before registering the device [Borislav] - s/device/devices in pr_info [Tom] - updated commit description v6: - added Tom's R-b v4: - explained better why we register it anyway in the commit message --- arch/x86/coco/sev/core.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/arch/x86/coco/sev/core.c b/arch/x86/coco/sev/core.c index 3bc5b47e7304..54272c9777cf 100644 --- a/arch/x86/coco/sev/core.c +++ b/arch/x86/coco/sev/core.c @@ -2688,6 +2688,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)) @@ -2696,7 +2701,11 @@ static int __init snp_init_platform_device(void) if (platform_device_register(&sev_guest_device)) return -ENODEV; - pr_info("SNP guest platform device initialized.\n"); + if (snp_svsm_vtpm_probe() && + platform_device_register(&tpm_svsm_device)) + return -ENODEV; + + pr_info("SNP guest platform devices initialized.\n"); return 0; } device_initcall(snp_init_platform_device);