From patchwork Mon Oct 17 15:46:02 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alberto Garcia X-Patchwork-Id: 9379721 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id EC936607D4 for ; Mon, 17 Oct 2016 15:50:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DE5A7291E9 for ; Mon, 17 Oct 2016 15:50:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D32752926E; Mon, 17 Oct 2016 15:50:51 +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=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 5B8DF291E9 for ; Mon, 17 Oct 2016 15:50:51 +0000 (UTC) Received: from localhost ([::1]:34001 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bwABe-00024b-JO for patchwork-qemu-devel@patchwork.kernel.org; Mon, 17 Oct 2016 11:50:50 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46519) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bwA7O-0006Wg-8z for qemu-devel@nongnu.org; Mon, 17 Oct 2016 11:46:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bwA7K-0001vj-3k for qemu-devel@nongnu.org; Mon, 17 Oct 2016 11:46:26 -0400 Received: from smtp3.mundo-r.com ([212.51.32.191]:49761 helo=smtp4.mundo-r.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bwA7J-0001v8-T9; Mon, 17 Oct 2016 11:46:22 -0400 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A2BTAgAm8QRY/5tjdVtcHAEBBAEBCgEBgzwBAQEBAR2BU400lV0BAQEBAQEFAYEXAY97gjGCD4IIhiICgWc4FAECAQEBAQEBAV4nhGICBCdSED8SPBsZiFYBwl4BAQgogi2DRYJQjHYFjzOKU5AEgW6IHoVpkHseNkQGCIIsUhyBVm+JAQEBAQ X-IPAS-Result: A2BTAgAm8QRY/5tjdVtcHAEBBAEBCgEBgzwBAQEBAR2BU400lV0BAQEBAQEFAYEXAY97gjGCD4IIhiICgWc4FAECAQEBAQEBAV4nhGICBCdSED8SPBsZiFYBwl4BAQgogi2DRYJQjHYFjzOKU5AEgW6IHoVpkHseNkQGCIIsUhyBVm+JAQEBAQ X-IronPort-AV: E=Sophos;i="5.31,357,1473112800"; d="scan'208";a="67262650" Received: from fanzine.igalia.com ([91.117.99.155]) by smtp4.mundo-r.com with ESMTP; 17 Oct 2016 17:46:17 +0200 Received: from a88-114-146-170.elisa-laajakaista.fi ([88.114.146.170] helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim) id 1bwA7F-0004Tp-Fe; Mon, 17 Oct 2016 17:46:17 +0200 Received: from berto by perseus.local with local (Exim 4.87) (envelope-from ) id 1bwA72-0004yM-3J; Mon, 17 Oct 2016 18:46:04 +0300 From: Alberto Garcia To: qemu-devel@nongnu.org Date: Mon, 17 Oct 2016 18:46:02 +0300 Message-Id: <65c04b17fb38a4d89a599d6d52a1a3f621388d55.1476718804.git.berto@igalia.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: References: In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 212.51.32.191 Subject: [Qemu-devel] [PATCH 1/2] throttle: Correct access to wrong BlockBackendPublic structures X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Paolo Bonzini , Alberto Garcia , qemu-stable@nongnu.org, qemu-block@nongnu.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP In 27ccdd52598290f0f8b58be56e235aff7aebfaf3 the throttling fields were moved from BlockDriverState to BlockBackend. However in a few cases the code started using throttling fields from the active BlockBackend instead of the round-robin token, making the algorithm behave incorrectly. This can cause starvation if there's a throttling group with several drives but only one of them has I/O. Reported-by: Paolo Bonzini Signed-off-by: Alberto Garcia Reviewed-by: Paolo Bonzini --- block/throttle-groups.c | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/block/throttle-groups.c b/block/throttle-groups.c index 59545e2..17b2efb 100644 --- a/block/throttle-groups.c +++ b/block/throttle-groups.c @@ -168,6 +168,22 @@ static BlockBackend *throttle_group_next_blk(BlockBackend *blk) return blk_by_public(next); } +/* + * Return whether a BlockBackend has pending requests. + * + * This assumes that tg->lock is held. + * + * @blk: the BlockBackend + * @is_write: the type of operation (read/write) + * @ret: whether the BlockBackend has pending requests. + */ +static inline bool blk_has_pending_reqs(BlockBackend *blk, + bool is_write) +{ + const BlockBackendPublic *blkp = blk_get_public(blk); + return blkp->pending_reqs[is_write]; +} + /* Return the next BlockBackend in the round-robin sequence with pending I/O * requests. * @@ -188,7 +204,7 @@ static BlockBackend *next_throttle_token(BlockBackend *blk, bool is_write) /* get next bs round in round robin style */ token = throttle_group_next_blk(token); - while (token != start && !blkp->pending_reqs[is_write]) { + while (token != start && !blk_has_pending_reqs(token, is_write)) { token = throttle_group_next_blk(token); } @@ -196,10 +212,13 @@ static BlockBackend *next_throttle_token(BlockBackend *blk, bool is_write) * then decide the token is the current bs because chances are * the current bs get the current request queued. */ - if (token == start && !blkp->pending_reqs[is_write]) { + if (token == start && !blk_has_pending_reqs(token, is_write)) { token = blk; } + /* Either we return the original BB, or one with pending requests */ + assert(token == blk || blk_has_pending_reqs(token, is_write)); + return token; } @@ -257,7 +276,7 @@ static void schedule_next_request(BlockBackend *blk, bool is_write) /* Check if there's any pending request to schedule next */ token = next_throttle_token(blk, is_write); - if (!blkp->pending_reqs[is_write]) { + if (!blk_has_pending_reqs(token, is_write)) { return; } @@ -271,7 +290,7 @@ static void schedule_next_request(BlockBackend *blk, bool is_write) qemu_co_queue_next(&blkp->throttled_reqs[is_write])) { token = blk; } else { - ThrottleTimers *tt = &blkp->throttle_timers; + ThrottleTimers *tt = &blk_get_public(token)->throttle_timers; int64_t now = qemu_clock_get_ns(tt->clock_type); timer_mod(tt->timers[is_write], now + 1); tg->any_timer_armed[is_write] = true;