Skip to content

Commit c024167

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 e501154 commit c024167

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

@@ -410,7 +414,10 @@ static void start_getting_msg_queue(struct smi_info *smi_info)
410414

411415
start_new_msg(smi_info, smi_info->curr_msg->data,
412416
smi_info->curr_msg->data_size);
413-
smi_info->si_state = SI_GETTING_MESSAGES;
417+
if (smi_info->si_state != SI_GETTING_MESSAGES) {
418+
smi_info->num_requests_in_a_row = 0;
419+
smi_info->si_state = SI_GETTING_MESSAGES;
420+
}
414421
}
415422

416423
static void start_getting_events(struct smi_info *smi_info)
@@ -421,7 +428,10 @@ static void start_getting_events(struct smi_info *smi_info)
421428

422429
start_new_msg(smi_info, smi_info->curr_msg->data,
423430
smi_info->curr_msg->data_size);
424-
smi_info->si_state = SI_GETTING_EVENTS;
431+
if (smi_info->si_state != SI_GETTING_EVENTS) {
432+
smi_info->num_requests_in_a_row = 0;
433+
smi_info->si_state = SI_GETTING_EVENTS;
434+
}
425435
}
426436

427437
/*
@@ -595,6 +605,7 @@ static void handle_transaction_done(struct smi_info *smi_info)
595605
smi_info->si_state = SI_NORMAL;
596606
} else {
597607
smi_info->msg_flags = msg[3];
608+
smi_info->last_was_flag_fetch = true;
598609
handle_flags(smi_info);
599610
}
600611
break;
@@ -640,6 +651,11 @@ static void handle_transaction_done(struct smi_info *smi_info)
640651
} else {
641652
smi_inc_stat(smi_info, events);
642653

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

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

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

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

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)