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=-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 CA657C433DB for ; Fri, 19 Feb 2021 11:46:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8DC9264EB3 for ; Fri, 19 Feb 2021 11:46:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230468AbhBSLqp (ORCPT ); Fri, 19 Feb 2021 06:46:45 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:47847 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230461AbhBSLqm (ORCPT ); Fri, 19 Feb 2021 06:46:42 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1613735115; 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=YJlwy/QOkf0QIlTzPZ6przivK3+kqukDr5TR8oal+wM=; b=dJVP5+S1tMVic0IRKW2XmEswBeQV8YIS+t1d3w+xxw75aN4BbJft5z8j8elVX8zlG4mtrd Hxf3OlSMIAAt/ID4rqLcfJ5RVBSqodb3LTI7giRjJUA7Wx6XtpUk/s4cW6n636kO983pzl KnNPLkMRPtJaobU1I3E+gpVgVo19sz8= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-62-kZgZ5Q5CM5CBmJtd3ctDKA-1; Fri, 19 Feb 2021 06:45:13 -0500 X-MC-Unique: kZgZ5Q5CM5CBmJtd3ctDKA-1 Received: by mail-wr1-f70.google.com with SMTP id l10so2325943wry.16 for ; Fri, 19 Feb 2021 03:45:13 -0800 (PST) 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=YJlwy/QOkf0QIlTzPZ6przivK3+kqukDr5TR8oal+wM=; b=IyntMUs9P42dVBZFeb2W4zmjUBy9Wuj2Q+UUnNcNr2tGl6qj3NhwOPD/YnhuPK9HPl s2NuUqYd2hyFvHB03qYywlklKSbDPEa26ifefS8lgRxBHig3nQSJE0RN0rrMApU+P9H8 M+xylZ/L20ZND8+KSgVrue+i1rmmJik9dAGfwo2OR//mGuyW3hYgPegObZg+vhAmM3Zo LnwFGWCw8rPxoBqDA+QZSEQ4Tf85Mr8qo8rHGYfVsQlnVWUGmZF9AB19u3i/18TDmzUU Xnya764d2yhTRCFpCDp9HsQ4jDt3hILdoE2WYYU9+4kmkk5kh79vEnd0ViqNOqMAGqv+ AMxA== X-Gm-Message-State: AOAM532BSwYLt//7E3h1HLq9jIZh+3sM5yfrhJRxXOCTj3rLltnGrXh1 D18WLbnrLSoenDg3hBAN72iS2vJ1JsupQacq16g5bTkfCJWEgSMHao21h+UekS219XMvzrIO0mH jYeSEI2ZG6qqF X-Received: by 2002:adf:bbca:: with SMTP id z10mr8877272wrg.168.1613735112115; Fri, 19 Feb 2021 03:45:12 -0800 (PST) X-Google-Smtp-Source: ABdhPJxZHhoZ2Wy0Wkb5v1FsmoSovOJoQjV0ghbc4hAJ/cIFmfZspDESkeyO+OZmJZh6DupK3/KHUQ== X-Received: by 2002:adf:bbca:: with SMTP id z10mr8877239wrg.168.1613735111985; Fri, 19 Feb 2021 03:45:11 -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 z17sm15710920wrv.9.2021.02.19.03.45.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Feb 2021 03:45:11 -0800 (PST) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Radoslaw Biernacki , Paolo Bonzini , qemu-s390x@nongnu.org, Greg Kurz , Marcel Apfelbaum , qemu-arm@nongnu.org, Cornelia Huck , Aleksandar Rikalo , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , BALATON Zoltan , Huacai Chen , Aurelien Jarno , Richard Henderson , "Edgar E. Iglesias" , Christian Borntraeger , Leif Lindholm , Alistair Francis , Thomas Huth , Peter Maydell , Eduardo Habkost , Jiaxun Yang , Halil Pasic , David Hildenbrand , qemu-ppc@nongnu.org, =?UTF-8?q?Herv=C3=A9=20Poussineau?= , David Gibson , Mark Cave-Ayland , kvm@vger.kernel.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH 7/7] accel/kvm: Exit gracefully when KVM is not supported Date: Fri, 19 Feb 2021 12:44:28 +0100 Message-Id: <20210219114428.1936109-8-philmd@redhat.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210219114428.1936109-1-philmd@redhat.com> References: <20210219114428.1936109-1-philmd@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Now that we added the 'kvm_supported' field to MachineClass and all our machines able to use KVM have this field set, we can check it in kvm_init() and exit gracefully with a friendly error message. Before: $ qemu-system-aarch64 -M raspi3b -enable-kvm qemu-system-aarch64: /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-aarch64 -M raspi3b -enable-kvm Machine 'raspi3b' does not support KVM $ qemu-system-aarch64 -M xlnx-zcu102 -enable-kvm -smp 6 Machine 'xlnx-zcu102' does not support KVM Signed-off-by: Philippe Mathieu-Daudé --- accel/kvm/kvm-all.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index b069938d881..8a8d3f64248 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -2001,6 +2001,12 @@ static int kvm_init(MachineState *ms) s = KVM_STATE(ms->accelerator); + if (!mc->kvm_supported) { + ret = -EINVAL; + fprintf(stderr, "Machine '%s' does not support KVM\n", mc->name); + exit(1); + } + /* * On systems where the kernel can support different base page * sizes, host page size may be different from TARGET_PAGE_SIZE, -- 2.26.2