Received: by 2002:ab2:2997:0:b0:1ec:cbc4:63fb with SMTP id n23csp442440lqb; Thu, 29 Feb 2024 05:47:05 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUJMfgoDAQieZnzr+UasERInGJI8bCUop7/RELJhmxv9B9+Uz8bOskTUkyAzO5eJ4tpIUSq9riJWbSMldOnrGTAz0FV1TZHYKc5wkUWgw== X-Google-Smtp-Source: AGHT+IGh8BWhefvQFdMpxl+gxNQiYNrNiJesm9K3SwB/TYvMOUfk1HKVvEi0bsvDqa1tAgitLoTN X-Received: by 2002:a05:6a00:be8:b0:6e4:fc2b:5f6c with SMTP id x40-20020a056a000be800b006e4fc2b5f6cmr2047438pfu.9.1709214425330; Thu, 29 Feb 2024 05:47:05 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709214425; cv=pass; d=google.com; s=arc-20160816; b=O4cNzMtH95bpdRKbhQfq6ihurdDpm3MaoK4CnsOTqOJthwWGk6E2AahCQXPPJIhzb7 G3NViWFYvEOvTqBQiE5TOSvqnFKvbBYPJXaixLaJVS2DtA2JfWK0MJyLyaclrtOkbhvm 3nW3kofENPv8j1pgpKy62euhDFkVeETNnR8oJhXtl9zQRXiJ82xgJlrM79UpALhXkOME iesn5Zu6NT7DJus6q9MDEqWf2eoAepm5b9Y32p5BU53g61Q84CwmY3F3OPlX1bi8oWdQ XBYAdO0IuLVTpolpq9rvG8iqbj6IOaWzt5dWC842BOeOkJOsDvIA8HUVI70BHkkpEAvn CKIA== 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 :content-language:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=LZRA3xUvJ6/fQPLEVDW7g+YFOxIMm0sYRMYX6IkS9/Y=; fh=uJ84oWDf2viIgBs2EUOvMcMbBLtxHHXp7lODycHKGXM=; b=FGbElbf6ZodgGEYJ+HR6oOMbp7BF6Q9juiiTBUlAydbajRL+A9FyrrNOZ+bAPG8l60 vnvWyYbySS51AYuhq4uhYgyjP7M7Ux2HVormPsOFjvL83B22ir76ZN1LMEHCnTBRtDtG ibnG5o+QyV3bl599PsJtNdLLHgdXU78knNrVkdforVvWLsQSXIA7z/LEMTVjTikiJ7ZV szFdpSETNKuYmwOzjtZgPUYrCKZq6V5WA6506+nFEu4PT0MX7dnb01TpLyDHU7ACg1vR WipUeL3sDOclSDcwa6vngZHGYc1kgbeqJeYCTKWN7QIZP8aRgL6+qUHo+f1QfCE1UsL1 44JQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=ihItAHfN; 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-86774-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-86774-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id h12-20020a63210c000000b005dc4fda246esi1355627pgh.615.2024.02.29.05.47.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Feb 2024 05:47:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-86774-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=ihItAHfN; 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-86774-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-86774-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 0348528510D for ; Thu, 29 Feb 2024 13:47:05 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B9A918626B; Thu, 29 Feb 2024 13:46:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="ihItAHfN" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.12]) (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 9220386245; Thu, 29 Feb 2024 13:46:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.12 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709214417; cv=none; b=ufzD84xXDS6g0RMf6TC6hy1eS01aYPPEtrZDVtso6b9a0oM9mHSiy/EBwm1mjbv37J8JeqgUUZPLKLr/lf7UWBHAZG34QGdd5N1qBn0pLCCBkgoyFZR1C/NQEY6l2dhHqnaLUYvroFqoo8zGpJYU8Y/t/lg7/55JE84yCwD/4XA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709214417; c=relaxed/simple; bh=IZyPadrgibtW1v1yI21TN031/QLEFzd+im+daJB3PsI=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=WiUkaHh0AMgqpTQNtOTuFXeP2I4XGULyddTTqHtC7S9bHsGX3u48jzV9UsC4ilGq/qmEFmXck6R8uKfU0EAdpeP/6Y94n622/ktQfmSLotKyIePUYHkfvTnxqq94NUc9GrBP17ucTupDawDEJ+IzUCYEJjsGRAhoEDIncDQX2YE= 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=ihItAHfN; arc=none smtp.client-ip=198.175.65.12 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=1709214414; x=1740750414; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=IZyPadrgibtW1v1yI21TN031/QLEFzd+im+daJB3PsI=; b=ihItAHfN5q5nhOXXW7h179LY1wcI1Fbu2oGMVz+wbFZd1UxmWUYVHfxb k446LwXC3NixSVVhFvqxsmn4TJcn5mCyyoDAA8EWAO2MOb9tK3pxEg8jr 8fRo8sY9dgVxFKKjXTwqMF0JwvchgtHyUMxpdBCWlpTabLc4MdJCzZ3j2 h+mS5rsGztPJ3AyWLBypTrt/aM0Hbg4Vd0INhsDbPBY8h/o27bruhSuDd 1nGcycG17KAP5tJI8KxoN7YLZGXq/fLiruwuv2YHZfGZyyzCGhkGFv9BL Li9nottZAnvOpt/1uIL4bM9mRTcBe1N/tsDxhTKlK5hdQe5ui65Shg9kg A==; X-IronPort-AV: E=McAfee;i="6600,9927,10998"; a="15124338" X-IronPort-AV: E=Sophos;i="6.06,194,1705392000"; d="scan'208";a="15124338" Received: from fmviesa004.fm.intel.com ([10.60.135.144]) by orvoesa104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Feb 2024 05:46:54 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,194,1705392000"; d="scan'208";a="12445275" Received: from xiaoyaol-hp-g830.ccr.corp.intel.com (HELO [10.125.243.127]) ([10.125.243.127]) by fmviesa004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Feb 2024 05:46:52 -0800 Message-ID: <7c0b583b-5e54-4b49-8180-8bfa0f1c67e4@intel.com> Date: Thu, 29 Feb 2024 21:46:49 +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 Content-Language: en-US To: Paolo Bonzini , linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: 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: Xiaoyao Li 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 Reviewed-by: Xiaoyao Li > --- > 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 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;