Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp3352598pxb; Mon, 4 Apr 2022 14:23:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyFHZJn0Kox7LJppL8jhsU920ydIfdkVCZP6r0cU/DFkxhr8+2fXUQi8v4cxL93OvN4uzZS X-Received: by 2002:a63:69c7:0:b0:380:afc8:33be with SMTP id e190-20020a6369c7000000b00380afc833bemr117962pgc.304.1649107429519; Mon, 04 Apr 2022 14:23:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649107429; cv=none; d=google.com; s=arc-20160816; b=f3KjqOLZDZFW0d67VaPo4v8ieaQJFg3l/5iuDKOo6ayDFBa93AaNvTfnfFM/mufkjm jNk8AQMzjExeEhu7kSClgYSSAdkQ8EDiVmHK6UhU90HPNszuNbCQ81AjkNeQ4YOD6WbT SsEfOpLeHK6CPRYCfcGPrP7Y3vLygp4Qo9TiPcKmjn90IEgS1Wy6yqVFgPsjmBKMdxHZ X8kle1WWRFuufrIpG1V5BiXAOSIPqpzzL4miM7vGx2gTD6WI3dk2U6Fp9/NWI86NenGJ cpcCzhN8OFnttEHahQBVHrvTxJVaA/pu2bFRTVc9icXN3jpn6fOIN6faJCW0p99ayT2Z Gzsw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:references:mime-version :message-id:in-reply-to:date:reply-to:dkim-signature; bh=i0u4JArrhDsLDMn+I/rLz2mNP22Vvf7YGTWgik9+mpU=; b=NWLhqPURDzNY+t+6hzy4vS+CadGntQ0QJXw434knAOY8evaKD7+hyPaczSFP77sajZ 0IPMJBI8l33kN0MHgywdj6ky66igJDek9aIfyweZvLTHA4jGrNXt599ZIdic6Kt65bmO Pts9bpHBUuFIglpGOYWHcV9MhKVeCKluL3oSCG179c0Vjr/GWkeCDsp37ST2zkiJtlaG 58/tklXTECPOJt3+H+LCZtI9nySr4DqeQnqXIdO3RzIf+8EnBLgSkqyFfaUQzCsIKsC6 N+5Q4y27ejUzH1neiyufn5fNOwlTlrSoa6TdM9xaLkK+QI/NN4qS6KRF4tZirjvNRPsW fCAQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=qVDGL0Id; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e5-20020a17090301c500b00155f0855954si11019873plh.524.2022.04.04.14.23.29; Mon, 04 Apr 2022 14:23:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=qVDGL0Id; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S1351737AbiDBBLm (ORCPT + 99 others); Fri, 1 Apr 2022 21:11:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43594 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353642AbiDBBLI (ORCPT ); Fri, 1 Apr 2022 21:11:08 -0400 Received: from mail-pg1-x54a.google.com (mail-pg1-x54a.google.com [IPv6:2607:f8b0:4864:20::54a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1403492D3B for ; Fri, 1 Apr 2022 18:09:16 -0700 (PDT) Received: by mail-pg1-x54a.google.com with SMTP id p9-20020a63f449000000b0035ec8c16f0bso2356860pgk.11 for ; Fri, 01 Apr 2022 18:09:16 -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=i0u4JArrhDsLDMn+I/rLz2mNP22Vvf7YGTWgik9+mpU=; b=qVDGL0IdD2Tdx7CvPjoGFys1TnI3wEvpBvsUv8P9V8q3FTljNfYJ2DPnWLfm/35OzJ PbT6IaDPucWH4KICB7hzdigaoj7xvylWvGxJeXIi+P9ovIJ148bq9LI//YlDaqEzycU2 H/Pec4/sMRC9KWL7rORgGHEqFqi2d2F97le923SgGv2YQbfootQxz9AvlO1zdiO1VdEF 3mWwX4hpVHo+UInfjOKAbUMF9PORaispXqGHyqdBTBY7jvasQQJ116Ey0kXxNHfncbBx UBr1yRcFTaFzGw3N7BwncRChA6aQNMe5g41GnN18St3Rs3Jk1uO1hEPfkW5BKVbj6Z8p cNCA== 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=i0u4JArrhDsLDMn+I/rLz2mNP22Vvf7YGTWgik9+mpU=; b=8MwIrlUFIioHvqdMg77yHc9xa9+tHoAuhfS/TMiibZ6OTdFIHxcLDSaPStZ8MWogLo C36QSkuLxDzkdEpgTLEZi1F1qfL7QRyr6nEH5K0MXJtIhVbs+X2dV8UHX3z4aGBGd5FG 2uUKUliJ5iIZYPcRRJz8M4y/suyR3dbqNxnEi0SVZcmwXug1JhtYjgAxF8Opuv97h+2D OoSS5y+SHS9va1rScCAdRLIokZe2SWoZ5pcGZ3269RMpW/K6x/1pOLiQYmhatOuKsimA eceJtElGbnFR9I4fqL49BwXAK6P8sKH4Js5ijRVM0SL1W/8kz7hx2Xpy04ifa2UMT6Pf rIKQ== X-Gm-Message-State: AOAM532jPJ4yoYPHNeTKXT4zjnv2Pxu19/9CktShavJBQM5cJm7ilbB9 Q/CxYG/i6oZGTmQUucti1r00vq8tTx0= X-Received: from seanjc.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3e5]) (user=seanjc job=sendgmr) by 2002:a05:6a00:10c2:b0:4fd:a140:d5a9 with SMTP id d2-20020a056a0010c200b004fda140d5a9mr13602205pfu.77.1648861755423; Fri, 01 Apr 2022 18:09:15 -0700 (PDT) Reply-To: Sean Christopherson Date: Sat, 2 Apr 2022 01:09:01 +0000 In-Reply-To: <20220402010903.727604-1-seanjc@google.com> Message-Id: <20220402010903.727604-7-seanjc@google.com> Mime-Version: 1.0 References: <20220402010903.727604-1-seanjc@google.com> X-Mailer: git-send-email 2.35.1.1094.g7c7d902a7c-goog Subject: [PATCH 6/8] KVM: SVM: Re-inject INTn instead of retrying the insn on "failure" From: Sean Christopherson To: Paolo Bonzini Cc: Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, "Maciej S . Szmigiero" Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL autolearn=unavailable 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 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); + break; default: break; } + } static void svm_cancel_injection(struct kvm_vcpu *vcpu) -- 2.35.1.1094.g7c7d902a7c-goog