
hulk inclusion category: feature bugzilla: https://gitee.com/openeuler/kernel/issues/I9UDJX -------------------------------- Since vma remap or split is not supported by l0, disable these two function for l0. Add memory limit for l0_mmap to prevent users from mistakenly requesting too much memory, leading to OOM. Signed-off-by: Wupeng Ma <mawupeng1@huawei.com> --- drivers/soc/hisilicon/hisi_l0.c | 35 +++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/drivers/soc/hisilicon/hisi_l0.c b/drivers/soc/hisilicon/hisi_l0.c index cc1ba59e246e..f11a9c7ac768 100644 --- a/drivers/soc/hisilicon/hisi_l0.c +++ b/drivers/soc/hisilicon/hisi_l0.c @@ -18,6 +18,9 @@ #include "hisi_l3t.h" +/* max size for l0 mmap */ +#define HISI_L0_MAX_SIZE (256UL << 20) + struct l0_vma_data { struct page *page; unsigned long size; @@ -99,9 +102,38 @@ static void l0_vma_close(struct vm_area_struct *vma) kfree(data); } +static int l0_mremap(struct vm_area_struct *vma) +{ + pr_err("mremap for l0 is not supported\n"); + + return -EINVAL; +} + +static void l0_open(struct vm_area_struct *vma) +{ + struct l0_vma_data *data; + + data = (struct l0_vma_data *)vma->vm_private_data; + if (!data) { + pr_err("%s: pid: %d, invalid private data\n", current->comm, + current->pid); + return; + } +} + +static int l0_may_split(struct vm_area_struct *vma, unsigned long addr) +{ + pr_err("L0 may not be split\n"); + + return -EINVAL; +} + static const struct vm_operations_struct l0_vm_ops = { + .open = l0_open, .huge_fault = l0_huge_fault, .close = l0_vma_close, + .split = l0_may_split, + .mremap = l0_mremap, }; static int l0_mmap(struct file *filp, struct vm_area_struct *vma) @@ -118,6 +150,9 @@ static int l0_mmap(struct file *filp, struct vm_area_struct *vma) if ((vma->vm_start % PMD_SIZE) || (vma->vm_end % PMD_SIZE)) return -EINVAL; + if (cont_size >= HISI_L0_MAX_SIZE) + return -EINVAL; + data = kzalloc(sizeof(struct l0_vma_data), GFP_KERNEL); if (!data) return -ENOMEM; -- 2.43.0