All of lore.kernel.org
 help / color / mirror / Atom feed
From: Corey Minyard <minyard@acm.org>
To: Shuah Khan <skhan@linuxfoundation.org>
Cc: arnd@arndb.de, gregkh@linuxfoundation.org, keescook@chromium.org,
	openipmi-developer@lists.sourceforge.net,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 09/11] drivers/char/ipmi: convert stats to use counter_atomic32
Date: Fri, 25 Sep 2020 19:15:10 -0500	[thread overview]
Message-ID: <20200926001510.GH3674@minyard.net> (raw)
In-Reply-To: <b742c2637a8b6083c471a6dd829db70071909f83.1601073127.git.skhan@linuxfoundation.org>

On Fri, Sep 25, 2020 at 05:47:23PM -0600, Shuah Khan wrote:
> counter_atomic* is introduced to be used when a variable is used as
> a simple counter and doesn't guard object lifetimes. This clearly
> differentiates atomic_t usages that guard object lifetimes.
> 
> counter_atomic* variables will wrap around to 0 when it overflows and
> should not be used to guard resource lifetimes, device usage and
> open counts that control state changes, and pm states.
> 
> atomic_t variables used for stats are atomic counters. Overflow will
> wrap around and reset the stats and no change with the conversion.
> 
> Convert them to use counter_atomic32.
> 
> Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>

Reviewed-by: Corey Minyard <cminyard@mvista.com>

I assume for this conversion that the plan is to eliminate atomic_t
completely and convert all atomic counters used for object lifetime to
struct kref?  The new naming is certainly more clear and I'm happy with
this change.

-corey

> ---
>  drivers/char/ipmi/ipmi_msghandler.c | 9 +++++----
>  drivers/char/ipmi/ipmi_si_intf.c    | 9 +++++----
>  2 files changed, 10 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
> index 737c0b6b24ea..36c0b1be22fb 100644
> --- a/drivers/char/ipmi/ipmi_msghandler.c
> +++ b/drivers/char/ipmi/ipmi_msghandler.c
> @@ -34,6 +34,7 @@
>  #include <linux/uuid.h>
>  #include <linux/nospec.h>
>  #include <linux/vmalloc.h>
> +#include <linux/counters.h>
>  
>  #define IPMI_DRIVER_VERSION "39.2"
>  
> @@ -584,7 +585,7 @@ struct ipmi_smi {
>  	struct ipmi_my_addrinfo addrinfo[IPMI_MAX_CHANNELS];
>  	bool channels_ready;
>  
> -	atomic_t stats[IPMI_NUM_STATS];
> +	struct counter_atomic32 stats[IPMI_NUM_STATS];
>  
>  	/*
>  	 * run_to_completion duplicate of smb_info, smi_info
> @@ -630,9 +631,9 @@ static LIST_HEAD(smi_watchers);
>  static DEFINE_MUTEX(smi_watchers_mutex);
>  
>  #define ipmi_inc_stat(intf, stat) \
> -	atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
> +	counter_atomic32_inc(&(intf)->stats[IPMI_STAT_ ## stat])
>  #define ipmi_get_stat(intf, stat) \
> -	((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
> +	((unsigned int) counter_atomic32_read(&(intf)->stats[IPMI_STAT_ ## stat]))
>  
>  static const char * const addr_src_to_str[] = {
>  	"invalid", "hotmod", "hardcoded", "SPMI", "ACPI", "SMBIOS", "PCI",
> @@ -3448,7 +3449,7 @@ int ipmi_add_smi(struct module         *owner,
>  	INIT_LIST_HEAD(&intf->cmd_rcvrs);
>  	init_waitqueue_head(&intf->waitq);
>  	for (i = 0; i < IPMI_NUM_STATS; i++)
> -		atomic_set(&intf->stats[i], 0);
> +		counter_atomic32_set(&intf->stats[i], 0);
>  
>  	mutex_lock(&ipmi_interfaces_mutex);
>  	/* Look for a hole in the numbers. */
> diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
> index 77b8d551ae7f..0909a3461f05 100644
> --- a/drivers/char/ipmi/ipmi_si_intf.c
> +++ b/drivers/char/ipmi/ipmi_si_intf.c
> @@ -43,6 +43,7 @@
>  #include "ipmi_si_sm.h"
>  #include <linux/string.h>
>  #include <linux/ctype.h>
> +#include <linux/counters.h>
>  
>  /* Measure times between events in the driver. */
>  #undef DEBUG_TIMING
> @@ -237,7 +238,7 @@ struct smi_info {
>  	bool dev_group_added;
>  
>  	/* Counters and things for the proc filesystem. */
> -	atomic_t stats[SI_NUM_STATS];
> +	struct counter_atomic32 stats[SI_NUM_STATS];
>  
>  	struct task_struct *thread;
>  
> @@ -245,9 +246,9 @@ struct smi_info {
>  };
>  
>  #define smi_inc_stat(smi, stat) \
> -	atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
> +	counter_atomic32_inc(&(smi)->stats[SI_STAT_ ## stat])
>  #define smi_get_stat(smi, stat) \
> -	((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
> +	((unsigned int) counter_atomic32_read(&(smi)->stats[SI_STAT_ ## stat]))
>  
>  #define IPMI_MAX_INTFS 4
>  static int force_kipmid[IPMI_MAX_INTFS];
> @@ -2013,7 +2014,7 @@ static int try_smi_init(struct smi_info *new_smi)
>  	atomic_set(&new_smi->req_events, 0);
>  	new_smi->run_to_completion = false;
>  	for (i = 0; i < SI_NUM_STATS; i++)
> -		atomic_set(&new_smi->stats[i], 0);
> +		counter_atomic32_set(&new_smi->stats[i], 0);
>  
>  	new_smi->interrupt_disabled = true;
>  	atomic_set(&new_smi->need_watch, 0);
> -- 
> 2.25.1
> 

  reply	other threads:[~2020-09-26  0:15 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-25 23:47 [PATCH 00/11] Introduce Simple atomic and non-atomic counters Shuah Khan
2020-09-25 23:47 ` Shuah Khan
2020-09-25 23:47 ` [PATCH 01/11] counters: Introduce counter_simple* and counter_atomic* counters Shuah Khan
2020-09-25 23:47 ` [PATCH 02/11] selftests:lib:test_counters: add new test for counters Shuah Khan
2020-09-25 23:47 ` [PATCH 03/11] drivers/base: convert deferred_trigger_count and probe_count to counter_atomic32 Shuah Khan
2020-09-25 23:47 ` [PATCH 04/11] drivers/base/devcoredump: convert devcd_count " Shuah Khan
2020-09-25 23:47 ` [PATCH 05/11] drivers/acpi: convert seqno counter_atomic32 Shuah Khan
2020-09-25 23:47 ` [PATCH 06/11] drivers/acpi/apei: " Shuah Khan
2020-09-25 23:47 ` [PATCH 07/11] drivers/android/binder: convert stats, transaction_log to counter_atomic32 Shuah Khan
2020-09-25 23:47   ` Shuah Khan
2020-09-27 23:39   ` Joel Fernandes
2020-09-27 23:39     ` Joel Fernandes
2020-09-25 23:47 ` [PATCH 08/11] drivers/base/test/test_async_driver_probe: convert to use counter_atomic32 Shuah Khan
2020-09-25 23:47 ` [PATCH 09/11] drivers/char/ipmi: convert stats " Shuah Khan
2020-09-26  0:15   ` Corey Minyard [this message]
2020-09-26  2:05     ` Shuah Khan
2020-09-25 23:47 ` [PATCH 10/11] drivers/misc/vmw_vmci: convert num guest devices counter to counter_atomic32 Shuah Khan
2020-09-25 23:47 ` [PATCH 11/11] drivers/edac: convert pci counters " Shuah Khan
2020-09-28 12:05   ` Borislav Petkov
2020-09-25 23:52 ` [PATCH 00/11] Introduce Simple atomic and non-atomic counters Kees Cook
2020-09-25 23:52   ` Kees Cook
2020-09-26  0:13   ` Shuah Khan
2020-09-26  0:13     ` Shuah Khan
2020-09-26 16:33     ` Kees Cook
2020-09-26 16:33       ` Kees Cook
2020-09-28 22:52       ` Shuah Khan
2020-09-28 22:52         ` Shuah Khan
2020-09-26 16:22 ` Kees Cook
2020-09-26 16:22   ` Kees Cook
2020-09-28 22:42   ` Shuah Khan
2020-09-28 22:42     ` Shuah Khan
2020-09-26 16:29 ` Kees Cook
2020-09-26 16:29   ` Kees Cook
2020-09-28 22:41   ` Shuah Khan
2020-09-28 22:41     ` Shuah Khan
2020-09-28 23:13     ` Kees Cook
2020-09-28 23:13       ` Kees Cook
2020-10-06 15:21       ` Shuah Khan
2020-10-06 15:21         ` Shuah Khan
2020-09-27 23:35 ` Joel Fernandes
2020-09-27 23:35   ` Joel Fernandes
2020-09-28 20:34   ` Kees Cook
2020-09-28 20:34     ` Kees Cook
2020-09-28 21:17     ` Joel Fernandes
2020-09-28 21:17       ` Joel Fernandes
2020-09-28 23:01       ` Shuah Khan
2020-09-28 23:01         ` Shuah Khan

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=20200926001510.GH3674@minyard.net \
    --to=minyard@acm.org \
    --cc=arnd@arndb.de \
    --cc=gregkh@linuxfoundation.org \
    --cc=keescook@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=openipmi-developer@lists.sourceforge.net \
    --cc=skhan@linuxfoundation.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.