Skip to content

Commit

Permalink
ON-15198: Enable differing values for max_sbufs in user and kernel space
Browse files Browse the repository at this point in the history
Users should be able to reload the onload kernel module without having
to recompile their user space program. As such, there will be differing
views of `CI_EFCT_MAX_SUPERBUFS` from user and kernel space due to this
patch. This case is now handled in the kernel module without returning
an error.
  • Loading branch information
ligallag-amd committed Jan 9, 2024
1 parent d2d2bb9 commit 2ec2eb6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/include/ci/internal/seq.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@
#define SEQ_MIN(x, y) (SEQ_LE(x, y) ? (x) : (y))
#define SEQ_MAX(x, y) (SEQ_LE(x, y) ? (y) : (x))

#endif /* __CI_INTERNAL_SEQ_H__ */
#endif /* __CI_INTERNAL_SEQ_H__ */
20 changes: 16 additions & 4 deletions src/lib/efrm/efrm_efct_rxq.c
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,15 @@ int efrm_rxq_refresh(struct efrm_efct_rxq *rxq, unsigned long superbufs,
struct xlnx_efct_hugepage spare_page = {};
size_t i;
int rc = 0;
bool is_sbuf_err_logged = false;
unsigned n_hugepages = CI_MIN(max_superbufs, (unsigned)CI_EFCT_MAX_SUPERBUFS) /
CI_EFCT_SUPERBUFS_PER_PAGE;

if (max_superbufs != CI_EFCT_MAX_SUPERBUFS) {
/* Could be supported without much difficulty, but no need for now */
return -EINVAL;
EFRM_TRACE("max_superbufs: %u passed in by user not equal to kernel's: %u. "
"Ensure you do not create enough apps to donate more than %u "
"superbufs!", max_superbufs, CI_EFCT_MAX_SUPERBUFS,
n_hugepages * CI_EFCT_SUPERBUFS_PER_PAGE);
}

pages = kmalloc_array(sizeof(pages[0]), CI_EFCT_MAX_HUGEPAGES,
Expand All @@ -218,11 +223,11 @@ int efrm_rxq_refresh(struct efrm_efct_rxq *rxq, unsigned long superbufs,
break;
}
}
for (i = 0; i < CI_EFCT_MAX_HUGEPAGES; i += REFRESH_BATCH_SIZE) {
for (i = 0; i < n_hugepages; i += REFRESH_BATCH_SIZE) {
uint64_t local_current[REFRESH_BATCH_SIZE];
size_t j;
size_t n = min((size_t)REFRESH_BATCH_SIZE,
CI_EFCT_MAX_HUGEPAGES - i);
n_hugepages - i);
bool changes = false;

if (copy_from_user(local_current, user_current + i,
Expand Down Expand Up @@ -254,6 +259,13 @@ int efrm_rxq_refresh(struct efrm_efct_rxq *rxq, unsigned long superbufs,
if (pages[i].page != NULL) {
put_page(pages[i].page);
fput(pages[i].file);
if (i > n_hugepages && !is_sbuf_err_logged) {
EFRM_ERR("More than %d superbufs have been donated. User max: %u, "
"kernel max: %u. There are likely too many applications running.",
n_hugepages * CI_EFCT_SUPERBUFS_PER_PAGE, max_superbufs,
CI_EFCT_MAX_SUPERBUFS);
is_sbuf_err_logged = true;
}
}
}

Expand Down

0 comments on commit 2ec2eb6

Please sign in to comment.