From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2B47BC433EF for ; Fri, 15 Jul 2022 20:42:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231526AbiGOUm4 (ORCPT ); Fri, 15 Jul 2022 16:42:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58324 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231522AbiGOUmr (ORCPT ); Fri, 15 Jul 2022 16:42:47 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0539687C20 for ; Fri, 15 Jul 2022 13:42:43 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id j2-20020a2597c2000000b0064b3e54191aso4706033ybo.20 for ; Fri, 15 Jul 2022 13:42:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=reply-to:date:in-reply-to:message-id:mime-version:references :subject:from:to:cc; bh=2CpovJeuRnY71/3WEgYmV3X/+gVqaILzwsGk5qWsmbA=; b=CI5eECRw/t2ePq8ve65FTKwSt2kIadrOWUlem3pEqQJDu81Pg2YyoetNf/oE+wfKBI UopyVVysF5uDMiduXGfWDIsKiN681CnG7/byuCseClaFFcQPW3p95aVCFGIVS1ULgrCs 7aXGdyzg370hIHpG0szNsdCGYhpSpQTYSjpfj71Op7j34ZFd1rrrRj8cAt3PMY2cbPvQ 7/nz/FyNlR6H0s28BBsGTnTeDI4R1cr+Lah0stzc4xzATBps+Pi0XHt/f9v19j4VuHyJ KApSjR7vZvCa9W5704VMuvdfGieZTRsWJslq5P3cRavi8JekmKcnqbVbBGyw2urJcNan VqVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:reply-to:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=2CpovJeuRnY71/3WEgYmV3X/+gVqaILzwsGk5qWsmbA=; b=MaHRP57edZrhjC+MVfV13ygF+b09sHyd1V4Sg4NB+Gki7OwJVn0Y3uRpLciFvjWdCF 2KJzcZwBNYvION6MkBGQWJAAEWMxpFvD/UARk1tINJD1vPoOtFpl2BDl/pMPuIWnYbui XWhy23Td5mmlUxIWjdBAORGdXFh6tvDk1F3P6SFtEu6oGr1q8DKRKNCTOCji0OlzaLwV 1nW3SzBYon9g0pxbYNYwL/WwSstT5W6350SRThBRyjdnt9MeCy6Q+pYkwWLtuYMr62M+ 2JKzwZBtESdPRzOijWKj/zNqkpGujPcZaBo0J19MTGyfAJcupCcpitYdsiz0my836xtq ASkQ== X-Gm-Message-State: AJIora9RQZOYNRnBwWyiFZwoTco9iKpgO0qAeCkkYRofIiW3xva0JgOG 9HKdJ9+jmr3UY9epWADrcmmcD4/vPPA= X-Google-Smtp-Source: AGRyM1s2ivCNo7cPKGrdosGL9wj+UwFqiTQrrkTdpFKnHi8+Ltkg+XTbhNDuxIbZcmpxoP5i6PdO0lvFIHQ= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a05:6902:1083:b0:66f:193f:edf with SMTP id v3-20020a056902108300b0066f193f0edfmr15543284ybu.281.1657917762733; Fri, 15 Jul 2022 13:42:42 -0700 (PDT) Reply-To: Sean Christopherson Date: Fri, 15 Jul 2022 20:42:07 +0000 In-Reply-To: <20220715204226.3655170-1-seanjc@google.com> Message-Id: <20220715204226.3655170-6-seanjc@google.com> Mime-Version: 1.0 References: <20220715204226.3655170-1-seanjc@google.com> X-Mailer: git-send-email 2.37.0.170.g444d1eabd0-goog Subject: [PATCH v2 05/24] KVM: nVMX: Prioritize TSS T-flag #DBs over Monitor Trap Flag From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Jim Mattson , Maxim Levitsky , Oliver Upton , Peter Shier Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Service TSS T-flag #DBs prior to pending MTFs, as such #DBs are higher priority than MTF. KVM itself doesn't emulate TSS #DBs, and any such exceptions injected from L1 will be handled by hardware (or morphed to a fault-like exception if injection fails), but theoretically userspace could pend a TSS T-flag #DB in conjunction with a pending MTF. Note, there's no known use case this fixes, it's purely to be technically correct with respect to Intel's SDM. Cc: Oliver Upton Cc: Peter Shier Fixes: 5ef8acbdd687 ("KVM: nVMX: Emulate MTF when performing instruction emulation") Signed-off-by: Sean Christopherson Reviewed-by: Maxim Levitsky --- arch/x86/kvm/vmx/nested.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c index 2409ed8dbc71..bc5759f82a3f 100644 --- a/arch/x86/kvm/vmx/nested.c +++ b/arch/x86/kvm/vmx/nested.c @@ -3932,15 +3932,17 @@ static int vmx_check_nested_events(struct kvm_vcpu *vcpu) } /* - * Process any exceptions that are not debug traps before MTF. + * Process exceptions that are higher priority than Monitor Trap Flag: + * fault-like exceptions, TSS T flag #DB (not emulated by KVM, but + * could theoretically come in from userspace), and ICEBP (INT1). * * Note that only a pending nested run can block a pending exception. * Otherwise an injected NMI/interrupt should either be * lost or delivered to the nested hypervisor in the IDT_VECTORING_INFO, * while delivering the pending exception. */ - - if (vcpu->arch.exception.pending && !vmx_get_pending_dbg_trap(vcpu)) { + if (vcpu->arch.exception.pending && + !(vmx_get_pending_dbg_trap(vcpu) & ~DR6_BT)) { if (vmx->nested.nested_run_pending) return -EBUSY; if (!nested_vmx_check_exception(vcpu, &exit_qual)) -- 2.37.0.170.g444d1eabd0-goog