Skip to content

Commit 3d37d21

Browse files
cminyardgregkh
authored andcommitted
ipmi: Add limits to event and receive message requests
commit c4cca23 upstream. The driver would just fetch events and receive messages until the BMC said it was done. To avoid issues with BMCs that never say they are done, add a limit of 10 fetches at a time. In addition, an si interface has an attn state it can return from the hardware which is supposed to cause a flag fetch to see if the driver needs to fetch events or message or a few other things. If the attn bit gets stuck, it's a similar problem. So allow messages in between flag fetches so the driver itself doesn't get stuck. This is a more general fix than the previous fix for the specific bad BMC, but should fix the more general issue of a BMC that won't stop saying it has data. This has been there from the beginning of the driver. It's not a bug per-se, but it is accounting for bugs in BMCs. Reported-by: Matt Fleming <mfleming@cloudflare.com> Closes: https://lore.kernel.org/lkml/20260415115930.3428942-1-matt@readmodwrite.com/ Fixes: <1da177e4c3f4> ("Linux-2.6.12-rc2") Cc: stable@vger.kernel.org Signed-off-by: Corey Minyard <corey@minyard.net> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 00d91bf commit 3d37d21

2 files changed

Lines changed: 64 additions & 13 deletions

File tree

drivers/char/ipmi/ipmi_si_intf.c

Lines changed: 43 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,10 @@ struct smi_info {
168168
OEM2_DATA_AVAIL)
169169
unsigned char msg_flags;
170170

171+
/* When requesting events and messages, don't do it forever. */
172+
unsigned int num_requests_in_a_row;
173+
bool last_was_flag_fetch;
174+
171175
/* Does the BMC have an event buffer? */
172176
bool has_event_buffer;
173177

@@ -411,7 +415,10 @@ static void start_getting_msg_queue(struct smi_info *smi_info)
411415

412416
start_new_msg(smi_info, smi_info->curr_msg->data,
413417
smi_info->curr_msg->data_size);
414-
smi_info->si_state = SI_GETTING_MESSAGES;
418+
if (smi_info->si_state != SI_GETTING_MESSAGES) {
419+
smi_info->num_requests_in_a_row = 0;
420+
smi_info->si_state = SI_GETTING_MESSAGES;
421+
}
415422
}
416423

417424
static void start_getting_events(struct smi_info *smi_info)
@@ -422,7 +429,10 @@ static void start_getting_events(struct smi_info *smi_info)
422429

423430
start_new_msg(smi_info, smi_info->curr_msg->data,
424431
smi_info->curr_msg->data_size);
425-
smi_info->si_state = SI_GETTING_EVENTS;
432+
if (smi_info->si_state != SI_GETTING_EVENTS) {
433+
smi_info->num_requests_in_a_row = 0;
434+
smi_info->si_state = SI_GETTING_EVENTS;
435+
}
426436
}
427437

428438
/*
@@ -596,6 +606,7 @@ static void handle_transaction_done(struct smi_info *smi_info)
596606
smi_info->si_state = SI_NORMAL;
597607
} else {
598608
smi_info->msg_flags = msg[3];
609+
smi_info->last_was_flag_fetch = true;
599610
handle_flags(smi_info);
600611
}
601612
break;
@@ -641,6 +652,11 @@ static void handle_transaction_done(struct smi_info *smi_info)
641652
} else {
642653
smi_inc_stat(smi_info, events);
643654

655+
smi_info->num_requests_in_a_row++;
656+
if (smi_info->num_requests_in_a_row > 10)
657+
/* Stop if we do this too many times. */
658+
smi_info->msg_flags &= ~EVENT_MSG_BUFFER_FULL;
659+
644660
/*
645661
* Do this before we deliver the message
646662
* because delivering the message releases the
@@ -679,6 +695,11 @@ static void handle_transaction_done(struct smi_info *smi_info)
679695
} else {
680696
smi_inc_stat(smi_info, incoming_messages);
681697

698+
smi_info->num_requests_in_a_row++;
699+
if (smi_info->num_requests_in_a_row > 10)
700+
/* Stop if we do this too many times. */
701+
smi_info->msg_flags &= ~RECEIVE_MSG_AVAIL;
702+
682703
/*
683704
* Do this before we deliver the message
684705
* because delivering the message releases the
@@ -820,6 +841,26 @@ static enum si_sm_result smi_event_handler(struct smi_info *smi_info,
820841
goto out;
821842
}
822843

844+
/*
845+
* If we are currently idle, or if the last thing that was
846+
* done was a flag fetch and there is a message pending, try
847+
* to start the next message.
848+
*
849+
* We do the waiting message check to avoid a stuck flag
850+
* completely wedging the driver. Let a message through
851+
* in between flag operations if that happens.
852+
*/
853+
if (si_sm_result == SI_SM_IDLE ||
854+
(si_sm_result == SI_SM_ATTN && smi_info->waiting_msg &&
855+
smi_info->last_was_flag_fetch)) {
856+
smi_info->last_was_flag_fetch = false;
857+
smi_inc_stat(smi_info, idles);
858+
859+
si_sm_result = start_next_msg(smi_info);
860+
if (si_sm_result != SI_SM_IDLE)
861+
goto restart;
862+
}
863+
823864
/*
824865
* We prefer handling attn over new messages. But don't do
825866
* this if there is not yet an upper layer to handle anything.
@@ -847,15 +888,6 @@ static enum si_sm_result smi_event_handler(struct smi_info *smi_info,
847888
}
848889
}
849890

850-
/* If we are currently idle, try to start the next message. */
851-
if (si_sm_result == SI_SM_IDLE) {
852-
smi_inc_stat(smi_info, idles);
853-
854-
si_sm_result = start_next_msg(smi_info);
855-
if (si_sm_result != SI_SM_IDLE)
856-
goto restart;
857-
}
858-
859891
if ((si_sm_result == SI_SM_IDLE)
860892
&& (atomic_read(&smi_info->req_events))) {
861893
/*

drivers/char/ipmi/ipmi_ssif.c

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,9 @@ struct ssif_info {
225225
bool has_event_buffer;
226226
bool supports_alert;
227227

228+
/* When requesting events and messages, don't do it forever. */
229+
unsigned int num_requests_in_a_row;
230+
228231
/*
229232
* Used to tell what we should do with alerts. If we are
230233
* waiting on a response, read the data immediately.
@@ -413,7 +416,10 @@ static void start_event_fetch(struct ssif_info *ssif_info, unsigned long *flags)
413416
}
414417

415418
ssif_info->curr_msg = msg;
416-
ssif_info->ssif_state = SSIF_GETTING_EVENTS;
419+
if (ssif_info->ssif_state != SSIF_GETTING_EVENTS) {
420+
ssif_info->num_requests_in_a_row = 0;
421+
ssif_info->ssif_state = SSIF_GETTING_EVENTS;
422+
}
417423
ipmi_ssif_unlock_cond(ssif_info, flags);
418424

419425
msg->data[0] = (IPMI_NETFN_APP_REQUEST << 2);
@@ -436,7 +442,10 @@ static void start_recv_msg_fetch(struct ssif_info *ssif_info,
436442
}
437443

438444
ssif_info->curr_msg = msg;
439-
ssif_info->ssif_state = SSIF_GETTING_MESSAGES;
445+
if (ssif_info->ssif_state != SSIF_GETTING_MESSAGES) {
446+
ssif_info->num_requests_in_a_row = 0;
447+
ssif_info->ssif_state = SSIF_GETTING_MESSAGES;
448+
}
440449
ipmi_ssif_unlock_cond(ssif_info, flags);
441450

442451
msg->data[0] = (IPMI_NETFN_APP_REQUEST << 2);
@@ -843,6 +852,11 @@ static void msg_done_handler(struct ssif_info *ssif_info, int result,
843852
ssif_info->msg_flags &= ~EVENT_MSG_BUFFER_FULL;
844853
handle_flags(ssif_info, flags);
845854
} else {
855+
ssif_info->num_requests_in_a_row++;
856+
if (ssif_info->num_requests_in_a_row > 10)
857+
/* Stop if we do this too many times. */
858+
ssif_info->msg_flags &= ~EVENT_MSG_BUFFER_FULL;
859+
846860
handle_flags(ssif_info, flags);
847861
ssif_inc_stat(ssif_info, events);
848862
deliver_recv_msg(ssif_info, msg);
@@ -876,6 +890,11 @@ static void msg_done_handler(struct ssif_info *ssif_info, int result,
876890
ssif_info->msg_flags &= ~RECEIVE_MSG_AVAIL;
877891
handle_flags(ssif_info, flags);
878892
} else {
893+
ssif_info->num_requests_in_a_row++;
894+
if (ssif_info->num_requests_in_a_row > 10)
895+
/* Stop if we do this too many times. */
896+
ssif_info->msg_flags &= ~RECEIVE_MSG_AVAIL;
897+
879898
ssif_inc_stat(ssif_info, incoming_messages);
880899
handle_flags(ssif_info, flags);
881900
deliver_recv_msg(ssif_info, msg);

0 commit comments

Comments
 (0)