2018-01-27 01:50:27 +07:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2009-06-15 09:42:57 +07:00
|
|
|
/*
|
2009-12-03 18:49:24 +07:00
|
|
|
* PCIe AER software error injection support.
|
2009-06-15 09:42:57 +07:00
|
|
|
*
|
2019-05-30 20:05:58 +07:00
|
|
|
* Debugging PCIe AER code is quite difficult because it is hard to
|
2009-06-15 09:42:57 +07:00
|
|
|
* trigger various real hardware errors. Software based error
|
|
|
|
* injection can fake almost all kinds of errors with the help of a
|
|
|
|
* user space helper tool aer-inject, which can be gotten from:
|
|
|
|
* http://www.kernel.org/pub/linux/utils/pci/aer-inject/
|
|
|
|
*
|
|
|
|
* Copyright 2009 Intel Corporation.
|
|
|
|
* Huang Ying <ying.huang@intel.com>
|
|
|
|
*/
|
|
|
|
|
2019-05-08 06:24:50 +07:00
|
|
|
#define dev_fmt(fmt) "aer_inject: " fmt
|
|
|
|
|
2009-06-15 09:42:57 +07:00
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/init.h>
|
2020-03-06 20:03:48 +07:00
|
|
|
#include <linux/interrupt.h>
|
2009-06-15 09:42:57 +07:00
|
|
|
#include <linux/miscdevice.h>
|
|
|
|
#include <linux/pci.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 15:04:11 +07:00
|
|
|
#include <linux/slab.h>
|
2009-06-15 09:42:57 +07:00
|
|
|
#include <linux/fs.h>
|
PCI: pcie, aer: checkpatch style cleanup in pcie/aer/*
Before:
drivers/pci/pcie/aer/aer_inject.c
total: 4 errors, 4 warnings, 473 lines checked
drivers/pci/pcie/aer/aerdrv.c
total: 5 errors, 2 warnings, 333 lines checked
drivers/pci/pcie/aer/aerdrv.h
total: 1 errors, 0 warnings, 139 lines checked
drivers/pci/pcie/aer/aerdrv_core.c
total: 4 errors, 3 warnings, 872 lines checked
drivers/pci/pcie/aer/aerdrv_errprint.c
total: 12 errors, 11 warnings, 248 lines checked
After:
drivers/pci/pcie/aer/aer_inject.c
total: 0 errors, 0 warnings, 466 lines checked
drivers/pci/pcie/aer/aerdrv.c
total: 0 errors, 0 warnings, 335 lines checked
drivers/pci/pcie/aer/aerdrv.h
total: 0 errors, 0 warnings, 139 lines checked
drivers/pci/pcie/aer/aerdrv_core.c
total: 0 errors, 0 warnings, 869 lines checked
drivers/pci/pcie/aer/aerdrv_errprint.c
total: 0 errors, 10 warnings, 247 lines checked
Signed-off-by: Hidetoshi Seto <seto.hidetoshi@jp.fujitsu.com>
Reviewed-by: Andrew Patterson <andrew.patterson@hp.com>
Signed-off-by: Jesse Barnes <jbarnes@virtuousgeek.org>
2009-09-07 15:07:29 +07:00
|
|
|
#include <linux/uaccess.h>
|
2009-10-13 02:14:05 +07:00
|
|
|
#include <linux/stddef.h>
|
2016-02-18 19:52:01 +07:00
|
|
|
#include <linux/device.h>
|
2018-06-08 20:40:25 +07:00
|
|
|
|
2018-06-08 20:48:47 +07:00
|
|
|
#include "portdrv.h"
|
2009-06-15 09:42:57 +07:00
|
|
|
|
2011-01-12 03:34:35 +07:00
|
|
|
/* Override the existing corrected and uncorrected error masks */
|
2012-01-13 06:02:20 +07:00
|
|
|
static bool aer_mask_override;
|
2011-01-12 03:34:35 +07:00
|
|
|
module_param(aer_mask_override, bool, 0);
|
|
|
|
|
PCI: pcie, aer: checkpatch style cleanup in pcie/aer/*
Before:
drivers/pci/pcie/aer/aer_inject.c
total: 4 errors, 4 warnings, 473 lines checked
drivers/pci/pcie/aer/aerdrv.c
total: 5 errors, 2 warnings, 333 lines checked
drivers/pci/pcie/aer/aerdrv.h
total: 1 errors, 0 warnings, 139 lines checked
drivers/pci/pcie/aer/aerdrv_core.c
total: 4 errors, 3 warnings, 872 lines checked
drivers/pci/pcie/aer/aerdrv_errprint.c
total: 12 errors, 11 warnings, 248 lines checked
After:
drivers/pci/pcie/aer/aer_inject.c
total: 0 errors, 0 warnings, 466 lines checked
drivers/pci/pcie/aer/aerdrv.c
total: 0 errors, 0 warnings, 335 lines checked
drivers/pci/pcie/aer/aerdrv.h
total: 0 errors, 0 warnings, 139 lines checked
drivers/pci/pcie/aer/aerdrv_core.c
total: 0 errors, 0 warnings, 869 lines checked
drivers/pci/pcie/aer/aerdrv_errprint.c
total: 0 errors, 10 warnings, 247 lines checked
Signed-off-by: Hidetoshi Seto <seto.hidetoshi@jp.fujitsu.com>
Reviewed-by: Andrew Patterson <andrew.patterson@hp.com>
Signed-off-by: Jesse Barnes <jbarnes@virtuousgeek.org>
2009-09-07 15:07:29 +07:00
|
|
|
struct aer_error_inj {
|
2009-06-15 09:42:57 +07:00
|
|
|
u8 bus;
|
|
|
|
u8 dev;
|
|
|
|
u8 fn;
|
|
|
|
u32 uncor_status;
|
|
|
|
u32 cor_status;
|
|
|
|
u32 header_log0;
|
|
|
|
u32 header_log1;
|
|
|
|
u32 header_log2;
|
|
|
|
u32 header_log3;
|
2016-01-13 03:18:09 +07:00
|
|
|
u32 domain;
|
2009-06-15 09:42:57 +07:00
|
|
|
};
|
|
|
|
|
PCI: pcie, aer: checkpatch style cleanup in pcie/aer/*
Before:
drivers/pci/pcie/aer/aer_inject.c
total: 4 errors, 4 warnings, 473 lines checked
drivers/pci/pcie/aer/aerdrv.c
total: 5 errors, 2 warnings, 333 lines checked
drivers/pci/pcie/aer/aerdrv.h
total: 1 errors, 0 warnings, 139 lines checked
drivers/pci/pcie/aer/aerdrv_core.c
total: 4 errors, 3 warnings, 872 lines checked
drivers/pci/pcie/aer/aerdrv_errprint.c
total: 12 errors, 11 warnings, 248 lines checked
After:
drivers/pci/pcie/aer/aer_inject.c
total: 0 errors, 0 warnings, 466 lines checked
drivers/pci/pcie/aer/aerdrv.c
total: 0 errors, 0 warnings, 335 lines checked
drivers/pci/pcie/aer/aerdrv.h
total: 0 errors, 0 warnings, 139 lines checked
drivers/pci/pcie/aer/aerdrv_core.c
total: 0 errors, 0 warnings, 869 lines checked
drivers/pci/pcie/aer/aerdrv_errprint.c
total: 0 errors, 10 warnings, 247 lines checked
Signed-off-by: Hidetoshi Seto <seto.hidetoshi@jp.fujitsu.com>
Reviewed-by: Andrew Patterson <andrew.patterson@hp.com>
Signed-off-by: Jesse Barnes <jbarnes@virtuousgeek.org>
2009-09-07 15:07:29 +07:00
|
|
|
struct aer_error {
|
2009-06-15 09:42:57 +07:00
|
|
|
struct list_head list;
|
2016-01-13 03:18:09 +07:00
|
|
|
u32 domain;
|
2009-06-15 09:42:57 +07:00
|
|
|
unsigned int bus;
|
|
|
|
unsigned int devfn;
|
|
|
|
int pos_cap_err;
|
|
|
|
|
|
|
|
u32 uncor_status;
|
|
|
|
u32 cor_status;
|
|
|
|
u32 header_log0;
|
|
|
|
u32 header_log1;
|
|
|
|
u32 header_log2;
|
|
|
|
u32 header_log3;
|
|
|
|
u32 root_status;
|
|
|
|
u32 source_id;
|
|
|
|
};
|
|
|
|
|
PCI: pcie, aer: checkpatch style cleanup in pcie/aer/*
Before:
drivers/pci/pcie/aer/aer_inject.c
total: 4 errors, 4 warnings, 473 lines checked
drivers/pci/pcie/aer/aerdrv.c
total: 5 errors, 2 warnings, 333 lines checked
drivers/pci/pcie/aer/aerdrv.h
total: 1 errors, 0 warnings, 139 lines checked
drivers/pci/pcie/aer/aerdrv_core.c
total: 4 errors, 3 warnings, 872 lines checked
drivers/pci/pcie/aer/aerdrv_errprint.c
total: 12 errors, 11 warnings, 248 lines checked
After:
drivers/pci/pcie/aer/aer_inject.c
total: 0 errors, 0 warnings, 466 lines checked
drivers/pci/pcie/aer/aerdrv.c
total: 0 errors, 0 warnings, 335 lines checked
drivers/pci/pcie/aer/aerdrv.h
total: 0 errors, 0 warnings, 139 lines checked
drivers/pci/pcie/aer/aerdrv_core.c
total: 0 errors, 0 warnings, 869 lines checked
drivers/pci/pcie/aer/aerdrv_errprint.c
total: 0 errors, 10 warnings, 247 lines checked
Signed-off-by: Hidetoshi Seto <seto.hidetoshi@jp.fujitsu.com>
Reviewed-by: Andrew Patterson <andrew.patterson@hp.com>
Signed-off-by: Jesse Barnes <jbarnes@virtuousgeek.org>
2009-09-07 15:07:29 +07:00
|
|
|
struct pci_bus_ops {
|
2009-06-15 09:42:57 +07:00
|
|
|
struct list_head list;
|
|
|
|
struct pci_bus *bus;
|
|
|
|
struct pci_ops *ops;
|
|
|
|
};
|
|
|
|
|
|
|
|
static LIST_HEAD(einjected);
|
|
|
|
|
|
|
|
static LIST_HEAD(pci_bus_ops_list);
|
|
|
|
|
|
|
|
/* Protect einjected and pci_bus_ops_list */
|
|
|
|
static DEFINE_SPINLOCK(inject_lock);
|
|
|
|
|
2016-01-13 03:18:09 +07:00
|
|
|
static void aer_error_init(struct aer_error *err, u32 domain,
|
2009-10-13 02:14:05 +07:00
|
|
|
unsigned int bus, unsigned int devfn,
|
|
|
|
int pos_cap_err)
|
2009-06-15 09:42:57 +07:00
|
|
|
{
|
|
|
|
INIT_LIST_HEAD(&err->list);
|
2009-10-13 02:14:05 +07:00
|
|
|
err->domain = domain;
|
2009-06-15 09:42:57 +07:00
|
|
|
err->bus = bus;
|
|
|
|
err->devfn = devfn;
|
|
|
|
err->pos_cap_err = pos_cap_err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* inject_lock must be held before calling */
|
2016-01-13 03:18:09 +07:00
|
|
|
static struct aer_error *__find_aer_error(u32 domain, unsigned int bus,
|
2009-10-13 02:14:05 +07:00
|
|
|
unsigned int devfn)
|
2009-06-15 09:42:57 +07:00
|
|
|
{
|
|
|
|
struct aer_error *err;
|
|
|
|
|
|
|
|
list_for_each_entry(err, &einjected, list) {
|
2009-10-13 02:14:05 +07:00
|
|
|
if (domain == err->domain &&
|
|
|
|
bus == err->bus &&
|
|
|
|
devfn == err->devfn)
|
2009-06-15 09:42:57 +07:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* inject_lock must be held before calling */
|
|
|
|
static struct aer_error *__find_aer_error_by_dev(struct pci_dev *dev)
|
|
|
|
{
|
2009-10-13 02:14:05 +07:00
|
|
|
int domain = pci_domain_nr(dev->bus);
|
|
|
|
if (domain < 0)
|
|
|
|
return NULL;
|
2016-01-13 03:18:09 +07:00
|
|
|
return __find_aer_error(domain, dev->bus->number, dev->devfn);
|
2009-06-15 09:42:57 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* inject_lock must be held before calling */
|
|
|
|
static struct pci_ops *__find_pci_bus_ops(struct pci_bus *bus)
|
|
|
|
{
|
|
|
|
struct pci_bus_ops *bus_ops;
|
|
|
|
|
|
|
|
list_for_each_entry(bus_ops, &pci_bus_ops_list, list) {
|
|
|
|
if (bus_ops->bus == bus)
|
|
|
|
return bus_ops->ops;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct pci_bus_ops *pci_bus_ops_pop(void)
|
|
|
|
{
|
|
|
|
unsigned long flags;
|
2016-01-22 21:50:19 +07:00
|
|
|
struct pci_bus_ops *bus_ops;
|
2009-06-15 09:42:57 +07:00
|
|
|
|
|
|
|
spin_lock_irqsave(&inject_lock, flags);
|
2016-01-22 21:50:19 +07:00
|
|
|
bus_ops = list_first_entry_or_null(&pci_bus_ops_list,
|
|
|
|
struct pci_bus_ops, list);
|
|
|
|
if (bus_ops)
|
|
|
|
list_del(&bus_ops->list);
|
2009-06-15 09:42:57 +07:00
|
|
|
spin_unlock_irqrestore(&inject_lock, flags);
|
|
|
|
return bus_ops;
|
|
|
|
}
|
|
|
|
|
|
|
|
static u32 *find_pci_config_dword(struct aer_error *err, int where,
|
|
|
|
int *prw1cs)
|
|
|
|
{
|
|
|
|
int rw1cs = 0;
|
|
|
|
u32 *target = NULL;
|
|
|
|
|
|
|
|
if (err->pos_cap_err == -1)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
switch (where - err->pos_cap_err) {
|
|
|
|
case PCI_ERR_UNCOR_STATUS:
|
|
|
|
target = &err->uncor_status;
|
|
|
|
rw1cs = 1;
|
|
|
|
break;
|
|
|
|
case PCI_ERR_COR_STATUS:
|
|
|
|
target = &err->cor_status;
|
|
|
|
rw1cs = 1;
|
|
|
|
break;
|
|
|
|
case PCI_ERR_HEADER_LOG:
|
|
|
|
target = &err->header_log0;
|
|
|
|
break;
|
|
|
|
case PCI_ERR_HEADER_LOG+4:
|
|
|
|
target = &err->header_log1;
|
|
|
|
break;
|
|
|
|
case PCI_ERR_HEADER_LOG+8:
|
PCI: pcie, aer: checkpatch style cleanup in pcie/aer/*
Before:
drivers/pci/pcie/aer/aer_inject.c
total: 4 errors, 4 warnings, 473 lines checked
drivers/pci/pcie/aer/aerdrv.c
total: 5 errors, 2 warnings, 333 lines checked
drivers/pci/pcie/aer/aerdrv.h
total: 1 errors, 0 warnings, 139 lines checked
drivers/pci/pcie/aer/aerdrv_core.c
total: 4 errors, 3 warnings, 872 lines checked
drivers/pci/pcie/aer/aerdrv_errprint.c
total: 12 errors, 11 warnings, 248 lines checked
After:
drivers/pci/pcie/aer/aer_inject.c
total: 0 errors, 0 warnings, 466 lines checked
drivers/pci/pcie/aer/aerdrv.c
total: 0 errors, 0 warnings, 335 lines checked
drivers/pci/pcie/aer/aerdrv.h
total: 0 errors, 0 warnings, 139 lines checked
drivers/pci/pcie/aer/aerdrv_core.c
total: 0 errors, 0 warnings, 869 lines checked
drivers/pci/pcie/aer/aerdrv_errprint.c
total: 0 errors, 10 warnings, 247 lines checked
Signed-off-by: Hidetoshi Seto <seto.hidetoshi@jp.fujitsu.com>
Reviewed-by: Andrew Patterson <andrew.patterson@hp.com>
Signed-off-by: Jesse Barnes <jbarnes@virtuousgeek.org>
2009-09-07 15:07:29 +07:00
|
|
|
target = &err->header_log2;
|
2009-06-15 09:42:57 +07:00
|
|
|
break;
|
|
|
|
case PCI_ERR_HEADER_LOG+12:
|
|
|
|
target = &err->header_log3;
|
|
|
|
break;
|
|
|
|
case PCI_ERR_ROOT_STATUS:
|
|
|
|
target = &err->root_status;
|
|
|
|
rw1cs = 1;
|
|
|
|
break;
|
2010-04-15 11:17:33 +07:00
|
|
|
case PCI_ERR_ROOT_ERR_SRC:
|
2009-06-15 09:42:57 +07:00
|
|
|
target = &err->source_id;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (prw1cs)
|
|
|
|
*prw1cs = rw1cs;
|
|
|
|
return target;
|
|
|
|
}
|
|
|
|
|
2018-10-12 01:34:12 +07:00
|
|
|
static int aer_inj_read(struct pci_bus *bus, unsigned int devfn, int where,
|
|
|
|
int size, u32 *val)
|
|
|
|
{
|
|
|
|
struct pci_ops *ops, *my_ops;
|
|
|
|
int rv;
|
|
|
|
|
|
|
|
ops = __find_pci_bus_ops(bus);
|
|
|
|
if (!ops)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
my_ops = bus->ops;
|
|
|
|
bus->ops = ops;
|
|
|
|
rv = ops->read(bus, devfn, where, size, val);
|
|
|
|
bus->ops = my_ops;
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int aer_inj_write(struct pci_bus *bus, unsigned int devfn, int where,
|
|
|
|
int size, u32 val)
|
|
|
|
{
|
|
|
|
struct pci_ops *ops, *my_ops;
|
|
|
|
int rv;
|
|
|
|
|
|
|
|
ops = __find_pci_bus_ops(bus);
|
|
|
|
if (!ops)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
my_ops = bus->ops;
|
|
|
|
bus->ops = ops;
|
|
|
|
rv = ops->write(bus, devfn, where, size, val);
|
|
|
|
bus->ops = my_ops;
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2016-02-05 03:02:45 +07:00
|
|
|
static int aer_inj_read_config(struct pci_bus *bus, unsigned int devfn,
|
|
|
|
int where, int size, u32 *val)
|
2009-06-15 09:42:57 +07:00
|
|
|
{
|
|
|
|
u32 *sim;
|
|
|
|
struct aer_error *err;
|
|
|
|
unsigned long flags;
|
2009-10-13 02:14:05 +07:00
|
|
|
int domain;
|
2015-12-23 04:44:51 +07:00
|
|
|
int rv;
|
2009-06-15 09:42:57 +07:00
|
|
|
|
|
|
|
spin_lock_irqsave(&inject_lock, flags);
|
|
|
|
if (size != sizeof(u32))
|
|
|
|
goto out;
|
2009-10-13 02:14:05 +07:00
|
|
|
domain = pci_domain_nr(bus);
|
|
|
|
if (domain < 0)
|
|
|
|
goto out;
|
2016-01-13 03:18:09 +07:00
|
|
|
err = __find_aer_error(domain, bus->number, devfn);
|
2009-06-15 09:42:57 +07:00
|
|
|
if (!err)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
sim = find_pci_config_dword(err, where, NULL);
|
|
|
|
if (sim) {
|
|
|
|
*val = *sim;
|
|
|
|
spin_unlock_irqrestore(&inject_lock, flags);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
out:
|
2018-10-12 01:34:12 +07:00
|
|
|
rv = aer_inj_read(bus, devfn, where, size, val);
|
2009-06-15 09:42:57 +07:00
|
|
|
spin_unlock_irqrestore(&inject_lock, flags);
|
2015-12-23 04:44:51 +07:00
|
|
|
return rv;
|
2009-06-15 09:42:57 +07:00
|
|
|
}
|
|
|
|
|
2016-02-05 03:02:45 +07:00
|
|
|
static int aer_inj_write_config(struct pci_bus *bus, unsigned int devfn,
|
|
|
|
int where, int size, u32 val)
|
2009-06-15 09:42:57 +07:00
|
|
|
{
|
|
|
|
u32 *sim;
|
|
|
|
struct aer_error *err;
|
|
|
|
unsigned long flags;
|
|
|
|
int rw1cs;
|
2009-10-13 02:14:05 +07:00
|
|
|
int domain;
|
2015-12-23 04:44:51 +07:00
|
|
|
int rv;
|
2009-06-15 09:42:57 +07:00
|
|
|
|
|
|
|
spin_lock_irqsave(&inject_lock, flags);
|
|
|
|
if (size != sizeof(u32))
|
|
|
|
goto out;
|
2009-10-13 02:14:05 +07:00
|
|
|
domain = pci_domain_nr(bus);
|
|
|
|
if (domain < 0)
|
|
|
|
goto out;
|
2016-01-13 03:18:09 +07:00
|
|
|
err = __find_aer_error(domain, bus->number, devfn);
|
2009-06-15 09:42:57 +07:00
|
|
|
if (!err)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
sim = find_pci_config_dword(err, where, &rw1cs);
|
|
|
|
if (sim) {
|
|
|
|
if (rw1cs)
|
|
|
|
*sim ^= val;
|
|
|
|
else
|
|
|
|
*sim = val;
|
|
|
|
spin_unlock_irqrestore(&inject_lock, flags);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
out:
|
2018-10-12 01:34:12 +07:00
|
|
|
rv = aer_inj_write(bus, devfn, where, size, val);
|
2009-06-15 09:42:57 +07:00
|
|
|
spin_unlock_irqrestore(&inject_lock, flags);
|
2015-12-23 04:44:51 +07:00
|
|
|
return rv;
|
2009-06-15 09:42:57 +07:00
|
|
|
}
|
|
|
|
|
2016-02-05 03:02:45 +07:00
|
|
|
static struct pci_ops aer_inj_pci_ops = {
|
|
|
|
.read = aer_inj_read_config,
|
|
|
|
.write = aer_inj_write_config,
|
2009-06-15 09:42:57 +07:00
|
|
|
};
|
|
|
|
|
|
|
|
static void pci_bus_ops_init(struct pci_bus_ops *bus_ops,
|
|
|
|
struct pci_bus *bus,
|
|
|
|
struct pci_ops *ops)
|
|
|
|
{
|
|
|
|
INIT_LIST_HEAD(&bus_ops->list);
|
|
|
|
bus_ops->bus = bus;
|
|
|
|
bus_ops->ops = ops;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int pci_bus_set_aer_ops(struct pci_bus *bus)
|
|
|
|
{
|
|
|
|
struct pci_ops *ops;
|
|
|
|
struct pci_bus_ops *bus_ops;
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
bus_ops = kmalloc(sizeof(*bus_ops), GFP_KERNEL);
|
|
|
|
if (!bus_ops)
|
|
|
|
return -ENOMEM;
|
2016-02-05 03:02:45 +07:00
|
|
|
ops = pci_bus_set_ops(bus, &aer_inj_pci_ops);
|
2009-06-15 09:42:57 +07:00
|
|
|
spin_lock_irqsave(&inject_lock, flags);
|
2016-02-05 03:02:45 +07:00
|
|
|
if (ops == &aer_inj_pci_ops)
|
2009-06-15 09:42:57 +07:00
|
|
|
goto out;
|
|
|
|
pci_bus_ops_init(bus_ops, bus, ops);
|
|
|
|
list_add(&bus_ops->list, &pci_bus_ops_list);
|
|
|
|
bus_ops = NULL;
|
|
|
|
out:
|
|
|
|
spin_unlock_irqrestore(&inject_lock, flags);
|
PCI: pcie, aer: checkpatch style cleanup in pcie/aer/*
Before:
drivers/pci/pcie/aer/aer_inject.c
total: 4 errors, 4 warnings, 473 lines checked
drivers/pci/pcie/aer/aerdrv.c
total: 5 errors, 2 warnings, 333 lines checked
drivers/pci/pcie/aer/aerdrv.h
total: 1 errors, 0 warnings, 139 lines checked
drivers/pci/pcie/aer/aerdrv_core.c
total: 4 errors, 3 warnings, 872 lines checked
drivers/pci/pcie/aer/aerdrv_errprint.c
total: 12 errors, 11 warnings, 248 lines checked
After:
drivers/pci/pcie/aer/aer_inject.c
total: 0 errors, 0 warnings, 466 lines checked
drivers/pci/pcie/aer/aerdrv.c
total: 0 errors, 0 warnings, 335 lines checked
drivers/pci/pcie/aer/aerdrv.h
total: 0 errors, 0 warnings, 139 lines checked
drivers/pci/pcie/aer/aerdrv_core.c
total: 0 errors, 0 warnings, 869 lines checked
drivers/pci/pcie/aer/aerdrv_errprint.c
total: 0 errors, 10 warnings, 247 lines checked
Signed-off-by: Hidetoshi Seto <seto.hidetoshi@jp.fujitsu.com>
Reviewed-by: Andrew Patterson <andrew.patterson@hp.com>
Signed-off-by: Jesse Barnes <jbarnes@virtuousgeek.org>
2009-09-07 15:07:29 +07:00
|
|
|
kfree(bus_ops);
|
2009-06-15 09:42:57 +07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int aer_inject(struct aer_error_inj *einj)
|
|
|
|
{
|
|
|
|
struct aer_error *err, *rperr;
|
|
|
|
struct aer_error *err_alloc = NULL, *rperr_alloc = NULL;
|
|
|
|
struct pci_dev *dev, *rpdev;
|
|
|
|
struct pcie_device *edev;
|
2018-10-12 01:34:10 +07:00
|
|
|
struct device *device;
|
2009-06-15 09:42:57 +07:00
|
|
|
unsigned long flags;
|
|
|
|
unsigned int devfn = PCI_DEVFN(einj->dev, einj->fn);
|
|
|
|
int pos_cap_err, rp_pos_cap_err;
|
2011-04-04 16:12:59 +07:00
|
|
|
u32 sever, cor_mask, uncor_mask, cor_mask_orig = 0, uncor_mask_orig = 0;
|
2009-06-15 09:42:57 +07:00
|
|
|
int ret = 0;
|
|
|
|
|
2016-01-13 03:18:09 +07:00
|
|
|
dev = pci_get_domain_bus_and_slot(einj->domain, einj->bus, devfn);
|
2009-06-15 09:42:57 +07:00
|
|
|
if (!dev)
|
2009-10-13 02:14:10 +07:00
|
|
|
return -ENODEV;
|
2009-06-15 09:42:57 +07:00
|
|
|
rpdev = pcie_find_root_port(dev);
|
|
|
|
if (!rpdev) {
|
2019-05-08 06:24:50 +07:00
|
|
|
pci_err(dev, "Root port not found\n");
|
2013-03-20 19:04:43 +07:00
|
|
|
ret = -ENODEV;
|
2009-06-15 09:42:57 +07:00
|
|
|
goto out_put;
|
|
|
|
}
|
|
|
|
|
2018-03-23 04:20:55 +07:00
|
|
|
pos_cap_err = dev->aer_cap;
|
2009-06-15 09:42:57 +07:00
|
|
|
if (!pos_cap_err) {
|
2019-05-08 06:24:50 +07:00
|
|
|
pci_err(dev, "Device doesn't support AER\n");
|
2016-02-18 19:50:45 +07:00
|
|
|
ret = -EPROTONOSUPPORT;
|
2009-06-15 09:42:57 +07:00
|
|
|
goto out_put;
|
|
|
|
}
|
|
|
|
pci_read_config_dword(dev, pos_cap_err + PCI_ERR_UNCOR_SEVER, &sever);
|
2010-01-23 04:06:53 +07:00
|
|
|
pci_read_config_dword(dev, pos_cap_err + PCI_ERR_COR_MASK, &cor_mask);
|
|
|
|
pci_read_config_dword(dev, pos_cap_err + PCI_ERR_UNCOR_MASK,
|
|
|
|
&uncor_mask);
|
2009-06-15 09:42:57 +07:00
|
|
|
|
2018-03-23 04:20:55 +07:00
|
|
|
rp_pos_cap_err = rpdev->aer_cap;
|
2009-06-15 09:42:57 +07:00
|
|
|
if (!rp_pos_cap_err) {
|
2019-05-08 06:24:50 +07:00
|
|
|
pci_err(rpdev, "Root port doesn't support AER\n");
|
2016-02-18 19:50:45 +07:00
|
|
|
ret = -EPROTONOSUPPORT;
|
2009-06-15 09:42:57 +07:00
|
|
|
goto out_put;
|
|
|
|
}
|
|
|
|
|
|
|
|
err_alloc = kzalloc(sizeof(struct aer_error), GFP_KERNEL);
|
|
|
|
if (!err_alloc) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto out_put;
|
|
|
|
}
|
|
|
|
rperr_alloc = kzalloc(sizeof(struct aer_error), GFP_KERNEL);
|
|
|
|
if (!rperr_alloc) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto out_put;
|
|
|
|
}
|
|
|
|
|
2011-01-12 03:34:35 +07:00
|
|
|
if (aer_mask_override) {
|
|
|
|
cor_mask_orig = cor_mask;
|
|
|
|
cor_mask &= !(einj->cor_status);
|
|
|
|
pci_write_config_dword(dev, pos_cap_err + PCI_ERR_COR_MASK,
|
|
|
|
cor_mask);
|
|
|
|
|
|
|
|
uncor_mask_orig = uncor_mask;
|
|
|
|
uncor_mask &= !(einj->uncor_status);
|
|
|
|
pci_write_config_dword(dev, pos_cap_err + PCI_ERR_UNCOR_MASK,
|
|
|
|
uncor_mask);
|
|
|
|
}
|
|
|
|
|
2009-06-15 09:42:57 +07:00
|
|
|
spin_lock_irqsave(&inject_lock, flags);
|
|
|
|
|
|
|
|
err = __find_aer_error_by_dev(dev);
|
|
|
|
if (!err) {
|
|
|
|
err = err_alloc;
|
|
|
|
err_alloc = NULL;
|
2009-10-13 02:14:05 +07:00
|
|
|
aer_error_init(err, einj->domain, einj->bus, devfn,
|
|
|
|
pos_cap_err);
|
2009-06-15 09:42:57 +07:00
|
|
|
list_add(&err->list, &einjected);
|
|
|
|
}
|
|
|
|
err->uncor_status |= einj->uncor_status;
|
|
|
|
err->cor_status |= einj->cor_status;
|
|
|
|
err->header_log0 = einj->header_log0;
|
|
|
|
err->header_log1 = einj->header_log1;
|
|
|
|
err->header_log2 = einj->header_log2;
|
|
|
|
err->header_log3 = einj->header_log3;
|
|
|
|
|
2011-01-12 03:34:35 +07:00
|
|
|
if (!aer_mask_override && einj->cor_status &&
|
|
|
|
!(einj->cor_status & ~cor_mask)) {
|
2009-12-17 20:22:48 +07:00
|
|
|
ret = -EINVAL;
|
2019-05-08 06:24:50 +07:00
|
|
|
pci_warn(dev, "The correctable error(s) is masked by device\n");
|
2009-12-17 20:22:48 +07:00
|
|
|
spin_unlock_irqrestore(&inject_lock, flags);
|
|
|
|
goto out_put;
|
|
|
|
}
|
2011-01-12 03:34:35 +07:00
|
|
|
if (!aer_mask_override && einj->uncor_status &&
|
|
|
|
!(einj->uncor_status & ~uncor_mask)) {
|
2009-12-17 20:22:48 +07:00
|
|
|
ret = -EINVAL;
|
2019-05-08 06:24:50 +07:00
|
|
|
pci_warn(dev, "The uncorrectable error(s) is masked by device\n");
|
2009-12-17 20:22:48 +07:00
|
|
|
spin_unlock_irqrestore(&inject_lock, flags);
|
|
|
|
goto out_put;
|
|
|
|
}
|
|
|
|
|
2009-06-15 09:42:57 +07:00
|
|
|
rperr = __find_aer_error_by_dev(rpdev);
|
|
|
|
if (!rperr) {
|
|
|
|
rperr = rperr_alloc;
|
|
|
|
rperr_alloc = NULL;
|
2009-10-13 02:14:05 +07:00
|
|
|
aer_error_init(rperr, pci_domain_nr(rpdev->bus),
|
|
|
|
rpdev->bus->number, rpdev->devfn,
|
2009-06-15 09:42:57 +07:00
|
|
|
rp_pos_cap_err);
|
|
|
|
list_add(&rperr->list, &einjected);
|
|
|
|
}
|
|
|
|
if (einj->cor_status) {
|
|
|
|
if (rperr->root_status & PCI_ERR_ROOT_COR_RCV)
|
|
|
|
rperr->root_status |= PCI_ERR_ROOT_MULTI_COR_RCV;
|
|
|
|
else
|
|
|
|
rperr->root_status |= PCI_ERR_ROOT_COR_RCV;
|
|
|
|
rperr->source_id &= 0xffff0000;
|
|
|
|
rperr->source_id |= (einj->bus << 8) | devfn;
|
|
|
|
}
|
|
|
|
if (einj->uncor_status) {
|
|
|
|
if (rperr->root_status & PCI_ERR_ROOT_UNCOR_RCV)
|
|
|
|
rperr->root_status |= PCI_ERR_ROOT_MULTI_UNCOR_RCV;
|
|
|
|
if (sever & einj->uncor_status) {
|
|
|
|
rperr->root_status |= PCI_ERR_ROOT_FATAL_RCV;
|
|
|
|
if (!(rperr->root_status & PCI_ERR_ROOT_UNCOR_RCV))
|
|
|
|
rperr->root_status |= PCI_ERR_ROOT_FIRST_FATAL;
|
|
|
|
} else
|
|
|
|
rperr->root_status |= PCI_ERR_ROOT_NONFATAL_RCV;
|
|
|
|
rperr->root_status |= PCI_ERR_ROOT_UNCOR_RCV;
|
|
|
|
rperr->source_id &= 0x0000ffff;
|
|
|
|
rperr->source_id |= ((einj->bus << 8) | devfn) << 16;
|
|
|
|
}
|
|
|
|
spin_unlock_irqrestore(&inject_lock, flags);
|
|
|
|
|
2011-01-12 03:34:35 +07:00
|
|
|
if (aer_mask_override) {
|
|
|
|
pci_write_config_dword(dev, pos_cap_err + PCI_ERR_COR_MASK,
|
|
|
|
cor_mask_orig);
|
|
|
|
pci_write_config_dword(dev, pos_cap_err + PCI_ERR_UNCOR_MASK,
|
|
|
|
uncor_mask_orig);
|
|
|
|
}
|
|
|
|
|
2009-06-15 09:42:57 +07:00
|
|
|
ret = pci_bus_set_aer_ops(dev->bus);
|
|
|
|
if (ret)
|
|
|
|
goto out_put;
|
|
|
|
ret = pci_bus_set_aer_ops(rpdev->bus);
|
|
|
|
if (ret)
|
|
|
|
goto out_put;
|
|
|
|
|
2018-10-12 01:34:10 +07:00
|
|
|
device = pcie_port_find_device(rpdev, PCIE_PORT_SERVICE_AER);
|
|
|
|
if (device) {
|
|
|
|
edev = to_pcie_device(device);
|
2009-12-12 06:42:35 +07:00
|
|
|
if (!get_service_data(edev)) {
|
2019-05-08 06:24:50 +07:00
|
|
|
pci_warn(edev->port, "AER service is not initialized\n");
|
2016-02-18 19:50:45 +07:00
|
|
|
ret = -EPROTONOSUPPORT;
|
2009-12-12 06:42:35 +07:00
|
|
|
goto out_put;
|
|
|
|
}
|
2019-05-08 06:24:50 +07:00
|
|
|
pci_info(edev->port, "Injecting errors %08x/%08x into device %s\n",
|
2016-02-18 19:54:02 +07:00
|
|
|
einj->cor_status, einj->uncor_status, pci_name(dev));
|
2020-03-06 20:03:48 +07:00
|
|
|
ret = irq_inject_interrupt(edev->irq);
|
2016-02-18 19:52:46 +07:00
|
|
|
} else {
|
2019-05-08 06:24:50 +07:00
|
|
|
pci_err(rpdev, "AER device not found\n");
|
2016-02-18 19:50:45 +07:00
|
|
|
ret = -ENODEV;
|
2016-02-18 19:52:46 +07:00
|
|
|
}
|
2009-06-15 09:42:57 +07:00
|
|
|
out_put:
|
PCI: pcie, aer: checkpatch style cleanup in pcie/aer/*
Before:
drivers/pci/pcie/aer/aer_inject.c
total: 4 errors, 4 warnings, 473 lines checked
drivers/pci/pcie/aer/aerdrv.c
total: 5 errors, 2 warnings, 333 lines checked
drivers/pci/pcie/aer/aerdrv.h
total: 1 errors, 0 warnings, 139 lines checked
drivers/pci/pcie/aer/aerdrv_core.c
total: 4 errors, 3 warnings, 872 lines checked
drivers/pci/pcie/aer/aerdrv_errprint.c
total: 12 errors, 11 warnings, 248 lines checked
After:
drivers/pci/pcie/aer/aer_inject.c
total: 0 errors, 0 warnings, 466 lines checked
drivers/pci/pcie/aer/aerdrv.c
total: 0 errors, 0 warnings, 335 lines checked
drivers/pci/pcie/aer/aerdrv.h
total: 0 errors, 0 warnings, 139 lines checked
drivers/pci/pcie/aer/aerdrv_core.c
total: 0 errors, 0 warnings, 869 lines checked
drivers/pci/pcie/aer/aerdrv_errprint.c
total: 0 errors, 10 warnings, 247 lines checked
Signed-off-by: Hidetoshi Seto <seto.hidetoshi@jp.fujitsu.com>
Reviewed-by: Andrew Patterson <andrew.patterson@hp.com>
Signed-off-by: Jesse Barnes <jbarnes@virtuousgeek.org>
2009-09-07 15:07:29 +07:00
|
|
|
kfree(err_alloc);
|
|
|
|
kfree(rperr_alloc);
|
2009-06-15 09:42:57 +07:00
|
|
|
pci_dev_put(dev);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t aer_inject_write(struct file *filp, const char __user *ubuf,
|
|
|
|
size_t usize, loff_t *off)
|
|
|
|
{
|
|
|
|
struct aer_error_inj einj;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (!capable(CAP_SYS_ADMIN))
|
|
|
|
return -EPERM;
|
2009-10-13 02:14:05 +07:00
|
|
|
if (usize < offsetof(struct aer_error_inj, domain) ||
|
|
|
|
usize > sizeof(einj))
|
2009-06-15 09:42:57 +07:00
|
|
|
return -EINVAL;
|
|
|
|
|
2009-10-13 02:14:05 +07:00
|
|
|
memset(&einj, 0, sizeof(einj));
|
2009-06-15 09:42:57 +07:00
|
|
|
if (copy_from_user(&einj, ubuf, usize))
|
|
|
|
return -EFAULT;
|
|
|
|
|
|
|
|
ret = aer_inject(&einj);
|
|
|
|
return ret ? ret : usize;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct file_operations aer_inject_fops = {
|
|
|
|
.write = aer_inject_write,
|
|
|
|
.owner = THIS_MODULE,
|
llseek: automatically add .llseek fop
All file_operations should get a .llseek operation so we can make
nonseekable_open the default for future file operations without a
.llseek pointer.
The three cases that we can automatically detect are no_llseek, seq_lseek
and default_llseek. For cases where we can we can automatically prove that
the file offset is always ignored, we use noop_llseek, which maintains
the current behavior of not returning an error from a seek.
New drivers should normally not use noop_llseek but instead use no_llseek
and call nonseekable_open at open time. Existing drivers can be converted
to do the same when the maintainer knows for certain that no user code
relies on calling seek on the device file.
The generated code is often incorrectly indented and right now contains
comments that clarify for each added line why a specific variant was
chosen. In the version that gets submitted upstream, the comments will
be gone and I will manually fix the indentation, because there does not
seem to be a way to do that using coccinelle.
Some amount of new code is currently sitting in linux-next that should get
the same modifications, which I will do at the end of the merge window.
Many thanks to Julia Lawall for helping me learn to write a semantic
patch that does all this.
===== begin semantic patch =====
// This adds an llseek= method to all file operations,
// as a preparation for making no_llseek the default.
//
// The rules are
// - use no_llseek explicitly if we do nonseekable_open
// - use seq_lseek for sequential files
// - use default_llseek if we know we access f_pos
// - use noop_llseek if we know we don't access f_pos,
// but we still want to allow users to call lseek
//
@ open1 exists @
identifier nested_open;
@@
nested_open(...)
{
<+...
nonseekable_open(...)
...+>
}
@ open exists@
identifier open_f;
identifier i, f;
identifier open1.nested_open;
@@
int open_f(struct inode *i, struct file *f)
{
<+...
(
nonseekable_open(...)
|
nested_open(...)
)
...+>
}
@ read disable optional_qualifier exists @
identifier read_f;
identifier f, p, s, off;
type ssize_t, size_t, loff_t;
expression E;
identifier func;
@@
ssize_t read_f(struct file *f, char *p, size_t s, loff_t *off)
{
<+...
(
*off = E
|
*off += E
|
func(..., off, ...)
|
E = *off
)
...+>
}
@ read_no_fpos disable optional_qualifier exists @
identifier read_f;
identifier f, p, s, off;
type ssize_t, size_t, loff_t;
@@
ssize_t read_f(struct file *f, char *p, size_t s, loff_t *off)
{
... when != off
}
@ write @
identifier write_f;
identifier f, p, s, off;
type ssize_t, size_t, loff_t;
expression E;
identifier func;
@@
ssize_t write_f(struct file *f, const char *p, size_t s, loff_t *off)
{
<+...
(
*off = E
|
*off += E
|
func(..., off, ...)
|
E = *off
)
...+>
}
@ write_no_fpos @
identifier write_f;
identifier f, p, s, off;
type ssize_t, size_t, loff_t;
@@
ssize_t write_f(struct file *f, const char *p, size_t s, loff_t *off)
{
... when != off
}
@ fops0 @
identifier fops;
@@
struct file_operations fops = {
...
};
@ has_llseek depends on fops0 @
identifier fops0.fops;
identifier llseek_f;
@@
struct file_operations fops = {
...
.llseek = llseek_f,
...
};
@ has_read depends on fops0 @
identifier fops0.fops;
identifier read_f;
@@
struct file_operations fops = {
...
.read = read_f,
...
};
@ has_write depends on fops0 @
identifier fops0.fops;
identifier write_f;
@@
struct file_operations fops = {
...
.write = write_f,
...
};
@ has_open depends on fops0 @
identifier fops0.fops;
identifier open_f;
@@
struct file_operations fops = {
...
.open = open_f,
...
};
// use no_llseek if we call nonseekable_open
////////////////////////////////////////////
@ nonseekable1 depends on !has_llseek && has_open @
identifier fops0.fops;
identifier nso ~= "nonseekable_open";
@@
struct file_operations fops = {
... .open = nso, ...
+.llseek = no_llseek, /* nonseekable */
};
@ nonseekable2 depends on !has_llseek @
identifier fops0.fops;
identifier open.open_f;
@@
struct file_operations fops = {
... .open = open_f, ...
+.llseek = no_llseek, /* open uses nonseekable */
};
// use seq_lseek for sequential files
/////////////////////////////////////
@ seq depends on !has_llseek @
identifier fops0.fops;
identifier sr ~= "seq_read";
@@
struct file_operations fops = {
... .read = sr, ...
+.llseek = seq_lseek, /* we have seq_read */
};
// use default_llseek if there is a readdir
///////////////////////////////////////////
@ fops1 depends on !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier readdir_e;
@@
// any other fop is used that changes pos
struct file_operations fops = {
... .readdir = readdir_e, ...
+.llseek = default_llseek, /* readdir is present */
};
// use default_llseek if at least one of read/write touches f_pos
/////////////////////////////////////////////////////////////////
@ fops2 depends on !fops1 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier read.read_f;
@@
// read fops use offset
struct file_operations fops = {
... .read = read_f, ...
+.llseek = default_llseek, /* read accesses f_pos */
};
@ fops3 depends on !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier write.write_f;
@@
// write fops use offset
struct file_operations fops = {
... .write = write_f, ...
+ .llseek = default_llseek, /* write accesses f_pos */
};
// Use noop_llseek if neither read nor write accesses f_pos
///////////////////////////////////////////////////////////
@ fops4 depends on !fops1 && !fops2 && !fops3 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier read_no_fpos.read_f;
identifier write_no_fpos.write_f;
@@
// write fops use offset
struct file_operations fops = {
...
.write = write_f,
.read = read_f,
...
+.llseek = noop_llseek, /* read and write both use no f_pos */
};
@ depends on has_write && !has_read && !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier write_no_fpos.write_f;
@@
struct file_operations fops = {
... .write = write_f, ...
+.llseek = noop_llseek, /* write uses no f_pos */
};
@ depends on has_read && !has_write && !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier read_no_fpos.read_f;
@@
struct file_operations fops = {
... .read = read_f, ...
+.llseek = noop_llseek, /* read uses no f_pos */
};
@ depends on !has_read && !has_write && !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
@@
struct file_operations fops = {
...
+.llseek = noop_llseek, /* no read or write fn */
};
===== End semantic patch =====
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Cc: Julia Lawall <julia@diku.dk>
Cc: Christoph Hellwig <hch@infradead.org>
2010-08-15 23:52:59 +07:00
|
|
|
.llseek = noop_llseek,
|
2009-06-15 09:42:57 +07:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct miscdevice aer_inject_device = {
|
|
|
|
.minor = MISC_DYNAMIC_MINOR,
|
|
|
|
.name = "aer_inject",
|
|
|
|
.fops = &aer_inject_fops,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int __init aer_inject_init(void)
|
|
|
|
{
|
|
|
|
return misc_register(&aer_inject_device);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit aer_inject_exit(void)
|
|
|
|
{
|
|
|
|
struct aer_error *err, *err_next;
|
|
|
|
unsigned long flags;
|
|
|
|
struct pci_bus_ops *bus_ops;
|
|
|
|
|
|
|
|
misc_deregister(&aer_inject_device);
|
|
|
|
|
|
|
|
while ((bus_ops = pci_bus_ops_pop())) {
|
|
|
|
pci_bus_set_ops(bus_ops->bus, bus_ops->ops);
|
|
|
|
kfree(bus_ops);
|
|
|
|
}
|
|
|
|
|
|
|
|
spin_lock_irqsave(&inject_lock, flags);
|
2009-10-13 02:14:15 +07:00
|
|
|
list_for_each_entry_safe(err, err_next, &einjected, list) {
|
2009-06-15 09:42:57 +07:00
|
|
|
list_del(&err->list);
|
|
|
|
kfree(err);
|
|
|
|
}
|
|
|
|
spin_unlock_irqrestore(&inject_lock, flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
module_init(aer_inject_init);
|
|
|
|
module_exit(aer_inject_exit);
|
|
|
|
|
2009-12-04 00:00:10 +07:00
|
|
|
MODULE_DESCRIPTION("PCIe AER software error injector");
|
2009-06-15 09:42:57 +07:00
|
|
|
MODULE_LICENSE("GPL");
|