Re: [PATCH 12/16] nvme-pci: Check DMA ops when indicating support for PCI P2PDMA

John Hubbard
2021-05-04T00:17:56Z

On 5/3/21 10:17 AM, Logan Gunthorpe wrote:
...
>>> blk_queue_flag_set(QUEUE_FLAG_NONROT, ns->queue);
>>> - if (ctrl->ops->flags & NVME_F_PCI_P2PDMA)
>>> + if (ctrl->ops->supports_pci_p2pdma &&
>>> + ctrl->ops->supports_pci_p2pdma(ctrl))
>>
>> This is a little excessive, as I suspected. How about providing a
>> default .supports_pci_p2pdma routine that returns false, so that
>> the op is always available (non-null)? By "default", maybe that
>> means either requiring an init_the_ops_struct() routine to be
>> used, and/or checking all the users of struct nvme_ctrl_ops.
>
> Honestly that sounds much more messy to me than simply checking if it's
> NULL before using it (which is a common, accepted pattern for ops).

OK, it's a minor suggestion, so feel free to ignore if you prefer it
the other way, sure.

>
>> Another idea: maybe you don't really need a bool .supports_pci_p2pdma()
>> routine at all, because the existing .flags really is about right.
>> You just need the flags to be filled in dynamically. So, do that
>> during nvme_pci setup/init time: that's when this module would call
>> dma_pci_p2pdma_supported().
>
> If the flag is filled in dynamically, then the ops struct would have to
> be non-constant. Ops structs should be constant for security reasons.
>

Hadn't thought about keeping ops structs constant. OK.

thanks,
--
John Hubbard
NVIDIA