Received: by 2002:ab2:6203:0:b0:1f5:f2ab:c469 with SMTP id o3csp178151lqt; Thu, 18 Apr 2024 11:37:11 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUK+husXA7cLhkhcA51xe39JF7gBrWPVq/ffYm4it5R8MQN6FzCNx1iP/MCdwUFxdHR8s/cv5IHf2ZYrnDCVu1hJhdFCLmWwVg/yz08KQ== X-Google-Smtp-Source: AGHT+IHB22MHLQYYf3Dha+V1gxSB00l9kNkIRx+FtGoTCqYQ8RMrbgmS42l7gpVT5KICJUfD/RzL X-Received: by 2002:a05:6214:8c:b0:69b:5989:3a34 with SMTP id n12-20020a056214008c00b0069b59893a34mr3532521qvr.38.1713465431659; Thu, 18 Apr 2024 11:37:11 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713465431; cv=pass; d=google.com; s=arc-20160816; b=0lbgYVMXmO8ReHuHh3jaqFC1ppOtoH23sAMQWiUn7MNXceDm3sl8z8JAgZvag+C5PM 1JfpMxH0zEzzdpHmMapWCLw7WGrM0P8PIcbAgG8Hy39l40QouPgXmbBUQ8y0fCtJXHmL TzCCh7eA/XATiPjwcKAdU2GrckDfd/uEO67GOow/Jv8eF+1aLdVHKVlLiJdTrBECoWJ2 birzksFfnUYOeSd0vVuk4vK0p6lUm47hfMdIb1MQo5n4lZorZDgm3o4r9WdltoqP0/Qy Y9Ztqg7X6mDCA/uW/hizdxVACqkSm65WmMCEouzDFrU7rULAEdVbZs339wUCjz3jAcmr 6A5g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :in-reply-to:date:dkim-signature; bh=+wlN/ce91bTf9rbFasUDQdfgpzsyETmNKvn6NbsAl7o=; fh=mgKwbmLBLPL6GhMI08rxhjiAf30BGTLLa1f3iCG6qSU=; b=BBpex4Yf2KKvJYsmcB9/ljomY0nitItq2HbtyzgImj/FQLjg37AhzawUft8KsYirYV qpwO7qgDfQ7zizRTdv0Jon/WGgmdpBCVcJcFhet6GXBdp9ExD4RFxZ2JpjAJvsAIPaLy kYlXfErPfN0NVDNBUMD4COibDGgRLzfmc1BE00QftluJXUOanvcULHMFRhbokss2PWhb 95XFZgw150znbsTuw25N66f6fre7aeX2RcOHSiy6PScaXvZ+0o8yAv6G/yd1f6Voam99 IUWuoC7OY1kJpV0xJJuxi1im8ID4kv47GQEqz48o0MbyoV9ltEJdrc2UCajibhb1lslP YWTQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=rS82ilXo; arc=pass (i=1 spf=pass spfdomain=flex--seanjc.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-150634-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-150634-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id 11-20020a0562140d4b00b006a049a4c02dsi1992019qvr.328.2024.04.18.11.37.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Apr 2024 11:37:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-150634-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=rS82ilXo; arc=pass (i=1 spf=pass spfdomain=flex--seanjc.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-150634-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-150634-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 65F241C21982 for ; Thu, 18 Apr 2024 18:37:11 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EE522178CFA; Thu, 18 Apr 2024 18:37:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="rS82ilXo" Received: from mail-pg1-f201.google.com (mail-pg1-f201.google.com [209.85.215.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DCFD916D30B for ; Thu, 18 Apr 2024 18:36:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713465421; cv=none; b=ilq0uYXoKLlawoVufHEUNpNx/honOKHNtTvQQ+YdmIw7Y4PYEs1NrOW9k8ncnJ9LH+fquryZ+jr0dmlTgxq2fCJKTkPjA6yZJDNustHd0GXBby+pQTJlQ6U7NI2ENgch4EbHHbhWZRQCkz1KAInsVH6HGSp1Hnhwn6ydC1S5Z+I= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713465421; c=relaxed/simple; bh=5M7sY2eNkmePxZYEhbphJRX7F7XSNeGGbs2z+TtGQ10=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=llXnI/x21oYV5JassrT5aGjrHLFSVziDmLI3ZBVNAnKLWOediWDTWTJ1zTZDtsDjtU7b+k0PPQwsHOFQiQ61fI82VWr+3Ma0fRJO3LytM5Xd5TVRPRtiqF1hIse7Eo85SAH4etaW4A9vdIyoYm3hBE7RGjoFwFiEXKl7r/dSIYM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=rS82ilXo; arc=none smtp.client-ip=209.85.215.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Received: by mail-pg1-f201.google.com with SMTP id 41be03b00d2f7-5f7c0bb1b95so207202a12.0 for ; Thu, 18 Apr 2024 11:36:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1713465419; x=1714070219; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:from:to:cc:subject:date:message-id :reply-to; bh=+wlN/ce91bTf9rbFasUDQdfgpzsyETmNKvn6NbsAl7o=; b=rS82ilXoy6GZhfwknA0JqCrTPIg4eHWWzsNFXY1+6YnMxmOVOpz2aPS6qs/yvXNBC/ IY3p6GFKqzBramDmAMK2oJckpsfw/Yn598Tt+qBYIbQXbpPg6r7dHXVYtSC9+j8yen4A dy9TKe3tzEbKadQoCnB6lloa+66xFKtdSB3yzhbns4IPAoFx9sWYXfxqEmbOvbrr7ZK3 Hx97/T559MRJtWsHSU0EpXXuuGNu70C0n9jExU8vFZuGpJy9SBuFgezejK6ccnSJSS0g rX93TTJp4H1GGbpedbgpkbLoU1sFTgy2HMnDjqDK7y1T3VFujup1bgFNb4wy/Fp7G4nu 6ozg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713465419; x=1714070219; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=+wlN/ce91bTf9rbFasUDQdfgpzsyETmNKvn6NbsAl7o=; b=lHF9cPk22rRighONkxABWVhZ7krmubNTC9c8qNo2DxqlsA76iXH6Y6ia/wPcFxdifG bkgm7SCzVKw3Wk+ybNHxiAe3XiWqKzY1V7caYAhGoNsX5hiZDIyfGvyDd0p0c385yfKa LRdZ/aiGmg+TSBEi0RPPNcXL+LiPalRnyc8ffYUP0GxIyPnvyvtgte4w/Sxbho1R7LU+ esUTJrNJEI49qt44owbO2NG9g2ktHB/0NDC5uiI320ddUYolJXqb2hvMmihIUUsAyvvO B3gcUGy/9CbX6Y/+cvf57tD/AjFAwYYwu5hjiOmfVKKc99h4OvwR8653TiItFPsT4kWj E55w== X-Forwarded-Encrypted: i=1; AJvYcCWvlHaQrLvcjGgqNXVlxPDyG2cZDrNfrfT2tQPzhX8h8IgeDbwFeHM+yQVfRKHSV/qjd3rqHhzLhyUklGAwwhuSw7llwQDtVz8tZCXA X-Gm-Message-State: AOJu0YyAk9NG0stFOktQrPy09uwA0tC3flU05B8LpyPuEcCfCtMOUM2a 7xtR57jhU74UgfDyUzdpITzo6K1b1Ca/FVZ59mlKt5I7MbVtbAflu3npCKY3WceJNVW7AFl2/ON E5w== X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a17:90a:3d4f:b0:2a2:bcae:83c1 with SMTP id o15-20020a17090a3d4f00b002a2bcae83c1mr15360pjf.3.1713465419139; Thu, 18 Apr 2024 11:36:59 -0700 (PDT) Date: Thu, 18 Apr 2024 11:36:57 -0700 In-Reply-To: <70f9f3f847e614cbb95be4c011ecb0a5cbd2ef34.camel@cyberus-technology.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240416123558.212040-1-julian.stecklina@cyberus-technology.de> <70f9f3f847e614cbb95be4c011ecb0a5cbd2ef34.camel@cyberus-technology.de> Message-ID: Subject: Re: [PATCH 1/2] KVM: nVMX: fix CR4_READ_SHADOW when L0 updates CR4 during a signal From: Sean Christopherson To: Thomas Prescher Cc: "mingo@redhat.com" , "x86@kernel.org" , "dave.hansen@linux.intel.com" , "hpa@zytor.com" , Julian Stecklina , "tglx@linutronix.de" , "bp@alien8.de" , "pbonzini@redhat.com" , "kvm@vger.kernel.org" , "linux-kernel@vger.kernel.org" Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable On Thu, Apr 18, 2024, Thomas Prescher wrote: > You are right. After your pointers and looking at the nesting code > again, I think I know what to do. Just to make sure I understand this > correctly:=C2=A0 >=20 > If L0 exits with L2 state, KVM_GET_NESTED_STATE will have > KVM_STATE_NESTED_RUN_PENDING set in the flags field. Not necessarily. KVM_STATE_NESTED_GUEST_MODE is the flag that says "L2 sta= te is loaded", the NESTED_RUN_PENDING flag is effectively a modifier on top of th= at. KVM_STATE_NESTED_RUN_PENDING is set when userspace interrupts KVM in the mi= ddle of nested VM-Enter emulation. In that case, KVM needs to complete emulatio= n of the VM-Enter instruction (VMLAUNCH, VMRESUME, or VMRUN) before doing anythi= ng. I.e. KVM has loaded L2 state and is committed to completing VM-Enter, but h= asn't actually done so yet. In retrospect, KVM probably should have forced userspace to call back into = KVM to complete emulation before allowing KVM_GET_NESTED_STATE to succeed, but it'= s a minor blip. > So when we restore the vCPU state after a vmsave/vmload cycle, we don't n= eed > to update anything in kvm_run.s.regs because KVM will enter the L2 > immediately. Is that correct? No? Presumably your touching vCPU state, otherwise you wouldn't be doing vmsave/vmload. And if you touch vCPU state, then you need to restore the o= ld state for things to work. Again, what are you trying to do, at a higher level? I.e. _why_ are you do= ing a save/restore cycle? If it's for something akin to live migration, where = you need to save and restore *everything*, then stating the obvious, you need t= o save and restore everything in KVM too, which includes nested state.