[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <aFyA881sUUjxHCFh@Asurada-Nvidia>
Date: Wed, 25 Jun 2025 16:06:27 -0700
From: Nicolin Chen <nicolinc@...dia.com>
To: "Tian, Kevin" <kevin.tian@...el.com>
CC: "jgg@...dia.com" <jgg@...dia.com>, "corbet@....net" <corbet@....net>,
"will@...nel.org" <will@...nel.org>, "bagasdotme@...il.com"
<bagasdotme@...il.com>, "robin.murphy@....com" <robin.murphy@....com>,
"joro@...tes.org" <joro@...tes.org>, "thierry.reding@...il.com"
<thierry.reding@...il.com>, "vdumpa@...dia.com" <vdumpa@...dia.com>,
"jonathanh@...dia.com" <jonathanh@...dia.com>, "shuah@...nel.org"
<shuah@...nel.org>, "jsnitsel@...hat.com" <jsnitsel@...hat.com>,
"nathan@...nel.org" <nathan@...nel.org>, "peterz@...radead.org"
<peterz@...radead.org>, "Liu, Yi L" <yi.l.liu@...el.com>,
"mshavit@...gle.com" <mshavit@...gle.com>, "praan@...gle.com"
<praan@...gle.com>, "zhangzekun11@...wei.com" <zhangzekun11@...wei.com>,
"iommu@...ts.linux.dev" <iommu@...ts.linux.dev>, "linux-doc@...r.kernel.org"
<linux-doc@...r.kernel.org>, "linux-kernel@...r.kernel.org"
<linux-kernel@...r.kernel.org>, "linux-arm-kernel@...ts.infradead.org"
<linux-arm-kernel@...ts.infradead.org>, "linux-tegra@...r.kernel.org"
<linux-tegra@...r.kernel.org>, "linux-kselftest@...r.kernel.org"
<linux-kselftest@...r.kernel.org>, "patches@...ts.linux.dev"
<patches@...ts.linux.dev>, "mochs@...dia.com" <mochs@...dia.com>,
"alok.a.tiwari@...cle.com" <alok.a.tiwari@...cle.com>, "vasant.hegde@....com"
<vasant.hegde@....com>, "dwmw2@...radead.org" <dwmw2@...radead.org>,
"baolu.lu@...ux.intel.com" <baolu.lu@...ux.intel.com>
Subject: Re: [PATCH v6 10/25] iommufd/viommu: Add IOMMUFD_CMD_HW_QUEUE_ALLOC
ioctl
On Wed, Jun 25, 2025 at 03:45:08AM +0000, Tian, Kevin wrote:
> > From: Nicolin Chen <nicolinc@...dia.com>
> > Sent: Saturday, June 14, 2025 3:15 PM
> > +
> > + offset =
> > + cmd->nesting_parent_iova - PAGE_ALIGN(cmd-
> > >nesting_parent_iova);
> > + max_npages = DIV_ROUND_UP(offset + cmd->length, PAGE_SIZE);
> > +
> > + /*
> > + * FIXME allocation may fail when sizeof(*pages) * max_npages is
> > + * larger than PAGE_SIZE. This might need a new API returning a
> > + * bio_vec or something more efficient.
> > + */
> > + pages = kcalloc(max_npages, sizeof(*pages), GFP_KERNEL);
> > + if (!pages)
> > + return ERR_PTR(-ENOMEM);
> > +
>
> any allocation may fail... can you elaborate more here? How does
> PAGE_SIZE become a boundary?
Memory fragmentation can be the reason. It's easy to get one page
but not for contiguous pages.
Jason suggested to use kvcalloc, so I am adding this:
@@ -249,11 +249,10 @@ iommufd_hw_queue_alloc_phys(struct iommu_hw_queue_alloc *cmd,
max_npages = DIV_ROUND_UP(offset + cmd->length, PAGE_SIZE);
/*
- * FIXME allocation may fail when sizeof(*pages) * max_npages is
- * larger than PAGE_SIZE. This might need a new API returning a
- * bio_vec or something more efficient.
+ * Use kvcalloc() to avoid memory fragmentation for a large page array.
+ * Set __GFP_NOWARN to avoid syzkaller blowups
*/
- pages = kcalloc(max_npages, sizeof(*pages), GFP_KERNEL);
+ pages = kvcalloc(max_npages, sizeof(*pages), GFP_KERNEL | __GFP_NOWARN);
if (!pages)
return ERR_PTR(-ENOMEM);
Thanks
Nicolin
Powered by blists - more mailing lists