From: Andrea Arcangeli Subject: [PATCH 03/10] mm: PT lock: export double_pt_lock/unlock Date: Wed, 2 Jul 2014 18:50:09 +0200 Message-ID: <1404319816-30229-4-git-send-email-aarcange@redhat.com> References: <1404319816-30229-1-git-send-email-aarcange@redhat.com> Cc: "\\\"Dr. David Alan Gilbert\\\"" , Johannes Weiner , Andrew Morton , Android Kernel Team , Robert Love , Mel Gorman , Hugh Dickins , Dave Hansen , Rik van Riel , Dmitry Adamushko , Neil Brown , Andrea Arcangeli , Mike Hommey , Taras Glek , Jan Kara , KOSAKI Motohiro , Michel Lespinasse , Minchan Kim , Keith Packard , "Huangpeng (Peter)" , Isaku Yamahata , To: qemu-devel@nongnu.org, kvm@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Return-path: In-Reply-To: <1404319816-30229-1-git-send-email-aarcange@redhat.com> Sender: owner-linux-mm@kvack.org List-Id: kvm.vger.kernel.org Those two helpers are needed by remap_anon_pages. Signed-off-by: Andrea Arcangeli --- include/linux/mm.h | 4 ++++ mm/fremap.c | 29 +++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/include/linux/mm.h b/include/linux/mm.h index 00faeda..0a7f0e1 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -1401,6 +1401,10 @@ static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long a } #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */ +/* mm/fremap.c */ +extern void double_pt_lock(spinlock_t *ptl1, spinlock_t *ptl2); +extern void double_pt_unlock(spinlock_t *ptl1, spinlock_t *ptl2); + #if USE_SPLIT_PTE_PTLOCKS #if ALLOC_SPLIT_PTLOCKS void __init ptlock_cache_init(void); diff --git a/mm/fremap.c b/mm/fremap.c index 72b8fa3..1e509f7 100644 --- a/mm/fremap.c +++ b/mm/fremap.c @@ -281,3 +281,32 @@ out_freed: return err; } + +void double_pt_lock(spinlock_t *ptl1, + spinlock_t *ptl2) + __acquires(ptl1) + __acquires(ptl2) +{ + spinlock_t *ptl_tmp; + + if (ptl1 > ptl2) { + /* exchange ptl1 and ptl2 */ + ptl_tmp = ptl1; + ptl1 = ptl2; + ptl2 = ptl_tmp; + } + /* lock in virtual address order to avoid lock inversion */ + spin_lock(ptl1); + if (ptl1 != ptl2) + spin_lock_nested(ptl2, SINGLE_DEPTH_NESTING); +} + +void double_pt_unlock(spinlock_t *ptl1, + spinlock_t *ptl2) + __releases(ptl1) + __releases(ptl2) +{ + spin_unlock(ptl1); + if (ptl1 != ptl2) + spin_unlock(ptl2); +} -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org