Received: by 2002:a25:86ce:0:0:0:0:0 with SMTP id y14csp2186961ybm; Thu, 23 May 2019 12:47:55 -0700 (PDT) X-Google-Smtp-Source: APXvYqznmZ1ULKIVcNJeVrs8eByfM45jVOZpsNO17QRpCcE+RERo9py+xO5K4ot3S7lrSbfIQARu X-Received: by 2002:a63:2160:: with SMTP id s32mr16652944pgm.431.1558640875577; Thu, 23 May 2019 12:47:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558640875; cv=none; d=google.com; s=arc-20160816; b=OwWBFeqits6z48ThFE9DYIGHWCPM5yer6iQBdgg/BwD8n5cPZ80SitkOlGjeY52Rle XiVJCrVEJUFxzMzktLFSZSq1VcXbZjPshtLctWboQloNhDwiLa5QwYr9iwvsYCsJo0YR TH2hewjMEWKgJMeq0RkzOyJthvsGDSyfT5Ez63xP9LG65sbYFJG6JJaQF9fA00YkCC8i j9iTqqATTuzrrIHCidydDq4hFxF8U2yKTx7RPx94+qW7mvnmHMraSxaC6HOSssu313a2 pPL0TkfsVW3MmqtmFh+/01csv+g7nAwGv9NQGAkfjOhq8uuk5nBD65MJ5MXwOishCcZp YS0g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:smtp-origin-cluster:cc:to :smtp-origin-hostname:from:smtp-origin-hostprefix:dkim-signature; bh=dguLJ5dXFo20uX3NNIRPvxtSl5doCiRMzTCOHYR6kDA=; b=DOCmYjvcommPvLb+nsm1P8VsxKHB+LFMJCfRSat9UrfL11NEz8EYQo6m6BBSn4oo4L drMrbAAYtbimnVC+aiNnuQDlEze7ijMpg5BGt3OKBO20Rf97RgotJmEAV6dZ9j0voSda Bfhy97ZAzvgrGoUNlhj8Ml5t7KZepmSWQAwZMwd/QA/hrpvh6GhYIOghWSvZs0L9KGPa XAF7OR/4+AfdsaIHYLGSyGRRFAFsu29rz7sn1VbmzQ3WjSGvumcFGmNqPgy0HOAmuGsr KfQSmpaZv1uGFeUlc4b9qzUXIUJrNLVhF3hE+nJEPzD60XCaaNAp/IhBhGeXRgigxfwa cQbw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@fb.com header.s=facebook header.b=ZgxBi6W6; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=fb.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id bc1si561130plb.55.2019.05.23.12.47.40; Thu, 23 May 2019 12:47:55 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@fb.com header.s=facebook header.b=ZgxBi6W6; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=fb.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388761AbfEWTq2 (ORCPT + 99 others); Thu, 23 May 2019 15:46:28 -0400 Received: from mx0a-00082601.pphosted.com ([67.231.145.42]:52036 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389295AbfEWTqQ (ORCPT ); Thu, 23 May 2019 15:46:16 -0400 Received: from pps.filterd (m0109334.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x4NJbjdL003916 for ; Thu, 23 May 2019 12:46:15 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=facebook; bh=dguLJ5dXFo20uX3NNIRPvxtSl5doCiRMzTCOHYR6kDA=; b=ZgxBi6W6jGo8DKHbJYzuR6jkS53jmKDx8cavFtfYQ10a9IS7N+Dt21J2l884qXS47FFz wV9RxZ/pMNcENcs/rilrAhSB/xwbgSmjsf3oFku+V97mA6FUErgwwEuukTUivoCnAWLe qRkvA0cdPl+UQc31qsvoYwF3UvsPiNsr8vM= Received: from maileast.thefacebook.com ([163.114.130.16]) by mx0a-00082601.pphosted.com with ESMTP id 2snt3p9sjs-6 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Thu, 23 May 2019 12:46:15 -0700 Received: from mx-out.facebook.com (2620:10d:c0a8:1b::d) by mail.thefacebook.com (2620:10d:c0a8:82::c) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5; Thu, 23 May 2019 12:46:10 -0700 Received: by devvm2643.prn2.facebook.com (Postfix, from userid 111017) id 532A2125B0483; Thu, 23 May 2019 12:45:33 -0700 (PDT) Smtp-Origin-Hostprefix: devvm From: Roman Gushchin Smtp-Origin-Hostname: devvm2643.prn2.facebook.com To: Alexei Starovoitov , CC: Daniel Borkmann , , Tejun Heo , , , Stanislav Fomichev , Yonghong Song , , Roman Gushchin Smtp-Origin-Cluster: prn2c23 Subject: [PATCH v3 bpf-next 3/4] selftests/bpf: enable all available cgroup v2 controllers Date: Thu, 23 May 2019 12:45:31 -0700 Message-ID: <20190523194532.2376233-4-guro@fb.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190523194532.2376233-1-guro@fb.com> References: <20190523194532.2376233-1-guro@fb.com> X-FB-Internal: Safe MIME-Version: 1.0 Content-Type: text/plain X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-05-23_16:,, signatures=0 X-Proofpoint-Spam-Details: rule=fb_default_notspam policy=fb_default score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=863 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1905230127 X-FB-Internal: deliver Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Enable all available cgroup v2 controllers when setting up the environment for the bpf kselftests. It's required to properly test the bpf prog auto-detach feature. Also it will generally increase the code coverage. Signed-off-by: Roman Gushchin Acked-by: Yonghong Song --- tools/testing/selftests/bpf/cgroup_helpers.c | 57 ++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/tools/testing/selftests/bpf/cgroup_helpers.c b/tools/testing/selftests/bpf/cgroup_helpers.c index 6692a40a6979..0d89f0396be4 100644 --- a/tools/testing/selftests/bpf/cgroup_helpers.c +++ b/tools/testing/selftests/bpf/cgroup_helpers.c @@ -33,6 +33,60 @@ snprintf(buf, sizeof(buf), "%s%s%s", CGROUP_MOUNT_PATH, \ CGROUP_WORK_DIR, path) +/** + * enable_all_controllers() - Enable all available cgroup v2 controllers + * + * Enable all available cgroup v2 controllers in order to increase + * the code coverage. + * + * If successful, 0 is returned. + */ +int enable_all_controllers(char *cgroup_path) +{ + char path[PATH_MAX + 1]; + char buf[PATH_MAX]; + char *c, *c2; + int fd, cfd; + size_t len; + + snprintf(path, sizeof(path), "%s/cgroup.controllers", cgroup_path); + fd = open(path, O_RDONLY); + if (fd < 0) { + log_err("Opening cgroup.controllers: %s", path); + return 1; + } + + len = read(fd, buf, sizeof(buf) - 1); + if (len < 0) { + close(fd); + log_err("Reading cgroup.controllers: %s", path); + return 1; + } + buf[len] = 0; + close(fd); + + /* No controllers available? We're probably on cgroup v1. */ + if (len == 0) + return 0; + + snprintf(path, sizeof(path), "%s/cgroup.subtree_control", cgroup_path); + cfd = open(path, O_RDWR); + if (cfd < 0) { + log_err("Opening cgroup.subtree_control: %s", path); + return 1; + } + + for (c = strtok_r(buf, " ", &c2); c; c = strtok_r(NULL, " ", &c2)) { + if (dprintf(cfd, "+%s\n", c) <= 0) { + log_err("Enabling controller %s: %s", c, path); + close(cfd); + return 1; + } + } + close(cfd); + return 0; +} + /** * setup_cgroup_environment() - Setup the cgroup environment * @@ -71,6 +125,9 @@ int setup_cgroup_environment(void) return 1; } + if (enable_all_controllers(cgroup_workdir)) + return 1; + return 0; } -- 2.20.1