Received: by 2002:ab2:3141:0:b0:1ed:23cc:44d1 with SMTP id i1csp1651790lqg; Sun, 3 Mar 2024 22:07:02 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXVv0ON3EWus1LY2MqtgJolR+/0KrNazxj0CkHWaOKUnTyyD4Z02oTUWQNNKNaGgsU/xNz2bilK83nGtSxv3ERmEB3WZ00RBcJ5sqCycg== X-Google-Smtp-Source: AGHT+IGy1WMaN9X5c2EJx5mqNhmNDKmbk1BK/Rfj5Xntk2jJlKhOYrrALhMAD0JedkF1vqh8E2ia X-Received: by 2002:a17:90a:77ca:b0:29a:f199:1647 with SMTP id e10-20020a17090a77ca00b0029af1991647mr11291067pjs.1.1709532421838; Sun, 03 Mar 2024 22:07:01 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709532421; cv=pass; d=google.com; s=arc-20160816; b=hSuRA5yPk0txWtMTfo5kexbdn8zxjohkJrtbalxaN0Z2LiXkgyST7TcrXe7N4Nhbdv g/lYq2JpaIEb9RaMZyxlx/ACItlnbKWyJvrZrzXKMhbaK/Q+FN/Nog9BHUr3VoL5KCXY 5kqYzIOoSeKi6ijdcgxiFA4AX0mGNSkrCycPbcoj9ARaXLMZqTqWqMu9VCDhpIRcJ6/S pH/AHWwFWhxLZ8kYwdhlJ6ZJE38T+bcWXJE0OVPh/G1Ua2ysagJOQBqTy+HdJqE+9c5z NJm1ZOCp8l7fUsVtQnMUxQqSVKb3cFuMBXqJvtKAsYxgv2b3rbbbC/l3poK4s/xcyEaB s+Bw== 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=oLm5QJkdwpBJJ2SO2TyRDolq0Gy/ncEB0GeDtGlk/aM=; fh=tgUWUbuI+B0KV3Xw+e/6lpHO2uTJDIACNIPu4ivbyA8=; b=MPXS8QlCqDQZNeZP1WAhe4IlHTK8RdxKnWDZjnL0X9xhprYHn4lClOK+qPa+q3exM+ GQ+pqQpI9a4twTvcZZHVdM6mMk+FEpEPLh56FYHn3DIfwGXIO1+CpN223AqCysp761yP 6ENC6CqxXmYde+t2m26Am2Old7jOwRwbKhiGea4SLMgVQNeTojySxWdNmu+2gXNhdMt0 F3ENT0DXuDVIjvyUliu48hnWpbRVBDqKT7myeutC3mBbC8PBS496L9q3Ze7o3/C4CIhv a2uox9lKR4wZXK7FX2XWcQo7XH8uGPsbklDHLIpvHc0MBYlP3EWfvgkMvzLkaC5doeeO jbeg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=SjEHjVn2; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-90048-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-90048-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id g15-20020a63f40f000000b005cdf488ba0asi7714349pgi.746.2024.03.03.22.07.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Mar 2024 22:07:01 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-90048-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=@intel.com header.s=Intel header.b=SjEHjVn2; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-90048-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-90048-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 7B99B281445 for ; Mon, 4 Mar 2024 04:48:30 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E984C6FA9; Mon, 4 Mar 2024 04:48:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="SjEHjVn2" 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 7F4B217F3; Mon, 4 Mar 2024 04:48:20 +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=1709527702; cv=none; b=Pm4UGQ/E1OWsR48JLHMIbxtp72xKHdA/FiQ86BSU01wPUKkFHPzz1wHb12kGHvY1FvqbmHjNopDSilXY3bivGwvsWeGXynvJS9x2VR96ox0b6CVgWHO7xiQP+ROSaON0aMDB0wRdnizL/ZLfkQd/wuOMK0D36AOraWkJBBDYBO4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709527702; c=relaxed/simple; bh=TkObtEKI/tyB4jiEf0y2L56Ri8j/zice+wU0hAX+lVw=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=qKcBC14olPhoMAUQe6IQjetwkpe4sSvvRNM8K7wP3GFEK1KXI0QbJ2n0YTeOv5TFJ3t70xIuh+wmtp+MZFyJw7B5UjFYuaf6FwQSG4wl6SG9k9LXmICubVr+EMLhxoeOjxg+od+sxQ80VeMsH3AAvWBmKydNPsyJ8NCdrzabmpU= 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=SjEHjVn2; 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=1709527700; x=1741063700; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=TkObtEKI/tyB4jiEf0y2L56Ri8j/zice+wU0hAX+lVw=; b=SjEHjVn2ijKtG4M4D3kYqrCBffIo3nkXjPa2v8TFhOxNroBRb3RdgQ/N SC3JbfxfTFVxHYkvpg80D6zHmlB6WnXkCNVgF9bViLHFm8MhYJg4tFBQ1 v1NhxChpRbbHiTAkpab2Xu2Mi7dN/WAIzH/sEFyieU6+Ao6wEEpFCXre3 QKQgxVPBP0UvweirX3CrZ+FTG8AWwJlndtYrD6cK5dGcloxfflhZK5fFT uRk11sgGIR3SDAw12utAxJ3mDFJ+vn/WodV2s3ucgfDL4FsHnlPGSdTkI Tm5Vo84bdYOcKbem65+d8/060Qbw8XJDrwqUS+8tiKpoGZ5chfh0evZ70 w==; X-IronPort-AV: E=McAfee;i="6600,9927,11002"; a="4167322" X-IronPort-AV: E=Sophos;i="6.06,203,1705392000"; d="scan'208";a="4167322" Received: from fmviesa003.fm.intel.com ([10.60.135.143]) by orvoesa109.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Mar 2024 20:48:19 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,203,1705392000"; d="scan'208";a="13437328" Received: from yilunxu-optiplex-7050.sh.intel.com (HELO localhost) ([10.239.159.165]) by fmviesa003.fm.intel.com with ESMTP; 03 Mar 2024 20:48:18 -0800 Date: Mon, 4 Mar 2024 12:44:07 +0800 From: Xu Yilun 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 Subject: Re: [PATCH 19/21] KVM: guest_memfd: add API to undo kvm_gmem_get_uninit_pfn Message-ID: References: <20240227232100.478238-1-pbonzini@redhat.com> <20240227232100.478238-20-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=us-ascii Content-Disposition: inline In-Reply-To: <20240227232100.478238-20-pbonzini@redhat.com> On Tue, Feb 27, 2024 at 06:20:58PM -0500, Paolo Bonzini wrote: > In order to be able to redo kvm_gmem_get_uninit_pfn, a hole must be punched > into the filemap, thus allowing FGP_CREAT_ONLY to succeed again. This will > be used whenever an operation that follows kvm_gmem_get_uninit_pfn fails. > > Signed-off-by: Paolo Bonzini > --- > include/linux/kvm_host.h | 7 +++++++ > virt/kvm/guest_memfd.c | 28 ++++++++++++++++++++++++++++ > 2 files changed, 35 insertions(+) > > diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h > index 03bf616b7308..192c58116220 100644 > --- a/include/linux/kvm_host.h > +++ b/include/linux/kvm_host.h > @@ -2436,6 +2436,8 @@ int kvm_gmem_get_pfn(struct kvm *kvm, struct kvm_memory_slot *slot, > gfn_t gfn, kvm_pfn_t *pfn, int *max_order); > int kvm_gmem_get_uninit_pfn(struct kvm *kvm, struct kvm_memory_slot *slot, > gfn_t gfn, kvm_pfn_t *pfn, int *max_order); > +int kvm_gmem_undo_get_pfn(struct kvm *kvm, struct kvm_memory_slot *slot, > + gfn_t gfn, int order); > #else > static inline int kvm_gmem_get_pfn(struct kvm *kvm, > struct kvm_memory_slot *slot, gfn_t gfn, > @@ -2452,6 +2454,11 @@ static inline int kvm_gmem_get_uninit_pfn(struct kvm *kvm, > KVM_BUG_ON(1, kvm); > return -EIO; > } > + > +static inline int kvm_gmem_undo_get_pfn(struct kvm *kvm, > + struct kvm_memory_slot *slot, gfn_t gfn, > + int order) > +{} return -EIO; or compiler would complain that no return value. > #endif /* CONFIG_KVM_PRIVATE_MEM */ > > #ifdef CONFIG_HAVE_KVM_GMEM_PREPARE > diff --git a/virt/kvm/guest_memfd.c b/virt/kvm/guest_memfd.c > index 7ec7afafc960..535ef1aa34fb 100644 > --- a/virt/kvm/guest_memfd.c > +++ b/virt/kvm/guest_memfd.c > @@ -590,3 +590,31 @@ int kvm_gmem_get_uninit_pfn(struct kvm *kvm, struct kvm_memory_slot *slot, > return __kvm_gmem_get_pfn(kvm, slot, gfn, pfn, max_order, false); > } > EXPORT_SYMBOL_GPL(kvm_gmem_get_uninit_pfn); > + > +int kvm_gmem_undo_get_pfn(struct kvm *kvm, struct kvm_memory_slot *slot, > + gfn_t gfn, int order) Didn't see the caller yet, but do we need to ensure the gfn is aligned with page order? e.g. WARN_ON(gfn & ((1UL << order) - 1)); > +{ > + pgoff_t index = gfn - slot->base_gfn + slot->gmem.pgoff; > + struct kvm_gmem *gmem; > + struct file *file; > + int r; > + > + file = kvm_gmem_get_file(slot); > + if (!file) > + return -EFAULT; > + > + gmem = file->private_data; > + > + if (WARN_ON_ONCE(xa_load(&gmem->bindings, index) != slot)) { > + r = -EIO; > + goto out_fput; > + } > + > + r = kvm_gmem_punch_hole(file_inode(file), index << PAGE_SHIFT, PAGE_SHIFT << order); ^ PAGE_SIZE << order Thanks, Yilun > + > +out_fput: > + fput(file); > + > + return r; > +} > +EXPORT_SYMBOL_GPL(kvm_gmem_undo_get_pfn); > -- > 2.39.0 > > >