From patchwork Fri Aug 19 13:39:20 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roman Kagan X-Patchwork-Id: 9290823 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 C9A74607FF for ; Fri, 19 Aug 2016 20:12:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B745229562 for ; Fri, 19 Aug 2016 20:12:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id ABDD429571; Fri, 19 Aug 2016 20:12:26 +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 1BC4829562 for ; Fri, 19 Aug 2016 20:12:26 +0000 (UTC) Received: from localhost ([::1]:58824 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1baq9O-0004DX-VS for patchwork-qemu-devel@patchwork.kernel.org; Fri, 19 Aug 2016 16:12:23 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56919) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1baq99-0004DH-Ke for qemu-devel@nongnu.org; Fri, 19 Aug 2016 16:12:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1baq94-0004uv-Kq for qemu-devel@nongnu.org; Fri, 19 Aug 2016 16:12:06 -0400 Received: from mail-he1eur01on0119.outbound.protection.outlook.com ([104.47.0.119]:19880 helo=EUR01-HE1-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1baq94-0004uq-3V for qemu-devel@nongnu.org; Fri, 19 Aug 2016 16:12:02 -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=Fn0Lbc/8L9VkOL9n7wTkBa4HSmEM07q5lAZskSbLM14=; b=XBHG3RF30t1/SQNp7xh0F14DKRyzWekrMedFqoZsc9Ovc2ssnbmC3+lKqMp3Uk9BG3UyJvDYEc00mDvVSsIAOoClbnwtM15HWG2JflsVv4PbX589BTp2a8XOkZVcdQHGmF1I7d6QaLuucT8acFxV+/8Mprn6EGKH5Xd1Ewjmgk4= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=rkagan@virtuozzo.com; Received: from rkaganb.sw.ru (195.214.232.10) by DB6PR0802MB2469.eurprd08.prod.outlook.com (10.172.251.17) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA_P384) id 15.1.549.15; Fri, 19 Aug 2016 13:39:40 +0000 From: Roman Kagan To: Date: Fri, 19 Aug 2016 16:39:20 +0300 Message-ID: <1471613966-7267-2-git-send-email-rkagan@virtuozzo.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1471613966-7267-1-git-send-email-rkagan@virtuozzo.com> References: <1471613966-7267-1-git-send-email-rkagan@virtuozzo.com> MIME-Version: 1.0 X-Originating-IP: [195.214.232.10] X-ClientProxiedBy: AM4PR01CA0021.eurprd01.prod.exchangelabs.com (10.164.74.159) To DB6PR0802MB2469.eurprd08.prod.outlook.com (10.172.251.17) X-MS-Office365-Filtering-Correlation-Id: 2fcb77ea-56b7-4a72-9aaf-08d3c836458c X-Microsoft-Exchange-Diagnostics: 1; DB6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B7OAsobSgursUTizCwkayFEt7ZDAPvR7zMHhWjSB2ORTglz9YMQIghzujWtxOzWjNCrnG61LvyhIStbpUlRw==; 31:WsrcQTlds/zJQCfl4deai7FChwBzTdw//z3PtRC9EeEwW+IVtTq+1nVp1l9pm7u3+wnI9MaGbDIcbuxk++3iVUPpfUxnVIkw7NJ2q9+asTXHh/SKlQyktJZxB/xSEOrJV2SH7xqlXtwpDKaTgf1jpiXuYx4VQyeJvVTRgPbbZy6OiXcK4leVmZo4ajEIHjXllB6UTzYj+D34EoTnm04zQkmhcjOQqrLXdX1V2uzQ34g= 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)(3002001)(10201501046)(6043046)(6042046); SRVR:DB6PR0802MB2469; BCL:0; PCL:0; RULEID:; SRVR:DB6PR0802MB2469; X-Microsoft-Exchange-Diagnostics: 1; DB6PR0802MB2469; 4:Jc39WMgBoA/ohojocy+0JwcR7kWQOv0rjcdtkY9E81yJcP6CpxnMT6NR5sucauQCZeHH7Hi1J6c8SG9jGYiim0m6tEC5lQQ8iUxX15x1LMxfqssnqOIgKy6r+ufmSiKalpQ+6q6l1Zn8UQl8lC5wXi9gnhPZQYPMzRXiW3RzxAfHTNnOKmbJaa0pgxwd3s+m4co8NfD0z08DGJWz/mrZ1bgN8oXTJF0aGy05WHWpFGMAABAqWcjw9iAcS9IcV8O3RYZmcNRBJRH7xXdFDIHikwXknSwSzgZlpnOgUOIWsMMOJwMbp3daIQms6FrpIsRMGYXgngLPm9q7VuujMKSLs/waKrYUxWRLS1J46fi6vMuPa+gjy1IkBCOeYsw+cpYgFXrk1iv1Wt0R1Wki4xfu+Z9ysTitUUG0w4Usng96OGM= X-Forefront-PRVS: 0039C6E5C5 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(4630300001)(6009001)(7916002)(189002)(199003)(33646002)(229853001)(305945005)(7736002)(81156014)(92566002)(8676002)(81166006)(7846002)(48376002)(105586002)(47776003)(66066001)(50466002)(101416001)(2906002)(4326007)(586003)(36756003)(2351001)(106356001)(86362001)(50986999)(76176999)(3846002)(6116002)(77096005)(5003940100001)(19580395003)(69596002)(19580405001)(97736004)(189998001)(68736007)(2950100001)(53416004)(110136002)(42186005)(50226002); DIR:OUT; SFP:1102; SCL:1; SRVR:DB6PR0802MB2469; H:rkaganb.sw.ru; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A: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; DB6PR0802MB2469; 23:CxXiDmwDZKVrEzSMkLRER+1VKcsddVykv9Lw1hT?= =?us-ascii?Q?uTCet5AVXkQasHFcr+lTQlNyVEorCqFOx4AJxZ3Uo0HZjckD7aOfyYxA93tI?= =?us-ascii?Q?HRAO+lAem/YpimtwRN29i1B9QePfEsrq4+rPONSJGhMMyxSjHWJ5C9n1wDoC?= =?us-ascii?Q?2RNHRr1uNFaznHYyWpXKcGQkFdqlMctj3FNW5buO1xjMeVr/3jrsQ3dlJZqS?= =?us-ascii?Q?STUFoZlcB4WpJvJWGPwRxiHT8O7XTZxRoE/gY2DJRGh90+K2kgeti/Mb3PHz?= =?us-ascii?Q?gFpv+xOMFBiM2lAmr2dUXHb74VRP2iTlGbYHwlpRwP+7YLccpAzBb9f/UAhf?= =?us-ascii?Q?b1PCkFO5JuPWbPRtLHrY8IdzM/ZegsSZ5Qs5m3VTkbTr/Myo0gbE/Vms+hf0?= =?us-ascii?Q?IgP1ZVDGUxeihL+oxZH7TQ2u9D6lcDOtyvWGcjBDA7Wedn/48F4gX+A++Be2?= =?us-ascii?Q?Y0GulLYuW1qiwVne819qphqg0gzNym+tm4JtlatxGhtTkrLzzu+BuHzbKdNc?= =?us-ascii?Q?+tevbG6ixihRUtaKNKyYzd63huZSuRJgu3S/4wq+guAiRTa8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DBNLs; 5:2QJYxWZnJ1RfUJ+/slDpj7Urd6TyAAdlDT3sN0+hF9e9t+yRkxUSyV6ir8tBApr0h3YMlDEVqlpqErYgdfTKvbkIr6dppqt/G0FAd6UFGCNAuml0lQiTudWE4PZApaSFp7pzP1761ZnzOO1Wto0KSQ==; 24:rWUF5AZpy4lbb2z4nB3VUs/MjcbpOxnSo7Z8fJfx7wQpgR97rP8We7iBehJ/L6IoQW/+U1AroAwqu1O/6Nk7ytsRP5mgSKofEuqFt7DM2SU=; 7:ALa339wFiHRrO5cAmItlk7z0MWG4UhwPJErrVEtsdNlOpHPkTTwG3D5U52w42blxnTF6wk5R+Gx9L99e2PD8Rzu/zL6SDvchPDda7rmAMCuVX8Y+ORReW1j7qSM6DnO2kD+bMm4rqu4hdtzl0AIqZfwCT4mezAgbwnEPza54Rmxt3VgSYB3wQafNKLl/Fl3XsxMQyvSDPhkbflM0AXheo0AcCmAfqxyjbTfXin9lPZZUGGttmhcNYDjt8DXg1wpg SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; DB6PR0802MB2469; 20:iZO3wKVPbwfCggggmOrfng8y3EeFWLnAGP8jTLMtzcofa9tr+XNxZj2shTvoXjf+ltV9Ed3KEAeqFCobAOkX6MKLUTXV7/Sc5PfRYmpv/Kps33MDYo2Xy/uYinHr9khN56V7yqZnV71Y60EKMEF7eOA+8gqUgYzodlrCNxIe8S0= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Aug 2016 13:39:40.4459 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB6PR0802MB2469 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 104.47.0.119 Subject: [Qemu-devel] [PATCH v2 1/6] 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" , Ladi Prosek , 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: Ladi Prosek Cc: Stefan Hajnoczi Reviewed-by: 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);