Received: by 2002:a05:6358:bb9e:b0:b9:5105:a5b4 with SMTP id df30csp5849105rwb; Wed, 7 Sep 2022 08:49:38 -0700 (PDT) X-Google-Smtp-Source: AA6agR774VEVrkSd6W4B17sIlq37NgGJ2PE5pdjPuFo35sHoKyyuk9+xPM5c6A+SsCh9prQ2/b0o X-Received: by 2002:a17:903:1ce:b0:176:cf65:219b with SMTP id e14-20020a17090301ce00b00176cf65219bmr4421471plh.30.1662565778543; Wed, 07 Sep 2022 08:49:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662565778; cv=none; d=google.com; s=arc-20160816; b=gByUgjUEt61pFW6WXlO6TMdL2q3py1vQuqZDD0Pgz4D3y0IyiLpqwEs3QjEywIVupE EqEoUXm/z/Z0ySN+z8SPv78ZFqhTxmhR6eJqVBNw5aFAsrxzUr+E3haSgTuj/DHo524F mxBCwT7JlUPkJWM/hII0PUo6zgR9Se89sS5WII18CifNU/mmAwunZcLzFqRp02vsiZLZ xgMsV44gNAL+2JYqkyd9RKVGWmwrD5s+qPdDgznMDbRq/eRI7yqtgXw2wtXRUutw1tDg 1rRc1va4280nXA1daHTcTOshb0MpcUoN8kBXBMalBLYmVAwdcMMVZqF+/0afTAkI/lIJ pJ+A== 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=/kPSWel6mobLfUIPD82aMK7TVuiyZeYuc3xqvzKcSuE=; b=S+T/U0o1xA9pHlAlndQICWJIOG+tZrJirROGJyzqGf/TAnTmoDzv+lNx/9j6Ry3E1h FY5j/9uTKwzCnJCK9ygaF+Ih1KE+61u8YS3eJiLcwNIzHRnmN+AKLaRIt3zadRywV7Q/ pJwD44I4dYyISyNKRn1AB47kKGeTawBnK2COOQOggXPQDyh3qfI5zQIAC1gw6imfCL+/ 9eoGDRb9KOlmHKv5pXcIRDi7w15moXYVMgzO038i+Qdu7/oo7EWaYJUAvGN5UREeiJ6w fIxSTHZqE3zwDZVhlKJGGgF4h72XDOBYw3/uFNWkxqS41898AX0lYyid6IZS+CQ0PVOz tHOw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=qmCNpHSx; 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 x10-20020a656aaa000000b0042b1e17d98csi19151933pgu.438.2022.09.07.08.49.26; Wed, 07 Sep 2022 08:49:38 -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=qmCNpHSx; 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 S229819AbiIGPs3 (ORCPT + 99 others); Wed, 7 Sep 2022 11:48:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53412 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229741AbiIGPsZ (ORCPT ); Wed, 7 Sep 2022 11:48:25 -0400 Received: from mail-pl1-x632.google.com (mail-pl1-x632.google.com [IPv6:2607:f8b0:4864:20::632]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 63CA1BADBE for ; Wed, 7 Sep 2022 08:48:23 -0700 (PDT) Received: by mail-pl1-x632.google.com with SMTP id b21so2089116plz.7 for ; Wed, 07 Sep 2022 08:48:23 -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=/kPSWel6mobLfUIPD82aMK7TVuiyZeYuc3xqvzKcSuE=; b=qmCNpHSx7oMT5E8bHSuoHnFgMqmTqMzbeDgsLX9BkR1z+KMoW5hzZIHMaBfZJsaOxJ Yl0l9/C9Jcn9iWO7FfYmZ+ANS+1i0aT5v2LKHY24Mr4s/W/ut3YHwIcn6Osg4NwrRv6b UNEYvl0Q0f80fy8D5hzdNQ5KHLjUTFB0a46NTc3/TKXHcQV6CuZAiDZ4DPbHpQwiJuYH 5zYYPdU9lpAx9qb4krs1P+LMZxujdCMMNGYiZnsen11pdaHZm1PkN4m96QrxEzGUWBxy pR884dXngnJjjQdlfXxIjIvx90AUO08BWUpuHP77sLHfLk236EFxqC+xBDeKssn2xTJH AKSg== 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=/kPSWel6mobLfUIPD82aMK7TVuiyZeYuc3xqvzKcSuE=; b=4jU3LNmP+mCXkKg7AcvaZ7R4nVcSb0LfJAMkEbC02k0Kc/nRyQiCh7jvnOJn4d21Iq XXEJuFe4JnbiRGG6HED4m1cjLP8jRAGHyw3d9ikHoiBm7DNzH1ytu5CSU2ygQ3+V+mSk 2cxFtJ1hqG0vVZn+QeRCfb4s3q6T76UKi1D85ACZno4a4mG+YxbeGOpVgWq0SexKdNVC W32a67i7agEWmrm4RwfkbcrCOKcxm+MuLQEq5cTHnTcrL1i6KBbXL3qlqsCa8kFMj/k4 2OoBoXWUlHcYSU/gmTvyl/8yWWNlkeeBdJ5YmQlVrM3oeMk11hK1wjzcKootLQM5cNzj LwnQ== X-Gm-Message-State: ACgBeo0ac3mjREutx0TaLmUsMGWSoQaffgXjRbhHtNecuj4K7xQgcrtp mkg1DYx+wIHLcUjaZctvozTVyw== X-Received: by 2002:a17:90b:4a8e:b0:1fe:1df3:bb11 with SMTP id lp14-20020a17090b4a8e00b001fe1df3bb11mr4599947pjb.22.1662565702390; Wed, 07 Sep 2022 08:48:22 -0700 (PDT) Received: from google.com (7.104.168.34.bc.googleusercontent.com. [34.168.104.7]) by smtp.gmail.com with ESMTPSA id y1-20020a17090264c100b00172b87d97cbsm4487356pli.67.2022.09.07.08.48.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Sep 2022 08:48:21 -0700 (PDT) Date: Wed, 7 Sep 2022 15:48:17 +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: <20220907053523.qb7qsbqfgcg2d2vx@yy-desk-7060> 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, 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(). > > It only tries to catch the vcpu block case. Even for the vcpu block case, > > the check of KVM_REQ_UNBLOCK is way too late. Ah, kvm_vcpu_check_block() is > > called by kvm_vcpu_block() which is called by vcpu_block(). The warning is > > triggered at the very beginning of vcpu_block(), i.e., within > > kvm_arch_vcpu_runnable(). So, please ignore the trace in my previous email. > > > > In addition, my minor push back for that is > > vcpu->arch.nested_get_pages_pending seems to be another > > KVM_REQ_GET_NESTED_STATE_PAGES. > > Yeah, but in concept level it's not a REQ mask lives in the > vcpu->requests which can be cached by e.g. kvm_request_pending(). > It's necessary to check vcpu->arch.nested_get_pages_pending in > vcpu_enter_guest() if Sean's idea is to replace > KVM_REQ_GET_NESTED_STATE_PAGES with nested_get_pages_pending. Yes, they key is that it's not a request. Requests have implicit properties: e.g. as above, effectively prevent running the vCPU until the request goes away, they can be pended from other vCPUs, etc... And the property that is most relevant to this bug: except for special cases, requests only need to be serviced before running vCPU. And the number of requests is limited due to them being stored in a bitmap. x86 still has plenty of room due to kvm_vcpu.requests being a u64, but it's still preferable to avoid using a request unless absolutely necessary. For this case, since using a request isn't strictly needed and using a request would require special casing that request, my strong preference is to not use a request. So yes, my idea is to "just" replace the request with a flag, but there are subtly quite a few impliciations in not using a request.