From patchwork Wed Mar 8 17:46:52 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ross Lagerwall X-Patchwork-Id: 9611743 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 40327602B4 for ; Wed, 8 Mar 2017 17:49:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2E5E428618 for ; Wed, 8 Mar 2017 17:49:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2345028624; Wed, 8 Mar 2017 17:49:39 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id A6FEB28618 for ; Wed, 8 Mar 2017 17:49:38 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1clfgM-0004Zd-9Q; Wed, 08 Mar 2017 17:47:26 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1clfgK-0004ZC-QZ for xen-devel@lists.xen.org; Wed, 08 Mar 2017 17:47:24 +0000 Received: from [85.158.139.211] by server-6.bemta-5.messagelabs.com id 1D/FC-16497-CA340C85; Wed, 08 Mar 2017 17:47:24 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmplkeJIrShJLcpLzFFi42JxWrrBXne184E Ig38rFS2WfFzM4sDocXT3b6YAxijWzLyk/IoE1ow92zuZCpqMKn7N6GBrYNyg2sXIySEh4C/R NvkqO4jNJmAgcevSd2YQW0RAXeJ0x0XWLkYuDmaBlYwShy7PYwJJCAs4SFy98IcFxGYRUJGY9 OEKWAOvgIfEyl+zWCGGykncPNcJFucU8JRY2DgdyObgEAKqaXlgDhIWElCTeLv8DAtEq6DEyZ lPwGxmAQmJgy9eME9g5J2FJDULSWoBI9MqRo3i1KKy1CJdQ0u9pKLM9IyS3MTMHF1DA1O93NT i4sT01JzEpGK95PzcTYzA4KlnYGDcwfio3+8QoyQHk5Ior9uyvRFCfEn5KZUZicUZ8UWlOanF hxhlODiUJHh3bAXKCRalpqdWpGXmAMMYJi3BwaMkwvtlC1Cat7ggMbc4Mx0idYpRUUqc1w+kT wAkkVGaB9cGi51LjLJSwryMDAwMQjwFqUW5mSWo8q8YxTkYlYR5S0Gm8GTmlcBNfwW0mAlosb Yr2OKSRISUVAOj+7z7Ym6vKxwbkj5fXrGzweOR9swvylf3Mp1R3HR/jfbVTUdKMgR87K49mbZ o/+etcQc0lB52Jdq5xuyotogX0dyedv5Ijce2OjN31w/vF5u+WRYwKYCBTWmjffnWX4zfjlR5 fvivwLRIL281y42G4A/8nStd7/lE7j/WYbmvyqn8x37j2SwTlFiKMxINtZiLihMB4Ath05gCA AA= X-Env-Sender: prvs=233b396aa=ross.lagerwall@citrix.com X-Msg-Ref: server-5.tower-206.messagelabs.com!1488995240!86865657!2 X-Originating-IP: [66.165.176.63] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni42MyA9PiAzMDYwNDg=\n, received_headers: No Received headers X-StarScan-Received: X-StarScan-Version: 9.2.3; banners=-,-,- X-VirusChecked: Checked Received: (qmail 57342 invoked from network); 8 Mar 2017 17:47:23 -0000 Received: from smtp02.citrix.com (HELO SMTP02.CITRIX.COM) (66.165.176.63) by server-5.tower-206.messagelabs.com with RC4-SHA encrypted SMTP; 8 Mar 2017 17:47:23 -0000 X-IronPort-AV: E=Sophos;i="5.36,265,1486425600"; d="scan'208";a="421279768" From: Ross Lagerwall To: Xen-devel Date: Wed, 8 Mar 2017 17:46:52 +0000 Message-ID: <1488995215-7647-4-git-send-email-ross.lagerwall@citrix.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1488995215-7647-1-git-send-email-ross.lagerwall@citrix.com> References: <1488995215-7647-1-git-send-email-ross.lagerwall@citrix.com> MIME-Version: 1.0 Cc: George Dunlap , Ross Lagerwall , Jan Beulich , Andrew Cooper Subject: [Xen-devel] [PATCH v2 3/6] mm: Use statically defined locking order X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP Instead of using a locking order based on line numbers which interacts poorly with trying to create a live patch, statically define the locking order. Signed-off-by: Ross Lagerwall Reviewed-by: Dario Faggioli Acked-by: George Dunlap --- Changes in v2: * Rearranged defines. * Make lock orders fit in a sign-extended 8-bit immediate. xen/arch/x86/mm/mm-locks.h | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/xen/arch/x86/mm/mm-locks.h b/xen/arch/x86/mm/mm-locks.h index 74fdfc1..e5fceb2 100644 --- a/xen/arch/x86/mm/mm-locks.h +++ b/xen/arch/x86/mm/mm-locks.h @@ -46,8 +46,10 @@ static inline int mm_locked_by_me(mm_lock_t *l) return (l->lock.recurse_cpu == current->processor); } -/* If you see this crash, the numbers printed are lines in this file - * where the offending locks are declared. */ +/* + * If you see this crash, the numbers printed are order levels defined + * in this file. + */ #define __check_lock_level(l) \ do { \ if ( unlikely(__get_lock_level() > (l)) ) \ @@ -152,12 +154,12 @@ static inline void mm_read_unlock(mm_rwlock_t *l) /* This wrapper uses the line number to express the locking order below */ #define declare_mm_lock(name) \ static inline void mm_lock_##name(mm_lock_t *l, const char *func, int rec)\ - { _mm_lock(l, func, __LINE__, rec); } + { _mm_lock(l, func, MM_LOCK_ORDER_##name, rec); } #define declare_mm_rwlock(name) \ static inline void mm_write_lock_##name(mm_rwlock_t *l, const char *func) \ - { _mm_write_lock(l, func, __LINE__); } \ + { _mm_write_lock(l, func, MM_LOCK_ORDER_##name); } \ static inline void mm_read_lock_##name(mm_rwlock_t *l) \ - { _mm_read_lock(l, __LINE__); } + { _mm_read_lock(l, MM_LOCK_ORDER_##name); } /* These capture the name of the calling function */ #define mm_lock(name, l) mm_lock_##name(l, __func__, 0) #define mm_lock_recursive(name, l) mm_lock_##name(l, __func__, 1) @@ -169,10 +171,10 @@ static inline void mm_read_unlock(mm_rwlock_t *l) * to ordering constraints. */ #define declare_mm_order_constraint(name) \ static inline void mm_enforce_order_lock_pre_##name(void) \ - { _mm_enforce_order_lock_pre(__LINE__); } \ + { _mm_enforce_order_lock_pre(MM_LOCK_ORDER_##name); } \ static inline void mm_enforce_order_lock_post_##name( \ int *unlock_level, unsigned short *recurse_count) \ - { _mm_enforce_order_lock_post(__LINE__, unlock_level, recurse_count); } \ + { _mm_enforce_order_lock_post(MM_LOCK_ORDER_##name, unlock_level, recurse_count); } \ static inline void mm_unlock(mm_lock_t *l) { @@ -201,8 +203,8 @@ static inline void mm_enforce_order_unlock(int unlock_level, /************************************************************************ * * - * To avoid deadlocks, these locks _MUST_ be taken in the order they're * - * declared in this file. The locking functions will enforce this. * + * To avoid deadlocks, these locks _MUST_ be taken in the order listed * + * below. The locking functions will enforce this. * * * ************************************************************************/ @@ -214,6 +216,7 @@ static inline void mm_enforce_order_unlock(int unlock_level, * - setting the "cr3" field of any p2m table to a non-P2M_BASE_EAADR value. * (i.e. assigning a p2m table to be the shadow of that cr3 */ +#define MM_LOCK_ORDER_nestedp2m 8 declare_mm_lock(nestedp2m) #define nestedp2m_lock(d) mm_lock(nestedp2m, &(d)->arch.nested_p2m_lock) #define nestedp2m_unlock(d) mm_unlock(&(d)->arch.nested_p2m_lock) @@ -240,6 +243,7 @@ declare_mm_lock(nestedp2m) * the altp2mlist lock in the middle. */ +#define MM_LOCK_ORDER_p2m 16 declare_mm_rwlock(p2m); /* Sharing per page lock @@ -251,6 +255,7 @@ declare_mm_rwlock(p2m); * * The lock is recursive because during share we lock two pages. */ +#define MM_LOCK_ORDER_per_page_sharing 24 declare_mm_order_constraint(per_page_sharing) #define page_sharing_mm_pre_lock() mm_enforce_order_lock_pre_per_page_sharing() #define page_sharing_mm_post_lock(l, r) \ @@ -265,6 +270,7 @@ declare_mm_order_constraint(per_page_sharing) * in the target domain must be paused. */ +#define MM_LOCK_ORDER_altp2mlist 32 declare_mm_lock(altp2mlist) #define altp2m_list_lock(d) mm_lock(altp2mlist, &(d)->arch.altp2m_list_lock) #define altp2m_list_unlock(d) mm_unlock(&(d)->arch.altp2m_list_lock) @@ -279,6 +285,7 @@ declare_mm_lock(altp2mlist) * up a gfn and later mutate it. */ +#define MM_LOCK_ORDER_altp2m 40 declare_mm_rwlock(altp2m); #define p2m_lock(p) \ do { \ @@ -307,6 +314,7 @@ declare_mm_rwlock(altp2m); * Protects private PoD data structs: entry and cache * counts, page lists, sweep parameters. */ +#define MM_LOCK_ORDER_pod 48 declare_mm_lock(pod) #define pod_lock(p) mm_lock(pod, &(p)->pod.lock) #define pod_unlock(p) mm_unlock(&(p)->pod.lock) @@ -319,6 +327,7 @@ declare_mm_lock(pod) * the ordering which we enforce here. * The lock is not recursive. */ +#define MM_LOCK_ORDER_page_alloc 56 declare_mm_order_constraint(page_alloc) #define page_alloc_mm_pre_lock() mm_enforce_order_lock_pre_page_alloc() #define page_alloc_mm_post_lock(l) mm_enforce_order_lock_post_page_alloc(&(l), NULL) @@ -339,6 +348,7 @@ declare_mm_order_constraint(page_alloc) * It also protects the log-dirty bitmap from concurrent accesses (and * teardowns, etc). */ +#define MM_LOCK_ORDER_paging 64 declare_mm_lock(paging) #define paging_lock(d) mm_lock(paging, &(d)->arch.paging.lock) #define paging_lock_recursive(d) \