From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 68B60C3DA4A for ; Tue, 30 Jul 2024 03:08:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D87E06B007B; Mon, 29 Jul 2024 23:08:55 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D37876B0083; Mon, 29 Jul 2024 23:08:55 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BD8136B0085; Mon, 29 Jul 2024 23:08:55 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 9AD676B007B for ; Mon, 29 Jul 2024 23:08:55 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 07B32A21C6 for ; Tue, 30 Jul 2024 03:08:55 +0000 (UTC) X-FDA: 82394937030.02.2EEFEA6 Received: from mail-vs1-f50.google.com (mail-vs1-f50.google.com [209.85.217.50]) by imf14.hostedemail.com (Postfix) with ESMTP id 3B4F310001C for ; Tue, 30 Jul 2024 03:08:53 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=BKpXCWMz; spf=pass (imf14.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.217.50 as permitted sender) smtp.mailfrom=21cnbao@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1722308861; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=LGwHErpXzosqNy0EwP2+ZXrgOtRglWVeO8E0C/27bD8=; b=fgfWUrjDMNVpjzbdnGmB1FPpRLcM1/ZITK5L3Kxa6ezLqPV2YNXQWQsgpbleUjrQ+Q25u5 FC5k0CJn/AE3Ml+PPiwcd0iWiRr+x4Kbd8xeT8iuCMXUuXqoQSuxZUrfZQaK8YKFxdBMlr /kkv1ed+ROWSpwga90P0hXnQoasan4k= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=BKpXCWMz; spf=pass (imf14.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.217.50 as permitted sender) smtp.mailfrom=21cnbao@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1722308861; a=rsa-sha256; cv=none; b=1wAi7Jz3Z/FqNeVuvt+q+9gVhzoK4pMtfoEa5WnxbFQ8+G8RWxEzB+jvkoiyhfJxbO15nD 36pTLKT4w1sb/j3+j5HYRGgeIvjZwd1rA+sCZWxA2dIJloMz9J9E3avfRRGrO2JuLmq/E5 tA++4nRO0F+MFf26rOuOyv6OQaX6ZOI= Received: by mail-vs1-f50.google.com with SMTP id ada2fe7eead31-493d748ba72so903172137.3 for ; Mon, 29 Jul 2024 20:08:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722308932; x=1722913732; darn=kvack.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=LGwHErpXzosqNy0EwP2+ZXrgOtRglWVeO8E0C/27bD8=; b=BKpXCWMzBxu6h2QBnJK0Q5sr/WSi7cFFqOOd9EKQ7cJ7uDKByGlW+hxYE//4vBllvv uu6Bd6zs/nKE+7XuQ1corXXP5V2+h2SMUPFur+BoG1oSBmrV4Q8dJPOQLTZSM8b6JdC5 7ccwCagzv5BrSLAooCw95X4nxx2w8c1gz/M4NWqczN740csw8GlXKCG3tCxjzaPtBrMR zHamwgODMyXQ1NfCXXeSkUaX8WCjToiejbE+N35kT6VdvSYqw+D2kJjTXJY35nQbelSG FfSvvJUT8i03U6ATlZvfb+bLGLz2L+zSYF/HypYBnO3egNFC3Jo+IN4NsoR/TvR0d8Md bNqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722308932; x=1722913732; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=LGwHErpXzosqNy0EwP2+ZXrgOtRglWVeO8E0C/27bD8=; b=ASC/etWqoT/kXI8edOGOOvmCrAd3ZZGKlKzTCJzWGPuot8eXHN7crF8UI+5fXTsGyZ cXq8DQAemBcy4wqjpcjAUVnFGIytPObtqWox5sLIo0BPGT0k0Dllw0T2rNrPfnHQ4n1f abJSfYg8z4C5rTsxbY0VSSJ642lFY8fKPCVpjMaP2X3SlKUHZc0T1kfV73RBEJSNa3rW nU7QXMLprfaqkqmlSR507DlkvWZjhaKkN2mgwD64gvQ7/i1lgnOqd7bv1WqCr6T4lmcl W10Y+uIqWHFaTsD8D+w5K1xQe7QXZoIJ7BYQlVVNVK+NqkXIm9Va0ickn21Vr251EqIL y5BA== X-Forwarded-Encrypted: i=1; AJvYcCV2qK9bm1tOUIetjiHYdhVROmh0KRF5kuQomUo+l731C9jYHyxqHR2ASiXlc+owko/y2ByGnUIqg03S8heSsT0maiw= X-Gm-Message-State: AOJu0Yx8Ug9XoI9IBnTx6p0bAZ/gwVAphiT0HAS7u3+4R/J0ID9avX8A VmMvip2P/nsXRG2kz0fQ5utU+OpZmHLJu6T8ZyyR/SPiywPhulDAnKiUl7Im4kBlINRP+7+NHaG MaQrBDxSYzeXY78y7We/cT2E7cZE= X-Google-Smtp-Source: AGHT+IEhuAQNKawilTtLqMQ1DZGdifl+qDGJs63nG9lYXmHxbBimB9J6YK/+7Ez1HthG1YMQqgWwy9agjivJOrf2fjk= X-Received: by 2002:a05:6102:38ce:b0:492:9394:d2e with SMTP id ada2fe7eead31-493fa1c7700mr11219166137.16.1722308932107; Mon, 29 Jul 2024 20:08:52 -0700 (PDT) MIME-Version: 1.0 References: <20240729060529.93243-1-21cnbao@gmail.com> In-Reply-To: From: Barry Song <21cnbao@gmail.com> Date: Tue, 30 Jul 2024 11:08:40 +0800 Message-ID: Subject: Re: [PATCH RFC 1/5] vpda: try to fix the potential crash due to misusing __GFP_NOFAIL To: Jason Wang Cc: 42.hyeyoo@gmail.com, akpm@linux-foundation.org, cl@linux.com, eperezma@redhat.com, hailong.liu@oppo.com, hch@infradead.org, iamjoonsoo.kim@lge.com, linux-mm@kvack.org, lstoakes@gmail.com, maxime.coquelin@redhat.com, mhocko@suse.com, mst@redhat.com, penberg@kernel.org, rientjes@google.com, roman.gushchin@linux.dev, torvalds@linux-foundation.org, urezki@gmail.com, v-songbaohua@oppo.com, vbabka@suse.cz, virtualization@lists.linux.dev, xuanzhuo@linux.alibaba.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 3B4F310001C X-Stat-Signature: t6r5ho4b7xq3fnyih1xk1hjrf5c6em1h X-Rspam-User: X-HE-Tag: 1722308933-690119 X-HE-Meta: U2FsdGVkX1/0crWm428GqR0h87SOOKAjFtJb0TifYx96gVrPezpu8VMzXjZ0rXjs2I50Nz8mTKx34iF5YWooDAO98aReDvGITZYDVkV3FvCI6nG16JTkLaZ40XhmMwt0R8/GT20T+3rQ8dorgWfkvG2LiJLtJAUS3ewWv5eM72oc0n0uYZXmr/q/gvJhNzULPeVJO6OWsuQehBUwCFW03ljIwl7Op8Duye8G00QwunMT9mIFd23z8RFYrJRPBQiXSPSTpnS0SgwRK96qutr+vLz228TvBTtsdvEFFC7BvQq42DgJkbs8ks7rEVEwBpEL1/RHfD30KoSVplMSdWuIgUT67Jh50OSscVjXyu25YWz0Z+egqp0YkJvPg1sIKgrK6O5ZJiH7rXvSPbW8vi8O1yGphuUxycmw87gVdlxm10aLD7CLUEIPwjJeQMxHON7KatymwXGZFezyShIYiyNPxpM7+LEZmqJ5rt4O8EbEUfxVa3752jOeYpgC8OnpnIFYyXRFGx3FlIX0zgbgXG3d6A2Ap+IE6hM5WK3Fh0h10qgNysk1KFPUNjGHWxI47qxS5X5s8M4uLyKDlNjP5SndJvrIeJqJuU7mYTr0hW+4IKxvgUGbp4awSxTMQBhkPAjCHz+KXFhdaFqqnVRYcpslIHt3IUVSi068WoslkcR/puesfZuDV5gLiBRhfn1nNM0ipnYgdrzpWtKibRcqOPlau8B2mxG9s4uhF2GS/tnEQdN9U+wuQ6EkeYRIxxTX9ZC9hRCAH6gz6OhowLIyy3sT7g49qI0b7OPiilLKNybAuVhyPztEJykV4myybKDSmUHiRQnWkRiFDImGjZp/0LmTw4WT9rQNKanOlQreSus3fibr+9Nu+8IdS3LGmCSDyDP2BNUImBBn+8GVHXd5luWc47cX9vxPKtMWldoi2BrNRt1YkUO1gAtrx7885l3TrG0cCK6TNQa5hXWeintut5z 4RShlSV5 oaxVHMeaIBKN7mW9cYQiEhsEOkBOnDkksK5Hsr7UOGIZ5uvmMkPgVV4yFJDZKddAWKgW22y+EAUp0D84C58W0beWaOiib2BM57NAd8wa6fD7Y+8wo9GqyAGK6z3hFHlJyYGrhtUQiEyu+21AM5TQ7X/tqksd/ydofemuMtrYLYPqhTAfgqADHyR94gwqL8Zf3TBgQjDkSVqzU9b+2iNbSH7mej3iJXZVhJXgH5AqRUGJ89IHnXjeMXpiblUFXI79rYwaPJS+n71bJHn7fMPneTF59t82wLv4oha1zX/av1hL5wtXT8GSiMCsUONBr9VyD2tJNIBfOhoALdYrhql2LDeN4QaAXIJaaUHK+hdBKWwNsdBFGedKgDJ09iZVZfPSuFoJ3JH2R8g77wavHVD+EvnWc18GfjPdXYd11fhM58QjU8SpA7K8a8SVGEN17pUeMW8z7IpAy/IzBO1oaOwehpBzwPRnFkTfBCjAj22A9lN0JqXZDha5oekyKVm7L0WcALpNnJfczwwfixg3g7J18s7K9nAuQg0a/QAFybW1wpQ7giR2IpjoCgZBl07PHtiXTmaXDXAOUJ2HN0cIT/Ejfib1wELOftjydBNT+PgkQWMy9lx7y2RaGdpuOQLbTUXDeLRzj X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Tue, Jul 30, 2024 at 10:49=E2=80=AFAM Jason Wang w= rote: > > On Mon, Jul 29, 2024 at 2:05=E2=80=AFPM Barry Song <21cnbao@gmail.com> wr= ote: > > > > On Mon, Jul 29, 2024 at 3:42=E2=80=AFPM Jason Wang wrote: > > > > > > On Thu, Jul 25, 2024 at 3:00=E2=80=AFPM Barry Song <21cnbao@gmail.com= > wrote: > > > > > > > > On Thu, Jul 25, 2024 at 6:08=E2=80=AFPM Michal Hocko wrote: > > > > > > > > > > On Thu 25-07-24 10:50:45, Barry Song wrote: > > > > > > On Thu, Jul 25, 2024 at 12:27=E2=80=AFAM Michal Hocko wrote: > > > > > > > > > > > > > > On Wed 24-07-24 20:55:40, Barry Song wrote: > > > > > [...] > > > > > > > > diff --git a/drivers/vdpa/vdpa_user/iova_domain.c b/drivers= /vdpa/vdpa_user/iova_domain.c > > > > > > > > index 791d38d6284c..eff700e5f7a2 100644 > > > > > > > > --- a/drivers/vdpa/vdpa_user/iova_domain.c > > > > > > > > +++ b/drivers/vdpa/vdpa_user/iova_domain.c > > > > > > > > @@ -287,28 +287,44 @@ void vduse_domain_remove_user_bounce_= pages(struct vduse_iova_domain *domain) > > > > > > > > { > > > > > > > > struct vduse_bounce_map *map; > > > > > > > > unsigned long i, count; > > > > > > > > + struct page **pages =3D NULL; > > > > > > > > > > > > > > > > write_lock(&domain->bounce_lock); > > > > > > > > if (!domain->user_bounce_pages) > > > > > > > > goto out; > > > > > > > > - > > > > > > > > count =3D domain->bounce_size >> PAGE_SHIFT; > > > > > > > > + write_unlock(&domain->bounce_lock); > > > > > > > > + > > > > > > > > + pages =3D kmalloc_array(count, sizeof(*pages), GFP_KE= RNEL | __GFP_NOFAIL); > > > > > > > > + for (i =3D 0; i < count; i++) > > > > > > > > + pages[i] =3D alloc_page(GFP_KERNEL | __GFP_NO= FAIL); > > > > > > > > > > > > > > AFAICS vduse_domain_release calls this function with > > > > > > > spin_lock(&domain->iotlb_lock) so dropping &domain->bounce_lo= ck is not > > > > > > > sufficient. > > > > > > > > > > > > yes. this is true: > > > > > > > > > > > > static int vduse_domain_release(struct inode *inode, struct fil= e *file) > > > > > > { > > > > > > struct vduse_iova_domain *domain =3D file->private_data= ; > > > > > > > > > > > > spin_lock(&domain->iotlb_lock); > > > > > > vduse_iotlb_del_range(domain, 0, ULLONG_MAX); > > > > > > vduse_domain_remove_user_bounce_pages(domain); > > > > > > vduse_domain_free_kernel_bounce_pages(domain); > > > > > > spin_unlock(&domain->iotlb_lock); > > > > > > put_iova_domain(&domain->stream_iovad); > > > > > > put_iova_domain(&domain->consistent_iovad); > > > > > > vhost_iotlb_free(domain->iotlb); > > > > > > vfree(domain->bounce_maps); > > > > > > kfree(domain); > > > > > > > > > > > > return 0; > > > > > > } > > > > > > > > > > > > This is quite a pain. I admit I don't have knowledge of this dr= iver, and I don't > > > > > > think it's safe to release two locks and then reacquire them. T= he situation is > > > > > > rather complex. Therefore, I would prefer if the VDPA maintaine= rs could > > > > > > take the lead in implementing a proper fix. > > > > > > > > > > Would it be possible to move all that work to a deferred context? > > > > > > > > My understanding is that we need to be aware of both the iotlb_lock= and > > > > bounce_lock to implement the correct changes. As long as we still n= eed > > > > to acquire these two locks in a deferred context, there doesn't see= m to > > > > be any difference. > > > > > > > > I can do the memory pre-allocation before spin_lock(&domain->iotlb_= lock), > > > > but I have no knowledge whether the "count" will change after I mak= e > > > > the preallocation. > > > > > > > > diff --git a/drivers/vdpa/vdpa_user/iova_domain.c > > > > b/drivers/vdpa/vdpa_user/iova_domain.c > > > > index 791d38d6284c..7ec87ef33d42 100644 > > > > --- a/drivers/vdpa/vdpa_user/iova_domain.c > > > > +++ b/drivers/vdpa/vdpa_user/iova_domain.c > > > > @@ -544,9 +544,12 @@ static int vduse_domain_release(struct inode > > > > *inode, struct file *file) > > > > { > > > > struct vduse_iova_domain *domain =3D file->private_data; > > > > > > > > + struct page **pages; > > > > + spin_lock(&domain->iotlb_lock); maybe also + bounce_lock? > > > > + count =3D domain->bounce_size >> PAGE_SHIFT; > > > > + spin_unlock(&domain->iotlb_lock); > > > > > > We probably don't need any lock here as bounce_size won't be changed = . > > > > > > > + > > > > + preallocate_count_pages(pages, count); > > > > + > > > > .... > > > > spin_lock(&domain->iotlb_lock); > > > > vduse_iotlb_del_range(domain, 0, ULLONG_MAX); > > > > - vduse_domain_remove_user_bounce_pages(domain); > > > > + vduse_domain_remove_user_bounce_pages(domain, pages); > > > > vduse_domain_free_kernel_bounce_pages(domain); > > > > spin_unlock(&domain->iotlb_lock); > > > > put_iova_domain(&domain->stream_iovad); > > > > > > This seems to work. > > > > Thanks, Jason. I personally have no knowledge of vDPA. Could you please= help > > review and test the patch below? > > > > From 1f3cae091159bfcaffdb4a999a4a8e37db2eacf1 Mon Sep 17 00:00:00 2001 > > From: Barry Song > > Date: Wed, 24 Jul 2024 20:55:40 +1200 > > Subject: [PATCH RFC v2] vpda: try to fix the potential crash due to mis= using > > __GFP_NOFAIL > > MIME-Version: 1.0 > > Content-Type: text/plain; charset=3DUTF-8 > > Content-Transfer-Encoding: 8bit > > > > mm doesn't support non-blockable __GFP_NOFAIL allocation. Because > > __GFP_NOFAIL without direct reclamation may just result in a busy > > loop within non-sleepable contexts. > > > > static inline struct page * > > __alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order, > > struct alloc_context *a= c) > > { > > ... > > /* > > * Make sure that __GFP_NOFAIL request doesn't leak out and mak= e sure > > * we always retry > > */ > > if (gfp_mask & __GFP_NOFAIL) { > > /* > > * All existing users of the __GFP_NOFAIL are blockable= , so warn > > * of any new users that actually require GFP_NOWAIT > > */ > > if (WARN_ON_ONCE_GFP(!can_direct_reclaim, gfp_mask)) > > goto fail; > > ... > > } > > ... > > fail: > > warn_alloc(gfp_mask, ac->nodemask, > > "page allocation failure: order:%u", order); > > got_pg: > > return page; > > } > > > > Let's move the memory allocation out of the atomic context and use > > the normal sleepable context to get pages. > > > > [RFC]: This has only been compile-tested; I'd prefer if the VDPA mainta= iners > > handles it. > > > > Cc: "Michael S. Tsirkin" > > Cc: Jason Wang > > Cc: Xuan Zhuo > > Cc: "Eugenio P=C3=A9rez" > > Cc: Maxime Coquelin > > Signed-off-by: Barry Song > > --- > > drivers/vdpa/vdpa_user/iova_domain.c | 21 ++++++++++++++++----- > > drivers/vdpa/vdpa_user/iova_domain.h | 3 ++- > > drivers/vdpa/vdpa_user/vduse_dev.c | 13 ++++++++++++- > > 3 files changed, 30 insertions(+), 7 deletions(-) > > > > diff --git a/drivers/vdpa/vdpa_user/iova_domain.c b/drivers/vdpa/vdpa_u= ser/iova_domain.c > > index 791d38d6284c..014809ac2b7c 100644 > > --- a/drivers/vdpa/vdpa_user/iova_domain.c > > +++ b/drivers/vdpa/vdpa_user/iova_domain.c > > @@ -283,7 +283,7 @@ int vduse_domain_add_user_bounce_pages(struct vduse= _iova_domain *domain, > > return ret; > > } > > > > -void vduse_domain_remove_user_bounce_pages(struct vduse_iova_domain *d= omain) > > +void vduse_domain_remove_user_bounce_pages(struct vduse_iova_domain *d= omain, struct page **pages) > > { > > struct vduse_bounce_map *map; > > unsigned long i, count; > > @@ -294,15 +294,16 @@ void vduse_domain_remove_user_bounce_pages(struct= vduse_iova_domain *domain) > > > > count =3D domain->bounce_size >> PAGE_SHIFT; > > for (i =3D 0; i < count; i++) { > > - struct page *page =3D NULL; > > + struct page *page =3D pages[i]; > > > > map =3D &domain->bounce_maps[i]; > > - if (WARN_ON(!map->bounce_page)) > > + if (WARN_ON(!map->bounce_page)) { > > + put_page(page); > > continue; > > + } > > > > /* Copy user page to kernel page if it's in use */ > > if (map->orig_phys !=3D INVALID_PHYS_ADDR) { > > - page =3D alloc_page(GFP_ATOMIC | __GFP_NOFAIL); > > memcpy_from_page(page_address(page), > > map->bounce_page, 0, PAGE_SIZE= ); > > } > > @@ -543,10 +544,19 @@ static int vduse_domain_mmap(struct file *file, s= truct vm_area_struct *vma) > > static int vduse_domain_release(struct inode *inode, struct file *file= ) > > { > > struct vduse_iova_domain *domain =3D file->private_data; > > + struct page **pages =3D NULL; > > + unsigned long count, i; > > + > > + if (domain->user_bounce_pages) { > > + count =3D domain->bounce_size >> PAGE_SHIFT; > > + pages =3D kmalloc_array(count, sizeof(*pages), GFP_KERN= EL | __GFP_NOFAIL); > > + for (i =3D 0; i < count; i++) > > + pages[i] =3D alloc_page(GFP_KERNEL | __GFP_NOFA= IL); > > + } > > > > spin_lock(&domain->iotlb_lock); > > vduse_iotlb_del_range(domain, 0, ULLONG_MAX); > > - vduse_domain_remove_user_bounce_pages(domain); > > + vduse_domain_remove_user_bounce_pages(domain, pages); > > vduse_domain_free_kernel_bounce_pages(domain); > > spin_unlock(&domain->iotlb_lock); > > put_iova_domain(&domain->stream_iovad); > > @@ -554,6 +564,7 @@ static int vduse_domain_release(struct inode *inode= , struct file *file) > > vhost_iotlb_free(domain->iotlb); > > vfree(domain->bounce_maps); > > kfree(domain); > > + kfree(pages); > > > > return 0; > > } > > diff --git a/drivers/vdpa/vdpa_user/iova_domain.h b/drivers/vdpa/vdpa_u= ser/iova_domain.h > > index f92f22a7267d..db0b793d86db 100644 > > --- a/drivers/vdpa/vdpa_user/iova_domain.h > > +++ b/drivers/vdpa/vdpa_user/iova_domain.h > > @@ -74,7 +74,8 @@ void vduse_domain_reset_bounce_map(struct vduse_iova_= domain *domain); > > int vduse_domain_add_user_bounce_pages(struct vduse_iova_domain *domai= n, > > struct page **pages, int count); > > > > -void vduse_domain_remove_user_bounce_pages(struct vduse_iova_domain *d= omain); > > +void vduse_domain_remove_user_bounce_pages(struct vduse_iova_domain *d= omain, > > + struct page **pages); > > > > void vduse_domain_destroy(struct vduse_iova_domain *domain); > > > > diff --git a/drivers/vdpa/vdpa_user/vduse_dev.c b/drivers/vdpa/vdpa_use= r/vduse_dev.c > > index 7ae99691efdf..df7c1b6f1350 100644 > > --- a/drivers/vdpa/vdpa_user/vduse_dev.c > > +++ b/drivers/vdpa/vdpa_user/vduse_dev.c > > @@ -1030,6 +1030,8 @@ static int vduse_dev_queue_irq_work(struct vduse_= dev *dev, > > static int vduse_dev_dereg_umem(struct vduse_dev *dev, > > u64 iova, u64 size) > > { > > + struct page **pages =3D NULL; > > + unsigned long count, i; > > int ret; > > > > mutex_lock(&dev->mem_lock); > > @@ -1044,13 +1046,22 @@ static int vduse_dev_dereg_umem(struct vduse_de= v *dev, > > if (dev->umem->iova !=3D iova || size !=3D dev->domain->bounce_= size) > > goto unlock; > > > > - vduse_domain_remove_user_bounce_pages(dev->domain); > > + if (dev->domain->user_bounce_pages) { > > + count =3D dev->domain->bounce_size >> PAGE_SHIFT; > > + pages =3D kmalloc_array(count, sizeof(*pages), > > + GFP_KERNEL | __GFP_NOFAIL); > > + for (i =3D 0; i < count; i++) > > + pages[i] =3D alloc_page(GFP_KERNEL | __GFP_NOFA= IL); > > + } > > Nit: there's some code duplication with vduse_domain_release(). > > Others look good to me. > > Would you like to post a formal patch? Jason, thanks! I haven't tested this patch and I don't have the setup to test. I wonder if you can post a tested-by tag before I send a formal patch. BTW, if we want to have a common function to remove the duplicated code, what is the name you suggest to have for this function? > > Thanks > > > + > > + vduse_domain_remove_user_bounce_pages(dev->domain, pages); > > unpin_user_pages_dirty_lock(dev->umem->pages, > > dev->umem->npages, true); > > atomic64_sub(dev->umem->npages, &dev->umem->mm->pinned_vm); > > mmdrop(dev->umem->mm); > > vfree(dev->umem->pages); > > kfree(dev->umem); > > + kfree(pages); > > dev->umem =3D NULL; > > ret =3D 0; > > unlock: > > -- > > 2.34.1 > > > > > > > > Thanks > > > > > > > > > > > > > > > > -- > > > > > Michal Hocko > > > > > SUSE Labs > > > > > > > > Thanks > > Barry > > > Thanks Barry