Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp2312820pxb; Wed, 9 Feb 2022 15:56:00 -0800 (PST) X-Google-Smtp-Source: ABdhPJzbDa0ib4W5gu/ouMYmwj2nfZXo1ha/jDTGG2McGBfZ8SALMUyKjrUjywOGda1FE9eyOiwS X-Received: by 2002:a17:902:c946:: with SMTP id i6mr4994913pla.74.1644450960076; Wed, 09 Feb 2022 15:56:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644450960; cv=none; d=google.com; s=arc-20160816; b=0d02pKbuav1T1Cck0tqOcZkeNWwZGeki/2LUGLZ5+3ng8ow2ZXBsmrN+yBKFiLhTja Qc7+nh2shgthlTmFRlYjlenudluB3T9uENRwgO8lKVl6LdOO9fbmmUGPAme3ACO0HXRN Mz231GO/toeJSjoj829u9E2tssUyFY49MXqpsfOLUK5eTS3n0eR+a0P05/2vTP3VOD8Y qoVfuSnAw7NNs7vZLVdoM95ZPX0TkZIBUrAVPPR8JI2JkqaC6/wM39JkQiWdrxyztl3Y N1W6W+rUkjszQvCzoRONT3ePLHEgZZMThN4C0GCymnr6fZg931xp+b+CTDkyeVXOWFFS qi9A== 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=5OgBvBtD/pqZyY1Wyl2wDigiqIzipvE7VvYdDX53RaU=; b=F7O88k48hLwTYpG2x4fiU0GS6Zr2mHD1sdkT7bSDfqQ1hm+UoSi8vxYovPYP+wN0J5 RbuJ90Wk3NPsZpbHrhfdp8yo2nX/7JCYzDP8rHMSEgQjhwd9JbKg1pynclf5zvcw8Y3C tyXmmz4KVVNdDwzKpIczvVcSMmRzcYNcvrFoqIpLYzFnZ7Aei3tfBEeQCy7i2xNboQ5y pSAASPcjIDvsQ754BmQeg9O0uyE32fkWfCE2rcpkpVBFP99sMSYeOnurHAWJ4MIqFhTR ctKwvUUHG+oDMt4hVBeioQUuIiti1Zb2RDMFK5eEuP58espr4S+cHPXff7y+QFongKIM ksFw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=lr8JBDfa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1: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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id i186si16919469pge.146.2022.02.09.15.55.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Feb 2022 15:56:00 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=lr8JBDfa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1: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: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 27671E056D03; Wed, 9 Feb 2022 15:25:57 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236568AbiBIWzQ (ORCPT + 99 others); Wed, 9 Feb 2022 17:55:16 -0500 Received: from gmail-smtp-in.l.google.com ([23.128.96.19]:33580 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236557AbiBIWzB (ORCPT ); Wed, 9 Feb 2022 17:55:01 -0500 Received: from mail-pl1-x634.google.com (mail-pl1-x634.google.com [IPv6:2607:f8b0:4864:20::634]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 249E4E04FF0E for ; Wed, 9 Feb 2022 14:55:04 -0800 (PST) Received: by mail-pl1-x634.google.com with SMTP id w20so220783plq.12 for ; Wed, 09 Feb 2022 14:55:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=5OgBvBtD/pqZyY1Wyl2wDigiqIzipvE7VvYdDX53RaU=; b=lr8JBDfah6TBBfm+fcfoKKyOkr4qRbOpNZKNSz0jmz/yX6P+3I80Gf127D2r/XjQUA 3Ks3cAXBSu53tT9w1ibvn5Il5wp07oxQoNqoZM1zcxtyyxZQIfHHyMuH9Wu320T/VBSm k21jxvs3Wk0sFwnWQ/apaH2I3G85S6jN0k4LlkwrlkW2AKh84OQTIFYY2tRdMAOHMMV/ dfkRftgcaKD3gXqcUskLTUJDhSvmru45c+ZrJg5RDsasia1xMO8axDk51mSdiBvv5IkB 8wNBRxeXfiFuT4lbyXRgU8v4Qw+Z4RiFePK00zyExo7XeCKjmjW2zkmocLU63lo4OBBP x8lQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=5OgBvBtD/pqZyY1Wyl2wDigiqIzipvE7VvYdDX53RaU=; b=CfamMLebIXwYxIlxlXKfUMNrHOjBUFhv9eGR6WFdVejSx/U78Ged2Tn7TDWd/vLPr+ UhH+Q6BwEsXWr0wWxE7jP9uWJfpW8Ch84yeP5TyogB3+3bB+68WesMNtMGF0qaTqwBBB dNxa4eUlhVQXLt/U9m3b6kzzhzF/utPGIqsb8VuoC0OblfESFSLSTKnxlqTEbgwCwqBN BZkeKYmSq8X+ldrbjp5dN1eFtI4nRUetwsGj0MUMR1V+stGol+j/YApLVGh8qIbDMOxj H2z2n3htbRG9zEnIitryJ28Sveqt6eIhXTMf4u8UaBB0bJbXcsza02DX7YsCw6jkJr+Q OI9A== X-Gm-Message-State: AOAM533Wn1ChfKA+BE5RJYx7eUBo2Hbx8euJGZoZOgJRm15iJ0qgO61h KC2hklkVWIIfelYnfc0RJivNTQ== X-Received: by 2002:a17:90b:4f8f:: with SMTP id qe15mr5110563pjb.94.1644447303388; Wed, 09 Feb 2022 14:55:03 -0800 (PST) Received: from google.com (157.214.185.35.bc.googleusercontent.com. [35.185.214.157]) by smtp.gmail.com with ESMTPSA id nl7sm7362138pjb.5.2022.02.09.14.55.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Feb 2022 14:55:02 -0800 (PST) Date: Wed, 9 Feb 2022 22:54:59 +0000 From: Sean Christopherson To: Paolo Bonzini Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, dmatlack@google.com, vkuznets@redhat.com Subject: Re: [PATCH 03/23] KVM: MMU: remove valid from extended role Message-ID: References: <20220204115718.14934-1-pbonzini@redhat.com> <20220204115718.14934-4-pbonzini@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220204115718.14934-4-pbonzini@redhat.com> X-Spam-Status: No, score=-9.5 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=no 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 Fri, Feb 04, 2022, Paolo Bonzini wrote: > The level field of the MMU role can act as a marker for validity > instead: it is guaranteed to be nonzero so a zero value means the role > is invalid and the MMU properties will be computed again. Nope, it's not guaranteed to be non-zero: static int role_regs_to_root_level(struct kvm_mmu_role_regs *regs) { if (!____is_cr0_pg(regs)) return 0; <============================================= else if (____is_efer_lma(regs)) return ____is_cr4_la57(regs) ? PT64_ROOT_5LEVEL : PT64_ROOT_4LEVEL; else if (____is_cr4_pae(regs)) return PT32E_ROOT_LEVEL; else return PT32_ROOT_LEVEL; } static union kvm_mmu_role kvm_calc_nested_mmu_role(struct kvm_vcpu *vcpu, struct kvm_mmu_role_regs *regs) { union kvm_mmu_role role; role = kvm_calc_shadow_root_page_role_common(vcpu, regs, false); /* * Nested MMUs are used only for walking L2's gva->gpa, they never have * shadow pages of their own and so "direct" has no meaning. Set it * to "true" to try to detect bogus usage of the nested MMU. */ role.base.direct = true; role.base.level = role_regs_to_root_level(regs); return role; } static void init_kvm_nested_mmu(struct kvm_vcpu *vcpu) { struct kvm_mmu_role_regs regs = vcpu_to_role_regs(vcpu); union kvm_mmu_role new_role = kvm_calc_nested_mmu_role(vcpu, ®s); struct kvm_mmu *g_context = &vcpu->arch.nested_mmu; if (new_role.as_u64 == g_context->mmu_role.as_u64) <== theoretically can get a false positive return;