atm: mpoa: remove 32-bit timekeeping

net/atm/mpoa_* files use 'struct timeval' to store event
timestamps. struct timeval uses a 32-bit seconds field which will
overflow in the year 2038 and beyond. Morever, the timestamps are being
compared only to get seconds elapsed, so struct timeval which stores
a seconds and microseconds field is an overkill. This patch replaces
the use of struct timeval with time64_t to store a 64-bit seconds field.

Signed-off-by: Tina Ruchandani <ruchandani.tina@gmail.com>
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
Tina Ruchandani 2017-11-27 15:02:17 +01:00 committed by David S. Miller
parent 59c036995c
commit d750dbdc07
5 changed files with 43 additions and 40 deletions

View File

@ -14,7 +14,7 @@
#include <linux/capability.h> #include <linux/capability.h>
#include <linux/mm.h> #include <linux/mm.h>
#include <linux/sched/signal.h> #include <linux/sched/signal.h>
#include <linux/time.h> /* struct timeval */ #include <linux/time64.h> /* 64-bit time for seconds */
#include <linux/skbuff.h> #include <linux/skbuff.h>
#include <linux/bitops.h> #include <linux/bitops.h>
#include <linux/init.h> #include <linux/init.h>

View File

@ -1089,7 +1089,7 @@ static void MPOA_trigger_rcvd(struct k_message *msg, struct mpoa_client *mpc)
msg->type = SND_MPOA_RES_RQST; msg->type = SND_MPOA_RES_RQST;
msg->content.in_info = entry->ctrl_info; msg->content.in_info = entry->ctrl_info;
msg_to_mpoad(msg, mpc); msg_to_mpoad(msg, mpc);
do_gettimeofday(&(entry->reply_wait)); entry->reply_wait = ktime_get_seconds();
mpc->in_ops->put(entry); mpc->in_ops->put(entry);
return; return;
} }
@ -1099,7 +1099,7 @@ static void MPOA_trigger_rcvd(struct k_message *msg, struct mpoa_client *mpc)
msg->type = SND_MPOA_RES_RQST; msg->type = SND_MPOA_RES_RQST;
msg->content.in_info = entry->ctrl_info; msg->content.in_info = entry->ctrl_info;
msg_to_mpoad(msg, mpc); msg_to_mpoad(msg, mpc);
do_gettimeofday(&(entry->reply_wait)); entry->reply_wait = ktime_get_seconds();
mpc->in_ops->put(entry); mpc->in_ops->put(entry);
return; return;
} }
@ -1175,8 +1175,9 @@ static void MPOA_res_reply_rcvd(struct k_message *msg, struct mpoa_client *mpc)
} }
entry->ctrl_info = msg->content.in_info; entry->ctrl_info = msg->content.in_info;
do_gettimeofday(&(entry->tv)); entry->time = ktime_get_seconds();
do_gettimeofday(&(entry->reply_wait)); /* Used in refreshing func from now on */ /* Used in refreshing func from now on */
entry->reply_wait = ktime_get_seconds();
entry->refresh_time = 0; entry->refresh_time = 0;
ddprintk_cont("entry->shortcut = %p\n", entry->shortcut); ddprintk_cont("entry->shortcut = %p\n", entry->shortcut);

View File

@ -117,7 +117,7 @@ static in_cache_entry *in_cache_add_entry(__be32 dst_ip,
memcpy(entry->MPS_ctrl_ATM_addr, client->mps_ctrl_addr, ATM_ESA_LEN); memcpy(entry->MPS_ctrl_ATM_addr, client->mps_ctrl_addr, ATM_ESA_LEN);
entry->ctrl_info.in_dst_ip = dst_ip; entry->ctrl_info.in_dst_ip = dst_ip;
do_gettimeofday(&(entry->tv)); entry->time = ktime_get_seconds();
entry->retry_time = client->parameters.mpc_p4; entry->retry_time = client->parameters.mpc_p4;
entry->count = 1; entry->count = 1;
entry->entry_state = INGRESS_INVALID; entry->entry_state = INGRESS_INVALID;
@ -148,7 +148,7 @@ static int cache_hit(in_cache_entry *entry, struct mpoa_client *mpc)
if (qos != NULL) if (qos != NULL)
msg.qos = qos->qos; msg.qos = qos->qos;
msg_to_mpoad(&msg, mpc); msg_to_mpoad(&msg, mpc);
do_gettimeofday(&(entry->reply_wait)); entry->reply_wait = ktime_get_seconds();
entry->entry_state = INGRESS_RESOLVING; entry->entry_state = INGRESS_RESOLVING;
} }
if (entry->shortcut != NULL) if (entry->shortcut != NULL)
@ -171,7 +171,7 @@ static int cache_hit(in_cache_entry *entry, struct mpoa_client *mpc)
if (qos != NULL) if (qos != NULL)
msg.qos = qos->qos; msg.qos = qos->qos;
msg_to_mpoad(&msg, mpc); msg_to_mpoad(&msg, mpc);
do_gettimeofday(&(entry->reply_wait)); entry->reply_wait = ktime_get_seconds();
} }
return CLOSED; return CLOSED;
@ -227,17 +227,16 @@ static void in_cache_remove_entry(in_cache_entry *entry,
static void clear_count_and_expired(struct mpoa_client *client) static void clear_count_and_expired(struct mpoa_client *client)
{ {
in_cache_entry *entry, *next_entry; in_cache_entry *entry, *next_entry;
struct timeval now; time64_t now;
do_gettimeofday(&now); now = ktime_get_seconds();
write_lock_bh(&client->ingress_lock); write_lock_bh(&client->ingress_lock);
entry = client->in_cache; entry = client->in_cache;
while (entry != NULL) { while (entry != NULL) {
entry->count = 0; entry->count = 0;
next_entry = entry->next; next_entry = entry->next;
if ((now.tv_sec - entry->tv.tv_sec) if ((now - entry->time) > entry->ctrl_info.holding_time) {
> entry->ctrl_info.holding_time) {
dprintk("holding time expired, ip = %pI4\n", dprintk("holding time expired, ip = %pI4\n",
&entry->ctrl_info.in_dst_ip); &entry->ctrl_info.in_dst_ip);
client->in_ops->remove_entry(entry, client); client->in_ops->remove_entry(entry, client);
@ -253,35 +252,35 @@ static void check_resolving_entries(struct mpoa_client *client)
struct atm_mpoa_qos *qos; struct atm_mpoa_qos *qos;
in_cache_entry *entry; in_cache_entry *entry;
struct timeval now; time64_t now;
struct k_message msg; struct k_message msg;
do_gettimeofday(&now); now = ktime_get_seconds();
read_lock_bh(&client->ingress_lock); read_lock_bh(&client->ingress_lock);
entry = client->in_cache; entry = client->in_cache;
while (entry != NULL) { while (entry != NULL) {
if (entry->entry_state == INGRESS_RESOLVING) { if (entry->entry_state == INGRESS_RESOLVING) {
if ((now.tv_sec - entry->hold_down.tv_sec) <
client->parameters.mpc_p6) { if ((now - entry->hold_down)
< client->parameters.mpc_p6) {
entry = entry->next; /* Entry in hold down */ entry = entry->next; /* Entry in hold down */
continue; continue;
} }
if ((now.tv_sec - entry->reply_wait.tv_sec) > if ((now - entry->reply_wait) > entry->retry_time) {
entry->retry_time) {
entry->retry_time = MPC_C1 * (entry->retry_time); entry->retry_time = MPC_C1 * (entry->retry_time);
/* /*
* Retry time maximum exceeded, * Retry time maximum exceeded,
* put entry in hold down. * put entry in hold down.
*/ */
if (entry->retry_time > client->parameters.mpc_p5) { if (entry->retry_time > client->parameters.mpc_p5) {
do_gettimeofday(&(entry->hold_down)); entry->hold_down = ktime_get_seconds();
entry->retry_time = client->parameters.mpc_p4; entry->retry_time = client->parameters.mpc_p4;
entry = entry->next; entry = entry->next;
continue; continue;
} }
/* Ask daemon to send a resolution request. */ /* Ask daemon to send a resolution request. */
memset(&(entry->hold_down), 0, sizeof(struct timeval)); memset(&entry->hold_down, 0, sizeof(time64_t));
msg.type = SND_MPOA_RES_RTRY; msg.type = SND_MPOA_RES_RTRY;
memcpy(msg.MPS_ctrl, client->mps_ctrl_addr, ATM_ESA_LEN); memcpy(msg.MPS_ctrl, client->mps_ctrl_addr, ATM_ESA_LEN);
msg.content.in_info = entry->ctrl_info; msg.content.in_info = entry->ctrl_info;
@ -289,7 +288,7 @@ static void check_resolving_entries(struct mpoa_client *client)
if (qos != NULL) if (qos != NULL)
msg.qos = qos->qos; msg.qos = qos->qos;
msg_to_mpoad(&msg, client); msg_to_mpoad(&msg, client);
do_gettimeofday(&(entry->reply_wait)); entry->reply_wait = ktime_get_seconds();
} }
} }
entry = entry->next; entry = entry->next;
@ -300,18 +299,18 @@ static void check_resolving_entries(struct mpoa_client *client)
/* Call this every MPC-p5 seconds. */ /* Call this every MPC-p5 seconds. */
static void refresh_entries(struct mpoa_client *client) static void refresh_entries(struct mpoa_client *client)
{ {
struct timeval now; time64_t now;
struct in_cache_entry *entry = client->in_cache; struct in_cache_entry *entry = client->in_cache;
ddprintk("refresh_entries\n"); ddprintk("refresh_entries\n");
do_gettimeofday(&now); now = ktime_get_seconds();
read_lock_bh(&client->ingress_lock); read_lock_bh(&client->ingress_lock);
while (entry != NULL) { while (entry != NULL) {
if (entry->entry_state == INGRESS_RESOLVED) { if (entry->entry_state == INGRESS_RESOLVED) {
if (!(entry->refresh_time)) if (!(entry->refresh_time))
entry->refresh_time = (2 * (entry->ctrl_info.holding_time))/3; entry->refresh_time = (2 * (entry->ctrl_info.holding_time))/3;
if ((now.tv_sec - entry->reply_wait.tv_sec) > if ((now - entry->reply_wait) >
entry->refresh_time) { entry->refresh_time) {
dprintk("refreshing an entry.\n"); dprintk("refreshing an entry.\n");
entry->entry_state = INGRESS_REFRESHING; entry->entry_state = INGRESS_REFRESHING;
@ -480,7 +479,7 @@ static eg_cache_entry *eg_cache_add_entry(struct k_message *msg,
memcpy(entry->MPS_ctrl_ATM_addr, client->mps_ctrl_addr, ATM_ESA_LEN); memcpy(entry->MPS_ctrl_ATM_addr, client->mps_ctrl_addr, ATM_ESA_LEN);
entry->ctrl_info = msg->content.eg_info; entry->ctrl_info = msg->content.eg_info;
do_gettimeofday(&(entry->tv)); entry->time = ktime_get_seconds();
entry->entry_state = EGRESS_RESOLVED; entry->entry_state = EGRESS_RESOLVED;
dprintk("new_eg_cache_entry cache_id %u\n", dprintk("new_eg_cache_entry cache_id %u\n",
ntohl(entry->ctrl_info.cache_id)); ntohl(entry->ctrl_info.cache_id));
@ -495,7 +494,7 @@ static eg_cache_entry *eg_cache_add_entry(struct k_message *msg,
static void update_eg_cache_entry(eg_cache_entry *entry, uint16_t holding_time) static void update_eg_cache_entry(eg_cache_entry *entry, uint16_t holding_time)
{ {
do_gettimeofday(&(entry->tv)); entry->time = ktime_get_seconds();
entry->entry_state = EGRESS_RESOLVED; entry->entry_state = EGRESS_RESOLVED;
entry->ctrl_info.holding_time = holding_time; entry->ctrl_info.holding_time = holding_time;
} }
@ -503,17 +502,16 @@ static void update_eg_cache_entry(eg_cache_entry *entry, uint16_t holding_time)
static void clear_expired(struct mpoa_client *client) static void clear_expired(struct mpoa_client *client)
{ {
eg_cache_entry *entry, *next_entry; eg_cache_entry *entry, *next_entry;
struct timeval now; time64_t now;
struct k_message msg; struct k_message msg;
do_gettimeofday(&now); now = ktime_get_seconds();
write_lock_irq(&client->egress_lock); write_lock_irq(&client->egress_lock);
entry = client->eg_cache; entry = client->eg_cache;
while (entry != NULL) { while (entry != NULL) {
next_entry = entry->next; next_entry = entry->next;
if ((now.tv_sec - entry->tv.tv_sec) if ((now - entry->time) > entry->ctrl_info.holding_time) {
> entry->ctrl_info.holding_time) {
msg.type = SND_EGRESS_PURGE; msg.type = SND_EGRESS_PURGE;
msg.content.eg_info = entry->ctrl_info; msg.content.eg_info = entry->ctrl_info;
dprintk("egress_cache: holding time expired, cache_id = %u.\n", dprintk("egress_cache: holding time expired, cache_id = %u.\n",

View File

@ -2,6 +2,7 @@
#ifndef MPOA_CACHES_H #ifndef MPOA_CACHES_H
#define MPOA_CACHES_H #define MPOA_CACHES_H
#include <linux/time64.h>
#include <linux/netdevice.h> #include <linux/netdevice.h>
#include <linux/types.h> #include <linux/types.h>
#include <linux/atm.h> #include <linux/atm.h>
@ -16,9 +17,9 @@ void atm_mpoa_init_cache(struct mpoa_client *mpc);
typedef struct in_cache_entry { typedef struct in_cache_entry {
struct in_cache_entry *next; struct in_cache_entry *next;
struct in_cache_entry *prev; struct in_cache_entry *prev;
struct timeval tv; time64_t time;
struct timeval reply_wait; time64_t reply_wait;
struct timeval hold_down; time64_t hold_down;
uint32_t packets_fwded; uint32_t packets_fwded;
uint16_t entry_state; uint16_t entry_state;
uint32_t retry_time; uint32_t retry_time;
@ -53,7 +54,7 @@ struct in_cache_ops{
typedef struct eg_cache_entry{ typedef struct eg_cache_entry{
struct eg_cache_entry *next; struct eg_cache_entry *next;
struct eg_cache_entry *prev; struct eg_cache_entry *prev;
struct timeval tv; time64_t time;
uint8_t MPS_ctrl_ATM_addr[ATM_ESA_LEN]; uint8_t MPS_ctrl_ATM_addr[ATM_ESA_LEN];
struct atm_vcc *shortcut; struct atm_vcc *shortcut;
uint32_t packets_rcvd; uint32_t packets_rcvd;

View File

@ -8,7 +8,7 @@
#include <linux/mm.h> #include <linux/mm.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/proc_fs.h> #include <linux/proc_fs.h>
#include <linux/time.h> #include <linux/ktime.h>
#include <linux/seq_file.h> #include <linux/seq_file.h>
#include <linux/uaccess.h> #include <linux/uaccess.h>
#include <linux/atmmpc.h> #include <linux/atmmpc.h>
@ -138,7 +138,7 @@ static int mpc_show(struct seq_file *m, void *v)
int i; int i;
in_cache_entry *in_entry; in_cache_entry *in_entry;
eg_cache_entry *eg_entry; eg_cache_entry *eg_entry;
struct timeval now; time64_t now;
unsigned char ip_string[16]; unsigned char ip_string[16];
if (v == SEQ_START_TOKEN) { if (v == SEQ_START_TOKEN) {
@ -148,15 +148,17 @@ static int mpc_show(struct seq_file *m, void *v)
seq_printf(m, "\nInterface %d:\n\n", mpc->dev_num); seq_printf(m, "\nInterface %d:\n\n", mpc->dev_num);
seq_printf(m, "Ingress Entries:\nIP address State Holding time Packets fwded VPI VCI\n"); seq_printf(m, "Ingress Entries:\nIP address State Holding time Packets fwded VPI VCI\n");
do_gettimeofday(&now); now = ktime_get_seconds();
for (in_entry = mpc->in_cache; in_entry; in_entry = in_entry->next) { for (in_entry = mpc->in_cache; in_entry; in_entry = in_entry->next) {
unsigned long seconds_delta = now - in_entry->time;
sprintf(ip_string, "%pI4", &in_entry->ctrl_info.in_dst_ip); sprintf(ip_string, "%pI4", &in_entry->ctrl_info.in_dst_ip);
seq_printf(m, "%-16s%s%-14lu%-12u", seq_printf(m, "%-16s%s%-14lu%-12u",
ip_string, ip_string,
ingress_state_string(in_entry->entry_state), ingress_state_string(in_entry->entry_state),
in_entry->ctrl_info.holding_time - in_entry->ctrl_info.holding_time -
(now.tv_sec-in_entry->tv.tv_sec), seconds_delta,
in_entry->packets_fwded); in_entry->packets_fwded);
if (in_entry->shortcut) if (in_entry->shortcut)
seq_printf(m, " %-3d %-3d", seq_printf(m, " %-3d %-3d",
@ -169,13 +171,14 @@ static int mpc_show(struct seq_file *m, void *v)
seq_printf(m, "Egress Entries:\nIngress MPC ATM addr\nCache-id State Holding time Packets recvd Latest IP addr VPI VCI\n"); seq_printf(m, "Egress Entries:\nIngress MPC ATM addr\nCache-id State Holding time Packets recvd Latest IP addr VPI VCI\n");
for (eg_entry = mpc->eg_cache; eg_entry; eg_entry = eg_entry->next) { for (eg_entry = mpc->eg_cache; eg_entry; eg_entry = eg_entry->next) {
unsigned char *p = eg_entry->ctrl_info.in_MPC_data_ATM_addr; unsigned char *p = eg_entry->ctrl_info.in_MPC_data_ATM_addr;
unsigned long seconds_delta = now - eg_entry->time;
for (i = 0; i < ATM_ESA_LEN; i++) for (i = 0; i < ATM_ESA_LEN; i++)
seq_printf(m, "%02x", p[i]); seq_printf(m, "%02x", p[i]);
seq_printf(m, "\n%-16lu%s%-14lu%-15u", seq_printf(m, "\n%-16lu%s%-14lu%-15u",
(unsigned long)ntohl(eg_entry->ctrl_info.cache_id), (unsigned long)ntohl(eg_entry->ctrl_info.cache_id),
egress_state_string(eg_entry->entry_state), egress_state_string(eg_entry->entry_state),
(eg_entry->ctrl_info.holding_time - (eg_entry->ctrl_info.holding_time - seconds_delta),
(now.tv_sec-eg_entry->tv.tv_sec)),
eg_entry->packets_rcvd); eg_entry->packets_rcvd);
/* latest IP address */ /* latest IP address */