Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp1129986rwe; Thu, 25 Aug 2022 16:26:35 -0700 (PDT) X-Google-Smtp-Source: AA6agR5GgOA0fgM1aMxUAJyW/UaP2qWe4/S6BwnCoCZoa7jMlUNkulxBvU+VZ3azw+3sNomOpQdw X-Received: by 2002:a17:907:6e86:b0:73d:7f7f:bbc9 with SMTP id sh6-20020a1709076e8600b0073d7f7fbbc9mr3750805ejc.409.1661469994703; Thu, 25 Aug 2022 16:26:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661469994; cv=none; d=google.com; s=arc-20160816; b=aEYpHFUOOTSY+/0t14J6sq/g3ulZgyP5GzSFafDwjIBSk9FKtp2XDuSVgyNOEsrbN3 uexBr78Wu5EPZJRSpgTHEoSR8aTd0KK3dic+6A/7JQs4tpolG10pi/67gq6qDjTQAP5E sAU+lM5cfUdJAMdFsGDrRpb9clzUxYVDy5I/8963pausZ/pgmiyLAVWpOZhSO6CxR0ws kkLlfiwE1pRtFHq58XT6UmnuXnGrLVvtiLCsGPzYp07TOwN32hdbezd74oVQvCFYeiAw oe1dNbWJHSVRVuX5B+iER+0H0m8NbEm2VAEBBAXVODZpCtT0htNDWieJ7B1i6EdABNpl C/LQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=9B7NG9IIEguT1hVUVREa1K+l0UW23cFMYp7Xko7sDvU=; b=pXH7Byi4E4qN7dy36iYc80tPzaCIY5OmesDPnyAXAmHNVJHRDyKT2BA5nq5MfQhU7B ROr0GX3seNTul8Aq7kQJVpcmzze+oAR+OZKnb30x6nadjOzNSQh7w86glo67wo/SnR5G Er0iFhk5tFSLf4J4/CvfxempOMU6f5WKa6KfE1navtziREyK7tdbEpV5f2YhaO3cKeNz tAlKxMxtgnpWO7v24pKb1vUgmrCQIKzEJ0JGF3QaTTFxahxv206ZdSIlENZOOw3swafM 1DfYDmgkGKXTyz2EC+7gF+/t5maKVXC7RQWbRFxOqzXeeek7fv79v36n9dNCc6ltbc0C THGA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=rnvllA09; 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 f14-20020a056402150e00b00446eaa6faddsi387488edw.445.2022.08.25.16.25.51; Thu, 25 Aug 2022 16:26:34 -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=rnvllA09; 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 S243863AbiHYXV3 (ORCPT + 99 others); Thu, 25 Aug 2022 19:21:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33590 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243989AbiHYXV0 (ORCPT ); Thu, 25 Aug 2022 19:21:26 -0400 Received: from mail-oi1-x229.google.com (mail-oi1-x229.google.com [IPv6:2607:f8b0:4864:20::229]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EE1B79AFE1 for ; Thu, 25 Aug 2022 16:21:24 -0700 (PDT) Received: by mail-oi1-x229.google.com with SMTP id w197so59602oie.5 for ; Thu, 25 Aug 2022 16:21:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc; bh=9B7NG9IIEguT1hVUVREa1K+l0UW23cFMYp7Xko7sDvU=; b=rnvllA09PhkWF1rz5Q9dDBciTpGrAEnMbJrKWffx6D/OzoYXjQKuIkdHBy6kKRGEl4 41FBDuwySDKBW/fxuOcA0PBpr8zJYIjpx7Fk3y5iPlB9OcluBHKfHJOA38EBdxl5G1c5 j99jEs5p7zjoNgvQ68imC646OuQbsLp1Pv7AP1oSDHcK/CiOH8m6eAXXU6G5/HTarMGP lhNNr4ZhKAZgSkfgyCrIPGeyW7EWq2sJxAJpGRrSn0O3hFXCxU0QBiaMLT3wcvgIv35C c9Xb0MEm7Ok9BSVS8lAyBLw0pAxCJpRyYClkI4PHpuGSLoR9tLAvs3vsu3mJyfhbggL5 ybEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc; bh=9B7NG9IIEguT1hVUVREa1K+l0UW23cFMYp7Xko7sDvU=; b=zRP8kO1ldQYeV5QE2jGrm8/QzfJ9Q6yiCSTtAI6NgfMaMXQmDzOR8P/CAhB/wcEBYW rMRIQrqiH4dp/kLbBf29ld1dto2rOjKU8MtW+NQfNUL2FMEZDQ01bviO9uHOXP1Mfj5M hBozzVxbo5aaMObHcWvcS8wEs74IXTYwSPFfoOZ4WmjkwdeQcjTVfEEGDwXJfcdTivyp 0FEeM4Th+CaqR4amWS8ZcbRrMq+nIlzrT4YVPeHzf1QrAZrdOD8w1fm2ceGtjv5G7EXc ioRdGITzBxLOt0/fK5q1Dsepan/AVBS+XikOGfN+Qrl0Oef1vUnmtjyqkSCbEQzm3vRc ROUQ== X-Gm-Message-State: ACgBeo21DElUXkKd3pM79l9JT0OcuyFLPXEwEk/7H3pkAWrpfrv6nzfn sQEE1wI3oA3l4MUWvvfeH6eX4Rz5orwDvWork0t3Rg== X-Received: by 2002:a05:6808:150f:b0:343:3202:91cf with SMTP id u15-20020a056808150f00b00343320291cfmr559807oiw.112.1661469684086; Thu, 25 Aug 2022 16:21:24 -0700 (PDT) MIME-Version: 1.0 References: <20220802230718.1891356-1-mizhang@google.com> <20220802230718.1891356-2-mizhang@google.com> <17505e309d02cf5a96e33f75ccdd6437a8c79222.camel@redhat.com> In-Reply-To: From: Jim Mattson Date: Thu, 25 Aug 2022 16:21:13 -0700 Message-ID: Subject: Re: [PATCH 1/5] KVM: x86: Get vmcs12 pages before checking pending interrupts To: Mingwei Zhang Cc: Sean Christopherson , Maxim Levitsky , Paolo Bonzini , Vitaly Kuznetsov , Wanpeng Li , Joerg Roedel , kvm , LKML , Oliver Upton Content-Type: text/plain; charset="UTF-8" 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 Thu, Aug 25, 2022 at 1:35 PM Mingwei Zhang wrote: > > > There are two uses of KVM_REQ_GET_NESTED_STATE_PAGES: > > > > 1. Defer loads when leaving SMM. > > > > 2: Defer loads for KVM_SET_NESTED_STATE. > > > > #1 is fully solvable without a request, e.g. split ->leave_smm() into two helpers, > > one that restores whatever metadata is needed before restoring from SMRAM, and > > a second to load guest virtualization state that _after_ restoring all other guest > > state from SMRAM. > > > > #2 is done because of the reasons Jim listed above, which are specific to demand > > paging (including userfaultfd). There might be some interactions with other > > ioctls() (KVM_SET_SREGS?) that are papered over by the request, but that can be > > solved without a full request since only the first KVM_RUN after KVM_SET_NESTED_STATE > > needs to refresh things (though ideally we'd avoid that). > > Ack on the fact that the 2-step process is specific to demand paging. > > Currently, KVM_SET_NESTED_STATE is a two-step process in which the 1st > step does not require vmcs12 to be ready. So, I am thinking about what > it means to deprecate KVM_REQ_GET_NESTED_STATE_PAGES? > > For case #2, I think there might be two options if we deprecate it: > > - Ensuring vmcs12 ready during the call to > ioctl(KVM_SET_NESTED_STATE). This requires, as Jim mentioned, that the > thread who is listening to the remote page request ready to serve > before this call (this is true regardless of uffd based or Google base > demand paging). We definitely can solve this ordering problem, but > that is beyond KVM scope. It basically requires our userspace to > cooperate. The vmcs12 isn't the problem, since its contents were loaded into L0 kernel memory at VMPTRLD. The problem is the structures hanging off of the vmcs12, like the posted interrupt descriptor. The new constraints need to be documented, and every user space VMM has to follow them before we can eliminate KVM_REQ_GET_NESTED_STATE_PAGES. > - Ensuring vmcs12 ready before vmenter. This basically defers the > vmcs12 checks to the last second. I think this might be a better one. > However, isn't it the same as the original implementation, i.e., > instead of using KVM_REQ_GET_NESTED_STATE_PAGES, we have to use some > other flags to tell KVM to load a vmcs12? Again, the vmcs12 is not a problem, since its contents are already cached in L0 kernel memory. Accesses to the structures hanging off of the vmcs12 are already handled *during KVM_RUN* by existing demand paging mechanisms. > Thanks. > -Mingwei > > > > In other words, if the demand paging use case goes away, then KVM can get rid of > > KVM_REQ_GET_NESTED_STATE_PAGES. > > > > > KVM_SET_NESTED_STATE in VMX, while in SVM implementation, it is simply > > > just a kvm_make_request(KVM_REQ_GET_NESTED_STATE_PAGES, vcpu); > > > > svm_set_nested_state() very rougly open codes enter_svm_guest_mode(). VMX could > > do the same, but that may or may not be a net positive. > > > > > hmm... so is the nested_vmx_enter_non_root_mode() call in vmx > > > KVM_SET_NESTED_STATE ioctl() still necessary? I am thinking that > > > because the same function is called again in nested_vmx_run(). > > > > nested_vmx_run() is used only to emulate VMLAUNCH/VMRESUME and wont' be invoked > > if the vCPU is already running L2 at the time of migration. > > Ack.