Received: by 10.223.176.46 with SMTP id f43csp2287249wra; Thu, 25 Jan 2018 07:40:20 -0800 (PST) X-Google-Smtp-Source: AH8x226UEQJz/flJ4LdDmzQ++zpCiqOrY6PWEY8P9ibpIqSyYifwfnHyh9NMYsxsboLGZlkMOTJM X-Received: by 2002:a17:902:f64:: with SMTP id 91-v6mr11370638ply.417.1516894820849; Thu, 25 Jan 2018 07:40:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516894820; cv=none; d=google.com; s=arc-20160816; b=oq6PNbSdm4qqpEwDwNBMr7qCRkbwxQwll69RnWrho6Zyf0q7eCLs6YP4dK6Sr60Y+G p//sBLJAVrOii5CHkGmMPu6Ebz/Tzle8zQ9k0dWVLmS9nikmj/+mpYwiLk4lT7/uxPJO vKTgEcF41/xmH0i3NQCkpP8F7brARB50DkwUMOtsG66wPW5+WGJI+yOMrGP26SjDrMsx cnz/t6PyAwZmYWHiTkAIRuopnJ5sFUQgEGnHIDlnvcfdpOD5HPKEYw6C5maoL48ZGR1Y HPMQFPrPW8EZqJMiyIT5C85uDwS1LGkEoxrSDnCf6LWnZeeQVsc7vuGlMkBOMGVx4nPF kNZQ== 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=JGZ+WG6OMBHaKqjD0DO39lgaHCuMQCioRcL/O2zzjjI=; b=ksx8P4XJBAeiPuS81Mj9yt1MyfsubEKd6dTfQDVkaX0ghdwkm9a7aQfbVx8l/MxQlV Q8IPyRBFlg9BSDFQwIT6tlmx4vria2LV8be1ogMhNIFeAc7HFNJadCBAB2/cYdVVj/vy DGupibDBH/CMUI1lhzkODtVgI60cz9gRF7AWFgbZ9WGhQnUbdEb8+pfIMxiJwmMg6nNu gF8AaAD53eFogKVXp7vJdVeKuS27NQSJnMF5QRjhl6apbc/S2QmSdH3727frySFo2e7m 4LQPSYd0M+o7TKHLFia6E7gSYNkWP/I6Mu7xvWl9lJi5Ov+9vVx8tsk1CW3yWyJE1NcQ MDAQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=BtNxr/g5; 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 k6-v6si2137404pla.496.2018.01.25.07.40.05; Thu, 25 Jan 2018 07:40:20 -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=BtNxr/g5; 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 S1751367AbeAYPjR (ORCPT + 99 others); Thu, 25 Jan 2018 10:39:17 -0500 Received: from mail-pg0-f66.google.com ([74.125.83.66]:41656 "EHLO mail-pg0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750769AbeAYPjN (ORCPT ); Thu, 25 Jan 2018 10:39:13 -0500 Received: by mail-pg0-f66.google.com with SMTP id 136so5276427pgd.8; Thu, 25 Jan 2018 07:39:12 -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=JGZ+WG6OMBHaKqjD0DO39lgaHCuMQCioRcL/O2zzjjI=; b=BtNxr/g5fpCRL9mMequoI7tVg3wE36ci6fj7pFksZ8JQ6XrF1lfrooQNY9WHlgrowE MRaSSni25gO7Zx/vTg6ITZ2XZifxXBFVjekARzzuGClfEfKhSV8CYP8IU9LipsxH0pNU yuhijgP65PUHCLxhKyPVqlMR2ikLY2sqQihoq/eyn1eYp7b6+Tuugyie8oH+t5mNXyjc LWRDbf3VQjtvzoLcvTYbApxcle9MXwhEoE4cJ6JyN+5tcpnLHs1M2x+JRkmIY+LyCwSG F50lUeQeHssm09oqZ9nHFZMn/XIscWY0YG8xJd/yMo+ibKurC9aTRcow+IIIlEJBVLFH GzGw== 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=JGZ+WG6OMBHaKqjD0DO39lgaHCuMQCioRcL/O2zzjjI=; b=CCxeighn3iboq/qgtWqMaWGYETWuaEkFZXs2S9FqGQWpgyhVmfkuEcOL2ms3EgD6WE mVjY2yLm0bct3q64VyQsrS8u3tBLuksGrNyr6PzBqEqe+rdwrVqpBZGx3ab+x9A0zZkK gbJdpYq84nZ+igJ9m/UMbgsILtARlNkelq2dNSWC3XYY9BJrKhLvGw0AoslO9wv78fpP o8zj2Ivncrqff5VxOAPFoonPRytzzcaFIhvvaOMlnDbt7hSEF5HDnN5BJyx9dVDFSGZF i7MKslFVyDqFtmZPgPrS4DO452lrzFLbUb7iAjmSSwVT4mHLoYkPUJ4ySkM/l5fcDFXA 5TjA== X-Gm-Message-State: AKwxytcjz/2X2qboZCnvzSN6rcopZJhRZZyEhi6/cG+RVLILMSUT3Rpo 07CGY70CIYuHfupuW7R7RmU= X-Received: by 2002:a17:902:598e:: with SMTP id p14-v6mr11128856pli.289.1516894752497; Thu, 25 Jan 2018 07:39:12 -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 e9sm4965430pgv.14.2018.01.25.07.39.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 25 Jan 2018 07:39:11 -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:38:48 +0800 Message-Id: <1516894728-2061-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 | 18 ++++++++++++++++-- kernel/cgroup/cgroup.c | 6 +----- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/include/linux/cgroup.h b/include/linux/cgroup.h index 473e0c0..1d67def 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) - return &cgrp_dfl_root.cgrp; + /* 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 task_cgroup(current, net_prio_cgrp_id); + } 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