Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp6267412ybi; Wed, 31 Jul 2019 11:13:11 -0700 (PDT) X-Google-Smtp-Source: APXvYqwyDPMOl9ovs3VPMfu0qBD6Zskb1T/T657wPKWYR1XL8E0uG74zdmpLhoz9Onih/O2YjHy5 X-Received: by 2002:a62:82c1:: with SMTP id w184mr49617746pfd.8.1564596790946; Wed, 31 Jul 2019 11:13:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564596790; cv=none; d=google.com; s=arc-20160816; b=uuY6lyK+qRNe+j4JOVbAC90BZKK7mFCMi2O1FyPR/yeqyRIVGgepNU+5HXXGqNz/Le w92ojg/0U6XXsRiIWc+ojuOecdmFBvEa5qP0zFuF9V30kIs+G/2UmGRGr0BWmgR35T7C 04eZ/3y4OZjXdTikm/mMFlHquhFx9PLhpCf1/ReIDWwYV9ayhYEggYNO2vG6VNx96N62 ER71c0ejmLqxsO52sNJ0P3zNOIwOeWrfSx76N5eyum8Q/jSxcUryl5+9pBRvq2GgXRz9 5KGEnqUP4wF93Q/cq+V1V3s87o/9ezJa50AEDX0eO3buytkwAEdEJzIF/fU65Mqzsjg1 6wtA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=AKmba4vf/ZPJ1ANSLVq0BszaZ5EHEw0+rluolW4cNw8=; b=IA3tigyqD78JkLKDkcUywB7pSJ0QXRpBId5y3fJlu+jJUEGT8BQ5HeF7ie9Zn/pGQ6 C7Gjcw5EFYa7DbB4uMlcVxSlx51GdMXMEZnNq9GTQs3LpJX65BoaxC8qVXvAd96YLJfP ofqGIdPg5Bi0g5WjwFu4ziAK2RHetNz0dP7mJqt2TxCvOEjQ4hDEjem2YlPQg7OJTwfO MUwScmJHPWGh7aHgrOYISHromKYX3cXNMLr1hCKJqQgjGeXy/4LZIN80Mfykon9jDfXf bfQIoj8Njh6wgdZR987OjBQNNFXLk5rG7Jyva99Gkau07zihVyvEaW8s3E2kmGNn+eeL PQUw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@shutemov-name.20150623.gappssmtp.com header.s=20150623 header.b=bo4uajak; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f4si32804183plb.38.2019.07.31.11.12.55; Wed, 31 Jul 2019 11:13:10 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@shutemov-name.20150623.gappssmtp.com header.s=20150623 header.b=bo4uajak; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388705AbfGaPI4 (ORCPT + 99 others); Wed, 31 Jul 2019 11:08:56 -0400 Received: from mail-ed1-f65.google.com ([209.85.208.65]:37858 "EHLO mail-ed1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388655AbfGaPIe (ORCPT ); Wed, 31 Jul 2019 11:08:34 -0400 Received: by mail-ed1-f65.google.com with SMTP id w13so66061343eds.4 for ; Wed, 31 Jul 2019 08:08:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=shutemov-name.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=AKmba4vf/ZPJ1ANSLVq0BszaZ5EHEw0+rluolW4cNw8=; b=bo4uajak/nrY2caCviEQ5+13QOOruKSVot/3mpFhnPUptXe8wQiI2pcggx1UFzkc+6 p2enaIZE1WQ0nur+4ojLwMmfA3mnX2TiIzq/vOH4fPX7tFzT7bwdjkaqQeNcebCtaRK2 YncpJbM19Mg+hJ0PgQoeGEunjUw6+YNXDPaFZKrtGi1suwJGSQ25iciPmh/QlVLzh68/ dFKIA5VbuTbQiB1EFWVSIRHLZOqQe4aOiF5cdzltkeIKMO93kV8/XGQs8282Dvs4jNAK r4taKwQzR2Fb1WQzuTvnWB10NdFL0EW3LOi1Sx3I7icX3Xv1+3uBneHoWO18TZnuPiw4 Xl9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=AKmba4vf/ZPJ1ANSLVq0BszaZ5EHEw0+rluolW4cNw8=; b=fz5BJ/zs41QMoX6Mlald7bs1o5d0zzvwcDLAkfv/VzB3/QTv6/ef1ZPZo/WLDKeyPW Q8+OGtzI6wOPH7Rc0Cg53k5pUKV/RyLBDbQ62OqBA9TgjCFTg+r4LK0MecI7+6kjdxFR u7f3eg0t++IZ3DvvVEEGpsPj6Mp0auvQP22u2zuPRwp1SvbUZT5qzqBR47zRQD9QTaR8 DSQBn6Kcdx6wkZaNMJUnZbfu3qPsgp4TMh8Hr3OzQ+6q5nXWya82efeiECjHLzt98ddH wQlRD9rK2RXbcBWZdTlZincVVHM5LRt8LNavsEe6ZNtkJHtoHkoTJQBYzu2p2WETtcSX k4ow== X-Gm-Message-State: APjAAAUO5LHBvUzEJ7sCT6M8ddzPnuc4tRA5Aj7Sn1AEYQiuFdAfJERB JtTMydB69Gd2HtjNc/SyD48= X-Received: by 2002:a17:906:b6c6:: with SMTP id ec6mr96502459ejb.183.1564585711755; Wed, 31 Jul 2019 08:08:31 -0700 (PDT) Received: from box.localdomain ([86.57.175.117]) by smtp.gmail.com with ESMTPSA id w24sm17512065edb.90.2019.07.31.08.08.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 31 Jul 2019 08:08:30 -0700 (PDT) From: "Kirill A. Shutemov" X-Google-Original-From: "Kirill A. Shutemov" Received: by box.localdomain (Postfix, from userid 1000) id 5E4AA1048A3; Wed, 31 Jul 2019 18:08:17 +0300 (+03) To: Andrew Morton , x86@kernel.org, Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , Borislav Petkov , Peter Zijlstra , Andy Lutomirski , David Howells Cc: Kees Cook , Dave Hansen , Kai Huang , Jacob Pan , Alison Schofield , linux-mm@kvack.org, kvm@vger.kernel.org, keyrings@vger.kernel.org, linux-kernel@vger.kernel.org, "Kirill A. Shutemov" Subject: [PATCHv2 51/59] x86/mm: Disable MKTME on incompatible platform configurations Date: Wed, 31 Jul 2019 18:08:05 +0300 Message-Id: <20190731150813.26289-52-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190731150813.26289-1-kirill.shutemov@linux.intel.com> References: <20190731150813.26289-1-kirill.shutemov@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Icelake Server requires additional check to make sure that MKTME usage is safe on Linux. Kernel needs a way to access encrypted memory. There can be different approaches to this: create a temporary mapping to access the page (using kmap() interface), modify kernel's direct mapping on allocation of encrypted page. In order to minimize runtime overhead, the Linux MKTME implementation uses multiple direct mappings, one per-KeyID. Kernel uses the direct mapping that is relevant for the page at the moment. Icelake Server in some configurations doesn't allow a page to be mapped with multiple KeyIDs at the same time. Even if only one of KeyIDs is actively used. It conflicts with the Linux MKTME implementation. OS can check if it's safe to map the same with multiple KeyIDs by examining bit 8 of MSR 0x6F. If the bit is set we cannot safely use MKTME on Linux. The user can disable the Directory Mode in BIOS setup to get the platform into Linux-compatible mode. Signed-off-by: Kirill A. Shutemov --- arch/x86/kernel/cpu/intel.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c index 9852580340b9..3583bea0a5b9 100644 --- a/arch/x86/kernel/cpu/intel.c +++ b/arch/x86/kernel/cpu/intel.c @@ -19,6 +19,7 @@ #include #include #include +#include #ifdef CONFIG_X86_64 #include @@ -560,6 +561,16 @@ static void detect_vmx_virtcap(struct cpuinfo_x86 *c) #define TME_ACTIVATE_CRYPTO_KNOWN_ALGS TME_ACTIVATE_CRYPTO_AES_XTS_128 +#define MSR_ICX_MKTME_STATUS 0x6F +#define MKTME_ALIASES_FORBIDDEN(x) (x & BIT(8)) + +/* Need to check MSR_ICX_MKTME_STATUS for these CPUs */ +static const struct x86_cpu_id mktme_status_msr_ids[] = { + { X86_VENDOR_INTEL, 6, INTEL_FAM6_ICELAKE_X }, + { X86_VENDOR_INTEL, 6, INTEL_FAM6_ICELAKE_XEON_D }, + {} +}; + /* Values for mktme_status (SW only construct) */ #define MKTME_ENABLED 0 #define MKTME_DISABLED 1 @@ -593,6 +604,17 @@ static void detect_tme(struct cpuinfo_x86 *c) return; } + /* Icelake Server quirk: do not enable MKTME if aliases are forbidden */ + if (x86_match_cpu(mktme_status_msr_ids)) { + u64 status; + rdmsrl(MSR_ICX_MKTME_STATUS, status); + + if (MKTME_ALIASES_FORBIDDEN(status)) { + pr_err_once("x86/tme: Directory Mode is enabled in BIOS\n"); + mktme_status = MKTME_DISABLED; + } + } + if (mktme_status != MKTME_UNINITIALIZED) goto detect_keyid_bits; -- 2.21.0