Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp1482884ybi; Sat, 27 Jul 2019 10:40:22 -0700 (PDT) X-Google-Smtp-Source: APXvYqybs0Dcu1EV2BpzA8MMxXK1remp5KbMEOrW4gpN4CBhYpZXHKYcbUmf/yz/98raZvq29FlJ X-Received: by 2002:a17:902:2865:: with SMTP id e92mr62686349plb.264.1564249222765; Sat, 27 Jul 2019 10:40:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564249222; cv=none; d=google.com; s=arc-20160816; b=s2+c5g/I9RLyLhXNmY+lXiEFRR95JtOQdQEt3Or2KnUMn+9GNgCX2qqZ6SWhJiz0UG JENlABe35c0KJY4YblOJCMdV6jhx65/ww5k3juv9g0tRDY6UxKQdwVURBL+TWtmcWIw8 pG9MG3n3+b1kwCSceRFxdq2V8aSw8vmqTIP/92KQGZMRPbhxv+h415ZALpXgwIrf+m9T lr+WcdKdj0nP1eQrVuM4ANeXBgEO7lIevAgv7qiwgjpKNshQ6w+gluoVt28riDsY07cR Yxspt5e6JkxU17XsjkoW7cAQxQsNO5GwBFEGKDs5vZby5SH8M901kl5wGIi7GPFCL3C9 xBTw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=MqIcXplnS5zt85QMcs3gjxA6MBQ/2W1mGvOzb72QgG4=; b=Gsoc8SqcfE6ThcBxWoUv1MFarcObBUX8ElQl/Z7beV/hOZTc4UySVUIHy6K6KHWPaH 682brd8F1ddiI1woT36Zm2C7PZDei7VV9juNOx1TLyGiJA6cJH2u0NLeyB/rcCHbiEKB lhcXDp5oWRyoBpZYu3iH1yp5szLgUp3ZD0JmUClU516YuPLolEHNp/zIcwxn6Aqj+/ur jxKcaON/d5dZFMqwXgR9kNnb7VR10C/hGFIkwE2mV9onCDVWWHrOnF0KqfhmHA0AgQVz EZ5c+tbeJPXqvObIQTMi7VMMkrP6IGzIGNhE6mWkPnypDeAMhQr9TI8MP6wj+6bJUg8u tI1w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=RZCyy6gK; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q38si7943122pgk.63.2019.07.27.10.40.07; Sat, 27 Jul 2019 10:40:22 -0700 (PDT) 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; dkim=pass header.i=@kernel.org header.s=default header.b=RZCyy6gK; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388037AbfG0RiS (ORCPT + 99 others); Sat, 27 Jul 2019 13:38:18 -0400 Received: from mail.kernel.org ([198.145.29.99]:41288 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388038AbfG0RiR (ORCPT ); Sat, 27 Jul 2019 13:38:17 -0400 Received: from mail-wm1-f42.google.com (mail-wm1-f42.google.com [209.85.128.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 676712166E for ; Sat, 27 Jul 2019 17:38:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1564249096; bh=kUWslRPU39oVlObLtgG3Hl8pm76FUT1cLz91UMA48ew=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=RZCyy6gKHyjKvKUJjlqGamViQZCRDsV+acvbcEuofVU9B8hzZAdEB/H4cnHobpPwR PR0yvQHQb/YlLGvJQmyht1q9N9wniM3yxQfd/mdd2RUjT8UcSp5z9rt6DmOF3+KKxN yDb3Opss3OxfKY6/XBocj611pRRXj9B5ZQEcZSSw= Received: by mail-wm1-f42.google.com with SMTP id f17so50083664wme.2 for ; Sat, 27 Jul 2019 10:38:16 -0700 (PDT) X-Gm-Message-State: APjAAAX12K3xWM3tatjMFxYHuuKEwwB0rPf1KIX2lVkyKykgul28MJSc 2LhPs8E33cXMZb/YpsTaWFZBfFrOv6wvI2HqS24IyQ== X-Received: by 2002:a1c:c5c2:: with SMTP id v185mr96261509wmf.161.1564249094779; Sat, 27 Jul 2019 10:38:14 -0700 (PDT) MIME-Version: 1.0 References: <20190727055214.9282-1-sean.j.christopherson@intel.com> <20190727055214.9282-9-sean.j.christopherson@intel.com> In-Reply-To: <20190727055214.9282-9-sean.j.christopherson@intel.com> From: Andy Lutomirski Date: Sat, 27 Jul 2019 10:38:03 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [RFC PATCH 08/21] KVM: x86: Add kvm_x86_ops hook to short circuit emulation To: Sean Christopherson Cc: Paolo Bonzini , =?UTF-8?B?UmFkaW0gS3LEjW3DocWZ?= , Thomas Gleixner , Ingo Molnar , Borislav Petkov , X86 ML , Jarkko Sakkinen , Joerg Roedel , "H. Peter Anvin" , kvm list , LKML , linux-sgx@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jul 26, 2019 at 10:52 PM Sean Christopherson wrote: > > Similar to the existing AMD #NPF case where emulation of the current > instruction is not possible due to lack of information, virtualization > of Intel SGX will introduce a scenario where emulation is not possible > due to the VMExit occurring in an SGX enclave. And again similar to > the AMD case, emulation can be initiated by kvm_mmu_page_fault(), i.e. > outside of the control of the vendor-specific code. > > While the cause and architecturally visible behavior of the two cases > is different, e.g. Intel SGX will inject a #UD whereas AMD #NPF is a > clean resume or complete shutdown, the impact on the common emulation > code is identical: KVM must stop emulation immediately and resume the > guest. > > Replace the exisiting need_emulation_on_page_fault() with a more generic > is_emulatable() kvm_x86_ops callback, which is called unconditionally > by x86_emulate_instruction(). > Having recently noticed that emulate_ud() is broken when the guest's TF is set, I suppose I should ask: does your new code function sensibly when TF is set? Also, anyone want to fix that emulate_ud() bug? The test case is merged now: # ./tools/testing/selftests/x86/syscall_arg_fault_32 [RUN] SYSENTER with invalid state [OK] Seems okay [RUN] SYSCALL with invalid state [SKIP] Illegal instruction [RUN] SYSENTER with TF and invalid state [OK] Seems okay [RUN] SYSCALL with TF and invalid state [WARN] Got stuck single-stepping -- you probably have a KVM bug