Re: [PATCH 04/10] PCI: endpoint: pci-epf-vntb: Exclude reserved slots from db_valid_mask

Frank Li <[email protected]> Wed, 25 Feb 2026 15:55:39 -0500
Newsgroups dev.linux.lists.ntb,org.kernel.vger.linux-kernel,org.kernel.vger.linux-pci
Message-ID <aZ9hy9RKR5pblGSc@lizhi-Precision-Tower-5810>
On Tue, Feb 24, 2026 at 10:34:53PM +0900, Koichiro Den wrote:
> In pci-epf-vntb, db_count represents the total number of doorbell slots
> exposed to the peer, including:
>   - slot #0 reserved for link events, and
>   - slot #1 historically unused (kept for compatibility).
>
> Only the remaining slots correspond to actual doorbell bits. The current
> db_valid_mask() exposes all slots as valid doorbells.
>
> Limit db_valid_mask() to the real doorbell bits by returning
> BIT_ULL(db_count - 2) - 1, and guard against db_count < 2.
>
> Fixes: e35f56bb0330 ("PCI: endpoint: Support NTB transfer between RC and EP")
> Signed-off-by: Koichiro Den <[email protected]>
> ---
Reviewed-by: Frank Li <[email protected]>
>  drivers/pci/endpoint/functions/pci-epf-vntb.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/pci/endpoint/functions/pci-epf-vntb.c b/drivers/pci/endpoint/functions/pci-epf-vntb.c
> index cbce50afc4dc..2eb3db035644 100644
> --- a/drivers/pci/endpoint/functions/pci-epf-vntb.c
> +++ b/drivers/pci/endpoint/functions/pci-epf-vntb.c
> @@ -1269,7 +1269,10 @@ static int vntb_epf_peer_mw_count(struct ntb_dev *ntb)
>
>  static u64 vntb_epf_db_valid_mask(struct ntb_dev *ntb)
>  {
> -	return BIT_ULL(ntb_ndev(ntb)->db_count) - 1;
> +	if (ntb_ndev(ntb)->db_count < 2)
> +		return 0;
> +
> +	return BIT_ULL(ntb_ndev(ntb)->db_count - 2) - 1;
>  }
>
>  static int vntb_epf_db_set_mask(struct ntb_dev *ntb, u64 db_bits)
> --
> 2.51.0
>