From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3074941E5E for ; Tue, 17 Oct 2023 12:46:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="NdZeNaaS" Received: from mail-ot1-x330.google.com (mail-ot1-x330.google.com [IPv6:2607:f8b0:4864:20::330]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0074C106; Tue, 17 Oct 2023 05:46:13 -0700 (PDT) Received: by mail-ot1-x330.google.com with SMTP id 46e09a7af769-6c67060fdfaso3899315a34.2; Tue, 17 Oct 2023 05:46:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697546773; x=1698151573; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=jiqCJaBgHOvH62i9xa1P2ChEL8G+IgbXj1FnfIkgM98=; b=NdZeNaaSWP6YUMy6j6nTws/ZTVWYt0qahHK8xL6Mg9+Qyt9qesz0HzgB/SUekiDaQS D2+ZNDQjBSDOER8w8irW6Dmhjsq6H6l0Fh1tGtY8Wv6Sgdm5oEYcpNFiYqCL3bpZ0ZHB /J5/UKctCZxgbLycQ0A3yW1bT3yaw/hclgjDZkS8W5H6+QoNYCnIktwknWLFiTmfC6Hx E1utn7bmKC3SEBR/I7fjPBc/LNqSDzLk+qVpedr84uAZySqKlY+dR0llVVs70VQweor7 G2+Ohi9jDjn/VMI8MzE9iToq6I4fle844HTeTG06JRxcqzjBRkPYS8Wu2vd6r+92Y5IO 9AfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697546773; x=1698151573; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=jiqCJaBgHOvH62i9xa1P2ChEL8G+IgbXj1FnfIkgM98=; b=jqEzdHk2SNZFhH8rs/8EQpm81i0eTco5XDSK4crUjrOdqGGjxyHZQADI23+Wfc3Wp3 GaF3Dlm9LB3wfxMmK0IsUApISKkdeSmi75n3kpGLmegJahLyb+7LIxcUmzdsVLv54yHh Zq68m+v9ePTqahljTqkTfsb1gkCMGoOSiHIzpL3Er1y1JGDFoHNVD0H9uD2aAHxkz9lD VbtEGSVwbbDE/p/QTR8NOsZRgBHvVIpHWam2tCVbS16Fh3Vy0tPAfxQHZFt6PVkShJIu 3riZo++yJm+7p5GmRYSkaikEJoi+Z7cDUYQxrbLi0IRabdVG2tDePa5kZ0IG7fut9rT3 Lb0g== X-Gm-Message-State: AOJu0YxFreNTLaxE2dLPrLVUA1izaT2LQRGSa+WcQrP7AWQbBSNd3rz1 FOQr+mtL+r1EKIwSYw1t7T0= X-Google-Smtp-Source: AGHT+IEVD5B3KICe8VoQ6DF5smnm6R6F+dA1k3JiZ6DklBUNk//eH2gBAogt2fhrbQ4pkADq8CqjWw== X-Received: by 2002:a05:6830:4b5:b0:6b9:2869:bd81 with SMTP id l21-20020a05683004b500b006b92869bd81mr2246831otd.18.1697546773216; Tue, 17 Oct 2023 05:46:13 -0700 (PDT) Received: from vultr.guest ([2001:19f0:ac01:3b2:5400:4ff:fe9b:d21b]) by smtp.gmail.com with ESMTPSA id fa36-20020a056a002d2400b006bdf4dfbe0dsm1375595pfb.12.2023.10.17.05.46.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 05:46:12 -0700 (PDT) From: Yafang Shao To: ast@kernel.org, daniel@iogearbox.net, john.fastabend@gmail.com, andrii@kernel.org, martin.lau@linux.dev, song@kernel.org, yonghong.song@linux.dev, kpsingh@kernel.org, sdf@google.com, haoluo@google.com, jolsa@kernel.org, tj@kernel.org, lizefan.x@bytedance.com, hannes@cmpxchg.org, yosryahmed@google.com, mkoutny@suse.com, sinquersw@gmail.com Cc: cgroups@vger.kernel.org, bpf@vger.kernel.org, Yafang Shao Subject: [RFC PATCH bpf-next v2 5/9] selftests/bpf: Fix issues in setup_classid_environment() Date: Tue, 17 Oct 2023 12:45:42 +0000 Message-Id: <20231017124546.24608-6-laoar.shao@gmail.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20231017124546.24608-1-laoar.shao@gmail.com> References: <20231017124546.24608-1-laoar.shao@gmail.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net If the net_cls subsystem is already mounted, attempting to mount it again in setup_classid_environment() will result in a failure with the error code EBUSY. Despite this, tmpfs will have been successfully mounted at /sys/fs/cgroup/net_cls. Consequently, the /sys/fs/cgroup/net_cls directory will be empty, causing subsequent setup operations to fail. Here's an error log excerpt illustrating the issue when net_cls has already been mounted at /sys/fs/cgroup/net_cls prior to running setup_classid_environment(): - Before that change $ tools/testing/selftests/bpf/test_progs --name=cgroup_v1v2 test_cgroup_v1v2:PASS:server_fd 0 nsec test_cgroup_v1v2:PASS:client_fd 0 nsec test_cgroup_v1v2:PASS:cgroup_fd 0 nsec test_cgroup_v1v2:PASS:server_fd 0 nsec run_test:PASS:skel_open 0 nsec run_test:PASS:prog_attach 0 nsec test_cgroup_v1v2:PASS:cgroup-v2-only 0 nsec (cgroup_helpers.c:248: errno: No such file or directory) Opening Cgroup Procs: /sys/fs/cgroup/net_cls/cgroup.procs (cgroup_helpers.c:540: errno: No such file or directory) Opening cgroup classid: /sys/fs/cgroup/net_cls/cgroup-test-work-dir/net_cls.classid run_test:PASS:skel_open 0 nsec run_test:PASS:prog_attach 0 nsec (cgroup_helpers.c:248: errno: No such file or directory) Opening Cgroup Procs: /sys/fs/cgroup/net_cls/cgroup-test-work-dir/cgroup.procs run_test:FAIL:join_classid unexpected error: 1 (errno 2) test_cgroup_v1v2:FAIL:cgroup-v1v2 unexpected error: -1 (errno 2) (cgroup_helpers.c:248: errno: No such file or directory) Opening Cgroup Procs: /sys/fs/cgroup/net_cls/cgroup.procs #44 cgroup_v1v2:FAIL Summary: 0/0 PASSED, 0 SKIPPED, 1 FAILED - After that change $ tools/testing/selftests/bpf/test_progs --name=cgroup_v1v2 #44 cgroup_v1v2:OK Summary: 1/0 PASSED, 0 SKIPPED, 0 FAILED Signed-off-by: Yafang Shao --- tools/testing/selftests/bpf/cgroup_helpers.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/tools/testing/selftests/bpf/cgroup_helpers.c b/tools/testing/selftests/bpf/cgroup_helpers.c index 5b1da2a32ea7..10b5f42e65e7 100644 --- a/tools/testing/selftests/bpf/cgroup_helpers.c +++ b/tools/testing/selftests/bpf/cgroup_helpers.c @@ -523,10 +523,20 @@ int setup_classid_environment(void) return 1; } - if (mount("net_cls", NETCLS_MOUNT_PATH, "cgroup", 0, "net_cls") && - errno != EBUSY) { - log_err("mount cgroup net_cls"); - return 1; + if (mount("net_cls", NETCLS_MOUNT_PATH, "cgroup", 0, "net_cls")) { + if (errno != EBUSY) { + log_err("mount cgroup net_cls"); + return 1; + } + + if (rmdir(NETCLS_MOUNT_PATH)) { + log_err("rmdir cgroup net_cls"); + return 1; + } + if (umount(CGROUP_MOUNT_DFLT)) { + log_err("umount cgroup base"); + return 1; + } } cleanup_classid_environment(); -- 2.30.1 (Apple Git-130)