€•íŒsphinx.addnodes”Œdocument”“”)�”}”(Œ rawsource”Œ”Œchildren”]”(Œ translations”Œ LanguagesNode”“”)�”}”(hhh]”(hŒ pending_xref”“”)�”}”(hhh]”Œdocutils.nodes”ŒText”“”ŒChinese (Simplified)”…”�”}”Œparent”hsbaŒ attributes”}”(Œids”]”Œclasses”]”Œnames”]”Œdupnames”]”Œbackrefs”]”Œ refdomain”Œstd”Œreftype”Œdoc”Œ reftarget”Œ*/translations/zh_CN/locking/lockdep-design”Œmodname”NŒ classname”NŒ refexplicit”ˆuŒtagname”hhh ubh)�”}”(hhh]”hŒChinese (Traditional)”…”�”}”hh2sbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ*/translations/zh_TW/locking/lockdep-design”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubh)�”}”(hhh]”hŒItalian”…”�”}”hhFsbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ*/translations/it_IT/locking/lockdep-design”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubh)�”}”(hhh]”hŒJapanese”…”�”}”hhZsbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ*/translations/ja_JP/locking/lockdep-design”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubh)�”}”(hhh]”hŒKorean”…”�”}”hhnsbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ*/translations/ko_KR/locking/lockdep-design”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubh)�”}”(hhh]”hŒPortuguese (Brazilian)”…”�”}”hh‚sbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ*/translations/pt_BR/locking/lockdep-design”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubh)�”}”(hhh]”hŒSpanish”…”�”}”hh–sbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ*/translations/sp_SP/locking/lockdep-design”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubeh}”(h]”h ]”h"]”h$]”h&]”Œcurrent_language”ŒEnglish”uh1h hhŒ _document”hŒsource”NŒline”NubhŒsection”“”)�”}”(hhh]”(hŒtitle”“”)�”}”(hŒ%Runtime locking correctness validator”h]”hŒ%Runtime locking correctness validator”…”�”}”(hh¼h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhh·h²hh³ŒD/var/lib/git/docbuild/linux/Documentation/locking/lockdep-design.rst”h´KubhŒ paragraph”“”)�”}”(hŒ)started by Ingo Molnar ”h]”(hŒstarted by Ingo Molnar <”…”�”}”(hhÍh²hh³Nh´NubhŒ reference”“”)�”}”(hŒmingo@redhat.com”h]”hŒmingo@redhat.com”…”�”}”(hh×h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”Œrefuri”Œmailto:mingo@redhat.com”uh1hÕhhÍubhŒ>”…”�”}”(hhÍh²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´Khh·h²hubhÌ)�”}”(hŒ5additions by Arjan van de Ven ”h]”(hŒadditions by Arjan van de Ven <”…”�”}”(hhñh²hh³Nh´NubhÖ)�”}”(hŒarjan@linux.intel.com”h]”hŒarjan@linux.intel.com”…”�”}”(hhùh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”Œrefuri”Œmailto:arjan@linux.intel.com”uh1hÕhhñubhŒ>”…”�”}”(hhñh²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´Khh·h²hubh¶)�”}”(hhh]”(h»)�”}”(hŒ Lock-class”h]”hŒ Lock-class”…”�”}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhjh²hh³hÊh´K ubhÌ)�”}”(hŒCThe basic object the validator operates upon is a 'class' of locks.”h]”hŒGThe basic object the validator operates upon is a ‘class’ of locks.”…”�”}”(hj$h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´K hjh²hubhÌ)�”}”(hX'A class of locks is a group of locks that are logically the same with respect to locking rules, even if the locks may have multiple (possibly tens of thousands of) instantiations. For example a lock in the inode struct is one class, while each inode has its own instantiation of that lock class.”h]”hX'A class of locks is a group of locks that are logically the same with respect to locking rules, even if the locks may have multiple (possibly tens of thousands of) instantiations. For example a lock in the inode struct is one class, while each inode has its own instantiation of that lock class.”…”�”}”(hj2h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´K hjh²hubhÌ)�”}”(hX_The validator tracks the 'usage state' of lock-classes, and it tracks the dependencies between different lock-classes. Lock usage indicates how a lock is used with regard to its IRQ contexts, while lock dependency can be understood as lock order, where L1 -> L2 suggests that a task is attempting to acquire L2 while holding L1. From lockdep's perspective, the two locks (L1 and L2) are not necessarily related; that dependency just means the order ever happened. The validator maintains a continuing effort to prove lock usages and dependencies are correct or the validator will shoot a splat if incorrect.”h]”hXeThe validator tracks the ‘usage state’ of lock-classes, and it tracks the dependencies between different lock-classes. Lock usage indicates how a lock is used with regard to its IRQ contexts, while lock dependency can be understood as lock order, where L1 -> L2 suggests that a task is attempting to acquire L2 while holding L1. From lockdep’s perspective, the two locks (L1 and L2) are not necessarily related; that dependency just means the order ever happened. The validator maintains a continuing effort to prove lock usages and dependencies are correct or the validator will shoot a splat if incorrect.”…”�”}”(hj@h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´Khjh²hubhÌ)�”}”(hXA lock-class's behavior is constructed by its instances collectively: when the first instance of a lock-class is used after bootup the class gets registered, then all (subsequent) instances will be mapped to the class and hence their usages and dependencies will contribute to those of the class. A lock-class does not go away when a lock instance does, but it can be removed if the memory space of the lock class (static or dynamic) is reclaimed, this happens for example when a module is unloaded or a workqueue is destroyed.”h]”hXA lock-class’s behavior is constructed by its instances collectively: when the first instance of a lock-class is used after bootup the class gets registered, then all (subsequent) instances will be mapped to the class and hence their usages and dependencies will contribute to those of the class. A lock-class does not go away when a lock instance does, but it can be removed if the memory space of the lock class (static or dynamic) is reclaimed, this happens for example when a module is unloaded or a workqueue is destroyed.”…”�”}”(hjNh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´Khjh²hubeh}”(h]”Œ lock-class”ah ]”h"]”Œ lock-class”ah$]”h&]”uh1hµhh·h²hh³hÊh´K ubh¶)�”}”(hhh]”(h»)�”}”(hŒState”h]”hŒState”…”�”}”(hjgh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhjdh²hh³hÊh´K'ubhÌ)�”}”(hŒnThe validator tracks lock-class usage history and divides the usage into (4 usages * n STATEs + 1) categories:”h]”hŒnThe validator tracks lock-class usage history and divides the usage into (4 usages * n STATEs + 1) categories:”…”�”}”(hjuh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´K)hjdh²hubhÌ)�”}”(hŒwhere the 4 usages can be:”h]”hŒwhere the 4 usages can be:”…”�”}”(hjƒh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´K,hjdh²hubhŒ bullet_list”“”)�”}”(hhh]”(hŒ list_item”“”)�”}”(hŒ'ever held in STATE context'”h]”hÌ)�”}”(hjšh]”hŒ ‘ever held in STATE context’”…”�”}”(hjœh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´K.hj˜ubah}”(h]”h ]”h"]”h$]”h&]”uh1j–hj“h²hh³hÊh´Nubj—)�”}”(hŒ('ever held as readlock in STATE context'”h]”hÌ)�”}”(hj±h]”hŒ,‘ever held as readlock in STATE context’”…”�”}”(hj³h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´K/hj¯ubah}”(h]”h ]”h"]”h$]”h&]”uh1j–hj“h²hh³hÊh´Nubj—)�”}”(hŒ'ever held with STATE enabled'”h]”hÌ)�”}”(hjÈh]”hŒ"‘ever held with STATE enabled’”…”�”}”(hjÊh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´K0hjÆubah}”(h]”h ]”h"]”h$]”h&]”uh1j–hj“h²hh³hÊh´Nubj—)�”}”(hŒ+'ever held as readlock with STATE enabled' ”h]”hÌ)�”}”(hŒ*'ever held as readlock with STATE enabled'”h]”hŒ.‘ever held as readlock with STATE enabled’”…”�”}”(hjáh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´K1hjÝubah}”(h]”h ]”h"]”h$]”h&]”uh1j–hj“h²hh³hÊh´Nubeh}”(h]”h ]”h"]”h$]”h&]”Œbullet”Œ-”uh1j‘h³hÊh´K.hjdh²hubhÌ)�”}”(hŒ[where the n STATEs are coded in kernel/locking/lockdep_states.h and as of now they include:”h]”hŒ[where the n STATEs are coded in kernel/locking/lockdep_states.h and as of now they include:”…”�”}”(hjýh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´K3hjdh²hubj’)�”}”(hhh]”(j—)�”}”(hŒhardirq”h]”hÌ)�”}”(hjh]”hŒhardirq”…”�”}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´K6hjubah}”(h]”h ]”h"]”h$]”h&]”uh1j–hj h²hh³hÊh´Nubj—)�”}”(hŒsoftirq ”h]”hÌ)�”}”(hŒsoftirq”h]”hŒsoftirq”…”�”}”(hj)h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´K7hj%ubah}”(h]”h ]”h"]”h$]”h&]”uh1j–hj h²hh³hÊh´Nubeh}”(h]”h ]”h"]”h$]”h&]”jûjüuh1j‘h³hÊh´K6hjdh²hubhÌ)�”}”(hŒwhere the last 1 category is:”h]”hŒwhere the last 1 category is:”…”�”}”(hjCh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´K9hjdh²hubj’)�”}”(hhh]”j—)�”}”(hŒH'ever used' [ == !unused ] ”h]”hÌ)�”}”(hŒG'ever used' [ == !unused ]”h]”hŒK‘ever used’ [ == !unused ]”…”�”}”(hjXh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´K;hjTubah}”(h]”h ]”h"]”h$]”h&]”uh1j–hjQh²hh³hÊh´Nubah}”(h]”h ]”h"]”h$]”h&]”jûjüuh1j‘h³hÊh´K;hjdh²hubhÌ)�”}”(hŒ§When locking rules are violated, these usage bits are presented in the locking error messages, inside curlies, with a total of 2 * n STATEs bits. A contrived example::”h]”hŒ¦When locking rules are violated, these usage bits are presented in the locking error messages, inside curlies, with a total of 2 * n STATEs bits. A contrived example:”…”�”}”(hjrh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´K=hjdh²hubhŒ literal_block”“”)�”}”(hŒÑmodprobe/2287 is trying to acquire lock: (&sio_locks[i].lock){-.-.}, at: [] mutex_lock+0x21/0x24 but task is already holding lock: (&sio_locks[i].lock){-.-.}, at: [] mutex_lock+0x21/0x24”h]”hŒÑmodprobe/2287 is trying to acquire lock: (&sio_locks[i].lock){-.-.}, at: [] mutex_lock+0x21/0x24 but task is already holding lock: (&sio_locks[i].lock){-.-.}, at: [] mutex_lock+0x21/0x24”…”�”}”hj‚sbah}”(h]”h ]”h"]”h$]”h&]”Œ xml:space”Œpreserve”uh1j€h³hÊh´KAhjdh²hubhÌ)�”}”(hŒßFor a given lock, the bit positions from left to right indicate the usage of the lock and readlock (if exists), for each of the n STATEs listed above respectively, and the character displayed at each bit position indicates:”h]”hŒßFor a given lock, the bit positions from left to right indicate the usage of the lock and readlock (if exists), for each of the n STATEs listed above respectively, and the character displayed at each bit position indicates:”…”�”}”(hj’h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´KHhjdh²hubhŒ block_quote”“”)�”}”(hX=== =================================================== '.' acquired while irqs disabled and not in irq context '-' acquired in irq context '+' acquired with irqs enabled '?' acquired in irq context with irqs enabled. === =================================================== ”h]”hŒtable”“”)�”}”(hhh]”hŒtgroup”“”)�”}”(hhh]”(hŒcolspec”“”)�”}”(hhh]”h}”(h]”h ]”h"]”h$]”h&]”Œcolwidth”Kuh1j°hj­ubj±)�”}”(hhh]”h}”(h]”h ]”h"]”h$]”h&]”Œcolwidth”K3uh1j°hj­ubhŒtbody”“”)�”}”(hhh]”(hŒrow”“”)�”}”(hhh]”(hŒentry”“”)�”}”(hhh]”hÌ)�”}”(hŒ'.'”h]”hŒ‘.’”…”�”}”(hjÕh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´KNhjÒubah}”(h]”h ]”h"]”h$]”h&]”uh1jÐhjÍubjÑ)�”}”(hhh]”hÌ)�”}”(hŒ3acquired while irqs disabled and not in irq context”h]”hŒ3acquired while irqs disabled and not in irq context”…”�”}”(hjìh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´KNhjéubah}”(h]”h ]”h"]”h$]”h&]”uh1jÐhjÍubeh}”(h]”h ]”h"]”h$]”h&]”uh1jËhjÈubjÌ)�”}”(hhh]”(jÑ)�”}”(hhh]”hÌ)�”}”(hŒ'-'”h]”hŒ‘-’”…”�”}”(hj h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´KOhj ubah}”(h]”h ]”h"]”h$]”h&]”uh1jÐhjubjÑ)�”}”(hhh]”hÌ)�”}”(hŒacquired in irq context”h]”hŒacquired in irq context”…”�”}”(hj#h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´KOhj ubah}”(h]”h ]”h"]”h$]”h&]”uh1jÐhjubeh}”(h]”h ]”h"]”h$]”h&]”uh1jËhjÈubjÌ)�”}”(hhh]”(jÑ)�”}”(hhh]”hÌ)�”}”(hŒ'+'”h]”hŒ‘+’”…”�”}”(hjCh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´KPhj@ubah}”(h]”h ]”h"]”h$]”h&]”uh1jÐhj=ubjÑ)�”}”(hhh]”hÌ)�”}”(hŒacquired with irqs enabled”h]”hŒacquired with irqs enabled”…”�”}”(hjZh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´KPhjWubah}”(h]”h ]”h"]”h$]”h&]”uh1jÐhj=ubeh}”(h]”h ]”h"]”h$]”h&]”uh1jËhjÈubjÌ)�”}”(hhh]”(jÑ)�”}”(hhh]”hÌ)�”}”(hŒ'?'”h]”hŒ‘?’”…”�”}”(hjzh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´KQhjwubah}”(h]”h ]”h"]”h$]”h&]”uh1jÐhjtubjÑ)�”}”(hhh]”hÌ)�”}”(hŒ*acquired in irq context with irqs enabled.”h]”hŒ*acquired in irq context with irqs enabled.”…”�”}”(hj‘h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´KQhjŽubah}”(h]”h ]”h"]”h$]”h&]”uh1jÐhjtubeh}”(h]”h ]”h"]”h$]”h&]”uh1jËhjÈubeh}”(h]”h ]”h"]”h$]”h&]”uh1jÆhj­ubeh}”(h]”h ]”h"]”h$]”h&]”Œcols”Kuh1j«hj¨ubah}”(h]”h ]”h"]”h$]”h&]”uh1j¦hj¢ubah}”(h]”h ]”h"]”h$]”h&]”uh1j h³hÊh´KMhjdh²hubhÌ)�”}”(hŒ*The bits are illustrated with an example::”h]”hŒ)The bits are illustrated with an example:”…”�”}”(hjÄh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´KThjdh²hubj�)�”}”(hX_(&sio_locks[i].lock){-.-.}, at: [] mutex_lock+0x21/0x24 |||| ||| \-> softirq disabled and not in softirq context || \--> acquired in softirq context | \---> hardirq disabled and not in hardirq context \----> acquired in hardirq context”h]”hX_(&sio_locks[i].lock){-.-.}, at: [] mutex_lock+0x21/0x24 |||| ||| \-> softirq disabled and not in softirq context || \--> acquired in softirq context | \---> hardirq disabled and not in hardirq context \----> acquired in hardirq context”…”�”}”hjÒsbah}”(h]”h ]”h"]”h$]”h&]”j�j‘uh1j€h³hÊh´KVhjdh²hubhÌ)�”}”(hXFor a given STATE, whether the lock is ever acquired in that STATE context and whether that STATE is enabled yields four possible cases as shown in the table below. The bit character is able to indicate which exact case is for the lock as of the reporting time.”h]”hXFor a given STATE, whether the lock is ever acquired in that STATE context and whether that STATE is enabled yields four possible cases as shown in the table below. The bit character is able to indicate which exact case is for the lock as of the reporting time.”…”�”}”(hjàh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´K^hjdh²hubj¡)�”}”(hXB+--------------+-------------+--------------+ | | irq enabled | irq disabled | +--------------+-------------+--------------+ | ever in irq | '?' | '-' | +--------------+-------------+--------------+ | never in irq | '+' | '.' | +--------------+-------------+--------------+ ”h]”j§)�”}”(hhh]”j¬)�”}”(hhh]”(j±)�”}”(hhh]”h}”(h]”h ]”h"]”h$]”h&]”Œcolwidth”Kuh1j°hjõubj±)�”}”(hhh]”h}”(h]”h ]”h"]”h$]”h&]”Œcolwidth”K uh1j°hjõubj±)�”}”(hhh]”h}”(h]”h ]”h"]”h$]”h&]”Œcolwidth”Kuh1j°hjõubjÇ)�”}”(hhh]”(jÌ)�”}”(hhh]”(jÑ)�”}”(hhh]”h}”(h]”h ]”h"]”h$]”h&]”uh1jÐhjubjÑ)�”}”(hhh]”hÌ)�”}”(hŒ irq enabled”h]”hŒ irq enabled”…”�”}”(hj(h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´Kdhj%ubah}”(h]”h ]”h"]”h$]”h&]”uh1jÐhjubjÑ)�”}”(hhh]”hÌ)�”}”(hŒ irq disabled”h]”hŒ irq disabled”…”�”}”(hj?h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´Kdhj<ubah}”(h]”h ]”h"]”h$]”h&]”uh1jÐhjubeh}”(h]”h ]”h"]”h$]”h&]”uh1jËhjubjÌ)�”}”(hhh]”(jÑ)�”}”(hhh]”hÌ)�”}”(hŒ ever in irq”h]”hŒ ever in irq”…”�”}”(hj_h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´Kfhj\ubah}”(h]”h ]”h"]”h$]”h&]”uh1jÐhjYubjÑ)�”}”(hhh]”hÌ)�”}”(hŒ'?'”h]”hŒ‘?’”…”�”}”(hjvh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´Kfhjsubah}”(h]”h ]”h"]”h$]”h&]”uh1jÐhjYubjÑ)�”}”(hhh]”hÌ)�”}”(hŒ'-'”h]”hŒ‘-’”…”�”}”(hj�h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´KfhjŠubah}”(h]”h ]”h"]”h$]”h&]”uh1jÐhjYubeh}”(h]”h ]”h"]”h$]”h&]”uh1jËhjubjÌ)�”}”(hhh]”(jÑ)�”}”(hhh]”hÌ)�”}”(hŒ never in irq”h]”hŒ never in irq”…”�”}”(hj­h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´Khhjªubah}”(h]”h ]”h"]”h$]”h&]”uh1jÐhj§ubjÑ)�”}”(hhh]”hÌ)�”}”(hŒ'+'”h]”hŒ‘+’”…”�”}”(hjÄh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´KhhjÁubah}”(h]”h ]”h"]”h$]”h&]”uh1jÐhj§ubjÑ)�”}”(hhh]”hÌ)�”}”(hŒ'.'”h]”hŒ‘.’”…”�”}”(hjÛh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´KhhjØubah}”(h]”h ]”h"]”h$]”h&]”uh1jÐhj§ubeh}”(h]”h ]”h"]”h$]”h&]”uh1jËhjubeh}”(h]”h ]”h"]”h$]”h&]”uh1jÆhjõubeh}”(h]”h ]”h"]”h$]”h&]”Œcols”Kuh1j«hjòubah}”(h]”h ]”h"]”h$]”h&]”uh1j¦hjîubah}”(h]”h ]”h"]”h$]”h&]”uh1j h³hÊh´Kchjdh²hubhÌ)�”}”(hŒžThe character '-' suggests irq is disabled because if otherwise the character '?' would have been shown instead. Similar deduction can be applied for '+' too.”h]”hŒªThe character ‘-’ suggests irq is disabled because if otherwise the character ‘?’ would have been shown instead. Similar deduction can be applied for ‘+’ too.”…”�”}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´Kkhjdh²hubhÌ)�”}”(hŒEUnused locks (e.g., mutexes) cannot be part of the cause of an error.”h]”hŒEUnused locks (e.g., mutexes) cannot be part of the cause of an error.”…”�”}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´Kohjdh²hubeh}”(h]”Œstate”ah ]”h"]”Œstate”ah$]”h&]”uh1hµhh·h²hh³hÊh´K'ubh¶)�”}”(hhh]”(h»)�”}”(hŒSingle-lock state rules:”h]”hŒSingle-lock state rules:”…”�”}”(hj5h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhj2h²hh³hÊh´KsubhÌ)�”}”(hŒ„A lock is irq-safe means it was ever used in an irq context, while a lock is irq-unsafe means it was ever acquired with irq enabled.”h]”hŒ„A lock is irq-safe means it was ever used in an irq context, while a lock is irq-unsafe means it was ever acquired with irq enabled.”…”�”}”(hjCh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´Kuhj2h²hubhÌ)�”}”(hŒºA softirq-unsafe lock-class is automatically hardirq-unsafe as well. The following states must be exclusive: only one of them is allowed to be set for any lock-class based on its usage::”h]”hŒ¹A softirq-unsafe lock-class is automatically hardirq-unsafe as well. The following states must be exclusive: only one of them is allowed to be set for any lock-class based on its usage:”…”�”}”(hjQh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´Kxhj2h²hubj�)�”}”(hŒE or or ”h]”hŒE or or ”…”�”}”hj_sbah}”(h]”h ]”h"]”h$]”h&]”j�j‘uh1j€h³hÊh´K|hj2h²hubhÌ)�”}”(hX‚This is because if a lock can be used in irq context (irq-safe) then it cannot be ever acquired with irq enabled (irq-unsafe). Otherwise, a deadlock may happen. For example, in the scenario that after this lock was acquired but before released, if the context is interrupted this lock will be attempted to acquire twice, which creates a deadlock, referred to as lock recursion deadlock.”h]”hX‚This is because if a lock can be used in irq context (irq-safe) then it cannot be ever acquired with irq enabled (irq-unsafe). Otherwise, a deadlock may happen. For example, in the scenario that after this lock was acquired but before released, if the context is interrupted this lock will be attempted to acquire twice, which creates a deadlock, referred to as lock recursion deadlock.”…”�”}”(hjmh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´Khj2h²hubhÌ)�”}”(hŒYThe validator detects and reports lock usage that violates these single-lock state rules.”h]”hŒYThe validator detects and reports lock usage that violates these single-lock state rules.”…”�”}”(hj{h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´K†hj2h²hubeh}”(h]”Œsingle-lock-state-rules”ah ]”h"]”Œsingle-lock state rules:”ah$]”h&]”uh1hµhh·h²hh³hÊh´Ksubh¶)�”}”(hhh]”(h»)�”}”(hŒMulti-lock dependency rules:”h]”hŒMulti-lock dependency rules:”…”�”}”(hj”h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhj‘h²hh³hÊh´KŠubhÌ)�”}”(hŒdThe same lock-class must not be acquired twice, because this could lead to lock recursion deadlocks.”h]”hŒdThe same lock-class must not be acquired twice, because this could lead to lock recursion deadlocks.”…”�”}”(hj¢h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´KŒhj‘h²hubhÌ)�”}”(hŒ:Furthermore, two locks can not be taken in inverse order::”h]”hŒ9Furthermore, two locks can not be taken in inverse order:”…”�”}”(hj°h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´K�hj‘h²hubj�)�”}”(hŒ -> -> ”h]”hŒ -> -> ”…”�”}”hj¾sbah}”(h]”h ]”h"]”h$]”h&]”j�j‘uh1j€h³hÊh´K‘hj‘h²hubhÌ)�”}”(hXÀbecause this could lead to a deadlock - referred to as lock inversion deadlock - as attempts to acquire the two locks form a circle which could lead to the two contexts waiting for each other permanently. The validator will find such dependency circle in arbitrary complexity, i.e., there can be any other locking sequence between the acquire-lock operations; the validator will still find whether these locks can be acquired in a circular fashion.”h]”hXÀbecause this could lead to a deadlock - referred to as lock inversion deadlock - as attempts to acquire the two locks form a circle which could lead to the two contexts waiting for each other permanently. The validator will find such dependency circle in arbitrary complexity, i.e., there can be any other locking sequence between the acquire-lock operations; the validator will still find whether these locks can be acquired in a circular fashion.”…”�”}”(hjÌh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´K”hj‘h²hubhÌ)�”}”(hŒgFurthermore, the following usage based lock dependencies are not allowed between any two lock-classes::”h]”hŒfFurthermore, the following usage based lock dependencies are not allowed between any two lock-classes:”…”�”}”(hjÚh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´Kœhj‘h²hubj�)�”}”(hŒK -> -> ”h]”hŒK -> -> ”…”�”}”hjèsbah}”(h]”h ]”h"]”h$]”h&]”j�j‘uh1j€h³hÊh´KŸhj‘h²hubhÌ)�”}”(hX!The first rule comes from the fact that a hardirq-safe lock could be taken by a hardirq context, interrupting a hardirq-unsafe lock - and thus could result in a lock inversion deadlock. Likewise, a softirq-safe lock could be taken by an softirq context, interrupting a softirq-unsafe lock.”h]”hX!The first rule comes from the fact that a hardirq-safe lock could be taken by a hardirq context, interrupting a hardirq-unsafe lock - and thus could result in a lock inversion deadlock. Likewise, a softirq-safe lock could be taken by an softirq context, interrupting a softirq-unsafe lock.”…”�”}”(hjöh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´K¢hj‘h²hubhÌ)�”}”(hŒÔThe above rules are enforced for any locking sequence that occurs in the kernel: when acquiring a new lock, the validator checks whether there is any rule violation between the new lock and any of the held locks.”h]”hŒÔThe above rules are enforced for any locking sequence that occurs in the kernel: when acquiring a new lock, the validator checks whether there is any rule violation between the new lock and any of the held locks.”…”�”}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´K¨hj‘h²hubhÌ)�”}”(hŒfWhen a lock-class changes its state, the following aspects of the above dependency rules are enforced:”h]”hŒfWhen a lock-class changes its state, the following aspects of the above dependency rules are enforced:”…”�”}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´K¬hj‘h²hubj’)�”}”(hhh]”(j—)�”}”(hŒhif a new hardirq-safe lock is discovered, we check whether it took any hardirq-unsafe lock in the past. ”h]”hÌ)�”}”(hŒgif a new hardirq-safe lock is discovered, we check whether it took any hardirq-unsafe lock in the past.”h]”hŒgif a new hardirq-safe lock is discovered, we check whether it took any hardirq-unsafe lock in the past.”…”�”}”(hj'h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´K¯hj#ubah}”(h]”h ]”h"]”h$]”h&]”uh1j–hj h²hh³hÊh´Nubj—)�”}”(hŒhif a new softirq-safe lock is discovered, we check whether it took any softirq-unsafe lock in the past. ”h]”hÌ)�”}”(hŒgif a new softirq-safe lock is discovered, we check whether it took any softirq-unsafe lock in the past.”h]”hŒgif a new softirq-safe lock is discovered, we check whether it took any softirq-unsafe lock in the past.”…”�”}”(hj?h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´K²hj;ubah}”(h]”h ]”h"]”h$]”h&]”uh1j–hj h²hh³hÊh´Nubj—)�”}”(hŒhif a new hardirq-unsafe lock is discovered, we check whether any hardirq-safe lock took it in the past. ”h]”hÌ)�”}”(hŒgif a new hardirq-unsafe lock is discovered, we check whether any hardirq-safe lock took it in the past.”h]”hŒgif a new hardirq-unsafe lock is discovered, we check whether any hardirq-safe lock took it in the past.”…”�”}”(hjWh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´KµhjSubah}”(h]”h ]”h"]”h$]”h&]”uh1j–hj h²hh³hÊh´Nubj—)�”}”(hŒhif a new softirq-unsafe lock is discovered, we check whether any softirq-safe lock took it in the past. ”h]”hÌ)�”}”(hŒgif a new softirq-unsafe lock is discovered, we check whether any softirq-safe lock took it in the past.”h]”hŒgif a new softirq-unsafe lock is discovered, we check whether any softirq-safe lock took it in the past.”…”�”}”(hjoh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´K¸hjkubah}”(h]”h ]”h"]”h$]”h&]”uh1j–hj h²hh³hÊh´Nubeh}”(h]”h ]”h"]”h$]”h&]”jûjüuh1j‘h³hÊh´K¯hj‘h²hubhÌ)�”}”(hŒó(Again, we do these checks too on the basis that an interrupt context could interrupt _any_ of the irq-unsafe or hardirq-unsafe locks, which could lead to a lock inversion deadlock - even if that lock scenario did not trigger in practice yet.)”h]”hŒó(Again, we do these checks too on the basis that an interrupt context could interrupt _any_ of the irq-unsafe or hardirq-unsafe locks, which could lead to a lock inversion deadlock - even if that lock scenario did not trigger in practice yet.)”…”�”}”(hj‰h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´K»hj‘h²hubeh}”(h]”Œmulti-lock-dependency-rules”ah ]”h"]”Œmulti-lock dependency rules:”ah$]”h&]”uh1hµhh·h²hh³hÊh´KŠubh¶)�”}”(hhh]”(h»)�”}”(hŒ=Exception: Nested data dependencies leading to nested locking”h]”hŒ=Exception: Nested data dependencies leading to nested locking”…”�”}”(hj¢h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhjŸh²hh³hÊh´KÁubhÌ)�”}”(hXŽThere are a few cases where the Linux kernel acquires more than one instance of the same lock-class. Such cases typically happen when there is some sort of hierarchy within objects of the same type. In these cases there is an inherent "natural" ordering between the two objects (defined by the properties of the hierarchy), and the kernel grabs the locks in this fixed order on each of the objects.”h]”hX’There are a few cases where the Linux kernel acquires more than one instance of the same lock-class. Such cases typically happen when there is some sort of hierarchy within objects of the same type. In these cases there is an inherent “naturalâ€� ordering between the two objects (defined by the properties of the hierarchy), and the kernel grabs the locks in this fixed order on each of the objects.”…”�”}”(hj°h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´KÃhjŸh²hubhÌ)�”}”(hX¾An example of such an object hierarchy that results in "nested locking" is that of a "whole disk" block-dev object and a "partition" block-dev object; the partition is "part of" the whole device and as long as one always takes the whole disk lock as a higher lock than the partition lock, the lock ordering is fully correct. The validator does not automatically detect this natural ordering, as the locking rule behind the ordering is not static.”h]”hXÎAn example of such an object hierarchy that results in “nested lockingâ€� is that of a “whole diskâ€� block-dev object and a “partitionâ€� block-dev object; the partition is “part ofâ€� the whole device and as long as one always takes the whole disk lock as a higher lock than the partition lock, the lock ordering is fully correct. The validator does not automatically detect this natural ordering, as the locking rule behind the ordering is not static.”…”�”}”(hj¾h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´KÊhjŸh²hubhÌ)�”}”(hŒåIn order to teach the validator about this correct usage model, new versions of the various locking primitives were added that allow you to specify a "nesting level". An example call, for the block device mutex, looks like this::”h]”hŒèIn order to teach the validator about this correct usage model, new versions of the various locking primitives were added that allow you to specify a “nesting levelâ€�. An example call, for the block device mutex, looks like this:”…”�”}”(hjÌh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´KÒhjŸh²hubj�)�”}”(hŒ«enum bdev_bd_mutex_lock_class { BD_MUTEX_NORMAL, BD_MUTEX_WHOLE, BD_MUTEX_PARTITION }; mutex_lock_nested(&bdev->bd_contains->bd_mutex, BD_MUTEX_PARTITION);”h]”hŒ«enum bdev_bd_mutex_lock_class { BD_MUTEX_NORMAL, BD_MUTEX_WHOLE, BD_MUTEX_PARTITION }; mutex_lock_nested(&bdev->bd_contains->bd_mutex, BD_MUTEX_PARTITION);”…”�”}”hjÚsbah}”(h]”h ]”h"]”h$]”h&]”j�j‘uh1j€h³hÊh´K×hjŸh²hubhÌ)�”}”(hŒRIn this case the locking is done on a bdev object that is known to be a partition.”h]”hŒRIn this case the locking is done on a bdev object that is known to be a partition.”…”�”}”(hjèh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´KàhjŸh²hubhÌ)�”}”(hŒ{The validator treats a lock that is taken in such a nested fashion as a separate (sub)class for the purposes of validation.”h]”hŒ{The validator treats a lock that is taken in such a nested fashion as a separate (sub)class for the purposes of validation.”…”�”}”(hjöh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´KãhjŸh²hubhÌ)�”}”(hŒÂNote: When changing code to use the _nested() primitives, be careful and check really thoroughly that the hierarchy is correctly mapped; otherwise you can get false positives or false negatives.”h]”hŒÂNote: When changing code to use the _nested() primitives, be careful and check really thoroughly that the hierarchy is correctly mapped; otherwise you can get false positives or false negatives.”…”�”}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´KæhjŸh²hubeh}”(h]”Œlock); [...] }”h]”hŒkvoid update_rq_clock(struct rq *rq) { s64 delta; lockdep_assert_held(&rq->lock); [...] }”…”�”}”hjGsbah}”(h]”h ]”h"]”h$]”h&]”j�j‘uh1j€h³hÊh´Kõhjh²hubhÌ)�”}”(hŒAwhere holding rq->lock is required to safely update a rq's clock.”h]”hŒCwhere holding rq->lock is required to safely update a rq’s clock.”…”�”}”(hjUh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´Kýhjh²hubhÌ)�”}”(hX[The other family of macros is lockdep_*pin_lock(), which is admittedly only used for rq->lock ATM. Despite their limited adoption these annotations generate a WARN() if the lock of interest is "accidentally" unlocked. This turns out to be especially helpful to debug code with callbacks, where an upper layer assumes a lock remains taken, but a lower layer thinks it can maybe drop and reacquire the lock ("unwittingly" introducing races). lockdep_pin_lock() returns a 'struct pin_cookie' that is then used by lockdep_unpin_lock() to check that nobody tampered with the lock, e.g. kernel/sched/sched.h::”h]”hXfThe other family of macros is lockdep_*pin_lock(), which is admittedly only used for rq->lock ATM. Despite their limited adoption these annotations generate a WARN() if the lock of interest is “accidentallyâ€� unlocked. This turns out to be especially helpful to debug code with callbacks, where an upper layer assumes a lock remains taken, but a lower layer thinks it can maybe drop and reacquire the lock (“unwittinglyâ€� introducing races). lockdep_pin_lock() returns a ‘struct pin_cookie’ that is then used by lockdep_unpin_lock() to check that nobody tampered with the lock, e.g. kernel/sched/sched.h:”…”�”}”(hjch²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´Kÿhjh²hubj�)�”}”(hX static inline void rq_pin_lock(struct rq *rq, struct rq_flags *rf) { rf->cookie = lockdep_pin_lock(&rq->lock); [...] } static inline void rq_unpin_lock(struct rq *rq, struct rq_flags *rf) { [...] lockdep_unpin_lock(&rq->lock, rf->cookie); }”h]”hX static inline void rq_pin_lock(struct rq *rq, struct rq_flags *rf) { rf->cookie = lockdep_pin_lock(&rq->lock); [...] } static inline void rq_unpin_lock(struct rq *rq, struct rq_flags *rf) { [...] lockdep_unpin_lock(&rq->lock, rf->cookie); }”…”�”}”hjqsbah}”(h]”h ]”h"]”h$]”h&]”j�j‘uh1j€h³hÊh´Mhjh²hubhÌ)�”}”(hXWhile comments about locking requirements might provide useful information, the runtime checks performed by annotations are invaluable when debugging locking problems and they carry the same level of details when inspecting code. Always prefer annotations when in doubt!”h]”hXWhile comments about locking requirements might provide useful information, the runtime checks performed by annotations are invaluable when debugging locking problems and they carry the same level of details when inspecting code. Always prefer annotations when in doubt!”…”�”}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´Mhjh²hubeh}”(h]”Œ annotations”ah ]”h"]”Œ annotations”ah$]”h&]”uh1hµhh·h²hh³hÊh´Këubh¶)�”}”(hhh]”(h»)�”}”(hŒProof of 100% correctness:”h]”hŒProof of 100% correctness:”…”�”}”(hj˜h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhj•h²hh³hÊh´MubhÌ)�”}”(hX{The validator achieves perfect, mathematical 'closure' (proof of locking correctness) in the sense that for every simple, standalone single-task locking sequence that occurred at least once during the lifetime of the kernel, the validator proves it with a 100% certainty that no combination and timing of these locking sequences can cause any class of lock related deadlock. [1]_”h]”(hX{The validator achieves perfect, mathematical ‘closure’ (proof of locking correctness) in the sense that for every simple, standalone single-task locking sequence that occurred at least once during the lifetime of the kernel, the validator proves it with a 100% certainty that no combination and timing of these locking sequences can cause any class of lock related deadlock. ”…”�”}”(hj¦h²hh³Nh´NubhŒfootnote_reference”“”)�”}”(hŒ[1]_”h]”hŒ1”…”�”}”(hj°h²hh³Nh´Nubah}”(h]”Œid1”ah ]”h"]”h$]”h&]”Œrefid”Œid2”Œdocname”Œlocking/lockdep-design”uh1j®hj¦Œresolved”Kubeh}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´Mhj•h²hubhÌ)�”}”(hXæI.e. complex multi-CPU and multi-task locking scenarios do not have to occur in practice to prove a deadlock: only the simple 'component' locking chains have to occur at least once (anytime, in any task/context) for the validator to be able to prove correctness. (For example, complex deadlocks that would normally need more than 3 CPUs and a very unlikely constellation of tasks, irq-contexts and timings to occur, can be detected on a plain, lightly loaded single-CPU system as well!)”h]”hXêI.e. complex multi-CPU and multi-task locking scenarios do not have to occur in practice to prove a deadlock: only the simple ‘component’ locking chains have to occur at least once (anytime, in any task/context) for the validator to be able to prove correctness. (For example, complex deadlocks that would normally need more than 3 CPUs and a very unlikely constellation of tasks, irq-contexts and timings to occur, can be detected on a plain, lightly loaded single-CPU system as well!)”…”�”}”(hjÊh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´M#hj•h²hubhÌ)�”}”(hX»This radically decreases the complexity of locking related QA of the kernel: what has to be done during QA is to trigger as many "simple" single-task locking dependencies in the kernel as possible, at least once, to prove locking correctness - instead of having to trigger every possible combination of locking interaction between CPUs, combined with every possible hardirq and softirq nesting scenario (which is impossible to do in practice).”h]”hX¿This radically decreases the complexity of locking related QA of the kernel: what has to be done during QA is to trigger as many “simpleâ€� single-task locking dependencies in the kernel as possible, at least once, to prove locking correctness - instead of having to trigger every possible combination of locking interaction between CPUs, combined with every possible hardirq and softirq nesting scenario (which is impossible to do in practice).”…”�”}”(hjØh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´M,hj•h²hubhŒfootnote”“”)�”}”(hX¨assuming that the validator itself is 100% correct, and no other part of the system corrupts the state of the validator in any way. We also assume that all NMI/SMM paths [which could interrupt even hardirq-disabled codepaths] are correct and do not interfere with the validator. We also assume that the 64-bit 'chain hash' value is unique for every lock-chain in the system. Also, lock recursion must not be higher than 20. ”h]”(hŒlabel”“”)�”}”(hŒ1”h]”hŒ1”…”�”}”(hjîh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jìhjèubhÌ)�”}”(hX§assuming that the validator itself is 100% correct, and no other part of the system corrupts the state of the validator in any way. We also assume that all NMI/SMM paths [which could interrupt even hardirq-disabled codepaths] are correct and do not interfere with the validator. We also assume that the 64-bit 'chain hash' value is unique for every lock-chain in the system. Also, lock recursion must not be higher than 20.”h]”hX«assuming that the validator itself is 100% correct, and no other part of the system corrupts the state of the validator in any way. We also assume that all NMI/SMM paths [which could interrupt even hardirq-disabled codepaths] are correct and do not interfere with the validator. We also assume that the 64-bit ‘chain hash’ value is unique for every lock-chain in the system. Also, lock recursion must not be higher than 20.”…”�”}”(hjüh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´M6hjèubeh}”(h]”jÀah ]”h"]”Œ1”ah$]”h&]”jºajÁjÂuh1jæh³hÊh´M4hj•h²hjÃKubeh}”(h]”Œproof-of-100-correctness”ah ]”h"]”Œproof of 100% correctness:”ah$]”h&]”uh1hµhh·h²hh³hÊh´Mubh¶)�”}”(hhh]”(h»)�”}”(hŒ Performance:”h]”hŒ Performance:”…”�”}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhjh²hh³hÊh´M?ubhÌ)�”}”(hXKThe above rules require **massive** amounts of runtime checking. If we did that for every lock taken and for every irqs-enable event, it would render the system practically unusably slow. The complexity of checking is O(N^2), so even with just a few hundred lock-classes we'd have to do tens of thousands of checks for every event.”h]”(hŒThe above rules require ”…”�”}”(hj*h²hh³Nh´NubhŒstrong”“”)�”}”(hŒ **massive**”h]”hŒmassive”…”�”}”(hj4h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1j2hj*ubhX* amounts of runtime checking. If we did that for every lock taken and for every irqs-enable event, it would render the system practically unusably slow. The complexity of checking is O(N^2), so even with just a few hundred lock-classes we’d have to do tens of thousands of checks for every event.”…”�”}”(hj*h²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´MAhjh²hubhÌ)�”}”(hXThis problem is solved by checking any given 'locking scenario' (unique sequence of locks taken after each other) only once. A simple stack of held locks is maintained, and a lightweight 64-bit hash value is calculated, which hash is unique for every lock chain. The hash value, when the chain is validated for the first time, is then put into a hash table, which hash-table can be checked in a lockfree manner. If the locking chain occurs again later on, the hash table tells us that we don't have to validate the chain again.”h]”hXThis problem is solved by checking any given ‘locking scenario’ (unique sequence of locks taken after each other) only once. A simple stack of held locks is maintained, and a lightweight 64-bit hash value is calculated, which hash is unique for every lock chain. The hash value, when the chain is validated for the first time, is then put into a hash table, which hash-table can be checked in a lockfree manner. If the locking chain occurs again later on, the hash table tells us that we don’t have to validate the chain again.”…”�”}”(hjLh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´MGhjh²hubeh}”(h]”Œ performance”ah ]”h"]”Œ performance:”ah$]”h&]”uh1hµhh·h²hh³hÊh´M?ubh¶)�”}”(hhh]”(h»)�”}”(hŒTroubleshooting:”h]”hŒTroubleshooting:”…”�”}”(hjeh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhjbh²hh³hÊh´MQubhÌ)�”}”(hŒ�The validator tracks a maximum of MAX_LOCKDEP_KEYS number of lock classes. Exceeding this number will trigger the following lockdep warning::”h]”hŒŒThe validator tracks a maximum of MAX_LOCKDEP_KEYS number of lock classes. Exceeding this number will trigger the following lockdep warning:”…”�”}”(hjsh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´MShjbh²hubj�)�”}”(hŒ-(DEBUG_LOCKS_WARN_ON(id >= MAX_LOCKDEP_KEYS))”h]”hŒ-(DEBUG_LOCKS_WARN_ON(id >= MAX_LOCKDEP_KEYS))”…”�”}”hj�sbah}”(h]”h ]”h"]”h$]”h&]”j�j‘uh1j€h³hÊh´MVhjbh²hubhÌ)�”}”(hXBy default, MAX_LOCKDEP_KEYS is currently set to 8191, and typical desktop systems have less than 1,000 lock classes, so this warning normally results from lock-class leakage or failure to properly initialize locks. These two problems are illustrated below:”h]”hXBy default, MAX_LOCKDEP_KEYS is currently set to 8191, and typical desktop systems have less than 1,000 lock classes, so this warning normally results from lock-class leakage or failure to properly initialize locks. These two problems are illustrated below:”…”�”}”(hj�h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´MXhjbh²hubhŒenumerated_list”“”)�”}”(hhh]”(j—)�”}”(hX¹Repeated module loading and unloading while running the validator will result in lock-class leakage. The issue here is that each load of the module will create a new set of lock classes for that module's locks, but module unloading does not remove old classes (see below discussion of reuse of lock classes for why). Therefore, if that module is loaded and unloaded repeatedly, the number of lock classes will eventually reach the maximum. ”h]”hÌ)�”}”(hX¸Repeated module loading and unloading while running the validator will result in lock-class leakage. The issue here is that each load of the module will create a new set of lock classes for that module's locks, but module unloading does not remove old classes (see below discussion of reuse of lock classes for why). Therefore, if that module is loaded and unloaded repeatedly, the number of lock classes will eventually reach the maximum.”h]”hXºRepeated module loading and unloading while running the validator will result in lock-class leakage. The issue here is that each load of the module will create a new set of lock classes for that module’s locks, but module unloading does not remove old classes (see below discussion of reuse of lock classes for why). Therefore, if that module is loaded and unloaded repeatedly, the number of lock classes will eventually reach the maximum.”…”�”}”(hj¦h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´M]hj¢ubah}”(h]”h ]”h"]”h$]”h&]”uh1j–hjŸh²hh³hÊh´Nubj—)�”}”(hX·Using structures such as arrays that have large numbers of locks that are not explicitly initialized. For example, a hash table with 8192 buckets where each bucket has its own spinlock_t will consume 8192 lock classes -unless- each spinlock is explicitly initialized at runtime, for example, using the run-time spin_lock_init() as opposed to compile-time initializers such as __SPIN_LOCK_UNLOCKED(). Failure to properly initialize the per-bucket spinlocks would guarantee lock-class overflow. In contrast, a loop that called spin_lock_init() on each lock would place all 8192 locks into a single lock class. The moral of this story is that you should always explicitly initialize your locks. ”h]”(hÌ)�”}”(hXaUsing structures such as arrays that have large numbers of locks that are not explicitly initialized. For example, a hash table with 8192 buckets where each bucket has its own spinlock_t will consume 8192 lock classes -unless- each spinlock is explicitly initialized at runtime, for example, using the run-time spin_lock_init() as opposed to compile-time initializers such as __SPIN_LOCK_UNLOCKED(). Failure to properly initialize the per-bucket spinlocks would guarantee lock-class overflow. In contrast, a loop that called spin_lock_init() on each lock would place all 8192 locks into a single lock class.”h]”hXaUsing structures such as arrays that have large numbers of locks that are not explicitly initialized. For example, a hash table with 8192 buckets where each bucket has its own spinlock_t will consume 8192 lock classes -unless- each spinlock is explicitly initialized at runtime, for example, using the run-time spin_lock_init() as opposed to compile-time initializers such as __SPIN_LOCK_UNLOCKED(). Failure to properly initialize the per-bucket spinlocks would guarantee lock-class overflow. In contrast, a loop that called spin_lock_init() on each lock would place all 8192 locks into a single lock class.”…”�”}”(hj¾h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´MehjºubhÌ)�”}”(hŒSThe moral of this story is that you should always explicitly initialize your locks.”h]”hŒSThe moral of this story is that you should always explicitly initialize your locks.”…”�”}”(hjÌh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´Mphjºubeh}”(h]”h ]”h"]”h$]”h&]”uh1j–hjŸh²hh³hÊh´Nubeh}”(h]”h ]”h"]”h$]”h&]”Œenumtype”Œarabic”Œprefix”hŒsuffix”Œ.”uh1j�hjbh²hh³hÊh´M]ubhÌ)�”}”(hXuOne might argue that the validator should be modified to allow lock classes to be reused. However, if you are tempted to make this argument, first review the code and think through the changes that would be required, keeping in mind that the lock classes to be removed are likely to be linked into the lock-dependency graph. This turns out to be harder to do than to say.”h]”hXuOne might argue that the validator should be modified to allow lock classes to be reused. However, if you are tempted to make this argument, first review the code and think through the changes that would be required, keeping in mind that the lock classes to be removed are likely to be linked into the lock-dependency graph. This turns out to be harder to do than to say.”…”�”}”(hjëh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´Mshjbh²hubhÌ)�”}”(hŒÖOf course, if you do run out of lock classes, the next thing to do is to find the offending lock classes. First, the following command gives you the number of lock classes currently in use along with the maximum::”h]”hŒÕOf course, if you do run out of lock classes, the next thing to do is to find the offending lock classes. First, the following command gives you the number of lock classes currently in use along with the maximum:”…”�”}”(hjùh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´Mzhjbh²hubj�)�”}”(hŒ'grep "lock-classes" /proc/lockdep_stats”h]”hŒ'grep "lock-classes" /proc/lockdep_stats”…”�”}”hj sbah}”(h]”h ]”h"]”h$]”h&]”j�j‘uh1j€h³hÊh´M~hjbh²hubhÌ)�”}”(hŒ?This command produces the following output on a modest system::”h]”hŒ>This command produces the following output on a modest system:”…”�”}”(hj h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´M€hjbh²hubj�)�”}”(hŒ6lock-classes: 748 [max: 8191]”h]”hŒ6lock-classes: 748 [max: 8191]”…”�”}”hj# sbah}”(h]”h ]”h"]”h$]”h&]”j�j‘uh1j€h³hÊh´M‚hjbh²hubhÌ)�”}”(hŒ«If the number allocated (748 above) increases continually over time, then there is likely a leak. The following command can be used to identify the leaking lock classes::”h]”hŒªIf the number allocated (748 above) increases continually over time, then there is likely a leak. The following command can be used to identify the leaking lock classes:”…”�”}”(hj1 h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´M„hjbh²hubj�)�”}”(hŒgrep "BD" /proc/lockdep”h]”hŒgrep "BD" /proc/lockdep”…”�”}”hj? sbah}”(h]”h ]”h"]”h$]”h&]”j�j‘uh1j€h³hÊh´Mˆhjbh²hubhÌ)�”}”(hŒæRun the command and save the output, then compare against the output from a later run of this command to identify the leakers. This same output can also help you find situations where runtime lock initialization has been omitted.”h]”hŒæRun the command and save the output, then compare against the output from a later run of this command to identify the leakers. This same output can also help you find situations where runtime lock initialization has been omitted.”…”�”}”(hjM h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´MŠhjbh²hubeh}”(h]”Œtroubleshooting”ah ]”h"]”Œtroubleshooting:”ah$]”h&]”uh1hµhh·h²hh³hÊh´MQubh¶)�”}”(hhh]”(h»)�”}”(hŒRecursive read locks:”h]”hŒRecursive read locks:”…”�”}”(hjf h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhjc h²hh³hÊh´M�ubhÌ)�”}”(hŒlThe whole of the rest document tries to prove a certain type of cycle is equivalent to deadlock possibility.”h]”hŒlThe whole of the rest document tries to prove a certain type of cycle is equivalent to deadlock possibility.”…”�”}”(hjt h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´M‘hjc h²hubhÌ)�”}”(hX<There are three types of lockers: writers (i.e. exclusive lockers, like spin_lock() or write_lock()), non-recursive readers (i.e. shared lockers, like down_read()) and recursive readers (recursive shared lockers, like rcu_read_lock()). And we use the following notations of those lockers in the rest of the document:”h]”hX<There are three types of lockers: writers (i.e. exclusive lockers, like spin_lock() or write_lock()), non-recursive readers (i.e. shared lockers, like down_read()) and recursive readers (recursive shared lockers, like rcu_read_lock()). And we use the following notations of those lockers in the rest of the document:”…”�”}”(hj‚ h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´M”hjc h²hubj¡)�”}”(hX)W or E: stands for writers (exclusive lockers). r: stands for non-recursive readers. R: stands for recursive readers. S: stands for all readers (non-recursive + recursive), as both are shared lockers. N: stands for writers and non-recursive readers, as both are not recursive. ”h]”hÌ)�”}”(hX(W or E: stands for writers (exclusive lockers). r: stands for non-recursive readers. R: stands for recursive readers. S: stands for all readers (non-recursive + recursive), as both are shared lockers. N: stands for writers and non-recursive readers, as both are not recursive.”h]”hX(W or E: stands for writers (exclusive lockers). r: stands for non-recursive readers. R: stands for recursive readers. S: stands for all readers (non-recursive + recursive), as both are shared lockers. N: stands for writers and non-recursive readers, as both are not recursive.”…”�”}”(hj” h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´M™hj� ubah}”(h]”h ]”h"]”h$]”h&]”uh1j h³hÊh´M™hjc h²hubhÌ)�”}”(hŒ+Obviously, N is "r or W" and S is "r or R".”h]”hŒ3Obviously, N is “r or Wâ€� and S is “r or Râ€�.”…”�”}”(hj¨ h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´MŸhjc h²hubhÌ)�”}”(hŒîRecursive readers, as their name indicates, are the lockers allowed to acquire even inside the critical section of another reader of the same lock instance, in other words, allowing nested read-side critical sections of one lock instance.”h]”hŒîRecursive readers, as their name indicates, are the lockers allowed to acquire even inside the critical section of another reader of the same lock instance, in other words, allowing nested read-side critical sections of one lock instance.”…”�”}”(hj¶ h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´M¡hjc h²hubhÌ)�”}”(hŒ”While non-recursive readers will cause a self deadlock if trying to acquire inside the critical section of another reader of the same lock instance.”h]”hŒ”While non-recursive readers will cause a self deadlock if trying to acquire inside the critical section of another reader of the same lock instance.”…”�”}”(hjÄ h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´M¥hjc h²hubhÌ)�”}”(hŒôThe difference between recursive readers and non-recursive readers is because: recursive readers get blocked only by a write lock *holder*, while non-recursive readers could get blocked by a write lock *waiter*. Considering the follow example::”h]”(hŒ‚The difference between recursive readers and non-recursive readers is because: recursive readers get blocked only by a write lock ”…”�”}”(hjÒ h²hh³Nh´NubhŒemphasis”“”)�”}”(hŒ*holder*”h]”hŒholder”…”�”}”(hjÜ h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jÚ hjÒ ubhŒ@, while non-recursive readers could get blocked by a write lock ”…”�”}”(hjÒ h²hh³Nh´NubjÛ )�”}”(hŒ*waiter*”h]”hŒwaiter”…”�”}”(hjî h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jÚ hjÒ ubhŒ!. Considering the follow example:”…”�”}”(hjÒ h²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´M¨hjc h²hubj�)�”}”(hŒeTASK A: TASK B: read_lock(X); write_lock(X); read_lock_2(X);”h]”hŒeTASK A: TASK B: read_lock(X); write_lock(X); read_lock_2(X);”…”�”}”hj sbah}”(h]”h ]”h"]”h$]”h&]”j�j‘uh1j€h³hÊh´M­hjc h²hubhÌ)�”}”(hXÏTask A gets the reader (no matter whether recursive or non-recursive) on X via read_lock() first. And when task B tries to acquire writer on X, it will block and become a waiter for writer on X. Now if read_lock_2() is recursive readers, task A will make progress, because writer waiters don't block recursive readers, and there is no deadlock. However, if read_lock_2() is non-recursive readers, it will get blocked by writer waiter B, and cause a self deadlock.”h]”hXÑTask A gets the reader (no matter whether recursive or non-recursive) on X via read_lock() first. And when task B tries to acquire writer on X, it will block and become a waiter for writer on X. Now if read_lock_2() is recursive readers, task A will make progress, because writer waiters don’t block recursive readers, and there is no deadlock. However, if read_lock_2() is non-recursive readers, it will get blocked by writer waiter B, and cause a self deadlock.”…”�”}”(hj h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´M³hjc h²hubeh}”(h]”Œrecursive-read-locks”ah ]”h"]”Œrecursive read locks:”ah$]”h&]”uh1hµhh·h²hh³hÊh´M�ubh¶)�”}”(hhh]”(h»)�”}”(hŒ>Block conditions on readers/writers of the same lock instance:”h]”hŒ>Block conditions on readers/writers of the same lock instance:”…”�”}”(hj- h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhj* h²hh³hÊh´M»ubhÌ)�”}”(hŒ'There are simply four block conditions:”h]”hŒ'There are simply four block conditions:”…”�”}”(hj; h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´M¼hj* h²hubjž)�”}”(hhh]”(j—)�”}”(hŒWriters block other writers.”h]”hÌ)�”}”(hjN h]”hŒWriters block other writers.”…”�”}”(hjP h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´M¾hjL ubah}”(h]”h ]”h"]”h$]”h&]”uh1j–hjI h²hh³hÊh´Nubj—)�”}”(hŒReaders block writers.”h]”hÌ)�”}”(hje h]”hŒReaders block writers.”…”�”}”(hjg h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´M¿hjc ubah}”(h]”h ]”h"]”h$]”h&]”uh1j–hjI h²hh³hÊh´Nubj—)�”}”(hŒ?Writers block both recursive readers and non-recursive readers.”h]”hÌ)�”}”(hj| h]”hŒ?Writers block both recursive readers and non-recursive readers.”…”�”}”(hj~ h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´MÀhjz ubah}”(h]”h ]”h"]”h$]”h&]”uh1j–hjI h²hh³hÊh´Nubj—)�”}”(hŒ�And readers (recursive or not) don't block other recursive readers but may block non-recursive readers (because of the potential co-existing writer waiters) ”h]”hÌ)�”}”(hŒœAnd readers (recursive or not) don't block other recursive readers but may block non-recursive readers (because of the potential co-existing writer waiters)”h]”hŒžAnd readers (recursive or not) don’t block other recursive readers but may block non-recursive readers (because of the potential co-existing writer waiters)”…”�”}”(hj• h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´MÁhj‘ ubah}”(h]”h ]”h"]”h$]”h&]”uh1j–hjI h²hh³hÊh´Nubeh}”(h]”h ]”h"]”h$]”h&]”jæjçjèhjéjêuh1j�hj* h²hh³hÊh´M¾ubhÌ)�”}”(hŒQBlock condition matrix, Y means the row blocks the column, and N means otherwise.”h]”hŒQBlock condition matrix, Y means the row blocks the column, and N means otherwise.”…”�”}”(hj¯ h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´MÅhj* h²hubj¡)�”}”(hŒá+---+---+---+---+ | | W | r | R | +---+---+---+---+ | W | Y | Y | Y | +---+---+---+---+ | r | Y | Y | N | +---+---+---+---+ | R | Y | Y | N | +---+---+---+---+ (W: writers, r: non-recursive readers, R: recursive readers) ”h]”(j§)�”}”(hhh]”j¬)�”}”(hhh]”(j±)�”}”(hhh]”h}”(h]”h ]”h"]”h$]”h&]”Œcolwidth”Kuh1j°hjÄ ubj±)�”}”(hhh]”h}”(h]”h ]”h"]”h$]”h&]”Œcolwidth”Kuh1j°hjÄ ubj±)�”}”(hhh]”h}”(h]”h ]”h"]”h$]”h&]”Œcolwidth”Kuh1j°hjÄ ubj±)�”}”(hhh]”h}”(h]”h ]”h"]”h$]”h&]”Œcolwidth”Kuh1j°hjÄ ubjÇ)�”}”(hhh]”(jÌ)�”}”(hhh]”(jÑ)�”}”(hhh]”h}”(h]”h ]”h"]”h$]”h&]”uh1jÐhjò ubjÑ)�”}”(hhh]”hÌ)�”}”(hŒW”h]”hŒW”…”�”}”(hj h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´MÈhjþ ubah}”(h]”h ]”h"]”h$]”h&]”uh1jÐhjò ubjÑ)�”}”(hhh]”hÌ)�”}”(hŒr”h]”hŒr”…”�”}”(hj h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´MÈhj ubah}”(h]”h ]”h"]”h$]”h&]”uh1jÐhjò ubjÑ)�”}”(hhh]”hÌ)�”}”(hŒR”h]”hŒR”…”�”}”(hj/ h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´MÈhj, ubah}”(h]”h ]”h"]”h$]”h&]”uh1jÐhjò ubeh}”(h]”h ]”h"]”h$]”h&]”uh1jËhjï ubjÌ)�”}”(hhh]”(jÑ)�”}”(hhh]”hÌ)�”}”(hj h]”hŒW”…”�”}”(hjO h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´MÊhjL ubah}”(h]”h ]”h"]”h$]”h&]”uh1jÐhjI ubjÑ)�”}”(hhh]”hÌ)�”}”(hŒY”h]”hŒY”…”�”}”(hje h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´MÊhjb ubah}”(h]”h ]”h"]”h$]”h&]”uh1jÐhjI ubjÑ)�”}”(hhh]”hÌ)�”}”(hjg h]”hŒY”…”�”}”(hj| h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´MÊhjy ubah}”(h]”h ]”h"]”h$]”h&]”uh1jÐhjI ubjÑ)�”}”(hhh]”hÌ)�”}”(hjg h]”hŒY”…”�”}”(hj’ h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´MÊhj� ubah}”(h]”h ]”h"]”h$]”h&]”uh1jÐhjI ubeh}”(h]”h ]”h"]”h$]”h&]”uh1jËhjï ubjÌ)�”}”(hhh]”(jÑ)�”}”(hhh]”hÌ)�”}”(hj h]”hŒr”…”�”}”(hj± h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´MÌhj® ubah}”(h]”h ]”h"]”h$]”h&]”uh1jÐhj« ubjÑ)�”}”(hhh]”hÌ)�”}”(hjg h]”hŒY”…”�”}”(hjÇ h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´MÌhjÄ ubah}”(h]”h ]”h"]”h$]”h&]”uh1jÐhj« ubjÑ)�”}”(hhh]”hÌ)�”}”(hjg h]”hŒY”…”�”}”(hjÝ h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´MÌhjÚ ubah}”(h]”h ]”h"]”h$]”h&]”uh1jÐhj« ubjÑ)�”}”(hhh]”hÌ)�”}”(hŒN”h]”hŒN”…”�”}”(hjó h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´MÌhjð ubah}”(h]”h ]”h"]”h$]”h&]”uh1jÐhj« ubeh}”(h]”h ]”h"]”h$]”h&]”uh1jËhjï ubjÌ)�”}”(hhh]”(jÑ)�”}”(hhh]”hÌ)�”}”(hj1 h]”hŒR”…”�”}”(hj h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´MÎhj ubah}”(h]”h ]”h"]”h$]”h&]”uh1jÐhj ubjÑ)�”}”(hhh]”hÌ)�”}”(hjg h]”hŒY”…”�”}”(hj) h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´MÎhj& ubah}”(h]”h ]”h"]”h$]”h&]”uh1jÐhj ubjÑ)�”}”(hhh]”hÌ)�”}”(hjg h]”hŒY”…”�”}”(hj? h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´MÎhj< ubah}”(h]”h ]”h"]”h$]”h&]”uh1jÐhj ubjÑ)�”}”(hhh]”hÌ)�”}”(hjõ h]”hŒN”…”�”}”(hjU h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´MÎhjR ubah}”(h]”h ]”h"]”h$]”h&]”uh1jÐhj ubeh}”(h]”h ]”h"]”h$]”h&]”uh1jËhjï ubeh}”(h]”h ]”h"]”h$]”h&]”uh1jÆhjÄ ubeh}”(h]”h ]”h"]”h$]”h&]”Œcols”Kuh1j«hjÁ ubah}”(h]”h ]”h"]”h$]”h&]”uh1j¦hj½ ubhÌ)�”}”(hŒ<(W: writers, r: non-recursive readers, R: recursive readers)”h]”hŒ<(W: writers, r: non-recursive readers, R: recursive readers)”…”�”}”(hj� h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´MÑhj½ ubeh}”(h]”h ]”h"]”h$]”h&]”uh1j h³hÊh´MÇhj* h²hubhÌ)�”}”(hŒ«acquired recursively. Unlike non-recursive read locks, recursive read locks only get blocked by current write lock *holders* other than write lock *waiters*, for example::”h]”(hŒsacquired recursively. Unlike non-recursive read locks, recursive read locks only get blocked by current write lock ”…”�”}”(hj• h²hh³Nh´NubjÛ )�”}”(hŒ *holders*”h]”hŒholders”…”�”}”(hj� h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jÚ hj• ubhŒ other than write lock ”…”�”}”(hj• h²hh³Nh´NubjÛ )�”}”(hŒ *waiters*”h]”hŒwaiters”…”�”}”(hj¯ h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jÚ hj• ubhŒ, for example:”…”�”}”(hj• h²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´MÔhj* h²hubj�)�”}”(hŒeTASK A: TASK B: read_lock(X); write_lock(X); read_lock(X);”h]”hŒeTASK A: TASK B: read_lock(X); write_lock(X); read_lock(X);”…”�”}”hjÇ sbah}”(h]”h ]”h"]”h$]”h&]”j�j‘uh1j€h³hÊh´MØhj* h²hubhÌ)�”}”(hXwis not a deadlock for recursive read locks, as while the task B is waiting for the lock X, the second read_lock() doesn't need to wait because it's a recursive read lock. However if the read_lock() is non-recursive read lock, then the above case is a deadlock, because even if the write_lock() in TASK B cannot get the lock, but it can block the second read_lock() in TASK A.”h]”hX{is not a deadlock for recursive read locks, as while the task B is waiting for the lock X, the second read_lock() doesn’t need to wait because it’s a recursive read lock. However if the read_lock() is non-recursive read lock, then the above case is a deadlock, because even if the write_lock() in TASK B cannot get the lock, but it can block the second read_lock() in TASK A.”…”�”•qa}”(hjÕ h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´Màhj* h²hubhÌ)�”}”(hX¾Note that a lock can be a write lock (exclusive lock), a non-recursive read lock (non-recursive shared lock) or a recursive read lock (recursive shared lock), depending on the lock operations used to acquire it (more specifically, the value of the 'read' parameter for lock_acquire()). In other words, a single lock instance has three types of acquisition depending on the acquisition functions: exclusive, non-recursive read, and recursive read.”h]”hXÂNote that a lock can be a write lock (exclusive lock), a non-recursive read lock (non-recursive shared lock) or a recursive read lock (recursive shared lock), depending on the lock operations used to acquire it (more specifically, the value of the ‘read’ parameter for lock_acquire()). In other words, a single lock instance has three types of acquisition depending on the acquisition functions: exclusive, non-recursive read, and recursive read.”…”�”}”(hjã h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´Mæhj* h²hubhÌ)�”}”(hŒŒTo be concise, we call that write locks and non-recursive read locks as "non-recursive" locks and recursive read locks as "recursive" locks.”h]”hŒ”To be concise, we call that write locks and non-recursive read locks as “non-recursiveâ€� locks and recursive read locks as “recursiveâ€� locks.”…”�”}”(hjñ h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´Míhj* h²hubhÌ)�”}”(hŒËRecursive locks don't block each other, while non-recursive locks do (this is even true for two non-recursive read locks). A non-recursive lock can block the corresponding recursive lock, and vice versa.”h]”hŒÍRecursive locks don’t block each other, while non-recursive locks do (this is even true for two non-recursive read locks). A non-recursive lock can block the corresponding recursive lock, and vice versa.”…”�”}”(hjÿ h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´Mðhj* h²hubhÌ)�”}”(hŒblock conditions on readers/writers of the same lock instance:”ah$]”h&]”uh1hµhh·h²hh³hÊh´M»ubh¶)�”}”(hhh]”(h»)�”}”(hŒ-Dependency types and strong dependency paths:”h]”hŒ-Dependency types and strong dependency paths:”…”�”}”(hjB h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhj? h²hh³hÊh´MubhÌ)�”}”(hŒÿLock dependencies record the orders of the acquisitions of a pair of locks, and because there are 3 types for lockers, there are, in theory, 9 types of lock dependencies, but we can show that 4 types of lock dependencies are enough for deadlock detection.”h]”hŒÿLock dependencies record the orders of the acquisitions of a pair of locks, and because there are 3 types for lockers, there are, in theory, 9 types of lock dependencies, but we can show that 4 types of lock dependencies are enough for deadlock detection.”…”�”}”(hjP h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´Mhj? h²hubhÌ)�”}”(hŒFor each lock dependency::”h]”hŒFor each lock dependency:”…”�”}”(hj^ h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´Mhj? h²hubj�)�”}”(hŒL1 -> L2”h]”hŒL1 -> L2”…”�”}”hjl sbah}”(h]”h ]”h"]”h$]”h&]”j�j‘uh1j€h³hÊh´M hj? h²hubhÌ)�”}”(hX , which means lockdep has seen L1 held before L2 held in the same context at runtime. And in deadlock detection, we care whether we could get blocked on L2 with L1 held, IOW, whether there is a locker L3 that L1 blocks L3 and L2 gets blocked by L3. So we only care about 1) what L1 blocks and 2) what blocks L2. As a result, we can combine recursive readers and non-recursive readers for L1 (as they block the same types) and we can combine writers and non-recursive readers for L2 (as they get blocked by the same types).”h]”hX , which means lockdep has seen L1 held before L2 held in the same context at runtime. And in deadlock detection, we care whether we could get blocked on L2 with L1 held, IOW, whether there is a locker L3 that L1 blocks L3 and L2 gets blocked by L3. So we only care about 1) what L1 blocks and 2) what blocks L2. As a result, we can combine recursive readers and non-recursive readers for L1 (as they block the same types) and we can combine writers and non-recursive readers for L2 (as they get blocked by the same types).”…”�”}”(hjz h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´M hj? h²hubhÌ)�”}”(hŒjWith the above combination for simplification, there are 4 types of dependency edges in the lockdep graph:”h]”hŒjWith the above combination for simplification, there are 4 types of dependency edges in the lockdep graph:”…”�”}”(hjˆ h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´Mhj? h²hubjž)�”}”(hhh]”(j—)�”}”(hŒ–-(ER)->: exclusive writer to recursive reader dependency, "X -(ER)-> Y" means X -> Y and X is a writer and Y is a recursive reader. ”h]”hŒdefinition_list”“”)�”}”(hhh]”hŒdefinition_list_item”“”)�”}”(hŒ„-(ER)->: exclusive writer to recursive reader dependency, "X -(ER)-> Y" means X -> Y and X is a writer and Y is a recursive reader. ”h]”(hŒterm”“”)�”}”(hŒ-(ER)->:”h]”hŒ-(ER)->:”…”�”}”(hjª h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1j¨ h³hÊh´Mhj¤ ubhŒ definition”“”)�”}”(hhh]”hÌ)�”}”(hŒzexclusive writer to recursive reader dependency, "X -(ER)-> Y" means X -> Y and X is a writer and Y is a recursive reader.”h]”hŒ~exclusive writer to recursive reader dependency, “X -(ER)-> Yâ€� means X -> Y and X is a writer and Y is a recursive reader.”…”�”}”(hj½ h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´Mhjº ubah}”(h]”h ]”h"]”h$]”h&]”uh1j¸ hj¤ ubeh}”(h]”h ]”h"]”h$]”h&]”uh1j¢ h³hÊh´MhjŸ ubah}”(h]”h ]”h"]”h$]”h&]”uh1j� hj™ ubah}”(h]”h ]”h"]”h$]”h&]”uh1j–hj– h²hh³Nh´Nubj—)�”}”(hŒ¯-(EN)->: exclusive writer to non-recursive locker dependency, "X -(EN)-> Y" means X -> Y and X is a writer and Y is either a writer or non-recursive reader. ”h]”jž )�”}”(hhh]”j£ )�”}”(hŒ�-(EN)->: exclusive writer to non-recursive locker dependency, "X -(EN)-> Y" means X -> Y and X is a writer and Y is either a writer or non-recursive reader. ”h]”(j© )�”}”(hŒ-(EN)->:”h]”hŒ-(EN)->:”…”�”}”(hjî h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1j¨ h³hÊh´Mhjê ubj¹ )�”}”(hhh]”hÌ)�”}”(hŒ“exclusive writer to non-recursive locker dependency, "X -(EN)-> Y" means X -> Y and X is a writer and Y is either a writer or non-recursive reader.”h]”hŒ—exclusive writer to non-recursive locker dependency, “X -(EN)-> Yâ€� means X -> Y and X is a writer and Y is either a writer or non-recursive reader.”…”�”}”(hjÿ h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´Mhjü ubah}”(h]”h ]”h"]”h$]”h&]”uh1j¸ hjê ubeh}”(h]”h ]”h"]”h$]”h&]”uh1j¢ h³hÊh´Mhjç ubah}”(h]”h ]”h"]”h$]”h&]”uh1j� hjã ubah}”(h]”h ]”h"]”h$]”h&]”uh1j–hj– h²hh³Nh´Nubj—)�”}”(hŒ¦-(SR)->: shared reader to recursive reader dependency, "X -(SR)-> Y" means X -> Y and X is a reader (recursive or not) and Y is a recursive reader. ”h]”jž )�”}”(hhh]”j£ )�”}”(hŒ”-(SR)->: shared reader to recursive reader dependency, "X -(SR)-> Y" means X -> Y and X is a reader (recursive or not) and Y is a recursive reader. ”h]”(j© )�”}”(hŒ-(SR)->:”h]”hŒ-(SR)->:”…”�”}”(hj0h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1j¨ h³hÊh´M hj,ubj¹ )�”}”(hhh]”hÌ)�”}”(hŒŠshared reader to recursive reader dependency, "X -(SR)-> Y" means X -> Y and X is a reader (recursive or not) and Y is a recursive reader.”h]”hŒŽshared reader to recursive reader dependency, “X -(SR)-> Yâ€� means X -> Y and X is a reader (recursive or not) and Y is a recursive reader.”…”�”}”(hjAh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´Mhj>ubah}”(h]”h ]”h"]”h$]”h&]”uh1j¸ hj,ubeh}”(h]”h ]”h"]”h$]”h&]”uh1j¢ h³hÊh´M hj)ubah}”(h]”h ]”h"]”h$]”h&]”uh1j� hj%ubah}”(h]”h ]”h"]”h$]”h&]”uh1j–hj– h²hh³Nh´Nubj—)�”}”(hŒÈ-(SN)->: shared reader to non-recursive locker dependency, "X -(SN)-> Y" means X -> Y and X is a reader (recursive or not) and Y is either a writer or non-recursive reader. ”h]”jž )�”}”(hhh]”j£ )�”}”(hŒ­-(SN)->: shared reader to non-recursive locker dependency, "X -(SN)-> Y" means X -> Y and X is a reader (recursive or not) and Y is either a writer or non-recursive reader. ”h]”(j© )�”}”(hŒ-(SN)->:”h]”hŒ-(SN)->:”…”�”}”(hjrh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1j¨ h³hÊh´M%hjnubj¹ )�”}”(hhh]”hÌ)�”}”(hŒ£shared reader to non-recursive locker dependency, "X -(SN)-> Y" means X -> Y and X is a reader (recursive or not) and Y is either a writer or non-recursive reader.”h]”hŒ§shared reader to non-recursive locker dependency, “X -(SN)-> Yâ€� means X -> Y and X is a reader (recursive or not) and Y is either a writer or non-recursive reader.”…”�”}”(hjƒh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´M#hj€ubah}”(h]”h ]”h"]”h$]”h&]”uh1j¸ hjnubeh}”(h]”h ]”h"]”h$]”h&]”uh1j¢ h³hÊh´M%hjkubah}”(h]”h ]”h"]”h$]”h&]”uh1j� hjgubah}”(h]”h ]”h"]”h$]”h&]”uh1j–hj– h²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”jæjçjèhjéŒ)”uh1j�hj? h²hh³hÊh´MubhÌ)�”}”(hŒZNote that given two locks, they may have multiple dependencies between them, for example::”h]”hŒYNote that given two locks, they may have multiple dependencies between them, for example:”…”�”}”(hj°h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´M'hj? h²hubj�)�”}”(hŒQTASK A: read_lock(X); write_lock(Y); ... TASK B: write_lock(X); write_lock(Y);”h]”hŒQTASK A: read_lock(X); write_lock(Y); ... TASK B: write_lock(X); write_lock(Y);”…”�”}”hj¾sbah}”(h]”h ]”h"]”h$]”h&]”j�j‘uh1j€h³hÊh´M*hj? h²hubhÌ)�”}”(hŒC, we have both X -(SN)-> Y and X -(EN)-> Y in the dependency graph.”h]”hŒC, we have both X -(SN)-> Y and X -(EN)-> Y in the dependency graph.”…”�”}”(hjÌh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´M5hj? h²hubhÌ)�”}”(hŒrWe use -(xN)-> to represent edges that are either -(EN)-> or -(SN)->, the similar for -(Ex)->, -(xR)-> and -(Sx)->”h]”hŒrWe use -(xN)-> to represent edges that are either -(EN)-> or -(SN)->, the similar for -(Ex)->, -(xR)-> and -(Sx)->”…”�”}”(hjÚh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´M7hj? h²hubhÌ)�”}”(hX8A "path" is a series of conjunct dependency edges in the graph. And we define a "strong" path, which indicates the strong dependency throughout each dependency in the path, as the path that doesn't have two conjunct edges (dependencies) as -(xR)-> and -(Sx)->. In other words, a "strong" path is a path from a lock walking to another through the lock dependencies, and if X -> Y -> Z is in the path (where X, Y, Z are locks), and the walk from X to Y is through a -(SR)-> or -(ER)-> dependency, the walk from Y to Z must not be through a -(SN)-> or -(SR)-> dependency.”h]”hXFA “pathâ€� is a series of conjunct dependency edges in the graph. And we define a “strongâ€� path, which indicates the strong dependency throughout each dependency in the path, as the path that doesn’t have two conjunct edges (dependencies) as -(xR)-> and -(Sx)->. In other words, a “strongâ€� path is a path from a lock walking to another through the lock dependencies, and if X -> Y -> Z is in the path (where X, Y, Z are locks), and the walk from X to Y is through a -(SR)-> or -(ER)-> dependency, the walk from Y to Z must not be through a -(SN)-> or -(SR)-> dependency.”…”�”}”(hjèh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´M:hj? h²hubhÌ)�”}”(hŒ L2 ... -> Ln -> L1”h]”hŒL1 -> L2 ... -> Ln -> L1”…”�”}”hj�sbah}”(h]”h ]”h"]”h$]”h&]”j�j‘uh1j€h³hÊh´M`hj h²hubhÌ)�”}”(hŒ$, which means we have dependencies::”h]”hŒ#, which means we have dependencies:”…”�”}”(hj›h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´Mbhj h²hubj�)�”}”(hŒ)L1 -> L2 L2 -> L3 ... Ln-1 -> Ln Ln -> L1”h]”hŒ)L1 -> L2 L2 -> L3 ... Ln-1 -> Ln Ln -> L1”…”�”}”hj©sbah}”(h]”h ]”h"]”h$]”h&]”j�j‘uh1j€h³hÊh´Mdhj h²hubhÌ)�”}”(hŒLWe now can construct a combination of locking sequences that cause deadlock:”h]”hŒLWe now can construct a combination of locking sequences that cause deadlock:”…”�”}”(hj·h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´Mjhj h²hubhÌ)�”}”(hŒ´Firstly let's make one CPU/task get the L1 in L1 -> L2, and then another get the L2 in L2 -> L3, and so on. After this, all of the Lx in Lx -> Lx+1 are held by different CPU/tasks.”h]”hŒ¶Firstly let’s make one CPU/task get the L1 in L1 -> L2, and then another get the L2 in L2 -> L3, and so on. After this, all of the Lx in Lx -> Lx+1 are held by different CPU/tasks.”…”�”}”(hjÅh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´Mlhj h²hubhÌ)�”}”(hX¸And then because we have L1 -> L2, so the holder of L1 is going to acquire L2 in L1 -> L2, however since L2 is already held by another CPU/task, plus L1 -> L2 and L2 -> L3 are not -(xR)-> and -(Sx)-> (the definition of strong), which means either L2 in L1 -> L2 is a non-recursive locker (blocked by anyone) or the L2 in L2 -> L3, is writer (blocking anyone), therefore the holder of L1 cannot get L2, it has to wait L2's holder to release.”h]”hXºAnd then because we have L1 -> L2, so the holder of L1 is going to acquire L2 in L1 -> L2, however since L2 is already held by another CPU/task, plus L1 -> L2 and L2 -> L3 are not -(xR)-> and -(Sx)-> (the definition of strong), which means either L2 in L1 -> L2 is a non-recursive locker (blocked by anyone) or the L2 in L2 -> L3, is writer (blocking anyone), therefore the holder of L1 cannot get L2, it has to wait L2’s holder to release.”…”�”}”(hjÓh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´Mphj h²hubhÌ)�”}”(hX-Moreover, we can have a similar conclusion for L2's holder: it has to wait L3's holder to release, and so on. We now can prove that Lx's holder has to wait for Lx+1's holder to release, and note that Ln+1 is L1, so we have a circular waiting scenario and nobody can get progress, therefore a deadlock.”h]”hX5Moreover, we can have a similar conclusion for L2’s holder: it has to wait L3’s holder to release, and so on. We now can prove that Lx’s holder has to wait for Lx+1’s holder to release, and note that Ln+1 is L1, so we have a circular waiting scenario and nobody can get progress, therefore a deadlock.”…”�”}”(hjáh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´Mwhj h²hubhÌ)�”}”(hŒProof for necessary (Lemma 2):”h]”hŒProof for necessary (Lemma 2):”…”�”}”(hjïh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´M|hj h²hubhÌ)�”}”(hŒvLemma 2 is equivalent to: If there is a deadlock scenario, then there must be a strong circle in the dependency graph.”h]”hŒvLemma 2 is equivalent to: If there is a deadlock scenario, then there must be a strong circle in the dependency graph.”…”�”}”(hjýh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´M~hj h²hubhÌ)�”}”(hXAccording to Wikipedia[1], if there is a deadlock, then there must be a circular waiting scenario, means there are N CPU/tasks, where CPU/task P1 is waiting for a lock held by P2, and P2 is waiting for a lock held by P3, ... and Pn is waiting for a lock held by P1. Let's name the lock Px is waiting as Lx, so since P1 is waiting for L1 and holding Ln, so we will have Ln -> L1 in the dependency graph. Similarly, we have L1 -> L2, L2 -> L3, ..., Ln-1 -> Ln in the dependency graph, which means we have a circle::”h]”hXAccording to Wikipedia[1], if there is a deadlock, then there must be a circular waiting scenario, means there are N CPU/tasks, where CPU/task P1 is waiting for a lock held by P2, and P2 is waiting for a lock held by P3, ... and Pn is waiting for a lock held by P1. Let’s name the lock Px is waiting as Lx, so since P1 is waiting for L1 and holding Ln, so we will have Ln -> L1 in the dependency graph. Similarly, we have L1 -> L2, L2 -> L3, ..., Ln-1 -> Ln in the dependency graph, which means we have a circle:”…”�”}”(hj h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´M�hj h²hubj�)�”}”(hŒLn -> L1 -> L2 -> ... -> Ln”h]”hŒLn -> L1 -> L2 -> ... -> Ln”…”�”}”hjsbah}”(h]”h ]”h"]”h$]”h&]”j�j‘uh1j€h³hÊh´M‰hj h²hubhÌ)�”}”(hŒ+, and now let's prove the circle is strong:”h]”hŒ-, and now let’s prove the circle is strong:”…”�”}”(hj'h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´M‹hj h²hubhÌ)�”}”(hXÊFor a lock Lx, Px contributes the dependency Lx-1 -> Lx and Px+1 contributes the dependency Lx -> Lx+1, and since Px is waiting for Px+1 to release Lx, so it's impossible that Lx on Px+1 is a reader and Lx on Px is a recursive reader, because readers (no matter recursive or not) don't block recursive readers, therefore Lx-1 -> Lx and Lx -> Lx+1 cannot be a -(xR)-> -(Sx)-> pair, and this is true for any lock in the circle, therefore, the circle is strong.”h]”hXÎFor a lock Lx, Px contributes the dependency Lx-1 -> Lx and Px+1 contributes the dependency Lx -> Lx+1, and since Px is waiting for Px+1 to release Lx, so it’s impossible that Lx on Px+1 is a reader and Lx on Px is a recursive reader, because readers (no matter recursive or not) don’t block recursive readers, therefore Lx-1 -> Lx and Lx -> Lx+1 cannot be a -(xR)-> -(Sx)-> pair, and this is true for any lock in the circle, therefore, the circle is strong.”…”�”}”(hj5h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´M�hj h²hubeh}”(h]”Œ!recursive-read-deadlock-detection”ah ]”h"]”Œ"recursive read deadlock detection:”ah$]”h&]”uh1hµhh·h²hh³hÊh´MFubh¶)�”}”(hhh]”(h»)�”}”(hŒ References:”h]”hŒ References:”…”�”}”(hjNh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhjKh²hh³hÊh´M•ubhÌ)�”}”(hŒx[1]: https://en.wikipedia.org/wiki/Deadlock [2]: Shibu, K. (2009). Intro To Embedded Systems (1st ed.). Tata McGraw-Hill”h]”(hŒ[1]: ”…”�”}”(hj\h²hh³Nh´NubhÖ)�”}”(hŒ&https://en.wikipedia.org/wiki/Deadlock”h]”hŒ&https://en.wikipedia.org/wiki/Deadlock”…”�”}”(hjdh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”Œrefuri”jfuh1hÕhj\ubhŒM [2]: Shibu, K. (2009). Intro To Embedded Systems (1st ed.). Tata McGraw-Hill”…”�”}”(hj\h²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´M–hjKh²hubeh}”(h]”Œ references”ah ]”h"]”Œ references:”ah$]”h&]”uh1hµhh·h²hh³hÊh´M•ubeh}”(h]”Œ%runtime-locking-correctness-validator”ah ]”h"]”Œ%runtime locking correctness validator”ah$]”h&]”uh1hµhhh²hh³hÊh´Kubeh}”(h]”h ]”h"]”h$]”h&]”Œsource”hÊuh1hŒcurrent_source”NŒ current_line”NŒsettings”Œdocutils.frontend”ŒValues”“”)�”}”(hºNŒ generator”NŒ datestamp”NŒ source_link”NŒ source_url”NŒ toc_backlinks”jÐŒfootnote_backlinks”KŒ sectnum_xform”KŒstrip_comments”NŒstrip_elements_with_classes”NŒ strip_classes”NŒ report_level”KŒ halt_level”KŒexit_status_level”KŒdebug”NŒwarning_stream”NŒ traceback”ˆŒinput_encoding”Œ utf-8-sig”Œinput_encoding_error_handler”Œstrict”Œoutput_encoding”Œutf-8”Œoutput_encoding_error_handler”j¯Œerror_encoding”Œutf-8”Œerror_encoding_error_handler”Œbackslashreplace”Œ language_code”Œen”Œrecord_dependencies”NŒconfig”NŒ id_prefix”hŒauto_id_prefix”Œid”Œ dump_settings”NŒdump_internals”NŒdump_transforms”NŒdump_pseudo_xml”NŒexpose_internals”NŒstrict_visitor”NŒ_disable_config”NŒ_source”hÊŒ _destination”NŒ _config_files”]”Œ7/var/lib/git/docbuild/linux/Documentation/docutils.conf”aŒfile_insertion_enabled”ˆŒ raw_enabled”KŒline_length_limit”M'Œpep_references”NŒ pep_base_url”Œhttps://peps.python.org/”Œpep_file_url_template”Œpep-%04d”Œrfc_references”NŒ rfc_base_url”Œ&https://datatracker.ietf.org/doc/html/”Œ tab_width”KŒtrim_footnote_reference_space”‰Œsyntax_highlight”Œlong”Œ smart_quotes”ˆŒsmartquotes_locales”]”Œcharacter_level_inline_markup”‰Œdoctitle_xform”‰Œ docinfo_xform”KŒsectsubtitle_xform”‰Œ image_loading”Œlink”Œembed_stylesheet”‰Œcloak_email_addresses”ˆŒsection_self_link”‰Œenv”NubŒreporter”NŒindirect_targets”]”Œsubstitution_defs”}”Œsubstitution_names”}”Œrefnames”}”Œ1”]”j°asŒrefids”}”Œnameids”}”(jŠj‡jaj^j/j,jŽj‹jœj™jjj’j�jjjjÀj_j\j` j] j' j$ j< j9 j jjHjEj‚juŒ nametypes”}”(jЉja‰j/‰jމjœ‰j‰j’‰j‰jˆj_‰j` ‰j' ‰j< ‰j ‰jH‰j‚‰uh}”(j‡h·j^jj,jdj‹j2j™j‘jjŸj�jjj•jºj°jÀjèj\jj] jbj$ jc j9 j* jj? jEj jjKuŒ footnote_refs”}”jï]”j°asŒ citation_refs”}”Œ autofootnotes”]”Œautofootnote_refs”]”Œsymbol_footnotes”]”Œsymbol_footnote_refs”]”Œ footnotes”]”jèaŒ citations”]”Œautofootnote_start”KŒsymbol_footnote_start”KŒ id_counter”Œ collections”ŒCounter”“”}”j½Ks…”R”Œparse_messages”]”Œtransform_messages”]”Œ transformer”NŒ include_log”]”Œ decoration”Nh²hub.