Received: by 10.223.176.5 with SMTP id f5csp626868wra; Wed, 7 Feb 2018 05:01:51 -0800 (PST) X-Google-Smtp-Source: AH8x226DZ0rQ3gud9ncdMjZr0RyyKDPQidJMLD9/NABfqO5IIfc/9T9Z0PdDJ7+FZJN7T3xCguEB X-Received: by 10.99.183.15 with SMTP id t15mr4988103pgf.416.1518008511653; Wed, 07 Feb 2018 05:01:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518008511; cv=none; d=google.com; s=arc-20160816; b=podIrkO3zAptHTwU/VRpMpST5TbSg0SJh2cWYem2Ci1w7da3PvVRv/6u/d7rSxI7oN OKKAuaj39SzZ+41qDahFRFgCZ7zfsZRjkFDTGx3tPsIKdViE4uIUKf76XKZKe8PWP5Pb 1SV7SJEtcWpddgClujQR1tJ/sePM7K7AagaatQGavZ9BU+5x1hCTJRRKl4z3w6cX3i8e BFR+yxAPhhyV2I1d3BlY4cJ/M3Cpqyq9sY6wa/0Rnn/X31rhOR/bGITqWPdV8I5j21Ft xR5bFG4f4NRGb3b0fByW6cquvuI4Z3onEwWiESl06yb56o83aGJPOJcxNfLmWQ5Juaus eYwg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=V/E1SNKni0p/a+lWi/Nu8V0M5aNjmhfCYP0JszLjAdg=; b=Ur2O3iJJcgqgraTCciGwksB8Yxcs+AR0MK9kbaRuPbSNYsRFqmMEZQH8MDWWf6y8Me f1i4Ery0Y7d6fIPcBeACnvTMz0TTpq540kGqENmhSdWYC/JKZnS71lBLcG96WgQ0ITRK fJlpItU00UPn8JVi8upl7hY9HAr6H3P9Ew9m+z/sOTdK7Nw7qLtysh+BpHmForlpuVZX usl4EFl3qnpF4IqiZ+TE3+DsbPzyk4Jb25uK2LBz+7NtJCB4XoaVvnOjf6Zc1PXrMnEz 7a8CEpJlaMeOQqatc+fpbWheBLARhcA5rx/mwpi5+xH4FGHvrqYLJzfpKueCgSmXP6Un qdXg== 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 o10si925187pgf.102.2018.02.07.05.01.36; Wed, 07 Feb 2018 05:01:51 -0800 (PST) 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 S1754156AbeBGNAe (ORCPT + 99 others); Wed, 7 Feb 2018 08:00:34 -0500 Received: from mga07.intel.com ([134.134.136.100]:26269 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753630AbeBGM74 (ORCPT ); Wed, 7 Feb 2018 07:59:56 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 07 Feb 2018 04:59:56 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.46,473,1511856000"; d="scan'208";a="29584595" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga001.jf.intel.com with ESMTP; 07 Feb 2018 04:59:53 -0800 Received: by black.fi.intel.com (Postfix, from userid 1000) id CDAFAA02; Wed, 7 Feb 2018 14:59:49 +0200 (EET) From: "Kirill A. Shutemov" To: Ingo Molnar , x86@kernel.org, Thomas Gleixner , "H. Peter Anvin" Cc: Tom Lendacky , Dave Hansen , Kai Huang , linux-kernel@vger.kernel.org, "Kirill A. Shutemov" Subject: [PATCHv2 5/5] x86/pconfig: Provide defines and helper to run MKTME_KEY_PROG leaf Date: Wed, 7 Feb 2018 15:59:46 +0300 Message-Id: <20180207125946.5906-6-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.15.1 In-Reply-To: <20180207125946.5906-1-kirill.shutemov@linux.intel.com> References: <20180207125946.5906-1-kirill.shutemov@linux.intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org MKTME_KEY_PROG allows to manipulate MKTME keys in the CPU. Signed-off-by: Kirill A. Shutemov --- 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 */ -- 2.15.1