Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp6110025ybi; Wed, 31 Jul 2019 08:30:11 -0700 (PDT) X-Google-Smtp-Source: APXvYqzvFzlRIGqyGaVhgm22ysWjSdBpRi8tHFDedrkIV8j18pFFYn87zLaWMN+y97TyGDZas1TZ X-Received: by 2002:a17:902:e6:: with SMTP id a93mr120730849pla.175.1564587011361; Wed, 31 Jul 2019 08:30:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564587011; cv=none; d=google.com; s=arc-20160816; b=OXSHxDH/yl0Z5ehW80qFqgmceObmQQKubLIxKA0Jup5SLqputok975JvqfQz/EAeBl DiVUt2cyZelUguwe40LVdq48vIL02kyEkg4ves6SmPqJrEBIVekqq9K393QlO/7TzYHy gwul3LO/SFqFU0ip2VtWPFb2ccji2WwhaGnOHP4A1fguPcs3YJTTLvpFNkIJ2ZQb09oJ kLrj6Laa5TJW9bf8K2zmX1SH8Zr+7aIqjdihkrxUAEuiN+xe0Lp7TWKHqQ+3IYDh6Mdg NR09UlkqAaY3YaOjSB/u53SDjPtOoJDnj4I9htjhfBtGbZeUTKSs1kMNIjPmV5Rym23b oGYw== 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=0SvRw1bdF/wj1/uPaALpB1mJItIzSwaE2+8pgarmj/0=; b=MDNB5Dn/ER/TMVi5hNxhBx2kImx7jbAcWEiwgjEel+MCpZ0RPtZFQjSGlcyMFFxQu+ qoVHINpwaCVioro/9kaYvNnNGEYJwwu5pl/tuYuSOEA6xROKYmz0c4DLc4uvZdOy6rj6 gLZfSOg2eW3lVYx0j6laXb72YBZdFFe6lbQBK1/ohMKLSeg8Py6Np+nuzBcPd1Kz77ia jK/KCUbGfZ+v3O46yD5ukTjhKDi4tyTg1JOcEvrakAZDMCVultgkkIozvyOY2B0bWF2/ RvfrVjQPmBjsnUEQbkvSB0leIFqP5zS1t0JoYR3HNbre00s0/D+35xDQPHBejTIbmobO 6rsw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@shutemov-name.20150623.gappssmtp.com header.s=20150623 header.b=K8GSlHVy; 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 s62si1736766pjc.75.2019.07.31.08.29.55; Wed, 31 Jul 2019 08:30:11 -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=K8GSlHVy; 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 S1729706AbfGaPUW (ORCPT + 99 others); Wed, 31 Jul 2019 11:20:22 -0400 Received: from mail-ed1-f66.google.com ([209.85.208.66]:40472 "EHLO mail-ed1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729722AbfGaPTu (ORCPT ); Wed, 31 Jul 2019 11:19:50 -0400 Received: by mail-ed1-f66.google.com with SMTP id k8so66032778eds.7 for ; Wed, 31 Jul 2019 08:19:49 -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=0SvRw1bdF/wj1/uPaALpB1mJItIzSwaE2+8pgarmj/0=; b=K8GSlHVyaCoX6eoUymMD8WNd8fo5NWDf75jpRiOk+1zSA+MpR6EfH2u4sq/cei0nEX o80zJP8en7QDpE5vzs8O5n4LrgF22geCbTMxZs9xW/Bw6G07hLfzIVGyGKyQoxIOnZBD YFtORfTsEPttMMQotUKNiwrIP4HCJfUjTSf2by1YSPzvrtnfC1aL0Dv/WEnFMeyqvoSY 1yZ+xCdOLBGgiLW+bKu/YcS0pacqJtrPn8i6k/jyqe3Rz1jF3T9VOENF63nv+EydMMBy h8eN884I5s73CM7fbg8Lu/9/FG0L4WKxt0gSlNtUkWxzIvuA+TNSCpjkFO+PNMv3SZs9 BR7A== 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=0SvRw1bdF/wj1/uPaALpB1mJItIzSwaE2+8pgarmj/0=; b=kBpAxFQeyk7gOcoakUz4Nu+jAqmmGi25D2xtilgv9by3nJQfV65bcmv2NQ0V0afhvJ l4fbMH/9wHl0HnMaLacY9qxUnlWIWGqWn3q70F+oXWobjtO55FTMS/cGEcARmn/Jbl3U rTgomdBeT4X1wGz3Pqg4OREXEib00lg0n8aD+u+F3151V6URUB86zx3JDWJPbNShhkEN njlmdKj/meBQKBVh1iG1/Fyo4JMsV91ryfbeJdSnk7u0h9EZh1IWgJDXvj7kDoCeFSk1 gElUYbNaz7ZUJsEkL0uVOHVEqmBXzIf7qz4tktDu5FeJwdsH5LW2IKgKbJi+yxZbxaUk hayA== X-Gm-Message-State: APjAAAWGFHM0d5bydwxf1CKi13PjiYtnk3shIQB+T7sI6W6BqCrxO78r aMyFc4yenV09dojZJCt6iu4= X-Received: by 2002:a17:906:e11a:: with SMTP id gj26mr95741299ejb.95.1564586040068; Wed, 31 Jul 2019 08:14:00 -0700 (PDT) Received: from box.localdomain ([86.57.175.117]) by smtp.gmail.com with ESMTPSA id qq13sm12564390ejb.27.2019.07.31.08.13.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 31 Jul 2019 08:13:57 -0700 (PDT) From: "Kirill A. Shutemov" X-Google-Original-From: "Kirill A. Shutemov" Received: by box.localdomain (Postfix, from userid 1000) id EF8F91045FB; Wed, 31 Jul 2019 18:08:16 +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 37/59] acpi/hmat: Evaluate topology presented in ACPI HMAT for MKTME Date: Wed, 31 Jul 2019 18:07:51 +0300 Message-Id: <20190731150813.26289-38-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 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 d27f4d17dfb3..8854ae942e37 100644 --- a/include/linux/acpi.h +++ b/include/linux/acpi.h @@ -1337,6 +1337,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.21.0