Received: by 2002:ab2:710b:0:b0:1ef:a325:1205 with SMTP id z11csp526562lql; Mon, 11 Mar 2024 09:28:10 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWDGPVrUxqhkAgg1qbD5HySwjkBnRvN4lAkhXDYU6Cgla+CMu4EuXaNX9zlCnFKmKMtxQjipPc5KMmQewicRugOYEccPF6yrds6oU+tfg== X-Google-Smtp-Source: AGHT+IEU1CI0mSh+7TTHcBuy+SPuFTE56Tsn3whNA+BC1esvXUtqHOIbw0gHxzXv0USFnColCsvV X-Received: by 2002:a50:cc9e:0:b0:565:6e34:da30 with SMTP id q30-20020a50cc9e000000b005656e34da30mr4782029edi.21.1710174490552; Mon, 11 Mar 2024 09:28:10 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710174490; cv=pass; d=google.com; s=arc-20160816; b=eRQhoyI+4h5TI8pg25qzAwPzPRsYCmaKou+Jda9BFLuIIQeK088TYP9FcK+m2MvPdZ z77+p3Gb0cOuAbmoTF5WrGLF+QhTEFGOT1aVVUnIZq5DGAJQ7s1UfFSjM1FPc+9XYWet 7xVpc9szCFefnR3XMCvrgJkmjoUroPNzily5kXYNAkhJl7Kdwhd9oPnnmHUnx6h5cm12 1rmSRR80VrXEFEXRqDZFZhcayQosFmYxeCVDKCBNRgci4Ni512lnzrBM92tO58WFIFdQ eRxoCbL+ZOFvMYJEBZNIT2KkFHmuQj9SszMqJHqaLHP1Pxg4zBkBni7Fm477eC2RHcLp kBRg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=0Nx+lR8M3d9xAl/7OW4v6MUggA0QirKWOFkex7liC38=; fh=9Fn7dYtMENR9sKFnS8PwyFE8X7Ywip5nC1/zf42FGtc=; b=KTM9OhLcw52TPwsvOXV1NyOfpWfy1be0t3ePiOcviqhb7oOjlDJUEG6saAm3PdOiMu 5gfd5PhRx2YhWTTAQ4ErKRxlvPOuvEyPtragFKzyjctMEtVf6JXhtrv5ykbi//lBhMgf gDNDv3rusMA6bqC3aqPdTioAyIqCIhFXXwoUxXNsDo6XYjfNFO/0HEnb+8obMIVeD33M pLu/FhVf77M9CG9K6W0uzT4HuMBnx4e0rnLu+vIj3MaFWAkdxubkdDrYGigL1IJNy/tI wSm2MAx5/ykCIhANe1mnBn9e27OBUcY76/zVYh2M8Ji9ajBHOQP9f7S3f/SB238LZaXr yJKg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=PUTLF6ua; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-99204-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-99204-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id t20-20020aa7d714000000b005682919cfd8si2590706edq.401.2024.03.11.09.28.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Mar 2024 09:28:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-99204-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=PUTLF6ua; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-99204-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-99204-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 56DEF1F24F6F for ; Mon, 11 Mar 2024 16:19:11 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E8C484F88B; Mon, 11 Mar 2024 16:17:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="PUTLF6ua" Received: from mail-wm1-f48.google.com (mail-wm1-f48.google.com [209.85.128.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DF5D24AEDA; Mon, 11 Mar 2024 16:17:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.48 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710173861; cv=none; b=auuHsbO8lRYl6R6aryNUO0GikapH4DIqBG9WYuFU04cFCiyLc8QXwAmCZkhVXEZDYjVAw814jzIw6GFcdVyaKYJ/khP+gGH1SFtnu//139zdZNs5B0L6bRsOqKBiy9kQ2MtF38aLeTZGDqoXbOjrd/Ae0EbZSY93QAtLHhFqA24= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710173861; c=relaxed/simple; bh=k4KATT8BongMPGyzu+avZmp/iNPi9MTSWDfDzR0R684=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=c5aeFlZtpz76M38YW9I4Ns5I21E0G+dSQY1pL1PqFJEyzsc7j/KRH/7NfBrHBHkrucxGZgYfOJwHQS4bNDsBkjGUil046m/sdrdj+BAWSIOzMb0idyfDXWahQ2YxtxsvwvJ6ZEE4K9FFvdUmm9Y7jAsxmYrQIAmqhLEKyxb6QBA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=PUTLF6ua; arc=none smtp.client-ip=209.85.128.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-wm1-f48.google.com with SMTP id 5b1f17b1804b1-4132a348546so6544325e9.1; Mon, 11 Mar 2024 09:17:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1710173855; x=1710778655; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=0Nx+lR8M3d9xAl/7OW4v6MUggA0QirKWOFkex7liC38=; b=PUTLF6uaQOodHYlkv1iYEultL0aqWR7CB2/oZzTdhptA4+ZO2sUH15yd1hzuNXLv+v 704nskS544QnNv5HYtbfj8CCVbNno7HOaThs5YOuZi5N+x2+FeJzQBoannaMBCRWVPjU ODXvu3RenOsYD0Xhd7VQFqlO7UQWIeL3u/y8GbirH9b1eo08U3JlFQGuARoyxayVjYrQ gevffjZkFz/K5KMwMLJ8MKBeM6HkzPU5ACvfVrieh59ggzX/Wk7WDt2nSQdRXxQONIJ/ /ZRyY+oL1SgXYPoJgNe5YYbNKpNGBULWDyq3Yv0xmBRLqd5E0hHgBbO+0qojNGDEELfY wvQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710173855; x=1710778655; 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=0Nx+lR8M3d9xAl/7OW4v6MUggA0QirKWOFkex7liC38=; b=AfD/PNRfmpthq50AibdLrWWBsgJe3IAjFP02vsibVWdJLXN4YVCNvt9ufVuYfkMOl/ P8+zzi+zIpbWYjk/lOyBYfvVYCohyC12XtDVpQKkpcChm4+Epr89y0APrIqTyUhZ4umI +UwOhebZ6GTzvDSE0S6RgTbXQsDO3egWNP/rX1tHIrtGA/qMWgV3LlTgcOqJMc7TejSf HNdhBFhFi2FJ3BK6LWJU8XEqVDbivnFg3Xz8GVVfaQpz9oIXEaYbrYHjj0Hw4Gq1An0k iTikp38lWl60Ok7DVUXcaUsK0U2EgNEQ8NyZYhiXIem5rfm/oSnWt9C0tvSc8UuMdcQ9 dtEA== X-Forwarded-Encrypted: i=1; AJvYcCX9oiQvplo1JI2G4Db1Q78OOSC8S3zCHh7mya4rIdEgLAq2pWsAOXh4wN+25skqDISe4aEdmKtvPeoYR4YXzjTSAdhReg5wLUkAXyPlKT95LAdaM8Y3Wc2SszM0qK00YNPBkTxhYp7XTFvGIo9I660t0WXi1Na+/hSi X-Gm-Message-State: AOJu0YyqOBpEz0pPxoGwPrq8/TAz6OrHXn7Adv852aUqD//jaU14vDOO qbpCAXtCOD89CpXU/zZZmjTXlcD3u86CeW+6OzjSd/pAvnJu3dWH X-Received: by 2002:a05:600c:458c:b0:413:2c3e:c323 with SMTP id r12-20020a05600c458c00b004132c3ec323mr1492631wmo.38.1710173855159; Mon, 11 Mar 2024 09:17:35 -0700 (PDT) Received: from vasant-suse.suse.cz ([2001:9e8:ab47:8200:c3b9:43af:f8e1:76f9]) by smtp.gmail.com with ESMTPSA id ba14-20020a0560001c0e00b0033e96fe9479sm2823815wrb.89.2024.03.11.09.17.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Mar 2024 09:17:34 -0700 (PDT) From: Vasant Karasulli To: x86@kernel.org Cc: joro@8bytes.org, cfir@google.com, dan.j.williams@intel.com, dave.hansen@linux.intel.com, ebiederm@xmission.com, erdemaktas@google.com, hpa@zytor.com, jgross@suse.com, jslaby@suse.cz, keescook@chromium.org, kexec@lists.infradead.org, kvm@vger.kernel.org, linux-coco@lists.linux.dev, linux-kernel@vger.kernel.org, luto@kernel.org, martin.b.radev@gmail.com, mhiramat@kernel.org, mstunes@vmware.com, nivedita@alum.mit.edu, peterz@infradead.org, rientjes@google.com, seanjc@google.com, stable@vger.kernel.org, thomas.lendacky@amd.com, virtualization@lists.linux-foundation.org, Joerg Roedel , Vasant Karasulli Subject: [PATCH v4 2/9] x86/sev: Save and print negotiated GHCB protocol version Date: Mon, 11 Mar 2024 17:17:20 +0100 Message-Id: <20240311161727.14916-3-vsntk18@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240311161727.14916-1-vsntk18@gmail.com> References: <20240311161727.14916-1-vsntk18@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Joerg Roedel Save the results of the GHCB protocol negotiation into a data structure and print information about versions supported and used to the kernel log. This is useful for debugging kexec issues in SEV-ES guests down the road to quickly spot whether kexec is supported on the given host. Signed-off-by: Joerg Roedel Signed-off-by: Vasant Karasulli --- arch/x86/kernel/sev-shared.c | 33 +++++++++++++++++++++++++++++++-- arch/x86/kernel/sev.c | 8 ++++++++ 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/arch/x86/kernel/sev-shared.c b/arch/x86/kernel/sev-shared.c index 1d24ec679915..c02a087c7945 100644 --- a/arch/x86/kernel/sev-shared.c +++ b/arch/x86/kernel/sev-shared.c @@ -17,6 +17,23 @@ #define WARN(condition, format...) (!!(condition)) #endif +/* + * struct ghcb_info - Used to return GHCB protocol + * negotiation details. + * + * @hv_proto_min: Minimum GHCB protocol version supported by Hypervisor + * @hv_proto_max: Maximum GHCB protocol version supported by Hypervisor + * @vm_proto: Protocol version the VM (this kernel) will use + */ +struct ghcb_info { + unsigned int hv_proto_min; + unsigned int hv_proto_max; + unsigned int vm_proto; +}; + +/* Negotiated GHCB protocol version */ +static struct ghcb_info ghcb_info __ro_after_init; + /* I/O parameters for CPUID-related helpers */ struct cpuid_leaf { u32 fn; @@ -152,12 +169,24 @@ static bool sev_es_negotiate_protocol(void) if (GHCB_MSR_INFO(val) != GHCB_MSR_SEV_INFO_RESP) return false; - if (GHCB_MSR_PROTO_MAX(val) < GHCB_PROTOCOL_MIN || - GHCB_MSR_PROTO_MIN(val) > GHCB_PROTOCOL_MAX) + /* Sanity check untrusted input */ + if (GHCB_MSR_PROTO_MIN(val) > GHCB_MSR_PROTO_MAX(val)) return false; + /* Use maximum supported protocol version */ ghcb_version = min_t(size_t, GHCB_MSR_PROTO_MAX(val), GHCB_PROTOCOL_MAX); + /* + * Hypervisor does not support any protocol version required for this + * kernel. + */ + if (ghcb_version < GHCB_MSR_PROTO_MIN(val)) + return false; + + ghcb_info.hv_proto_min = GHCB_MSR_PROTO_MIN(val); + ghcb_info.hv_proto_max = GHCB_MSR_PROTO_MAX(val); + ghcb_info.vm_proto = ghcb_version; + return true; } diff --git a/arch/x86/kernel/sev.c b/arch/x86/kernel/sev.c index c67285824e82..179ab6eab0be 100644 --- a/arch/x86/kernel/sev.c +++ b/arch/x86/kernel/sev.c @@ -1392,6 +1392,14 @@ void __init sev_es_init_vc_handling(void) /* Secondary CPUs use the runtime #VC handler */ initial_vc_handler = (unsigned long)kernel_exc_vmm_communication; + + /* + * Print information about supported and negotiated GHCB protocol + * versions. + */ + pr_info("Hypervisor GHCB protocol version support: min=%u max=%u\n", + ghcb_info.hv_proto_min, ghcb_info.hv_proto_max); + pr_info("Using GHCB protocol version %u\n", ghcb_info.vm_proto); } static void __init vc_early_forward_exception(struct es_em_ctxt *ctxt) -- 2.34.1