You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Need to document the callback best practices which we defined while working on the IFU and TAA patches. Not sure whether it belongs in the author guide or in the kernel callback docs. Maybe both.
For the IFU mitigation, we used a simple shadow-variable refcount mechanism to run pre-patch callbacks on the first kpatch load and the post-unpatch callback on the last kpatch unload:
/* * kpatch note: called from a KPATCH_PRE_PATCH_CALLBACK */staticintkpatch_ifu_pre_patch(void)
{
int*refcount;
intret;
/* patch upgrade ref counting - only do init the first time */refcount=klp_shadow_get(NULL, KLP_SHADOW_CPU_BUGS_COUNT);
if (refcount) {
(*refcount)++;
return0;
}
refcount=klp_shadow_alloc(NULL, KLP_SHADOW_CPU_BUGS_COUNT,
sizeof(*refcount), GFP_KERNEL,
NULL, NULL);
if (WARN_ON(!refcount))
return-ENOMEM;
*refcount=1;
/* * ... typical pre-patch init code here, only runs once, * assuming there isn't a problem that triggers the error * path below ... */return0;
/* ... typical pre-patch error code here ... */err:
klp_shadow_free(NULL, KLP_SHADOW_CPU_BUGS_COUNT, NULL);
returnret;
}
/* * kpatch note: called from a KPATCH_POST_UNPATCH_CALLBACK */staticvoidkpatch_ifu_post_unpatch(void)
{
int*refcount;
/* patch upgrade ref counting - only do exit the last time */refcount=klp_shadow_get(NULL, KLP_SHADOW_CPU_BUGS_COUNT);
if (WARN_ON(!refcount))
return;
(*refcount)--;
if (*refcount>0)
return;
/* * ... typical post-unpatch error code here, only runs once * the refcount is 0 (ie, the last kpatch is unloading) ... */klp_shadow_free(NULL, KLP_SHADOW_CPU_BUGS_COUNT, NULL);
}
Activity
jpoimboe commentedon Nov 20, 2019
Also may need to mention other things discussed like how globals are harmful though I did open another issue for that.
jpoimboe commentedon Nov 20, 2019
Can maybe also document how to add/remove sysfs files to existing dirs?
joe-lawrence commentedon Dec 10, 2019
For the recent TAA mitigation, we added something like this to arch/x86/kernel/cpu/bugs.c, is it generic enough?
joe-lawrence commentedon Dec 10, 2019
For the IFU mitigation, we used a simple shadow-variable refcount mechanism to run pre-patch callbacks on the first kpatch load and the post-unpatch callback on the last kpatch unload:
github-actions commentedon Aug 3, 2023
This issue has been open for 30 days with no activity and no assignee. It will be closed in 7 days unless a comment is added.
jpoimboe commentedon Aug 3, 2023
bump, we should probably do this if we haven't already :-)
github-actions commentedon Sep 3, 2023
This issue has been open for 30 days with no activity and no assignee. It will be closed in 7 days unless a comment is added.
github-actions commentedon Sep 11, 2023
This issue was closed because it was inactive for 7 days after being marked stale.