From patchwork Sat Oct 20 18:56:11 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dennis Zhou X-Patchwork-Id: 10650583 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1C25F1508 for ; Sat, 20 Oct 2018 18:56:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0FDFA28608 for ; Sat, 20 Oct 2018 18:56:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 028F82864B; Sat, 20 Oct 2018 18:56:39 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AC15C28608 for ; Sat, 20 Oct 2018 18:56:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727635AbeJUDHs (ORCPT ); Sat, 20 Oct 2018 23:07:48 -0400 Received: from mail-yb1-f195.google.com ([209.85.219.195]:35996 "EHLO mail-yb1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727350AbeJUDHs (ORCPT ); Sat, 20 Oct 2018 23:07:48 -0400 Received: by mail-yb1-f195.google.com with SMTP id w16-v6so1877496ybp.3; Sat, 20 Oct 2018 11:56:26 -0700 (PDT) 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=L0Pq2h/W1f/KYzbrrTowNUuevgyASLGv6InK8Va0E1U=; b=ewQOpztj2I0W0+6wPbNGobLJiJAII8mINwrQXZyIxwnKMSxYYL0iey0raX+qNVt9YW 5tt8rWTqCh/DoNFcyEDOpTFJaK0pd28OnE/FO/5Vpw64tS8/wIPAL4G+vgDLumXcrciR byA89Mrld5iT82uGk2WgBYN43BlfhKxxX3H8VthPk5WRggxaatvcBmnXPqbMErl3soEF hJUN4VZdxHGB5Bhw0nBN43gWI2MclWpNkZTxLpBdQ9xwpmmEiO5oNjSb3tsVqW4kS6JD SEBOqD/13lKhEOcs50o+SdwvnrMRAZAIIZTpkqbhhJFvgAPHxaScYKPfDxNjJrBEbRX4 VkrQ== X-Gm-Message-State: ABuFfoi+onzAUoD3iW3h+Kkq9Y/f7Ub5gryrHlvqp4a1ZgVrsxgNErfg /ZqG2wzdL9Lg/EMJdxPDU7g= X-Google-Smtp-Source: ACcGV62QcjZJ5yqgOFNNTr8TrQWepjlmv4VHXaNBk0GkduVfY+YhYN9heIlg/OqqXOYOzjLlYmuSvw== X-Received: by 2002:a25:bd05:: with SMTP id f5-v6mr6303567ybk.415.1540061785660; Sat, 20 Oct 2018 11:56:25 -0700 (PDT) Received: from dennisz-mbp.thefacebook.com ([199.201.65.3]) by smtp.gmail.com with ESMTPSA id h63-v6sm1977456ywb.110.2018.10.20.11.56.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 20 Oct 2018 11:56:24 -0700 (PDT) From: Dennis Zhou To: Jens Axboe Cc: Tejun Heo , Valdis Kletnieks , kernel-team@fb.com, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, Dennis Zhou Subject: [PATCH 1/2] blkcg: fix edge case for blk_get_rl() under memory pressure Date: Sat, 20 Oct 2018 14:56:11 -0400 Message-Id: <20181020185612.51587-2-dennis@kernel.org> X-Mailer: git-send-email 2.13.5 In-Reply-To: <20181020185612.51587-1-dennis@kernel.org> References: <20181020185612.51587-1-dennis@kernel.org> Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP It is possible for blkg creation to fail when in blk_get_rl(). In this situation, the fallback logic returns the nearest created blkg. There is however special handling for the request_list for the root blkcg. This fixes the missing edge case from the earlier series changing blk_get_rl(). Fixes: e2b0989954ae ("blkcg: cleanup and make blk_get_rl use blkg_lookup_create") Signed-off-by: Dennis Zhou --- include/linux/blk-cgroup.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/linux/blk-cgroup.h b/include/linux/blk-cgroup.h index b7fd08013de2..1e76ceebeb5d 100644 --- a/include/linux/blk-cgroup.h +++ b/include/linux/blk-cgroup.h @@ -597,7 +597,7 @@ static inline struct request_list *blk_get_rl(struct request_queue *q, if (unlikely(!blkg)) blkg = __blkg_lookup_create(blkcg, q); - if (!blkg_tryget(blkg)) + if (blkg->blkcg == &blkcg_root || !blkg_tryget(blkg)) goto rl_use_root; rcu_read_unlock(); From patchwork Sat Oct 20 18:56:12 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dennis Zhou X-Patchwork-Id: 10650585 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 53A6590 for ; Sat, 20 Oct 2018 18:56:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4711B28608 for ; Sat, 20 Oct 2018 18:56:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3B78828640; Sat, 20 Oct 2018 18:56:40 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CCE8D2863B for ; Sat, 20 Oct 2018 18:56:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727713AbeJUDHu (ORCPT ); Sat, 20 Oct 2018 23:07:50 -0400 Received: from mail-yb1-f196.google.com ([209.85.219.196]:37775 "EHLO mail-yb1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727350AbeJUDHt (ORCPT ); Sat, 20 Oct 2018 23:07:49 -0400 Received: by mail-yb1-f196.google.com with SMTP id d18-v6so470230yba.4; Sat, 20 Oct 2018 11:56:27 -0700 (PDT) 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=KkdtuFX2uavZKvEtnUbKPx2Udp2W7+C0YOnpZnMzffg=; b=DKSrhHiJS4mvR9NdPn9v9oGbYp6v91srxFUJvwrWd71K1FJX9xtszL7T33eI6USNM5 i3yRIoRwx/ULw1rr/s3fXmw0xJAgn7rbIqW0D5apWoADOQE+Mod06nTbn+orhpvuzbGs w7x6uQDQo6M4e53OslCejlN8kFoOKSnttzkYDG8Jk0D73ijSBdp/yrZOOHFmCMZlePoe m9EwYl97FKFxi/5claUTTi0mW4mm27FgiIxBXizZUptKq+ZI+V1TCoIIcIOq4Gd0abpH Al/pEe/MZXI+5G0MGK5h7R4J63PwgkCNTA2BS8hTR7k1uSNOVxEOEHeHSPsGLZpW9zrF LrXg== X-Gm-Message-State: ABuFfoi3j75wj0gUzBDvq5hi6SPgvLJkvSUUOeFNHHAMbgR5/7Z9F4mN 1Eft0cEdoYVBnr3b9k0/XHk= X-Google-Smtp-Source: ACcGV61iqM4jLAZJMdJnAzbS+++7R/6Q/sfZEV3s0jVPmljHLnR6EUnrgmw7olZnY2WDxTmpBXCxQQ== X-Received: by 2002:a25:51c7:: with SMTP id f190-v6mr27659736ybb.426.1540061786997; Sat, 20 Oct 2018 11:56:26 -0700 (PDT) Received: from dennisz-mbp.thefacebook.com ([199.201.65.3]) by smtp.gmail.com with ESMTPSA id h63-v6sm1977456ywb.110.2018.10.20.11.56.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 20 Oct 2018 11:56:26 -0700 (PDT) From: Dennis Zhou To: Jens Axboe Cc: Tejun Heo , Valdis Kletnieks , kernel-team@fb.com, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, Dennis Zhou Subject: [PATCH 2/2] blkcg: reassociate bios when make_request() is called recursively Date: Sat, 20 Oct 2018 14:56:12 -0400 Message-Id: <20181020185612.51587-3-dennis@kernel.org> X-Mailer: git-send-email 2.13.5 In-Reply-To: <20181020185612.51587-1-dennis@kernel.org> References: <20181020185612.51587-1-dennis@kernel.org> Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP When submitting a bio, multiple recursive calls to make_request() may occur. This causes the initial associate done in blkcg_bio_issue_check() to be incorrect and reference the prior request_queue. This introduces a helper to do reassociation when make_request() is recursively called. Fixes: a7b39b4e961c ("blkcg: always associate a bio with a blkg") Reported-by: Valdis Kletnieks Signed-off-by: Dennis Zhou Tested-by: Valdis Kletnieks --- block/bio.c | 20 ++++++++++++++++++++ block/blk-core.c | 1 + include/linux/bio.h | 3 +++ 3 files changed, 24 insertions(+) diff --git a/block/bio.c b/block/bio.c index 17a8b0aa7050..bbfeb4ee2892 100644 --- a/block/bio.c +++ b/block/bio.c @@ -2083,6 +2083,26 @@ int bio_associate_create_blkg(struct request_queue *q, struct bio *bio) return ret; } +/** + * bio_reassociate_blkg - reassociate a bio with a blkg from q + * @q: request_queue where bio is going + * @bio: target bio + * + * When submitting a bio, multiple recursive calls to make_request() may occur. + * This causes the initial associate done in blkcg_bio_issue_check() to be + * incorrect and reference the prior request_queue. This performs reassociation + * when this situation happens. + */ +int bio_reassociate_blkg(struct request_queue *q, struct bio *bio) +{ + if (bio->bi_blkg) { + blkg_put(bio->bi_blkg); + bio->bi_blkg = NULL; + } + + return bio_associate_create_blkg(q, bio); +} + /** * bio_disassociate_task - undo bio_associate_current() * @bio: target bio diff --git a/block/blk-core.c b/block/blk-core.c index cdfabc5646da..3ed60723e242 100644 --- a/block/blk-core.c +++ b/block/blk-core.c @@ -2433,6 +2433,7 @@ blk_qc_t generic_make_request(struct bio *bio) if (q) blk_queue_exit(q); q = bio->bi_disk->queue; + bio_reassociate_blkg(q, bio); flags = 0; if (bio->bi_opf & REQ_NOWAIT) flags = BLK_MQ_REQ_NOWAIT; diff --git a/include/linux/bio.h b/include/linux/bio.h index f447b0ebb288..b47c7f716731 100644 --- a/include/linux/bio.h +++ b/include/linux/bio.h @@ -514,6 +514,7 @@ int bio_associate_blkg(struct bio *bio, struct blkcg_gq *blkg); int bio_associate_blkg_from_css(struct bio *bio, struct cgroup_subsys_state *css); int bio_associate_create_blkg(struct request_queue *q, struct bio *bio); +int bio_reassociate_blkg(struct request_queue *q, struct bio *bio); void bio_disassociate_task(struct bio *bio); void bio_clone_blkg_association(struct bio *dst, struct bio *src); #else /* CONFIG_BLK_CGROUP */ @@ -522,6 +523,8 @@ static inline int bio_associate_blkg_from_css(struct bio *bio, { return 0; } static inline int bio_associate_create_blkg(struct request_queue *q, struct bio *bio) { return 0; } +static inline int bio_reassociate_blkg(struct request_queue *q, struct bio *bio) +{ return 0; } static inline void bio_disassociate_task(struct bio *bio) { } static inline void bio_clone_blkg_association(struct bio *dst, struct bio *src) { }