Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp6109522ybi; Wed, 31 Jul 2019 08:29:44 -0700 (PDT) X-Google-Smtp-Source: APXvYqyCObbRLPh+NvrEM/7iUq5MPfe/25YXsATHbAuDJOtWlbK8I8a7gKUSmXtXmP58thdDAYx0 X-Received: by 2002:a65:65c5:: with SMTP id y5mr113279835pgv.342.1564586984330; Wed, 31 Jul 2019 08:29:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564586984; cv=none; d=google.com; s=arc-20160816; b=THgPp0kKKYz98ONLosD1bFYb8VVYpMtO3ocxvfizWLvyrSIzW30Ha/CDsBfmefNr0c 1IdjNhG2p6tkucne6fXAxtLYMKcElcAH8LNu0L0qrzW6Cu6zDvoE7whLkPQV5bMNLqPH lzkDyvzl6LYD0HlxxWpHW6f3kpU2wXanMZ/gBA+sgluC3gfYPQXDqJvr/KgaKh6mHKqv /pwK3faWwZVAYH+kT+2B8OAEdi1POYVTY96vtvb2LfnrHGj0i8z9FU6XFfQQgyZZWnFk ICnCa4T15epjmMIJRW6GXisL/Fxfo3mOZGsL4oUE7S/MulLfpmqxnSF+wrc83AeJE9LZ cbog== 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=vwkKEN+NO/42LLW7V4MVtQKdg9NG9HC4dwr+b7oU7/A=; b=fkub8wdDP1k/ssRjz3za8O4B73MdjjyufAnPu1PuF64zA6F3NT20BYvWhgMVLsWtUc 2LImxENHmXaDbiFnHJjTjoO/UOEj1VxxrIjuQevp+1dQ1lXluDLAZ58YwaE2465+dmIa Cy/CJngkCpgt5ZYdYIMIsgubBglYddYj3hHqkMyyKlZ0fNTMwmfriSGSNStDphTkwOdH faMCbhwsyqLNnLFyU4j8XPJzs3QALwYxXBesUM2kfKVhA9IasM3VQERprPir7xEBrGK8 quscYu3t1R72LQ6gFyejAY5VpwVyo2kpLXAhOebq4nqQgr5vwo6O2gDToqIGTQdepFCb jDkw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@shutemov-name.20150623.gappssmtp.com header.s=20150623 header.b=Uf1FCuDX; 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 x69si31441751pgd.168.2019.07.31.08.29.29; Wed, 31 Jul 2019 08:29:44 -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=Uf1FCuDX; 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 S1730045AbfGaPUd (ORCPT + 99 others); Wed, 31 Jul 2019 11:20:33 -0400 Received: from mail-ed1-f66.google.com ([209.85.208.66]:44356 "EHLO mail-ed1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729729AbfGaPU3 (ORCPT ); Wed, 31 Jul 2019 11:20:29 -0400 Received: by mail-ed1-f66.google.com with SMTP id k8so66014182edr.11 for ; Wed, 31 Jul 2019 08:20:28 -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=vwkKEN+NO/42LLW7V4MVtQKdg9NG9HC4dwr+b7oU7/A=; b=Uf1FCuDX52sEvKUCsJficveOp2kKNYX4EUGxdRJNZykLCtDIIDHpegDxYsp6cPe5pW EAoTzT/6HRwwAnq5QnSYpAtuKu32nvYS2kUdpN1mP4PQQ10UlxLyuA/tskPf2FIwxPud pUuxivdUf/yz+Tp+pjhIEiW+/6YgFS3K9zGL+Qh3OQ4/mioDDDPpCShm0v2J1MgLE8ff LAdvm4H5jX3b3WNwtdu5V9RM3W2HZGEtg1DkZ1XkWQ5ltdRlOKm5W2OJllK1ZO7oeFpf AvmUIe2HLJhkTNVz6b9FQaFDlX7qZyFGnnid7IyU8Nt0XiTLAB+dX1L/C7HwTI3yhcZW +xaA== 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=vwkKEN+NO/42LLW7V4MVtQKdg9NG9HC4dwr+b7oU7/A=; b=DV82haWlkGBDAK7nsCzAYQbRZjzGOu4cUtIz9/7jvJTqHsfCWxGnA21dZbfsAHk+Xl 6EKJ8VAiWCgsZEVdvEI/FeE6JHtLE3SH9gnk0jOWD66jxEioLvUK11ZxOdxf/NgL0SpD Hu30hzJcCA25crldeiHTOyA+HH9iujrXJBuzMQ2e+jUXcL9bxGORbzih0Xoc+pCp20Be UiGLoCIgqHk7COIDo3yDJLDFXgs8DFVlWouXc/bf97T2OAc9OhcY8xZUhv7FZoMaFU+6 3lstZ+s21bro0gMpPBbIV+M3m885/oQijYkcCKJFrqBCRSYF9l4J7qUYicPKUP+e8FHJ IJqQ== X-Gm-Message-State: APjAAAWmK9R9yhyG9jgUah9k4YgxVi6r9glVyuMtHeXTxFHtxSHnDyZd dMpbqszbYua3sHncxV+4660= X-Received: by 2002:a17:906:43c9:: with SMTP id j9mr92667128ejn.248.1564586034633; Wed, 31 Jul 2019 08:13:54 -0700 (PDT) Received: from box.localdomain ([86.57.175.117]) by smtp.gmail.com with ESMTPSA id k10sm17260344eda.9.2019.07.31.08.13.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 31 Jul 2019 08:13:53 -0700 (PDT) From: "Kirill A. Shutemov" X-Google-Original-From: "Kirill A. Shutemov" Received: by box.localdomain (Postfix, from userid 1000) id 103E71045FE; 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 40/59] keys/mktme: Block memory hotplug additions when MKTME is enabled Date: Wed, 31 Jul 2019 18:07:54 +0300 Message-Id: <20190731150813.26289-41-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 Intel platforms supporting MKTME need the ability to evaluate the memory topology before allowing new memory to go online. That evaluation would determine if the kernel can program the memory controller. Every memory controller needs to have a CPU online, capable of programming its MKTME keys. The kernel uses the ACPI HMAT at boot time to determine a safe MKTME topology, but at run time, there is no update to the HMAT. That run time support will come in the future with platform and kernel support for the _HMA method. Meanwhile, be safe, and do not allow any MEM_GOING_ONLINE events when MKTME is enabled. Signed-off-by: Alison Schofield Signed-off-by: Kirill A. Shutemov --- security/keys/mktme_keys.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/security/keys/mktme_keys.c b/security/keys/mktme_keys.c index b042df73899d..f804d780fc91 100644 --- a/security/keys/mktme_keys.c +++ b/security/keys/mktme_keys.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -497,6 +498,26 @@ static int mktme_cpu_teardown(unsigned int cpu) return ret; } +static int mktme_memory_callback(struct notifier_block *nb, + unsigned long action, void *arg) +{ + /* + * Do not allow the hot add of memory until run time + * support of the ACPI HMAT is available via an _HMA + * method. Without it, the new memory cannot be + * evaluated to determine an MTKME safe topology. + */ + if (action == MEM_GOING_ONLINE) + return NOTIFY_BAD; + + return NOTIFY_OK; +} + +static struct notifier_block mktme_memory_nb = { + .notifier_call = mktme_memory_callback, + .priority = 99, /* priority ? */ +}; + static int __init init_mktme(void) { int ret, cpuhp; @@ -543,10 +564,15 @@ static int __init init_mktme(void) if (cpuhp < 0) goto free_encrypt; + if (register_memory_notifier(&mktme_memory_nb)) + goto remove_cpuhp; + ret = register_key_type(&key_type_mktme); if (!ret) return ret; /* SUCCESS */ + unregister_memory_notifier(&mktme_memory_nb); +remove_cpuhp: cpuhp_remove_state_nocalls(cpuhp); free_encrypt: kvfree(encrypt_count); -- 2.21.0