Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp1533062ybf; Thu, 27 Feb 2020 12:52:41 -0800 (PST) X-Google-Smtp-Source: APXvYqzQXtAfrLE8KeOaKi8qEpSyBa/WlxElH/WqzndsJU8Ev4sNL1OUK1eG7L+H28dG4JBFJDM3 X-Received: by 2002:aca:2b0a:: with SMTP id i10mr667679oik.137.1582836761119; Thu, 27 Feb 2020 12:52:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582836761; cv=none; d=google.com; s=arc-20160816; b=ktUPnOzrSyGIuNcDZmSULLiPZbEDz+wjfOJ68LFMG6/wv928uG8D4dIAIo4O48Zq6M YDr1hmtTAVw76MrjK2+bxKWnR0wxyptpHlJR65+WOTvAn6etFLbkx/PfQh0oCYoSw0q5 63Y2pliQXYX1L2ngkxEX/aTMUzwNI1l0cq2dd7Mg6UtmUhihQLdp+xMNyCmiYay9pBHI lz4BG2jH0alNSdwmXDhGAgyHcrZaECu4qEArjjX+x8RQ2eSjP2Pv/XuVb0uzeuDAaPpC pT+akiu1TQ+QJ5wisiSy/MNzqF8bSeItt77C7I9oj+wVsh5wVT9e/3fnGKAmCQmRlRrR YqOg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=yEHF72SjoXV4TEetM/BAvq4e9frC7eAamZNl/QsDHxY=; b=YYivBP5Itov0/Qmi2Qd3sECO7AKbJhMt0cqUzCx8TRMRUjlJ6DseY7c68JEUE2OLVG oUCRHutsSXNgJjA7iidS1qw2w5EeEsmWBGKKtIF3reGgyHjBZGH+nFgedV3UuXKNqNGd qwAM54fUk/vXUha2Q+wjBcxlXpnMxn9aKJ2jJj9YvWgzgiel7xqBtvGFFBoR3flIa5pE MKUljn59Z2bydsgBO/xJAVGnu17GFWoM9Dk0jYFBxpl/mogY207NfGukacxmVbs24e5m ZENJ4G95kCIdrPRwaEL32ksn6o+2ejTZgOYg37k7oln6wVgoKgml3xuqAItjNKcdNtd6 Pk+A== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y144si510750oia.67.2020.02.27.12.52.18; Thu, 27 Feb 2020 12:52:41 -0800 (PST) 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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729723AbgB0Uvy (ORCPT + 99 others); Thu, 27 Feb 2020 15:51:54 -0500 Received: from mga05.intel.com ([192.55.52.43]:41482 "EHLO mga05.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726758AbgB0Uvy (ORCPT ); Thu, 27 Feb 2020 15:51:54 -0500 X-Amp-Result: UNKNOWN X-Amp-Original-Verdict: FILE UNKNOWN X-Amp-File-Uploaded: False Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 Feb 2020 12:51:53 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,493,1574150400"; d="scan'208";a="272366192" Received: from sjchrist-coffee.jf.intel.com (HELO linux.intel.com) ([10.54.74.202]) by fmsmga002.fm.intel.com with ESMTP; 27 Feb 2020 12:51:53 -0800 Date: Thu, 27 Feb 2020 12:51:53 -0800 From: Sean Christopherson To: Krish Sadhukhan Cc: Paolo Bonzini , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Xiaoyao Li Subject: Re: [PATCH] KVM: nVMX: Consult only the "basic" exit reason when routing nested exit Message-ID: <20200227205153.GC17014@linux.intel.com> References: <20200227174430.26371-1-sean.j.christopherson@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Feb 27, 2020 at 12:08:55PM -0800, Krish Sadhukhan wrote: > > On 2/27/20 9:44 AM, Sean Christopherson wrote: > >Consult only the basic exit reason, i.e. bits 15:0 of vmcs.EXIT_REASON, > >when determining whether a nested VM-Exit should be reflected into L1 or > >handled by KVM in L0. > > > >For better or worse, the switch statement in nested_vmx_exit_reflected() > >currently defaults to "true", i.e. reflects any nested VM-Exit without > >dedicated logic. Because the case statements only contain the basic > >exit reason, any VM-Exit with modifier bits set will be reflected to L1, > >even if KVM intended to handle it in L0. > > > >Practically speaking, this only affects EXIT_REASON_MCE_DURING_VMENTRY, > >i.e. a #MC that occurs on nested VM-Enter would be incorrectly routed to > >L1, as "failed VM-Entry" is the only modifier that KVM can currently > >encounter. The SMM modifiers will never be generated as KVM doesn't > >support/employ a SMI Transfer Monitor. Ditto for "exit from enclave", > >as KVM doesn't yet support virtualizing SGX, i.e. it's impossible to > >enter an enclave in a KVM guest (L1 or L2). > > > It seems nested_vmx_exit_reflected() deals only with the basic exit reason. > If it doesn't need anything beyond bits 15:0, may be vmx_handle_exit() can > pass just the base exit reason ? Argh. I was going to simply respond with "It traces exit_reason via trace_kvm_nested_vmexit().", but then I looked at the tracing code :-( The tracepoints that print the names of the VM-Exit are flawed in the sense that they'll always print the raw value for VM-Exits with modifiers. E.g. a consistency check VM-Exit on invalid guest state will print 0x80000021 instead of INVALID_STATE. Stripping bits 31:16 when invoking the tracepoint would fix the immediate issue, but I'm not sure I like that approach because doing so drops information that could potentially be quite helpful, e.g. if nested VM-Exit injection injected EXIT_REASON_MSR_LOAD_FAIL without also setting VMX_EXIT_REASONS_FAILED_VMENTRY, which could break/confuse the L1 VMM. I'm also not remotely confident that we won't screw this up again in the future :-) So part of me thinks the best way to resolve the printing would be to modify VMX_EXIT_REASONS to do "| VMX_EXIT_REASONS_FAILED_VMENTRY" where appropriate, i.e. on INVALID_STATE, MSR_LOAD_FAIL and MCE_DURING_VMENTRY. The downside of that approach is it breaks again when new modifiers come along, e.g. SGX's ENCLAVE_EXIT. But again, the modifier is likely useful information. I think the most foolproof and informative way to handle this would be to add a macro and/or helper function, e.g. kvm_print_vmx_exit_reason(), to wrap __print_symbolic(__entry->exit_code, VMX_EXIT_REASONS) so that it prints both the name of the basic exit reason as well as the names for any modifiers. TL;DR: I still like this patch as is, especially since it'll be easy to backport. I'll send a separate patch for the tracepoint issue.