From patchwork Thu Mar 2 15:17:11 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brijesh Singh X-Patchwork-Id: 9600677 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id A518460429 for ; Thu, 2 Mar 2017 15:54:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 92EBA28485 for ; Thu, 2 Mar 2017 15:54:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 85A3D285AA; Thu, 2 Mar 2017 15:54:30 +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,DKIM_SIGNED, DKIM_VALID,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 6646C28485 for ; Thu, 2 Mar 2017 15:54:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932108AbdCBPy1 (ORCPT ); Thu, 2 Mar 2017 10:54:27 -0500 Received: from mail-sn1nam02on0078.outbound.protection.outlook.com ([104.47.36.78]:53633 "EHLO NAM02-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753205AbdCBPwB (ORCPT ); Thu, 2 Mar 2017 10:52:01 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector1-amd-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=XqBL1dDy498Q/mIUG78NzgdR3+HB8FW1LOLcTFFFykg=; b=Mv/qhadtTTR4IJWoijFpXUKL7wXR+7u4C2+PwMv/wcu2/PvjIFjS0BLbukA4JCeayFUK9evmWbQHf5AFcZB+RaZiYi+2h7RjvpE02SFTBFqR2JxiRWvFa8ryE/fQRmMKJIcQzNlQj39mQiycCrKXq6ZLeVkhd5bT7hBMIWaKIKE= Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none; vger.kernel.org; dmarc=none action=none header.from=amd.com; Received: from [127.0.1.1] (165.204.77.1) by MWHPR12MB1613.namprd12.prod.outlook.com (10.172.56.14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.933.12; Thu, 2 Mar 2017 15:17:14 +0000 Subject: [RFC PATCH v2 23/32] kvm: introduce KVM_MEMORY_ENCRYPT_OP ioctl From: Brijesh Singh To: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Date: Thu, 2 Mar 2017 10:17:11 -0500 Message-ID: <148846783136.2349.9362218518503742320.stgit@brijesh-build-machine> In-Reply-To: <148846752022.2349.13667498174822419498.stgit@brijesh-build-machine> References: <148846752022.2349.13667498174822419498.stgit@brijesh-build-machine> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: MWHPR21CA0071.namprd21.prod.outlook.com (10.172.93.161) To MWHPR12MB1613.namprd12.prod.outlook.com (10.172.56.14) X-MS-Office365-Filtering-Correlation-Id: 805e247e-dc4d-4b82-c478-08d4617f36c5 X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(48565401081); SRVR:MWHPR12MB1613; X-Microsoft-Exchange-Diagnostics: 1; MWHPR12MB1613; 3:y67RqzKyt8Hp985cQU4ZPfuvPncDx9cvAwRs6ZKJNnti4/c9GkQggOoqJYyAFLoKBvD48wiv5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SpZLUftvTH5uDb39iqxbUX8mltXf03DrtL5iMG7eQttLPLwdjdoyUzs7lnwv8xJe8mFAYIdqyKaIDXJMa4rOhGkvdhhlkd6Jeesed1ZPY4BQ2OnXbyYORI0iicZ1HnY7y7fW/z06y7/uwL4vrrsB/zdyKNjUhFMNVeoGgUl248yEhqlLT6IBxoGNIvNf+Wo0nsRYV/F0FXGs1ay6knUsxSkbq7kfufTs/o3wqSZs6Msv6xgieipFvLskY2TE+WoLxZh/PUTBfEDl5Op7EUd3aWKwOFHAOIDyk942v7EgI0qnpNC+qwYao6vUmhxJxT4t86vgS9c7PgIfg5i8y56Ys4Px1zMITABErCg078i7L4fnSs2vv2F7EB9sNVhekxurBnWYKJPRtB/PjRgZXTO75UvgQTsvBsiwnjq5FQwSaiI X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(767451399110); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040375)(601004)(2401047)(8121501046)(5005006)(10201501046)(3002001)(6055026)(6041248)(20161123555025)(20161123564025)(20161123562025)(20161123558025)(20161123560025)(6072148); SRVR:MWHPR12MB1613; BCL:0; PCL:0; RULEID:; SRVR:MWHPR12MB1613; X-Microsoft-Exchange-Diagnostics: 1; MWHPR12MB1613; 4:5AXX9MdI9jVMx7+AMna9M+VHlacl8JChORPgrP4Er8Z5A4Fypo6LdELm6w4tjJJH9/qQdLn8DYR/oO5fBet2f3cS9I3EDxOuNe6iDCPRtSGhif4p1/MBTdKdVM/M6AQrsgMzO5Yth7BKvdB8hcqvfoIu0NnFVgUl2Qv1EiBmOhbMj9GiHDl64Fqy+I3U8Pj+DPFnJJCKhBZTixuxFoxHc+wxV0A++9yoSFhBZ6Tg+7sxF23MI9o15Sg49tzbQ0XeKo2Z9gCWvayRDZYDaz7v3Vp5+KSG0XA12tB7YcraKRySzU9e7iOeZ1ZTMXcGHubHFHEvxMwFOGaxYYp7w1r0cMyMytnLtpWVbeQjykrDye7el484UWKZwLKOabhuJA5rHng4MQ76x3yC95VxAPpXW8Rg7FkwQKIuLWtTCo41Vd2bYvLQcEfvdya6CYjNqNIpYPirLV0zhcHNkz1x/0/QTuIyDBiLXpQAcNuYL1CLk4v+LK64uopQYfMyX+sx237GQKBZhn0INS7KEaEeD5UqIy3A1DoY3Rz8SR6hO4AAx3pr4kIwyutwsFA2idR+d1dKDKqrF5Yjans+yzshqh/Ozqtl0tWPVtdV60z/M+QlyGyS6xUzq87vxuThVcSrg69Ux3KcqXMxWHMksbJ/es2E8s1rGsplKrqmPlv7oGjGq44= X-Forefront-PRVS: 023495660C X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(6009001)(6049001)(7916002)(39450400003)(39840400002)(39860400002)(39410400002)(39850400002)(54356999)(230700001)(42186005)(76176999)(3846002)(2950100002)(5660300001)(2906002)(33646002)(33716001)(50986999)(6666003)(83506001)(6116002)(66066001)(8676002)(9686003)(38730400002)(25786008)(53936002)(92566002)(77096006)(6486002)(189998001)(90366009)(2201001)(50466002)(23676002)(7406005)(1191002)(7366002)(103116003)(86362001)(7416002)(7736002)(305945005)(81166006)(47776003)(921003)(2101003)(1121003)(83996005)(217873001)(84006005); DIR:OUT; SFP:1101; SCL:1; SRVR:MWHPR12MB1613; H:[127.0.1.1]; FPR:; SPF:None; MLV:sfv; LANG:en; X-Microsoft-Exchange-Diagnostics: =?utf-8?B?MTtNV0hQUjEyTUIxNjEzOzIzOnJjUnhieVpMWHF0THpLRzZpaXpYRzlqcFRk?= =?utf-8?B?TUIrb0F1Y2xmeUdEZ3BCNUVaNVlUSGIydVlhVmJ3SmVVK0M1VUFrZVNyVUxo?= =?utf-8?B?TTBzWFZTcTljVTVTQ2xNUEx3MTN2Rlp6RE1XTFp0b0NrRUN0WUZLeG5CV3Bk?= =?utf-8?B?UEE4bFBvSDFvN1M3T3NiWTg3QTJnc0FRM0k4ajlxWUVRalU5NDl3YVRoZ2Zv?= =?utf-8?B?WDgxR003VGRkK3lQRVIyb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jQ/5KsY+eDB9+NcCiX+W1+Z05nM+9dniXZdGXDtn4FBmGjuQjC38Ehxfu/DBODls/EdA0mwmOy7HY=; 5:9SpSZcE0o9xiSFES9MkPDr8DGwEdMAZwnjms7BUcM2+cOELJQb5foBT8eIaoVn3rGCGYUzOHmLL4yfzfeZHP2OH3tyVL1JnYAB/jVGC74DgPxMlBNKM7ZhUdIpQv66D+b0pL+zcoIXJPcXJXRUNSKQ==; 24:C9JrT8KsmwjvWdpuYRSXa/RHjJn3MULTyR/0YOUBR3dvCRQpLZmXc1PAQaiDjPtOJeQwSQO3DCvpQBivN41tFLp+C3JAmhGx54eTv0W3hek= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; MWHPR12MB1613; 7:pXSoqQgSaawNwd5FeJOlQIymUo9ocimuPaULEurtfv9EIkbRkVEmRVu59Af9snRunvH30xgKaWWQb84racuSnEW4WJ/+agQyaPefe/2xmHAbCTHHiKVEUcyOxOkvmVeI74NKs7+X90cOiEC2d+psowmXTeFnsp2+u8x4UOd/uBEpCar2I5It3HRoo/XkzJ3hchepoLw4uAJcXh/oXJGiDwSJv4x8Xe5UuWi0O1bk/cZD6uiRLokY0nOHTbBm3CzfQaHiMP7Z+k30LmHLxtkjsHsvXPgWZywWNDx1W56PTID06B0raqmzVSxAIL4BeBjiM0flCObnoXegoiB0Ij+2Dg==; 20:FcCjHupoHYyCPfW26ijVf8Eckyp3Lq4rS1PFD0WwakacDk6gPtETq+wwXM5suE2AUireqXkEt4bcc2p9dwBoLMN0pyyu4ozR6REh7LstJ3rzaOUehv5+OM1FsHzN8rWTw44JMLpQ5O/gFZtaPksfBPK8cBsfqfnH5h9D+IzyoCnGkJ7jnca3cNtLFUcTqjmSsxwF6IwNz5vSt0fDL2NS7PRstoJ3UFWjjg+3+SUEr7YX5xg5kxdY43JI+x0/vIAY X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Mar 2017 15:17:14.3910 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR12MB1613 Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP If hardware supports encrypting then KVM_MEMORY_ENCRYPT_OP ioctl can be used by qemu to issue platform specific memory encryption commands. Signed-off-by: Brijesh Singh Reviewed-by: Paolo Bonzini --- arch/x86/include/asm/kvm_host.h | 2 ++ arch/x86/kvm/x86.c | 12 ++++++++++++ include/uapi/linux/kvm.h | 2 ++ 3 files changed, 16 insertions(+) diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index bff1f15..62651ad 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -1033,6 +1033,8 @@ struct kvm_x86_ops { void (*cancel_hv_timer)(struct kvm_vcpu *vcpu); void (*setup_mce)(struct kvm_vcpu *vcpu); + + int (*memory_encryption_op)(struct kvm *kvm, void __user *argp); }; struct kvm_arch_async_pf { diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 2099df8..6a737e9 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -3926,6 +3926,14 @@ static int kvm_vm_ioctl_enable_cap(struct kvm *kvm, return r; } +static int kvm_vm_ioctl_memory_encryption_op(struct kvm *kvm, void __user *argp) +{ + if (kvm_x86_ops->memory_encryption_op) + return kvm_x86_ops->memory_encryption_op(kvm, argp); + + return -ENOTTY; +} + long kvm_arch_vm_ioctl(struct file *filp, unsigned int ioctl, unsigned long arg) { @@ -4189,6 +4197,10 @@ long kvm_arch_vm_ioctl(struct file *filp, r = kvm_vm_ioctl_enable_cap(kvm, &cap); break; } + case KVM_MEMORY_ENCRYPT_OP: { + r = kvm_vm_ioctl_memory_encryption_op(kvm, argp); + break; + } default: r = kvm_vm_ioctl_assigned_device(kvm, ioctl, arg); } diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h index cac48ed..fef7d83 100644 --- a/include/uapi/linux/kvm.h +++ b/include/uapi/linux/kvm.h @@ -1281,6 +1281,8 @@ struct kvm_s390_ucas_mapping { #define KVM_S390_GET_IRQ_STATE _IOW(KVMIO, 0xb6, struct kvm_s390_irq_state) /* Available with KVM_CAP_X86_SMM */ #define KVM_SMI _IO(KVMIO, 0xb7) +/* Memory Encryption Commands */ +#define KVM_MEMORY_ENCRYPT_OP _IOWR(KVMIO, 0xb8, unsigned long) #define KVM_DEV_ASSIGN_ENABLE_IOMMU (1 << 0) #define KVM_DEV_ASSIGN_PCI_2_3 (1 << 1)