Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

nvme-pci: rework the build time assert for NVME_MAX_NR_DESCRIPTORS

The current use of an always_inline helper is a bit convoluted.
Instead use macros that represent the arithmetics used for building
up the PRP chain.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Keith Busch <kbusch@kernel.org>
Reviewed-by: Daniel Gomez <da.gomez@samsung.com>
Reviewed-by: Leon Romanovsky <leonro@nvidia.com>
Link: https://lore.kernel.org/r/20250625113531.522027-9-hch@lst.de
Signed-off-by: Jens Axboe <axboe@kernel.dk>

authored by

Christoph Hellwig and committed by
Jens Axboe
ba83e321 16353f1b

+15 -13
+15 -13
drivers/nvme/host/pci.c
··· 57 57 #define NVME_MAX_META_SEGS \ 58 58 ((NVME_SMALL_POOL_SIZE / sizeof(struct nvme_sgl_desc)) - 1) 59 59 60 + /* 61 + * The last entry is used to link to the next descriptor. 62 + */ 63 + #define PRPS_PER_PAGE \ 64 + (((NVME_CTRL_PAGE_SIZE / sizeof(__le64))) - 1) 65 + 66 + /* 67 + * I/O could be non-aligned both at the beginning and end. 68 + */ 69 + #define MAX_PRP_RANGE \ 70 + (NVME_MAX_BYTES + 2 * (NVME_CTRL_PAGE_SIZE - 1)) 71 + 72 + static_assert(MAX_PRP_RANGE / NVME_CTRL_PAGE_SIZE <= 73 + (1 /* prp1 */ + NVME_MAX_NR_DESCRIPTORS * PRPS_PER_PAGE)); 74 + 60 75 static int use_threaded_interrupts; 61 76 module_param(use_threaded_interrupts, int, 0444); 62 77 ··· 418 403 } 419 404 420 405 return true; 421 - } 422 - 423 - /* 424 - * Will slightly overestimate the number of pages needed. This is OK 425 - * as it only leads to a small amount of wasted memory for the lifetime of 426 - * the I/O. 427 - */ 428 - static __always_inline int nvme_pci_npages_prp(void) 429 - { 430 - unsigned max_bytes = NVME_MAX_BYTES + NVME_CTRL_PAGE_SIZE; 431 - unsigned nprps = DIV_ROUND_UP(max_bytes, NVME_CTRL_PAGE_SIZE); 432 - return DIV_ROUND_UP(8 * nprps, NVME_CTRL_PAGE_SIZE - 8); 433 406 } 434 407 435 408 static struct nvme_descriptor_pools * ··· 3941 3938 BUILD_BUG_ON(sizeof(struct nvme_create_sq) != 64); 3942 3939 BUILD_BUG_ON(sizeof(struct nvme_delete_queue) != 64); 3943 3940 BUILD_BUG_ON(IRQ_AFFINITY_MAX_SETS < 2); 3944 - BUILD_BUG_ON(nvme_pci_npages_prp() > NVME_MAX_NR_DESCRIPTORS); 3945 3941 3946 3942 return pci_register_driver(&nvme_driver); 3947 3943 }