From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.2 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2A30AC47258 for ; Tue, 5 May 2020 13:02:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 12CC5207DD for ; Tue, 5 May 2020 13:02:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728939AbgEENCU (ORCPT ); Tue, 5 May 2020 09:02:20 -0400 Received: from foss.arm.com ([217.140.110.172]:39348 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728512AbgEENCU (ORCPT ); Tue, 5 May 2020 09:02:20 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 69E5230E; Tue, 5 May 2020 06:02:19 -0700 (PDT) Received: from [192.168.0.110] (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 977013F68F; Tue, 5 May 2020 06:02:18 -0700 (PDT) Subject: Re: [PATCH v3 kvmtool 26/32] vesa: Create device exactly once To: =?UTF-8?Q?Andr=c3=a9_Przywara?= , kvm@vger.kernel.org Cc: will@kernel.org, julien.thierry.kdev@gmail.com, sami.mujawar@arm.com, lorenzo.pieralisi@arm.com References: <20200326152438.6218-1-alexandru.elisei@arm.com> <20200326152438.6218-27-alexandru.elisei@arm.com> From: Alexandru Elisei Message-ID: Date: Tue, 5 May 2020 14:02:49 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.7.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Content-Language: en-US Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Hi, On 4/2/20 9:58 AM, André Przywara wrote: > On 26/03/2020 15:24, Alexandru Elisei wrote: >> A vesa device is used by the SDL, GTK or VNC framebuffers. Don't allow the >> user to specify more than one of these options because kvmtool will create >> identical devices and bad things will happen: >> >> $ ./lkvm run -c2 -m2048 -k bzImage --sdl --gtk >> # lkvm run -k bzImage -m 2048 -c 2 --name guest-10159 >> Error: device region [d0000000-d012bfff] would overlap device region [d0000000-d012bfff] >> *** Error in `./lkvm': free(): invalid pointer: 0x00007fad78002e40 *** >> *** Error in `./lkvm': free(): invalid pointer: 0x00007fad78002e40 *** >> *** Error in `./lkvm': free(): invalid pointer: 0x00007fad78002e40 *** >> ======= Backtrace: ========= >> ======= Backtrace: ========= >> /lib/x86_64-linux-gnu/libc.so.6(+0x777e5)[0x7fae0ed447e5] >> ======= Backtrace: ========= >> /lib/x86_64-linux-gnu/libc.so.6/lib/x86_64-linux-gnu/libc.so.6(+0x8037a)[0x7fae0ed4d37a] >> (+0x777e5)[0x7fae0ed447e5] >> /lib/x86_64-linux-gnu/libc.so.6(+0x777e5)[0x7fae0ed447e5] >> /lib/x86_64-linux-gnu/libc.so.6(+0x8037a)[0x7fae0ed4d37a] >> /lib/x86_64-linux-gnu/libc.so.6(cfree+0x4c)[0x7fae0ed5153c] >> *** Error in `./lkvm': free(): invalid pointer: 0x00007fad78002e40 *** >> /lib/x86_64-linux-gnu/libglib-2.0.so.0(g_string_free+0x3b)[0x7fae0f814dab] >> /lib/x86_64-linux-gnu/libglib-2.0.so.0(g_string_free+0x3b)[0x7fae0f814dab] >> /usr/lib/x86_64-linux-gnu/libgtk-3.so.0(+0x21121c)[0x7fae1023321c] >> /usr/lib/x86_64-linux-gnu/libgtk-3.so.0(+0x21121c)[0x7fae1023321c] >> ======= Backtrace: ========= >> Aborted (core dumped) >> >> The vesa device is explicitly created during the initialization phase of >> the above framebuffers. Remove the superfluous check for their existence. >> > Not really happy about this pointer comparison, but I don't see a better > way, and it's surely good enough for that purpose. I've been giving this patch some thought. I think the fix is wrong. The problem is that the user is allowed to specify more than one of --gtk, --sdl and --vnc. I'll rewrite the patch to fix that, and print an error message that is actually useful for the user. Thanks, Alex > >> Signed-off-by: Alexandru Elisei > Reviewed-by: Andre Przywara > > Cheers, > Andre > >> --- >> hw/vesa.c | 7 +++++-- >> 1 file changed, 5 insertions(+), 2 deletions(-) >> >> diff --git a/hw/vesa.c b/hw/vesa.c >> index dd59a112330b..8071ad153f27 100644 >> --- a/hw/vesa.c >> +++ b/hw/vesa.c >> @@ -61,8 +61,11 @@ struct framebuffer *vesa__init(struct kvm *kvm) >> BUILD_BUG_ON(!is_power_of_two(VESA_MEM_SIZE)); >> BUILD_BUG_ON(VESA_MEM_SIZE < VESA_BPP/8 * VESA_WIDTH * VESA_HEIGHT); >> >> - if (!kvm->cfg.vnc && !kvm->cfg.sdl && !kvm->cfg.gtk) >> - return NULL; >> + if (device__find_dev(vesa_device.bus_type, vesa_device.dev_num) == &vesa_device) { >> + r = -EEXIST; >> + goto out_error; >> + } >> + >> vesa_base_addr = pci_get_io_port_block(PCI_IO_SIZE); >> r = ioport__register(kvm, vesa_base_addr, &vesa_io_ops, PCI_IO_SIZE, NULL); >> if (r < 0) >>