Thanks for the review. This is addressed in v7, where this patch is 2/2
(patch 1 of v6 has been applied upstream). The code items are fixed; the
question about users is answered at the end.
> [Severity: Low]
> Does this queue have any users in this series? Every probe now takes an
> async-pool vector and installs a hard IRQ handler:
>
> zxdh_pf_eq_table_init()
> zxdh_pf_async_irq_request()
> zxdh_get_irq_of_pool()
> zxdh_irq_affinity_request()
> zxdh_irq_pool_request_irq()
> zxdh_irq_alloc()
> request_irq()
>
> When the interrupt fires, zxdh_eq_async_riscv_int() dispatches to
> zxdh_dev->eq_table.nh[], but nothing registers on those chains. Under
> drivers/net/ethernet/zte/, the only reference to eq_table.nh[] is the
> atomic_notifier_call_chain() call in zxdh_eq_async_riscv_int().
>
> zxdh_eq.h also exports only zxdh_pf_eq_table_init() and
> zxdh_pf_eq_table_destroy(), with no register/unregister helper. Later
> subscribers would have to reach into struct zxdh_eq_table directly.
>
> The commit message says:
>
> "the PF side wired here is live as soon as that channel is enabled.
> Subscribers for the RISCV_READY event register on the notifier chains
> in later series as well."
>
> Even with the channel enabled, every RISCV_READY dispatch would go to an
> empty chain. Could this be merged together with the BAR message channel
> and the first subscriber? Then the design could be reviewed against its
> consumers, including the event payload, valid/ack handling and ownership
> of the mailbox offsets.
You are right that there is no subscriber in this series: the notifier
chains are empty, and the queue is inert until the BAR message channel
handshake tells the firmware which vector to signal. The register/unregister
helper for subscribers will come with the first one.
We kept the queue in this series because the vector allocation, the IRQ
lifetime and the teardown order belong with the interrupt pools, and the
first subscriber, the event payload and the ownership of the mailbox offsets
are easier to review together with the channel. The valid bit of the header
is handled here.
If you would rather see this folded into the BAR message channel series, we
can hold it. Holding the queue also leaves the async pool in 1/2 without a
consumer, so in that case we would hold both patches and send them together
with the channel.
> [Severity: Medium]
> Should the handler check that a new message was actually posted before
> it uses this event_id?
>
> The >> 16 discards bytes 0-1 of the header. In the 12-byte BAR message
> header, byte 0 holds the per-message flag bits (valid, sync, emec, ack,
> poll, usr).
>
> The BAR mailbox protocol isn't in the tree yet, so this is based on the
> DPDK zxdh PMD. Its header layout matches the comment here (event_id at
> offset 2, RISC_READY = 13). Its receive path rejects any header without
> the valid bit in zxdh_bar_chan_msg_header_check().
>
> zxdh_irq_int_handler() calls the chain on every interrupt:
>
> atomic_notifier_call_chain(&zxdh_irq->nh, 0, NULL);
>
> return IRQ_HANDLED;
>
> so nothing earlier filters these events. If the mailbox still says 13,
> ZXDH_EQ_EVENT_TYPE_RISCV_READY would be dispatched again on any
> interrupt on this vector. That includes a stale header from an earlier
> notification, an uninitialized mailbox, or a spurious MSI-X. It also
> covers interrupts meant for other users if zxdh_irq_affinity_request()
> shares the vector when the pool runs out.
>
> Can subscribers then receive a RISCV_READY event that the firmware
> didn't post for this interrupt?
The handler now reads the whole header word, checks the valid flag (bit 0 of
byte 0, the same position the DPDK PMD uses) and returns without dispatching
if it is not set.
> [Severity: Medium]
> What gives the receive sub-channel back to the firmware once the
> message is handled? This handler is its only consumer, and it returns
> without writing anything to the mailbox.
>
> In the DPDK zxdh receive path, zxdh_bar_irq_recv() resets the header's
> valid field to usable. For sync messages it also writes a reply header
> with the ack bit set.
>
> Without this, could the RISC-V core keep seeing an unconsumed message
> and fail to post the next notification? Could a sync-flagged sender
> wait for an ack until it times out? The old header would also stay in
> the mailbox, so the stale re-dispatch described above could repeat on
> every later interrupt.
The valid flag is cleared with a read-modify-write of the first word once
the message has been dispatched, mirroring what the DPDK receive path does,
and this happens whether or not a subscriber handled the event.
This series only receives asynchronous notifications. The sync request/reply
path, including the ack header, comes with the BAR message channel series,
where both ends of the protocol are in the tree.
> [Severity: Low]
> This isn't a bug, but what does table->lock protect? zxdh_eq.h
> documents it as:
>
> /* Serializes async EQ setup/teardown. */
> struct mutex lock;
>
> zxdh_pf_eq_table_init() only calls mutex_init(). It then sets eq->irq
> and calls zxdh_irq_attach_nb() without taking the lock. This
> mutex_lock() in zxdh_pf_eq_table_destroy() is the only place it is
> acquired.
>
> The driver core already serializes probe and remove, and the hard IRQ
> path can't take a mutex. Holding the lock here also keeps it held across
> synchronize_rcu() in atomic_notifier_chain_unregister(),
> synchronize_irq(), pool->lock and free_irq().
>
> Could the lock be removed, or the comment changed to match what it
> actually guarantees?
Removed. It was only taken in the teardown path, while probe and remove are
already serialized by the driver core, and holding it across unregister and
free_irq did not protect anything.