i2c: gpio: fault-injector: add two new injectors
Subsystems (3)
Wolfram Sang
maintainerv2 cover i2c: gpio: fault-injector: add two new injectors
After sending out the 'lose_arbitration' injector as RFC, here is now a patch series with that injector updated and another one added.
The first one successfully triggers an ARBITRATION_LOST interrupt on my Renesas Lager board (R-Car H2). The other one leaves SCL low on the same board because of the Kernel panic, so reboot handlers need to handle that. But more interestingly, it causes a deadlock because it needs this I2C adapter to trigger a reboot via the PMIC. This is a good testcase for the soon to be developed master_xfer_atomic callback for the I2C core.
Changes since V1:
* fixed a typo in the docs and used UTF8 for µs there
* limit user-supplied delay to 100ms
* don't overwrite existing errorcode if gpiod_direction_output() suceeds
No error propagation when we receive a signal. This is all handled seperately in other layers as further tests have shown.
Wolfram Sang (2):
i2c: gpio: fault-injector: add 'lose_arbitration' injector
i2c: gpio: fault-injector: add 'inject_panic' injector
Documentation/i2c/gpio-fault-injection | 51 ++++++++++++++++ drivers/i2c/busses/i2c-gpio.c | 103 +++++++++++++++++++++++++++++++++ 2 files changed, 154 insertions(+)
Signature · 1 line
2.11.0
Wolfram Sang
maintainerPATCH v2 1/2 i2c: gpio: fault-injector: add 'lose_arbitration' injector
Add a fault injector simulating 'arbitration lost' from multi-master setups. Read the docs for its usage.
A helper function for future fault injectors using SCL interrupts is created to achieve this.
--- Documentation/i2c/gpio-fault-injection | 25 ++++++++++++ drivers/i2c/busses/i2c-gpio.c | 74 ++++++++++++++++++++++++++++++++++ 2 files changed, 99 insertions(+)
Documentation/i2c/gpio-fault-injection +25 -0
@@ -83,3 +83,28 @@ This is why bus recovery (up to 9 clock pulses) must either check SDA or send additional STOP conditions to ensure the bus has been released. Otherwise random data will be written to a device! +Lost arbitration +================ + +Here, we want to simulate the condition where the master under test loses the +bus arbitration against another master in a multi-master setup. + +"lose_arbitration" +------------------ + +This file is write only and you need to write the duration of the arbitration +intereference (in µs, maximum is 100ms). The calling process will then sleep +and wait for the next bus clock. The process is interruptible, though. + +Arbitration lost is achieved by waiting for SCL going down by the master under +test and then pulling SDA low for some time. So, the I2C address sent out +should be corrupted and that should be detected properly. That means that the +address sent out should have a lot of '1' bits to be able to detect corruption. +There doesn't need to be a device at this address because arbitration lost +should be detected beforehand. Also note, that SCL going down is monitored +using interrupts, so the interrupt latency might cause the first bits to be not +corrupted. A good starting point for using this fault injector on an otherwise +idle bus is: + +# echo 200 > lose_arbitration & +# i2cget -y <bus_to_test> 0x3f
drivers/i2c/busses/i2c-gpio.c +74 -0
108 lines not on this page · raw message
Signature · 1 line
2.11.0
Wolfram Sang
AppliedRe: [PATCH v2 1/2] i2c: gpio: fault-injector: add 'lose_arbitration' injector
Quoted 7 lines · Wolfram Sang
Add a fault injector simulating 'arbitration lost' from multi-master setups. Read the docs for its usage.
A helper function for future fault injectors using SCL interrupts is created to achieve this.
Signed-off-by Wolfram Sang <[email protected]>
Applied to for-next, thanks!
Wolfram Sang
maintainerPATCH v2 2/2 i2c: gpio: fault-injector: add 'inject_panic' injector
In reply to Wolfram SangAdd a fault injector simulating a Kernel panic happening after starting a transfer. Read the docs for its usage.
--- Documentation/i2c/gpio-fault-injection | 26 ++++++++++++++++++++++++++ drivers/i2c/busses/i2c-gpio.c | 31 ++++++++++++++++++++++++++++++- 2 files changed, 56 insertions(+), 1 deletion(-)
Documentation/i2c/gpio-fault-injection +26 -0
@@ -108,3 +108,29 @@ idle bus is: # echo 200 > lose_arbitration & # i2cget -y <bus_to_test> 0x3f + +Panic during transfer +===================== + +This fault injector will create a Kernel panic once the master under test +started a transfer. This usually means that the state machine of the bus master +driver will be ungracefully interrupted and the bus may end up in an unusual +state. Use this to check if your shutdown/reboot/boot code can handle this +scenario. + +"inject_panic" +-------------- + +This file is write only and you need to write the delay between the detected +start of a transmission and the induced Kernel panic (in µs, maximum is 100ms). +The calling process will then sleep and wait for the next bus clock. The +process is interruptible, though. + +Start of a transfer is detected by waiting for SCL going down by the master +under test. A good starting point for using this fault injector is: + +# echo 0 > inject_panic & +# i2cget -y <bus_to_test> <some_address> + +Note that there doesn't need to be a device listening to the address you are +using. Results may vary depending on that, though.
drivers/i2c/busses/i2c-gpio.c +30 -1
@@ -231,6 +231,32 @@ static int fops_lose_arbitration_set(void *data, u64 duration) }DEFINE_DEBUGFS_ATTRIBUTE (fops_lose_arbitration,NULL , fops_lose_arbitration_set,"%llu\n" ); +static irqreturn_t inject_panic_irq (int irq,void *dev_id) +{ +struct i2c_gpio_private_data *priv = dev_id; + +udelay (priv->scl_irq_data); +panic ("I2C fault injector induced panic" ); + +return IRQ_HANDLED ; +} + +static int fops_inject_panic_set (void *data,u64 duration) +{ +struct i2c_gpio_private_data *priv = data; + +if (duration >100 *1000 ) +return -EINVAL ; + + priv->scl_irq_data = duration; +/* +* Interrupt on falling SCL. This ensures that the master under test has +* really started the transfer. +*/ +return i2c_gpio_fi_act_on_scl_irq (priv, inject_panic_irq); +} +DEFINE_DEBUGFS_ATTRIBUTE (fops_inject_panic,NULL , fops_inject_panic_set,"%llu\n" ); +static void i2c_gpio_fault_injector_init (struct platform_device *pdev) {struct i2c_gpio_private_data *priv =platform_get_drvdata (pdev);
@@ -256,9 +282,12 @@ static void i2c_gpio_fault_injector_init(struct platform_device *pdev) priv, &fops_incomplete_addr_phase);debugfs_create_file_unsafe ("incomplete_write_byte" ,0200 , priv->debug_dir, priv, &fops_incomplete_write_byte); -if (priv->bit_data.getscl) +if (priv->bit_data.getscl) { +debugfs_create_file_unsafe ("inject_panic" ,0200 , priv->debug_dir, + priv, &fops_inject_panic);debugfs_create_file_unsafe ("lose_arbitration" ,0200 , priv->debug_dir, priv, &fops_lose_arbitration); + }debugfs_create_file_unsafe ("scl" ,0600 , priv->debug_dir, priv, &fops_scl);debugfs_create_file_unsafe ("sda" ,0600 , priv->debug_dir, priv, &fops_sda); }
Signature · 1 line
2.11.0
Wolfram Sang
AppliedRe: [PATCH v2 2/2] i2c: gpio: fault-injector: add 'inject_panic' injector
Quoted 4 lines · Wolfram Sang
Add a fault injector simulating a Kernel panic happening after starting a transfer. Read the docs for its usage.
Signed-off-by Wolfram Sang <[email protected]>
Applied to for-next, thanks!