Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp5289300yba; Wed, 8 May 2019 10:44:38 -0700 (PDT) X-Google-Smtp-Source: APXvYqz7o/dhD4jHU0Hlpj9wZcnTCD4qgCAMs8m8ylyvOXvcGfVppubjQCjRbBWPeBsjUHF8eMsJ X-Received: by 2002:a62:1a51:: with SMTP id a78mr40941150pfa.133.1557337478471; Wed, 08 May 2019 10:44:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557337478; cv=none; d=google.com; s=arc-20160816; b=xxCuE4sxsyAgx7cujWiieIoy+RasFKBjkn6QOfGcHU8h6b3qml5g29GpirsNiG1sy9 G/rWU9pctxOpCEtNgO9Xz50bUq43B+MtarHa1PkBv8611EJukOHx/n7RzhBVpWUR+IDS 1tuEHrhj6C483rw5Wd2adIvJqEhT4urwRrovgW1/rs3kXsTOHNTIBRqngRj+g4Z+Wdw2 duMc9L/mb0pQXgV1nJtDWyPb9gPl62tCHytAoobxRifV7NKuwPsmcw3lyG5zVviMaeqM Z9jwQY47qsXXhEa2aHIVB4vMUNz+zniQ4fpRng5RNvaF89Gud3GKvKCDeK7QI6DryGPi 2rSA== 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; bh=sFNXeoj5VSTs2wgVxlm7rC7QOxoLc6G2loYXKuB7a6o=; b=tFGQjZbalP4K+IDk68LzosxTXTB03Ko76T+mB0zuk7M9Mf1ZeYKW0WrXEEXdDnRx0w 3xVTMsaL6ZPFErFYu4WLOa8SY2Uaqv0xs5wvTKIVVSx0zRwA9OLoelMHfYFYf64cNuMA H7H0kAGl5WBFfB1JhoORFOh9LrtJhzoibs1YvJAr404cR1FFCQCP/XMhnRIv5Qo6jE7o J9+NpcV8i4JX+7jLInlNYSxDHB55rZCuR7i/dpoXfrE3ex+dNrD4ccsIjsfemz0x1Mnm knVua/YVXBJgeRfB7bTtbcknP0Y5cPmHagJNYVptvoC8Og3izyjClkzOF0F7kJiGaUSn 2yeQ== ARC-Authentication-Results: i=1; mx.google.com; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l11si24577719plb.370.2019.05.08.10.44.22; Wed, 08 May 2019 10:44:38 -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; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727873AbfEHOru (ORCPT + 99 others); Wed, 8 May 2019 10:47:50 -0400 Received: from mga06.intel.com ([134.134.136.31]:57660 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728425AbfEHOov (ORCPT ); Wed, 8 May 2019 10:44:51 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 08 May 2019 07:44:50 -0700 X-ExtLoop1: 1 Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga006.fm.intel.com with ESMTP; 08 May 2019 07:44:43 -0700 Received: by black.fi.intel.com (Postfix, from userid 1000) id 78815BD3; Wed, 8 May 2019 17:44:30 +0300 (EEST) From: "Kirill A. Shutemov" 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: [PATCH, RFC 36/62] acpi/hmat: Evaluate topology presented in ACPI HMAT for MKTME Date: Wed, 8 May 2019 17:43:56 +0300 Message-Id: <20190508144422.13171-37-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190508144422.13171-1-kirill.shutemov@linux.intel.com> References: <20190508144422.13171-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 From: Alison Schofield MKTME, Multi-Key Total Memory Encryption, is a feature on Intel platforms. The ACPI HMAT table can be used to verify that the platform topology is safe for the usage of MKTME. The kernel must be capable of programming every memory controller on the platform. This means that there must be a CPU online, in the same proximity domain of each memory controller. Signed-off-by: Alison Schofield Signed-off-by: Kirill A. Shutemov --- drivers/acpi/hmat/hmat.c | 54 ++++++++++++++++++++++++++++++++++++++++ include/linux/acpi.h | 1 + 2 files changed, 55 insertions(+) diff --git a/drivers/acpi/hmat/hmat.c b/drivers/acpi/hmat/hmat.c index 38e3341f569f..936a403c0694 100644 --- a/drivers/acpi/hmat/hmat.c +++ b/drivers/acpi/hmat/hmat.c @@ -677,3 +677,57 @@ bool acpi_hmat_present(void) acpi_put_table(tbl); return true; } + +static int mktme_parse_proximity_domains(union acpi_subtable_headers *header, + const unsigned long end) +{ + struct acpi_hmat_proximity_domain *mar = (void *)header; + struct acpi_hmat_structure *hdr = (void *)header; + + const struct cpumask *tmp_mask; + + if (!hdr || hdr->type != ACPI_HMAT_TYPE_PROXIMITY) + return -EINVAL; + + if (mar->header.length != sizeof(*mar)) { + pr_warn("MKTME: invalid header length in HMAT\n"); + return -1; + } + /* + * Require a valid processor proximity domain. + * This will catch memory only physical packages with + * no processor capable of programming the key table. + */ + if (!(mar->flags & ACPI_HMAT_PROCESSOR_PD_VALID)) { + pr_warn("MKTME: no valid processor proximity domain\n"); + return -1; + } + /* Require an online CPU in the processor proximity domain. */ + tmp_mask = cpumask_of_node(pxm_to_node(mar->processor_PD)); + if (!cpumask_intersects(tmp_mask, cpu_online_mask)) { + pr_warn("MKTME: no online CPU in proximity domain\n"); + return -1; + } + return 0; +} + +/* Returns true if topology is safe for MKTME key creation */ +bool mktme_hmat_evaluate(void) +{ + struct acpi_table_header *tbl; + bool ret = true; + acpi_status status; + + status = acpi_get_table(ACPI_SIG_HMAT, 0, &tbl); + if (ACPI_FAILURE(status)) + return -EINVAL; + + if (acpi_table_parse_entries(ACPI_SIG_HMAT, + sizeof(struct acpi_table_hmat), + ACPI_HMAT_TYPE_PROXIMITY, + mktme_parse_proximity_domains, 0) < 0) { + ret = false; + } + acpi_put_table(tbl); + return ret; +} diff --git a/include/linux/acpi.h b/include/linux/acpi.h index fe3ad4ca5bb3..82b270dfb785 100644 --- a/include/linux/acpi.h +++ b/include/linux/acpi.h @@ -1341,6 +1341,7 @@ acpi_platform_notify(struct device *dev, enum kobject_action action) #ifdef CONFIG_X86_INTEL_MKTME extern bool acpi_hmat_present(void); +extern bool mktme_hmat_evaluate(void); #endif /* CONFIG_X86_INTEL_MKTME */ #endif /*_LINUX_ACPI_H*/ -- 2.20.1