Received: by 10.213.65.68 with SMTP id h4csp19071imn; Mon, 12 Mar 2018 05:25:14 -0700 (PDT) X-Google-Smtp-Source: AG47ELtJ0Rge6n6iUntmWwttTBrRlmnb+uePC1TZjIC8W3RHw28o5wdvgRBFObBVKWk3WQv9+77U X-Received: by 10.99.167.2 with SMTP id d2mr6459740pgf.408.1520857514002; Mon, 12 Mar 2018 05:25:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1520857513; cv=none; d=google.com; s=arc-20160816; b=RbZsXjGHMc19haaDozoHD1MJmePJn9osqxtnlBYwTvnbAzxEO2ZSyEpwfwG+R8kpI8 R+dkZEf/P2bT96l5SLOZ+SyvxYdlVZgUMcCOMqimf/ZCJxhHZDxYfpyPCECxjozWYvWV ehvMyoKwfF0szfI6lk7hHrgEBcueBxKQ5jmJIGT4Y6ZdirEvRzWBXZF2K4C1izCq/aQs ZHip6gbo0DMZq62wc7p353bErPpitNVs0XU97a+O9hNnezrp4UkqxpnpLvm2trV/kXF8 mYeP5pEXPkMvD7WFmVNkdA8aTyt2fS8RYf82l+zU574HAxul4aF0/MDWdck992e/5m9e fwww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition :content-transfer-encoding:mime-version:robot-unsubscribe:robot-id :git-commit-id:subject:to:references:in-reply-to:reply-to:cc :message-id:from:date:arc-authentication-results; bh=lI4xQeGX28GQztN6grnTTv/ptZTG0eTuBkd2RKPC7w4=; b=rQoPgqquOeR8GYKiXIeWidIWjdqjORrUFlhxKNr/Y5j78Lbp4Xxa/mQRKyp0AOpWKn wR6y0po+Sq5Yqj5sykYYsSPee4z4Uxu7G2ROfNCbjBYGOCmq+KT6x9wGchOQxcPVQOq4 vMHC2YpCuUrec4RorlKL3gkXepfIKoFUDWCQtEC+pu7/FJTitFCltx6cMuv32o9A0h3L 4/o6kN/GHK5kGRsDvQ/sXH4fMeAApHbmK6Tbsfqd/pIVxyZjQgtvzHlAvfko/S+/JaqG 1VWQLinidAh1ojvESqQZvB8mq/DAJoHv7Bi0wJjAXU12KzjGcJQ+FToP82ISU3AhYMxe svIw== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 5si5687800pfx.208.2018.03.12.05.24.59; Mon, 12 Mar 2018 05:25:13 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932178AbeCLMXZ (ORCPT + 99 others); Mon, 12 Mar 2018 08:23:25 -0400 Received: from terminus.zytor.com ([198.137.202.136]:44931 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751502AbeCLMXW (ORCPT ); Mon, 12 Mar 2018 08:23:22 -0400 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTP id w2CCN18c017535; Mon, 12 Mar 2018 05:23:01 -0700 Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id w2CCN0dX017532; Mon, 12 Mar 2018 05:23:00 -0700 Date: Mon, 12 Mar 2018 05:23:00 -0700 X-Authentication-Warning: terminus.zytor.com: tipbot set sender to tipbot@zytor.com using -f From: "tip-bot for Kirill A. Shutemov" Message-ID: Cc: kai.huang@linux.intel.com, torvalds@linux-foundation.org, tglx@linutronix.de, thomas.lendacky@amd.com, mingo@kernel.org, hpa@zytor.com, peterz@infradead.org, kirill.shutemov@linux.intel.com, linux-kernel@vger.kernel.org, dave.hansen@intel.com Reply-To: dave.hansen@intel.com, kirill.shutemov@linux.intel.com, linux-kernel@vger.kernel.org, peterz@infradead.org, tglx@linutronix.de, thomas.lendacky@amd.com, hpa@zytor.com, mingo@kernel.org, torvalds@linux-foundation.org, kai.huang@linux.intel.com In-Reply-To: <20180305162610.37510-6-kirill.shutemov@linux.intel.com> References: <20180305162610.37510-6-kirill.shutemov@linux.intel.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:x86/mm] x86/pconfig: Provide defines and helper to run MKTME_KEY_PROG leaf Git-Commit-ID: 24c517856af6511be1339dd55edd131160e37aac X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline X-Spam-Status: No, score=-2.9 required=5.0 tests=ALL_TRUSTED,BAYES_00 autolearn=ham autolearn_force=no version=3.4.1 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on terminus.zytor.com Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: 24c517856af6511be1339dd55edd131160e37aac Gitweb: https://git.kernel.org/tip/24c517856af6511be1339dd55edd131160e37aac Author: Kirill A. Shutemov AuthorDate: Mon, 5 Mar 2018 19:25:53 +0300 Committer: Ingo Molnar CommitDate: Mon, 12 Mar 2018 12:10:54 +0100 x86/pconfig: Provide defines and helper to run MKTME_KEY_PROG leaf MKTME_KEY_PROG allows to manipulate MKTME keys in the CPU. Signed-off-by: Kirill A. Shutemov Cc: Dave Hansen Cc: Kai Huang Cc: Linus Torvalds Cc: Peter Zijlstra Cc: Thomas Gleixner Cc: Tom Lendacky Cc: linux-mm@kvack.org Link: http://lkml.kernel.org/r/20180305162610.37510-6-kirill.shutemov@linux.intel.com Signed-off-by: Ingo Molnar --- arch/x86/include/asm/intel_pconfig.h | 50 ++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/arch/x86/include/asm/intel_pconfig.h b/arch/x86/include/asm/intel_pconfig.h index fb7a37c3798b..3cb002b1d0f9 100644 --- a/arch/x86/include/asm/intel_pconfig.h +++ b/arch/x86/include/asm/intel_pconfig.h @@ -12,4 +12,54 @@ enum pconfig_target { int pconfig_target_supported(enum pconfig_target target); +enum pconfig_leaf { + MKTME_KEY_PROGRAM = 0, + PCONFIG_LEAF_INVALID, +}; + +#define PCONFIG ".byte 0x0f, 0x01, 0xc5" + +/* Defines and structure for MKTME_KEY_PROGRAM of PCONFIG instruction */ + +/* mktme_key_program::keyid_ctrl COMMAND, bits [7:0] */ +#define MKTME_KEYID_SET_KEY_DIRECT 0 +#define MKTME_KEYID_SET_KEY_RANDOM 1 +#define MKTME_KEYID_CLEAR_KEY 2 +#define MKTME_KEYID_NO_ENCRYPT 3 + +/* mktme_key_program::keyid_ctrl ENC_ALG, bits [23:8] */ +#define MKTME_AES_XTS_128 (1 << 8) + +/* Return codes from the PCONFIG MKTME_KEY_PROGRAM */ +#define MKTME_PROG_SUCCESS 0 +#define MKTME_INVALID_PROG_CMD 1 +#define MKTME_ENTROPY_ERROR 2 +#define MKTME_INVALID_KEYID 3 +#define MKTME_INVALID_ENC_ALG 4 +#define MKTME_DEVICE_BUSY 5 + +/* Hardware requires the structure to be 256 byte alinged. Otherwise #GP(0). */ +struct mktme_key_program { + u16 keyid; + u32 keyid_ctrl; + u8 __rsvd[58]; + u8 key_field_1[64]; + u8 key_field_2[64]; +} __packed __aligned(256); + +static inline int mktme_key_program(struct mktme_key_program *key_program) +{ + unsigned long rax = MKTME_KEY_PROGRAM; + + if (!pconfig_target_supported(MKTME_TARGET)) + return -ENXIO; + + asm volatile(PCONFIG + : "=a" (rax), "=b" (key_program) + : "0" (rax), "1" (key_program) + : "memory", "cc"); + + return rax; +} + #endif /* _ASM_X86_INTEL_PCONFIG_H */