From patchwork Thu Jun 29 13:46:57 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?UmFkaW0gS3LEjW3DocWZ?= X-Patchwork-Id: 9817003 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 338CE602B1 for ; Thu, 29 Jun 2017 13:47:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2688028608 for ; Thu, 29 Jun 2017 13:47:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1A67F286C8; Thu, 29 Jun 2017 13:47:08 +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.9 required=2.0 tests=BAYES_00,HK_RANDOM_FROM, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B33AC28608 for ; Thu, 29 Jun 2017 13:47:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753197AbdF2NrG (ORCPT ); Thu, 29 Jun 2017 09:47:06 -0400 Received: from mx1.redhat.com ([209.132.183.28]:51464 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753177AbdF2NrF (ORCPT ); Thu, 29 Jun 2017 09:47:05 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 88DD22DA455 for ; Thu, 29 Jun 2017 13:47:04 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 88DD22DA455 Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=rkrcmar@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 88DD22DA455 Received: from potion (unknown [10.43.2.65]) by smtp.corp.redhat.com (Postfix) with SMTP id B5B098908D; Thu, 29 Jun 2017 13:46:58 +0000 (UTC) Received: by potion (sSMTP sendmail emulation); Thu, 29 Jun 2017 15:46:57 +0200 Date: Thu, 29 Jun 2017 15:46:57 +0200 From: Radim =?utf-8?B?S3LEjW3DocWZ?= To: Paolo Bonzini Cc: kvm@vger.kernel.org, Drew Jones , Laurent Vivier , Thomas Huth , David Hildenbrand Subject: Re: [kvm-unit-tests PATCH 5/5] arch/run: unify accelerator detection Message-ID: <20170629134657.GA14932@potion> References: <20170628200857.1718-1-rkrcmar@redhat.com> <20170628200857.1718-6-rkrcmar@redhat.com> <13f36817-1957-0c9d-2c7e-86850b695c53@redhat.com> <20170629124549.GB10661@potion> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20170629124549.GB10661@potion> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Thu, 29 Jun 2017 13:47:04 +0000 (UTC) Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 2017-06-29 14:45+0200, Radim Krčmář: > 2017-06-28 22:48+0200, Paolo Bonzini: > > On 28/06/2017 22:08, Radim Krčmář wrote: > > > -if [ "$ACCEL" = "kvm" ] && [ "$kvm_available" != "yes" ]; then > > > - echo "KVM is needed, but not available on this host" > > > +ACCEL=$(get_accel '([ "$HOST" = "arm" ] && [ "$ARCH" = "arm" ]) || [ "$HOST" = "aarch64" ]') || > > > exit 2 > > > > Should x86 do the same as ARM (follow-up patch)? > > Yeah, I'll prepare it when we've agreed on the format. > > > And maybe the test could move from an argument of get_accel to a > > function "arch_kvm_available" that returns 0 if available and 1 if not? > > Right, the arm condition needs to be fixed as > > ([ "$HOST" = "arm" ] && [ "$ARCH" = "arm" ]) || > ([ "$HOST" = "aarch64" ] && [ "$ARCH" = arm -o "$ARCH" = arm64 ]) > > and it would look even worse in the argument ... > > Would it be ok like this? No, we can make a better use of the $HOST variable: diff --git a/arm/run b/arm/run index f2e71eca022d..1245d42edae7 100755 --- a/arm/run +++ b/arm/run @@ -10,7 +10,7 @@ if [ -z "$STANDALONE" ]; then fi processor="$PROCESSOR" -ACCEL=$(get_accel '([ "$HOST" = "arm" ] && [ "$ARCH" = "arm" ]) || [ "$HOST" = "aarch64" ]') || +ACCEL=$(get_accel) || exit 2 qemu=$(search_qemu_binary) || diff --git a/powerpc/run b/powerpc/run index 55b987c5efc5..58921e81eb8f 100755 --- a/powerpc/run +++ b/powerpc/run @@ -9,7 +9,7 @@ if [ -z "$STANDALONE" ]; then source scripts/arch-run.bash fi -ACCEL=$(get_accel '[ "$HOST" = "ppc64" ] && [ "$ARCH" = "ppc64" ]') || +ACCEL=$(get_accel) || exit 2 qemu=$(search_qemu_binary) || diff --git a/s390x/run b/s390x/run index 67d6e88ea7e4..2242ebb79fbc 100755 --- a/s390x/run +++ b/s390x/run @@ -9,7 +9,7 @@ if [ -z "$STANDALONE" ]; then source scripts/arch-run.bash fi -ACCEL=$(get_accel '[ "$HOST" = "s390x" ] && [ "$ARCH" = "s390x" ]') || +ACCEL=$(get_accel) || exit 2 qemu=$(search_qemu_binary) || diff --git a/scripts/arch-run.bash b/scripts/arch-run.bash index a696652c61b1..77071216ff99 100644 --- a/scripts/arch-run.bash +++ b/scripts/arch-run.bash @@ -273,22 +273,26 @@ trap_exit_push () trap -- "$1; $old_exit" EXIT } +kvm_available () +{ + [ -c /dev/kvm ] || + return 1 + + [ "$HOST" = "$ARCH_NAME" ] || + [ "$HOST" = aarch64 -a "$ARCH" = arm ] || + [ "$HOST" = x86_64 -a "$ARCH" = i386 ] +} + get_accel () { - local kvm_available - - if [ -c /dev/kvm ] && eval "$@"; then - kvm_available=yes - fi - - if [ "$ACCEL" = "kvm" ] && [ "$kvm_available" != "yes" ]; then + if [ "$ACCEL" = "kvm" ] && ! kvm_available; then echo "KVM is needed, but not available on this host" >&2 return 2 fi if [ "$ACCEL" ]; then echo $ACCEL - elif [ "$kvm_available" = "yes" ]; then + elif kvm_available; then echo kvm else echo tcg