Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp734991pxu; Fri, 23 Oct 2020 11:58:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy3nrf251zOCtRLursau4k1Qbj6nQR2tQgwHOhPmgZ+4/V/ZIAe0QSUJQt4OBSJzxH5Euqz X-Received: by 2002:a17:906:53d6:: with SMTP id p22mr3373921ejo.517.1603479481355; Fri, 23 Oct 2020 11:58:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603479481; cv=none; d=google.com; s=arc-20160816; b=Fv0hGLZo4jnnfy9rZgWnc8FVqx3TLG8wgEwtf+shdFRJLqQxigchk36DNUa7QPKedS ip5BOe/wImQVeCJquSwsPh13FuB/QMx4GoCwe66iVo/BAdgSPr+LlHyHIorNLt4+vFr5 kAaj5tka1b3IKTkPSQBNicGjXpF8KCnudzu3R9ZyH8ZYZASTTlKAqHQ+EyuE3szITWDd mbypJ/zct/YvoUirdnbeX9wLBs1ArOjZUJwlwWSt8VH0FGcOpRddCKdjTQ1IjZfHw0Od Dvt6TpcvQM9sTp7ObFlCxDkK+pjvCJ/l5Pgos3k67HUOl1Jq27VLOwxASGWcOGQcf7J4 dBaw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=GSVr128pqOoBVgaQYWDeH7y0Q+csz3WwPIzOZPNEXDU=; b=hTfOe1KugpL/mSGu9jIFwajLBGhOQnkeB+VqKGtme2dE9dvyVYX7A1pACvuNJu64XY de+ojlryMquG97iSNFqtbdlnhP7Wahkd8wUQlCdR95r4eGcXNsB64XG1bAtHV158nNC7 umMW3n/Ro0ag2xXBxXNn841RayMI5jsKrResSnJpgXsctHd5KD7cLP3vNuwiAarikVj0 CsnDowfQP0i2GJsOuy1VwEcnl+5aJCEqiKiEJc79F0dNBKd/2qdUnAklMbfKC75meHs8 h1kQTGKNEUn3OXSeVdABbo0QBd9kKT8TB2dJrbb+x1BiuexeTgK/CWqiuM2GzUbXQyEF OHSg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=Gm9gB8Lf; 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 r25si2119115edc.210.2020.10.23.11.57.39; Fri, 23 Oct 2020 11:58:01 -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=Gm9gB8Lf; 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 S1751509AbgJWQ7R (ORCPT + 99 others); Fri, 23 Oct 2020 12:59:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53120 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S462951AbgJWQ7R (ORCPT ); Fri, 23 Oct 2020 12:59:17 -0400 Received: from mail-ot1-x341.google.com (mail-ot1-x341.google.com [IPv6:2607:f8b0:4864:20::341]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 542B1C0613CE for ; Fri, 23 Oct 2020 09:59:17 -0700 (PDT) Received: by mail-ot1-x341.google.com with SMTP id o14so1975976otj.6 for ; Fri, 23 Oct 2020 09:59:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=GSVr128pqOoBVgaQYWDeH7y0Q+csz3WwPIzOZPNEXDU=; b=Gm9gB8LfWqXjYNl+ezisHjcKPpuYsHthevYvIaDtlEB9d+b83tyLXhvxMbEAce2RCO CmF8L6JhFKT5CK4tQHjNkssG/iskl/etKY6pLS+99Ew2EqkVPbrprYCdRzwzkjudwoPf Dfkh6+Z5B7HoPwQvg1wb//RugPRsKW2CDOH9dKQLQ7WLbz4rR5u4HvTWlgz5rgBdDd+j 3WTb3QYAXr7pej5bwi+5CdYDUZi9D4M5JopRMJee1TnfGVj3oVywjh7rApTeHq4nqZDp GTDkyqsJy2mwxZ/NVxcjG+ll2QChI1WzogLNWiZ8G0k6ung0cvBNwr8oZIExoq4nG1Yo 0fIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=GSVr128pqOoBVgaQYWDeH7y0Q+csz3WwPIzOZPNEXDU=; b=Rl5Eg2E5nb83wKIZFeIybnCustnzc38Y49pzjStu5TL92ZZWKG5d9WAaB2ST3uR4Lm gGnRJPvvLaNDn4hCapUtpxuOP3Bnuhwi1fIcIE9DjuTuc8W3Na3r9p7kxQI595kwrGeG NWMPTsRTD9ucCqTj7OpIMOD6sJZMCYkKCp92CSbh2ekAfsMLu0/LIW925zop+ws0qvxc jcjRqkDjH74JHY8OwX+kxlUNnnFnKBjcuTU7J3zoBxpVNgD9IxjyWNzKHVtSuUdPDwbh zos0cY/ezb2YpH/r1g9T3O6FLVi2fibJxQ6dbViMkrMQbmcaBOML50Tvw7q6ukEnBOEb Dsvw== X-Gm-Message-State: AOAM5301eVdE7LR4D5FfTZsgjSbrHBt2RybyneaQmVHzwiEY57+KpX4n z9rxnLLbM5k6GWWNDElwgv+QoZO/Vz+Wc3uXx2DKqw== X-Received: by 2002:a05:6830:10d3:: with SMTP id z19mr2501059oto.295.1603472354961; Fri, 23 Oct 2020 09:59:14 -0700 (PDT) MIME-Version: 1.0 References: <20200710154811.418214-1-mgamal@redhat.com> <20200710154811.418214-8-mgamal@redhat.com> <20201023031433.GF23681@linux.intel.com> <498cfe12-f3e4-c4a2-f36b-159ccc10cdc4@redhat.com> In-Reply-To: <498cfe12-f3e4-c4a2-f36b-159ccc10cdc4@redhat.com> From: Jim Mattson Date: Fri, 23 Oct 2020 09:59:03 -0700 Message-ID: Subject: Re: [PATCH v3 7/9] KVM: VMX: Add guest physical address check in EPT violation and misconfig To: Paolo Bonzini Cc: Sean Christopherson , Mohammed Gamal , kvm list , LKML , Vitaly Kuznetsov , Wanpeng Li , Joerg Roedel Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Oct 23, 2020 at 2:22 AM Paolo Bonzini wrote: > > On 23/10/20 05:14, Sean Christopherson wrote: > >>>> + > >>>> + /* > >>>> + * Check that the GPA doesn't exceed physical memory limits, as that is > >>>> + * a guest page fault. We have to emulate the instruction here, because > >>>> + * if the illegal address is that of a paging structure, then > >>>> + * EPT_VIOLATION_ACC_WRITE bit is set. Alternatively, if supported we > >>>> + * would also use advanced VM-exit information for EPT violations to > >>>> + * reconstruct the page fault error code. > >>>> + */ > >>>> + if (unlikely(kvm_mmu_is_illegal_gpa(vcpu, gpa))) > >>>> + return kvm_emulate_instruction(vcpu, 0); > >>>> + > >>> Is kvm's in-kernel emulator up to the task? What if the instruction in > >>> question is AVX-512, or one of the myriad instructions that the > >>> in-kernel emulator can't handle? Ice Lake must support the advanced > >>> VM-exit information for EPT violations, so that would seem like a > >>> better choice. > >>> > >> Anyone? > > > > Using "advanced info" if it's supported seems like the way to go. Outright > > requiring it is probably overkill; if userspace wants to risk having to kill a > > (likely broken) guest, so be it. > > Yeah, the instruction is expected to page-fault here. However the > comment is incorrect and advanced information does not help here. > > The problem is that page fault error code bits cannot be reconstructed > from bits 0..2 of the EPT violation exit qualification, if bit 8 is > clear in the exit qualification (that is, if the access causing the EPT > violation is to a paging-structure entry). In that case bits 0..2 refer > to the paging-structure access rather than to the final access. In fact > advanced information is not available at all for paging-structure access > EPT violations. True, but the in-kernel emulator can only handle a very small subset of the available instructions. If bit 8 is set in the exit qualification, we should use the advanced VM-exit information. If it's clear, we should just do a software page walk of the guest's x86 page tables. The in-kernel emulator should only be used as a last resort on hardware that doesn't support the advanced VM-exit information for EPT violations.