Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp3495802lqp; Tue, 26 Mar 2024 10:34:36 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXl90BcHulv6lKzwDypoT71Pds9LalJnTPp/jfGw+5FZakR3lG87pmOA100bthPUmvYJPJHU0fngXq+dJcxLf+Tj9rO3RKmPTEVVbThTA== X-Google-Smtp-Source: AGHT+IHoWDQJsHX8IiU79BMElA7GsmZIJpGlnDq4sC0X1/Rd0r/BtcbkOU9ClC38J8WG/jHgNpoe X-Received: by 2002:a50:951e:0:b0:566:6a9d:6147 with SMTP id u30-20020a50951e000000b005666a9d6147mr2082589eda.0.1711474476782; Tue, 26 Mar 2024 10:34:36 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711474476; cv=pass; d=google.com; s=arc-20160816; b=CzOnyKKC3JgTeDMqtcpBlPlI+k/qwpe2hfPf/7f8EFf/udcCYFNgZB/PSbVU7gtNCa 18rLT6qnTcfAxTTS3fsIZY9ZxsAsi24zLeu9i7GfFQfENfjXS8xGKHhF85Ea1wVq/9j+ Tl8KRJon5F+fGuzfdUTUBv9zzX5HYIe/aIypf10nLb8NvMZ1EpnGzcziUNCCzUB1naeD 1bRTjmCHvXvGNXdNe6w17h6uc2jdD80e1qrBghBpoQbUUEm3/+C/fHH6gg74Q6uLEJ5n ryiaYMgDGrZrEATnEmBp2VUEvGJo/RKjHzhTZAvnirv/8xyVjsLF9M4LbUsX2yarnaCN njjQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=XkombZvNBO5SfC3g6dxyb3a+XV8RbCKa623c8cImg5M=; fh=P/quV/w7uXmndbL78FtEpLTNkJRPx4LJS51PzREvtL8=; b=G0PsBerPxitEcuGWM9U+vWm9/x+jRBhEnz0znU+ueayHHPaIGn1OcAsMlU3K3sX81J /i/KCIXM9JAJwwM9uZypXz7lOGyAmAAqKw64ZVYqLzbulAtsAskfMzCy4maFXVi3zO6R ZMsKRXp8Nv5Foa2BLCxFvXMnAFjPTZwLo3/nKpeKAkn04+xj3zYxq4E/fAm+KIQBPJ/H AeO1aDGJqNarSU2wiiD5yPH/ox5LhuRyqTrNow3ix18O9EMM7+dZ1+4YFGAJsAeaoOIQ W7oWr3jmQRiStxcNh2Ptq3kCztjtq2QTPFdTKTyAPzdV84ChVF8TRCSChdKm87/pW5Cm Qcag==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Vds0Pkbf; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-119607-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-119607-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id b14-20020a056402278e00b0056833760684si3947846ede.272.2024.03.26.10.34.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Mar 2024 10:34:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-119607-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Vds0Pkbf; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-119607-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-119607-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 828A01F3C733 for ; Tue, 26 Mar 2024 17:34:36 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 68B40208B4; Tue, 26 Mar 2024 17:34:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="Vds0Pkbf" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.9]) (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 12C941CD3F; Tue, 26 Mar 2024 17:34:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.9 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711474461; cv=none; b=Cw5E19fgtlfu8jRekLiV81vvJH5oP7QyOwmLcJprrmIPhLVsXpkudSTAluLucSEi7tNudNz71tA76/v5Dl7DQGUiUbqnPSNRhGmEBDWNNAOUJBR1mi6nEhNgk7CSlNMTHUfn7FtK2xWs0aybDygYY/sYSt/rUGFEQ8JLCfqXEv8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711474461; c=relaxed/simple; bh=PP2+ULTolFHZ6Yk2NHBFIy4YY1fXuiQgaFH7sDpUkzY=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=gQzyKMHyIm13AUX8V5Mee7eQxqk9q872+dDKcF14k+ELSqgtqmewByi1NCNkyXkt6Hrmkhr2DP35rolwTk4QB3ZsHWA/ZLOgUnsWHljhzvQ3dsn9eM6HiPHmL9M7nA18IZozv6QDtBvJxaJZFb2x452xsr+oXqZZzhw6kQ9B6Lw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=Vds0Pkbf; arc=none smtp.client-ip=198.175.65.9 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1711474459; x=1743010459; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=PP2+ULTolFHZ6Yk2NHBFIy4YY1fXuiQgaFH7sDpUkzY=; b=Vds0PkbfEO3VkHWO/9dODTzy7j5+RvjPDSIxRoC4KkDQjmlQfUvL9tpN Ngh+5dPhG3drcHLlU1/0GEGDe68CNZIUBChCpaw3yyxvS25RPp12e4pP1 QjkBQviektM4PP/F8m4aHRKUrEUocvnsRBZSAfs4LBEn5lJDB3QhrjIft 3onDqCq9/+nrCU8x5Tk4hIDGVCZ0+YXoyV0vuXiUMvs6JG87NDGkr3Jxk F/Mhq9GZLdRT63enVnzrThEruzTZXM7gUOad35zo9q4B/YG/F+cIkyLsB iYWZoxIiYW0Eh7qusbpMy39xck/dpZWRe9z7BuFeyLfpvKAWYvhZoQWHl A==; X-CSE-ConnectionGUID: sbjI3EQWQu+oLngKAChAUg== X-CSE-MsgGUID: INtoZqSVTPGD4JqUIPVsuQ== X-IronPort-AV: E=McAfee;i="6600,9927,11025"; a="29020005" X-IronPort-AV: E=Sophos;i="6.07,156,1708416000"; d="scan'208";a="29020005" Received: from fmviesa010.fm.intel.com ([10.60.135.150]) by orvoesa101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Mar 2024 10:34:18 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,156,1708416000"; d="scan'208";a="15942645" Received: from ls.sc.intel.com (HELO localhost) ([172.25.112.31]) by fmviesa010-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Mar 2024 10:34:16 -0700 Date: Tue, 26 Mar 2024 10:34:14 -0700 From: Isaku Yamahata To: Binbin Wu Cc: isaku.yamahata@intel.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, isaku.yamahata@gmail.com, Paolo Bonzini , erdemaktas@google.com, Sean Christopherson , Sagi Shahar , Kai Huang , chen.bo@intel.com, hang.yuan@intel.com, tina.zhang@intel.com, isaku.yamahata@linux.intel.com Subject: Re: [PATCH v19 048/130] KVM: Allow page-sized MMU caches to be initialized with custom 64-bit values Message-ID: <20240326173414.GA2444378@ls.amr.corp.intel.com> References: <9c392612eac4f3c489ad12dd4a4d505cf10d36dc.1708933498.git.isaku.yamahata@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: On Tue, Mar 26, 2024 at 11:53:02PM +0800, Binbin Wu wrote: > > > On 2/26/2024 4:25 PM, isaku.yamahata@intel.com 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 > > --- > > include/linux/kvm_types.h | 1 + > > virt/kvm/kvm_main.c | 16 ++++++++++++++-- > > 2 files changed, 15 insertions(+), 2 deletions(-) > > > > diff --git a/include/linux/kvm_types.h b/include/linux/kvm_types.h > > index 9d1f7835d8c1..60c8d5c9eab9 100644 > > --- a/include/linux/kvm_types.h > > +++ b/include/linux/kvm_types.h > > @@ -94,6 +94,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 de38f308738e..d399009ef1d7 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)); > > Do we need a static_assert() to make sure mc->init_value is 64bit? I don't see much value. Is your concern sizeof() part? If so, we can replace it with 8. memset64(page, mc->init_value, PAGE_SIZE / 8); -- Isaku Yamahata