From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.3 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 63D39C4363D for ; Wed, 23 Sep 2020 01:44:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2BDFB238A1 for ; Wed, 23 Sep 2020 01:44:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600825481; bh=IlXSrWQ+Hh8AENvKc4YCm8HkzNeU/LouDK77SasiFIg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=1/9UnVySPVFbjmQJGbGowG1uLVSTiZ4PeepXogD2PKZtQkMPtIGLnI0eXkgjcQYjx hc7xykexLthv0fOEm5kipogIRQtmbRh3gZ6rerMba10EoWXxfEkwPx6mGt7x6NQ82J FPCFsR86PFqeKtn1SrNnXrNOGv4ZwQPFX75ZN/nw= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727226AbgIWBok (ORCPT ); Tue, 22 Sep 2020 21:44:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56846 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727170AbgIWBo0 (ORCPT ); Tue, 22 Sep 2020 21:44:26 -0400 Received: from mail-ot1-x342.google.com (mail-ot1-x342.google.com [IPv6:2607:f8b0:4864:20::342]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 426EFC0613D0 for ; Tue, 22 Sep 2020 18:44:26 -0700 (PDT) Received: by mail-ot1-x342.google.com with SMTP id n61so17493322ota.10 for ; Tue, 22 Sep 2020 18:44:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=hAa/7FCcR/kmgCzTDm4BV8p1GGTgIacqCiPKzsb8XqA=; b=WnSq6uLWHqqrRligHEcVIeXpbmVZvEORc2Zxh+jmhmXxHkbO4G8kcfoImsvwStzUWc jb9cKva8GdNDBTAkKWLGSTy2hGwwX67ob8R0XFN+lysja9GbKwlOyBZ1k/AfdnARSi4/ noqxUFUndVbvAH+XxJOtzC0FQC4mP3xpTi+Oo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=hAa/7FCcR/kmgCzTDm4BV8p1GGTgIacqCiPKzsb8XqA=; b=IsOZ9bkjYcptdihif1qnNhEz9CDVTIF9BvnJyO7983jYVkM2el4k711fNL8lvNYFzc 5qu5qrir4Cm3oSCSsXb4+CAuSNHzLRPNGCBwDfxR1vJmm5yv0jWDiPBXBgQxyLQbgdg0 K02n8yxg70aDN/1cuJdH5ahlJLm1zaq8szEmN8Q/en8ITfwwkM6sRqWEpGuzkU6vvZls XVL5eXjgkv4pD9nnlb0OtzElxs1w8oNPM6UfPIjcnUR2RdtBZdyYd2L3yqID1vY0+uc5 NHh428+MXAIzVBIoCGObIYln6htu+b5HORN/OOlfENyx4V4QSE1zpRpq7kz67xLYmDHb L4HA== X-Gm-Message-State: AOAM530bWZsj1y5oRekEhuDXUzX04iu8Nj3wPT2hF/IpLr23WqesjNoQ 2L5c0RT3Mz3Z7umEjoBnPJRtsA== X-Google-Smtp-Source: ABdhPJwytX0mlOo4QI3fd1gLgDwgIvZk30z+k1ZY5QxwttvEkCKpOA5/cb/JZeaHEvhq3Kx4RnM70A== X-Received: by 2002:a9d:6b16:: with SMTP id g22mr3390081otp.42.1600825465640; Tue, 22 Sep 2020 18:44:25 -0700 (PDT) Received: from shuah-t480s.internal (c-24-9-64-241.hsd1.co.comcast.net. [24.9.64.241]) by smtp.gmail.com with ESMTPSA id y23sm8801820ooj.34.2020.09.22.18.44.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Sep 2020 18:44:25 -0700 (PDT) From: Shuah Khan To: minyard@acm.org, arnd@arndb.de, gregkh@linuxfoundation.org, keescook@chromium.org Cc: Shuah Khan , openipmi-developer@lists.sourceforge.net, linux-kernel@vger.kernel.org Subject: [RFC PATCH 09/11] drivers/char/ipmi: convert stats to use counter_atomic Date: Tue, 22 Sep 2020 19:43:38 -0600 Message-Id: <4d4e8e16549a770cdb97c48886502db0ed5a03ea.1600816121.git.skhan@linuxfoundation.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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_atomic. Signed-off-by: Shuah Khan --- 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..c3ad8edd1da3 100644 --- a/drivers/char/ipmi/ipmi_msghandler.c +++ b/drivers/char/ipmi/ipmi_msghandler.c @@ -34,6 +34,7 @@ #include #include #include +#include #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_atomic 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_atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat]) #define ipmi_get_stat(intf, stat) \ - ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat])) + ((unsigned int) counter_atomic_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_atomic_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..cea1131f7639 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 #include +#include /* 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_atomic 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_atomic_inc(&(smi)->stats[SI_STAT_ ## stat]) #define smi_get_stat(smi, stat) \ - ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat])) + ((unsigned int) counter_atomic_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_atomic_set(&new_smi->stats[i], 0); new_smi->interrupt_disabled = true; atomic_set(&new_smi->need_watch, 0); -- 2.25.1