Skip to content

Commit d750dbd

Browse files
Tinabr7davem330
authored andcommitted
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>
1 parent 59c0369 commit d750dbd

5 files changed

Lines changed: 43 additions & 40 deletions

File tree

‎net/atm/common.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#include <linux/capability.h>
1515
#include <linux/mm.h>
1616
#include <linux/sched/signal.h>
17-
#include <linux/time.h> /* struct timeval */
17+
#include <linux/time64.h> /* 64-bit time for seconds */
1818
#include <linux/skbuff.h>
1919
#include <linux/bitops.h>
2020
#include <linux/init.h>

‎net/atm/mpc.c‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1089,7 +1089,7 @@ static void MPOA_trigger_rcvd(struct k_message *msg, struct mpoa_client *mpc)
10891089
msg->type = SND_MPOA_RES_RQST;
10901090
msg->content.in_info = entry->ctrl_info;
10911091
msg_to_mpoad(msg, mpc);
1092-
do_gettimeofday(&(entry->reply_wait));
1092+
entry->reply_wait = ktime_get_seconds();
10931093
mpc->in_ops->put(entry);
10941094
return;
10951095
}
@@ -1099,7 +1099,7 @@ static void MPOA_trigger_rcvd(struct k_message *msg, struct mpoa_client *mpc)
10991099
msg->type = SND_MPOA_RES_RQST;
11001100
msg->content.in_info = entry->ctrl_info;
11011101
msg_to_mpoad(msg, mpc);
1102-
do_gettimeofday(&(entry->reply_wait));
1102+
entry->reply_wait = ktime_get_seconds();
11031103
mpc->in_ops->put(entry);
11041104
return;
11051105
}
@@ -1175,8 +1175,9 @@ static void MPOA_res_reply_rcvd(struct k_message *msg, struct mpoa_client *mpc)
11751175
}
11761176

11771177
entry->ctrl_info = msg->content.in_info;
1178-
do_gettimeofday(&(entry->tv));
1179-
do_gettimeofday(&(entry->reply_wait)); /* Used in refreshing func from now on */
1178+
entry->time = ktime_get_seconds();
1179+
/* Used in refreshing func from now on */
1180+
entry->reply_wait = ktime_get_seconds();
11801181
entry->refresh_time = 0;
11811182
ddprintk_cont("entry->shortcut = %p\n", entry->shortcut);
11821183

‎net/atm/mpoa_caches.c‎

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ static in_cache_entry *in_cache_add_entry(__be32 dst_ip,
117117

118118
memcpy(entry->MPS_ctrl_ATM_addr, client->mps_ctrl_addr, ATM_ESA_LEN);
119119
entry->ctrl_info.in_dst_ip = dst_ip;
120-
do_gettimeofday(&(entry->tv));
120+
entry->time = ktime_get_seconds();
121121
entry->retry_time = client->parameters.mpc_p4;
122122
entry->count = 1;
123123
entry->entry_state = INGRESS_INVALID;
@@ -148,7 +148,7 @@ static int cache_hit(in_cache_entry *entry, struct mpoa_client *mpc)
148148
if (qos != NULL)
149149
msg.qos = qos->qos;
150150
msg_to_mpoad(&msg, mpc);
151-
do_gettimeofday(&(entry->reply_wait));
151+
entry->reply_wait = ktime_get_seconds();
152152
entry->entry_state = INGRESS_RESOLVING;
153153
}
154154
if (entry->shortcut != NULL)
@@ -171,7 +171,7 @@ static int cache_hit(in_cache_entry *entry, struct mpoa_client *mpc)
171171
if (qos != NULL)
172172
msg.qos = qos->qos;
173173
msg_to_mpoad(&msg, mpc);
174-
do_gettimeofday(&(entry->reply_wait));
174+
entry->reply_wait = ktime_get_seconds();
175175
}
176176

177177
return CLOSED;
@@ -227,17 +227,16 @@ static void in_cache_remove_entry(in_cache_entry *entry,
227227
static void clear_count_and_expired(struct mpoa_client *client)
228228
{
229229
in_cache_entry *entry, *next_entry;
230-
struct timeval now;
230+
time64_t now;
231231

232-
do_gettimeofday(&now);
232+
now = ktime_get_seconds();
233233

234234
write_lock_bh(&client->ingress_lock);
235235
entry = client->in_cache;
236236
while (entry != NULL) {
237237
entry->count = 0;
238238
next_entry = entry->next;
239-
if ((now.tv_sec - entry->tv.tv_sec)
240-
> entry->ctrl_info.holding_time) {
239+
if ((now - entry->time) > entry->ctrl_info.holding_time) {
241240
dprintk("holding time expired, ip = %pI4\n",
242241
&entry->ctrl_info.in_dst_ip);
243242
client->in_ops->remove_entry(entry, client);
@@ -253,43 +252,43 @@ static void check_resolving_entries(struct mpoa_client *client)
253252

254253
struct atm_mpoa_qos *qos;
255254
in_cache_entry *entry;
256-
struct timeval now;
255+
time64_t now;
257256
struct k_message msg;
258257

259-
do_gettimeofday(&now);
258+
now = ktime_get_seconds();
260259

261260
read_lock_bh(&client->ingress_lock);
262261
entry = client->in_cache;
263262
while (entry != NULL) {
264263
if (entry->entry_state == INGRESS_RESOLVING) {
265-
if ((now.tv_sec - entry->hold_down.tv_sec) <
266-
client->parameters.mpc_p6) {
264+
265+
if ((now - entry->hold_down)
266+
< client->parameters.mpc_p6) {
267267
entry = entry->next; /* Entry in hold down */
268268
continue;
269269
}
270-
if ((now.tv_sec - entry->reply_wait.tv_sec) >
271-
entry->retry_time) {
270+
if ((now - entry->reply_wait) > entry->retry_time) {
272271
entry->retry_time = MPC_C1 * (entry->retry_time);
273272
/*
274273
* Retry time maximum exceeded,
275274
* put entry in hold down.
276275
*/
277276
if (entry->retry_time > client->parameters.mpc_p5) {
278-
do_gettimeofday(&(entry->hold_down));
277+
entry->hold_down = ktime_get_seconds();
279278
entry->retry_time = client->parameters.mpc_p4;
280279
entry = entry->next;
281280
continue;
282281
}
283282
/* Ask daemon to send a resolution request. */
284-
memset(&(entry->hold_down), 0, sizeof(struct timeval));
283+
memset(&entry->hold_down, 0, sizeof(time64_t));
285284
msg.type = SND_MPOA_RES_RTRY;
286285
memcpy(msg.MPS_ctrl, client->mps_ctrl_addr, ATM_ESA_LEN);
287286
msg.content.in_info = entry->ctrl_info;
288287
qos = atm_mpoa_search_qos(entry->ctrl_info.in_dst_ip);
289288
if (qos != NULL)
290289
msg.qos = qos->qos;
291290
msg_to_mpoad(&msg, client);
292-
do_gettimeofday(&(entry->reply_wait));
291+
entry->reply_wait = ktime_get_seconds();
293292
}
294293
}
295294
entry = entry->next;
@@ -300,18 +299,18 @@ static void check_resolving_entries(struct mpoa_client *client)
300299
/* Call this every MPC-p5 seconds. */
301300
static void refresh_entries(struct mpoa_client *client)
302301
{
303-
struct timeval now;
302+
time64_t now;
304303
struct in_cache_entry *entry = client->in_cache;
305304

306305
ddprintk("refresh_entries\n");
307-
do_gettimeofday(&now);
306+
now = ktime_get_seconds();
308307

309308
read_lock_bh(&client->ingress_lock);
310309
while (entry != NULL) {
311310
if (entry->entry_state == INGRESS_RESOLVED) {
312311
if (!(entry->refresh_time))
313312
entry->refresh_time = (2 * (entry->ctrl_info.holding_time))/3;
314-
if ((now.tv_sec - entry->reply_wait.tv_sec) >
313+
if ((now - entry->reply_wait) >
315314
entry->refresh_time) {
316315
dprintk("refreshing an entry.\n");
317316
entry->entry_state = INGRESS_REFRESHING;
@@ -480,7 +479,7 @@ static eg_cache_entry *eg_cache_add_entry(struct k_message *msg,
480479

481480
memcpy(entry->MPS_ctrl_ATM_addr, client->mps_ctrl_addr, ATM_ESA_LEN);
482481
entry->ctrl_info = msg->content.eg_info;
483-
do_gettimeofday(&(entry->tv));
482+
entry->time = ktime_get_seconds();
484483
entry->entry_state = EGRESS_RESOLVED;
485484
dprintk("new_eg_cache_entry cache_id %u\n",
486485
ntohl(entry->ctrl_info.cache_id));
@@ -495,25 +494,24 @@ static eg_cache_entry *eg_cache_add_entry(struct k_message *msg,
495494

496495
static void update_eg_cache_entry(eg_cache_entry *entry, uint16_t holding_time)
497496
{
498-
do_gettimeofday(&(entry->tv));
497+
entry->time = ktime_get_seconds();
499498
entry->entry_state = EGRESS_RESOLVED;
500499
entry->ctrl_info.holding_time = holding_time;
501500
}
502501

503502
static void clear_expired(struct mpoa_client *client)
504503
{
505504
eg_cache_entry *entry, *next_entry;
506-
struct timeval now;
505+
time64_t now;
507506
struct k_message msg;
508507

509-
do_gettimeofday(&now);
508+
now = ktime_get_seconds();
510509

511510
write_lock_irq(&client->egress_lock);
512511
entry = client->eg_cache;
513512
while (entry != NULL) {
514513
next_entry = entry->next;
515-
if ((now.tv_sec - entry->tv.tv_sec)
516-
> entry->ctrl_info.holding_time) {
514+
if ((now - entry->time) > entry->ctrl_info.holding_time) {
517515
msg.type = SND_EGRESS_PURGE;
518516
msg.content.eg_info = entry->ctrl_info;
519517
dprintk("egress_cache: holding time expired, cache_id = %u.\n",

‎net/atm/mpoa_caches.h‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#ifndef MPOA_CACHES_H
33
#define MPOA_CACHES_H
44

5+
#include <linux/time64.h>
56
#include <linux/netdevice.h>
67
#include <linux/types.h>
78
#include <linux/atm.h>
@@ -16,9 +17,9 @@ void atm_mpoa_init_cache(struct mpoa_client *mpc);
1617
typedef struct in_cache_entry {
1718
struct in_cache_entry *next;
1819
struct in_cache_entry *prev;
19-
struct timeval tv;
20-
struct timeval reply_wait;
21-
struct timeval hold_down;
20+
time64_t time;
21+
time64_t reply_wait;
22+
time64_t hold_down;
2223
uint32_t packets_fwded;
2324
uint16_t entry_state;
2425
uint32_t retry_time;
@@ -53,7 +54,7 @@ struct in_cache_ops{
5354
typedef struct eg_cache_entry{
5455
struct eg_cache_entry *next;
5556
struct eg_cache_entry *prev;
56-
struct timeval tv;
57+
time64_t time;
5758
uint8_t MPS_ctrl_ATM_addr[ATM_ESA_LEN];
5859
struct atm_vcc *shortcut;
5960
uint32_t packets_rcvd;

‎net/atm/mpoa_proc.c‎

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#include <linux/mm.h>
99
#include <linux/module.h>
1010
#include <linux/proc_fs.h>
11-
#include <linux/time.h>
11+
#include <linux/ktime.h>
1212
#include <linux/seq_file.h>
1313
#include <linux/uaccess.h>
1414
#include <linux/atmmpc.h>
@@ -138,7 +138,7 @@ static int mpc_show(struct seq_file *m, void *v)
138138
int i;
139139
in_cache_entry *in_entry;
140140
eg_cache_entry *eg_entry;
141-
struct timeval now;
141+
time64_t now;
142142
unsigned char ip_string[16];
143143

144144
if (v == SEQ_START_TOKEN) {
@@ -148,15 +148,17 @@ static int mpc_show(struct seq_file *m, void *v)
148148

149149
seq_printf(m, "\nInterface %d:\n\n", mpc->dev_num);
150150
seq_printf(m, "Ingress Entries:\nIP address State Holding time Packets fwded VPI VCI\n");
151-
do_gettimeofday(&now);
151+
now = ktime_get_seconds();
152152

153153
for (in_entry = mpc->in_cache; in_entry; in_entry = in_entry->next) {
154+
unsigned long seconds_delta = now - in_entry->time;
155+
154156
sprintf(ip_string, "%pI4", &in_entry->ctrl_info.in_dst_ip);
155157
seq_printf(m, "%-16s%s%-14lu%-12u",
156158
ip_string,
157159
ingress_state_string(in_entry->entry_state),
158160
in_entry->ctrl_info.holding_time -
159-
(now.tv_sec-in_entry->tv.tv_sec),
161+
seconds_delta,
160162
in_entry->packets_fwded);
161163
if (in_entry->shortcut)
162164
seq_printf(m, " %-3d %-3d",
@@ -169,13 +171,14 @@ static int mpc_show(struct seq_file *m, void *v)
169171
seq_printf(m, "Egress Entries:\nIngress MPC ATM addr\nCache-id State Holding time Packets recvd Latest IP addr VPI VCI\n");
170172
for (eg_entry = mpc->eg_cache; eg_entry; eg_entry = eg_entry->next) {
171173
unsigned char *p = eg_entry->ctrl_info.in_MPC_data_ATM_addr;
174+
unsigned long seconds_delta = now - eg_entry->time;
175+
172176
for (i = 0; i < ATM_ESA_LEN; i++)
173177
seq_printf(m, "%02x", p[i]);
174178
seq_printf(m, "\n%-16lu%s%-14lu%-15u",
175179
(unsigned long)ntohl(eg_entry->ctrl_info.cache_id),
176180
egress_state_string(eg_entry->entry_state),
177-
(eg_entry->ctrl_info.holding_time -
178-
(now.tv_sec-eg_entry->tv.tv_sec)),
181+
(eg_entry->ctrl_info.holding_time - seconds_delta),
179182
eg_entry->packets_rcvd);
180183

181184
/* latest IP address */

0 commit comments

Comments
 (0)