diff options
author | Sam Nelson <sam.nelson@ti.com> | 2018-01-26 12:28:45 -0500 |
---|---|---|
committer | Sam Nelson <sam.nelson@ti.com> | 2018-01-26 12:28:45 -0500 |
commit | d0be7e99ea7b12baf1b0d796f6fa12e5f0a4d712 (patch) | |
tree | 8612d63c8f194fe49f9182d39923af048f671d6f | |
parent | d594423cb39a99426ba4bd8f6dc5e775365a0821 (diff) | |
download | linuxutils-d0be7e99ea7b12baf1b0d796f6fa12e5f0a4d712.tar.gz |
cmemk: Need protection for find_vma for multithread use
There is a race condition when mmap is happening simultaneously in a
different thread and find_vma returns invalid value.
Adding protection here to avoid race condition
Signed-off-by: Sam Nelson <sam.nelson@ti.com>
-rw-r--r-- | src/cmem/module/cmemk.c | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/src/cmem/module/cmemk.c b/src/cmem/module/cmemk.c index 598e8d9..681ffc0 100644 --- a/src/cmem/module/cmemk.c +++ b/src/cmem/module/cmemk.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2007-2014 Texas Instruments Incorporated - http://www.ti.com + * Copyright (C) 2007-2018 Texas Instruments Incorporated - http://www.ti.com * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -633,9 +633,11 @@ static phys_addr_t get_phys(void *virtp) __D("get_phys: virt_to_phys translated direct-mapped %#lx to %#llx\n", virt, (unsigned long long)physp); } - + down_read(¤t->mm->mmap_sem); + vma = find_vma(mm, virt); + up_read(¤t->mm->mmap_sem); /* this will catch, kernel-allocated, mmaped-to-usermode addresses */ - else if ((vma = find_vma(mm, virt)) && + if (vma && (vma->vm_flags & VM_IO) && (vma->vm_pgoff)) { physp = ((unsigned long long)vma->vm_pgoff << PAGE_SHIFT) + |