smc_sysctl.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Shared Memory Communications over RDMA (SMC-R) and RoCE
  4. *
  5. * smc_sysctl.c: sysctl interface to SMC subsystem.
  6. *
  7. * Copyright (c) 2022, Alibaba Inc.
  8. *
  9. * Author: Tony Lu <tonylu@linux.alibaba.com>
  10. *
  11. */
  12. #include <linux/init.h>
  13. #include <linux/sysctl.h>
  14. #include <net/net_namespace.h>
  15. #include "smc.h"
  16. #include "smc_core.h"
  17. #include "smc_llc.h"
  18. #include "smc_sysctl.h"
  19. static int min_sndbuf = SMC_BUF_MIN_SIZE;
  20. static int min_rcvbuf = SMC_BUF_MIN_SIZE;
  21. static int max_sndbuf = INT_MAX / 2;
  22. static int max_rcvbuf = INT_MAX / 2;
  23. static const int net_smc_wmem_init = (64 * 1024);
  24. static const int net_smc_rmem_init = (64 * 1024);
  25. static int links_per_lgr_min = SMC_LINKS_ADD_LNK_MIN;
  26. static int links_per_lgr_max = SMC_LINKS_ADD_LNK_MAX;
  27. static int conns_per_lgr_min = SMC_CONN_PER_LGR_MIN;
  28. static int conns_per_lgr_max = SMC_CONN_PER_LGR_MAX;
  29. static struct ctl_table smc_table[] = {
  30. {
  31. .procname = "autocorking_size",
  32. .data = &init_net.smc.sysctl_autocorking_size,
  33. .maxlen = sizeof(unsigned int),
  34. .mode = 0644,
  35. .proc_handler = proc_douintvec,
  36. },
  37. {
  38. .procname = "smcr_buf_type",
  39. .data = &init_net.smc.sysctl_smcr_buf_type,
  40. .maxlen = sizeof(unsigned int),
  41. .mode = 0644,
  42. .proc_handler = proc_douintvec_minmax,
  43. .extra1 = SYSCTL_ZERO,
  44. .extra2 = SYSCTL_TWO,
  45. },
  46. {
  47. .procname = "smcr_testlink_time",
  48. .data = &init_net.smc.sysctl_smcr_testlink_time,
  49. .maxlen = sizeof(int),
  50. .mode = 0644,
  51. .proc_handler = proc_dointvec_jiffies,
  52. },
  53. {
  54. .procname = "wmem",
  55. .data = &init_net.smc.sysctl_wmem,
  56. .maxlen = sizeof(int),
  57. .mode = 0644,
  58. .proc_handler = proc_dointvec_minmax,
  59. .extra1 = &min_sndbuf,
  60. .extra2 = &max_sndbuf,
  61. },
  62. {
  63. .procname = "rmem",
  64. .data = &init_net.smc.sysctl_rmem,
  65. .maxlen = sizeof(int),
  66. .mode = 0644,
  67. .proc_handler = proc_dointvec_minmax,
  68. .extra1 = &min_rcvbuf,
  69. .extra2 = &max_rcvbuf,
  70. },
  71. {
  72. .procname = "smcr_max_links_per_lgr",
  73. .data = &init_net.smc.sysctl_max_links_per_lgr,
  74. .maxlen = sizeof(int),
  75. .mode = 0644,
  76. .proc_handler = proc_dointvec_minmax,
  77. .extra1 = &links_per_lgr_min,
  78. .extra2 = &links_per_lgr_max,
  79. },
  80. {
  81. .procname = "smcr_max_conns_per_lgr",
  82. .data = &init_net.smc.sysctl_max_conns_per_lgr,
  83. .maxlen = sizeof(int),
  84. .mode = 0644,
  85. .proc_handler = proc_dointvec_minmax,
  86. .extra1 = &conns_per_lgr_min,
  87. .extra2 = &conns_per_lgr_max,
  88. },
  89. {
  90. .procname = "limit_smc_hs",
  91. .data = &init_net.smc.limit_smc_hs,
  92. .maxlen = sizeof(int),
  93. .mode = 0644,
  94. .proc_handler = proc_dointvec_minmax,
  95. .extra1 = SYSCTL_ZERO,
  96. .extra2 = SYSCTL_ONE,
  97. },
  98. };
  99. int __net_init smc_sysctl_net_init(struct net *net)
  100. {
  101. size_t table_size = ARRAY_SIZE(smc_table);
  102. struct ctl_table *table;
  103. table = smc_table;
  104. if (!net_eq(net, &init_net)) {
  105. int i;
  106. table = kmemdup(table, sizeof(smc_table), GFP_KERNEL);
  107. if (!table)
  108. goto err_alloc;
  109. for (i = 0; i < table_size; i++)
  110. table[i].data += (void *)net - (void *)&init_net;
  111. }
  112. net->smc.smc_hdr = register_net_sysctl_sz(net, "net/smc", table,
  113. table_size);
  114. if (!net->smc.smc_hdr)
  115. goto err_reg;
  116. net->smc.sysctl_autocorking_size = SMC_AUTOCORKING_DEFAULT_SIZE;
  117. net->smc.sysctl_smcr_buf_type = SMCR_PHYS_CONT_BUFS;
  118. net->smc.sysctl_smcr_testlink_time = SMC_LLC_TESTLINK_DEFAULT_TIME;
  119. WRITE_ONCE(net->smc.sysctl_wmem, net_smc_wmem_init);
  120. WRITE_ONCE(net->smc.sysctl_rmem, net_smc_rmem_init);
  121. net->smc.sysctl_max_links_per_lgr = SMC_LINKS_PER_LGR_MAX_PREFER;
  122. net->smc.sysctl_max_conns_per_lgr = SMC_CONN_PER_LGR_PREFER;
  123. /* disable handshake limitation by default */
  124. net->smc.limit_smc_hs = 0;
  125. return 0;
  126. err_reg:
  127. if (!net_eq(net, &init_net))
  128. kfree(table);
  129. err_alloc:
  130. return -ENOMEM;
  131. }
  132. void __net_exit smc_sysctl_net_exit(struct net *net)
  133. {
  134. const struct ctl_table *table;
  135. table = net->smc.smc_hdr->ctl_table_arg;
  136. unregister_net_sysctl_table(net->smc.smc_hdr);
  137. if (!net_eq(net, &init_net))
  138. kfree(table);
  139. }