From patchwork Fri Aug 13 07:12:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Edmondson X-Patchwork-Id: 12434963 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-11.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 05060C4338F for ; Fri, 13 Aug 2021 07:12:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E0FD160241 for ; Fri, 13 Aug 2021 07:12:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239275AbhHMHMs (ORCPT ); Fri, 13 Aug 2021 03:12:48 -0400 Received: from forward2-smtp.messagingengine.com ([66.111.4.226]:59575 "EHLO forward2-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239230AbhHMHMq (ORCPT ); Fri, 13 Aug 2021 03:12:46 -0400 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailforward.nyi.internal (Postfix) with ESMTP id 25FA0194076A; Fri, 13 Aug 2021 03:12:18 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Fri, 13 Aug 2021 03:12:18 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :message-id:mime-version:subject:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm3; bh=IJ84Zz7cXD2dARXk2 E4si9LSMTMEPXvMGAWxocLB7k8=; b=KLPKleY+V+TZn7ffDpWBbAMHhDbU5PLd4 CGEukJFWJMJ7zseXMfvCsGkDWVB+JlDZkCvkQXLeWg4dh3neJ1756YodHhm6klEP sEVgh3+3vTpDt8hcQhyB4/vRnrn84CHG1g3FfGtK9lAjlAv4cSR6aGOYqFioCo9B PcjhPSw+vhMMDSl8b0jKttvFway/muwGtKvByqBZuWNShdmX5LP5CeNv1hMwC028 3ZkTBN4i/+hODlDecP30cGFoJyl2ydSItwmqaknnqo+IwdktqMpZEDp1xqN/wHhd c/poT2PtVokLUiSwvZvG1fMWEtgG1RSptilx/u0bPt1PJoODfp6pA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvtddrkeeggdduudejucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvufffkffoggfgsedtkeertdertddtnecuhfhrohhmpeffrghvihguucfg ughmohhnughsohhnuceouggrvhhiugdrvggumhhonhgushhonhesohhrrggtlhgvrdgtoh hmqeenucggtffrrghtthgvrhhnpeduhfetvdfhgfeltddtgeelheetveeufeegteevtddu iedvgeejhfdukeegteehheenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmh grihhlfhhrohhmpegurghvihgurdgvughmohhnughsohhnsehorhgrtghlvgdrtghomh X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 13 Aug 2021 03:12:14 -0400 (EDT) Received: from localhost (disaster-area.hh.sledj.net [local]) by disaster-area.hh.sledj.net (OpenSMTPD) with ESMTPA id 94f31bc7; Fri, 13 Aug 2021 07:12:12 +0000 (UTC) From: David Edmondson To: linux-kernel@vger.kernel.org Cc: Jim Mattson , Borislav Petkov , Paolo Bonzini , Vitaly Kuznetsov , "H. Peter Anvin" , Thomas Gleixner , Wanpeng Li , Ingo Molnar , Sean Christopherson , Joerg Roedel , David Matlack , x86@kernel.org, kvm@vger.kernel.org, David Edmondson Subject: [PATCH v4 0/4] KVM: x86: Convey the exit reason, etc. to user-space on emulation failure Date: Fri, 13 Aug 2021 08:12:07 +0100 Message-Id: <20210813071211.1635310-1-david.edmondson@oracle.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org To help when debugging failures in the field, if instruction emulation fails, report the VM exit reason, etc. to userspace in order that it can be recorded. The SGX changes here are compiled but untested. Sean: if you want me to add your name to patch 3, given that I adopted your sample code almost unaltered, please say. v4: - Update the API for preparing emulation failure report (Sean) - sgx uses the provided API in all relevant cases (Sean) - Clarify the intended layout of kvm_run.emulation_failure. v3: - Convey any debug data un-flagged after the ABI specified data in struct emulation_failure (Sean) - Obey the ABI protocol in sgx_handle_emulation_failure() (Sean) v2: - Improve patch comments (dmatlock) - Intel should provide the full exit reason (dmatlock) - Pass a boolean rather than flags (dmatlock) - Use the helper in kvm_task_switch() and kvm_handle_memory_failure() (dmatlock) - Describe the exit_reason field of the emulation_failure structure (dmatlock) David Edmondson (4): KVM: x86: Clarify the kvm_run.emulation_failure structure layout KVM: x86: Get exit_reason as part of kvm_x86_ops.get_exit_info KVM: x86: On emulation failure, convey the exit reason, etc. to userspace KVM: x86: SGX must obey the KVM_INTERNAL_ERROR_EMULATION protocol arch/x86/include/asm/kvm_host.h | 10 +++-- arch/x86/kvm/svm/svm.c | 8 ++-- arch/x86/kvm/trace.h | 9 ++-- arch/x86/kvm/vmx/nested.c | 2 +- arch/x86/kvm/vmx/sgx.c | 16 +++----- arch/x86/kvm/vmx/vmx.c | 11 +++-- arch/x86/kvm/x86.c | 73 ++++++++++++++++++++++++++------- include/uapi/linux/kvm.h | 15 ++++++- 8 files changed, 100 insertions(+), 44 deletions(-)