From patchwork Fri Aug 21 02:20:15 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhenyu Zheng X-Patchwork-Id: 248042 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:522:0:0:0:0 with SMTP id h2csp1881732ils; Thu, 20 Aug 2020 19:21:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz6pFNyAVX1KhZ9iywAGXfM/8GPI4UvJRqwfeOHIeKhWCuL/yxYDW6Ad31kpaojrLZN+1KB X-Received: by 2002:a05:6902:4a9:: with SMTP id r9mr871575ybs.242.1597976482197; Thu, 20 Aug 2020 19:21:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597976482; cv=none; d=google.com; s=arc-20160816; b=R66RiSmMKRmytBa/FMf3ZMMWOn+n/AOpaiViC9fvSlZZYcT/dP6h9VruUp09VcBGQ/ GaSmDLdZlXeZv1djSV1bI9bYdfgDo5MFhWBvFCIoLCmTnMioj0L8BDu3PUow6yPRMrGG OAjkpOf8beFxPoe0yJCPPOPA/S8fAJ7OMAEKsKVgi5zqF/CMxXvTE2eXf++lE30m3Szg 4vwmxqoAzTDpPi9whwG2ZA03km1APjz1amICRx+3K6fAEpYKX0KhohB/Fddv/9zHJu40 AJglnXSGZt2Wqc4/9dMfi7X2SMSmZkRuLvEBwbJbkcFabJRiRLea2YCPtsIFj9XmQE/P 5pvw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:errors-to:sender:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence:cc :mime-version:message-id:date:subject:to:from:delivered-to; bh=dZqT5RVzUJPJ56DTcFr5VvFXTp5grmuuu0D+APZ76jE=; b=JBxQjZzs+HHRUmv3sC+IOeDy6rrhcNQJ8fHf45aNmAGoXVdYRpbI4Z9E2z0O0RSk6u mzJEd1ele6bKShyUHX2OKL0hZcF7MG5gOhAHIxKDuWsRpklSJDi7McYicrUjFxlwmIXy eYIpy5NVKCcefPWinw5T47IqZCgv+hPnnnunuhZbURiXX9pTLDIwkAa44Q9Uql2VjDxB wVc4ucvi8zsXKM9+0YaNT4U3VZcJJlaflNmnlHAWpzk54Lfl1wVZXrcJapv38HgX8nTn 94sHudtPbMA8Lvy328oxHLzKzkuKcAfxaA9pbwQYrId81BKrzTbhSh1iEy1z9tVWrOsQ YbCA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of libvir-list-bounces@redhat.com designates 205.139.110.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=outlook.com Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com. [205.139.110.120]) by mx.google.com with ESMTPS id t16si535667ybl.50.2020.08.20.19.21.22 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 20 Aug 2020 19:21:22 -0700 (PDT) Received-SPF: pass (google.com: domain of libvir-list-bounces@redhat.com designates 205.139.110.120 as permitted sender) client-ip=205.139.110.120; Authentication-Results: mx.google.com; spf=pass (google.com: domain of libvir-list-bounces@redhat.com designates 205.139.110.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=outlook.com Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-16-fVQ2RJhIMImlyrq-9AmFrg-1; Thu, 20 Aug 2020 22:21:19 -0400 X-MC-Unique: fVQ2RJhIMImlyrq-9AmFrg-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7E7EC81CAF9; Fri, 21 Aug 2020 02:21:13 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1FB7D614F1; Fri, 21 Aug 2020 02:21:11 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id CEBC6183D020; Fri, 21 Aug 2020 02:21:03 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 07L2L1Fh016906 for ; Thu, 20 Aug 2020 22:21:01 -0400 Received: by smtp.corp.redhat.com (Postfix) id 927812166BA4; Fri, 21 Aug 2020 02:21:01 +0000 (UTC) Delivered-To: libvir-list@redhat.com Received: from mimecast-mx02.redhat.com (mimecast02.extmail.prod.ext.rdu2.redhat.com [10.11.55.18]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8D0162166BA3 for ; Fri, 21 Aug 2020 02:20:59 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 531558EDF00 for ; Fri, 21 Aug 2020 02:20:59 +0000 (UTC) Received: from APC01-PU1-obe.outbound.protection.outlook.com (mail-oln040092254108.outbound.protection.outlook.com [40.92.254.108]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-364-sImm6Z1VP0OqRSIZsANmDw-1; Thu, 20 Aug 2020 22:20:56 -0400 X-MC-Unique: sImm6Z1VP0OqRSIZsANmDw-1 Received: from PU1APC01FT008.eop-APC01.prod.protection.outlook.com (2a01:111:e400:7ebe::41) by PU1APC01HT044.eop-APC01.prod.protection.outlook.com (2a01:111:e400:7ebe::390) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3305.24; Fri, 21 Aug 2020 02:20:53 +0000 Received: from OSYP286MB0181.JPNP286.PROD.OUTLOOK.COM (2a01:111:e400:7ebe::48) by PU1APC01FT008.mail.protection.outlook.com (2a01:111:e400:7ebe::66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3305.24 via Frontend Transport; Fri, 21 Aug 2020 02:20:53 +0000 X-IncomingTopHeaderMarker: OriginalChecksum:E5B22E7B39342B9CCFC9E6130FFD6C8163F18763677C5C40B47F04E44DE5AAA3; UpperCasedChecksum:FE03E598B64E93DD86786250F72B90FB9556C2AAD89924E324EE8E93B0AB9F6A; SizeAsReceived:7375; Count:47 Received: from OSYP286MB0181.JPNP286.PROD.OUTLOOK.COM ([fe80::959a:13d8:e2ce:477f]) by OSYP286MB0181.JPNP286.PROD.OUTLOOK.COM ([fe80::959a:13d8:e2ce:477f%6]) with mapi id 15.20.3305.024; Fri, 21 Aug 2020 02:20:52 +0000 From: Zhenyu Zheng To: libvir-list@redhat.com Subject: [PATCH] Modify virCPUarmCompare to perform compare actions Date: Fri, 21 Aug 2020 10:20:15 +0800 Message-ID: X-ClientProxiedBy: HK2PR0401CA0015.apcprd04.prod.outlook.com (2603:1096:202:2::25) To OSYP286MB0181.JPNP286.PROD.OUTLOOK.COM (2603:1096:604:92::16) X-Microsoft-Original-Message-ID: <20200821022015.8492-1-zheng.zhenyu@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost.localdomain (119.8.114.27) by HK2PR0401CA0015.apcprd04.prod.outlook.com (2603:1096:202:2::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3305.25 via Frontend Transport; Fri, 21 Aug 2020 02:20:52 +0000 X-Microsoft-Original-Message-ID: <20200821022015.8492-1-zheng.zhenyu@outlook.com> X-TMN: [qY+fO6zqHAUbI3Dk1gnjUXamujgXkNgO] X-MS-PublicTrafficType: Email X-IncomingHeaderCount: 47 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-Correlation-Id: dee9a35f-6f5a-4f7f-c06e-08d84578d3c7 X-MS-Exchange-SLBlob-MailProps: S/btQ8cKWiSkiJdE9wKp+PuK79RS7dAGUusaNASoCNCsKRmKlc962erDZk7SeXi2Xek7kYsl6jpZcmyn1tXYwUSoe0NFgQmCoI3B6Klwxc+ndqcKrh93PbUmNxH5Tqx/TA08dxkeD7KxHejRnuSbQeWjOw63VliVqZ8DVr8YQ+xjqajFMvpguFf1SLb3TBQfgCzuBwUjPLj7O4K5lXFBWmFx4z+WfxvNp4paGxdgbSgOGrZyId0nMHQ9ynTVrgkrWQVNzG0uKJxs43nWXwIShC1KQ2nHURHOp2fpZqg2mW4r7Lfl/0e2teNGQC65lXd1+7E9gkGq8CtwtQOPLWMrTBHVy8LQb/dJI11RP6wSgGGZs108jIMADwFMofboXkBdbQ+UhePzAonqCwcnT0zlKdaJlrl/vdgshtcKFS5mmxwc3VfL903cmOmf707q+EcPOFauAin/opvZ66bT0XEI5hFQgLBq15rveNh3bADwFGXokTiez9eRLfLCq+rVD4A1rjBRG/7xROiZHQntIppfEs0bYv8GpW9h1VEooAapZq5XG3y8PrZQLkjIz35bN597dI9J+x9nmSiSOgRuPiJ3Eq7ylsiWKWh92kZsu0S1cRyEoQKtv6I65vyD2IQbBxcLOixMrlXwovtCpX+nvzb1oM70Z5+iAmLIWoI2udJowwifbdoaZ47SWlPq6+PRyjvnm2uF43X5lXnxqI8vPHsFff5iMg5oI8Jd+TMWUF2oLX58WMfEYwutxDhpcT46R+dnuU50sPn7YfA= X-MS-TrafficTypeDiagnostic: PU1APC01HT044: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: J67VVOQkPiqPEns21DAt9nHTu8vJwgjEBztS3AbYenRUEnJirdOO8prl3UrO2yd6J5PGZM9eIFdhYL+qDMoyxBbQBY8I9PyHBZfjCZy59sklmJAHjktT4jvdwwJ4YAdbw9KaR/8YKKPoFCK8fyG4GtRNJ9PSYoebOpTDmMGEHY5MNf+rSIFH+sdHvjShNDKDtxPzSbcZWnJV129/3i3qRQ== X-MS-Exchange-AntiSpam-MessageData: y8of0onBPxzBgzyG/lZT7vJYNEQe9fcuLapBw0a2gWzX/SAiWSSHqIwHGL6kzLpicgmfJj3d664YHEFn5fFnG06doSj3g+J2qA8U1IeibhQPkLU/tuWo9njiosvbdT34VB3UcB2GJnE7GqC7GJVy4w== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: dee9a35f-6f5a-4f7f-c06e-08d84578d3c7 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Aug 2020 02:20:52.6730 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-AuthSource: PU1APC01FT008.eop-APC01.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: Internet X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: PU1APC01HT044 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false; X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-MIME-Autoconverted: from quoted-printable to 8bit by lists01.pubmisc.prod.ext.phx2.redhat.com id 07L2L1Fh016906 X-loop: libvir-list@redhat.com Cc: Zhenyu Zheng X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0.003 X-Mimecast-Originator: redhat.com Modify virCPUarmCompare in cpu_arm.c to perform actual compare actions. Compare host cpu vendor and model info with guest cpu as initial implementation, as most ARM clouds uses host-passthrogh mode. Signed-off-by: Zhenyu Zheng --- src/cpu/cpu_arm.c | 188 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 184 insertions(+), 4 deletions(-) -- 2.20.1 diff --git a/src/cpu/cpu_arm.c b/src/cpu/cpu_arm.c index 374a4d6f6c..98c5e551f5 100644 --- a/src/cpu/cpu_arm.c +++ b/src/cpu/cpu_arm.c @@ -118,6 +118,36 @@ virCPUarmMapNew(void) return map; } +static int +virCPUarmDataCopy(virCPUarmData *dst, const virCPUarmData *src) +{ + if (VIR_ALLOC(dst->features) < 0) + return -1; + + dst->pvr = src->pvr; + dst->vendor_id = src->vendor_id; + dst->features = src->features; + + return 0; +} + +static virCPUDataPtr +virCPUarmMakeCPUData(virArch arch, + virCPUarmData *data) +{ + virCPUDataPtr cpuData; + + if (VIR_ALLOC(cpuData) < 0) + return NULL; + + cpuData->arch = arch; + + if (virCPUarmDataCopy(&cpuData->data.arm, data) < 0) + VIR_FREE(cpuData); + + return cpuData; +} + static void virCPUarmDataClear(virCPUarmData *data) { @@ -376,6 +406,42 @@ virCPUarmModelParse(xmlXPathContextPtr ctxt, return 0; } +static virCPUarmModelPtr +virCPUarmModelCopy(virCPUarmModelPtr model) +{ + virCPUarmModelPtr copy; + + copy = g_new0(virCPUarmModel, 1); + copy->name = g_strdup(model->name); + virCPUarmDataCopy(©->data, &model->data); + copy->vendor = model->vendor; + + return g_steal_pointer(©); +} + +static virCPUarmModelPtr +virCPUarmModelFromCPU(const virCPUDef *cpu, + virCPUarmMapPtr map) +{ + g_autoptr(virCPUarmModel) model = NULL; + + if (!cpu->model) { + virReportError(VIR_ERR_INVALID_ARG, "%s", + _("no CPU model specified")); + return NULL; + } + + if (!(model = virCPUarmModelFind(map, cpu->model))) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Unknown CPU model %s"), cpu->model); + return NULL; + } + + model = virCPUarmModelCopy(model); + + return g_steal_pointer(&model); +} + static virCPUarmMapPtr virCPUarmLoadMap(void) { @@ -463,11 +529,125 @@ virCPUarmBaseline(virCPUDefPtr *cpus, } static virCPUCompareResult -virCPUarmCompare(virCPUDefPtr host G_GNUC_UNUSED, - virCPUDefPtr cpu G_GNUC_UNUSED, - bool failMessages G_GNUC_UNUSED) +armCompute(virCPUDefPtr host, + virCPUDefPtr cpu, + virCPUDataPtr *guestData, + char **message) { - return VIR_CPU_COMPARE_IDENTICAL; + virCPUarmMapPtr map = NULL; + virCPUarmModelPtr host_model = NULL; + virCPUarmModelPtr guest_model = NULL; + virCPUCompareResult ret = VIR_CPU_COMPARE_ERROR; + virArch arch; + size_t i; + + if (cpu->arch != VIR_ARCH_NONE) { + bool found = false; + + for (i = 0; i < G_N_ELEMENTS(archs); i++) { + if (archs[i] == cpu->arch) { + found = true; + break; + } + } + + if (!found) { + VIR_DEBUG("CPU arch %s does not match host arch", + virArchToString(cpu->arch)); + if (message) + *message = g_strdup_printf(_("CPU arch %s does not match host arch"), + virArchToString(cpu->arch)); + + ret = VIR_CPU_COMPARE_INCOMPATIBLE; + goto cleanup; + } + arch = cpu->arch; + } else { + arch = host->arch; + } + + if (cpu->vendor && + (!host->vendor || STRNEQ(cpu->vendor, host->vendor))) { + VIR_DEBUG("host CPU vendor does not match required CPU vendor %s", + cpu->vendor); + if (message) { + *message = g_strdup_printf(_("host CPU vendor does not match required " + "CPU vendor %s"), + cpu->vendor); + } + + ret = VIR_CPU_COMPARE_INCOMPATIBLE; + goto cleanup; + } + + if (!(map = virCPUarmLoadMap())) + goto cleanup; + + /* Host CPU information */ + if (!(host_model = virCPUarmModelFromCPU(host, map))) + goto cleanup; + + /* Guest CPU information */ + if (!(guest_model = virCPUarmModelFromCPU(cpu, map))) + goto cleanup; + + if (STRNEQ(guest_model->name, host_model->name)) { + VIR_DEBUG("host CPU model does not match required CPU model %s", + guest_model->name); + if (message) { + *message = g_strdup_printf(_("host CPU model does not match required " + "CPU model %s"), + guest_model->name); + } + + ret = VIR_CPU_COMPARE_INCOMPATIBLE; + goto cleanup; + } + + if (guestData) + if (!(*guestData = virCPUarmMakeCPUData(arch, &guest_model->data))) + goto cleanup; + + ret = VIR_CPU_COMPARE_IDENTICAL; + + cleanup: + virCPUarmModelFree(host_model); + virCPUarmModelFree(guest_model); + return ret; +} + +static virCPUCompareResult +virCPUarmCompare(virCPUDefPtr host, + virCPUDefPtr cpu, + bool failIncompatible) +{ + virCPUCompareResult ret; + char *message = NULL; + + if (!host || !host->model) { + if (failIncompatible) { + virReportError(VIR_ERR_CPU_INCOMPATIBLE, "%s", + _("unknown host CPU")); + } else { + VIR_WARN("unknown host CPU"); + ret = VIR_CPU_COMPARE_INCOMPATIBLE; + } + return -1; + } + + ret = armCompute(host, cpu, NULL, &message); + + if (failIncompatible && ret == VIR_CPU_COMPARE_INCOMPATIBLE) { + ret = VIR_CPU_COMPARE_ERROR; + if (message) { + virReportError(VIR_ERR_CPU_INCOMPATIBLE, "%s", message); + } else { + virReportError(VIR_ERR_CPU_INCOMPATIBLE, NULL); + } + } + VIR_FREE(message); + + return ret; } static int