Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp781354pxb; Fri, 22 Apr 2022 11:01:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzoXlOdYSbXNDalSeS0cVYB4XnyPWTgYbcJnWlPvzdeMWOZOjB3ldRetpfSqDEEkO9kdb1O X-Received: by 2002:aca:b405:0:b0:322:ed83:59a1 with SMTP id d5-20020acab405000000b00322ed8359a1mr6184804oif.16.1650650501266; Fri, 22 Apr 2022 11:01:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650650501; cv=none; d=google.com; s=arc-20160816; b=ozDGNyFrHskOKxhjRzLGigcMntanIUiVytUOAPeHep31zKU/h0VPGVDMpW4Xs9Fj3B uVdw4yTm27yDlUnyMJbITDBLJT/F29tnSEcUERtpl75X5QxJTA5d+9dAB7j86djEtgfC yUfserZoITxgq7mjq2hAI/m7C9m7XZON+xLdsBQXBmwRmSHBhqIzrNaWN+LmXnNRFwpc yhRRFlGxQ1dmiDiFmp8cDbwvGDkk+w0LHlgWbjATYcUVy3TrBQcDJVglT305PjxZPEaQ yJdjqeflEzpxQGjmkpQEuPwagC5bfIwPVcm4tgsewuCfYdKg19zY1Y2ZmsLw/+2cFPNo bfIw== 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=i6L4akEkVxKPhVRDAOiT0FePP0EWPGcPFgsC+RRy/gQ=; b=EF0tcWlpdf8FhTPEbQ3KYKL94ttlDZN8fqR8TbVCwZrVaipS6FTNroKbpstdYO9aHu P8MQ3GRovdDQOJCzYt/ZUjZ4slhDMrabiM1HebHH51ASnh7AKUpt1WYBqg/iyBpgoGpM 82DxPk0ZvvTdJ5vYTfp//FZl1BGq6UmZGfPBLMqoqBs0a0stpn7qkCzwgzl9HB82piJc rXWgIqzbgR4qcv3AUimIvsDYYGsh2KaQ8mkUcT/+bTXWw0nEeFSZJL58V0znS3Mk3Wmm ZyJHfWbKhqFPwJxQz1ejYos/IVUthfANGLrvRonbdfd3R70Z7HXWs7h0hoptrJtHmnkc SHQw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=bnlPfTSo; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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. [23.128.96.19]) by mx.google.com with ESMTPS id n2-20020a056870240200b000e60f5ad4b4si3599454oap.6.2022.04.22.11.01.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Apr 2022 11:01:41 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=bnlPfTSo; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 25F8FCE640; Fri, 22 Apr 2022 10:42:18 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345881AbiDST5u (ORCPT + 99 others); Tue, 19 Apr 2022 15:57:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47708 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345719AbiDST5s (ORCPT ); Tue, 19 Apr 2022 15:57:48 -0400 Received: from mail-pf1-x430.google.com (mail-pf1-x430.google.com [IPv6:2607:f8b0:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2726CBC8A for ; Tue, 19 Apr 2022 12:55:05 -0700 (PDT) Received: by mail-pf1-x430.google.com with SMTP id p8so9340603pfh.8 for ; Tue, 19 Apr 2022 12:55:05 -0700 (PDT) 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=i6L4akEkVxKPhVRDAOiT0FePP0EWPGcPFgsC+RRy/gQ=; b=bnlPfTSoWYmUXo/nUZ9t0gIb4mbtq/+ury0PkxRLIvhP2n132giaO0/k/ddiyI4vjR D6if6T1Dp5dS+ovCaT2bmXVebbUo1/IEMb+aqjsIDHxuky2VnG1jfRHRwN+nOsTqOQIT +pbAUJlzGUvLE+tgL44HpCken2Qu2XEzqlpzQDZbQ04wk+zaWlEhU6k6spJzHVNtdWZm oQfy0zWk1taM9EC8ZgMBXa+/M9aOIdNEkOJv/oxqqr1lI5jTJuzyGYLqH8Nz1REcGZDC +N3A764GiPsmZIBmwmtdLFt7HOF9Com+Fudh+DKy60Bys+SvW2fYdjyLY8ydh1TqFv1S fTTw== 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=i6L4akEkVxKPhVRDAOiT0FePP0EWPGcPFgsC+RRy/gQ=; b=EMC7zhaGuvGw+wiN3VDdW3ga9Ub8rQ8aYapavv0/r5eBevr2lemiZQy5DHeK51DLdN MC9eQzklOLWyPeJbyxL4H89A+JlsK//MQiqcZUgVN2JZVTAE8fdxUyU+G0Lwb61LM0x2 FsUUsdBDtXFIt+PUBkddlf4FJF6E7vFXHZHWp2r7jLMtcleY/fKYUtUNNxrOvuSCwTgu usRi+mSvhlO68RoFrFV8Hcug+W1vjPNsz9Rs2OI11z/4LFEpImtBbLmTaUu0TqQHFI0I HGHRZcmXiD7b0dMPLpSZ5zKjiTSJMOprrZgZ7WELXLa8Y7eP0g6ol7L33csbwra4Wfmx yE3A== X-Gm-Message-State: AOAM53052zBi+PwR0d7lnPhI/NiNLY4dvv6s3g2+bZ84A+eZDZLVQ/RE fnm2mSteHx/CSkfln4gCVNEzSA== X-Received: by 2002:a65:6c10:0:b0:380:437a:c154 with SMTP id y16-20020a656c10000000b00380437ac154mr15914468pgu.549.1650398104459; Tue, 19 Apr 2022 12:55:04 -0700 (PDT) Received: from google.com (157.214.185.35.bc.googleusercontent.com. [35.185.214.157]) by smtp.gmail.com with ESMTPSA id j10-20020a17090a31ca00b001cb87502e32sm16911021pjf.23.2022.04.19.12.55.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Apr 2022 12:55:03 -0700 (PDT) Date: Tue, 19 Apr 2022 19:55:00 +0000 From: Sean Christopherson To: Isaku Yamahata Cc: Paolo Bonzini , isaku.yamahata@intel.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Jim Mattson , erdemaktas@google.com, Connor Kuehl Subject: Re: [RFC PATCH v5 042/104] KVM: x86/mmu: Track shadow MMIO value/mask on a per-VM basis Message-ID: References: <84d56339-4a8a-6ddb-17cb-12074588ba9c@redhat.com> <20220408184659.GC857847@ls.amr.corp.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220408184659.GC857847@ls.amr.corp.intel.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,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 Sorry, missed my name... On Fri, Apr 08, 2022, Isaku Yamahata wrote: > On Tue, Apr 05, 2022 at 05:25:34PM +0200, > Paolo Bonzini wrote: > > > On 3/4/22 20:48, isaku.yamahata@intel.com wrote: > > > + if (enable_ept) { > > > + const u64 init_value = enable_tdx ? VMX_EPT_SUPPRESS_VE_BIT : 0ull; > > > kvm_mmu_set_ept_masks(enable_ept_ad_bits, > > > - cpu_has_vmx_ept_execute_only()); > > > + cpu_has_vmx_ept_execute_only(), init_value); > > > + kvm_mmu_set_spte_init_value(init_value); > > > + } > > > > I think kvm-intel.ko should use VMX_EPT_SUPPRESS_VE_BIT unconditionally as > > the init value. The bit is ignored anyway if the "EPT-violation #VE" > > execution control is 0. > > Otherwise looks good, but I have a couple more crazy ideas: > > > > 1) there could even be a test mode where KVM enables the execution control, > > traps #VE in the exception bitmap, and shouts loudly if it gets a #VE. That > > might avoid hard-to-find bugs due to forgetting about > > VMX_EPT_SUPPRESS_VE_BIT. > > > > 2) or even, perhaps the init_value for the TDP MMU could set bit 63 > > _unconditionally_, because KVM always sets the NX bit on AMD hardware. Heh, took me a minute to realize you mean EFER.NX. To clarify: KVM requires NX support in hardware if (!boot_cpu_has(X86_FEATURE_NX)) { pr_err_ratelimited("NX (Execute Disable) not supported\n"); return -EOPNOTSUPP; } and 64-bit or PAE paging to enable NPT if (!IS_ENABLED(CONFIG_X86_64) && !IS_ENABLED(CONFIG_X86_PAE)) npt_enabled = false; and the _kernel_ forces EFER.NX=1 for 64-bit and PAE kernels. But whether or not EFER.NX is enabled is irrelevant, it's only the initial value, i.e. the SPTE is guaranteed to be !PRESENT, so hardware will never generate a reserved bit #PF. > > That would remove the whole infrastructure to keep shadow_init_value, > > because it would be constant 0 in mmu.c and constant BIT(63) in tdp_mmu.c. > > > > Sean, what do you think? I like #2, though I suspect we'll still want shadow_init_value so that the MMU caches can be shared without creating a mess. But I still like keeping that detail in the MMUs and out of the vendor modules, even though there's obviously a hard dependency on the MMU doing the right thing. > Then, I'll start with 1) because it's a bit hard for me to test 2) with real AMD > hardware. If someone is willing to test 2), I'm quite fine to implement 2) > on top of 1). 2) isn't exclusive with 1). I can test #2. Tangentially related, the kvm_gfn_stolen_mask() exception to MMIO SPTEs is unnecessarily convoluted and gross. That's partly my fault as I should have just updated enable_mmio_caching when hardware can't support it instead of using shadow_mmio_value to convey that information. I'll submit a patch to fix that, then is_mmio_spte() can be left alone in the TDX series.