Received: by 2002:a05:7208:3003:b0:81:def:69cd with SMTP id f3csp160629rba; Tue, 26 Mar 2024 12:02:41 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXv3s5lB0R0juvDZGMQAlGBHJUhF/ykPIosVqV/WLXG9ccXHyeIGoez72+NjkLqDmttutuNCMmld7oxJAQKN9nswWSOGQLHe+ivMt7IEg== X-Google-Smtp-Source: AGHT+IEmRXoYzK1XbhN0d5uYdsgOCYNgXrCkUsTJUgeC9QeXoY9oF57Rid7pl3rdKxDyafkj/369 X-Received: by 2002:a50:8a9c:0:b0:56c:2f0a:a63a with SMTP id j28-20020a508a9c000000b0056c2f0aa63amr1317451edj.5.1711479761002; Tue, 26 Mar 2024 12:02:41 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711479760; cv=pass; d=google.com; s=arc-20160816; b=wCdnaI4j1c3cDT06D1nRYlUC4uXo726v/rj5u7DGFM3j2gvVJNR/rysh9mzXoEfn/u vT8bZsifbYf+4VNOG1We01ocwKSFKx+MaB9RGzRgCsOHopJQ11JxvnyYACDHGywjtfYO +0Erp44ZkEj2JnO0tAXwx4/Dlrh9cs0b5b90NMenmecZofqObl6chicGoKvw56k4tP34 PiIBNpGrjIMFI86vH4CAZpbiKo5Rg5/ajqBkHiVwISb+auQI0pCAyNeAj8FJZrvjLRqb QXvNaF/YYg6VKOS0ox722+uMYlz/zcHe3PXal3Kgnjqel6DOie0sG4akG26Ma6n6S2EF E0+Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:references:cc:to:from:subject :user-agent:mime-version:list-unsubscribe:list-subscribe:list-id :precedence:date:message-id:dkim-signature; bh=9+E9LeuDdTvA4vCNCJ2WjoeXm0io06/ijNyNbBT1ukM=; fh=tgUWUbuI+B0KV3Xw+e/6lpHO2uTJDIACNIPu4ivbyA8=; b=RdC8YdYlwrYOR3bIaPXzMm46k34+QpyFP/OxsGXwi/kjiUl9RAlfmgTPUmjRGQ0vVY +D6p5XkIdDueDHzyr+PsmXkEXTtIaXaudcKpE4XtzdLkGlvSbIIjIgpwtxWu7JrALnwc GoHOJXHZZsiRiGTQdbbesDa8g3B2sEUxlr4RRDmkcw7pX35fylnkzmVJsAa8W6WoNWUp ugmY6kqZX+nh6Z1ENoUGy/y7VJ3xysnkfjRTBbwWJtav5E/H9D2RINndgq4kDL/hhALv 55se3ANcAGVsCgZQ9dRPLHIXIKVU0BTrow9bzB9mGyzjcf6aGdc/gcCHHI6EOFj9pMop gG6Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=dM6mSoOO; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-119397-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-119397-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. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id i9-20020a508709000000b0056715a786ffsi3807386edb.544.2024.03.26.12.02.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Mar 2024 12:02:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-119397-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=dM6mSoOO; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-119397-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-119397-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 926CC1F8003A for ; Tue, 26 Mar 2024 15:56:52 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 609CB13C8F9; Tue, 26 Mar 2024 15:56:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="dM6mSoOO" 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 ABC586AF85; Tue, 26 Mar 2024 15:56:40 +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=1711468602; cv=none; b=Yj7k+fcaQL5xAxWNokjAtwHMJTNDJ2kNOK2MgQfbrodyCjKZ22Lim9zn2qTNBF9nsvWDUswtEX7RFh8SDiumXpn5llKCzpQ1eTsAvn8HrlH5jaFS2MMG5RsGfwqSxwGOpP5GNZJS6CWmwbnL77Slk2LPEXDta2JIMVDtbICu16E= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711468602; c=relaxed/simple; bh=7zSnmZvqIpBKuNdtr4g7033y1zN+MsTfLVhiT3kPAG0=; h=Message-ID:Date:MIME-Version:Subject:From:To:Cc:References: In-Reply-To:Content-Type; b=nfEZ9cBdG6vdAdFh5gVBw5n6wcU4hhPLRaJy0FDLHvlfygCedj5N4H/2kMgeb4O2E/C6xoQwRsziuiOcOP12VU1o7c9wCzYKIf3OjKXILcnm9AqY3Giff2fuOT+utHQe1WOfvOtcEK+wi0ziIKq5Qc71p2VZ7XU6D22XnCxHRg0= 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=dM6mSoOO; 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=1711468601; x=1743004601; h=message-id:date:mime-version:subject:from:to:cc: references:in-reply-to:content-transfer-encoding; bh=7zSnmZvqIpBKuNdtr4g7033y1zN+MsTfLVhiT3kPAG0=; b=dM6mSoOOjGlWaHtC/TpoNVO2zrut/HYR9uc/b65fRfFxPiBR51cNYh4w xT8mSTmkT6Fe7d9hoh2IV9nte3e3t1W02JypNUMfvyPPOoxa1ug/xb5qV WfNRoChWBbtVMFp7Tx5led/fh77fiQkPBDqBjhGDo3XujiF3xQtn4rSRk 6RppdIlHXoJ/M9VSJOJF9yWavxuztjiAeV8JUiqsEPEH8z4W0cz9Szr61 X2+F3EJriQwIZtWfj0huXZInV+zcGKxYhg4JmrF2mW4wWrtQBfH9fuAOj 71jW80ecph+tQ2DNQD2g0m7/BpJLhx96vWqzErCSjzDH+zZ+6cFq320NA g==; X-CSE-ConnectionGUID: rphYpOdLSu223Zei2Py9Zg== X-CSE-MsgGUID: yAIhvQGCRmmqFCtRnk3jrw== X-IronPort-AV: E=McAfee;i="6600,9927,11025"; a="6634265" X-IronPort-AV: E=Sophos;i="6.07,156,1708416000"; d="scan'208";a="6634265" Received: from fmviesa006.fm.intel.com ([10.60.135.146]) by orvoesa109.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Mar 2024 08:56:40 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,156,1708416000"; d="scan'208";a="16039150" Received: from binbinwu-mobl.ccr.corp.intel.com (HELO [10.124.242.47]) ([10.124.242.47]) by fmviesa006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Mar 2024 08:56:38 -0700 Message-ID: <4d0d9f64-4cc4-4c1e-ba27-ff70c9827570@linux.intel.com> Date: Tue, 26 Mar 2024 23:56:35 +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 From: Binbin Wu 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> <6bd61607-9491-4517-8fc8-8d61d9416cab@linux.intel.com> In-Reply-To: <6bd61607-9491-4517-8fc8-8d61d9416cab@linux.intel.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 3/5/2024 2:55 PM, Binbin Wu wrote: > > > 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)); Do we need a static_assert() to make sure mc->init_value is 64bit? >> +    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; > >