From patchwork Tue Oct 4 09:07:30 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Huth X-Patchwork-Id: 677977 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3spCjg19ndz9s65 for ; Tue, 4 Oct 2016 20:07:35 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752296AbcJDJHe (ORCPT ); Tue, 4 Oct 2016 05:07:34 -0400 Received: from mx1.redhat.com ([209.132.183.28]:43198 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751790AbcJDJHd (ORCPT ); Tue, 4 Oct 2016 05:07:33 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (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 01F50C00BB0D; Tue, 4 Oct 2016 09:07:33 +0000 (UTC) Received: from thh440s.str.redhat.com. (dhcp-192-218.str.redhat.com [10.33.192.218]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u9497VqV016041; Tue, 4 Oct 2016 05:07:31 -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 v3] powerpc: Check whether TM is available before running other tests Date: Tue, 4 Oct 2016 11:07:30 +0200 Message-Id: <1475572050-13164-1-git-send-email-thuth@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Tue, 04 Oct 2016 09:07:33 +0000 (UTC) Sender: kvm-ppc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm-ppc@vger.kernel.org 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 is not available. Reviewed-by: Laurent Vivier Reviewed-by: Andrew Jones Signed-off-by: Thomas Huth Reviewed-by: Suraj Jitindar Singh --- v3: - Removed unnecessary check for "plen >= 26" in cpu_has_tm() v2: - Reworked the check for the "ibm,pa-features" and added a comment - Use a dedicated variable "has_tm" instead of "i" in main() powerpc/tm.c | 43 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/powerpc/tm.c b/powerpc/tm.c index 6ce750a..b611061 100644 --- a/powerpc/tm.c +++ b/powerpc/tm.c @@ -10,6 +10,41 @@ #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); + if (!prop) /* No features means TM is also not available */ + return; + /* Sanity check for the property layout (first two bytes are header) */ + assert(plen >= 8 && prop->data[1] == 0 && prop->data[0] <= plen - 2); + + /* + * The "Transactional Memory Category Support" flags are at byte + * offset 22 and 23 of the attribute type 0, so when adding the + * two bytes for the header, we've got to look at offset 24 for + * the TM support bit. + */ + if (prop->data[0] >= 24 && (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) { @@ -101,11 +136,17 @@ struct { int main(int argc, char **argv) { - bool all; + bool all, has_tm; int i; report_prefix_push("tm"); + has_tm = all_cpus_have_tm(); + report_xfail("TM available in 'ibm,pa-features' property", + !has_tm, has_tm); + if (!has_tm) + return report_summary(); + all = argc == 1 || !strcmp(argv[1], "all"); for (i = 0; hctests[i].name != NULL; i++) {