<div dir="ltr"><div><div><div><div><div><div><div><div><div>Hi all,<br><br></div>Thanks for the pointer! The instruction callbacks are very useful.<br></div>Now, I&#39;m trying to get the target address the instruction is trying to flush.<br><br></div>But I seem to be getting bogus results, i.e.<br></div>for some instruction `clflush (%rax)`, I get flushes at extremely high addresses such as 0xffffc90040001180,<br></div>even though the workload under examination is performing its writes to the 1G-2G range.<br><br></div>I&#39;m trying to read the register from the instruction encoding then grab it from the CPU state,<br></div>does this look like I&#39;m accessing the QEMU emulated registers correctly? <br><a href="https://github.com/williewillus/panda_scratchpad/blob/master/personal_plugins/panda/plugins/writetracker/writetracker.cpp#L24-L61">https://github.com/williewillus/panda_scratchpad/blob/master/personal_plugins/panda/plugins/writetracker/writetracker.cpp#L24-L61</a><br><br></div>Thanks in advance,<br></div>Vincent<br><div><br><div><div><div><div><div><div><div><br></div></div></div></div></div></div></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Mar 18, 2018 at 2:08 PM, Brendan Dolan-Gavitt <span dir="ltr">&lt;<a href="mailto:brendandg@nyu.edu" target="_blank">brendandg@nyu.edu</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Even though it doesn&#39;t result in native code generation, you should<br>
still be able to use an instruction hook. Use an insn_translate<br>
callback to check if QEMU is about to translate a<br>
clflush/clflushopt/clwb instruction and then return true from that<br>
callback. Then your insn_exec callback will fire whenever one of those<br>
instructions is executed. Roughly:<br>
<br>
bool insn_translate(CPUState *env, target_ulong pc) {<br>
    uint8_t bytes[2];<br>
    panda_virtual_memory_read(env, pc, bytes, 2);<br>
    if (bytes[0] == 0x0F &amp;&amp; bytes[1] == 0xAE) return true; // clflush<br>
    else return false;<br>
}<br>
<br>
int insn_exec(CPUState *env, target_ulong pc) {<br>
    printf(&quot;Saw a clflush at &quot; TARGET_FMT_lx &quot;\n&quot;, pc);<br>
    return 0;<br>
}<br>
<br>
-Brendan<br>
<div><div class="h5"><br>
On Sun, Mar 18, 2018 at 2:59 PM, Vincent Lee &lt;<a href="mailto:vincent_lee@utexas.edu">vincent_lee@utexas.edu</a>&gt; wrote:<br>
&gt; Hi all,<br>
&gt;<br>
&gt; I&#39;d like to communicate to a plugin whenever a (x86_64) guest calls the<br>
&gt; clflush, clflushopt, or clwb instructions.<br>
&gt; Does anyone have any pointers or documentation where I should look to begin<br>
&gt; implementing this?<br>
&gt;<br>
&gt; From what I can tell so far:<br>
&gt; * TCG translation of clwb/clflush/clflushopt simply call &quot;gen_nop_modrm&quot;,<br>
&gt; which does nothing<br>
&gt; * TCG-&gt;native codegen is where panda&#39;s memory hooks are inserted<br>
&gt;<br>
&gt; Would this be a valid (if ad-hoc) plan?<br>
&gt; * Modify QEMU TCG to have some concept of &quot;clflush/clwb/clflushopt&quot; and emit<br>
&gt; this from code-&gt;TCG translation<br>
&gt; * add a new panda callback type for &quot;clflush/clwb/clflushopt&quot;<br>
&gt; * change TCG-&gt;native codegen to inject a call to panda callbacks<br>
&gt;<br>
&gt; Thanks,<br>
&gt; Vincent<br>
&gt;<br>
</div></div>&gt; ______________________________<wbr>_________________<br>
&gt; panda-users mailing list<br>
&gt; <a href="mailto:panda-users@mit.edu">panda-users@mit.edu</a><br>
&gt; <a href="http://mailman.mit.edu/mailman/listinfo/panda-users" rel="noreferrer" target="_blank">http://mailman.mit.edu/<wbr>mailman/listinfo/panda-users</a><br>
&gt;<br>
<span class="HOEnZb"><font color="#888888"><br>
<br>
<br>
--<br>
Brendan Dolan-Gavitt<br>
Assistant Professor, Department of Computer Science and Engineering<br>
NYU Tandon School of Engineering<br>
</font></span></blockquote></div><br></div>