From patchwork Wed Jul 31 15:07:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Nikunj A. Dadhania" X-Patchwork-Id: 13748878 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2047.outbound.protection.outlook.com [40.107.92.47]) (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 810F01BC076; Wed, 31 Jul 2024 15:08:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.92.47 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722438522; cv=fail; b=tmoHAHJJySfB1iDKuxZVOZ48o5YLoe/GtbaTc2jsi1A0/9ETMVmuOhDgsjukDzilEC1BQuuUOvcx7V6EEbGagD3e8NgrhnQK/qSlFUfhOkTmACkOvSOqhAyDKG6fn2S86XDAj0wfBa7WHrNMJvWN/UDGECLEBqwUJRZuICNJJKc= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722438522; c=relaxed/simple; bh=apqqWgOfktwH1fXodVikRqHcQoXPo7DTRsEUrrc5Pgg=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=hmcQD/PQp3YCTw2mGhG5gOhQj7pn4QmGQytuvgUKPp+GyRcshtcpQ2bvHIFDy8y5PFJjaoEbajrtOHsnDj696gal+WNgH2OvVMusZb7jTqqlhKBwXmcfB+El3xRHAD8KkyeKi3WU6xAeVDeUj05ETNNkbuAaN3T6WEELgZRkKKQ= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=O7/BqpCW; arc=fail smtp.client-ip=40.107.92.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="O7/BqpCW" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=BCB3jC0iZPbfrsq0cQ+j9PQApex2RvGF6yGh1hV2P4rvrSWIqOhUQcNlnskG9THzGxJJEl8uILjbwxwQ6OGvQLsrKc8NsQmF7YbSMYHIn0p7OMwolSJ40jl228OblxkfTkFy1dZbi3UyPjWLucOcVK61zcRpEbou4RNpoTV/vlrHbxuJzjuZvsyM4P4v7s1Rqlicru6PJYEWwuBwPoHIZ0EbJY3VhYh3iZvIvMoRL+b9cRytpNrkZ6N1iHAZTmVmaywdx6lYdNVzUqzZpR4qyyuk/AiLCcDa3kTqOn6dP9WcdYUkmvCMyMTkraNEvXwmIEuYHrQ3h8fjELPBItx6WA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=sI+KQmNa1O0s/3SQT0PxzoU7ph/iN3D5qTwcnH+7Qh0=; b=X8KvYstJdW5qqDrTG457TNFzcm+jcEdlnR7p0C6O29GX/EbB8r1sSg7R7QZ6VRZMX2q+z0iBhtD+qnKFd4MDgKicVCDltWvNXtwnBAnbw8uRSQG9oABdrpVT/CVbzSgVyB4+TPytOmwXrPwRMkwQ9QjGDcJ+pNLgD2k76be6w86eFkI3p0wgoX9VRegkPZZkGuc7Qk9vRctGr+3WPGsuiGDhrQts0Z4IBDbSnO7TN9XCGDzqHDYvug1u1MP8cCJ/hokyX0MLm9Bo2QO6WK1kN8vMuQA33oKtkKG7w2Wh0Ew4XD1VUqOAsE18FOYNXPsmKvMt0qHAiHKVVTz2vfrJgw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=sI+KQmNa1O0s/3SQT0PxzoU7ph/iN3D5qTwcnH+7Qh0=; b=O7/BqpCWZKkt5KQ+62Yu5TVR/mRN2foJncToyUIQ0eO4F19SaPIi27ZDdsGSYtl7dZ4I0n3vMlqRwP2YaBHGdOZcj6eIaXdbLu8lBJknPEtnVXeTIRp7eU2+fE5OsmQORHPFMWHbR3f/c9VN5gALjPfYN5Rrnfej8GQOD+RuNcc= Received: from CH0P223CA0020.NAMP223.PROD.OUTLOOK.COM (2603:10b6:610:116::10) by DM6PR12MB4402.namprd12.prod.outlook.com (2603:10b6:5:2a5::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7807.32; Wed, 31 Jul 2024 15:08:33 +0000 Received: from DS3PEPF0000C37B.namprd04.prod.outlook.com (2603:10b6:610:116:cafe::8f) by CH0P223CA0020.outlook.office365.com (2603:10b6:610:116::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7784.34 via Frontend Transport; Wed, 31 Jul 2024 15:08:33 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by DS3PEPF0000C37B.mail.protection.outlook.com (10.167.23.5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7828.19 via Frontend Transport; Wed, 31 Jul 2024 15:08:32 +0000 Received: from gomati.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Wed, 31 Jul 2024 10:08:28 -0500 From: Nikunj A Dadhania To: , , , , CC: , , , , , , Subject: [PATCH v11 01/20] virt: sev-guest: Replace dev_dbg with pr_debug Date: Wed, 31 Jul 2024 20:37:52 +0530 Message-ID: <20240731150811.156771-2-nikunj@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240731150811.156771-1-nikunj@amd.com> References: <20240731150811.156771-1-nikunj@amd.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS3PEPF0000C37B:EE_|DM6PR12MB4402:EE_ X-MS-Office365-Filtering-Correlation-Id: db08cde5-cf2b-49ca-e894-08dcb172a4e6 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|36860700013|7416014|376014|82310400026; X-Microsoft-Antispam-Message-Info: 3Zw6dlHh/khyurWK9U/lcw4mRLrxWjWqOWZRkAlnGD6t0S0UWR2dYe8immiyM8O0rICLUdIWvxlgA50vg9j7+jKyk/1u2ugNEPSvJiKTjIS0mvFTxAaIoh/hRpdhXHRyq2M1bGfrUTYutMl06YWEVMfYSfiIsRnIvcjDfutNdrzUCoy6qQqpnT/Jh8poNgnzuOBqt2702kSpbeOqjNCEVha5YZrtWzoiBFHm9A3m24o4W5ES23EAOVi3/lt7tSPd3nHM+WF+HMbYSJwCk0AJrMnnNRp8vieSwbnPWKiMZ6q3LrE4LPgyI3wOrsVp30NWWP2UZMtAc6KkBrVwIn7/Qkq53AJyFkl3Vp8Pcl+7gy/um1eVXlaqG/jzIpZluSyzFroAzHgaCI9n+W984X8BwjREE1w+0drcD5ikGWtTKeZczc42rmBJgbSXVt5SDL5ElUP7AUujGRsOHVYcl+BLyxLbtxfPZcRJClNCo6WEhFZHf8CHPin8VU9FYZQanNnYJhybhwJ9umO9ycbZFB5+OG1LpbCIi/9w2VFoFUU4mVRbgIebzqfPk+gODZBg09YM1Ivj4TWADz1DqnGQwiOJcjy+xa0jD2IhcOLrmjGwPgYvh6qrmFHbOj5uUvOXdILi0Z0WhPIx3zTeLaiwmUDGPIRiV3FtOAx1Rsu8DCUQzLajuJXFQIsXliMvGhbQgnPHf5nVxyLl83A/U4ObIyIG4pstjWv56SonCy9LUR+SzT8P4kGSA5nkwFRdmEpbA3uowLm0obpWu37uz9KfDE6qptwVHvp2BQD3Y7Xu5WNgAmmBZcoIqvnTKJNON6UjMsTbT5rYOQLXS1DRr1+uxqS5D07MpfptE93GHoLQDnU/UmQv/P6uejyveLtZP8g7oyLaURE2UZiWNE4hIPkx2Pf//IaXiZt8qm6BKVCfQuKfvQ9pRaX94600gpQVaRHRd7fhWBSR++nm6UwLx2OWDId/Eyy8bjH8mg4RyeCBDq9Pt3cQV1Pc/XyBLF+K2WajEOgdEU2Mcmk/R2LDV6D8Fa2LBjaJlLXVRyXWWPIV+hco2mKrGdWirZWjbowGE1AYS/QY6jfd8+yon2izieGpAHg10nBDO8PEoaaY4ryR1GfFX3S1eHAvI9/5qpT3VY5nfrJu6QdXjh2de2+kT0cs9o7RgQxCAAUJHxLWsO8tU/8LG7RuLH49eFqo/JkjOBGnERaZh36IbrIS0jQvEcAy28drjxPfoUIv2ZcA/iZiKU2WRLYua+JoLC8XEIX0G85FnS0WoMQDhceDUr9YpfSmnjSmk5CHsYuJqvpmEAKBnxtxY7hj04XCZOxkhbs1NIBlpXIBk1Zo+yyHicwRpABAiptHgRt+nfBOU+cOsGL7AM77brZTG9yHTQdiTW/T5glxdQW72DKz6uPlU2/hea90BGDg5Cl2fr31idIFV98gJ2AIHjog+I1sS6oGHICP4pILGsYP X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(1800799024)(36860700013)(7416014)(376014)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Jul 2024 15:08:32.9033 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: db08cde5-cf2b-49ca-e894-08dcb172a4e6 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: DS3PEPF0000C37B.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4402 In preparation of moving code to arch/x86/coco/sev/core.c, replace dev_dbg with pr_debug. No functional change. Signed-off-by: Nikunj A Dadhania Reviewed-by: Tom Lendacky Tested-by: Peter Gonda Reviewed-by: Borislav Petkov (AMD) --- drivers/virt/coco/sev-guest/sev-guest.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/drivers/virt/coco/sev-guest/sev-guest.c b/drivers/virt/coco/sev-guest/sev-guest.c index 6fc7884ea0a1..7d343f2c6ef8 100644 --- a/drivers/virt/coco/sev-guest/sev-guest.c +++ b/drivers/virt/coco/sev-guest/sev-guest.c @@ -296,8 +296,9 @@ static int verify_and_dec_payload(struct snp_guest_dev *snp_dev, void *payload, struct snp_guest_msg_hdr *req_hdr = &req->hdr; struct snp_guest_msg_hdr *resp_hdr = &resp->hdr; - dev_dbg(snp_dev->dev, "response [seqno %lld type %d version %d sz %d]\n", - resp_hdr->msg_seqno, resp_hdr->msg_type, resp_hdr->msg_version, resp_hdr->msg_sz); + pr_debug("response [seqno %lld type %d version %d sz %d]\n", + resp_hdr->msg_seqno, resp_hdr->msg_type, resp_hdr->msg_version, + resp_hdr->msg_sz); /* Copy response from shared memory to encrypted memory. */ memcpy(resp, snp_dev->response, sizeof(*resp)); @@ -343,8 +344,8 @@ static int enc_payload(struct snp_guest_dev *snp_dev, u64 seqno, int version, u8 if (!hdr->msg_seqno) return -ENOSR; - dev_dbg(snp_dev->dev, "request [seqno %lld type %d version %d sz %d]\n", - hdr->msg_seqno, hdr->msg_type, hdr->msg_version, hdr->msg_sz); + pr_debug("request [seqno %lld type %d version %d sz %d]\n", + hdr->msg_seqno, hdr->msg_type, hdr->msg_version, hdr->msg_sz); return __enc_payload(snp_dev, req, payload, sz); } From patchwork Wed Jul 31 15:07:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Nikunj A. Dadhania" X-Patchwork-Id: 13748879 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2059.outbound.protection.outlook.com [40.107.244.59]) (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 EE67D1642B; Wed, 31 Jul 2024 15:08:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.244.59 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722438522; cv=fail; b=goYExKAfT+vI8Kgdpum8pWQprhATlOaQOOULmydxgCxlygl1LOozjsaCk4Qgqfx2z7buZJomSY3Sj4blvcs7l3OcuECSOn15EBSBieacsoXX73tVcINU6yCGAGyyUn7Bu0Uf6xYvqafZ+/UVTjStsu91C7Cnt4658pLjclK7nCM= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722438522; c=relaxed/simple; bh=fGJ+lIY/hPW1oEwvfYo4MYfbjZXSsjIAxaWtomyqg1w=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=JFQJr5pxG/3qtsZktUMtgsr/KKhFRE+RlMN3IQNVK8Gut92sNqUD272fv0MaX49eM2+Yk9eu5eBDsqZ3YF8KAjkehuAO5vOO5hqWV4ODsKhmdjdOQ/ozK43MXxEZYY6+lJQnZ4lr96JWscvgPvIf3PXF7NHhiZ0tuqr14twxP7Q= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=AsDtIkr9; arc=fail smtp.client-ip=40.107.244.59 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="AsDtIkr9" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=q1CO7Bv8usE0J5uEfTQXJvO9K/vKJ71PODmPo5yOyOZxmfYCCxventUFdpGwpEuS/mBnfOnN9MkNe7TzkXPzyb6Ujn876oZvqiDAYMrBbKsz9uaQa0+EOgRdswhvijfJuPR2QoTbZgEilAMGLQL/Dbyxfbkm7C/Ke5JVnwGxaTAufd5znbLwfe+El5cgarEdypUS1UfMnV56yV4mhNBywRJQ3ZqJhlGfQIDr8Cd1sx/U7dHd91oESQCXRaJltvfWidTz4HRR6LKcIoom4ybsOvGP7Wq8OVLYlNJ1FI3aWviQy4XskjuTNsNkm7bsecqY8exO4wsSTPjR8wuMTcfAdQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=dDIU+dN7hmPMFZLrMG6r1pt0eQllgDBIc7Y6ee0j0y8=; b=hY6q1HZxwpcxnI8zccSqU1ZQsYwL6lz++B+M98j+5VP6dNtVIp36wVQDQz2W3qtug8dWIaOXclAG8wlvTGF2BbYLGRrBFA7cMDOVisTVv92VawhI1OhQh+/7ArGGZ6iK3kcpFqQim+BawjYwk6tOAqv/LtXDF+Kyf1Us6GIlMlY8AVL/eWp+BcX0zIfp0i+KwngH37zUOeNh1Wh7n/ialbT/yifvrT674lH+kpmfB/eX949SyDj/z+eVP8JLa5o9mwKQ/xiVT+J0rOJFZQicWqo4lJwRHTGOUFD5AHViyLKC9Q75CPWMa4H7+/M0d9T87Lq9BEXaASQm6Iiq3UX0Qg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=dDIU+dN7hmPMFZLrMG6r1pt0eQllgDBIc7Y6ee0j0y8=; b=AsDtIkr9ZUlYde3aO9jyWGSrL0H7IrNOV+DXZuYaNi5qZy94NFh5p+zVYz0DdDhQ7P3qPMW4MpMeoVRvy+Ez2YzwF2z0LqDx9d/wyWDdp1ZUdj6qlibsmoqoEYdAnyEXQ8ECv8IopJghB2Wwmw0LRb8V71dFm6dTI56G0OKjLNo= Received: from DM6PR07CA0089.namprd07.prod.outlook.com (2603:10b6:5:337::22) by MW3PR12MB4395.namprd12.prod.outlook.com (2603:10b6:303:5c::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7807.28; Wed, 31 Jul 2024 15:08:38 +0000 Received: from DS3PEPF0000C37E.namprd04.prod.outlook.com (2603:10b6:5:337:cafe::9e) by DM6PR07CA0089.outlook.office365.com (2603:10b6:5:337::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7828.21 via Frontend Transport; Wed, 31 Jul 2024 15:08:37 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by DS3PEPF0000C37E.mail.protection.outlook.com (10.167.23.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7828.19 via Frontend Transport; Wed, 31 Jul 2024 15:08:36 +0000 Received: from gomati.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Wed, 31 Jul 2024 10:08:32 -0500 From: Nikunj A Dadhania To: , , , , CC: , , , , , , Subject: [PATCH v11 02/20] virt: sev-guest: Rename local guest message variables Date: Wed, 31 Jul 2024 20:37:53 +0530 Message-ID: <20240731150811.156771-3-nikunj@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240731150811.156771-1-nikunj@amd.com> References: <20240731150811.156771-1-nikunj@amd.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS3PEPF0000C37E:EE_|MW3PR12MB4395:EE_ X-MS-Office365-Filtering-Correlation-Id: 02d48060-03b5-44b4-bc8f-08dcb172a73f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|1800799024|376014|7416014|82310400026; X-Microsoft-Antispam-Message-Info: qVoHcJJBpurQu3A3VNqSlvPpy0D0zcI+rOPSilO1vJEveCBB1R7/XkoZzxIsH3pjnamuooVED4vGpQ0MQzHLbxG2HzZ1g6Fh5ZyiQMqpRsXHECzwO84YR7xqK9zi66lbkshSDqPtkcD4TDS8oM67uXeLn4Rm6Dyfu5V/TV8+UqBdiPvKJzSf1gIk6R52CZRhPetmZx9mxxX866a4IZpF7iYQ52Z3oDn5Ne00jAPkymz4JRfKwxZClz3Qoc0vq9A3+lxrd51G+y/kXwGzCEyZe+tj8Ir5KLFAzZp7SpXXIfNfi0tldfcoLj28y3/vJMkNCU4Dpaob9xHT5YfGvFYKjEtXi6F+kgBtc8Q43eji2Za7VuI6RfmY/2IgQXNsBr0dwuyFekbx/hu7Py9xjsX14BRJThOqb7TjVxt62bClRZsDGKdI/e/iS8MkTMkz0efAuPZqgDnU8jAsEMYNT1OsW0MnchVqt1QrZq3GtuJaylkGKZgdTuIGQA7ATcyf6yJwSqmOorvqEn/P9jUX53VJOir9cR9o4+m+io69DAqzMVOf5Q0GmhSKe0Ba36uVchUKa/5gZ+SjfPW0yzrtmojoOcl+sM0FzMVaRdSY9nz4cb8nqM9hkrBhvDjkCk5N7ev9adLha19Iz1EYQsPec/c9SvQy//0i2a0oH6h8ChZxGzkXWrGAaKHqGbMb6rdZ1HWaOqNqm6hrPskZBTYoOz3A1mrU8LQj+C+aQTw8OQrfV9hkhleiHk6MMxyWYOzUseAGp+lOqeOyDHw/eY0iJi0m88vPJAtaiudWRneGK9GRNMLJRkd/WFiWOxrTvo02AkvWBJKMrKZYmnmkPAA5i9FGYyZiEv7TlWcv+Q5I0UEm2tKTIe8lJhnxg/fMVfi9q+KBlEisTtv39CUFoDtEkthvqN0mQlz7crqgbWle1l4bi93+9rn4aKSZcHuz9beh2MYY0h7gMSy8Kex0eW75NczydS0lbFPFFQXzlcPuUJEGwsqIwp+F9/O/7L/7y88vRqomKDp5+zjvPgRnLejBxUXXfKhfCFhZAmOtGyeaICFNliduuGae7H73zUmH/Vj16gwxMPmX017kz9VQZd9eIWuZUk5lbBaxaGJoH251z+VbRqWTsy9e1VngsX5MiBx2aTKt1jdlvVq1j72AH8aJbJDkpviGOntfIeDkbH64PNJ7aPVLVSfMKLgy3mNartnIEUrGshlt3FM7ffFs3MqP2MOkGHJ49jpVzPXx3SBeEWrENIGJmVmdsvsCABMUWUhWf4X8n9irX2Z5AlXqfgUXBqOx71S0yZx6LcMIwl2xCoRbSi09TcLsRpYcben2nmM0VghFPp+HTqvpCTVEYJRFxTniNgFREa/JyMhJWVCVxis/wZzL20sYKO/MNedSBbB0nhOu7SQnWIARCKGN54//OED0jnsY0NPDcqBf14ll8aYEM9CUVFUVf2pa4yVqNtMxYlSr X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(36860700013)(1800799024)(376014)(7416014)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Jul 2024 15:08:36.9034 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 02d48060-03b5-44b4-bc8f-08dcb172a73f X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: DS3PEPF0000C37E.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW3PR12MB4395 Rename local guest message variables for more clarity No functional change. Signed-off-by: Nikunj A Dadhania Reviewed-by: Tom Lendacky --- drivers/virt/coco/sev-guest/sev-guest.c | 117 ++++++++++++------------ 1 file changed, 59 insertions(+), 58 deletions(-) diff --git a/drivers/virt/coco/sev-guest/sev-guest.c b/drivers/virt/coco/sev-guest/sev-guest.c index 7d343f2c6ef8..a72fe1e959c2 100644 --- a/drivers/virt/coco/sev-guest/sev-guest.c +++ b/drivers/virt/coco/sev-guest/sev-guest.c @@ -291,45 +291,45 @@ static int dec_payload(struct snp_guest_dev *snp_dev, struct snp_guest_msg *msg, static int verify_and_dec_payload(struct snp_guest_dev *snp_dev, void *payload, u32 sz) { struct snp_guest_crypto *crypto = snp_dev->crypto; - struct snp_guest_msg *resp = &snp_dev->secret_response; - struct snp_guest_msg *req = &snp_dev->secret_request; - struct snp_guest_msg_hdr *req_hdr = &req->hdr; - struct snp_guest_msg_hdr *resp_hdr = &resp->hdr; + struct snp_guest_msg *resp_msg = &snp_dev->secret_response; + struct snp_guest_msg *req_msg = &snp_dev->secret_request; + struct snp_guest_msg_hdr *req_msg_hdr = &req_msg->hdr; + struct snp_guest_msg_hdr *resp_msg_hdr = &resp_msg->hdr; pr_debug("response [seqno %lld type %d version %d sz %d]\n", - resp_hdr->msg_seqno, resp_hdr->msg_type, resp_hdr->msg_version, - resp_hdr->msg_sz); + resp_msg_hdr->msg_seqno, resp_msg_hdr->msg_type, resp_msg_hdr->msg_version, + resp_msg_hdr->msg_sz); /* Copy response from shared memory to encrypted memory. */ - memcpy(resp, snp_dev->response, sizeof(*resp)); + memcpy(resp_msg, snp_dev->response, sizeof(*resp_msg)); /* Verify that the sequence counter is incremented by 1 */ - if (unlikely(resp_hdr->msg_seqno != (req_hdr->msg_seqno + 1))) + if (unlikely(resp_msg_hdr->msg_seqno != (req_msg_hdr->msg_seqno + 1))) return -EBADMSG; /* Verify response message type and version number. */ - if (resp_hdr->msg_type != (req_hdr->msg_type + 1) || - resp_hdr->msg_version != req_hdr->msg_version) + if (resp_msg_hdr->msg_type != (req_msg_hdr->msg_type + 1) || + resp_msg_hdr->msg_version != req_msg_hdr->msg_version) return -EBADMSG; /* * If the message size is greater than our buffer length then return * an error. */ - if (unlikely((resp_hdr->msg_sz + crypto->a_len) > sz)) + if (unlikely((resp_msg_hdr->msg_sz + crypto->a_len) > sz)) return -EBADMSG; /* Decrypt the payload */ - return dec_payload(snp_dev, resp, payload, resp_hdr->msg_sz + crypto->a_len); + return dec_payload(snp_dev, resp_msg, payload, resp_msg_hdr->msg_sz + crypto->a_len); } static int enc_payload(struct snp_guest_dev *snp_dev, u64 seqno, int version, u8 type, void *payload, size_t sz) { - struct snp_guest_msg *req = &snp_dev->secret_request; - struct snp_guest_msg_hdr *hdr = &req->hdr; + struct snp_guest_msg *msg = &snp_dev->secret_request; + struct snp_guest_msg_hdr *hdr = &msg->hdr; - memset(req, 0, sizeof(*req)); + memset(msg, 0, sizeof(*msg)); hdr->algo = SNP_AEAD_AES_256_GCM; hdr->hdr_version = MSG_HDR_VER; @@ -347,7 +347,7 @@ static int enc_payload(struct snp_guest_dev *snp_dev, u64 seqno, int version, u8 pr_debug("request [seqno %lld type %d version %d sz %d]\n", hdr->msg_seqno, hdr->msg_type, hdr->msg_version, hdr->msg_sz); - return __enc_payload(snp_dev, req, payload, sz); + return __enc_payload(snp_dev, msg, payload, sz); } static int __handle_guest_request(struct snp_guest_dev *snp_dev, u64 exit_code, @@ -496,8 +496,8 @@ struct snp_req_resp { static int get_report(struct snp_guest_dev *snp_dev, struct snp_guest_request_ioctl *arg) { struct snp_guest_crypto *crypto = snp_dev->crypto; - struct snp_report_req *req = &snp_dev->req.report; - struct snp_report_resp *resp; + struct snp_report_req *report_req = &snp_dev->req.report; + struct snp_report_resp *report_resp; int rc, resp_len; lockdep_assert_held(&snp_cmd_mutex); @@ -505,7 +505,7 @@ static int get_report(struct snp_guest_dev *snp_dev, struct snp_guest_request_io if (!arg->req_data || !arg->resp_data) return -EINVAL; - if (copy_from_user(req, (void __user *)arg->req_data, sizeof(*req))) + if (copy_from_user(report_req, (void __user *)arg->req_data, sizeof(*report_req))) return -EFAULT; /* @@ -513,30 +513,29 @@ static int get_report(struct snp_guest_dev *snp_dev, struct snp_guest_request_io * response payload. Make sure that it has enough space to cover the * authtag. */ - resp_len = sizeof(resp->data) + crypto->a_len; - resp = kzalloc(resp_len, GFP_KERNEL_ACCOUNT); - if (!resp) + resp_len = sizeof(report_resp->data) + crypto->a_len; + report_resp = kzalloc(resp_len, GFP_KERNEL_ACCOUNT); + if (!report_resp) return -ENOMEM; - rc = handle_guest_request(snp_dev, SVM_VMGEXIT_GUEST_REQUEST, arg, - SNP_MSG_REPORT_REQ, req, sizeof(*req), resp->data, - resp_len); + rc = handle_guest_request(snp_dev, SVM_VMGEXIT_GUEST_REQUEST, arg, SNP_MSG_REPORT_REQ, + report_req, sizeof(*report_req), report_resp->data, resp_len); if (rc) goto e_free; - if (copy_to_user((void __user *)arg->resp_data, resp, sizeof(*resp))) + if (copy_to_user((void __user *)arg->resp_data, report_resp, sizeof(*report_resp))) rc = -EFAULT; e_free: - kfree(resp); + kfree(report_resp); return rc; } static int get_derived_key(struct snp_guest_dev *snp_dev, struct snp_guest_request_ioctl *arg) { - struct snp_derived_key_req *req = &snp_dev->req.derived_key; + struct snp_derived_key_req *derived_key_req = &snp_dev->req.derived_key; struct snp_guest_crypto *crypto = snp_dev->crypto; - struct snp_derived_key_resp resp = {0}; + struct snp_derived_key_resp derived_key_resp = {0}; int rc, resp_len; /* Response data is 64 bytes and max authsize for GCM is 16 bytes. */ u8 buf[64 + 16]; @@ -551,25 +550,27 @@ static int get_derived_key(struct snp_guest_dev *snp_dev, struct snp_guest_reque * response payload. Make sure that it has enough space to cover the * authtag. */ - resp_len = sizeof(resp.data) + crypto->a_len; + resp_len = sizeof(derived_key_resp.data) + crypto->a_len; if (sizeof(buf) < resp_len) return -ENOMEM; - if (copy_from_user(req, (void __user *)arg->req_data, sizeof(*req))) + if (copy_from_user(derived_key_req, (void __user *)arg->req_data, + sizeof(*derived_key_req))) return -EFAULT; - rc = handle_guest_request(snp_dev, SVM_VMGEXIT_GUEST_REQUEST, arg, - SNP_MSG_KEY_REQ, req, sizeof(*req), buf, resp_len); + rc = handle_guest_request(snp_dev, SVM_VMGEXIT_GUEST_REQUEST, arg, SNP_MSG_KEY_REQ, + derived_key_req, sizeof(*derived_key_req), buf, resp_len); if (rc) return rc; - memcpy(resp.data, buf, sizeof(resp.data)); - if (copy_to_user((void __user *)arg->resp_data, &resp, sizeof(resp))) + memcpy(derived_key_resp.data, buf, sizeof(derived_key_resp.data)); + if (copy_to_user((void __user *)arg->resp_data, &derived_key_resp, + sizeof(derived_key_resp))) rc = -EFAULT; /* The response buffer contains the sensitive data, explicitly clear it. */ memzero_explicit(buf, sizeof(buf)); - memzero_explicit(&resp, sizeof(resp)); + memzero_explicit(&derived_key_resp, sizeof(derived_key_resp)); return rc; } @@ -577,9 +578,9 @@ static int get_ext_report(struct snp_guest_dev *snp_dev, struct snp_guest_reques struct snp_req_resp *io) { - struct snp_ext_report_req *req = &snp_dev->req.ext_report; + struct snp_ext_report_req *report_req = &snp_dev->req.ext_report; struct snp_guest_crypto *crypto = snp_dev->crypto; - struct snp_report_resp *resp; + struct snp_report_resp *report_resp; int ret, npages = 0, resp_len; sockptr_t certs_address; @@ -588,22 +589,22 @@ static int get_ext_report(struct snp_guest_dev *snp_dev, struct snp_guest_reques if (sockptr_is_null(io->req_data) || sockptr_is_null(io->resp_data)) return -EINVAL; - if (copy_from_sockptr(req, io->req_data, sizeof(*req))) + if (copy_from_sockptr(report_req, io->req_data, sizeof(*report_req))) return -EFAULT; /* caller does not want certificate data */ - if (!req->certs_len || !req->certs_address) + if (!report_req->certs_len || !report_req->certs_address) goto cmd; - if (req->certs_len > SEV_FW_BLOB_MAX_SIZE || - !IS_ALIGNED(req->certs_len, PAGE_SIZE)) + if (report_req->certs_len > SEV_FW_BLOB_MAX_SIZE || + !IS_ALIGNED(report_req->certs_len, PAGE_SIZE)) return -EINVAL; if (sockptr_is_kernel(io->resp_data)) { - certs_address = KERNEL_SOCKPTR((void *)req->certs_address); + certs_address = KERNEL_SOCKPTR((void *)report_req->certs_address); } else { - certs_address = USER_SOCKPTR((void __user *)req->certs_address); - if (!access_ok(certs_address.user, req->certs_len)) + certs_address = USER_SOCKPTR((void __user *)report_req->certs_address); + if (!access_ok(certs_address.user, report_req->certs_len)) return -EFAULT; } @@ -613,45 +614,45 @@ static int get_ext_report(struct snp_guest_dev *snp_dev, struct snp_guest_reques * the host. If host does not supply any certs in it, then copy * zeros to indicate that certificate data was not provided. */ - memset(snp_dev->certs_data, 0, req->certs_len); - npages = req->certs_len >> PAGE_SHIFT; + memset(snp_dev->certs_data, 0, report_req->certs_len); + npages = report_req->certs_len >> PAGE_SHIFT; cmd: /* * The intermediate response buffer is used while decrypting the * response payload. Make sure that it has enough space to cover the * authtag. */ - resp_len = sizeof(resp->data) + crypto->a_len; - resp = kzalloc(resp_len, GFP_KERNEL_ACCOUNT); - if (!resp) + resp_len = sizeof(report_resp->data) + crypto->a_len; + report_resp = kzalloc(resp_len, GFP_KERNEL_ACCOUNT); + if (!report_resp) return -ENOMEM; snp_dev->input.data_npages = npages; - ret = handle_guest_request(snp_dev, SVM_VMGEXIT_EXT_GUEST_REQUEST, arg, - SNP_MSG_REPORT_REQ, &req->data, - sizeof(req->data), resp->data, resp_len); + ret = handle_guest_request(snp_dev, SVM_VMGEXIT_EXT_GUEST_REQUEST, arg, SNP_MSG_REPORT_REQ, + &report_req->data, sizeof(report_req->data), + report_resp->data, resp_len); /* If certs length is invalid then copy the returned length */ if (arg->vmm_error == SNP_GUEST_VMM_ERR_INVALID_LEN) { - req->certs_len = snp_dev->input.data_npages << PAGE_SHIFT; + report_req->certs_len = snp_dev->input.data_npages << PAGE_SHIFT; - if (copy_to_sockptr(io->req_data, req, sizeof(*req))) + if (copy_to_sockptr(io->req_data, report_req, sizeof(*report_req))) ret = -EFAULT; } if (ret) goto e_free; - if (npages && copy_to_sockptr(certs_address, snp_dev->certs_data, req->certs_len)) { + if (npages && copy_to_sockptr(certs_address, snp_dev->certs_data, report_req->certs_len)) { ret = -EFAULT; goto e_free; } - if (copy_to_sockptr(io->resp_data, resp, sizeof(*resp))) + if (copy_to_sockptr(io->resp_data, report_resp, sizeof(*report_resp))) ret = -EFAULT; e_free: - kfree(resp); + kfree(report_resp); return ret; } From patchwork Wed Jul 31 15:07:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Nikunj A. Dadhania" X-Patchwork-Id: 13748880 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2053.outbound.protection.outlook.com [40.107.237.53]) (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 B503F1BD01E; Wed, 31 Jul 2024 15:08:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.237.53 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722438526; cv=fail; b=TL0813cFnXJfprsdERO+IbvM+s2b1fK4rgeqF8ypFac9rDvKttm9py9q/Nzhol7M4aQtWmWsx1t6JzwRPEgUQ4TtdCTeP7Tx64zAwrEvE4nljwhywWOZDHUlAFSd8JjGqJmkqmpFISwgWtRzM9UpCWxJwxtBSlNnPa2oVZPdlQA= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722438526; c=relaxed/simple; bh=RJrrpH7n82L3nqgu4KAK9RvKxu/5yEN1FvsgCaBTYKg=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=UXAzKf5dxox9eObaiM8Kzz8kMbLBV55bu3a7n351kJX+I3JEkx0cymYClm5xwCIaSETy/OoO4eqAwsExSWNBZ0KYnLpMcdDXoomQBsa0zXCuP4FeNMNl80ltcFQPhjBNUI8npOHIBKxYJPNlCpJopQtG4J66QRC/DzyrFPwyEbA= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=3NzVs+8e; arc=fail smtp.client-ip=40.107.237.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="3NzVs+8e" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Yhkoy0H/9nM68JnuzfpXxAsTVsjYnaFPoLCM4bbm9pAkvw5eadCuLePYvkcnvlOxG8Uu1yeWMtXA7HRHfkQdueim1xr6SXAF9aGdfGJHqz3ZuSzbbglk2xIHwSnl/9msYEyyNj+gDqpy6FiX9GAUR2kqFNfxnzYrBIPivjVMey0E1HDaNNOgULpz5NRrMkwgDnu3yaci+bmjsie+ijlAoU5xfOEKq97cyLdY9vmPS+6PbS2cgPDDLnoaowjaaGmMoAGngCKYW0Cbg5zBtcZXNX31fCWXocLIaFYCYJLGvxHN6W4s+MatuOZ13OZ0YdQzU/ohI0ITsM2U1YZImtlAvA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=WkZGq3bai46ckmEgSN33AjEVuSTC3teGhxVXz8ILwHA=; b=UUp78RtVe7b/d1+Q64pK4u+E5RrNRJTSfQOCQrLfPbYf2tpw66QFCGQDvY/r896iTfgzTzYjxdkQLC3RJvidSaHy0Z94K8Qe889OyvTrmmdFNRkTpgXfy9oem9Fu9jnWT9I58qLORaoZvTrWiO7Fd6e9QpwyBNi7vTgw/N24K2QQbF17s0gl5CPUfg8y5CDjLb2urJAt/TnkdTgahhSQzmXqbz22rmevP6Vozu5qZibtLX9AJsYadUF137fYZ8VyIxqXjtHZHdnUjAXpHbWNS67mOKeHg6r+3M6b2wieFQKvT7lfs7ttU+pRnh+aNjdPdefDefF8BOEy+fPc/WceKw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=WkZGq3bai46ckmEgSN33AjEVuSTC3teGhxVXz8ILwHA=; b=3NzVs+8euH9ydtD1j2a61ZZ1FJOlQorcsh3rAWQbFkCZwFtr4d4H20sbJ9WEWAldduUQ28N+O7nAQVPamLScNeoSS3yWm2FJrN3TpljGJSflsJihqIBbiExNU4Hpzrj69G9eIeeCqU6+bYj5RL4rgGkjo3V4+sfAg5tnhAijELc= Received: from DM6PR07CA0080.namprd07.prod.outlook.com (2603:10b6:5:337::13) by DS0PR12MB7876.namprd12.prod.outlook.com (2603:10b6:8:148::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7828.22; Wed, 31 Jul 2024 15:08:40 +0000 Received: from DS3PEPF0000C37E.namprd04.prod.outlook.com (2603:10b6:5:337:cafe::ee) by DM6PR07CA0080.outlook.office365.com (2603:10b6:5:337::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7784.34 via Frontend Transport; Wed, 31 Jul 2024 15:08:40 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by DS3PEPF0000C37E.mail.protection.outlook.com (10.167.23.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7828.19 via Frontend Transport; Wed, 31 Jul 2024 15:08:40 +0000 Received: from gomati.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Wed, 31 Jul 2024 10:08:36 -0500 From: Nikunj A Dadhania To: , , , , CC: , , , , , , Subject: [PATCH v11 03/20] virt: sev-guest: Fix user-visible strings Date: Wed, 31 Jul 2024 20:37:54 +0530 Message-ID: <20240731150811.156771-4-nikunj@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240731150811.156771-1-nikunj@amd.com> References: <20240731150811.156771-1-nikunj@amd.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS3PEPF0000C37E:EE_|DS0PR12MB7876:EE_ X-MS-Office365-Filtering-Correlation-Id: a553b994-5b4e-404f-53f1-08dcb172a97e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|36860700013|7416014|82310400026|376014; X-Microsoft-Antispam-Message-Info: GRzzbUBm/hmY4J5jz1XKeiFMqfTUV4GFD43MNopT1LI5q1tpdF2sQdFlzObimyc208EBoYPKvRFsNqeqTjUdbanyQNnkcT78KL/WKrHum1DnL648bBkzomChti0y5mRwAZKKmK2VDai1mGsh1zagSamnKyXPGtIeGC6Fr084dPveBXJTyx7IZ5z1rbNcu2QDMUhvsuUPT+MqbMGOqsSFr0HWr42BaMb1oHHx2Zyu/FKgZuqKzbQH8J/FPyoFAe7Ru5x7V8SrVkaztRJr1DwcRn6P7oszLulhYsJgVqjaM4yJaNsi1mSXG5wCKMoX0R7Z2OjLleh9fn8wEJB0dXiy9zgon7wBqU/A2rDGXk+Seoi2RzOJBu3VwBEjIPX/RyjsiS4wiG038nPgYesJ4s5EuswtXymMWbsXbpxRC+y0CWDrArO3EeoG/QI8pwK/GJZ3e0rlf1J544w1UqJ6ERe858qZWRvdRscG9Mjc7As92WkJd8UzJPf0TegBFNx8BnTRIGn8fr/vHwvJ3gaAjCNE72eQLaMm9w0lMSL+qvFsfsQXJFtEiVXAy5lbgGoZpmXcEz0COOo9YisT1JyYmu/PjmgtY/m5QC/7NkQpBsdrCH8ODcJJwoPkP6bP3wUHuhx9r45uNsb7jNOPhG+rqjSv5zLmBmEjz057zlNx7+z/8H80bmoWQDM+03BQ7FkaD6ZYWwUyV4hUveouS6S22Z6cbpPt4sLaBUULRsie4dP2lJwgpdZ3EXEHpRROc8lrv5Q+3BvqheRXF8QIXY0OHxnzLMxNjekMq9BMNQw+5tjLOx/yGOa9KoVibBp5wgdcY0M9ResrC5w56cEhC9p2KKzyE+OVpf8Zr7tkOB60T6vSaM8QqHwk7oBh8FR7WiDn130utLmr2Td7H7BfczuW9g1r83wN6M4L9zunmBKBCslGg+vaTafcyd+sRJJ0k3WXHRFPB6DE+WUgM60IKwz+9xaTOgnh1JDj8UsLT4tCqOmb3+EMbgc5PL3svQDXWriMQ4WPkFFAWuOk0K7Z+XxegdknKcmxnyXiD4HN/VQVD3gC3XXvx/CEeZBJWdFQo34ANAeoHuLcM7Q6dKwZRGfpO0xRs0VDBH0pxuT7LnABeXKW2eUDcHk1eCkFKBPiI+PLWTRe7FwwCsECy56fHidro4PZDjo2wSebBalK+rmCvsrpeSV/WpuL7oNxEsX6XVg4YsABnnIkwAx+rHkbgDHcbMaTzYBWtlqy+/ID9qN484/QsO26z/7laiKJ+7eexc2rpKhLKFa8aFs42hlVjUzHp4JTi+XY/LcrYbfI1hPYoUw48Yc/hMtS2CCSsg3mjjtdX5UpwoG47WktxUH/CCIb417E2EXdfkrO2+fGBgs+J4uDu3LCyaKYbf3MeEd+cN0e5gOZmLtMbDdAQJoLGPm89CDVEiFfAgJBLeVoY6h5EoSReCQ1fmMW89DMWl/CwXPWpSdX X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(1800799024)(36860700013)(7416014)(82310400026)(376014);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Jul 2024 15:08:40.6690 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a553b994-5b4e-404f-53f1-08dcb172a97e X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: DS3PEPF0000C37E.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB7876 User-visible abbreviations should be in capitals, ensure messages are readable and clear. No functional change. Signed-off-by: Nikunj A Dadhania Reviewed-by: Tom Lendacky --- drivers/virt/coco/sev-guest/sev-guest.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/virt/coco/sev-guest/sev-guest.c b/drivers/virt/coco/sev-guest/sev-guest.c index a72fe1e959c2..3b76cbf78f41 100644 --- a/drivers/virt/coco/sev-guest/sev-guest.c +++ b/drivers/virt/coco/sev-guest/sev-guest.c @@ -114,7 +114,7 @@ static bool is_vmpck_empty(struct snp_guest_dev *snp_dev) */ static void snp_disable_vmpck(struct snp_guest_dev *snp_dev) { - dev_alert(snp_dev->dev, "Disabling vmpck_id %d to prevent IV reuse.\n", + dev_alert(snp_dev->dev, "Disabling VMPCK%d communication key to prevent IV reuse.\n", vmpck_id); memzero_explicit(snp_dev->vmpck, VMPCK_KEY_LEN); snp_dev->vmpck = NULL; @@ -1117,13 +1117,13 @@ static int __init sev_guest_probe(struct platform_device *pdev) ret = -EINVAL; snp_dev->vmpck = get_vmpck(vmpck_id, secrets, &snp_dev->os_area_msg_seqno); if (!snp_dev->vmpck) { - dev_err(dev, "invalid vmpck id %d\n", vmpck_id); + dev_err(dev, "Invalid VMPCK%d communication key\n", vmpck_id); goto e_unmap; } /* Verify that VMPCK is not zero. */ if (is_vmpck_empty(snp_dev)) { - dev_err(dev, "vmpck id %d is null\n", vmpck_id); + dev_err(dev, "Empty VMPCK%d communication key\n", vmpck_id); goto e_unmap; } @@ -1174,7 +1174,7 @@ static int __init sev_guest_probe(struct platform_device *pdev) if (ret) goto e_free_cert_data; - dev_info(dev, "Initialized SEV guest driver (using vmpck_id %d)\n", vmpck_id); + dev_info(dev, "Initialized SEV guest driver (using VMPCK%d communication key)\n", vmpck_id); return 0; e_free_cert_data: From patchwork Wed Jul 31 15:07:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Nikunj A. Dadhania" X-Patchwork-Id: 13748881 Received: from NAM04-BN8-obe.outbound.protection.outlook.com (mail-bn8nam04on2079.outbound.protection.outlook.com [40.107.100.79]) (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 D9A951BD4E9; Wed, 31 Jul 2024 15:08:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.100.79 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722438529; cv=fail; b=pePGKBA3xvry3UNuCDbvAXSXeor2kWrFQeeK83sZ35ISTzIGgDXm8ypxLJBIaqmNAWudTgc+pT3xOTNTJTBY5ZFRQqp+rKrIen2+OC5HGFtEg7oxTtJjrdffnlZZhj8Vl83d5Nl5KtLeDmvCQwRQZJakLgQoJ0v2Y2q/PMFni2M= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722438529; c=relaxed/simple; bh=Mmvg97okGCyiJtHTPCEbYYo70LTO+mCOglmOhzElZoM=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ZKMQiGd/ZSx3wXzx9iYss3iuvan/Bltp8dIaiGPEcOJWA12eKqZvtIoWiL2VnJbYE4Q+Me7SuxAZe8ThrR6TxuGgYCEIFGtnlySgggACBKTn/kZ0EhXPSnPFSw05fC7Ss4ALjkmQBpRNyrMdNcXgCZNg4jk0cNCGU/8jyKWJbYI= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=sWsm8Ek8; arc=fail smtp.client-ip=40.107.100.79 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="sWsm8Ek8" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=P/3jPH9KW3qmya2IAbUk4ROcwHP+MD/y712Vk0krcDCRcSj166kftYgo3zyEw1sqHGLV/TI+ELMt2113C0lN+vpcmEICOhinVXh5LUeocTtw2DAXSikUNWhGOnC905VOr4VeJU42mNYTIcPwjClBsEg+GVd5RqItsjPkuS+amIg9wz1Tbkzal3ohLdc3nXXYVH9/4uth1ciOOSw0Bvi7CFdJzQ2YEEpzeJx9UpgSJ0yGsuITDs72h6tgPGVSgevsGocZv64l9rr+6dDxbqQgyD2iD7m4+DTnv8uPycdwq5leWhiuuEurXAgZT5Ao+rWvgudbT6+TJkSJwv0tVYU6jQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=FbjWWUGOuINJ9pQgi9EEriHDcboXIVDNMMGrDh8DLoc=; b=XM18sQbJsBee2C3jcetBUyRP0RO83AipIx6nupoHGVfU+PAORMR6FVLdngiAESBnvXBZpz06lDMghv6h8NiYWYFrz+JC1rDlY24qLwR4CN3w4drn57aK6YfYrarahTQ9go7fp8xtp9MFHj68jR0pf7z3bBEEf0Z1JYqUZcysoP8lK05OTosf2Kj1k1sP9BFHUif49zqAHlrjx7cLdQ2M8brlyxdUWJddmdd9LHZY6VazReh2lv5yuFJki012Zoey7mE45gfSlTHbZYg0mDqm65/c7UuSyqN+M5JY57hkmVzZDsT+XuxU+su1FhBid1XSUg1n9cfaWenkW/bruUZjHg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=FbjWWUGOuINJ9pQgi9EEriHDcboXIVDNMMGrDh8DLoc=; b=sWsm8Ek8GFohpOcBxT9xWA42L+jmhuxM1bhoqVoU0JgQ7NdqTDjVA/GrumU0hMRkiNqVB5yhJ/mJ1g+3uvKOOSJ0qQVnuarh7RKb1ZeyfqFmkOkZo1YFIKF9Ho9MPozCuhESq3oUklo9XNUnxSQ9PLhYeC4rTPbruE5MYuzhB7o= Received: from DM6PR07CA0091.namprd07.prod.outlook.com (2603:10b6:5:337::24) by IA1PR12MB8406.namprd12.prod.outlook.com (2603:10b6:208:3da::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7828.22; Wed, 31 Jul 2024 15:08:44 +0000 Received: from DS3PEPF0000C37E.namprd04.prod.outlook.com (2603:10b6:5:337:cafe::81) by DM6PR07CA0091.outlook.office365.com (2603:10b6:5:337::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7784.35 via Frontend Transport; Wed, 31 Jul 2024 15:08:44 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by DS3PEPF0000C37E.mail.protection.outlook.com (10.167.23.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7828.19 via Frontend Transport; Wed, 31 Jul 2024 15:08:44 +0000 Received: from gomati.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Wed, 31 Jul 2024 10:08:40 -0500 From: Nikunj A Dadhania To: , , , , CC: , , , , , , Subject: [PATCH v11 04/20] virt: sev-guest: Ensure the SNP guest messages do not exceed a page Date: Wed, 31 Jul 2024 20:37:55 +0530 Message-ID: <20240731150811.156771-5-nikunj@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240731150811.156771-1-nikunj@amd.com> References: <20240731150811.156771-1-nikunj@amd.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS3PEPF0000C37E:EE_|IA1PR12MB8406:EE_ X-MS-Office365-Filtering-Correlation-Id: 62bc6c1f-b0a0-4a9c-9d4a-08dcb172abae X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|36860700013|7416014|82310400026|376014; X-Microsoft-Antispam-Message-Info: rZBbNmNB3tbbfs9s0wyAIfbgwxp5rqPKhqneedSuxZnVQ21tNZL12O4mi72Pk00CGzwQ5CsyEbnFho4flOP9s6Bi3vwsJAyxVQQTHjFALvm0jvKkQlnCGw3wY2OJhkXG78AtVdL2j6riv4BjNfzje3dL5jZMrxOcyNyL9ySFLG0zD8fPtFXzJ3cO6eZeqKpfUY1j2hp0/lNUeEhKe4+4B6GWT+7qo/9bHHnLm8yK6eumNrluLgGDilE+oJ4PmqpguWHVl/AIg4acVDvHgxPuW7U7qFC9A3Vbm2NCRNaVxmc9AQAPoTnImRmEADuop60LFItnB9X3B8V8TugArMwnAN2e0JsV9AOx5WWY4RrMzjYQSRTamb5Wk3Gl+TZ0qZBQpHPbB1S5senXQ1piIMzx0b0QVYUHeRk1+4w7EYBJH3Gd/JIZMbV9N6xJrGC3C6CV5NEeMtou5GjEdpx+lFi3mNNoLp4whtFf4jb4HFYimXUUgtMK/x56mR3ZzexeL4Acxk7Up7hWRNYYAp1TSDUnIJuyK6bh5bkuysgLfggm92RKSesWO5w00FReFEXxhE8vRbm6B2kEpmJqnoJwkNUBpvNZ4HEFVOcEchlEhn0JHRlYOIGc4kB5rUro5jds976/t/FttQvxXAMu11nIHZyoJ3Wj0eVkJBYl6/TeXRBdOnfoqtj4fGRKxnhudYL/fT1/jNH2OB+4xO/73HjxumZQBo54n3aRwU7+WQj9BOsGsQnwso8nD0CZoggatllSsykvrNCJdFyqHrrpdaRnTchxS+qF0ZUOcsf2kzkaBFFPqzJszANwyvUv4IKQXsytbVNM1Ua6iLWAYqHGrCql9rQa424vN7PVsTxHaCL0uZLRzn6qg1GdUfVzmAp/AjM+bvC1PywBWlj1ckwJjAJaqJYT7/SlzloK9LbuIMKaTfsqK8ujCfmERW6iYXSyGTqTu3q0B/r/tcFDgnbEaSjtA43593HXVVf7emY+0T5MFvN/83N6NooLO1OeVyEIyXtYW6ynyAX2z3qYVIWb7simAoH53dAkOI3QropOLPqRlIUhkvgLQgdqB1m6Y+2cQknwDkVHXuF80HCsVA2Ps6lnhlDCdDLtl60GjrM+puWsvwgfcBYbQvxuAwGmMMmPKFJ/Imu9UZPxmygcUovXji7ndqxVPyjq/QTYiVohxaRQIGNokOERRcxEOL7ZZMmEESWMadoiAKMrxFev0+2moa6CpWOqTe43oY8q0bquJ4PYe61Kaimwy4Uj3jx8NRdXQZsYRwApcXolJkJMv0x0fC2mwtHbsyIOOZiD5KazZgGVEVhMcCo5lLZk91sMUA+gaeumvc9MaJM383TcXCJiT1qvX87KsGXra2CmL6ZS4QJoW6qPHo6PW7NouqABtPoplyD707s/c1S5smAYuNKz4ZpcTtjZkJzqPZ3CmC1I6HDjgUoYbV/hZ2xF8JYr7ctI1RdLCHr8 X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(1800799024)(36860700013)(7416014)(82310400026)(376014);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Jul 2024 15:08:44.3409 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 62bc6c1f-b0a0-4a9c-9d4a-08dcb172abae X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: DS3PEPF0000C37E.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB8406 Currently, snp_guest_msg includes a message header (96 bytes) and a payload (4000 bytes). There is an implicit assumption here that the SNP message header will always be 96 bytes, and with that assumption the payload array size has been set to 4000 bytes magic number. If any new member is added to the SNP message header, the SNP guest message will span more than a page. Instead of using magic number '4000' for the payload, declare the snp_guest_msg in a way that payload plus the message header do not exceed a page. Signed-off-by: Nikunj A Dadhania Suggested-by: Tom Lendacky Acked-by: Borislav Petkov (AMD) --- arch/x86/include/asm/sev.h | 2 +- drivers/virt/coco/sev-guest/sev-guest.c | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/arch/x86/include/asm/sev.h b/arch/x86/include/asm/sev.h index 79bbe2be900e..ee34ab00a8d6 100644 --- a/arch/x86/include/asm/sev.h +++ b/arch/x86/include/asm/sev.h @@ -164,7 +164,7 @@ struct snp_guest_msg_hdr { struct snp_guest_msg { struct snp_guest_msg_hdr hdr; - u8 payload[4000]; + u8 payload[PAGE_SIZE - sizeof(struct snp_guest_msg_hdr)]; } __packed; struct sev_guest_platform_data { diff --git a/drivers/virt/coco/sev-guest/sev-guest.c b/drivers/virt/coco/sev-guest/sev-guest.c index 3b76cbf78f41..0b950069bfcb 100644 --- a/drivers/virt/coco/sev-guest/sev-guest.c +++ b/drivers/virt/coco/sev-guest/sev-guest.c @@ -1131,6 +1131,9 @@ static int __init sev_guest_probe(struct platform_device *pdev) snp_dev->dev = dev; snp_dev->secrets = secrets; + /* Ensure SNP guest messages do not span more than a page */ + BUILD_BUG_ON(sizeof(struct snp_guest_msg) > PAGE_SIZE); + /* Allocate the shared page used for the request and response message. */ snp_dev->request = alloc_shared_pages(dev, sizeof(struct snp_guest_msg)); if (!snp_dev->request) From patchwork Wed Jul 31 15:07:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Nikunj A. Dadhania" X-Patchwork-Id: 13748882 Received: from NAM02-SN1-obe.outbound.protection.outlook.com (mail-sn1nam02on2075.outbound.protection.outlook.com [40.107.96.75]) (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 52B561BD51F; Wed, 31 Jul 2024 15:08:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.96.75 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722438534; cv=fail; b=NEi3g2GDW3U9sVnaUe5Jz7d/Tu0iylbRdKuWIFyJF+fdJ+1LNwLA7imnJ2yu0rEevK7+H7alXpSRvqA2optRavJOkoUfo1v6qSxc7YOGjtkuMhY0rcVG+fe+BBH7Ek9LbHLxCt6BsOR3ezZ9t66YbeHBPkeKypr8REnPjgocHtw= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722438534; c=relaxed/simple; bh=X/c1tU5wseIly3dd2hxCEg7kJ1dXU797cKl/muit0So=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=bUJ03evT8k6vGvqi7XTHq0/hbpV4aftFV+HA4WzmVcl1WxLRuQIMiX00vhyHRf/CgwUEMAewHbUxrb7I9owni59yyfzgPt61VwZ/t52u/5Fi2zxfXS+b+6Qekr8IcVJ2c4E74KcqU/4Lff1pDV3WKWqUe8T7K6jnN7z8kpfk0uk= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=vTWzSGQY; arc=fail smtp.client-ip=40.107.96.75 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="vTWzSGQY" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Rehv2G1NDUFvCGHKzY8T3K00tjYaml23eTtYg+Fm2aTNDdnNMScosGQ6MG35zLMJaBUrma9DLc3TbxmIdqvvI4z5jwAKR7V9YfCtvfL+QYNMu6H9szy/pkBWIcdBlbMP6/MbA8+g5BIfa/vZKrxK1xZ7CnqiDLPfYYwFa9CMiSTEka0HIra/bxktdc2IhGVPWMrXyCwwRGx1JY5Rc9fX1XSeztiIfxPCt2eJoMTEjdac1ie4dKbfffvf9g7F+CWV99Cb32R6juclZRU3eTglNLsxuvnxzy5wl1rlUnGlSrPQTinir2Q4KuXev5DM9YswpJM/RAnOni4jHStaVu6bQg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=2Ut0PQbocBDA6BRrESZl3aqAZdZPopO4v1wevVq9FEc=; b=csq9sVhsuqY5/jxryDeA7QwNM6oskdUsfjvLfrwBNTjSlAMvW9TImkXOQkmi5FX8azN4zEhr9N/+hXmP0UDSJKBKNgV4wnoyePLcAEtbhAzamVM0oKsjaoBTzNcG8rAJ33GxT1HeSEAIc6sxiMj1F1tCIHvyT6TLA9YWqoO5kEdvqp7hV6gPXN52tA9tD3Skw+QxEjJNIHZiq9qXGPwtKNawjupVNe5misJh5M0wArSUvyKM/9GPnNv/qY3dhDb1qRipaW82on1ww/e3YVzNJu7KxiHCYAPrdKJK7hXoaO9GFbNW/MDwXXpfSX+sMH4KQH9Y/3qaw6ByxLgWlmmvAg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=2Ut0PQbocBDA6BRrESZl3aqAZdZPopO4v1wevVq9FEc=; b=vTWzSGQYiTuW5XDdEj4GmdthVatVnwSUOhm1YiiFP+Mkb3bt30QQ86dHU/xQxhTywgJ0/dkzmJAn8tbVy6yQIFBEzIXcBlMrgu1YsgsQGtwpEpWIEBYD1HEG1BCR3cG2zyVekpgKVmeQ3vYGdijrLLU9QqbRaYQYKNBN6Z8eDyQ= Received: from CH5PR05CA0017.namprd05.prod.outlook.com (2603:10b6:610:1f0::7) by SN7PR12MB8772.namprd12.prod.outlook.com (2603:10b6:806:341::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7828.21; Wed, 31 Jul 2024 15:08:48 +0000 Received: from DS3PEPF0000C380.namprd04.prod.outlook.com (2603:10b6:610:1f0:cafe::ff) by CH5PR05CA0017.outlook.office365.com (2603:10b6:610:1f0::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7828.20 via Frontend Transport; Wed, 31 Jul 2024 15:08:48 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by DS3PEPF0000C380.mail.protection.outlook.com (10.167.23.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7828.19 via Frontend Transport; Wed, 31 Jul 2024 15:08:48 +0000 Received: from gomati.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Wed, 31 Jul 2024 10:08:44 -0500 From: Nikunj A Dadhania To: , , , , CC: , , , , , , Subject: [PATCH v11 05/20] virt: sev-guest: Use AES GCM crypto library Date: Wed, 31 Jul 2024 20:37:56 +0530 Message-ID: <20240731150811.156771-6-nikunj@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240731150811.156771-1-nikunj@amd.com> References: <20240731150811.156771-1-nikunj@amd.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS3PEPF0000C380:EE_|SN7PR12MB8772:EE_ X-MS-Office365-Filtering-Correlation-Id: b6d186d7-f073-4f25-a5ed-08dcb172adfa X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|376014|7416014|1800799024|36860700013; X-Microsoft-Antispam-Message-Info: oN+HWieJAIWzLKX3MLTaQHIBB+cX9ycRjEkymXM8EGZqCcGkEDAUuu74duls7x3h4NfSoVua0oJcCGGsFxZ0lflfooO8ZPoAY82xSm9liwQOIdRGssJ6ssNCVVvbB8NpYBodFzFtpr0B3qQV4N2aieY2qTdjjCQdqCRa9L5j4dPzhk/rAlQgQU6SiouMo1KccTIxz2QbIV/UZu4hCr7HRWi1Lkc4cZO8SGfHITDWfjW2YkwKXa5JGLEaO3mHZdpoHAIa9MxlLfcVLIsjketb8IBamIMZC7Y0OilZo020o5nyzWup9omGztzWSV/g1ktGP1o4yOJQcHfO0oQnMtvnar/oIIGuJnOmLIsbYIzJLYdxhHZ6SJQrSF1+LfUQ4hxEx6ARA52HJ/ShXIeActtaYSDUd2aSexf1RAb1yeMo05wq6E04jKMThkm5xgxBmSJhFuwqyzpEts1Yu8TQt0gOaWSZmXAP4WfqpUTk11c4BLbZuL3iue8Sn5QDQfghPGIqR4tnO9tHZuBRmcO24rih4GkhWAeNRWgfKfUhE5ZeDFrmw86+w4xQWqSFfLFjIHZoy6VwfP3vw7B3ZpabxITT+ZHu0c2O4+Gkj++TndmfrfnFS/kbRA5rqHnlPIv7CqTCEttuJV/vEtZH+ClQ9db5FRYSkIHqOTUb9PH6DL6tKiw/HWF0g7idIYyDnToX0qvj93iy5ACgUXflStqiskz/5WQyH5koEvRXMl3VriVLTJrsqJTHdNxIlaALUXbhvANBNsVMH8d1CuAJ0R1nUUFjz1L9vqvehZWYM0kNx+FEiuDIzRDskZFwsRz9vzZpknDybaeP+Hvp0wdEGWthQ1i1msyT66/6vZ2OJOdRQjdNb9NghLiq57sz6HymCHu8OAJWtz1AT5iR7c9zbm2S/iGZeXCf1OQTxJxGoPfYkKI8Ckfi6l8qJqQ0hjx8z7mMduOfFHrM3xina0ruLDtyMq1nS4ryT6QHwPZ1wIRBImlNC5uJXWpQNCEHdOv4FlryXguGb1JMHy3HzUfStbnLagNMaFuX9gS7AokhAg/njXOhbvtG2VPl3eKIT4wm1v3wcm+e29ZEzx8Q8WbLnotaXpPcH45LFELXsFnzqTsRyvRocIVYhnT9CoAA9NSdmld7e+TEBYQQjnZ1o7brJZplxFkNuqS/FO3o/U685NVeOqxJ7h9rPUriOL9VKgMJW12zFZ706Agv1OHVfRFIxTCVJUuUppUayQtDuYSjZ12jHieycOZWtdcVbKYLgU5VCcGIhnUxCZoYPOIjzmkP7KXa5ymw5kATeZ2rNIriREKq368QkYmTxrGaM6uBQ2HcIEXcS8fWmIG/fhMOYDj3Xm7FMQb4tEgwRG4YC5DLUeayH2rM7QDUH0dK4tvjREtXTcz2G+1KtWiN0RTSle8jhZsky5rULit4hYuVVs5t2I2cL1O1xFkLYscvcUIpjcGj4OpJvyMi X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(82310400026)(376014)(7416014)(1800799024)(36860700013);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Jul 2024 15:08:48.1790 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b6d186d7-f073-4f25-a5ed-08dcb172adfa X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: DS3PEPF0000C380.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR12MB8772 The sev-guest driver encryption code uses the crypto API for SNP guest messaging with the AMD Security processor. In order to enable secure TSC, SEV-SNP guests need to send such a TSC_INFO message before the APs are booted. Details from the TSC_INFO response will then be used to program the VMSA before the APs are brought up. However, the crypto API is not available this early in the boot process. In preparation for moving the encryption code out of sev-guest to support secure TSC and to ease review, switch to using the AES GCM library implementation instead. Drop __enc_payload() and dec_payload() helpers as both are small and can be moved to the respective callers. CC: Ard Biesheuvel Signed-off-by: Nikunj A Dadhania Reviewed-by: Tom Lendacky Tested-by: Peter Gonda Acked-by: Borislav Petkov (AMD) --- arch/x86/include/asm/sev.h | 3 + drivers/virt/coco/sev-guest/sev-guest.c | 175 ++++++------------------ drivers/virt/coco/sev-guest/Kconfig | 4 +- 3 files changed, 43 insertions(+), 139 deletions(-) diff --git a/arch/x86/include/asm/sev.h b/arch/x86/include/asm/sev.h index ee34ab00a8d6..e7977f76d77e 100644 --- a/arch/x86/include/asm/sev.h +++ b/arch/x86/include/asm/sev.h @@ -120,6 +120,9 @@ struct snp_req_data { }; #define MAX_AUTHTAG_LEN 32 +#define AUTHTAG_LEN 16 +#define AAD_LEN 48 +#define MSG_HDR_VER 1 /* See SNP spec SNP_GUEST_REQUEST section for the structure */ enum msg_type { diff --git a/drivers/virt/coco/sev-guest/sev-guest.c b/drivers/virt/coco/sev-guest/sev-guest.c index 0b950069bfcb..39d90dd0b012 100644 --- a/drivers/virt/coco/sev-guest/sev-guest.c +++ b/drivers/virt/coco/sev-guest/sev-guest.c @@ -17,8 +17,7 @@ #include #include #include -#include -#include +#include #include #include #include @@ -31,26 +30,18 @@ #include #define DEVICE_NAME "sev-guest" -#define AAD_LEN 48 -#define MSG_HDR_VER 1 #define SNP_REQ_MAX_RETRY_DURATION (60*HZ) #define SNP_REQ_RETRY_DELAY (2*HZ) #define SVSM_MAX_RETRIES 3 -struct snp_guest_crypto { - struct crypto_aead *tfm; - u8 *iv, *authtag; - int iv_len, a_len; -}; - struct snp_guest_dev { struct device *dev; struct miscdevice misc; void *certs_data; - struct snp_guest_crypto *crypto; + struct aesgcm_ctx *ctx; /* request and response are in unencrypted memory */ struct snp_guest_msg *request, *response; @@ -169,132 +160,31 @@ static inline struct snp_guest_dev *to_snp_dev(struct file *file) return container_of(dev, struct snp_guest_dev, misc); } -static struct snp_guest_crypto *init_crypto(struct snp_guest_dev *snp_dev, u8 *key, size_t keylen) +static struct aesgcm_ctx *snp_init_crypto(u8 *key, size_t keylen) { - struct snp_guest_crypto *crypto; + struct aesgcm_ctx *ctx; - crypto = kzalloc(sizeof(*crypto), GFP_KERNEL_ACCOUNT); - if (!crypto) + ctx = kzalloc(sizeof(*ctx), GFP_KERNEL_ACCOUNT); + if (!ctx) return NULL; - crypto->tfm = crypto_alloc_aead("gcm(aes)", 0, 0); - if (IS_ERR(crypto->tfm)) - goto e_free; - - if (crypto_aead_setkey(crypto->tfm, key, keylen)) - goto e_free_crypto; - - crypto->iv_len = crypto_aead_ivsize(crypto->tfm); - crypto->iv = kmalloc(crypto->iv_len, GFP_KERNEL_ACCOUNT); - if (!crypto->iv) - goto e_free_crypto; - - if (crypto_aead_authsize(crypto->tfm) > MAX_AUTHTAG_LEN) { - if (crypto_aead_setauthsize(crypto->tfm, MAX_AUTHTAG_LEN)) { - dev_err(snp_dev->dev, "failed to set authsize to %d\n", MAX_AUTHTAG_LEN); - goto e_free_iv; - } + if (aesgcm_expandkey(ctx, key, keylen, AUTHTAG_LEN)) { + pr_err("Crypto context initialization failed\n"); + kfree(ctx); + return NULL; } - crypto->a_len = crypto_aead_authsize(crypto->tfm); - crypto->authtag = kmalloc(crypto->a_len, GFP_KERNEL_ACCOUNT); - if (!crypto->authtag) - goto e_free_iv; - - return crypto; - -e_free_iv: - kfree(crypto->iv); -e_free_crypto: - crypto_free_aead(crypto->tfm); -e_free: - kfree(crypto); - - return NULL; -} - -static void deinit_crypto(struct snp_guest_crypto *crypto) -{ - crypto_free_aead(crypto->tfm); - kfree(crypto->iv); - kfree(crypto->authtag); - kfree(crypto); -} - -static int enc_dec_message(struct snp_guest_crypto *crypto, struct snp_guest_msg *msg, - u8 *src_buf, u8 *dst_buf, size_t len, bool enc) -{ - struct snp_guest_msg_hdr *hdr = &msg->hdr; - struct scatterlist src[3], dst[3]; - DECLARE_CRYPTO_WAIT(wait); - struct aead_request *req; - int ret; - - req = aead_request_alloc(crypto->tfm, GFP_KERNEL); - if (!req) - return -ENOMEM; - - /* - * AEAD memory operations: - * +------ AAD -------+------- DATA -----+---- AUTHTAG----+ - * | msg header | plaintext | hdr->authtag | - * | bytes 30h - 5Fh | or | | - * | | cipher | | - * +------------------+------------------+----------------+ - */ - sg_init_table(src, 3); - sg_set_buf(&src[0], &hdr->algo, AAD_LEN); - sg_set_buf(&src[1], src_buf, hdr->msg_sz); - sg_set_buf(&src[2], hdr->authtag, crypto->a_len); - - sg_init_table(dst, 3); - sg_set_buf(&dst[0], &hdr->algo, AAD_LEN); - sg_set_buf(&dst[1], dst_buf, hdr->msg_sz); - sg_set_buf(&dst[2], hdr->authtag, crypto->a_len); - - aead_request_set_ad(req, AAD_LEN); - aead_request_set_tfm(req, crypto->tfm); - aead_request_set_callback(req, 0, crypto_req_done, &wait); - - aead_request_set_crypt(req, src, dst, len, crypto->iv); - ret = crypto_wait_req(enc ? crypto_aead_encrypt(req) : crypto_aead_decrypt(req), &wait); - - aead_request_free(req); - return ret; -} - -static int __enc_payload(struct snp_guest_dev *snp_dev, struct snp_guest_msg *msg, - void *plaintext, size_t len) -{ - struct snp_guest_crypto *crypto = snp_dev->crypto; - struct snp_guest_msg_hdr *hdr = &msg->hdr; - - memset(crypto->iv, 0, crypto->iv_len); - memcpy(crypto->iv, &hdr->msg_seqno, sizeof(hdr->msg_seqno)); - - return enc_dec_message(crypto, msg, plaintext, msg->payload, len, true); -} - -static int dec_payload(struct snp_guest_dev *snp_dev, struct snp_guest_msg *msg, - void *plaintext, size_t len) -{ - struct snp_guest_crypto *crypto = snp_dev->crypto; - struct snp_guest_msg_hdr *hdr = &msg->hdr; - - /* Build IV with response buffer sequence number */ - memset(crypto->iv, 0, crypto->iv_len); - memcpy(crypto->iv, &hdr->msg_seqno, sizeof(hdr->msg_seqno)); - - return enc_dec_message(crypto, msg, msg->payload, plaintext, len, false); + return ctx; } static int verify_and_dec_payload(struct snp_guest_dev *snp_dev, void *payload, u32 sz) { - struct snp_guest_crypto *crypto = snp_dev->crypto; struct snp_guest_msg *resp_msg = &snp_dev->secret_response; struct snp_guest_msg *req_msg = &snp_dev->secret_request; struct snp_guest_msg_hdr *req_msg_hdr = &req_msg->hdr; struct snp_guest_msg_hdr *resp_msg_hdr = &resp_msg->hdr; + struct aesgcm_ctx *ctx = snp_dev->ctx; + u8 iv[GCM_AES_IV_SIZE] = {}; pr_debug("response [seqno %lld type %d version %d sz %d]\n", resp_msg_hdr->msg_seqno, resp_msg_hdr->msg_type, resp_msg_hdr->msg_version, @@ -316,11 +206,16 @@ static int verify_and_dec_payload(struct snp_guest_dev *snp_dev, void *payload, * If the message size is greater than our buffer length then return * an error. */ - if (unlikely((resp_msg_hdr->msg_sz + crypto->a_len) > sz)) + if (unlikely((resp_msg_hdr->msg_sz + ctx->authsize) > sz)) return -EBADMSG; /* Decrypt the payload */ - return dec_payload(snp_dev, resp_msg, payload, resp_msg_hdr->msg_sz + crypto->a_len); + memcpy(iv, &resp_msg_hdr->msg_seqno, min(sizeof(iv), sizeof(resp_msg_hdr->msg_seqno))); + if (!aesgcm_decrypt(ctx, payload, resp_msg->payload, resp_msg_hdr->msg_sz, + &resp_msg_hdr->algo, AAD_LEN, iv, resp_msg_hdr->authtag)) + return -EBADMSG; + + return 0; } static int enc_payload(struct snp_guest_dev *snp_dev, u64 seqno, int version, u8 type, @@ -328,6 +223,8 @@ static int enc_payload(struct snp_guest_dev *snp_dev, u64 seqno, int version, u8 { struct snp_guest_msg *msg = &snp_dev->secret_request; struct snp_guest_msg_hdr *hdr = &msg->hdr; + struct aesgcm_ctx *ctx = snp_dev->ctx; + u8 iv[GCM_AES_IV_SIZE] = {}; memset(msg, 0, sizeof(*msg)); @@ -347,7 +244,14 @@ static int enc_payload(struct snp_guest_dev *snp_dev, u64 seqno, int version, u8 pr_debug("request [seqno %lld type %d version %d sz %d]\n", hdr->msg_seqno, hdr->msg_type, hdr->msg_version, hdr->msg_sz); - return __enc_payload(snp_dev, msg, payload, sz); + if (WARN_ON((sz + ctx->authsize) > sizeof(msg->payload))) + return -EBADMSG; + + memcpy(iv, &hdr->msg_seqno, min(sizeof(iv), sizeof(hdr->msg_seqno))); + aesgcm_encrypt(ctx, msg->payload, payload, sz, &hdr->algo, AAD_LEN, + iv, hdr->authtag); + + return 0; } static int __handle_guest_request(struct snp_guest_dev *snp_dev, u64 exit_code, @@ -495,7 +399,6 @@ struct snp_req_resp { static int get_report(struct snp_guest_dev *snp_dev, struct snp_guest_request_ioctl *arg) { - struct snp_guest_crypto *crypto = snp_dev->crypto; struct snp_report_req *report_req = &snp_dev->req.report; struct snp_report_resp *report_resp; int rc, resp_len; @@ -513,7 +416,7 @@ static int get_report(struct snp_guest_dev *snp_dev, struct snp_guest_request_io * response payload. Make sure that it has enough space to cover the * authtag. */ - resp_len = sizeof(report_resp->data) + crypto->a_len; + resp_len = sizeof(report_resp->data) + snp_dev->ctx->authsize; report_resp = kzalloc(resp_len, GFP_KERNEL_ACCOUNT); if (!report_resp) return -ENOMEM; @@ -534,7 +437,6 @@ static int get_report(struct snp_guest_dev *snp_dev, struct snp_guest_request_io static int get_derived_key(struct snp_guest_dev *snp_dev, struct snp_guest_request_ioctl *arg) { struct snp_derived_key_req *derived_key_req = &snp_dev->req.derived_key; - struct snp_guest_crypto *crypto = snp_dev->crypto; struct snp_derived_key_resp derived_key_resp = {0}; int rc, resp_len; /* Response data is 64 bytes and max authsize for GCM is 16 bytes. */ @@ -550,7 +452,7 @@ static int get_derived_key(struct snp_guest_dev *snp_dev, struct snp_guest_reque * response payload. Make sure that it has enough space to cover the * authtag. */ - resp_len = sizeof(derived_key_resp.data) + crypto->a_len; + resp_len = sizeof(derived_key_resp.data) + snp_dev->ctx->authsize; if (sizeof(buf) < resp_len) return -ENOMEM; @@ -579,7 +481,6 @@ static int get_ext_report(struct snp_guest_dev *snp_dev, struct snp_guest_reques { struct snp_ext_report_req *report_req = &snp_dev->req.ext_report; - struct snp_guest_crypto *crypto = snp_dev->crypto; struct snp_report_resp *report_resp; int ret, npages = 0, resp_len; sockptr_t certs_address; @@ -622,7 +523,7 @@ static int get_ext_report(struct snp_guest_dev *snp_dev, struct snp_guest_reques * response payload. Make sure that it has enough space to cover the * authtag. */ - resp_len = sizeof(report_resp->data) + crypto->a_len; + resp_len = sizeof(report_resp->data) + snp_dev->ctx->authsize; report_resp = kzalloc(resp_len, GFP_KERNEL_ACCOUNT); if (!report_resp) return -ENOMEM; @@ -1148,8 +1049,8 @@ static int __init sev_guest_probe(struct platform_device *pdev) goto e_free_response; ret = -EIO; - snp_dev->crypto = init_crypto(snp_dev, snp_dev->vmpck, VMPCK_KEY_LEN); - if (!snp_dev->crypto) + snp_dev->ctx = snp_init_crypto(snp_dev->vmpck, VMPCK_KEY_LEN); + if (!snp_dev->ctx) goto e_free_cert_data; misc = &snp_dev->misc; @@ -1175,11 +1076,13 @@ static int __init sev_guest_probe(struct platform_device *pdev) ret = misc_register(misc); if (ret) - goto e_free_cert_data; + goto e_free_ctx; dev_info(dev, "Initialized SEV guest driver (using VMPCK%d communication key)\n", vmpck_id); return 0; +e_free_ctx: + kfree(snp_dev->ctx); e_free_cert_data: free_shared_pages(snp_dev->certs_data, SEV_FW_BLOB_MAX_SIZE); e_free_response: @@ -1198,7 +1101,7 @@ static void __exit sev_guest_remove(struct platform_device *pdev) free_shared_pages(snp_dev->certs_data, SEV_FW_BLOB_MAX_SIZE); free_shared_pages(snp_dev->response, sizeof(struct snp_guest_msg)); free_shared_pages(snp_dev->request, sizeof(struct snp_guest_msg)); - deinit_crypto(snp_dev->crypto); + kfree(snp_dev->ctx); misc_deregister(&snp_dev->misc); } diff --git a/drivers/virt/coco/sev-guest/Kconfig b/drivers/virt/coco/sev-guest/Kconfig index 1cffc72c41cb..0b772bd921d8 100644 --- a/drivers/virt/coco/sev-guest/Kconfig +++ b/drivers/virt/coco/sev-guest/Kconfig @@ -2,9 +2,7 @@ config SEV_GUEST tristate "AMD SEV Guest driver" default m depends on AMD_MEM_ENCRYPT - select CRYPTO - select CRYPTO_AEAD2 - select CRYPTO_GCM + select CRYPTO_LIB_AESGCM select TSM_REPORTS help SEV-SNP firmware provides the guest a mechanism to communicate with From patchwork Wed Jul 31 15:07:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Nikunj A. Dadhania" X-Patchwork-Id: 13748883 Received: from NAM04-BN8-obe.outbound.protection.outlook.com (mail-bn8nam04on2068.outbound.protection.outlook.com [40.107.100.68]) (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 D4C861CABF; Wed, 31 Jul 2024 15:08:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.100.68 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722438537; cv=fail; b=jQRlsk2xyk8ewIwPUNxjAc7m0aNVlJG2zy97NRXgwjIeZUF7NNT3dPBde6rOgQGvAaYrjF0sFOR4db/Q8DvJ/jf/wkMHxZ3COcD+BHSDkcsSUYkjL4C8zBU1RSuts+StaeH2cYKvcLiZjJPQjoSuHwK9kldvsOjho2WZq8MN+cI= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722438537; c=relaxed/simple; bh=1zJ34qRNdt4eq8G7OUYU9BUQ/QIAq0ZnCelY3alVorI=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=hQL6DyUFEjUYrEHeyplP02QRN9hpoJMT9aRHH8tdahvf9q1/MGoMm1mbVuXXHTxnOWa7VLpv7hEAL5htsd+jyY/2m5h+PD4k8/CrBbgQ4Qd5dIfyVRmZmbNVI23C/7WqPDMswGFYfvLC++t4zku3shuzjOYhTD7nKLO88q+x6ZU= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=Dkh26gng; arc=fail smtp.client-ip=40.107.100.68 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="Dkh26gng" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=WnVrsvUQkBvyoCRMnMEOSu678rS9JeC2irkqPbEyVdyVe2JuQt1hNHWzBReKuIYXm4L0cUcF6rnDcDhQmp5ERHtK2C6Oe0BL9fxlt0DN76CmwpkPild0BCxos9SoLAvv3kOnDMjGgU6L8T7aeUoiu5CdE8vrM0bZbASJTGRDx2ymLQr5yiRwcR7umrCnA0Ws3i11vNo03DF9igObO8y2MqHtTJf1FEaefRb3ENuNFEVu+LMS2C3k8S5HtkwiRIMZXJDAiGrJvc8diqDzbUr2yKk0xfvHb+ui2rmo3N/UEKeVBkkmYLWuLEwvjb0dqQQDrwIXedZsUR7euxi+2i3trg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=aBZbd+6vfgzmsCuDkCZy6V+wB1Yn4gE3mvKYArsqRyc=; b=B3Cd7d+QNHYWvoLophfBS+YqaIaSPggEv48K3ljYR+2MQ06eAJS+Dfxvko1td42B5B8y8qv8hs8q0L1nNT+FPmSqoIdEVP4+pTfOmkMeAiU9/OylsZoTfRQpvLJPEHoOzJI6B5K/HA88qXpiOB0QNea2XeB0FJwLlItvW/Tjq8SV/5KwlXzn3JBvTVIFxLh85o16fhFf0QVyH3vqVwday3c+mcsJNFAeWvUl9R9K+6GYCQSWEFiRAWDFcZiSkx5hDLVeT4glQH995KvymWOk7VvIekhmKONMW/G9+CM8bbQr9rkInDfQgGPzZXO+0TdTqvBapg5fqiWC/YMScYNFNg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=aBZbd+6vfgzmsCuDkCZy6V+wB1Yn4gE3mvKYArsqRyc=; b=Dkh26gng5Uv8dabUJts4Y9i+yqs63j1SjDY5u50QILwSCYtwBgGrM8XXecgnwOJx++6Tm+U85G4KF0A3DuW2xuhMkZ1tKbVa/15rHDEOnK3G7yggmF7SsyumLB2F4qHKclzcmrEFICxuuEBbmfQ4XskEZmFR+twcIzcRoBdsezs= Received: from DM6PR07CA0057.namprd07.prod.outlook.com (2603:10b6:5:74::34) by SA1PR12MB7102.namprd12.prod.outlook.com (2603:10b6:806:29f::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7807.24; Wed, 31 Jul 2024 15:08:52 +0000 Received: from DS3PEPF0000C37C.namprd04.prod.outlook.com (2603:10b6:5:74:cafe::51) by DM6PR07CA0057.outlook.office365.com (2603:10b6:5:74::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7784.35 via Frontend Transport; Wed, 31 Jul 2024 15:08:52 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by DS3PEPF0000C37C.mail.protection.outlook.com (10.167.23.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7828.19 via Frontend Transport; Wed, 31 Jul 2024 15:08:52 +0000 Received: from gomati.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Wed, 31 Jul 2024 10:08:47 -0500 From: Nikunj A Dadhania To: , , , , CC: , , , , , , Subject: [PATCH v11 06/20] x86/sev: Handle failures from snp_init() Date: Wed, 31 Jul 2024 20:37:57 +0530 Message-ID: <20240731150811.156771-7-nikunj@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240731150811.156771-1-nikunj@amd.com> References: <20240731150811.156771-1-nikunj@amd.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS3PEPF0000C37C:EE_|SA1PR12MB7102:EE_ X-MS-Office365-Filtering-Correlation-Id: 180ca082-30c5-4d50-d250-08dcb172b06a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|376014|1800799024|82310400026|36860700013; X-Microsoft-Antispam-Message-Info: JQFurnZzs/BPi3h4PKawHpW8WhjBWkhJKN8nRPTKt9h9c+rgOjqlz7pOZYUT4ewslVlofTbOruYrWQBNa/vQFm8q2si3j16HfF2PN3abFyZw021zD1JAY+kz7mE5/fYYdazHXTjEawGW4beUpxNQX0aB/FakJfzBvPtVBTTiIEmqUW9XiBPMxomZMQu4fsr6KySAuVn2uQZQf/DiKnHcbItjZJMf7oiy2LBazqIX53NlAvC1pYnJQxT7EYrluroJln/P8jHA/oKrkwGj1eWn4qwwOr7bMfEpcrKLG1fMgluH+ot9iEnRVj78ZJtJOzRdY/DmbWotvbcDJgjLPyijjSUM1IGZL5EeRnIS5de63SxJ0qmVRdvh+UZi6VWG3ajcRzcA/TY+GlMuwRJW2VGlTXPQUbi+uuE0G+5wsXakzMzxOqQbdFUIdojXrl1GDCw9wxNJPQYVPJdycUROYMBJk0BvXZ0HhfUfLBRMkLoUmC+NsLiVqSktiIKw67+Sz2DMcg888eAUxshXv9UjHftiMQ43wse2DQCXMt5x2Ba33kZwcF3vDcnhN9ppR+S+Z3l3BnexWyZ9fBoxr1ZNB7e6QrmbdRPOdBdskElPDNEWMZiIQvqeiDCsWzPg0CiP3PEdl8pEca0TZnSis3h49O/d2vnrf4yVXjo7tI6lAIjVLKalRJBV3weeDqKugHqFhmrrW37aflqkwa1s/W3ibTEWx1P1MaqqIapKfBYMj5ghVZNXOKbi3s3lhds3Q0G5PUJGDdLt12DE6FKwbm7U6Fahh5tmZ5GqgvwS4vN2E0BYGXj5HyX9zvLRiLyiT7x9pjqCCmCr5lhvwiSxoqGsqojDTq+LQ12PuvKQ8H7ofGsEoMtSDFZp5CyBR2ZcmSfphG8t/SE8m/LWMWjdJnNlyO5j9CHHNdIB8nuSeycWMeZQPOYCFd6NDoAIe7AojPsMGeo6xw01F5DlXb+U8NLlXGZR3shoiX9PTjWhvM/4oMFWOuO8GhIRIcW34duOJFYrKj1XHkVUsF5TSrHQFj9JB6KJJ44TFNbNTaVneaPpIcMkW5AAeHULNyqPr/PL3QKTMZWt31hkj6A+ZBYZZqujN1lSNGUrNwTdXOzrrzrTPnHpYNdjuFNjqhud3GlbI9CtHHaVDnycpt/Sq3BJS1kLAcR/ey0rvGdSDT45ufQzV4/ekJ7ok7DyXGWXovzV/3tElQdGHTvFW6PpoMne6XZcOCWCuTeH09zbMGoLclVR+7yJJJBM6+lK8hddSNB5zAcL3n7nrFXtPqDlOiyLawZXX9BpVQkcImTYyzUoh0+cSyocW1jQ44FrKWn5NE0NCIgqExO9QiKO+9umcqmBgGU1pyg/l7RZ8Cn6VTptD7M0GD2J/hUiNdnCN/yZ+XVwDYZRe9TK5M3Wzo54gJDzjYOYrqz3QHadqpmK3obziubGN08zK3dloboGXeATxefg/4m8imZ5 X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(7416014)(376014)(1800799024)(82310400026)(36860700013);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Jul 2024 15:08:52.2852 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 180ca082-30c5-4d50-d250-08dcb172b06a X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: DS3PEPF0000C37C.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR12MB7102 Address the ignored failures from snp_init() in sme_enable(). Add error handling for scenarios where snp_init() fails to retrieve the SEV-SNP CC blob or encounters issues while parsing the CC blob. This change ensures that SNP guests will error out early, preventing delayed error reporting or undefined behavior. Signed-off-by: Nikunj A Dadhania Signed-off-by: Nikunj A Dadhania --- arch/x86/mm/mem_encrypt_identity.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/arch/x86/mm/mem_encrypt_identity.c b/arch/x86/mm/mem_encrypt_identity.c index ac33b2263a43..e83b363c5e68 100644 --- a/arch/x86/mm/mem_encrypt_identity.c +++ b/arch/x86/mm/mem_encrypt_identity.c @@ -535,6 +535,13 @@ void __head sme_enable(struct boot_params *bp) if (snp && !(msr & MSR_AMD64_SEV_SNP_ENABLED)) snp_abort(); + /* + * The SEV-SNP CC blob should be present and parsing CC blob should + * succeed when SEV-SNP is enabled. + */ + if (!snp && (msr & MSR_AMD64_SEV_SNP_ENABLED)) + snp_abort(); + /* Check if memory encryption is enabled */ if (feature_mask == AMD_SME_BIT) { if (!(bp->hdr.xloadflags & XLF_MEM_ENCRYPTION)) From patchwork Wed Jul 31 15:07:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Nikunj A. Dadhania" X-Patchwork-Id: 13748884 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2078.outbound.protection.outlook.com [40.107.236.78]) (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 E49B91BE851; Wed, 31 Jul 2024 15:09:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.236.78 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722438544; cv=fail; b=pIT29Fism68fEq38b/bY3juJBxDeFxsRwY0jbRkod7CGd8bRxwBJsKHzgYNYlyFCIcSZj49Ubvz3JePdrLXOpon7TTd6sqYb3VOf2ffpe5O39V1QVih6x2E4lmYmibrMOtrIp9SSTDQBaxsUMPFj9Gno5T2Ixy48HRNLuUJl9lE= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722438544; c=relaxed/simple; bh=HnO8omW8SicKCqY9xH0+gCZ7+UPc6jxUsFgZzJxv3TE=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=VIalO4pxZAqsCxix8sjQseJwNO8uAOV/HETfOWIAkQ7+tEYug2vvcl/EsIK83ArQbRd979epJssjBkNj8jWAJPzjR3R9Fl+4ZahbC9FPM4P2o5TDOzRpGgYSbYPLDodcAGMRKVdkA50SZTdokQAm4ISGzzOq3BbVy0rWlq56W5o= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=iu0Q0oih; arc=fail smtp.client-ip=40.107.236.78 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="iu0Q0oih" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=eJxwJiPtDTa7G66Ourfohgt28PUZQQUiwmbOaYpi9J2/F0T1Tj4VzlloB3pfVVTM4omQPWa4PpYwjc30Cf2GCKd20JZUbSczDhgT5t+OwyteVnBLbB5ecjMfNgTAOLzqcumSmMgcpStYJJpVUt97h4wzxsuj+E4LsOMAuadAifEY01q5ZWll5hk2mpR7oev9jYgb+2Mdd+Uuk7Y64PBR5ay9Z8CQT1GOZmgvPIr/Q/UiMga/u/yF0J4nlXOYUztbu0hJH/0oJLMLi36PH6JsdZMUr3ysN5ZARiS4taSJRoJ1kFc/vy/G1Is1GEZ+9MYmLpnh6j3YF5HkHEBAuQ/k/g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=YUVryATV69BcwcXaKxjkuok2Lyt9krnyGsk2B2MfiFw=; b=FEMe10QDUAvJfQ9232mjliMJvZqDd5ojH6RwQOqNPcSbDuobIyKOxP+ljLRl6wi0jIRmVzKYBJdquyYLa2laz9//5+zSMOiyRl8yY3Z1XI2/hXwHfh/xjSGMDrMnXnDb54CrgoHk1LBINAGpA7kYsKjkTrA4RqkKw4gD1vCzgx2rRKO0TePj3sFLoVH38SpBclx1lXKeLx5Rkl9dYnP3qWViE0U0mivTKXnKg0YfoWTS0bkXKt9MrZsF/drK7AB29QWj/xQN7/e8X0COEy22rHfsEJIU2JdhzzFjAyb5nU1TbGRMD6MUo6X1QrIh3INYVx0VTSSh8IPGWx9xnYseAQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=YUVryATV69BcwcXaKxjkuok2Lyt9krnyGsk2B2MfiFw=; b=iu0Q0oihCTbDgXZhJO0LQVxSdDQSzjQH7jZCILVxh6PnOqKulf4FoctMpS361fnbeNQGBvcA2VXqo/eXbUPZWrWswbGXe8E9HVLkWpFLOh/q2r/9LvoLjcvMM3vvyWLdu8jbAQIqHD3OJCqp6vmbBYNXkOtsRuuQGOXGVw7Y4AA= Received: from CH0P223CA0001.NAMP223.PROD.OUTLOOK.COM (2603:10b6:610:116::32) by CH3PR12MB7619.namprd12.prod.outlook.com (2603:10b6:610:14b::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7807.28; Wed, 31 Jul 2024 15:08:57 +0000 Received: from DS3PEPF0000C37B.namprd04.prod.outlook.com (2603:10b6:610:116:cafe::66) by CH0P223CA0001.outlook.office365.com (2603:10b6:610:116::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7784.35 via Frontend Transport; Wed, 31 Jul 2024 15:08:55 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by DS3PEPF0000C37B.mail.protection.outlook.com (10.167.23.5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7828.19 via Frontend Transport; Wed, 31 Jul 2024 15:08:55 +0000 Received: from gomati.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Wed, 31 Jul 2024 10:08:51 -0500 From: Nikunj A Dadhania To: , , , , CC: , , , , , , Subject: [PATCH v11 07/20] x86/sev: Cache the secrets page address Date: Wed, 31 Jul 2024 20:37:58 +0530 Message-ID: <20240731150811.156771-8-nikunj@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240731150811.156771-1-nikunj@amd.com> References: <20240731150811.156771-1-nikunj@amd.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS3PEPF0000C37B:EE_|CH3PR12MB7619:EE_ X-MS-Office365-Filtering-Correlation-Id: f6bac3b7-3222-407f-c48a-08dcb172b26c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|1800799024|376014|7416014|82310400026; X-Microsoft-Antispam-Message-Info: 1MjA5YicdTUq67dhvxvtG71uJdC5xFZdBGovC/ppzvkckzzoPDqTz2lOy48b3qGPDeqHd0yMyua1TxGUNG/D/SpFMqHqhpxcBX6rad5ONovH2nfWyWfVZYBqsL1ErlOcNSB1iMXsH0iqKG/WmeVvaAXhKyCT2AQkYgf5kAzoU/6kXCYxgQEuQ7Uz0/NPld4Evf+Cc2D5bjntmTjCjrCa9tZPMfoqf/NQvwX7b7MBvuUlB83iG8Wih6bQvLagsnKwLBuqCZvUTD7p0JnrYa4PAqdR93hFyn3cGhRtTzay/0JOrGCCCMYbValgrZRF/yJ9Y5iX2QforBG/aZ38d0jdqmNRIq3EOa8g9uKGBmKFvK7lAld78QKcqSbnzT9sQIV3xHqIZh0HBfEVDQt1z7DUNzsdNXhX4mJcqI/VvXX6gWewCTI0wZfu1sWIYzWsGZYRxCyBzQHlBJIOMKnpI8uiOYEce0sGeEDQE1VJ5gUkBnFgtH35jbDqiKHQdrHk+Kv1j08fAidG9MNimo6MipusgThZkwFFRtPeNmgodY6ChrPmBC+M8tMSZzVcfQAsuf+L0lS9SBTcHbSXkg14KQub2NLvb2Xl9LIbN45Y/GXozc8X43njlBwiv8CsJTBOOTLc4DCE/51j9iphjsrsWloX/q9BLTg+pUgnNef0I4aEvIaKOOfjPWi2Wi3OjPpT3nSSjHQkQoWgH9en4PbDZEH6LtPR5n4t1f+hIcun1IG3+7n3kTf5NI+609XfAw8y7jiWfbvPQ2Kv4KDIwJa2DKpvBfT9UNID0OwEsFpgsI45mUEa7gqlzKa08YcMuWjb7Bcz7Gi0wF6//kaO4qVZ/7h0nFlquu48isiVKZHs9hVGtqkFAEN4x/p5s9zFG++qTWfdInKqss+pZHFQvVqicbPXE5udvSL3ePmJYwJQffKTo77iUS41lpl6t8HU4qoCaC8Ww4c5gJ3jFVxbZxhNEddRvQNGgtaSeICzgIZ08bCZDWQ7hCYLQWKYbxEHoxm5h9uagMNNqjTzml7HTHAGJCZagvmDr9FmUbZKwOm4C3Uq62q3h+9tpr8694OztpQ57z0XL2BVfTifyOzH/EWF3fTN+58Z5NytPa5OT0xh47SS6Z6WfyPSK8sPdkAFWTVaP4e1oGh/wIO7PVlcCsnhRDPRS8U4ySzq92kBEN2EqCyoXCYPRJjyLPiXKBZxnq+ATPnGSr1EUVGWrrPkGi/Q+AwgWsczMgmVsotN/DuWuo8pPUT6iWK1QdGOMkMHjOZ8/iIbCAKBVgE9jtRmKzPLVfPW2vE6C0M+lWGcW5Vf1ZnCcJzuY8ZOCfyN8G4z2EXQik+Jy0pD4/lN/0rDrD0iB3HygwrM/a8O3vud2VZLQ2KTnfxKRMDoALZV6VCpeLRHeD2ya/Qz8ZDBLp4DWIM54/b04mxWVaqC/O81a2Hd0Cza/zfX7tC8ZnSe8nPxptj0yw15 X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(36860700013)(1800799024)(376014)(7416014)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Jul 2024 15:08:55.6534 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f6bac3b7-3222-407f-c48a-08dcb172b26c X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: DS3PEPF0000C37B.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH3PR12MB7619 Instead of calling get_secrets_page(), which parses the CC blob every time to get the secrets page physical address (secrets_pa), save the secrets page physical address during snp_init() from the CC blob. Since get_secrets_page() is no longer used, remove the function. Signed-off-by: Nikunj A Dadhania Reviewed-by: Tom Lendacky --- arch/x86/coco/sev/core.c | 51 +++++++++------------------------------- 1 file changed, 11 insertions(+), 40 deletions(-) diff --git a/arch/x86/coco/sev/core.c b/arch/x86/coco/sev/core.c index 082d61d85dfc..a0b64cfd4b8e 100644 --- a/arch/x86/coco/sev/core.c +++ b/arch/x86/coco/sev/core.c @@ -92,6 +92,9 @@ static struct ghcb *boot_ghcb __section(".data"); /* Bitmap of SEV features supported by the hypervisor */ static u64 sev_hv_features __ro_after_init; +/* Secrets page physical address from the CC blob */ +static u64 secrets_pa __ro_after_init; + /* #VC handler runtime per-CPU data */ struct sev_es_runtime_data { struct ghcb ghcb_page; @@ -722,45 +725,13 @@ void noinstr __sev_es_nmi_complete(void) __sev_put_ghcb(&state); } -static u64 __init get_secrets_page(void) -{ - u64 pa_data = boot_params.cc_blob_address; - struct cc_blob_sev_info info; - void *map; - - /* - * The CC blob contains the address of the secrets page, check if the - * blob is present. - */ - if (!pa_data) - return 0; - - map = early_memremap(pa_data, sizeof(info)); - if (!map) { - pr_err("Unable to locate SNP secrets page: failed to map the Confidential Computing blob.\n"); - return 0; - } - memcpy(&info, map, sizeof(info)); - early_memunmap(map, sizeof(info)); - - /* smoke-test the secrets page passed */ - if (!info.secrets_phys || info.secrets_len != PAGE_SIZE) - return 0; - - return info.secrets_phys; -} - static u64 __init get_snp_jump_table_addr(void) { struct snp_secrets_page *secrets; void __iomem *mem; - u64 pa, addr; - - pa = get_secrets_page(); - if (!pa) - return 0; + u64 addr; - mem = ioremap_encrypted(pa, PAGE_SIZE); + mem = ioremap_encrypted(secrets_pa, PAGE_SIZE); if (!mem) { pr_err("Unable to locate AP jump table address: failed to map the SNP secrets page.\n"); return 0; @@ -2300,6 +2271,11 @@ bool __head snp_init(struct boot_params *bp) if (!cc_info) return false; + if (cc_info->secrets_phys && cc_info->secrets_len == PAGE_SIZE) + secrets_pa = cc_info->secrets_phys; + else + return false; + setup_cpuid_table(cc_info); svsm_setup(cc_info); @@ -2513,16 +2489,11 @@ static struct platform_device sev_guest_device = { static int __init snp_init_platform_device(void) { struct sev_guest_platform_data data; - u64 gpa; if (!cc_platform_has(CC_ATTR_GUEST_SEV_SNP)) return -ENODEV; - gpa = get_secrets_page(); - if (!gpa) - return -ENODEV; - - data.secrets_gpa = gpa; + data.secrets_gpa = secrets_pa; if (platform_device_add_data(&sev_guest_device, &data, sizeof(data))) return -ENODEV; From patchwork Wed Jul 31 15:07:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Nikunj A. Dadhania" X-Patchwork-Id: 13748885 Received: from NAM02-BN1-obe.outbound.protection.outlook.com (mail-bn1nam02on2071.outbound.protection.outlook.com [40.107.212.71]) (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 8C4A51CABF; Wed, 31 Jul 2024 15:09:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.212.71 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722438546; cv=fail; b=h+ShjHegbenC368GYvy7XlUWs+c2FBbj+x1nmhfSR/ZtvFNozP0mwGSjfQ5Hf7ObYCExioD/LdHEPYR689HVucgQMZlMBR4yDG8f5r7hYIw6kvgxP2mS/Cp/GfOA/4n81vbOqXvJ5qXjM/bq4S9t31AptA3GAWX7MrqJ4WyP0SA= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722438546; c=relaxed/simple; bh=1WS+0PXaNSz2aeUzqscIh2sY1ep25VTIh92vKblhI00=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=sZgpHejmGdJmVPuXmSootc4aIamx9x+LIh+9VyvYOGdsY9DQc3hkDZ+esYh0xrGE45wiHRddyJqsquwMmE15vjvyz5LB3S/riGwz7FnRGMJ06+nltggJZyyU/Vns9ZTZ2Vr2O6u13MH4rmBHN5KoVNdSI1zBvQ15IyHoeQ+OHTo= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=i59uVKuj; arc=fail smtp.client-ip=40.107.212.71 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="i59uVKuj" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=bgmn0L10O9iEFJ2NpKxbo7dWoaX2DGW/1yBoaSUJW7faFy8pKFKSB5wI0gt6T0CJWoAYuzg12uIuMULvDfNjfj3wPj+D0PDma45pIyLx1mzTrp/HlsjFsCT+xnZi/cuWzT9CQ9C9m4jGvYQQGIGXvKNVb0js1LtoVJzA9G4MqdBrNoAhCN88h+rFTyFLWpKFH+hK5JUlrmOoVTlN+w5bT8nQOckyTWzRxLCKuBPHk7NpfL141AAOafHM1N6UmRsC9Ly0XaLaRVxeCTG01B9B1V5C7qnBIRfwRAbGzwqL3nqWT1ZT2Q4t9GYPB0ydLAElImNvuIIXK002hU+bSXaqwA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=zzfL2xIRi73ARgskJwg0WWUbHDsEvovJpoqRTOe/fXU=; b=vjTsTNYuLwh2cAcHqVy5xI7XHyta72FcaAy+YB6QMLSys6hFt5G7wqT0SUDssAqxpk8tx++bxbeQi8+jUBkW55YAWlIp9/LtXJ5Yj65drdHM0Jy8irzjkXpZBunGdP63gDB6hgY/or+s8gaLCOlis6TFCHqe4c6BIGLQyELGJ2/zqx4SMH1kw2R7fC4PNxumWGqRMApQTiIXiHnWPcBr3N8bjcCVa1cPKglNQBIwsum0NkTFEgJQmHU9XTab3/ThYKSRLIG+bAfSUUGeXmBBCB+wY6nqf8Pzbpo7Qazn26fBUuBf43yE60BYqbc6kF9dog031Mlducum3x9YTyYCdw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=zzfL2xIRi73ARgskJwg0WWUbHDsEvovJpoqRTOe/fXU=; b=i59uVKujsy6nN2ek212cPLS4F67zj15LF8oB0wNBTtUaG/WUXJhXdqkv9YNBzZRkdNA0z8x63AzuArq3Q/zMwC/7DJvwp9Lk4ycd/XwDff/oAG7OAwSZuRV5jVmtJlqzdEtr1BLY3oi7I9pmdvk4RgPuIW0HJVW3HfrhPTVApRk= Received: from CH0PR03CA0301.namprd03.prod.outlook.com (2603:10b6:610:118::11) by PH7PR12MB5758.namprd12.prod.outlook.com (2603:10b6:510:1d1::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7828.19; Wed, 31 Jul 2024 15:09:00 +0000 Received: from DS3PEPF0000C381.namprd04.prod.outlook.com (2603:10b6:610:118:cafe::66) by CH0PR03CA0301.outlook.office365.com (2603:10b6:610:118::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7784.34 via Frontend Transport; Wed, 31 Jul 2024 15:08:59 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by DS3PEPF0000C381.mail.protection.outlook.com (10.167.23.11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7828.19 via Frontend Transport; Wed, 31 Jul 2024 15:08:59 +0000 Received: from gomati.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Wed, 31 Jul 2024 10:08:55 -0500 From: Nikunj A Dadhania To: , , , , CC: , , , , , , Subject: [PATCH v11 08/20] virt: sev-guest: Consolidate SNP guest messaging parameters to a struct Date: Wed, 31 Jul 2024 20:37:59 +0530 Message-ID: <20240731150811.156771-9-nikunj@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240731150811.156771-1-nikunj@amd.com> References: <20240731150811.156771-1-nikunj@amd.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS3PEPF0000C381:EE_|PH7PR12MB5758:EE_ X-MS-Office365-Filtering-Correlation-Id: 3e9388f3-b99d-4fb6-e4f3-08dcb172b4be X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|1800799024|376014|7416014|82310400026; X-Microsoft-Antispam-Message-Info: einwppbntHhdovf2ArFPvQuwVyTIciAIyEK6VLjRqiL6ZwMDlPKvhbgv2HLAhcxuaGQuntuumERFE3+ekI4Imo6SmcNB+VCoTCLQFXD03EMM5xVu6nQtUFLR6Sp+klHCfIxNx4X8Sn1Dqb0ZuGEFPiU51706OrarmOciR/e79md23MBfv2sWBPv7Kji210e/W6j+QtwVCpw2Z08TJvKIABzOExO8rmAO8mESV7o7pHM1y4Y7VjOf+ySsy5sQcQjYZh05RRP+EpGOKlYCZEhei9MpzCH1WiRr0DPSTyglurf9MyIp8ZAXvIx1cz7LDSLuFfM+NsGyRcIeHBweqcnl4xTsQBAPsxehMaD0TEKNQnJm44L2Cp360IbP33lsGyKoxwNpcCCYd+H9agGnb6c2atvNqTrvvoubZyNUFYzfuptqos3mCH2mbtBw7y5PuwlKnjizgQfgAcJI1EZfw7sABluVVXoH7i3DH2seMpfx/JZ1xFtwEnf4p1sBy+mo99sHtN72cGOTRZ6OSzUBmTevy/g/bDIoeb5KH7BffjMMl/npk/gvXhbs+B0j3OlCgb55a05nIOwBU6zNlMEj+YCmGTNv6il4DDy4rJ1jMqpp7QQt3dZiJ/g0xT4ewFfFPqVN1ZxypE+fH++JCdy0SZh+eo2PAFtzEnXQ7/ND0uuzGf/8E5wpIFldR7QQ2oHKJzfH7tJKCMjGEwhgjSFAtQlkho2D4r/unYPzx5+t/wcPjb33ujgKXxp0sFqu+WNTTavQRuN92rgznCHARer4laaed66UiNUhSXyFXc2dIGrZ6Wu+HYiyxPDkyUCAqZUcztCgteBA950WKiz4DhOlFZuNWIKg1HET0cXmNEqokTyNw17G/g6X4klvQwdJrFNelaivLvZkdZnQay3lxaLhcudeMZr23t23U/QXviYqlYp1NucdVVgjAZIweP9AtXsfIpAFX9w9VD686KbFeeJl7uAMd2nGVpfL0t1E+z3zmQ3hK00wiFojoYRRF8GUxV0wiDqSSO8upghIbXM6YqUKG/bJjTvqES2zvr6YWUaiAecIVqryxHNuLlT6XPo2Ff0ewta55RBVG7lIEHPuC26kUVr/BQVT53aRk5l3E1nURgp5OPiTbZ/j3rxwz0I+li6GYxEflOJL0sqgpMn5bCz20VcMYsqJY/Miw1P540b2pizE8FARqyYQPjWnxx03JHhxGgS6buKufF5huKkbgkjv1LsH8Jt+JHoGw9ENEvE/aKsapgfRlYz4MVni4ZsKsOlK3mje4wQxjAv+0D6GuJlz0VbxZ9jlQqNSosWyKoHuPm83uiot23E9y6rXfShRf/iATn42wWe7OlpUyBB4howyHh5pGbNt/2j5UC9VBeWah9nZ1hbh8qPOnH/xvZbot7SEPeOL2Wg7oKpI5uZPikhzxyil3Zt0z+7UxHfMnpTaCgIHSvz7kA25CuF41NbnZ4lHFmQM X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(36860700013)(1800799024)(376014)(7416014)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Jul 2024 15:08:59.5471 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3e9388f3-b99d-4fb6-e4f3-08dcb172b4be X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: DS3PEPF0000C381.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB5758 Add a snp_guest_req structure to eliminate the need to pass a long list of parameters. This structure will be used to call the SNP Guest message request API, simplifying the function arguments. Update the snp_issue_guest_request() prototype to include the new guest request structure. Signed-off-by: Nikunj A Dadhania Reviewed-by: Tom Lendacky --- arch/x86/include/asm/sev.h | 19 +++++++- arch/x86/coco/sev/core.c | 9 ++-- drivers/virt/coco/sev-guest/sev-guest.c | 62 ++++++++++++++++--------- 3 files changed, 61 insertions(+), 29 deletions(-) diff --git a/arch/x86/include/asm/sev.h b/arch/x86/include/asm/sev.h index e7977f76d77e..27fa1c9c3465 100644 --- a/arch/x86/include/asm/sev.h +++ b/arch/x86/include/asm/sev.h @@ -174,6 +174,19 @@ struct sev_guest_platform_data { u64 secrets_gpa; }; +struct snp_guest_req { + void *req_buf; + size_t req_sz; + + void *resp_buf; + size_t resp_sz; + + u64 exit_code; + unsigned int vmpck_id; + u8 msg_version; + u8 msg_type; +}; + /* * The secrets page contains 96-bytes of reserved field that can be used by * the guest OS. The guest OS uses the area to save the message sequence @@ -395,7 +408,8 @@ void snp_set_wakeup_secondary_cpu(void); bool snp_init(struct boot_params *bp); void __noreturn snp_abort(void); void snp_dmi_setup(void); -int snp_issue_guest_request(u64 exit_code, struct snp_req_data *input, struct snp_guest_request_ioctl *rio); +int snp_issue_guest_request(struct snp_guest_req *req, struct snp_req_data *input, + struct snp_guest_request_ioctl *rio); int snp_issue_svsm_attest_req(u64 call_id, struct svsm_call *call, struct svsm_attest_call *input); void snp_accept_memory(phys_addr_t start, phys_addr_t end); u64 snp_get_unsupported_features(u64 status); @@ -425,7 +439,8 @@ static inline void snp_set_wakeup_secondary_cpu(void) { } static inline bool snp_init(struct boot_params *bp) { return false; } static inline void snp_abort(void) { } static inline void snp_dmi_setup(void) { } -static inline int snp_issue_guest_request(u64 exit_code, struct snp_req_data *input, struct snp_guest_request_ioctl *rio) +static inline int snp_issue_guest_request(struct snp_guest_req *req, struct snp_req_data *input, + struct snp_guest_request_ioctl *rio) { return -ENOTTY; } diff --git a/arch/x86/coco/sev/core.c b/arch/x86/coco/sev/core.c index a0b64cfd4b8e..e6a3f3df4637 100644 --- a/arch/x86/coco/sev/core.c +++ b/arch/x86/coco/sev/core.c @@ -2417,7 +2417,8 @@ int snp_issue_svsm_attest_req(u64 call_id, struct svsm_call *call, } EXPORT_SYMBOL_GPL(snp_issue_svsm_attest_req); -int snp_issue_guest_request(u64 exit_code, struct snp_req_data *input, struct snp_guest_request_ioctl *rio) +int snp_issue_guest_request(struct snp_guest_req *req, struct snp_req_data *input, + struct snp_guest_request_ioctl *rio) { struct ghcb_state state; struct es_em_ctxt ctxt; @@ -2441,12 +2442,12 @@ int snp_issue_guest_request(u64 exit_code, struct snp_req_data *input, struct sn vc_ghcb_invalidate(ghcb); - if (exit_code == SVM_VMGEXIT_EXT_GUEST_REQUEST) { + if (req->exit_code == SVM_VMGEXIT_EXT_GUEST_REQUEST) { ghcb_set_rax(ghcb, input->data_gpa); ghcb_set_rbx(ghcb, input->data_npages); } - ret = sev_es_ghcb_hv_call(ghcb, &ctxt, exit_code, input->req_gpa, input->resp_gpa); + ret = sev_es_ghcb_hv_call(ghcb, &ctxt, req->exit_code, input->req_gpa, input->resp_gpa); if (ret) goto e_put; @@ -2461,7 +2462,7 @@ int snp_issue_guest_request(u64 exit_code, struct snp_req_data *input, struct sn case SNP_GUEST_VMM_ERR(SNP_GUEST_VMM_ERR_INVALID_LEN): /* Number of expected pages are returned in RBX */ - if (exit_code == SVM_VMGEXIT_EXT_GUEST_REQUEST) { + if (req->exit_code == SVM_VMGEXIT_EXT_GUEST_REQUEST) { input->data_npages = ghcb_get_rbx(ghcb); ret = -ENOSPC; break; diff --git a/drivers/virt/coco/sev-guest/sev-guest.c b/drivers/virt/coco/sev-guest/sev-guest.c index 39d90dd0b012..92734a2345a6 100644 --- a/drivers/virt/coco/sev-guest/sev-guest.c +++ b/drivers/virt/coco/sev-guest/sev-guest.c @@ -177,7 +177,7 @@ static struct aesgcm_ctx *snp_init_crypto(u8 *key, size_t keylen) return ctx; } -static int verify_and_dec_payload(struct snp_guest_dev *snp_dev, void *payload, u32 sz) +static int verify_and_dec_payload(struct snp_guest_dev *snp_dev, struct snp_guest_req *req) { struct snp_guest_msg *resp_msg = &snp_dev->secret_response; struct snp_guest_msg *req_msg = &snp_dev->secret_request; @@ -206,20 +206,19 @@ static int verify_and_dec_payload(struct snp_guest_dev *snp_dev, void *payload, * If the message size is greater than our buffer length then return * an error. */ - if (unlikely((resp_msg_hdr->msg_sz + ctx->authsize) > sz)) + if (unlikely((resp_msg_hdr->msg_sz + ctx->authsize) > req->resp_sz)) return -EBADMSG; /* Decrypt the payload */ memcpy(iv, &resp_msg_hdr->msg_seqno, min(sizeof(iv), sizeof(resp_msg_hdr->msg_seqno))); - if (!aesgcm_decrypt(ctx, payload, resp_msg->payload, resp_msg_hdr->msg_sz, + if (!aesgcm_decrypt(ctx, req->resp_buf, resp_msg->payload, resp_msg_hdr->msg_sz, &resp_msg_hdr->algo, AAD_LEN, iv, resp_msg_hdr->authtag)) return -EBADMSG; return 0; } -static int enc_payload(struct snp_guest_dev *snp_dev, u64 seqno, int version, u8 type, - void *payload, size_t sz) +static int enc_payload(struct snp_guest_dev *snp_dev, u64 seqno, struct snp_guest_req *req) { struct snp_guest_msg *msg = &snp_dev->secret_request; struct snp_guest_msg_hdr *hdr = &msg->hdr; @@ -231,11 +230,11 @@ static int enc_payload(struct snp_guest_dev *snp_dev, u64 seqno, int version, u8 hdr->algo = SNP_AEAD_AES_256_GCM; hdr->hdr_version = MSG_HDR_VER; hdr->hdr_sz = sizeof(*hdr); - hdr->msg_type = type; - hdr->msg_version = version; + hdr->msg_type = req->msg_type; + hdr->msg_version = req->msg_version; hdr->msg_seqno = seqno; - hdr->msg_vmpck = vmpck_id; - hdr->msg_sz = sz; + hdr->msg_vmpck = req->vmpck_id; + hdr->msg_sz = req->req_sz; /* Verify the sequence number is non-zero */ if (!hdr->msg_seqno) @@ -244,17 +243,17 @@ static int enc_payload(struct snp_guest_dev *snp_dev, u64 seqno, int version, u8 pr_debug("request [seqno %lld type %d version %d sz %d]\n", hdr->msg_seqno, hdr->msg_type, hdr->msg_version, hdr->msg_sz); - if (WARN_ON((sz + ctx->authsize) > sizeof(msg->payload))) + if (WARN_ON((req->req_sz + ctx->authsize) > sizeof(msg->payload))) return -EBADMSG; memcpy(iv, &hdr->msg_seqno, min(sizeof(iv), sizeof(hdr->msg_seqno))); - aesgcm_encrypt(ctx, msg->payload, payload, sz, &hdr->algo, AAD_LEN, - iv, hdr->authtag); + aesgcm_encrypt(ctx, msg->payload, req->req_buf, req->req_sz, &hdr->algo, + AAD_LEN, iv, hdr->authtag); return 0; } -static int __handle_guest_request(struct snp_guest_dev *snp_dev, u64 exit_code, +static int __handle_guest_request(struct snp_guest_dev *snp_dev, struct snp_guest_req *req, struct snp_guest_request_ioctl *rio) { unsigned long req_start = jiffies; @@ -269,7 +268,7 @@ static int __handle_guest_request(struct snp_guest_dev *snp_dev, u64 exit_code, * sequence number must be incremented or the VMPCK must be deleted to * prevent reuse of the IV. */ - rc = snp_issue_guest_request(exit_code, &snp_dev->input, rio); + rc = snp_issue_guest_request(req, &snp_dev->input, rio); switch (rc) { case -ENOSPC: /* @@ -280,7 +279,7 @@ static int __handle_guest_request(struct snp_guest_dev *snp_dev, u64 exit_code, * IV reuse. */ override_npages = snp_dev->input.data_npages; - exit_code = SVM_VMGEXIT_GUEST_REQUEST; + req->exit_code = SVM_VMGEXIT_GUEST_REQUEST; /* * Override the error to inform callers the given extended @@ -340,10 +339,8 @@ static int __handle_guest_request(struct snp_guest_dev *snp_dev, u64 exit_code, return rc; } -static int handle_guest_request(struct snp_guest_dev *snp_dev, u64 exit_code, - struct snp_guest_request_ioctl *rio, u8 type, - void *req_buf, size_t req_sz, void *resp_buf, - u32 resp_sz) +static int snp_send_guest_request(struct snp_guest_dev *snp_dev, struct snp_guest_req *req, + struct snp_guest_request_ioctl *rio) { u64 seqno; int rc; @@ -357,7 +354,7 @@ static int handle_guest_request(struct snp_guest_dev *snp_dev, u64 exit_code, memset(snp_dev->response, 0, sizeof(struct snp_guest_msg)); /* Encrypt the userspace provided payload in snp_dev->secret_request. */ - rc = enc_payload(snp_dev, seqno, rio->msg_version, type, req_buf, req_sz); + rc = enc_payload(snp_dev, seqno, req); if (rc) return rc; @@ -368,7 +365,7 @@ static int handle_guest_request(struct snp_guest_dev *snp_dev, u64 exit_code, memcpy(snp_dev->request, &snp_dev->secret_request, sizeof(snp_dev->secret_request)); - rc = __handle_guest_request(snp_dev, exit_code, rio); + rc = __handle_guest_request(snp_dev, req, rio); if (rc) { if (rc == -EIO && rio->exitinfo2 == SNP_GUEST_VMM_ERR(SNP_GUEST_VMM_ERR_INVALID_LEN)) @@ -382,7 +379,7 @@ static int handle_guest_request(struct snp_guest_dev *snp_dev, u64 exit_code, return rc; } - rc = verify_and_dec_payload(snp_dev, resp_buf, resp_sz); + rc = verify_and_dec_payload(snp_dev, req); if (rc) { dev_alert(snp_dev->dev, "Detected unexpected decode failure from ASP. rc: %d\n", rc); snp_disable_vmpck(snp_dev); @@ -392,6 +389,25 @@ static int handle_guest_request(struct snp_guest_dev *snp_dev, u64 exit_code, return 0; } +static int handle_guest_request(struct snp_guest_dev *snp_dev, u64 exit_code, + struct snp_guest_request_ioctl *rio, u8 type, + void *req_buf, size_t req_sz, void *resp_buf, + u32 resp_sz) +{ + struct snp_guest_req req = { + .msg_version = rio->msg_version, + .msg_type = type, + .vmpck_id = vmpck_id, + .req_buf = req_buf, + .req_sz = req_sz, + .resp_buf = resp_buf, + .resp_sz = resp_sz, + .exit_code = exit_code, + }; + + return snp_send_guest_request(snp_dev, &req, rio); +} + struct snp_req_resp { sockptr_t req_data; sockptr_t resp_data; @@ -1058,7 +1074,7 @@ static int __init sev_guest_probe(struct platform_device *pdev) misc->name = DEVICE_NAME; misc->fops = &snp_guest_fops; - /* initial the input address for guest request */ + /* Initialize the input addresses for guest request */ snp_dev->input.req_gpa = __pa(snp_dev->request); snp_dev->input.resp_gpa = __pa(snp_dev->response); snp_dev->input.data_gpa = __pa(snp_dev->certs_data); From patchwork Wed Jul 31 15:08:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Nikunj A. Dadhania" X-Patchwork-Id: 13748886 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2080.outbound.protection.outlook.com [40.107.94.80]) (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 344DD1BE87E; Wed, 31 Jul 2024 15:09:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.94.80 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722438549; cv=fail; b=CreYpmTC08oNHwntei6rFhY5XbdQ2bqvmI7fn8iQOylc4xyCaVGCrWquEI2jsqYEPxGAxmnC730nFhcVWTAZkdRpa8rA6Wsmpe/os0Ks6Q+qA5RJzsvwq5pihq19j1LCPkPP6qRh+QFU4yrU3Wficw550t2ybwLsJZyH2XhXuLA= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722438549; c=relaxed/simple; bh=873UYNPs74NRbebFgGrFHaJvV2TXQGX4q+s5REb44so=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=H/25k88cscxZJvF2AdgCAQ5viaIGXVIkOW2KTginnMKwCvgLkyNgbt+ajJ99+k7tmItTXYxbRdZ6Mvm0v6x+WLjo9CcaiuEP10084ZFvAxb5yY98ZYrUoCWHTY0i/sW97SA7X2zLzvW+BaqPm3yUyd4k+3OW5Iygr+irIgaRhME= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=4M/0uwPr; arc=fail smtp.client-ip=40.107.94.80 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="4M/0uwPr" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=U50HkV29J8wjVi+j6NxS1wWd9QyPOt7iNtKRqfgKOki8CasrXtxC1APnEBA6NcsR8ti5GXrf50xYp+DARE0wclrCRN59F4uzAk73OegGFzoodPUs+PB+lgoHFy+QC6+gldGeVtTnShN6CBb2tllspd3yqQi2yayWe47nQqkvESPqHC6dtvTZjwuBiHzrV/lTRKMwK9nRfVWtGMmT9VHSVsLW3WOB61U6XXFl9aNxcseW4OJw527pNGzoeXOjA54mkHRnXhba5YBG4PEJCL6SXk8HoGqKtwI9oxjz1sGX+Psmh0OVvOlvtRcuSkkpeQMEI43gLBd6+1hKoOTUBL37MA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=+6Vfup39AQ2zzjj9KaUPtqjrlhiyTaZ2dG5/4SdAdJA=; b=fFfatpRxVjwJQUKDna875BKzFGxnhqU6H6mFAyuz0w5uDoIMhYLL6moS8tSQBj/xUj7VnIG5+AK/Cw1FLibysxVS75z6m3g0rnttVklfZdVvlN251ijZePN3f0p7mkp94pX9wvmCoa2I5GgbvnD7XRTehSNJBQuE7FKWVzib2E/cQxvjpMhCi3NXwxKRSkqUEX633oEN1B3jpUQzdPPGka+2trm1FgxWl35c9xK9Bkp7iVNSeRnhoXfa6dWBf6vEoxQcRgsZqRUxKTADXgDA8PiJbMisxj3mLbCMm8pHJc0h0z2SOnvZBVh5v6WGoP62MkVIzrvNloBB7QThXIRCVA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=+6Vfup39AQ2zzjj9KaUPtqjrlhiyTaZ2dG5/4SdAdJA=; b=4M/0uwPrl/qHlHCzhR/F88WPCd+IXtGlqiVbfxEn60BS85ZfoKJTr4gObh5fpwikJ1S2v0edqokihCBvtmocEXEA+A4PQ8mN37OEZS2Ahl1pH1Kl6OE8j79+nBDBudtbwM1oG3TIV1fWHeZJxeN9KsnERyEjeoAPxR2hxtnTGLo= Received: from DM6PR07CA0050.namprd07.prod.outlook.com (2603:10b6:5:74::27) by DS0PR12MB6416.namprd12.prod.outlook.com (2603:10b6:8:cb::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7807.28; Wed, 31 Jul 2024 15:09:03 +0000 Received: from DS3PEPF0000C37C.namprd04.prod.outlook.com (2603:10b6:5:74:cafe::4b) by DM6PR07CA0050.outlook.office365.com (2603:10b6:5:74::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7784.34 via Frontend Transport; Wed, 31 Jul 2024 15:09:03 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by DS3PEPF0000C37C.mail.protection.outlook.com (10.167.23.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7828.19 via Frontend Transport; Wed, 31 Jul 2024 15:09:03 +0000 Received: from gomati.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Wed, 31 Jul 2024 10:08:59 -0500 From: Nikunj A Dadhania To: , , , , CC: , , , , , , Subject: [PATCH v11 09/20] virt: sev-guest: Reduce the scope of SNP command mutex Date: Wed, 31 Jul 2024 20:38:00 +0530 Message-ID: <20240731150811.156771-10-nikunj@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240731150811.156771-1-nikunj@amd.com> References: <20240731150811.156771-1-nikunj@amd.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS3PEPF0000C37C:EE_|DS0PR12MB6416:EE_ X-MS-Office365-Filtering-Correlation-Id: d499e578-977c-4e0c-3a9c-08dcb172b705 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|36860700013|1800799024|376014|7416014; X-Microsoft-Antispam-Message-Info: L4dmwp/FftzVrqPwjSZR0nKXGCbVbsrQZR6BV0OfWk7Kd55nRPN3txRnu+ixshuN35/HdjpQz4vp+rPa8MPCQG/2maXge1DakZYw+AGO1PMoFaJ4/ObvZYSq2NOMpUI1SaS7ec48ZlLicgclSXz/FpFGCtryEaomDrXdqbe9bgUiPa4PUh+CcZnben3glC3WiHccOgjx/e8xbJ6b05PRAk0dQ7KL4CI628mp4TscnBSbUHjz443tcQvN95fVTpiITjuaRe3YCaBGDR+Chyhlc6+1jpzZ0lxydMXwasGQYwBtXxxFzPoczVeARjST31WDXoccL4feTTPsfjUpRWPurdDnQ0wICMKWbvcPU6z8LsNI0rcLEWwG9XiBkq+4KB5AQFbib1zgmIm1ktX65pi7/EYTVD58+IaYCiHxkXAjdABm+5oDM7WR2bzC+k7eixBFPWehczNbjrMPMBclXk46312UqyRcii+or4ZDP/uBVZXpgnm+LTdyVOHChurqMNQ2ngSizMEyRt8L/S6q9rKQK+xaFPtLfHVOhFErGtAj3JmZG8FfFNECwhg48me1AvyGmXSySD8thrv722+0odgNG8LAJRM4W80zmxKIPqPF2g5HDE3ApBPTUqsYBDgmQMUGsR+N2LU619+myY2oILaZxg6ji5Fmqs8zM+Ks0Pl78TdyYbZOwcZbp1k/8zr/FIU5xTg7kGR25wmVKqya1nwOoHp7dfQI7XwSptiIhyq2yW48cLg9LuatL1ZiNwpPVaHChtAPelzsh6cC1TqttjawNS9EYULxs0gL4I3/8yyV547d1QDKJ//k2SttwSqwfzjg79nLlvn1kCv6V9okOqGrd+BquC44Lv0mg0hVsCeyy8Fz+ObCISKV0szIW2ZNUVgvzHmU66dHhTfA/Z4WzQXIEjzYLueq9sSHOc4CyyenIPdny/gzxzSuIiPw4SfgA3g10WhQTUNEVqJCybIqMnVxOh4HTWEhC5fGJFpE+ol9lnU0AZ+e7AS2I46caVwkaZV/7A5T8g+ItX44XLurHHd2eda4b+dsvXvGYEOSN/QAtZSev4izsaJ3+BXykCG+pP5WpFG/VoaAlh68qyp6y1pc/kQwmMBOsQODMBYDJEIA+IFzFNURWP1DENuJjO1XdEiShGtT+0htY9boP8KsYWUKJMsPoQd8oGdwYqowyfO33z57JEbjGktuuh/Vcdq/bvfYYSvNw5i+XsaCR5faRa/bO6zaZnjC2SdVwbf094Ddn9HuE7xA17HRMNm7U/bbO7ndCnfyl3NkFH8t6tDR2rAlgKPWSlOwyTUZy2yVwKmpqpYDBZHT457PJ251KDS/wnRuFzpX0jdeLH9Y2gmdB3iXjE985DKH0zpiGFsJfRt1ADhK/9SEYTx9e65+ecSQOMzn2vWARda77hi2eXE23U/OFatbZ+Z3mIT5HTDY2oD9ljLO/k/YMUGG64rxXlqrQHLx X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(82310400026)(36860700013)(1800799024)(376014)(7416014);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Jul 2024 15:09:03.3635 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d499e578-977c-4e0c-3a9c-08dcb172b705 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: DS3PEPF0000C37C.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB6416 The SNP command mutex is used to serialize access to the shared buffer, command handling, and message sequence number. All shared buffer, command handling, and message sequence updates are done within snp_send_guest_request(), so moving the mutex to this function is appropriate and maintains the critical section. Since the mutex is now taken at a later point in time, remove the lockdep checks that occur before taking the mutex. Signed-off-by: Nikunj A Dadhania --- drivers/virt/coco/sev-guest/sev-guest.c | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/drivers/virt/coco/sev-guest/sev-guest.c b/drivers/virt/coco/sev-guest/sev-guest.c index 92734a2345a6..42f7126f1718 100644 --- a/drivers/virt/coco/sev-guest/sev-guest.c +++ b/drivers/virt/coco/sev-guest/sev-guest.c @@ -345,6 +345,8 @@ static int snp_send_guest_request(struct snp_guest_dev *snp_dev, struct snp_gues u64 seqno; int rc; + guard(mutex)(&snp_cmd_mutex); + /* Get message sequence and verify that its a non-zero */ seqno = snp_get_msg_seqno(snp_dev); if (!seqno) @@ -419,8 +421,6 @@ static int get_report(struct snp_guest_dev *snp_dev, struct snp_guest_request_io struct snp_report_resp *report_resp; int rc, resp_len; - lockdep_assert_held(&snp_cmd_mutex); - if (!arg->req_data || !arg->resp_data) return -EINVAL; @@ -458,8 +458,6 @@ static int get_derived_key(struct snp_guest_dev *snp_dev, struct snp_guest_reque /* Response data is 64 bytes and max authsize for GCM is 16 bytes. */ u8 buf[64 + 16]; - lockdep_assert_held(&snp_cmd_mutex); - if (!arg->req_data || !arg->resp_data) return -EINVAL; @@ -501,8 +499,6 @@ static int get_ext_report(struct snp_guest_dev *snp_dev, struct snp_guest_reques int ret, npages = 0, resp_len; sockptr_t certs_address; - lockdep_assert_held(&snp_cmd_mutex); - if (sockptr_is_null(io->req_data) || sockptr_is_null(io->resp_data)) return -EINVAL; @@ -590,12 +586,9 @@ static long snp_guest_ioctl(struct file *file, unsigned int ioctl, unsigned long if (!input.msg_version) return -EINVAL; - mutex_lock(&snp_cmd_mutex); - /* Check if the VMPCK is not empty */ if (is_vmpck_empty(snp_dev)) { dev_err_ratelimited(snp_dev->dev, "VMPCK is disabled\n"); - mutex_unlock(&snp_cmd_mutex); return -ENOTTY; } @@ -620,8 +613,6 @@ static long snp_guest_ioctl(struct file *file, unsigned int ioctl, unsigned long break; } - mutex_unlock(&snp_cmd_mutex); - if (input.exitinfo2 && copy_to_user(argp, &input, sizeof(input))) return -EFAULT; @@ -736,8 +727,6 @@ static int sev_svsm_report_new(struct tsm_report *report, void *data) man_len = SZ_4K; certs_len = SEV_FW_BLOB_MAX_SIZE; - guard(mutex)(&snp_cmd_mutex); - if (guid_is_null(&desc->service_guid)) { call_id = SVSM_ATTEST_CALL(SVSM_ATTEST_SERVICES); } else { @@ -872,8 +861,6 @@ static int sev_report_new(struct tsm_report *report, void *data) if (!buf) return -ENOMEM; - guard(mutex)(&snp_cmd_mutex); - /* Check if the VMPCK is not empty */ if (is_vmpck_empty(snp_dev)) { dev_err_ratelimited(snp_dev->dev, "VMPCK is disabled\n"); From patchwork Wed Jul 31 15:08:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Nikunj A. Dadhania" X-Patchwork-Id: 13748887 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2078.outbound.protection.outlook.com [40.107.94.78]) (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 395D91BF32D; Wed, 31 Jul 2024 15:09:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.94.78 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722438555; cv=fail; b=VSOQXSUA5a/pVBetm2zF04kCynOqJXB7KM8o5kK7K2VRXRq4hzXARtiBKfKQcs2QRbjI2lW6NxS8mwpuzhnLSE64ZSZ/Mof+k9ymVGAqHaTExdCaEh0BaqsogC96qEdhwKVetk0PhLxYmwDzoUdQHBpArBg0hlcR180saJYi65s= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722438555; c=relaxed/simple; bh=rxCYyydYurEGQ452jDl2JXd3rWp6Rk52l2zHhsMneyM=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=KqAM/cLzEcEilSnYNf0lD64uvHIlImq+eQHbITBhEhZzwCAvWyHVbiN9scZ/r7Vjn2PaiXGj7zYvgZ4JWXbGPtI47Tc9B147GEol785Z+CiDQQQlS+qHK/2cvh2t3z9SUY/Ujhubs8FBMUDqZn1SjFV6hx9U44nmnX0J0nsJkcc= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=jigwKcfX; arc=fail smtp.client-ip=40.107.94.78 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="jigwKcfX" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=UMFfUGbUhEyXzKTETtAOdFewQDpu98u0C0WCj147lefHNkgy5Yyeq0PEc91fvI4Sy1eUOLtzTiDnH00qe93sMgzqMtjthVuJlm759OqieBJZQ2wsKglc2yKymq0jBierop2JUdjz0ETtp8FLzjB6+olOBfafwo9vyY1nGYPbTXemQq2eK8MIo2zVdAFhANeuU5g7klS1yAUITOq0JlDKo51pD51Aqow1Rn6IvpObBJ+XMA/A0Sl3eqikrr5vsHZtTlxlSSTW6P0nR1U4bcEeWe6yPFKgdI9FkjfknLc+yLeCmSjK6Rr7KH//EG1crY8lMVcDRjUyjdYSTNsXoxuOhw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=8XxOGg4Vub8SIqF4B9jWB+UnotZ7bk4T7E34wGTTAs8=; b=rrMjS6AwUt5Jip8VpJ/W6vGTXjFyKBForS6eB2sLoCoUZWBEnB+POtS7DLXODHDVKkktjU6tBRnYSFGHm6MnRm5O5NoAjKt1u21A5EYHfmgWMF5lVcIe60g2y5j6DqHoscyHVSFVUWYxa+Y+7BoV7LDK62YribHqVnXLvXsDbJ9UnAsLuT5tm6mIo6PUZcH87x/cxYPQSlpmq9jd/5VIeQJzn5VCgHgrzMT0IFXEJDs06e478Cgz2ORKUfW6u/aEWDVgikbLG/fgWNZ86yBxS4ybzQObOBQ94ExegIup/Tz8Cwq3Zf3w2/oh0s0mg2Plcwfq/WLyu5fzBaS9f9Oyjw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=8XxOGg4Vub8SIqF4B9jWB+UnotZ7bk4T7E34wGTTAs8=; b=jigwKcfXsdPBbaIy8mc4jHeSwFPTDevxg+Vw0f5Knj2ogIqp8zSurK46NQa9whhQ92Qb1fTlQeKAUe3LWQsTwSKht+p34IjJMM9L/aua4kVVtSSf9bXdLtdcymB7a4VDNAO1TSMxEF8tJreMQTwK6I3sNY8WD9+BhE7hfd4poAw= Received: from CH0P223CA0002.NAMP223.PROD.OUTLOOK.COM (2603:10b6:610:116::21) by DS0PR12MB6437.namprd12.prod.outlook.com (2603:10b6:8:cb::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7828.21; Wed, 31 Jul 2024 15:09:09 +0000 Received: from DS3PEPF0000C37B.namprd04.prod.outlook.com (2603:10b6:610:116:cafe::1b) by CH0P223CA0002.outlook.office365.com (2603:10b6:610:116::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7784.34 via Frontend Transport; Wed, 31 Jul 2024 15:09:09 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by DS3PEPF0000C37B.mail.protection.outlook.com (10.167.23.5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7828.19 via Frontend Transport; Wed, 31 Jul 2024 15:09:09 +0000 Received: from gomati.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Wed, 31 Jul 2024 10:09:02 -0500 From: Nikunj A Dadhania To: , , , , CC: , , , , , , Subject: [PATCH v11 10/20] virt: sev-guest: Carve out SNP message context structure Date: Wed, 31 Jul 2024 20:38:01 +0530 Message-ID: <20240731150811.156771-11-nikunj@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240731150811.156771-1-nikunj@amd.com> References: <20240731150811.156771-1-nikunj@amd.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS3PEPF0000C37B:EE_|DS0PR12MB6437:EE_ X-MS-Office365-Filtering-Correlation-Id: 90a359ec-906e-4648-4117-08dcb172ba82 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|376014|7416014|1800799024|36860700013; X-Microsoft-Antispam-Message-Info: y0K48bHlhKtJHczgzSy7q772uUd5plnt2L/NxWiCCmtfZglZdygV5R6Clnd11B9oyhL1U1qbR3oU34iCHfoV5i8TC1cSIl0KdvONMvZbnTtndd2gi+v0aoLfEtKVrkrZX2RMibvAvmmI5TBIHQdnN3ngiC93xFg36Hfn8MAGFYBbiBjeCL91wjDWNyNElen0LIdM36YmDjn0PRKPB+n6PERRu22tzxBQFB293AI7Xrc1U3bjp99SE1WhZoJkMcPyMnOQl7XK8np/SGFZLoml+j7OxxfyxghfrRBFadKB3m4Rq1vYyR6oF2JOAHX5iBn1AkVvGWmandDyOEd6LfmAwVHFpgEb0WXsRNb/UoJZqVMRwB9CB5+zoe4JAuKecrppnMZaiqYy63fIn8awGFDSdIOZIuCrEzL7yV905sMJpXjoryMxtBKn42mur7XkMTm7qBIUo3EmAdb8kiWMhbmQT+Xm9ngL+HjS0pnzlMRHif3HIIJM27vcLN+WHh8aKewyWQF2s2KmKAz3qJvOTlC2L/Gf7z6Uep8ojDmcWyhOoglffEriquS5PZzzUY8ncESVzeM1AyLgx4e+8WiwyHm0TKH9HrI33nG7x3XaJ3f7m9/k5qoxq8JBdU2lqjer/+4ObP805K00uzNCq/GSKFgrdkFtvtp9WlVKM2O/ldUE4ko2aJwCXt2XJABoGlWS76zxGF20CrxSvZ/Ti5J43wu19MUDVzlPTMwdKnXmZ6OaFCn0XnED2w3QZgRRXsOwP2VtktRV4688CmhRg6V4ThudD3aOSpWB0xL1gFJvng7AIGR9IQgCKiZhi2lT3Gy84Mzp1hCo1+kKdEGyycJTuGQjgrXMFPgInsvY2Ce20R5LbxtU+PhHPvMUurtzg0BywCciu6mrPe25mILQif1DlJ2xqa7SRxxvkRDmFUNawqaUsFz/Zoa0hYgIQeginc+2Q70f+LqPNnsZCgbttqkVhl5nBjtKgjN+K1OX5x8Q61GF8LekhX0ve1Cr5uKXlO+JI/CDs79RvtYEWyUsuAPEVOKk1VyCQuDVQ+3bUj+sC/tIGADeQFbD0PgMQIXDT50TSu1wWtqXedzpinCiyc4CabqElMzpUCPSyk/bGcdLoWaemmtvQHFXf2X1xi1tM2rcSCtMaOj7xzkHzLJa8R0i0cJPkvsVfaZyXoPUx7AKuOW7Qoc0r7PvkUSCJ2GpUSl4cZSUS81uEITreXi2g2A2QvkcCcFp2l4ubHCwuo7jNT+/Mka4i7bvE8QTz6TbptOyXmhfne/zt5FUOauo7SjhLpIS3H9btuZzKTF9YZ2i1YBDDfdJrGa+ckHjMRKyRIK0JRYuzYLr2kyS8eccpnT3qPFiprVaaw9LKtPVtsWoFeHJ8Anz0ASjatFXUUrqsj2lePl7I48W/VKkbGw4lQi+O+FwHgrKfpdL+fYjughyJsppe99cXL+E3rW8sq0iBLd5AYIA X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(82310400026)(376014)(7416014)(1800799024)(36860700013);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Jul 2024 15:09:09.2160 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 90a359ec-906e-4648-4117-08dcb172ba82 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: DS3PEPF0000C37B.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB6437 Currently, the sev-guest driver is the only user of SNP guest messaging. snp_guest_dev structure holds all the allocated buffers, secrets page and VMPCK details. In preparation of adding messaging allocation and initialization APIs, decouple snp_guest_dev from messaging-related information by carving out guest message context structure(snp_msg_desc). Incorporate this newly added context into snp_send_guest_request() and all related functions, replacing the use of the snp_guest_dev. No functional change. Signed-off-by: Nikunj A Dadhania Reviewed-by: Tom Lendacky --- arch/x86/include/asm/sev.h | 21 +++ drivers/virt/coco/sev-guest/sev-guest.c | 183 ++++++++++++------------ 2 files changed, 111 insertions(+), 93 deletions(-) diff --git a/arch/x86/include/asm/sev.h b/arch/x86/include/asm/sev.h index 27fa1c9c3465..2e49c4a9e7fe 100644 --- a/arch/x86/include/asm/sev.h +++ b/arch/x86/include/asm/sev.h @@ -234,6 +234,27 @@ struct snp_secrets_page { u8 rsvd4[3744]; } __packed; +struct snp_msg_desc { + /* request and response are in unencrypted memory */ + struct snp_guest_msg *request, *response; + + /* + * Avoid information leakage by double-buffering shared messages + * in fields that are in regular encrypted memory. + */ + struct snp_guest_msg secret_request, secret_response; + + struct snp_secrets_page *secrets; + struct snp_req_data input; + + void *certs_data; + + struct aesgcm_ctx *ctx; + + u32 *os_area_msg_seqno; + u8 *vmpck; +}; + /* * The SVSM Calling Area (CA) related structures. */ diff --git a/drivers/virt/coco/sev-guest/sev-guest.c b/drivers/virt/coco/sev-guest/sev-guest.c index 42f7126f1718..38ddabcd7ba3 100644 --- a/drivers/virt/coco/sev-guest/sev-guest.c +++ b/drivers/virt/coco/sev-guest/sev-guest.c @@ -40,26 +40,13 @@ struct snp_guest_dev { struct device *dev; struct miscdevice misc; - void *certs_data; - struct aesgcm_ctx *ctx; - /* request and response are in unencrypted memory */ - struct snp_guest_msg *request, *response; - - /* - * Avoid information leakage by double-buffering shared messages - * in fields that are in regular encrypted memory. - */ - struct snp_guest_msg secret_request, secret_response; + struct snp_msg_desc *msg_desc; - struct snp_secrets_page *secrets; - struct snp_req_data input; union { struct snp_report_req report; struct snp_derived_key_req derived_key; struct snp_ext_report_req ext_report; } req; - u32 *os_area_msg_seqno; - u8 *vmpck; }; /* @@ -76,12 +63,12 @@ MODULE_PARM_DESC(vmpck_id, "The VMPCK ID to use when communicating with the PSP. /* Mutex to serialize the shared buffer access and command handling. */ static DEFINE_MUTEX(snp_cmd_mutex); -static bool is_vmpck_empty(struct snp_guest_dev *snp_dev) +static bool is_vmpck_empty(struct snp_msg_desc *mdesc) { char zero_key[VMPCK_KEY_LEN] = {0}; - if (snp_dev->vmpck) - return !memcmp(snp_dev->vmpck, zero_key, VMPCK_KEY_LEN); + if (mdesc->vmpck) + return !memcmp(mdesc->vmpck, zero_key, VMPCK_KEY_LEN); return true; } @@ -103,30 +90,30 @@ static bool is_vmpck_empty(struct snp_guest_dev *snp_dev) * vulnerable. If the sequence number were incremented for a fresh IV the ASP * will reject the request. */ -static void snp_disable_vmpck(struct snp_guest_dev *snp_dev) +static void snp_disable_vmpck(struct snp_msg_desc *mdesc) { - dev_alert(snp_dev->dev, "Disabling VMPCK%d communication key to prevent IV reuse.\n", + pr_alert("Disabling VMPCK%d communication key to prevent IV reuse.\n", vmpck_id); - memzero_explicit(snp_dev->vmpck, VMPCK_KEY_LEN); - snp_dev->vmpck = NULL; + memzero_explicit(mdesc->vmpck, VMPCK_KEY_LEN); + mdesc->vmpck = NULL; } -static inline u64 __snp_get_msg_seqno(struct snp_guest_dev *snp_dev) +static inline u64 __snp_get_msg_seqno(struct snp_msg_desc *mdesc) { u64 count; lockdep_assert_held(&snp_cmd_mutex); /* Read the current message sequence counter from secrets pages */ - count = *snp_dev->os_area_msg_seqno; + count = *mdesc->os_area_msg_seqno; return count + 1; } /* Return a non-zero on success */ -static u64 snp_get_msg_seqno(struct snp_guest_dev *snp_dev) +static u64 snp_get_msg_seqno(struct snp_msg_desc *mdesc) { - u64 count = __snp_get_msg_seqno(snp_dev); + u64 count = __snp_get_msg_seqno(mdesc); /* * The message sequence counter for the SNP guest request is a 64-bit @@ -137,20 +124,20 @@ static u64 snp_get_msg_seqno(struct snp_guest_dev *snp_dev) * invalid number and will fail the message request. */ if (count >= UINT_MAX) { - dev_err(snp_dev->dev, "request message sequence counter overflow\n"); + pr_err("request message sequence counter overflow\n"); return 0; } return count; } -static void snp_inc_msg_seqno(struct snp_guest_dev *snp_dev) +static void snp_inc_msg_seqno(struct snp_msg_desc *mdesc) { /* * The counter is also incremented by the PSP, so increment it by 2 * and save in secrets page. */ - *snp_dev->os_area_msg_seqno += 2; + *mdesc->os_area_msg_seqno += 2; } static inline struct snp_guest_dev *to_snp_dev(struct file *file) @@ -177,13 +164,13 @@ static struct aesgcm_ctx *snp_init_crypto(u8 *key, size_t keylen) return ctx; } -static int verify_and_dec_payload(struct snp_guest_dev *snp_dev, struct snp_guest_req *req) +static int verify_and_dec_payload(struct snp_msg_desc *mdesc, struct snp_guest_req *req) { - struct snp_guest_msg *resp_msg = &snp_dev->secret_response; - struct snp_guest_msg *req_msg = &snp_dev->secret_request; + struct snp_guest_msg *resp_msg = &mdesc->secret_response; + struct snp_guest_msg *req_msg = &mdesc->secret_request; struct snp_guest_msg_hdr *req_msg_hdr = &req_msg->hdr; struct snp_guest_msg_hdr *resp_msg_hdr = &resp_msg->hdr; - struct aesgcm_ctx *ctx = snp_dev->ctx; + struct aesgcm_ctx *ctx = mdesc->ctx; u8 iv[GCM_AES_IV_SIZE] = {}; pr_debug("response [seqno %lld type %d version %d sz %d]\n", @@ -191,7 +178,7 @@ static int verify_and_dec_payload(struct snp_guest_dev *snp_dev, struct snp_gues resp_msg_hdr->msg_sz); /* Copy response from shared memory to encrypted memory. */ - memcpy(resp_msg, snp_dev->response, sizeof(*resp_msg)); + memcpy(resp_msg, mdesc->response, sizeof(*resp_msg)); /* Verify that the sequence counter is incremented by 1 */ if (unlikely(resp_msg_hdr->msg_seqno != (req_msg_hdr->msg_seqno + 1))) @@ -218,11 +205,11 @@ static int verify_and_dec_payload(struct snp_guest_dev *snp_dev, struct snp_gues return 0; } -static int enc_payload(struct snp_guest_dev *snp_dev, u64 seqno, struct snp_guest_req *req) +static int enc_payload(struct snp_msg_desc *mdesc, u64 seqno, struct snp_guest_req *req) { - struct snp_guest_msg *msg = &snp_dev->secret_request; + struct snp_guest_msg *msg = &mdesc->secret_request; struct snp_guest_msg_hdr *hdr = &msg->hdr; - struct aesgcm_ctx *ctx = snp_dev->ctx; + struct aesgcm_ctx *ctx = mdesc->ctx; u8 iv[GCM_AES_IV_SIZE] = {}; memset(msg, 0, sizeof(*msg)); @@ -253,7 +240,7 @@ static int enc_payload(struct snp_guest_dev *snp_dev, u64 seqno, struct snp_gues return 0; } -static int __handle_guest_request(struct snp_guest_dev *snp_dev, struct snp_guest_req *req, +static int __handle_guest_request(struct snp_msg_desc *mdesc, struct snp_guest_req *req, struct snp_guest_request_ioctl *rio) { unsigned long req_start = jiffies; @@ -268,7 +255,7 @@ static int __handle_guest_request(struct snp_guest_dev *snp_dev, struct snp_gues * sequence number must be incremented or the VMPCK must be deleted to * prevent reuse of the IV. */ - rc = snp_issue_guest_request(req, &snp_dev->input, rio); + rc = snp_issue_guest_request(req, &mdesc->input, rio); switch (rc) { case -ENOSPC: /* @@ -278,7 +265,7 @@ static int __handle_guest_request(struct snp_guest_dev *snp_dev, struct snp_gues * order to increment the sequence number and thus avoid * IV reuse. */ - override_npages = snp_dev->input.data_npages; + override_npages = mdesc->input.data_npages; req->exit_code = SVM_VMGEXIT_GUEST_REQUEST; /* @@ -318,7 +305,7 @@ static int __handle_guest_request(struct snp_guest_dev *snp_dev, struct snp_gues * structure and any failure will wipe the VMPCK, preventing further * use anyway. */ - snp_inc_msg_seqno(snp_dev); + snp_inc_msg_seqno(mdesc); if (override_err) { rio->exitinfo2 = override_err; @@ -334,12 +321,12 @@ static int __handle_guest_request(struct snp_guest_dev *snp_dev, struct snp_gues } if (override_npages) - snp_dev->input.data_npages = override_npages; + mdesc->input.data_npages = override_npages; return rc; } -static int snp_send_guest_request(struct snp_guest_dev *snp_dev, struct snp_guest_req *req, +static int snp_send_guest_request(struct snp_msg_desc *mdesc, struct snp_guest_req *req, struct snp_guest_request_ioctl *rio) { u64 seqno; @@ -348,15 +335,15 @@ static int snp_send_guest_request(struct snp_guest_dev *snp_dev, struct snp_gues guard(mutex)(&snp_cmd_mutex); /* Get message sequence and verify that its a non-zero */ - seqno = snp_get_msg_seqno(snp_dev); + seqno = snp_get_msg_seqno(mdesc); if (!seqno) return -EIO; /* Clear shared memory's response for the host to populate. */ - memset(snp_dev->response, 0, sizeof(struct snp_guest_msg)); + memset(mdesc->response, 0, sizeof(struct snp_guest_msg)); - /* Encrypt the userspace provided payload in snp_dev->secret_request. */ - rc = enc_payload(snp_dev, seqno, req); + /* Encrypt the userspace provided payload in mdesc->secret_request. */ + rc = enc_payload(mdesc, seqno, req); if (rc) return rc; @@ -364,34 +351,33 @@ static int snp_send_guest_request(struct snp_guest_dev *snp_dev, struct snp_gues * Write the fully encrypted request to the shared unencrypted * request page. */ - memcpy(snp_dev->request, &snp_dev->secret_request, - sizeof(snp_dev->secret_request)); + memcpy(mdesc->request, &mdesc->secret_request, + sizeof(mdesc->secret_request)); - rc = __handle_guest_request(snp_dev, req, rio); + rc = __handle_guest_request(mdesc, req, rio); if (rc) { if (rc == -EIO && rio->exitinfo2 == SNP_GUEST_VMM_ERR(SNP_GUEST_VMM_ERR_INVALID_LEN)) return rc; - dev_alert(snp_dev->dev, - "Detected error from ASP request. rc: %d, exitinfo2: 0x%llx\n", - rc, rio->exitinfo2); + pr_alert("Detected error from ASP request. rc: %d, exitinfo2: 0x%llx\n", + rc, rio->exitinfo2); - snp_disable_vmpck(snp_dev); + snp_disable_vmpck(mdesc); return rc; } - rc = verify_and_dec_payload(snp_dev, req); + rc = verify_and_dec_payload(mdesc, req); if (rc) { - dev_alert(snp_dev->dev, "Detected unexpected decode failure from ASP. rc: %d\n", rc); - snp_disable_vmpck(snp_dev); + pr_alert("Detected unexpected decode failure from ASP. rc: %d\n", rc); + snp_disable_vmpck(mdesc); return rc; } return 0; } -static int handle_guest_request(struct snp_guest_dev *snp_dev, u64 exit_code, +static int handle_guest_request(struct snp_msg_desc *mdesc, u64 exit_code, struct snp_guest_request_ioctl *rio, u8 type, void *req_buf, size_t req_sz, void *resp_buf, u32 resp_sz) @@ -407,7 +393,7 @@ static int handle_guest_request(struct snp_guest_dev *snp_dev, u64 exit_code, .exit_code = exit_code, }; - return snp_send_guest_request(snp_dev, &req, rio); + return snp_send_guest_request(mdesc, &req, rio); } struct snp_req_resp { @@ -418,6 +404,7 @@ struct snp_req_resp { static int get_report(struct snp_guest_dev *snp_dev, struct snp_guest_request_ioctl *arg) { struct snp_report_req *report_req = &snp_dev->req.report; + struct snp_msg_desc *mdesc = snp_dev->msg_desc; struct snp_report_resp *report_resp; int rc, resp_len; @@ -432,12 +419,12 @@ static int get_report(struct snp_guest_dev *snp_dev, struct snp_guest_request_io * response payload. Make sure that it has enough space to cover the * authtag. */ - resp_len = sizeof(report_resp->data) + snp_dev->ctx->authsize; + resp_len = sizeof(report_resp->data) + mdesc->ctx->authsize; report_resp = kzalloc(resp_len, GFP_KERNEL_ACCOUNT); if (!report_resp) return -ENOMEM; - rc = handle_guest_request(snp_dev, SVM_VMGEXIT_GUEST_REQUEST, arg, SNP_MSG_REPORT_REQ, + rc = handle_guest_request(mdesc, SVM_VMGEXIT_GUEST_REQUEST, arg, SNP_MSG_REPORT_REQ, report_req, sizeof(*report_req), report_resp->data, resp_len); if (rc) goto e_free; @@ -454,6 +441,7 @@ static int get_derived_key(struct snp_guest_dev *snp_dev, struct snp_guest_reque { struct snp_derived_key_req *derived_key_req = &snp_dev->req.derived_key; struct snp_derived_key_resp derived_key_resp = {0}; + struct snp_msg_desc *mdesc = snp_dev->msg_desc; int rc, resp_len; /* Response data is 64 bytes and max authsize for GCM is 16 bytes. */ u8 buf[64 + 16]; @@ -466,7 +454,7 @@ static int get_derived_key(struct snp_guest_dev *snp_dev, struct snp_guest_reque * response payload. Make sure that it has enough space to cover the * authtag. */ - resp_len = sizeof(derived_key_resp.data) + snp_dev->ctx->authsize; + resp_len = sizeof(derived_key_resp.data) + mdesc->ctx->authsize; if (sizeof(buf) < resp_len) return -ENOMEM; @@ -474,7 +462,7 @@ static int get_derived_key(struct snp_guest_dev *snp_dev, struct snp_guest_reque sizeof(*derived_key_req))) return -EFAULT; - rc = handle_guest_request(snp_dev, SVM_VMGEXIT_GUEST_REQUEST, arg, SNP_MSG_KEY_REQ, + rc = handle_guest_request(mdesc, SVM_VMGEXIT_GUEST_REQUEST, arg, SNP_MSG_KEY_REQ, derived_key_req, sizeof(*derived_key_req), buf, resp_len); if (rc) return rc; @@ -495,6 +483,7 @@ static int get_ext_report(struct snp_guest_dev *snp_dev, struct snp_guest_reques { struct snp_ext_report_req *report_req = &snp_dev->req.ext_report; + struct snp_msg_desc *mdesc = snp_dev->msg_desc; struct snp_report_resp *report_resp; int ret, npages = 0, resp_len; sockptr_t certs_address; @@ -527,7 +516,7 @@ static int get_ext_report(struct snp_guest_dev *snp_dev, struct snp_guest_reques * the host. If host does not supply any certs in it, then copy * zeros to indicate that certificate data was not provided. */ - memset(snp_dev->certs_data, 0, report_req->certs_len); + memset(mdesc->certs_data, 0, report_req->certs_len); npages = report_req->certs_len >> PAGE_SHIFT; cmd: /* @@ -535,19 +524,19 @@ static int get_ext_report(struct snp_guest_dev *snp_dev, struct snp_guest_reques * response payload. Make sure that it has enough space to cover the * authtag. */ - resp_len = sizeof(report_resp->data) + snp_dev->ctx->authsize; + resp_len = sizeof(report_resp->data) + mdesc->ctx->authsize; report_resp = kzalloc(resp_len, GFP_KERNEL_ACCOUNT); if (!report_resp) return -ENOMEM; - snp_dev->input.data_npages = npages; - ret = handle_guest_request(snp_dev, SVM_VMGEXIT_EXT_GUEST_REQUEST, arg, SNP_MSG_REPORT_REQ, + mdesc->input.data_npages = npages; + ret = handle_guest_request(mdesc, SVM_VMGEXIT_EXT_GUEST_REQUEST, arg, SNP_MSG_REPORT_REQ, &report_req->data, sizeof(report_req->data), report_resp->data, resp_len); /* If certs length is invalid then copy the returned length */ if (arg->vmm_error == SNP_GUEST_VMM_ERR_INVALID_LEN) { - report_req->certs_len = snp_dev->input.data_npages << PAGE_SHIFT; + report_req->certs_len = mdesc->input.data_npages << PAGE_SHIFT; if (copy_to_sockptr(io->req_data, report_req, sizeof(*report_req))) ret = -EFAULT; @@ -556,7 +545,7 @@ static int get_ext_report(struct snp_guest_dev *snp_dev, struct snp_guest_reques if (ret) goto e_free; - if (npages && copy_to_sockptr(certs_address, snp_dev->certs_data, report_req->certs_len)) { + if (npages && copy_to_sockptr(certs_address, mdesc->certs_data, report_req->certs_len)) { ret = -EFAULT; goto e_free; } @@ -572,6 +561,7 @@ static int get_ext_report(struct snp_guest_dev *snp_dev, struct snp_guest_reques static long snp_guest_ioctl(struct file *file, unsigned int ioctl, unsigned long arg) { struct snp_guest_dev *snp_dev = to_snp_dev(file); + struct snp_msg_desc *mdesc = snp_dev->msg_desc; void __user *argp = (void __user *)arg; struct snp_guest_request_ioctl input; struct snp_req_resp io; @@ -587,7 +577,7 @@ static long snp_guest_ioctl(struct file *file, unsigned int ioctl, unsigned long return -EINVAL; /* Check if the VMPCK is not empty */ - if (is_vmpck_empty(snp_dev)) { + if (is_vmpck_empty(mdesc)) { dev_err_ratelimited(snp_dev->dev, "VMPCK is disabled\n"); return -ENOTTY; } @@ -862,7 +852,7 @@ static int sev_report_new(struct tsm_report *report, void *data) return -ENOMEM; /* Check if the VMPCK is not empty */ - if (is_vmpck_empty(snp_dev)) { + if (is_vmpck_empty(snp_dev->msg_desc)) { dev_err_ratelimited(snp_dev->dev, "VMPCK is disabled\n"); return -ENOTTY; } @@ -992,6 +982,7 @@ static int __init sev_guest_probe(struct platform_device *pdev) struct snp_secrets_page *secrets; struct device *dev = &pdev->dev; struct snp_guest_dev *snp_dev; + struct snp_msg_desc *mdesc; struct miscdevice *misc; void __iomem *mapping; int ret; @@ -1014,46 +1005,50 @@ static int __init sev_guest_probe(struct platform_device *pdev) if (!snp_dev) goto e_unmap; + mdesc = devm_kzalloc(&pdev->dev, sizeof(struct snp_msg_desc), GFP_KERNEL); + if (!mdesc) + goto e_unmap; + /* Adjust the default VMPCK key based on the executing VMPL level */ if (vmpck_id == -1) vmpck_id = snp_vmpl; ret = -EINVAL; - snp_dev->vmpck = get_vmpck(vmpck_id, secrets, &snp_dev->os_area_msg_seqno); - if (!snp_dev->vmpck) { + mdesc->vmpck = get_vmpck(vmpck_id, secrets, &mdesc->os_area_msg_seqno); + if (!mdesc->vmpck) { dev_err(dev, "Invalid VMPCK%d communication key\n", vmpck_id); goto e_unmap; } /* Verify that VMPCK is not zero. */ - if (is_vmpck_empty(snp_dev)) { + if (is_vmpck_empty(mdesc)) { dev_err(dev, "Empty VMPCK%d communication key\n", vmpck_id); goto e_unmap; } platform_set_drvdata(pdev, snp_dev); snp_dev->dev = dev; - snp_dev->secrets = secrets; + mdesc->secrets = secrets; /* Ensure SNP guest messages do not span more than a page */ BUILD_BUG_ON(sizeof(struct snp_guest_msg) > PAGE_SIZE); /* Allocate the shared page used for the request and response message. */ - snp_dev->request = alloc_shared_pages(dev, sizeof(struct snp_guest_msg)); - if (!snp_dev->request) + mdesc->request = alloc_shared_pages(dev, sizeof(struct snp_guest_msg)); + if (!mdesc->request) goto e_unmap; - snp_dev->response = alloc_shared_pages(dev, sizeof(struct snp_guest_msg)); - if (!snp_dev->response) + mdesc->response = alloc_shared_pages(dev, sizeof(struct snp_guest_msg)); + if (!mdesc->response) goto e_free_request; - snp_dev->certs_data = alloc_shared_pages(dev, SEV_FW_BLOB_MAX_SIZE); - if (!snp_dev->certs_data) + mdesc->certs_data = alloc_shared_pages(dev, SEV_FW_BLOB_MAX_SIZE); + if (!mdesc->certs_data) goto e_free_response; ret = -EIO; - snp_dev->ctx = snp_init_crypto(snp_dev->vmpck, VMPCK_KEY_LEN); - if (!snp_dev->ctx) + mdesc->ctx = snp_init_crypto(mdesc->vmpck, VMPCK_KEY_LEN); + if (!mdesc->ctx) goto e_free_cert_data; misc = &snp_dev->misc; @@ -1062,9 +1057,9 @@ static int __init sev_guest_probe(struct platform_device *pdev) misc->fops = &snp_guest_fops; /* Initialize the input addresses for guest request */ - snp_dev->input.req_gpa = __pa(snp_dev->request); - snp_dev->input.resp_gpa = __pa(snp_dev->response); - snp_dev->input.data_gpa = __pa(snp_dev->certs_data); + mdesc->input.req_gpa = __pa(mdesc->request); + mdesc->input.resp_gpa = __pa(mdesc->response); + mdesc->input.data_gpa = __pa(mdesc->certs_data); /* Set the privlevel_floor attribute based on the vmpck_id */ sev_tsm_ops.privlevel_floor = vmpck_id; @@ -1081,17 +1076,18 @@ static int __init sev_guest_probe(struct platform_device *pdev) if (ret) goto e_free_ctx; + snp_dev->msg_desc = mdesc; dev_info(dev, "Initialized SEV guest driver (using VMPCK%d communication key)\n", vmpck_id); return 0; e_free_ctx: - kfree(snp_dev->ctx); + kfree(mdesc->ctx); e_free_cert_data: - free_shared_pages(snp_dev->certs_data, SEV_FW_BLOB_MAX_SIZE); + free_shared_pages(mdesc->certs_data, SEV_FW_BLOB_MAX_SIZE); e_free_response: - free_shared_pages(snp_dev->response, sizeof(struct snp_guest_msg)); + free_shared_pages(mdesc->response, sizeof(struct snp_guest_msg)); e_free_request: - free_shared_pages(snp_dev->request, sizeof(struct snp_guest_msg)); + free_shared_pages(mdesc->request, sizeof(struct snp_guest_msg)); e_unmap: iounmap(mapping); return ret; @@ -1100,11 +1096,12 @@ static int __init sev_guest_probe(struct platform_device *pdev) static void __exit sev_guest_remove(struct platform_device *pdev) { struct snp_guest_dev *snp_dev = platform_get_drvdata(pdev); + struct snp_msg_desc *mdesc = snp_dev->msg_desc; - free_shared_pages(snp_dev->certs_data, SEV_FW_BLOB_MAX_SIZE); - free_shared_pages(snp_dev->response, sizeof(struct snp_guest_msg)); - free_shared_pages(snp_dev->request, sizeof(struct snp_guest_msg)); - kfree(snp_dev->ctx); + free_shared_pages(mdesc->certs_data, SEV_FW_BLOB_MAX_SIZE); + free_shared_pages(mdesc->response, sizeof(struct snp_guest_msg)); + free_shared_pages(mdesc->request, sizeof(struct snp_guest_msg)); + kfree(mdesc->ctx); misc_deregister(&snp_dev->misc); } From patchwork Wed Jul 31 15:08:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Nikunj A. Dadhania" X-Patchwork-Id: 13748888 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2073.outbound.protection.outlook.com [40.107.237.73]) (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 92A8D1C0DC0; Wed, 31 Jul 2024 15:09:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.237.73 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722438559; cv=fail; b=tPxU43RVoO9+Ik09Dy1wkDlc9ap9c1s7IVTbhpu4Mj9GnHYG61YoDZRC5yY+meZawDihVjBv5/P7iRmo9ZWp7kLHN/RFZMGs26jFbFKffazaGxV0+cfRABEsQaUOGPggQX6qCZ/SiJft7XUvb77uefnTe9Fv5bxB0N1c0FTSyY8= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722438559; c=relaxed/simple; bh=bvJUM1mqFzgMX5bjaSkw8PYBb6VubsmBYjJlHwtDxak=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=C2QiIgsGtSe2ChHac8Ie2t4otkc/NeXL3Y+YXX/zbD+n8BYEbdk6FvhIeGZJwVH6TR0soaXaV8zkLLvelJgG38GzJ9wO6SGofvEnlzvXhl4UmAWs88VAvNLrvfdFe/xvOGMRickykSwMxMnAohSzsF8TM1FygUm06jwCMxnvU8g= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=45nZvLuB; arc=fail smtp.client-ip=40.107.237.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="45nZvLuB" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=JzvBcekWAg47SVfKTCbr4ouC+BMsdKy7wIXdQq/GavJHBKvfN8uREFr2XKrLMxim+9smzTX7Yrz/5CV1+pLMAJLu/hMTDJEwytd/fdIvOWVOOl+BvGp0ydrVvQC+nsTCReIWYlzU/+C2bDwhS5zwAussM3zBtJVVOmvTf+4A2gw+vICILmCJphE3t8rlsprxwgVM+RJrocg9K6fGVUZDXJ7yXg3746fPw/AfzHpM9TxghXi95kqIytsvY+WdHHusIFANxntxhNCvpWwHTK2kHdatK8bXRwhrj3wRPW2qFhpuB80zs+yE+jeh/HppBPl1iT+d1XyRC1Pd3fSiTHPnoQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=LnoYFjOKQ5Yyx5ib4xxPC9vTTK5wLuOSbcJcFYeqLr8=; b=jGDHHesFuQY/uBzw6D7Tvd3eRsfP+hZs6hpfOxzGN58wzUhHHrh8k0CLca28BustA3XyN3gfpiUnwdbnOznmyhno1x9o6u11skrVMHM56e5hD1ovCRm1MYpR8zrl1kFa3APoxFs2WffbhUI+xc56BpYdtixV19u5QFpo9ATqLW+BfTz/ksCLrvPksRjvuUZopGjpCvedo4kTd2jpVZtiXXOmE4R4eBA4ML0yDozyBPIY2rL/eY6k6hwG9I10S+LJiscYzoovyWC6idx4+vLzWlJXtQ8VAwb84oeD2joAZnwozM3dbTapvCKciRA9nGtuO1CeEz23sgRzJgBruE12yw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=LnoYFjOKQ5Yyx5ib4xxPC9vTTK5wLuOSbcJcFYeqLr8=; b=45nZvLuB2u4jXGkiRbOr5usZUd4fJPpBuEvRi9sIhlDod5XX8kBVIJaKb/otxdwZwq5ZhVL3vLFdNZfeVOrg5soPD+5m5pqjgrRqHjqywuq8IlGG+DCsgJ7KX2WFLUZ6aAW3O0BZtwADBfz7egQPITWzRhBdLA94jcTTn78uPYs= Received: from CH0PR03CA0310.namprd03.prod.outlook.com (2603:10b6:610:118::33) by PH7PR12MB7018.namprd12.prod.outlook.com (2603:10b6:510:1b8::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7807.27; Wed, 31 Jul 2024 15:09:12 +0000 Received: from DS3PEPF0000C381.namprd04.prod.outlook.com (2603:10b6:610:118:cafe::73) by CH0PR03CA0310.outlook.office365.com (2603:10b6:610:118::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7784.35 via Frontend Transport; Wed, 31 Jul 2024 15:09:11 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by DS3PEPF0000C381.mail.protection.outlook.com (10.167.23.11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7828.19 via Frontend Transport; Wed, 31 Jul 2024 15:09:11 +0000 Received: from gomati.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Wed, 31 Jul 2024 10:09:06 -0500 From: Nikunj A Dadhania To: , , , , CC: , , , , , , Subject: [PATCH v11 11/20] x86/sev: Carve out and export SNP guest messaging init routines Date: Wed, 31 Jul 2024 20:38:02 +0530 Message-ID: <20240731150811.156771-12-nikunj@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240731150811.156771-1-nikunj@amd.com> References: <20240731150811.156771-1-nikunj@amd.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS3PEPF0000C381:EE_|PH7PR12MB7018:EE_ X-MS-Office365-Filtering-Correlation-Id: 3031440e-b0e9-49f1-4480-08dcb172bbd5 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|1800799024|36860700013|376014|82310400026; X-Microsoft-Antispam-Message-Info: QPKsoq/Hul8VjMuJhNKMIdcopj57uVbzPRXAJSVk2ksTTUwVFGKLm2PxSclCzXuSDKjJt8bPyiJcJM5OpCuHNUWDzVTigyb51StGRzMT1fKldxV9jTHnz31q6CfpKARNzqwRHofbkh4mO5IAaDrhDiOXYe+usGwbUtG6gx2LUJKajI+/QN0SoK3aDUiu4+uoMEePY7pZxtORXqqsbR0i8PKu74p0ArsT5qCOq6VUUx8KehNH3Sd4JIdMC6eeAqhz7RaaN525v5+Pez4ul/oNnimlTE/06REfLTDjPZ2ssGkcLbvjc27XNcxWT762XzX9ELRpBC6Axbg5nF8a49owrTqoOoLBzw1MX+mkdeVwd9rX8BH5b72Ik2kY6UXuRXL9duEKFEf9gci2L9xhiVj4EgB78fVp9rI51812EpKMKmCp8waudIGBYM7KpRqEmiysJStmYxAlTN1m4o/iWvPrC1JivqfUj5He7LarMs3yoe73p64NFAhlWY98+G8RrXsY+F59dei/qIvBhHRStnBvXaJtN4rRXAqti9WqcN2bMJ+HwfJE+mwq1B1TxFc0l2Pa3pKa9QUYCQ0HmW28LVzcQ8RxhtyGyL0aUxnlwihxjwPn/hK6kUero5Y3xo9tvMDOrbpU56SsR6MoBQGEDymt1HJynSlyNtAF6rWb2pSkY56e+oWRbZ5+lpSYeUfCcqPrPk1j1H/+WhkTnEO2bTxj11yaQtCA4BIvMauu4/tOUFmt7D2ZeTcx3tVHUL6Yu7k9qbdE0B4aWfelz6cJmYzCyLrV3wLQmIQZPgF3INzhs7n39wN98FnijnZj+1d8PJLNyJjO89IO8HKHpNoqFk/6NNvzIVIzbzF2Aii/MknbvJlgjD83XnN56CFagPhXno31AnhsS4n+nGEKfP29GtOAtFRRCoWCU9lsrghpYTnmCrkza3lUcMrdC0M2NYsDViT1vvU3yJTQ8FigYwW3Q9UJr8hvLcyQvveyNHdtriTS0iJ4Qj9SMV98CVxzJuhXdDxQFMX+C/whM2ZMAewOsAvl03iaXPKieNlK0rrJI1T/h20aRJ/akXk48lHY97Tkyg5geF7sDr44290FmKyPbBV1cjtnLlFStxtMNruwInXyRxrLA4eijzFLa9gSo5zBkKvmh4SQ9/GxFOnF2tAEQIb/wFdAxZcdr6XOf0fyPfk4A3l5muh3eKi85eku9ZH3+ee9NE4430JIp89DPHkFNfosZ8kqyBmb9hBqoAAEVRMsRwzkQC/LBXUkLSFwZ4/biZ6cTaxSCZInllKucxARMW35a7N5jkgZz9gOFbC3+kegbMnDkx72ERWBeGjQyvC04VXUwOhj8FPfbYZJUm42KVdd5X5ALrsI6xpA5AP42+RX4RIz6Ipgt0XxV0NWnWgNOAlrbnUXzlq1ZHRkQq28brUiZKZXzs2xhFSHDlgGpchfvxGgbIrNPmutIgWLKbYwZ8js X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(7416014)(1800799024)(36860700013)(376014)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Jul 2024 15:09:11.4378 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3031440e-b0e9-49f1-4480-08dcb172bbd5 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: DS3PEPF0000C381.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB7018 Currently, the SEV guest driver is the only user of SNP guest messaging. All routines for initializing SNP guest messaging are implemented within the SEV guest driver. To add Secure TSC guest support, these initialization routines need to be available during early boot. Carve out common SNP guest messaging buffer allocations and message initialization routines to core/sev.c and export them. These newly added APIs set up the SNP message context (snp_msg_desc), which contains all the necessary details for sending SNP guest messages. At present, the SEV guest platform data structure is used to pass the secrets page physical address to SEV guest driver. Since the secrets page address is locally available to the initialization routine, use the cached address. Remove the unused SEV guest platform data structure. Signed-off-by: Nikunj A Dadhania Reviewed-by: Tom Lendacky --- arch/x86/include/asm/sev.h | 71 ++++++++- arch/x86/coco/sev/core.c | 133 +++++++++++++++- drivers/virt/coco/sev-guest/sev-guest.c | 194 +++--------------------- 3 files changed, 213 insertions(+), 185 deletions(-) diff --git a/arch/x86/include/asm/sev.h b/arch/x86/include/asm/sev.h index 2e49c4a9e7fe..3812692ba3fe 100644 --- a/arch/x86/include/asm/sev.h +++ b/arch/x86/include/asm/sev.h @@ -14,6 +14,7 @@ #include #include #include +#include #define GHCB_PROTOCOL_MIN 1ULL #define GHCB_PROTOCOL_MAX 2ULL @@ -170,10 +171,6 @@ struct snp_guest_msg { u8 payload[PAGE_SIZE - sizeof(struct snp_guest_msg_hdr)]; } __packed; -struct sev_guest_platform_data { - u64 secrets_gpa; -}; - struct snp_guest_req { void *req_buf; size_t req_sz; @@ -253,6 +250,7 @@ struct snp_msg_desc { u32 *os_area_msg_seqno; u8 *vmpck; + int vmpck_id; }; /* @@ -438,6 +436,63 @@ u64 sev_get_status(void); void sev_show_status(void); void snp_update_svsm_ca(void); +static inline void free_shared_pages(void *buf, size_t sz) +{ + unsigned int npages = PAGE_ALIGN(sz) >> PAGE_SHIFT; + int ret; + + if (!buf) + return; + + ret = set_memory_encrypted((unsigned long)buf, npages); + if (ret) { + WARN_ONCE(ret, "failed to restore encryption mask (leak it)\n"); + return; + } + + __free_pages(virt_to_page(buf), get_order(sz)); +} + +static inline void *alloc_shared_pages(size_t sz) +{ + unsigned int npages = PAGE_ALIGN(sz) >> PAGE_SHIFT; + struct page *page; + int ret; + + page = alloc_pages(GFP_KERNEL_ACCOUNT, get_order(sz)); + if (!page) + return NULL; + + ret = set_memory_decrypted((unsigned long)page_address(page), npages); + if (ret) { + pr_err("failed to mark page shared, ret=%d\n", ret); + __free_pages(page, get_order(sz)); + return NULL; + } + + return page_address(page); +} + +static inline bool is_vmpck_empty(struct snp_msg_desc *mdesc) +{ + char zero_key[VMPCK_KEY_LEN] = {0}; + + if (mdesc->vmpck) + return !memcmp(mdesc->vmpck, zero_key, VMPCK_KEY_LEN); + + return true; +} + +int snp_msg_init(struct snp_msg_desc *mdesc, int vmpck_id); +struct snp_msg_desc *snp_msg_alloc(void); + +static inline void snp_msg_cleanup(struct snp_msg_desc *mdesc) +{ + mdesc->vmpck = NULL; + mdesc->os_area_msg_seqno = NULL; + kfree(mdesc->ctx); +} + #else /* !CONFIG_AMD_MEM_ENCRYPT */ #define snp_vmpl 0 @@ -474,6 +529,14 @@ static inline u64 snp_get_unsupported_features(u64 status) { return 0; } static inline u64 sev_get_status(void) { return 0; } static inline void sev_show_status(void) { } static inline void snp_update_svsm_ca(void) { } +static inline void free_shared_pages(void *buf, size_t sz) { } +static inline void *alloc_shared_pages(size_t sz) { return NULL; } +static inline bool is_vmpck_empty(struct snp_msg_desc *mdesc) { return false; } + +static inline int snp_msg_init(struct snp_msg_desc *mdesc, int vmpck_id) { return -1; } +static inline struct snp_msg_desc *snp_msg_alloc(void) { return NULL; } + +static inline void snp_msg_cleanup(struct snp_msg_desc *mdesc) { } #endif /* CONFIG_AMD_MEM_ENCRYPT */ diff --git a/arch/x86/coco/sev/core.c b/arch/x86/coco/sev/core.c index e6a3f3df4637..6787d0972a45 100644 --- a/arch/x86/coco/sev/core.c +++ b/arch/x86/coco/sev/core.c @@ -25,6 +25,7 @@ #include #include #include +#include #include #include @@ -95,6 +96,8 @@ static u64 sev_hv_features __ro_after_init; /* Secrets page physical address from the CC blob */ static u64 secrets_pa __ro_after_init; +static struct snp_msg_desc *snp_mdesc; + /* #VC handler runtime per-CPU data */ struct sev_es_runtime_data { struct ghcb ghcb_page; @@ -2489,15 +2492,9 @@ static struct platform_device sev_guest_device = { static int __init snp_init_platform_device(void) { - struct sev_guest_platform_data data; - if (!cc_platform_has(CC_ATTR_GUEST_SEV_SNP)) return -ENODEV; - data.secrets_gpa = secrets_pa; - if (platform_device_add_data(&sev_guest_device, &data, sizeof(data))) - return -ENODEV; - if (platform_device_register(&sev_guest_device)) return -ENODEV; @@ -2576,3 +2573,127 @@ static int __init sev_sysfs_init(void) } arch_initcall(sev_sysfs_init); #endif // CONFIG_SYSFS + +static u8 *get_vmpck(int id, struct snp_secrets_page *secrets, u32 **seqno) +{ + u8 *key = NULL; + + switch (id) { + case 0: + *seqno = &secrets->os_area.msg_seqno_0; + key = secrets->vmpck0; + break; + case 1: + *seqno = &secrets->os_area.msg_seqno_1; + key = secrets->vmpck1; + break; + case 2: + *seqno = &secrets->os_area.msg_seqno_2; + key = secrets->vmpck2; + break; + case 3: + *seqno = &secrets->os_area.msg_seqno_3; + key = secrets->vmpck3; + break; + default: + break; + } + + return key; +} + +static struct aesgcm_ctx *snp_init_crypto(u8 *key, size_t keylen) +{ + struct aesgcm_ctx *ctx; + + ctx = kzalloc(sizeof(*ctx), GFP_KERNEL_ACCOUNT); + if (!ctx) + return NULL; + + if (aesgcm_expandkey(ctx, key, keylen, AUTHTAG_LEN)) { + pr_err("Crypto context initialization failed\n"); + kfree(ctx); + return NULL; + } + + return ctx; +} + +int snp_msg_init(struct snp_msg_desc *mdesc, int vmpck_id) +{ + /* Adjust the default VMPCK key based on the executing VMPL level */ + if (vmpck_id == -1) + vmpck_id = snp_vmpl; + + mdesc->vmpck = get_vmpck(vmpck_id, mdesc->secrets, &mdesc->os_area_msg_seqno); + if (!mdesc->vmpck) { + pr_err("Invalid VMPCK%d communication key\n", vmpck_id); + return -EINVAL; + } + + /* Verify that VMPCK is not zero. */ + if (is_vmpck_empty(mdesc)) { + pr_err("Empty VMPCK%d communication key\n", vmpck_id); + return -EINVAL; + } + + mdesc->vmpck_id = vmpck_id; + + mdesc->ctx = snp_init_crypto(mdesc->vmpck, VMPCK_KEY_LEN); + if (!mdesc->ctx) + return -ENOMEM; + + return 0; +} +EXPORT_SYMBOL_GPL(snp_msg_init); + +struct snp_msg_desc *snp_msg_alloc(void) +{ + struct snp_msg_desc *mdesc; + + if (snp_mdesc) + return snp_mdesc; + + mdesc = kzalloc(sizeof(struct snp_msg_desc), GFP_KERNEL); + if (!mdesc) + return ERR_PTR(-ENOMEM); + + mdesc->secrets = ioremap_encrypted(secrets_pa, PAGE_SIZE); + if (!mdesc->secrets) + return ERR_PTR(-ENODEV); + + /* Ensure SNP guest messages do not span more than a page */ + BUILD_BUG_ON(sizeof(struct snp_guest_msg) > PAGE_SIZE); + + /* Allocate the shared page used for the request and response message. */ + mdesc->request = alloc_shared_pages(sizeof(struct snp_guest_msg)); + if (!mdesc->request) + goto e_unmap; + + mdesc->response = alloc_shared_pages(sizeof(struct snp_guest_msg)); + if (!mdesc->response) + goto e_free_request; + + mdesc->certs_data = alloc_shared_pages(SEV_FW_BLOB_MAX_SIZE); + if (!mdesc->certs_data) + goto e_free_response; + + /* initial the input address for guest request */ + mdesc->input.req_gpa = __pa(mdesc->request); + mdesc->input.resp_gpa = __pa(mdesc->response); + mdesc->input.data_gpa = __pa(mdesc->certs_data); + + snp_mdesc = mdesc; + + return mdesc; + +e_free_response: + free_shared_pages(mdesc->response, sizeof(struct snp_guest_msg)); +e_free_request: + free_shared_pages(mdesc->request, sizeof(struct snp_guest_msg)); +e_unmap: + iounmap(mdesc->secrets); + + return ERR_PTR(-ENOMEM); +} +EXPORT_SYMBOL_GPL(snp_msg_alloc); diff --git a/drivers/virt/coco/sev-guest/sev-guest.c b/drivers/virt/coco/sev-guest/sev-guest.c index 38ddabcd7ba3..40509fe18658 100644 --- a/drivers/virt/coco/sev-guest/sev-guest.c +++ b/drivers/virt/coco/sev-guest/sev-guest.c @@ -63,16 +63,6 @@ MODULE_PARM_DESC(vmpck_id, "The VMPCK ID to use when communicating with the PSP. /* Mutex to serialize the shared buffer access and command handling. */ static DEFINE_MUTEX(snp_cmd_mutex); -static bool is_vmpck_empty(struct snp_msg_desc *mdesc) -{ - char zero_key[VMPCK_KEY_LEN] = {0}; - - if (mdesc->vmpck) - return !memcmp(mdesc->vmpck, zero_key, VMPCK_KEY_LEN); - - return true; -} - /* * If an error is received from the host or AMD Secure Processor (ASP) there * are two options. Either retry the exact same encrypted request or discontinue @@ -93,7 +83,7 @@ static bool is_vmpck_empty(struct snp_msg_desc *mdesc) static void snp_disable_vmpck(struct snp_msg_desc *mdesc) { pr_alert("Disabling VMPCK%d communication key to prevent IV reuse.\n", - vmpck_id); + mdesc->vmpck_id); memzero_explicit(mdesc->vmpck, VMPCK_KEY_LEN); mdesc->vmpck = NULL; } @@ -147,23 +137,6 @@ static inline struct snp_guest_dev *to_snp_dev(struct file *file) return container_of(dev, struct snp_guest_dev, misc); } -static struct aesgcm_ctx *snp_init_crypto(u8 *key, size_t keylen) -{ - struct aesgcm_ctx *ctx; - - ctx = kzalloc(sizeof(*ctx), GFP_KERNEL_ACCOUNT); - if (!ctx) - return NULL; - - if (aesgcm_expandkey(ctx, key, keylen, AUTHTAG_LEN)) { - pr_err("Crypto context initialization failed\n"); - kfree(ctx); - return NULL; - } - - return ctx; -} - static int verify_and_dec_payload(struct snp_msg_desc *mdesc, struct snp_guest_req *req) { struct snp_guest_msg *resp_msg = &mdesc->secret_response; @@ -385,7 +358,7 @@ static int handle_guest_request(struct snp_msg_desc *mdesc, u64 exit_code, struct snp_guest_req req = { .msg_version = rio->msg_version, .msg_type = type, - .vmpck_id = vmpck_id, + .vmpck_id = mdesc->vmpck_id, .req_buf = req_buf, .req_sz = req_sz, .resp_buf = resp_buf, @@ -609,76 +582,11 @@ static long snp_guest_ioctl(struct file *file, unsigned int ioctl, unsigned long return ret; } -static void free_shared_pages(void *buf, size_t sz) -{ - unsigned int npages = PAGE_ALIGN(sz) >> PAGE_SHIFT; - int ret; - - if (!buf) - return; - - ret = set_memory_encrypted((unsigned long)buf, npages); - if (ret) { - WARN_ONCE(ret, "failed to restore encryption mask (leak it)\n"); - return; - } - - __free_pages(virt_to_page(buf), get_order(sz)); -} - -static void *alloc_shared_pages(struct device *dev, size_t sz) -{ - unsigned int npages = PAGE_ALIGN(sz) >> PAGE_SHIFT; - struct page *page; - int ret; - - page = alloc_pages(GFP_KERNEL_ACCOUNT, get_order(sz)); - if (!page) - return NULL; - - ret = set_memory_decrypted((unsigned long)page_address(page), npages); - if (ret) { - dev_err(dev, "failed to mark page shared, ret=%d\n", ret); - __free_pages(page, get_order(sz)); - return NULL; - } - - return page_address(page); -} - static const struct file_operations snp_guest_fops = { .owner = THIS_MODULE, .unlocked_ioctl = snp_guest_ioctl, }; -static u8 *get_vmpck(int id, struct snp_secrets_page *secrets, u32 **seqno) -{ - u8 *key = NULL; - - switch (id) { - case 0: - *seqno = &secrets->os_area.msg_seqno_0; - key = secrets->vmpck0; - break; - case 1: - *seqno = &secrets->os_area.msg_seqno_1; - key = secrets->vmpck1; - break; - case 2: - *seqno = &secrets->os_area.msg_seqno_2; - key = secrets->vmpck2; - break; - case 3: - *seqno = &secrets->os_area.msg_seqno_3; - key = secrets->vmpck3; - break; - default: - break; - } - - return key; -} - struct snp_msg_report_resp_hdr { u32 status; u32 report_size; @@ -978,130 +886,66 @@ static void unregister_sev_tsm(void *data) static int __init sev_guest_probe(struct platform_device *pdev) { - struct sev_guest_platform_data *data; - struct snp_secrets_page *secrets; struct device *dev = &pdev->dev; struct snp_guest_dev *snp_dev; struct snp_msg_desc *mdesc; struct miscdevice *misc; - void __iomem *mapping; int ret; if (!cc_platform_has(CC_ATTR_GUEST_SEV_SNP)) return -ENODEV; - if (!dev->platform_data) - return -ENODEV; - - data = (struct sev_guest_platform_data *)dev->platform_data; - mapping = ioremap_encrypted(data->secrets_gpa, PAGE_SIZE); - if (!mapping) - return -ENODEV; - - secrets = (__force void *)mapping; - - ret = -ENOMEM; snp_dev = devm_kzalloc(&pdev->dev, sizeof(struct snp_guest_dev), GFP_KERNEL); if (!snp_dev) - goto e_unmap; - - mdesc = devm_kzalloc(&pdev->dev, sizeof(struct snp_msg_desc), GFP_KERNEL); - if (!mdesc) - goto e_unmap; - - /* Adjust the default VMPCK key based on the executing VMPL level */ - if (vmpck_id == -1) - vmpck_id = snp_vmpl; + return -ENOMEM; - ret = -EINVAL; - mdesc->vmpck = get_vmpck(vmpck_id, secrets, &mdesc->os_area_msg_seqno); - if (!mdesc->vmpck) { - dev_err(dev, "Invalid VMPCK%d communication key\n", vmpck_id); - goto e_unmap; - } + mdesc = snp_msg_alloc(); + if (IS_ERR_OR_NULL(mdesc)) + return -ENOMEM; - /* Verify that VMPCK is not zero. */ - if (is_vmpck_empty(mdesc)) { - dev_err(dev, "Empty VMPCK%d communication key\n", vmpck_id); - goto e_unmap; - } + ret = snp_msg_init(mdesc, vmpck_id); + if (ret) + return -EIO; platform_set_drvdata(pdev, snp_dev); snp_dev->dev = dev; - mdesc->secrets = secrets; - - /* Ensure SNP guest messages do not span more than a page */ - BUILD_BUG_ON(sizeof(struct snp_guest_msg) > PAGE_SIZE); - - /* Allocate the shared page used for the request and response message. */ - mdesc->request = alloc_shared_pages(dev, sizeof(struct snp_guest_msg)); - if (!mdesc->request) - goto e_unmap; - - mdesc->response = alloc_shared_pages(dev, sizeof(struct snp_guest_msg)); - if (!mdesc->response) - goto e_free_request; - - mdesc->certs_data = alloc_shared_pages(dev, SEV_FW_BLOB_MAX_SIZE); - if (!mdesc->certs_data) - goto e_free_response; - - ret = -EIO; - mdesc->ctx = snp_init_crypto(mdesc->vmpck, VMPCK_KEY_LEN); - if (!mdesc->ctx) - goto e_free_cert_data; misc = &snp_dev->misc; misc->minor = MISC_DYNAMIC_MINOR; misc->name = DEVICE_NAME; misc->fops = &snp_guest_fops; - /* Initialize the input addresses for guest request */ - mdesc->input.req_gpa = __pa(mdesc->request); - mdesc->input.resp_gpa = __pa(mdesc->response); - mdesc->input.data_gpa = __pa(mdesc->certs_data); - /* Set the privlevel_floor attribute based on the vmpck_id */ - sev_tsm_ops.privlevel_floor = vmpck_id; + sev_tsm_ops.privlevel_floor = mdesc->vmpck_id; ret = tsm_register(&sev_tsm_ops, snp_dev); if (ret) - goto e_free_cert_data; + goto e_msg_init; ret = devm_add_action_or_reset(&pdev->dev, unregister_sev_tsm, NULL); if (ret) - goto e_free_cert_data; + goto e_msg_init; ret = misc_register(misc); if (ret) - goto e_free_ctx; + goto e_msg_init; snp_dev->msg_desc = mdesc; - dev_info(dev, "Initialized SEV guest driver (using VMPCK%d communication key)\n", vmpck_id); + dev_info(dev, "Initialized SEV guest driver (using VMPCK%d communication key)\n", + mdesc->vmpck_id); return 0; -e_free_ctx: - kfree(mdesc->ctx); -e_free_cert_data: - free_shared_pages(mdesc->certs_data, SEV_FW_BLOB_MAX_SIZE); -e_free_response: - free_shared_pages(mdesc->response, sizeof(struct snp_guest_msg)); -e_free_request: - free_shared_pages(mdesc->request, sizeof(struct snp_guest_msg)); -e_unmap: - iounmap(mapping); +e_msg_init: + snp_msg_cleanup(mdesc); + return ret; } static void __exit sev_guest_remove(struct platform_device *pdev) { struct snp_guest_dev *snp_dev = platform_get_drvdata(pdev); - struct snp_msg_desc *mdesc = snp_dev->msg_desc; - free_shared_pages(mdesc->certs_data, SEV_FW_BLOB_MAX_SIZE); - free_shared_pages(mdesc->response, sizeof(struct snp_guest_msg)); - free_shared_pages(mdesc->request, sizeof(struct snp_guest_msg)); - kfree(mdesc->ctx); + snp_msg_cleanup(snp_dev->msg_desc); misc_deregister(&snp_dev->misc); } From patchwork Wed Jul 31 15:08:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Nikunj A. Dadhania" X-Patchwork-Id: 13748889 Received: from NAM04-MW2-obe.outbound.protection.outlook.com (mail-mw2nam04on2054.outbound.protection.outlook.com [40.107.101.54]) (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 C8F261C0DC6; Wed, 31 Jul 2024 15:09:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.101.54 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722438561; cv=fail; b=F9GYb0p4Z2TOxTOjicnAnsqz1kM6T/nr88d64LS7Sjbvrryywf5SYz7x3nuMvA+SRjNwiG9KHyQRtXIaGrCXpRTPRq0dTrFxQ0EZnqVliy92hwgw8nk2x4ltMd7OBBrKGBaFIuILpx+frBwl3+wm6f/kEyGPV4/zzS4xUezlyuI= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722438561; c=relaxed/simple; bh=APJb6aRVvzsrUk/klZpQIYKBKlkdnu2FYzpfCfDHVNo=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=B2IaG0vYU3EwYjf1pd3MjZEzzqIV6qm8sP6uy5N/m+zO7bkHMX7bL0kAqeDOJ7gXDXbU5DuOYfJKwHtr9MD/W+UpmGnkKHN/6N9AB+9JvOAbYNQC5KLxwiGP0e98Up/EdqIJDBG/1fcHzbCnC9epcidtBzeqC61xE9s7QbBuDn4= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=g50nkpPX; arc=fail smtp.client-ip=40.107.101.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="g50nkpPX" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=EYPMDLflokyz7LQoXPuwVDPBEfuFiMTYt7pNwE5xxamDN4PCCphrpIAdnVZQv9u3X/0eQVR/y77BsZGpYmuX4NAmbpjGqmAi9qtf5GCr4mMcwr1BTOpPob7/FyEQqRP18yR3zv/nqLfaRcSwx/v9uziGRrEMP6r28EFoAfvR0lKCEeyIDDOsA2zivXLh2ZqVqj+B0GT+UvNu5CsNDH1e0Xjtb5sF6RyTpW6E5EfBK5TxvsWi2+B8h0lfW2Z+PwAywL1CIhM355PlUIopwHgXD1SUe01W1WKO3FKhyz8T1bnbFMkv0M/+VVpilWB2aFvd+PdOyzd5aFWUY3tn1Xrzig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=+XZk/lUnDYxhTXYX4tGAqZb3sUBgHXEjwvhBs4mJL8M=; b=Ef18Uy//VgG5Gb8HpNqWl2lSN4gBtmBRBCFwmKmcoHHix8Qk2so3skbCONyLraXcjytkw0K/2Bby//6tvHpuSrUNs+aTrRpGwshaMY/Sjn5sVlmh0IIp0KOnKZleW9Wt96eBCeUFDMACIb65WKtky0+KXvEjLJFChD+4LHkyBemuqjyKvBv5d8Fp3+Lta/EV5TibJekcALzUOyHRUiu7xourEjc+w7fEhaoiT/Ug0wyPxNgOWMM2jWZDnpaGf3nR6F3ptHQ/R5z2kDuivqBHhd+wJDVjP6GlWXiYH1SmbS2pEELOSiT2/2hvx3L2bre9KRLbI43fii4C0n6WtadUrA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=+XZk/lUnDYxhTXYX4tGAqZb3sUBgHXEjwvhBs4mJL8M=; b=g50nkpPXrYeStUrUjLTDud16jq5DXzShtbePRUQhdPjwZHzPjboQgFtxzEDhiiaAJZlE6bm8ZoCS7MjYcGmTzqOyWU1/7okOWdQgvk/vYcw8nU8Uzvusq+S1eqys+gDy32g814w37R1GOfjUyxOeOKUFklDF0EX4zXl/BscnXxQ= Received: from CH0PR03CA0309.namprd03.prod.outlook.com (2603:10b6:610:118::30) by MN0PR12MB5811.namprd12.prod.outlook.com (2603:10b6:208:377::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7807.28; Wed, 31 Jul 2024 15:09:15 +0000 Received: from DS3PEPF0000C381.namprd04.prod.outlook.com (2603:10b6:610:118:cafe::cf) by CH0PR03CA0309.outlook.office365.com (2603:10b6:610:118::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7784.34 via Frontend Transport; Wed, 31 Jul 2024 15:09:15 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by DS3PEPF0000C381.mail.protection.outlook.com (10.167.23.11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7828.19 via Frontend Transport; Wed, 31 Jul 2024 15:09:14 +0000 Received: from gomati.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Wed, 31 Jul 2024 10:09:10 -0500 From: Nikunj A Dadhania To: , , , , CC: , , , , , , Subject: [PATCH v11 12/20] x86/sev: Relocate SNP guest messaging routines to common code Date: Wed, 31 Jul 2024 20:38:03 +0530 Message-ID: <20240731150811.156771-13-nikunj@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240731150811.156771-1-nikunj@amd.com> References: <20240731150811.156771-1-nikunj@amd.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS3PEPF0000C381:EE_|MN0PR12MB5811:EE_ X-MS-Office365-Filtering-Correlation-Id: ba522584-a26d-4395-90bf-08dcb172bdc7 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|36860700013|7416014|376014|1800799024; X-Microsoft-Antispam-Message-Info: gPUUmVdnWyqnFHfF7/Ub0xsfPLi/DUazrFCmyFeZ3Sp5cCGSxfcBGVT1t+4Pn4FUXUM1j57QtrQIhslo5l0OGkpsQQvdZuCIQfjzi7Thnh3LKG9NiI1AwR7aWrqVull/NPI1z6bM99Tb07c103JNrZltNBD6pC6m15kZHzFsCMYQQWG1L6Mq0pV2RHV8AXSbW/xnfFKu8qZ75MDtgvQUmbzjJIEwO9S3PonP2EcyUVsVCGbF7PD5mpzD1rSbXgyylFXw4sElhX8w6X7srqPuWuzQM9043WJvu8OXmPv3/gAeU/qujpRABcX6tImJQAJKuSFL+Taz0VyOLG+2gAqwI44zZisLeFn2Pg15QeAgF2rHqJo+HLNFvKyyDvdKlw9kK7AsXYx6SzlPbG3zbjv2KeDgVen+0a040PE/vNNWIU/G7YhV2x8eSHAZUu55XmPCtfcevMEDwpXrk2pM8Z5Xgavn9etZi+kytO9DbP7Et31KznXiMkhKOP+OoLh+s2ZxGqcTQ5Dk7s3kbGSz668XN8+VeXX5NUQiSKvj042oy9kz5DN/fLkHD1Da/qSBf0IrMOtjBMpRX48xMjEw5XPGM+pk85t5t3DSUjuGgjhx38tETvI1KMwb7bDrXVVf1g8r3aVeyarh4gwCKkl5dtlF5zJZbrU4sAWMt87V/fUu7nOyNnDWuTkm4wj9acNdW4hnznXAeYzFYEGAmdkcz2NjQqtOfVqWEYlxbWljnanSm2RcW3HJZKuHBXqmwCPXrwdOYcGXwmZ4Rd4mDuXhq5JgIXRzgp3bJX3Dg5Fuwz8slHV85xeGBWNb6skY7DkGYwjMZHeN2dgvyk7aVxXSqo6DRyV8+v/ZR2vR/3JJZAfyS2TLhQkFOb2vIuI1PP/EJj+0uk0domE8+bM0QpX3h1S2NI2+o1ZnrURLZjjP6o4831DnPD8pIFCjwK54C6an+LLZvbr+1qj4xzvCtrf/gtdEq2+CObDZfIuiBcidy5iw0QeZR4SJwVTGzA4+Un7DEQDBBWSYCgnZMyIfasesqV8IfNEuHSN8OJ/qJAi2qaDY1vv9bN6rOxU1m7DpBCrtJWpO84wuOI+6sII+k0HldCTMSC6akK7oJKyRd9nujrJRFLsqWjzdZ1C12cbHzkHE15IbnHJnMytv6Y0Hufr+gtroHb5NEXO5l23jeKpq4+KTNgRoUJWfTd1jk8TIgj28f47/IDtolXocePzQH2hPqZrbPr7R5+DdVMc6JBt957bb+AWSjFl4h0KueMSwdD5whn8IDKxsHi+lyA01q0cbGrGM0970BB/S05YzEWoiuWnGsHhsj7A2u8nNfughJMS/4UV++V0TPgzf7bvw75wOhEPpwOjV7O5OZn9BZaXA540fLapyO0g7mZDiJevHZOW54X1C27yx57zT+4f/OsaPE8qfRsQT0OVNFpzlklfY2B33ABIK+fQamSfcvzfO9wAr0fYb X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(82310400026)(36860700013)(7416014)(376014)(1800799024);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Jul 2024 15:09:14.7034 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ba522584-a26d-4395-90bf-08dcb172bdc7 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: DS3PEPF0000C381.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN0PR12MB5811 At present, the SEV guest driver exclusively handles SNP guest messaging. All routines for sending guest messages are embedded within the guest driver. To support Secure TSC, SEV-SNP guests must communicate with the AMD Security Processor during early boot. However, these guest messaging functions are not accessible during early boot since they are currently part of the guest driver. Hence, relocate the core SNP guest messaging functions to SEV common code and provide an API for sending SNP guest messages. No functional change, but just an export symbol. Signed-off-by: Nikunj A Dadhania Reviewed-by: Tom Lendacky --- arch/x86/include/asm/sev.h | 8 + arch/x86/coco/sev/core.c | 284 +++++++++++++++++++++++ drivers/virt/coco/sev-guest/sev-guest.c | 286 ------------------------ arch/x86/Kconfig | 1 + drivers/virt/coco/sev-guest/Kconfig | 1 - 5 files changed, 293 insertions(+), 287 deletions(-) diff --git a/arch/x86/include/asm/sev.h b/arch/x86/include/asm/sev.h index 3812692ba3fe..eda435eba53e 100644 --- a/arch/x86/include/asm/sev.h +++ b/arch/x86/include/asm/sev.h @@ -125,6 +125,9 @@ struct snp_req_data { #define AAD_LEN 48 #define MSG_HDR_VER 1 +#define SNP_REQ_MAX_RETRY_DURATION (60*HZ) +#define SNP_REQ_RETRY_DELAY (2*HZ) + /* See SNP spec SNP_GUEST_REQUEST section for the structure */ enum msg_type { SNP_MSG_TYPE_INVALID = 0, @@ -493,6 +496,9 @@ static inline void snp_msg_cleanup(struct snp_msg_desc *mdesc) kfree(mdesc->ctx); } +int snp_send_guest_request(struct snp_msg_desc *mdesc, struct snp_guest_req *req, + struct snp_guest_request_ioctl *rio); + #else /* !CONFIG_AMD_MEM_ENCRYPT */ #define snp_vmpl 0 @@ -537,6 +543,8 @@ static inline int snp_msg_init(struct snp_msg_desc *mdesc, int vmpck_id) { retur static inline struct snp_msg_desc *snp_msg_alloc(void) { return NULL; } static inline void snp_msg_cleanup(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; } #endif /* CONFIG_AMD_MEM_ENCRYPT */ diff --git a/arch/x86/coco/sev/core.c b/arch/x86/coco/sev/core.c index 6787d0972a45..aaeeca938265 100644 --- a/arch/x86/coco/sev/core.c +++ b/arch/x86/coco/sev/core.c @@ -2697,3 +2697,287 @@ struct snp_msg_desc *snp_msg_alloc(void) return ERR_PTR(-ENOMEM); } EXPORT_SYMBOL_GPL(snp_msg_alloc); + +/* Mutex to serialize the shared buffer access and command handling. */ +static DEFINE_MUTEX(snp_cmd_mutex); + +/* + * If an error is received from the host or AMD Secure Processor (ASP) there + * are two options. Either retry the exact same encrypted request or discontinue + * using the VMPCK. + * + * This is because in the current encryption scheme GHCB v2 uses AES-GCM to + * encrypt the requests. The IV for this scheme is the sequence number. GCM + * cannot tolerate IV reuse. + * + * The ASP FW v1.51 only increments the sequence numbers on a successful + * guest<->ASP back and forth and only accepts messages at its exact sequence + * number. + * + * So if the sequence number were to be reused the encryption scheme is + * vulnerable. If the sequence number were incremented for a fresh IV the ASP + * will reject the request. + */ +static void snp_disable_vmpck(struct snp_msg_desc *mdesc) +{ + pr_alert("Disabling VMPCK%d communication key to prevent IV reuse.\n", + mdesc->vmpck_id); + memzero_explicit(mdesc->vmpck, VMPCK_KEY_LEN); + mdesc->vmpck = NULL; +} + +static inline u64 __snp_get_msg_seqno(struct snp_msg_desc *mdesc) +{ + u64 count; + + lockdep_assert_held(&snp_cmd_mutex); + + /* Read the current message sequence counter from secrets pages */ + count = *mdesc->os_area_msg_seqno; + + return count + 1; +} + +/* Return a non-zero on success */ +static u64 snp_get_msg_seqno(struct snp_msg_desc *mdesc) +{ + u64 count = __snp_get_msg_seqno(mdesc); + + /* + * The message sequence counter for the SNP guest request is a 64-bit + * value but the version 2 of GHCB specification defines a 32-bit storage + * for it. If the counter exceeds the 32-bit value then return zero. + * The caller should check the return value, but if the caller happens to + * not check the value and use it, then the firmware treats zero as an + * invalid number and will fail the message request. + */ + if (count >= UINT_MAX) { + pr_err("request message sequence counter overflow\n"); + return 0; + } + + return count; +} + +static void snp_inc_msg_seqno(struct snp_msg_desc *mdesc) +{ + /* + * The counter is also incremented by the PSP, so increment it by 2 + * and save in secrets page. + */ + *mdesc->os_area_msg_seqno += 2; +} + +static int verify_and_dec_payload(struct snp_msg_desc *mdesc, struct snp_guest_req *req) +{ + struct snp_guest_msg *resp_msg = &mdesc->secret_response; + struct snp_guest_msg *req_msg = &mdesc->secret_request; + struct snp_guest_msg_hdr *req_msg_hdr = &req_msg->hdr; + struct snp_guest_msg_hdr *resp_msg_hdr = &resp_msg->hdr; + struct aesgcm_ctx *ctx = mdesc->ctx; + u8 iv[GCM_AES_IV_SIZE] = {}; + + pr_debug("response [seqno %lld type %d version %d sz %d]\n", + resp_msg_hdr->msg_seqno, resp_msg_hdr->msg_type, resp_msg_hdr->msg_version, + resp_msg_hdr->msg_sz); + + /* Copy response from shared memory to encrypted memory. */ + memcpy(resp_msg, mdesc->response, sizeof(*resp_msg)); + + /* Verify that the sequence counter is incremented by 1 */ + if (unlikely(resp_msg_hdr->msg_seqno != (req_msg_hdr->msg_seqno + 1))) + return -EBADMSG; + + /* Verify response message type and version number. */ + if (resp_msg_hdr->msg_type != (req_msg_hdr->msg_type + 1) || + resp_msg_hdr->msg_version != req_msg_hdr->msg_version) + return -EBADMSG; + + /* + * If the message size is greater than our buffer length then return + * an error. + */ + if (unlikely((resp_msg_hdr->msg_sz + ctx->authsize) > req->resp_sz)) + return -EBADMSG; + + /* Decrypt the payload */ + memcpy(iv, &resp_msg_hdr->msg_seqno, min(sizeof(iv), sizeof(resp_msg_hdr->msg_seqno))); + if (!aesgcm_decrypt(ctx, req->resp_buf, resp_msg->payload, resp_msg_hdr->msg_sz, + &resp_msg_hdr->algo, AAD_LEN, iv, resp_msg_hdr->authtag)) + return -EBADMSG; + + return 0; +} + +static int enc_payload(struct snp_msg_desc *mdesc, u64 seqno, struct snp_guest_req *req) +{ + struct snp_guest_msg *msg = &mdesc->secret_request; + struct snp_guest_msg_hdr *hdr = &msg->hdr; + struct aesgcm_ctx *ctx = mdesc->ctx; + u8 iv[GCM_AES_IV_SIZE] = {}; + + memset(msg, 0, sizeof(*msg)); + + hdr->algo = SNP_AEAD_AES_256_GCM; + hdr->hdr_version = MSG_HDR_VER; + hdr->hdr_sz = sizeof(*hdr); + hdr->msg_type = req->msg_type; + hdr->msg_version = req->msg_version; + hdr->msg_seqno = seqno; + hdr->msg_vmpck = req->vmpck_id; + hdr->msg_sz = req->req_sz; + + /* Verify the sequence number is non-zero */ + if (!hdr->msg_seqno) + return -ENOSR; + + pr_debug("request [seqno %lld type %d version %d sz %d]\n", + hdr->msg_seqno, hdr->msg_type, hdr->msg_version, hdr->msg_sz); + + if (WARN_ON((req->req_sz + ctx->authsize) > sizeof(msg->payload))) + return -EBADMSG; + + memcpy(iv, &hdr->msg_seqno, min(sizeof(iv), sizeof(hdr->msg_seqno))); + aesgcm_encrypt(ctx, msg->payload, req->req_buf, req->req_sz, &hdr->algo, + AAD_LEN, iv, hdr->authtag); + + return 0; +} + +static int __handle_guest_request(struct snp_msg_desc *mdesc, struct snp_guest_req *req, + struct snp_guest_request_ioctl *rio) +{ + unsigned long req_start = jiffies; + unsigned int override_npages = 0; + u64 override_err = 0; + int rc; + +retry_request: + /* + * Call firmware to process the request. In this function the encrypted + * message enters shared memory with the host. So after this call the + * sequence number must be incremented or the VMPCK must be deleted to + * prevent reuse of the IV. + */ + rc = snp_issue_guest_request(req, &mdesc->input, rio); + switch (rc) { + case -ENOSPC: + /* + * If the extended guest request fails due to having too + * small of a certificate data buffer, retry the same + * guest request without the extended data request in + * order to increment the sequence number and thus avoid + * IV reuse. + */ + override_npages = mdesc->input.data_npages; + req->exit_code = SVM_VMGEXIT_GUEST_REQUEST; + + /* + * Override the error to inform callers the given extended + * request buffer size was too small and give the caller the + * required buffer size. + */ + override_err = SNP_GUEST_VMM_ERR(SNP_GUEST_VMM_ERR_INVALID_LEN); + + /* + * If this call to the firmware succeeds, the sequence number can + * be incremented allowing for continued use of the VMPCK. If + * there is an error reflected in the return value, this value + * is checked further down and the result will be the deletion + * of the VMPCK and the error code being propagated back to the + * user as an ioctl() return code. + */ + goto retry_request; + + /* + * The host may return SNP_GUEST_VMM_ERR_BUSY if the request has been + * throttled. Retry in the driver to avoid returning and reusing the + * message sequence number on a different message. + */ + case -EAGAIN: + if (jiffies - req_start > SNP_REQ_MAX_RETRY_DURATION) { + rc = -ETIMEDOUT; + break; + } + schedule_timeout_killable(SNP_REQ_RETRY_DELAY); + goto retry_request; + } + + /* + * Increment the message sequence number. There is no harm in doing + * this now because decryption uses the value stored in the response + * structure and any failure will wipe the VMPCK, preventing further + * use anyway. + */ + snp_inc_msg_seqno(mdesc); + + if (override_err) { + rio->exitinfo2 = override_err; + + /* + * If an extended guest request was issued and the supplied certificate + * buffer was not large enough, a standard guest request was issued to + * prevent IV reuse. If the standard request was successful, return -EIO + * back to the caller as would have originally been returned. + */ + if (!rc && override_err == SNP_GUEST_VMM_ERR(SNP_GUEST_VMM_ERR_INVALID_LEN)) + rc = -EIO; + } + + if (override_npages) + mdesc->input.data_npages = override_npages; + + return rc; +} + +int snp_send_guest_request(struct snp_msg_desc *mdesc, struct snp_guest_req *req, + struct snp_guest_request_ioctl *rio) +{ + u64 seqno; + int rc; + + guard(mutex)(&snp_cmd_mutex); + + /* Get message sequence and verify that its a non-zero */ + seqno = snp_get_msg_seqno(mdesc); + if (!seqno) + return -EIO; + + /* Clear shared memory's response for the host to populate. */ + memset(mdesc->response, 0, sizeof(struct snp_guest_msg)); + + /* Encrypt the userspace provided payload in mdesc->secret_request. */ + rc = enc_payload(mdesc, seqno, req); + if (rc) + return rc; + + /* + * Write the fully encrypted request to the shared unencrypted + * request page. + */ + memcpy(mdesc->request, &mdesc->secret_request, + sizeof(mdesc->secret_request)); + + rc = __handle_guest_request(mdesc, req, rio); + if (rc) { + if (rc == -EIO && + rio->exitinfo2 == SNP_GUEST_VMM_ERR(SNP_GUEST_VMM_ERR_INVALID_LEN)) + return rc; + + pr_alert("Detected error from ASP request. rc: %d, exitinfo2: 0x%llx\n", + rc, rio->exitinfo2); + + snp_disable_vmpck(mdesc); + return rc; + } + + rc = verify_and_dec_payload(mdesc, req); + if (rc) { + pr_alert("Detected unexpected decode failure from ASP. rc: %d\n", rc); + snp_disable_vmpck(mdesc); + return rc; + } + + return 0; +} +EXPORT_SYMBOL_GPL(snp_send_guest_request); diff --git a/drivers/virt/coco/sev-guest/sev-guest.c b/drivers/virt/coco/sev-guest/sev-guest.c index 40509fe18658..019eca753f85 100644 --- a/drivers/virt/coco/sev-guest/sev-guest.c +++ b/drivers/virt/coco/sev-guest/sev-guest.c @@ -31,9 +31,6 @@ #define DEVICE_NAME "sev-guest" -#define SNP_REQ_MAX_RETRY_DURATION (60*HZ) -#define SNP_REQ_RETRY_DELAY (2*HZ) - #define SVSM_MAX_RETRIES 3 struct snp_guest_dev { @@ -60,76 +57,6 @@ static int vmpck_id = -1; module_param(vmpck_id, int, 0444); MODULE_PARM_DESC(vmpck_id, "The VMPCK ID to use when communicating with the PSP."); -/* Mutex to serialize the shared buffer access and command handling. */ -static DEFINE_MUTEX(snp_cmd_mutex); - -/* - * If an error is received from the host or AMD Secure Processor (ASP) there - * are two options. Either retry the exact same encrypted request or discontinue - * using the VMPCK. - * - * This is because in the current encryption scheme GHCB v2 uses AES-GCM to - * encrypt the requests. The IV for this scheme is the sequence number. GCM - * cannot tolerate IV reuse. - * - * The ASP FW v1.51 only increments the sequence numbers on a successful - * guest<->ASP back and forth and only accepts messages at its exact sequence - * number. - * - * So if the sequence number were to be reused the encryption scheme is - * vulnerable. If the sequence number were incremented for a fresh IV the ASP - * will reject the request. - */ -static void snp_disable_vmpck(struct snp_msg_desc *mdesc) -{ - pr_alert("Disabling VMPCK%d communication key to prevent IV reuse.\n", - mdesc->vmpck_id); - memzero_explicit(mdesc->vmpck, VMPCK_KEY_LEN); - mdesc->vmpck = NULL; -} - -static inline u64 __snp_get_msg_seqno(struct snp_msg_desc *mdesc) -{ - u64 count; - - lockdep_assert_held(&snp_cmd_mutex); - - /* Read the current message sequence counter from secrets pages */ - count = *mdesc->os_area_msg_seqno; - - return count + 1; -} - -/* Return a non-zero on success */ -static u64 snp_get_msg_seqno(struct snp_msg_desc *mdesc) -{ - u64 count = __snp_get_msg_seqno(mdesc); - - /* - * The message sequence counter for the SNP guest request is a 64-bit - * value but the version 2 of GHCB specification defines a 32-bit storage - * for it. If the counter exceeds the 32-bit value then return zero. - * The caller should check the return value, but if the caller happens to - * not check the value and use it, then the firmware treats zero as an - * invalid number and will fail the message request. - */ - if (count >= UINT_MAX) { - pr_err("request message sequence counter overflow\n"); - return 0; - } - - return count; -} - -static void snp_inc_msg_seqno(struct snp_msg_desc *mdesc) -{ - /* - * The counter is also incremented by the PSP, so increment it by 2 - * and save in secrets page. - */ - *mdesc->os_area_msg_seqno += 2; -} - static inline struct snp_guest_dev *to_snp_dev(struct file *file) { struct miscdevice *dev = file->private_data; @@ -137,219 +64,6 @@ static inline struct snp_guest_dev *to_snp_dev(struct file *file) return container_of(dev, struct snp_guest_dev, misc); } -static int verify_and_dec_payload(struct snp_msg_desc *mdesc, struct snp_guest_req *req) -{ - struct snp_guest_msg *resp_msg = &mdesc->secret_response; - struct snp_guest_msg *req_msg = &mdesc->secret_request; - struct snp_guest_msg_hdr *req_msg_hdr = &req_msg->hdr; - struct snp_guest_msg_hdr *resp_msg_hdr = &resp_msg->hdr; - struct aesgcm_ctx *ctx = mdesc->ctx; - u8 iv[GCM_AES_IV_SIZE] = {}; - - pr_debug("response [seqno %lld type %d version %d sz %d]\n", - resp_msg_hdr->msg_seqno, resp_msg_hdr->msg_type, resp_msg_hdr->msg_version, - resp_msg_hdr->msg_sz); - - /* Copy response from shared memory to encrypted memory. */ - memcpy(resp_msg, mdesc->response, sizeof(*resp_msg)); - - /* Verify that the sequence counter is incremented by 1 */ - if (unlikely(resp_msg_hdr->msg_seqno != (req_msg_hdr->msg_seqno + 1))) - return -EBADMSG; - - /* Verify response message type and version number. */ - if (resp_msg_hdr->msg_type != (req_msg_hdr->msg_type + 1) || - resp_msg_hdr->msg_version != req_msg_hdr->msg_version) - return -EBADMSG; - - /* - * If the message size is greater than our buffer length then return - * an error. - */ - if (unlikely((resp_msg_hdr->msg_sz + ctx->authsize) > req->resp_sz)) - return -EBADMSG; - - /* Decrypt the payload */ - memcpy(iv, &resp_msg_hdr->msg_seqno, min(sizeof(iv), sizeof(resp_msg_hdr->msg_seqno))); - if (!aesgcm_decrypt(ctx, req->resp_buf, resp_msg->payload, resp_msg_hdr->msg_sz, - &resp_msg_hdr->algo, AAD_LEN, iv, resp_msg_hdr->authtag)) - return -EBADMSG; - - return 0; -} - -static int enc_payload(struct snp_msg_desc *mdesc, u64 seqno, struct snp_guest_req *req) -{ - struct snp_guest_msg *msg = &mdesc->secret_request; - struct snp_guest_msg_hdr *hdr = &msg->hdr; - struct aesgcm_ctx *ctx = mdesc->ctx; - u8 iv[GCM_AES_IV_SIZE] = {}; - - memset(msg, 0, sizeof(*msg)); - - hdr->algo = SNP_AEAD_AES_256_GCM; - hdr->hdr_version = MSG_HDR_VER; - hdr->hdr_sz = sizeof(*hdr); - hdr->msg_type = req->msg_type; - hdr->msg_version = req->msg_version; - hdr->msg_seqno = seqno; - hdr->msg_vmpck = req->vmpck_id; - hdr->msg_sz = req->req_sz; - - /* Verify the sequence number is non-zero */ - if (!hdr->msg_seqno) - return -ENOSR; - - pr_debug("request [seqno %lld type %d version %d sz %d]\n", - hdr->msg_seqno, hdr->msg_type, hdr->msg_version, hdr->msg_sz); - - if (WARN_ON((req->req_sz + ctx->authsize) > sizeof(msg->payload))) - return -EBADMSG; - - memcpy(iv, &hdr->msg_seqno, min(sizeof(iv), sizeof(hdr->msg_seqno))); - aesgcm_encrypt(ctx, msg->payload, req->req_buf, req->req_sz, &hdr->algo, - AAD_LEN, iv, hdr->authtag); - - return 0; -} - -static int __handle_guest_request(struct snp_msg_desc *mdesc, struct snp_guest_req *req, - struct snp_guest_request_ioctl *rio) -{ - unsigned long req_start = jiffies; - unsigned int override_npages = 0; - u64 override_err = 0; - int rc; - -retry_request: - /* - * Call firmware to process the request. In this function the encrypted - * message enters shared memory with the host. So after this call the - * sequence number must be incremented or the VMPCK must be deleted to - * prevent reuse of the IV. - */ - rc = snp_issue_guest_request(req, &mdesc->input, rio); - switch (rc) { - case -ENOSPC: - /* - * If the extended guest request fails due to having too - * small of a certificate data buffer, retry the same - * guest request without the extended data request in - * order to increment the sequence number and thus avoid - * IV reuse. - */ - override_npages = mdesc->input.data_npages; - req->exit_code = SVM_VMGEXIT_GUEST_REQUEST; - - /* - * Override the error to inform callers the given extended - * request buffer size was too small and give the caller the - * required buffer size. - */ - override_err = SNP_GUEST_VMM_ERR(SNP_GUEST_VMM_ERR_INVALID_LEN); - - /* - * If this call to the firmware succeeds, the sequence number can - * be incremented allowing for continued use of the VMPCK. If - * there is an error reflected in the return value, this value - * is checked further down and the result will be the deletion - * of the VMPCK and the error code being propagated back to the - * user as an ioctl() return code. - */ - goto retry_request; - - /* - * The host may return SNP_GUEST_VMM_ERR_BUSY if the request has been - * throttled. Retry in the driver to avoid returning and reusing the - * message sequence number on a different message. - */ - case -EAGAIN: - if (jiffies - req_start > SNP_REQ_MAX_RETRY_DURATION) { - rc = -ETIMEDOUT; - break; - } - schedule_timeout_killable(SNP_REQ_RETRY_DELAY); - goto retry_request; - } - - /* - * Increment the message sequence number. There is no harm in doing - * this now because decryption uses the value stored in the response - * structure and any failure will wipe the VMPCK, preventing further - * use anyway. - */ - snp_inc_msg_seqno(mdesc); - - if (override_err) { - rio->exitinfo2 = override_err; - - /* - * If an extended guest request was issued and the supplied certificate - * buffer was not large enough, a standard guest request was issued to - * prevent IV reuse. If the standard request was successful, return -EIO - * back to the caller as would have originally been returned. - */ - if (!rc && override_err == SNP_GUEST_VMM_ERR(SNP_GUEST_VMM_ERR_INVALID_LEN)) - rc = -EIO; - } - - if (override_npages) - mdesc->input.data_npages = override_npages; - - return rc; -} - -static int snp_send_guest_request(struct snp_msg_desc *mdesc, struct snp_guest_req *req, - struct snp_guest_request_ioctl *rio) -{ - u64 seqno; - int rc; - - guard(mutex)(&snp_cmd_mutex); - - /* Get message sequence and verify that its a non-zero */ - seqno = snp_get_msg_seqno(mdesc); - if (!seqno) - return -EIO; - - /* Clear shared memory's response for the host to populate. */ - memset(mdesc->response, 0, sizeof(struct snp_guest_msg)); - - /* Encrypt the userspace provided payload in mdesc->secret_request. */ - rc = enc_payload(mdesc, seqno, req); - if (rc) - return rc; - - /* - * Write the fully encrypted request to the shared unencrypted - * request page. - */ - memcpy(mdesc->request, &mdesc->secret_request, - sizeof(mdesc->secret_request)); - - rc = __handle_guest_request(mdesc, req, rio); - if (rc) { - if (rc == -EIO && - rio->exitinfo2 == SNP_GUEST_VMM_ERR(SNP_GUEST_VMM_ERR_INVALID_LEN)) - return rc; - - pr_alert("Detected error from ASP request. rc: %d, exitinfo2: 0x%llx\n", - rc, rio->exitinfo2); - - snp_disable_vmpck(mdesc); - return rc; - } - - rc = verify_and_dec_payload(mdesc, req); - if (rc) { - pr_alert("Detected unexpected decode failure from ASP. rc: %d\n", rc); - snp_disable_vmpck(mdesc); - return rc; - } - - return 0; -} - static int handle_guest_request(struct snp_msg_desc *mdesc, u64 exit_code, struct snp_guest_request_ioctl *rio, u8 type, void *req_buf, size_t req_sz, void *resp_buf, diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index 007bab9f2a0e..45060e7cea48 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -1552,6 +1552,7 @@ config AMD_MEM_ENCRYPT select ARCH_HAS_CC_PLATFORM select X86_MEM_ENCRYPT select UNACCEPTED_MEMORY + select CRYPTO_LIB_AESGCM help Say yes to enable support for the encryption of system memory. This requires an AMD processor that supports Secure Memory diff --git a/drivers/virt/coco/sev-guest/Kconfig b/drivers/virt/coco/sev-guest/Kconfig index 0b772bd921d8..a6405ab6c2c3 100644 --- a/drivers/virt/coco/sev-guest/Kconfig +++ b/drivers/virt/coco/sev-guest/Kconfig @@ -2,7 +2,6 @@ config SEV_GUEST tristate "AMD SEV Guest driver" default m depends on AMD_MEM_ENCRYPT - select CRYPTO_LIB_AESGCM select TSM_REPORTS help SEV-SNP firmware provides the guest a mechanism to communicate with From patchwork Wed Jul 31 15:08:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Nikunj A. Dadhania" X-Patchwork-Id: 13748890 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2072.outbound.protection.outlook.com [40.107.94.72]) (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 C5D621C0DD7; Wed, 31 Jul 2024 15:09:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.94.72 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722438562; cv=fail; b=Yu0QWIgimLyqAh2OsG6DJavodgj0FOarv/NX6OGmxweiHlVGRscaCdyLzIfTW13fi2IiAfz49g9mW98+LKAq78sfn7X7dblrw9kRlHZIfthV0VBwZC0A7UzK9dHLFziA1Ea8CN/+iKZ6nmK1JCwlObpdbU8gmJPW7YoQdXptzww= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722438562; c=relaxed/simple; bh=+CjyfxxWIq/2nT2z+2bGhN5uYpTUeMt9rZ+KekxMMMI=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Cu7KxoEFy3DiTbekjcH/pBGNbtg+nGnPhz1ejJFHLi2+HvcNiDVOLZ/xOnYHZBnFcsXnyvwwbNFpClmP00y5MT8U5g8yYJrDryAtnfQA4yt32WOc7TkornschxMRsvx12VfFv6T85x1XOdr9HZheeWXnxtb5hnoK0ihWCccMwXc= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=AYoqh2vH; arc=fail smtp.client-ip=40.107.94.72 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="AYoqh2vH" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=tr5zQ6r/TpgHtsw4Noz+wxJHI2/7b1FfcFkme4wUZLd9HMoJpFJSr2XGdlpKj9bIBZd2yEHEFfFV7J0HH2Anxk/O+qrUMP7MvoK5BM6d5kNXBFcgIXKXYA9qm4UK8P3sKowfHr0TMt4lorwdxkPk56M+hDgLJU0DdRBXHy54n7RNVI/1azWYHCrsj8T67qfTBLB76OydLG20RbJcg5oOO+iaKdjVlkG7TQlKyPnKm6qbVKNcCvSmvcFBGcqQkMLx2YxVQDHAqrq7hOBC7EePmSRMMJ2ZzhJ5yKZGvkTdyZkqQfe19KnZ9DmnNoaODIXe7UdHs5miBmaDrYych7E2HA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=FjU/yVYwUd+1601e1A45mtNJii9C2k9bMq3+GN4J2kY=; b=YA3T87c91qBbvwPV2RtQwQ5lShE8vqzb7mPGLaw+yV5P5MuhGlEVAfwiXPy9tFMsRncgt9f2pv5w3DWOmowDNfcX+Rqi4LKcf+sd5UQMHM8/CuY3prZUjhNNH4dKEhhuWCteMwq3ySX0FyCXHiOm4BEaJcLH0rSrhNKaIRM4IeenaavUYMh16HjzEoJ34aJAYCaMDh6/MYv1csvXsHVcS509O1QbPhA84SGrC3htgflkj0eJlx3oDb8KjVs4z3fpBPPfESuCwnUIK4kbMM7WN+PMK2eaWXfatMvplV+n0JC4b8GP3zY+z+dSk5Jo74/j3RyV+xa5J7OURiS3IHmAvw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=FjU/yVYwUd+1601e1A45mtNJii9C2k9bMq3+GN4J2kY=; b=AYoqh2vHfrfRoNNdrNL+qCO9ydWnRXrYdOaLiPqZI2Y3XpxYF1xrWzYnU3DspxLQtC2GGbDIs9GORPMrJFgnHcomxnb03Xw4eeRB3zflmCMLEBHC7d/mUmI4xtJ43vA2Fz+oEfjiP9cbWyLPCJbnp6HC7jzBL+RH7171Rmuh0Gw= Received: from DS7PR06CA0030.namprd06.prod.outlook.com (2603:10b6:8:54::22) by CY8PR12MB7290.namprd12.prod.outlook.com (2603:10b6:930:55::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7828.21; Wed, 31 Jul 2024 15:09:18 +0000 Received: from DS3PEPF0000C37F.namprd04.prod.outlook.com (2603:10b6:8:54:cafe::82) by DS7PR06CA0030.outlook.office365.com (2603:10b6:8:54::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7828.21 via Frontend Transport; Wed, 31 Jul 2024 15:09:18 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by DS3PEPF0000C37F.mail.protection.outlook.com (10.167.23.9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7828.19 via Frontend Transport; Wed, 31 Jul 2024 15:09:18 +0000 Received: from gomati.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Wed, 31 Jul 2024 10:09:14 -0500 From: Nikunj A Dadhania To: , , , , CC: , , , , , , Subject: [PATCH v11 13/20] x86/cc: Add CC_ATTR_GUEST_SECURE_TSC Date: Wed, 31 Jul 2024 20:38:04 +0530 Message-ID: <20240731150811.156771-14-nikunj@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240731150811.156771-1-nikunj@amd.com> References: <20240731150811.156771-1-nikunj@amd.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS3PEPF0000C37F:EE_|CY8PR12MB7290:EE_ X-MS-Office365-Filtering-Correlation-Id: b3ef1bc8-e0e7-4b83-5057-08dcb172bfeb X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|7416014|376014|1800799024|36860700013; X-Microsoft-Antispam-Message-Info: iFFi+Ugd+YrM+YeKQ0j1VXj8QSQzLdmUFqYZve91dEdtYxq1jBU/fQ/Le4HST+0QK/4u0pf3ZLSB3LBRjvIwPchQ0H9JbCWTNqP4du1MabmbrnswMm6pOgZdt4cdQF0gVk3xR/X6cJqrLAiVS3xZrLOo+0z3AqwV+gE7tPguu+RqR6LVaNmQG3kxyJamv5CeBiS0ieLGHMlRe2GXAAKKhFfeiNjR/YbQu8cCzXjKZIflJJgqBfD2z437xaGCfaajN9fjiwrAydmlttlhxheZSzteEf/Ml17VL3bMkFcdiU9ehAF8sT54Buuf+BzUGPp8al4VuoaHEepUURLtxbbcOOQjkn/Cx30k1oBjhTTiXNtvm/5W2JSCIoJLMDEFmYDJy8R6snhL72cx2f5zcq20y7DG0Oh0p6JO/CwhDH1S7j3uKewccagHmbDjQGLPVypvDw5L1qOTbTvRx212Xxp7fypSuncrYCnkeS+7Ksa+3VHZo1QXGOIac/50pdwAI8yG4Onk+aCgfZ16D4vLjiiN4E15pAj7cyu3kJgA/yd6K6UKAUBQ1LBbl2ThnrYWfDYFZI2MfHx5Z+0Q0RU8mhoXBGlHDnwyIsJHdpg4mYr8D8OUXnNS9KLkArlmNRPP1k3RmMr1VpX5vw6SOAFRMBScRnvTV7kPh5F0Q4SRPF7mJCSwTVeeRjJLH6PnPH8aOmWy23xVtL0v/GpOGKT4SxdCDRRKQbCfcQt2QYq0koAtlH1BgRvp/tGpOYglf78txzVh8Eem8tTmfLiBy482RBk6LuRHrs38DrDlamFEpI8iU7+g8asTthWca0oBvPaa7s/0NQAFrGad4W+vlxS9yGDEMCK/BXWophoC4gaIXJkwdmBOOGkyuPGa8JcPgUZk6Hij7KLsaIrg4LgLNIo1rOzpELAW5YharI/DnLNVbrF7I0eKAYG+NoRo44psRL4ti9h8HyU6DFh3PATRZo/rnbK8CSjQvB/OvMHnA+4raknP2umCLen8ZKMhT9f3KfsSelXAOrmjwKCjZdsXtphqv1EjxyY7EOpNAZndfbcX4mA5hjxu2Maj5ErnYnTqlC+fsRs4qE9p4SMG0N4qHWmsFZXKO4flJ/5QgXMvMzrE7ACpOijA8gI6cacYag9sCx8yLCPzz4PVeSjN76ABjCV+T/XEMs8t3DMElOaAPh8ZYDx/ZLkIyPEoSj6nfC2pyimgenqD7ijfS4HdiDrKO+Yg03Q1/pCmvYSaZ98G4/Ukbv0/+g0tjAHlzSO+67OoQ2BF+QQ49wbWq+uX4NPy/J/DC4N2eldbGWK7eC4poEgjF0hHaFlFppqTV7QwwSY7Lf8H1prj9bTBr3pLgIxbD5oGHLTUXdEIP5tsopxNBMYnrgZtEjC8EHo9ooB454yHD5Xh2RhyM7eag83i+yqSNTiW8pISEI+cMYxgNvn+ihjR8DWJ7/wwWAALcBNq2ljt7vOdpcOK X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(82310400026)(7416014)(376014)(1800799024)(36860700013);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Jul 2024 15:09:18.3244 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b3ef1bc8-e0e7-4b83-5057-08dcb172bfeb X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: DS3PEPF0000C37F.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY8PR12MB7290 Add confidential compute platform attribute CC_ATTR_GUEST_SECURE_TSC that can be used by the guest to query whether the Secure TSC feature is active. Signed-off-by: Nikunj A Dadhania --- include/linux/cc_platform.h | 8 ++++++++ arch/x86/coco/core.c | 3 +++ 2 files changed, 11 insertions(+) diff --git a/include/linux/cc_platform.h b/include/linux/cc_platform.h index caa4b4430634..96dc61846c9d 100644 --- a/include/linux/cc_platform.h +++ b/include/linux/cc_platform.h @@ -88,6 +88,14 @@ enum cc_attr { * enabled to run SEV-SNP guests. */ CC_ATTR_HOST_SEV_SNP, + + /** + * @CC_ATTR_GUEST_SECURE_TSC: Secure TSC is active. + * + * The platform/OS is running as a guest/virtual machine and actively + * using AMD SEV-SNP Secure TSC feature. + */ + CC_ATTR_GUEST_SECURE_TSC, }; #ifdef CONFIG_ARCH_HAS_CC_PLATFORM diff --git a/arch/x86/coco/core.c b/arch/x86/coco/core.c index 0f81f70aca82..00df00e2cb4a 100644 --- a/arch/x86/coco/core.c +++ b/arch/x86/coco/core.c @@ -100,6 +100,9 @@ static bool noinstr amd_cc_platform_has(enum cc_attr attr) case CC_ATTR_HOST_SEV_SNP: return cc_flags.host_sev_snp; + case CC_ATTR_GUEST_SECURE_TSC: + return sev_status & MSR_AMD64_SNP_SECURE_TSC; + default: return false; } From patchwork Wed Jul 31 15:08:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Nikunj A. Dadhania" X-Patchwork-Id: 13748891 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2082.outbound.protection.outlook.com [40.107.92.82]) (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 288BD1C232E; Wed, 31 Jul 2024 15:09:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.92.82 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722438568; cv=fail; b=eAQirNVkR+3xRAhgYtYANNYRSxG2HWCzObF4gzAU3Vz2RuHosX+Ic9beqahdp6xIh6nbp3BC+F4F/0MOo8dJ1ps9s2IT2sO0zFi4yvCjL2l8Kim/UlF9Np2SCA4eQYLASerTNJMA+jYkj9E+i1R/CH/aInOjcyW/5L2ho0kA5nM= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722438568; c=relaxed/simple; bh=iaXoBx6lsgfXyR7THnyyodnRKXmFqANcRlbfLAcrl1E=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=MapqzHZbCnHikBrv2/NYHXPhcurd3Q27OfV0s3j5vJon4Y2iKN4Wd0f+rkzaIYqJ1ymLvZjeGA/wu08hopECYxEv6fDPwf6+AgOyvlnPQRM8qiXWWMfIYlf/jnUItNa0/NPwKIscIFrzqFONpBuSCpejwjfPUPAUF234kD3QvTs= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=dyQRI2Nf; arc=fail smtp.client-ip=40.107.92.82 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="dyQRI2Nf" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Mb3OWEMfJDDFQIstBjMtYwjiiJrJWY74NT36zyxceyGtD9PU34f9VNsDWYLS5OQ1ypY5o/Yv67SNQyfOF9MZ0xjpc3dMcEJc1vNFrWDwWisxaDMeMkeRHxGu9yLvugX/s0rInlbGcqK3YS6ug6a3dyILhhiy/1x0kABWnNx/4ieBQYh9LVTphPM3MDnVza0Xygusyv+4+n69vz+12Vi/hpMBXlTOMtIcjpUMqRhYvPGOVsdWx8BVsbmqfGpczPtYTV9K44FUFe6Ek8/BTisDaGkCkwzYagBDVtNmU38tH5CjRDDOgGUI8BIkeB5aCewLepy+d1G+FQaqCdz+ybZiLA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=dYLQVJjvBgsar8MUVP4HHfuEpFxqxsNv2B/YLptzzqI=; b=YadNUvNgUbqeh4T8SjYVTez6bLnVjtIaNrkOZTWSWs+pwsEJ1LKcf0kHowQqsielh3edu/E/4Kp6isNKwKxXc+YdWPWlrdx3rURLyDvggggxOUFf5tCFFEhMfuKiRf5e24DiNquY/hSUBhrBKT5nTjrFCqa+TcNWWXWmAtSNUr8sBxXjjVq2uB/A/a2DJE9XYQnwJ2EYsj67iITdIGk3lpjCI6tl+muHbjbIJMDQESN2vcP2TclkSYPMgybcyzvu+MrgvoBmidzfU5zmJQGqvT43h31X8uC+hqlLmJQ5w11L308I6fc9H5j/lnKV2LLRx+78qw3F2KmkKDAlAiZLWw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=dYLQVJjvBgsar8MUVP4HHfuEpFxqxsNv2B/YLptzzqI=; b=dyQRI2Nf+7q9RqvzvUpmHXigIV6t6UjLX8YV7NEBoZdSrXZW/G9v7JGRMX7iDFdhUi2ofTUBB2q8JPS1KBL4QUE0SnJt10N4YQ3ewdIk00rGwxHIlwXw24aqpE/l56/WOkxF5TCLuOJqrhJCm3IrHWSM+4Eb8C5wynAIie5+7qI= Received: from CH0PR08CA0020.namprd08.prod.outlook.com (2603:10b6:610:33::25) by IA1PR12MB8588.namprd12.prod.outlook.com (2603:10b6:208:44f::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7807.27; Wed, 31 Jul 2024 15:09:22 +0000 Received: from DS3PEPF0000C37B.namprd04.prod.outlook.com (2603:10b6:610:33:cafe::12) by CH0PR08CA0020.outlook.office365.com (2603:10b6:610:33::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7784.35 via Frontend Transport; Wed, 31 Jul 2024 15:09:22 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by DS3PEPF0000C37B.mail.protection.outlook.com (10.167.23.5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7828.19 via Frontend Transport; Wed, 31 Jul 2024 15:09:22 +0000 Received: from gomati.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Wed, 31 Jul 2024 10:09:18 -0500 From: Nikunj A Dadhania To: , , , , CC: , , , , , , Subject: [PATCH v11 14/20] x86/sev: Add Secure TSC support for SNP guests Date: Wed, 31 Jul 2024 20:38:05 +0530 Message-ID: <20240731150811.156771-15-nikunj@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240731150811.156771-1-nikunj@amd.com> References: <20240731150811.156771-1-nikunj@amd.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS3PEPF0000C37B:EE_|IA1PR12MB8588:EE_ X-MS-Office365-Filtering-Correlation-Id: 6b674d2e-3647-4974-5e22-08dcb172c257 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|376014|7416014|1800799024|82310400026; X-Microsoft-Antispam-Message-Info: X1XGvgQsJxTc7UEmAym6HWABNXUJf0zC1reOlXgpdBvwfpB1WrCQYUM8LwnlJxP9OhX5tyS00nNB/H8irYTVGdCknCRWtwJqt6iICZN51dNeBVIUSo5BcdS3ShIYZVqsM+AV1vGv/cEm4klOROgcc35hBNJQ+hS6nZ/7ftoc6IVQaRXxDt4Fqy9oGfjvHEUu3HzXhKs9NIsk9oh8L+y3zc4pH7TT2/qor0hFwVfnhRPdLXyyfIhiiTEOx18K544K2/IaD+m7ZO/JYk4SUF+898LlMEODvDqZ3FKxhBpOA67GM59+U99cZOBAopfXmL24H0YAnUGRDl+zQ7xl8+U6Ahky0XTO/uaQyBnA+yNSWb/Qha9xhAEgsdi6q7v+k86Kxx3g5hsXhrRVa0IJh0IR9BssBz0guj5tjwiZHTCw6Ygs9DI3OLB7P4kdSxEVRjLQMv0Y1xuyEj16bpxb9m+jYZ6GOc6ohas0hbKtzpzUXGndGscUwFsFhNMZEeTuqNZylSqN9tu5Ttrn5zRcUGCagMmI9nAIO0Ycj4D/TxzwlXcnSmOadj3YqfQgv0fu5B6utxRlH6ZdqF8pjwA1SLroypQg3y4UqKjqGoOzIQre6nSdGZoLfOteTXLl9cJcIlxiYtyNzXWDNMFXJkWd+tLYxyAbMLn7q7qxKS/NEdVXn8EjILtZqOSoNmMrRl+9ny+BVDjFIxG91c/GG4lEUUQ89tqIkvahd0xUp5I1dA9Tg+MZDB9rEq8zHqqVl12L8nGLVrqOn8uRX9dNgoHlRB0lW8FXvc1JUDjfYr+93DRLGW8B2FW4EauoinaOD6kVbgumVAC+jHXEwp1zrH1OzxBuLfPX2FTDI9jL5ntCrrn3xbZG31RjjCe5fHmuWZoQWSX90wQSUv5x7jTgfcsA/KNjQGGoHV4XJ7TceIOMoOdcxjijmpd5Ji2yBcKVa2N7i8HRueKiF/bNEStzpBgszJdjrAP+tiAvXjTvgQT7bwBq3CeNZVGeeMe7ErQvvzouSDY/MwoZV4dt0wo/cO9BDaHdpaog0/PQ2OJsrAkuDuJxOQJsXVZVaiZGf0gzmBVukbGiTAZu99OLB+Yw1NG47p7AangbR859p2aCybRcDIcpA2vd6i8INkqwek/LP7CCSYkO/sEpuQeL0WwQbgS3GtAyf0egkmXw7dLiChrym5soO7pv78Tv5z+S/lw6+kze0HUpjCslnYxH1kvD7QhW/BXyg0v071r6XMmukHCGTJ4+EpjYvRT8fmPKffNTdJK2GjqcbxWv5LxJvN5UHvaUn/nmdaOOClD0OnE2ffrFN+LH3bBRtluLKuwq64iL+Qe6BqGRFUiSUuLLwLxTEyf6RW3U2V24inri6VAU8iN+7iX0SwbECfqmXGB+1UgyglxBxzd29JXR9b9uPeNgYb7ywbWW/OIpCzK/AHE5BfcO4Vd/Kb1aovp4Nei5/68t6g+2n/bV X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(36860700013)(376014)(7416014)(1800799024)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Jul 2024 15:09:22.3567 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 6b674d2e-3647-4974-5e22-08dcb172c257 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: DS3PEPF0000C37B.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB8588 Add support for Secure TSC in SNP-enabled guests. Secure TSC allows guests to securely use RDTSC/RDTSCP instructions, ensuring that the parameters used cannot be altered by the hypervisor once the guest is launched. Secure TSC-enabled guests need to query TSC information from the AMD Security Processor. This communication channel is encrypted between the AMD Security Processor and the guest, with the hypervisor acting merely as a conduit to deliver the guest messages to the AMD Security Processor. Each message is protected with AEAD (AES-256 GCM). Use a minimal AES GCM library to encrypt and decrypt SNP guest messages for communication with the PSP. Use mem_encrypt_init() to fetch SNP TSC information from the AMD Security Processor and initialize snp_tsc_scale and snp_tsc_offset. During secondary CPU initialization, set the VMSA fields GUEST_TSC_SCALE (offset 2F0h) and GUEST_TSC_OFFSET (offset 2F8h) with snp_tsc_scale and snp_tsc_offset, respectively. Since handle_guest_request() is common routine used by both the SEV guest driver and Secure TSC code, move it to the SEV header file. Signed-off-by: Nikunj A Dadhania Tested-by: Peter Gonda Reviewed-by: Tom Lendacky --- arch/x86/include/asm/sev-common.h | 1 + arch/x86/include/asm/sev.h | 46 +++++++++++++ arch/x86/include/asm/svm.h | 6 +- arch/x86/coco/sev/core.c | 91 +++++++++++++++++++++++++ arch/x86/mm/mem_encrypt.c | 4 ++ drivers/virt/coco/sev-guest/sev-guest.c | 19 ------ 6 files changed, 146 insertions(+), 21 deletions(-) diff --git a/arch/x86/include/asm/sev-common.h b/arch/x86/include/asm/sev-common.h index 98726c2b04f8..655eb0ac5032 100644 --- a/arch/x86/include/asm/sev-common.h +++ b/arch/x86/include/asm/sev-common.h @@ -206,6 +206,7 @@ struct snp_psc_desc { #define GHCB_TERM_NO_SVSM 7 /* SVSM is not advertised in the secrets page */ #define GHCB_TERM_SVSM_VMPL0 8 /* SVSM is present but has set VMPL to 0 */ #define GHCB_TERM_SVSM_CAA 9 /* SVSM is present but CAA is not page aligned */ +#define GHCB_TERM_SECURE_TSC 10 /* Secure TSC initialization failed */ #define GHCB_RESP_CODE(v) ((v) & GHCB_MSR_INFO_MASK) diff --git a/arch/x86/include/asm/sev.h b/arch/x86/include/asm/sev.h index eda435eba53e..f95fa64bf480 100644 --- a/arch/x86/include/asm/sev.h +++ b/arch/x86/include/asm/sev.h @@ -146,6 +146,9 @@ enum msg_type { SNP_MSG_VMRK_REQ, SNP_MSG_VMRK_RSP, + SNP_MSG_TSC_INFO_REQ = 17, + SNP_MSG_TSC_INFO_RSP, + SNP_MSG_TYPE_MAX }; @@ -174,6 +177,22 @@ struct snp_guest_msg { u8 payload[PAGE_SIZE - sizeof(struct snp_guest_msg_hdr)]; } __packed; +#define SNP_TSC_INFO_REQ_SZ 128 +#define SNP_TSC_INFO_RESP_SZ 128 + +struct snp_tsc_info_req { + u8 rsvd[SNP_TSC_INFO_REQ_SZ]; +} __packed; + +struct snp_tsc_info_resp { + u32 status; + u32 rsvd1; + u64 tsc_scale; + u64 tsc_offset; + u32 tsc_factor; + u8 rsvd2[100]; +} __packed; + struct snp_guest_req { void *req_buf; size_t req_sz; @@ -499,6 +518,27 @@ static inline void snp_msg_cleanup(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); +static inline int handle_guest_request(struct snp_msg_desc *mdesc, u64 exit_code, + struct snp_guest_request_ioctl *rio, u8 type, + void *req_buf, size_t req_sz, void *resp_buf, + u32 resp_sz) +{ + struct snp_guest_req req = { + .msg_version = rio->msg_version, + .msg_type = type, + .vmpck_id = mdesc->vmpck_id, + .req_buf = req_buf, + .req_sz = req_sz, + .resp_buf = resp_buf, + .resp_sz = resp_sz, + .exit_code = exit_code, + }; + + return snp_send_guest_request(mdesc, &req, rio); +} + +void __init snp_secure_tsc_prepare(void); + #else /* !CONFIG_AMD_MEM_ENCRYPT */ #define snp_vmpl 0 @@ -545,6 +585,12 @@ static inline struct snp_msg_desc *snp_msg_alloc(void) { return NULL; } static inline void snp_msg_cleanup(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 handle_guest_request(struct snp_msg_desc *mdesc, u64 exit_code, + struct snp_guest_request_ioctl *rio, u8 type, + void *req_buf, size_t req_sz, void *resp_buf, + u32 resp_sz) { return -ENODEV; } + +static inline void __init snp_secure_tsc_prepare(void) { } #endif /* CONFIG_AMD_MEM_ENCRYPT */ diff --git a/arch/x86/include/asm/svm.h b/arch/x86/include/asm/svm.h index f0dea3750ca9..1695a933106b 100644 --- a/arch/x86/include/asm/svm.h +++ b/arch/x86/include/asm/svm.h @@ -417,7 +417,9 @@ struct sev_es_save_area { u8 reserved_0x298[80]; u32 pkru; u32 tsc_aux; - u8 reserved_0x2f0[24]; + u64 tsc_scale; + u64 tsc_offset; + u8 reserved_0x300[8]; u64 rcx; u64 rdx; u64 rbx; @@ -549,7 +551,7 @@ static inline void __unused_size_checks(void) BUILD_BUG_RESERVED_OFFSET(sev_es_save_area, 0x1c0); BUILD_BUG_RESERVED_OFFSET(sev_es_save_area, 0x248); BUILD_BUG_RESERVED_OFFSET(sev_es_save_area, 0x298); - BUILD_BUG_RESERVED_OFFSET(sev_es_save_area, 0x2f0); + BUILD_BUG_RESERVED_OFFSET(sev_es_save_area, 0x300); BUILD_BUG_RESERVED_OFFSET(sev_es_save_area, 0x320); BUILD_BUG_RESERVED_OFFSET(sev_es_save_area, 0x380); BUILD_BUG_RESERVED_OFFSET(sev_es_save_area, 0x3f0); diff --git a/arch/x86/coco/sev/core.c b/arch/x86/coco/sev/core.c index aaeeca938265..9815aa419978 100644 --- a/arch/x86/coco/sev/core.c +++ b/arch/x86/coco/sev/core.c @@ -98,6 +98,10 @@ static u64 secrets_pa __ro_after_init; static struct snp_msg_desc *snp_mdesc; +/* Secure TSC values read using TSC_INFO SNP Guest request */ +static u64 snp_tsc_scale __ro_after_init; +static u64 snp_tsc_offset __ro_after_init; + /* #VC handler runtime per-CPU data */ struct sev_es_runtime_data { struct ghcb ghcb_page; @@ -1175,6 +1179,12 @@ static int wakeup_cpu_via_vmgexit(u32 apic_id, unsigned long start_ip) vmsa->vmpl = snp_vmpl; vmsa->sev_features = sev_status >> 2; + /* Set Secure TSC parameters */ + if (cc_platform_has(CC_ATTR_GUEST_SECURE_TSC)) { + vmsa->tsc_scale = snp_tsc_scale; + vmsa->tsc_offset = snp_tsc_offset; + } + /* Switch the page over to a VMSA page now that it is initialized */ ret = snp_set_vmsa(vmsa, caa, apic_id, true); if (ret) { @@ -2981,3 +2991,84 @@ int snp_send_guest_request(struct snp_msg_desc *mdesc, struct snp_guest_req *req return 0; } EXPORT_SYMBOL_GPL(snp_send_guest_request); + +static int __init snp_get_tsc_info(void) +{ + static u8 buf[SNP_TSC_INFO_RESP_SZ + AUTHTAG_LEN]; + struct snp_guest_request_ioctl rio; + struct snp_tsc_info_resp tsc_resp; + struct snp_tsc_info_req *tsc_req; + struct snp_msg_desc *mdesc; + struct snp_guest_req req; + int rc; + + /* + * The intermediate response buffer is used while decrypting the + * response payload. Make sure that it has enough space to cover the + * authtag. + */ + BUILD_BUG_ON(sizeof(buf) < (sizeof(tsc_resp) + AUTHTAG_LEN)); + + mdesc = snp_msg_alloc(); + if (IS_ERR_OR_NULL(mdesc)) + return -ENOMEM; + + rc = snp_msg_init(mdesc, snp_vmpl); + if (rc) + return rc; + + tsc_req = kzalloc(sizeof(struct snp_tsc_info_req), GFP_KERNEL); + if (!tsc_req) + return -ENOMEM; + + memset(&req, 0, sizeof(req)); + memset(&rio, 0, sizeof(rio)); + memset(buf, 0, sizeof(buf)); + + req.msg_version = MSG_HDR_VER; + req.msg_type = SNP_MSG_TSC_INFO_REQ; + req.vmpck_id = snp_vmpl; + req.req_buf = tsc_req; + req.req_sz = sizeof(*tsc_req); + req.resp_buf = buf; + req.resp_sz = sizeof(tsc_resp) + AUTHTAG_LEN; + req.exit_code = SVM_VMGEXIT_GUEST_REQUEST; + + rc = snp_send_guest_request(mdesc, &req, &rio); + if (rc) + goto err_req; + + memcpy(&tsc_resp, buf, sizeof(tsc_resp)); + pr_debug("%s: response status %x scale %llx offset %llx factor %x\n", + __func__, tsc_resp.status, tsc_resp.tsc_scale, tsc_resp.tsc_offset, + tsc_resp.tsc_factor); + + if (tsc_resp.status == 0) { + snp_tsc_scale = tsc_resp.tsc_scale; + snp_tsc_offset = tsc_resp.tsc_offset; + } else { + pr_err("Failed to get TSC info, response status %x\n", tsc_resp.status); + rc = -EIO; + } + +err_req: + /* The response buffer contains the sensitive data, explicitly clear it. */ + memzero_explicit(buf, sizeof(buf)); + memzero_explicit(&tsc_resp, sizeof(tsc_resp)); + memzero_explicit(&req, sizeof(req)); + + return rc; +} + +void __init snp_secure_tsc_prepare(void) +{ + if (!cc_platform_has(CC_ATTR_GUEST_SECURE_TSC)) + return; + + if (snp_get_tsc_info()) { + pr_alert("Unable to retrieve Secure TSC info from ASP\n"); + sev_es_terminate(SEV_TERM_SET_LINUX, GHCB_TERM_SECURE_TSC); + } + + pr_debug("SecureTSC enabled"); +} diff --git a/arch/x86/mm/mem_encrypt.c b/arch/x86/mm/mem_encrypt.c index 0a120d85d7bb..996ca27f0b72 100644 --- a/arch/x86/mm/mem_encrypt.c +++ b/arch/x86/mm/mem_encrypt.c @@ -94,6 +94,10 @@ void __init mem_encrypt_init(void) /* Call into SWIOTLB to update the SWIOTLB DMA buffers */ swiotlb_update_mem_attributes(); + /* Initialize SNP Secure TSC */ + if (cc_platform_has(CC_ATTR_GUEST_SEV_SNP)) + snp_secure_tsc_prepare(); + print_mem_encrypt_feature_info(); } diff --git a/drivers/virt/coco/sev-guest/sev-guest.c b/drivers/virt/coco/sev-guest/sev-guest.c index 019eca753f85..db1b00db624d 100644 --- a/drivers/virt/coco/sev-guest/sev-guest.c +++ b/drivers/virt/coco/sev-guest/sev-guest.c @@ -64,25 +64,6 @@ static inline struct snp_guest_dev *to_snp_dev(struct file *file) return container_of(dev, struct snp_guest_dev, misc); } -static int handle_guest_request(struct snp_msg_desc *mdesc, u64 exit_code, - struct snp_guest_request_ioctl *rio, u8 type, - void *req_buf, size_t req_sz, void *resp_buf, - u32 resp_sz) -{ - struct snp_guest_req req = { - .msg_version = rio->msg_version, - .msg_type = type, - .vmpck_id = mdesc->vmpck_id, - .req_buf = req_buf, - .req_sz = req_sz, - .resp_buf = resp_buf, - .resp_sz = resp_sz, - .exit_code = exit_code, - }; - - return snp_send_guest_request(mdesc, &req, rio); -} - struct snp_req_resp { sockptr_t req_data; sockptr_t resp_data; From patchwork Wed Jul 31 15:08:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Nikunj A. Dadhania" X-Patchwork-Id: 13748892 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2072.outbound.protection.outlook.com [40.107.94.72]) (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 BE9081C688B; Wed, 31 Jul 2024 15:09:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.94.72 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722438570; cv=fail; b=GLyStzNfLNlvf7spAK34wDnUFdKdGH1Lezqmm2WGm36s2g0jhNc5e1O+tzgL30zTLUAor1GCq3f0ORcoBPzYS2ivzSRmxca6K99rS/QucndYYMVjPbVDPokHx6wFQoJsg1U22YlS1QDXketE11/FmYQ99E9X2uBA55L3p6Tqjz4= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722438570; c=relaxed/simple; bh=hSZbUW2/bM1A6QdJ60yq069vhtw0izSkgM8HaEajmac=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=XN8sZze4hctq+g1dDtdN0TLsU/XW3xJMNggZbKifSlLz5pGwoYuP2LEu4K/xWKy3MoyFKV6UejisJ7JfhtYYqCAZwR/OxDWxQNrRKw8/IBnUBOfTHoDOumEiXyNQq9QM1dOg0lX3xXRFlKe4TOnQgIpQClLPBsNX7uTiUj7Za8s= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=1VmQAjJQ; arc=fail smtp.client-ip=40.107.94.72 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="1VmQAjJQ" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=C9nGsjZfGwfVs5mtOpCj+vv2FguiYcAxJhavKnGnGWiiIFfF/Q0Wu5bjlBE3XqV5P5C6632g2/1X5CFfM4ol4dn249ksyLJFH1n+qSzs6DfngAX0qX/9YDYKOTJwfrkDNrzoXca9qMJsgLW5T0vJ611E6TA87+XOOWGpsBV64TFQToL57Fk905r15i0IbEKHN8I4e3ZC8/SyxoNQro9cCbLgLr9IdX5hPWVAC73Sj4cj05Xsq95I7q0z9Q9pBJXTYCk6Td1zNtaZ9k0ncZDVFm4y7SmcZPRUwtW1uN2Z0m5pAKpRnC+uFkVhNsIL/ULYoJn6/fmpBpJ7yAW36QN3yw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=8pvAGzjYDbGXaW/62fZKkjZr7d9W/JeYpXG1PMAlFkk=; b=xZy2m4cANEkoCezvfgDJ5yUOOxWuNuhwYyX9+JfBplTZsfZUnjMdryTY344MupoHupWh6rfVltWypTWQAaXj5yq41qGiGgq6b0mkTDFOqxJJkkZxlPgrPZBdN2QCSOiK6LvMetpTJvt83gLeZvOntP12KcKQ4yyB6e2M2C9qT+9qVaRARKv76B+hOOOovw+E0q+HtQ/DkBfkiYBX697DqQFWs+Cxvt8FjBpp252zLNRVbkIYRHlxSh2syEMQpWUBB9wr4oSTUdGpZg20Ft/73WRxvmyboTpllRqsna1x7YFR/wCW4o2wnIM/P0FqycsxS0KncPp/hgv4n+Pes5D1Lw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=8pvAGzjYDbGXaW/62fZKkjZr7d9W/JeYpXG1PMAlFkk=; b=1VmQAjJQLh/pYTMUE4MRKDuQRRPjV1D674Itwr1vhGvvx3J+L5Kp4bWuERoHUk8p8u0QG1DtL9jNmHJCPEo/Lf2znt+8cXiEaeU3ggi+wLR8Txq1F8BAXUqTdGn1ZjztBxZip3bso3mn9IKLzXGu6htKm7f47wD3ATqSZq7qCYg= Received: from DS7PR06CA0042.namprd06.prod.outlook.com (2603:10b6:8:54::23) by CH3PR12MB8481.namprd12.prod.outlook.com (2603:10b6:610:157::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7828.21; Wed, 31 Jul 2024 15:09:26 +0000 Received: from DS3PEPF0000C37F.namprd04.prod.outlook.com (2603:10b6:8:54:cafe::24) by DS7PR06CA0042.outlook.office365.com (2603:10b6:8:54::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7784.35 via Frontend Transport; Wed, 31 Jul 2024 15:09:26 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by DS3PEPF0000C37F.mail.protection.outlook.com (10.167.23.9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7828.19 via Frontend Transport; Wed, 31 Jul 2024 15:09:26 +0000 Received: from gomati.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Wed, 31 Jul 2024 10:09:22 -0500 From: Nikunj A Dadhania To: , , , , CC: , , , , , , Subject: [PATCH v11 15/20] x86/sev: Change TSC MSR behavior for Secure TSC enabled guests Date: Wed, 31 Jul 2024 20:38:06 +0530 Message-ID: <20240731150811.156771-16-nikunj@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240731150811.156771-1-nikunj@amd.com> References: <20240731150811.156771-1-nikunj@amd.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS3PEPF0000C37F:EE_|CH3PR12MB8481:EE_ X-MS-Office365-Filtering-Correlation-Id: 526e4af0-dcab-4d1d-2f3f-08dcb172c498 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|376014|7416014|36860700013|1800799024; X-Microsoft-Antispam-Message-Info: SayNvtN1Le2T/25a8zf5/C1edYkmEjnVpOO0wkPw9ga0EnVTLxbUHLPTGPo0XB2dTsWw7JkHe52cyI2Xh85w8GRri1uHHbvMQrn9PrvnIhxKVdVfNDTehHhyr706kxjr413SbR8x/1401fLmuuiNS61bzKoE2EdMnFKxj/G0JaCbpGsvm/TYHEJpFQQExUuGbXROIKMKlgJbiTzz+cW9rfc2o0FV7EYMf44lTc/WghU4bLIfv+Rk4rxrTpYHwffRMil9tWQmbKCkvo5FEHgzNhyXLAXLRlvKIUNNB/KThv8ePYP/I0cSxUvD6g3TT/a8Prg4ot3IMxZqp5C2koFqmaWnafBPqi3wmQrBI2ZNzizaGU/bodJyKC2bYraT8eGBNgQVslqDbdTxxAQI7Xs3gJRdNIKFYapRrzs1HFoLLNLo8mEHAJ+qk48iV4uPy97Ug4shCUK35d4KpMn4uzijY8Xr1ngV2/60/jRTWT30ab3It8UzrK7KVg/nSGyN22b2gBt31/6VdpyUlk4B7uQIuNaZ1/ECDETsGKi5WuN4+P1gaS3wq9/A6LasyupVbtvSuxTzbtKKfuA07fFzPVPFdZOF3PvM9cPJ3zu87cr8cs2J3hCM1cicy16tKO4VwaAuYPY53RdNmIdl1woNmBThrajizZ5AkeKgtY/a9vbx/cRukPEYfgi0cyQ6MboitZqRP2UtUtFtzROwhmKuxy9RmApz1mqCulkDim1SCE38guKLJHF2bxcgIe1LA32gUPX7Csf6ElnUZQLBzkGDsP7E9avaYT58VqVvO1zzliPeWANJ+OgcoON7eB8tM1DaepACZ9zBu3A5kKUDsANtrDTLjLKZ7K5bRsW1uGW2+lRDl4BdcxpVJWGSNfMZA6ZNxX/SYCyRfVILbZcWyoQHB2sQHcsdpF5jJDNml5TXROG329pvZy1U4F2x/p7yUD01c8cN8/AaD4t5oUc7MrmStB7VY2Qc+8QRKJOwKGobRc8/6Vs1bv20Tbu7KaFTrdxTOIkOrLRezWR81jcgO0EK3nBUDLzYy/+dRh7MGhLcvGi6lrmHW4Xp//NEW1thB55Fm+84JzlV3YXAg7560m5rJ6XczMAl/Z/JoPtDHPz731VTIYWra89KUJv5etnKkYuizWfXdanRAXG2eytC+U7orleNh5ZhjFOtYGaV0wo4qSYsNtuePes00FGlulb1ND8WoPOb0xwMe5abY92+Q6RpIIgq4vTbo49j3+YemQ5fQQ4Hyq/MyEzSpHy2wX5RrAIU8HUrHe0XxEwgyiBeMq9uywjR1cOrNvPUO3i7B0y0APGke7Fx+kl0BImFSn6Trxz54Fb91xXnvoQa0+8UbZsR+DgnZRnWB06cx8OUe6pIOzAw/GsI1av7ZI47di6N/f4U7lysQhlg4aocO2j2rnzekeWR604fqRsL6nbhWNstcC1y0gAhhnQZLMng+3PjO5CSLpPr X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(82310400026)(376014)(7416014)(36860700013)(1800799024);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Jul 2024 15:09:26.1370 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 526e4af0-dcab-4d1d-2f3f-08dcb172c498 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: DS3PEPF0000C37F.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH3PR12MB8481 Secure TSC enabled guests should not write to MSR_IA32_TSC(10H) register as the subsequent TSC value reads are undefined. MSR_IA32_TSC read/write accesses should not exit to the hypervisor for such guests. Accesses to MSR_IA32_TSC needs special handling in the #VC handler for the guests with Secure TSC enabled. Writes to MSR_IA32_TSC should be ignored, and reads of MSR_IA32_TSC should return the result of the RDTSC instruction. Signed-off-by: Nikunj A Dadhania Reviewed-by: Tom Lendacky Tested-by: Peter Gonda --- arch/x86/coco/sev/core.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/arch/x86/coco/sev/core.c b/arch/x86/coco/sev/core.c index 9815aa419978..a4c737afce50 100644 --- a/arch/x86/coco/sev/core.c +++ b/arch/x86/coco/sev/core.c @@ -1335,6 +1335,30 @@ static enum es_result vc_handle_msr(struct ghcb *ghcb, struct es_em_ctxt *ctxt) return ES_OK; } + /* + * TSC related accesses should not exit to the hypervisor when a + * guest is executing with SecureTSC enabled, so special handling + * is required for accesses of MSR_IA32_TSC: + * + * Writes: Writing to MSR_IA32_TSC can cause subsequent reads + * of the TSC to return undefined values, so ignore all + * writes. + * Reads: Reads of MSR_IA32_TSC should return the current TSC + * value, use the value returned by RDTSC. + */ + if (regs->cx == MSR_IA32_TSC && cc_platform_has(CC_ATTR_GUEST_SECURE_TSC)) { + u64 tsc; + + if (exit_info_1) + return ES_OK; + + tsc = rdtsc(); + regs->ax = UINT_MAX & tsc; + regs->dx = UINT_MAX & (tsc >> 32); + + return ES_OK; + } + ghcb_set_rcx(ghcb, regs->cx); if (exit_info_1) { ghcb_set_rax(ghcb, regs->ax); From patchwork Wed Jul 31 15:08:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Nikunj A. Dadhania" X-Patchwork-Id: 13748893 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2048.outbound.protection.outlook.com [40.107.220.48]) (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 D0AFA1C8FAA; Wed, 31 Jul 2024 15:09:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.220.48 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722438574; cv=fail; b=H0p1JHgBWzonS8Csw+F+Q87PLtZnx/El53OyEdCcDEj0mE8Dlqe3SXm0s1RE7nxvIv8V0h1R/8Tv1cXNf3MKJ9dKph+sRIq8jmAFGF1UAglKJ8pJ21HQ8oAb91x9AiA0mgL045pbzA61x9r4lOyC9xHAvDYXgABflXZIjdYnsXk= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722438574; c=relaxed/simple; bh=ItwoiZD9LvgFRJA2ybGt2PhIvRzdO0LtcWvnUMsPZdM=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=N9/o2kXmH5UPnTxM1ejmStfFIuAWaTMV+Hl/VTFYkwLHxwepiFzxdxTFPSDHMG05Me5LLOpEKiMVb0AJGF4coAC+y1kwcjPz+Fe9rQTfBXsm5ULKw6Ov46FnxiLhDToIGsRLLijZBlOyBOui+AlOynamYhWRFMqqQGE02pFFUwM= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=rKBL4Tvl; arc=fail smtp.client-ip=40.107.220.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="rKBL4Tvl" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=TxTDZsIV3WoYjzD8+1ES8HkOoZkgJdBy1hM5mTVGA2n159xaRzhr9U3+Dyp0/oFUmsF7/w+5/E/EPAF09dYWuT693f+XmAxEDFwTtjdrzVnyqNYmIxfWIrxPUjOmtzPT4ttLBcRmNSjVRJM2kyRh27+t6uvQeTzzOZCU/iUoph1yk0ZXgEKxE3zGwdKIWIL0wPDBnCegaDfMMeFEPXynlwaF1fumQyUyhkzWT40h16Jg4PMfIKT32A1wBPcAAgFL1dqNOwrGXsakFavdLI0Ee5JJQFrJ5OroLD3QFdLC6iYvoSC1N8Q2ccIP/Tlvgg3EbPvbQ0XxTQXmljYaK+TdMA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=TJ2QdKOWRkpeQDBq/qhe8xRHxlc7lUFXXHL1l+Uqt/o=; b=ddms13Q42lSYABp50Su3j7KJpLmIkxh9Tx3tBa6dxyLAbEBM5YILDTrVqs+EHHJHQFc9VAPJTTj4S6+4qukD9ddG2iudcGtGqtnf+Tw9ZGUZ0QbP742FXHAk3+MfB03FS4Ma9Pi6Y9IyfebYSENdOrcdg6UB9d/Heh7Ik64Kggc35INK5KyQ0oU4B/A4ZuDiHfEEUXrG3YWPORc1QDO5FxT6nhAV5azOsRmxrL3VwvjALrIN8hyq8TPA1kRLztI2V5pn61FUFLAULi8RpiAG7eSmjcieX3B0JYaHmW7A7axbbTyheuJrm/E50OI6ArgjJlXqcjvTFPQ2LwpnUO1DtA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=TJ2QdKOWRkpeQDBq/qhe8xRHxlc7lUFXXHL1l+Uqt/o=; b=rKBL4Tvln4RRRau9mn+rvYe/VJuHf7G1zRFMgnsn3N+q7AWVfQmRXNsEBGyaK759Iu5FAWSellJexlTpseiZP5pM4ltHQTgj5TZLUTrpUSVxsldACZ7e0Fbqv9hoK1+396INPA40J/56YMJjnK/DEpGrSwIVVPn14P3QKR99xyE= Received: from DM6PR13CA0009.namprd13.prod.outlook.com (2603:10b6:5:bc::22) by DM3PR12MB9288.namprd12.prod.outlook.com (2603:10b6:0:4a::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7828.21; Wed, 31 Jul 2024 15:09:30 +0000 Received: from DS3PEPF0000C37D.namprd04.prod.outlook.com (2603:10b6:5:bc:cafe::9d) by DM6PR13CA0009.outlook.office365.com (2603:10b6:5:bc::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7762.19 via Frontend Transport; Wed, 31 Jul 2024 15:09:30 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by DS3PEPF0000C37D.mail.protection.outlook.com (10.167.23.7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7828.19 via Frontend Transport; Wed, 31 Jul 2024 15:09:30 +0000 Received: from gomati.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Wed, 31 Jul 2024 10:09:25 -0500 From: Nikunj A Dadhania To: , , , , CC: , , , , , , Subject: [PATCH v11 16/20] x86/sev: Prevent RDTSC/RDTSCP interception for Secure TSC enabled guests Date: Wed, 31 Jul 2024 20:38:07 +0530 Message-ID: <20240731150811.156771-17-nikunj@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240731150811.156771-1-nikunj@amd.com> References: <20240731150811.156771-1-nikunj@amd.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS3PEPF0000C37D:EE_|DM3PR12MB9288:EE_ X-MS-Office365-Filtering-Correlation-Id: 751e721d-873a-4cdf-bf99-08dcb172c70a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|36860700013|82310400026|376014|7416014; X-Microsoft-Antispam-Message-Info: R5m2LtzmGRqFgl+4G9BBNkCOo5LGGtYS4/v/NGEriyFO3CxLKgWYlWLO5inZWjbo82aEcKC+0FbNCEqFw5hhFw3Tr8o1jzBur0q9hIi3lp6Lro6Xtsr/5Jui1bvp54EKnpKZHkPnpnaC217JicSg1O/WbI6G46vHSN/ZgNTt7ZU5cKfGnua+Xt78wkymoDGhvw2XEHC9gKqFAwRyUQ5qsTQ7W46q09oXlji9gQVP5mbE4wivguxo3xEIqYoksw/0QFHiLp1dP6jVG5tzggUVSFS86aBRz0nS+w/HiiRxjClg/aYAwOZvMyKQPzNpkgR7OsM4KwXIi65rZQW3JiJ5Xt1ZMqQCYrtwZYrwJWA0NU1dNTxT+y9Cv+si6vVKtl3RZndPsiwDT2OSuydNt04k1PBb27FUeg5o0YnCUQpuAVZHK+M3yYei1UOBVUwAXyxe5F6Dv38N2c0kvNas3KDe2jTDoGN3vc/2y0dgzJE1yZdSA8L52YMrvpiLKwWSiqEXsZDNrlgCn9fqT2/cGFeftMFIHWuGBUoIhX8LTUfCUKUAyWEqIvNEde3nuP3Urv2AlwroVKHx2CZ5EDoeHSYUviuBOq9JLfTAOiCTEfoxTh5vdu0XhYXZvxzDBfL2IM8/mEz3KFaqyOfsarc2LjxEhuXgcjPZGDrffeFLtmue8jh+pzNtgXIGdfCCIOsTCP9oaoPYUsZ9JPwPH5X9cq2v2msNHEsvqzigwWTEEVgRqDUgd/FGS8VcsRdFAuLXV+ArnOgBL157uRgXOTEuc5pfccuItcSgxoPdbpB3bDjpe2lKC9jrbmOkGUIW/dvkWZpFztB2k9CHNTrxriMwL4dv6pgc5UjT4TY2d6Pony6NhkHkWnChdpXdvlRU/w/vEVa89xbLuVln3xz7z1FISSV0q2oZ70RWgdaHwFW/n5dp6ab87nDtrzauszfGdS84nq0cG4oRKnrmno2Z4uvqg2ko+wq8xz9VkJq+F/H1L5MkbRU2ZeK4lWe7pwiL4T0iFM72DtN4Q2BMximPzDQW3O8unm7MUWENash+1DtTLWw270qeXhdLajshlaWF9o3BAxedvg7DOPVtVvvHEKwqSBODOvCS5f1bjVb+5Nhe5h1uf8qXp/WAmEND2jJRs6s2a6r1Qsmd+yobUznogaN8VvI78JixVYDidq0alnEYgkMys+Mprrknus9TyXmxgGYqsvG74C+9p0oOJBTQcneYBsoXmIZ3x4BOgFNpAIdHTlKrYoi/oLx5yAOXn2sYh3ht1iFkEhRbdZma7O0/fRSTFMWnneKlE+cuftZfLYOsLmBedznQYkVxpETcl9ZJXxtQp4wCOYBUliLps10tapUSPLLAufq05//G1p0qw2GRgDcFT7FotnQ8bqc5LZP4uFEtxETV6hg/GlX8r1Znjea0qMzeGGNQQvT/+KZ13QREBqVMP8Q6omj09Ux1Bw2oV2sZEn3W X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(1800799024)(36860700013)(82310400026)(376014)(7416014);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Jul 2024 15:09:30.2432 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 751e721d-873a-4cdf-bf99-08dcb172c70a X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: DS3PEPF0000C37D.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM3PR12MB9288 The hypervisor should not be intercepting RDTSC/RDTSCP when Secure TSC is enabled. A #VC exception will be generated if the RDTSC/RDTSCP instructions are being intercepted. If this should occur and Secure TSC is enabled, terminate guest execution. Signed-off-by: Nikunj A Dadhania Tested-by: Peter Gonda Reviewed-by: Tom Lendacky --- arch/x86/coco/sev/shared.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/arch/x86/coco/sev/shared.c b/arch/x86/coco/sev/shared.c index 71de53194089..c2a9e2ada659 100644 --- a/arch/x86/coco/sev/shared.c +++ b/arch/x86/coco/sev/shared.c @@ -1140,6 +1140,16 @@ static enum es_result vc_handle_rdtsc(struct ghcb *ghcb, bool rdtscp = (exit_code == SVM_EXIT_RDTSCP); enum es_result ret; + /* + * RDTSC and RDTSCP should not be intercepted when Secure TSC is + * enabled. Terminate the SNP guest when the interception is enabled. + * This file is included from kernel/sev.c and boot/compressed/sev.c, + * use sev_status here as cc_platform_has() is not available when + * compiling boot/compressed/sev.c. + */ + if (sev_status & MSR_AMD64_SNP_SECURE_TSC) + return ES_VMM_ERROR; + ret = sev_es_ghcb_hv_call(ghcb, ctxt, exit_code, 0, 0); if (ret != ES_OK) return ret; From patchwork Wed Jul 31 15:08:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Nikunj A. Dadhania" X-Patchwork-Id: 13748894 Received: from NAM04-DM6-obe.outbound.protection.outlook.com (mail-dm6nam04on2042.outbound.protection.outlook.com [40.107.102.42]) (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 23C4A1C8FD3; Wed, 31 Jul 2024 15:09:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.102.42 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722438577; cv=fail; b=MYF/ifY3cxu1kBSqWrr6V1RVNajQ60OT0ePQ7YLpD0YBeLIel3xwOuI6Da6v95LepNsdjcSmKwCTq9fVXvL+2ltq9CjZIBjKs6bLb+RjLc1R050HpFVarbglb5gH7rI36OnKVvCGmN9njQsI92vwEx3HYSMVwC2NyTXAwweg0WM= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722438577; c=relaxed/simple; bh=cAC/VFJ4wEnAQpkNDwUveWrurfRumjkFBldmm9DGTEY=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=RLiuhG9AsJGSRhuB9rxQ+cM7W2CtSRu9hJjAdn3lkGESMixSNk3rNJKfap9qMW/a8dIvVshqXSzryBmO3PxQbBqCoVTSX6FF4bfYvTtQlpgqr70GwwsG5wm6oUHTU5UrQwXE0q1x0+sDvqod0TansKee1uQb6MSo9jwIsPX0N/Q= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=JZIt4EpY; arc=fail smtp.client-ip=40.107.102.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="JZIt4EpY" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Gbsir2laVek9LdC1gRLEALCmAoA3kBxPZR0Yfk4DZONaHNshmPadW0fuBm2lomeSrivf5WzsIoqfoDnlerbWiiw9fPivFzOwVRTIxFC97TM05f4cq3Z7veBR1xGr63MHSbeL+J+CbVjXZ2D28MVEkXJRjZpmE0EzLMfreTLcZwHmc2Tcam38zCeTkOvaZIAYlOvhNCeLiWlxpMeeLL0iSrUzOI+T8Xw+x4p90B8NHsGeo/qy+v1yL29IWQLykIMXpVPryk8vYsJ8OrCd9ZBd/U5LVkDeL1AWQ8TrmYrd5R6mqDlzv8cptLJMKEMbiNQyzVoU7bS4kFJ2fTXdvjk2tg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=UNKGJqPN3gcI3Ygqznh20qY8AnS8F0rxhXhh636gblQ=; b=mXuqURDUBcKj0NBl1wgY9oUf5PrepuvbcfZQKmPCvDD43iUdRC08MLF9Gt8wlST+u1kyeoDEw4DoJ0bmnC8jlPjVYSiwTkDZmj4J2AmQZHM/5bNc9QKhpEgoBK8a/rDLKR5fnNt9WR93nTUQLDMe5YKQe2D6xbA7jqpet6kBo8O09UdCINHcfa75jiubJM91045xz+O8++sATfPEGvJiXyszDc4HxAQjYTI8GkFa0T4l2JTvcBcr1ysOOOxqMOK4UgRKauzuNBOU2qOXG4xjpPBuHUmHUcN3qUtIjBibTkUcNqy+dwsN24ViMkXelb2ad5EdySlu1L7Zg0ZqjweOxw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=UNKGJqPN3gcI3Ygqznh20qY8AnS8F0rxhXhh636gblQ=; b=JZIt4EpYqzOS2mFoxBvnm/OKyEPHmJMDn0YRbU/tlfJgmhlbl+hAEDGKjheDBI/rgqUjQw0c2KRZgPZb8lppFLUQ8+OCX0RomDlRx0KAtcEwF0yE9NYsTReVdk5vIMdbqd2LPnsWP7pr/cfzlOTs+fz/1haPPa8p9/wTxfI/JT4= Received: from DS7PR06CA0034.namprd06.prod.outlook.com (2603:10b6:8:54::18) by CYYPR12MB9014.namprd12.prod.outlook.com (2603:10b6:930:bf::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7807.27; Wed, 31 Jul 2024 15:09:33 +0000 Received: from DS3PEPF0000C37F.namprd04.prod.outlook.com (2603:10b6:8:54:cafe::5f) by DS7PR06CA0034.outlook.office365.com (2603:10b6:8:54::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7784.35 via Frontend Transport; Wed, 31 Jul 2024 15:09:33 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by DS3PEPF0000C37F.mail.protection.outlook.com (10.167.23.9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7828.19 via Frontend Transport; Wed, 31 Jul 2024 15:09:33 +0000 Received: from gomati.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Wed, 31 Jul 2024 10:09:29 -0500 From: Nikunj A Dadhania To: , , , , CC: , , , , , , Subject: [PATCH v11 17/20] x86/sev: Allow Secure TSC feature for SNP guests Date: Wed, 31 Jul 2024 20:38:08 +0530 Message-ID: <20240731150811.156771-18-nikunj@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240731150811.156771-1-nikunj@amd.com> References: <20240731150811.156771-1-nikunj@amd.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS3PEPF0000C37F:EE_|CYYPR12MB9014:EE_ X-MS-Office365-Filtering-Correlation-Id: 9887e7e2-db4b-4c7a-fc82-08dcb172c912 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|36860700013|1800799024|376014|82310400026; X-Microsoft-Antispam-Message-Info: 9IgiZBd0jsY6iRLaDRc2M7Zo6XLbmEdQ+lQyVhnBZBO0zemVUV8j/mmLGEN0MUVnSwbhsydHA6S0KUiK3XJMByOLZawz10UmRsLaKMHGgwnyftLaLpBnmt3xep4/FbgaYrkr9vgSLbKpsfCrTq26SGIFUy+9W7Ds9MJwYF37EV1IKc/bLJ4eqDO8fReEmGgeTn7tJAbwbeG1iJtiZmqYn2SsjwHI5047Msz/JmgrAYLQLd+ckSYRuJ/6waSaT1k7Hv7nEvD05tB04SY/nmOkif/6xhRQhnywt7pna4Mix7w+1AXBpu8HS8+qZegz08g2WBzkFgLRBrmbkR57elryoLsNpoCTzcwqgtG47/8NVILm0A3iuRhvjSLTUqHsu5UAZiyY+Pgy/GXJnbFw2q+I+nXJdW+MVaC6egrJXHmdBSRqziMAZLPVjZuAg7tuBaPMTxi5cKo3aFRILUjEO2Ct6yGeF7RrW4K+iHSdEx0/wQdNqxbGSHx0xiDEXQjpK+cqOcUB94BtTI91rE5n5Xgqa76hiGqaOISFATa+zJTlF8JdCVZZTR+bjzks7RSMvHtCEc0jhODUIj/uTJ9nVp4h9zbWYBVYDFGM8DQFVk+8pyjwC3H8Bf1mWyx/idMr1anIyPOdOwSor7qtEqXJzmpv8LN1pBLfXSYKhKVIgImR74W/8weT39KIzuH2+TEZPk77CtU/NbrL5rB8891LLOQGhdvOloVsCdv3020QKhQZgtYydcFcWBvfLCDuH0rQRFuzuDG9Ripwak0b3KYKqERas0Gf3NUATQJ95vgY8xsBAUfDnXIQrNJBzUan/qOJkBsDC5IdijS5W9EtPn493hHqF1UoBH3+uhV1Iagv+zcQn36hPS2AYBznJ+ZeAvvNnj6corV7l67u4yYVHfzQCauxtoXU+2cEqdnDRr7OARD4XWlx1Jug1csKTXF87cOo7HhdEX6zbKsFcC7AzwRhyhJ5zw6MXEZzKYsb0bBmGMSCMkf2i7DEFfwcwSs1KVxHFTHUT5ptc5vikSs0Xw1WCzyaWumjMjLnlHwJ+PiGT7NFUSvMAZ4JT6YPWRnBMd8pbX41bCw6bIDl7euPsx3UqgTVbiAOL8LZkdinC6QouBrV0KUWBMFD8cSwvFwTf5la8qp3fqOcQa7nJL7xg7onL/MNKhzytZxSA9h6i7qUQtUJR0kj1XB98TiOH2wD3BBx7jgpTpImxXdkPVsyAFn47cqbdR8x4/865RQG3o77iA1pIa2bg1xz7thofM5Zd/ODVSEbD6UM+3ZZngjxGYZ6+ytOgeH9m4YoFY/4KaufToTLbQj7aynLMpzrMQiaDAwmvQwAb2ZcwnYYB80btP7RaIPg+YnAcjhwdM1c/rwq3W0HD1zaHsUYDlYT7wDy6AS3wqPTBXIfYy1A3KIXOpJtHGrrIxSoOOfXPltWKBgtmxlIqgy/y40UsYGNBDz/C70xxFuz X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(7416014)(36860700013)(1800799024)(376014)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Jul 2024 15:09:33.6683 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 9887e7e2-db4b-4c7a-fc82-08dcb172c912 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: DS3PEPF0000C37F.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CYYPR12MB9014 Now that all the required plumbing is done for enabling SNP Secure TSC feature, add Secure TSC to SNP features present list. Signed-off-by: Nikunj A Dadhania Tested-by: Peter Gonda Reviewed-by: Tom Lendacky --- arch/x86/boot/compressed/sev.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/arch/x86/boot/compressed/sev.c b/arch/x86/boot/compressed/sev.c index cd44e120fe53..bb55934c1cee 100644 --- a/arch/x86/boot/compressed/sev.c +++ b/arch/x86/boot/compressed/sev.c @@ -401,7 +401,8 @@ void do_boot_stage2_vc(struct pt_regs *regs, unsigned long exit_code) * by the guest kernel. As and when a new feature is implemented in the * guest kernel, a corresponding bit should be added to the mask. */ -#define SNP_FEATURES_PRESENT MSR_AMD64_SNP_DEBUG_SWAP +#define SNP_FEATURES_PRESENT (MSR_AMD64_SNP_DEBUG_SWAP | \ + MSR_AMD64_SNP_SECURE_TSC) u64 snp_get_unsupported_features(u64 status) { From patchwork Wed Jul 31 15:08:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Nikunj A. Dadhania" X-Patchwork-Id: 13748895 Received: from NAM02-DM3-obe.outbound.protection.outlook.com (mail-dm3nam02on2041.outbound.protection.outlook.com [40.107.95.41]) (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 2F5B61C8FC2; Wed, 31 Jul 2024 15:09:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.95.41 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722438581; cv=fail; b=gNlZAi+gSVrk46U6sYWoz98NRWcHbrZWdOhk23B9HYl+0w6c+t/Sh6ak3mvcKoyf8nPyDOn8gO964j05jzoDP3yd8B7v874w6WD/gxrhFGlbu2YwZwbgLscrz9rAW+23e5G/SLgtt8CeZgnHKrV6s0K7NShxgfLeCOHHMJLB7pk= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722438581; c=relaxed/simple; bh=b37O4lQqBPKsNL0DwTG5JCBRVlps5U2jLlKi4ogaW+g=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=eO/odZFMdVGhkbOQ//1TIO1dzXMhvR7cGTwBwBjjNENyVj72lwTlVpD3eiREY11zVMlaroqYSMj0w/ffq2rzxXIIWDdr/GK8IIVPlaum25mzBFfDEnEeuNRuKar8A4B0RcyMXJQknGO0qVWipTE6ErRbiRr8UI/oH8UdmhEldW0= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=c09fXsl1; arc=fail smtp.client-ip=40.107.95.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="c09fXsl1" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=UlyDA64P43EWMlAAKMaoQMqqD0Y8a5m2tnVKRkDuJ3Glwzp8R9uIEEaXanz7GipkASrdoXLLsSf+JJbZmdNeAQ4d4y2oqwxzSaUCNES3U/LqMdIEw524wMSA29/D/mWW6FpY/BjvFDXsvWI9BLnY1JzExcwt5HFht0Qpzgkhdq78d+0kqYN93OuGhxTrjqZ+j8bJeInUR2qnlE7NAunzqi7cSQ9qLeI0rnhZZxqXqU7Ol+p8S6iVqTnfnOobvFXjCo30GHLfD0oBeAzqWyFg1ODG94ajvT2pGa1jVwCGfXtFtXef2zh2ZYmw+rVEieDcX5LXZ/TK9WnTw1eTRHzgrA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=wfT+hwz8PcFeBkDyFc9aLCH6nZ1dOhY63Bd+A2eXLEs=; b=LszWFosRArMGj5q6izov6PEUFTQfViDX864sM5S9Zes7vGEdfiJ/UgjOVk0weGUROJFIsei4QapwvHbsL2FYCHJ1EF3afj6rwX6qprJjwEjq5V8R3EhOFq89eaDYyN/1UMmFJTb+Bcyp6gVZmqvM/FRnUVfFIS+rNnwnyOhcxUwNS8g36oOijM7XL/x4p6gB+oE1MBIPJu6QTq7wzdmB5ydVgSERDBTHqlOezoIdsbsGQdbXW3oxz+vlR+GcKFlExupkg4qEh0xGhGUNzGH5eCsuN70OL1rE+KP3JwRJxjywt7hp7B/ywGtnj/ogppHkWfIadphiCZhSh+ANTeVFeg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=wfT+hwz8PcFeBkDyFc9aLCH6nZ1dOhY63Bd+A2eXLEs=; b=c09fXsl1LaP60sH1SAF5WZMCGpP8ruP3a32JFCIRZrFSXYVpLs0kwC/vNmXKFMZwNhIhVdUlZXhR96zMVENc9rik6Qxnlec6SXdjJkVIDl5Eiyh8QOMbAWKFpcD4hPZyaOVUJG+jgVauSsKIHCh6n6grFRiAojpnXCJFXOh25CQ= Received: from DS7PR06CA0036.namprd06.prod.outlook.com (2603:10b6:8:54::14) by IA1PR12MB8333.namprd12.prod.outlook.com (2603:10b6:208:3fe::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7807.28; Wed, 31 Jul 2024 15:09:37 +0000 Received: from DS3PEPF0000C37A.namprd04.prod.outlook.com (2603:10b6:8:54:cafe::4d) by DS7PR06CA0036.outlook.office365.com (2603:10b6:8:54::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7828.21 via Frontend Transport; Wed, 31 Jul 2024 15:09:37 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by DS3PEPF0000C37A.mail.protection.outlook.com (10.167.23.4) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7828.19 via Frontend Transport; Wed, 31 Jul 2024 15:09:37 +0000 Received: from gomati.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Wed, 31 Jul 2024 10:09:33 -0500 From: Nikunj A Dadhania To: , , , , CC: , , , , , , Subject: [PATCH v11 18/20] x86/sev: Mark Secure TSC as reliable clocksource Date: Wed, 31 Jul 2024 20:38:09 +0530 Message-ID: <20240731150811.156771-19-nikunj@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240731150811.156771-1-nikunj@amd.com> References: <20240731150811.156771-1-nikunj@amd.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS3PEPF0000C37A:EE_|IA1PR12MB8333:EE_ X-MS-Office365-Filtering-Correlation-Id: 1c23a3c6-0a93-455b-b0f2-08dcb172cb51 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|7416014|376014|1800799024|36860700013; X-Microsoft-Antispam-Message-Info: /pKYobcDKtFSKgZ1NRctIHqp4EEvCMtiqFSfl6Am115O2NEUaJQfErmtpn5SeQmerZ1wvXQlq+35Ypl1jgC34uG5CFXPDilOV4uEgSTrQF1HFVoN3Sgg/Q8V4kCTk1092hDJLDP1brA7EIPJQ7ntcbg+yZSgZOrm08EhwTNcRrjkLuHWyNe11w3y2RVq4LWUIT794Sf0YL8tnS7QazjPtTl/MeND9aU/FloC6O5vBa8cS/uuctX40BwNLMVzsfDq8ADzPmNDbuS8H1FNQ2ubYYU4C+W9nzGObequxMFhQlqsC72HyMoiQFRLxFKxKMmso3/CF3CHF2M42vgqlBSMBp8arpXqeR1LP6eoMRU/XVYM7C5eOL+xQTPMIIhsjHt9YdR/u3bRQ8HZ+tbl3cK93qzDgPAaNjmEPdGghzNaZa3JyKX9lP+PdZ/wD3QvFGng7Vf9pqo7L9e7B4eyGpkhZToTB3r2grii//4w3yUovpUosWNT/9Jm1S/l1M79XY6+rG02W/GO9TNplx/4dDjp5hSml247A8iD0nrGqTboP3Ghb1nfOsmxCEmK68tCJ4pC/dSVy7IQ/6OOJHOwaClklnRNYsacYs22zmg8vw19jKjKbeRT3h3O62aonU57bIHc4rLFdfFaOiBjya5coT96ctXMv2Dam1skoK199nRFVsz2U9C35FiVRT/oObgm1B5OdNuzmpaicJ+h54BQYfVhjcnXDO4Niv4tNvyJ0QKRiRRIWP69TmsiMDSv8MtDL3UwoeBKWifBvz1AyYUCtkPDPZb41EDRqT/I6I1ILWT9knGxzSEwn/wyJpRiXBpaJVDKU7djeSxvMfMbZyHw2HMHJf4Z0sbGBsZPwu9tkVaotIpDsJASKHWksbeyGLRtVt1zwBYhbYKQ6G14ISuGblUKvh0/DbPSpLLiiH577ppND2YqhFeSUKsO/o/7xdEPYVW022LgkGlfldcDMgEtgcVRtME+4F1ezvLtZmHpaehDvbBapWQ4NIaLz/kY6MtUuGJ+NAt7j6fAiDIYNOGj5MV3X50I+//HbJJOIt+c6v8vwHGFuzFj1CmWzY/GpUL3b5dEOYBFoGRDjglKDIVSjCoTg5jarTuKHjBHy4kUAkbQnZZNCXDHdEN+/0SM6uC4pldfodOoRqxcc5d0dZv/j07/h1U9qYa1ob5kre8/GIi5x/A8V8Waul3t4Gb0iaUKo5r9oHHbcCRM8tSh9tbYDPfOq7FTj8NMWcbWRSV0QoHv3vD7b7lv7Q1w6OQVq2fir9/G7dacanqgU1Ih3rcdZA2dr/4ArT0qp++QHmaNDzSu5JIHBawKGJZaslKmAkz0HhIOiPCt97K3ZlTEXlgARHLId/5Ko3UMQJVvteQH737QpA/odKGMbGKVJ5ErFoPpP/KN6iRU5R3fAsTNQU9OMOSVImDlgU7a9GUQfPSPIYHLvM5WTKDxPenaIATUQXd3ikgl X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(82310400026)(7416014)(376014)(1800799024)(36860700013);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Jul 2024 15:09:37.4190 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 1c23a3c6-0a93-455b-b0f2-08dcb172cb51 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: DS3PEPF0000C37A.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB8333 In SNP guest environment with Secure TSC enabled, unlike other clock sources (such as HPET, ACPI timer, APIC, etc.), the RDTSC instruction is handled without causing a VM exit, resulting in minimal overhead and jitters. Hence, mark Secure TSC as the only reliable clock source, bypassing unstable calibration. Signed-off-by: Nikunj A Dadhania Tested-by: Peter Gonda Reviewed-by: Tom Lendacky --- arch/x86/mm/mem_encrypt_amd.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/arch/x86/mm/mem_encrypt_amd.c b/arch/x86/mm/mem_encrypt_amd.c index 86a476a426c2..e9fb5f24703a 100644 --- a/arch/x86/mm/mem_encrypt_amd.c +++ b/arch/x86/mm/mem_encrypt_amd.c @@ -516,6 +516,10 @@ void __init sme_early_init(void) * kernel mapped. */ snp_update_svsm_ca(); + + /* Mark the TSC as reliable when Secure TSC is enabled */ + if (sev_status & MSR_AMD64_SNP_SECURE_TSC) + setup_force_cpu_cap(X86_FEATURE_TSC_RELIABLE); } void __init mem_encrypt_free_decrypted_mem(void) From patchwork Wed Jul 31 15:08:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Nikunj A. Dadhania" X-Patchwork-Id: 13748896 Received: from NAM04-BN8-obe.outbound.protection.outlook.com (mail-bn8nam04on2080.outbound.protection.outlook.com [40.107.100.80]) (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 26C4F1CB31C; Wed, 31 Jul 2024 15:09:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.100.80 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722438586; cv=fail; b=bpjuKMxA4EurvlfGq4oBvnM1ebwg48e58HgQj1MrejHx8vzNhS235To6VdFKXUqDihDZwhGSLfO5BInE/UR93VmRfat2l0ZM/YJJ8gkkjihwHKWhp5rkqlYK/BY0JSAV0rRwyHizjkAK4szLgX5SQlepZ5xZkrXWSrw+Xew69+0= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722438586; c=relaxed/simple; bh=4uyj7G0a4vT6/sxbJBvIsYtflmX5hLJGrOmw6Kq2PNg=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=I8ggTlzg8mCICflotBg1bt7IJ11OnJ2gJrzYmuPExGskE8R7ld91Cgw4Qqyi0TwW49mBLJl/xPtjWiWveiPwRExysp1cfkRF3dvh/zP2VcPddAYIx/oHugwOBZ+kY5xVHTuwuA9Z9AykQZl3uXEbGH8PrBzN97mU2qHAciLkXMo= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=PpTBIwE/; arc=fail smtp.client-ip=40.107.100.80 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="PpTBIwE/" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=RXS7sYEOrTfp8IXvNJcYG7gj17DoHZkaPMeQP/ypqHD6rqwKM6a92qgh/dPXwdLeH+Uvtg+jCyeHbjVGRKVRo0JLvqmClPMV+UNycCBUy4P9AKc8dgw2g8quwe9bHa2T7liA1EyxcQ/UgOR4xubMCWOLxp2RX/zll0vE2nBj/141Yqe2aq1N+qrvyPxydvOmTO4rYzq7SQSbcuDeGYC88WnIuOquyR0APpu5qgcQtgZ3l42rh+KLANor4s3RmUBAodSqTsW5Sv6o7XgScfV/PIIXNNPhdN332XbylHCLdB4fvN7NJzWrpL25dvYcmWIZlAoO1jL86FSbOP++c6JaTg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=mpq2RL7/mLnCVwuZz+gs7mct4r+12ku081S+bYQqtYs=; b=CBVHmOiz+H5l+yxTf7t2iVk2i91H0Ggeua9LsKXEDBcMfi6RhtfWhWdHPDyd3UQux7m37czWztXJWQINzJwwdxGy4+AaKLrQ3Q63K5mv/TYzkbhLzJhusSewb9qo1dMW7Pmmv8i+aLCOpXIQ9DdIdBUBdFaLLEzRAfAuCoBGe5Ds7FxTMbPy5UpU9cmRdF6RFpmQqnpm7BmxKfPIPzj7tV8zoPmHhkssn4Qley3zuwivhF0+bQ3OIXPIU5FUKrAL7m7WxqQnLe1H8jMR1gFgUJyxgQLlJowYgm9FttRrpz/e/O8qiWkJBCO2eLlO/rYQ0Outuw68ruuPf9CWsoQaYw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=mpq2RL7/mLnCVwuZz+gs7mct4r+12ku081S+bYQqtYs=; b=PpTBIwE/Qk2icD1VG3r7TC2mpWXEQI0Cn/CrDiN1nxgUOYraVmp9wTHKID8UK6G6MNWnFRPHfdjZoXT0hvJ7nwzgrsYM2X6RWnbtfCAKQ4Mnj2z6mwIZslWhVPRGx9HF92SL2JJVBHGwt0X5VypgE73MrXJPZReLyXURocVEQjA= Received: from DS7PR06CA0029.namprd06.prod.outlook.com (2603:10b6:8:54::29) by IA0PR12MB8208.namprd12.prod.outlook.com (2603:10b6:208:409::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7807.27; Wed, 31 Jul 2024 15:09:42 +0000 Received: from DS3PEPF0000C37A.namprd04.prod.outlook.com (2603:10b6:8:54:cafe::b0) by DS7PR06CA0029.outlook.office365.com (2603:10b6:8:54::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7828.21 via Frontend Transport; Wed, 31 Jul 2024 15:09:41 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by DS3PEPF0000C37A.mail.protection.outlook.com (10.167.23.4) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7828.19 via Frontend Transport; Wed, 31 Jul 2024 15:09:41 +0000 Received: from gomati.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Wed, 31 Jul 2024 10:09:37 -0500 From: Nikunj A Dadhania To: , , , , CC: , , , , , , Subject: [PATCH v11 19/20] x86/kvmclock: Skip kvmclock when Secure TSC is available Date: Wed, 31 Jul 2024 20:38:10 +0530 Message-ID: <20240731150811.156771-20-nikunj@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240731150811.156771-1-nikunj@amd.com> References: <20240731150811.156771-1-nikunj@amd.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS3PEPF0000C37A:EE_|IA0PR12MB8208:EE_ X-MS-Office365-Filtering-Correlation-Id: 9b0714bb-dbbb-4ce1-d022-08dcb172cdf6 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|36860700013|7416014|82310400026|376014; X-Microsoft-Antispam-Message-Info: Xfc1v0G8ZdUYL8aIaRI+zW7dgSsrDUcBtN3DsyPQa7d1OGcdJSYeiVaDqTu0O8Lbxlx4Uw460N/Pt+Fdc1cfXsMMJT/T2HTj9PCi6CrCxBUXMvH7txiTxzMjWYuNotGrenB1t30N3UI5k6aB2hxrKY0kODwUHqVJLVytMPaB83WZdJQUcptPldVfURGbm1C5KmieO8QLWPBpuOecLIII0v6JR481UyuhjmC/zX8EUsrzbLJ8YPPnjYcE8PsKO/JbpD8u0LrMvrZ2GXIFRyTHKjuM+1y1yN5o9KmnjciELPCTWdT3ufqYKVDJ7u/967EUp8UVHHB46pPkvBHgmaurkirWP7slDWIDt/jlSQe3d8Ao7K0Bcz4uVQ1ESZ7pVflPOpskctdnyju0ca3YxMjLpsrL9kqVp4CJxjWAEs5gL9HoIP246viT9fA24doHH1aTokNDqcQ7Rbgd5v5tnk+9dbNVhZvY1VZ1Eka8D2xBdRcURLiJb/CYZApAvgxfDMtPBhFP4EJcosYF8aef5Jd7EGLt8Q5IgMC/7GHegF69bTf2dOmwrCQxH+/GdBVf1Mg/WgEpHqTBTgYJ8FSVq2hNpw/pacTn2dZK+0Tqa4ZdgFFSvtxSPYzOWbEYm7Uo7iEilug2OclMJx1Zd1BtWC5aXqcDKKqgJoAlHVOGSRRtJT3WYCaT97iIQ/h9LN9bKSfOY89G4wamBNprINX7wo3jroxQ9GqKiAMoVkDKMNxhvPoBxUEM4hjj3f4Bj7KByYrbTRm/v6lI44v5nL8bWHdB9SXur0/wdwG2kpqkhk+SaqND2n4YM6N2aWAs7whKnoEhCeRAr4xW19INQXep8YqJh+D8CixunPoa89bWi84+7lxkyyR1l7W5tg9W6SGlsGYHjQt9GTFrIkSqbBr76wGOTOJ9ZI3tj5yUbRdw4x3aWM08U7iXGP7VKOINUj11cCiyZpVXY1nQW+E6LveVBz1xLJhWXSRl+dJFn015d95/Lx7wpXkE+yeSfbcA9QFJyX7nlSjDpk4dCL0+RtAmDU1wUxEDHU5ExQIJugPGrJCtzmkWKJ2fz5Ft4fLgsdpp4f6ief3HOHwXDk59PuHpeHtfRgcHcsE6+q3PX6ZLXgXrRTYD974rTcNOu1Brxeqzm6231cuox+Qp+5O9TjII7L/Ef7wiCq42v/H6eyybk1L29yJ5n2wvfaTiDxO8itwrUHiStiQsviUr0zhR8CgB1BTjybFJgZe4nHW96tDYx2FGAaWHrR2efn5bg2WACjcXnSQxvgC6Wpyc1eCvqSeVCWHOOy4W11oISL79d0YyEqTfe8YStgYNsBnCHS8gtYiqVY3Az2c+HpBRqkbC3moA5pNVEOK19Var91zI4o4YKkI63ZLovWrRA0MnAx1jPN8rZ5Q+NZqxUyoJnH3ge+Z9DHvS3aM3dCD35LN8XFZNT5z2EtkXFZYZt3OcfXq8UWjdiXlh X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(1800799024)(36860700013)(7416014)(82310400026)(376014);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Jul 2024 15:09:41.8566 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 9b0714bb-dbbb-4ce1-d022-08dcb172cdf6 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: DS3PEPF0000C37A.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA0PR12MB8208 For AMD SNP guests with SecureTSC enabled, kvm-clock is being picked up momentarily instead of selecting more stable TSC clocksource. [ 0.000000] kvm-clock: Using msrs 4b564d01 and 4b564d00 [ 0.000001] kvm-clock: using sched offset of 1799357702246960 cycles [ 0.001493] clocksource: kvm-clock: mask: 0xffffffffffffffff max_cycles: 0x1cd42e4dffb, max_idle_ns: 881590591483 ns [ 0.006289] tsc: Detected 1996.249 MHz processor [ 0.305123] clocksource: tsc-early: mask: 0xffffffffffffffff max_cycles: 0x398cadd9d93, max_idle_ns: 881590552906 ns [ 1.045759] clocksource: Switched to clocksource kvm-clock [ 1.141326] clocksource: tsc: mask: 0xffffffffffffffff max_cycles: 0x398cadd9d93, max_idle_ns: 881590552906 ns [ 1.144634] clocksource: Switched to clocksource tsc When Secure TSC is enabled, skip using the kvmclock. The guest kernel will fallback and use Secure TSC based clocksource. Signed-off-by: Nikunj A Dadhania Tested-by: Peter Gonda Reviewed-by: Tom Lendacky Signed-off-by: Nikunj A Dadhania --- arch/x86/kernel/kvmclock.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/x86/kernel/kvmclock.c b/arch/x86/kernel/kvmclock.c index 5b2c15214a6b..3d03b4c937b9 100644 --- a/arch/x86/kernel/kvmclock.c +++ b/arch/x86/kernel/kvmclock.c @@ -289,7 +289,7 @@ void __init kvmclock_init(void) { u8 flags; - if (!kvm_para_available() || !kvmclock) + if (!kvm_para_available() || !kvmclock || cc_platform_has(CC_ATTR_GUEST_SECURE_TSC)) return; if (kvm_para_has_feature(KVM_FEATURE_CLOCKSOURCE2)) { From patchwork Wed Jul 31 15:08:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Nikunj A. Dadhania" X-Patchwork-Id: 13748897 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2076.outbound.protection.outlook.com [40.107.92.76]) (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 9AB611CB32F; Wed, 31 Jul 2024 15:09:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.92.76 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722438590; cv=fail; b=MBI12GyWfrP+8tN1pl8TbJblks3quzEPToStlNZdWdzWLbNl7YuxB4wSjSCg9rTW41NYArqMjICmvrAOtvOV2hGW+98bkkHmV/S4T4R/Jku1QQW+SBvZnjEA90oLxhgZbx3sh6cOWebTAu/+ofb4xzl6L2hYaULwY804Bz5tx8I= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722438590; c=relaxed/simple; bh=2k6VbzH2BIqJNNwYxpT7TO+paYM30wolsECgnn94tRQ=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=MwS1kr3jlKkdxyPNP0vjxq7O3oMCDeU+8jppLYJj+5D6hyn6FkXzu9x8om5VdzewG6E6/lBuEGyA1KgiBABAjlOT30KYiDjzHfxX31IVX3neGqOf7sdp4PfL4TYMwnOjX/Vq4HthqwY5rYbpjJWv95gaFqSMMQZ26rLncL7BEu8= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=fRdWxwX/; arc=fail smtp.client-ip=40.107.92.76 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="fRdWxwX/" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=IX+BMBa9iti0Sx3v42x3CsK59eV70bbqiXzomz1ODUBtra++QYJBMHP/GJgKh9dmUgM84SpbfpWFqltA8TJd9d/GIA1+LRo8kl2LqKiKSq04ABlObTLDd8X7l4GIxqlcUutrTzUJsh5184DafbMrK49dIiKOig9tMBGqOVEfijeC4e9PSfDMY29qg9BHSo04kn/zYsGSQskBObdvBWekLEqTN3WRKtB7wLhgFRSy0BHxHFMK+lOYrqkE2bHVhlF8GpYGTOich529xcpUKX7vC9Gl1cClHRY0gAn8C6fDZ6cNxC5lOZzZ7ockiFPLHLyscj0urQF5F3Y3MATtMcNS1Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=R35YcfpMfkkvWIJmb1WPtShF2Ta3rExIk7TUgVjB+5Y=; b=uyJmo1XlB0C0KZ5WEOm9wfxayaxBmOpTp1ZfQcSxp67WscS2d29kwKKKbt6Ba8K2qhC53kl3l7NIIxUhtPtMYyvvwcCiU2niy5XRTGAA8C4cP9gIIdCHt8pyv3fnWZRIrBYLG3gRzwDWRE9pW3akuAOG3sa5lEgGmgkcw/xVW6mqwaHs8QLyyIDl3gIB459Zafkp4l94QMTYj1dvv1iydlNpHYbYUjfxf4EjbPpGMP2eMyjIPxtKgDDSAXfJoZ0cPFhefXQ82zZPeIf3PksCG++pyeQvVNpa+mfGYOqAXFT2R8kcHG+VeYF0TCCc8bcndwVIrfhjcru7R+QmZLxPHA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=R35YcfpMfkkvWIJmb1WPtShF2Ta3rExIk7TUgVjB+5Y=; b=fRdWxwX/pKN/kKsW82CjWXMxFs0DBD8b1L41+A2Z/NESDZEANDLfzsRNjeaUQRM/T/WvoZNpqPaweJbfgB34qeJiAfInBS+ks9N9q7eJrtcW230fNcywPQUuJczoEyHKArE2If1m1EH70fcbE50JK6Uu0egIITM3Nq30+Plxfto= Received: from DM6PR13CA0030.namprd13.prod.outlook.com (2603:10b6:5:bc::43) by DM6PR12MB4137.namprd12.prod.outlook.com (2603:10b6:5:218::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7828.20; Wed, 31 Jul 2024 15:09:45 +0000 Received: from DS3PEPF0000C37D.namprd04.prod.outlook.com (2603:10b6:5:bc:cafe::8) by DM6PR13CA0030.outlook.office365.com (2603:10b6:5:bc::43) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7762.23 via Frontend Transport; Wed, 31 Jul 2024 15:09:45 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by DS3PEPF0000C37D.mail.protection.outlook.com (10.167.23.7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7828.19 via Frontend Transport; Wed, 31 Jul 2024 15:09:45 +0000 Received: from gomati.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Wed, 31 Jul 2024 10:09:41 -0500 From: Nikunj A Dadhania To: , , , , CC: , , , , , , Subject: [PATCH v11 20/20] x86/cpu/amd: Do not print FW_BUG for Secure TSC Date: Wed, 31 Jul 2024 20:38:11 +0530 Message-ID: <20240731150811.156771-21-nikunj@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240731150811.156771-1-nikunj@amd.com> References: <20240731150811.156771-1-nikunj@amd.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS3PEPF0000C37D:EE_|DM6PR12MB4137:EE_ X-MS-Office365-Filtering-Correlation-Id: 2431b0ee-0c4d-4678-e36d-08dcb172d009 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|36860700013|82310400026|7416014|1800799024; X-Microsoft-Antispam-Message-Info: elEgJjT5FbuQ8tfjLqoqI5eFNWzyijAjWL+kZt1sHfuTX3QLTH+oLGgCdLFHFNrkdESnAg+tdwDofX+E8XNxL6HwCwtGLHQJZwePn8gVapzkSXYBBlUjjtOLmhbltsIdVwOwWHmW/QRErlDUOS7xT91u/vdtaYi6blheDkKnadRuqa6cjx1l0B2fgK1kFKvEieWMq/9ASVOgpaMTysYR04ELXu7liS/dKBOhFTE5+nF+iNnAo6FZ134TZAIaM+f4BfugeWrvOTJDYvqo+qD6LAng8MCVWzhpO8pbXj9KVl0vaRcoXQ72H8OCf8F8HMUO1fuImlO0odzRqSmKBo5cxh8KxNnFKqGWOu5+j2thMRuuPzPlVLwxjrEAbG23hW6ns0iq7bg05uEFZ142J9f3HRXXrY+QiqN+IVJbfnoNf1LZI96K0jbuKxpie+KVrgybOcouFUFwzs1/uRF1hq9HvSlQfXI9uUNA9izLhSYlrGmpkCNBYCE9Mhpt5lURk7rh8KLIEUNZ0JwEbP7aVdrl8Vvxkg2gm+juT9J4u0E+9t66o9yOJtewqH3yaxZKlOHd47+ga2ASClrzTNWCJKl4vOSB6XMLP5+e2eZ0XJzBhi7suMmm9JU4qz4MsBInLJK+d9y5KfT3mSjU4Rhvrbhjy8LgzYiLEje4++/D0uytdc2Zp7uUFS3fq/A09z5g3GdMc++MOgeLUecrb7QOBGEH1Ipp9oDB+OIzJYxekOiA/EStf80gTcpk+/cqNGVpoUXeC8S37YFrFu+HuolHMPPCBF0nnXqJcfyHtQv1Q9ufhuxS4p9dhClBg6kdvUXw4x3SnqtBU+oDNmR3Pqm61Yt6JU9h2orvRxPyBAV/gvYRTcsLvvQhRvnmk14vyldrG4tH8N6qSPGXpZ707snv7rnrEqTIvHy7BiwjgowJZ+qV5dNHoUXaBftBat1sxOZ5tGx5wMxMts9ygjFy/Z0JAc4nOoUnt0kIT3iyx7AdUzjCAiEnRLE5PbHJxiVcGNWnj8zxKRkO1V6JSrF4KQHNXrdPSDaSHpB8qCsYj9JcirBfGN4GVZGA//J0BHEErxvQVs8qKrwVOKh633U0Co8ty4THRRaTIvgNJ+XHt+gpBm5FHS6TXcgC4SgGAlpqRmqcAhQyeOLMonwqPbblzZWFYFWYRZegzPTu2etZdXoo2SL75rS14gLFw96G/QKLT5FbjQlYr2NMi4MsgVSB5UlUYRSfzkEDPgV3xTAc3lzgOncgvaVLrKHeRBjlEdCC1cndahD59Y3ux+TJLLFZogdGv3VNBsBnZwAhNKLcOdhiV6LGN53U5h0Ryp/qJZ9xML7FQ63Wc58Bf1+243Ce/CTn/xWaZovu44wz8d0XyD1kq0Imao4Ypow5+3CL7CDs2X/wCamRK6AiT9yZwoTiWaop07D7Dr1q0KCTW5kJuyV1YLlcC9JUZBcdyMwjVjua53TzkVxl X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(376014)(36860700013)(82310400026)(7416014)(1800799024);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Jul 2024 15:09:45.3371 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2431b0ee-0c4d-4678-e36d-08dcb172d009 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: DS3PEPF0000C37D.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4137 When Secure TSC is enabled and TscInvariant (bit 8) in CPUID_8000_0007_edx is set, the kernel complains with the below firmware bug: [Firmware Bug]: TSC doesn't count with P0 frequency! Secure TSC does not need to run at P0 frequency; the TSC frequency is set by the VMM as part of the SNP_LAUNCH_START command. Skip this check when Secure TSC is enabled Signed-off-by: Nikunj A Dadhania Tested-by: Peter Gonda Reviewed-by: Tom Lendacky --- arch/x86/kernel/cpu/amd.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c index be5889bded49..87b55d2183a0 100644 --- a/arch/x86/kernel/cpu/amd.c +++ b/arch/x86/kernel/cpu/amd.c @@ -370,7 +370,8 @@ static void bsp_determine_snp(struct cpuinfo_x86 *c) static void bsp_init_amd(struct cpuinfo_x86 *c) { - if (cpu_has(c, X86_FEATURE_CONSTANT_TSC)) { + if (cpu_has(c, X86_FEATURE_CONSTANT_TSC) && + !cc_platform_has(CC_ATTR_GUEST_SECURE_TSC)) { if (c->x86 > 0x10 || (c->x86 == 0x10 && c->x86_model >= 0x2)) {