smc_sysctl.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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 <[email protected]>
  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 struct ctl_table smc_table[] = {
  26. {
  27. .procname = "autocorking_size",
  28. .data = &init_net.smc.sysctl_autocorking_size,
  29. .maxlen = sizeof(unsigned int),
  30. .mode = 0644,
  31. .proc_handler = proc_douintvec,
  32. },
  33. {
  34. .procname = "smcr_buf_type",
  35. .data = &init_net.smc.sysctl_smcr_buf_type,
  36. .maxlen = sizeof(unsigned int),
  37. .mode = 0644,
  38. .proc_handler = proc_douintvec_minmax,
  39. .extra1 = SYSCTL_ZERO,
  40. .extra2 = SYSCTL_TWO,
  41. },
  42. {
  43. .procname = "smcr_testlink_time",
  44. .data = &init_net.smc.sysctl_smcr_testlink_time,
  45. .maxlen = sizeof(int),
  46. .mode = 0644,
  47. .proc_handler = proc_dointvec_jiffies,
  48. },
  49. {
  50. .procname = "wmem",
  51. .data = &init_net.smc.sysctl_wmem,
  52. .maxlen = sizeof(int),
  53. .mode = 0644,
  54. .proc_handler = proc_dointvec_minmax,
  55. .extra1 = &min_sndbuf,
  56. .extra2 = &max_sndbuf,
  57. },
  58. {
  59. .procname = "rmem",
  60. .data = &init_net.smc.sysctl_rmem,
  61. .maxlen = sizeof(int),
  62. .mode = 0644,
  63. .proc_handler = proc_dointvec_minmax,
  64. .extra1 = &min_rcvbuf,
  65. .extra2 = &max_rcvbuf,
  66. },
  67. { }
  68. };
  69. int __net_init smc_sysctl_net_init(struct net *net)
  70. {
  71. struct ctl_table *table;
  72. table = smc_table;
  73. if (!net_eq(net, &init_net)) {
  74. int i;
  75. table = kmemdup(table, sizeof(smc_table), GFP_KERNEL);
  76. if (!table)
  77. goto err_alloc;
  78. for (i = 0; i < ARRAY_SIZE(smc_table) - 1; i++)
  79. table[i].data += (void *)net - (void *)&init_net;
  80. }
  81. net->smc.smc_hdr = register_net_sysctl(net, "net/smc", table);
  82. if (!net->smc.smc_hdr)
  83. goto err_reg;
  84. net->smc.sysctl_autocorking_size = SMC_AUTOCORKING_DEFAULT_SIZE;
  85. net->smc.sysctl_smcr_buf_type = SMCR_PHYS_CONT_BUFS;
  86. net->smc.sysctl_smcr_testlink_time = SMC_LLC_TESTLINK_DEFAULT_TIME;
  87. WRITE_ONCE(net->smc.sysctl_wmem, net_smc_wmem_init);
  88. WRITE_ONCE(net->smc.sysctl_rmem, net_smc_rmem_init);
  89. return 0;
  90. err_reg:
  91. if (!net_eq(net, &init_net))
  92. kfree(table);
  93. err_alloc:
  94. return -ENOMEM;
  95. }
  96. void __net_exit smc_sysctl_net_exit(struct net *net)
  97. {
  98. struct ctl_table *table;
  99. table = net->smc.smc_hdr->ctl_table_arg;
  100. unregister_net_sysctl_table(net->smc.smc_hdr);
  101. if (!net_eq(net, &init_net))
  102. kfree(table);
  103. }