Received: by 10.223.176.46 with SMTP id f43csp2299824wra; Thu, 25 Jan 2018 07:52:02 -0800 (PST) X-Google-Smtp-Source: AH8x2262R8v+37vYe8WouLlfJXsdxc/oHzfQRTNmOZoi/FIhnzz73ICkc5d3frHV9nbq7xcfHlK3 X-Received: by 2002:a17:902:bd82:: with SMTP id q2-v6mr2226339pls.339.1516895522201; Thu, 25 Jan 2018 07:52:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516895522; cv=none; d=google.com; s=arc-20160816; b=swKhktia8JzhD9qb3QaPHXF4yA8BDqhB3wVY3ZLsZi6n7uaslb9nn16/zJUOEN5LmV 7i+LY2Svh7tGE5hOeRjr+bZC7GdLrdX32Qf0iXL1rFOvt2ePlrnh4p+NaMnJv74mK2vc QUZxJn6lpBH0rnMu33yzXOkd1h5Wo4U6nPmxC7PtkDuql+ztoZ5c2H8mP2NY0vwxY8f9 ZovPO22YIpy5jIPm4oLFtR40l6W7xWmMO1d0h2L0mUO8CJ7ryXM0RkbveDmWMeteEz3X muVssO2leoHPM2ksGicQ49BR13jE6hIabHH8WypDbAKIti5LQBuqCnDUl6sncmi5NdwK 4HIA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=URyhHaYCA6dtxn/yFTGGRDkza89QjZnfuxPB/1gDO0w=; b=I76BOdb9tn0baNPXxhFjDqoCIHsVbBrbsjDuIZs5BKvOm0i3+meOcveWGJ9rNLriZo x6OPWV+GK1YVPkN+blCMGLkK2URcC+p+tkIhjz7442Q3dGNofP8t7+2jCKQzu7cJGWzl egjR/oQ+BCU8bP7VjV5b0khj8v19nq+AIPEo0sW5FLLwb42QtkFcKT6EBOV1JwA0Uq2k 7fYmUd3NYOgchK2rkiDwo/0YChyzY2weIgl1+MQfXFGSr13GVJr/1IAYyWVYS+RAOj3A vxRtv+YbGhcfXxfbKDbY4szf7W0dDvCwUTI5Bw6TzYtXFuMbEe+4XCRkzbIHAB3S/6oo uiFQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Ws/1Kkoj; 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=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x25si4831265pfj.295.2018.01.25.07.51.47; Thu, 25 Jan 2018 07:52:02 -0800 (PST) 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=@gmail.com header.s=20161025 header.b=Ws/1Kkoj; 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=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751318AbeAYPut (ORCPT + 99 others); Thu, 25 Jan 2018 10:50:49 -0500 Received: from mail-pg0-f68.google.com ([74.125.83.68]:43061 "EHLO mail-pg0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751255AbeAYPur (ORCPT ); Thu, 25 Jan 2018 10:50:47 -0500 Received: by mail-pg0-f68.google.com with SMTP id n17so5291783pgf.10; Thu, 25 Jan 2018 07:50:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=URyhHaYCA6dtxn/yFTGGRDkza89QjZnfuxPB/1gDO0w=; b=Ws/1KkojY3+6izCI7O4SoVei68zQwihMExy1v7GJpgGzE0m65V+KjI7D1vtk2yJRvx AXHVQ5gtG4xBgiPOMUaTWQuw1bAdxV9a2y6dznc70tOTj6BCIazAtjwm81T27wwwS0+G BRKR7IjtPcujHI73CILoe1Cw9L//RxYD6WXvUqFzAcyIt/pLtk1Y+kXZSvwMfJvnjvhg 6XdpFShGl75Oafr7UahQNbbErfsvgDaz3Y5qHeYZZaSx5ITE0yeHQbuJbambqbNeLv/c TCpu1MbEl2jiUHDfDHWtJKt2J/w8tKcOxUvhmTEF/NKd2qYt7m7AJepSzPdqEX6++3RL JLnA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=URyhHaYCA6dtxn/yFTGGRDkza89QjZnfuxPB/1gDO0w=; b=sVLgWBbjlolFN/usfrlGpJ3cETqix4kQ4/HqOLw8+piTWYdPZDQjMFUAz7i9V+W7VD TYarj9bT9yGjfAAJvX4vlpYYFyiQdZ5iRGlYC0IJ3a6ntCEU2p6H93Q8AowydeX2uuK3 8lAj3ho35in/07eohmTPynV3yZG5uLGKgKMpPoNKDc+W9HloLj5dj62qc04a2uicyFN4 +YYlDVIEfi/YvPFTQW7FIOy4wVmMSaOqaKL7cFS3okGzwxsbdo0uHhtDeRXJakUmrlfF iFhpIW0otmMeyPsKVKv0RdQKxscnst1nj/I7aeJuecPRBUxH9U56ocGoYIDqDdq9imBM LPug== X-Gm-Message-State: AKwxytcr3UsKczSnAz4i9d8ngkjNdsmkmZQpH0PWF8ri3GIiN1wCyA44 ZcLmeFohoApOWknCSqVvlhMWWmh4 X-Received: by 2002:a17:902:2bc5:: with SMTP id l63-v6mr4434973plb.108.1516895447072; Thu, 25 Jan 2018 07:50:47 -0800 (PST) Received: from li1588-6.members.linode.com (li1588-6.members.linode.com. [139.162.104.6]) by smtp.gmail.com with ESMTPSA id c185sm15436816pfb.146.2018.01.25.07.50.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 25 Jan 2018 07:50:46 -0800 (PST) From: Yafang Shao To: tj@kernel.org, guro@fb.com, davem@davemloft.net, longman@redhat.com, lizefan@huawei.com, hannes@cmpxchg.org Cc: cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, Yafang Shao Subject: [PATCH bpf-next] cgroup: support attaching eBPF programs to net_prio cgroup Date: Thu, 25 Jan 2018 23:50:25 +0800 Message-Id: <1516895425-2311-1-git-send-email-laoar.shao@gmail.com> X-Mailer: git-send-email 1.8.3.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org If net_prio is used, we could also use eBPF programs to attach it, because the net_prio cgroup could be got with prioidx in struct sock_cgroup_data. Hence it should not only be limited to cgroup2. Signed-off-by: Yafang Shao --- include/linux/cgroup.h | 16 +++++++++++++++- kernel/cgroup/cgroup.c | 6 +----- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/include/linux/cgroup.h b/include/linux/cgroup.h index 473e0c0..c0cb46b 100644 --- a/include/linux/cgroup.h +++ b/include/linux/cgroup.h @@ -772,8 +772,22 @@ static inline struct cgroup *sock_cgroup_ptr(struct sock_cgroup_data *skcd) */ v = READ_ONCE(skcd->val); - if (v & 1) + /* either net_prio or net_cls or both being used. */ + if (v & 1) { + if (skcd->prioidx != 1) { + struct cgroup_subsys_state *css; + struct cgroup *cg; + + rcu_read_lock(); + css = css_from_id(skcd->prioidx, &net_prio_cgrp_subsys); + cg = css->cgroup; + rcu_read_unlock(); + + return cg; + } + return &cgrp_dfl_root.cgrp; + } return (struct cgroup *)(unsigned long)v ?: &cgrp_dfl_root.cgrp; #else diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c index 7e4c445..59610f5 100644 --- a/kernel/cgroup/cgroup.c +++ b/kernel/cgroup/cgroup.c @@ -5735,7 +5735,7 @@ struct cgroup *cgroup_get_from_path(const char *path) /** * cgroup_get_from_fd - get a cgroup pointer from a fd - * @fd: fd obtained by open(cgroup2_dir) + * @fd: fd obtained by open(cgroup2_dir or net_prio_dir) * * Find the cgroup from a fd which should be obtained * by opening a cgroup directory. Returns a pointer to the @@ -5758,10 +5758,6 @@ struct cgroup *cgroup_get_from_fd(int fd) return ERR_CAST(css); cgrp = css->cgroup; - if (!cgroup_on_dfl(cgrp)) { - cgroup_put(cgrp); - return ERR_PTR(-EBADF); - } return cgrp; } -- 1.8.3.1