From patchwork Fri Aug 26 16:52:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Michal_Koutn=C3=BD?= X-Patchwork-Id: 12956311 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5D7F7ECAAD6 for ; Fri, 26 Aug 2022 16:53:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344798AbiHZQxE (ORCPT ); Fri, 26 Aug 2022 12:53:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57392 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344476AbiHZQxB (ORCPT ); Fri, 26 Aug 2022 12:53:01 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6DCE3D13E; Fri, 26 Aug 2022 09:53:00 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 08C541F949; Fri, 26 Aug 2022 16:52:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1661532779; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ji1E7MsAjBcqVqSFC5OGyfterDo89Vpl5wgi0w24b2M=; b=Io6WW/lReFEVoh0tfyG65yeK5q597USr4Ezze431kIQSvyKY1QYxepjQxV3ql44sWtofbX hNVvKkQfzzU0rpNHiECt8GFBaNvlmnpadC5ihjwByiJMu3sJtF5lb5fx+HO9UYgkl9e49E KIrXDEF6vjiXxrjlkJq/9h74MgAHJDE= Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id C0DE613A82; Fri, 26 Aug 2022 16:52:58 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id QDM2Lmr6CGMofAAAMHmgww (envelope-from ); Fri, 26 Aug 2022 16:52:58 +0000 From: =?utf-8?q?Michal_Koutn=C3=BD?= To: linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, bpf@vger.kernel.org Cc: Tejun Heo , Aditya Kali , Serge Hallyn , Roman Gushchin , Yonghong Song , Muneendra Kumar , Yosry Ahmed , Hao Luo Subject: [PATCH 3/4] cgroup: Homogenize cgroup_get_from_id() return value Date: Fri, 26 Aug 2022 18:52:37 +0200 Message-Id: <20220826165238.30915-4-mkoutny@suse.com> X-Mailer: git-send-email 2.37.0 In-Reply-To: <20220826165238.30915-1-mkoutny@suse.com> References: <20220826165238.30915-1-mkoutny@suse.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org Cgroup id is user provided datum hence extend its return domain to include possible error reason (similar to cgroup_get_from_fd()). This change also fixes commit d4ccaf58a847 ("bpf: Introduce cgroup iter") that would use NULL instead of proper error handling in d4ccaf58a847 ("bpf: Introduce cgroup iter"). Additionally, neither of: fc_appid_store, bpf_iter_attach_cgroup, mem_cgroup_get_from_ino (callers of cgroup_get_from_fd) is built without CONFIG_CGROUPS (depends via CONFIG_BLK_CGROUP, direct, transitive CONFIG_MEMCG respectively) transitive, so drop the singular definition not needed with !CONFIG_CGROUPS. Fixes: d4ccaf58a847 ("bpf: Introduce cgroup iter") Signed-off-by: Michal Koutný --- block/blk-cgroup-fc-appid.c | 4 ++-- include/linux/cgroup.h | 5 ----- kernel/cgroup/cgroup.c | 4 ++-- mm/memcontrol.c | 4 ++-- 4 files changed, 6 insertions(+), 11 deletions(-) diff --git a/block/blk-cgroup-fc-appid.c b/block/blk-cgroup-fc-appid.c index 760a2e1878dd..842e5e1c0f3c 100644 --- a/block/blk-cgroup-fc-appid.c +++ b/block/blk-cgroup-fc-appid.c @@ -19,8 +19,8 @@ int blkcg_set_fc_appid(char *app_id, u64 cgrp_id, size_t app_id_len) return -EINVAL; cgrp = cgroup_get_from_id(cgrp_id); - if (!cgrp) - return -ENOENT; + if (IS_ERR(cgrp)) + return PTR_ERR(cgrp); css = cgroup_get_e_css(cgrp, &io_cgrp_subsys); if (!css) { ret = -ENOENT; diff --git a/include/linux/cgroup.h b/include/linux/cgroup.h index ed53bfe7c46c..b6a9528374a8 100644 --- a/include/linux/cgroup.h +++ b/include/linux/cgroup.h @@ -752,11 +752,6 @@ static inline bool task_under_cgroup_hierarchy(struct task_struct *task, static inline void cgroup_path_from_kernfs_id(u64 id, char *buf, size_t buflen) {} - -static inline struct cgroup *cgroup_get_from_id(u64 id) -{ - return NULL; -} #endif /* !CONFIG_CGROUPS */ #ifdef CONFIG_CGROUPS diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c index 4ca90ee6b902..c0377726031f 100644 --- a/kernel/cgroup/cgroup.c +++ b/kernel/cgroup/cgroup.c @@ -6006,7 +6006,7 @@ void cgroup_path_from_kernfs_id(u64 id, char *buf, size_t buflen) /* * cgroup_get_from_id : get the cgroup associated with cgroup id * @id: cgroup id - * On success return the cgrp, on failure return NULL + * On success return the cgrp or ERR_PTR on failure * Only cgroups within current task's cgroup NS are valid. */ struct cgroup *cgroup_get_from_id(u64 id) @@ -6038,7 +6038,7 @@ struct cgroup *cgroup_get_from_id(u64 id) cgrp = NULL; } out: - return cgrp; + return cgrp ?: ERR_PTR(-ENOENT); } EXPORT_SYMBOL_GPL(cgroup_get_from_id); diff --git a/mm/memcontrol.c b/mm/memcontrol.c index b69979c9ced5..86f5ca8c6fa6 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -5110,8 +5110,8 @@ struct mem_cgroup *mem_cgroup_get_from_ino(unsigned long ino) struct mem_cgroup *memcg; cgrp = cgroup_get_from_id(ino); - if (!cgrp) - return ERR_PTR(-ENOENT); + if (IS_ERR(cgrp)) + return PTR_ERR(cgrp); css = cgroup_get_e_css(cgrp, &memory_cgrp_subsys); if (css)