Received: by 2002:ab2:3319:0:b0:1ef:7a0f:c32d with SMTP id i25csp250962lqc; Thu, 7 Mar 2024 16:57:20 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUjZ4x8SbuUIHPz2p7QgybwpKpCWoAgaXFzuBzl28iLGcAkfoAebqgV6t4qtWdF67XwjauhA3eHwxfWFsckuOc/o5/tF3YOUFih18g0+g== X-Google-Smtp-Source: AGHT+IHG7MUEjL70mwgv0ZQ4/Fox2ydCX3sfQOVpDRZzEdh3nRkG8388+dPevKc9SHCbDmQpzrU5 X-Received: by 2002:a2e:9ccb:0:b0:2d3:f9ec:6df3 with SMTP id g11-20020a2e9ccb000000b002d3f9ec6df3mr2156741ljj.44.1709859440215; Thu, 07 Mar 2024 16:57:20 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709859440; cv=pass; d=google.com; s=arc-20160816; b=d4iYfaSdKu3iZjprkrny0rWMC7HPl2fS7tpdgBKSTyn/hqisNDj/RDfxccI1BGvdw/ WIkcTrGcNn+BmR1hMNLYJXT9w2IleeM37L/QcVzWNS36DjU+z1B2wnBQKXoQQOgsbls9 C/AFa+T703oNxlmaS5GM9kbFxxsZZDj7PJzrJ9NvSJP4BeJfaGVFkYeKvdzIGvRzUDFE ej99vZ7Q8okCY/W5bPW7aaU0P4Vyhy+azTX5V7zzRWFc4WFI2vwk0/wBt+gO1lvdaEiA k67zbWHjxOwSUPTYTX/jqQp21uAc2E3G+o8nzpvNlg+VRDcx4gifndKwymIAxfPmuReP k7Dg== 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=8Qnw8MPyfIgI73N12VWT1J4+tWNjVVYbLsggYSkFPpk=; fh=JalFkZFdU1FXhwya2e1p/07WOyIUqVQuwzaNOvW3u2Q=; b=uIyrVpNfN677v6bytPGh015ejujYGTCjfmNQllscsIHpr/zKsf3G/csmmjKDa0ds2A EbDVKqdNEfXduOhCUIjOCTlpB5HeaNQxdl/IlFPDPvNgp6uoQ/DfxZfUS7DjGtgZyW/z OfZJL/lwvNxQdsHh8kuNUzfm6mh0ksb/A4zDBcGgSzeIbN23an1lLUlInfAo4g+7ElUD yS/G5AetKiQuetU4ossIO3gfEFv+uClo15QIKykK/aaKxPqGqIUwZu3W0sMWtAUR6xBm 7KwsYoMGITwQ5V3gPKUrcK5Eam/4wGXZ/Um2T1r4ByH/jWO+2BEynx7H/yf7np8zkvDS AtkA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=eHeD94aq; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-96400-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-96400-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id i19-20020a508713000000b005664aed2ecbsi7357679edb.172.2024.03.07.16.57.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Mar 2024 16:57:20 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-96400-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=@google.com header.s=20230601 header.b=eHeD94aq; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-96400-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-96400-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.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 E9FBE1F221E8 for ; Fri, 8 Mar 2024 00:57:19 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A4A762261B; Fri, 8 Mar 2024 00:56:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="eHeD94aq" Received: from mail-pg1-f170.google.com (mail-pg1-f170.google.com [209.85.215.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7361D219F6 for ; Fri, 8 Mar 2024 00:56:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.170 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709859417; cv=none; b=GRoRmcVgRiOzHF0/Jv5sKwShWLhQi1fowUy2bqHza6Baf9XwIQIF8Aahx1wdbSLoN/7dhrM2qfEd9MyTzE2EMhQ0Ei5MWp+FlI1vW5CoWaGMu56/fbQdJV94iv/Fm3BQJA/5Jht+AGWoMS05EFpuhnrvRxjZ87j7Xk8eJPI0MCw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709859417; c=relaxed/simple; bh=X73gZ6oo5HIXF3CAaAbkTGjsN3KT8Yzd6Bfe5mNNhhk=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=KM6/cNLG++nVgdbLNOxabeLZR79LYvVusfkmFa+fVZEqu//T10liOOC3yfcQNK00EYhtxQIrasheXHfBV0TyNvRJtEc3iSKjgPUBiowV25eOUx6FDp9EXogWLBbmJz5ivvPvm35FsjI+3Uv1rU6+9ggLIQ2cy4lJ7NiCqPQ+qsM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=eHeD94aq; arc=none smtp.client-ip=209.85.215.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Received: by mail-pg1-f170.google.com with SMTP id 41be03b00d2f7-5d8b887bb0cso1240766a12.2 for ; Thu, 07 Mar 2024 16:56:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1709859416; x=1710464216; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=8Qnw8MPyfIgI73N12VWT1J4+tWNjVVYbLsggYSkFPpk=; b=eHeD94aqNe6vUeiHH1b3yYIRlqdMKi+5TSF+WSXfJYSZF4yCtEthZ4Wih4130Bb7tU e6ocq4OxmAlPoZDvhh7kRIJHThzvTnalZ04urF7Rs5rQrjanEnI/9NwtDiLpyMSKJlIX hSKt8Bin86K0l1LdtAyhmyeDxZfA2H/DYNLUtUnaArDBJGII2hoOnFkNVIGI0WGXXlzr rxW6mPUYtArWn5zVi4G6to4T/JisKJ/0lgxjTtVJxqHWG+DTk01Mulms9ZAyGdkvll/D 4bP5PI7L5t0Hnz0WlSfb57XCh30QlqHZmaoz6bgWVDyuAqFKZMD98dCSh8FVUkjqRBzd p4TQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709859416; x=1710464216; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=8Qnw8MPyfIgI73N12VWT1J4+tWNjVVYbLsggYSkFPpk=; b=OyqeXQ5ARx+KZReOwFtX2EZQ5eY1a70IH67l/8lmni+SGesQYkE6QIR48P65DtWZQc ErE+cpuLsD1WzSeeYSijkto3xVuxt34J4qK6gLJ5ej0H6IETniGU8apiwEiqyDlQovQH CX5bIAghjJ1HR2ztgDog9Yvr64w/fIPS/EgX7+WeoPpjcxQj+kDutURrWmqqoqH9fHPb Hx7yPgVun0J166Fql4RFsGIvUtIASrLLUTjCKTIpB+rAssqrSOLBnfaasfnWTsq2s3jd adwJ172gcODvQVaDFRwrGvi1a/tjFszkSwicW8A0PvRougmDAQ/kcbyI5G61gRJaOg0r IGxA== X-Forwarded-Encrypted: i=1; AJvYcCXZjX6p1irpkZ8lI5qNV5Y4dM5xl2+m/qvFaPgBylGVUiOgpyZ1/bPFmiFhtA8y5uiSQJZzP8T8HYfQvcyNoMgsci69Ji5wH9Jwwz57 X-Gm-Message-State: AOJu0YzZ4FEqP7X3WIWE9Qeu5M7ShtLmnjuTCKibaUIzcFzN+zPg7JVe e9rQAsGUgA0XSC+HcjJTYVMizRoby72TxABlTMVCZD+8ajGJ9L7arForWDniow== X-Received: by 2002:a05:6a20:6a06:b0:1a1:7529:1942 with SMTP id p6-20020a056a206a0600b001a175291942mr4080776pzk.24.1709859415535; Thu, 07 Mar 2024 16:56:55 -0800 (PST) Received: from google.com (61.139.125.34.bc.googleusercontent.com. [34.125.139.61]) by smtp.gmail.com with ESMTPSA id p28-20020aa79e9c000000b006e65d676d3dsm1816625pfq.18.2024.03.07.16.56.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Mar 2024 16:56:54 -0800 (PST) Date: Thu, 7 Mar 2024 16:56:51 -0800 From: David Matlack To: "Huang, Kai" Cc: Isaku Yamahata , "kvm@vger.kernel.org" , "Yamahata, Isaku" , "federico.parola@polito.it" , "pbonzini@redhat.com" , "linux-kernel@vger.kernel.org" , "isaku.yamahata@gmail.com" , "michael.roth@amd.com" , "seanjc@google.com" Subject: Re: [RFC PATCH 1/8] KVM: Document KVM_MAP_MEMORY ioctl Message-ID: References: <9f8d8e3b707de3cd879e992a30d646475c608678.camel@intel.com> <20240307203340.GI368614@ls.amr.corp.intel.com> <35141245-ce1a-4315-8597-3df4f66168f8@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=us-ascii Content-Disposition: inline In-Reply-To: <35141245-ce1a-4315-8597-3df4f66168f8@intel.com> On 2024-03-08 01:20 PM, Huang, Kai wrote: > > > > +: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. > > Sorry I don't quite follow. What's wrong if KVM just append the #PF USER > error bit before it calls into the fault handler? > > My question is, since this is ABI, you have to tell how userspace is > supposed to use this. Maybe I am missing something, but I don't see how > USER should be used here. If we restrict this API to the TDP MMU then KVM_MEMORY_MAPPING_FLAG_USER is meaningless, PFERR_USER_MASK is only relevant for shadow paging. KVM_MEMORY_MAPPING_FLAG_WRITE seems useful to allow memslots to be populated with writes (which avoids just faulting in the zero-page for anon or tmpfs backed memslots), while also allowing populating read-only memslots. I don't really see a use-case for KVM_MEMORY_MAPPING_FLAG_EXEC.