€•ÚxŒ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/livepatch/shadow-vars”Œ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/livepatch/shadow-vars”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubh)”}”(hhh]”hŒItalian”…””}”hhFsbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ)/translations/it_IT/livepatch/shadow-vars”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubh)”}”(hhh]”hŒJapanese”…””}”hhZsbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ)/translations/ja_JP/livepatch/shadow-vars”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubh)”}”(hhh]”hŒKorean”…””}”hhnsbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ)/translations/ko_KR/livepatch/shadow-vars”Œ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/livepatch/shadow-vars”Œ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ŒShadow Variables”h]”hŒShadow Variables”…””}”(hh¨hžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h¦hh£hžhhŸŒC/var/lib/git/docbuild/linux/Documentation/livepatch/shadow-vars.rst”h KubhŒ paragraph”“”)”}”(hX]Shadow variables are a simple way for livepatch modules to associate additional "shadow" data with existing data structures. Shadow data is allocated separately from parent data structures, which are left unmodified. The shadow variable API described in this document is used to allocate/add and remove/free shadow variables to/from their parents.”h]”hXaShadow variables are a simple way for livepatch modules to associate additional “shadow†data with existing data structures. Shadow data is allocated separately from parent data structures, which are left unmodified. The shadow variable API described in this document is used to allocate/add and remove/free shadow variables to/from their parents.”…””}”(hh¹hžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h Khh£hžhubh¸)”}”(hXThe implementation introduces a global, in-kernel hashtable that associates pointers to parent objects and a numeric identifier of the shadow data. The numeric identifier is a simple enumeration that may be used to describe shadow variable version, class or type, etc. More specifically, the parent pointer serves as the hashtable key while the numeric id subsequently filters hashtable queries. Multiple shadow variables may attach to the same parent object, but their numeric identifier distinguishes between them.”h]”hXThe implementation introduces a global, in-kernel hashtable that associates pointers to parent objects and a numeric identifier of the shadow data. The numeric identifier is a simple enumeration that may be used to describe shadow variable version, class or type, etc. More specifically, the parent pointer serves as the hashtable key while the numeric id subsequently filters hashtable queries. Multiple shadow variables may attach to the same parent object, but their numeric identifier distinguishes between them.”…””}”(hhÇhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h K hh£hžhubh¢)”}”(hhh]”(h§)”}”(hŒ1. Brief API summary”h]”hŒ1. Brief API summary”…””}”(hhØhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h¦hhÕhžhhŸh¶h Kubh¸)”}”(hŒ=(See the full API usage docbook notes in livepatch/shadow.c.)”h]”hŒ=(See the full API usage docbook notes in livepatch/shadow.c.)”…””}”(hhæhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h KhhÕhžhubh¸)”}”(hŒqA hashtable references all shadow variables. These references are stored and retrieved through a pair.”h]”hŒqA hashtable references all shadow variables. These references are stored and retrieved through a pair.”…””}”(hhôhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h KhhÕhžhubhŒ bullet_list”“”)”}”(hhh]”hŒ list_item”“”)”}”(hŒËThe klp_shadow variable data structure encapsulates both tracking meta-data and shadow-data: - meta-data - obj - pointer to parent object - id - data identifier - data[] - storage for shadow data ”h]”(h¸)”}”(hŒ\The klp_shadow variable data structure encapsulates both tracking meta-data and shadow-data:”h]”hŒ\The klp_shadow variable data structure encapsulates both tracking meta-data and shadow-data:”…””}”(hj hžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h Khj ubj)”}”(hhh]”(j)”}”(hŒCmeta-data - obj - pointer to parent object - id - data identifier ”h]”(h¸)”}”(hŒ meta-data”h]”hŒ meta-data”…””}”(hj"hžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h K hjubj)”}”(hhh]”(j)”}”(hŒobj - pointer to parent object”h]”h¸)”}”(hj5h]”hŒobj - pointer to parent object”…””}”(hj7hžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h K"hj3ubah}”(h]”h ]”h"]”h$]”h&]”uh1jhj0ubj)”}”(hŒid - data identifier ”h]”h¸)”}”(hŒid - data identifier”h]”hŒid - data identifier”…””}”(hjNhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h K#hjJubah}”(h]”h ]”h"]”h$]”h&]”uh1jhj0ubeh}”(h]”h ]”h"]”h$]”h&]”Œbullet”Œ-”uh1jhŸh¶h K"hjubeh}”(h]”h ]”h"]”h$]”h&]”uh1jhjubj)”}”(hŒ!data[] - storage for shadow data ”h]”h¸)”}”(hŒ data[] - storage for shadow data”h]”hŒ data[] - storage for shadow data”…””}”(hjthžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h K%hjpubah}”(h]”h ]”h"]”h$]”h&]”uh1jhjubeh}”(h]”h ]”h"]”h$]”h&]”jhjiuh1jhŸh¶h K hj ubeh}”(h]”h ]”h"]”h$]”h&]”uh1jhjhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”jhŒ*”uh1jhŸh¶h KhhÕhžhubh¸)”}”(hX It is important to note that the klp_shadow_alloc() and klp_shadow_get_or_alloc() are zeroing the variable by default. They also allow to call a custom constructor function when a non-zero value is needed. Callers should provide whatever mutual exclusion is required.”h]”hX It is important to note that the klp_shadow_alloc() and klp_shadow_get_or_alloc() are zeroing the variable by default. They also allow to call a custom constructor function when a non-zero value is needed. Callers should provide whatever mutual exclusion is required.”…””}”(hj›hžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h K'hhÕhžhubh¸)”}”(hŒ˜Note that the constructor is called under klp_shadow_lock spinlock. It allows to do actions that can be done only once when a new variable is allocated.”h]”hŒ˜Note that the constructor is called under klp_shadow_lock spinlock. It allows to do actions that can be done only once when a new variable is allocated.”…””}”(hj©hžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h K-hhÕhžhubj)”}”(hhh]”(j)”}”(hŒaklp_shadow_get() - retrieve a shadow variable data pointer - search hashtable for pair ”h]”h¸)”}”(hŒ`klp_shadow_get() - retrieve a shadow variable data pointer - search hashtable for pair”h]”hŒ`klp_shadow_get() - retrieve a shadow variable data pointer - search hashtable for pair”…””}”(hj¾hžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h K0hjºubah}”(h]”h ]”h"]”h$]”h&]”uh1jhj·hžhhŸh¶h Nubj)”}”(hXKklp_shadow_alloc() - allocate and add a new shadow variable - search hashtable for pair - if exists - WARN and return NULL - if doesn't already exist - allocate a new shadow variable - initialize the variable using a custom constructor and data when provided - add to the global hashtable ”h]”(h¸)”}”(hŒaklp_shadow_alloc() - allocate and add a new shadow variable - search hashtable for pair”h]”hŒaklp_shadow_alloc() - allocate and add a new shadow variable - search hashtable for pair”…””}”(hjÖhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h K3hjÒubj)”}”(hhh]”(j)”}”(hŒ"if exists - WARN and return NULL ”h]”(h¸)”}”(hŒ if exists”h]”hŒ if exists”…””}”(hjëhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h K6hjçubj)”}”(hhh]”j)”}”(hŒWARN and return NULL ”h]”h¸)”}”(hŒWARN and return NULL”h]”hŒWARN and return NULL”…””}”(hjhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h K8hjüubah}”(h]”h ]”h"]”h$]”h&]”uh1jhjùubah}”(h]”h ]”h"]”h$]”h&]”jhjiuh1jhŸh¶h K8hjçubeh}”(h]”h ]”h"]”h$]”h&]”uh1jhjäubj)”}”(hŒ¹if doesn't already exist - allocate a new shadow variable - initialize the variable using a custom constructor and data when provided - add to the global hashtable ”h]”(h¸)”}”(hŒ"if doesn't already exist”h]”hŒ$if doesn’t already exist”…””}”(hj$hžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h K:hj ubj)”}”(hhh]”(j)”}”(hŒallocate a new shadow variable”h]”h¸)”}”(hj7h]”hŒallocate a new shadow variable”…””}”(hj9hžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h K to the global hashtable ”h]”h¸)”}”(hŒ%add to the global hashtable”h]”hŒ%add to the global hashtable”…””}”(hjghžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h K>hjcubah}”(h]”h ]”h"]”h$]”h&]”uh1jhj2ubeh}”(h]”h ]”h"]”h$]”h&]”jhjiuh1jhŸh¶h K pair - if exists - return existing shadow variable - if doesn't already exist - allocate a new shadow variable - initialize the variable using a custom constructor and data when provided - add pair to the global hashtable ”h]”(h¸)”}”(hŒmklp_shadow_get_or_alloc() - get existing or alloc a new shadow variable - search hashtable for pair”h]”hŒmklp_shadow_get_or_alloc() - get existing or alloc a new shadow variable - search hashtable for pair”…””}”(hj—hžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h K@hj“ubj)”}”(hhh]”(j)”}”(hŒ-if exists - return existing shadow variable ”h]”(h¸)”}”(hŒ if exists”h]”hŒ if exists”…””}”(hj¬hžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h KChj¨ubj)”}”(hhh]”j)”}”(hŒ return existing shadow variable ”h]”h¸)”}”(hŒreturn existing shadow variable”h]”hŒreturn existing shadow variable”…””}”(hjÁhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h KEhj½ubah}”(h]”h ]”h"]”h$]”h&]”uh1jhjºubah}”(h]”h ]”h"]”h$]”h&]”jhjiuh1jhŸh¶h KEhj¨ubeh}”(h]”h ]”h"]”h$]”h&]”uh1jhj¥ubj)”}”(hŒ¾if doesn't already exist - allocate a new shadow variable - initialize the variable using a custom constructor and data when provided - add pair to the global hashtable ”h]”(h¸)”}”(hŒ"if doesn't already exist”h]”hŒ$if doesn’t already exist”…””}”(hjåhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h KGhjáubj)”}”(hhh]”(j)”}”(hŒallocate a new shadow variable”h]”h¸)”}”(hjøh]”hŒallocate a new shadow variable”…””}”(hjúhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h KIhjöubah}”(h]”h ]”h"]”h$]”h&]”uh1jhjóubj)”}”(hŒIinitialize the variable using a custom constructor and data when provided”h]”h¸)”}”(hjh]”hŒIinitialize the variable using a custom constructor and data when provided”…””}”(hjhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h KJhj ubah}”(h]”h ]”h"]”h$]”h&]”uh1jhjóubj)”}”(hŒ+add pair to the global hashtable ”h]”h¸)”}”(hŒ*add pair to the global hashtable”h]”hŒ*add pair to the global hashtable”…””}”(hj(hžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h KKhj$ubah}”(h]”h ]”h"]”h$]”h&]”uh1jhjóubeh}”(h]”h ]”h"]”h$]”h&]”jhjiuh1jhŸh¶h KIhjáubeh}”(h]”h ]”h"]”h$]”h&]”uh1jhj¥ubeh}”(h]”h ]”h"]”h$]”h&]”jhjiuh1jhŸh¶h KChj“ubeh}”(h]”h ]”h"]”h$]”h&]”uh1jhj·hžhhŸNh Nubj)”}”(hŒÒklp_shadow_free() - detach and free a shadow variable - find and remove a reference from global hashtable - if found - call destructor function if defined - free shadow variable ”h]”(h¸)”}”(hŒ}klp_shadow_free() - detach and free a shadow variable - find and remove a reference from global hashtable”h]”hŒ}klp_shadow_free() - detach and free a shadow variable - find and remove a reference from global hashtable”…””}”(hjXhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h KMhjTubhŒ block_quote”“”)”}”(hŒM- if found - call destructor function if defined - free shadow variable ”h]”j)”}”(hhh]”j)”}”(hŒGif found - call destructor function if defined - free shadow variable ”h]”(h¸)”}”(hŒif found”h]”hŒif found”…””}”(hjshžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h KPhjoubj)”}”(hhh]”(j)”}”(hŒ#call destructor function if defined”h]”h¸)”}”(hj†h]”hŒ#call destructor function if defined”…””}”(hjˆhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h KRhj„ubah}”(h]”h ]”h"]”h$]”h&]”uh1jhjubj)”}”(hŒfree shadow variable ”h]”h¸)”}”(hŒfree shadow variable”h]”hŒfree shadow variable”…””}”(hjŸhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h KShj›ubah}”(h]”h ]”h"]”h$]”h&]”uh1jhjubeh}”(h]”h ]”h"]”h$]”h&]”jhjiuh1jhŸh¶h KRhjoubeh}”(h]”h ]”h"]”h$]”h&]”uh1jhjlubah}”(h]”h ]”h"]”h$]”h&]”jhjiuh1jhŸh¶h KPhjhubah}”(h]”h ]”h"]”h$]”h&]”uh1jfhŸh¶h KPhjTubeh}”(h]”h ]”h"]”h$]”h&]”uh1jhj·hžhhŸh¶h Nubj)”}”(hŒÙklp_shadow_free_all() - detach and free all <_, id> shadow variables - find and remove any <_, id> references from global hashtable - if found - call destructor function if defined - free shadow variable ”h]”(h¸)”}”(hŒƒklp_shadow_free_all() - detach and free all <_, id> shadow variables - find and remove any <_, id> references from global hashtable”h]”hŒƒklp_shadow_free_all() - detach and free all <_, id> shadow variables - find and remove any <_, id> references from global hashtable”…””}”(hjÕhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h KUhjÑubjg)”}”(hŒN- if found - call destructor function if defined - free shadow variable ”h]”j)”}”(hhh]”j)”}”(hŒHif found - call destructor function if defined - free shadow variable ”h]”(h¸)”}”(hŒif found”h]”hŒif found”…””}”(hjîhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h KXhjêubj)”}”(hhh]”(j)”}”(hŒ#call destructor function if defined”h]”h¸)”}”(hjh]”hŒ#call destructor function if defined”…””}”(hjhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h KZhjÿubah}”(h]”h ]”h"]”h$]”h&]”uh1jhjüubj)”}”(hŒfree shadow variable ”h]”h¸)”}”(hŒfree shadow variable”h]”hŒfree shadow variable”…””}”(hjhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h K[hjubah}”(h]”h ]”h"]”h$]”h&]”uh1jhjüubeh}”(h]”h ]”h"]”h$]”h&]”jhjiuh1jhŸh¶h KZhjêubeh}”(h]”h ]”h"]”h$]”h&]”uh1jhjçubah}”(h]”h ]”h"]”h$]”h&]”jhjiuh1jhŸh¶h KXhjãubah}”(h]”h ]”h"]”h$]”h&]”uh1jfhŸh¶h KXhjÑubeh}”(h]”h ]”h"]”h$]”h&]”uh1jhj·hžhhŸh¶h Nubeh}”(h]”h ]”h"]”h$]”h&]”jhjšuh1jhŸh¶h K0hhÕhžhubeh}”(h]”Œbrief-api-summary”ah ]”h"]”Œ1. brief api summary”ah$]”h&]”uh1h¡hh£hžhhŸh¶h Kubh¢)”}”(hhh]”(h§)”}”(hŒ 2. Use cases”h]”hŒ 2. Use cases”…””}”(hj]hžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h¦hjZhžhhŸh¶h K_ubh¸)”}”(hŒj(See the example shadow variable livepatch modules in samples/livepatch/ for full working demonstrations.)”h]”hŒj(See the example shadow variable livepatch modules in samples/livepatch/ for full working demonstrations.)”…””}”(hjkhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h KahjZhžhubh¸)”}”(hXFor the following use-case examples, consider commit 1d147bfa6429 ("mac80211: fix AP powersave TX vs. wakeup race"), which added a spinlock to net/mac80211/sta_info.h :: struct sta_info. Each use-case example can be considered a stand-alone livepatch implementation of this fix.”h]”hXFor the following use-case examples, consider commit 1d147bfa6429 (“mac80211: fix AP powersave TX vs. wakeup raceâ€), which added a spinlock to net/mac80211/sta_info.h :: struct sta_info. Each use-case example can be considered a stand-alone livepatch implementation of this fix.”…””}”(hjyhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h KdhjZhžhubh¢)”}”(hhh]”(h§)”}”(hŒMatching parent's lifecycle”h]”hŒMatching parent’s lifecycle”…””}”(hjŠhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h¦hj‡hžhhŸh¶h Klubh¸)”}”(hXûIf parent data structures are frequently created and destroyed, it may be easiest to align their shadow variables lifetimes to the same allocation and release functions. In this case, the parent data structure is typically allocated, initialized, then registered in some manner. Shadow variable allocation and setup can then be considered part of the parent's initialization and should be completed before the parent "goes live" (ie, any shadow variable get-API requests are made for this pair.)”h]”hXIf parent data structures are frequently created and destroyed, it may be easiest to align their shadow variables lifetimes to the same allocation and release functions. In this case, the parent data structure is typically allocated, initialized, then registered in some manner. Shadow variable allocation and setup can then be considered part of the parent’s initialization and should be completed before the parent “goes live†(ie, any shadow variable get-API requests are made for this pair.)”…””}”(hj˜hžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h Knhj‡hžhubh¸)”}”(hŒ‹For commit 1d147bfa6429, when a parent sta_info structure is allocated, allocate a shadow copy of the ps_lock pointer, then initialize it::”h]”hŒŠFor commit 1d147bfa6429, when a parent sta_info structure is allocated, allocate a shadow copy of the ps_lock pointer, then initialize it:”…””}”(hj¦hžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h Kwhj‡hžhubhŒ literal_block”“”)”}”(hXH#define PS_LOCK 1 struct sta_info *sta_info_alloc(struct ieee80211_sub_if_data *sdata, const u8 *addr, gfp_t gfp) { struct sta_info *sta; spinlock_t *ps_lock; /* Parent structure is created */ sta = kzalloc(sizeof(*sta) + hw->sta_data_size, gfp); /* Attach a corresponding shadow variable, then initialize it */ ps_lock = klp_shadow_alloc(sta, PS_LOCK, sizeof(*ps_lock), gfp, NULL, NULL); if (!ps_lock) goto shadow_fail; spin_lock_init(ps_lock); ...”h]”hXH#define PS_LOCK 1 struct sta_info *sta_info_alloc(struct ieee80211_sub_if_data *sdata, const u8 *addr, gfp_t gfp) { struct sta_info *sta; spinlock_t *ps_lock; /* Parent structure is created */ sta = kzalloc(sizeof(*sta) + hw->sta_data_size, gfp); /* Attach a corresponding shadow variable, then initialize it */ ps_lock = klp_shadow_alloc(sta, PS_LOCK, sizeof(*ps_lock), gfp, NULL, NULL); if (!ps_lock) goto shadow_fail; spin_lock_init(ps_lock); ...”…””}”hj¶sbah}”(h]”h ]”h"]”h$]”h&]”Œ xml:space”Œpreserve”uh1j´hŸh¶h Kzhj‡hžhubh¸)”}”(hŒiWhen requiring a ps_lock, query the shadow variable API to retrieve one for a specific struct sta_info:::”h]”hŒhWhen requiring a ps_lock, query the shadow variable API to retrieve one for a specific struct sta_info::”…””}”(hjÆhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h KŒhj‡hžhubjµ)”}”(hŒùvoid ieee80211_sta_ps_deliver_wakeup(struct sta_info *sta) { spinlock_t *ps_lock; /* sync with ieee80211_tx_h_unicast_ps_buf */ ps_lock = klp_shadow_get(sta, PS_LOCK); if (ps_lock) spin_lock(ps_lock); ...”h]”hŒùvoid ieee80211_sta_ps_deliver_wakeup(struct sta_info *sta) { spinlock_t *ps_lock; /* sync with ieee80211_tx_h_unicast_ps_buf */ ps_lock = klp_shadow_get(sta, PS_LOCK); if (ps_lock) spin_lock(ps_lock); ...”…””}”hjÔsbah}”(h]”h ]”h"]”h$]”h&]”jÄjÅuh1j´hŸh¶h Khj‡hžhubh¸)”}”(hŒMWhen the parent sta_info structure is freed, first free the shadow variable::”h]”hŒLWhen the parent sta_info structure is freed, first free the shadow variable:”…””}”(hjâhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h K™hj‡hžhubjµ)”}”(hŒvoid sta_info_free(struct ieee80211_local *local, struct sta_info *sta) { klp_shadow_free(sta, PS_LOCK, NULL); kfree(sta); ...”h]”hŒvoid sta_info_free(struct ieee80211_local *local, struct sta_info *sta) { klp_shadow_free(sta, PS_LOCK, NULL); kfree(sta); ...”…””}”hjðsbah}”(h]”h ]”h"]”h$]”h&]”jÄjÅuh1j´hŸh¶h Kœhj‡hžhubeh}”(h]”Œmatching-parent-s-lifecycle”ah ]”h"]”Œmatching parent's lifecycle”ah$]”h&]”uh1h¡hjZhžhhŸh¶h Klubh¢)”}”(hhh]”(h§)”}”(hŒIn-flight parent objects”h]”hŒIn-flight parent objects”…””}”(hj hžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h¦hjhžhhŸh¶h K¤ubh¸)”}”(hXBSometimes it may not be convenient or possible to allocate shadow variables alongside their parent objects. Or a livepatch fix may require shadow variables for only a subset of parent object instances. In these cases, the klp_shadow_get_or_alloc() call can be used to attach shadow variables to parents already in-flight.”h]”hXBSometimes it may not be convenient or possible to allocate shadow variables alongside their parent objects. Or a livepatch fix may require shadow variables for only a subset of parent object instances. In these cases, the klp_shadow_get_or_alloc() call can be used to attach shadow variables to parents already in-flight.”…””}”(hjhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h K¦hjhžhubh¸)”}”(hŒpFor commit 1d147bfa6429, a good spot to allocate a shadow spinlock is inside ieee80211_sta_ps_deliver_wakeup()::”h]”hŒoFor commit 1d147bfa6429, a good spot to allocate a shadow spinlock is inside ieee80211_sta_ps_deliver_wakeup():”…””}”(hj%hžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h K¬hjhžhubjµ)”}”(hXint ps_lock_shadow_ctor(void *obj, void *shadow_data, void *ctor_data) { spinlock_t *lock = shadow_data; spin_lock_init(lock); return 0; } #define PS_LOCK 1 void ieee80211_sta_ps_deliver_wakeup(struct sta_info *sta) { spinlock_t *ps_lock; /* sync with ieee80211_tx_h_unicast_ps_buf */ ps_lock = klp_shadow_get_or_alloc(sta, PS_LOCK, sizeof(*ps_lock), GFP_ATOMIC, ps_lock_shadow_ctor, NULL); if (ps_lock) spin_lock(ps_lock); ...”h]”hXint ps_lock_shadow_ctor(void *obj, void *shadow_data, void *ctor_data) { spinlock_t *lock = shadow_data; spin_lock_init(lock); return 0; } #define PS_LOCK 1 void ieee80211_sta_ps_deliver_wakeup(struct sta_info *sta) { spinlock_t *ps_lock; /* sync with ieee80211_tx_h_unicast_ps_buf */ ps_lock = klp_shadow_get_or_alloc(sta, PS_LOCK, sizeof(*ps_lock), GFP_ATOMIC, ps_lock_shadow_ctor, NULL); if (ps_lock) spin_lock(ps_lock); ...”…””}”hj3sbah}”(h]”h ]”h"]”h$]”h&]”jÄjÅuh1j´hŸh¶h K¯hjhžhubh¸)”}”(hŒ…This usage will create a shadow variable, only if needed, otherwise it will use one that was already created for this pair.”h]”hŒ…This usage will create a shadow variable, only if needed, otherwise it will use one that was already created for this pair.”…””}”(hjAhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h KÅhjhžhubh¸)”}”(hŒÍLike the previous use-case, the shadow spinlock needs to be cleaned up. A shadow variable can be freed just before its parent object is freed, or even when the shadow variable itself is no longer required.”h]”hŒÍLike the previous use-case, the shadow spinlock needs to be cleaned up. A shadow variable can be freed just before its parent object is freed, or even when the shadow variable itself is no longer required.”…””}”(hjOhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h KÈhjhžhubeh}”(h]”Œin-flight-parent-objects”ah ]”h"]”Œin-flight parent objects”ah$]”h&]”uh1h¡hjZhžhhŸh¶h K¤ubh¢)”}”(hhh]”(h§)”}”(hŒOther use-cases”h]”hŒOther use-cases”…””}”(hjhhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h¦hjehžhhŸh¶h KÎubh¸)”}”(hŒøShadow variables can also be used as a flag indicating that a data structure was allocated by new, livepatched code. In this case, it doesn't matter what data value the shadow variable holds, its existence suggests how to handle the parent object.”h]”hŒúShadow variables can also be used as a flag indicating that a data structure was allocated by new, livepatched code. In this case, it doesn’t matter what data value the shadow variable holds, its existence suggests how to handle the parent object.”…””}”(hjvhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h KÐhjehžhubeh}”(h]”Œother-use-cases”ah ]”h"]”Œother use-cases”ah$]”h&]”uh1h¡hjZhžhhŸh¶h KÎubeh}”(h]”Œ use-cases”ah ]”h"]”Œ 2. use cases”ah$]”h&]”uh1h¡hh£hžhhŸh¶h K_ubh¢)”}”(hhh]”(h§)”}”(hŒ 3. References”h]”hŒ 3. References”…””}”(hj—hžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h¦hj”hžhhŸh¶h K×ubj)”}”(hhh]”(j)”}”(hŒrhttps://github.com/dynup/kpatch The livepatch implementation is based on the kpatch version of shadow variables. ”h]”(h¸)”}”(hŒhttps://github.com/dynup/kpatch”h]”hŒ reference”“”)”}”(hj®h]”hŒhttps://github.com/dynup/kpatch”…””}”(hj²hžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”Œrefuri”j®uh1j°hj¬ubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h KÙhj¨ubh¸)”}”(hŒPThe livepatch implementation is based on the kpatch version of shadow variables.”h]”hŒPThe livepatch implementation is based on the kpatch version of shadow variables.”…””}”(hjÆhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h KÛhj¨ubeh}”(h]”h ]”h"]”h$]”h&]”uh1jhj¥hžhhŸh¶h Nubj)”}”(hXhttp://files.mkgnu.net/files/dynamos/doc/papers/dynamos_eurosys_07.pdf Dynamic and Adaptive Updates of Non-Quiescent Subsystems in Commodity Operating System Kernels (Kritis Makris, Kyung Dong Ryu 2007) presented a datatype update technique called "shadow data structures".”h]”(h¸)”}”(hŒFhttp://files.mkgnu.net/files/dynamos/doc/papers/dynamos_eurosys_07.pdf”h]”j±)”}”(hjàh]”hŒFhttp://files.mkgnu.net/files/dynamos/doc/papers/dynamos_eurosys_07.pdf”…””}”(hjâhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”Œrefuri”jàuh1j°hjÞubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h KÞhjÚubh¸)”}”(hŒÊDynamic and Adaptive Updates of Non-Quiescent Subsystems in Commodity Operating System Kernels (Kritis Makris, Kyung Dong Ryu 2007) presented a datatype update technique called "shadow data structures".”h]”hŒÎDynamic and Adaptive Updates of Non-Quiescent Subsystems in Commodity Operating System Kernels (Kritis Makris, Kyung Dong Ryu 2007) presented a datatype update technique called “shadow data structuresâ€.”…””}”(hjöhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h KàhjÚubeh}”(h]”h ]”h"]”h$]”h&]”uh1jhj¥hžhhŸh¶h Nubeh}”(h]”h ]”h"]”h$]”h&]”jhjšuh1jhŸh¶h KÙhj”hžhubeh}”(h]”Œ references”ah ]”h"]”Œ 3. references”ah$]”h&]”uh1h¡hh£hžhhŸh¶h K×ubeh}”(h]”Œshadow-variables”ah ]”h"]”Œshadow variables”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”Œentry”Œ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”jCŒ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”}”Œrefids”}”Œnameids”}”(jjjWjTj‘jŽjjjbj_j‰j†jjuŒ nametypes”}”(j‰jW‰j‘‰j‰jb‰j‰‰j‰uh}”(jh£jThÕjŽjZjj‡j_jj†jejj”uŒ footnote_refs”}”Œ citation_refs”}”Œ autofootnotes”]”Œautofootnote_refs”]”Œsymbol_footnotes”]”Œsymbol_footnote_refs”]”Œ footnotes”]”Œ citations”]”Œautofootnote_start”KŒsymbol_footnote_start”KŒ id_counter”Œ collections”ŒCounter”“”}”…”R”Œparse_messages”]”Œtransform_messages”]”Œ transformer”NŒ include_log”]”Œ decoration”Nhžhub.