Received: by 2002:a89:48b:0:b0:1f5:f2ab:c469 with SMTP id a11csp741090lqd; Wed, 24 Apr 2024 16:00:05 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCX9Shw8QX/6f9NgNLpOYcn8nk6tQXgRKpvtLTWqlzn6gXtbqL3Ii06aeXoQcJPMUnif1tyKFpVXmr27XjNGixJ6ljWg2hlWSSFfQONweg== X-Google-Smtp-Source: AGHT+IFpEmAVgEqrTlH5ekTHhpj1UNpT3Rxv6fp8Nv6Pjtm6DOrxPCO2iMbfRYHzL2N7iBM/E6hl X-Received: by 2002:a9d:744e:0:b0:6ea:1d8e:19fc with SMTP id p14-20020a9d744e000000b006ea1d8e19fcmr4453538otk.34.1713999604995; Wed, 24 Apr 2024 16:00:04 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713999604; cv=pass; d=google.com; s=arc-20160816; b=NaYkrG115zAgyuQIng9yEGwd77dPuyYP0H7OgbHqqSlbupAUODXhXrGIS1avsw1NCV 8Jw+ClWf8m5XlBPna0FHzC9aCd0tCUnhm1MLtIInvc0AmiHuccxvTSlhuISUkMokMiv6 ba7Rhgp5zb/Ks5V1wQBg8JgQy8P9Au6deeeAdHU9PEfxDBCoW5L9TH1kTI7S8XXxL8LQ 2zMr2WdYuaqhqGPFNB9LFc27RP05xMQqlcQ6YgwyTNL2HD6z7Hk/rNGTiFobj0SrrnOZ jBUiQXao05nG6NdE8xTms8M5X/PHaAuG6JdZCdRZJGKQ9gUre84qZCh0ybMYzoGyQ+u+ /F+Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:references:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:in-reply-to:date :dkim-signature; bh=CPQuZuOq+EB+82vseydeL3MmBIwkyv7t/AeyvUHFOt0=; fh=uTe4RNUovI16CcTR5RyOf5Ezo4ahT1OCtLTXVwuIdrc=; b=POCPZFwIoswx2Wb5fyIv4G9DULTyCMj2LioOGzw/VecBakfs4INMkbRrDCfLKOmwuR +5LQyO+AEOYjV2TsLhzwfR6nbvt3QR444bFtYlhFl0QtIPvydMKcdDLqNlVGcuB6BOKR QWg0iqXFR8i+YztWlsEtUKGjlzmoBD7uuXwLJ+EkYjol1b4Vp/wp1RNdZbS9MXl5ucPc RFd8Cg0Z9IlaDwFjGRa6AONU5bxiY3Y94zF9JTJ2rHWseGnmROaWIpIwh/lOI3oXGYbE ZiTDTJIIw6ERY3ByNN3MuSuh1F75SR3LMRwcdzDkMbiA2onnZFfqk68ndX4zaKn/DF/9 F6ZA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=308TfEim; arc=pass (i=1 spf=pass spfdomain=flex--seanjc.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-157818-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-157818-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id k8-20020a634b48000000b005f42e08ab46si11888438pgl.456.2024.04.24.16.00.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Apr 2024 16:00:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-157818-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=@google.com header.s=20230601 header.b=308TfEim; arc=pass (i=1 spf=pass spfdomain=flex--seanjc.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-157818-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-157818-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 94522287FAE for ; Wed, 24 Apr 2024 23:00:04 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4843C157465; Wed, 24 Apr 2024 23:00:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="308TfEim" Received: from mail-pg1-f202.google.com (mail-pg1-f202.google.com [209.85.215.202]) (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 25DD116EBE9 for ; Wed, 24 Apr 2024 22:59:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713999601; cv=none; b=GneY02RgAuo1kIvvBUmbw1m91ijgfyq+1WibON+JkhCHm5T463oAJETkeFvbAY0um4dVvat3C34rmm8jfdaTqEqwcwchrd9SLUau4kRzkiv/9RaouscOu1/cHdgm1gg4b+lREWSql24brbW3aDYhCi0tDvwjZlBZykT2AQ/JW/c= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713999601; c=relaxed/simple; bh=DqAQEHGDx6EY1b993wyDcxpyd3anFLT4vTfzBQtDgJo=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=BcmCphKd/Cc4ocEPTisVzJFbazy+i1QjxMixWepP7zQhKaeh/13cHZhs/sWn8Ak1Pb428hiMxHNTgukufxYGwiOJ4TicYNPhyQCNseaj6PW4PzYhp8GniK62EMh1cKL1nIAPZC0Krwy92sMSE4q91EXXZlA4flePzzHcf+QaC1A= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=308TfEim; arc=none smtp.client-ip=209.85.215.202 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=flex--seanjc.bounces.google.com Received: by mail-pg1-f202.google.com with SMTP id 41be03b00d2f7-5f80a77b95cso400593a12.0 for ; Wed, 24 Apr 2024 15:59:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1713999599; x=1714604399; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=CPQuZuOq+EB+82vseydeL3MmBIwkyv7t/AeyvUHFOt0=; b=308TfEimuLnkpfRVOrYv07ACb1i4MW0YkblfTFvKsAJku8M9LW1prn2LG1ErqAORDm jJf6OPI6to43ypEM1jHqaFvzxXvzfpLFiwV6LKeHpmmWITo287h2/dRr7j18XuLRmsjx xOtI8BOS+KSXnViqeg2NI0W6dB5chgwVVOWwLh6+MPPBJh7n8fm9ZArELImF17WUTpvv JuLM9USYfZ6GSsMCEMd1TG1g7YQSCLaQPF0ffEN0vPlRJXsuN1jSPcqPDmP772Qrty75 p7nlJZnwT1QewAYyNbGCvCoWzUAVrG60uAknMS3phnMEtn2LAvzjFATtF7c1XdQL7Pv7 BTFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713999599; x=1714604399; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=CPQuZuOq+EB+82vseydeL3MmBIwkyv7t/AeyvUHFOt0=; b=LU0cw4zx79CORgki0dxqwJbDdqK4nDylq1dh59EBgy8dfzk5xwZCD+oKCEjzcL4r0j 5/0R6nTlPsnV9yWI8xQHL3vrPOc6bKcMpIDkr2ZRByn0ZzebvjE6dzF8+YnDUn6bxQPc dwPJIHoNmqgufSeIMP8bLmwPV5SMlkvksPWA7ci1aWzhcB28UHHyBsf1lK2adkO9XGC1 HKxDtQZYf+Bd6x1SaZmFMcCzOCIw2ZZI/Umj++AMmdum31RKXIJ2zvOBdxwc0aeIa3un YvwuFIorMMUyR9qyZVezWMsX3NsoEdfwE98iFASG9SfnSyTDSuI/g8P9mZi/ss6zbE75 yVPQ== X-Gm-Message-State: AOJu0Yx6DhhKSMuxg/5HLIa2F+ZMWjHg0s8+Mp8fRfvAU+Vbnj1LZnIg Yiz6kVsMqMWRa6ES0cIF2dn14t6DQB3FgpSCFhycRWLxdOal9uE90oczBIAZgWf+mrGCb/Ogllp I0Q== X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a63:4c13:0:b0:5f7:d61e:50e5 with SMTP id z19-20020a634c13000000b005f7d61e50e5mr46918pga.6.1713999599325; Wed, 24 Apr 2024 15:59:59 -0700 (PDT) Date: Wed, 24 Apr 2024 15:59:57 -0700 In-Reply-To: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240404185034.3184582-1-pbonzini@redhat.com> <20240404185034.3184582-8-pbonzini@redhat.com> Message-ID: Subject: Re: [PATCH 07/11] KVM: guest_memfd: extract __kvm_gmem_get_pfn() From: Sean Christopherson To: Paolo Bonzini Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, michael.roth@amd.com, isaku.yamahata@intel.com Content-Type: text/plain; charset="us-ascii" On Wed, Apr 24, 2024, Sean Christopherson wrote: > On Thu, Apr 04, 2024, Paolo Bonzini wrote: > > In preparation for adding a function that walks a set of pages > > provided by userspace and populates them in a guest_memfd, > > add a version of kvm_gmem_get_pfn() that has a "bool prepare" > > argument and passes it down to kvm_gmem_get_folio(). > > > > Populating guest memory has to call repeatedly __kvm_gmem_get_pfn() > > on the same file, so make the new function take struct file*. > > > > Signed-off-by: Paolo Bonzini > > --- > > virt/kvm/guest_memfd.c | 38 +++++++++++++++++++++++--------------- > > 1 file changed, 23 insertions(+), 15 deletions(-) > > > > diff --git a/virt/kvm/guest_memfd.c b/virt/kvm/guest_memfd.c > > index 486748e65f36..a537a7e63ab5 100644 > > --- a/virt/kvm/guest_memfd.c > > +++ b/virt/kvm/guest_memfd.c > > @@ -540,33 +540,29 @@ void kvm_gmem_unbind(struct kvm_memory_slot *slot) > > fput(file); > > } > > > > -int kvm_gmem_get_pfn(struct kvm *kvm, struct kvm_memory_slot *slot, > > - gfn_t gfn, kvm_pfn_t *pfn, int *max_order) > > +static int __kvm_gmem_get_pfn(struct file *file, struct kvm_memory_slot *slot, > > + gfn_t gfn, kvm_pfn_t *pfn, int *max_order, bool prepare) > > I genuinely don't know what it means to "prepare" a guest_memfd. I see it becomes > > if (!prepare) > fgp_flags |= FGP_CREAT_ONLY; > > but I find the name "prepare" to be extremely unhelpful. Ah, I'm blind. Maybe "do_prepare", or "do_arch_prepare"? To make it clear that it's a command, not a description of the operation (which is how I first read it). And I feel like overloading it to also mean FGP_CREAT_ONLY when _not_ preparing the memory is odd. if (prepare) { int r = kvm_gmem_prepare_folio(inode, index, folio); if (r < 0) { folio_unlock(folio); folio_put(folio); return ERR_PTR(r); } } Instead of "prepare" as a command, would it make sense to describe the "populating" case? Because I think it's more intuitive that populating _needs_ to operate on new, unprepared data.