From patchwork Fri Jan 29 00:36:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Babu Moger X-Patchwork-Id: 12054805 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BFF9FC433E0 for ; Fri, 29 Jan 2021 00:39:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7C45D61481 for ; Fri, 29 Jan 2021 00:39:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231394AbhA2AjK (ORCPT ); Thu, 28 Jan 2021 19:39:10 -0500 Received: from mail-mw2nam10on2052.outbound.protection.outlook.com ([40.107.94.52]:39681 "EHLO NAM10-MW2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S231387AbhA2Ah5 (ORCPT ); Thu, 28 Jan 2021 19:37:57 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LBKiDkDt1bMNL6gFOJ7acDvmgQc7ssDhaf317CLZJD4SqliseZbHfJXF17jK+TIfz1X3P1zclr9+kjgH109k0VQACKIY4km4eQig4obp0NbdYtJt/IMrTVT4e0yk6ik4jXWOybT07yHDKvxaDfmOjHAjW6E6047uPb45mhOKK4KbqhldGzSC3tSeQYkVfbp+zyU6f+ISs/JHs23PnOtZHIMRlnmnZ2nAwG5h0xgyulAnmnjEIfliqlBri5wx5+lxUqI0C2AQEHus06jncfZtHL7W5rEK6PhOO5I+LUwu03CHh6rka74ZdGukFhlEAbKi1LydHpGLr4DgomasKBen+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=LroqR7U1lDdU3oQnauGVHLHLnWXk3xAM7TJ0lqnX5Qo=; b=cKvqhEQJg2s1ZAnMmlkOTBak6rsyWi1G2Ic9m3gIS3EmdD8p9oibv/nk0xH21Le+nhGxXXWpAN2UGABmGhjuR3W4EHA8ptrQ989UVM1Cb9xkJTMGu9hsZim9lVk/ThOjZGCdYFvu3NPri/h7S4EtFEBwfKmoiFme9N3f8X/uPVcOUlfxaaEfDsebx5YETuUTfLT+vjoIcH8GjqEfY9Uru0hoWYILlXmm3nDHQHJFlQl8tGd7XHK8f/Kqi6fBHoE6BPlnPCN0k8phrrE4+YPpnMNZylJ2pa2ky5C/UYmecgHwYkrppBUzad94e6n3sePTd2s1IydD3yZ3g1QRp2b1aA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none 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=LroqR7U1lDdU3oQnauGVHLHLnWXk3xAM7TJ0lqnX5Qo=; b=t/uNLI5dfmhOBAXKKLQb7C+kuZNSPPEyK1IIu3hiLAs9+i0PD0YS89aAKNqYKZ6jv/GNqlR2IZf6TECsSJkn2IwjsnIy8NuzOoYly7OPDQBAVjyq2FwJejXCMc/4X+yGU/URVVWGPUcwt2L8N4yQEgXzeo4HIQ4qt0fZGeYbWxI= Authentication-Results: amd.com; dkim=none (message not signed) header.d=none;amd.com; dmarc=none action=none header.from=amd.com; Received: from SN1PR12MB2560.namprd12.prod.outlook.com (2603:10b6:802:26::19) by SN1PR12MB2525.namprd12.prod.outlook.com (2603:10b6:802:29::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3805.17; Fri, 29 Jan 2021 00:36:20 +0000 Received: from SN1PR12MB2560.namprd12.prod.outlook.com ([fe80::8c0e:9a64:673b:4fff]) by SN1PR12MB2560.namprd12.prod.outlook.com ([fe80::8c0e:9a64:673b:4fff%5]) with mapi id 15.20.3805.019; Fri, 29 Jan 2021 00:36:20 +0000 Subject: [kvm-unit-tests PATCH v2 1/2] x86: Add SPEC CTRL detection tests From: Babu Moger Cc: kvm@vger.kernel.org Date: Thu, 28 Jan 2021 18:36:19 -0600 Message-ID: <161188057905.28708.10578820564970956832.stgit@bmoger-ubuntu> In-Reply-To: <161188044937.28708.9182196001493811398.stgit@bmoger-ubuntu> References: <161188044937.28708.9182196001493811398.stgit@bmoger-ubuntu> User-Agent: StGit/0.17.1-dirty X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: SA0PR11CA0052.namprd11.prod.outlook.com (2603:10b6:806:d0::27) To SN1PR12MB2560.namprd12.prod.outlook.com (2603:10b6:802:26::19) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from [127.0.1.1] (165.204.77.1) by SA0PR11CA0052.namprd11.prod.outlook.com (2603:10b6:806:d0::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3805.16 via Frontend Transport; Fri, 29 Jan 2021 00:36:20 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: e6e041d1-cbff-44fa-7c36-08d8c3ede5b1 X-MS-TrafficTypeDiagnostic: SN1PR12MB2525: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:1388; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: gb3WompLLSYOkYCz5cUpx2iNOIS9yYZSt7IuHVrIK/wmM8fjQRjRrYQdS30cp47TcSImj+xV1d3cMWWYWdOS8Ixuft8PXYawUpgAnb86B9m7dwj2B6dUmbpT72MfPfnbWNlso05I04utVmhBomA6LRv3+hYJChb268yDsSdcBhH5g36h2f6+B84FglXdS3AE1ehauizmcA/aRsIXLyc9iy67HOeRU0MhIDEflV6qHHed7KIsYix6LI2F+FKIU3B0MHKRX1A/q9c5Zon7XzbjnBkb4zsetZgg+o8mutHNYU1Kzt5EotSOWGsPLm8x6pYGqTfoIq40SXZiiiLJ80zmitExKT4DhHREOQtm6aMlQC/IOXasU1zpAH3HN/B+85Y4GPT2XSK6PUJ2sgBDaktDk501XsjnaezHpgLHTRU5oWntcZFDRpega5tJhEZQG9E1kaW9z5SNX9Ye0o7+nrT1J93oWjAfgMvVZWY+fkXPrqZP94T7stW8gRpy2bwyWa3vv+pQdgx+YJTVCzGmUdqrnA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SN1PR12MB2560.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(7916004)(396003)(346002)(39860400002)(366004)(136003)(376002)(83380400001)(2906002)(103116003)(66946007)(8936002)(8676002)(52116002)(4326008)(86362001)(66476007)(66556008)(109986005)(186003)(6486002)(478600001)(16526019)(26005)(5660300002)(33716001)(44832011)(316002)(16576012)(9686003)(956004);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?utf-8?q?drrdcVCIm0jCcmp70z/U+cVRL8cZQY?= =?utf-8?q?7UVYttDpiXnhdcMcLSUSLDQTCOsnHwuIWwY8k4y+dMz9o7O94mPF16S4MKEe5jskd?= =?utf-8?q?DulucOKx6g69URbj0LlZGjVWSkbhpOR2xY6SKB5jg+6Fq0kvC7CxJQ2IlqR8vygAE?= =?utf-8?q?GW9DRayY2VhTHLBu67chAIYzgv3Npt86BCVZaOUIT0v9KIOlnwCwkDScc5wc76kN4?= =?utf-8?q?WoniDDVVUGUSmVMaNSSS2EBBrRMHhBxdbar+obEil/amVHTzMbjlI9nPGsQ742gAC?= =?utf-8?q?t+mZF1LfXh8FK8mKvf8QU2Vjb/TlFYAAICsekgw7Cc/yiJ2JEFvWLQBhnLD5IwFR7?= =?utf-8?q?9hivhDNQ6kRnYrHA9nwHceaCth4K/MdZphR6a+ND+9OzSHIB0Cwy30h3lDscyxeLl?= =?utf-8?q?JZCkN7SQLWMyu54vthLCImffxVEdeJqx6OQZslzRmuLn4xcSXea22hZTi32v3XzAt?= =?utf-8?q?0gANL4eNQ06Q+4DEYCjZA1U7XqwZGWn9rfPWSnL94dP27z9d/hAZsz0lEpJSQFkkl?= =?utf-8?q?a5hu7F+cqII5VOWfjFl1cmCiLEDGUlqAPdQBrysY5pLeE5KVTWC9TR/VMyUvJzxgH?= =?utf-8?q?w8tjEScH5mFSvqnT/BJ1Hs0xIx9QssdJbkWWaV7O+GVJnvz3Tl9DGPrT/jH3Wsh0X?= =?utf-8?q?73gDXsEH9uWOdOyIbYNPOXXlFkcJpc0XD2klVgQLW+fAop1AW0vEV2+S4U7v1I2YM?= =?utf-8?q?R8XOO0XEAB9ewNzOF/zxPmetxNiUEJzW3k8HFmLzc992KPcPYpFt9UHJVxPNNquJt?= =?utf-8?q?2ob3s4Ig27WdtxCX08F9/0gY7CYD/6AyhbmPF5immnEKQCtf5Gr050a0DS6hjb/jV?= =?utf-8?q?KMkr2BcF8JNrxuXthzdKOIQifhmWZV4bcM9Ndi7PNFqLyA4gN4CtZPKZetsCmx6Rh?= =?utf-8?q?fh5mMEhhgi+zIZFErh5H0zIf5vddZQonFRKiXgQm6yRSLUMUw5g1fBh1nOsAmfHfY?= =?utf-8?q?mbBwiPgzijOPr6jcawcYLcNxfbEIXh2GVMBKli+FV1QeUVAkpoz89mp/vRt/4XsuQ?= =?utf-8?q?jSxTKiLaS27G1WSPma?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: e6e041d1-cbff-44fa-7c36-08d8c3ede5b1 X-MS-Exchange-CrossTenant-AuthSource: SN1PR12MB2560.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Jan 2021 00:36:20.5192 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: AYRY3A05VyWaYpjbhg5WnBzlOvK0RVX5zcT9YrS3j5oJk9UVBEhbrEgGd5/MuAKf X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1PR12MB2525 To: unlisted-recipients:; (no To-header on input) Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Detect the available SPEC CTRL settings on the host. Signed-off-by: Babu Moger --- lib/x86/processor.h | 5 +++++ x86/Makefile.x86_64 | 1 + x86/spec_ctrl.c | 30 ++++++++++++++++++++++++++++++ x86/unittests.cfg | 5 +++++ 4 files changed, 41 insertions(+) create mode 100644 x86/spec_ctrl.c diff --git a/lib/x86/processor.h b/lib/x86/processor.h index 87112bd..40caac1 100644 --- a/lib/x86/processor.h +++ b/lib/x86/processor.h @@ -159,7 +159,9 @@ static inline u8 cpuid_maxphyaddr(void) #define X86_FEATURE_LA57 (CPUID(0x7, 0, ECX, 16)) #define X86_FEATURE_RDPID (CPUID(0x7, 0, ECX, 22)) #define X86_FEATURE_SPEC_CTRL (CPUID(0x7, 0, EDX, 26)) +#define X86_FEATURE_STIBP (CPUID(0x7, 0, EDX, 27)) #define X86_FEATURE_ARCH_CAPABILITIES (CPUID(0x7, 0, EDX, 29)) +#define X86_FEATURE_SSBD (CPUID(0x7, 0, EDX, 31)) #define X86_FEATURE_PKS (CPUID(0x7, 0, ECX, 31)) #define X86_FEATURE_NX (CPUID(0x80000001, 0, EDX, 20)) #define X86_FEATURE_RDPRU (CPUID(0x80000008, 0, EBX, 4)) @@ -170,6 +172,9 @@ static inline u8 cpuid_maxphyaddr(void) #define X86_FEATURE_SVM (CPUID(0x80000001, 0, ECX, 2)) #define X86_FEATURE_RDTSCP (CPUID(0x80000001, 0, EDX, 27)) #define X86_FEATURE_AMD_IBPB (CPUID(0x80000008, 0, EBX, 12)) +#define X86_FEATURE_AMD_IBRS (CPUID(0x80000008, 0, EBX, 14)) +#define X86_FEATURE_AMD_STIBP (CPUID(0x80000008, 0, EBX, 15)) +#define X86_FEATURE_AMD_SSBD (CPUID(0x80000008, 0, EBX, 24)) #define X86_FEATURE_NPT (CPUID(0x8000000A, 0, EDX, 0)) #define X86_FEATURE_NRIPS (CPUID(0x8000000A, 0, EDX, 3)) diff --git a/x86/Makefile.x86_64 b/x86/Makefile.x86_64 index 3a353df..79e4586 100644 --- a/x86/Makefile.x86_64 +++ b/x86/Makefile.x86_64 @@ -21,6 +21,7 @@ tests += $(TEST_DIR)/intel-iommu.flat tests += $(TEST_DIR)/vmware_backdoors.flat tests += $(TEST_DIR)/rdpru.flat tests += $(TEST_DIR)/pks.flat +tests += $(TEST_DIR)/spec_ctrl.flat include $(SRCDIR)/$(TEST_DIR)/Makefile.common diff --git a/x86/spec_ctrl.c b/x86/spec_ctrl.c new file mode 100644 index 0000000..7359a9d --- /dev/null +++ b/x86/spec_ctrl.c @@ -0,0 +1,30 @@ +/* SPEC CTRL Tests */ + +#include "libcflat.h" +#include "processor.h" + +int main(int ac, char **av) +{ + if (this_cpu_has(X86_FEATURE_AMD_IBPB)) + report(true, "X86_FEATURE_AMD_IBPB detected"); + + if (this_cpu_has(X86_FEATURE_AMD_IBRS)) + report(true, "X86_FEATURE_AMD_IBRS detected"); + + if (this_cpu_has(X86_FEATURE_AMD_STIBP)) + report(true, "X86_FEATURE_AMD_STIBP detected"); + + if (this_cpu_has(X86_FEATURE_AMD_SSBD)) + report(true, "X86_FEATURE_AMD_SSBD detected"); + + if (this_cpu_has(X86_FEATURE_SPEC_CTRL)) + report(true, "X86_FEATURE_SPEC_CTRL(IBRS and IBPB) detected"); + + if (this_cpu_has(X86_FEATURE_STIBP)) + report(true, "X86_FEATURE_STIBP detected"); + + if (this_cpu_has(X86_FEATURE_SSBD)) + report(true, "X86_FEATURE_SSBD detected"); + + return report_summary(); +} diff --git a/x86/unittests.cfg b/x86/unittests.cfg index 90e370f..b3c5320 100644 --- a/x86/unittests.cfg +++ b/x86/unittests.cfg @@ -251,6 +251,11 @@ file = rdpru.flat extra_params = -cpu max arch = x86_64 +[spec_ctrl] +file = spec_ctrl.flat +extra_params = -cpu host +arch = x86_64 + [umip] file = umip.flat extra_params = -cpu qemu64,+umip From patchwork Fri Jan 29 00:36:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Babu Moger X-Patchwork-Id: 12054807 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D8C78C433E9 for ; Fri, 29 Jan 2021 00:39:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9E7C261481 for ; Fri, 29 Jan 2021 00:39:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231561AbhA2AjQ (ORCPT ); Thu, 28 Jan 2021 19:39:16 -0500 Received: from mail-bn8nam12on2064.outbound.protection.outlook.com ([40.107.237.64]:49601 "EHLO NAM12-BN8-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S231467AbhA2Ai2 (ORCPT ); Thu, 28 Jan 2021 19:38:28 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=OfHIAOwH5dL/7AF2tlsTJAAC4CIcfnnl+5f236UcayfHEtPMfqMrSjJjGiHlBnP/poAALCueeAYbSNpe85h3D4gfFzXiIgiUwLqGT+CpJuXSs09UTMyFgxUSg127Td+fKKhr7a3FsjopHvcENtTk8BhhEAklEAJZly44Fqp3ykDe++VLaHD0AzKci0QNDKq5IGZbn6tXHPmZwYyh6UZyet7L1r9Pvkl4ncXc0ZQJEWiL29MUatYPdaZioNFJmXA172+vHOhpK252+Yb5hnp3k4aFINPM8dcbPlZ9EjxT1Lz1mcSzO3eUCKz4s2isbDeM6UA/vcBPCUJV6xSqTd5WZw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=peXwcfq24eAMODaWFHYYRbuRqjpmR30FR0l51gPg/UE=; b=X0fw1p73TogabWrA+39SfWArDqyDFOy8pXOJq+AZ7W2iWhS6BTs6m2Ru53pW9Ptl07xG2Sk3J66MKYrLYM9Zfrww3ZgZWZS8Vr713IU8PspTy/OeTcPwwmkecjDBdZQfQi/XGKM+n37dXkMqfplAgD0/tauLhYqgTXOPkhPOXiL0KsOXVEKAdiRtDcoZ6r62JDQFCy4fh403jZrjB5ShNzEuPYj1rGwd7XhtLSMnHFRRX3sZjLKwisliPrmj23ATc+saaSp8CbGgXkF1qLtBvXPh8iKzmJTzZww6btpJiQLKkTxlJhKCTt68FYChkHrM48AI8Bn1EPCwRHacARvfuQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none 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=peXwcfq24eAMODaWFHYYRbuRqjpmR30FR0l51gPg/UE=; b=g9x4ow3r+m54OtZVOJjR9g84VEU0OMnEm0YsSAzTCWNL8vl7R5vmvm4WxrGGKHgzgAB5UHRciWCyzCCVNceG9x4dGKW1aGZtw6qWZTbYRPs66Wg0OHz+HFdKXE5EY5AnNIkqKxgR+X3OG9f2Zw3LtB7td34dlW/X6WZhnlQDqic= Authentication-Results: amd.com; dkim=none (message not signed) header.d=none;amd.com; dmarc=none action=none header.from=amd.com; Received: from SN1PR12MB2560.namprd12.prod.outlook.com (2603:10b6:802:26::19) by SN1PR12MB2525.namprd12.prod.outlook.com (2603:10b6:802:29::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3805.17; Fri, 29 Jan 2021 00:36:27 +0000 Received: from SN1PR12MB2560.namprd12.prod.outlook.com ([fe80::8c0e:9a64:673b:4fff]) by SN1PR12MB2560.namprd12.prod.outlook.com ([fe80::8c0e:9a64:673b:4fff%5]) with mapi id 15.20.3805.019; Fri, 29 Jan 2021 00:36:27 +0000 Subject: [kvm-unit-tests PATCH v2 2/2] x86: svm: Add SPEC_CTRL feature test From: Babu Moger Cc: kvm@vger.kernel.org Date: Thu, 28 Jan 2021 18:36:25 -0600 Message-ID: <161188058573.28708.18210438890249970432.stgit@bmoger-ubuntu> In-Reply-To: <161188044937.28708.9182196001493811398.stgit@bmoger-ubuntu> References: <161188044937.28708.9182196001493811398.stgit@bmoger-ubuntu> User-Agent: StGit/0.17.1-dirty X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: SN7PR04CA0199.namprd04.prod.outlook.com (2603:10b6:806:126::24) To SN1PR12MB2560.namprd12.prod.outlook.com (2603:10b6:802:26::19) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from [127.0.1.1] (165.204.77.1) by SN7PR04CA0199.namprd04.prod.outlook.com (2603:10b6:806:126::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3805.17 via Frontend Transport; Fri, 29 Jan 2021 00:36:26 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 7a5be1e0-62e8-425c-d0a4-08d8c3ede9a1 X-MS-TrafficTypeDiagnostic: SN1PR12MB2525: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7691; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: J5Bdk6Y/yISBZ/zAVFhDRfeohuj/ove6xHa+ja2ubxRSOu4jrSO3Se2KkKYzqcWdoBbaQa/zQi53IXD1NexVis094Y3yC7V9cZV2/buu/c7YTXHAvIyTJ+ZuuYbdt2kBuEC5AQ3UUDMq3+K4EgTUIXR12UC62FE8QfTtdGimM4ogRpuXP5hRppEqkN6G6NQ8YxGCbJhi0ElYYPVUdrit7EJrafiVjPGCzsELzhqbH49VQWUI/7BeUCK8adiG+Mhqn9PhDOInV6ne/luWIuJTk71Y/L26grfMYTOfGCO3gAzbMGkIz1JYVGC5LuCofqjk7FBSlzYKmPA+4GhbQSGO3GHK4hAnIF4lMDeaoHa+b9WSdr2L50gCIG6clofmGgdFJpjhlTu8x95BqsEQY4DvGfWgi4oLi/4L4xSThXLpfEqRo7uuWvmNqGlm3HMmAsAy3Xh4OjJYMKiKi8e7b22Uo4PA0j4xsVHwZXr00CS2uIIxET2gakNZzd7gTU13svSo845YhJ9INNINPfAI4bwIGA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SN1PR12MB2560.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(7916004)(396003)(346002)(39860400002)(366004)(136003)(376002)(83380400001)(2906002)(103116003)(66946007)(8936002)(8676002)(52116002)(4326008)(86362001)(66476007)(66556008)(109986005)(186003)(6486002)(478600001)(16526019)(26005)(5660300002)(33716001)(44832011)(316002)(16576012)(9686003)(956004);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?utf-8?q?Mbj+2AOVRQvHzEa7t7Ldvr6sPhHzRq?= =?utf-8?q?1WUSX86zpuK5g+xo8AYw2unvKCoZBegKj6GF+7X1B3c67FQtX7/unUTXUOwGEv7UR?= =?utf-8?q?43BzEHYzma18MKzYIGsNUO6gGUTxoGwYLECswVwfqMtj4lANt3DEbZp0N+jRZ1EmO?= =?utf-8?q?vhAxPWcJIB0yv0Z8tdabutaEbV0vuYW5Rlv/oK6SFITjnM2taN3wuFXdZup1UgfSD?= =?utf-8?q?lkkGIrCv8I3wa6ouYQfJjDOpT4BgoM1ai83Yx/KtiRZJAXj/hoLjSDyTuxb/o98mS?= =?utf-8?q?QrtP8Kt63P9VRWAkqvfkTI71yxVFmbNFRLt9aGD/l1WGxWljG0uCLeEAeYstWpPt0?= =?utf-8?q?cvSpnFxFN6xGmIH+aY+6fVjOIE/i8DnzzzOj34e+XDdUoD0z7ewn5AyAUX3onxz3C?= =?utf-8?q?RpCHOTzqA8BGPWnAzws7PxBUi28GiYpc20lS3wLbzKaso4Vcgcf6Ge5R/OW0dQ9qG?= =?utf-8?q?iYIaJK8GV2cUX39uc+FliPDpNg1EicQ/C8YxnuVTYKZe6UxO8N0tHz3wKkoTpZhww?= =?utf-8?q?r8Cvl41mRWlvOnJAn2GORrGanU/JAijNNeRLEDlYTD+mxCufIygSrzI0s26zViJgD?= =?utf-8?q?VFW9Q0Vcm/0r5aOSGc8jlwtPmUwHdSETGXY94xFqKm/ETunsIXHKZkPDTIqc0k0vU?= =?utf-8?q?i97eN3c0knL5yMWl9OJkCrB2OmCjzcNDg1ZfGTtU9DkuT2eoNahluCXami6YS7fmB?= =?utf-8?q?j/dRNBtGfmu242PUdVvIX9QYRrz0ogatyk4dwPgjWEzklrheDz+JS825g7v2vuirB?= =?utf-8?q?5UNTRqi6h/CUWeyrKoiOFIo92JaJLqXjxH7qEF3KIj0Wu5Az7U4MH3/nHV478pop9?= =?utf-8?q?KnM4VAG7NiNmrzrcZEqnFnnyi1rxJjtgASrr1RWHHKB/KSL41bNmQ2MpXAKgOL26u?= =?utf-8?q?/gtlt4D5Fv99XbYadGbI2qVoD3lZR5HirIULzi+5V7844bOOXVVbo98fd+qqWKj3h?= =?utf-8?q?4pvSZuefLxkjOz2puxvfZaY59iSsvPgdDM1tAASUU3+DWMtTeblE8TAaTcdcE9qxS?= =?utf-8?q?oHFQBMECnw2nq0YqGJ?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7a5be1e0-62e8-425c-d0a4-08d8c3ede9a1 X-MS-Exchange-CrossTenant-AuthSource: SN1PR12MB2560.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Jan 2021 00:36:27.1734 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: JZZkEDKic5UPfw3f2ZYwLTtnmJuMkJxIDsN5J/zzdUXJfFbbMwRWnUdSD6/9Wqlv X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1PR12MB2525 To: unlisted-recipients:; (no To-header on input) Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Add the SPEC_CTRL tests for SVM and make sure the settings on L2 guests does not overwrite the L1 guest's SPEC_CTRL settings. Test Method. 1. Save the L1 guests SPEC_CTRL settings(rdmsr). Normally 0. 2. Start the L2 guest 3. Change the L2 guests SPEC_CTRL settings. 4. Exit the L2 guest. 5. Verify if the settings from step #1 still holds. Signed-off-by: Babu Moger --- x86/svm_tests.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/x86/svm_tests.c b/x86/svm_tests.c index 29a0b59..2867337 100644 --- a/x86/svm_tests.c +++ b/x86/svm_tests.c @@ -2002,6 +2002,55 @@ static bool init_intercept_check(struct svm_test *test) return init_intercept; } +/* Indirect Branch Restricted Speculation(bit 0) */ +#define SPEC_CTRL_IBRS 1 +/* Single Thread Indirect Branch Predictor (STIBP)(bit 1) */ +#define SPEC_CTRL_STIBP 2 +/* Speculative Store Bypass Disable (bit 2) */ +#define SPEC_CTRL_SSBD 4 + +static bool spec_ctrl_supported(void) +{ + return this_cpu_has(X86_FEATURE_AMD_SSBD) || + this_cpu_has(X86_FEATURE_AMD_STIBP) || + this_cpu_has(X86_FEATURE_AMD_IBRS); +} + +static void spec_ctrl_prepare(struct svm_test *test) +{ + vmcb_ident(vmcb); + test->scratch = rdmsr(MSR_IA32_SPEC_CTRL); +} + +/* + * Write it twice to bypass the interception. The first write to + * SPEC_CTRL is intercepted in older kernels. + */ +static void spec_ctrl_test(struct svm_test *test) +{ + int spec_ctrl = 0; + + if (this_cpu_has(X86_FEATURE_AMD_SSBD)) + spec_ctrl |= SPEC_CTRL_SSBD; + if (this_cpu_has(X86_FEATURE_AMD_STIBP)) + spec_ctrl |= SPEC_CTRL_STIBP; + if (this_cpu_has(X86_FEATURE_AMD_IBRS)) + spec_ctrl |= SPEC_CTRL_IBRS; + + wrmsr(MSR_IA32_SPEC_CTRL, spec_ctrl); + wrmsr(MSR_IA32_SPEC_CTRL, spec_ctrl); +} + +static bool spec_ctrl_finished(struct svm_test *test) +{ + return vmcb->control.exit_code == SVM_EXIT_VMMCALL; +} + +static bool spec_ctrl_check(struct svm_test *test) +{ + return test->scratch == rdmsr(MSR_IA32_SPEC_CTRL); +} + #define TEST(name) { #name, .v2 = name } /* @@ -2492,6 +2541,9 @@ struct svm_test svm_tests[] = { { "svm_init_intercept_test", smp_supported, init_intercept_prepare, default_prepare_gif_clear, init_intercept_test, init_intercept_finished, init_intercept_check, .on_vcpu = 2 }, + { "SPEC_CTRL", spec_ctrl_supported, spec_ctrl_prepare, + default_prepare_gif_clear, spec_ctrl_test, + spec_ctrl_finished, spec_ctrl_check }, TEST(svm_cr4_osxsave_test), TEST(svm_guest_state_test), TEST(svm_vmrun_errata_test),