Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp258454ybi; Thu, 13 Jun 2019 15:31:25 -0700 (PDT) X-Google-Smtp-Source: APXvYqwXSubINRhz2pS9Yo5lYkQT6JusMYCLkwNICB37IvNTZyFQEDNopSuGkt1P6q2xsVeIKy3N X-Received: by 2002:a65:6210:: with SMTP id d16mr31029069pgv.180.1560465085045; Thu, 13 Jun 2019 15:31:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560465085; cv=none; d=google.com; s=arc-20160816; b=OCIp3W9Rk+IICh+i+IWu6nUdHLD9yW3l4DQYtIXS3XczHFudIhUUEhlhF27qsuCCWc MDPDLvv1gOkAm+moPWdMT2AjS3FuoA7aCFA7+47Fe4Blf8ZmG/jlDFA/ksS+oTB3LceM 4kYSFxSsq0USqPgHFFEOiLuRI0/gawbk+9NhK3rxwvTbmFCLABb79qQFcsBHUjt7Zq7K 1x0s/NcnEaBXemKCIIunmTPi0JweM2+GLaFan9iCBVS50gVJjAEVLiShyW6twYGiM3Ho TLfX8d+pNVC7bJeMifKJPbu5J2StZxQw9H1iz/4qPi7aAg40sz43+cQQ8ih8nBoSm2ej nxQQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=ATSPMY1LycdMuuen2+FGO8unSu2r280Z+V2tABkqPms=; b=A6MUVdf5t3iEqNWaN3igJAgzZ/ST/NTQho1BSNTS6eEWcxHBhoD9PIhCHVHJ+RKpFO Xknen9fssGfLguHPD3R72rGdcAA5C8SzJ6D0EtA3HmDWb4L9CbME0CUr3B6vBe73VEDi c4sNEy06hITJc6xW/oio0BZAZxVpatKPRVINeuWjc+8m/ld2Gzu9WRhMOrGnO1XFB56A F8nQDM9w1HxjowXOvVyMAMz9xr02N2KJhByYY79JPof1v2F9N3TZSvow/yXN9KL1X4Vp 0ReRNlmaTIQuAm9j0kGTsJZDZ6UpokPlLtQ7RRJtdE4wkufUxAcuefnPocLQ7IA6QyR5 0Q3w== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=jd4bLITK; 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=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e69si775090pgc.154.2019.06.13.15.31.09; Thu, 13 Jun 2019 15:31:25 -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=fail header.i=@gmail.com header.s=20161025 header.b=jd4bLITK; 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=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727215AbfFMWa5 (ORCPT + 99 others); Thu, 13 Jun 2019 18:30:57 -0400 Received: from mail-pg1-f193.google.com ([209.85.215.193]:47091 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725616AbfFMWaz (ORCPT ); Thu, 13 Jun 2019 18:30:55 -0400 Received: by mail-pg1-f193.google.com with SMTP id v9so290548pgr.13; Thu, 13 Jun 2019 15:30:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=ATSPMY1LycdMuuen2+FGO8unSu2r280Z+V2tABkqPms=; b=jd4bLITKkEvMA8EMVkFOd9Ei4BxXWQzDCuwF62Q8ZBCnX0Mk2AgZ6mXhMpphlt5gai 9+m+18b0dpK42LncKcfIVTRr+OZXfr6RjfPx78oCyVZpJ0ZuDU6vU38kEnzVHTD/M+Td b+7Qx8HWfW4ETnpyfylVcf/RWC0pTQKEUb25HfUhhntRDuLMzbmfvLKuHhxS5dSSmLnX lpxAicyhV8QJWZ5lQU19bkCDYaxIftr5AJM2U4pitEmiZwd2HRnQrP3559QxCwNF/3UM EeDu1oZRlfb0V4Mk380crYwB2gp6EJV86S1vmrpT0DwW/PvbHGGGN9EF8dFIIp17KpDq IoMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=ATSPMY1LycdMuuen2+FGO8unSu2r280Z+V2tABkqPms=; b=KTxa2AEtvxL/VtWHYOl2CsDfZ3z91dZrsB3VcE7l6EBV3b37zdnX/boZKnO18EvMUP 3nBSbXegO4lC6hoek/MlhYYMRGbrpFm+RuMyHs+vYk/fzHtrqKox5abV42kOVvsJtQ7G TwYIdrAGFAA6Mvlv9Zcg92Vggq+dKMNxK/15vbHxVbUCudGQmpGUmUomuBXyy84/q+KP 5ObDnGLC54p4Ms/DglytCZc9uUiIASSQBxl6g5RIj9eWRn8HkTn+UNWjOIyIfPer9wLd Iu6MJzJMI/NklH7GrKY23bOlfFXdoY8Y/RpsjfuY1stfbQ+FzeLU1MtQxxKpRnp25uN7 hirA== X-Gm-Message-State: APjAAAUa1LqtCj6e/sK77aTZaV5/JztOc0VA3CmWzE8cVgwLlU/mbxH8 QFz6XW8fDfDJz1hEGh8XUbbA/F9u X-Received: by 2002:a63:fc61:: with SMTP id r33mr32782404pgk.294.1560465054306; Thu, 13 Jun 2019 15:30:54 -0700 (PDT) Received: from localhost ([2620:10d:c091:500::2:9d14]) by smtp.gmail.com with ESMTPSA id f3sm740516pjo.31.2019.06.13.15.30.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 13 Jun 2019 15:30:53 -0700 (PDT) From: Tejun Heo To: axboe@kernel.dk, jbacik@fb.com Cc: linux-kernel@vger.kernel.org, linux-block@vger.kernel.org, kernel-team@fb.com, dennis@kernel.org, jack@suse.cz, Tejun Heo Subject: [PATCH 3/5] blkcg: perpcu_ref init/exit should be done from blkg_alloc/free() Date: Thu, 13 Jun 2019 15:30:39 -0700 Message-Id: <20190613223041.606735-4-tj@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190613223041.606735-1-tj@kernel.org> References: <20190613223041.606735-1-tj@kernel.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org blkg alloc is performed as a separate step from the rest of blkg creation so that GFP_KERNEL allocations can be used when creating blkgs from configuration file writes because otherwise user actions may fail due to failures of opportunistic GFP_NOWAIT allocations. While making blkgs use percpu_ref, 7fcf2b033b84 ("blkcg: change blkg reference counting to use percpu_ref") incorrectly added unconditional opportunistic percpu_ref_init() to blkg_create() breaking this guarantee. This patch moves percpu_ref_init() to blkg_alloc() so makes it use @gfp_mask that blkg_alloc() is called with. Also, percpu_ref_exit() is moved to blkg_free() for consistency. Signed-off-by: Tejun Heo Fixes: 7fcf2b033b84 ("blkcg: change blkg reference counting to use percpu_ref") Cc: Dennis Zhou --- block/blk-cgroup.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c index e4715b35d42c..04d286934c5e 100644 --- a/block/blk-cgroup.c +++ b/block/blk-cgroup.c @@ -79,6 +79,7 @@ static void blkg_free(struct blkcg_gq *blkg) blkg_rwstat_exit(&blkg->stat_ios); blkg_rwstat_exit(&blkg->stat_bytes); + percpu_ref_exit(&blkg->refcnt); kfree(blkg); } @@ -86,8 +87,6 @@ static void __blkg_release(struct rcu_head *rcu) { struct blkcg_gq *blkg = container_of(rcu, struct blkcg_gq, rcu_head); - percpu_ref_exit(&blkg->refcnt); - /* release the blkcg and parent blkg refs this blkg has been holding */ css_put(&blkg->blkcg->css); if (blkg->parent) @@ -132,6 +131,9 @@ static struct blkcg_gq *blkg_alloc(struct blkcg *blkcg, struct request_queue *q, if (!blkg) return NULL; + if (percpu_ref_init(&blkg->refcnt, blkg_release, 0, gfp_mask)) + goto err_free; + if (blkg_rwstat_init(&blkg->stat_bytes, gfp_mask) || blkg_rwstat_init(&blkg->stat_ios, gfp_mask)) goto err_free; @@ -244,11 +246,6 @@ static struct blkcg_gq *blkg_create(struct blkcg *blkcg, blkg_get(blkg->parent); } - ret = percpu_ref_init(&blkg->refcnt, blkg_release, 0, - GFP_NOWAIT | __GFP_NOWARN); - if (ret) - goto err_cancel_ref; - /* invoke per-policy init */ for (i = 0; i < BLKCG_MAX_POLS; i++) { struct blkcg_policy *pol = blkcg_policy[i]; @@ -281,8 +278,6 @@ static struct blkcg_gq *blkg_create(struct blkcg *blkcg, blkg_put(blkg); return ERR_PTR(ret); -err_cancel_ref: - percpu_ref_exit(&blkg->refcnt); err_put_congested: wb_congested_put(wb_congested); err_put_css: -- 2.17.1