From patchwork Fri Feb 19 17:38:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 12095909 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=-18.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT 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 06532C433DB for ; Fri, 19 Feb 2021 17:40:14 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id B128560295 for ; Fri, 19 Feb 2021 17:40:13 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B128560295 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.87045.164068 (Exim 4.92) (envelope-from ) id 1lD9l8-000214-L6; Fri, 19 Feb 2021 17:40:06 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 87045.164068; Fri, 19 Feb 2021 17:40:06 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lD9l8-00020S-Gd; Fri, 19 Feb 2021 17:40:06 +0000 Received: by outflank-mailman (input) for mailman id 87045; Fri, 19 Feb 2021 17:40:05 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lD9l7-0001FU-0e for xen-devel@lists.xenproject.org; Fri, 19 Feb 2021 17:40:05 +0000 Received: from us-smtp-delivery-124.mimecast.com (unknown [216.205.24.124]) by us1-rack-iad1.inumbo.com (Halon) with ESMTP id 93aca1b8-4db5-4802-8025-a8201b57b270; Fri, 19 Feb 2021 17:39:58 +0000 (UTC) Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-17-d_bDoTa2MTOYcktTrTGPgA-1; Fri, 19 Feb 2021 12:39:54 -0500 Received: by mail-wr1-f69.google.com with SMTP id o10so2763211wru.11 for ; Fri, 19 Feb 2021 09:39:54 -0800 (PST) Received: from localhost.localdomain (68.red-83-57-175.dynamicip.rima-tde.net. [83.57.175.68]) by smtp.gmail.com with ESMTPSA id r7sm15304999wre.25.2021.02.19.09.39.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Feb 2021 09:39:52 -0800 (PST) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 93aca1b8-4db5-4802-8025-a8201b57b270 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1613756398; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=LKRfXZiJfNSqbVRL/SaOx1v+Z64xt5w41cSycQqYFFE=; b=Bjmh6fywSPPU/REtaHEaRlu05bWrrONLBE99Z0WDU6KkBh5uB5z5oE3Y47iRFrTXGr0SYs RFMVwi+f/B1Sayp+X7BK3Ev2Xfu6SQWa4npECu6Uv0w9KmosKUGsRpi6IzY/+TmyC9x82W 1Hr8PPe5yTIFCaSl849mrAO6sSos6JA= X-MC-Unique: d_bDoTa2MTOYcktTrTGPgA-1 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:mime-version:content-transfer-encoding; bh=LKRfXZiJfNSqbVRL/SaOx1v+Z64xt5w41cSycQqYFFE=; b=AAL8ZTRHOPlZN0QiZUIc+8QYrfFuC6rdnT8QjHxsoEaapKmH7G7bjGYvTch1DDj1uO y8VenlKSel4HewBVKkLDuoTcxacVvRLp9cLVHaArbxl/Sj36fNHAulvQSFkO1yFztyF/ +7/XQnEuw/U8EmLm7/xUeRyw5xKM+A3Y2igRKJ/r6fvacOmYPUH3xw1VV7u1CTvKTfnj RmfjWmI5QBGjeskq/fx46ADaFF3mBDW0hQ0A20yxN7cFiN/ybpNddfSG4jXlA6hyg7Ik J0xXH7Srvv9KGVZyi0LZP22lPRyxX+tZzxgru9bLTBoOLYP9Z39AzKKBLtOZE8qPAV1p wgbA== X-Gm-Message-State: AOAM532s7D8XqURdoAUH5lGSMUSBXmC+142X9KyObcxA2I7s409alMKH kekEhooBvrzDemK6QJJdaGH+24X/SA9ieZIH3DEcM2lxE/e7KdpUADGi+g/jqF3rEjBsLjQ91Bp MHzQM6zyVy+llyBZwRFwxuWisxFg= X-Received: by 2002:a1c:4c03:: with SMTP id z3mr9342124wmf.82.1613756393453; Fri, 19 Feb 2021 09:39:53 -0800 (PST) X-Google-Smtp-Source: ABdhPJx2yrJUDqwa1ymG/2RErXjJWx3WIzkQzNQF90+7ijmcN7yAwa2G2hjcHhwa/T8ilbMl1bPCyw== X-Received: by 2002:a1c:4c03:: with SMTP id z3mr9342087wmf.82.1613756393314; Fri, 19 Feb 2021 09:39:53 -0800 (PST) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Aurelien Jarno , Peter Maydell , Anthony Perard , qemu-ppc@nongnu.org, qemu-s390x@nongnu.org, Halil Pasic , Huacai Chen , xen-devel@lists.xenproject.org, Marcel Apfelbaum , David Gibson , qemu-arm@nongnu.org, Stefano Stabellini , Paolo Bonzini , kvm@vger.kernel.org, BALATON Zoltan , Leif Lindholm , Richard Henderson , Radoslaw Biernacki , Alistair Francis , Paul Durrant , Eduardo Habkost , "Michael S. Tsirkin" , Thomas Huth , Jiaxun Yang , =?utf-8?q?Herv=C3=A9_Poussineau?= , Greg Kurz , Christian Borntraeger , Cornelia Huck , "Edgar E. Iglesias" , David Hildenbrand , Mark Cave-Ayland , Aleksandar Rikalo , =?utf-8?q?Philippe_Mathie?= =?utf-8?q?u-Daud=C3=A9?= , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?q?=C3=A9?= Subject: [PATCH v2 11/11] softmmu/vl: Exit gracefully when accelerator is not supported Date: Fri, 19 Feb 2021 18:38:47 +0100 Message-Id: <20210219173847.2054123-12-philmd@redhat.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210219173847.2054123-1-philmd@redhat.com> References: <20210219173847.2054123-1-philmd@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=philmd@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Before configuring an accelerator, check it is valid for the current machine. Doing so we can return a simple error message instead of criptic one. Before: $ qemu-system-arm -M raspi2b -enable-kvm qemu-system-arm: /build/qemu-ETIdrs/qemu-4.2/exec.c:865: cpu_address_space_init: Assertion `asidx == 0 || !kvm_enabled()' failed. Aborted $ qemu-system-aarch64 -M xlnx-zcu102 -enable-kvm -smp 6 qemu-system-aarch64: kvm_init_vcpu: kvm_arch_init_vcpu failed (0): Invalid argument After: $ qemu-system-arm -M raspi2b -enable-kvm qemu-system-aarch64: invalid accelerator 'kvm' for machine raspi2b $ qemu-system-aarch64 -M xlnx-zcu102 -enable-kvm -smp 6 qemu-system-aarch64: -accel kvm: invalid accelerator 'kvm' for machine xlnx-zcu102 Signed-off-by: Philippe Mathieu-Daudé --- softmmu/vl.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/softmmu/vl.c b/softmmu/vl.c index b219ce1f357..f2c4074310b 100644 --- a/softmmu/vl.c +++ b/softmmu/vl.c @@ -2133,6 +2133,7 @@ static int do_configure_accelerator(void *opaque, QemuOpts *opts, Error **errp) const char *acc = qemu_opt_get(opts, "accel"); AccelClass *ac = accel_find(acc); AccelState *accel; + MachineClass *mc; int ret; bool qtest_with_kvm; @@ -2145,6 +2146,12 @@ static int do_configure_accelerator(void *opaque, QemuOpts *opts, Error **errp) } return 0; } + mc = MACHINE_GET_CLASS(current_machine); + if (!qtest_chrdev && !machine_class_valid_for_accelerator(mc, ac->name)) { + *p_init_failed = true; + error_report("invalid accelerator '%s' for machine %s", acc, mc->name); + return 0; + } accel = ACCEL(object_new_with_class(OBJECT_CLASS(ac))); object_apply_compat_props(OBJECT(accel)); qemu_opt_foreach(opts, accelerator_set_property,