From: Alexander Duyck The fbnic_fw_xmit_heartbeat_message function records the request time on entry, before it allocates the message. The service task sends the heartbeat with RTNL held, and under memory pressure that GFP_KERNEL page allocation can sit in direct reclaim for minutes. The request then goes out stamped at the start of the stall, so the FW_HEARTBEAT_PERIOD gate in the fbnic_fw_check_heartbeat function has already expired on the next service task pass. That pass expects the response to have been processed already, and if the mailbox interrupt thread has not got to it yet on a host that is still struggling, the heartbeat is reported as missed and handled as a firmware crash although the firmware answered. Take the request time after the allocation, just before the message is posted. A response still cannot be recorded as older than its request, and the firmware gets the full period to answer however long the allocation took. The fbnic_fw_xmit_ownership_msg function restarts the heartbeat the same way, stamping the request and the last response before it allocates the message. It runs from the service task with RTNL held when recovering from a firmware crash, so move its timestamp after the allocation as well. This was seen on production hosts during host memory stalls, where a page allocation stall of 464 seconds in this allocation was followed by a "Firmware did not respond to heartbeat message" warning while the firmware kept running normally. Fixes: 20d2e88cc746 ("eth: fbnic: Add initial messaging to notify FW of our presence") Signed-off-by: Alexander Duyck --- drivers/net/ethernet/meta/fbnic/fbnic_fw.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/drivers/net/ethernet/meta/fbnic/fbnic_fw.c b/drivers/net/ethernet/meta/fbnic/fbnic_fw.c index e00d626f6438..3465f0139883 100644 --- a/drivers/net/ethernet/meta/fbnic/fbnic_fw.c +++ b/drivers/net/ethernet/meta/fbnic/fbnic_fw.c @@ -538,8 +538,8 @@ static bool fbnic_mbx_event(struct fbnic_dev *fbd) */ int fbnic_fw_xmit_ownership_msg(struct fbnic_dev *fbd, bool take_ownership) { - unsigned long req_time = jiffies; struct fbnic_tlv_msg *msg; + unsigned long req_time; int err = 0; if (!fbnic_fw_present(fbd)) @@ -556,8 +556,10 @@ int fbnic_fw_xmit_ownership_msg(struct fbnic_dev *fbd, bool take_ownership) } /* Initialize heartbeat, set last response to 1 second in the past - * so that we will trigger a timeout if the firmware doesn't respond + * so that we will trigger a timeout if the firmware doesn't respond. + * Take the time after the allocation, as for the heartbeat request. */ + req_time = jiffies; fbd->last_heartbeat_response = req_time - HZ; fbd->last_heartbeat_request = req_time; @@ -793,8 +795,8 @@ static int fbnic_fw_parse_heartbeat_resp(void *opaque, static int fbnic_fw_xmit_heartbeat_message(struct fbnic_dev *fbd) { - unsigned long req_time = jiffies; struct fbnic_tlv_msg *msg; + unsigned long req_time; int err = 0; if (!fbnic_fw_present(fbd)) @@ -804,6 +806,12 @@ static int fbnic_fw_xmit_heartbeat_message(struct fbnic_dev *fbd) if (!msg) return -ENOMEM; + /* Stamp the request after the allocation, which can stall in + * reclaim, but before posting it, so the response can never be + * recorded as older than the request. + */ + req_time = jiffies; + err = fbnic_mbx_map_tlv_msg(fbd, msg); if (err) goto free_message;