Skip to content

Commit

Permalink
kernel/freebsd: include mapped buffers in core dump
Browse files Browse the repository at this point in the history
It was impossible to include mapped contigmem buffers in core dump.
Add hw.contigmem.coredump_enable tunable to control the inclusion.

Mappings backed by OBJ_FICTITIOUS are excluded from core dump.
While contigmem is a device and its OBJT_DEVICE mappings get this flag,
they are actually backed by memory.
Clear OBJ_FICTITIOUS mapping bit to include them in core dump.
Do this only if hw.contigmem.coredump_enable=1.

Signed-off-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
Acked-by: Bruce Richardson <bruce.richardson@intel.com>
  • Loading branch information
PlushBeaver authored and tmonjalo committed Nov 19, 2024
1 parent ff92d10 commit cbe57f3
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
27 changes: 20 additions & 7 deletions doc/guides/freebsd_gsg/build_dpdk.rst
Original file line number Diff line number Diff line change
Expand Up @@ -86,22 +86,35 @@ module loading using::
kenv hw.contigmem.num_buffers=n
kenv hw.contigmem.buffer_size=m

Where n is the number of blocks and m is the size in bytes of each area of contiguous memory.
A default of two buffers of size 1073741824 bytes (1 Gigabyte) each
is set during module load if they are not specified in the environment.

Buffers are excluded from core dump by default.
Mapped buffers can be included in core dump using the following tunable::

hw.contigmem.coredump_enable=1

.. note::

Including contigmem buffers in core dump file increases its size,
which may fill the storage or overload the transport.
Buffers typically hold data processed by the application,
like network packets, which may contain sensitive information.

The kernel environment variables can also be specified during boot by placing the
following in ``/boot/loader.conf``:

.. code-block:: shell
hw.contigmem.num_buffers=n
hw.contigmem.buffer_size=m
hw.contigmem.coredump_enable=1
The variables can be inspected using the following command::

sysctl -a hw.contigmem

Where n is the number of blocks and m is the size in bytes of each area of
contiguous memory. A default of two buffers of size 1073741824 bytes (1 Gigabyte)
each is set during module load if they are not specified in the environment.

The module can then be loaded using kldload::

kldload contigmem
Expand All @@ -115,13 +128,13 @@ up time. This can be achieved by placing lines similar to the following into
hw.contigmem.num_buffers=1
hw.contigmem.buffer_size=1073741824
hw.contigmem.coredump_enable=1
contigmem_load="YES"
.. note::

The contigmem_load directive should be placed after any definitions of
``hw.contigmem.num_buffers`` and ``hw.contigmem.buffer_size`` if the default values
are not to be used.
The ``contigmem_load`` directive should be placed after any definitions
of ``hw.contigmem.*`` if the default values are not to be used.

An error such as::

Expand Down
8 changes: 8 additions & 0 deletions kernel/freebsd/contigmem/contigmem.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ static d_close_t contigmem_close;

static int contigmem_num_buffers = RTE_CONTIGMEM_DEFAULT_NUM_BUFS;
static int64_t contigmem_buffer_size = RTE_CONTIGMEM_DEFAULT_BUF_SIZE;
static bool contigmem_coredump_enable;

static eventhandler_tag contigmem_eh_tag;
static struct contigmem_buffer contigmem_buffers[RTE_CONTIGMEM_MAX_NUM_BUFS];
Expand All @@ -59,6 +60,7 @@ static int contigmem_refcnt;

TUNABLE_INT("hw.contigmem.num_buffers", &contigmem_num_buffers);
TUNABLE_QUAD("hw.contigmem.buffer_size", &contigmem_buffer_size);
TUNABLE_BOOL("hw.contigmem.coredump_enable", &contigmem_coredump_enable);

static SYSCTL_NODE(_hw, OID_AUTO, contigmem, CTLFLAG_RD, 0, "contigmem");

Expand All @@ -68,6 +70,8 @@ SYSCTL_QUAD(_hw_contigmem, OID_AUTO, buffer_size, CTLFLAG_RD,
&contigmem_buffer_size, 0, "Size of each contiguous buffer");
SYSCTL_INT(_hw_contigmem, OID_AUTO, num_references, CTLFLAG_RD,
&contigmem_refcnt, 0, "Number of references to contigmem");
SYSCTL_BOOL(_hw_contigmem, OID_AUTO, coredump_enable, CTLFLAG_RD,
&contigmem_coredump_enable, 0, "Include mapped buffers in core dump");

static SYSCTL_NODE(_hw_contigmem, OID_AUTO, physaddr, CTLFLAG_RD, 0,
"physaddr");
Expand Down Expand Up @@ -357,5 +361,9 @@ contigmem_mmap_single(struct cdev *cdev, vm_ooffset_t *offset, vm_size_t size,
*obj = cdev_pager_allocate(vmh, OBJT_DEVICE, &contigmem_cdev_pager_ops,
size, nprot, *offset, curthread->td_ucred);

/* Mappings backed by OBJ_FICTITIOUS are excluded from core dump. */
if (contigmem_coredump_enable)
(*obj)->flags &= ~OBJ_FICTITIOUS;

return 0;
}

0 comments on commit cbe57f3

Please sign in to comment.