Received: by 10.223.185.116 with SMTP id b49csp2780094wrg; Mon, 5 Mar 2018 08:33:58 -0800 (PST) X-Google-Smtp-Source: AG47ELtLm8KnQm4FLiJNSagk2hM+iOcXngqmqff7YtaS8B71DvGZaI8w/l0oyH/SDJWC6xuxDnKE X-Received: by 10.99.37.7 with SMTP id l7mr7882168pgl.212.1520267637989; Mon, 05 Mar 2018 08:33:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520267637; cv=none; d=google.com; s=arc-20160816; b=GKj6KopWGUkmc2bFFNbMvNDd5nEL5NCuSPN6uClIcE92rRLwvPqSBoEYBoVUBA5vEc UgP4UDIBf2lisHqmv1ndlNgbjmIHlZbdDJFII8Ehd46g15VdssfeBNB7lvOcPZLlE0nM Cwmgkd7a0FMkJOnlz7tcyK1lrOX6b8X29d+FC/C3CbEwn1kuPixvLPvTMO/nEz2lx97z cJjgaUEYlfoD5hsKTMSCMumnjuFOSzc51ec71zKP8RFshkrG0PYCtkHv2tDWvFQSbu/w HPwQTfYNIQ1y0Ne+5cwE38ywY9MMBi5E8rMFgts3UakTAdnW8WvdAuHIBtUEdvLv/nQ9 xiIA== 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=1Y44jOx9zbmMqgs67/qutxBqL2ATaKEVCReny2l+XCE=; b=MsEVOhQFCN2lz1SS6g8QR9L8vmxOKtMNBOJmSuGY0hUpILXbw35lNlQON15a6oJetX b5ZqOaHkwHu6p0ZLwFct+/gXINKlB4s3ZkMNVgZbuJZ+8KBj+15frNQFYQ4kfgQvSxSM hGuaIUl6O6Jp8tryVdDKqjmYdk/1k0JT+Dqy8eqXl+VL3b+iznU1JyywgFziCK//LDx6 Vf7fHyLRDksYdA2QqZh5pRfshwbqPtfuP/3zDoxLVJnBKntBupxc4/z5RgmhQI2M5oX7 bqv8StgTSGlOqi66CaTxjKoqCo1AnhpIFeViU11tCzwYG/VAcVfEsNEm9BGemh8+NS6s JlBA== 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 j127si8588275pgc.653.2018.03.05.08.33.43; Mon, 05 Mar 2018 08:33:57 -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 S932128AbeCEQaj (ORCPT + 99 others); Mon, 5 Mar 2018 11:30:39 -0500 Received: from mga06.intel.com ([134.134.136.31]:14691 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752372AbeCEQ01 (ORCPT ); Mon, 5 Mar 2018 11:26:27 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 05 Mar 2018 08:26:27 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.47,427,1515484800"; d="scan'208";a="34759445" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga004.fm.intel.com with ESMTP; 05 Mar 2018 08:26:24 -0800 Received: by black.fi.intel.com (Postfix, from userid 1000) id 1FC7C3BD; Mon, 5 Mar 2018 18:26:20 +0200 (EET) From: "Kirill A. Shutemov" To: Ingo Molnar , x86@kernel.org, Thomas Gleixner , "H. Peter Anvin" , Tom Lendacky Cc: Dave Hansen , Kai Huang , linux-kernel@vger.kernel.org, linux-mm@kvack.org, "Kirill A. Shutemov" Subject: [RFC, PATCH 05/22] x86/pconfig: Provide defines and helper to run MKTME_KEY_PROG leaf Date: Mon, 5 Mar 2018 19:25:53 +0300 Message-Id: <20180305162610.37510-6-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180305162610.37510-1-kirill.shutemov@linux.intel.com> References: <20180305162610.37510-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.16.1