Skip to content

Commit 80057b2

Browse files
0x7f454c46davem330
authored andcommitted
selftest/tcp-ao: Work on namespace-ified sysctl_optmem_max
Since commit f5769fa ("net: Namespace-ify sysctl_optmem_max") optmem_max is per-netns, so need of switching to root namespace. It seems trivial to keep the old logic working, so going to keep it for a while (at least, until kernel with netns-optmem_max will be release). Currently, there is a test that checks that optmem_max limit applies to TCP-AO keys and a little benchmark that measures linked-list TCP-AO keys scaling, those are fixed by this. Cc: Eric Dumazet <[email protected]> Signed-off-by: Dmitry Safonov <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 72cd9f8 commit 80057b2

File tree

1 file changed

+27
-8
lines changed
  • tools/testing/selftests/net/tcp_ao/lib

1 file changed

+27
-8
lines changed

tools/testing/selftests/net/tcp_ao/lib/setup.c

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -277,50 +277,69 @@ void __test_init(unsigned int ntests, int family, unsigned int prefix,
277277

278278
/* /proc/sys/net/core/optmem_max artifically limits the amount of memory
279279
* that can be allocated with sock_kmalloc() on each socket in the system.
280-
* It is not virtualized, so it has to written outside test namespaces.
281-
* To be nice a test will revert optmem back to the old value.
280+
* It is not virtualized in v6.7, so it has to written outside test
281+
* namespaces. To be nice a test will revert optmem back to the old value.
282282
* Keeping it simple without any file lock, which means the tests that
283283
* need to set/increase optmem value shouldn't run in parallel.
284284
* Also, not re-entrant.
285+
* Since commit f5769faeec36 ("net: Namespace-ify sysctl_optmem_max")
286+
* it is per-namespace, keeping logic for non-virtualized optmem_max
287+
* for v6.7, which supports TCP-AO.
285288
*/
286289
static const char *optmem_file = "/proc/sys/net/core/optmem_max";
287290
static size_t saved_optmem;
291+
static int optmem_ns = -1;
292+
293+
static bool is_optmem_namespaced(void)
294+
{
295+
if (optmem_ns == -1) {
296+
int old_ns = switch_save_ns(nsfd_child);
297+
298+
optmem_ns = !access(optmem_file, F_OK);
299+
switch_ns(old_ns);
300+
}
301+
return !!optmem_ns;
302+
}
288303

289304
size_t test_get_optmem(void)
290305
{
306+
int old_ns = 0;
291307
FILE *foptmem;
292-
int old_ns;
293308
size_t ret;
294309

295-
old_ns = switch_save_ns(nsfd_outside);
310+
if (!is_optmem_namespaced())
311+
old_ns = switch_save_ns(nsfd_outside);
296312
foptmem = fopen(optmem_file, "r");
297313
if (!foptmem)
298314
test_error("failed to open %s", optmem_file);
299315

300316
if (fscanf(foptmem, "%zu", &ret) != 1)
301317
test_error("can't read from %s", optmem_file);
302318
fclose(foptmem);
303-
switch_ns(old_ns);
319+
if (!is_optmem_namespaced())
320+
switch_ns(old_ns);
304321
return ret;
305322
}
306323

307324
static void __test_set_optmem(size_t new, size_t *old)
308325
{
326+
int old_ns = 0;
309327
FILE *foptmem;
310-
int old_ns;
311328

312329
if (old != NULL)
313330
*old = test_get_optmem();
314331

315-
old_ns = switch_save_ns(nsfd_outside);
332+
if (!is_optmem_namespaced())
333+
old_ns = switch_save_ns(nsfd_outside);
316334
foptmem = fopen(optmem_file, "w");
317335
if (!foptmem)
318336
test_error("failed to open %s", optmem_file);
319337

320338
if (fprintf(foptmem, "%zu", new) <= 0)
321339
test_error("can't write %zu to %s", new, optmem_file);
322340
fclose(foptmem);
323-
switch_ns(old_ns);
341+
if (!is_optmem_namespaced())
342+
switch_ns(old_ns);
324343
}
325344

326345
static void test_revert_optmem(void)

0 commit comments

Comments
 (0)