Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp4663287rwb; Mon, 21 Nov 2022 10:13:03 -0800 (PST) X-Google-Smtp-Source: AA0mqf7HuD1eA/r1vWhgqoxIaHDoWK7uS3MVYvjP82KQh8P44gFYhegaXeWN+Qsp5e0qBdYi3suk X-Received: by 2002:a05:6402:3214:b0:459:278b:7a8b with SMTP id g20-20020a056402321400b00459278b7a8bmr2950046eda.355.1669054382980; Mon, 21 Nov 2022 10:13:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669054382; cv=none; d=google.com; s=arc-20160816; b=lF/3+OGaRzD+tpKxrQCzt7AOztIMIHPm3LTEvZ9lqPO/0dHJykMtdKy6VM/Di78AsG lxSrWJbVDiuuKWZMzDezIrBwFJd+DO6Io1SBrlVUk+lLMebl4KCej0xNyh8dRhtS/l4a DV+SScEq3Ya/Pab24XD9nveNtLSLmY1iasL4Q8mfynq4CXX3Olp0DZXuJFKPsBmHvWNt PJojf1J57hNJ3aU3jkqsmnvEIGT+IYKNgYlvALt43Jqc+9T1VhK6Prg6kq78PZ/rbxJp J/41r3VfcGddCr6dcW9RjLBHb+T34BcmrEA2XjGDaiDK2YkFNXBUTNLffBR6zU2qQWfo DiBw== 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-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=RhAYFXLIQS2qzqEcnPTGyFvoB7XVIT1zAlrBiS9X3as=; b=ty7z8P3tuKCdLCeGnpv/UsGr5kb5unrelIe116XQDlkHOi+VjH4PywZsvYLWJWVm4E 8VGdRIVdiUgtWVAGpysfhKh2Y9TIG42XOwyodKFPffxfKvhOqPMYBdZwSjzruFTcohgK tFSZdhBisQgDP9C5ORG+ysrKEnyjCA1rP9q08M1iiJdQwzaP6xUGdGna9EWGKioxYkqv FYw2+l4FQANqzGrWzwbdurRkCuLDEDegl3v6H8byF1qYeRkkt63XnWWe6QyAcRwlzuUa PcKGI/UOx2HMh7CNspmcqQ5HcGz08/+trlU1siCjj3AypJ/KlsdPFRpEEKR92FLBCosG GEsg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=l9dgayGm; 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 z19-20020a05640235d300b00461f10cb543si11048693edc.154.2022.11.21.10.12.36; Mon, 21 Nov 2022 10:13:02 -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=@google.com header.s=20210112 header.b=l9dgayGm; 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 S230342AbiKURvV (ORCPT + 93 others); Mon, 21 Nov 2022 12:51:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41938 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229925AbiKURvS (ORCPT ); Mon, 21 Nov 2022 12:51:18 -0500 Received: from mail-pg1-x52e.google.com (mail-pg1-x52e.google.com [IPv6:2607:f8b0:4864:20::52e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 183EFD28A3 for ; Mon, 21 Nov 2022 09:51:17 -0800 (PST) Received: by mail-pg1-x52e.google.com with SMTP id q1so11804299pgl.11 for ; Mon, 21 Nov 2022 09:51:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=RhAYFXLIQS2qzqEcnPTGyFvoB7XVIT1zAlrBiS9X3as=; b=l9dgayGmBp69vNWuCME0DkDszXhtX5YuYBFfiY16JZGw6bpUAC7pOD03pf7xQY1P6E LDNQDKTVqfidj8enF+srWG7HVLGFHaGkBLPVqgkQ9/4yfHoWz1U1dcAfLs8vx3xdbBDx Yj9uX7QeAlpfubC8g5u86M9QrX6i9JyC+Fl9FeUMKb9BvWRnttr5lPBHSuROZJoyOkgT yfD1JcGKuz4JK46/upSl0QuofIUxcsF6luxDen/MhpWsEqPg29fo0OYa3ZOSbIHPpA+U xtyb0vKqyLC1hta4+sKdU0isvvEtaYEuw/wUHGjHtzSAkuZ+YYp7iRfgoZxKnuCByEoZ gqIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=RhAYFXLIQS2qzqEcnPTGyFvoB7XVIT1zAlrBiS9X3as=; b=4hlZa0Ej0tzZV0ETMd5sjVImsIE5/vCeAIZ0pv55KZjI6GNkm4eL8HovwbJZNnDIlD Mk8b75ELhHMlUbHc6sFjTpWr8rcPt59NIQWPLgWN3u3siQNgCTDy2znQKrczQDxCAqMU didTyzvTO+yEMwwuWmTVxFm1Ynao9cjgw8b621rPGkir9k6IsTLAUuyA6wexp7LhzCSc vcyC1x7TLpj22O2YjiWv4jXcO8sAehpElljiBy2Y1PaiTyrwzZmvqLtrl0B5yYSVFcx1 TSnW9KoP94v6YeWk589+n6LEzs2pGFMegO7Mob80o2WurAr43WFZBnfUiKPXpyj5toJA D5Sg== X-Gm-Message-State: ANoB5pmFl+Da9Mbr27WNTVoZvGvqpadBbXV0D3Znc7ODXaXuIAObYAop kCE8AnIHK14aUt/jTo6e8UOCIw== X-Received: by 2002:a63:4b16:0:b0:476:d0b8:1117 with SMTP id y22-20020a634b16000000b00476d0b81117mr18320733pga.104.1669053076443; Mon, 21 Nov 2022 09:51:16 -0800 (PST) Received: from google.com (7.104.168.34.bc.googleusercontent.com. [34.168.104.7]) by smtp.gmail.com with ESMTPSA id ms17-20020a17090b235100b00218b8f8af91sm1956111pjb.48.2022.11.21.09.51.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Nov 2022 09:51:16 -0800 (PST) Date: Mon, 21 Nov 2022 17:51:12 +0000 From: Sean Christopherson To: Maxim Levitsky Cc: kvm@vger.kernel.org, Paolo Bonzini , Ingo Molnar , "H. Peter Anvin" , Dave Hansen , linux-kernel@vger.kernel.org, Peter Zijlstra , Thomas Gleixner , Sandipan Das , Daniel Sneddon , Jing Liu , Josh Poimboeuf , Wyes Karny , Borislav Petkov , Babu Moger , Pawan Gupta , Jim Mattson , x86@kernel.org Subject: Re: [PATCH 02/13] KVM: nSVM: don't call nested_sync_control_from_vmcb02 on each VM exit Message-ID: References: <20221117143242.102721-1-mlevitsk@redhat.com> <20221117143242.102721-3-mlevitsk@redhat.com> <3829b20beeeed8ec2480eada30b2639b07bc579e.camel@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <3829b20beeeed8ec2480eada30b2639b07bc579e.camel@redhat.com> 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, USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=unavailable 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, Nov 21, 2022, Maxim Levitsky wrote: > On Thu, 2022-11-17 at 20:04 +0000, Sean Christopherson wrote: > > On Thu, Nov 17, 2022, Maxim Levitsky wrote: > > > Calling nested_sync_control_from_vmcb02 on each VM exit (nested or not), > > > was an attempt to keep the int_ctl field in the vmcb12 cache > > > up to date on each VM exit. > > > > This doesn't mesh with the reasoning in commit 2d8a42be0e2b ("KVM: nSVM: synchronize > > VMCB controls updated by the processor on every vmexit"), which states that the > > goal is to keep svm->nested.ctl.* synchronized, not vmcb12.? Or is nested.ctl the > > cache you are referring to? > > Thanks for digging that commit out. > > My reasoning was that cache contains both control and 'save' fields, and > we don't update 'save' fields on each VM exit. > > For control it indeed looks like int_ctl and eventinj are the only fields > that are updated by the CPU, although IMHO they don't *need* to be updated > until we do a nested VM exit, because the VM isn't supposed to look at vmcb > while it is in use by the CPU, its state is undefined. The point of the cache isn't to forward info to L2 though, it's so that KVM can query the effective VMCB state without having to read guest memory and/or track where the current state lives. > For migration though, this does look like a problem. It can be fixed during > reading the nested state but it is a hack as well. > > My idea was as you had seen in the patches it to unify int_ctl handling, > since some bits might need to be copied to vmcb12 but some to vmcb01, > and we happened to have none of these so far, and it "happened" to work. > > Do you have an idea on how to do this cleanly? I can just leave this as is > and only sync the bits of int_ctl from vmcb02 to vmcb01 on nested VM exit. > Ugly but would work. That honestly seems like the best option to me. The ugly part isn't as much KVM's caching as it is the mixed, conditional behavior of int_ctl. E.g. VMX has even more caching and synchronization (eVMCS, shadow VMCS, etc...), but off the top of my head I can't think of any scenarios where KVM needs to splice/split VMCS fields. KVM needs to conditionally sync fields, but not split like this. In other words, I think this particular code is going to be rather ugly no matter what KVM does.