From patchwork Wed Mar 16 10:18:40 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Olaf Hering X-Patchwork-Id: 8597371 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id C2440C0553 for ; Wed, 16 Mar 2016 10:19:11 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 2983D20225 for ; Wed, 16 Mar 2016 10:19:11 +0000 (UTC) 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.kernel.org (Postfix) with ESMTPS id 53839201CE for ; Wed, 16 Mar 2016 10:19:06 +0000 (UTC) Received: from localhost ([::1]:54349 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ag8Xh-00082D-Jg for patchwork-qemu-devel@patchwork.kernel.org; Wed, 16 Mar 2016 06:19:05 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48898) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ag8XZ-0007zV-N0 for qemu-devel@nongnu.org; Wed, 16 Mar 2016 06:18:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ag8XV-00006f-9P for qemu-devel@nongnu.org; Wed, 16 Mar 2016 06:18:57 -0400 Received: from mo6-p00-ob.smtp.rzone.de ([2a01:238:20a:202:5300::8]:41540) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ag8XT-00005r-25; Wed, 16 Mar 2016 06:18:51 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1458123528; l=1467; s=domk; d=aepfle.de; h=In-Reply-To:Content-Disposition:Content-Type:MIME-Version: References:Subject:Cc:To:From:Date; bh=iXDlVm1H9SdgsQ8ZJslSspQUnqSSjtc4BFjqEGBCQJo=; b=yTYAxKqHEyQix6jaYpJ+yBft8lEM7r7J6Lgb02bY2rp7pm84YCkS1V1ZvBLy1+m14q2 G3j5bpu9GUTmmnxBsrUQ4Od1lPmyrYB1G8072GYg/8AzyWM8qp/5nS5ZGsT3L2x55hC+K dli4HikEXm5U+YipTvPJaouAsnXp9DisTPY= X-RZG-AUTH: :P2EQZWCpfu+qG7CngxMFH1J+yackYocTD1iAi8x+OWi/zfN1cLnDYUgpS1SBkIG9WGZgtt2gcEfH2YKVIitlCy4DhA== X-RZG-CLASS-ID: mo00 Received: from probook ([2001:a62:1240:71ff:8:db8a:64aa:c476]) by smtp.strato.de (RZmta 37.21 AUTH) with ESMTPSA id 4036f5s2GAIg01l (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (curve secp521r1 with 521 ECDH bits, eq. 15360 bits RSA)) (Client did not present a certificate); Wed, 16 Mar 2016 11:18:42 +0100 (CET) Received: by probook (Postfix, from userid 1000) id F2D0850733; Wed, 16 Mar 2016 11:18:40 +0100 (CET) Date: Wed, 16 Mar 2016 11:18:40 +0100 From: Olaf Hering To: Kevin Wolf Message-ID: <20160316101840.GA9298@aepfle.de> References: <20160309121139.GA21975@aepfle.de> <56E0173C.70407@redhat.com> <20160309144514.GA29027@aepfle.de> <20160309145837.GI5205@noname.redhat.com> <20160309165026.GA14059@aepfle.de> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20160309165026.GA14059@aepfle.de> User-Agent: Mutt/1.5.24 (6572) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a01:238:20a:202:5300::8 Cc: Paolo Bonzini , qemu-block@nongnu.org, qemu-devel@nongnu.org, Stefan Hajnoczi Subject: Re: [Qemu-devel] bogus bdrv_check_request in bdrv_co_discard X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On Wed, Mar 09, Olaf Hering wrote: > On Wed, Mar 09, Kevin Wolf wrote: > > > Removing integer overflow checks without removing the potentially > > overflowing operation doesn't feel like a particularly good idea, > > though. > > Why does the code use signed ints anyway for sectors and offset?! Until this underlying bug is fixed a change like this works for me: Olaf diff --git a/block/io.c b/block/io.c index a69bfc4..df1e383 100644 --- a/block/io.c +++ b/block/io.c @@ -2464,7 +2464,7 @@ static void coroutine_fn bdrv_discard_co_entry(void *opaque) rwco->ret = bdrv_co_discard(rwco->bs, rwco->sector_num, rwco->nb_sectors); } -int coroutine_fn bdrv_co_discard(BlockDriverState *bs, int64_t sector_num, +static int __bdrv_co_discard(BlockDriverState *bs, int64_t sector_num, int nb_sectors) { BdrvTrackedRequest req; @@ -2546,6 +2546,26 @@ out: return ret; } +int coroutine_fn bdrv_co_discard(BlockDriverState *bs, int64_t sector_num, + int nb_sectors) +{ + int num, ret; + int limit = BDRV_REQUEST_MAX_SECTORS; + int remaining = nb_sectors; + int64_t sector_offset = sector_num; + + do { + num = remaining > limit ? limit : remaining; + ret = __bdrv_co_discard(bs, sector_offset, num); + if (ret < 0) + break; + remaining -= num; + sector_offset += num; + } while (remaining > 0); + + return ret; +} + int bdrv_discard(BlockDriverState *bs, int64_t sector_num, int nb_sectors) { Coroutine *co;