From patchwork Thu Nov 9 18:17:41 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Denis V. Lunev\" via" X-Patchwork-Id: 10051619 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 AC247603FA for ; Thu, 9 Nov 2017 18:18:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A41072AF1C for ; Thu, 9 Nov 2017 18:18:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 983532AFA9; Thu, 9 Nov 2017 18:18:48 +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=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 267212AF1C for ; Thu, 9 Nov 2017 18:18:47 +0000 (UTC) Received: from localhost ([::1]:38262 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eCrPa-000409-RN for patchwork-qemu-devel@patchwork.kernel.org; Thu, 09 Nov 2017 13:18:46 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34044) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eCrOq-000402-BX for qemu-devel@nongnu.org; Thu, 09 Nov 2017 13:18:06 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eCrOp-0005YK-Hc for qemu-devel@nongnu.org; Thu, 09 Nov 2017 13:18:00 -0500 Received: from mail-io0-x241.google.com ([2607:f8b0:4001:c06::241]:44620) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eCrOp-0005Xl-Ba for qemu-devel@nongnu.org; Thu, 09 Nov 2017 13:17:59 -0500 Received: by mail-io0-x241.google.com with SMTP id m16so10845174iod.1 for ; Thu, 09 Nov 2017 10:17:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=0XhEwFKKACfxw8EP+AK9nPs0IYynAoSBtvLf8k2b/tk=; b=TYQE4PeCT8Mu2Liw64Mz1q+1SVwpBzc3fLHxTIGcn4AhIFgYGO+EbnJSrMmTwQ/VAY gUZdNMj+Ay+uqLx4ZZsOsxqVrWGM5hHcajbv5JF8WGiBIZ/jkoyUwsI5e9QqzlQ3U5cS CEXJR7LyaDdDzYN32wMyYvwysomes3agJoPZM1WqtRikQwxtsSOJt1D1JxooIFES1VFP COBUhb6seGrL5I87WK0nOKN3JsEIMv25qN9IGZ8gBM/GnF2+gLGwo2amKXo3HbTm26M7 Zz6qj+VKviIEPks7a4lc1o9GAc23DJRnVXbiB4zrOWr94UTQj1/C4i9gR5q/SILO48aD 012g== 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=0XhEwFKKACfxw8EP+AK9nPs0IYynAoSBtvLf8k2b/tk=; b=IM3RK+ORLs9RfYnoGSmr/g3zGYHxvw8LIZezs9li+WWssXkd9T/qm8PZUN91ISHei+ cnKucLgxWq4oFzBbKitujIb1AryztDbV3ETrPbtpXr47bgvBrBjyvfe6ra7/Ipj37as7 qU/sHMFshXyOcARgVJuK2fDkxayM0u5UG+FvN20z8Z2GOIzFqUBtyufSGnwjX1ebQ3ie 5hjfQizZOxs585uMOLpXIgbSbmqxBnPfYsjoWBvfDdqbb1DUmyLiG6VCjP8XEFi+/SH4 VisZOOJRkb5vnfGjl9Ahy/6Gq7etoM1YRGpP7WHEVDen1eXTZSytMKSbrA+2lgZqGRgi i/wg== X-Gm-Message-State: AJaThX6BCdSyX7VrxzX8hZElgi13il+H00yjmPoFgLFdBfZoOQculxE6 akE//cIzTOUrdZWwDXfgWvf0Og== X-Google-Smtp-Source: AGs4zMaR4fVKI/40Gp8E5KhkDVMYQKyFAc8KEpsuJRhOU5PROBTA/J+Ad8CAexLG552fcJCugb68zw== X-Received: by 10.107.42.10 with SMTP id q10mr1803880ioq.196.1510251477564; Thu, 09 Nov 2017 10:17:57 -0800 (PST) Received: from paxos.mtv.corp.google.com ([2620:0:1000:1611:719f:dcc4:97cf:59b5]) by smtp.gmail.com with ESMTPSA id f3sm3577054iob.70.2017.11.09.10.17.56 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 09 Nov 2017 10:17:56 -0800 (PST) To: qemu-devel@nongnu.org, kraxel@redhat.com Date: Thu, 9 Nov 2017 10:17:41 -0800 Message-Id: <20171109181741.31318-1-lepton@google.com> X-Mailer: git-send-email 2.15.0.448.gf294e3d99a-goog In-Reply-To: <152319465.38481678.1510223677165.JavaMail.zimbra@redhat.com> References: <152319465.38481678.1510223677165.JavaMail.zimbra@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4001:c06::241 Subject: [Qemu-devel] [PATCH] virtio-gpu: fix bug in host memory calculation. 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: , X-Patchwork-Original-From: Tao Wu via Qemu-devel From: "Denis V. Lunev\" via" Reply-To: Tao Wu Cc: marcandre.lureau@redhat.com, Tao Wu , airlied@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP The old code treats bits as bytes when calculating host memory usage. Change it to be consistent with allocation logic in pixman library. Signed-off-by: Tao Wu Reviewed-by: Marc-André Lureau --- hw/display/virtio-gpu.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/hw/display/virtio-gpu.c b/hw/display/virtio-gpu.c index 43bbe09ea0..274e365713 100644 --- a/hw/display/virtio-gpu.c +++ b/hw/display/virtio-gpu.c @@ -322,6 +322,18 @@ static pixman_format_code_t get_pixman_format(uint32_t virtio_gpu_format) } } +static uint32_t calc_image_hostmem(pixman_format_code_t pformat, + uint32_t width, uint32_t height) +{ + /* Copied from pixman/pixman-bits-image.c, skip integer overflow check. + * pixman_image_create_bits will fail in case it overflow. + */ + + int bpp = PIXMAN_FORMAT_BPP(pformat); + int stride = ((width * bpp + 0x1f) >> 5) * sizeof(uint32_t); + return height * stride; +} + static void virtio_gpu_resource_create_2d(VirtIOGPU *g, struct virtio_gpu_ctrl_command *cmd) { @@ -366,7 +378,7 @@ static void virtio_gpu_resource_create_2d(VirtIOGPU *g, return; } - res->hostmem = PIXMAN_FORMAT_BPP(pformat) * c2d.width * c2d.height; + res->hostmem = calc_image_hostmem(pformat, c2d.width, c2d.height); if (res->hostmem + g->hostmem < g->conf.max_hostmem) { res->image = pixman_image_create_bits(pformat, c2d.width, @@ -1087,7 +1099,7 @@ static int virtio_gpu_load(QEMUFile *f, void *opaque, size_t size, return -EINVAL; } - res->hostmem = PIXMAN_FORMAT_BPP(pformat) * res->width * res->height; + res->hostmem = calc_image_hostmem(pformat, res->width, res->height); res->addrs = g_new(uint64_t, res->iov_cnt); res->iov = g_new(struct iovec, res->iov_cnt);