Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp152877imm; Thu, 30 Aug 2018 18:57:51 -0700 (PDT) X-Google-Smtp-Source: ANB0VdY0cnLxLx5ak7P9zFJut7aHyrk3dgiUF3wa4tIs34SHmK/KyCwnl/A7wjFk8cHxUmg8sMrB X-Received: by 2002:a62:1a8f:: with SMTP id a137-v6mr13325304pfa.190.1535680671411; Thu, 30 Aug 2018 18:57:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535680671; cv=none; d=google.com; s=arc-20160816; b=H/hzitDlzo5oQduIdxzn/QhjHyTDSRg7mHEqzHcwwlL0xoLzTt9gUa0GPDbU+bds8Q MvuhucltPgb97R+fGx1T+RY/eXowf80Qhsg0YCUCtvEAF3gq3j1Z/oG2dcNm+Cq1QNNl xYkzHaAxjCiVEebYjbm2NCvsD0hb+RcuNCj276Uu8UAUqgtfjxG5m8thONUR5NdG37t3 25qMg53M7CauwiuzSbIJwApf3tNYfg9H++kERtHksWdGNCgb4eg/ojWyRt5K0/nLs+EO RxLVMpM3mjFFYBNKt1QsEL1HkcfG7f80JPogIPgIHXYqqPJChBRz5wcScTDN40xsknDt HZkA== 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:arc-authentication-results; bh=rHUzs00gtBEcf/iXCghUQ5cCQKHUCn7Y3ahs7HcS1YY=; b=SpYEqrmXYRvLzpDPDYQOltPb81U3ObhgiKzyckN4h5fZ3RRAShq6khfEwdJ81CCqnK vHMXTE5OLY5jTJNFoOHiozo3y/iXGcmcp7C0cbKMIUfwHqsSiJOhqpZoJ9zCrl1K2lEW gDzaqkzBsibBji8+CwFeA5md1Z9Oete7nQxbkTyxuNGVxB5goJ8fHpT7MAgYpeBajwyQ b2M4bUWi5X9eVbTP0AgpqAmhaGkt4ryYNNGVPSChJYw6farSszGAxUPDg3/y185WVK2+ 3ZJerhxppMZcSiLCTuuX39FDc0vL04oiwEfOOaCIZmOKk+x0HlA7PQt4guWoq5D9+MKS B5sw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=EssQLpyr; 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=QUARANTINE 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 29-v6si8356988pgv.292.2018.08.30.18.57.37; Thu, 30 Aug 2018 18:57:51 -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=pass header.i=@gmail.com header.s=20161025 header.b=EssQLpyr; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727479AbeHaF7V (ORCPT + 99 others); Fri, 31 Aug 2018 01:59:21 -0400 Received: from mail-yb1-f195.google.com ([209.85.219.195]:37464 "EHLO mail-yb1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727352AbeHaF7U (ORCPT ); Fri, 31 Aug 2018 01:59:20 -0400 Received: by mail-yb1-f195.google.com with SMTP id f145-v6so330089ybg.4; Thu, 30 Aug 2018 18:54:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=rHUzs00gtBEcf/iXCghUQ5cCQKHUCn7Y3ahs7HcS1YY=; b=EssQLpyrDxGRJAzRuWy/YJuWpnvt4vsVL2opMZ/12iKE7Tpsb2wt7YhKs3p29chxB3 SoGVl+CqnoPxteowucNydIkpR6aG77oygw6KhmjKEjVPFx7IDLKM/uI0lv5Kkn1WMCks HxhMTSU837YTmCpNj8+CZPcL9pcqzDoYMrJ0OkeiqWKDigan/iSPlBmx502CNvbiFDO4 uSWt8NEJgxwWfQnSuuQzdXkgbRnc3ocbCh8QlTLa0+iluHa+friudt9TwJZW/KpzhVg2 8ByHXyrPfknxI1BgKyrySXdJ6mgEtAU8rDg6EVqAjJAXkAdRgZA5gGGeaAzfUnL+B76f 3BRg== 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:in-reply-to :references; bh=rHUzs00gtBEcf/iXCghUQ5cCQKHUCn7Y3ahs7HcS1YY=; b=hR/BiM2KgLUE6EUWwOvCIJ0jJ0PPzdnLsgRGybRuWFLGxZZFV5S987lNudlo+PCer6 J4oCgfT11ayV6boQVOnLx2Bk2ViwkQJLgBplnX4LoqYqH15eThU5eNmcIi2N/J4MBfGZ Op0OTC8XMjt+mY8iAZEL+M6lS/40Kh6aX9fbGybvysXS+V7yVUnKfE8sUs5qQ1sTFHEa wP6jMQI8HbYwyYBgBG0mnbQNcWazgGAQxMZwKJ224u+6dCIfMpSGJatbDevWEU3Eh6sp dEYAVL/R5ywoDx7iWk8avwXhDxtQYWKU86+hRV+HnfT62K8f1Jz9TXrEmveoA+4o0f14 3iHQ== X-Gm-Message-State: APzg51A6yDuiwqRheuxhU+t37ZpR9zGG29dNXrev62RcjsxRueCZrtvd hvhv6DQr6TcoVzi+8ZAR34U= X-Received: by 2002:a25:b906:: with SMTP id x6-v6mr7117416ybj.309.1535680458315; Thu, 30 Aug 2018 18:54:18 -0700 (PDT) Received: from dennisz-mbp.thefacebook.com ([199.201.65.129]) by smtp.gmail.com with ESMTPSA id j70-v6sm3274084ywb.69.2018.08.30.18.54.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 30 Aug 2018 18:54:17 -0700 (PDT) From: Dennis Zhou To: Jens Axboe , Tejun Heo , Johannes Weiner , Josef Bacik Cc: kernel-team@fb.com, linux-block@vger.kernel.org, cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, "Dennis Zhou (Facebook)" , Jiufei Xue , Joseph Qi Subject: [PATCH 03/15] blkcg: use tryget logic when associating a blkg with a bio Date: Thu, 30 Aug 2018 21:53:44 -0400 Message-Id: <20180831015356.69796-4-dennisszhou@gmail.com> X-Mailer: git-send-email 2.13.5 In-Reply-To: <20180831015356.69796-1-dennisszhou@gmail.com> References: <20180831015356.69796-1-dennisszhou@gmail.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: "Dennis Zhou (Facebook)" There is a very small change a bio gets caught up in a really unfortunate race between a task migration, cgroup exiting, and itself trying to associate with a blkg. This is due to css offlining being performed after the css->refcnt is killed which triggers removal of blkgs that reach their blkg->refcnt of 0. To avoid this, association with a blkg should use tryget and fallback to using the root_blkg. Fixes: 08e18eab0c579 ("block: add bi_blkg to the bio for cgroups") Signed-off-by: Dennis Zhou Cc: Jiufei Xue Cc: Joseph Qi Cc: Tejun Heo Cc: Josef Bacik Cc: Jens Axboe --- block/bio.c | 3 ++- block/blk-throttle.c | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/block/bio.c b/block/bio.c index 04969b392c72..4473ccd22987 100644 --- a/block/bio.c +++ b/block/bio.c @@ -1987,7 +1987,8 @@ int bio_associate_blkg(struct bio *bio, struct blkcg_gq *blkg) { if (unlikely(bio->bi_blkg)) return -EBUSY; - blkg_get(blkg); + if (!blkg_try_get(blkg)) + return -ENODEV; bio->bi_blkg = blkg; return 0; } diff --git a/block/blk-throttle.c b/block/blk-throttle.c index a3eede00d302..c626e1f7cdcd 100644 --- a/block/blk-throttle.c +++ b/block/blk-throttle.c @@ -2129,8 +2129,9 @@ static inline void throtl_update_latency_buckets(struct throtl_data *td) static void blk_throtl_assoc_bio(struct throtl_grp *tg, struct bio *bio) { #ifdef CONFIG_BLK_DEV_THROTTLING_LOW - if (bio->bi_css) - bio_associate_blkg(bio, tg_to_blkg(tg)); + /* fallback to root_blkg if we fail to get a blkg ref */ + if (bio->bi_css && bio_associate_blkg(bio, tg_to_blkg(tg))) + bio_associate_blkg(bio, bio->bi_disk->queue->root_blkg); bio_issue_init(&bio->bi_issue, bio_sectors(bio)); #endif } -- 2.17.1