From patchwork Tue May 30 15:07:24 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Huth X-Patchwork-Id: 9754773 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 CCC91602B9 for ; Tue, 30 May 2017 15:07:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BD3AA274A3 for ; Tue, 30 May 2017 15:07:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B068E27F07; Tue, 30 May 2017 15:07:45 +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,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 48DBC274A3 for ; Tue, 30 May 2017 15:07:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751486AbdE3PHn (ORCPT ); Tue, 30 May 2017 11:07:43 -0400 Received: from mx1.redhat.com ([209.132.183.28]:33826 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751106AbdE3PHm (ORCPT ); Tue, 30 May 2017 11:07:42 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 903C47F4AF; Tue, 30 May 2017 15:07:41 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 903C47F4AF Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=thuth@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 903C47F4AF Received: from thh440s.str.redhat.com (dhcp-192-189.str.redhat.com [10.33.192.189]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6CBBD7FE85; Tue, 30 May 2017 15:07:25 +0000 (UTC) From: Thomas Huth To: kvm@vger.kernel.org Cc: pbonzini@redhat.com, rkrcmar@redhat.com, lvivier@redhat.com, kvm-ppc@vger.kernel.org Subject: [kvm-unit-tests PATCH] powerpc: Fix endless loop that occurs without a device tree Date: Tue, 30 May 2017 17:07:24 +0200 Message-Id: <1496156844-29196-1-git-send-email-thuth@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Tue, 30 May 2017 15:07:41 +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 When running a powerpc kvm-unit-test, and there is accidentially no device tree available, the test ends up in an endless loop, spamming the console with "rtas_node: /rtas: FDT_ERR_BADMAGIC" messages: Somewhere the code calls abort() due to the missing device tree, and abort() calls exit() which in turn tries to shut down the VM with rtas_power_off(). rtas_power_off() needs the device tree again to look up the right RTAS token and we then end up in the next iteration. Fix it by adding some proper checks to rtas_power_off() and rtas_token(). Signed-off-by: Thomas Huth Reviewed-by: Laurent Vivier --- lib/powerpc/rtas.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/powerpc/rtas.c b/lib/powerpc/rtas.c index 3407e25..a1c560b 100644 --- a/lib/powerpc/rtas.c +++ b/lib/powerpc/rtas.c @@ -74,6 +74,9 @@ int rtas_token(const char *service) const struct fdt_property *prop; u32 *token; + if (!dt_available()) + return RTAS_UNKNOWN_SERVICE; + prop = fdt_get_property(dt_fdt(), rtas_node(), service, NULL); if (prop) { token = (u32 *)prop->data; @@ -116,6 +119,14 @@ int rtas_call(int token, int nargs, int nret, int *outputs, ...) void rtas_power_off(void) { - int ret = rtas_call(rtas_token("power-off"), 2, 1, NULL, -1, -1); + int token, ret; + + token = rtas_token("power-off"); + if (token < 0) { + puts("RTAS power-off not available\n"); + return; + } + + ret = rtas_call(token, 2, 1, NULL, -1, -1); printf("RTAS power-off returned %d\n", ret); }