VirtualBox

Changeset 100371 in vbox for trunk/src/VBox/Devices/VirtIO


Ignore:
Timestamp:
Jul 5, 2023 7:47:33 AM (22 months ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
158108
Message:

Devices/VirtIO,DevVirtioNet,DevVirtioSCSI: Get rid of VIRTIO_VBUF_ON_STACK which is the default for quite some time now to make the code more straight forward, bugref:10459

Location:
trunk/src/VBox/Devices/VirtIO
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/VirtIO/VirtioCore.cpp

    r99775 r100371  
    635635    uint16_t uUsedIdxShadow  = pVirtq->uUsedIdxShadow;
    636636
    637 #ifdef VIRTIO_VBUF_ON_STACK
    638637    VIRTQBUF_T VirtqBuf;
    639638    PVIRTQBUF pVirtqBuf = &VirtqBuf;
    640 #else /* !VIRTIO_VBUF_ON_STACK */
    641     PVIRTQBUF pVirtqBuf = NULL;
    642 #endif /* !VIRTIO_VBUF_ON_STACK */
    643 
    644639    bool fEmpty = IS_VIRTQ_EMPTY(pDevIns, pVirtio, pVirtq);
    645640
     
    649644    if (!fEmpty)
    650645    {
    651 #ifdef VIRTIO_VBUF_ON_STACK
    652646        virtioCoreR3VirtqAvailBufPeek(pDevIns,  pVirtio, uVirtq, pVirtqBuf);
    653 #else /* !VIRTIO_VBUF_ON_STACK */
    654         virtioCoreR3VirtqAvailBufPeek(pDevIns,  pVirtio, uVirtq, &pVirtqBuf);
    655 #endif /* !VIRTIO_VBUF_ON_STACK */
    656647        cSendSegs   = pVirtqBuf->pSgPhysSend ? pVirtqBuf->pSgPhysSend->cSegs : 0;
    657648        cReturnSegs = pVirtqBuf->pSgPhysReturn ? pVirtqBuf->pSgPhysReturn->cSegs : 0;
     
    704695}
    705696
    706 #ifdef VIRTIO_VBUF_ON_STACK
     697
    707698/** API Function: See header file */
    708699PVIRTQBUF virtioCoreR3VirtqBufAlloc(void)
     
    714705    return pVirtqBuf;
    715706}
    716 #endif /* VIRTIO_VBUF_ON_STACK */
     707
    717708
    718709/** API Function: See header file */
     
    788779
    789780/** API function: See Header file  */
    790 #ifdef VIRTIO_VBUF_ON_STACK
    791781int virtioCoreR3VirtqAvailBufPeek(PPDMDEVINS pDevIns, PVIRTIOCORE pVirtio, uint16_t uVirtq, PVIRTQBUF pVirtqBuf)
    792782{
    793783    return virtioCoreR3VirtqAvailBufGet(pDevIns, pVirtio, uVirtq, pVirtqBuf, false);
    794784}
    795 #else /* !VIRTIO_VBUF_ON_STACK */
    796 int virtioCoreR3VirtqAvailBufPeek(PPDMDEVINS pDevIns, PVIRTIOCORE pVirtio, uint16_t uVirtq,
    797                          PPVIRTQBUF ppVirtqBuf)
    798 {
    799     return virtioCoreR3VirtqAvailBufGet(pDevIns, pVirtio, uVirtq, ppVirtqBuf, false);
    800 }
    801 #endif /* !VIRTIO_VBUF_ON_STACK */
     785
    802786
    803787/** API function: See Header file  */
     
    821805
    822806/** API Function: See header file */
    823 #ifdef VIRTIO_VBUF_ON_STACK
    824807int virtioCoreR3VirtqAvailBufGet(PPDMDEVINS pDevIns, PVIRTIOCORE pVirtio, uint16_t uVirtq,
    825808                                 uint16_t uHeadIdx, PVIRTQBUF pVirtqBuf)
    826 #else /* !VIRTIO_VBUF_ON_STACK */
    827 int virtioCoreR3VirtqAvailBufGet(PPDMDEVINS pDevIns, PVIRTIOCORE pVirtio, uint16_t uVirtq,
    828                              uint16_t uHeadIdx, PPVIRTQBUF ppVirtqBuf)
    829 #endif /* !VIRTIO_VBUF_ON_STACK */
    830 {
    831 #ifndef VIRTIO_VBUF_ON_STACK
    832     AssertReturn(ppVirtqBuf, VERR_INVALID_POINTER);
    833     *ppVirtqBuf = NULL;
    834 #endif /* !VIRTIO_VBUF_ON_STACK */
    835 
     809{
    836810    AssertMsgReturn(uVirtq < RT_ELEMENTS(pVirtio->aVirtqueues),
    837811                        ("uVirtq out of range"), VERR_INVALID_PARAMETER);
     
    850824     * Allocate and initialize the descriptor chain structure.
    851825     */
    852 #ifndef VIRTIO_VBUF_ON_STACK
    853     PVIRTQBUF pVirtqBuf = (PVIRTQBUF)RTMemAllocZ(sizeof(VIRTQBUF_T));
    854     AssertReturn(pVirtqBuf, VERR_NO_MEMORY);
    855 #endif /* !VIRTIO_VBUF_ON_STACK */
    856826    pVirtqBuf->u32Magic  = VIRTQBUF_MAGIC;
    857827    pVirtqBuf->cRefs     = 1;
    858828    pVirtqBuf->uHeadIdx  = uHeadIdx;
    859829    pVirtqBuf->uVirtq    = uVirtq;
    860 #ifndef VIRTIO_VBUF_ON_STACK
    861     *ppVirtqBuf          = pVirtqBuf;
    862 #endif /* !VIRTIO_VBUF_ON_STACK */
    863830
    864831    /*
     
    958925
    959926/** API function: See Header file  */
    960 #ifdef VIRTIO_VBUF_ON_STACK
    961927int virtioCoreR3VirtqAvailBufGet(PPDMDEVINS pDevIns, PVIRTIOCORE pVirtio, uint16_t uVirtq,
    962928                                 PVIRTQBUF pVirtqBuf, bool fRemove)
    963 #else /* !VIRTIO_VBUF_ON_STACK */
    964 int virtioCoreR3VirtqAvailBufGet(PPDMDEVINS pDevIns, PVIRTIOCORE pVirtio, uint16_t uVirtq,
    965                          PPVIRTQBUF ppVirtqBuf, bool fRemove)
    966 #endif /* !VIRTIO_VBUF_ON_STACK */
    967929{
    968930    Assert(uVirtq < RT_ELEMENTS(pVirtio->aVirtqueues));
     
    980942        pVirtq->uAvailIdxShadow++;
    981943
    982 #ifdef VIRTIO_VBUF_ON_STACK
    983     int rc = virtioCoreR3VirtqAvailBufGet(pDevIns, pVirtio, uVirtq, uHeadIdx, pVirtqBuf);
    984 #else /* !VIRTIO_VBUF_ON_STACK */
    985     int rc = virtioCoreR3VirtqAvailBufGet(pDevIns, pVirtio, uVirtq, uHeadIdx, ppVirtqBuf);
    986 #endif /* !VIRTIO_VBUF_ON_STACK */
    987     return rc;
     944    return virtioCoreR3VirtqAvailBufGet(pDevIns, pVirtio, uVirtq, uHeadIdx, pVirtqBuf);
    988945}
    989946
  • trunk/src/VBox/Devices/VirtIO/VirtioCore.h

    r99739 r100371  
    3232# pragma once
    3333#endif
    34 
    35 /* Do not allocate VIRTQBUF from the heap when possible */
    36 #define VIRTIO_VBUF_ON_STACK 1
    3734
    3835#include <iprt/ctype.h>
     
    698695uint16_t virtioCoreVirtqAvailBufCount(PPDMDEVINS pDevIns, PVIRTIOCORE pVirtio, uint16_t uVirtqNbr);
    699696
    700 #ifdef VIRTIO_VBUF_ON_STACK
    701697/**
    702698 * This function is identical to virtioCoreR3VirtqAvailBufGet(), *except* it doesn't consume
     
    767763int virtioCoreR3VirtqAvailBufGet(PPDMDEVINS pDevIns, PVIRTIOCORE pVirtio, uint16_t uVirtqNbr,
    768764                                  uint16_t uHeadIdx, PVIRTQBUF pVirtqBuf);
    769 #else /* !VIRTIO_VBUF_ON_STACK */
    770 /**
    771  * This function is identical to virtioCoreR3VirtqAvailBufGet(), *except* it doesn't consume
    772  * peeked buffer from avail ring of the virtq. The function *becomes* identical to the
    773  * virtioCoreR3VirtqAvailBufGet() only if virtioCoreR3VirtqAvailRingNext() is invoked to
    774  * consume buf from the queue's avail ring, followed by invocation of virtioCoreR3VirtqUsedBufPut(),
    775  * to hand host-processed buffer back to guest, which completes guest-initiated virtq buffer circuit.
    776  *
    777  * @param   pDevIns     The device instance.
    778  * @param   pVirtio     Pointer to the shared virtio state.
    779  * @param   uVirtqNbr   Virtq number
    780  * @param   ppVirtqBuf  Address to store pointer to descriptor chain that contains the
    781  *                      pre-processed transaction information pulled from the virtq.
    782  *
    783  * @returns VBox status code:
    784  * @retval  VINF_SUCCESS         Success
    785  * @retval  VERR_INVALID_STATE   VirtIO not in ready state (asserted).
    786  * @retval  VERR_NOT_AVAILABLE   If the queue is empty.
    787  */
    788 int  virtioCoreR3VirtqAvailBufPeek(PPDMDEVINS pDevIns, PVIRTIOCORE pVirtio, uint16_t uVirtqNbr,
    789                                    PPVIRTQBUF ppVirtqBuf);
    790 
    791 /**
    792  * This function fetches the next buffer (descriptor chain) from the VirtIO "avail" ring of
    793  * indicated queue, separating the buf's s/g vectors into OUT (e.g. guest-to-host)
    794  * components and and IN (host-to-guest) components.
    795  *
    796  * Caller is responsible for GCPhys to host virtual memory conversions. If the
    797  * virtq buffer being peeked at is "consumed", virtioCoreR3VirtqAvailRingNext() must
    798  * be called, and after that virtioCoreR3VirtqUsedBufPut() must be called to
    799  * complete the buffer transfer cycle with the guest.
    800  *
    801  * @param   pDevIns     The device instance.
    802  * @param   pVirtio     Pointer to the shared virtio state.
    803  * @param   uVirtqNbr   Virtq number
    804  * @param   ppVirtqBuf  Address to store pointer to descriptor chain that contains the
    805  *                      pre-processed transaction information pulled from the virtq.
    806  *                      Returned reference must be released by calling
    807  *                      virtioCoreR3VirtqBufRelease().
    808  * @param   fRemove     flags whether to remove desc chain from queue (false = peek)
    809  *
    810  * @returns VBox status code:
    811  * @retval  VINF_SUCCESS         Success
    812  * @retval  VERR_INVALID_STATE   VirtIO not in ready state (asserted).
    813  * @retval  VERR_NOT_AVAILABLE   If the queue is empty.
    814  */
    815 int  virtioCoreR3VirtqAvailBufGet(PPDMDEVINS pDevIns, PVIRTIOCORE pVirtio, uint16_t uVirtqNbr,
    816                                   PPVIRTQBUF ppVirtqBuf, bool fRemove);
    817 
    818 /**
    819  * Fetches a specific descriptor chain using avail ring of indicated queue and converts the
    820  * descriptor chain into its OUT (to device) and IN (to guest) components.
    821  *
    822  * The caller is responsible for GCPhys to host virtual memory conversions and *must*
    823  * return the virtq buffer using virtioCoreR3VirtqUsedBufPut() to complete the roundtrip
    824  * virtq transaction.
    825  * *
    826  * @param   pDevIns     The device instance.
    827  * @param   pVirtio     Pointer to the shared virtio state.
    828  * @param   uVirtqNbr   Virtq number
    829  * @param   ppVirtqBuf  Address to store pointer to descriptor chain that contains the
    830  *                      pre-processed transaction information pulled from the virtq.
    831  *                      Returned reference must be released by calling
    832  *                      virtioCoreR3VirtqBufRelease().
    833  * @param   fRemove     flags whether to remove desc chain from queue (false = peek)
    834  *
    835  * @returns VBox status code:
    836  * @retval  VINF_SUCCESS         Success
    837  * @retval  VERR_INVALID_STATE   VirtIO not in ready state (asserted).
    838  * @retval  VERR_NOT_AVAILABLE   If the queue is empty.
    839  */
    840 int virtioCoreR3VirtqAvailBufGet(PPDMDEVINS pDevIns, PVIRTIOCORE pVirtio, uint16_t uVirtqNbr,
    841                                   uint16_t uHeadIdx, PPVIRTQBUF ppVirtqBuf);
    842 #endif /* !VIRTIO_VBUF_ON_STACK */
    843765
    844766/**
     
    11851107int  virtioCoreVirtqUsedRingSync(PPDMDEVINS pDevIns, PVIRTIOCORE pVirtio, uint16_t uVirtqNbr);
    11861108
    1187 #ifdef VIRTIO_VBUF_ON_STACK
    11881109/**
    11891110 * Allocates a descriptor chain object with the reference count of one. Copying the reference
     
    12001121 */
    12011122PVIRTQBUF virtioCoreR3VirtqBufAlloc(void);
    1202 #endif /* VIRTIO_VBUF_ON_STACK */
    12031123
    12041124/**
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette