Received: by 2002:ab2:3319:0:b0:1ef:7a0f:c32d with SMTP id i25csp145544lqc; Thu, 7 Mar 2024 12:54:13 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWRxk6M5kDetVMPUPZIjci4oZbfGCzsJrqm8nJfEjBmvSbcIF7NAyucfZISE/+yJ8FqzlMLdKqYKkiPS/Z8j3xP6CWE1fLJoqBbg5UUiw== X-Google-Smtp-Source: AGHT+IH7lRIhDKa+ROP/7gZkxZYMs6uDzDypsSCU+/oIgf4PgwOeiePyIHjtL/TJbzcXArqqRYZE X-Received: by 2002:a05:6a20:1611:b0:1a1:490f:25af with SMTP id l17-20020a056a20161100b001a1490f25afmr8926511pzj.3.1709844853643; Thu, 07 Mar 2024 12:54:13 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709844853; cv=pass; d=google.com; s=arc-20160816; b=DQNHc3oLOy5e/up84v39FGItE836xtClwdfd1hlHVaS+Rz2h1up0JcFHHpjgKXXF3f 3dCbjgo7ND35bfNXg9CAkuQkzx1aqBfHQZjKnfQDW5sh8Kdh8Lby6r6YzmuCQJLFMkLc h9AHH/deQMuz1Sj1jNV4Mr0rlSWqCuZZKdp4bYIi2HsY3lXUtzHwmUIXyASjYeqpYF1m c/o6i8+ZmhxQWzm01x6xKnVl33SDdMNVkE7zrZQtY8cTJJCdGq6UhqV7joA5vFRDmNLs G5m0Za5vFUExBjCVbVtrC97P82KxpvxEJMnS4MUbCK/h9+eEqKiwHP6fvfNOwEFJPy+h zSAA== 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=tdfnvqHHAFCN5LZamptxp6ThwmNQiOcE5AoATftj/Fk=; fh=e8sl/TXpGsOWeP8txUfVz2K3a85kgvL4G/xXkOVpQ9o=; b=HNYIkFczGVC1UpGBw6+fOlex5w18Vvyawh9qJFH2sjucEUfvZrYGPN4fUmy5RbS9RR GLUg+0eSPkAbUIojG0F6/JAiVSJQizcSZcQ5Cl5A7kkv5KyuTYVc8IMB88PaOgXwaP95 5yIdFZbl+buLMVrsekxAqUw2muSh/aAp3uPIdXSQZEaDKUEOyal5sx7xq0SRJ1jhUaDj DZc6lYGaszcZbceTd7jkBCml+E6IIWsJkXM7G+LlZiGEiHsfW6L6b71sw3j4aJI4eR3W bCbNCfv7s94hFWeoCqo/8zsN+ugVEpxe/n8HjZ9SjVbWeZbIvZyl3A75dw6at5/evvOz df4g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=dp7wx2PO; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-96201-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-96201-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id q4-20020a056a00084400b006e5a09708fbsi14168508pfk.386.2024.03.07.12.54.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Mar 2024 12:54:13 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-96201-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=dp7wx2PO; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-96201-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-96201-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 986BDB242F7 for ; Thu, 7 Mar 2024 20:33:52 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E50DD64CC6; Thu, 7 Mar 2024 20:33:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="dp7wx2PO" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.11]) (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 62DF5139571; Thu, 7 Mar 2024 20:33:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.11 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709843624; cv=none; b=YTmFq9DnCwEjAa33FKSTpp+Es/bVONBR9uOTUMzuhj2qVXtz21saP6YfDsc02vDpC6a9h5s1ck9KIqZzeSYxlBLY0cj5suhhVHg2bZfGlewzLSd6grZfdlOC2Oj6NTdAIaEF3+Xpc488IkTw7Q+aYmuP0rQLMmgN/acCNo6/jAA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709843624; c=relaxed/simple; bh=pYm922DxqcT6fMWqbP4U26AYgN9ggB1aB8F8XfUPFDY=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=jxpqlsPUJ9wkceLmJmFkPWAl3sTDrK6hUfIFygIZz668vGwohG7FgootaFGfx4qmjl73o/OzT7D24r0nypCaOXBnsveNzVbsCVMjjSGAxZtgcXup7z/OitRJIONHloD5lplcZpO2Dzf8hjzer0IVIwENf9yma5wD7jNrsYcx/CE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=dp7wx2PO; arc=none smtp.client-ip=198.175.65.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.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=1709843622; x=1741379622; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=pYm922DxqcT6fMWqbP4U26AYgN9ggB1aB8F8XfUPFDY=; b=dp7wx2POs3xpLzSCM+m21mhYB5gxMakh50CsTujO1zMNKRcBFGjlvwK0 MjAvSoT30HTdj/LrLBNH59xXS1XqRTrChtp6li/TzWO0xiRmypfru/Jh/ vw+PNrVkVnf5DCRmUdG9dMvIHnsXUm2UhuMFPBA5EnbZ57sjq49wKBLH0 v420U6JMlJM7J+QM20SHUbGOgEWjY1XrESNtgykdQE0SvsaLz6VFqvyjJ ESbwCm/QAmXlbhFfTnDis61nqqoESUKjcJ62jR6p+E7pF33bet3wiTcJB ZqU0HJCDcRAVxz+1EH9pSEbTZ2n0UyNBd8Y+QQHyrcDkiUlDnXCzrf9dC Q==; X-IronPort-AV: E=McAfee;i="6600,9927,11006"; a="15109178" X-IronPort-AV: E=Sophos;i="6.07,107,1708416000"; d="scan'208";a="15109178" Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by orvoesa103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Mar 2024 12:33:41 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,107,1708416000"; d="scan'208";a="41212476" Received: from ls.sc.intel.com (HELO localhost) ([172.25.112.31]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Mar 2024 12:33:41 -0800 Date: Thu, 7 Mar 2024 12:33:40 -0800 From: Isaku Yamahata To: "Huang, Kai" Cc: "kvm@vger.kernel.org" , "Yamahata, Isaku" , "federico.parola@polito.it" , "pbonzini@redhat.com" , "dmatlack@google.com" , "linux-kernel@vger.kernel.org" , "isaku.yamahata@gmail.com" , "michael.roth@amd.com" , "seanjc@google.com" , isaku.yamahata@linux.intel.com Subject: Re: [RFC PATCH 1/8] KVM: Document KVM_MAP_MEMORY ioctl Message-ID: <20240307203340.GI368614@ls.amr.corp.intel.com> References: <9f8d8e3b707de3cd879e992a30d646475c608678.camel@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: <9f8d8e3b707de3cd879e992a30d646475c608678.camel@intel.com> On Thu, Mar 07, 2024 at 12:30:04PM +0000, "Huang, Kai" wrote: > On Fri, 2024-03-01 at 09:28 -0800, isaku.yamahata@intel.com wrote: > > From: Isaku Yamahata > > > > Adds documentation of KVM_MAP_MEMORY ioctl. > > > > It pre-populates guest memory. And potentially do initialized memory > > contents with encryption and measurement depending on underlying > > technology. > > > > Suggested-by: Sean Christopherson > > Signed-off-by: Isaku Yamahata > > --- > > Documentation/virt/kvm/api.rst | 36 ++++++++++++++++++++++++++++++++++ > > 1 file changed, 36 insertions(+) > > > > diff --git a/Documentation/virt/kvm/api.rst b/Documentation/virt/kvm/api.rst > > index 0b5a33ee71ee..33d2b63f7dbf 100644 > > --- a/Documentation/virt/kvm/api.rst > > +++ b/Documentation/virt/kvm/api.rst > > @@ -6352,6 +6352,42 @@ a single guest_memfd file, but the bound ranges must not overlap). > > > > See KVM_SET_USER_MEMORY_REGION2 for additional details. > > > > +4.143 KVM_MAP_MEMORY > > +------------------------ > > + > > +:Capability: KVM_CAP_MAP_MEMORY > > +:Architectures: none > > +:Type: vcpu ioctl > > I think "vcpu ioctl" means theoretically it can be called on multiple vcpus. > > What happens in that case? Each vcpu can handle the ioctl simaltaneously. If we assume tdp_mmu, each vcpu calls the kvm fault handler simultaneously with read spinlock. If gfn ranges overlap, vcpu will get 0 (success) or EAGAIN. > > +:Parameters: struct kvm_memory_mapping(in/out) > > +:Returns: 0 on success, <0 on error > > + > > +KVM_MAP_MEMORY populates guest memory without running vcpu. > > + > > +:: > > + > > + struct kvm_memory_mapping { > > + __u64 base_gfn; > > + __u64 nr_pages; > > + __u64 flags; > > + __u64 source; > > + }; > > + > > + /* For kvm_memory_mapping:: flags */ > > + #define KVM_MEMORY_MAPPING_FLAG_WRITE _BITULL(0) > > + #define KVM_MEMORY_MAPPING_FLAG_EXEC _BITULL(1) > > + #define KVM_MEMORY_MAPPING_FLAG_USER _BITULL(2) > > I am not sure what's the good of having "FLAG_USER"? > > This ioctl is called from userspace, thus I think we can just treat this always > as user-fault? The point is how to emulate kvm page fault as if vcpu caused the kvm page fault. Not we call the ioctl as user context. -- Isaku Yamahata