From: Ankita Garg <ankita@in.ibm.com>
To: Josh Hunt <johunt@akamai.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
linux-kernel@vger.kernel.org, Tapan Dhimant <tdhimant@akamai.com>
Subject: Re: [PATCH] lkdtm: Fix race when crashpoint is hit multiple times before checking count
Date: Wed, 15 Jun 2011 18:28:16 +0530 [thread overview]
Message-ID: <20110615125816.GB23151@in.ibm.com> (raw)
In-Reply-To: <1308094827-29684-1-git-send-email-johunt@akamai.com>
Hi,
On Tue, Jun 14, 2011 at 04:40:27PM -0700, Josh Hunt wrote:
> We observed the crash point count going negative in cases where the crash point
> is hit multiple times before the check of "count == 0" is done. Because of this
> we never call lkdtm_do_action(). This patch just adds a spinlock to protect
> count.
>
Good catch! The fix Looks fine.
> Reported-by: Tapan Dhimant <tdhimant@akamai.com>
> Signed-off-by: Josh Hunt <johunt@akamai.com>
Acked-by: Ankita Garg <ankita@in.ibm.com>
> ---
> drivers/misc/lkdtm.c | 8 ++++++++
> 1 files changed, 8 insertions(+), 0 deletions(-)
>
> diff --git a/drivers/misc/lkdtm.c b/drivers/misc/lkdtm.c
> index 81d7fa4..150cd70 100644
> --- a/drivers/misc/lkdtm.c
> +++ b/drivers/misc/lkdtm.c
> @@ -120,6 +120,7 @@ static int recur_count = REC_NUM_DEFAULT;
> static enum cname cpoint = CN_INVALID;
> static enum ctype cptype = CT_NONE;
> static int count = DEFAULT_COUNT;
> +static DEFINE_SPINLOCK(count_lock);
>
> module_param(recur_count, int, 0644);
> MODULE_PARM_DESC(recur_count, " Recursion level for the stack overflow test, "\
> @@ -230,11 +231,14 @@ static const char *cp_name_to_str(enum cname name)
> static int lkdtm_parse_commandline(void)
> {
> int i;
> + unsigned long flags;
>
> if (cpoint_count < 1 || recur_count < 1)
> return -EINVAL;
>
> + spin_lock_irqsave(&count_lock, flags);
> count = cpoint_count;
> + spin_unlock_irqrestore(&count_lock, flags);
>
> /* No special parameters */
> if (!cpoint_type && !cpoint_name)
> @@ -349,6 +353,9 @@ static void lkdtm_do_action(enum ctype which)
>
> static void lkdtm_handler(void)
> {
> + unsigned long flags;
> +
> + spin_lock_irqsave(&count_lock, flags);
> count--;
> printk(KERN_INFO "lkdtm: Crash point %s of type %s hit, trigger in %d rounds\n",
> cp_name_to_str(cpoint), cp_type_to_str(cptype), count);
> @@ -357,6 +364,7 @@ static void lkdtm_handler(void)
> lkdtm_do_action(cptype);
> count = cpoint_count;
> }
> + spin_unlock_irqrestore(&count_lock, flags);
> }
>
> static int lkdtm_register_cpoint(enum cname which)
--
Regards,
Ankita Garg (ankita@in.ibm.com)
Linux Technology Center
IBM India Systems & Technology Labs,
Bangalore, India
prev parent reply other threads:[~2011-06-15 12:58 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-06-14 23:40 Josh Hunt
2011-06-15 12:58 ` Ankita Garg [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20110615125816.GB23151@in.ibm.com \
--to=ankita@in.ibm.com \
--cc=akpm@linux-foundation.org \
--cc=johunt@akamai.com \
--cc=linux-kernel@vger.kernel.org \
--cc=tdhimant@akamai.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®