Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp4283817pxb; Mon, 25 Oct 2021 00:54:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw/Oiu3DL9ooWCv6ZqzmY7S6ULVXCg1mEf/cdA/ddb0woPycu2tc8dMaxi4qZoTP99GqjVu X-Received: by 2002:a05:6402:1e88:: with SMTP id f8mr23854395edf.247.1635148477783; Mon, 25 Oct 2021 00:54:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635148477; cv=none; d=google.com; s=arc-20160816; b=wKf7f5ZBAd4uYFONhAAVWCEPQVAhmqsGj7Hsi1fQ4CdltYhXkIsmw6XZ1yJPROYAMS Gr+/8H0zolLDOUUXPvpBUXf6NB98vArwOjPhLnT4bnT9T0hZFmm4NtI6hZTLArDVfzrN yQpoz4nczcYnmKFw31Q8fwSVot21xcVrxopmZGMoA5tl2Uhsy1on9IQtpNqRx63GJ74f hOAsntpOi4Ny3yrRKxXZY3wBOX1rZ30PjvkouTLZfmkJx5i9cvOTzgqelUU3QLpWKbXH 8YdUjYY1Pb5qF8Ri1VKBhLJiCwPultaj9kx7GKQCcDe4oJ4hKfHUHDy1acnaVPkOD26q Kn0w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:references:mime-version :message-id:in-reply-to:date:dkim-signature; bh=ZWcH7rWC3ZsHErnrMwwxWzyNMoxVakai+vPjAaFHzVQ=; b=QyuwCOLrpDDvfmEo8/ZGTC0kLlaGxTrXHP5QZbEUWTwguy8lrzCPQf/tkKj2w4snUN MjTlQ6rxvjGNHYSFBmFnU0+IFI/RzzawNRkwI2Ixg9FQkMh+duo9iS4YKyVT0D71RfO0 bMxImMvglSYSyIG54p85oytODXNw+BvIKVy4cRFKqT+F/DpBe6kDGOJ1HNI0iCQSmhKs lOnpuAht56mlLwE9f7ypMBsC83BbOU9BM5whZhrCeUfT4cw1kCRpViA9kXDOB7FComwN XaeXO2Duoi0xyDGqmD0EO+XhGfLS8et6qrcyXE1dTyoVxoApaxci6lLQLZnuDfd2OMpv 3T5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=hOMf4il3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j30si12226056edj.419.2021.10.25.00.54.12; Mon, 25 Oct 2021 00:54:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=hOMf4il3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230345AbhJYGWH (ORCPT + 99 others); Mon, 25 Oct 2021 02:22:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40376 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230342AbhJYGWG (ORCPT ); Mon, 25 Oct 2021 02:22:06 -0400 Received: from mail-pj1-x104a.google.com (mail-pj1-x104a.google.com [IPv6:2607:f8b0:4864:20::104a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 59464C061745 for ; Sun, 24 Oct 2021 23:19:45 -0700 (PDT) Received: by mail-pj1-x104a.google.com with SMTP id n2-20020a17090a2fc200b001a1bafb59bfso6532972pjm.1 for ; Sun, 24 Oct 2021 23:19:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=ZWcH7rWC3ZsHErnrMwwxWzyNMoxVakai+vPjAaFHzVQ=; b=hOMf4il33vbkfJyrzLVbrglaaETehyTreBSt+7K7c6eZFmlWBxyFhb8QmG53tAMHjo 9A8hK5RqzXNl6UGb+aHrz3o1OoeY2Qi/m87JHrptd2Cscjtjhi5OKqHdS3euGZ+DDudF vDpFkGp7HmYoSHhDu/i8JDYjJ/9Lj7E5M5UyH79Xjg+64TS9RKsRfayisnySku0cQpbz UtDKoXNGhPG1DtxPSW40RGRHQEKG2ZqIpmm1+0BsfREZ2y4LufrJHNbKls/e8a1bWs3t JqdKSFi/RIalkhdeKVCE8qoaIHmviBIT1IK5Avzg832qRyK/hHnWPb2D5A/j1A1wC+am eBCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=ZWcH7rWC3ZsHErnrMwwxWzyNMoxVakai+vPjAaFHzVQ=; b=NIfnfnigOvMsIpNons5xGsQ8LJhaSKDTUFfclh5rrujjmzEvvjp/38jJ2/Lz6pSeUB ML8bzeL9j3/tYp9+2b+4fg+XMxky30pTazwzni46/MxzI+6i4unH6DHmqVT6rZVX4e8o OicGwE+qOmXIKPCSpdCUux7bC3DwL7zSx0ukSRKeoDdnWAhHYHls8pnz7izDWnZmPuE1 0R0RoVOUUEIeG6NruPWLDLgDBc0xFe56olbjDFSKVjLLYfis/yUryZ+WMZvGAsUmgysd 2GU9WjsUGaUBEuNFR5xow4z9dVjNMoDyXU5wzPsLv2xxgj2usEvgnhcvGxQ6YZuHZdpn V29g== X-Gm-Message-State: AOAM533nFiRzhzdR01n+MVIBgjZusQQ6q92vI9yAdmjahlSCOCzEXEfa bfaHOnJlRyBdHF196B8Mr27kjO2npvVGaw== X-Received: from shakeelb.svl.corp.google.com ([2620:15c:2cd:202:faf1:73d1:a656:9f7e]) (user=shakeelb job=sendgmr) by 2002:a17:90a:62ca:: with SMTP id k10mr18394369pjs.38.1635142784779; Sun, 24 Oct 2021 23:19:44 -0700 (PDT) Date: Sun, 24 Oct 2021 23:19:15 -0700 In-Reply-To: <20211025061916.3853623-1-shakeelb@google.com> Message-Id: <20211025061916.3853623-2-shakeelb@google.com> Mime-Version: 1.0 References: <20211025061916.3853623-1-shakeelb@google.com> X-Mailer: git-send-email 2.33.0.1079.g6e70778dc9-goog Subject: [PATCH 2/3] cgroup: remove cgroup_mutex from cgroupstats_build From: Shakeel Butt To: Tejun Heo Cc: "=?UTF-8?q?Michal=20Koutn=C3=BD?=" , cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, Shakeel Butt Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The function cgroupstats_build extracts cgroup from the kernfs_node's priv pointer which is a RCU pointer. So, there is no need to grab cgroup_mutex. Just get the reference on the cgroup before using and remove the cgroup_mutex altogether. Signed-off-by: Shakeel Butt --- kernel/cgroup/cgroup-v1.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/kernel/cgroup/cgroup-v1.c b/kernel/cgroup/cgroup-v1.c index f6cc5f8484dc..fd14a60379c1 100644 --- a/kernel/cgroup/cgroup-v1.c +++ b/kernel/cgroup/cgroup-v1.c @@ -698,8 +698,6 @@ int cgroupstats_build(struct cgroupstats *stats, struct dentry *dentry) kernfs_type(kn) != KERNFS_DIR) return -EINVAL; - mutex_lock(&cgroup_mutex); - /* * We aren't being called from kernfs and there's no guarantee on * @kn->priv's validity. For this and css_tryget_online_from_dir(), @@ -707,9 +705,8 @@ int cgroupstats_build(struct cgroupstats *stats, struct dentry *dentry) */ rcu_read_lock(); cgrp = rcu_dereference(*(void __rcu __force **)&kn->priv); - if (!cgrp || cgroup_is_dead(cgrp)) { + if (!cgrp || !cgroup_tryget(cgrp)) { rcu_read_unlock(); - mutex_unlock(&cgroup_mutex); return -ENOENT; } rcu_read_unlock(); @@ -737,7 +734,7 @@ int cgroupstats_build(struct cgroupstats *stats, struct dentry *dentry) } css_task_iter_end(&it); - mutex_unlock(&cgroup_mutex); + cgroup_put(cgrp); return 0; } -- 2.33.0.1079.g6e70778dc9-goog