From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.1 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9B165C433EF for ; Wed, 22 Sep 2021 16:48:55 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 2E0D760F70 for ; Wed, 22 Sep 2021 16:48:55 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 2E0D760F70 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:51966 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mT5QU-0003fM-9S for qemu-devel@archiver.kernel.org; Wed, 22 Sep 2021 12:48:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48504) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mT5Af-0001kT-SD for qemu-devel@nongnu.org; Wed, 22 Sep 2021 12:32:33 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:32647) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mT5AR-0001r6-Q1 for qemu-devel@nongnu.org; Wed, 22 Sep 2021 12:32:33 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1632328335; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=tGml+z5wri++cNviwkr9uOImZi4qRo1/XZ9h9m3hxa4=; b=cUl77KfgRCL9fbX9h3g40vvnZ+5ypfq6D/R8HQJFDSUNB9AUNngiYuzVKmBY0MjmhcHE/x HEbQ7yLCFOYw1tYrBGkD7yhUK6o3K3iz/vcDJibPDglAMfrOUJhCyG5twKkwIZ5NuAkVaC HqEzp74bTAZDtWd2DCb6h0TYsgQk7RY= 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-138-ZN6EHD2bOcehOHZg4VtXTQ-1; Wed, 22 Sep 2021 12:32:00 -0400 X-MC-Unique: ZN6EHD2bOcehOHZg4VtXTQ-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 50C8E1006AA5; Wed, 22 Sep 2021 16:31:56 +0000 (UTC) Received: from redhat.com (unknown [10.39.195.69]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 097F119724; Wed, 22 Sep 2021 16:30:47 +0000 (UTC) Date: Wed, 22 Sep 2021 17:30:44 +0100 From: Daniel =?utf-8?B?UC4gQmVycmFuZ8Op?= To: Dongli Zhang Subject: Re: [PATCH v2 38/53] qapi: introduce x-query-lapic QMP command Message-ID: References: <20210914142042.1655100-1-berrange@redhat.com> <20210914142042.1655100-39-berrange@redhat.com> <68cebe2f-ba56-545f-686a-b9ac2120c5c4@oracle.com> MIME-Version: 1.0 In-Reply-To: <68cebe2f-ba56-545f-686a-b9ac2120c5c4@oracle.com> User-Agent: Mutt/2.0.7 (2021-05-04) X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=berrange@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=170.10.133.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -16 X-Spam_score: -1.7 X-Spam_bar: - X-Spam_report: (-1.7 / 5.0 requ) DKIMWL_WL_HIGH=-1.472, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Daniel =?utf-8?B?UC4gQmVycmFuZ8Op?= Cc: Peter Maydell , Chris Wulff , David Hildenbrand , Bin Meng , Mark Cave-Ayland , qemu-devel@nongnu.org, Peter Xu , Laurent Vivier , Max Filippov , Taylor Simpson , Alistair Francis , Gerd Hoffmann , "Edgar E. Iglesias" , Eric Blake , Marek Vasut , Yoshinori Sato , Markus Armbruster , Halil Pasic , Christian Borntraeger , Palmer Dabbelt , Artyom Tarasenko , Laurent Vivier , Thomas Huth , Eduardo Habkost , Richard Henderson , Greg Kurz , Yuval Shaia , qemu-s390x@nongnu.org, qemu-arm@nongnu.org, Michael Rolnik , Stafford Horne , David Gibson , qemu-riscv@nongnu.org, Bastian Koppelmann , Cornelia Huck , Philippe =?utf-8?Q?Mathieu-Daud=C3=A9?= , qemu-ppc@nongnu.org, Aurelien Jarno , Paolo Bonzini , Aleksandar Rikalo , "Dr. David Alan Gilbert" Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" On Mon, Sep 20, 2021 at 10:27:06PM -0700, Dongli Zhang wrote: > Hi Daniel, > > On 9/14/21 7:20 AM, Daniel P. Berrangé wrote: > > This is a counterpart to the HMP "info lapic" command. It is being > > added with an "x-" prefix because this QMP command is intended as an > > adhoc debugging tool and will thus not be modelled in QAPI as fully > > structured data, nor will it have long term guaranteed stability. > > The existing HMP command is rewritten to call the QMP command. > > > > This command is unable to use the pre-existing HumanReadableText, > > because if 'common.json' is included into 'machine-target.json' > > the static marshalling method for HumanReadableText will be reported > > as unused by the compiler on all architectures except s390x. > > > > Possible options were > > > > 1 Support 'if' conditionals on 'include' statements in QAPI > > 2 Add further commands to 'machine-target.json' that use > > HumanReadableText, such that it has at least one usage > > on all architecture targets. > > 3 Duplicate HumanReadableText as TargetHumanReadableText > > adding conditions > > > > This patch takes option (3) in the belief that we will eventually > > get to a point where option (2) happens, and TargetHumanReadableText > > can be removed again. > > > > Signed-off-by: Daniel P. Berrangé > > --- > > hw/core/cpu-common.c | 7 ++ > > include/hw/core/cpu.h | 10 +++ > > qapi/machine-target.json | 19 ++++- > > target/i386/cpu-dump.c | 161 ++++++++++++++++++++------------------- > > target/i386/cpu.h | 4 +- > > target/i386/monitor.c | 46 +++++++++-- > > 6 files changed, 160 insertions(+), 87 deletions(-) > > diff --git a/target/i386/monitor.c b/target/i386/monitor.c > > index 19468c4e85..fc09f90059 100644 > > --- a/target/i386/monitor.c > > +++ b/target/i386/monitor.c > > @@ -33,6 +33,7 @@ > > #include "qapi/error.h" > > #include "sev_i386.h" > > #include "qapi/qapi-commands-misc-target.h" > > +#include "qapi/qapi-commands-machine-target.h" > > #include "qapi/qapi-commands-misc.h" > > #include "hw/i386/pc.h" > > > > @@ -650,23 +651,52 @@ const MonitorDef *target_monitor_defs(void) > > return monitor_defs; > > } > > > > +TargetHumanReadableText *qmp_x_query_lapic(int64_t apicid, > > + Error **errp) > > +{ > > + TargetHumanReadableText *ret; > > + g_autoptr(GString) buf = NULL; > > + CPUState *cs = cpu_by_arch_id(apicid); > > + > > + if (!cs) { > > + error_setg(errp, "No CPU with APIC ID %" PRId64 " available", apicid); > > + return NULL; > > + } > > Suppose the accelerator is KVM, the CPUState (cs) might not be syncrhonized with > KVM kernel space (APIC+PIR). As a result, the data is stale. > > I sent below patch long time ago but it never got reviewed. > > https://lore.kernel.org/qemu-devel/20210908143803.29191-1-dongli.zhang@oracle.com/ I'll include your patch in the next version of this series just before this patch, and then update this patch to take it into account. > > > + > > + buf = x86_cpu_format_local_apic_state(cs, CPU_DUMP_FPU, errp); > > + if (!buf) { > > + return NULL; > > + } > > + > > + ret = g_new0(TargetHumanReadableText, 1); > > + ret->human_readable_text = g_steal_pointer(&buf->str); > > + return ret; > > +} > > + > > void hmp_info_local_apic(Monitor *mon, const QDict *qdict) > > { > > - CPUState *cs; > > + Error *err = NULL; > > + g_autoptr(TargetHumanReadableText) info = NULL; > > + int64_t apicid; > > > > if (qdict_haskey(qdict, "apic-id")) { > > - int id = qdict_get_try_int(qdict, "apic-id", 0); > > - cs = cpu_by_arch_id(id); > > + apicid = qdict_get_try_int(qdict, "apic-id", 0); > > Here is where I used to fix with the patch. > > Thank you very much! > > Dongli Zhang > > > } else { > > - cs = mon_get_cpu(mon); > > + CPUState *cs = mon_get_cpu(mon); > > + if (!cs) { > > + monitor_printf(mon, "No CPU available\n"); > > + return; > > + } > > + apicid = cpu_get_arch_id(cs); > > } > > > > - > > - if (!cs) { > > - monitor_printf(mon, "No CPU available\n"); > > + info = qmp_x_query_lapic(apicid, &err); > > + if (err) { > > + error_report_err(err); > > return; > > } > > - x86_cpu_dump_local_apic_state(cs, CPU_DUMP_FPU); > > + > > + monitor_printf(mon, "%s", info->human_readable_text); > > } > > > > SevInfo *qmp_query_sev(Error **errp) > > > Regards, Daniel -- |: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|