Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp689058pxv; Thu, 8 Jul 2021 11:39:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyI4bezAYCSM0yEKE1k4JqiJNGS3XF9SbPnI5/j8xPD9Pp0wnjMOQjKpc8zJyKq5slTjF6m X-Received: by 2002:a05:6638:3048:: with SMTP id u8mr27907191jak.91.1625769548417; Thu, 08 Jul 2021 11:39:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625769548; cv=none; d=google.com; s=arc-20160816; b=r2OoTtkpasdoB6Jdjo3ehD5JI3ik50Vu/gDjEz0rQ65khOS+Nq5ucaAs67BikE0L70 T3+1fyz/fu3THSjMfaONw/AK92EWp6tdIpBLshlf4VS3IV/faVPxe3l2y97/PytmOebR LsKcim58PKhKqtY4caq0sl+c/UUikqygm0NpqVbjGhP2QaudJb059R0Rpx+q79ZYBv93 4V+nD+bjplnui2WYMYq+IdC8th9tPNJI9yu57I+syN84H8+g90iCNaDgEEKsVeS8B0wC 8gmy+wfwoJpwQfHpoxoNJPfH+AteIcG63zMjEG/8MYIIysJZLH9vO8jgXN1D6A115jYi AAbQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=7IMuMUvHO82Rf0Ss8PXs63y6ANC76fGZyxGH24nk1uY=; b=Ds32mSrxKab1NEsePYunubZ3re79OaF+OLAMAO+utGby/yj88sOsIDFVJ7/uXF3kol uIUieG8cq39Pnv2Al9g2zvk4ciqlL9sYJTEyjGBltujiRxoQuqR+V1eyItaL/EydAesQ O/fknxY2pz6+EvL2pYMzqt/ysFuLrLwGFZlXZJck8nONDTXJmvnO9HuNEbBpvLnhODya KLJ5RZHPn3j52eJzbfMFIOfAqBWcQoYiWYCpd+KnfMRHdkrNA4tiS+5ezKji+YWTSSgh NjMZAEhbxyUZgVSC/KkaJ7cpuxOED9jp0gjjn5obOxF/LNaZ+/L1acC9963/pjWp23Ap tgxQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=AEJUmU09; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b6si3311065ilv.22.2021.07.08.11.38.55; Thu, 08 Jul 2021 11:39:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=AEJUmU09; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229631AbhGHSlG (ORCPT + 99 others); Thu, 8 Jul 2021 14:41:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48844 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229469AbhGHSlG (ORCPT ); Thu, 8 Jul 2021 14:41:06 -0400 Received: from mail-pg1-x52f.google.com (mail-pg1-x52f.google.com [IPv6:2607:f8b0:4864:20::52f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6AF0BC06175F for ; Thu, 8 Jul 2021 11:38:24 -0700 (PDT) Received: by mail-pg1-x52f.google.com with SMTP id u14so7114573pga.11 for ; Thu, 08 Jul 2021 11:38:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=7IMuMUvHO82Rf0Ss8PXs63y6ANC76fGZyxGH24nk1uY=; b=AEJUmU092XhSjinH3RNlcQMS/9jJCUfRHFTvGQOCYGEgAkLDTt91AoUhpV20zqrqaG DgxEkyC7dIjMJejx10JKJCCad8mo9r17BDUHgTgdADxDWEmoQX6MI/Ks82PTsEV6wf6b wKLuoB0Bw21064KfDHSoi9ggEs0OdmCiFqzx+6A/Qav7JexZHVOP5GV64ONuI1uoMqnJ IK8vOt7ia2yi82nY24zzCbuTHHcTJGeeT6wXiPdp0g3awgHWnmetypwl0L8gEXlERsvv zaj3cym87YUy76sBrw/rUq8ip5xJy8lswH9QtOrhmAE4wJ4AU/HW2//+e5yWeiPhqfWo iJxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=7IMuMUvHO82Rf0Ss8PXs63y6ANC76fGZyxGH24nk1uY=; b=KtvTNNU5jNI1m27SnWczbb6cOg8jmvD7Tr/IMy5VX0Q13+LvoyhYK6qCua7Nz5PUMf kHaDE0cal4zhBm1wN8O4H8L25/WhfKU4xe8pD6a++sSRwdXl5ucqudw3lOTFFp/NystB KV+oOKTM5g2CAamVXaXBPXLcifrJUGaVoehnDV/cDuWOwP4D57+FIS0g1ljUZkjHyMxn bCjCRY7xQSE5PvlT4LSoCpK4dViQp4i8C3zL8+06kaA5tNclbA8W0VMeNWYJxEz1VwOP cpN9iNHMi3DzMnmG3xgQO2kRT+1JhtPHopxUtZiGKdJP3MlYfFWTxBbyxb3uBwy3fOHt bz8w== X-Gm-Message-State: AOAM532ypHaZO5YGBbStqz0geOlasOlI+iHD8nZv5n2cTXqKtgsuWD5s D2vPfogXvBW8fecUJotGVBD26Q== X-Received: by 2002:aa7:8d5a:0:b029:302:e2cb:6d79 with SMTP id s26-20020aa78d5a0000b0290302e2cb6d79mr32258922pfe.71.1625769503629; Thu, 08 Jul 2021 11:38:23 -0700 (PDT) Received: from google.com (254.80.82.34.bc.googleusercontent.com. [34.82.80.254]) by smtp.gmail.com with ESMTPSA id 2sm4277773pgz.26.2021.07.08.11.38.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Jul 2021 11:38:22 -0700 (PDT) Date: Thu, 8 Jul 2021 18:38:18 +0000 From: David Matlack To: David Edmondson Cc: linux-kernel@vger.kernel.org, Wanpeng Li , Jim Mattson , Sean Christopherson , Borislav Petkov , Vitaly Kuznetsov , Joerg Roedel , kvm@vger.kernel.org, Paolo Bonzini , Thomas Gleixner , x86@kernel.org, Ingo Molnar , "H. Peter Anvin" Subject: Re: [PATCH v2 0/2] kvm: x86: Convey the exit reason to user-space on emulation failure Message-ID: References: <20210706101207.2993686-1-david.edmondson@oracle.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jul 08, 2021 at 03:17:40PM +0100, David Edmondson wrote: > Apologies if you see two of these - I had some email problems earlier. I only got one! :) > > On Wednesday, 2021-07-07 at 23:20:04 UTC, David Matlack wrote: > > > On Tue, Jul 06, 2021 at 11:12:05AM +0100, David Edmondson wrote: > >> To help when debugging failures in the field, if instruction emulation > >> fails, report the VM exit reason to userspace in order that it can be > >> recorded. > > > > What is the benefit of seeing the VM-exit reason that led to an > > emulation failure? > > I can't cite an example of where this has definitively led in a > direction that helped solve a problem, but we do sometimes see emulation > failures reported in situations where we are not able to reproduce the > failures on demand and the existing information provided at the time of > failure is either insufficient or suspect. > > Given that, I'm left casting about for data that can be made available > to assist in postmortem analysis of the failures. Understood, thanks for the context. My only concern would be that userspace APIs are difficult to change once they exist. If it turns out knowing the exit reason does not help with debugging emulation failures we'd still be stuck with exporting it on every emulation failure. My intuition is that the instruction bytes (which are now available with Aaron's patch) and the guest register state (which is queryable through other ioctls) should be sufficient to set up a reproduction of the emulation failure in a kvm-unit-test and the exit reason should not really matter. I'm curious if that's not the case? I'm really not opposed to exporting the exit reason if it is useful, I'm just not sure it will help. > > >> I'm unsure whether sgx_handle_emulation_failure() needs to be adapted > >> to use the emulation_failure part of the exit union in struct kvm_run > >> - advice welcomed. > >> > >> v2: > >> - Improve patch comments (dmatlack) > >> - Intel should provide the full exit reason (dmatlack) > >> - Pass a boolean rather than flags (dmatlack) > >> - Use the helper in kvm_task_switch() and kvm_handle_memory_failure() > >> (dmatlack) > >> - Describe the exit_reason field of the emulation_failure structure > >> (dmatlack) > >> > >> David Edmondson (2): > >> KVM: x86: Add kvm_x86_ops.get_exit_reason > >> KVM: x86: On emulation failure, convey the exit reason to userspace > >> > >> arch/x86/include/asm/kvm-x86-ops.h | 1 + > >> arch/x86/include/asm/kvm_host.h | 3 +++ > >> arch/x86/kvm/svm/svm.c | 6 ++++++ > >> arch/x86/kvm/vmx/vmx.c | 11 +++++++---- > >> arch/x86/kvm/x86.c | 22 +++++++++++++--------- > >> include/uapi/linux/kvm.h | 7 +++++++ > >> 6 files changed, 37 insertions(+), 13 deletions(-) > >> > >> -- > >> 2.30.2 > >> > > dme. > -- > It's gettin', it's gettin', it's gettin' kinda hectic.