From patchwork Wed Sep 27 10:42:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 13400650 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 4C116E810C1 for ; Wed, 27 Sep 2023 10:43:04 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.608872.947646 (Exim 4.92) (envelope-from ) id 1qlS0M-0008Rd-IE; Wed, 27 Sep 2023 10:42:54 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 608872.947646; Wed, 27 Sep 2023 10:42:54 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qlS0M-0008RW-F4; Wed, 27 Sep 2023 10:42:54 +0000 Received: by outflank-mailman (input) for mailman id 608872; Wed, 27 Sep 2023 10:42:53 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qlS0L-0008Ha-IC for xen-devel@lists.xenproject.org; Wed, 27 Sep 2023 10:42:53 +0000 Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-he1eur04on2075.outbound.protection.outlook.com [40.107.7.75]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 9b765daa-5d22-11ee-9b0d-b553b5be7939; Wed, 27 Sep 2023 12:42:51 +0200 (CEST) Received: from AS8PR04MB8788.eurprd04.prod.outlook.com (2603:10a6:20b:42f::21) by AS8PR04MB9126.eurprd04.prod.outlook.com (2603:10a6:20b:449::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6838.21; Wed, 27 Sep 2023 10:42:22 +0000 Received: from AS8PR04MB8788.eurprd04.prod.outlook.com ([fe80::afae:3fda:c84d:bcdc]) by AS8PR04MB8788.eurprd04.prod.outlook.com ([fe80::afae:3fda:c84d:bcdc%7]) with mapi id 15.20.6838.016; Wed, 27 Sep 2023 10:42:22 +0000 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 9b765daa-5d22-11ee-9b0d-b553b5be7939 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LGbrm3vrVISwmdRh5PfDZDO6YsaiAhEP3apU2/5y2/rh5h59wxNLzQGUtFttmfr2xnAeyZMBXoHOwQeaooqxdxXNCjaiaRn+5eLT295NL35LsL8cS4ZQmC1qBpCIlM4zil9ZkAkYnaPonUPi8Gpyd+/6ph6CgIrXye/qy7XWcUvMMhCse5I3t1w7JtBB7QI0lgIbq1PLDPjoYzJAlupJVSublBy3Kt+iwKMteRUF7ltngmF4q5n9nlm5PHTxYPORNn2RwZZszFXjDOMOvHbpMXc/uO5uh/IcupGn090e0/00842zYN+rHHaERsqUatp/lfG/dVUzbLeozK4jj3YlVA== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=omkVjQfeBv81Qnb7mWu3p+UblKFRDxvjBwxiZYEpSf4=; b=IQtXE4qknaAhfI8qj9PMhUHTWuQsiAhV6rjRxFx4YDkRy5q98iuR1sqZ4rGKaEy+Ald1dSr+jKNEalf7REfSMS/jI4rLD7jlKo6yHz0UxPLjRd4DQzPXSjf3Vu0JLztS3jp+teUDgJtY4Ld/+s+DED3VA0V9U+EQq/ngORmiJJcWHPlf2a9Y54PCmQotuYBCbRex2hD1B6QE1dFrf5Hilhh7Nwg9FHaOOj+rFeBcYRojEQKhNI7Vdl6/tmVVzFKBph/3jySyuVrAKGkaA9hciNtqQUcGXI2j1TzYCsiPIf9UaFuN1fFxNIPWhBi+a9hXzdkHk1PUm+rcWM/6OIsdAg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=omkVjQfeBv81Qnb7mWu3p+UblKFRDxvjBwxiZYEpSf4=; b=E+odiOI2uhLpoz2VSR2AnsRx58t0EbIOMOT9D8nRKDcW+a1FD5kN1hOqPiaHz95O5q7rnnYIl3Vv65GdPbdWBHfbPqGasw3xpd8iD8PFI8/mSGsgLuFWA6iNfBezqizmQ8/QjYeQtvqkXKO4wG0ves7XTuy7MVwUbQ8QP+pH+Ca6z8rwksOS2jb6kBvHhNHV4EI0FKA3wCw/Xl6dHkOU8mOSTxh+zsUzRoK605kio0IL69RSCVGSAkjZgyNUxXeR3gPkh0TT7EQyUY2flgMoc3tnsGyosj8f0zJacLGjRYFBdWgn+oK0xYfOpaLUOArWp5z6T7I8ModzgZUO+jQbdg== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com; Message-ID: <0846e69c-22ec-0cc2-de5b-b895ff20e860@suse.com> Date: Wed, 27 Sep 2023 12:42:20 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.15.1 From: Jan Beulich Subject: [PATCH v3 for-4.18?] x86: support data operand independent timing mode To: "xen-devel@lists.xenproject.org" Cc: Andrew Cooper , George Dunlap , Julien Grall , Stefano Stabellini , Wei Liu , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Demi Marie Obenour , Henry Wang Content-Language: en-US X-ClientProxiedBy: FR2P281CA0161.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:99::20) To AS8PR04MB8788.eurprd04.prod.outlook.com (2603:10a6:20b:42f::21) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8PR04MB8788:EE_|AS8PR04MB9126:EE_ X-MS-Office365-Filtering-Correlation-Id: 0e0ade53-2782-48b9-120c-08dbbf466e3c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: xZovxUWyveolH0v91Pku/tag2f0p341T1jna6bSgkdsklh6rzAdQmCDy5cJty7m1Vz/ZhNNv5doKj+7JDmVS2C4GtlhxY7m79iJpm+ZQDrHXHyiHuAyF93ea56DA0ucHrwjNDT5Y8ZblDlEk3/K7Pxz9gymtkkXJAEKovjELtywH3bi5L2HvoNJxcCUjBT4mLgWu6hdi5FqPj7JG0eO/m+9l0iYnIKxVUqGDOPiH4RDpcd+x7WHoPyMdF7bYk5qNlVl79e+Ys043r0G9f4laLyn9Xq9DJPKODVVaMYZEusZv6uHw1dZBnXvKJB7DQQKhrLxRfm2gExKc5EnE5cngxHDhoEZtozldUzsOYHm+FD0qnQqPp0TTbBkkSVyjcuxPxe4svby6rnM0ysQkbzsbJHJJUlknjqG+W+E4fN6GwPCiSsaFtYVOnbArs23+HSJwTGE/U15mFKqaUaMDblbBVmkMdPF6buHsKRxm6nf0wmjulggf81gtLMlmq0rPo4TAVlvrDB7UgMoz4XiF7jghgAKtzkL/plolCcGRo5k7E9A2QuU83snxos9SsHvVf7Va5KG6yzav8U4jFCN9Q3PhZIGMfBPY/BMGJFYXPuL9cDEXkl/PmoHMMqXJNOphudYB7RYQzEShW2KY6GjW0QJvIw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AS8PR04MB8788.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(376002)(39860400002)(366004)(136003)(396003)(346002)(230922051799003)(186009)(451199024)(1800799009)(316002)(83380400001)(2616005)(26005)(54906003)(66946007)(6916009)(66476007)(66556008)(41300700001)(8936002)(8676002)(4326008)(6486002)(6506007)(6512007)(478600001)(966005)(2906002)(31696002)(36756003)(86362001)(38100700002)(5660300002)(31686004)(45980500001)(43740500002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?3RQi4q7wGyZ7W2W1NuuH8SBQ1A9T?= =?utf-8?q?mbUcnviSriCAv/aQjID67vsMf2P8BnbFMhB0/FIJlZFf0EXIlhTuQ8rsVl8xCNjPJ?= =?utf-8?q?qj5ocUmYEQRb9u73pernD/ADcScy+uj9+CjAF0ZQXPQojVQjdmuicD7j0ruSkGd3f?= =?utf-8?q?4w51xbwBEZQRcqEIGC4geQFXHJ+y8ciGBbqhW8mdIjSPeXpo5gV/IOKD/SEDm4Hos?= =?utf-8?q?O1Y8rL0XPJmWkUFvXrUTdzPlvUWMFMqvt8NtAwQHANY00dCEEMyViH1PLUw0YNvvg?= =?utf-8?q?7V8bDiEMR8sbXOv9d3aHzUg3TmRnXhrmeNC6Rn7dRm762+RO8jbXuCXbqUG0Z72nV?= =?utf-8?q?sAHzpH3hOvZOq8WLXoW0Rq7A19vWWpada3pCaT8ITzses3WJVllPLS+tkX+XJRtvB?= =?utf-8?q?vCdXiip9IRXwylDWuhP5UyvDNT2l3qNRcH8nyC6ss+lVkgXz6sK+GN3A1hbfrXF6d?= =?utf-8?q?zWqiF2xTat4tQH5rjLBzyA03H+xJZK0ZDc+zM8QCHQs903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fjDl8h2YxHgG0y9wa2zWOPdGx8KeAlGkE1qSTBDsr?= =?utf-8?q?rchMMApMCvB/MWvXgdNKkp8rJt6vwQiekSWl+VzNcaqz9jFmGz5BaYHPi8ijMJmvo?= =?utf-8?q?dlMyE5a51KGJoF1lpb06xFuvor0CkWMP1QsrdscjJ/nCULXLiD0jW4diBngxGxlRZ?= =?utf-8?q?ZLBvDxMYl/Na?= X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0e0ade53-2782-48b9-120c-08dbbf466e3c X-MS-Exchange-CrossTenant-AuthSource: AS8PR04MB8788.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Sep 2023 10:42:22.2062 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: f7a17af6-1c5c-4a36-aa8b-f5be247aa4ba X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: XhA7vOFcv8UP2hl56UY60U5oWGR7E1LsWxsSOe/lSJ+ZLmwtTgbbrI/1EaNFVPon3x7hqdu/XW1BJZoDxsW1hQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR04MB9126 [1] specifies a long list of instructions which are intended to exhibit timing behavior independent of the data they operate on. On certain hardware this independence is optional, controlled by a bit in a new MSR. Provide a command line option to control the mode Xen and its guests are to operate in, with a build time control over the default. Longer term we may want to allow guests to control this. Since Arm64 supposedly also has such a control, put command line option and Kconfig control in common files. [1] https://www.intel.com/content/www/us/en/developer/articles/technical/software-security-guidance/best-practices/data-operand-independent-timing-isa-guidance.html Requested-by: Demi Marie Obenour Signed-off-by: Jan Beulich Release-acked-by: Henry Wang --- This may be viewed as a new feature, and hence be too late for 4.18. It may, however, also be viewed as security relevant, which is why I'd like to propose to at least consider it. Slightly RFC, in particular for whether the Kconfig option should default to Y or N. I would have wanted to invoke setup_doitm() from cpu_init(), but that works only on the BSP. On APs cpu_init() runs before ucode loading. Plus recheck_cpu_features() invoking identify_cpu() takes care of the BSP during S3 resume. --- v3: Extend command line doc. Add changelog entry. v2: Introduce and use cpu_has_doitm. Add comment "borrowed" from the XenServer patch queue patch providing similar functionality. Re-base. --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,8 @@ The format is based on [Keep a Changelog - Add Intel Hardware P-States (HWP) cpufreq driver. - On Arm, experimental support for dynamic addition/removal of Xen device tree nodes using a device tree overlay binary (.dtbo). + - On x86, support for enforcing system-wide operation in Data Operand + Independent Timing Mode. ### Removed - On x86, the "pku" command line option has been removed. It has never --- a/docs/misc/xen-command-line.pandoc +++ b/docs/misc/xen-command-line.pandoc @@ -788,6 +788,16 @@ Specify the size of the console debug tr additionally a trace buffer of the specified size is allocated per cpu. The debug trace feature is only enabled in debugging builds of Xen. +### dit (x86/Intel) +> `= ` + +> Default: `CONFIG_DIT_DEFAULT` + +Specify whether Xen and guests should operate in Data Independent Timing +mode. Note that enabling this option cannot guarantee anything beyond what +underlying hardware guarantees (with, where available and known to Xen, +respective tweaks applied). + ### dma_bits > `= ` --- a/xen/arch/x86/Kconfig +++ b/xen/arch/x86/Kconfig @@ -15,6 +15,7 @@ config X86 select HAS_ALTERNATIVE select HAS_COMPAT select HAS_CPUFREQ + select HAS_DIT select HAS_EHCI select HAS_EX_TABLE select HAS_FAST_MULTIPLY --- a/xen/arch/x86/cpu/common.c +++ b/xen/arch/x86/cpu/common.c @@ -204,6 +204,28 @@ void ctxt_switch_levelling(const struct alternative_vcall(ctxt_switch_masking, next); } +static void setup_doitm(void) +{ + uint64_t msr; + + if ( !cpu_has_doitm ) + return; + + /* + * We don't currently enumerate DOITM to guests. As a conseqeuence, guest + * kernels will believe they're safe even when they are not. + * + * For now, set it unilaterally. This prevents otherwise-correct crypto + * code from becoming vulnerable to timing sidechannels. + */ + + rdmsrl(MSR_UARCH_MISC_CTRL, msr); + msr |= UARCH_CTRL_DOITM; + if ( !opt_dit ) + msr &= ~UARCH_CTRL_DOITM; + wrmsrl(MSR_UARCH_MISC_CTRL, msr); +} + bool opt_cpu_info; boolean_param("cpuinfo", opt_cpu_info); @@ -589,6 +611,8 @@ void identify_cpu(struct cpuinfo_x86 *c) mtrr_bp_init(); } + + setup_doitm(); } /* leaf 0xb SMT level */ --- a/xen/arch/x86/include/asm/cpufeature.h +++ b/xen/arch/x86/include/asm/cpufeature.h @@ -201,6 +201,7 @@ static inline bool boot_cpu_has(unsigned #define cpu_has_if_pschange_mc_no boot_cpu_has(X86_FEATURE_IF_PSCHANGE_MC_NO) #define cpu_has_tsx_ctrl boot_cpu_has(X86_FEATURE_TSX_CTRL) #define cpu_has_taa_no boot_cpu_has(X86_FEATURE_TAA_NO) +#define cpu_has_doitm boot_cpu_has(X86_FEATURE_DOITM) #define cpu_has_fb_clear boot_cpu_has(X86_FEATURE_FB_CLEAR) #define cpu_has_rrsba boot_cpu_has(X86_FEATURE_RRSBA) #define cpu_has_gds_ctrl boot_cpu_has(X86_FEATURE_GDS_CTRL) --- a/xen/common/Kconfig +++ b/xen/common/Kconfig @@ -41,6 +41,9 @@ config HAS_COMPAT config HAS_DEVICE_TREE bool +config HAS_DIT # Data Independent Timing + bool + config HAS_EX_TABLE bool @@ -175,6 +178,18 @@ config SPECULATIVE_HARDEN_GUEST_ACCESS endmenu +config DIT_DEFAULT + bool "Data Independent Timing default" + depends on HAS_DIT + help + Hardware often surfaces instructions the timing of which is dependent + on the data they process. Some of these instructions may be used in + timing sensitive environments, e.g. cryptography. When such + instructions exist, hardware may further surface a control allowing + to make the behavior of such instructions independent of the data + they act upon. Choose the default here for when no "dit" command line + option is present. + config HYPFS bool "Hypervisor file system support" default y --- a/xen/common/kernel.c +++ b/xen/common/kernel.c @@ -28,6 +28,11 @@ CHECK_feature_info; enum system_state system_state = SYS_STATE_early_boot; +#ifdef CONFIG_HAS_DIT +bool __ro_after_init opt_dit = IS_ENABLED(CONFIG_DIT_DEFAULT); +boolean_param("dit", opt_dit); +#endif + static xen_commandline_t saved_cmdline; static const char __initconst opt_builtin_cmdline[] = CONFIG_CMDLINE; --- a/xen/include/xen/param.h +++ b/xen/include/xen/param.h @@ -184,6 +184,8 @@ extern struct param_hypfs __paramhypfs_s string_param(_name, _var); \ string_runtime_only_param(_name, _var) +extern bool opt_dit; + static inline void no_config_param(const char *cfg, const char *param, const char *s, const char *e) {