From patchwork Wed Sep 28 10:18:39 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Huth X-Patchwork-Id: 9353703 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 E356B6086A for ; Wed, 28 Sep 2016 10:18:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D4559294A5 for ; Wed, 28 Sep 2016 10:18:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C8891294A7; Wed, 28 Sep 2016 10:18:49 +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 6BA54294A6 for ; Wed, 28 Sep 2016 10:18:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753481AbcI1KSq (ORCPT ); Wed, 28 Sep 2016 06:18:46 -0400 Received: from mx1.redhat.com ([209.132.183.28]:49636 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751907AbcI1KSn (ORCPT ); Wed, 28 Sep 2016 06:18:43 -0400 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BC679624AA; Wed, 28 Sep 2016 10:18:42 +0000 (UTC) Received: from thh440s.redhat.com (ovpn-116-53.ams2.redhat.com [10.36.116.53]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u8SAIeXE017778; Wed, 28 Sep 2016 06:18:41 -0400 From: Thomas Huth To: kvm@vger.kernel.org Cc: =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= , kvm-ppc@vger.kernel.org, Laurent Vivier , Drew Jones , Suraj Jitindar Singh Subject: [kvm-unit-tests PATCH] powerpc: Check whether TM is available before running other tests Date: Wed, 28 Sep 2016 12:18:39 +0200 Message-Id: <1475057919-29017-1-git-send-email-thuth@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Wed, 28 Sep 2016 10:18:42 +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 Transactional memory is currently only supported on KVM-HV, and not yet on KVM-PR. So it's better to check the device tree first and fail gracefully if it's not available. Signed-off-by: Thomas Huth Reviewed-by: Andrew Jones Reviewed-by: Laurent Vivier Reviewed-by: Suraj Jitindar Singh --- powerpc/tm.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/powerpc/tm.c b/powerpc/tm.c index 6ce750a..83d9d3d 100644 --- a/powerpc/tm.c +++ b/powerpc/tm.c @@ -10,6 +10,32 @@ #include #include #include +#include +#include + +/* Check "ibm,pa-features" property of a CPU node for the TM flag */ +static void cpu_has_tm(int fdtnode, u32 regval __unused, void *ptr) +{ + const struct fdt_property *prop; + int plen; + + prop = fdt_get_property(dt_fdt(), fdtnode, "ibm,pa-features", &plen); + assert(prop != NULL); + + if (plen >= 26 && prop->data[1] == 0 && (prop->data[24] & 0x80) != 0) + *(int *)ptr += 1; +} + +/* Check whether all CPU nodes have the TM flag */ +static bool all_cpus_have_tm(void) +{ + int ret; + int available = 0; + + ret = dt_for_each_cpu_node(cpu_has_tm, &available); + + return ret == 0 && available == nr_cpus; +} static int h_cede(void) { @@ -106,6 +132,11 @@ int main(int argc, char **argv) report_prefix_push("tm"); + i = all_cpus_have_tm(); + report_xfail("TM available in 'ibm,pa-features' property", !i, i); + if (!i) + return report_summary(); + all = argc == 1 || !strcmp(argv[1], "all"); for (i = 0; hctests[i].name != NULL; i++) {