From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ot1-f51.google.com (mail-ot1-f51.google.com [209.85.210.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4645C3ACF0E for ; Tue, 28 Apr 2026 11:45:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.51 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777376724; cv=none; b=jskChJzVS/cI03UPWgqY76GoDvXw7Y7LvmHbLWIODb3kOlDuIzmy5CU71QoVyx3z7XIlhKc+45pISgzWPiM9d+GJbc2poy+MeiGslCDbiM2GA8mWbCn84UqwKXYAh4yjlMrBhWp/7Nu+isz2mLTuFbTanaUZy9knwGkMjuDxffk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777376724; c=relaxed/simple; bh=12HhzKjY37nXpEUIlxxcx7/wzC9CcCcO+35cMA792fI=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=fs9tr31yoZ2hJgq68oEkmi3r40AzeCrWlyEF/gvwkY9Vyv6C27zHpob0e5/L8Cf/LmqubU1VMRxqS6BE0sH3Xnhz5aN52lWKbBi3XaGiQ+MKtBvAkNIyyOPWX7pt4u0LbPYGJ3lcfR7Xr5oQZQZPt0dPMDKMyWXuh54tP1f4hEo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=minyard.net; spf=pass smtp.mailfrom=minyard.net; dkim=pass (2048-bit key) header.d=minyard.net header.i=@minyard.net header.b=fWwNc6eQ; arc=none smtp.client-ip=209.85.210.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=minyard.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=minyard.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=minyard.net header.i=@minyard.net header.b="fWwNc6eQ" Received: by mail-ot1-f51.google.com with SMTP id 46e09a7af769-7dccda31d3eso2731599a34.3 for ; Tue, 28 Apr 2026 04:45:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=minyard.net; s=google; t=1777376721; x=1777981521; darn=vger.kernel.org; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:reply-to:message-id:subject:cc:to:from:date :from:to:cc:subject:date:message-id:reply-to; bh=wGegJh+XMiVUnAu14oQ8XqrjJ1magSoqSyK79ZedG1c=; b=fWwNc6eQbTGaYWQ4E4bhKqL/W2ubIpmd4Nl5U6UTg71DuMKIkt9tE1wPCuwRrY0Iau ZhfONSKo7Lalr6aRFhmy+ea205LGPFOVpL9Bi94qJHcOuoepAT4zJ+gCsR5r/7qlBeSa ZJRKs5g5/nkDQ+3OMRW0ng9VAikRWreoPwOrQ9ZbcDHxQJvXKXZbf5UjHCWz7Xxugp8O aTc+ruoCEA+PKFcP+SXGPBmatKE/NSm3YtW11CNC52tPrJkrBOI2Bd+Jhq/DqILNLe8Q v/sycHQBYj+FYWbAb+Ee3mWkH3iszyRVBsWcl83dMMheQx3nf7Nu0WkuY8Twtn2p1wL5 vARQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777376721; x=1777981521; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:reply-to:message-id:subject:cc:to:from:date :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=wGegJh+XMiVUnAu14oQ8XqrjJ1magSoqSyK79ZedG1c=; b=HggAhErFlbQiq+ZvXIKzel5UX+ruWNQ0zpk01hWwLEVBgYHP2t19BS0S8oHVpwlRiT yz8kUbGVqpLSWc5GvxqRXPr5H8/xCebWUgY0XOhAJVRAXoUbp6xL9oY2dx+bKKAv4sL4 BhZHFFs7i8XR9jUz752DDJcMr/psrg6ZF94ohD/DPucUBebGXBU3C0dGka+jQ1qAm22m 1qXP7XbHDP+z2hs+RdR5CxY5MeQBzfxI8hAnlfBMSvrTd6fFS+9CjgMl0GCvr0VRzD0N yTrCT7wjlgboANdGcgRIQhS1dh6C+H8GBKI6Ec84qAVQI1J+YqYgMrHx7a/Pi1T8k5LS /I8A== X-Forwarded-Encrypted: i=1; AFNElJ8RRj2HHCwGp9BZS7NiEk98jlDFNZKIwt1TJZkt7vVuDiR+3YY7hjd0ccUSwkTiKs54QnoJejcsmL/W0So=@vger.kernel.org X-Gm-Message-State: AOJu0YzHHHhTLr8QVJ2njQRtzrUDrExDxc09uVmsZPoja3XFn28pPqvO cuNWaEN1QWQgRxhWoTZEUVY2Pw009RDLr7X3fJoFqBEn0W6HIDj0yQD2xhUFx7ozqhQ= X-Gm-Gg: AeBDieu6IinArtJB5gF5KOstgr2zuu5Rh0D5HdasMkws3oakZ34YXwhLF5ND3qFarQe hV6fQ8I0IptfVsg4ug+/21M1V2OM2s2VEx7EwEV2GvhOs6JSnG2muxixu5Yjz5d2tZKQ4vzSCTJ 1W9sH+L1p9m8xxYwPt/WnOmL9Q39o9xNswE8QECMiFFPXsq/dcvE3GYFcBmckpMdPfpWCZqcX7P 5d/s1R6sLHfg+FtRaprTsEC+DzPdRO+rhzp0TXm+EmJJmnZ5VJY/Hs3QE0yVBgRve1A3xzux0DD g5xBrX3ZYL05F/QMksypL0K8HB7RjTw3DmjbDzi7QZUPY88xQ/HmTBDjebVyOpADB0DjPgTjmXq DJsHVIZG445foMK+aiOedkA/dFI7BQY0l6u1C8Z5jUYeKRkX74lztGjWIQWvM//icaVIIzVf+D0 3HE6sCjTQAgmbd36W3cT4QkJZxx+Qv6XPhF0SdJftY2UwHembnE4Wi2JR+/QFnEIJSE1oBe3Tjw c1biQUFcdkh/ESnuJlUyVQbow== X-Received: by 2002:a05:6830:448e:b0:7de:495a:cf80 with SMTP id 46e09a7af769-7de9a0b6c8fmr1619131a34.16.1777376721043; Tue, 28 Apr 2026 04:45:21 -0700 (PDT) Received: from mail.minyard.net ([2001:470:b8f6:1b:689e:6348:f71f:894a]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7de984f63casm1682000a34.9.2026.04.28.04.45.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Apr 2026 04:45:20 -0700 (PDT) Date: Tue, 28 Apr 2026 06:45:15 -0500 From: Corey Minyard To: Matt Fleming Cc: Matt Fleming , openipmi-developer@lists.sourceforge.net, Tony Camuso , linux-kernel@vger.kernel.org, kernel-team@cloudflare.com, stable@vger.kernel.org Subject: Re: [PATCH 2/2] ipmi: Add limits to event and receive message requests Message-ID: Reply-To: corey@minyard.net References: <20260421132544.2666174-1-corey@minyard.net> <20260421132544.2666174-3-corey@minyard.net> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: On Tue, Apr 28, 2026 at 11:15:46AM +0100, Matt Fleming wrote: > On Sat, Apr 25, 2026 at 06:58:48PM -0500, Corey Minyard wrote: > > > > Oh, yeah. > > > > Moving it to handle_transaction_done() is not ideal, though. If > > something was spewing receive messages, it would never get to events, > > which is why I did it like I did. > > > > The following should fix this. You could also have different limits for > > receive messages and events, but I think the following is more clear. > > > > diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c > > index 2a739123270c..e46f4150ceb5 100644 > > --- a/drivers/char/ipmi/ipmi_si_intf.c > > +++ b/drivers/char/ipmi/ipmi_si_intf.c > > @@ -413,8 +413,10 @@ static void start_getting_msg_queue(struct smi_info *smi_info) > > > > start_new_msg(smi_info, smi_info->curr_msg->data, > > smi_info->curr_msg->data_size); > > - smi_info->num_requests_in_a_row = 0; > > - smi_info->si_state = SI_GETTING_MESSAGES; > > + if (smi_info->si_state != SI_GETTING_MESSAGES) { > > + smi_info->num_requests_in_a_row = 0; > > + smi_info->si_state = SI_GETTING_MESSAGES; > > + } > > } > > > > static void start_getting_events(struct smi_info *smi_info) > > @@ -425,8 +427,10 @@ static void start_getting_events(struct smi_info *smi_info) > > > > start_new_msg(smi_info, smi_info->curr_msg->data, > > smi_info->curr_msg->data_size); > > - smi_info->num_requests_in_a_row = 0; > > - smi_info->si_state = SI_GETTING_EVENTS; > > + if (smi_info->si_state != SI_GETTING_EVENTS) { > > + smi_info->num_requests_in_a_row = 0; > > + smi_info->si_state = SI_GETTING_EVENTS; > > + } > > Thanks. Does this correctly handle a stream of mixed receive+event > flags, though? If we bounce between MESSAGES and EVENTS, won't we keep > resetting the counter on each state transition and never hit the limit? It should. Once the limit is reached it clears the bit in msg_flags. That should prevent the messages or events from being re-requested until the next flags fetch. So if a continuous stream of messages and events was coming in, it should fetch 10 messages, clear the bit, then fetch 10 events, then clear that bit, then go back to normal operation. Of course, the next flag fetch will start the process over. > > I was able to cook up a simple repro in Qemu for this class of bug. I was thinking about how to do an automated test for this. I use an external simulated BMC for the automated tests I have. So I'll work in that direction. But thanks, this should help me develop that test. -corey > > ---->8---- > > diff --git a/hw/ipmi/ipmi_bmc_sim.c b/hw/ipmi/ipmi_bmc_sim.c > index fd875491f5..127db30c03 100644 > --- a/hw/ipmi/ipmi_bmc_sim.c > +++ b/hw/ipmi/ipmi_bmc_sim.c > @@ -249,6 +249,21 @@ struct IPMIBmcSim { > uint8_t evtbuf[16]; > > QTAILQ_HEAD(, IPMIRcvBufEntry) rcvbufs; > + > + /* > + * Fault injection: sticky EVENT_MSG_BUFFER_FULL. > + * > + * Simulates a BMC that continuously generates events (e.g. after a > + * cold reset causes sensor state changes). Once armed, every > + * READ_EVENT_MSG_BUFFER returns success but never clears the > + * EVT_BUF_FULL flag, starving waiting_msg in the SI layer's > + * handle_flags() loop. Reproduces the 517m277 / KRN-1233 wedge. > + */ > + bool fi_sticky_events; /* enable via property */ > + uint32_t fi_evt_arm_after; /* arm after N completed responses */ > + uint32_t fi_evt_rsp_count; /* responses completed so far */ > + bool fi_evt_armed; /* fault is active */ > + uint32_t fi_evt_read_count; /* READ_EVENT_MSG_BUFFER calls served */ > }; > > #define IPMI_BMC_MSG_FLAG_WATCHDOG_TIMEOUT_MASK (1 << 3) > @@ -494,7 +509,7 @@ static int sel_add_event(IPMIBmcSim *ibs, uint8_t *event) > static int attn_set(IPMIBmcSim *ibs) > { > return IPMI_BMC_MSG_FLAG_RCV_MSG_QUEUE_SET(ibs) > - || IPMI_BMC_MSG_FLAG_EVT_BUF_FULL_SET(ibs) > + || (!ibs->fi_evt_armed && IPMI_BMC_MSG_FLAG_EVT_BUF_FULL_SET(ibs)) > || IPMI_BMC_MSG_FLAG_WATCHDOG_TIMEOUT_MASK_SET(ibs); > } > > @@ -750,6 +765,48 @@ static void ipmi_sim_handle_command(IPMIBmc *b, > out: > k->handle_rsp(s, msg_id, rsp.buffer, rsp.len); > > + /* > + * Fault injection: count completed responses and arm sticky > + * EVENT_MSG_BUFFER_FULL after the configured threshold. > + */ > + if (ibs->fi_sticky_events && !ibs->fi_evt_armed) { > + ibs->fi_evt_rsp_count++; > + if (ibs->fi_evt_rsp_count >= ibs->fi_evt_arm_after) { > + ibs->fi_evt_armed = true; > + ibs->fi_evt_read_count = 0; > + > + /* > + * Seed the event buffer with a synthetic sensor event > + * (sensor type 0x01 = Temperature, event type 0x01 = > + * threshold, evd1 = upper critical going high). > + * This matches what real BMCs generate after a cold reset. > + */ > + memset(ibs->evtbuf, 0, 16); > + ibs->evtbuf[2] = 0x02; /* System event record */ > + ibs->evtbuf[7] = ibs->parent.slave_addr; > + ibs->evtbuf[9] = 0x04; /* Format version */ > + ibs->evtbuf[10] = 0x01; /* Sensor type: Temperature */ > + ibs->evtbuf[11] = 0x01; /* Sensor number */ > + ibs->evtbuf[12] = 0x01; /* Event type: threshold */ > + ibs->evtbuf[13] = 0x09; /* Upper critical going high */ > + ibs->evtbuf[14] = 0x57; /* Threshold value */ > + ibs->evtbuf[15] = 0x00; /* Sequence (incremented on reads) */ > + > + ibs->msg_flags |= IPMI_BMC_MSG_FLAG_EVT_BUF_FULL; > + > + /* Ensure event message buffer is enabled in global enables > + * so the kernel sees it. Also enable event logging. > + */ > + ibs->bmc_global_enables |= (1 << IPMI_BMC_EVENT_MSG_BUF_BIT) > + | (1 << IPMI_BMC_EVENT_LOG_BIT); > + > + k->set_atn(s, 1, attn_irq_enabled(ibs)); > + > + fprintf(stderr, "[FI] sticky-events armed after %u responses\n", > + ibs->fi_evt_rsp_count); > + } > + } > + > next_timeout(ibs); > } > > @@ -1013,8 +1070,14 @@ static void clr_msg_flags(IPMIBmcSim *ibs, > { > IPMIInterface *s = ibs->parent.intf; > IPMIInterfaceClass *k = IPMI_INTERFACE_GET_CLASS(s); > + uint8_t clear_mask = cmd[2]; > + > + if (ibs->fi_evt_armed) { > + /* Don't allow clearing EVT_BUF_FULL when sticky events active */ > + clear_mask &= ~IPMI_BMC_MSG_FLAG_EVT_BUF_FULL; > + } > > - ibs->msg_flags &= ~cmd[2]; > + ibs->msg_flags &= ~clear_mask; > k->set_atn(s, attn_set(ibs), attn_irq_enabled(ibs)); > } > > @@ -1040,7 +1103,19 @@ static void read_evt_msg_buf(IPMIBmcSim *ibs, > for (i = 0; i < 16; i++) { > rsp_buffer_push(rsp, ibs->evtbuf[i]); > } > - ibs->msg_flags &= ~IPMI_BMC_MSG_FLAG_EVT_BUF_FULL; > + > + if (ibs->fi_evt_armed) { > + /* > + * Sticky mode: return success but keep EVT_BUF_FULL set. > + * Vary the event data slightly so the kernel doesn't > + * de-duplicate (increment evd3 as a sequence number). > + */ > + ibs->fi_evt_read_count++; > + ibs->evtbuf[15] = (uint8_t)(ibs->fi_evt_read_count & 0xff); > + /* Don't clear the flag — starvation continues */ > + } else { > + ibs->msg_flags &= ~IPMI_BMC_MSG_FLAG_EVT_BUF_FULL; > + } > k->set_atn(s, attn_set(ibs), attn_irq_enabled(ibs)); > } > > @@ -2670,6 +2745,8 @@ static const Property ipmi_sim_properties[] = { > DEFINE_PROP_STRING("lan.netmask", IPMIBmcSim, lan.arg_netmask), > DEFINE_PROP_STRING("lan.defgw_ipaddr", IPMIBmcSim, lan.arg_defgw_ipaddr), > DEFINE_PROP_MACADDR("lan.defgw_macaddr", IPMIBmcSim, lan.defgw_macaddr), > + DEFINE_PROP_BOOL("fi_sticky_events", IPMIBmcSim, fi_sticky_events, false), > + DEFINE_PROP_UINT32("fi_evt_arm_after", IPMIBmcSim, fi_evt_arm_after, 40), > }; > > static void ipmi_sim_class_init(ObjectClass *oc, const void *data)