Skip to content

Commit b7cb382

Browse files
mjkravetzakpm00
authored andcommitted
udmabuf: revert 'Add support for mapping hugepages (v4)'
This effectively reverts commit 16c243e ("udmabuf: Add support for mapping hugepages (v4)"). Recently, Junxiao Chang found a BUG with page map counting as described here [1]. This issue pointed out that the udmabuf driver was making direct use of subpages of hugetlb pages. This is not a good idea, and no other mm code attempts such use. In addition to the mapcount issue, this also causes issues with hugetlb vmemmap optimization and page poisoning. For now, remove hugetlb support. If udmabuf wants to be used on hugetlb mappings, it should be changed to only use complete hugetlb pages. This will require different alignment and size requirements on the UDMABUF_CREATE API. [1] https://lore.kernel.org/linux-mm/[email protected]/ Link: https://lkml.kernel.org/r/[email protected] Fixes: 16c243e ("udmabuf: Add support for mapping hugepages (v4)") Signed-off-by: Mike Kravetz <[email protected]> Acked-by: Greg Kroah-Hartman <[email protected]> Acked-by: Vivek Kasireddy <[email protected]> Acked-by: Gerd Hoffmann <[email protected]> Cc: David Hildenbrand <[email protected]> Cc: Dongwon Kim <[email protected]> Cc: James Houghton <[email protected]> Cc: Jerome Marchand <[email protected]> Cc: Junxiao Chang <[email protected]> Cc: Kirill A. Shutemov <[email protected]> Cc: Michal Hocko <[email protected]> Cc: Muchun Song <[email protected]> Cc: <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent c8a8f3b commit b7cb382

File tree

1 file changed

+6
-41
lines changed

1 file changed

+6
-41
lines changed

drivers/dma-buf/udmabuf.c

Lines changed: 6 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
#include <linux/shmem_fs.h>
1313
#include <linux/slab.h>
1414
#include <linux/udmabuf.h>
15-
#include <linux/hugetlb.h>
1615
#include <linux/vmalloc.h>
1716
#include <linux/iosys-map.h>
1817

@@ -207,9 +206,7 @@ static long udmabuf_create(struct miscdevice *device,
207206
struct udmabuf *ubuf;
208207
struct dma_buf *buf;
209208
pgoff_t pgoff, pgcnt, pgidx, pgbuf = 0, pglimit;
210-
struct page *page, *hpage = NULL;
211-
pgoff_t subpgoff, maxsubpgs;
212-
struct hstate *hpstate;
209+
struct page *page;
213210
int seals, ret = -EINVAL;
214211
u32 i, flags;
215212

@@ -245,7 +242,7 @@ static long udmabuf_create(struct miscdevice *device,
245242
if (!memfd)
246243
goto err;
247244
mapping = memfd->f_mapping;
248-
if (!shmem_mapping(mapping) && !is_file_hugepages(memfd))
245+
if (!shmem_mapping(mapping))
249246
goto err;
250247
seals = memfd_fcntl(memfd, F_GET_SEALS, 0);
251248
if (seals == -EINVAL)
@@ -256,48 +253,16 @@ static long udmabuf_create(struct miscdevice *device,
256253
goto err;
257254
pgoff = list[i].offset >> PAGE_SHIFT;
258255
pgcnt = list[i].size >> PAGE_SHIFT;
259-
if (is_file_hugepages(memfd)) {
260-
hpstate = hstate_file(memfd);
261-
pgoff = list[i].offset >> huge_page_shift(hpstate);
262-
subpgoff = (list[i].offset &
263-
~huge_page_mask(hpstate)) >> PAGE_SHIFT;
264-
maxsubpgs = huge_page_size(hpstate) >> PAGE_SHIFT;
265-
}
266256
for (pgidx = 0; pgidx < pgcnt; pgidx++) {
267-
if (is_file_hugepages(memfd)) {
268-
if (!hpage) {
269-
hpage = find_get_page_flags(mapping, pgoff,
270-
FGP_ACCESSED);
271-
if (!hpage) {
272-
ret = -EINVAL;
273-
goto err;
274-
}
275-
}
276-
page = hpage + subpgoff;
277-
get_page(page);
278-
subpgoff++;
279-
if (subpgoff == maxsubpgs) {
280-
put_page(hpage);
281-
hpage = NULL;
282-
subpgoff = 0;
283-
pgoff++;
284-
}
285-
} else {
286-
page = shmem_read_mapping_page(mapping,
287-
pgoff + pgidx);
288-
if (IS_ERR(page)) {
289-
ret = PTR_ERR(page);
290-
goto err;
291-
}
257+
page = shmem_read_mapping_page(mapping, pgoff + pgidx);
258+
if (IS_ERR(page)) {
259+
ret = PTR_ERR(page);
260+
goto err;
292261
}
293262
ubuf->pages[pgbuf++] = page;
294263
}
295264
fput(memfd);
296265
memfd = NULL;
297-
if (hpage) {
298-
put_page(hpage);
299-
hpage = NULL;
300-
}
301266
}
302267

303268
exp_info.ops = &udmabuf_ops;

0 commit comments

Comments
 (0)