Received: by 2002:a05:6358:bb9e:b0:b9:5105:a5b4 with SMTP id df30csp5911429rwb; Wed, 7 Sep 2022 09:42:00 -0700 (PDT) X-Google-Smtp-Source: AA6agR6ZLN5mkN6sJT7XLZFanlDg48zGwKnXag0R44I2CrGn6lB3HGf1CP61CdFjk6Ep8l3k5Hse X-Received: by 2002:a17:907:2702:b0:741:5881:1054 with SMTP id w2-20020a170907270200b0074158811054mr2885276ejk.411.1662568920412; Wed, 07 Sep 2022 09:42:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662568920; cv=none; d=google.com; s=arc-20160816; b=KIQIV+GBpOQaRe0RUnms1rJ6Vbm+9xVih6pMELvkZCYE9xtMI+4ZWMcLJNXgltx46l S486KC0uHiU+jyybWxAZOAVFtvqy8eLqeY+bE+AUVJEvnNXilSVF8z7eT2LH5TP+ygC4 CjednV5rDLpydPg474uPFoBKFQvj62Oe/zB7VqmzNxaZq3DGbCiv9nlt3Q+9pJ8YybOh 7tTnb2onuYQssFuqIHzkcvhgbOZkD80tmgKvnWpp0jTP6v5hVja98opctq5O762zXjZ/ +cJKwk/M0Gw9BBjYbhN1t+UaPZN6PjUSjjC6jRxqoJuuyjfWL68D56dpRvRXuC0788Ev p1Hw== 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=gu51tTeubGA4NmbCnkGTbmAG64OE9zjLhtK0FhQe950=; b=GORCcPgK8JBLuyS8krVEVq/nNycwJJc62fFVQU1rSwOGqA4PU1cvmqCZ2Y2VOeppeu heymkrd2+mUDH5XFvdhzgA8PIr6JLLj0z8h+cT1wxoIzgvk9f/9i+BaR1rZafg0HuOS3 +FPw0VzNSCKBoXmsZDjNrL5tas77NVEUpGZ7s13QXNaz5Btj5jERuaT9PLYCthRYh4NV dLPs/+I1oC4ECqXmOEMeSgkLzL5pzXpxp3x0q05QnxXqFkDK1Fa/qZSXQRu/KXciq2Sl U6oOmdiSCql89+ASjATms02Ves53buC2KqwsY0ZmV4p4CZAZZs4G2AeYZSgq0e8j1ISB wPXw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=Pr86m6G9; 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 d38-20020a056402402600b0044f2093e0f5si1252490eda.630.2022.09.07.09.41.35; Wed, 07 Sep 2022 09:42:00 -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=Pr86m6G9; 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 S229549AbiIGP4S (ORCPT + 99 others); Wed, 7 Sep 2022 11:56:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44422 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229964AbiIGP4Q (ORCPT ); Wed, 7 Sep 2022 11:56:16 -0400 Received: from mail-pj1-x1033.google.com (mail-pj1-x1033.google.com [IPv6:2607:f8b0:4864:20::1033]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E7EF97FFB1 for ; Wed, 7 Sep 2022 08:56:11 -0700 (PDT) Received: by mail-pj1-x1033.google.com with SMTP id n65-20020a17090a5ac700b001fbb4fad865so15254221pji.1 for ; Wed, 07 Sep 2022 08:56:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date; bh=gu51tTeubGA4NmbCnkGTbmAG64OE9zjLhtK0FhQe950=; b=Pr86m6G98JqU1Urcvo1EUkEDGK9pfiks9+WPDL8jR4YkN8/2gldaS0vRK1P+XSnPxe MlJCY/ltfWaGduF+UUkYT1iLlFjv9NpjpJI8kbEk7vBBQj6qQBAypwpr/KEKvAe1zcE+ Qlpod8JfhDYhxWEpQhrv/Vv/0kQkn1lJJvgNeBD9k+jwdx8Jzpa3d3RBOdWVJ9mTitme pmtUpeXH29obpufNv5uP7nHMZAxksBoaarLwO2xLzGiiVxRdg0wWKvIDlxuc6R5DQzKy t611VsGsQ0HcT2kDuxf12Tc3PymfZwevBZttehAKFwNA4s59+DwFD7dEk3oLG07yujdM 20Kw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date; bh=gu51tTeubGA4NmbCnkGTbmAG64OE9zjLhtK0FhQe950=; b=vjxqe8wOmEP7dWve0Gj5lgdrrCteJ58rjm2907hzIMEOQ9yoxXwZoyogwuHZY1MM3N 7y4BIpfiRI4BYKcLFVPAtodV5vIClfIeDLJY//ns3AD2Ivbq8kOb7EUyYyKf0b9cpii4 R3Mcf8h9V+fxjmNt/FNfTIwDxkpgcx5F4c/h8zbqo508jh4+FJLsYpyMWS62TG5HUDJW 4Z+SBRpVeNsw3WRcXP0lWl+clJ9lTDf+/6FPxXeQcgu1SVwmdNU5NKCajs1zY0rWjFlT xaI6ODgDqOm9Y0VBmEYPPiFdxxihDlKlJ5lfF9CQHC0CmrJ/AxPeGmRVdtOVBk3IH+VZ +SBQ== X-Gm-Message-State: ACgBeo0d8ST61R+PayhLBpkVJHDlueOnZF6zwUP9aqakfbxB7sK7Y7H2 vIgpHF8sJc3Rn8d9df1FoWxVTg== X-Received: by 2002:a17:90b:1e47:b0:200:b9b4:ba1e with SMTP id pi7-20020a17090b1e4700b00200b9b4ba1emr4321382pjb.172.1662566171350; Wed, 07 Sep 2022 08:56:11 -0700 (PDT) Received: from google.com (7.104.168.34.bc.googleusercontent.com. [34.168.104.7]) by smtp.gmail.com with ESMTPSA id s2-20020aa78bc2000000b0053e0d6f353esm4858065pfd.27.2022.09.07.08.56.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Sep 2022 08:56:10 -0700 (PDT) Date: Wed, 7 Sep 2022 15:56:07 +0000 From: Sean Christopherson To: Yuan Yao Cc: Mingwei Zhang , Paolo Bonzini , kvm , LKML , Maxim Levitsky , Vitaly Kuznetsov , Oliver Upton , Jim Mattson Subject: Re: [PATCH v2 1/4] KVM: x86: move the event handling of KVM_REQ_GET_VMCS12_PAGES into a common function Message-ID: References: <20220828222544.1964917-1-mizhang@google.com> <20220828222544.1964917-2-mizhang@google.com> <20220907025042.hvfww56wskwhsjwk@yy-desk-7060> <20220907053523.qb7qsbqfgcg2d2vx@yy-desk-7060> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL 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 On Wed, Sep 07, 2022, Sean Christopherson wrote: > On Wed, Sep 07, 2022, Yuan Yao wrote: > > On Tue, Sep 06, 2022 at 09:26:33PM -0700, Mingwei Zhang wrote: > > > > > @@ -10700,6 +10706,12 @@ static int vcpu_run(struct kvm_vcpu *vcpu) > > > > > if (kvm_cpu_has_pending_timer(vcpu)) > > > > > kvm_inject_pending_timer_irqs(vcpu); > > > > > > > > > > + if (vcpu->arch.nested_get_pages_pending) { > > > > > + r = kvm_get_nested_state_pages(vcpu); > > > > > + if (r <= 0) > > > > > + break; > > > > > + } > > > > > + > > > > > > > > Will this leads to skip the get_nested_state_pages for L2 first time > > > > vmentry in every L2 running iteration ? Because with above changes > > > > KVM_REQ_GET_NESTED_STATE_PAGES is not set in > > > > nested_vmx_enter_non_root_mode() and > > > > vcpu->arch.nested_get_pages_pending is not checked in > > > > vcpu_enter_guest(). > > > > > > > Good catch. I think the diff won't work when vcpu is runnable. > > It works, but it's inefficient if the request comes from KVM_SET_NESTED_STATE. > The pending KVM_REQ_UNBLOCK that comes with the flag will prevent actually running > the guest. Specifically, this chunk of code will detect the pending request and > bail out of vcpu_enter_guest(). > > if (kvm_vcpu_exit_request(vcpu)) { > vcpu->mode = OUTSIDE_GUEST_MODE; > smp_wmb(); > local_irq_enable(); > preempt_enable(); > kvm_vcpu_srcu_read_lock(vcpu); > r = 1; > goto cancel_injection; > } > > But the inefficiency is a non-issue since "true" emulation of VM-Enter will flow > through this path (the VMRESUME/VMLAUNCH/VMRUN exit handler runs at the end of > vcpu_enter_guest(). Actually, nested VM-Enter doesn't use this path at all. The above holds true for emulated RSM, but that's largely a moot point since RSM isn't exactly a hot path.