From nobody Mon Nov 25 11:40:33 2024 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2083.outbound.protection.outlook.com [40.107.94.83]) (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 6DF7A190059; Mon, 28 Oct 2024 05:35:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.94.83 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730093722; cv=fail; b=sIrlXt6dm/ZeWuXAkUcdhySVgfVDWfZaSlB2I62lJATp1gIWP0PRp22igINz6473GI4rTbeLSJXQpLmXt7hc9oIn3f7FqjkWzR4vu9O3m/JvUXRUt8ZqtcRKKz6ktaa2dd1WF4fPcI828rwT6D84rzXqNOa9n3cS6uRV3Coe3FA= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730093722; c=relaxed/simple; bh=pME00bVnTJogCyHOxeOmNwbWSncjjDziRL7bZH4hGeY=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=iQRzsHGIQgbXHeRjQJbERbb1TwWiDJdBNMzMXwCXwAOePD2ejZbgnMarMtFd7NuHgEvuqz08sFleft70YL2Etgh+lEgnAQLL2Gzdd2hr8bq6mvY0oxyhpwAvKbrhohoNQ3wgIgJrgeLCa4CMMz6/8O5VR5/V8D662cPqQPPqkIc= 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=vwiEp3wF; arc=fail smtp.client-ip=40.107.94.83 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="vwiEp3wF" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=PWntWVf9YcvrEgsFtA0/clIGQeIydS4XkCL68a7qnbphNN+O8dTH4YKCMcSNZD8E3synJnRJO3c9cB2goxGNJtmZtF+LSw99UsCW6ejmM4H1lI4TvvSmSDKCv5gPkzf4+8HordAuEeJkxZUy3HZnZ96q6Inmp6Pnww1219dAbgAwegy+IaF0y65v1uKzTX1BOMYHNNYmwdsWF1/ANjiOq7YKe2xUTPukXYKtut4+NheahWGnOqeD0jTeDqQYSg+2woXafWUqirhndHZsj49YbuUfGj63A5EV/dVd2hlyRA6T95uwMbO5+3by2pwScAf6VXLM8c2ozQ7eq/tP/jAScA== 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=cgnZz6sBWYHCJXbdUT93V5kE72/4pEh6Tlp+77STnTw=; b=JcyKCZXw2S7/ldqH0H1crTDbvOEwBX3ceFA4iRY0y5SNOvtPC6nrvNYByHcale03zILMo+TsTRbAb0rCqqkgORcn4PMBAyCDK4/xKbPjPri34WEhD5H0p48BmvPHjBgMd0BZTkT6LUDs2fe5JQgmQcO7xRfxOvfk+3T+B2VgOnP2qALDaRAXpGd5cNrSKV3dkoppqRR46BVnVpnIZ+dLEVyt6JbrVW5/7Ipp327pAT1WGQysOfHkCFyOtwSknwymhe3MuT6BE3Tc+t7WyYfa9LRGMpVuTCuglIXLYXUGJmrIhxDuZ3Aq0UPKvdePfZB1DXdPa/1qUuSkwtLArynWjQ== 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=cgnZz6sBWYHCJXbdUT93V5kE72/4pEh6Tlp+77STnTw=; b=vwiEp3wFuKtyo0j1ve5+uhCKWutNcexvxHCM+nH6jgDk7EXn115fxVyX8Wwz1cXPqJExz/OUfglA6dCgOK1ogd4Pvs1uPirbD15BfiAWUGxVhPClh+8ZwUO9qj2I2ePv9sPk2bsy/ML1x3OgnYevNanV/DPqOL61fnVSLnK4cG4= Received: from BN9PR03CA0931.namprd03.prod.outlook.com (2603:10b6:408:108::6) by DM3PR12MB9413.namprd12.prod.outlook.com (2603:10b6:8:1af::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8093.21; Mon, 28 Oct 2024 05:35:13 +0000 Received: from BL6PEPF0001AB53.namprd02.prod.outlook.com (2603:10b6:408:108:cafe::df) by BN9PR03CA0931.outlook.office365.com (2603:10b6:408:108::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8069.29 via Frontend Transport; Mon, 28 Oct 2024 05:35:13 +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 BL6PEPF0001AB53.mail.protection.outlook.com (10.167.241.5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8114.16 via Frontend Transport; Mon, 28 Oct 2024 05:35:12 +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; Mon, 28 Oct 2024 00:35:08 -0500 From: Nikunj A Dadhania To: , , , , CC: , , , , , , Subject: [PATCH v14 01/13] x86/sev: Carve out and export SNP guest messaging init routines Date: Mon, 28 Oct 2024 11:04:19 +0530 Message-ID: <20241028053431.3439593-2-nikunj@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241028053431.3439593-1-nikunj@amd.com> References: <20241028053431.3439593-1-nikunj@amd.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL6PEPF0001AB53:EE_|DM3PR12MB9413:EE_ X-MS-Office365-Filtering-Correlation-Id: d8a68ac7-47ae-481a-463b-08dcf7124baa 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: =?us-ascii?Q?8qK8g8/rbq4XTJtYjEHxxghK46/ersWYT7VR1+TmnCfM7coIbrUb7LYyP8U7?= =?us-ascii?Q?IsyZy9aDNfajvWX9f1WmoMqzoHcEnwPon4IsRuLJQtYBfFx2BtxmfTXK9Ll2?= =?us-ascii?Q?qqQeq8mg2MG0DZamHLCBlSdDvcHhf8XeQ6+Bu0rH1z3cAIDPHAWZKjKBtssj?= =?us-ascii?Q?rnrLOMoXdaoovJIx4cZ7Bj3GhiOIaXVOV9nJotJtmgvlJ2/KCnrXyR0NGIF0?= =?us-ascii?Q?xl2WYbVDMBcRCRs/LMan5QTD6BGUYsSJrpoOgRjyKIFr07eiurD7OoWYL/0J?= =?us-ascii?Q?Axk6G3aZGBBryc7KCzgTJAKwfRn4XoS4noy1MD/gQJPwuV7GiPm/hLst6qws?= =?us-ascii?Q?aGnVQ/KNqW2bnNtpaD7kne+aB+0EQ/GX0pitcfYgibMctxx8wjCy6shrA7Za?= =?us-ascii?Q?n85j3dO8lZI4OMKoJdM8BSn0P2unZ5vJoOashzvZGRsadWWHtpRf/ort0E+I?= =?us-ascii?Q?DotkdwLEZwDhOk/c7np2hd+eLRHcGvTXjmS0YXi8SZlE46RpNXhsQ5gSAyKU?= =?us-ascii?Q?mbQKLEmGt8/wsJJ4uw0REINyOzQWFQ/h4SykPMWSaiwLPWLKvGQnZCz0nsF8?= =?us-ascii?Q?kYaxiqNxVWiEY0V8PnLVJp0FaFn8UHpVQErMnYJglzJUFmu5rx6SDavi8OIB?= =?us-ascii?Q?U1nEXrswzbWkJyW7FPFkD0bJrqHOxqPWuGuhLQ12vwRiB792YdpatKLPuzzj?= =?us-ascii?Q?TTjX1nwG0dm5yDEMLYu1ed9QjaBkXz9rcU/BqCweJiRBRlQ2Us0O3YjFZQao?= =?us-ascii?Q?cI2ATDk1Ri7th14fAx7nU45D4mhd4kjEFcsbuXsd0FrpmhjqSurUFI/d+k+Q?= =?us-ascii?Q?FRUdvwYoPFw3u8a870G/ivccgwgEUW7mJCNBqytv/kZtDWFfTB8cD+qySMsL?= =?us-ascii?Q?oAFP97cjkhR6PbnZqTLZl+3UDoaJg3asJ2ZkLEmM9AB/AWErzuD4BymSIJa1?= =?us-ascii?Q?sQI75yMU2p6zsvsI5QxxfR/GEK8vo3rYDZ440EQGQOJ6Yn8b+IW0xvuazMbh?= =?us-ascii?Q?x2f3PBYzNHyGZIeJtBO0beNVDFDLG80Na8nnYSq3ZPEiOON0yx25XGp7208A?= =?us-ascii?Q?L9U5sjRclfrmH6ZxnZX2MNwZPwSzljzpDjMSlXhF+SZusYdAtjdDV8snHFHZ?= =?us-ascii?Q?juFBuiOlE9obBXNkbR2Nr070YzooN2e8nzjhA49WILmVtUDVus0bgKs+Ckbq?= =?us-ascii?Q?k1yReVqwcQ+/du67anl3FqyCJ3rRl09D2vttT8u721k/2pYOUekAH/ewOty4?= =?us-ascii?Q?3OjcpNR6LVLDHE95gmpQ0YBq5X3ky/2Psy4JYxfVG3ARJ9RdniNmg2PSTeSS?= =?us-ascii?Q?bi+GcmXLAkImt9Wu4hp0yDJJ9UBXn2JtyXwtR1FEGqZNkcAfo1AC1UebQn72?= =?us-ascii?Q?WykZuJU9w5n6dlEe1X4ng2zd/8ALBzRCd4oTVlvtR+xpQIxz1Q=3D=3D?= 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: 28 Oct 2024 05:35:12.9283 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d8a68ac7-47ae-481a-463b-08dcf7124baa 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: BL6PEPF0001AB53.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM3PR12MB9413 Content-Type: text/plain; charset="utf-8" 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 | 195 +++--------------------- 3 files changed, 215 insertions(+), 184 deletions(-) diff --git a/arch/x86/include/asm/sev.h b/arch/x86/include/asm/sev.h index 2e49c4a9e7fe..63c30f4d44d7 100644 --- a/arch/x86/include/asm/sev.h +++ b/arch/x86/include/asm/sev.h @@ -14,6 +14,7 @@ #include #include #include +#include =20 #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; =20 -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 { =20 u32 *os_area_msg_seqno; u8 *vmpck; + int vmpck_id; }; =20 /* @@ -438,6 +436,63 @@ u64 sev_get_status(void); void sev_show_status(void); void snp_update_svsm_ca(void); =20 +static inline void free_shared_pages(void *buf, size_t sz) +{ + unsigned int npages =3D PAGE_ALIGN(sz) >> PAGE_SHIFT; + int ret; + + if (!buf) + return; + + ret =3D 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 =3D PAGE_ALIGN(sz) >> PAGE_SHIFT; + struct page *page; + int ret; + + page =3D alloc_pages(GFP_KERNEL_ACCOUNT, get_order(sz)); + if (!page) + return NULL; + + ret =3D set_memory_decrypted((unsigned long)page_address(page), npages); + if (ret) { + pr_err("failed to mark page shared, ret=3D%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) +{ + static const char zero_key[VMPCK_KEY_LEN] =3D {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 =3D NULL; + mdesc->os_area_msg_seqno =3D NULL; + kfree(mdesc->ctx); +} + #else /* !CONFIG_AMD_MEM_ENCRYPT */ =20 #define snp_vmpl 0 @@ -474,6 +529,14 @@ static inline u64 snp_get_unsupported_features(u64 sta= tus) { 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 fal= se; } + +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) { } =20 #endif /* CONFIG_AMD_MEM_ENCRYPT */ =20 diff --git a/arch/x86/coco/sev/core.c b/arch/x86/coco/sev/core.c index c7b4270d0e18..6ba13ae0b153 100644 --- a/arch/x86/coco/sev/core.c +++ b/arch/x86/coco/sev/core.c @@ -25,6 +25,7 @@ #include #include #include +#include =20 #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; =20 +static struct snp_msg_desc *snp_mdesc; + /* #VC handler runtime per-CPU data */ struct sev_es_runtime_data { struct ghcb ghcb_page; @@ -2445,15 +2448,9 @@ static struct platform_device sev_guest_device =3D { =20 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; =20 - data.secrets_gpa =3D secrets_pa; - if (platform_device_add_data(&sev_guest_device, &data, sizeof(data))) - return -ENODEV; - if (platform_device_register(&sev_guest_device)) return -ENODEV; =20 @@ -2532,3 +2529,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 =3D NULL; + + switch (id) { + case 0: + *seqno =3D &secrets->os_area.msg_seqno_0; + key =3D secrets->vmpck0; + break; + case 1: + *seqno =3D &secrets->os_area.msg_seqno_1; + key =3D secrets->vmpck1; + break; + case 2: + *seqno =3D &secrets->os_area.msg_seqno_2; + key =3D secrets->vmpck2; + break; + case 3: + *seqno =3D &secrets->os_area.msg_seqno_3; + key =3D secrets->vmpck3; + break; + default: + break; + } + + return key; +} + +static struct aesgcm_ctx *snp_init_crypto(u8 *key, size_t keylen) +{ + struct aesgcm_ctx *ctx; + + ctx =3D 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 =3D=3D -1) + vmpck_id =3D snp_vmpl; + + mdesc->vmpck =3D 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 =3D vmpck_id; + + mdesc->ctx =3D 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; + + BUILD_BUG_ON(sizeof(struct snp_guest_msg) > PAGE_SIZE); + + if (snp_mdesc) + return snp_mdesc; + + mdesc =3D kzalloc(sizeof(struct snp_msg_desc), GFP_KERNEL); + if (!mdesc) + return ERR_PTR(-ENOMEM); + + mdesc->secrets =3D (__force struct snp_secrets_page *)ioremap_encrypted(s= ecrets_pa, + PAGE_SIZE); + if (!mdesc->secrets) + return ERR_PTR(-ENODEV); + + /* Allocate the shared page used for the request and response message. */ + mdesc->request =3D alloc_shared_pages(sizeof(struct snp_guest_msg)); + if (!mdesc->request) + goto e_unmap; + + mdesc->response =3D alloc_shared_pages(sizeof(struct snp_guest_msg)); + if (!mdesc->response) + goto e_free_request; + + mdesc->certs_data =3D 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 =3D __pa(mdesc->request); + mdesc->input.resp_gpa =3D __pa(mdesc->response); + mdesc->input.data_gpa =3D __pa(mdesc->certs_data); + + snp_mdesc =3D 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((__force void __iomem *)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/se= v-guest/sev-guest.c index fca5c45ed5cd..862fc74452ac 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 com= municating with the PSP. /* Mutex to serialize the shared buffer access and command handling. */ static DEFINE_MUTEX(snp_cmd_mutex); =20 -static bool is_vmpck_empty(struct snp_msg_desc *mdesc) -{ - char zero_key[VMPCK_KEY_LEN] =3D {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) the= re * are two options. Either retry the exact same encrypted request or disco= ntinue @@ -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 =3D 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); } =20 -static struct aesgcm_ctx *snp_init_crypto(u8 *key, size_t keylen) -{ - struct aesgcm_ctx *ctx; - - ctx =3D 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_g= uest_req *req) { struct snp_guest_msg *resp_msg =3D &mdesc->secret_response; @@ -414,7 +387,7 @@ static int get_report(struct snp_guest_dev *snp_dev, st= ruct snp_guest_request_io =20 req.msg_version =3D arg->msg_version; req.msg_type =3D SNP_MSG_REPORT_REQ; - req.vmpck_id =3D vmpck_id; + req.vmpck_id =3D mdesc->vmpck_id; req.req_buf =3D report_req; req.req_sz =3D sizeof(*report_req); req.resp_buf =3D report_resp->data; @@ -461,7 +434,7 @@ static int get_derived_key(struct snp_guest_dev *snp_de= v, struct snp_guest_reque =20 req.msg_version =3D arg->msg_version; req.msg_type =3D SNP_MSG_KEY_REQ; - req.vmpck_id =3D vmpck_id; + req.vmpck_id =3D mdesc->vmpck_id; req.req_buf =3D derived_key_req; req.req_sz =3D sizeof(*derived_key_req); req.resp_buf =3D buf; @@ -539,7 +512,7 @@ static int get_ext_report(struct snp_guest_dev *snp_dev= , struct snp_guest_reques =20 req.msg_version =3D arg->msg_version; req.msg_type =3D SNP_MSG_REPORT_REQ; - req.vmpck_id =3D vmpck_id; + req.vmpck_id =3D mdesc->vmpck_id; req.req_buf =3D &report_req->data; req.req_sz =3D sizeof(report_req->data); req.resp_buf =3D report_resp->data; @@ -616,76 +589,11 @@ static long snp_guest_ioctl(struct file *file, unsign= ed int ioctl, unsigned long return ret; } =20 -static void free_shared_pages(void *buf, size_t sz) -{ - unsigned int npages =3D PAGE_ALIGN(sz) >> PAGE_SHIFT; - int ret; - - if (!buf) - return; - - ret =3D 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 =3D PAGE_ALIGN(sz) >> PAGE_SHIFT; - struct page *page; - int ret; - - page =3D alloc_pages(GFP_KERNEL_ACCOUNT, get_order(sz)); - if (!page) - return NULL; - - ret =3D set_memory_decrypted((unsigned long)page_address(page), npages); - if (ret) { - dev_err(dev, "failed to mark page shared, ret=3D%d\n", ret); - __free_pages(page, get_order(sz)); - return NULL; - } - - return page_address(page); -} - static const struct file_operations snp_guest_fops =3D { .owner =3D THIS_MODULE, .unlocked_ioctl =3D snp_guest_ioctl, }; =20 -static u8 *get_vmpck(int id, struct snp_secrets_page *secrets, u32 **seqno) -{ - u8 *key =3D NULL; - - switch (id) { - case 0: - *seqno =3D &secrets->os_area.msg_seqno_0; - key =3D secrets->vmpck0; - break; - case 1: - *seqno =3D &secrets->os_area.msg_seqno_1; - key =3D secrets->vmpck1; - break; - case 2: - *seqno =3D &secrets->os_area.msg_seqno_2; - key =3D secrets->vmpck2; - break; - case 3: - *seqno =3D &secrets->os_area.msg_seqno_3; - key =3D secrets->vmpck3; - break; - default: - break; - } - - return key; -} - struct snp_msg_report_resp_hdr { u32 status; u32 report_size; @@ -979,13 +887,10 @@ static void unregister_sev_tsm(void *data) =20 static int __init sev_guest_probe(struct platform_device *pdev) { - struct sev_guest_platform_data *data; - struct snp_secrets_page *secrets; struct device *dev =3D &pdev->dev; struct snp_guest_dev *snp_dev; struct snp_msg_desc *mdesc; struct miscdevice *misc; - void __iomem *mapping; int ret; =20 BUILD_BUG_ON(sizeof(struct snp_guest_msg) > PAGE_SIZE); @@ -993,115 +898,57 @@ static int __init sev_guest_probe(struct platform_de= vice *pdev) if (!cc_platform_has(CC_ATTR_GUEST_SEV_SNP)) return -ENODEV; =20 - if (!dev->platform_data) - return -ENODEV; - - data =3D (struct sev_guest_platform_data *)dev->platform_data; - mapping =3D ioremap_encrypted(data->secrets_gpa, PAGE_SIZE); - if (!mapping) - return -ENODEV; - - secrets =3D (__force void *)mapping; - - ret =3D -ENOMEM; snp_dev =3D devm_kzalloc(&pdev->dev, sizeof(struct snp_guest_dev), GFP_KE= RNEL); if (!snp_dev) - goto e_unmap; - - mdesc =3D devm_kzalloc(&pdev->dev, sizeof(struct snp_msg_desc), GFP_KERNE= L); - if (!mdesc) - goto e_unmap; - - /* Adjust the default VMPCK key based on the executing VMPL level */ - if (vmpck_id =3D=3D -1) - vmpck_id =3D snp_vmpl; + return -ENOMEM; =20 - ret =3D -EINVAL; - mdesc->vmpck =3D 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 =3D snp_msg_alloc(); + if (IS_ERR_OR_NULL(mdesc)) + return -ENOMEM; =20 - /* 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 =3D snp_msg_init(mdesc, vmpck_id); + if (ret) + return -EIO; =20 platform_set_drvdata(pdev, snp_dev); snp_dev->dev =3D dev; - mdesc->secrets =3D secrets; - - /* Allocate the shared page used for the request and response message. */ - mdesc->request =3D alloc_shared_pages(dev, sizeof(struct snp_guest_msg)); - if (!mdesc->request) - goto e_unmap; - - mdesc->response =3D alloc_shared_pages(dev, sizeof(struct snp_guest_msg)); - if (!mdesc->response) - goto e_free_request; - - mdesc->certs_data =3D alloc_shared_pages(dev, SEV_FW_BLOB_MAX_SIZE); - if (!mdesc->certs_data) - goto e_free_response; - - ret =3D -EIO; - mdesc->ctx =3D snp_init_crypto(mdesc->vmpck, VMPCK_KEY_LEN); - if (!mdesc->ctx) - goto e_free_cert_data; =20 misc =3D &snp_dev->misc; misc->minor =3D MISC_DYNAMIC_MINOR; misc->name =3D DEVICE_NAME; misc->fops =3D &snp_guest_fops; =20 - /* Initialize the input addresses for guest request */ - mdesc->input.req_gpa =3D __pa(mdesc->request); - mdesc->input.resp_gpa =3D __pa(mdesc->response); - mdesc->input.data_gpa =3D __pa(mdesc->certs_data); - /* Set the privlevel_floor attribute based on the vmpck_id */ - sev_tsm_ops.privlevel_floor =3D vmpck_id; + sev_tsm_ops.privlevel_floor =3D mdesc->vmpck_id; =20 ret =3D tsm_register(&sev_tsm_ops, snp_dev); if (ret) - goto e_free_cert_data; + goto e_msg_init; =20 ret =3D devm_add_action_or_reset(&pdev->dev, unregister_sev_tsm, NULL); if (ret) - goto e_free_cert_data; + goto e_msg_init; =20 ret =3D misc_register(misc); if (ret) - goto e_free_ctx; + goto e_msg_init; =20 snp_dev->msg_desc =3D 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; =20 -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; } =20 static void __exit sev_guest_remove(struct platform_device *pdev) { struct snp_guest_dev *snp_dev =3D platform_get_drvdata(pdev); - struct snp_msg_desc *mdesc =3D snp_dev->msg_desc; =20 - 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); } =20 --=20 2.34.1 From nobody Mon Nov 25 11:40:33 2024 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2076.outbound.protection.outlook.com [40.107.237.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 A2B1218CBF9; Mon, 28 Oct 2024 05:35:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.237.76 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730093726; cv=fail; b=h537DjSvvK0im3mxcK1BXKx+TpzeiRREptf4CTfnYnSAoha3srV7F64YXchOby0WC1kTZcmWq0qcjH84xVOn3uWCFG6NMhCeVsXGg113cVhL/E/SLzyd/+63CW6EzW+k72ZpgQalrzIQ0+g4KGSm9yO0fZEnOAqUXWMzvAHQE5M= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730093726; c=relaxed/simple; bh=RHBmoHqM5ZGAiGvChT+X2KckG2N4x4w/n0lg6f+cjok=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=KT0fZDzLvKo5oVroRybl/9o7xEf8XKplCrLVoNwYnCIIdwCIVR4QALF9JktXERPHcjclxv/Y9bYzmXJzLvwHZvCPxZNGgxo5hHO9kKZTgs4MH6btM99fVKB3T1tTUe9Hii7VUf/d56wKeQ91mQ6Qj10XbDW6geGrQ7Ocf2elUmI= 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=MeqBMoC4; arc=fail smtp.client-ip=40.107.237.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="MeqBMoC4" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=dIQiBO02q470w3eZL6RgJAWcWEwnO8/TW0PIUstnRISo7lG0fT0RpL3jGCg8QWcTNKI9s6qzxZ2BDMHXZLqrq8g3GAGy7mEvW4XuvSb49m5bQp6TTTsweaTWT/dXv/MKTyerYBWwoiQE9e1j7YFffBIf2pxQ3v4FwYwPlrTNuNi1eyNpJiTMzIEtPr8PAZdwmh8VayfMw78K2uQRdQe11WmMGly3rsB5kuKqvk2kGHPGih+L7iKEMcTOTERSoAM50XOcZ2CZwEkIOPSFtWVhXMYsX3yILiPHC9BqmUfpGGcnieYDGGRfrS1zRDlm/HoWMHjonPXySWy1EUNWw7b86w== 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=1hDZP03aUpnP3mricDnRDxtyoyn6Nm7/c7XIhDSatWo=; b=ist5SylQmrBpR7ZdLR+fxo0UDMsAjy3fB/+gW7u4J1FAiltnH7N1TjU8te5bwMLcve3pCnuJWmOCYVyp4XqIRZmiXaRDKl5bJ8jggVbHFEsdVho+QuW9pLnMcLmasOXcPlRv9Pn6dDmx0+PSXDYYaXF0UhQAgT8gvh3dfgnwutVzkPVMKPJZiZ57yZ968iEztJZS6CgTnJVkQaz9qkXh1sqyhXoknFkSYvnjmx3kDN/Vf/fyftLfxNgMbikazI2Ll+Lk2XuSCsNHbE/1y5BbIQKXkkZVmnIv0Qdya+5Qu1bjHNs87ffSSgI9Vmt4J2yJmdn0gckBLtcOYTbC56gzkA== 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=1hDZP03aUpnP3mricDnRDxtyoyn6Nm7/c7XIhDSatWo=; b=MeqBMoC4F9qcDq7IGH4dxqPNUS18tMCPW4h9VJp1KMpn9FIuvFU/kIuZG0q4Az5bDEMF8c3y6+i8qb7t4Hc3YJKtp7tiJawnprONhaYHMhsjIbV3bnjd/4XtjN7nKIH0ZJ0wFBubMCod2nvUBwcc4pNNksRJFDUp5G0av0L5CRI= Received: from BN9PR03CA0936.namprd03.prod.outlook.com (2603:10b6:408:108::11) by DM6PR12MB4436.namprd12.prod.outlook.com (2603:10b6:5:2a3::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8093.27; Mon, 28 Oct 2024 05:35:17 +0000 Received: from BL6PEPF0001AB53.namprd02.prod.outlook.com (2603:10b6:408:108:cafe::15) by BN9PR03CA0936.outlook.office365.com (2603:10b6:408:108::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8069.28 via Frontend Transport; Mon, 28 Oct 2024 05:35:16 +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 BL6PEPF0001AB53.mail.protection.outlook.com (10.167.241.5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8114.16 via Frontend Transport; Mon, 28 Oct 2024 05:35:16 +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; Mon, 28 Oct 2024 00:35:12 -0500 From: Nikunj A Dadhania To: , , , , CC: , , , , , , Subject: [PATCH v14 02/13] x86/sev: Relocate SNP guest messaging routines to common code Date: Mon, 28 Oct 2024 11:04:20 +0530 Message-ID: <20241028053431.3439593-3-nikunj@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241028053431.3439593-1-nikunj@amd.com> References: <20241028053431.3439593-1-nikunj@amd.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL6PEPF0001AB53:EE_|DM6PR12MB4436:EE_ X-MS-Office365-Filtering-Correlation-Id: 511f1e36-f12d-49de-1875-08dcf7124de4 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|1800799024|7416014|376014|82310400026; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?wE3TuORqziv9EFgMsDBt3gQE/eUGLU0nDrzLir9RuHbvkJ7ABOiSW03sRm7z?= =?us-ascii?Q?FtTt5TBeDr5QzNcibeidIn+MrB9IfyXsDYTvEXBNfcReytQ4Bp4ff1XKzSzF?= =?us-ascii?Q?MKn522vIhYEbJQUOeWCuNYvU5AQeHsmhAEyIcP9ZBBK3VWjFaMyq02nqstzk?= =?us-ascii?Q?3pwPcwRecBXBPULwz7kIpnQ3/qj4htElsHh7QntTDDnj648uQ5zz6SPpvgcC?= =?us-ascii?Q?OpihgZowOfrrf73OF0VT5M2nyy9gWumpbZ73DSkJR2S+kJMExrCwAxRQny+l?= =?us-ascii?Q?xW/WKqTyCcF3S3YdKWEFlh5T7wXcWNDNgf//1+r1QZWv2DahWaY/bvbpcOu0?= =?us-ascii?Q?+Z6jCtHoTg84iRd8ObJ8T3pXFBffpm7OokdjX+D6FqrYSx3GJUVueZYlzQ+B?= =?us-ascii?Q?pnSoI2o4piSBAZ2CnHV5KWjq0kkl2raV54J1V5dHe9Wqk8c08ZZyUBeaGUw1?= =?us-ascii?Q?jCxqx8MafKp3n5k0Y8Z/elJyeH/cCRC5k2hF0703DysorI5BmMomTMrinTve?= =?us-ascii?Q?c3w9N64y3ep69APqLPc8pDjuzyDWOD49786l2sZm1ejsK3b1KTQkNhrTMQj3?= =?us-ascii?Q?AioR2eA+kHUs2BMKC2xa4qqjkeL/QinBmOgy1PbAop0WmOWSMNi/UgJSba3j?= =?us-ascii?Q?QWlC+CeUVfxkBfbhW219Z4u/0duhLW2EpwK2VooltqN/2Ly/v1LUTKe+e3g0?= =?us-ascii?Q?SMZadT7B3Ld8iCfHejj0rYtXOpKBfiI2w4nizQDXl/NmOxnpEVmUmgC1LlZa?= =?us-ascii?Q?zEJLH4blal+PffclmJxPTKnlyq1/XNhjhnY9Xcx8cxHQklwfMgZDoGCY6Mn4?= =?us-ascii?Q?i6/SFRqbY0B53ubovZYINprGMlBRRjIiuR2vcbTUVXoIPZ5gdjch5nfA7V+j?= =?us-ascii?Q?lqKfcvGGVPuRx9maczWJiKSrqhh5bucOkOfrGT9O2WHs922hZ475prrBWBtG?= =?us-ascii?Q?kl+fmNeOYDj1qm6VgNfqCzsuvTwPcBhb7XzgjlQxkAVEKoHh44nMeLELB4pq?= =?us-ascii?Q?60VvddkynJWELCs8UQq+VGt/n1Eo6rSwpzzd4KqXJP/2dJCRUa4UdCsmRDhp?= =?us-ascii?Q?+gDO0LwnlUoxof+L+jYdZTb6TX4E639JX0T1l3GWQ4ZBObwxWOJjwWB4RMyy?= =?us-ascii?Q?PEDzdUjql3KT4uZglB4o88Grl3ZDmWOBbOMT3LOFERaaZKbfYu55FkCVRU3F?= =?us-ascii?Q?z/OVZJDiW5SLdKBOqJ0SmyP2NFXeC4gnksSnltmh3RDLLMCiWcvUy67No7GE?= =?us-ascii?Q?MgpgEOUkM6n9hIbbTXuTVCKanVf5IsQnZQF6Rkmzb3x2mSmI8oAHLtW2vjRW?= =?us-ascii?Q?O1JniyZLMXF8vj6zO1TiD+1eRyCJI9f11n6+PZkX1hc0/0ziS1NHCJi21FHL?= =?us-ascii?Q?/Pv6zvxEC8pqeeVQb0iCK7FPCya0HK8PdeJbA7b/98j1oiWgIQ=3D=3D?= 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)(7416014)(376014)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Oct 2024 05:35:16.7252 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 511f1e36-f12d-49de-1875-08dcf7124de4 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: BL6PEPF0001AB53.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4436 Content-Type: text/plain; charset="utf-8" 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 added for sev_send_geust_message() and dropped the export symbol on snp_issue_guest_request() and made it static. Signed-off-by: Nikunj A Dadhania Reviewed-by: Tom Lendacky --- arch/x86/include/asm/sev.h | 15 +- arch/x86/coco/sev/core.c | 295 +++++++++++++++++++++++- drivers/virt/coco/sev-guest/sev-guest.c | 292 ----------------------- arch/x86/Kconfig | 1 + drivers/virt/coco/sev-guest/Kconfig | 1 - 5 files changed, 301 insertions(+), 303 deletions(-) diff --git a/arch/x86/include/asm/sev.h b/arch/x86/include/asm/sev.h index 63c30f4d44d7..2c542b9e8dbf 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 =20 +#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 =3D 0, @@ -427,8 +430,6 @@ 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(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); @@ -493,6 +494,9 @@ static inline void snp_msg_cleanup(struct snp_msg_desc = *mdesc) kfree(mdesc->ctx); } =20 +int snp_send_guest_request(struct snp_msg_desc *mdesc, struct snp_guest_re= q *req, + struct snp_guest_request_ioctl *rio); + #else /* !CONFIG_AMD_MEM_ENCRYPT */ =20 #define snp_vmpl 0 @@ -515,11 +519,6 @@ 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(struct snp_guest_req *req, struc= t snp_req_data *input, - struct snp_guest_request_ioctl *rio) -{ - return -ENOTTY; -} static inline int snp_issue_svsm_attest_req(u64 call_id, struct svsm_call = *call, struct svsm_attest_call *input) { return -ENOTTY; @@ -537,6 +536,8 @@ static inline int snp_msg_init(struct snp_msg_desc *mde= sc, int vmpck_id) { retur static inline struct snp_msg_desc *snp_msg_alloc(void) { return NULL; } =20 static inline void snp_msg_cleanup(struct snp_msg_desc *mdesc) { } +static inline int snp_send_guest_request(struct snp_msg_desc *mdesc, struc= t snp_guest_req *req, + struct snp_guest_request_ioctl *rio) { return -ENODEV; } =20 #endif /* CONFIG_AMD_MEM_ENCRYPT */ =20 diff --git a/arch/x86/coco/sev/core.c b/arch/x86/coco/sev/core.c index 6ba13ae0b153..c96b742789c5 100644 --- a/arch/x86/coco/sev/core.c +++ b/arch/x86/coco/sev/core.c @@ -2376,8 +2376,8 @@ int snp_issue_svsm_attest_req(u64 call_id, struct svs= m_call *call, } EXPORT_SYMBOL_GPL(snp_issue_svsm_attest_req); =20 -int snp_issue_guest_request(struct snp_guest_req *req, struct snp_req_data= *input, - struct snp_guest_request_ioctl *rio) +static int snp_issue_guest_request(struct snp_guest_req *req, struct snp_r= eq_data *input, + struct snp_guest_request_ioctl *rio) { struct ghcb_state state; struct es_em_ctxt ctxt; @@ -2439,7 +2439,6 @@ int snp_issue_guest_request(struct snp_guest_req *req= , struct snp_req_data *inpu =20 return ret; } -EXPORT_SYMBOL_GPL(snp_issue_guest_request); =20 static struct platform_device sev_guest_device =3D { .name =3D "sev-guest", @@ -2653,3 +2652,293 @@ 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) the= re + * are two options. Either retry the exact same encrypted request or disco= ntinue + * 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 seque= nce + * 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 =3D 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 =3D *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 =3D __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 >=3D 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 +=3D 2; +} + +static int verify_and_dec_payload(struct snp_msg_desc *mdesc, struct snp_g= uest_req *req) +{ + struct snp_guest_msg *resp_msg =3D &mdesc->secret_response; + struct snp_guest_msg *req_msg =3D &mdesc->secret_request; + struct snp_guest_msg_hdr *req_msg_hdr =3D &req_msg->hdr; + struct snp_guest_msg_hdr *resp_msg_hdr =3D &resp_msg->hdr; + struct aesgcm_ctx *ctx =3D mdesc->ctx; + u8 iv[GCM_AES_IV_SIZE] =3D {}; + + 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_vers= ion, + 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 !=3D (req_msg_hdr->msg_seqno + 1))) + return -EBADMSG; + + /* Verify response message type and version number. */ + if (resp_msg_hdr->msg_type !=3D (req_msg_hdr->msg_type + 1) || + resp_msg_hdr->msg_version !=3D 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_g= uest_req *req) +{ + struct snp_guest_msg *msg =3D &mdesc->secret_request; + struct snp_guest_msg_hdr *hdr =3D &msg->hdr; + struct aesgcm_ctx *ctx =3D mdesc->ctx; + u8 iv[GCM_AES_IV_SIZE] =3D {}; + + memset(msg, 0, sizeof(*msg)); + + hdr->algo =3D SNP_AEAD_AES_256_GCM; + hdr->hdr_version =3D MSG_HDR_VER; + hdr->hdr_sz =3D sizeof(*hdr); + hdr->msg_type =3D req->msg_type; + hdr->msg_version =3D req->msg_version; + hdr->msg_seqno =3D seqno; + hdr->msg_vmpck =3D req->vmpck_id; + hdr->msg_sz =3D 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_g= uest_req *req, + struct snp_guest_request_ioctl *rio) +{ + unsigned long req_start =3D jiffies; + unsigned int override_npages =3D 0; + u64 override_err =3D 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 =3D 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 =3D mdesc->input.data_npages; + req->exit_code =3D 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 =3D 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 =3D -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 =3D 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 =3D=3D SNP_GUEST_VMM_ERR(SNP_GUEST_VMM_ERR_INVAL= ID_LEN)) + rc =3D -EIO; + } + + if (override_npages) + mdesc->input.data_npages =3D override_npages; + + return rc; +} + +int snp_send_guest_request(struct snp_msg_desc *mdesc, struct snp_guest_re= q *req, + struct snp_guest_request_ioctl *rio) +{ + u64 seqno; + int rc; + + guard(mutex)(&snp_cmd_mutex); + + /* Check if the VMPCK is not empty */ + if (is_vmpck_empty(mdesc)) { + pr_err_ratelimited("VMPCK is disabled\n"); + return -ENOTTY; + } + + /* Get message sequence and verify that its a non-zero */ + seqno =3D 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 =3D 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 =3D __handle_guest_request(mdesc, req, rio); + if (rc) { + if (rc =3D=3D -EIO && + rio->exitinfo2 =3D=3D SNP_GUEST_VMM_ERR(SNP_GUEST_VMM_ERR_INVALID_LE= N)) + 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 =3D 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/se= v-guest/sev-guest.c index 862fc74452ac..d64efc489686 100644 --- a/drivers/virt/coco/sev-guest/sev-guest.c +++ b/drivers/virt/coco/sev-guest/sev-guest.c @@ -31,9 +31,6 @@ =20 #define DEVICE_NAME "sev-guest" =20 -#define SNP_REQ_MAX_RETRY_DURATION (60*HZ) -#define SNP_REQ_RETRY_DELAY (2*HZ) - #define SVSM_MAX_RETRIES 3 =20 struct snp_guest_dev { @@ -60,76 +57,6 @@ static int vmpck_id =3D -1; module_param(vmpck_id, int, 0444); MODULE_PARM_DESC(vmpck_id, "The VMPCK ID to use when communicating with th= e PSP."); =20 -/* 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) the= re - * are two options. Either retry the exact same encrypted request or disco= ntinue - * 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 seque= nce - * 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 =3D 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 =3D *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 =3D __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 >=3D 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 +=3D 2; -} - static inline struct snp_guest_dev *to_snp_dev(struct file *file) { struct miscdevice *dev =3D file->private_data; @@ -137,225 +64,6 @@ static inline struct snp_guest_dev *to_snp_dev(struct = file *file) return container_of(dev, struct snp_guest_dev, misc); } =20 -static int verify_and_dec_payload(struct snp_msg_desc *mdesc, struct snp_g= uest_req *req) -{ - struct snp_guest_msg *resp_msg =3D &mdesc->secret_response; - struct snp_guest_msg *req_msg =3D &mdesc->secret_request; - struct snp_guest_msg_hdr *req_msg_hdr =3D &req_msg->hdr; - struct snp_guest_msg_hdr *resp_msg_hdr =3D &resp_msg->hdr; - struct aesgcm_ctx *ctx =3D mdesc->ctx; - u8 iv[GCM_AES_IV_SIZE] =3D {}; - - 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_vers= ion, - 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 !=3D (req_msg_hdr->msg_seqno + 1))) - return -EBADMSG; - - /* Verify response message type and version number. */ - if (resp_msg_hdr->msg_type !=3D (req_msg_hdr->msg_type + 1) || - resp_msg_hdr->msg_version !=3D 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_g= uest_req *req) -{ - struct snp_guest_msg *msg =3D &mdesc->secret_request; - struct snp_guest_msg_hdr *hdr =3D &msg->hdr; - struct aesgcm_ctx *ctx =3D mdesc->ctx; - u8 iv[GCM_AES_IV_SIZE] =3D {}; - - memset(msg, 0, sizeof(*msg)); - - hdr->algo =3D SNP_AEAD_AES_256_GCM; - hdr->hdr_version =3D MSG_HDR_VER; - hdr->hdr_sz =3D sizeof(*hdr); - hdr->msg_type =3D req->msg_type; - hdr->msg_version =3D req->msg_version; - hdr->msg_seqno =3D seqno; - hdr->msg_vmpck =3D req->vmpck_id; - hdr->msg_sz =3D 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_g= uest_req *req, - struct snp_guest_request_ioctl *rio) -{ - unsigned long req_start =3D jiffies; - unsigned int override_npages =3D 0; - u64 override_err =3D 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 =3D 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 =3D mdesc->input.data_npages; - req->exit_code =3D 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 =3D 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 =3D -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 =3D 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 =3D=3D SNP_GUEST_VMM_ERR(SNP_GUEST_VMM_ERR_INVAL= ID_LEN)) - rc =3D -EIO; - } - - if (override_npages) - mdesc->input.data_npages =3D override_npages; - - return rc; -} - -static int snp_send_guest_request(struct snp_msg_desc *mdesc, struct snp_g= uest_req *req, - struct snp_guest_request_ioctl *rio) -{ - u64 seqno; - int rc; - - guard(mutex)(&snp_cmd_mutex); - - /* Check if the VMPCK is not empty */ - if (is_vmpck_empty(mdesc)) { - pr_err_ratelimited("VMPCK is disabled\n"); - return -ENOTTY; - } - - /* Get message sequence and verify that its a non-zero */ - seqno =3D 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 =3D 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 =3D __handle_guest_request(mdesc, req, rio); - if (rc) { - if (rc =3D=3D -EIO && - rio->exitinfo2 =3D=3D SNP_GUEST_VMM_ERR(SNP_GUEST_VMM_ERR_INVALID_LE= N)) - 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 =3D 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; -} - struct snp_req_resp { sockptr_t req_data; sockptr_t resp_data; diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index 2852fcd82cbd..6426b6d469a4 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -1556,6 +1556,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-gu= est/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 --=20 2.34.1 From nobody Mon Nov 25 11:40:33 2024 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2089.outbound.protection.outlook.com [40.107.236.89]) (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 80766190079; Mon, 28 Oct 2024 05:35:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.236.89 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730093726; cv=fail; b=Mg6c97M/x+0rkeyrvxSAtFqGvnXVLgvNE8evpJ4LIb+s+5jW3vdXMW3Ps5b6OURC6YYDSCv4M9lUCQdmmeqtQVpKLA8doy2EJXuxsO2pU6qpAbNWg61VKGWuLp7NATpdvDXuuBgsp1YDeQo+GWsCISBb8lC0YLbkHLxKLSssdKQ= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730093726; c=relaxed/simple; bh=5O6370OwjE0Ca04YwZ2U8AgGgGU/W+46HjtUPOt1iQg=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=UF/1Gb5M1KdgW0w5yJoFMQCKeeWzSZkEXYsBxBlfe9/iiX0qe5V9YQ8yLJ5WBowB0/kcxglnAP7H310SNkGb0vhztv2R/t1I6iMUfit3QBOs0NIk68391CnFSJR6MjvwA6bGcMax4ASDqcXneQOov2dCQvp933FyXQ5hBuB7sYE= 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=AaiKOw5v; arc=fail smtp.client-ip=40.107.236.89 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="AaiKOw5v" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=pDdQ5lRMMlFf5VpJEilV3cc3rEv8AahMAu7r3jSMVwILQ/fkN8b911c9hJtIeBsqo6XdRfHH5xnwAMm9I1ZaULPEMrbx4j8++sl9Gg/60kYBmUnlnn8aTNz/lTfKKcFQ6oTlMzZ6MFulwh8hE5jMo7lJ2kiO+23ZWcIrujUBJdyjMtuuvbDNhR+eU3pXCrmv2usNxE4e1J+SOFKuqKrtLob6hXE4TWkD3pWqRKSAvNBrVW0aF5iiMPGdAsPoXb7x9yiZTw2LAvPoYobhf2oHhKQyw0KW+XC4GpBmYweqWFI3XYKSHL4S+zKsDUHbvVbukbnHlX9L+1gUgFSfP315jQ== 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=rQQnCe2bBeTrqq0wJPkrQAKDQ2OuPHAVeGY0I+nKRSA=; b=kCvSmAMRq8rFuf2NopFwmXfrlrgGsKEzKAxsHntOL98dYrP25p+s7i0LbxDl0IFpG+zpzbTYJTZJdXtCjeZ720QmP+X4B36Y2NSxzq02/Ue/bD5VyVREadG99l3D1JduHa4WF3gJ4JY+y6LmE4uBLKiRkVS/8nDQfbGViUsC4SH8nnxHIoCbxEoTJXU9yqlmOHiOQyWIBwcf3wRsS/UM6E2fl39Z0IUYG2kTcPhiClnZs3mSwRAv3pGVxLHfi0VmmNxcH7r27CrQmfnCT7vXDJsXSjoNTs+/5UGII3Dwzb+6KAJczvUSYyxUmS8z1Uul766RLNjk8AJKz/oX+NdjRg== 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=rQQnCe2bBeTrqq0wJPkrQAKDQ2OuPHAVeGY0I+nKRSA=; b=AaiKOw5vHwcBIP6jc7y2nzn5BWmJ7zSxkXnAwknGThPXxoTh05j3sWITxGhXf2SIc9aNE4GpMr75pFah6TxXc+9ur5lVS+oF/61FatA9JnkfweS8CpUmzyYJIS6wxfCboX0U8Jo1DHmnoniaDOU4ZigAUMsajwpVTJfEUbiKMxM= Received: from BN1PR14CA0017.namprd14.prod.outlook.com (2603:10b6:408:e3::22) by SN7PR12MB8004.namprd12.prod.outlook.com (2603:10b6:806:341::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8069.27; Mon, 28 Oct 2024 05:35:20 +0000 Received: from BL6PEPF0001AB58.namprd02.prod.outlook.com (2603:10b6:408:e3:cafe::12) by BN1PR14CA0017.outlook.office365.com (2603:10b6:408:e3::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8093.25 via Frontend Transport; Mon, 28 Oct 2024 05:35:20 +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 BL6PEPF0001AB58.mail.protection.outlook.com (10.167.241.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8114.16 via Frontend Transport; Mon, 28 Oct 2024 05:35:20 +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; Mon, 28 Oct 2024 00:35:16 -0500 From: Nikunj A Dadhania To: , , , , CC: , , , , , , Subject: [PATCH v14 03/13] x86/sev: Add Secure TSC support for SNP guests Date: Mon, 28 Oct 2024 11:04:21 +0530 Message-ID: <20241028053431.3439593-4-nikunj@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241028053431.3439593-1-nikunj@amd.com> References: <20241028053431.3439593-1-nikunj@amd.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL6PEPF0001AB58:EE_|SN7PR12MB8004:EE_ X-MS-Office365-Filtering-Correlation-Id: ab84cba3-6df2-4ea8-8794-08dcf7124ff9 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: =?us-ascii?Q?31wAuoy4+7ZoJs4/BXBnsANzUv5wy/1rkSeg/KtuesNRMUpIBV+UKI1Nj2D+?= =?us-ascii?Q?1wunXNXp5b9Gq+F7KPUKBEc4+vEnOFzOL0SskFi3nWNwf3ufQtftw2fctMxl?= =?us-ascii?Q?CTukmAyMgPlyQHsa1HHZ9506uojZ4Em9TBBz8Q+YlwcOthwQ9nrLQwq3x2I0?= =?us-ascii?Q?qyk3+cQTOSyjTIk1IH7D9s2cAiXD4K5IrrTBPdPEBvIH0cu9h4AXd0sFc8xM?= =?us-ascii?Q?lMEdKw3nUe5ZEfV7glTo9djGRoM6Ub2QPXBm+BCJ2jDA7kY3SO5/0ieZSCkS?= =?us-ascii?Q?aH+3D5B+FH3sh4ygUzT3MG3MCKezd47mjq9DQQclrVt2AH9Z20cetFW7Ge4t?= =?us-ascii?Q?wjshLN/9ZAryUI/2VmAGyjaiiE4cpOE6utssllJW2Jzz1CK16l4SVIdZmY0z?= =?us-ascii?Q?Fonskr1uJx0GK5k9L3JF5DKE5OCPWVWvzFjtVEfoGqJ+z9CxSrKNSbD1IfZE?= =?us-ascii?Q?tzPA3kdX3EOENJitknbjr6iePQbP70T3sflO0osM2xS6LMPuaFVtk+3kTAn6?= =?us-ascii?Q?YcCatVhe4CeT8amxGTlh8N4HVZLGzqGnryDsvdu2+M++Uy1Z6O0HliTNgG9s?= =?us-ascii?Q?K/W3tY1iYhhV8kgIcTIifB6ybvLI+gfHWU4vaMxt5kkyIp21jIxDNJpx62tL?= =?us-ascii?Q?bCQ149yROa1/0SuoRBzCZPl4/7H43P6p/GyanQR/bYgBsz324e6L8CyfSwOs?= =?us-ascii?Q?KicMiB/l3YrNXEPSAk1I3HMbkeFNnAvYU5xweyys2E3xfBqd/qn4qHRIvodA?= =?us-ascii?Q?zwuEX7FHQZwa3XrMVKUjsmNGpUnd2cNL8GnpAt4uIMTDjvCmMvgJ4T6Nko8O?= =?us-ascii?Q?4LcqP0Azi/UnDBzKTLsZto5W9ud7EPqwa8VbieMio7YSj77kJBGo35LXMcnw?= =?us-ascii?Q?BwNhJ1OEkpVRtAMgTs7pvCK0pJNJL+uORRq91gN9MwVN9rL3GkJOeHV1nm7J?= =?us-ascii?Q?oOlrnLgihomOV1tpWyvMF3Mt0O2WlJVGKtL8PPUJMNanUJ7fzF7BCD9Qa/EN?= =?us-ascii?Q?b2NTp7Bi71DYnQ07YNR37uGk5fe2KHGFyvOrYCR5BpKftJmOQjVJit0A5Uaa?= =?us-ascii?Q?JMx/5WZ2ph7YIBQl5gsJwmqW8VloQoR/L77Bu20LSNjLGbspqnRsTWgL/+E8?= =?us-ascii?Q?G6hQiBCierfTwMUEm60lx3Z7Bw1xTfZhWng3bEScLcvwskSMbke/mxBrLWJh?= =?us-ascii?Q?wHsQ/hYM42JFuDoAosK/Lcq7rrXS1sDXdNJhE6tGnUmG5QhRQAJHq5XLrKOr?= =?us-ascii?Q?SaEpUFIY+jkrXOnkWXsiDh7ayXBD/oh10S7pME4dtlXsqWQD9355RAYuYqxm?= =?us-ascii?Q?GylfUL4HCPC1ZI7XiRZxKoiHvkiBlyK6cnxwBHg/tRO4mqYt8vNSOfPoBiTn?= =?us-ascii?Q?P/OmatpJI1DgtxdOQw3/eRFAv3LG0J3+vNRqMOpTB2PAsLqixQ=3D=3D?= 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: 28 Oct 2024 05:35:20.2211 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ab84cba3-6df2-4ea8-8794-08dcf7124ff9 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: BL6PEPF0001AB58.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR12MB8004 Content-Type: text/plain; charset="utf-8" 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. Add confidential compute platform attribute CC_ATTR_GUEST_SNP_SECURE_TSC that can be used by the guest to query whether the Secure TSC feature is active. 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 ++- include/linux/cc_platform.h | 8 +++ arch/x86/coco/core.c | 3 ++ arch/x86/coco/sev/core.c | 90 +++++++++++++++++++++++++++++++ arch/x86/mm/mem_encrypt.c | 4 ++ 7 files changed, 156 insertions(+), 2 deletions(-) diff --git a/arch/x86/include/asm/sev-common.h b/arch/x86/include/asm/sev-c= ommon.h index 50f5666938c0..6ef92432a5ce 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 align= ed */ +#define GHCB_TERM_SECURE_TSC 10 /* Secure TSC initialization failed */ =20 #define GHCB_RESP_CODE(v) ((v) & GHCB_MSR_INFO_MASK) =20 diff --git a/arch/x86/include/asm/sev.h b/arch/x86/include/asm/sev.h index 2c542b9e8dbf..d27c4e0f9f57 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, =20 + SNP_MSG_TSC_INFO_REQ =3D 17, + SNP_MSG_TSC_INFO_RSP, + SNP_MSG_TYPE_MAX }; =20 @@ -174,6 +177,22 @@ struct snp_guest_msg { u8 payload[PAGE_SIZE - sizeof(struct snp_guest_msg_hdr)]; } __packed; =20 +#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; @@ -497,6 +516,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_re= q *req, struct snp_guest_request_ioctl *rio); =20 +static inline int handle_guest_request(struct snp_msg_desc *mdesc, u64 exi= t_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 =3D { + .msg_version =3D rio->msg_version, + .msg_type =3D type, + .vmpck_id =3D mdesc->vmpck_id, + .req_buf =3D req_buf, + .req_sz =3D req_sz, + .resp_buf =3D resp_buf, + .resp_sz =3D resp_sz, + .exit_code =3D exit_code, + }; + + return snp_send_guest_request(mdesc, &req, rio); +} + +void __init snp_secure_tsc_prepare(void); + #else /* !CONFIG_AMD_MEM_ENCRYPT */ =20 #define snp_vmpl 0 @@ -538,6 +578,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, struc= t snp_guest_req *req, struct snp_guest_request_ioctl *rio) { return -ENODEV; } +static inline int handle_guest_request(struct snp_msg_desc *mdesc, u64 exi= t_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) { } =20 #endif /* CONFIG_AMD_MEM_ENCRYPT */ =20 diff --git a/arch/x86/include/asm/svm.h b/arch/x86/include/asm/svm.h index 2b59b9951c90..92e18798f197 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; @@ -564,7 +566,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/include/linux/cc_platform.h b/include/linux/cc_platform.h index caa4b4430634..cb7103dc124f 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_SNP_SECURE_TSC: SNP 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_SNP_SECURE_TSC, }; =20 #ifdef CONFIG_ARCH_HAS_CC_PLATFORM diff --git a/arch/x86/coco/core.c b/arch/x86/coco/core.c index 0f81f70aca82..5b9a358a3254 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 at= tr) case CC_ATTR_HOST_SEV_SNP: return cc_flags.host_sev_snp; =20 + case CC_ATTR_GUEST_SNP_SECURE_TSC: + return sev_status & MSR_AMD64_SNP_SECURE_TSC; + default: return false; } diff --git a/arch/x86/coco/sev/core.c b/arch/x86/coco/sev/core.c index c96b742789c5..88cae62382c2 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; =20 static struct snp_msg_desc *snp_mdesc; =20 +/* 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; @@ -1148,6 +1152,12 @@ static int wakeup_cpu_via_vmgexit(u32 apic_id, unsig= ned long start_ip) vmsa->vmpl =3D snp_vmpl; vmsa->sev_features =3D sev_status >> 2; =20 + /* Set Secure TSC parameters */ + if (cc_platform_has(CC_ATTR_GUEST_SNP_SECURE_TSC)) { + vmsa->tsc_scale =3D snp_tsc_scale; + vmsa->tsc_offset =3D snp_tsc_offset; + } + /* Switch the page over to a VMSA page now that it is initialized */ ret =3D snp_set_vmsa(vmsa, caa, apic_id, true); if (ret) { @@ -2942,3 +2952,83 @@ int snp_send_guest_request(struct snp_msg_desc *mdes= c, 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 =3D snp_msg_alloc(); + if (IS_ERR_OR_NULL(mdesc)) + return -ENOMEM; + + rc =3D snp_msg_init(mdesc, snp_vmpl); + if (rc) + return rc; + + tsc_req =3D 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 =3D MSG_HDR_VER; + req.msg_type =3D SNP_MSG_TSC_INFO_REQ; + req.vmpck_id =3D snp_vmpl; + req.req_buf =3D tsc_req; + req.req_sz =3D sizeof(*tsc_req); + req.resp_buf =3D buf; + req.resp_sz =3D sizeof(tsc_resp) + AUTHTAG_LEN; + req.exit_code =3D SVM_VMGEXIT_GUEST_REQUEST; + + rc =3D 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 =3D=3D 0) { + snp_tsc_scale =3D tsc_resp.tsc_scale; + snp_tsc_offset =3D tsc_resp.tsc_offset; + } else { + pr_err("Failed to get TSC info, response status %x\n", tsc_resp.status); + rc =3D -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)); + + return rc; +} + +void __init snp_secure_tsc_prepare(void) +{ + if (!cc_platform_has(CC_ATTR_GUEST_SNP_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(); =20 + /* Initialize SNP Secure TSC */ + if (cc_platform_has(CC_ATTR_GUEST_SEV_SNP)) + snp_secure_tsc_prepare(); + print_mem_encrypt_feature_info(); } =20 --=20 2.34.1 From nobody Mon Nov 25 11:40:33 2024 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2086.outbound.protection.outlook.com [40.107.92.86]) (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 0F8A31917E4; Mon, 28 Oct 2024 05:35:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.92.86 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730093731; cv=fail; b=uNMkvl9RajD5SQarfpXu3jebK7BC8T21UdSFiNUY1gJrjAYLDlo3I/bR2tROY/YsQAjQBVCN9zoExQC2StNlVRyYtomiQAHNP/mT0s4Qp8AqWF33HLElkKasMowF2OZ5lb2XSAVqxCUSYfsfx1fONvU6yOZSX+GgOSzr1y2Xmgs= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730093731; c=relaxed/simple; bh=AEr5Ri+xaiOZYfOIJW+1r5+kemaLI6PLPTJcqjdAAIQ=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=jvxxPVvI/Y/F/aAx/C8kYj5RvioQh4oZ/nA8kJyhWs7icFHGseXd4vr7AsVCTrkqqFZxKdW844EUj0X/E2+VST7ND9JiXj8zV3bMRtLw46eH/DbhftNhn/q04GULfX7OjUVwPfS9rz2N0OJmsciJW2zwp7lNMSRnoUNDYrx7gb4= 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=48XA1GLJ; arc=fail smtp.client-ip=40.107.92.86 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="48XA1GLJ" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=JSnrr8UJY2X0aHwJckBaxXqeF/zq6bt/uTp25/TejdLEJOUksjqN3nkdck0xpQxsmHLEYKVP3pSNJWqAT2+9x0NaOVOqNJZXWw5fGSzJuT1sIrmq3UfraKW1dDmIV9i9xI966TgYH7v8YfUpkqxw/dTaHLIeP99PW3DnnlicCglruNhdulfy+FaPuFZBeYm6eEzBgTu+MrbDIcCN+3P65FE9ebSlboyfwEn31yoNYdEJDLlWRS6Mrh10a3T5yZl3KN8NYlHDI3G3vfAqirHwaca3qse82c+5yoaa9gFoayqDcV1nA8CsRdsbYMnCdXARUffnPM1Mef9u/z8YxvYLBQ== 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=QH4/9vcAmKmjNGsFX/8gyVKe4ilMnHswTQTnRodhqkQ=; b=lqyXzay7JPDPsi6JZQTp7u9aDRAdCK/Feh5H3BhXCDbWq2SFKh3kxFdQ7sLo+z4a5VvndhlAmcxUKM51mk8DA7zNfQa1BgkGVgmtoIye7SNrMhCiJ3sFnaYM93FTuWTA2I0eD2SXJXoAG1On/E6S7lxbXBmuefXs6yKX6+5radTTdAtfObhnSbPfx3oSfY3W8xUMSVAYuDgq8o5GxIYLgMrO7iedZBL4P8C6WfzQYf3Sb7If26qjE0JMM6grOXdsBtINJkhFzUZQJ2Zq2guB0A9FD7XB8cHCmOZBgnLquAcjB+RePx7WxY/vi28MIpTGk0pjEdgwTBkmunenYb+IPg== 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=QH4/9vcAmKmjNGsFX/8gyVKe4ilMnHswTQTnRodhqkQ=; b=48XA1GLJAboEfdOyNwD5H32MAwVIRAq1NvTaKGrNxGeW0eY06UNwKxoyikT7yXPVMSHTOLdoBZAW0hUjMLIEkuRSt0hsnnTUeUzX3fQQmfuhn03mwMiuPBnReLcfnKh/Aqp875VTx7q86nvMyvmRNYC/SjPzC9pVYh+9po6HTTM= Received: from BN9P222CA0013.NAMP222.PROD.OUTLOOK.COM (2603:10b6:408:10c::18) by MW6PR12MB7072.namprd12.prod.outlook.com (2603:10b6:303:238::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8093.21; Mon, 28 Oct 2024 05:35:24 +0000 Received: from BL6PEPF0001AB55.namprd02.prod.outlook.com (2603:10b6:408:10c:cafe::6f) by BN9P222CA0013.outlook.office365.com (2603:10b6:408:10c::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8093.23 via Frontend Transport; Mon, 28 Oct 2024 05:35:23 +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 BL6PEPF0001AB55.mail.protection.outlook.com (10.167.241.7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8114.16 via Frontend Transport; Mon, 28 Oct 2024 05:35:23 +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; Mon, 28 Oct 2024 00:35:19 -0500 From: Nikunj A Dadhania To: , , , , CC: , , , , , , Subject: [PATCH v14 04/13] x86/sev: Change TSC MSR behavior for Secure TSC enabled guests Date: Mon, 28 Oct 2024 11:04:22 +0530 Message-ID: <20241028053431.3439593-5-nikunj@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241028053431.3439593-1-nikunj@amd.com> References: <20241028053431.3439593-1-nikunj@amd.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL6PEPF0001AB55:EE_|MW6PR12MB7072:EE_ X-MS-Office365-Filtering-Correlation-Id: ebe52921-5914-4835-9b96-08dcf7125216 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|7416014|1800799024|36860700013|82310400026; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?0IySgieLjVSyekFG4LwTehUqAhqV+SMmcSZH/bE0D5laKOXR2aYp8p8OYzaS?= =?us-ascii?Q?jh+O8dqyIl0Gekg0PmCiHACnI3iz2K+IDGsryvhZ7Waxm+weLDs0pHfhd01T?= =?us-ascii?Q?FuK0P5NZ2RftGp2+Qbm3re4/JEakke4T63OTUdAaBNqPv/nObNrbUVyDSfPy?= =?us-ascii?Q?5u/dH8OkyDqG91wGxYsuitoqpAV6smeuRxbWma7Ws7kmsH+nyHDZG1jyR6b/?= =?us-ascii?Q?ehceo1DBHvjyA7D+EPGgFMDdJoDw415p8WNCG9kE3JalBOTvGJzCnML+v2c2?= =?us-ascii?Q?l9fYXWg3R/SDz+GC8veihG24ONkKA2qjqmF7SIHWqppj14sjarjqFQFq7zUD?= =?us-ascii?Q?4SX2Q+Q5H0Fw7dw7feBLlRHkECGm/vTSlqL0xvsguFvDVumwwvtFbXxbhxKo?= =?us-ascii?Q?ViwEtm27FVHQLtFbEL2QByD3FJKEc4kZVG3dYouvN9vuva767/vijAQEejm2?= =?us-ascii?Q?4NzOgBrgN1orOyk8V/e2sdOo9aOADzdh2AvZGl42g++A5p5cHPUzKiGGxsL7?= =?us-ascii?Q?CJVWgYsyQwN7tBkPAnWE8zHlePgYOyabYboSh9PjkisRhSEk0lZu3j2Uh7nj?= =?us-ascii?Q?e/kY24EGHlYZLxS+fHU8vL+Yf2Y1xxW3n6wV64/jSceQjIlHETKmP1DvC9rB?= =?us-ascii?Q?ZQCnNRs0tiOyZO9RgLLD19KFYdj3PAyZfCYA6UJBPe3onACVKEzFsF49wfAx?= =?us-ascii?Q?2EYvmPks4n6aqcXg22QifAVZgk5nkgiqXrgMK7bnJMgPyHJyb0UVhPCyyGg0?= =?us-ascii?Q?OXekaLsIMXkk64jV29QaSHfjY5AjdkEnJt0CXq4+0tUlDjqgfTCFQ+oHmkNX?= =?us-ascii?Q?P6MpA77mdb9bpT/xJtpX+Ww1fyB3cmnCrOPJWTs2kTFhqpgMYeARM2RZ3Xyf?= =?us-ascii?Q?32Q+2LKLSvoAAEVkIZPfAf04XKdkoL5cJsdqIunXsrejDjreUVjfIO5Obbje?= =?us-ascii?Q?adT5XRQkwst6uDis4psbVj+K3jVZl2x5uTB/BylQ02UahcFth35vdp25S4jj?= =?us-ascii?Q?Y/NL7sCGWXcVnOS0/rgoe/PV7AsSDz8qFnQrpSVfRK+f0HPvD8S1/QiPOvVb?= =?us-ascii?Q?dk+AfRrxofhTawQk9Q9cdM8b6AHlMgxlM3mWEzV7suJKE2pgNpYpPQcW9NX/?= =?us-ascii?Q?rB3c6wrGr78enuESn150plGwY/wd20sPAN8MtnQGCmdf5xOuQA5b01+UW+Wk?= =?us-ascii?Q?wjOh+9neeQ5ZdepiNBqza4z8tJK5EywqMmix8hZzIyE8Gal0Cx1ZymjBPJaP?= =?us-ascii?Q?yBvXRCHxuMtcYVyCFp2b1g5hOIEM0AtcXKiK8WQYZkWYgYiFX6ZpyWn81CYR?= =?us-ascii?Q?j1BbB4AVno0Ud4poPdSwo3MHxw0ROcswShOyF7z1okJPiVZFM5Z16wlTgZQe?= =?us-ascii?Q?KLuD0TEhWK0odgX4c8iRd6+3fMzE+dM1+oRJPX4ruH6VWFRy0g=3D=3D?= 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)(7416014)(1800799024)(36860700013)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Oct 2024 05:35:23.7671 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ebe52921-5914-4835-9b96-08dcf7125216 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: BL6PEPF0001AB55.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW6PR12MB7072 Content-Type: text/plain; charset="utf-8" Secure TSC enabled guests should not write to MSR_IA32_TSC(10H) register as the subsequent TSC value reads are undefined. For AMD platform, MSR_IA32_TSC is intercepted by the hypervisor, 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 88cae62382c2..585022b26028 100644 --- a/arch/x86/coco/sev/core.c +++ b/arch/x86/coco/sev/core.c @@ -1308,6 +1308,30 @@ static enum es_result vc_handle_msr(struct ghcb *ghc= b, struct es_em_ctxt *ctxt) return ES_OK; } =20 + /* + * 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 =3D=3D MSR_IA32_TSC && (sev_status & MSR_AMD64_SNP_SECURE_TS= C)) { + u64 tsc; + + if (exit_info_1) + return ES_OK; + + tsc =3D rdtsc(); + regs->ax =3D UINT_MAX & tsc; + regs->dx =3D UINT_MAX & (tsc >> 32); + + return ES_OK; + } + ghcb_set_rcx(ghcb, regs->cx); if (exit_info_1) { ghcb_set_rax(ghcb, regs->ax); --=20 2.34.1 From nobody Mon Nov 25 11:40:33 2024 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2042.outbound.protection.outlook.com [40.107.220.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 D9D51191F84; Mon, 28 Oct 2024 05:35:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.220.42 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730093732; cv=fail; b=R0pVyfYX/s2ERC2EQUGZYgqekAc1gLW+NBBaPdrtv7bIYah35/nfMWe/7Mhbv5H7g1ljIcuj3hHir2SpFToVdsrOz2/2ZhCDo3Du0B2l99T3U3UxXxuRU4esIDeCnzK4pweUqhP5qhCdT/65my1dK3Kz9SSG/8jaNR5G8rHGvpw= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730093732; c=relaxed/simple; bh=i3ZmhVc7Nr7IImnmj8NYhE4cNnqX5u2EktPp1OsemRc=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=KZtPJAkWiccaBsIebKag+FP9KJNkfrc5Dl+sEqxwBuOzVj9XALZSuLtIuyEDI6lQRdZW5oFFd5mq0EpbvxhUO0LaiqFyDRgv0szZg5qyrQAH+W233hSwT7LY4qWMA8gx6Vv5AVPzc1bwHP2/BMFOQX8SzIwGdSt0WRJzgRSCMKU= 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=yU04gy58; arc=fail smtp.client-ip=40.107.220.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="yU04gy58" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=sXhnTmRndINn5deUfjHLmn6h03Br/5wIgZE5V/8TqI5r6Grrh5M+1oYn+PiIyI6/BZb/zWl7sjb7NmUuTcTnNI+p76RHvLPe2jRENrUXUskd3ILUZCd45xpSnr7VG+DS/8OPLNFAjSeDLY4xOoxkgwJPgUDy0qtRTze+IWOv5v8vAzt8EwPqwHY4ZcTDz9HvH9uSG3/sWgC5x217icvRttpf64lEHsA/8rkF2VpTIgFeW+Syw6GGqXVk7fvWchHegjuPypDU6oJWFGOTo1I4odx8368/E3NhQXEaRmR1/GerG8k12NN0HSnwwibG+Br5CBfYCWHCSxUNLsNzQmRa/A== 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=+UBvqghZDCtRzYNcOIM3HjPWQCN1d9UafoX5Ow9nh4A=; b=UOFnheigucIN9KU8Rx2oBIksDKmh/VOMotnFduu85fRQhxMKHJI+kHvSJxBI1r1+V9VtDGDoXARhZVzSyhmlbVc0sYYWyyUhl1u0OOFUNb5ISWZllCvIO3Y/1Nmwm2yUBU+RV4CnC2tsx9U1Egruu9+d97Gb8gYX4JHZ7Iez5fzXB08vF8UVIMqa+HvOcTO2UNChlT9RyCpYuARE2AucKrle3LfakWnUkPCExT494u187JuclReJnuPaOkSLJHB5PhwZ3xMZoRrlmemtoJkg65N5RLj6KvO/95tKwmdVZ/snBzngakYRbzTYdXo5xXRfxhzZCfjSVR2wyuuUKo0+0Q== 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=+UBvqghZDCtRzYNcOIM3HjPWQCN1d9UafoX5Ow9nh4A=; b=yU04gy58qagyxHFXia2BXJD2L3ZPV+PYWe5bMsfszwknmSbZ/J5ovyn13bZhTVlM1AXZ3PPk7rPoZceE+SSfcVThSn3Xni/MUqptYxSiS8sOr4dVHpRlPf5AjD5xpt+gmWYCAB+8g2TB3sGTL3gadpOsSYBhdxPfDRCnlbmmb3s= Received: from BN1PR14CA0018.namprd14.prod.outlook.com (2603:10b6:408:e3::23) by IA1PR12MB7568.namprd12.prod.outlook.com (2603:10b6:208:42c::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8093.24; Mon, 28 Oct 2024 05:35:27 +0000 Received: from BL6PEPF0001AB58.namprd02.prod.outlook.com (2603:10b6:408:e3:cafe::5d) by BN1PR14CA0018.outlook.office365.com (2603:10b6:408:e3::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8093.25 via Frontend Transport; Mon, 28 Oct 2024 05:35:27 +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 BL6PEPF0001AB58.mail.protection.outlook.com (10.167.241.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8114.16 via Frontend Transport; Mon, 28 Oct 2024 05:35:27 +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; Mon, 28 Oct 2024 00:35:23 -0500 From: Nikunj A Dadhania To: , , , , CC: , , , , , , Subject: [PATCH v14 05/13] x86/sev: Prevent RDTSC/RDTSCP interception for Secure TSC enabled guests Date: Mon, 28 Oct 2024 11:04:23 +0530 Message-ID: <20241028053431.3439593-6-nikunj@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241028053431.3439593-1-nikunj@amd.com> References: <20241028053431.3439593-1-nikunj@amd.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL6PEPF0001AB58:EE_|IA1PR12MB7568:EE_ X-MS-Office365-Filtering-Correlation-Id: df79551f-259e-48b1-0810-08dcf7125428 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|7416014|376014|36860700013|82310400026; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?G3KVUHxsBIkot/MFpyoZXwvTyzKzOMsaKB27eJXYg7frkrpoyzHGwGxZUGnC?= =?us-ascii?Q?72B2cdQDc7ms6yikjYwoupFxPiAyEXKy902FxPzr8YdlPudTe7iTE2ATTDqV?= =?us-ascii?Q?NvfhIxwS7xjz6JaG2r8q9gYrleCmaZatqAefHDYszZUzAdjDaSnA9N6hGA8a?= =?us-ascii?Q?aMLadFQpflDrAe1R7dZjXiBm3yuBIjrmuMvPag5DHCcVGaWzMC9jdyD/zk/Q?= =?us-ascii?Q?TEws1ZAoIhkhdq6m8sxHN3lOkXm7cKV/vm9eP4o63KerOQiu9ww9EAlNzvm1?= =?us-ascii?Q?Tf5v/VfUi6wMP27znNgpjBT9TKt3NEGgnZDnAigYeLYeygYgPb9xarByJHmE?= =?us-ascii?Q?bPNX8gwhxTTIa8emZTTTZ+enJzJUI1ZDjxRup/i132yfpZ3KrQBg+1dMFfmH?= =?us-ascii?Q?GhFtoGwJDyHvJEOqmeLlzgx+q9y1smhyGHGZm0l9hNSO9+QEbmS04YCx2+IA?= =?us-ascii?Q?7QYBh9lHuv2SXhTucWcF3kY5ZaRR475ry8tgQZK/1tjfViPPpQNDYKQZjCLA?= =?us-ascii?Q?/Eh/0cvegD9FzSAaJANM+1LeObM4O0XyVO3gjZO8bF+hSxBPe5M6AuX5JRfN?= =?us-ascii?Q?AyBiFDYhTm7A644xp67zKTlucHkELlFb1mIoC5TFXmIVzDxlOJq1e1x6kIbY?= =?us-ascii?Q?hq0+swP1DeruAmKwCe5n8hSBzbzai5QK6D+dykQJMgfSk3TGY8sQ4LCun8oI?= =?us-ascii?Q?ogYJWrxdS6p6InLMbUGZ9nc/0cKF6VuMrI37TECKBoQutvsMlgqrPrlaFWfX?= =?us-ascii?Q?a72MWVEycDBiFKzQWJB43vAvJ3CD4u+CcnHX6pedeNakg51wVeGJC6Da1jZ6?= =?us-ascii?Q?o2FWD/01R2C2RD0sHhjkzPGAhEAr3WHBsRaujokw1KMZ8L1N2BT3Ws7f0Wni?= =?us-ascii?Q?ViLUyYVtdqFioXjrOVsg4/xBvTmbA6bOCZgOLTgWzVtZxyqAs0zSDVylTVrr?= =?us-ascii?Q?F0TUtvHaMUg/5qeG+DlNhsZEoCvZ85fuRigv0GffDZGj/xyUyUKGG49XM5T7?= =?us-ascii?Q?yr+srhd08W8XdDvYTFW4cH033NDkFMjEwunaWOzC/iuMUb5D+R/b5KoVm9+u?= =?us-ascii?Q?1VP4AwzF0h8Nbrdh1jKJS6j57liIqZOqP023bDaP6F4yjCS2Rp0eMXKkLrhI?= =?us-ascii?Q?UvYPO3Va5rfv0ZvTSaZNAISUzgzUg48eVj8MAehhrD/CsjRWo2PHtYZfG7oc?= =?us-ascii?Q?qOHLp87+6cOttOEnr9Dw0sP+8IZJr3eUKlZDGFImzEoUhidRqR5jTUup5IVJ?= =?us-ascii?Q?Q/exYqJ4OzTza+KyyWz2inf60DAWHJZLDIC44BMQcu03xj8VGDEFou6LzOf8?= =?us-ascii?Q?93k9A9B/zgkl8BkrP7THIeNvxNEVhXkbGcNjg6JS965ntuPOcYVI7REVHugJ?= =?us-ascii?Q?434KtntnmsjWRu+U+gL+FGpM8IEc7EF5fx4DkezMmHZyIES5Dw=3D=3D?= 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)(7416014)(376014)(36860700013)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Oct 2024 05:35:27.1586 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: df79551f-259e-48b1-0810-08dcf7125428 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: BL6PEPF0001AB58.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB7568 Content-Type: text/plain; charset="utf-8" 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, guest execution should be terminated as the guest cannot rely on the TSC value provided by the hypervisor. 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 *g= hcb, bool rdtscp =3D (exit_code =3D=3D SVM_EXIT_RDTSCP); enum es_result ret; =20 + /* + * 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 =3D sev_es_ghcb_hv_call(ghcb, ctxt, exit_code, 0, 0); if (ret !=3D ES_OK) return ret; --=20 2.34.1 From nobody Mon Nov 25 11:40:33 2024 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2074.outbound.protection.outlook.com [40.107.92.74]) (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 0F51C192B6F; Mon, 28 Oct 2024 05:35:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.92.74 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730093737; cv=fail; b=tw2lWnJ0g/wz+O9CE+UyR6/HhfbPRmpEnfTaI4Iop2PaQQ8rITyg9C85Y40ldyKbgV971Htfx+lXbAM/byzo4QxGpUcLKsqLcHsbKEcRMVeHB9y0+3IeDnIW9vdQCcaeJ2oHN7VHVm9Prm55P5izSY3R9wSv+DMMdrZxp8C6evk= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730093737; c=relaxed/simple; bh=84IW3SMR2DWYi6Rj4+JDj9lTgR8VK13nCyA49M/wkUU=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=mkd7cljP8HJ+mJ0G0YSMChStPwnFsxYrbYY4GaTh7A1FDwsSrZtfHIOGIaPhBUnLvf+vdn1FPW7BnUPkNZrdfplYlTu88ZYAEjjrsred8n3RSRusIcXoz75RNKfFMjcVm7Rlnd8OcXAvld28YMEYhiWcz1pEf4bxJVlHs58kK0w= 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=gTEBbA4Z; arc=fail smtp.client-ip=40.107.92.74 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="gTEBbA4Z" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=KNy3uMMxEZunZBdGXrikDeJFWpBvthz+sc9oCfiqk0++vRpUInRMMn74pIe9DxcfMtNIrBO0CaAYwXu4d6YHT4DcksAHtGOebgJzXTulW8JR575BV8pQ8Aw7x12+qElOFZ6JNUaZDlpXlDUz8DIYjTJttneHZrm+5bBMwKk7LHXBRG+DhhCFPr1dUII6ZoE6vCRWQFt6H85qpX+FC9rkvu91yY9KIAdK5k6pOrmK9cJ45I8x3RAEYNnmb+vzNe3hVCtbmHese8RiQ9YJPeqUtJ66xjFyZ0GvBHyOOVoRFkXFlQmXp18LPTqVG8uGJbUYJOmAiv4QaDm4Nez2y+/UPA== 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=bY1L50c0WxQg8MOFHr+tzQWs7PqGLtUwBGPdUbzW1vU=; b=KhHOIvFdCw7Q+yrIEFU2HtuKywjjWoX9bZ011ykk6tu+Az+l7m/KCr+nwP73nFGxdIQTRuW9DmPbQXwKEKtkxrPFZppwtolUFTXo40Lo10M/1k50u5HAgi0bWIcILVDyE1pr6UNwK9oP4QbaA6Uw6oG6UlJjLifzpWkDZwBAzV5bztq+viOinSEOXymqYnrIARe2S5RSRkyIbzHuCiHtxm8cH/odQ5TxdgVC917kK0uM5ZEvTHFioFflIpca710grdB3zQVqzQVZn5NjeZi7wnZXR4Bqc2szPXFJlqTANo2/BTVA1STKsV40Qq4/xfUfpaPBgB4U9FTV+ynWx0t2pw== 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=bY1L50c0WxQg8MOFHr+tzQWs7PqGLtUwBGPdUbzW1vU=; b=gTEBbA4ZVr8s9DUJD0+fYE71Z/fFcV/OhuxF3Lu0WaGFv+hq+seJ+OH76qdEGTJ8hd81d1ZChtuwEFBP7sUYNErzIktRm0ACiYKOxqydPgO17DLOIckmYdk5fj9dolSYqwMDgfOgXMlSazYS8JO245TtgQc8NGx8zlVGhbtuhv8= Received: from BN9PR03CA0532.namprd03.prod.outlook.com (2603:10b6:408:131::27) by PH7PR12MB7966.namprd12.prod.outlook.com (2603:10b6:510:274::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8093.23; Mon, 28 Oct 2024 05:35:31 +0000 Received: from BL6PEPF0001AB54.namprd02.prod.outlook.com (2603:10b6:408:131:cafe::ae) by BN9PR03CA0532.outlook.office365.com (2603:10b6:408:131::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8093.23 via Frontend Transport; Mon, 28 Oct 2024 05:35:31 +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 BL6PEPF0001AB54.mail.protection.outlook.com (10.167.241.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8114.16 via Frontend Transport; Mon, 28 Oct 2024 05:35: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; Mon, 28 Oct 2024 00:35:27 -0500 From: Nikunj A Dadhania To: , , , , CC: , , , , , , Subject: [PATCH v14 06/13] x86/sev: Prevent GUEST_TSC_FREQ MSR interception for Secure TSC enabled guests Date: Mon, 28 Oct 2024 11:04:24 +0530 Message-ID: <20241028053431.3439593-7-nikunj@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241028053431.3439593-1-nikunj@amd.com> References: <20241028053431.3439593-1-nikunj@amd.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL6PEPF0001AB54:EE_|PH7PR12MB7966:EE_ X-MS-Office365-Filtering-Correlation-Id: a34b1305-ead8-4d9e-93d8-08dcf7125657 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: =?us-ascii?Q?ZvmNsKHPPLu2MACdiePzbolYV10K+JdjUK9SY1J7Ih/4P5UoBxhEAPwTIba5?= =?us-ascii?Q?jQbRPlrNLAHGVfLEjItqaCjo1U/IABb1k8L1m8WvjLdwQOjMx/WN6bH+2LxL?= =?us-ascii?Q?dTueY3epQkzktmeRS4iyONO4CRPWDeYeCXB3MMSGeeucokhcyKjzckLKa1vI?= =?us-ascii?Q?SYVVA5Crf/r4P/BpKjyZTj4j1IEk/yw2KD70c5GZeG9BWUZtRFqpqt4n2s1g?= =?us-ascii?Q?+toRONcEGCG5N6n5x8UwJHet2bgGFAb5/p18eCylLphAhLd7KNujqaUEyV5e?= =?us-ascii?Q?7oqbnmAI13h2YOw8uf++s7NFgKJwOYFUPVVQ4NmHGFeojSlWXglxgAOE0+iT?= =?us-ascii?Q?VVe4RVWSn76NNCVcClzyUPhKTK850ROwZvyWA5OSfa2yuVEAU5/OVCtEtkX2?= =?us-ascii?Q?Ax7ZQORCRTrDOYMqSAatdnNO/b53L01BI4ybKMG8BrOHl1V5ffdBR7jKGFNp?= =?us-ascii?Q?6uJ5xWESAzBmnFfPBkjJdxW/7fjh3VFPlst1kjD7NWdN3walEF8Z1I1AsKfv?= =?us-ascii?Q?sjJ4EBvS+6JXfNuY+Hh/XvZo7DkPzrf3rnx/flpHE3XMMmeNffFSY0+uRSO8?= =?us-ascii?Q?o2Gak807aFPq+BtGvS/zjQiFoXCZD/SQh5MQQ7ew/7PECTmKFiDHIZtfBdQ/?= =?us-ascii?Q?KOVoq5cMlanxxNvl7rbwSD4SKoYTSXawXlJlgp6raUOefE24Y9MwnkfhxZbG?= =?us-ascii?Q?Ks2XnxlHMuZspJ+S16OGwXZSAcGPVR452EzL7JS9GW+V/YqSV+Ws8w6WOUGz?= =?us-ascii?Q?TRXkRJg5RqRPyz+OSK3P7aEz+7Q63Np/KPZJKTtiQic5Hli9W2H4XYrcE4jO?= =?us-ascii?Q?aVAwD6fqPe2ZQQJkTbGe7qyoCOcmmBVXFE7KLSSEz2RZ32JTCH5OJDe7N2Ub?= =?us-ascii?Q?3j6yME4ZszDZXBzbRFR+dmctwY9QZh6FSRB5Kucz6dz+dVmH6p9u6z4uEF1g?= =?us-ascii?Q?zQ3IP9GFxCRebmChSdqCA3sCPjWTgIPI6KXEHybk+rNd3/OYV1Fl3b7ld8r2?= =?us-ascii?Q?4J1wzdgQv7ulqdjWk3dMdIRnexxcBX0HxAl0rXCRIBCFvX8Snp5cSYRK6oHY?= =?us-ascii?Q?u3DhJJmsv7ipVRiAimYrg0chAmfg6IKgGsFhRQts0Xneg+nZ3uZVlNro+Etj?= =?us-ascii?Q?Q5bzUP4EdaT6hNO/YCPNtfQdQ9Z9J8DSExtilJuW+x0GgH8dGKVkUJ2mrobK?= =?us-ascii?Q?lUfo0nAw7IvFnmMiMTJMV0d/YbFqlnEVwE9qEbPjNrBrbdYozfI+65JQGTLs?= =?us-ascii?Q?Kibzs74jknlEXHwadzJN4qFlf4KaNyidMaLnuCr6SUUhELBeZKpJZW4poGQ5?= =?us-ascii?Q?P9c86YVjhpDkxyMQMFjpxmFEkFcXIIGr7jDxi1pn4Y7toQUp+4SGeMYsm9eH?= =?us-ascii?Q?8xN/JAT5PiSKQaiPDGt0LJbZSJQtTUUP12I0Mn/5Go2mtfYTqw=3D=3D?= 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: 28 Oct 2024 05:35:30.9038 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a34b1305-ead8-4d9e-93d8-08dcf7125657 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: BL6PEPF0001AB54.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB7966 Content-Type: text/plain; charset="utf-8" The hypervisor should not be intercepting GUEST_TSC_FREQ MSR(0xcOO10134) when Secure TSC is enabled. A #VC exception will be generated if the GUEST_TSC_FREQ MSR is being intercepted. If this should occur and SecureTSC is enabled, terminate guest execution. Signed-off-by: Nikunj A Dadhania Reviewed-by: Tom Lendacky --- arch/x86/include/asm/msr-index.h | 1 + arch/x86/coco/sev/core.c | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/arch/x86/include/asm/msr-index.h b/arch/x86/include/asm/msr-in= dex.h index 3ae84c3b8e6d..233be13cc21f 100644 --- a/arch/x86/include/asm/msr-index.h +++ b/arch/x86/include/asm/msr-index.h @@ -608,6 +608,7 @@ #define MSR_AMD_PERF_CTL 0xc0010062 #define MSR_AMD_PERF_STATUS 0xc0010063 #define MSR_AMD_PSTATE_DEF_BASE 0xc0010064 +#define MSR_AMD64_GUEST_TSC_FREQ 0xc0010134 #define MSR_AMD64_OSVW_ID_LENGTH 0xc0010140 #define MSR_AMD64_OSVW_STATUS 0xc0010141 #define MSR_AMD_PPIN_CTL 0xc00102f0 diff --git a/arch/x86/coco/sev/core.c b/arch/x86/coco/sev/core.c index 585022b26028..140759fafe0c 100644 --- a/arch/x86/coco/sev/core.c +++ b/arch/x86/coco/sev/core.c @@ -1332,6 +1332,14 @@ static enum es_result vc_handle_msr(struct ghcb *ghc= b, struct es_em_ctxt *ctxt) return ES_OK; } =20 + /* + * GUEST_TSC_FREQ should not be intercepted when Secure TSC is + * enabled. Terminate the SNP guest when the interception is enabled. + */ + if (regs->cx =3D=3D MSR_AMD64_GUEST_TSC_FREQ && (sev_status & MSR_AMD64_S= NP_SECURE_TSC)) + return ES_VMM_ERROR; + + ghcb_set_rcx(ghcb, regs->cx); if (exit_info_1) { ghcb_set_rax(ghcb, regs->ax); --=20 2.34.1 From nobody Mon Nov 25 11:40:33 2024 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2059.outbound.protection.outlook.com [40.107.92.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 33394192D70; Mon, 28 Oct 2024 05:35:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.92.59 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730093740; cv=fail; b=bwh9tlaAJiSM31PafYQ2bt76imh0O32xFIfqf2HHv1qH7567qADZmXDyEdLKbj894kOP7s4WeTLiQM445pYWv5RjAg4iunb6ohFU68sb7/lNDSPJ89p+e/j67ZFcyxl81ZQAKaVO+fhHEp5oucHZqgVHgA7PSOY4pzCKzaAl8lY= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730093740; c=relaxed/simple; bh=wTiiW3zg+ZEXEs6HyoUwSSwd2a1sEJVoTxWCh49OUQg=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=OiIBGHE3XNBy4O3iJFpdYUI8L2Az2gl8BCELqniJv1+oCogy9jcLnmn/eGt0vjqFhY7POBZHXISOxqoATEz6eP9Z0WQo6+5EwA58N10kOOyu9sVFNAdrMKROMz09ZmwPA1A1NWEE9Uf0HYE+OwbCS/7DJcV/s0hXDu1HuefOIHM= 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=2uwhUj/7; arc=fail smtp.client-ip=40.107.92.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="2uwhUj/7" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=WHS1a4FRDGp0VZZ5iW8sKp8sErYr6CQV3QNLUb4TdZSXWaWdBh0HJ4rxIhvk3bvAtpUyQZ++pHggMBFv5UrXnE7QZIs7cpz18z76qKN6kHZOnInNfgFp96tuAR2pts/fc6v6TdsmGzDNBIBavtwIMSJIxZNb/Vh2YDy6TsyYtRTcA0cSZAWywfEftl69AH64pVdHTf3roi57Rg04FG1RpzH63SHiskxEXyhVAGYeo2yNED4E4YezkjumbXVEQA8U/DtrzOyY5okY38sBb6ILydwDRWFSXqLf8ob0wl28uCOgy8FFWUrcyYKmiCNNVMtCnGiMDnNpu0w7iLniz9Ejlg== 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=gJbrswFKIOzOu5VNK+d/iLVqlwq3bvmZy+UUG5Gjm70=; b=x89xhI/FaSi6kIEnG0iwt75YtB/frn5AhrUPhSnu0AYLi8CE6M3BLDBYSbLyCWNJMEZm7EIrLya7wZm1Bss3wGRD0tVs5l7nZ+lkWGLmz07ZBjY4fovHAo3QvWHaqQUZBvCGMmS+7EEfgbSQvqzQPT99E9qG63XIqgsk+zmgY7lGocYl/stsKsHTPXDphzNPyUtinv0F8FuBxlzyGgP94FteGscSMbpWceh6R3PcgBsfGJyVoX4QLVu/xfdRA/3ZQTDDDVUKQZrT9bOZkMJIStW5+xhe/CObJBF82RvBdgo3vDNalztI4E0BCGvVRfrTECK6zRg2KFXxKJzHYjGKPA== 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=gJbrswFKIOzOu5VNK+d/iLVqlwq3bvmZy+UUG5Gjm70=; b=2uwhUj/7Ku/+2j6eYnbVNmMBI3G/TduYKaHHmId7I4AvlzbDBOGy/s4W2HByaBjhwCfd8TRIYdNUn9Ydfd2hgRWvfuzAAHGqyydWVN9pC4rfFkaRB3nWk+oKoS9Quk7XMvl9U3BFSBOlRxPnxS8HErLVd4nlFrXmTmLdE6DMLa0= Received: from BN9PR03CA0518.namprd03.prod.outlook.com (2603:10b6:408:131::13) by MN0PR12MB5907.namprd12.prod.outlook.com (2603:10b6:208:37b::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8093.25; Mon, 28 Oct 2024 05:35:34 +0000 Received: from BL6PEPF0001AB54.namprd02.prod.outlook.com (2603:10b6:408:131:cafe::84) by BN9PR03CA0518.outlook.office365.com (2603:10b6:408:131::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8093.23 via Frontend Transport; Mon, 28 Oct 2024 05:35:34 +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 BL6PEPF0001AB54.mail.protection.outlook.com (10.167.241.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8114.16 via Frontend Transport; Mon, 28 Oct 2024 05:35:34 +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; Mon, 28 Oct 2024 00:35:30 -0500 From: Nikunj A Dadhania To: , , , , CC: , , , , , , Subject: [PATCH v14 07/13] x86/sev: Mark Secure TSC as reliable clocksource Date: Mon, 28 Oct 2024 11:04:25 +0530 Message-ID: <20241028053431.3439593-8-nikunj@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241028053431.3439593-1-nikunj@amd.com> References: <20241028053431.3439593-1-nikunj@amd.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL6PEPF0001AB54:EE_|MN0PR12MB5907:EE_ X-MS-Office365-Filtering-Correlation-Id: df5a1d38-6252-40bf-dedd-08dcf7125887 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|376014|7416014|82310400026|1800799024; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?mu/eT0MXqHu7yr3w09rZxU29thKKjHxWX0HIg6C6OPi6msNCQH0bCW4EUV+q?= =?us-ascii?Q?6wHmMPMUSvvc6YL2dHcvwNPwrRQlKuXisXflTQZvXJy9fAO2JfUgPq3y6OTv?= =?us-ascii?Q?yjMPLLEcPjG5rj3MQyNwNxj5NfrDP1f1BUR4oF+KFxr+crjsaBs5gzBSTIld?= =?us-ascii?Q?kTUmaOeaUM/5dXsUoaIIdsckwl/8aeDWxjEYDoYd+eBQKvx9buXPx4cJdGST?= =?us-ascii?Q?6l6KwqE0O3tLSjkDOBsjNlQAcAm0aXomyrrf0gARknUhnzkpxwmJTdtho3L7?= =?us-ascii?Q?mOk8aIox+ixAUVCUF/am3eTvjeqJVD0lkDBNWiLAED7s0vg6rf4RGF0BbutP?= =?us-ascii?Q?nkCdQX7V4ApvPnwhZkDkIzXjdR1V3EpGHsmBUUSifVSf1uxnWsr33XyG+a6G?= =?us-ascii?Q?TDzqLiBvLNjMeVMcBjXN3uOTVq7ieopHu1JkTHC1ZUNFg/x1CKKIm5rEWmeG?= =?us-ascii?Q?HO1n7p/6peCXyMQ5vdS15er6FvkcLhcleQwfsCSQQjbnbWv04YRr8dBCYtVP?= =?us-ascii?Q?onUijuaFOdtbqVVnFlr9Cj1CF4UiRi/wojO/5plDdQXCYh6GBi6BLYTmEDUA?= =?us-ascii?Q?OapABcxwmh0laY2REItXOkV9s8kR55tTS/Tkrt+MUOGMjFVAk31VMcXGq1fn?= =?us-ascii?Q?CyOfGFNYfh+kyBMwR2uoBDbbQB8NANety6W4qymj1zBpevhtfPEJybu8Xnve?= =?us-ascii?Q?GS+O6VXcql2yA3uCYChEp0r6DezfWLSJOnsu27Ow8hAifHQUcr5RLVaGxY6a?= =?us-ascii?Q?App5UswioNn7NTcESel+lnRCf1kcKVY4Mmum1f1V7NiF3eizWJlGChDTzaoh?= =?us-ascii?Q?0J+rzWVXAnEE+PGpfUZQEeoW/RQHxYsMvV6qiYXzGdM7qkLiq2razdOij1BC?= =?us-ascii?Q?4eftAipRCSgxeRzTOxHNE1l6p5ZQzZsQVmtQ3rg1j9E8OL3v0zCSNXjfHEP+?= =?us-ascii?Q?7yjtPkUIu2cwvmto08r2Icpz+aKoDqu5WFgp/bx+M13vSlfSetPEee4QzjDj?= =?us-ascii?Q?3JByZfrrJ8SEsjsa9B34h4QOgUMZc6jxg+W6opvlKkksCVFJfHCBOKBX/8cf?= =?us-ascii?Q?DqS8qW8IZ5JmsOeowAno9w51EPAZ8FvquYaMKcvXTY/A+u2wIYjcPwH2Pg/C?= =?us-ascii?Q?NwhhZXupS1GNsLRwGr+CaxaOh4eZq2GsyvqAhZ+oeUtPPcx2fvz6lhOMCUQH?= =?us-ascii?Q?UN2EzdmYz9G0v+LmiGJAFJ6YygfRdIqooKU7uCF42m4nTsJDOqBtffEEUEzK?= =?us-ascii?Q?MA8zNupGPHWcxI1XM51BlXbjw3S4ZHOSM8jOn7YmE0zbySOBvKoAXi2BiGqq?= =?us-ascii?Q?78UIvbbLOWHlyE1TcQTU30rtQJiYem78w/bLpy7AjWVxJ0MMq/UEm3DTlBV1?= =?us-ascii?Q?dWEu4o0XPT4PNg+MjRuxv7v3b+wXp/TWSbGyvlGGSW4PLkUjCQ=3D=3D?= 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)(82310400026)(1800799024);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Oct 2024 05:35:34.5757 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: df5a1d38-6252-40bf-dedd-08dcf7125887 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: BL6PEPF0001AB54.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN0PR12MB5907 Content-Type: text/plain; charset="utf-8" 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); } =20 void __init mem_encrypt_free_decrypted_mem(void) --=20 2.34.1 From nobody Mon Nov 25 11:40:33 2024 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2051.outbound.protection.outlook.com [40.107.94.51]) (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 A6D4D1BDAA2; Mon, 28 Oct 2024 05:35:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.94.51 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730093743; cv=fail; b=lNDkQHJCKImB5nQr1vHvrifrVRRVH1Gn8tTfuMmYVbK+62UL+LeVbtV1MONiJuQT/0Rv0GvzQMoWHmBZ60cCc6YYA3KvdAJSz36e8em6JLiUblSo3jGhbdGF5RYqVO7XcNoe9uYk1IiIWtNguzuxHt7U7524mD8E3t9pUR5mQok= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730093743; c=relaxed/simple; bh=OB/6ASxdYsnfcl4J0jmZ0yh5aIWCHB0Fx5bvb3/XE7g=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=gKJ1F7uvHYVp6mulVJeV6InJat4rabOkdDYrvdoP1l12ANmbJMbxf+AkYO0kLMBGExpEUQoMVPvj9vOCohNR65+c/h0qZacU5+QfjezGKIh0olNcCoJAhx2nj1+Gy5WKnUxGD4IWfiZBxgV7DzoufV7ieLYYS0nXt7q99F7Uw7I= 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=khe6fsla; arc=fail smtp.client-ip=40.107.94.51 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="khe6fsla" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=wmAJcAXo1TEVVR9q7ZKMKxky6fU1R8pXx0dBDNcsJ1xldkZXbmJpahrxTT7cKXfiQxAhft+h+CW7opEPA6eG3dPrtIqC1vScdC/amTfc07xT0jY2rbKMxtnRloRKjHcE0a3vVoIUQQKHkeZPU5av56nDQu6WskBGirmLVZhoYZUIEyZUTZJGiIHI98Yj7FC1xP9khSkCoYCb2pNdrxOo0BNITgMJydUOFpG8ykF4oohiVDDRh9EbJUQOIu6Cj7hBJFHyMFcEnM0rkBDFbN2ZYDbhO/ibCo4YW49WG0BMIH3FF3STFlcUSP7qovZe03VSPJeuZWnsJDKCFbUdLNH0XA== 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=sYYQW7AgR12vwgxAo6ihnztYZVBXhW9FEUsl9seDdjA=; b=GFuEeF+fmXvKiSe2YqwyuTqnzlxd2GCJx4b/DiBBVLNHFRHQ9eJpuL36PxtaO8NGxP0TdRalgTduArzOn291Zo3F72fDa+TyqUP5C63zPCgQBChDEYjj/T1y5sRL+0YK1Nwx7s1Xs4VItAXAF2ZjqYlFJ0pef4kVSlaTShiNea9+leUyuj+La5fA80Z9T0NPZNRsqzEIGKaYHbDHo2IDxS4/VJmGyHiNciNz949AX7dxP9OgZj+76JoWXUm4qgFJTXXw6iG+aA0oqlyiACwmwfVsCi2uIfsPAKQezmd6kliJ8E73nIor4j3FYq4RsjTZPQgmk0PppGS38GrSoq9oVA== 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=sYYQW7AgR12vwgxAo6ihnztYZVBXhW9FEUsl9seDdjA=; b=khe6fsla37nlgYCZ/v7n12rfB9RBLnySUxZIvgT/pqwbt2H402VLwUYCO2HN1cWhCHJ6f+Qyx1i0GpCfJkSFGht4FAKAh6R+5IoAQi2bOXxElleOnhbQobls8SO8Qo8jxUaiSYOm1080zWZGrD4mo09ZArjDXktvxeXvge6vkNA= Received: from BN9PR03CA0952.namprd03.prod.outlook.com (2603:10b6:408:108::27) by DM3PR12MB9286.namprd12.prod.outlook.com (2603:10b6:8:1ae::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8093.24; Mon, 28 Oct 2024 05:35:38 +0000 Received: from BL6PEPF0001AB53.namprd02.prod.outlook.com (2603:10b6:408:108:cafe::84) by BN9PR03CA0952.outlook.office365.com (2603:10b6:408:108::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8093.23 via Frontend Transport; Mon, 28 Oct 2024 05:35:38 +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 BL6PEPF0001AB53.mail.protection.outlook.com (10.167.241.5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8114.16 via Frontend Transport; Mon, 28 Oct 2024 05:35:38 +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; Mon, 28 Oct 2024 00:35:34 -0500 From: Nikunj A Dadhania To: , , , , CC: , , , , , , Subject: [PATCH v14 08/13] x86/cpu/amd: Do not print FW_BUG for Secure TSC Date: Mon, 28 Oct 2024 11:04:26 +0530 Message-ID: <20241028053431.3439593-9-nikunj@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241028053431.3439593-1-nikunj@amd.com> References: <20241028053431.3439593-1-nikunj@amd.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL6PEPF0001AB53:EE_|DM3PR12MB9286:EE_ X-MS-Office365-Filtering-Correlation-Id: d92c094a-c9ef-4313-bf40-08dcf7125a95 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|376014|7416014|36860700013|82310400026; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?HkjypUuIHZeaiu0ouLUADoOH69fm5x+HDwVJkQmaf64g/2cceFuiC3x+fXLO?= =?us-ascii?Q?h6AgCa5sFyYfXAGYHEjArA1vNMp15WdOasSru+FU0WZKapWYCWSivQIsXNQI?= =?us-ascii?Q?tBTNS2AF5v8qmNuoxhlqiOwyJaBbmG0IAEx+vsMgc990hzjUDM11xFpWdyQq?= =?us-ascii?Q?yEyH74RIAmc5SIXzprNk4zmMHVyhCcvz3cCL1gF9YytLMN1mANBuL1kTTN7y?= =?us-ascii?Q?0LSfd9B/j1Pa/UUXihuQOr1fHoQCaONxW0FS69gB0a7K+ORb4Cpn5kDEM35w?= =?us-ascii?Q?pH6WEfuSmsEfriVoPpGzMaq7l2221GeYvuYWcoECdLM9HiAdJIamWkJuqmir?= =?us-ascii?Q?/LSPG8kLOrO82amNS8cVfIH6QFrOlrSfPjM6FTCRM5s5neSWzchrzlRLlYMZ?= =?us-ascii?Q?77iymLdoIsecQhyUrde9QvwWLqjICI205JjfpQyRA+Pc+WVfURANT7QNhjdz?= =?us-ascii?Q?HMR+AWs9oXxmijRDXEsjnhzAy0mAd8odTiAjmQz+/Bj792T2z9cU9OyibtYk?= =?us-ascii?Q?G1LGaXmHt83ENplgfU4TO8Z85jScz6FAXynB2frzCNmsV5arMS4oV2VWh021?= =?us-ascii?Q?ZiK605pjA6EPy5YsKeU13Qysj26EGL6CFKURlWjAPWSSgvxM3cP3xNKIf8ev?= =?us-ascii?Q?0N5g3Fy+4cTTUSAsh6JecOFFXC321r8UFlp7+5jTMdY3kS5/fE8ruKKsDL9w?= =?us-ascii?Q?a6z9TVTan+V6VuVKPUhEEfAMTrjGC/ryHQ+yRSG02sviJDk/MhbGVw75ugDU?= =?us-ascii?Q?TJ1zCoQ3L09jLBN7vgwpjq9We2p7a/NhD96jZL5gMAJAZ9v8/oqBZf7g72Qf?= =?us-ascii?Q?oNzUP7e+M13iqoLgzR6nhyqUdwxXu59mUNh15r82mFaWssPWoidOYTYYKmXI?= =?us-ascii?Q?Kl1i5cszGfFipPzzh2lHyg0PApkVCgHFxf5GNLpgJiGGHr8DsCQi7tZObmSY?= =?us-ascii?Q?I/2dU3mQiGaaF+FTT58mQReSBEewH9eU3psIv3e0J7uetUMXDlGxRGjhMSNc?= =?us-ascii?Q?LLFuBreZfS0ZTAn6fVT9gLBWGqlrlsGJed+xKa4fFQCYT/CCGD6HxEyYrW/B?= =?us-ascii?Q?nNfHTbTYPUPfhL0aRcFwcxdz7JgtdHrJAoj9tVKsumwP7EMe1VEDbMSn4htk?= =?us-ascii?Q?AFGJuNwQyKNK1QpHnJTmZCrtt5rGkGxnSAYaTj54goJrnf41aPe8iude4lQk?= =?us-ascii?Q?VQGiB6H+BCgYnxNz54igMn7TUU/D9v1HnptwjwuDaAtl7HneQOI29SiBYBK5?= =?us-ascii?Q?0BbcdPOt62GTRWLyepAB9i6NTMGP+7M4/il0SekcSSvExMWHWle1IIKmljsf?= =?us-ascii?Q?S/4C6B3+53eU3uUn6uD3nLulDUZ12GvxVmKbG0gRUC+tlPjUK2+yTFOzdWue?= =?us-ascii?Q?PhT3n5wdIeS5EU+gmj0RjgHULVCmKBiRoIYM59OKO7+au9Ja9g=3D=3D?= 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)(376014)(7416014)(36860700013)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Oct 2024 05:35:38.0378 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d92c094a-c9ef-4313-bf40-08dcf7125a95 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: BL6PEPF0001AB53.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM3PR12MB9286 Content-Type: text/plain; charset="utf-8" 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 015971adadfc..4769c10cba04 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) =20 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_SNP_SECURE_TSC)) { =20 if (c->x86 > 0x10 || (c->x86 =3D=3D 0x10 && c->x86_model >=3D 0x2)) { --=20 2.34.1 From nobody Mon Nov 25 11:40:33 2024 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2057.outbound.protection.outlook.com [40.107.94.57]) (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 869AB1CF2AE; Mon, 28 Oct 2024 05:35:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.94.57 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730093750; cv=fail; b=FwFsHgFnc8N6pe7L/3BTsejbq4/dExXDUhR9hoEjGRmnXLkUsWaPknByC6RGpQsMWC4o8dLfeqQXxx5lKEzFeveTVTRSwx4Cfl7aMVHIdK8aM9cWL/9sx1hoIKz2DuSqr00CsUlzNMt/VP7j+ZrdOr7tjywvfY51Hc5DG8MyFWA= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730093750; c=relaxed/simple; bh=KcuVe6tvnsfd+IKKQi4vkI1D0HN4ZCzvsoAIWepPZoI=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=id9ofhoXxBjy/x8oFJSvxJf2r4UUhICLGLmFNqQyj0BuIKCJn8zdAMV+pQFsa/YmHacOU1KCMiuJnoD5fTSSiwmJPB2RPL7607akg6X2CwOrqod1EBWzvopXG9ETIgfM2nHDFxgX8TxNyZ44LsFZv56zwOr4/IRu2sdRTUOc07Y= 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=N7SfWOA0; arc=fail smtp.client-ip=40.107.94.57 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="N7SfWOA0" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=OVC25jDXFs1xp3s/o4WqOeaw70f+3D3lMtxd07a70WNSre+90IzYSGSugy2ijBRQpLmYnWohNwZ0snsg6bxk/HqOgQG7NcsQHdyJpREq2UNhWZAJlb+FRgEqhFZcgwapcHXuP2RnJg5usVW6kyzX9NUbQ8ZB8r0lVElJR87NWuBnJJJrfgpw1IM8WU/sw19pgK/pV4Ny0ZJf65LC1aD3v53/zrp5++o77RSTRdOgosb5wSK1ZAEyEuVkP6BbuW9PaBJhfd7anlDfNiG6h/jOZqW0Q/yDsoECIQqRF3mBLGcQeNH0r9ZJtselBClnu579jRp2vg6zyMKs4mHM0wJfvg== 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=U3brF1Z3m8W78VNKIzQdWgsHj8gOmkzBWQuD+SmGK3g=; b=LYgsJAI9iG7ncnhJNg44V1uZrwO+OiM1z21RYG4R4/9U+MUMfzdEeu6pbXgziUia9/cZsgBhoXKvuk6fRNj02nyM3Cv7ew/BysomnaZ6P5t6C6xRJUZYH/sWHGUxdbaTBDrie496WlEpSBAR5/4xRzULgWgA5zA581oZ1bMJyUZ0wEdgJ15bo7UCmlOfqICfkIjgaqniWwpL0n4eF++8xgoE5Cd4ZSfGtf0xQyrgEwsZ+u230noOnF9q5C5gvIRr1EwzuJelCputpqgg+mJjVNUqoh8KTqj3hb8RNCIbfHlseozOodJwwvLvbxqIVR1bFemUss1H9KTTsU3qCU01Og== 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=U3brF1Z3m8W78VNKIzQdWgsHj8gOmkzBWQuD+SmGK3g=; b=N7SfWOA08SXNpTVnvVApGkl820o6X/2E8gQwRdE9XOh2BMb/rHBTx6aDP8MX+/ccJe3MTy8+iKB9Dz7VoF5E2gSUaJb4KOyT7TIvVCP0ma+WNCo6yzVhRZI6fDagOnNAmWmNhicwLn2v6OY+1dj9+V7olfbguVZGMSPu3wipWPA= Received: from BN1PR14CA0005.namprd14.prod.outlook.com (2603:10b6:408:e3::10) by SA1PR12MB8117.namprd12.prod.outlook.com (2603:10b6:806:334::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8093.25; Mon, 28 Oct 2024 05:35:42 +0000 Received: from BL6PEPF0001AB58.namprd02.prod.outlook.com (2603:10b6:408:e3:cafe::39) by BN1PR14CA0005.outlook.office365.com (2603:10b6:408:e3::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8093.25 via Frontend Transport; Mon, 28 Oct 2024 05:35: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 BL6PEPF0001AB58.mail.protection.outlook.com (10.167.241.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8114.16 via Frontend Transport; Mon, 28 Oct 2024 05:35: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; Mon, 28 Oct 2024 00:35:37 -0500 From: Nikunj A Dadhania To: , , , , CC: , , , , , , Subject: [PATCH v14 09/13] tsc: Use the GUEST_TSC_FREQ MSR for discovering TSC frequency Date: Mon, 28 Oct 2024 11:04:27 +0530 Message-ID: <20241028053431.3439593-10-nikunj@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241028053431.3439593-1-nikunj@amd.com> References: <20241028053431.3439593-1-nikunj@amd.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL6PEPF0001AB58:EE_|SA1PR12MB8117:EE_ X-MS-Office365-Filtering-Correlation-Id: adb7418b-a61a-4fef-6817-08dcf7125cc5 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|7416014|1800799024|82310400026|36860700013; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?LbjwYDY9OnarOQIESl6sB2nUCmQ2yzop3cpx50O/m0sSapaiedQAJ/9n45lG?= =?us-ascii?Q?dGsgAd51OdOKLZ0/c8eXQ9wXdkPfJgonZt5himbm8tofP88E21O9IvAznwUo?= =?us-ascii?Q?w2KIBof0zkSS6SRyZsOxJ46BWk/d+v8g0Z4fZaVtLT8ycvFjeNBiwJ0dm71d?= =?us-ascii?Q?6070PREp9Z6lZ0g3Kx46JgSuX0S6SxrHqjPLKXC8hx1rjn0CXWl0yb+EWNsm?= =?us-ascii?Q?FYyZLDAz0xPp90GnFZpDyXvxmjp1pAnMoFJV2gh1vWXjuXedSmEAGBM7aZ/Y?= =?us-ascii?Q?l7zU/WH8nVqe+iHODQMe19hRWLn8c1yzKJMt2kK6hOcSTNU4Rz+kiTa9OSBa?= =?us-ascii?Q?0hTtYp2gQOUGUQQNjWbtK/nVj4eUTUdKv9aRrgCKED+Rz4rqA1e9YWKrrXIA?= =?us-ascii?Q?1xBJsS7cfZtEYp5nfv8i01nH74lsxfwovI9leutzcI1xfQT+XHOmdK7FGRED?= =?us-ascii?Q?sPXtTCLyNuXTqGRNMzHDOqaIoIJM/4jKqXM+WSOGPbydeSi8SFLt2xadIACH?= =?us-ascii?Q?OrasKRDhY5/rGkrGbniTron6mS04eGPpPZfOaa34UtIe0fPil1DhD1Fx87Xa?= =?us-ascii?Q?uwFWrBWOvJBX4Ck162z3hvxRXoXxuQFTeZVIGXr3oxVUQg/97r8TZuwYM41V?= =?us-ascii?Q?3G+LezTk5YOoy2B54Mc2yY/M0wdFyR0G3bKFPCPgHraHBmg+YEvvKSDBneVx?= =?us-ascii?Q?JAtjZLmP0r2Ovh4u8fXgeMfOlFhBg+Gb5TEm/r9dezNC4iCmiAFNpcDryLJH?= =?us-ascii?Q?fRx6ocROgYH1DgA3JkrF+RjUTNX/pge6pTLrlNl/Bkc5F9yAvM3Xk9MPZcax?= =?us-ascii?Q?DMEtiiadUG8QGEAbmgJYB9axWcHgWyaJpKUi/UhVz2yUYebCujU6bRclNwVQ?= =?us-ascii?Q?OZNrA/Ms7ngdq0ba2LFKARXJxFuq+VnnC49XkNKLOkxWElg9uxjLREaJJdtO?= =?us-ascii?Q?474b1zZIM8egTicxZjtJTrbOi3gzyGbCM3eUgwat1IkPG0xU5n368arGTTl6?= =?us-ascii?Q?oYwbWOjHatR461J4jCTC3DHPIeQYiPZ3y6/rXXFfoSn7+sajQROogj1fef5c?= =?us-ascii?Q?+Mmir7xPywFGsh4S88vJDJpVcdIFJdSOwmKbkPHahV/CYYufAq7VUMm2m2yV?= =?us-ascii?Q?WNTDpn9NxQUFTB2zjcV9LhsOKh5vjq8/bzH8VjJRu72I+SV8s3vfbEVvAZeR?= =?us-ascii?Q?K051gUHeIsrnW40/Pj4zw/4XfA7ZoNbGVfkmpLchSqSz0oFmxP8LUmms0G5J?= =?us-ascii?Q?Zji74RSKmqVuXUW7Ougfb9gd8uzMq3WDvUU8PJDGTDxvPk3q86v3sJ8rTZ7u?= =?us-ascii?Q?+2KB38jeEMAZFpqXokEHJNvPZBiBGR7Ci4II1B1gBIlgbW+iLdvWBn8mIITD?= =?us-ascii?Q?/pxifS+jMDYwf/ij3gisM9X+ftA8BjYXzxUIuO5Qe/ACSI+dYg=3D=3D?= 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)(7416014)(1800799024)(82310400026)(36860700013);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Oct 2024 05:35:41.7055 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: adb7418b-a61a-4fef-6817-08dcf7125cc5 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: BL6PEPF0001AB58.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR12MB8117 Content-Type: text/plain; charset="utf-8" Calibrating the TSC frequency using the kvmclock is not correct for SecureTSC enabled guests. Use the platform provided TSC frequency via the GUEST_TSC_FREQ MSR (C001_0134h). Signed-off-by: Nikunj A Dadhania --- arch/x86/include/asm/sev.h | 2 ++ arch/x86/coco/sev/core.c | 16 ++++++++++++++++ arch/x86/kernel/tsc.c | 5 +++++ 3 files changed, 23 insertions(+) diff --git a/arch/x86/include/asm/sev.h b/arch/x86/include/asm/sev.h index d27c4e0f9f57..9ee63ddd0d90 100644 --- a/arch/x86/include/asm/sev.h +++ b/arch/x86/include/asm/sev.h @@ -536,6 +536,7 @@ static inline int handle_guest_request(struct snp_msg_d= esc *mdesc, u64 exit_code } =20 void __init snp_secure_tsc_prepare(void); +void __init snp_secure_tsc_init(void); =20 #else /* !CONFIG_AMD_MEM_ENCRYPT */ =20 @@ -584,6 +585,7 @@ static inline int handle_guest_request(struct snp_msg_d= esc *mdesc, u64 exit_code u32 resp_sz) { return -ENODEV; } =20 static inline void __init snp_secure_tsc_prepare(void) { } +static inline void __init snp_secure_tsc_init(void) { } =20 #endif /* CONFIG_AMD_MEM_ENCRYPT */ =20 diff --git a/arch/x86/coco/sev/core.c b/arch/x86/coco/sev/core.c index 140759fafe0c..0be9496b8dea 100644 --- a/arch/x86/coco/sev/core.c +++ b/arch/x86/coco/sev/core.c @@ -3064,3 +3064,19 @@ void __init snp_secure_tsc_prepare(void) =20 pr_debug("SecureTSC enabled"); } + +static unsigned long securetsc_get_tsc_khz(void) +{ + unsigned long long tsc_freq_mhz; + + setup_force_cpu_cap(X86_FEATURE_TSC_KNOWN_FREQ); + rdmsrl(MSR_AMD64_GUEST_TSC_FREQ, tsc_freq_mhz); + + return (unsigned long)(tsc_freq_mhz * 1000); +} + +void __init snp_secure_tsc_init(void) +{ + x86_platform.calibrate_cpu =3D securetsc_get_tsc_khz; + x86_platform.calibrate_tsc =3D securetsc_get_tsc_khz; +} diff --git a/arch/x86/kernel/tsc.c b/arch/x86/kernel/tsc.c index dfe6847fd99e..730cbbd4554e 100644 --- a/arch/x86/kernel/tsc.c +++ b/arch/x86/kernel/tsc.c @@ -30,6 +30,7 @@ #include #include #include +#include =20 unsigned int __read_mostly cpu_khz; /* TSC clocks / usec, not used here */ EXPORT_SYMBOL(cpu_khz); @@ -1514,6 +1515,10 @@ void __init tsc_early_init(void) /* Don't change UV TSC multi-chassis synchronization */ if (is_early_uv_system()) return; + + if (cc_platform_has(CC_ATTR_GUEST_SNP_SECURE_TSC)) + snp_secure_tsc_init(); + if (!determine_cpu_tsc_frequencies(true)) return; tsc_enable_sched_clock(); --=20 2.34.1 From nobody Mon Nov 25 11:40:33 2024 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2071.outbound.protection.outlook.com [40.107.244.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 D28171D1305; Mon, 28 Oct 2024 05:35:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.244.71 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730093753; cv=fail; b=Qx81PZOgckD1tR5s9pSHowkztzoeoxWQBDPRPUgj+k85JJsZOv2DmdmmmhxCPVMz+jNP/d6cApOvDwz07eKmVQpeCdSQmh/PXqBYXPOBMC9PC/vRWET/wb9LAUb73892XXSNP27afHHxAJm1I6AsrSQBe3cW0KBmGuOaoxUDnRk= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730093753; c=relaxed/simple; bh=JVX7OfWm4DeB7mmK9cRP7mo2EX+qQxw5B1sYp5c/VJE=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=T5OTfuzyJ2nseDn6mytRq6vfK9jKJNuCJ8M7e8xDWfbCHHe+LaktdktVTjMkIhDhdB1O3wpB0DnKMXeK3fCcGL/WEHts4frq2cR7P6627klV3MAkA1k/bHI3WwjSGWuNkLPu0RMA8p/EPo671b6YDXn0OLX/V02h8Ck8WjYH2uQ= 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=kBvo6c/N; arc=fail smtp.client-ip=40.107.244.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="kBvo6c/N" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=bvizQ14VpXRXWDEHLx7v3hiY65OZgL8d7ZgepQixd0bYLpvqmenD/cS5siGDNnyj23GDviSRSza0KUboGQqlA8K/+YPj+b5lTePscQ+7DXIKviNi9jFrgUg8EzCEYU5W4xxluE68B6HKgKn/zo0vrw6cS838SY1Lakd0S5XoxBOeztV49wC5uw/Cr8NMrpMmUZ+BKNeuADGlGElph1J0ld6a4U1pZeeHl6bleOGsJgmtp1shdR7UvANhZymoHtwwaSZs81G7GXBjS4t1w8ZHBevx6dj80qD5D01d+uPUOUTziLe12a3p87mmMvrJyjVp4+IadBhqbuCifUy93vKnww== 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=WJhGospZZdvaX4gyCb2Bop62etrYm3d8Va0F14x/EOg=; b=i4TCjKdiDwPGDe8dnwDFjW1UoTmRXDW4pWWIEdg/+5LzYuCb+mjZ4+UsxHD3cnZggdc7hTN19MvjOfHwxt/EDYht2LPA7TLO+OQJ2OTGwaafwccogi3TiBhadbAzP/P9N9IXJVYUswKo7kgiUb3X8p/711w5j5wwZEJHV2hUFyKQbxjQwroUpenNT7SPxc+Py6oTYvP04lRjJPZmyztaGM0VkjCu1OJqLg5RmpVpJm9LEWYtZzepRZjc5undoZb7Avyaw2rZIuB8LIB2okgI506qdm2QVqCXQAYTngTvDClMUggOngOqo8eW5kYZsF++LohFcmmj7lgUUKskGLgg7g== 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=WJhGospZZdvaX4gyCb2Bop62etrYm3d8Va0F14x/EOg=; b=kBvo6c/NPJPh4XrsvyjdZ7hsCbO3Y7PH3ciC2IjDjOx5IV2IaYz83gnoum6rXUxTNZ2i/NDAnfH9GX9iHxiqFhLzAHjDYFjQ9H/fisOj2tw2guBwjhYzlhx9dTilCPT2D+dZ9CB3mZ9qb3uW3G3hu45RTrDettYaS/7uV8LwUww= Received: from SJ0PR03CA0135.namprd03.prod.outlook.com (2603:10b6:a03:33c::20) by CY5PR12MB6177.namprd12.prod.outlook.com (2603:10b6:930:26::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8093.25; Mon, 28 Oct 2024 05:35:49 +0000 Received: from SJ1PEPF00001CE9.namprd03.prod.outlook.com (2603:10b6:a03:33c:cafe::a0) by SJ0PR03CA0135.outlook.office365.com (2603:10b6:a03:33c::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8093.20 via Frontend Transport; Mon, 28 Oct 2024 05:35: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 SJ1PEPF00001CE9.mail.protection.outlook.com (10.167.242.25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8093.14 via Frontend Transport; Mon, 28 Oct 2024 05:35: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; Mon, 28 Oct 2024 00:35:41 -0500 From: Nikunj A Dadhania To: , , , , CC: , , , , , , , Alexey Makhalov , "Juergen Gross" , Boris Ostrovsky Subject: [PATCH v14 10/13] tsc: Upgrade TSC clocksource rating Date: Mon, 28 Oct 2024 11:04:28 +0530 Message-ID: <20241028053431.3439593-11-nikunj@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241028053431.3439593-1-nikunj@amd.com> References: <20241028053431.3439593-1-nikunj@amd.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ1PEPF00001CE9:EE_|CY5PR12MB6177:EE_ X-MS-Office365-Filtering-Correlation-Id: 2d9cc462-70cd-4e65-73d3-08dcf71260e7 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|376014|7416014|36860700013|82310400026; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?Jb2KaZWdEhCAgGPTV5235w/5blLol8zGD81+8Mrkbo1QzZG5voh7nC7AH4R2?= =?us-ascii?Q?7RSWx1F0lRZSfFcMtN9y/qVexQ7PkOhZX12I91rTSFAlrZc0/96Smcd/9DDI?= =?us-ascii?Q?eoWy9mSTiyystg/3q9vPbOI3YvJNPVxcQl/oJ98ycoE0TiZEaltUpiS/VQhG?= =?us-ascii?Q?eN6imMX0Z8XQUsV1gh9fySg4pBnRiTL8LCGVdyER7J21UTtgFhlOv2FvS99Q?= =?us-ascii?Q?QwgSdf9HcO7ggwZREJ56xLoEOGHDMdLaIZRlBO3UQxgbtP8bZAoLh+MZEi0S?= =?us-ascii?Q?/CtcMKgPyl337xHP4wvMghqn5BADdrK17YwtQSmHxXvmH5fNbVxzBU0dCD1u?= =?us-ascii?Q?FeTwX1BctbYAZ/N6BFzkoCb5yEh2Mn/e6EYjpqJVDmXrP/4miaWzY/87ll5d?= =?us-ascii?Q?0TITm5OQfrv9XRu/Cx5T6Z/Rmt35LW/TK8GaxA5VN7RhLz9NgpOKPk8S4XhN?= =?us-ascii?Q?lDhlixjo39Bs4GBJxndtIpdzaOU4B+YC0ogSX89bs0ShPFvuR84XO4ssFDxU?= =?us-ascii?Q?iH4faviWkSvm5C68ZtxYCQBkSvfdfnXhwkHI5fvhNJ64V01ogUToIobkdNFj?= =?us-ascii?Q?FPfyoZ+QTaJwDbfK96BU80a345BQtawqirZSiWs/Drywf41kHtQ8KZkvrnov?= =?us-ascii?Q?8FalgooEE0LsvbfkFkpoDpmboqmeibPPxFHXvIiE0qmosOMYDuKlbZIqbrd/?= =?us-ascii?Q?U5eIuS0+gWczE8R4ON2Qz/jIO0liGlKqtxMTnmJcTRxKaMV6oUN97AuffrGn?= =?us-ascii?Q?Lc5cVIklp2HFzTmc8mpSnJgXk1aLrZyZbepshLUrjgdx9U2TmfMq1DifaMlG?= =?us-ascii?Q?2ZDJIosiPwc4Hh6LgP0++mJipd8hYEVCSGV9NvJnPCDaP5BSIjPWOmhq1izZ?= =?us-ascii?Q?GJxUvqOYjljOkgeQnZSlruVUIjxpoUL6/nw6e5BHGi+26BC7h0mAvg5KbEq9?= =?us-ascii?Q?y/I/7WEtX3zjGef9NEwQ7g1G9By0nX/EXxkB4iyaBZkK59tFwKxld+YfKdJg?= =?us-ascii?Q?f6QBkknoUfnlSytjCmOJEFEU6OZZe70duFqy6UeLi6lLnWeS+WHwaYsYMGYj?= =?us-ascii?Q?/eFFUILzIOgwhJVkl6p2uLfV7BEsN0eKFwMChJzrWaI8EygpKnvCsVcLLhyg?= =?us-ascii?Q?B5GZW7GwrTIdMw3NVb3oOnivfAQ+bs4EG4mCgEMu7miyg02ClouSniAqsrZs?= =?us-ascii?Q?mIQMTG01l6u6y88E0tNEeqdsTkdgVbxJsZr3ypG95s1CF9+276o8ett7Immf?= =?us-ascii?Q?C5yu5iTBy0CpH3KgO+F5pFWigFPiY31AsIjEL2VGkGkNmuxgF+qZ8E8e6VzU?= =?us-ascii?Q?G91cV3VA163CsSBpq4tgxbks8MVkC8ceTHHUD3/cvmiJjPJ2ZEk31sSGXyez?= =?us-ascii?Q?ku/qg23gR9edGd5lEnSibTz4+G6rx8RHdhqdVE8aw7rKtiFiTQ=3D=3D?= 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)(376014)(7416014)(36860700013)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Oct 2024 05:35:48.5302 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2d9cc462-70cd-4e65-73d3-08dcf71260e7 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: SJ1PEPF00001CE9.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY5PR12MB6177 Content-Type: text/plain; charset="utf-8" In virtualized environments running on modern CPUs, the underlying platforms guarantees to have a stable, always running TSC, i.e. that the TSC is a superior timesource as compared to other clock sources (such as kvmclock, HPET, ACPI timer, APIC, etc.). Upgrade the rating of the early and regular clock source to prefer TSC over other clock sources when TSC is invariant, non-stop and stable. Cc: Alexey Makhalov Cc: Juergen Gross Cc: Boris Ostrovsky Suggested-by: Thomas Gleixner Signed-off-by: Nikunj A Dadhania --- arch/x86/kernel/tsc.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/arch/x86/kernel/tsc.c b/arch/x86/kernel/tsc.c index 730cbbd4554e..cf29ede4ee80 100644 --- a/arch/x86/kernel/tsc.c +++ b/arch/x86/kernel/tsc.c @@ -1264,6 +1264,21 @@ static void __init check_system_tsc_reliable(void) tsc_disable_clocksource_watchdog(); } =20 +static void __init upgrade_clock_rating(struct clocksource *tsc_early, + struct clocksource *tsc) +{ + /* + * Upgrade the clock rating for TSC early and regular clocksource when + * the underlying platform provides non-stop, invaraint and stable TSC. + */ + if (boot_cpu_has(X86_FEATURE_CONSTANT_TSC) && + boot_cpu_has(X86_FEATURE_NONSTOP_TSC) && + !tsc_unstable) { + tsc_early->rating =3D 449; + tsc->rating =3D 450; + } +} + /* * Make an educated guess if the TSC is trustworthy and synchronized * over all CPUs. @@ -1565,6 +1580,8 @@ void __init tsc_init(void) if (tsc_clocksource_reliable || no_tsc_watchdog) tsc_disable_clocksource_watchdog(); =20 + upgrade_clock_rating(&clocksource_tsc_early, &clocksource_tsc); + clocksource_register_khz(&clocksource_tsc_early, tsc_khz); detect_art(); } --=20 2.34.1 From nobody Mon Nov 25 11:40:33 2024 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2083.outbound.protection.outlook.com [40.107.94.83]) (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 444F61D2796; Mon, 28 Oct 2024 05:35:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.94.83 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730093756; cv=fail; b=EccitYo+zUtcRxt3Dgl+0lgY/VhSDzg6gn1zqKZcbVBA3NFnI6QKiOhiccLwKOVe58R40IRZFE1HxyjOlJTL42vq/aUOBESq3uflngyWUqokbQ0I1YSrJhsEQXHPJOovb32OM/UMq33ykt4sOtteVBSFX0bawjTGX0wW2CeTwMA= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730093756; c=relaxed/simple; bh=xRjLm55uZZf34G6ds8D/krpLHmfwoDqavN6Bg0q75aI=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Ge41Rs7dCo+nhb6myfVSNvUY0//pqlXcrPTTt0+waSd2T063m7jAOXaMDJKHi2Gjob2gXgGymLL+UkZ/gni0DC8ZWbQ/8FIzmOc9/PBa4/IkSkC6N54CcptgVwmcAPN1lWHN2Lb2/EPbG0gEiyCSr0v7y3FsiHRogZ14FILzIow= 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=wkyhbzzb; arc=fail smtp.client-ip=40.107.94.83 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="wkyhbzzb" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=RxBWfun1C5K3QYxHSmRDLI4zoKfhQCOyCrd41LNKFO+Sn5kMmt4Vko+TuECu9uARDjA7xHvQnPWuOHH7K3T33dOpwE0kvmdnUbCXphVmcbnn9IHzc4cS2tfKKjUeJB78BINNyY2AQbP+4+ZUVB9mB/4qYUP1M8OT9Ikj+1JWm5p92nRpZFVSzsSbMsA5HrnKl6EkjutUzsDKIMKoK2Pt4kRSpJyOSEcUNYsuVclp3wOMl9PTKlTmXiOo0dckr4b/tRNh7GYJjyetjMgGu8fIWo8cLGZ1FApymHbOHGJ8T8IUKqtld3bUt6ZhnIobt/GpaemBCJHWp4xPB9Vf4ShP+A== 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=puOvZD7dMnyP/mSy5fX3y3C0dWkvUQhiYs0GJr6meQc=; b=w7ubDvFJSJa4nRNh/SSjR4sI9NVsUkHhBHLjlz/dWQ2GTJDJK2ngd8GGeN7cuoYE2ZVDmvTQBipHQSDnqI2tsRUTkc0GdqtHBGpNDzs5/XQd8aDFvu8+5u1W4S8OKDrlWCq9TQCkaxwC/kHqLCS7JOiR3lSnIQnBDsbWkIznTwb6/QmJwYy+I8Wp6Zida30M8S4Xt2WozaZHqheg8JSE+4jfZHgD1biErQHkLP80xe1ZAsZPF8YcBsevWj0/+od8zSF8Q4HN2Q0agMXJtmRALFsS8THY8KhCpU2c9fs6xn2Xd3wA5U5aeAmhlX0YnrBtQxl9XdRkGcGltfjHH8UjAg== 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=puOvZD7dMnyP/mSy5fX3y3C0dWkvUQhiYs0GJr6meQc=; b=wkyhbzzb2ThoXvnkmQDLcoCALAG451CbTYXfuIeNHZeB/9ipxeYGvrZauKLVg6G8Ze4imLT9rkbx64puljyf8X+9I7weMyt+5N4w1bSnQnO4IFVknM+oakI4Pq4BCk1NvWeWAMqNcZevBX4yKtrreITA7QcPJkAKEw89Blu85Ak= Received: from SJ0PR13CA0078.namprd13.prod.outlook.com (2603:10b6:a03:2c4::23) by SJ2PR12MB7992.namprd12.prod.outlook.com (2603:10b6:a03:4c3::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8093.25; Mon, 28 Oct 2024 05:35:50 +0000 Received: from SJ1PEPF00001CE7.namprd03.prod.outlook.com (2603:10b6:a03:2c4:cafe::f2) by SJ0PR13CA0078.outlook.office365.com (2603:10b6:a03:2c4::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8114.14 via Frontend Transport; Mon, 28 Oct 2024 05:35:50 +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 SJ1PEPF00001CE7.mail.protection.outlook.com (10.167.242.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8114.16 via Frontend Transport; Mon, 28 Oct 2024 05:35:50 +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; Mon, 28 Oct 2024 00:35:45 -0500 From: Nikunj A Dadhania To: , , , , CC: , , , , , , , Alexey Makhalov , "Juergen Gross" , Boris Ostrovsky Subject: [PATCH v14 11/13] tsc: Switch to native sched clock Date: Mon, 28 Oct 2024 11:04:29 +0530 Message-ID: <20241028053431.3439593-12-nikunj@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241028053431.3439593-1-nikunj@amd.com> References: <20241028053431.3439593-1-nikunj@amd.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ1PEPF00001CE7:EE_|SJ2PR12MB7992:EE_ X-MS-Office365-Filtering-Correlation-Id: 4e117700-9a39-4799-e2c8-08dcf712621c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|7416014|376014|36860700013|82310400026; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?BibSuHp9VLA5N+QT33c5AG8UElOKm10GTdb0ISFTqNI0kOoNEWm2oAElcgrt?= =?us-ascii?Q?uyz4BgaRfDa9yJjeEPTqF5oJ5k+w8LxddOJQUY+xjYRrhHchxibTy7GIgc8j?= =?us-ascii?Q?2h3U2UGZLejuLEeCdFJPQ2MkIPMDc9b6bCTR4Zm4Lj7C2qYBq+A/GdJAhcZt?= =?us-ascii?Q?9j0KXDWzB39Jx6dpNepR/9SgsFv6QG9UzT47a6hcforxTLog0rh6Ty6GPzLm?= =?us-ascii?Q?A+2NcTtlhJ3vBOj0oY+4EgsBIaIDfNRTkL8KHlKrsOAVFw2MDBpSeLn6CLqh?= =?us-ascii?Q?Gm0FD4F7g7d/3C++6A6qtb6z8nkHwSKO1MM8Nt1A7NVxS2AwvV4gmXVLz4rS?= =?us-ascii?Q?yOY1fHrrD63KLpACCHMlPlNcPX8vApHLJd0KAW8AsoBw9Bxl00qQs+PeGitX?= =?us-ascii?Q?NSs4as/9fkmlri/Lt1MfdNVulHWE8yg6leqF3F8K3CHk5VQdHqEIN1rS3lPJ?= =?us-ascii?Q?1WW5NGq6NE/9zeBeLCovr5X8we3CGJi+oz2WjgdM9AmhUFZpH/OuCGTMji7k?= =?us-ascii?Q?zxWxP2b21D9XAg/B1WBDmeu5e9uXoQWIWzI1pktmndSVW0zRHY1OpJDGX3Mj?= =?us-ascii?Q?lfraeGLvYwhv3dVFllUiUv3hEp54uIJOSS3MjTFTUb2Siuo8Ev4yTDDpXL8u?= =?us-ascii?Q?FC/c20xE6DalBV3zDGbHmT6Dl0UqrRxIuoG6w+XY3vrguxg2zT2qJvam7Og1?= =?us-ascii?Q?Lh+D4KtO/z4Mvq/4CsQmpi2dhvkNp1edH3PTJkxCm8Sb47kXf/3dIAMnk0J2?= =?us-ascii?Q?P0HoWNib48lgWqtVzsUG2LraS/Z33fdNvOX3+vfHcR3zfNmdxm9Ha2X1iKa0?= =?us-ascii?Q?wMGf3NxUIwEYPEwcZUrKPA6cm2mn9SJ9pcICW/fWZUt2wSFqdH6XmmxDMRjz?= =?us-ascii?Q?+lgHDptNzf0Aq/zrp1TBWzCkaz+iAxs3sn5eeOlHKdCevYdpzbXaZuFm++NG?= =?us-ascii?Q?aDQLcWs0j8NtlczZOpmk/vsz89MWQJLQnXd711dc7y5CpHwIJ7bw3iwwE16m?= =?us-ascii?Q?+P4XQ1veu7tU1+oAYOKUezmryNOgHAm9YNtjLB/HRibIlSQT814Tz1tNyBnW?= =?us-ascii?Q?ghbTGZnOXu7p7u1vj+EpVhbqJ6ia4NbsuZOoJnFqN+lB6H0JC3h5Gy+rYZqz?= =?us-ascii?Q?B+E2X3vm7YVQeB0+rY66vPU+M0eM/IkX65YoCdIaIIGvkhO00nrtzP+bacdy?= =?us-ascii?Q?+46WojWsFmJEFga/LblIG3zZ++P8rwPIN3xJcLbaNBynCWa81ZZnRXdArgBa?= =?us-ascii?Q?l+DvvXjzxHURSBHReWgOkm2Wuysn1Jah+lA2b0KC3B6UnKqaYjgf+lXWgBp6?= =?us-ascii?Q?+mHzykxHuezNndprsCxXrd3WK1QqzDOQJ04w/cJHHYWVraIsa75ZWlIl0x4f?= =?us-ascii?Q?bpm2P/ZNbbhXZmFv3XoQdtc9Xf2Gn8iW3my0MVpXKN8qI+RGnQ=3D=3D?= 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)(7416014)(376014)(36860700013)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Oct 2024 05:35:50.5737 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 4e117700-9a39-4799-e2c8-08dcf712621c 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: SJ1PEPF00001CE7.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ2PR12MB7992 Content-Type: text/plain; charset="utf-8" Although the kernel switches over to stable TSC clocksource instead of PV clocksource, the scheduler still keeps on using PV clocks as the sched clock source. This is because KVM, Xen and VMWare, switch the paravirt sched clock handler in their init routines. HyperV is the only PV clock source that checks if the platform provides an invariant TSC and does not switch to PV sched clock. When switching back to stable TSC, restore the scheduler clock to native_sched_clock(). As the clock selection happens in the stop machine context, schedule delayed work to update the static_call() Cc: Alexey Makhalov Cc: Juergen Gross Cc: Boris Ostrovsky Signed-off-by: Nikunj A Dadhania --- arch/x86/kernel/tsc.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/arch/x86/kernel/tsc.c b/arch/x86/kernel/tsc.c index cf29ede4ee80..d8f4844244f4 100644 --- a/arch/x86/kernel/tsc.c +++ b/arch/x86/kernel/tsc.c @@ -272,10 +272,25 @@ bool using_native_sched_clock(void) { return static_call_query(pv_sched_clock) =3D=3D native_sched_clock; } + +static void enable_native_sc_work(struct work_struct *work) +{ + pr_info("using native sched clock\n"); + paravirt_set_sched_clock(native_sched_clock); +} +static DECLARE_DELAYED_WORK(enable_native_sc, enable_native_sc_work); + +static void enable_native_sched_clock(void) +{ + if (!using_native_sched_clock()) + schedule_delayed_work(&enable_native_sc, 0); +} #else u64 sched_clock_noinstr(void) __attribute__((alias("native_sched_clock"))); =20 bool using_native_sched_clock(void) { return true; } + +static void enable_native_sched_clock(void) { } #endif =20 notrace u64 sched_clock(void) @@ -1157,6 +1172,10 @@ static void tsc_cs_tick_stable(struct clocksource *c= s) static int tsc_cs_enable(struct clocksource *cs) { vclocks_set_used(VDSO_CLOCKMODE_TSC); + + /* Restore native_sched_clock() when switching to TSC */ + enable_native_sched_clock(); + return 0; } =20 --=20 2.34.1 From nobody Mon Nov 25 11:40:33 2024 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2069.outbound.protection.outlook.com [40.107.92.69]) (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 2B23818CBEC; Mon, 28 Oct 2024 05:35:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.92.69 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730093762; cv=fail; b=BmCR6tJBoEw0K6xQjv4M8PQYREYC+Qe1aUmZVdEYJA2/qY28712k690LEg5qvMEBEt1T2OUpYGT8PRcfGMufqzosQXEyQqnXAkMKanuMfJxBfB12g3ZE9HXp26gT49wYOtS5gJTZCu+XQMK/xGOtjHqCWB2BIFfqtA4sF1JkJas= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730093762; c=relaxed/simple; bh=YnD4/6vvVaIcqsZxXAJiIONT0oWUG8QRzHPp/70Bue0=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=UFskKlcxSz4paek2H/PWxU1BG/KE0zhUGDn+EvBpGitjr4HIoL5Tp5xgWB4Hgkn0j+Xga6Lsji5H7yATIigY+evZqyrWNhct+sFMl2XYGT90OxQtkUaYq5ggjyNQEEdLcPXIGJvyaP+PnvY0vUVCCSOp1X7qeQG3xi1tNGD4dNg= 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=eKmBUVGn; arc=fail smtp.client-ip=40.107.92.69 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="eKmBUVGn" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=XkyNlLZZmTuwDOARCpVD07J8pNWrIxj9ysi2Yb+Y2DcKVIzRvogj0AvoMKTrJLERKV0c8m0kH72J1nGq5uTzGLEo2cL2WiycKBMhAF/Oqx6Pe9h5hE2tly5oOzx8N8JKOjVKtNnCNRtwHho0D18X3l2jdRD2WffL4CSuzGxA0yu32EivT6dJb/0p9whP3Td9cgOfVmS0YOU+fUocKID9X/sOliRk9a9bsQqiKuNR88RmzAhFE9OOIXeVf3HaXImiPLbW+2PlMdEjJDc1KYvmr8tMlKN/XNLRCY8iTSnVbY+7dvyk1iZqrdv7zDJ19LXfuRmwxicgGTHQlXwD1JThzg== 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=YMZootdqQlrbmJT8z5xz7E275aebH+r3KKMcmjLatFk=; b=YzoMYePqx2quLCkn2PKrn/SSqtCaGnPzjxNdvtsRbUWv+kJdMht24yXo2f9gqI/bhCIQEtDoowCjDId7kS3VDtdTYRhlW285c1wY3vu9OSx160OIEymmpK1ExsbwLDQGftEWYd2F9tiHghHUQ36dLUh/cADJaGxpY8fF6/F3l6ugoMU9FpXaKfDTfIpmIFonERcs+71HtHh01g7CrIwpnGDDQSatv/rFYp4WTdv3Bi7q63P2455mfd4FufY237ysAqP/v69SypTVc298XCx4BJqPKQRUOBbn5wipi74ys5dXABnrnu2mw4qSrXJt7l4N/7c2Zt13DfSxKAf8pPs59A== 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=YMZootdqQlrbmJT8z5xz7E275aebH+r3KKMcmjLatFk=; b=eKmBUVGncxw7JHgbc3pB1Jp9Ya0ReppsXvW0T3G56IcQ6iPmKaY+7UdCj4eiWnbn5ta1vCj1f84Sa+68Rw5clZCN/70a4B+YWtyOAM0jCrgN6wxl1uWVCn/iU2NPWWYidcGcMDSJaskw2ufMz6OTAdgCFFc2yVRu6aZ0OVKi8rw= Received: from BY5PR03CA0007.namprd03.prod.outlook.com (2603:10b6:a03:1e0::17) by BL1PR12MB5921.namprd12.prod.outlook.com (2603:10b6:208:398::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8093.24; Mon, 28 Oct 2024 05:35:55 +0000 Received: from SJ1PEPF00001CE6.namprd03.prod.outlook.com (2603:10b6:a03:1e0:cafe::66) by BY5PR03CA0007.outlook.office365.com (2603:10b6:a03:1e0::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8093.19 via Frontend Transport; Mon, 28 Oct 2024 05:35:54 +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 SJ1PEPF00001CE6.mail.protection.outlook.com (10.167.242.22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8093.14 via Frontend Transport; Mon, 28 Oct 2024 05:35:54 +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; Mon, 28 Oct 2024 00:35:50 -0500 From: Nikunj A Dadhania To: , , , , CC: , , , , , , Subject: [PATCH v14 12/13] x86/kvmclock: Abort SecureTSC enabled guest when kvmclock is selected Date: Mon, 28 Oct 2024 11:04:30 +0530 Message-ID: <20241028053431.3439593-13-nikunj@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241028053431.3439593-1-nikunj@amd.com> References: <20241028053431.3439593-1-nikunj@amd.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ1PEPF00001CE6:EE_|BL1PR12MB5921:EE_ X-MS-Office365-Filtering-Correlation-Id: 96d32ca0-6f54-439a-878d-08dcf712647c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|1800799024|82310400026|376014|7416014; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?bb3wCE8pxsIw32rvegsmqIX7J1+IDJKPtK16ISXktlSEIzPJ5x/JvL3ePMdC?= =?us-ascii?Q?tdiEY3qQvMgCUKDkyiYyGfqofBIJFuI39QJjfYPgmVU34dawUO7eiDQcmiej?= =?us-ascii?Q?8bighUCTcO09DhoAHVbzQu+61dDQOZ9nkk0La9gYfbpWK0Q6SBpmvGlPZY+b?= =?us-ascii?Q?V9+pNYsXMBDBFWF9sgPl0DVVK4MLtcqaAs7SA1NVM21Exr6eagfxcvt6ktVw?= =?us-ascii?Q?TN3lGG+jQzofXJJdH3TOmvUijcxUNN8izsAPBkFtC8TYghMWB74K4pVneHFD?= =?us-ascii?Q?u2ud9CQneTxCJ9Or9rKbokaw1bU7buCzaDE+NXZ4aRV+tYM+/YJZtE5HLvD8?= =?us-ascii?Q?zkP1HD7iNwuvxiGc5/N3N0wEiWHL+lz4ldysvXNEnwlMP0DH3wOR6LXXvBXZ?= =?us-ascii?Q?ELvqEcpBAEQWViv25/AQn+9o9Q1cHk2HZUsoV10ngCkQdXJ5VsZU2nlqzj73?= =?us-ascii?Q?6Yp4dnsxaI5hf/Wg04TRhui6TF6MByMu/NOnIgasU2p/lK7T9fLwORegDLkj?= =?us-ascii?Q?Zr5JqLcl8iHiu/4UAB6/tBWDvN7Jx6tWEFq3sUSB0KVVd34ambDN9GMg+Aya?= =?us-ascii?Q?d941nsEdfk9qYNmHpLd6KHqIyqM6JEJyGylIgjzAebyBZhNxlxs/S3KAMPcA?= =?us-ascii?Q?X1b+OiZE8VfrV06bEYW77phO21OW6kh+a3QTMP8VZile3kAIBDzIfwXiyLUk?= =?us-ascii?Q?i1r8ej6IwG/2crmqIki2C4jw8fT9/eUddhjRAhfq5QcPCWDcrKQuk9l4x9Jz?= =?us-ascii?Q?2lAdRKrfucLf1YDuyREKWpbh2pDM+V2rcKP+CSiuWCZR1nl/CdL+WW8//qmU?= =?us-ascii?Q?YIT0T0XHwUQvBtguZaAO+A4hYUQmAZeXyq0q37pH/LhmK6rucjd5+1bffCxI?= =?us-ascii?Q?cjaCQCyORqjBJw2ItZ1wj7/rtLZBGldKHcBK9jF1dzs0n3+tRTGXz+heQDuZ?= =?us-ascii?Q?PSGyz1eKrcOjiesEY6DxBS9vcL90qdIdi1I7Hdpu8+Nv9aaCyhJEJeB0Ya5F?= =?us-ascii?Q?S2FF+huK2/gLji0HXFGwzspUSjsSc5CFvo0Fccz/dpJhNDvAptTKCrlSRwxf?= =?us-ascii?Q?VKJOuD6SW3uLOL+jTVfWchQlIrOZ/VHdJ93eRZlJKp9VQVdop8SNnACSMjVA?= =?us-ascii?Q?ikFP7uynckmQngBrIZS8JQM1hlNOw71eK+EweRgoSRz/gcu8YYoRlUTB+Zpg?= =?us-ascii?Q?jNR5mjS/lH652SZKKh/TWTTCJJmIlVsRaA3f3GNWMhc5/TmqCkfPdvDW0FbE?= =?us-ascii?Q?8qOOpXX4UA4v9kJcEOHLLzjpFW5DeL+hjHyP1mv5JRKHtZ/aj91U8I01SgyJ?= =?us-ascii?Q?lJe+qZ4MyZEGmBeSgvl2gCUX7Tu7qE1+diDryT1aGW8cMcFF3zd/Skfdzqan?= =?us-ascii?Q?3oBr02hGkkvM5RbuGs7SFsIOgfVT391g4UEx/O/ZDdDccz0Lzw=3D=3D?= 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)(82310400026)(376014)(7416014);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Oct 2024 05:35:54.4466 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 96d32ca0-6f54-439a-878d-08dcf712647c 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: SJ1PEPF00001CE6.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR12MB5921 Content-Type: text/plain; charset="utf-8" SecureTSC enabled guests should use TSC as the only clock source, terminate the guest with appropriate code when clock source switches to hypervisor controlled kvmclock. Signed-off-by: Nikunj A Dadhania --- arch/x86/include/asm/sev-common.h | 1 + arch/x86/include/asm/sev.h | 2 ++ arch/x86/coco/sev/shared.c | 3 +-- arch/x86/kernel/kvmclock.c | 9 +++++++++ 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/arch/x86/include/asm/sev-common.h b/arch/x86/include/asm/sev-c= ommon.h index 6ef92432a5ce..ad0743800b0e 100644 --- a/arch/x86/include/asm/sev-common.h +++ b/arch/x86/include/asm/sev-common.h @@ -207,6 +207,7 @@ struct snp_psc_desc { #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 align= ed */ #define GHCB_TERM_SECURE_TSC 10 /* Secure TSC initialization failed */ +#define GHCB_TERM_SECURE_TSC_KVMCLOCK 11 /* KVM clock selected instead of = Secure TSC */ =20 #define GHCB_RESP_CODE(v) ((v) & GHCB_MSR_INFO_MASK) =20 diff --git a/arch/x86/include/asm/sev.h b/arch/x86/include/asm/sev.h index 9ee63ddd0d90..99877e96c986 100644 --- a/arch/x86/include/asm/sev.h +++ b/arch/x86/include/asm/sev.h @@ -537,6 +537,7 @@ static inline int handle_guest_request(struct snp_msg_d= esc *mdesc, u64 exit_code =20 void __init snp_secure_tsc_prepare(void); void __init snp_secure_tsc_init(void); +void __noreturn sev_es_terminate(unsigned int set, unsigned int reason); =20 #else /* !CONFIG_AMD_MEM_ENCRYPT */ =20 @@ -586,6 +587,7 @@ static inline int handle_guest_request(struct snp_msg_d= esc *mdesc, u64 exit_code =20 static inline void __init snp_secure_tsc_prepare(void) { } static inline void __init snp_secure_tsc_init(void) { } +static inline void sev_es_terminate(unsigned int set, unsigned int reason)= { } =20 #endif /* CONFIG_AMD_MEM_ENCRYPT */ =20 diff --git a/arch/x86/coco/sev/shared.c b/arch/x86/coco/sev/shared.c index c2a9e2ada659..d202790e1385 100644 --- a/arch/x86/coco/sev/shared.c +++ b/arch/x86/coco/sev/shared.c @@ -117,8 +117,7 @@ static bool __init sev_es_check_cpu_features(void) return true; } =20 -static void __head __noreturn -sev_es_terminate(unsigned int set, unsigned int reason) +void __head __noreturn sev_es_terminate(unsigned int set, unsigned int rea= son) { u64 val =3D GHCB_MSR_TERM_REQ; =20 diff --git a/arch/x86/kernel/kvmclock.c b/arch/x86/kernel/kvmclock.c index 5b2c15214a6b..39dda04b5ba0 100644 --- a/arch/x86/kernel/kvmclock.c +++ b/arch/x86/kernel/kvmclock.c @@ -21,6 +21,7 @@ #include #include #include +#include =20 static int kvmclock __initdata =3D 1; static int kvmclock_vsyscall __initdata =3D 1; @@ -150,6 +151,14 @@ bool kvm_check_and_clear_guest_paused(void) =20 static int kvm_cs_enable(struct clocksource *cs) { + /* + * For a guest with SecureTSC enabled, the TSC should be the only clock + * source. Abort the guest when kvmclock is selected as the clock + * source. + */ + if (WARN_ON(cc_platform_has(CC_ATTR_GUEST_SNP_SECURE_TSC))) + sev_es_terminate(SEV_TERM_SET_LINUX, GHCB_TERM_SECURE_TSC_KVMCLOCK); + vclocks_set_used(VDSO_CLOCKMODE_PVCLOCK); return 0; } --=20 2.34.1 From nobody Mon Nov 25 11:40:33 2024 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2086.outbound.protection.outlook.com [40.107.243.86]) (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 C06CE1D54D6; Mon, 28 Oct 2024 05:36:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.243.86 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730093765; cv=fail; b=OgzGFimKIuZjqa49W5AwQDuwxAUbqEFZia9+LEzt07HZsDPrsl9WZZRe40smL9fgg6GS8P66JZkeCaC+pFp8RGUhoe8TmHT0C2KbeIKmMN/FA9M2I2/8prBgfmQel/YQ0ISn1W2dxl8N87rYxwMFFtdiAO+WLBtjPVvTSH8Pu8c= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730093765; c=relaxed/simple; bh=J7ITyZv4fTZN+ZfiudI2wlQZ6XlSSdAR/6O3kPxxatE=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Q3ojP3ESl6RN0JVfqAdpAK940mmLhMuJslbf/D2VM083V5Ml+rw5hpH/WCFvYVZEQ/eGKy4QmSi0168c6KrBNkn388urSZwI2wEIXrqDIecRUZJfDObLrRhOFfYgvAYuxnoAcVtEn/zsYWvgeOz8QHhVk9c0wizv3kZkbK3ZJKA= 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=aazIxmqW; arc=fail smtp.client-ip=40.107.243.86 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="aazIxmqW" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=qTqkiiEumCFD3x22vlbq6cdJTxDDxTro7caHZXRpaFs2CtAe5m4WdmR70BK4beqGj8HT70WyW9u+HVpjgEiCg3GRuEFtu2v3d2hrnw5uyP2wREAK/zYqKYZC0RVrci1CX5TPLYhJmbfS9zNmBpXAWAbp+rHXN00Bzu29DkXagf4629CVKdXPrfNQmwK8emDynmt8fa4XIO2t0dJni3/fVHBZjmBUD7JFsTURDhe+c9dAMTFT4XpoStSVqO12SKuS5xyiVb97LAa/WtntoQQGSpHqHghHaDEm639ILzI88oNTnbkAxRYCv1xevyIPmeTCA/KLOyKWzu+SF7nBNZvCWA== 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=atjBLt16IpratFsJbg/6ZonMoxx3kjKCKv65wzEaGEI=; b=OFYuxfmyzKeo7p0gVSIfTsaugW18CzmZuKU3zX6H316R25PWWyxS82eXPGnJ3wnzOSOPSZWLdnRcCNTa5CKpopDI0Q6+Ndoc330cj+mdy+XRtLo3bj7KWtcP/g53+9sciYcpeGt4hMGlgxbkLORohcsXQ942Zh/CjnZHw/w5Dd0sz0NrlmwidqxW8pdl1Xfd2mrp2ziLgEv0Js6omh+dK3yCYKWu8hyTHfB5T6VFyUnr5Vnkb1HtgExk1ur9CkxSojS6LQLOsTwxeiQcWJcTrCk61zuTDYGyxsLTienyuNQN7Cls6q95e1VfmEbZa8PYcd58t+efHBLK/c2+pi7trA== 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=atjBLt16IpratFsJbg/6ZonMoxx3kjKCKv65wzEaGEI=; b=aazIxmqWAyBdlhVayXe067K2t5WhQu6IGClil4y/bywDnD7orvvnZ75mD237d+sZ7zk9ciAeuDvRkhvk6+u9IiZ6JXjs3YhbQ8Xlr4MxDHst1QGIjWU4yfkVb2kUMqwoeCZtWRzNz+Lbve1h8gj0GKG8waj0p9Yyo3l8q1VIhSk= Received: from MW2PR16CA0012.namprd16.prod.outlook.com (2603:10b6:907::25) by SN7PR12MB7371.namprd12.prod.outlook.com (2603:10b6:806:29a::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8093.24; Mon, 28 Oct 2024 05:36:01 +0000 Received: from SJ1PEPF00001CE5.namprd03.prod.outlook.com (2603:10b6:907:0:cafe::3b) by MW2PR16CA0012.outlook.office365.com (2603:10b6:907::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8093.21 via Frontend Transport; Mon, 28 Oct 2024 05:36:00 +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 SJ1PEPF00001CE5.mail.protection.outlook.com (10.167.242.21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8114.16 via Frontend Transport; Mon, 28 Oct 2024 05:36:00 +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; Mon, 28 Oct 2024 00:35:53 -0500 From: Nikunj A Dadhania To: , , , , CC: , , , , , , Subject: [PATCH v14 13/13] x86/sev: Allow Secure TSC feature for SNP guests Date: Mon, 28 Oct 2024 11:04:31 +0530 Message-ID: <20241028053431.3439593-14-nikunj@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241028053431.3439593-1-nikunj@amd.com> References: <20241028053431.3439593-1-nikunj@amd.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ1PEPF00001CE5:EE_|SN7PR12MB7371:EE_ X-MS-Office365-Filtering-Correlation-Id: 959bb9ed-6d77-44cf-7112-08dcf71267f2 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|376014|1800799024|36860700013|82310400026; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?RWvUNBW7Z2WxICWH/8rz4P8vOLZF5Z7u/7MW9VD0ijtvbTNComrnugYuYi9E?= =?us-ascii?Q?YYxbwl+KYRwXxl52lXdxNrZOxf2I8feeJmsk7jYeL2Zl6jch6cN9+HAEA8I2?= =?us-ascii?Q?VSf4hLKNYvF05aJ9uTgSK3KysV4yJLoy49kCpUR6bnl7I5SD+J/t0GzRM1zC?= =?us-ascii?Q?dvW2NNMsp/KCpJjbF6nw3GsYP1ANdBJTgE8nadZw7ioWIjgBrddpCIlIbrNu?= =?us-ascii?Q?YuUt8CfhcM+1I2hSrZNQfPJA6wJx7b0Z+ByW6niY3lGybQ79ofExZlncY428?= =?us-ascii?Q?FuhkxYcLzezHVUuZz9KVdu30g7AfLuu7HqpXABKGuBuvNiD+a6bq63vCl5Nz?= =?us-ascii?Q?d+RdqdcNGhzGcW/VeZWfv08ecJ/kfXnNoFHmPhwzkgpaczw0FGhggFLo88pI?= =?us-ascii?Q?MjcXG19CURbkgm7t3zF2JyIbjCDQ56yPfF7czowBE0j1G721+A1mhTIWKcrw?= =?us-ascii?Q?dSTMj8sQYZPQE1OqAo/0heNDh8+w+PPVCAIxyuUWuZM4CV5iwv3SaJ8nvfay?= =?us-ascii?Q?7BVd8kqG4Ql2M8b3s1X150yoxaqllH6hVD02aOzZUg9zWEXzvdlAUaxr1vOi?= =?us-ascii?Q?jnQSW6q9tE9+vftv9ZNV3fPOtpeX46+KNzsXkxJhfamy80idgM4smR+PpNlp?= =?us-ascii?Q?ISCZdk4LANBJMaTiDpWpDWq2J1MlVkbb4+3/tcMPRJMax6RqE+2cwH3Vx8lT?= =?us-ascii?Q?V6QaVQ1gQxzEHuvcrzqDwWvxD64h6o6v0/j0sbaaGqMuhLlTOXkmqaKE7heN?= =?us-ascii?Q?uGPuAM9HeE2qeayPoJsxcdhJFhAamcH8km55ZaK3/bVNXwAYcl6mV78dh+z4?= =?us-ascii?Q?ad8nwJrEyg8Csrwb1GjCFMvu8IyXlApBmnFDVGx3gDKRbXPkalVQthCr7FB3?= =?us-ascii?Q?aNX5wjS2EAoWQIiqkB/9bZZ2WdPmJuxQVkF0LB3ABItzoFDQQBirHHPfycbL?= =?us-ascii?Q?ftEgyww3Qe1aGpeMhThyAxhd5FaAL8/gpAulRBJYPsIWojDs84bnf8c4Pz3j?= =?us-ascii?Q?3igSsf2k9/ilYGkoLmmDKUjYKsfutpL1o9yihLzy/XnmqU3HMXoyTtVCCWLK?= =?us-ascii?Q?n4H4IwJDlzFedWEFCQqFXDYFSZHhYL/v7iR3M9oKozTQs2F1OthT/7B0XNdO?= =?us-ascii?Q?uggLTdw/uieDLjmEN27iLbo1xQt2uReq79h6Gw45+R8qLeUB/I2hYpA6v9Mu?= =?us-ascii?Q?W4eNhLAkB42kH4U7StIKkbNfJRYEaPeAr1RjHedv08CYSdZpPgchB50H3kZA?= =?us-ascii?Q?uayAtTmTaBga9Xgw4HvWiGu9Vc4kgmuHHnlgGf2hZ5fFh9HDv/Vh6UpHm1OB?= =?us-ascii?Q?kFLTLIcjO8gpHqPuOQmR/mlBl27viw3iDg/DXD0AM/wd9Zm/+rum97Qnv2gR?= =?us-ascii?Q?ctsaAQmwfzVxEiJb00BX+bEdpnER0oAti/UMyirXAPplwTcBLA=3D=3D?= 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)(36860700013)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Oct 2024 05:36:00.3619 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 959bb9ed-6d77-44cf-7112-08dcf71267f2 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: SJ1PEPF00001CE5.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR12MB7371 Content-Type: text/plain; charset="utf-8" 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 l= ong 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) =20 u64 snp_get_unsupported_features(u64 status) { --=20 2.34.1