Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp5731992pxj; Wed, 23 Jun 2021 07:52:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw6zFzbxA2LjrmNZng9Ufp5EdSq7jiQ9eOYylS0e/QNp6mk6D7UF9ELaT48NjJ/zra+kEmI X-Received: by 2002:a5d:94d5:: with SMTP id y21mr7546637ior.110.1624459973119; Wed, 23 Jun 2021 07:52:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624459973; cv=none; d=google.com; s=arc-20160816; b=cmDXVGGLixtJGu9QltKR9Wyz+KhHDb8S74a4UAvShWHqswM5q/rGeFZABAsqryaGFa 7DviP3U4a4rlEvrm0RzKe2CxGfG7QPYhNOlF+BFOQ1ruCG63feUSSEGsvbDCYH+Y1/oB tMTyHVGfsdTjWHOWXhS4iYnhzavLomo1Ia6FSJEIKlJQ/I6Msw7ov3Ncax+bujEZF0LL t9IuE0ZUWCXZlzhdAsJ3FeG+7z465Q9yysDWuy2N1TRdP+myOWt5y3pwytAFosFExA97 J7ZSVJiHC5Vc6HUccIFH8bwh2ZMa1aGd1Tz2FW7C9cTd7kitoEokytlByl4rv7LO5Hpn UOsw== 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=B6xy+P4LVZ8ouXpvquxMkTV0ybbyNpWgSEbmXO80cWc=; b=zsvikN5gCX/h3fTkF40ho4LLBW0XCPMmQLLJpKK16OFs+A/FM1riM5wIYzJS8RBTBj QwYbEAF0sDu/uNBAes4hRDmYqLddFsnB2dtdJalTkk+PcAVz/ugefO3vrDkryvw05lR8 9JK+g+ULQR8b3z4NF3Z5UB2NEiYVq7f4klmi+aB3jNXRSQZGOl2V6rYfhNRtkVCiSsgD DKNVzHvl66cXr/G0zUo3Gi42YZaGpMSj7TLz/JoD+JGSGESl2C1OsUAOJcz07ll+JLuR F/4Kg7PPyQ3jtoV0uwZh8q5OrgttkbiwlS3kBVUjWByLrE/RwasR6gKWkRbThBJvkI5Q za/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=sPiDqD7K; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s13si175825jat.111.2021.06.23.07.52.40; Wed, 23 Jun 2021 07:52:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=sPiDqD7K; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S231229AbhFWOxA (ORCPT + 99 others); Wed, 23 Jun 2021 10:53:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36386 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230263AbhFWOw7 (ORCPT ); Wed, 23 Jun 2021 10:52:59 -0400 Received: from mail-pf1-x42c.google.com (mail-pf1-x42c.google.com [IPv6:2607:f8b0:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5090EC061574 for ; Wed, 23 Jun 2021 07:50:41 -0700 (PDT) Received: by mail-pf1-x42c.google.com with SMTP id 21so2513979pfp.3 for ; Wed, 23 Jun 2021 07:50:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=B6xy+P4LVZ8ouXpvquxMkTV0ybbyNpWgSEbmXO80cWc=; b=sPiDqD7KtpRqVbkfjKi/s1koOVTNNfoE70fuvxFKXX5liM9MIF2f1G9qv2pXBoOrB7 uE5N5s8LNU13c4KWdeD/X7DC2ZMXQeckoX0ayH5GbOTxmz2H48l2eMxjHA6i3dH82v1e l52OM4KXoxxaIHyLQdhz4ibxldhl6il9OZ81Wde44ob6c+HRv66Y5VF+l4wqqW9OK/bp cuK9trMNbWir3heZ8sBT4Z7VpvmJSEOS1a297/Rx5M32axc+aE5zBbDP6iHRtOuOZT7k jFZ/9Kt89wO031pkkexcHnafog0v4wPz2svckv4Wn5ZgjF7OTUygvjaZ1y4h7YvJyuCW hh7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=B6xy+P4LVZ8ouXpvquxMkTV0ybbyNpWgSEbmXO80cWc=; b=KkKWS0qU7UCyso8dGxDaTLdubor2X8/8Hx1punw+34KISBA/xhm1RRVlrsWDGCREYL BYuY5UrfYUnKSqHhfn801eMdyx71JdOzQh5vL8rKmE3EB5fRHbU5J56TbrCS3b8J2/G3 7ZbfMBgHrtBd2JWpYXAKEVEUGJfrlyPh9+8zdDBPi3pcLKR04TaXxo2OmmWkafWb5iSx 9j5j3/rOGsZrBLvMaKMNUqhIf7y1A0owNhcwamv+ye4n6qkR1UHx5BXpBjDUBP/3Okae 6YFTE3mHQkBUmBMwQEnnqC6eny2Qxto+ZgOaYiTNDqqpQQ2w3KkPF4919Haimbp+ij/M Ny0Q== X-Gm-Message-State: AOAM531zRqgaSzMDufZ9BBAhHht+fgywpHy3PzQ9/y+oB0+pIIf1TPUk UeBNDF2OknSxqVtzFRdmigyv0Q== X-Received: by 2002:a63:ed12:: with SMTP id d18mr4205416pgi.12.1624459840567; Wed, 23 Jun 2021 07:50:40 -0700 (PDT) Received: from google.com (157.214.185.35.bc.googleusercontent.com. [35.185.214.157]) by smtp.gmail.com with ESMTPSA id w123sm198370pfb.109.2021.06.23.07.50.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Jun 2021 07:50:39 -0700 (PDT) Date: Wed, 23 Jun 2021 14:50:36 +0000 From: Sean Christopherson To: Paolo Bonzini Cc: Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Yu Zhang , Maxim Levitsky Subject: Re: [PATCH 03/54] KVM: x86: Properly reset MMU context at vCPU RESET/INIT Message-ID: References: <20210622175739.3610207-1-seanjc@google.com> <20210622175739.3610207-4-seanjc@google.com> <3c3f9251-cab4-70ee-6e38-85fe8e6579f7@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <3c3f9251-cab4-70ee-6e38-85fe8e6579f7@redhat.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jun 23, 2021, Paolo Bonzini wrote: > On 22/06/21 19:56, Sean Christopherson wrote: > > + /* > > + * Reset the MMU context if paging was enabled prior to INIT (which is > > + * implied if CR0.PG=1 as CR0 will be '0' prior to RESET). Unlike the > > + * standard CR0/CR4/EFER modification paths, only CR0.PG needs to be > > + * checked because it is unconditionally cleared on INIT and all other > > + * paging related bits are ignored if paging is disabled, i.e. CR0.WP, > > + * CR4, and EFER changes are all irrelevant if CR0.PG was '0'. > > + */ > > + if (old_cr0 & X86_CR0_PG) > > + kvm_mmu_reset_context(vcpu); > > Hmm, I'll answer myself, is it because of the plan to add a vCPU reset > ioctl? Heh, no, I'm not thinking that far ahead at the moment. Using "if (init_event)" also resets the MMU when paging was disabled prior to INIT, which is unnecessary. "if (init_event && (old_cr0 & X86_CR0_PG))" would obviously work, but I guess I was feeling clever. As for why I don't want to unnecessarily reset the MMU, my preference for the MMU role/context logic is to be as precise as possible to help document "why". Doing a MMU reset on any INIT obviously won't break anything, but it doesn't highlight that the true motivation is CR0.PG being cleared, not simply that INIT occurred. I.e. the MMU context is a KVM construct, there is no architectural model that we're trying to follow.