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: 10592677 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 3ED8714E2 for ; Fri, 7 Sep 2018 22:37:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2FDF5292AC for ; Fri, 7 Sep 2018 22:37:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 23A102B2D7; Fri, 7 Sep 2018 22:37:40 +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=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=unavailable version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BE3CE292AC for ; Fri, 7 Sep 2018 22:37:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D93E48E000C; Fri, 7 Sep 2018 18:37:38 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id D430B8E0001; Fri, 7 Sep 2018 18:37:38 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C34F68E000C; Fri, 7 Sep 2018 18:37:38 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pg1-f197.google.com (mail-pg1-f197.google.com [209.85.215.197]) by kanga.kvack.org (Postfix) with ESMTP id 833748E0001 for ; Fri, 7 Sep 2018 18:37:38 -0400 (EDT) Received: by mail-pg1-f197.google.com with SMTP id m4-v6so7796002pgq.19 for ; Fri, 07 Sep 2018 15:37:38 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:date:from:to :cc:subject:message-id:references:mime-version:content-disposition :in-reply-to:user-agent; bh=VxFtrsbBNJemFQjMlwaEYWQrGEweXrDFjS0+vM3QRHg=; b=kQy0I9O33DAVjzeZUsP1LT2vlWqot1CZMNkOZ6tlse+9ulqDYq+9nITxK1kzrpGsCy SBiZv2m0xdYVM6OUK3sM9pvreO8fjfZx0yTnlb0ear3Dh7lqM8dtzbG5yvtQ8cxxYNEa U2tjNWAGwRtmr8W0yyHk3BLmnf4BtWP/eH8JB0/wKdYWWvZVhUp7EaorDtBszmM7tHuG l48NbsmnaIpCzW0lQqY1/F7xFzenoGLpL8qSwGdxzEhU+3FbL9ykCJ+ea8WmW1+d/GUn y/HrW+izdNnJQ3Zyg068xdWgX1h0ULWgrfAsbvoEQyTswJFGiwf1qYxrixbTQwtP84De DqPQ== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of alison.schofield@intel.com designates 134.134.136.20 as permitted sender) smtp.mailfrom=alison.schofield@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Gm-Message-State: APzg51Dg8Zawq8IgUKzDLCD/jPi5X+A/TlvmAFguYTW9V9OmnGOLJ/cW aXHbSNkKycK6Jk+EgEITRhYEsgT2NxUuhezcqhFdGaMRxkV0n/Dge+qQo+QYVEPpwyMog3UGRYW BelmkWR991q68yJ2KKAkffkZR8lPlMEpkNwhNcI/wVmOk3+l0JKFwfJI7CF0s0zeToQ== X-Received: by 2002:a17:902:e281:: with SMTP id cf1-v6mr10265627plb.86.1536359858219; Fri, 07 Sep 2018 15:37:38 -0700 (PDT) X-Google-Smtp-Source: ANB0Vdb2p8cV6ye/pmYrXMBCmw9Fjtq8OyATFm6NHzNelPE6JqSa9/5LZmik0VHj9IwpwM12i8UK X-Received: by 2002:a17:902:e281:: with SMTP id cf1-v6mr10265585plb.86.1536359857304; Fri, 07 Sep 2018 15:37:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536359857; cv=none; d=google.com; s=arc-20160816; b=GeeJ47e8WGFAh8QqCcd9VJvLg+qkE984+rkA4UJEG/SNmGXCPDYA6VnUSArYsYXaZe WjDPBM/i1iC0f43j05IemId7/tmWY2WzNGsFBorTbSOdIgHC8cSsGdgY/s5gGcZk6LeO FLiCcPst54I9QRJPFKPr2oYjP8QG7L6GxIDCYmBHOy89YElQULN1lvYmfiRZ6SPhpc0W S3rdKiAafwqioqoyE5Hu2bEaSW5VYWrr9U7INHtW8U0dyAAdisLu0cbozZY4DZMZQVJI X9Kxll6+shzlPUeCNonqSZEPVrFoalLj2VD6+FIvILevHcRVxtRO6mxtfcHIcOBdMIy2 t+/g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=user-agent:in-reply-to:content-disposition:mime-version:references :message-id:subject:cc:to:from:date; bh=VxFtrsbBNJemFQjMlwaEYWQrGEweXrDFjS0+vM3QRHg=; b=Mzb5VrIayov0BA/eT08lqkjY7e9uJRJOZoc5BxwXlLMcmPUu9/Gg17FhHgzpI2y8dq QIL01Z0Lsc9xHPs3z4WJHEwteMljQiANbChDqczsQv/WzXHIcTzdZdVuCJi3ADnIda6z SA0n9h1h8JT/jJfsI2hJ2011RD71ZRHfHguWt1OCXrhsZA04kxDccAd6AHPb2zK6EtVR /uEEQT+Aaiw6yXaUzqH4mL4PG6GM0RHSjCM5OUB43ZE43fDjFxtB/9vKoFd+XV5dxhKD TfnOUROl6zZyJm+rYGJAW2789X0LKvwlSf0GkKhXvV/ebsuoX3Iasz8uMser1zWENFez JTMQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of alison.schofield@intel.com designates 134.134.136.20 as permitted sender) smtp.mailfrom=alison.schofield@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from mga02.intel.com (mga02.intel.com. [134.134.136.20]) by mx.google.com with ESMTPS id 10-v6si9957731ple.60.2018.09.07.15.37.37 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 07 Sep 2018 15:37:37 -0700 (PDT) Received-SPF: pass (google.com: domain of alison.schofield@intel.com designates 134.134.136.20 as permitted sender) client-ip=134.134.136.20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of alison.schofield@intel.com designates 134.134.136.20 as permitted sender) smtp.mailfrom=alison.schofield@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Amp-Result: UNSCANNABLE X-Amp-File-Uploaded: False Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga101.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) X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org 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 */