From patchwork Tue Mar 7 02:39:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Li, Xin3" X-Patchwork-Id: 65228 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp2211358wrd; Mon, 6 Mar 2023 19:12:25 -0800 (PST) X-Google-Smtp-Source: AK7set9iKJDQAd/rPM36WIHn41UaKRpBG16yXgRQfIwu6Pi2yuXjU0ylfwOaMITmZPYGRKQbJjmU X-Received: by 2002:a05:6a20:6a9e:b0:cc:f047:afaf with SMTP id bi30-20020a056a206a9e00b000ccf047afafmr11625138pzb.11.1678158745256; Mon, 06 Mar 2023 19:12:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678158745; cv=none; d=google.com; s=arc-20160816; b=HTlt4zbbSl7SvodiywC/PZr+SmeKVnFnHAR//35AzKqKnV//h2jfQTdZjoAOkk+zbz wLeIF0PrLb8M/vB7afMZEw5/pAPQk5j1zzNJKAeYnF7cCUtAWUC9QRBrShCXIEcFQAJQ Syn0MTgh+CgZBkuT9KWpfkaA2Mmjpd5oSEdUEDN6QLbdsYHWxSUMdKQYZyoYIz7TEhyS ArVOAHu4KrC/+N4+RMZjOWLugXtHwMpoSKs1G0bxNDZE8FUWnlxj18IGdJvJPLjHQsLW +8qhNKF3tEt92ewpHtEZUg+1veFuBa5m9NFkV8djIGKsVlPwPEwa4b3OkJbZ4qmM0QQJ jaDg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=vWhOxDLf+Qm0Yk+GhlABnoMsuYqHp/rarXsgskBzrC4=; b=C0eDPG1k4MUB7u1rdOJ+NgAIQqGUx3jrjnLajPVzgn3pombIgyaw4wBGZun/LmG44Q KjT33SFqUKjPacn+E8sqrJPbI2nChZicz99svh7TrIp6zMX9/5F8FeL3gUvP7uNfnppH mIxH3A4vd/jZAUYlnV/KrXlfkr3ZeEphxV0FLOamJjn6iEiffTeMkGtJhAdmJmj+wZVm 2XxJGkAnrWRC1vBpalFDj4dWyp/fsX1n9mYFA28X6vGs+CHDX/JTPSWwsBMxk7LaS3zD 2hRwFQXZb2TR7TJr3S3cX25q6+eICaLxvvXehrSpF9VQCVePbKuHTgNC6WCw3xwkWnID zz/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=M4NaJqFj; 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=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u125-20020a627983000000b005e37ee6d9c1si11400712pfc.281.2023.03.06.19.12.12; Mon, 06 Mar 2023 19:12:25 -0800 (PST) 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=@intel.com header.s=Intel header.b=M4NaJqFj; 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=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231208AbjCGDIV (ORCPT + 99 others); Mon, 6 Mar 2023 22:08:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43108 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231161AbjCGDHp (ORCPT ); Mon, 6 Mar 2023 22:07:45 -0500 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 44E6087A02; Mon, 6 Mar 2023 19:06:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1678158374; x=1709694374; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=qJRDv1JU3EvBoam3ACq+r69aYmF+cFETAZ2lAy63Iv0=; b=M4NaJqFjiHGVFafB6zOO46uLyk2CuFmlKks6EFh4Ha+YhS/sER3Texol LpEvoOIa2gijPhKFjV+aXNXRsuJ93oF4UMOebHCDNH61bm/VkF4zOUjr5 d7yyHHJOieuZcKU3pxg+n5AlQ8sS8PzLgugwlt838CEhtxolJjUwRMAdy 2b0ITG7s86o5Nfx2Jg87su1w+xGr0CKler46DZKvU3jJ2CXGqBXXJGN+9 CO+qrMZNoiUVRVt+ZBHvY4R04x7QsA8UixD/aGTnmlm1fOeFSHnsJJJk9 4Ce0sToKVhIU+ZWHOwsbQVMAmnw8U/tO0kA9JpEydOrwZJD9xm091vULp Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10641"; a="338072643" X-IronPort-AV: E=Sophos;i="5.98,238,1673942400"; d="scan'208";a="338072643" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Mar 2023 19:05:24 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10641"; a="676409959" X-IronPort-AV: E=Sophos;i="5.98,238,1673942400"; d="scan'208";a="676409959" Received: from unknown (HELO fred..) ([172.25.112.68]) by orsmga002.jf.intel.com with ESMTP; 06 Mar 2023 19:05:23 -0800 From: Xin Li To: linux-kernel@vger.kernel.org, x86@kernel.org, kvm@vger.kernel.org Cc: tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, hpa@zytor.com, peterz@infradead.org, andrew.cooper3@citrix.com, seanjc@google.com, pbonzini@redhat.com, ravi.v.shankar@intel.com Subject: [PATCH v5 33/34] KVM: x86/vmx: call external_interrupt() to handle IRQ in IRQ caused VM exits Date: Mon, 6 Mar 2023 18:39:45 -0800 Message-Id: <20230307023946.14516-34-xin3.li@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230307023946.14516-1-xin3.li@intel.com> References: <20230307023946.14516-1-xin3.li@intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE,URIBL_BLOCKED autolearn=ham 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759676984802539905?= X-GMAIL-MSGID: =?utf-8?q?1759676984802539905?= When FRED is enabled, IDT is gone, thus call external_interrupt() to handle IRQ in IRQ caused VM exits. Create an event return stack frame with the host context immediately after a VM exit for calling external_interrupt(). All other fields of the pt_regs structure are cleared to 0. Refer to the discussion about the register values in the pt_regs structure at: https://lore.kernel.org/kvm/ef2c54f7-14b9-dcbb-c3c4-1533455e7a18@redhat.com/ Tested-by: Shan Kang Signed-off-by: Xin Li --- Changes since v4: *) Do NOT use the term "injection", which in the KVM context means to reinject an event into the guest (Sean Christopherson). *) Use cs/ss instead of csx/ssx when initializing the pt_regs structure for calling external_interrupt(), otherwise it breaks i386 build. --- arch/x86/kvm/vmx/vmx.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index bcac3efcde41..3ebeaab34b2e 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -47,6 +47,7 @@ #include #include #include +#include #include #include @@ -6923,7 +6924,26 @@ static void handle_external_interrupt_irqoff(struct kvm_vcpu *vcpu) return; kvm_before_interrupt(vcpu, KVM_HANDLING_IRQ); - vmx_do_interrupt_irqoff(gate_offset(desc)); + if (cpu_feature_enabled(X86_FEATURE_FRED)) { + struct vcpu_vmx *vmx = to_vmx(vcpu); + struct pt_regs regs = {}; + + /* + * Create an event return stack frame with the + * host context immediately after a VM exit. + * + * All other fields of the pt_regs structure are + * cleared to 0. + */ + regs.ss = __KERNEL_DS; + regs.sp = vmx->loaded_vmcs->host_state.rsp; + regs.flags = X86_EFLAGS_FIXED; + regs.cs = __KERNEL_CS; + regs.ip = (unsigned long)vmx_vmexit; + + external_interrupt(®s, vector); + } else + vmx_do_interrupt_irqoff(gate_offset(desc)); kvm_after_interrupt(vcpu); vcpu->arch.at_instruction_boundary = true;