Re: [PATCH v3 09/10] NTB: epf: Fix doorbell bitmask handling in db_read/db_clear
From: Manivannan Sadhasivam
Date: Fri May 01 2026 - 12:30:48 EST
On Mon, Mar 23, 2026 at 12:15:43PM +0900, Koichiro Den wrote:
> The EPF driver currently stores the incoming doorbell as a vector number
> (irq_no + 1) in db_val and db_clear() clears all bits unconditionally.
> This breaks db_read()/db_clear() semantics when multiple doorbells are
> used.
>
> Store doorbells as a bitmask (BIT_ULL(vector)) and make
> db_clear(db_bits) clear only the specified bits. Use atomic64 operations
> as db_val is updated from interrupt context.
>
> Fixes: 812ce2f8d14e ("NTB: Add support for EPF PCI Non-Transparent Bridge")
> Reviewed-by: Frank Li <Frank.Li@xxxxxxx>
> Suggested-by: Dave Jiang <dave.jiang@xxxxxxxxx>
> Signed-off-by: Koichiro Den <den@xxxxxxxxxxxxx>
On this patch too, but some pre-existing issues as well:
https://sashiko.dev/#/patchset/20260323031544.2598111-1-den%40valinux.co.jp?part=9
- Mani
> ---
> drivers/ntb/hw/epf/ntb_hw_epf.c | 10 ++++++----
> 1 file changed, 6 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/ntb/hw/epf/ntb_hw_epf.c b/drivers/ntb/hw/epf/ntb_hw_epf.c
> index 67cdc5d729d5..741d30821390 100644
> --- a/drivers/ntb/hw/epf/ntb_hw_epf.c
> +++ b/drivers/ntb/hw/epf/ntb_hw_epf.c
> @@ -6,6 +6,7 @@
> * Author: Kishon Vijay Abraham I <kishon@xxxxxx>
> */
>
> +#include <linux/atomic.h>
> #include <linux/delay.h>
> #include <linux/module.h>
> #include <linux/pci.h>
> @@ -108,7 +109,7 @@ struct ntb_epf_dev {
> unsigned int self_spad;
> unsigned int peer_spad;
>
> - int db_val;
> + atomic64_t db_val;
> u64 db_valid_mask;
> };
>
> @@ -337,15 +338,16 @@ static irqreturn_t ntb_epf_vec_isr(int irq, void *dev)
> int irq_no;
>
> irq_no = irq - pci_irq_vector(ndev->ntb.pdev, 0);
> - ndev->db_val = irq_no + 1;
>
> if (irq_no == EPF_IRQ_LINK) {
> ntb_link_event(&ndev->ntb);
> } else if (irq_no == EPF_IRQ_RESERVED_DB) {
> dev_warn_ratelimited(ndev->dev,
> "Unexpected irq_no 1 received. Treat it as DB#0.\n");
> + atomic64_or(BIT_ULL(0), &ndev->db_val);
> ntb_db_event(&ndev->ntb, 0);
> } else {
> + atomic64_or(BIT_ULL(irq_no - EPF_IRQ_DB_START), &ndev->db_val);
> ntb_db_event(&ndev->ntb, irq_no - EPF_IRQ_DB_START);
> }
>
> @@ -530,7 +532,7 @@ static u64 ntb_epf_db_read(struct ntb_dev *ntb)
> {
> struct ntb_epf_dev *ndev = ntb_ndev(ntb);
>
> - return ndev->db_val;
> + return atomic64_read(&ndev->db_val);
> }
>
> static int ntb_epf_db_clear_mask(struct ntb_dev *ntb, u64 db_bits)
> @@ -542,7 +544,7 @@ static int ntb_epf_db_clear(struct ntb_dev *ntb, u64 db_bits)
> {
> struct ntb_epf_dev *ndev = ntb_ndev(ntb);
>
> - ndev->db_val = 0;
> + atomic64_and(~db_bits, &ndev->db_val);
>
> return 0;
> }
> --
> 2.51.0
>
--
மணிவண்ணன் சதாசிவம்