Received: by 2002:ab2:6203:0:b0:1f5:f2ab:c469 with SMTP id o3csp2447766lqt; Mon, 22 Apr 2024 10:55:51 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXOwc/sFUXwl5U+2QFcd2i+O13LdM/y1lHjOKQqoLyxmLKTAC/S6kmrFDEl0pmM0O5ctEsP/H3Tsa8LJihREvJ2bdRLsGLRCHD76xPpnQ== X-Google-Smtp-Source: AGHT+IFnoRaN1FMk6VR4fVgcvPpQEZLTAoY/HoE7Vyqpek6HikTJmF7SydEk4e/pkCvSg2lWVMNb X-Received: by 2002:a05:6512:3b82:b0:519:2d60:d71b with SMTP id g2-20020a0565123b8200b005192d60d71bmr9836403lfv.22.1713808551734; Mon, 22 Apr 2024 10:55:51 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713808551; cv=pass; d=google.com; s=arc-20160816; b=TsPEhU+Mi9e379EGPlNijfsum546RpIvqkxsZg10dhEgP6xOrdvRSa0Gsw5OthwEtu o5fQptlE+RtCYSAwdqSV1V3CPiV39S2ADooOfYStjfbf6nUTjTdrDRNGDTfNXV9u/Hqm T5mhZcOJdU4XjCj3EZQJo/DDIS7rxSfLNxqAWV8CovN4RBoNfSu72JegHW7DLWO9CoYW rCU/ucnx+H8rgHccgVQa8q2dePfXdzOwidlxe/Q/M8O6F21YRl1wYVle1F1v1AwB7aHf 9w3z/sQ5gXJF+yE8vPM4HUFBejYbbM8hjqQfT5fdw7Iti/insous6eJfIuM0z0B2Xcmx FMJQ== 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=qdlDqYoxvhGVVVFtcRjAJKufPegaUkp/gTwuWotRLWY=; fh=rNw/TV07zUvZIgJ5Uf5Jix7YwtViiSdM8tLS90sD/iw=; b=gbU1bFf5/aDl3OriYgyVQMNnrfbscnAzX45nbzVDv01XMTrGLUt893BU7cns8uxMuy H3cBxBnWNFIBPTvip3EiQ2FGiIR9jgkFBIgGlXFmSpTHEikrjMquK6qW+YyqQuyvpcY0 UoxjBxyr2EPbA3UrOB7x/EK2IMGz1BkL0P3M4GxDRx4ciJJWR7VmP6Q3rUh7tfzCqedq e597VrzvYo3PohRXMPVu4bQ/BDR7pDMtiilbnJ3FLk9Ss5MhUAxB+j6yEAYCzTD+WmZA Ulb13XjYdLgvlAGZh0M+Q9EM+9S7M8xyGqpF0uI+fpvxTBf8igHMwBpg6QE8AmLAE/aL AVjw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=fsBSt78+; 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-153809-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-153809-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 le13-20020a170906ae0d00b00a5190b11420si5752198ejb.250.2024.04.22.10.55.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Apr 2024 10:55:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-153809-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=fsBSt78+; 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-153809-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-153809-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 71DC11F21BCA for ; Mon, 22 Apr 2024 17:55:51 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 54A7D154427; Mon, 22 Apr 2024 17:55:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="fsBSt78+" Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.7]) (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 8D8EC152197; Mon, 22 Apr 2024 17:55:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.7 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713808541; cv=none; b=jRXdkFRRyxOaxX61+waQEvO47IX/vwclvDw0OcqnLAhL0cAVMfbdJBleVg+sP/LklN0WHvwecoBvHdiWrwq5EYAG7WRh42hQcYJyg/9oyNA6h7FQ5AEm2IOBhBO5PKNSTgdDVyiAb2SMtgGQIKdgMNr46OwUIG1YI4SRy8CrB6Q= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713808541; c=relaxed/simple; bh=6Qrukdm+oftDRYXT1lb8r+vqv5iPHwTKX+hyL1P5koo=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=vGsYQA887gn+N7/nMOistiEAxXIWekfwS/XfVOUEI/nouyMGqig/YhuC8q2qxHNnbkWPkT8+AQBQm2QWEvZOCMYrpI0FyiM2ETHuE5Gnvd0tURhu9uuZ6Gu50Tdmvq2TSCC0v7FFTDE5oEWGOezfpA3M3hBd19LRWJ+1/LeYRmo= 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=fsBSt78+; arc=none smtp.client-ip=192.198.163.7 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=1713808539; x=1745344539; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=6Qrukdm+oftDRYXT1lb8r+vqv5iPHwTKX+hyL1P5koo=; b=fsBSt78+TdFklZwTV6UA61j6qHKVQJZVD0XoGGq6yQ5xkLx1Tmy/rOGq eOEcWsbHDy3g/VH39/ouXuf3FonMUTr4MfFkffGwB0pK+d9mV0ZOY1gkt BbtAv48Z/xvGiewOSZ5qOcvmSbMs2T5jygWeX1W1Y63vROD/qPIXNr2nW mZ3VHkN53qNgSVLUOZO+2/hp/G8ISLSodSkvAtuPg7uV6umRdyFnCrdSr BbMtyGaSS2xwRHxr8j88LWgFInhouqt5mcOYHbqsEMAZAygFb///9Z3hB zZuXOr/RliGUPb/su2vff7WjcdpHnTXlAFy4c1fj4nlCn34d10EKjSSNb A==; X-CSE-ConnectionGUID: FFGgRTrAT7eGPD/Ls+6WKw== X-CSE-MsgGUID: uVjK1Pg4Rm2nbCgDNNeXbg== X-IronPort-AV: E=McAfee;i="6600,9927,11052"; a="34759292" X-IronPort-AV: E=Sophos;i="6.07,221,1708416000"; d="scan'208";a="34759292" Received: from fmviesa008.fm.intel.com ([10.60.135.148]) by fmvoesa101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Apr 2024 10:55:22 -0700 X-CSE-ConnectionGUID: 1haqLAR8T+W8zDo3immlDA== X-CSE-MsgGUID: jlma1gcbQV2IpAEITMkNiA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,221,1708416000"; d="scan'208";a="24165434" Received: from ls.sc.intel.com (HELO localhost) ([172.25.112.31]) by fmviesa008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Apr 2024 10:55:21 -0700 Date: Mon, 22 Apr 2024 10:55:21 -0700 From: Isaku Yamahata To: Paolo Bonzini Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, isaku.yamahata@intel.com, xiaoyao.li@intel.com, binbin.wu@linux.intel.com, seanjc@google.com, rick.p.edgecombe@intel.com, isaku.yamahata@linux.intel.com Subject: Re: [PATCH 1/6] KVM: Document KVM_PRE_FAULT_MEMORY ioctl Message-ID: <20240422175521.GM3596705@ls.amr.corp.intel.com> References: <20240419085927.3648704-1-pbonzini@redhat.com> <20240419085927.3648704-2-pbonzini@redhat.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: <20240419085927.3648704-2-pbonzini@redhat.com> On Fri, Apr 19, 2024 at 04:59:22AM -0400, Paolo Bonzini wrote: > From: Isaku Yamahata > > Adds documentation of KVM_PRE_FAULT_MEMORY ioctl. [1] > > It populates guest memory. It doesn't do extra operations on the > underlying technology-specific initialization [2]. For example, > CoCo-related operations won't be performed. Concretely for TDX, this API > won't invoke TDH.MEM.PAGE.ADD() or TDH.MR.EXTEND(). Vendor-specific APIs > are required for such operations. > > The key point is to adapt of vcpu ioctl instead of VM ioctl. First, > populating guest memory requires vcpu. If it is VM ioctl, we need to pick > one vcpu somehow. Secondly, vcpu ioctl allows each vcpu to invoke this > ioctl in parallel. It helps to scale regarding guest memory size, e.g., > hundreds of GB. > > [1] https://lore.kernel.org/kvm/Zbrj5WKVgMsUFDtb@google.com/ > [2] https://lore.kernel.org/kvm/Ze-TJh0BBOWm9spT@google.com/ > > Suggested-by: Sean Christopherson > Signed-off-by: Isaku Yamahata > Message-ID: <9a060293c9ad9a78f1d8994cfe1311e818e99257.1712785629.git.isaku.yamahata@intel.com> > Signed-off-by: Paolo Bonzini > --- > Documentation/virt/kvm/api.rst | 50 ++++++++++++++++++++++++++++++++++ > 1 file changed, 50 insertions(+) > > diff --git a/Documentation/virt/kvm/api.rst b/Documentation/virt/kvm/api.rst > index f0b76ff5030d..bbcaa5d2b54b 100644 > --- a/Documentation/virt/kvm/api.rst > +++ b/Documentation/virt/kvm/api.rst > @@ -6352,6 +6352,56 @@ a single guest_memfd file, but the bound ranges must not overlap). > > See KVM_SET_USER_MEMORY_REGION2 for additional details. > > +4.143 KVM_PRE_FAULT_MEMORY > +------------------------ > + > +:Capability: KVM_CAP_PRE_FAULT_MEMORY > +:Architectures: none > +:Type: vcpu ioctl > +:Parameters: struct kvm_pre_fault_memory (in/out) > +:Returns: 0 on success, < 0 on error > + > +Errors: > + > + ========== =============================================================== > + EINVAL The specified `gpa` and `size` were invalid (e.g. not > + page aligned). > + ENOENT The specified `gpa` is outside defined memslots. > + EINTR An unmasked signal is pending and no page was processed. > + EFAULT The parameter address was invalid. > + EOPNOTSUPP Mapping memory for a GPA is unsupported by the > + hypervisor, and/or for the current vCPU state/mode. EIO Unexpected error happened. > + ========== =============================================================== > + > +:: > + > + struct kvm_pre_fault_memory { > + /* in/out */ > + __u64 gpa; > + __u64 size; > + /* in */ > + __u64 flags; > + __u64 padding[5]; > + }; > + > +KVM_PRE_FAULT_MEMORY populates KVM's stage-2 page tables used to map memory > +for the current vCPU state. KVM maps memory as if the vCPU generated a > +stage-2 read page fault, e.g. faults in memory as needed, but doesn't break > +CoW. However, KVM does not mark any newly created stage-2 PTE as Accessed. > + > +In some cases, multiple vCPUs might share the page tables. In this > +case, the ioctl can be called in parallel. > + > +Shadow page tables cannot support this ioctl because they > +are indexed by virtual address or nested guest physical address. > +Calling this ioctl when the guest is using shadow page tables (for > +example because it is running a nested guest with nested page tables) > +will fail with `EOPNOTSUPP` even if `KVM_CHECK_EXTENSION` reports > +the capability to be present. > + > +`flags` must currently be zero. `flags` and `padding` > + > + > 5. The kvm_run structure > ======================== > > -- > 2.43.0 > > > -- Isaku Yamahata