From: Shuah Khan <skhan@linuxfoundation.org>
To: minyard@acm.org, arnd@arndb.de, gregkh@linuxfoundation.org,
keescook@chromium.org, peterz@infradead.org
Cc: Shuah Khan <skhan@linuxfoundation.org>,
openipmi-developer@lists.sourceforge.net,
linux-kernel@vger.kernel.org
Subject: [PATCH 06/13] drivers/char/ipmi: convert stats to use seqnum_ops
Date: Tue, 10 Nov 2020 12:53:32 -0700 [thread overview]
Message-ID: <e383f5e0b72ecd524e65b5d4931f85db2b374ea0.1605027593.git.skhan@linuxfoundation.org> (raw)
In-Reply-To: <cover.1605027593.git.skhan@linuxfoundation.org>
seqnum_ops api is introduced to be used when a variable is used as
a sequence/stat counter and doesn't guard object lifetimes. This
clearly differentiates atomic_t usages that guard object lifetimes.
seqnum32 variables wrap around to INT_MIN 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 seqnum_ops.
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
---
drivers/char/ipmi/ipmi_msghandler.c | 9 +++++----
drivers/char/ipmi/ipmi_si_intf.c | 9 +++++----
drivers/char/ipmi/ipmi_ssif.c | 9 +++++----
3 files changed, 15 insertions(+), 12 deletions(-)
diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
index 8774a3b8ff95..a8f03b4dade9 100644
--- a/drivers/char/ipmi/ipmi_msghandler.c
+++ b/drivers/char/ipmi/ipmi_msghandler.c
@@ -35,6 +35,7 @@
#include <linux/nospec.h>
#include <linux/vmalloc.h>
#include <linux/delay.h>
+#include <linux/seqnum_ops.h>
#define IPMI_DRIVER_VERSION "39.2"
@@ -587,7 +588,7 @@ struct ipmi_smi {
struct ipmi_my_addrinfo addrinfo[IPMI_MAX_CHANNELS];
bool channels_ready;
- atomic_t stats[IPMI_NUM_STATS];
+ struct seqnum32 stats[IPMI_NUM_STATS];
/*
* run_to_completion duplicate of smb_info, smi_info
@@ -633,9 +634,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])
+ seqnum32_inc(&(intf)->stats[IPMI_STAT_ ## stat])
#define ipmi_get_stat(intf, stat) \
- ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
+ ((unsigned int) seqnum32_read(&(intf)->stats[IPMI_STAT_ ## stat]))
static const char * const addr_src_to_str[] = {
"invalid", "hotmod", "hardcoded", "SPMI", "ACPI", "SMBIOS", "PCI",
@@ -3468,7 +3469,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);
+ seqnum32_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 5eac94cf4ff8..e1354076a58a 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/seqnum_ops.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 seqnum32 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])
+ seqnum32_inc(&(smi)->stats[SI_STAT_ ## stat])
#define smi_get_stat(smi, stat) \
- ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
+ ((unsigned int) seqnum32_read(&(smi)->stats[SI_STAT_ ## stat]))
#define IPMI_MAX_INTFS 4
static int force_kipmid[IPMI_MAX_INTFS];
@@ -2030,7 +2031,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);
+ seqnum32_set(&new_smi->stats[i], 0);
new_smi->interrupt_disabled = true;
atomic_set(&new_smi->need_watch, 0);
diff --git a/drivers/char/ipmi/ipmi_ssif.c b/drivers/char/ipmi/ipmi_ssif.c
index 0416b9c9d410..0e61e072b213 100644
--- a/drivers/char/ipmi/ipmi_ssif.c
+++ b/drivers/char/ipmi/ipmi_ssif.c
@@ -47,6 +47,7 @@
#include <linux/acpi.h>
#include <linux/ctype.h>
#include <linux/time64.h>
+#include <linux/seqnum_ops.h>
#include "ipmi_dmi.h"
#define DEVICE_NAME "ipmi_ssif"
@@ -286,13 +287,13 @@ struct ssif_info {
unsigned int multi_len;
unsigned int multi_pos;
- atomic_t stats[SSIF_NUM_STATS];
+ struct seqnum32 stats[SSIF_NUM_STATS];
};
#define ssif_inc_stat(ssif, stat) \
- atomic_inc(&(ssif)->stats[SSIF_STAT_ ## stat])
+ seqnum32_inc(&(ssif)->stats[SSIF_STAT_ ## stat])
#define ssif_get_stat(ssif, stat) \
- ((unsigned int) atomic_read(&(ssif)->stats[SSIF_STAT_ ## stat]))
+ ((unsigned int) seqnum32_read(&(ssif)->stats[SSIF_STAT_ ## stat]))
static bool initialized;
static bool platform_registered;
@@ -1864,7 +1865,7 @@ static int ssif_probe(struct i2c_client *client, const struct i2c_device_id *id)
timer_setup(&ssif_info->watch_timer, watch_timeout, 0);
for (i = 0; i < SSIF_NUM_STATS; i++)
- atomic_set(&ssif_info->stats[i], 0);
+ seqnum32_set(&ssif_info->stats[i], 0);
if (ssif_info->supports_pec)
ssif_info->client->flags |= I2C_CLIENT_PEC;
--
2.27.0
next prev parent reply other threads:[~2020-11-10 19:55 UTC|newest]
Thread overview: 43+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-10 19:53 [PATCH 00/13] Introduce seqnum_ops Shuah Khan
2020-11-10 19:53 ` [PATCH 01/13] seqnum_ops: Introduce Sequence Number Ops Shuah Khan
2020-11-10 20:41 ` Greg KH
2020-11-10 20:43 ` Greg KH
2020-11-11 0:18 ` Kees Cook
2020-11-11 19:23 ` Shuah Khan
2020-11-12 12:36 ` Matthew Wilcox
2020-11-12 16:17 ` Shuah Khan
2020-11-12 16:45 ` Greg KH
2020-11-12 16:59 ` Shuah Khan
2020-11-12 21:27 ` Shuah Khan
2020-11-17 12:27 ` Peter Zijlstra
2020-11-10 21:03 ` Matthew Wilcox
2020-11-10 22:58 ` Shuah Khan
2020-11-11 0:20 ` Kees Cook
2020-11-11 15:42 ` Shuah Khan
2020-11-11 8:23 ` Peter Zijlstra
2020-11-11 15:56 ` Shuah Khan
2020-11-11 16:04 ` Peter Zijlstra
2020-11-11 17:34 ` Shuah Khan
2020-11-11 17:50 ` Peter Zijlstra
2020-11-11 18:28 ` Shuah Khan
2020-11-11 20:15 ` Peter Zijlstra
2020-11-12 13:29 ` Greg KH
2020-11-10 19:53 ` [PATCH 02/13] selftests:lib:test_seqnum_ops: add new test for seqnum_ops Shuah Khan
2020-11-10 19:53 ` [PATCH 03/13] drivers/acpi: convert seqno seqnum_ops Shuah Khan
2020-11-10 19:53 ` [PATCH 04/13] drivers/acpi/apei: convert seqno to seqnum_ops Shuah Khan
2020-11-10 19:53 ` [PATCH 05/13] drivers/base/test/test_async_driver_probe: convert to use seqnum_ops Shuah Khan
2020-11-10 19:53 ` Shuah Khan [this message]
2020-11-10 19:53 ` [PATCH 07/13] drivers/edac: convert pci counters to seqnum_ops Shuah Khan
2020-11-10 19:53 ` [PATCH 08/13] drivers/oprofile: convert stats to use seqnum_ops Shuah Khan
2020-11-10 19:53 ` [PATCH 09/13] drivers/staging/rtl8723bs: " Shuah Khan
2020-11-10 19:53 ` [PATCH 10/13] usb: usbip/vhci: convert seqno to seqnum_ops Shuah Khan
2020-11-10 19:53 ` [PATCH 11/13] drivers/staging/rtl8188eu: convert stats to use seqnum_ops Shuah Khan
2020-11-10 19:53 ` [PATCH 12/13] drivers/staging/unisys/visorhba: " Shuah Khan
2020-11-10 20:42 ` Greg KH
2020-11-10 21:02 ` Shuah Khan
2020-11-10 19:53 ` [PATCH 13/13] security/integrity/ima: converts stats to seqnum_ops Shuah Khan
2020-11-10 20:44 ` [PATCH 00/13] Introduce seqnum_ops Alan Stern
2020-11-10 22:42 ` Shuah Khan
2020-11-11 4:33 ` Matthew Wilcox
2020-11-11 16:03 ` Shuah Khan
2020-11-11 16:41 ` Matthew Wilcox
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=e383f5e0b72ecd524e65b5d4931f85db2b374ea0.1605027593.git.skhan@linuxfoundation.org \
--to=skhan@linuxfoundation.org \
--cc=arnd@arndb.de \
--cc=gregkh@linuxfoundation.org \
--cc=keescook@chromium.org \
--cc=linux-kernel@vger.kernel.org \
--cc=minyard@acm.org \
--cc=openipmi-developer@lists.sourceforge.net \
--cc=peterz@infradead.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).