From patchwork Fri Sep 7 22:38:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alison Schofield X-Patchwork-Id: 10592675 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BCF1314E2 for ; Fri, 7 Sep 2018 22:37:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AC214292AC for ; Fri, 7 Sep 2018 22:37:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A042F2B2D7; Fri, 7 Sep 2018 22:37:38 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 487A2292AC for ; Fri, 7 Sep 2018 22:37:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726434AbeIHDUp (ORCPT ); Fri, 7 Sep 2018 23:20:45 -0400 Received: from mga18.intel.com ([134.134.136.126]:12679 "EHLO mga18.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726010AbeIHDUp (ORCPT ); Fri, 7 Sep 2018 23:20:45 -0400 X-Amp-Result: UNSCANNABLE X-Amp-File-Uploaded: False Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 07 Sep 2018 15:37:37 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.53,344,1531810800"; d="scan'208";a="231141235" Received: from alison-desk.jf.intel.com ([10.54.74.53]) by orsmga004.jf.intel.com with ESMTP; 07 Sep 2018 15:37:27 -0700 Date: Fri, 7 Sep 2018 15:38:10 -0700 From: Alison Schofield To: dhowells@redhat.com, tglx@linutronix.de Cc: Kai Huang , Jun Nakajima , Kirill Shutemov , Dave Hansen , Jarkko Sakkinen , jmorris@namei.org, keyrings@vger.kernel.org, linux-security-module@vger.kernel.org, mingo@redhat.com, hpa@zytor.com, x86@kernel.org, linux-mm@kvack.org Subject: [RFC 10/12] x86/pconfig: Program memory encryption keys on a system-wide basis Message-ID: <0947e4ad711e8b7c1f581a446e808f514620b49b.1536356108.git.alison.schofield@intel.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: X-Virus-Scanned: ClamAV using ClamSMTP The kernel manages the MKTME (Multi-Key Total Memory Encryption) Keys as a system wide single pool of keys. The hardware, however, manages the keys on a per physical package basis. Each physical package maintains a key table that all CPU's in that package share. In order to maintain the consistent, system wide view that the kernel requires, program all physical packages during a key program request. Signed-off-by: Alison Schofield --- arch/x86/include/asm/intel_pconfig.h | 42 ++++++++++++++++++++++++++++++------ 1 file changed, 36 insertions(+), 6 deletions(-) diff --git a/arch/x86/include/asm/intel_pconfig.h b/arch/x86/include/asm/intel_pconfig.h index 3cb002b1d0f9..d3bf0a297e89 100644 --- a/arch/x86/include/asm/intel_pconfig.h +++ b/arch/x86/include/asm/intel_pconfig.h @@ -3,6 +3,7 @@ #include #include +#include enum pconfig_target { INVALID_TARGET = 0, @@ -47,19 +48,48 @@ struct mktme_key_program { u8 key_field_2[64]; } __packed __aligned(256); -static inline int mktme_key_program(struct mktme_key_program *key_program) +struct mktme_key_program_info { + struct mktme_key_program *key_program; + unsigned long status; +}; + +static void mktme_package_program(void *key_program_info) { + struct mktme_key_program_info *info = key_program_info; unsigned long rax = MKTME_KEY_PROGRAM; + asm volatile(PCONFIG + : "=a" (rax), "=b" (info->key_program) + : "0" (rax), "1" (info->key_program) + : "memory", "cc"); + + if (rax != MKTME_PROG_SUCCESS) + WRITE_ONCE(info->status, rax); +} + +/* + * MKTME keys are managed as a system-wide single pool of keys. + * In the hardware, each physical package maintains a separate key + * table. Program all physical packages with the same key info to + * maintain that system-wide kernel view. + */ +static inline int mktme_key_program(struct mktme_key_program *key_program, + cpumask_var_t mktme_cpumask) +{ + struct mktme_key_program_info info = { + .key_program = key_program, + .status = MKTME_PROG_SUCCESS, + }; + if (!pconfig_target_supported(MKTME_TARGET)) return -ENXIO; - asm volatile(PCONFIG - : "=a" (rax), "=b" (key_program) - : "0" (rax), "1" (key_program) - : "memory", "cc"); + get_online_cpus(); + on_each_cpu_mask(mktme_cpumask, mktme_package_program, + &info, 1); + put_online_cpus(); - return rax; + return info.status; } #endif /* _ASM_X86_INTEL_PCONFIG_H */