Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp3506410pxb; Mon, 4 Apr 2022 19:10:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJysonl2QnEphitHtdu9+hqQKHgSjPd+DJW168JXKAV6RsM/VFMnsjv/iS9vkUtpJoka5CTw X-Received: by 2002:aa7:9f9c:0:b0:4fa:7ffa:7cc7 with SMTP id z28-20020aa79f9c000000b004fa7ffa7cc7mr1124577pfr.43.1649124640734; Mon, 04 Apr 2022 19:10:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649124640; cv=none; d=google.com; s=arc-20160816; b=MQE5vf823MZDBuQ77FEp4O1gAwBLy4rdzezjJrUFuLFuzsC/aSZ2rDko6TLenHMxj8 VSOp1Wfgpscyyt7+806TaLjXwNxCn6F7xSQyXSNDSC69egNRgCDCX7UZvLBclfQYjHdY G7ISoT5PLTJckCZ5ufW3J9KrTVuK8i21m8WfOeB6RRFsrlO5fGs6nbvU+G4TamOjSn5j flJPpd+yHf/c8jBVKXEtS4i0xzuiSeCHO2DaYCN/Wi2vNQrOyQ1IeYz8y0cUYltiKChb pbKVbFDB7yKSdcQu3c7KdkYIWRKCjCff8xSar+OmBVkdKfTG3YZfidMvVQXbgXEpziyP IyyA== 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:to:from:date:dkim-signature; bh=f7CZTXIAAoKnaeTzl2cBEFXf6R/B35g02/GjhJjJB74=; b=NO3jHi+3aENU3F8oo/MCIbmG8i/sMBnNvyRvbNNzGDqp+qywIRHOCRcSXgALJs/jg9 t+up40U4suNbd9nHMctFxq+KCpibse9o4mcQAn1EwYb3iQqZMUAN2VsMu8qChXC0uFEi PT7qn0LOZNrNmpgmirdg54jNDiQZuZkGBnFXzjOXMKmXWb74Hz/AtQSu7wrg0ASu3Cep Q8p+6gNR9SE7yIsrdA9n8ZRytXM56nBfwLvUtGkgHLWLYB85Qa4j9FQsx3mbEy9XqQy3 Q9LDUJnMi9lNDWR2bAdNeJHoe0R/PhyK45ezoViswG+y2zxMhToezyb3fLe41Mi9DwIi qmeA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=eBZWszMf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1: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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id b198-20020a6334cf000000b003816043f011si11512815pga.518.2022.04.04.19.10.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Apr 2022 19:10:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=eBZWszMf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1: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: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id C86272527AA; Mon, 4 Apr 2022 17:33:38 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1357886AbiDDWGW (ORCPT + 99 others); Mon, 4 Apr 2022 18:06:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55056 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379495AbiDDRQU (ORCPT ); Mon, 4 Apr 2022 13:16:20 -0400 Received: from mail-pj1-x102c.google.com (mail-pj1-x102c.google.com [IPv6:2607:f8b0:4864:20::102c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A024E13F77 for ; Mon, 4 Apr 2022 10:14:24 -0700 (PDT) Received: by mail-pj1-x102c.google.com with SMTP id o5-20020a17090ad20500b001ca8a1dc47aso3995366pju.1 for ; Mon, 04 Apr 2022 10:14:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:from:to:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=f7CZTXIAAoKnaeTzl2cBEFXf6R/B35g02/GjhJjJB74=; b=eBZWszMfrYAS1A0VrXpWNQWYDljGRJ+69p04Uob5nwN5mkb+RRRbhGQtuSACDJkmvd JzPqoBdgGu43CiEvMKn6MoJcRQCsl7Owmu3MNRPIYKMky87OkSaEID6ZI70cN+xFHfx5 ZxAL+FJLp9ve4zSfapVXowsj+6Ldxi2KIv9zTO/Uf8ZtGfgDzG/o8faLsk22qy3LIdgI 2FPf//bfqpfCAuXBJpK7xeekXuFiEuJ24MyqK4BXHra2TdclI296/kmZ9f5cwYj4K+7B g9g8MWWBtQB00iQfM4jblH3lazcS3nWsLZzRPoAvtYHlPcGNcHEHkXEhancJVBtgTKuU /Smg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=f7CZTXIAAoKnaeTzl2cBEFXf6R/B35g02/GjhJjJB74=; b=lAZSfNGND8uo4mQ+v7Zwv3RT46LTTxHcA1GJChC3kNsQ74Hbi9Ro0F/iKY7OeY0KcB OoJ9WLqUA92P2XN0owP9IFb770qJ5ndUYVo0RRiYDWC5fAfFB1B0wi3HibyK/aHrzqFN wHyzQ9lsyxX7b1Rt4jqyI19FkXs69SbKEuMtMBL8Gtor4wnWMclCHMbvAKI8yxdOfwYs gdELMKETrdqrLjQNfXFg0OtIKUVzucZs7pUUfBrY8qAm++42/Hc7d1Tok7DH7x4PUq7x +gsYEUptu2SXJ4OnOhb/ZJT0YUImcdgmhpaxpOvQ8TxhOFrCKPEm+NFqw/D3AWWQfhgC Lqsw== X-Gm-Message-State: AOAM532LCfBUf12h8i6dTibEU/aj/fv1STKtuVP3j4Ws9fjgv1NTSqJv ICzepemHbmZDcc0Yje04loUixA== X-Received: by 2002:a17:90b:713:b0:1c6:c8f5:6138 with SMTP id s19-20020a17090b071300b001c6c8f56138mr207055pjz.138.1649092463964; Mon, 04 Apr 2022 10:14:23 -0700 (PDT) Received: from google.com (157.214.185.35.bc.googleusercontent.com. [35.185.214.157]) by smtp.gmail.com with ESMTPSA id o11-20020a17090aac0b00b001cab1712455sm50391pjq.40.2022.04.04.10.14.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Apr 2022 10:14:23 -0700 (PDT) Date: Mon, 4 Apr 2022 17:14:19 +0000 From: Sean Christopherson To: Paolo Bonzini , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, "Maciej S . Szmigiero" Subject: Re: [PATCH 6/8] KVM: SVM: Re-inject INTn instead of retrying the insn on "failure" Message-ID: References: <20220402010903.727604-1-seanjc@google.com> <20220402010903.727604-7-seanjc@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220402010903.727604-7-seanjc@google.com> X-Spam-Status: No, score=-9.5 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Apr 02, 2022, Sean Christopherson wrote: > Re-inject INTn software interrupts instead of retrying the instruction if > the CPU encountered an intercepted exception while vectoring the INTn, > e.g. if KVM intercepted a #PF when utilizing shadow paging. Retrying the > instruction is architecturally wrong e.g. will result in a spurious #DB > if there's a code breakpoint on the INT3/O, and lack of re-injection also > breaks nested virtualization, e.g. if L1 injects a software interrupt and > vectoring the injected interrupt encounters an exception that is > intercepted by L0 but not L1. > > Signed-off-by: Sean Christopherson > --- > arch/x86/kvm/svm/svm.c | 16 +++++++++++++++- > 1 file changed, 15 insertions(+), 1 deletion(-) > > diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c > index ecc828d6921e..00b1399681d1 100644 > --- a/arch/x86/kvm/svm/svm.c > +++ b/arch/x86/kvm/svm/svm.c > @@ -3425,14 +3425,24 @@ static void svm_inject_nmi(struct kvm_vcpu *vcpu) > static void svm_inject_irq(struct kvm_vcpu *vcpu) > { > struct vcpu_svm *svm = to_svm(vcpu); > + u32 type; > > WARN_ON(!gif_set(svm)); > > + if (vcpu->arch.interrupt.soft) { > + if (svm_update_soft_interrupt_rip(vcpu)) > + return; > + > + type = SVM_EVTINJ_TYPE_SOFT; > + } else { > + type = SVM_EVTINJ_TYPE_INTR; > + } > + > trace_kvm_inj_virq(vcpu->arch.interrupt.nr); > ++vcpu->stat.irq_injections; > > svm->vmcb->control.event_inj = vcpu->arch.interrupt.nr | > - SVM_EVTINJ_VALID | SVM_EVTINJ_TYPE_INTR; > + SVM_EVTINJ_VALID | type; > } > > void svm_complete_interrupt_delivery(struct kvm_vcpu *vcpu, int delivery_mode, > @@ -3787,9 +3797,13 @@ static void svm_complete_interrupts(struct kvm_vcpu *vcpu) > case SVM_EXITINTINFO_TYPE_INTR: > kvm_queue_interrupt(vcpu, vector, false); > break; > + case SVM_EXITINTINFO_TYPE_SOFT: > + kvm_queue_interrupt(vcpu, vector, true); I believe this patch is wrong, it needs to also tweak the soft_int_injected logic to look for SVM_EXITINTINFO_TYPE_EXEPT _or_ SVM_EXITINTINFO_TYPE_SOFT, e.g. if the SOFT-type interrupt doesn't complete due to a non-legacy-exception exit, e.g. #NPF. > + break; > default: > break; > } > + > }