From nobody Fri May 3 04:21:03 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) client-ip=205.139.110.61; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=outlook.com ARC-Seal: i=1; a=rsa-sha256; t=1597976482; cv=none; d=zohomail.com; s=zohoarc; b=A9D9LqUgyifZeI5m8uLB1NvtI1ZAKVwaqJa1nBrVXcI2dw+/YI35mQe8H85jeax6Wm/8dScl3SvnwS5Hmte6cdsOcfrp4b8P2mc0hsIFP+L/mcK2682043AGMLHTJ9/EMfxDVQqPEWQwYYOlp66IrAyBKzpOwuOH+vQBjH8axPI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1597976482; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=dZqT5RVzUJPJ56DTcFr5VvFXTp5grmuuu0D+APZ76jE=; b=HbJo+208sNG6H3CnoLuqhh5blCCJjhsm+nDHjXrtF5dTrNEwRrTc8W42LZOxAC45U0hr0hVglGekHsCKZtq0CvvYOYjbtxjsewdqPoPWjUlK9QpsiRlDS8CiGBFMk5lHO/DrvzCv/bszGpShUzK2RIKZDWC/b7Lryl0JEa2RK0I= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-2.mimecast.com [205.139.110.61]) by mx.zohomail.com with SMTPS id 159797648271619.96715814770721; Thu, 20 Aug 2020 19:21:22 -0700 (PDT) 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 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) 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 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 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 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-MC-Unique: fVQ2RJhIMImlyrq-9AmFrg-1 X-MC-Unique: sImm6Z1VP0OqRSIZsANmDw-1 X-IncomingTopHeaderMarker: OriginalChecksum:E5B22E7B39342B9CCFC9E6130FFD6C8163F18763677C5C40B47F04E44DE5AAA3; UpperCasedChecksum:FE03E598B64E93DD86786250F72B90FB9556C2AAD89924E324EE8E93B0AB9F6A; SizeAsReceived:7375; Count:47 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 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 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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(-) 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; } =20 +static int +virCPUarmDataCopy(virCPUarmData *dst, const virCPUarmData *src) +{ + if (VIR_ALLOC(dst->features) < 0) + return -1; + + dst->pvr =3D src->pvr; + dst->vendor_id =3D src->vendor_id; + dst->features =3D src->features; + + return 0; +} + +static virCPUDataPtr +virCPUarmMakeCPUData(virArch arch, + virCPUarmData *data) +{ + virCPUDataPtr cpuData; + + if (VIR_ALLOC(cpuData) < 0) + return NULL; + + cpuData->arch =3D 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; } =20 +static virCPUarmModelPtr +virCPUarmModelCopy(virCPUarmModelPtr model) +{ + virCPUarmModelPtr copy; + + copy =3D g_new0(virCPUarmModel, 1); + copy->name =3D g_strdup(model->name); + virCPUarmDataCopy(©->data, &model->data); + copy->vendor =3D model->vendor; + + return g_steal_pointer(©); +} + +static virCPUarmModelPtr +virCPUarmModelFromCPU(const virCPUDef *cpu, + virCPUarmMapPtr map) +{ + g_autoptr(virCPUarmModel) model =3D NULL; + + if (!cpu->model) { + virReportError(VIR_ERR_INVALID_ARG, "%s", + _("no CPU model specified")); + return NULL; + } + + if (!(model =3D virCPUarmModelFind(map, cpu->model))) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Unknown CPU model %s"), cpu->model); + return NULL; + } + + model =3D virCPUarmModelCopy(model); + + return g_steal_pointer(&model); +} + static virCPUarmMapPtr virCPUarmLoadMap(void) { @@ -463,11 +529,125 @@ virCPUarmBaseline(virCPUDefPtr *cpus, } =20 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 =3D NULL; + virCPUarmModelPtr host_model =3D NULL; + virCPUarmModelPtr guest_model =3D NULL; + virCPUCompareResult ret =3D VIR_CPU_COMPARE_ERROR; + virArch arch; + size_t i; + + if (cpu->arch !=3D VIR_ARCH_NONE) { + bool found =3D false; + + for (i =3D 0; i < G_N_ELEMENTS(archs); i++) { + if (archs[i] =3D=3D cpu->arch) { + found =3D true; + break; + } + } + + if (!found) { + VIR_DEBUG("CPU arch %s does not match host arch", + virArchToString(cpu->arch)); + if (message) + *message =3D g_strdup_printf(_("CPU arch %s does not match= host arch"), + virArchToString(cpu->arch)); + + ret =3D VIR_CPU_COMPARE_INCOMPATIBLE; + goto cleanup; + } + arch =3D cpu->arch; + } else { + arch =3D 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 =3D g_strdup_printf(_("host CPU vendor does not match= required " + "CPU vendor %s"), + cpu->vendor); + } + + ret =3D VIR_CPU_COMPARE_INCOMPATIBLE; + goto cleanup; + } + + if (!(map =3D virCPUarmLoadMap())) + goto cleanup; + + /* Host CPU information */ + if (!(host_model =3D virCPUarmModelFromCPU(host, map))) + goto cleanup; + + /* Guest CPU information */ + if (!(guest_model =3D 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 =3D g_strdup_printf(_("host CPU model does not match = required " + "CPU model %s"), + guest_model->name); + } + + ret =3D VIR_CPU_COMPARE_INCOMPATIBLE; + goto cleanup; + } + + if (guestData) + if (!(*guestData =3D virCPUarmMakeCPUData(arch, &guest_model->data= ))) + goto cleanup; + + ret =3D 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 =3D NULL; + + if (!host || !host->model) { + if (failIncompatible) { + virReportError(VIR_ERR_CPU_INCOMPATIBLE, "%s", + _("unknown host CPU")); + } else { + VIR_WARN("unknown host CPU"); + ret =3D VIR_CPU_COMPARE_INCOMPATIBLE; + } + return -1; + } + + ret =3D armCompute(host, cpu, NULL, &message); + + if (failIncompatible && ret =3D=3D VIR_CPU_COMPARE_INCOMPATIBLE) { + ret =3D 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; } =20 static int --=20 2.20.1