> From: Jason Gunthorpe <jgg@xxxxxxxxxx> > Sent: Friday, August 4, 2023 10:04 PM > > On Fri, Aug 04, 2023 at 01:04:57PM +0000, Liu, Yi L wrote: > > > > Having the driver copy in a loop might be better > > > > > > > > > > Can you elaborate? > > > > I think Jason means the way in patch 09. > > Yeah, you can't reuse the stack buffer for an array, so patch 9 copies > each element uniquely. > > This is more calls to copy_to_user, which has some cost > > But we avoid a memory allocation Yes. > Patch 9 should not abuse the user_data, cast it to the inv_info and > just put req on the stack: > > struct iommu_hwpt_vtd_s1_invalidate *inv_info = user_data; > struct iommu_hwpt_vtd_s1_invalidate_desc req; Sure. The way in patch 09 is a bit tricky. The above is better and clearer. 😊 > But I'm not sure about this entry_size logic, what happens if the > entry_size is larger than the kernel supports? I think it should > fail.. Yes. should fail. It should be failed in copy_struct_from_user() as I use it to copy the struct iommu_hwpt_vtd_s1_invalidate_desc. * -E2BIG: (@usize > @ksize) and there are non-zero trailing bytes in @src. Regards, Yi Liu