Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RHEL-69068: Apply clang-format for fwcfg64 folder #1207

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ Language: Cpp

AlignConsecutiveMacros:
Enabled: true
AcrossEmptyLines: false
AcrossComments: false
AcrossEmptyLines: true
AcrossComments: true
AlignCompound: false
AlignFunctionPointers: false
PadOperators: false
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/clang-format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
matrix:
path:
- check: '.'
exclude: './fwcfg64|./ivshmem|./NetKVM|./pciserial|./pvpanic|./viocrypt|./viofs|./viogpu|./vioinput|./viomem|./viorng|./vioscsi|./vioserial|./viosock|./viostor|./VirtIO'
exclude: './ivshmem|./NetKVM|./pciserial|./pvpanic|./viocrypt|./viofs|./viogpu|./vioinput|./viomem|./viorng|./vioscsi|./vioserial|./viosock|./viostor|./VirtIO'
- check: 'VirtIO'
exclude: ''

Expand Down
2 changes: 2 additions & 0 deletions .hck-ci/triggers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ viomem:
- build/
- VirtIO/
exclude:
- .clang-format
- VirtIO/.clang-format
- .github/
- .hck-ci/triggers.yml
- Tools/
Expand Down
2 changes: 1 addition & 1 deletion Balloon/sys/ProtoTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
#include "trace.h"

/* The ID for virtio_balloon */
#define VIRTIO_ID_BALLOON 5
#define VIRTIO_ID_BALLOON 5

/* The feature bitmap for virtio balloon */
#define VIRTIO_BALLOON_F_MUST_TELL_HOST 0 /* Tell before reclaiming pages */
Expand Down
4 changes: 2 additions & 2 deletions Balloon/sys/trace.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,11 @@ extern int driverDebugLevel;
WPP_DEFINE_BIT(DBG_HW_ACCESS) /* bit 12 = 0x00001000 */ \
)

#define WPP_FLAG_LEVEL_LOGGER(flag, level) WPP_LEVEL_LOGGER(flag)
#define WPP_FLAG_LEVEL_LOGGER(flag, level) WPP_LEVEL_LOGGER(flag)

#define WPP_FLAG_LEVEL_ENABLED(flag, level) (WPP_LEVEL_ENABLED(flag) && WPP_CONTROL(WPP_BIT_##flag).Level >= level)

#define WPP_LEVEL_FLAGS_LOGGER(lvl, flags) WPP_LEVEL_LOGGER(flags)
#define WPP_LEVEL_FLAGS_LOGGER(lvl, flags) WPP_LEVEL_LOGGER(flags)

#define WPP_LEVEL_FLAGS_ENABLED(lvl, flags) (WPP_LEVEL_ENABLED(flags) && WPP_CONTROL(WPP_BIT_##flags).Level >= lvl)

Expand Down
51 changes: 23 additions & 28 deletions fwcfg64/driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ NTSTATUS VMCoreInfoFill(PDEVICE_CONTEXT ctx)
TraceEvents(TRACE_LEVEL_VERBOSE, DBG_ALL, "Obtaining header");

hdr_buf = (PUCHAR)ctx->vmci_data.pNote + FIELD_OFFSET(VMCI_ELF64_NOTE, n_desc);
status = KeInitializeCrashDumpHeader(DUMP_TYPE_FULL, 0, hdr_buf,
DUMP_HDR_SIZE, &bufSizeNeeded);
status = KeInitializeCrashDumpHeader(DUMP_TYPE_FULL, 0, hdr_buf, DUMP_HDR_SIZE, &bufSizeNeeded);

if (!NT_SUCCESS(status))
{
Expand Down Expand Up @@ -53,8 +52,12 @@ NTSTATUS VMCoreInfoSend(PDEVICE_CONTEXT ctx)

TraceEvents(TRACE_LEVEL_VERBOSE, DBG_ALL, "Sending header");

status = FWCfgDmaSend(ctx->ioBase, ctx->vmci_data.vmci_pa, ctx->index,
sizeof(VMCOREINFO), ctx->dma_access, ctx->dma_access_pa);
status = FWCfgDmaSend(ctx->ioBase,
ctx->vmci_data.vmci_pa,
ctx->index,
sizeof(VMCOREINFO),
ctx->dma_access,
ctx->dma_access_pa);

return status;
}
Expand All @@ -73,7 +76,7 @@ NTSTATUS GetKdbg(PDEVICE_CONTEXT ctx)
PUCHAR minidump;
ULONG32 kdbg_offset;
ULONG32 kdbg_size;
CONTEXT context = { 0 };
CONTEXT context = {0};
NTSTATUS status = STATUS_SUCCESS;

minidump = ExAllocatePoolUninitialized(NonPagedPoolNx, MINIDUMP_BUFFER_SIZE, 'pmdm');
Expand All @@ -88,9 +91,11 @@ NTSTATUS GetKdbg(PDEVICE_CONTEXT ctx)
kdbg_offset = *(PULONG32)(minidump + MINIDUMP_OFFSET_KDBG_OFFSET);
kdbg_size = *(PULONG32)(minidump + MINIDUMP_OFFSET_KDBG_SIZE);

TraceEvents(TRACE_LEVEL_VERBOSE, DBG_INIT,
"KdDebuggerDataBlock size = %lx, offset = 0x%lx",
kdbg_size, kdbg_offset);
TraceEvents(TRACE_LEVEL_VERBOSE,
DBG_INIT,
"KdDebuggerDataBlock size = %lx, offset = 0x%lx",
kdbg_size,
kdbg_offset);

/*
* KeCapturePersistentThreadState is supposed to save Small Memory Dump to the buffer.
Expand Down Expand Up @@ -164,35 +169,28 @@ NTSTATUS FwCfgEvtDeviceAdd(IN WDFDRIVER Driver, IN PWDFDEVICE_INIT DeviceInit)

if (!NT_SUCCESS(status))
{
TraceEvents(TRACE_LEVEL_ERROR, DBG_INIT,
"WdfDeviceCreate failed: %!STATUS!", status);
TraceEvents(TRACE_LEVEL_ERROR, DBG_INIT, "WdfDeviceCreate failed: %!STATUS!", status);
return status;
}

ctx = GetDeviceContext(device);
memset(ctx, 0, sizeof(*ctx));

WDF_DMA_ENABLER_CONFIG_INIT(&dmaEnablerConfig, WdfDmaProfilePacket64,
sizeof(CBUF_DATA));
status = WdfDmaEnablerCreate(device, &dmaEnablerConfig,
WDF_NO_OBJECT_ATTRIBUTES, &ctx->dmaEnabler);
WDF_DMA_ENABLER_CONFIG_INIT(&dmaEnablerConfig, WdfDmaProfilePacket64, sizeof(CBUF_DATA));
status = WdfDmaEnablerCreate(device, &dmaEnablerConfig, WDF_NO_OBJECT_ATTRIBUTES, &ctx->dmaEnabler);

if (!NT_SUCCESS(status))
{
TraceEvents(TRACE_LEVEL_ERROR, DBG_INIT,
"Failed to create DMA enabler");
TraceEvents(TRACE_LEVEL_ERROR, DBG_INIT, "Failed to create DMA enabler");
return status;
}

TraceEvents(TRACE_LEVEL_VERBOSE, DBG_INIT,
"DMA enabler created");
TraceEvents(TRACE_LEVEL_VERBOSE, DBG_INIT, "DMA enabler created");

status = WdfCommonBufferCreate(ctx->dmaEnabler, sizeof(CBUF_DATA),
WDF_NO_OBJECT_ATTRIBUTES, &ctx->cbuf);
status = WdfCommonBufferCreate(ctx->dmaEnabler, sizeof(CBUF_DATA), WDF_NO_OBJECT_ATTRIBUTES, &ctx->cbuf);
if (!NT_SUCCESS(status))
{
TraceEvents(TRACE_LEVEL_ERROR, DBG_INIT,
"Failed to create common buffer");
TraceEvents(TRACE_LEVEL_ERROR, DBG_INIT, "Failed to create common buffer");
return status;
}

Expand All @@ -205,8 +203,7 @@ NTSTATUS FwCfgEvtDeviceAdd(IN WDFDRIVER Driver, IN PWDFDEVICE_INIT DeviceInit)
return STATUS_SUCCESS;
}

NTSTATUS DriverEntry(IN PDRIVER_OBJECT DriverObject,
IN PUNICODE_STRING RegistryPath)
NTSTATUS DriverEntry(IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegistryPath)
{
NTSTATUS status;
WDF_DRIVER_CONFIG config;
Expand All @@ -219,12 +216,10 @@ NTSTATUS DriverEntry(IN PDRIVER_OBJECT DriverObject,

WDF_DRIVER_CONFIG_INIT(&config, FwCfgEvtDeviceAdd);

status = WdfDriverCreate(DriverObject, RegistryPath, &attributes,
&config, WDF_NO_HANDLE);
status = WdfDriverCreate(DriverObject, RegistryPath, &attributes, &config, WDF_NO_HANDLE);
if (!NT_SUCCESS(status))
{
TraceEvents(TRACE_LEVEL_ERROR, DBG_INIT,
"WdfDriverCreate failed: %!STATUS!", status);
TraceEvents(TRACE_LEVEL_ERROR, DBG_INIT, "WdfDriverCreate failed: %!STATUS!", status);
WPP_CLEANUP(DriverObject);
}

Expand Down
77 changes: 41 additions & 36 deletions fwcfg64/driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,29 @@
#include <wdf.h>
#include "fwcfg.h"

#define ENTRY_NAME "etc/vmcoreinfo"
#define VMCI_ELF_NOTE_NAME "VMCOREINFO"
#define DUMP_TYPE_FULL 1
#define VMCOREINFO_FORMAT_ELF 0x1
#define ENTRY_NAME "etc/vmcoreinfo"
#define VMCI_ELF_NOTE_NAME "VMCOREINFO"
#define DUMP_TYPE_FULL 1
#define VMCOREINFO_FORMAT_ELF 0x1
#ifdef _AMD64_
#define DUMP_HDR_SIZE (PAGE_SIZE * 2)
#define MINIDUMP_OFFSET_KDBG_OFFSET (DUMP_HDR_SIZE + 0x70)
#define MINIDUMP_OFFSET_KDBG_SIZE (DUMP_HDR_SIZE + 0x74)
#define DUMP_HDR_OFFSET_BUGCHECK_PARAM1 0x40
#define DUMP_HDR_SIZE (PAGE_SIZE * 2)
#define MINIDUMP_OFFSET_KDBG_OFFSET (DUMP_HDR_SIZE + 0x70)
#define MINIDUMP_OFFSET_KDBG_SIZE (DUMP_HDR_SIZE + 0x74)
#define DUMP_HDR_OFFSET_BUGCHECK_PARAM1 0x40
#else
#define DUMP_HDR_SIZE (PAGE_SIZE)
#define MINIDUMP_OFFSET_KDBG_OFFSET (DUMP_HDR_SIZE + 0x58)
#define MINIDUMP_OFFSET_KDBG_SIZE (DUMP_HDR_SIZE + 0x5c)
#define DUMP_HDR_OFFSET_BUGCHECK_PARAM1 0x2c
#define DUMP_HDR_SIZE (PAGE_SIZE)
#define MINIDUMP_OFFSET_KDBG_OFFSET (DUMP_HDR_SIZE + 0x58)
#define MINIDUMP_OFFSET_KDBG_SIZE (DUMP_HDR_SIZE + 0x5c)
#define DUMP_HDR_OFFSET_BUGCHECK_PARAM1 0x2c
#endif

#define MINIDUMP_BUFFER_SIZE 0x40000

#define ROUND_UP(x, n) (((x) + (n) - 1) & (-(n)))
#define ROUND_UP(x, n) (((x) + (n) - 1) & (-(n)))

#pragma pack(push, 1)
typedef struct VMCOREINFO {
typedef struct VMCOREINFO
{
UINT16 host_fmt;
UINT16 guest_fmt;
UINT32 size;
Expand All @@ -38,38 +39,42 @@ typedef struct VMCOREINFO {
#pragma pack(pop)

#pragma pack(push, 1)
typedef struct VMCI_ELF64_NOTE {
UINT32 n_namesz;
UINT32 n_descsz;
UINT32 n_type;
UCHAR n_name[ROUND_UP(sizeof(VMCI_ELF_NOTE_NAME), 4)];
UCHAR n_desc[ROUND_UP(DUMP_HDR_SIZE, 4)];
typedef struct VMCI_ELF64_NOTE
{
UINT32 n_namesz;
UINT32 n_descsz;
UINT32 n_type;
UCHAR n_name[ROUND_UP(sizeof(VMCI_ELF_NOTE_NAME), 4)];
UCHAR n_desc[ROUND_UP(DUMP_HDR_SIZE, 4)];
} VMCI_ELF64_NOTE, *PVMCI_ELF64_NOTE;
#pragma pack(pop)

typedef struct CBUF_DATA {
typedef struct CBUF_DATA
{
VMCI_ELF64_NOTE note;
VMCOREINFO vmci;
FWCfgDmaAccess fwcfg_da;
} CBUF_DATA, *PCBUF_DATA;

typedef struct VMCI_DATA {
PVMCOREINFO pVmci;
PVMCI_ELF64_NOTE pNote;
LONGLONG vmci_pa;
LONGLONG note_pa;
typedef struct VMCI_DATA
{
PVMCOREINFO pVmci;
PVMCI_ELF64_NOTE pNote;
LONGLONG vmci_pa;
LONGLONG note_pa;
} VMCI_DATA, *PVMCI_DATA;

typedef struct DEVICE_CONTEXT {
PVOID ioBase;
ULONG ioSize;
UINT16 index;
WDFCOMMONBUFFER cbuf;
WDFDMAENABLER dmaEnabler;
VMCI_DATA vmci_data;
FWCfgDmaAccess *dma_access;
LONGLONG dma_access_pa;
PUCHAR kdbg;
typedef struct DEVICE_CONTEXT
{
PVOID ioBase;
ULONG ioSize;
UINT16 index;
WDFCOMMONBUFFER cbuf;
WDFDMAENABLER dmaEnabler;
VMCI_DATA vmci_data;
FWCfgDmaAccess *dma_access;
LONGLONG dma_access_pa;
PUCHAR kdbg;
} DEVICE_CONTEXT, *PDEVICE_CONTEXT;

ULONG NTAPI KeCapturePersistentThreadState(PCONTEXT Context,
Expand Down
27 changes: 17 additions & 10 deletions fwcfg64/fwcfg.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@ NTSTATUS FWCfgCheckSig(PVOID ioBase)
UCHAR signature[FW_CFG_SIG_SIZE];

FWCfgReadBlob(ioBase, FW_CFG_SIGNATURE, signature, FW_CFG_SIG_SIZE);
TraceEvents(TRACE_LEVEL_VERBOSE, DBG_ALL,
"Signature is [%.4s]", (PCHAR)signature);
TraceEvents(TRACE_LEVEL_VERBOSE, DBG_ALL, "Signature is [%.4s]", (PCHAR)signature);
if (memcmp(signature, FW_CFG_QEMU, FW_CFG_SIG_SIZE))
{
TraceEvents(TRACE_LEVEL_ERROR, DBG_ALL, "Signature check failed, "
"["FW_CFG_QEMU"] expected");
TraceEvents(TRACE_LEVEL_ERROR,
DBG_ALL,
"Signature check failed, "
"[" FW_CFG_QEMU "] expected");
return STATUS_BAD_DATA;
}

Expand All @@ -39,8 +40,11 @@ NTSTATUS FWCfgCheckFeatures(PVOID ioBase, UINT32 features)
TraceEvents(TRACE_LEVEL_VERBOSE, DBG_ALL, "Features are 0x%lx", f_bitmap);
if ((f_bitmap & features) != features)
{
TraceEvents(TRACE_LEVEL_ERROR, DBG_ALL, "Features check failed, "
" 0x%lx expected", features);
TraceEvents(TRACE_LEVEL_ERROR,
DBG_ALL,
"Features check failed, "
" 0x%lx expected",
features);
return STATUS_BAD_DATA;
}

Expand Down Expand Up @@ -89,8 +93,7 @@ UINT32 FWCfgGetEntriesNum(PVOID ioBase)
return num;
}

NTSTATUS FWCfgFindEntry(PVOID ioBase, const char *name,
PUSHORT index, ULONG size)
NTSTATUS FWCfgFindEntry(PVOID ioBase, const char *name, PUSHORT index, ULONG size)
{
UINT32 i;
UINT32 total = FWCfgGetEntriesNum(ioBase);
Expand Down Expand Up @@ -119,8 +122,12 @@ NTSTATUS FWCfgFindEntry(PVOID ioBase, const char *name,
return STATUS_BAD_DATA;
}

NTSTATUS FWCfgDmaSend(PVOID ioBase, LONGLONG data_pa, USHORT index,
UINT32 size, FWCfgDmaAccess *pDmaAccess, LONGLONG dmaAccess_pa)
NTSTATUS FWCfgDmaSend(PVOID ioBase,
LONGLONG data_pa,
USHORT index,
UINT32 size,
FWCfgDmaAccess *pDmaAccess,
LONGLONG dmaAccess_pa)
{
UINT16 ctrl = FW_CFG_DMA_CTL_SELECT | FW_CFG_DMA_CTL_WRITE;
NTSTATUS status;
Expand Down
Loading