Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp1142913pxb; Wed, 6 Apr 2022 09:42:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzVo/AKUoEFF4Jt3Pp3D6PIV0csr263gX7hIPKR8SAyOSDJ02dI+KQdltU1gHeGJSQcZPYQ X-Received: by 2002:a17:90b:1b10:b0:1c9:cf93:c57 with SMTP id nu16-20020a17090b1b1000b001c9cf930c57mr10716013pjb.154.1649263348853; Wed, 06 Apr 2022 09:42:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649263348; cv=none; d=google.com; s=arc-20160816; b=pI4FtodBo9Cyu5qOIBzYAXdNavHxL1cVBq8qlPEOQYiqOwFgTyIpJycVBdVYJiV+M9 Jbra5n360nPaJHrQCE8hOgspb2JABXhWILXW3/5fYfek4X06njN4p+m9YRgZDhtCEPBU 4zGAi5HGh6jEhT+qYP8d2ab+l107JXkLpSQxiLpJ0oaeBEZcEE+apq9g3foOGtzd7k8s h/EAdm3g2L9Lsn4ev5sVa0Bkv8vyCaTpQRGvlkn9h9D/aJPCDcPK64HAd9nowbLH9hHN topgHUBnbI9CbiRhZGxheE167L5jJhOX1+Pp52b1WnVvPKDPXGxCMdxap4E7cAGySiGU HXRQ== 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:cc:to:from:date:dkim-signature; bh=tUE3dxQm/ksTxTn0YMfdCief23RhMLZPJwxq1FLJlMc=; b=QPxxtT1ofzVtgpq5xunI0g+nIJcCYGf2/WuZLtmE1FEbi9/41vjFsztstL/qjiOBiI QJYJSM4wOGqV+Gx/+Hp78MibL4A77IE2nDBMdtFjpvRDz2cFerWhIBIbzovQl6c4RRHo 8NsqQDZfS2sBut5UFb1eXl+niIlw10NwYbyzWWoOgrnPItSWkBsRXx8+/y+2FsdNj/KA L8M+nGBxrpbK4XJMbrXN+fZUL8sxcpskpRCWU+ydLguFmk1KzhjBM0yj0OxXRXzAft6W 9OzRmLDbwZXLZnVPB6hxIHXeI0sowy3MKsHa0B03XaFZEQNKJMMh4jgAFY05Zq1OuAAc MUuQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=VDD6vs6I; 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 b12-20020a170902d88c00b001562e0ba125si15213655plz.504.2022.04.06.09.42.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Apr 2022 09:42:28 -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=VDD6vs6I; 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 7350AA27C4; Wed, 6 Apr 2022 09:29:07 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237125AbiDFQbB (ORCPT + 99 others); Wed, 6 Apr 2022 12:31:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53440 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237556AbiDFQah (ORCPT ); Wed, 6 Apr 2022 12:30:37 -0400 Received: from mail-pl1-x629.google.com (mail-pl1-x629.google.com [IPv6:2607:f8b0:4864:20::629]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 22ED941FD1A for ; Tue, 5 Apr 2022 18:48:20 -0700 (PDT) Received: by mail-pl1-x629.google.com with SMTP id n9so694361plc.4 for ; Tue, 05 Apr 2022 18:48:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=tUE3dxQm/ksTxTn0YMfdCief23RhMLZPJwxq1FLJlMc=; b=VDD6vs6I4ZQlRu9OeS2u6w2N8sFH2qI9RbfYFDtXvg9XdFfZxICldOMoE7yokycFxh yuQyWgSPIAK+HELV4CSopTWMPJFA4XXa6j+0duIyjmxDyTV/2aQhlNB37qiN6edt+A+l YKf4BLcWUI+o1ieTRXp19Q8G55/hJgpwrrR8fcNKpbsWe3NA7JyJeE64hoWBFtAaGd+P XySN7WvclIffaDz9YH+XEZmBp4VKMuYdfOMJ8CuG00zY7T+uhq78Y/nlQ3LX0nSrTlpq SSM1ZYh6SRV+g6pnoay+cqEe9rhAWH8yj5JELx/5ziOXmXPfFhpoRGCtQ/5FX5qZXUQC MUnQ== 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:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=tUE3dxQm/ksTxTn0YMfdCief23RhMLZPJwxq1FLJlMc=; b=oHcEVS5T3SWwjqUmxg/ndoaqlPAQB8SeQiTKyZIOlKb37f0OwvshdJikCTa2THbLOr PGkh+Q/+1b2TdBItuUKffuVic/g09Z5l/M2IuWjW/3/4AN53jOcz8b2Cb7IU81E5xzuf 6Ui29DxIN1Jeow9ZvsrqHCYL6+LbEQsEvifN6wP16L7HWoQLJxjzId8/DzOhpwngscQn X9dEs2EmO5owNupqxgouja+D1Hvx5z9vwSiJxpqw1u6eD4/hklRGOFaz+ugsFnFHv2A7 wNUEkYtuly4tb7SY75MVqdCfniiVOr/lnUTw7ew3nHC1S56IFJhPDxmf4IkB7kge4ZH2 GqhQ== X-Gm-Message-State: AOAM532yi9YlcLrLReNb0CozwNvGeYLWQzk4C6d5/i6eCBweZRT9KGQj 4wzcZUXyYfWx+pE86VLDWA+g2BQAJlqFMA== X-Received: by 2002:a17:902:da90:b0:154:1510:acc7 with SMTP id j16-20020a170902da9000b001541510acc7mr6258840plx.103.1649209699460; Tue, 05 Apr 2022 18:48:19 -0700 (PDT) Received: from google.com (157.214.185.35.bc.googleusercontent.com. [35.185.214.157]) by smtp.gmail.com with ESMTPSA id y3-20020a17090a8b0300b001c735089cc2sm3534686pjn.54.2022.04.05.18.48.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Apr 2022 18:48:18 -0700 (PDT) Date: Wed, 6 Apr 2022 01:48:15 +0000 From: Sean Christopherson To: "Maciej S. Szmigiero" Cc: Maxim Levitsky , Paolo Bonzini , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , kvm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 5/8] KVM: SVM: Re-inject INT3/INTO instead of retrying the instruction Message-ID: References: <20220402010903.727604-1-seanjc@google.com> <20220402010903.727604-6-seanjc@google.com> <7caee33a-da0f-00be-3195-82c3d1cd4cb4@maciej.szmigiero.name> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <7caee33a-da0f-00be-3195-82c3d1cd4cb4@maciej.szmigiero.name> 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 Mon, Apr 04, 2022, Maciej S. Szmigiero wrote: > On 4.04.2022 18:49, Sean Christopherson wrote: > > On Mon, Apr 04, 2022, Maxim Levitsky wrote: > > In svm_update_soft_interrupt_rip(), snapshot all information regardless of whether > > or not nrips is enabled: > > > > svm->soft_int_injected = true; > > svm->soft_int_csbase = svm->vmcb->save.cs.base; > > svm->soft_int_old_rip = old_rip; > > svm->soft_int_next_rip = rip; > > > > if (nrips) > > kvm_rip_write(vcpu, old_rip); > > > > if (static_cpu_has(X86_FEATURE_NRIPS)) > > svm->vmcb->control.next_rip = rip; > > > > and then in svm_complete_interrupts(), change the linear RIP matching code to look > > for the old rip in the nrips case and stuff svm->vmcb->control.next_rip on match. > > > > bool soft_int_injected = svm->soft_int_injected; > > unsigned soft_int_rip; > > > > svm->soft_int_injected = false; > > > > if (soft_int_injected) { > > if (nrips) > > soft_int_rip = svm->soft_int_old_rip; > > else > > soft_int_rip = svm->soft_int_next_rip; > > } > > > > ... > > > > if soft_int_injected && type == SVM_EXITINTINFO_TYPE_EXEPT && > > kvm_is_linear_rip(vcpu, soft_int_rip + svm->soft_int_csbase)) { > > if (nrips) > > svm->vmcb->control.next_rip = svm->soft_int_next_rip; > > else > > kvm_rip_write(vcpu, svm->soft_int_old_rip); > > } > > > > > > > > Despite what the svm_update_soft_interrupt_rip() name might suggest this > handles only *soft exceptions*, not *soft interrupts* > (which are injected by svm_inject_irq() and also need proper next_rip > management). Yeah, soft interrupts are handled in the next patch. I couldn't come up with a less awful name. > Also, I'm not sure that even the proposed updated code above will > actually restore the L1-requested next_rip correctly on L1 -> L2 > re-injection (will review once the full version is available). Spoiler alert, it doesn't. Save yourself the review time. :-) The missing piece is stashing away the injected event on nested VMRUN. Those events don't get routed through the normal interrupt/exception injection code and so the next_rip info is lost on the subsequent #NPF. Treating soft interrupts/exceptions like they were injected by KVM (which they are, technically) works and doesn't seem too gross. E.g. when prepping vmcb02 if (svm->nrips_enabled) vmcb02->control.next_rip = svm->nested.ctl.next_rip; else if (boot_cpu_has(X86_FEATURE_NRIPS)) vmcb02->control.next_rip = vmcb12_rip; if (is_evtinj_soft(vmcb02->control.event_inj)) { svm->soft_int_injected = true; svm->soft_int_csbase = svm->vmcb->save.cs.base; svm->soft_int_old_rip = vmcb12_rip; if (svm->nrips_enabled) svm->soft_int_next_rip = svm->nested.ctl.next_rip; else svm->soft_int_next_rip = vmcb12_rip; } And then the VMRUN error path just needs to clear soft_int_injected.