Skip to content

Commit

Permalink
edac: lock module owner to avoid error report conflicts
Browse files Browse the repository at this point in the history
APEI GHES and i7core_edac/sb_edac currently can be loaded at
the same time, but those are Highlander modules:
	"There can be only one".

There are two reasons for that:

1) Each driver assumes that it is the only one registering at
   the EDAC core, as it is driver's responsibility to number
   the memory controllers, and all of them start from 0;

2) If BIOS is handling the memory errors, the OS can't also be
   doing it, as one will mangle with the other.

So, we need to add an module owner's lock at the EDAC core,
in order to avoid having two different modules handling memory
errors at the same time. The best way for doing this lock seems
to use the driver's name, as this is unique, and won't require
changes on every driver.

Signed-off-by: Mauro Carvalho Chehab <[email protected]>
  • Loading branch information
Mauro Carvalho Chehab committed Feb 21, 2013
1 parent c2c93db commit 80cc7d8
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions drivers/edac/edac_mc.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@
static DEFINE_MUTEX(mem_ctls_mutex);
static LIST_HEAD(mc_devices);

/*
* Used to lock EDAC MC to just one module, avoiding two drivers e. g.
* apei/ghes and i7core_edac to be used at the same time.
*/
static void const *edac_mc_owner;

unsigned edac_dimm_info_location(struct dimm_info *dimm, char *buf,
unsigned len)
{
Expand Down Expand Up @@ -659,16 +665,18 @@ static int add_mc_to_global_list(struct mem_ctl_info *mci)
return 1;
}

static void del_mc_from_global_list(struct mem_ctl_info *mci)
static int del_mc_from_global_list(struct mem_ctl_info *mci)
{
atomic_dec(&edac_handlers);
int handlers = atomic_dec_return(&edac_handlers);
list_del_rcu(&mci->link);

/* these are for safe removal of devices from global list while
* NMI handlers may be traversing list
*/
synchronize_rcu();
INIT_LIST_HEAD(&mci->link);

return handlers;
}

/**
Expand Down Expand Up @@ -712,6 +720,7 @@ EXPORT_SYMBOL(edac_mc_find);
/* FIXME - should a warning be printed if no error detection? correction? */
int edac_mc_add_mc(struct mem_ctl_info *mci)
{
int ret = -EINVAL;
edac_dbg(0, "\n");

#ifdef CONFIG_EDAC_DEBUG
Expand Down Expand Up @@ -742,6 +751,11 @@ int edac_mc_add_mc(struct mem_ctl_info *mci)
#endif
mutex_lock(&mem_ctls_mutex);

if (edac_mc_owner && edac_mc_owner != mci->mod_name) {
ret = -EPERM;
goto fail0;
}

if (add_mc_to_global_list(mci))
goto fail0;

Expand All @@ -768,6 +782,8 @@ int edac_mc_add_mc(struct mem_ctl_info *mci)
edac_mc_printk(mci, KERN_INFO, "Giving out device to '%s' '%s':"
" DEV %s\n", mci->mod_name, mci->ctl_name, edac_dev_name(mci));

edac_mc_owner = mci->mod_name;

mutex_unlock(&mem_ctls_mutex);
return 0;

Expand All @@ -776,7 +792,7 @@ int edac_mc_add_mc(struct mem_ctl_info *mci)

fail0:
mutex_unlock(&mem_ctls_mutex);
return 1;
return ret;
}
EXPORT_SYMBOL_GPL(edac_mc_add_mc);

Expand All @@ -802,7 +818,8 @@ struct mem_ctl_info *edac_mc_del_mc(struct device *dev)
return NULL;
}

del_mc_from_global_list(mci);
if (!del_mc_from_global_list(mci))
edac_mc_owner = NULL;
mutex_unlock(&mem_ctls_mutex);

/* flush workq processes */
Expand Down

0 comments on commit 80cc7d8

Please sign in to comment.