cachepc-qemu

Fork of AMDESE/qemu with changes for cachepc side-channel attack
git clone https://git.sinitax.com/sinitax/cachepc-qemu
Log | Files | Refs | Submodules | LICENSE | sfeed.txt

arm-cpu-features.c (24128B)


      1/*
      2 * Arm CPU feature test cases
      3 *
      4 * Copyright (c) 2019 Red Hat Inc.
      5 * Authors:
      6 *  Andrew Jones <drjones@redhat.com>
      7 *
      8 * This work is licensed under the terms of the GNU GPL, version 2 or later.
      9 * See the COPYING file in the top-level directory.
     10 */
     11#include "qemu/osdep.h"
     12#include "qemu/bitops.h"
     13#include "libqos/libqtest.h"
     14#include "qapi/qmp/qdict.h"
     15#include "qapi/qmp/qjson.h"
     16
     17/*
     18 * We expect the SVE max-vq to be 16. Also it must be <= 64
     19 * for our test code, otherwise 'vls' can't just be a uint64_t.
     20 */
     21#define SVE_MAX_VQ 16
     22
     23#define MACHINE     "-machine virt,gic-version=max -accel tcg "
     24#define MACHINE_KVM "-machine virt,gic-version=max -accel kvm -accel tcg "
     25#define QUERY_HEAD  "{ 'execute': 'query-cpu-model-expansion', " \
     26                    "  'arguments': { 'type': 'full', "
     27#define QUERY_TAIL  "}}"
     28
     29static bool kvm_enabled(QTestState *qts)
     30{
     31    QDict *resp, *qdict;
     32    bool enabled;
     33
     34    resp = qtest_qmp(qts, "{ 'execute': 'query-kvm' }");
     35    g_assert(qdict_haskey(resp, "return"));
     36    qdict = qdict_get_qdict(resp, "return");
     37    g_assert(qdict_haskey(qdict, "enabled"));
     38    enabled = qdict_get_bool(qdict, "enabled");
     39    qobject_unref(resp);
     40
     41    return enabled;
     42}
     43
     44static QDict *do_query_no_props(QTestState *qts, const char *cpu_type)
     45{
     46    return qtest_qmp(qts, QUERY_HEAD "'model': { 'name': %s }"
     47                          QUERY_TAIL, cpu_type);
     48}
     49
     50static QDict *do_query(QTestState *qts, const char *cpu_type,
     51                       const char *fmt, ...)
     52{
     53    QDict *resp;
     54
     55    if (fmt) {
     56        QDict *args;
     57        va_list ap;
     58
     59        va_start(ap, fmt);
     60        args = qdict_from_vjsonf_nofail(fmt, ap);
     61        va_end(ap);
     62
     63        resp = qtest_qmp(qts, QUERY_HEAD "'model': { 'name': %s, "
     64                                                    "'props': %p }"
     65                              QUERY_TAIL, cpu_type, args);
     66    } else {
     67        resp = do_query_no_props(qts, cpu_type);
     68    }
     69
     70    return resp;
     71}
     72
     73static const char *resp_get_error(QDict *resp)
     74{
     75    QDict *qdict;
     76
     77    g_assert(resp);
     78
     79    qdict = qdict_get_qdict(resp, "error");
     80    if (qdict) {
     81        return qdict_get_str(qdict, "desc");
     82    }
     83
     84    return NULL;
     85}
     86
     87#define assert_error(qts, cpu_type, expected_error, fmt, ...)          \
     88({                                                                     \
     89    QDict *_resp;                                                      \
     90    const char *_error;                                                \
     91                                                                       \
     92    _resp = do_query(qts, cpu_type, fmt, ##__VA_ARGS__);               \
     93    g_assert(_resp);                                                   \
     94    _error = resp_get_error(_resp);                                    \
     95    g_assert(_error);                                                  \
     96    g_assert(g_str_equal(_error, expected_error));                     \
     97    qobject_unref(_resp);                                              \
     98})
     99
    100static bool resp_has_props(QDict *resp)
    101{
    102    QDict *qdict;
    103
    104    g_assert(resp);
    105
    106    if (!qdict_haskey(resp, "return")) {
    107        return false;
    108    }
    109    qdict = qdict_get_qdict(resp, "return");
    110
    111    if (!qdict_haskey(qdict, "model")) {
    112        return false;
    113    }
    114    qdict = qdict_get_qdict(qdict, "model");
    115
    116    return qdict_haskey(qdict, "props");
    117}
    118
    119static QDict *resp_get_props(QDict *resp)
    120{
    121    QDict *qdict;
    122
    123    g_assert(resp);
    124    g_assert(resp_has_props(resp));
    125
    126    qdict = qdict_get_qdict(resp, "return");
    127    qdict = qdict_get_qdict(qdict, "model");
    128    qdict = qdict_get_qdict(qdict, "props");
    129
    130    return qdict;
    131}
    132
    133static bool resp_get_feature(QDict *resp, const char *feature)
    134{
    135    QDict *props;
    136
    137    g_assert(resp);
    138    g_assert(resp_has_props(resp));
    139    props = resp_get_props(resp);
    140    g_assert(qdict_get(props, feature));
    141    return qdict_get_bool(props, feature);
    142}
    143
    144#define assert_has_feature(qts, cpu_type, feature)                     \
    145({                                                                     \
    146    QDict *_resp = do_query_no_props(qts, cpu_type);                   \
    147    g_assert(_resp);                                                   \
    148    g_assert(resp_has_props(_resp));                                   \
    149    g_assert(qdict_get(resp_get_props(_resp), feature));               \
    150    qobject_unref(_resp);                                              \
    151})
    152
    153#define assert_has_not_feature(qts, cpu_type, feature)                 \
    154({                                                                     \
    155    QDict *_resp = do_query_no_props(qts, cpu_type);                   \
    156    g_assert(_resp);                                                   \
    157    g_assert(!resp_has_props(_resp) ||                                 \
    158             !qdict_get(resp_get_props(_resp), feature));              \
    159    qobject_unref(_resp);                                              \
    160})
    161
    162#define resp_assert_feature(resp, feature, expected_value)             \
    163({                                                                     \
    164    QDict *_props;                                                     \
    165                                                                       \
    166    g_assert(_resp);                                                   \
    167    g_assert(resp_has_props(_resp));                                   \
    168    _props = resp_get_props(_resp);                                    \
    169    g_assert(qdict_get(_props, feature));                              \
    170    g_assert(qdict_get_bool(_props, feature) == (expected_value));     \
    171})
    172
    173#define assert_feature(qts, cpu_type, feature, expected_value)         \
    174({                                                                     \
    175    QDict *_resp;                                                      \
    176                                                                       \
    177    _resp = do_query_no_props(qts, cpu_type);                          \
    178    g_assert(_resp);                                                   \
    179    resp_assert_feature(_resp, feature, expected_value);               \
    180    qobject_unref(_resp);                                              \
    181})
    182
    183#define assert_set_feature(qts, cpu_type, feature, value)              \
    184({                                                                     \
    185    const char *_fmt = (value) ? "{ %s: true }" : "{ %s: false }";     \
    186    QDict *_resp;                                                      \
    187                                                                       \
    188    _resp = do_query(qts, cpu_type, _fmt, feature);                    \
    189    g_assert(_resp);                                                   \
    190    resp_assert_feature(_resp, feature, value);                        \
    191    qobject_unref(_resp);                                              \
    192})
    193
    194#define assert_has_feature_enabled(qts, cpu_type, feature)             \
    195    assert_feature(qts, cpu_type, feature, true)
    196
    197#define assert_has_feature_disabled(qts, cpu_type, feature)            \
    198    assert_feature(qts, cpu_type, feature, false)
    199
    200static void assert_type_full(QTestState *qts)
    201{
    202    const char *error;
    203    QDict *resp;
    204
    205    resp = qtest_qmp(qts, "{ 'execute': 'query-cpu-model-expansion', "
    206                            "'arguments': { 'type': 'static', "
    207                                           "'model': { 'name': 'foo' }}}");
    208    g_assert(resp);
    209    error = resp_get_error(resp);
    210    g_assert(error);
    211    g_assert(g_str_equal(error,
    212                         "The requested expansion type is not supported"));
    213    qobject_unref(resp);
    214}
    215
    216static void assert_bad_props(QTestState *qts, const char *cpu_type)
    217{
    218    const char *error;
    219    QDict *resp;
    220
    221    resp = qtest_qmp(qts, "{ 'execute': 'query-cpu-model-expansion', "
    222                            "'arguments': { 'type': 'full', "
    223                                           "'model': { 'name': %s, "
    224                                                      "'props': false }}}",
    225                     cpu_type);
    226    g_assert(resp);
    227    error = resp_get_error(resp);
    228    g_assert(error);
    229    g_assert(g_str_equal(error,
    230                         "Invalid parameter type for 'props', expected: dict"));
    231    qobject_unref(resp);
    232}
    233
    234static uint64_t resp_get_sve_vls(QDict *resp)
    235{
    236    QDict *props;
    237    const QDictEntry *e;
    238    uint64_t vls = 0;
    239    int n = 0;
    240
    241    g_assert(resp);
    242    g_assert(resp_has_props(resp));
    243
    244    props = resp_get_props(resp);
    245
    246    for (e = qdict_first(props); e; e = qdict_next(props, e)) {
    247        if (strlen(e->key) > 3 && !strncmp(e->key, "sve", 3) &&
    248            g_ascii_isdigit(e->key[3])) {
    249            char *endptr;
    250            int bits;
    251
    252            bits = g_ascii_strtoll(&e->key[3], &endptr, 10);
    253            if (!bits || *endptr != '\0') {
    254                continue;
    255            }
    256
    257            if (qdict_get_bool(props, e->key)) {
    258                vls |= BIT_ULL((bits / 128) - 1);
    259            }
    260            ++n;
    261        }
    262    }
    263
    264    g_assert(n == SVE_MAX_VQ);
    265
    266    return vls;
    267}
    268
    269#define assert_sve_vls(qts, cpu_type, expected_vls, fmt, ...)          \
    270({                                                                     \
    271    QDict *_resp = do_query(qts, cpu_type, fmt, ##__VA_ARGS__);        \
    272    g_assert(_resp);                                                   \
    273    g_assert(resp_has_props(_resp));                                   \
    274    g_assert(resp_get_sve_vls(_resp) == expected_vls);                 \
    275    qobject_unref(_resp);                                              \
    276})
    277
    278static void sve_tests_default(QTestState *qts, const char *cpu_type)
    279{
    280    /*
    281     * With no sve-max-vq or sve<N> properties on the command line
    282     * the default is to have all vector lengths enabled. This also
    283     * tests that 'sve' is 'on' by default.
    284     */
    285    assert_sve_vls(qts, cpu_type, BIT_ULL(SVE_MAX_VQ) - 1, NULL);
    286
    287    /* With SVE off, all vector lengths should also be off. */
    288    assert_sve_vls(qts, cpu_type, 0, "{ 'sve': false }");
    289
    290    /* With SVE on, we must have at least one vector length enabled. */
    291    assert_error(qts, cpu_type, "cannot disable sve128", "{ 'sve128': false }");
    292
    293    /* Basic enable/disable tests. */
    294    assert_sve_vls(qts, cpu_type, 0x7, "{ 'sve384': true }");
    295    assert_sve_vls(qts, cpu_type, ((BIT_ULL(SVE_MAX_VQ) - 1) & ~BIT_ULL(2)),
    296                   "{ 'sve384': false }");
    297
    298    /*
    299     * ---------------------------------------------------------------------
    300     *               power-of-two(vq)   all-power-            can      can
    301     *                                  of-two(< vq)        enable   disable
    302     * ---------------------------------------------------------------------
    303     * vq < max_vq      no                MUST*              yes      yes
    304     * vq < max_vq      yes               MUST*              yes      no
    305     * ---------------------------------------------------------------------
    306     * vq == max_vq     n/a               MUST*              yes**    yes**
    307     * ---------------------------------------------------------------------
    308     * vq > max_vq      n/a               no                 no       yes
    309     * vq > max_vq      n/a               yes                yes      yes
    310     * ---------------------------------------------------------------------
    311     *
    312     * [*] "MUST" means this requirement must already be satisfied,
    313     *     otherwise 'max_vq' couldn't itself be enabled.
    314     *
    315     * [**] Not testable with the QMP interface, only with the command line.
    316     */
    317
    318    /* max_vq := 8 */
    319    assert_sve_vls(qts, cpu_type, 0x8b, "{ 'sve1024': true }");
    320
    321    /* max_vq := 8, vq < max_vq, !power-of-two(vq) */
    322    assert_sve_vls(qts, cpu_type, 0x8f,
    323                   "{ 'sve1024': true, 'sve384': true }");
    324    assert_sve_vls(qts, cpu_type, 0x8b,
    325                   "{ 'sve1024': true, 'sve384': false }");
    326
    327    /* max_vq := 8, vq < max_vq, power-of-two(vq) */
    328    assert_sve_vls(qts, cpu_type, 0x8b,
    329                   "{ 'sve1024': true, 'sve256': true }");
    330    assert_error(qts, cpu_type, "cannot disable sve256",
    331                 "{ 'sve1024': true, 'sve256': false }");
    332
    333    /* max_vq := 3, vq > max_vq, !all-power-of-two(< vq) */
    334    assert_error(qts, cpu_type, "cannot disable sve512",
    335                 "{ 'sve384': true, 'sve512': false, 'sve640': true }");
    336
    337    /*
    338     * We can disable power-of-two vector lengths when all larger lengths
    339     * are also disabled. We only need to disable the power-of-two length,
    340     * as all non-enabled larger lengths will then be auto-disabled.
    341     */
    342    assert_sve_vls(qts, cpu_type, 0x7, "{ 'sve512': false }");
    343
    344    /* max_vq := 3, vq > max_vq, all-power-of-two(< vq) */
    345    assert_sve_vls(qts, cpu_type, 0x1f,
    346                   "{ 'sve384': true, 'sve512': true, 'sve640': true }");
    347    assert_sve_vls(qts, cpu_type, 0xf,
    348                   "{ 'sve384': true, 'sve512': true, 'sve640': false }");
    349}
    350
    351static void sve_tests_sve_max_vq_8(const void *data)
    352{
    353    QTestState *qts;
    354
    355    qts = qtest_init(MACHINE "-cpu max,sve-max-vq=8");
    356
    357    assert_sve_vls(qts, "max", BIT_ULL(8) - 1, NULL);
    358
    359    /*
    360     * Disabling the max-vq set by sve-max-vq is not allowed, but
    361     * of course enabling it is OK.
    362     */
    363    assert_error(qts, "max", "cannot disable sve1024", "{ 'sve1024': false }");
    364    assert_sve_vls(qts, "max", 0xff, "{ 'sve1024': true }");
    365
    366    /*
    367     * Enabling anything larger than max-vq set by sve-max-vq is not
    368     * allowed, but of course disabling everything larger is OK.
    369     */
    370    assert_error(qts, "max", "cannot enable sve1152", "{ 'sve1152': true }");
    371    assert_sve_vls(qts, "max", 0xff, "{ 'sve1152': false }");
    372
    373    /*
    374     * We can enable/disable non power-of-two lengths smaller than the
    375     * max-vq set by sve-max-vq, but, while we can enable power-of-two
    376     * lengths, we can't disable them.
    377     */
    378    assert_sve_vls(qts, "max", 0xff, "{ 'sve384': true }");
    379    assert_sve_vls(qts, "max", 0xfb, "{ 'sve384': false }");
    380    assert_sve_vls(qts, "max", 0xff, "{ 'sve256': true }");
    381    assert_error(qts, "max", "cannot disable sve256", "{ 'sve256': false }");
    382
    383    qtest_quit(qts);
    384}
    385
    386static void sve_tests_sve_off(const void *data)
    387{
    388    QTestState *qts;
    389
    390    qts = qtest_init(MACHINE "-cpu max,sve=off");
    391
    392    /* SVE is off, so the map should be empty. */
    393    assert_sve_vls(qts, "max", 0, NULL);
    394
    395    /* The map stays empty even if we turn lengths off. */
    396    assert_sve_vls(qts, "max", 0, "{ 'sve128': false }");
    397
    398    /* It's an error to enable lengths when SVE is off. */
    399    assert_error(qts, "max", "cannot enable sve128", "{ 'sve128': true }");
    400
    401    /* With SVE re-enabled we should get all vector lengths enabled. */
    402    assert_sve_vls(qts, "max", BIT_ULL(SVE_MAX_VQ) - 1, "{ 'sve': true }");
    403
    404    /* Or enable SVE with just specific vector lengths. */
    405    assert_sve_vls(qts, "max", 0x3,
    406                   "{ 'sve': true, 'sve128': true, 'sve256': true }");
    407
    408    qtest_quit(qts);
    409}
    410
    411static void sve_tests_sve_off_kvm(const void *data)
    412{
    413    QTestState *qts;
    414
    415    qts = qtest_init(MACHINE_KVM "-cpu max,sve=off");
    416
    417    /*
    418     * We don't know if this host supports SVE so we don't
    419     * attempt to test enabling anything. We only test that
    420     * everything is disabled (as it should be with sve=off)
    421     * and that using sve<N>=off to explicitly disable vector
    422     * lengths is OK too.
    423     */
    424    assert_sve_vls(qts, "max", 0, NULL);
    425    assert_sve_vls(qts, "max", 0, "{ 'sve128': false }");
    426
    427    qtest_quit(qts);
    428}
    429
    430static void pauth_tests_default(QTestState *qts, const char *cpu_type)
    431{
    432    assert_has_feature_enabled(qts, cpu_type, "pauth");
    433    assert_has_feature_disabled(qts, cpu_type, "pauth-impdef");
    434    assert_set_feature(qts, cpu_type, "pauth", false);
    435    assert_set_feature(qts, cpu_type, "pauth", true);
    436    assert_set_feature(qts, cpu_type, "pauth-impdef", true);
    437    assert_set_feature(qts, cpu_type, "pauth-impdef", false);
    438    assert_error(qts, cpu_type, "cannot enable pauth-impdef without pauth",
    439                 "{ 'pauth': false, 'pauth-impdef': true }");
    440}
    441
    442static void test_query_cpu_model_expansion(const void *data)
    443{
    444    QTestState *qts;
    445
    446    qts = qtest_init(MACHINE "-cpu max");
    447
    448    /* Test common query-cpu-model-expansion input validation */
    449    assert_type_full(qts);
    450    assert_bad_props(qts, "max");
    451    assert_error(qts, "foo", "The CPU type 'foo' is not a recognized "
    452                 "ARM CPU type", NULL);
    453    assert_error(qts, "max", "Parameter 'not-a-prop' is unexpected",
    454                 "{ 'not-a-prop': false }");
    455    assert_error(qts, "host", "The CPU type 'host' requires KVM", NULL);
    456
    457    /* Test expected feature presence/absence for some cpu types */
    458    assert_has_feature_enabled(qts, "cortex-a15", "pmu");
    459    assert_has_not_feature(qts, "cortex-a15", "aarch64");
    460
    461    /* Enabling and disabling pmu should always work. */
    462    assert_has_feature_enabled(qts, "max", "pmu");
    463    assert_set_feature(qts, "max", "pmu", false);
    464    assert_set_feature(qts, "max", "pmu", true);
    465
    466    assert_has_not_feature(qts, "max", "kvm-no-adjvtime");
    467    assert_has_not_feature(qts, "max", "kvm-steal-time");
    468
    469    if (g_str_equal(qtest_get_arch(), "aarch64")) {
    470        assert_has_feature_enabled(qts, "max", "aarch64");
    471        assert_has_feature_enabled(qts, "max", "sve");
    472        assert_has_feature_enabled(qts, "max", "sve128");
    473        assert_has_feature_enabled(qts, "cortex-a57", "pmu");
    474        assert_has_feature_enabled(qts, "cortex-a57", "aarch64");
    475
    476        assert_has_feature_enabled(qts, "a64fx", "pmu");
    477        assert_has_feature_enabled(qts, "a64fx", "aarch64");
    478        /*
    479         * A64FX does not support any other vector lengths besides those
    480         * that are enabled by default(128bit, 256bits, 512bit).
    481         */
    482        assert_has_feature_enabled(qts, "a64fx", "sve");
    483        assert_sve_vls(qts, "a64fx", 0xb, NULL);
    484        assert_error(qts, "a64fx", "cannot enable sve384",
    485                     "{ 'sve384': true }");
    486        assert_error(qts, "a64fx", "cannot enable sve640",
    487                     "{ 'sve640': true }");
    488
    489        sve_tests_default(qts, "max");
    490        pauth_tests_default(qts, "max");
    491
    492        /* Test that features that depend on KVM generate errors without. */
    493        assert_error(qts, "max",
    494                     "'aarch64' feature cannot be disabled "
    495                     "unless KVM is enabled and 32-bit EL1 "
    496                     "is supported",
    497                     "{ 'aarch64': false }");
    498    }
    499
    500    qtest_quit(qts);
    501}
    502
    503static void test_query_cpu_model_expansion_kvm(const void *data)
    504{
    505    QTestState *qts;
    506
    507    qts = qtest_init(MACHINE_KVM "-cpu max");
    508
    509    /*
    510     * These tests target the 'host' CPU type, so KVM must be enabled.
    511     */
    512    if (!kvm_enabled(qts)) {
    513        qtest_quit(qts);
    514        return;
    515    }
    516
    517    /* Enabling and disabling kvm-no-adjvtime should always work. */
    518    assert_has_feature_disabled(qts, "host", "kvm-no-adjvtime");
    519    assert_set_feature(qts, "host", "kvm-no-adjvtime", true);
    520    assert_set_feature(qts, "host", "kvm-no-adjvtime", false);
    521
    522    if (g_str_equal(qtest_get_arch(), "aarch64")) {
    523        bool kvm_supports_steal_time;
    524        bool kvm_supports_sve;
    525        char max_name[8], name[8];
    526        uint32_t max_vq, vq;
    527        uint64_t vls;
    528        QDict *resp;
    529        char *error;
    530
    531        assert_error(qts, "cortex-a15",
    532            "We cannot guarantee the CPU type 'cortex-a15' works "
    533            "with KVM on this host", NULL);
    534
    535        assert_has_feature_enabled(qts, "host", "aarch64");
    536
    537        /* Enabling and disabling pmu should always work. */
    538        assert_has_feature_enabled(qts, "host", "pmu");
    539        assert_set_feature(qts, "host", "pmu", false);
    540        assert_set_feature(qts, "host", "pmu", true);
    541
    542        /*
    543         * Some features would be enabled by default, but they're disabled
    544         * because this instance of KVM doesn't support them. Test that the
    545         * features are present, and, when enabled, issue further tests.
    546         */
    547        assert_has_feature(qts, "host", "kvm-steal-time");
    548        assert_has_feature(qts, "host", "sve");
    549
    550        resp = do_query_no_props(qts, "host");
    551        kvm_supports_steal_time = resp_get_feature(resp, "kvm-steal-time");
    552        kvm_supports_sve = resp_get_feature(resp, "sve");
    553        vls = resp_get_sve_vls(resp);
    554        qobject_unref(resp);
    555
    556        if (kvm_supports_steal_time) {
    557            /* If we have steal-time then we should be able to toggle it. */
    558            assert_set_feature(qts, "host", "kvm-steal-time", false);
    559            assert_set_feature(qts, "host", "kvm-steal-time", true);
    560        }
    561
    562        if (kvm_supports_sve) {
    563            g_assert(vls != 0);
    564            max_vq = 64 - __builtin_clzll(vls);
    565            sprintf(max_name, "sve%u", max_vq * 128);
    566
    567            /* Enabling a supported length is of course fine. */
    568            assert_sve_vls(qts, "host", vls, "{ %s: true }", max_name);
    569
    570            /* Get the next supported length smaller than max-vq. */
    571            vq = 64 - __builtin_clzll(vls & ~BIT_ULL(max_vq - 1));
    572            if (vq) {
    573                /*
    574                 * We have at least one length smaller than max-vq,
    575                 * so we can disable max-vq.
    576                 */
    577                assert_sve_vls(qts, "host", (vls & ~BIT_ULL(max_vq - 1)),
    578                               "{ %s: false }", max_name);
    579
    580                /*
    581                 * Smaller, supported vector lengths cannot be disabled
    582                 * unless all larger, supported vector lengths are also
    583                 * disabled.
    584                 */
    585                sprintf(name, "sve%u", vq * 128);
    586                error = g_strdup_printf("cannot disable %s", name);
    587                assert_error(qts, "host", error,
    588                             "{ %s: true, %s: false }",
    589                             max_name, name);
    590                g_free(error);
    591            }
    592
    593            /*
    594             * The smallest, supported vector length is required, because
    595             * we need at least one vector length enabled.
    596             */
    597            vq = __builtin_ffsll(vls);
    598            sprintf(name, "sve%u", vq * 128);
    599            error = g_strdup_printf("cannot disable %s", name);
    600            assert_error(qts, "host", error, "{ %s: false }", name);
    601            g_free(error);
    602
    603            /* Get an unsupported length. */
    604            for (vq = 1; vq <= max_vq; ++vq) {
    605                if (!(vls & BIT_ULL(vq - 1))) {
    606                    break;
    607                }
    608            }
    609            if (vq <= SVE_MAX_VQ) {
    610                sprintf(name, "sve%u", vq * 128);
    611                error = g_strdup_printf("cannot enable %s", name);
    612                assert_error(qts, "host", error, "{ %s: true }", name);
    613                g_free(error);
    614            }
    615        } else {
    616            g_assert(vls == 0);
    617        }
    618    } else {
    619        assert_has_not_feature(qts, "host", "aarch64");
    620        assert_has_not_feature(qts, "host", "pmu");
    621        assert_has_not_feature(qts, "host", "sve");
    622        assert_has_not_feature(qts, "host", "kvm-steal-time");
    623    }
    624
    625    qtest_quit(qts);
    626}
    627
    628int main(int argc, char **argv)
    629{
    630    g_test_init(&argc, &argv, NULL);
    631
    632    qtest_add_data_func("/arm/query-cpu-model-expansion",
    633                        NULL, test_query_cpu_model_expansion);
    634
    635    /*
    636     * For now we only run KVM specific tests with AArch64 QEMU in
    637     * order avoid attempting to run an AArch32 QEMU with KVM on
    638     * AArch64 hosts. That won't work and isn't easy to detect.
    639     */
    640    if (g_str_equal(qtest_get_arch(), "aarch64")) {
    641        qtest_add_data_func("/arm/kvm/query-cpu-model-expansion",
    642                            NULL, test_query_cpu_model_expansion_kvm);
    643    }
    644
    645    if (g_str_equal(qtest_get_arch(), "aarch64")) {
    646        qtest_add_data_func("/arm/max/query-cpu-model-expansion/sve-max-vq-8",
    647                            NULL, sve_tests_sve_max_vq_8);
    648        qtest_add_data_func("/arm/max/query-cpu-model-expansion/sve-off",
    649                            NULL, sve_tests_sve_off);
    650        qtest_add_data_func("/arm/kvm/query-cpu-model-expansion/sve-off",
    651                            NULL, sve_tests_sve_off_kvm);
    652    }
    653
    654    return g_test_run();
    655}