Received: by 2002:a89:2c3:0:b0:1ed:23cc:44d1 with SMTP id d3csp219452lqs; Mon, 4 Mar 2024 22:56:05 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXswXYtnfHLVZQ0AEsNhV52kaG2JOlwKRsl5x//VNx24rAMflpdF0sRTp9Tkee0o1W6yj/so/MmQvDBBR6n+NpOFIbyfoLoQ037Flm4Cg== X-Google-Smtp-Source: AGHT+IG+kDnSlLiaWfQm7IuX6a/vF1i56ZlU4IjoIODlJ93QIqol5FJdZc7Ivs5Mj6mBg+etAHbQ X-Received: by 2002:a05:620a:222b:b0:788:346e:6535 with SMTP id n11-20020a05620a222b00b00788346e6535mr870445qkh.42.1709621764779; Mon, 04 Mar 2024 22:56:04 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709621764; cv=pass; d=google.com; s=arc-20160816; b=KcwQeKp3H1ruS/tEubbbkCA24/OK88mycULbQFECmynVbG2Ou9ZcA2fHnm6vh9/Se0 f3QEsinJmHWI9eevgEJ8arZ0zH1SZ2m/w7rflTWW3KS/kD+COZSFAArtjko6pqRBUOu2 b3EDDA6mdUrqjjrh4D+6sgB7Q+oG++DIy91AAZ0a9pAEmLRYXKMPCD9Hm4SMp3cnVj5q jdZs7bIrJGudCFMUqTMlSZtM6LEPW/C5JXDeUc7zEZSKtkXYNglkcJ4ZCgBhnsv/7pTH etqxUbcqUeP3+NaMigKv8oBGEBmNf/8jKC9VhYxzSlTjF66FMNo5J99ZpQcp3V4nPrGl 3jOA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to:subject :user-agent:mime-version:list-unsubscribe:list-subscribe:list-id :precedence:date:message-id:dkim-signature; bh=jcTLPjURxw0YNfVng3hXNwDT+GD9bh5ZL5PcPACIMyQ=; fh=tgUWUbuI+B0KV3Xw+e/6lpHO2uTJDIACNIPu4ivbyA8=; b=nVXpzlD13+H6LeKZJgL04NuXqslP4au7bT+rIkbBo7Y172DJ8SC1gE6uNfoigRZTOf vSb3ADQwfR6B4i2/OZSU2fARWuk40cG7nJqKsz1epfgoavr2XTtn+4vLfQKw6n3P2HRA Dxsg3R6FE0igpiVTxZIzJ0rurERTGOi7Ex0RG0RVtCHC3hmTeR3vfWhObTs2WxLB25S5 n3cscYOWUrXpYI1Ed65vE4f4rvDn+wN+7BWqzojuuA8v/P2OxwjKCBJL5CdWbSGBl0E0 AF1MprfIUE28qfAuIkMvJQGwsPzCBOyuNpBWjYxNuBRHCjV0gl8KN5bULLfs7r3ImCmr ZaJw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=cvy3S4ln; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-91753-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-91753-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id l8-20020a05620a210800b0078825f44274si4226042qkl.587.2024.03.04.22.56.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Mar 2024 22:56:04 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-91753-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=cvy3S4ln; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-91753-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-91753-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.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 7F6081C20A9E for ; Tue, 5 Mar 2024 06:56:04 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 318647C085; Tue, 5 Mar 2024 06:55:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="cvy3S4ln" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A4DFC43AC5; Tue, 5 Mar 2024 06:55:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.17 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709621753; cv=none; b=BL/yYZLwiMiOSpao8EUNvMbWCBL4TeAaGqLnw5zAGcOT0OJ5umjwjRRCrNxvcO4SYsNgI2bIMC4ts4C/dLnTRx22alCugIbsFVY0uV8bQME+vLvifEWHg9FvZ3T6s+NKkD0ne933S1WQ5OJwSdFzr+sLPBDnKdqoXfVCYMhjp8A= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709621753; c=relaxed/simple; bh=l5gLoZUsr+5xcG/0VUQfe6qG8NXwhnl1SQb/YulRLgo=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=eANaRHcGYJulqphbwvC2v9GIUYoYFe8CvwZAsZKLj57XSan+7Kfmam11McIDgOeF7uap/tdwi0oh8N0bnWH9t9O9IxKGTkIqbjq7qzdr/ccyry+QogCEKl6Av/KEAP5Yaq4vdaVfjV9yAO3LYq89G4jEwsrwkC+DboDI2KvT3xw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=cvy3S4ln; arc=none smtp.client-ip=198.175.65.17 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1709621751; x=1741157751; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=l5gLoZUsr+5xcG/0VUQfe6qG8NXwhnl1SQb/YulRLgo=; b=cvy3S4lnvR1Gq7gDozw/DX+ml7GpU/tobGlFYVUMgS65TkCpaN3AkXrP CrT20ozBlR8Zd+dWA5t31fuxL39n5oN4smQDzztRmMf8/7GLqFPEVPIEZ CS6jzgSyEvpGpmetuwib/Gzmx9YuGMOBFp1YqSSPw13XaJtKolaicmiSX DGIdO/3b5LrTpsYoHGKqjyCESz39yW41zIKkRHuGY/FlDjHZ2QwzdXYN0 VQadFyNu3lolx9vlXTfn9IQsb0eKuxuPr+2s19eS4SLrZauINqxclLdFQ nSlLXs7ADT1uYyUgSy/ydAfwAt6lqHNrdPPN4Gk0LyGDX7GaiBNuoHZDz A==; X-IronPort-AV: E=McAfee;i="6600,9927,11003"; a="4313734" X-IronPort-AV: E=Sophos;i="6.06,205,1705392000"; d="scan'208";a="4313734" Received: from orviesa006.jf.intel.com ([10.64.159.146]) by orvoesa109.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Mar 2024 22:55:51 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,205,1705392000"; d="scan'208";a="9684219" Received: from binbinwu-mobl.ccr.corp.intel.com (HELO [10.238.8.218]) ([10.238.8.218]) by orviesa006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Mar 2024 22:55:50 -0800 Message-ID: <6bd61607-9491-4517-8fc8-8d61d9416cab@linux.intel.com> Date: Tue, 5 Mar 2024 14:55:46 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 02/21] KVM: Allow page-sized MMU caches to be initialized with custom 64-bit values To: Paolo Bonzini Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, seanjc@google.com, michael.roth@amd.com, isaku.yamahata@intel.com, thomas.lendacky@amd.com References: <20240227232100.478238-1-pbonzini@redhat.com> <20240227232100.478238-3-pbonzini@redhat.com> From: Binbin Wu In-Reply-To: <20240227232100.478238-3-pbonzini@redhat.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 2/28/2024 7:20 AM, Paolo Bonzini wrote: > From: Sean Christopherson > > Add support to MMU caches for initializing a page with a custom 64-bit > value, e.g. to pre-fill an entire page table with non-zero PTE values. > The functionality will be used by x86 to support Intel's TDX, which needs > to set bit 63 in all non-present PTEs in order to prevent !PRESENT page > faults from getting reflected into the guest (Intel's EPT Violation #VE > architecture made the less than brilliant decision of having the per-PTE > behavior be opt-out instead of opt-in). > > Signed-off-by: Sean Christopherson > Signed-off-by: Isaku Yamahata > Message-Id: <5919f685f109a1b0ebc6bd8fc4536ee94bcc172d.1705965635.git.isaku.yamahata@intel.com> > Signed-off-by: Paolo Bonzini > --- > include/linux/kvm_types.h | 1 + > virt/kvm/kvm_main.c | 16 ++++++++++++++-- > 2 files changed, 15 insertions(+), 2 deletions(-) Reviewed-by: Binbin Wu > > diff --git a/include/linux/kvm_types.h b/include/linux/kvm_types.h > index d93f6522b2c3..827ecc0b7e10 100644 > --- a/include/linux/kvm_types.h > +++ b/include/linux/kvm_types.h > @@ -86,6 +86,7 @@ struct gfn_to_pfn_cache { > struct kvm_mmu_memory_cache { > gfp_t gfp_zero; > gfp_t gfp_custom; > + u64 init_value; > struct kmem_cache *kmem_cache; > int capacity; > int nobjs; > diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c > index 9c99c9373a3e..c9828feb7a1c 100644 > --- a/virt/kvm/kvm_main.c > +++ b/virt/kvm/kvm_main.c > @@ -401,12 +401,17 @@ static void kvm_flush_shadow_all(struct kvm *kvm) > static inline void *mmu_memory_cache_alloc_obj(struct kvm_mmu_memory_cache *mc, > gfp_t gfp_flags) > { > + void *page; > + > gfp_flags |= mc->gfp_zero; > > if (mc->kmem_cache) > return kmem_cache_alloc(mc->kmem_cache, gfp_flags); > - else > - return (void *)__get_free_page(gfp_flags); > + > + page = (void *)__get_free_page(gfp_flags); > + if (page && mc->init_value) > + memset64(page, mc->init_value, PAGE_SIZE / sizeof(mc->init_value)); > + return page; > } > > int __kvm_mmu_topup_memory_cache(struct kvm_mmu_memory_cache *mc, int capacity, int min) > @@ -421,6 +426,13 @@ int __kvm_mmu_topup_memory_cache(struct kvm_mmu_memory_cache *mc, int capacity, > if (WARN_ON_ONCE(!capacity)) > return -EIO; > > + /* > + * Custom init values can be used only for page allocations, > + * and obviously conflict with __GFP_ZERO. > + */ > + if (WARN_ON_ONCE(mc->init_value && (mc->kmem_cache || mc->gfp_zero))) > + return -EIO; > + > mc->objects = kvmalloc_array(capacity, sizeof(void *), gfp); > if (!mc->objects) > return -ENOMEM;