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 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 4B694C433EF for ; Wed, 27 Apr 2022 03:50:18 +0000 (UTC) Received: from localhost ([::1]:57642 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1njYgy-0000vr-UV for qemu-devel@archiver.kernel.org; Tue, 26 Apr 2022 23:50:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41166) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1njYgA-0000Fk-Id for qemu-devel@nongnu.org; Tue, 26 Apr 2022 23:49:26 -0400 Received: from mail-io1-xd30.google.com ([2607:f8b0:4864:20::d30]:34340) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1njYg8-0008Jt-B6 for qemu-devel@nongnu.org; Tue, 26 Apr 2022 23:49:26 -0400 Received: by mail-io1-xd30.google.com with SMTP id r28so1355007iot.1 for ; Tue, 26 Apr 2022 20:49:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=grA1PIFURDYRKxCnblL1BMN1Xhs7U+RCApcoSu5ooIU=; b=oFTkNz26UAEWfM8V3sjA6tlM5j4s89w30IEe2XZvuxi2SiqMxDqt6/mbcl/WLm+7Sv JQI0pJ1sV3SRBv2Wv2y7LUYS95X/VVVBPhmyQRvYrZ9arKJoAsfPBgQVvZj0eMEjTH37 8FTa+lB/L/6WpiPNboV6r6j1+nczj0I7bLzVrllQ1GMh+MKA2X4bQWeoA4agy+ce5Xry 4JXSJtI3deaVrzN6V9sfxTNH41GwmgMC1Rb3JxarkrkJlDf/SVcY375Cx+tFVGFItez6 +wUPcMfg53F41cp36usw9BNL68UNab3DoMeBmUi3jdTAVyjl7pxPb/0WB75LvHiduc5P VhOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=grA1PIFURDYRKxCnblL1BMN1Xhs7U+RCApcoSu5ooIU=; b=gYdJGNogTpNITw/oghaRdxaGaf+kA/+y2ZSm5M/VldBSJ939LPMytFFE7fhwZwcfVs dsnSJIjrAJBW3pvQ0/CvnzorJEwCU1SPnnmYDf6OH+XxyN7KEEALljy8JBGZBukdTMX0 crdDpbfc/TH8e3ETjIegTWU6Pyz4PqbTvO1/nHRlTmhAWEMyst/kdL26qPRVdgY2VjeH 9gdRFZVu6e1qUmYWaWhzRU/GJvl+LBxj4pFLvzFjDDGUh8+g0C4lpPgKHlPbQ51VZ+k6 f24ZYbGX+gKhhoO6S4onAuFEwCYZKDljuMVQ3xPxPyoYbtcfRc1iTXj+/6tulDkUyng6 nlRQ== X-Gm-Message-State: AOAM531hXlySlyVz7hOy4odT8xxpoYSl583R7Azo1MbmmTxM0ylD6gKr sFMe1JSfZ1tU8sSrfsTNtn/fLZQtzTlumU8+JZE= X-Google-Smtp-Source: ABdhPJzLhHmzv6ZLt37Sbja0NghrejE1f1xpYz9QGotZM5ysiVta4TyHx9KUJ3lBqoDIfQcCUNe1Oy7hxHWoOTOBZtM= X-Received: by 2002:a92:d2ca:0:b0:2ca:ca3a:de89 with SMTP id w10-20020a92d2ca000000b002caca3ade89mr10510511ilg.127.1651031362884; Tue, 26 Apr 2022 20:49:22 -0700 (PDT) MIME-Version: 1.0 References: <54ec2a88.968d.1805473f2da.Coremail.xcd19@mails.tsinghua.edu.cn> In-Reply-To: <54ec2a88.968d.1805473f2da.Coremail.xcd19@mails.tsinghua.edu.cn> From: Wei Li Date: Wed, 27 Apr 2022 11:49:08 +0800 Message-ID: Subject: Re: qemu questions about x86 To: =?UTF-8?B?6aG55pmo5Lic?= Content-Type: multipart/alternative; boundary="000000000000e5d90105dd9ab1fa" Received-SPF: pass client-ip=2607:f8b0:4864:20::d30; envelope-from=hduweili@gmail.com; helo=mail-io1-xd30.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" --000000000000e5d90105dd9ab1fa Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Dear =E9=A1=B9=E6=99=A8=E4=B8=9C On Sat, Apr 23, 2022 at 3:57 PM =E9=A1=B9=E6=99=A8=E4=B8=9C wrote: > Dear qemu developers: > hello~ I'm Xiang Chen dong, a student from Tsinghua University. recently = I > am trying to accomplish new X86 feature named user-interrupts which can > view here > > . > I worked for a couple of time, reaching status that new msrs added and > access of msrs is work well, also add new CPUID infos to qemu64, also I > could catch new instructions by modify `translate.c` file. my code could > find here , the correspond linux kernel > version could find here . > but now I have some problems when trying to accomplish instructions named > SENDUIPI and UIRET. > for SENDUIPI, the main function of it is sending the user-interrupts. the > detail way is, machine access memory(address saved in new msr), then read > another address from memory, then write some content to this memory. I re= ad > the qemu source code, find a lot of functions like tcg_gen_qemu_ld, but > when i click into it from IDE(vscode), i could not find where the functio= n > body(maybe due to the macro). So I don't understand how the function work= s > and how can I wirte a new function to access guest machine memory and wri= te > back in qemu. > tcg_frontend: gen_op_ld_v-->tcg_gen_qemu_ld_tl-->tcg_gen_qemu_ld_i64 (tcg/tcg-op.c)-->gen_ldst_i64 tcg_backend: case INDEX_op_qemu_ld_i64:-->tcg_out_qemu_ld (tcg-target.c.inc tcg/i386) You only need to focus on the frontend and learn from how to translate other instructions. another problem is that I am not quite get the idea of accomplishment of > Interrupt, i could find functions like raise_interrupt and raise_exceptio= n, > but I don't understand how it interact with apic(how the control flow > switched to other functions, i find cpu_loop_exit_restore, but can not fi= nd > the function body), either how the interrupt handled. > hardware interrupt produce pc_i8259_create-->i8259_init-->x86_allocate_cpu_irq-->pic_irq_request pic_irq_request-->cpu_interrupt(cs, CPU_INTERRUPT_HARD) -->softmmu/cpus.c/cpu_interrupt-->tcg_handle_interrupt -->cpu_reset_interrupt-->hw/core/cpu-common.c/cpu_reset_interrupt hardware interrupt handle cpu_exec-->cpu_handle_interrupt-->cc->tcg_ops->cpu_exec_interrupt-->x86_cpu= _exec_interrupt -->cpu_get_pic_interrupt-->pic_read_irq -->do_interrupt_x86_hardirq-->do_interrupt_all-->do_interrupt_protected--> use siglongjmp or sigsetjmp exception handle cpu_handle_exception-->cc->tcg_ops->fake_user_interrupt-->x86_cpu_do_interr= upt-->do_interrupt_all > > the problem is difficult in some ways, I discussed with my classmates and > friends, but there is no answer. > so I'm hoping to get important information from you. Is my way of reading > code right? Is there any tools for development(finding the function > body)=EF=BC=9FHow can I accomplish this quickly=EF=BC=9F > thank you very very much=EF=BC=81 > best wishes=EF=BC=81 > Xiang Chen Dong > Everything here maybe have some mistakes. Hope it is useful for you. --=20 best wishes=EF=BC=81 Wei Li --000000000000e5d90105dd9ab1fa Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Dear =E9=A1=B9=E6=99=A8=E4=B8=9C

On Sa= t, Apr 23, 2022 at 3:57 PM =E9=A1=B9=E6=99=A8=E4=B8=9C <xcd19@mails.tsinghua.edu.cn> wrote:
Dear qemu develop= ers:
hello~ I'm Xiang = Chen dong, a student from Tsinghua University. recently I am trying to=C2= =A0 accomplish new X86 feature named user-interrupts which can view here.
I wo= rked for a couple of time, reaching status that new msrs added and access o= f msrs is work well, also add new CPUID infos to qemu64, also I could catch= new instructions by modify `translate.c` file. my code could find here, the=C2=A0= correspond linux kernel version could find here.
but now I have some problems when trying = to accomplish instructions named SENDUIPI and UIRET.
for SENDUIPI, the main function of it is = sending the user-interrupts. the detail way is, machine=C2=A0access memory(= address saved in new msr), then read another address from memory, then writ= e some content to this memory. I read the qemu source code, find a lot of f= unctions like tcg_gen_qemu_ld,=C2=A0 but when i click into it from IDE(vsco= de), i could not find where the function body(maybe due to the macro). So I= don't understand how the function works and how can I wirte a new func= tion to access guest machine memory and write back in qemu.
=C2=A0
=C2=A0 =C2=A0 tcg_frontend: gen_op_ld_v-->tcg_gen_qe= mu_ld_tl-->tcg_gen_qemu_ld_i64 (tcg/tcg-op.c)-->gen_ldst_i64
=C2= =A0 =C2=A0 tcg_backend: case INDEX_op_qemu_ld_i64:-->tcg_out_qemu_ld (tc= g-target.c.inc tcg/i386)
=C2=A0 =C2=A0 You only need to focus on th= e frontend and learn from how to translate other instructions.=C2=A0
<= div>
another problem is that I am not qui= te get the idea of accomplishment of Interrupt, i could find functions like= raise_interrupt and raise_exception, but I don't understand how it int= eract with apic(how the control flow switched to other functions, i find cp= u_loop_exit_restore, but can not find the function body), either how the in= terrupt handled.

=C2=A0 =C2=A0 hardwa= re interrupt produce
pc_i8259_create-->i8259_init-->x86_allocate_c= pu_irq-->pic_irq_request
pic_irq_request-->cpu_interrupt(cs, CPU_I= NTERRUPT_HARD)
-->softmmu/cpus.c/cpu_interrupt-->tcg_handle_interr= upt
=C2=A0 -->cpu_reset_interrupt-->hw/core/cpu-common.c/cpu_reset= _interrupt

=C2=A0 =C2=A0 =C2=A0hardware interrupt handle
cpu_exec= -->cpu_handle_interrupt-->cc->tcg_ops->cpu_exec_interrupt-->= x86_cpu_exec_interrupt
-->cpu_get_pic_interrupt-->pic_read_irq
= -->do_interrupt_x86_hardirq-->do_interrupt_all-->do_interrupt_prot= ected-->
use siglongjmp or sigsetjmp

=C2=A0 =C2=A0 exception h= andle
cpu_handle_exception-->cc->tcg_ops->fake_user_interrupt--= >x86_cpu_do_interrupt-->do_interrupt_all
=C2=A0
=C2=A0
the problem is difficult in some ways, I discus= sed with my classmates and friends, but there is no answer.
so I'm hoping to get important = information from you. Is my way of reading code right? Is there any tools f= or development(finding the function body)=EF=BC=9FHow can I accomplish this= quickly=EF=BC=9F
th= ank you very very much=EF=BC=81
best wishes=EF=BC=81
= Xiang Chen Dong
=

Everything here maybe have some mistakes.
Hope it is useful for y= ou.
--
best wishes=EF=BC=81

Wei Li
--000000000000e5d90105dd9ab1fa--