Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1501609

Re: [PATCH 04/10] fault injection: prevent recursive fault injection

From "Hillf Danton" <hillf.zj@alibaba-inc.com>
Newsgroups linux.kernel
Subject Re: [PATCH 04/10] fault injection: prevent recursive fault injection
Date 2016-10-17 06:10 +0200
Message-ID <st7pn-6SP-3@gated-at.bofh.it> (permalink)
References <ssW0V-7I2-3@gated-at.bofh.it> <ssW0W-7I2-15@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


On Sunday, October 16, 2016 11:56 PM Vegard Nossum wrote:
> 
> If something we call in the fail_dump() code path tries to acquire a
> resource that might fail (due to fault injection), then we should not
> try to recurse back into the fault injection code.
> 
> I've seen this happen with the console semaphore in the upcoming
> semaphore trylock fault injection code.
> 
> Cc: Hillf Danton <hillf.zj@alibaba-inc.com>
> Signed-off-by: Vegard Nossum <vegard.nossum@oracle.com>
> ---
>  lib/fault-inject.c | 34 ++++++++++++++++++++++++++++------
>  1 file changed, 28 insertions(+), 6 deletions(-)
> 
> diff --git a/lib/fault-inject.c b/lib/fault-inject.c
> index 6a823a5..adba7c9 100644
> --- a/lib/fault-inject.c
> +++ b/lib/fault-inject.c
> @@ -100,6 +100,33 @@ static inline bool fail_stacktrace(struct fault_attr *attr)
> 
>  #endif /* CONFIG_FAULT_INJECTION_STACKTRACE_FILTER */
> 
> +static DEFINE_PER_CPU(int, fault_active);
> +
> +static bool __fail(struct fault_attr *attr)
> +{
> +	bool ret = false;
> +
> +	/*
> +	 * Prevent recursive fault injection (this could happen if for
> +	 * example printing the fault would itself run some code that
> +	 * could fail)
> +	 */
> +	preempt_disable();
> +	if (unlikely(__this_cpu_inc_return(fault_active) != 1))
> +		goto out;
> +
> +	ret = true;
> +	fail_dump(attr);
> +
> +	if (atomic_read(&attr->times) != -1)
> +		atomic_dec_not_zero(&attr->times);
> +
> +out:
> +	__this_cpu_dec(fault_active);
> +	preempt_enable();

Given no see other patches in this set, I could easily miss 
anything important and correct me please. 

Though added, there are no words in the change log about 
preempt, and my wonder again is: can we add it in contexts
like the fast path of buddy allocator?

thanks
Hillf
> +	return ret;
> +}
> +
>  /*
>   * This code is stolen from failmalloc-1.0
>   * http://www.nongnu.org/failmalloc/
> @@ -134,12 +161,7 @@ bool should_fail(struct fault_attr *attr, ssize_t size)
>  	if (!fail_stacktrace(attr))
>  		return false;
> 
> -	fail_dump(attr);
> -
> -	if (atomic_read(&attr->times) != -1)
> -		atomic_dec_not_zero(&attr->times);
> -
> -	return true;
> +	return __fail(attr);
>  }
>  EXPORT_SYMBOL_GPL(should_fail);
> 
> --
> 2.10.0.479.g221bd91

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH 01/10] fault injection: fix a few documentation errors Vegard Nossum <vegard.nossum@oracle.com> - 2016-10-16 18:00 +0200
  [PATCH 04/10] fault injection: prevent recursive fault injection Vegard Nossum <vegard.nossum@oracle.com> - 2016-10-16 18:00 +0200
    Re: [PATCH 04/10] fault injection: prevent recursive fault injection "Hillf Danton" <hillf.zj@alibaba-inc.com> - 2016-10-17 06:10 +0200
  [PATCH 02/10] fault injection: fix Kconfig menu Vegard Nossum <vegard.nossum@oracle.com> - 2016-10-16 18:00 +0200
    Re: [PATCH 02/10] fault injection: fix Kconfig menu Ulf Hansson <ulf.hansson@linaro.org> - 2016-10-18 11:40 +0200
  [PATCH 05/10] fault injection: mutex_trylock() fault injection Vegard Nossum <vegard.nossum@oracle.com> - 2016-10-16 18:00 +0200
    Re: [PATCH 05/10] fault injection: mutex_trylock() fault injection Peter Zijlstra <peterz@infradead.org> - 2016-10-16 18:30 +0200
  [PATCH 03/10] fault injection: allow FAULT_INJECTION_STACKTRACE_FILTER on X86_64 Vegard Nossum <vegard.nossum@oracle.com> - 2016-10-16 18:00 +0200
  [PATCH 09/10] fault injection: spin_trylock() fault injection Vegard Nossum <vegard.nossum@oracle.com> - 2016-10-16 18:00 +0200
    Re: [PATCH 09/10] fault injection: spin_trylock() fault injection Peter Zijlstra <peterz@infradead.org> - 2016-10-16 18:40 +0200
  [PATCH 10/10] fault injection: inject faults in new/rare callchains Vegard Nossum <vegard.nossum@oracle.com> - 2016-10-16 18:00 +0200
    Re: [PATCH 10/10] fault injection: inject faults in new/rare callchains Akinobu Mita <akinobu.mita@gmail.com> - 2016-10-21 02:40 +0200
  [PATCH 08/10] fault injection: down_{read,write}_trylock() fault injection Vegard Nossum <vegard.nossum@oracle.com> - 2016-10-16 18:00 +0200
    Re: [PATCH 08/10] fault injection: down_{read,write}_trylock() fault  injection Peter Zijlstra <peterz@infradead.org> - 2016-10-16 18:30 +0200
  [PATCH 07/10] fault injection: down_trylock() fault injection Vegard Nossum <vegard.nossum@oracle.com> - 2016-10-16 18:00 +0200
    Re: [PATCH 07/10] fault injection: down_trylock() fault injection Peter Zijlstra <peterz@infradead.org> - 2016-10-16 18:30 +0200

csiph-web