From patchwork Thu Aug 18 18:27:51 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roman Kagan X-Patchwork-Id: 9288733 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 318F260574 for ; Thu, 18 Aug 2016 23:01:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1ACB229183 for ; Thu, 18 Aug 2016 23:01:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0E9FF291DE; Thu, 18 Aug 2016 23:01:41 +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.8 required=2.0 tests=BAD_ENC_HEADER,BAYES_00, DKIM_SIGNED, RCVD_IN_DNSWL_HI, T_DKIM_INVALID 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 5256D29183 for ; Thu, 18 Aug 2016 23:01:39 +0000 (UTC) Received: from localhost ([::1]:54630 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1baWJe-0001Kb-A8 for patchwork-qemu-devel@patchwork.kernel.org; Thu, 18 Aug 2016 19:01:38 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57516) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1baWJI-0001KK-3H for qemu-devel@nongnu.org; Thu, 18 Aug 2016 19:01:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1baWJC-0005Na-75 for qemu-devel@nongnu.org; Thu, 18 Aug 2016 19:01:15 -0400 Received: from mail-db5eur01on0113.outbound.protection.outlook.com ([104.47.2.113]:46816 helo=EUR01-DB5-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1baWJB-0005ME-In for qemu-devel@nongnu.org; Thu, 18 Aug 2016 19:01:10 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtuozzo.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=DWSpyduPSQ17gqvgPNmy0x5zbmGsjKohKcAK7/6abzA=; b=fB++1z5bbX2iE4CARlkF+2/jWXddVrKV3+RhjBYZBatnaXvXQqArSAgqT2kaTfEtO4wabyDn7tMrUHCVUWexF45kVtKBQIXoe+w5qnP/74YsT0+f0u/D/zSLP/PzHeYfjA4FiETRTSLQq+XUKc0CZrUWNCfLcJKzJM4JxIzURIw= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=rkagan@virtuozzo.com; Received: from rkaganb.sw.ru (195.214.232.10) by HE1PR0802MB2476.eurprd08.prod.outlook.com (10.175.34.149) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA_P384) id 15.1.587.9; Thu, 18 Aug 2016 18:28:34 +0000 From: Roman Kagan To: Date: Thu, 18 Aug 2016 21:27:51 +0300 Message-ID: <1471544874-26996-2-git-send-email-rkagan@virtuozzo.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1471544874-26996-1-git-send-email-rkagan@virtuozzo.com> References: <1471544874-26996-1-git-send-email-rkagan@virtuozzo.com> MIME-Version: 1.0 X-Originating-IP: [195.214.232.10] X-ClientProxiedBy: VI1PR07CA0121.eurprd07.prod.outlook.com (10.165.229.175) To HE1PR0802MB2476.eurprd08.prod.outlook.com (10.175.34.149) X-MS-Office365-Filtering-Correlation-Id: 774e1bdf-6031-489b-be1c-08d3c7957705 X-Microsoft-Exchange-Diagnostics: 1; HE1PR0802M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2uJo7gVHgVorcbMPrTaxbNcPQLQxs1f5safIOFolguy7d4OM8W1VsR1wrZQPo8UWuZd99J0kGfjQoRx; 31:+kZLeKG6BSp2D+1nCVcZbKBphT7uaTw821L4YmUcpoGEUW0zQw3S1TJsbkyCPD6at8JHBGNI1kGGmQwTkHQl1VZFLMjZzGJUBt7p8JBylDWFsD3bDvXpLFT8KECMplgkMXs4vOco4cYZKxm1G8yTwX7Rq124fz4p/MhXPsPRc+Wn9qbL9+A9pQkosy7Zz34YnGieXvT3qhyGksdoNRngOBmzH7ha0R6iMYRNPvpTqMU= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040176)(601004)(2401047)(5005006)(8121501046)(10201501046)(3002001)(6043046)(6042046); SRVR:HE1PR0802MB2476; BCL:0; PCL:0; RULEID:; SRVR:HE1PR0802MB2476; X-Microsoft-Exchange-Diagnostics: 1; HE1PR0802MB2476; 4:9Ep+3VnB+iaQ8buaSNl+1gmzeoFwiyA7IYXrxSepOh0dyFIYanpUCS9D02bKRp4a59OYuVdP9j9wRinriS99aUQ0CSxhd1i2y/RxeMb9aPx9HqBSnvO8fCCcp4r/vpOTavdhGg7QOvytZnyCo622tW3OAbA+gUGjft8WgJn5Te4UmuQGT4DxLA/J7dhSRqnG6mFivaHY5cva7h4iPRGhv8YlHMiInWLatgv983hf5VU1Lk+CQwygsdYeIJ260mqK4Kh5ESUYJuENK2Be5+UW1njPciaHcW2PKE0ff8+E2nz7HfKaUOS/CfR3i8NtH4a0+YPXWC9d+7WbNjXt9EtXP8vaN3uP9UDNdXB/TTC1XZ0XXsAdvzlPiRnn2E4SQ9BQRve4YMtnBgpuo8h7vxFMsje9xVPZxdw70KDKVzv/XOQ= X-Forefront-PRVS: 0038DE95A2 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(4630300001)(6009001)(7916002)(199003)(189002)(76176999)(19580405001)(7846002)(7736002)(50466002)(229853001)(50226002)(6116002)(2351001)(33646002)(4326007)(305945005)(47776003)(3846002)(2906002)(586003)(81156014)(8676002)(66066001)(101416001)(42186005)(86362001)(77096005)(81166006)(50986999)(53416004)(68736007)(97736004)(105586002)(5003940100001)(92566002)(189998001)(19580395003)(110136002)(48376002)(69596002)(106356001)(2950100001)(36756003); DIR:OUT; SFP:1102; SCL:1; SRVR:HE1PR0802MB2476; H:rkaganb.sw.ru; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX:1; LANG:en; Received-SPF: None (protection.outlook.com: virtuozzo.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; HE1PR0802MB2476; 23:bsaPBmKU0VGyRa2YStd30R5b0CZ+UAFUr5jIoys?= =?us-ascii?Q?EfDxbr7nOCia4nCnhjBeCgEWn1JcofaidgdsyN1liHxMuSiNPhSrrcTDk3DK?= =?us-ascii?Q?EdTUqHqMBESHSeYNenOQVXPxqol+4jWg8uR7lyvoBfOMv8GwFj6FQnG52vup?= =?us-ascii?Q?iedPk0ds5azRrJ2pZkQRgBAFnh8awc7KKCMXQp6BNpAJN3JsmzA+e/iuATsM?= =?us-ascii?Q?k5V+CFfnPJHZGJzrB1k4FW4F5sl4vwMNVIGeXmyS+vO4ZgOaH1YEhkgmKEQM?= =?us-ascii?Q?75+mIqPPLw9PIDeHySReWz1+qLETJXuxKpDssUX3Ywa5UTesbifDStGFGsG/?= =?us-ascii?Q?dc+Nx4nXsjUkf5Vr2uVpyxWN5mcOunJrDWtiYSeUrJe32yXPiUcBvS2lZ0PX?= =?us-ascii?Q?MSq08LesRWIZK9KD1UrJDVv7qldEPCPXxxntyVZgQXQdRhFDGVAADVE4mODr?= =?us-ascii?Q?IaMzx/YU2s4mwUy/zN7sA2+Xn9V9QR2D/dwp9mhbxpoHrJpX3FokF5mp/v8L?= =?us-ascii?Q?ajuQPDJEyImnfeIHYCUy/aaBlNaLjBVkCjQnSVmXjQTdjf4W0JDyuNXt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wi9c5xRU3YhHSgiuGqYVzLVhfKl19rehUCeWs+aJptjvhBQMls+82u/CKjBpFYlktUPuufefRuZvOPPxQQ5HnH0wkLHYW0t4JWv986Se8in5T48S02ziEV5J3Vj1GXKDsXuH/mKaRwPg==; 24:bLe7IM2bo1CTXlMVnPBGdxN/Od0Uvo1xjSLLXK2k/2JEulI5Yv43w7i/GE937g858kP9BwaT1vQIAci2/wcuZgr+2zNBfOdq8fD/FZPEodI=; 7:9/jwkBDO3cXgGEBcMCCgu95w2UsC53PQDogyX4g/a41mVtLVYGifCrWtCfCdgAT2meYNA5zvU4o1lacWWiJvxftERFR2wJz71hvfPfDY2arYBB+dFwp/f+W1dPXhZxFq3mwr5nJqtzk4Fg+rBMiwwiWNcNtwSCCslfQ4kUNdEmbdVXIDOlV42BpvGKP9EFRWgk19dXDFeRnWdTx/Qga4EALFw0IbmYieFBGECks7VtF0wf1pM8KCwmSE6hMtWJzD SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; HE1PR0802MB2476; 20:KUUo58NphIh6j+chRLEyDYfzRZ1nj6z5WErplIHXNjMygb45r9rigxJ68YVjm6B107BBo/G7vxxOcedV+ezzJX0gDAF1ss9CwHYn3c7f6pYTTMWTcKVMtLWiYCXK8Ar20caIifyEsucX+06/sWkWIia7Y91oAaJVhOgp3zygiu4= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Aug 2016 18:28:34.2735 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: HE1PR0802MB2476 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 104.47.2.113 Subject: [Qemu-devel] [PATCH 1/4] virtio: assert on ->inuse underflow 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: "Denis V. Lunev" , Roman Kagan , Stefan Hajnoczi , "Michael S. Tsirkin" Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Make sure that ->inuse counter on virtqueue never goes negative. This complements commit afd9096eb1882f23929f5b5c177898ed231bac66, "virtio: error out if guest exceeds virtqueue size", which, due to signed ->inuse comparison against unsigned ->vring.num, manifested a bug in virtio-balloon where virtqueue_push() was called before the matching virtqueu_pop(). [That problem will be addressed in followup patches]. Signed-off-by: Roman Kagan Cc: "Michael S. Tsirkin" Cc: Stefan Hajnoczi --- hw/virtio/virtio.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index 15ee3a7..7a57857 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -92,7 +92,7 @@ struct VirtQueue uint16_t queue_index; - int inuse; + unsigned int inuse; uint16_t vector; VirtIOHandleOutput handle_output; @@ -290,6 +290,7 @@ void virtqueue_fill(VirtQueue *vq, const VirtQueueElement *elem, void virtqueue_flush(VirtQueue *vq, unsigned int count) { uint16_t old, new; + assert(vq->inuse >= count); /* Make sure buffer is written before we update index. */ smp_wmb(); trace_virtqueue_flush(vq, count);