Re: [PATCH v3 03/14] mm, hugetlb: protect region tracking via newly introduced resv_map lock
On Wed, 2013-12-18 at 15:53 +0900, Joonsoo Kim wrote: > There is a race condition if we map a same file on different processes. > Region tracking is protected by mmap_sem and hugetlb_instantiation_mutex. > When we do mmap, we don't grab a hugetlb_instantiation_mutex, but, > grab a mmap_sem. This doesn't prevent other process to modify region > structure, so it can be modified by two processes concurrently. > > To solve this, I introduce a lock to resv_map and make region manipulation > function grab a lock before they do actual work. This makes region > tracking safe. > > Signed-off-by: Joonsoo Kim Reviewed-by: Davidlohr Bueso -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [PATCH v3 03/14] mm, hugetlb: protect region tracking via newly introduced resv_map lock
On Tue, Dec 24, 2013 at 11:00:12PM +1100, David Gibson wrote: > On Mon, Dec 23, 2013 at 10:05:17AM +0900, Joonsoo Kim wrote: > > On Sun, Dec 22, 2013 at 12:58:19AM +1100, David Gibson wrote: > > > On Wed, Dec 18, 2013 at 03:53:49PM +0900, Joonsoo Kim wrote: > > > > There is a race condition if we map a same file on different processes. > > > > Region tracking is protected by mmap_sem and > > > > hugetlb_instantiation_mutex. > > > > When we do mmap, we don't grab a hugetlb_instantiation_mutex, but, > > > > grab a mmap_sem. This doesn't prevent other process to modify region > > > > structure, so it can be modified by two processes concurrently. > > > > > > > > To solve this, I introduce a lock to resv_map and make region > > > > manipulation > > > > function grab a lock before they do actual work. This makes region > > > > tracking safe. > > > > > > It's not clear to me if you're saying there is a list corruption race > > > bug in the existing code, or only that there will be if the > > > instantiation mutex goes away. > > > > Hello, > > > > The race exists in current code. > > Currently, region tracking is protected by either down_write(&mm->mmap_sem) > > or > > down_read(&mm->mmap_sem) + instantiation mutex. But if we map this hugetlbfs > > file to two different processes, holding a mmap_sem doesn't have any impact > > on > > the other process and concurrent access to data structure is possible. > > Ouch. In that case: > > Acked-by: David Gibson > > It would be really nice to add a testcase for this race to the > libhugetlbfs testsuite. Okay! I will add it. Thanks. -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [PATCH v3 03/14] mm, hugetlb: protect region tracking via newly introduced resv_map lock
On Mon, Dec 23, 2013 at 10:05:17AM +0900, Joonsoo Kim wrote: > On Sun, Dec 22, 2013 at 12:58:19AM +1100, David Gibson wrote: > > On Wed, Dec 18, 2013 at 03:53:49PM +0900, Joonsoo Kim wrote: > > > There is a race condition if we map a same file on different processes. > > > Region tracking is protected by mmap_sem and hugetlb_instantiation_mutex. > > > When we do mmap, we don't grab a hugetlb_instantiation_mutex, but, > > > grab a mmap_sem. This doesn't prevent other process to modify region > > > structure, so it can be modified by two processes concurrently. > > > > > > To solve this, I introduce a lock to resv_map and make region manipulation > > > function grab a lock before they do actual work. This makes region > > > tracking safe. > > > > It's not clear to me if you're saying there is a list corruption race > > bug in the existing code, or only that there will be if the > > instantiation mutex goes away. > > Hello, > > The race exists in current code. > Currently, region tracking is protected by either down_write(&mm->mmap_sem) or > down_read(&mm->mmap_sem) + instantiation mutex. But if we map this hugetlbfs > file to two different processes, holding a mmap_sem doesn't have any impact on > the other process and concurrent access to data structure is possible. Ouch. In that case: Acked-by: David Gibson It would be really nice to add a testcase for this race to the libhugetlbfs testsuite. -- David Gibson| I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson pgpmC88k4T2MR.pgp Description: PGP signature
Re: [PATCH v3 03/14] mm, hugetlb: protect region tracking via newly introduced resv_map lock
On Sun, Dec 22, 2013 at 12:58:19AM +1100, David Gibson wrote: > On Wed, Dec 18, 2013 at 03:53:49PM +0900, Joonsoo Kim wrote: > > There is a race condition if we map a same file on different processes. > > Region tracking is protected by mmap_sem and hugetlb_instantiation_mutex. > > When we do mmap, we don't grab a hugetlb_instantiation_mutex, but, > > grab a mmap_sem. This doesn't prevent other process to modify region > > structure, so it can be modified by two processes concurrently. > > > > To solve this, I introduce a lock to resv_map and make region manipulation > > function grab a lock before they do actual work. This makes region > > tracking safe. > > It's not clear to me if you're saying there is a list corruption race > bug in the existing code, or only that there will be if the > instantiation mutex goes away. Hello, The race exists in current code. Currently, region tracking is protected by either down_write(&mm->mmap_sem) or down_read(&mm->mmap_sem) + instantiation mutex. But if we map this hugetlbfs file to two different processes, holding a mmap_sem doesn't have any impact on the other process and concurrent access to data structure is possible. Thanks. -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [PATCH v3 03/14] mm, hugetlb: protect region tracking via newly introduced resv_map lock
On Wed, Dec 18, 2013 at 03:53:49PM +0900, Joonsoo Kim wrote: > There is a race condition if we map a same file on different processes. > Region tracking is protected by mmap_sem and hugetlb_instantiation_mutex. > When we do mmap, we don't grab a hugetlb_instantiation_mutex, but, > grab a mmap_sem. This doesn't prevent other process to modify region > structure, so it can be modified by two processes concurrently. > > To solve this, I introduce a lock to resv_map and make region manipulation > function grab a lock before they do actual work. This makes region > tracking safe. It's not clear to me if you're saying there is a list corruption race bug in the existing code, or only that there will be if the instantiation mutex goes away. -- David Gibson| I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson pgp7inwXYHbj_.pgp Description: PGP signature