lx: no request that can sleep runs on the driver's incoming-call thread

On 241 a request that waited on a GPU ring that had stopped ran on the
one thread DriverKit delivers every client's calls on: every client froze,
and the driver could not take its own Stop after the GPU was powered off.

Every Linux-file request that can sleep now runs on a worker of the
client's process and completes through AsyncCompletion:
- mlg_lx_cmd_sleeps (lx_describe.c, shared by the client library and the
  driver) names the few requests that provably do not sleep: VERSION,
  GET_CAP, SET_CLIENT_CAP, the syncobj create, destroy, export, import,
  reset, signal, timeline signal, query and eventfd requests, a syncobj
  wait that only polls, and KFD GET_VERSION. Everything else is async,
  AMDGPU_CS, INFO, GEM and context requests included.
- LX_IOCTL runs only those, through rt_lx_ioctl_nosleep; any other is
  refused without running (kIOReturnNotPermitted) and logged with the
  request and the process.
- LX_CALL_ASYNC (selector 105) runs open, close, mmap and munmap on a
  worker; the synchronous selectors 96, 97, 101 and 103 are retired.
- A Linux-file client's Stop hands its process's exit to a thread of its
  own (rt_lx_client_retire) instead of waiting for its calls on the
  incoming-call thread; a session close waits for those exits
  (rt_lx_retire_drain) before the driver goes. On an unplug the Stop has
  already begun removal, which completes the GPU's fences, so the exits
  finish.
- An async call holds one of MLG_LX_MAX_ASYNC slots until its result is
  delivered: with the completion (the slot frees before it is sent) or by
  LX_RESULT, whose result is in place before the completion goes out. The
  client library keeps its calls within the limit, waiting on its own
  thread. A worker still sending a completion holds no slot, so a call
  queues for it instead of failing.
- The transport revision is MLG_LX_ABI 2: libmlg_drm's dylib
  compatibility version, and the text MLG_LX_ABI_TAG in the library for
  launchers to check. A client library older than this driver fails at
  its first sleeping request or open, with the reason in the driver log.

Events reach the unified log; routine lines stay in the retained ring.
The dext logged every line through os_log, and nothing from it reached
the unified log in the boot where 241 hung (probably quarantined for
volume), so the hang's cause was lost with the dext. Now only events go
there, prefixed "mac.linuxgpu: EVENT ": driver start, probe outcome,
removal, quarantine and release, session close, DMA mapping failures,
printk at error level and above (ring timeouts among them), and the head
of a device coredump, which dev_coredumpm now logs before freeing it.
Read them with
  log show --predicate 'eventMessage BEGINSWITH "mac.linuxgpu: EVENT"'

Tests: test_lx_files covers the table, the synchronous refusal, the
operations on workers, inline and fetched results and the new slot rules.
blocked_call_check (test-cs-selftest) blocks a client's AMDGPU_CS behind
amdgpu_sched_jobs submissions on a held compute engine and checks that
every call returns at once, the blocked client's non-sleeping request
runs and its sleeping one is refused synchronously, another client opens,
allocates and completes SDMA work, the blocked client's Stop returns at
once and its exit finishes when the engine runs, and, during the surprise
removal check, that removal ends a blocked submission and the client's
exit completes.
This commit is contained in:
geramyloveless committed 2026-10-04 20:27:43 -07:00
1 parent b4d1555088
commit ec8198541d
28 files changed
+1641 -342

No files matched your search

+5
View File
@@ -1123,10 +1123,15 @@ $(MLG_DRM_BUILD)/%.o: linuxu/src/amdgpu-rt/%.c
@mkdir -p $(dir $@)
clang $(MLG_DRM_CFLAGS) -c $< -o $@
# The transport revision (rt/lx_abi.h MLG_LX_ABI): the dylib's compatibility
# version, so a libdrm_mlg linked against it refuses an older one at load.
MLG_LX_ABI := $(shell sed -n 's/^\#define MLG_LX_ABI[[:space:]]*\([0-9][0-9]*\)$$/\1/p' linuxu/headers/rt/lx_abi.h)
libmlg_drm: $(MLG_DRM_OBJS)
@rm -f $(MLG_DRM_BUILD)/libmlg_drm.a
ar rcs $(MLG_DRM_BUILD)/libmlg_drm.a $(MLG_DRM_OBJS)
clang -dynamiclib -install_name @rpath/libmlg_drm.dylib $(MLG_DRM_OBJS) \
-compatibility_version $(MLG_LX_ABI).0 -current_version $(MLG_LX_ABI).0 \
-framework IOKit -framework CoreFoundation -o $(MLG_DRM_BUILD)/libmlg_drm.dylib
@echo "libmlg_drm: OK ($(MLG_DRM_BUILD)/libmlg_drm.a, libmlg_drm.dylib)"
+7
View File
@@ -75,6 +75,13 @@ the next steps.
`gpu_busy_percent`, `mem_busy_percent`, `gpu_metrics` and hwmon, and
`AMDGPU_INFO`. That's the same data `amdgpu_top` reads on Linux, and what
[amdgpu_mtopg](https://github.com/lemonade-sdk/amdgpu_mtopg) displays.
Events that matter after a hang or a reboot (driver start, probe result,
GPU ring timeouts and device dumps, errors from upstream, removal,
quarantine, session close) also go to the macOS unified log, prefixed
`mac.linuxgpu: EVENT`; routine lines stay in the retained log only. Read
them, from any boot the log still holds, with
`log show --last 1d --predicate 'eventMessage BEGINSWITH "mac.linuxgpu: EVENT"'`
(DriverKit logs through the kernel, so they show as `kernel`).
- **Vulkan (in progress).** Mesa's RADV builds for macOS on the same
upstream amdgpu DRM interface, through a libdrm over the driver's
Linux-file transport, and runs offline on the test suite's software GPU.
+143 -91
View File
@@ -170,16 +170,16 @@ static_assert(kMacAMDGPUMethodReleaseQuarantine == MLG_SELECTOR_RELEASE_QUARANTI
static_assert(MLG_SELECTOR_SYSFS_READ > kMacAMDGPUMethodReleaseQuarantine &&
MLG_SELECTOR_DRM_INFO > kMacAMDGPUMethodReleaseQuarantine, "Linux read selectors");
static_assert(MLG_SELECTOR_DISPLAY > MLG_SELECTOR_DRM_SELFTEST &&
MLG_SELECTOR_DISPLAY < MLG_SELECTOR_LX_OPEN, "display selector");
MLG_SELECTOR_DISPLAY < MLG_SELECTOR_LX_FIRST, "display selector");
static_assert(MLG_SELECTOR_EVENT > MLG_SELECTOR_RETIRE &&
MLG_SELECTOR_EVENT_WAIT < MLG_SELECTOR_LX_OPEN &&
MLG_SELECTOR_EVENT_WAIT < MLG_SELECTOR_LX_FIRST &&
MLG_EVENT_WAIT_IDS == RT_KFD_WAIT_EVENTS_MAX &&
MLG_EVENT_WAIT_MAX_MS == RT_KFD_WAIT_MAX_MS &&
DEXT_COMPUTE_EVENT_CREATE == MLG_EVENT_OP_CREATE &&
DEXT_COMPUTE_EVENT_DESTROY == MLG_EVENT_OP_DESTROY &&
DEXT_COMPUTE_EVENT_SET == MLG_EVENT_OP_SET, "event selectors");
static_assert(MLG_SELECTOR_RETIRE > MLG_SELECTOR_DISPLAY &&
MLG_SELECTOR_RETIRE < MLG_SELECTOR_LX_OPEN, "retire selector");
MLG_SELECTOR_RETIRE < MLG_SELECTOR_LX_FIRST, "retire selector");
static_assert(MLG_DISPLAY_PATTERNS == RT_DISPLAY_PATTERNS &&
MLG_DISPLAY_PATTERN_BARS == RT_DISPLAY_PATTERN_BARS &&
MLG_DISPLAY_PATTERN_WHITE == RT_DISPLAY_PATTERN_WHITE &&
@@ -249,12 +249,17 @@ extern "C" int rt_pci_probe_cleanup_retained(void *pdev);
extern "C" int fw_table_register_embedded(void);
#include "retained_log.h"
static void maclinuxgpu_log_sink(const char *text)
// The unified log takes only events (MACLINUXGPU_EVENT): a dext that logs
// every routine line there gets its logging quarantined by the system for
// high volume, and then the lines that matter after a hang are lost with
// the rest. Routine lines stay in the retained ring (read-driver-log.py).
static void maclinuxgpu_event_sink(const char *text)
{
os_log(OS_LOG_DEFAULT, "%{public}s", text);
}
#define MACLINUXGPU_LOG(...) \
maclinuxgpu::RetainedLog(maclinuxgpu_log_sink, __VA_ARGS__)
#define MACLINUXGPU_LOG(...) maclinuxgpu::RetainedLog(nullptr, __VA_ARGS__)
#define MACLINUXGPU_EVENT(...) \
maclinuxgpu::RetainedEvent(maclinuxgpu_event_sink, __VA_ARGS__)
// ----------------------------------------------------------------
// MacLinuxGPU (IOService) — the OSMetaClass method bodies.
@@ -494,6 +499,8 @@ static void lx_gate_close()
static bool lx_teardown_all()
{
lx_gate_close();
// Clients a Stop handed to their own threads (lx_client_stop).
rt_lx_retire_drain();
for (;;) {
struct rt_lx_client *lx = nullptr;
lx_registry_acquire();
@@ -542,7 +549,7 @@ static void note_quarantine(uint32_t cause, int code)
} else {
return;
}
MACLINUXGPU_LOG("quarantine cause: step %u code %d (observed by step %u)",
MACLINUXGPU_EVENT("quarantine cause: step %u code %d (observed by step %u)",
s_quarantineCause, s_quarantineCode, s_quarantineObserved);
}
@@ -564,7 +571,7 @@ static void quarantine_session(MacLinuxGPU *driver)
s_pciIsolation = isolated;
s_pciIsolationAttempted = true;
if (isolated != 0)
MACLINUXGPU_LOG("quarantine: PCI isolation unconfirmed (%d); retaining all owners", isolated);
MACLINUXGPU_EVENT("quarantine: PCI isolation unconfirmed (%d); retaining all owners", isolated);
}
// Why a quarantined session cannot be released yet, from cached state only.
@@ -641,7 +648,7 @@ static void request_termination(MacLinuxGPU *driver)
const kern_return_t ret = driver->Terminate(0);
if (ret != kIOReturnSuccess) {
s_terminateRequested = false;
MACLINUXGPU_LOG("retire: Terminate failed (%#x); the idle instance stays until its "
MACLINUXGPU_EVENT("retire: Terminate failed (%#x); the idle instance stays until its "
"device leaves or the Mac restarts", ret);
}
}
@@ -652,7 +659,7 @@ static void complete_session_close(MacLinuxGPU *driver)
{
if (s_deviceRemoved) {
const int closed = dext_pci_close_removed();
MACLINUXGPU_LOG("removal: provider %s (%d); the next device probes afresh",
MACLINUXGPU_EVENT("removal: provider %s (%d); the next device probes afresh",
closed ? "close deferred" : "closed", closed);
s_deviceRemoved = false;
} else {
@@ -693,7 +700,7 @@ static uint32_t release_quarantine(MacLinuxGPU *driver)
{
const uint32_t blocker = release_blocker();
if (blocker != MLG_RELEASE_READY) {
MACLINUXGPU_LOG("quarantine release refused: blocker %u%s", blocker,
MACLINUXGPU_EVENT("quarantine release refused: blocker %u%s", blocker,
mlg_release_blocker_permanent(blocker) ?
"; restart required, do not kill the driver" : "; retry after it clears");
return blocker;
@@ -713,11 +720,11 @@ static uint32_t release_quarantine(MacLinuxGPU *driver)
if (result) {
s_releaseFailed = true;
quarantine_session(driver);
MACLINUXGPU_LOG("quarantine release failed (%d); restart required, do not kill the driver", result);
MACLINUXGPU_EVENT("quarantine release failed (%d); restart required, do not kill the driver", result);
return MLG_RELEASE_RESET_FAILED;
}
s_dmaQuarantined = false;
MACLINUXGPU_LOG("quarantine released after endpoint reset; provider closed");
MACLINUXGPU_EVENT("quarantine released after endpoint reset; provider closed");
complete_session_close(driver);
return MLG_RELEASE_READY;
}
@@ -735,16 +742,16 @@ static void note_device_removed(const char *where)
{
if (s_deviceRemoved) return;
s_deviceRemoved = true;
MACLINUXGPU_LOG("device removed from the bus (%s): no further hardware access; "
MACLINUXGPU_EVENT("device removed from the bus (%s): no further hardware access; "
"the session closes without waiting for the GPU", where);
dext_pci_mark_removed();
if (s_rtDevice != nullptr) {
const int begun = rt_removal_begin(static_cast<struct pci_dev *>(rt_device_get_pdev(s_rtDevice)));
if (begun) MACLINUXGPU_LOG("removal: GPU work completion thread not started (%d)", begun);
if (begun) MACLINUXGPU_EVENT("removal: GPU work completion thread not started (%d)", begun);
}
dext_compute_device_removed();
const int kept = dext_dma_device_removed();
if (kept) MACLINUXGPU_LOG("removal: %d DMA descriptor(s) could not be completed; backing retained", kept);
if (kept) MACLINUXGPU_EVENT("removal: %d DMA descriptor(s) could not be completed; backing retained", kept);
power_device_removed();
}
@@ -798,14 +805,14 @@ static void close_session(MacLinuxGPU *driver)
s_dmaQuarantined = true;
note_quarantine(MLG_QUARANTINE_COMPUTE_UNCERTAIN, -16);
}
MACLINUXGPU_LOG("session close begin: probe=%d result=%d modules=%d pci=%d quarantine=%d participants=%u",
MACLINUXGPU_EVENT("session close begin: probe=%d result=%d modules=%d pci=%d quarantine=%d participants=%u",
s_probeAttempted, s_probeResult, s_modulesRunning, s_pciOpen,
s_dmaQuarantined, s_participants);
// Stop is also reached through forced service termination. It provides
// no proof that a client's raw BAR mappings have been revoked yet.
if (s_rawBARLease.hasMappings() && s_deviceRemoved) {
// The mapped BAR belongs to a device that is gone; it carries no DMA.
MACLINUXGPU_LOG("session close: a client still maps a BAR of the removed device");
MACLINUXGPU_EVENT("session close: a client still maps a BAR of the removed device");
} else if (s_rawBARLease.hasMappings()) {
s_dmaQuarantined = true;
note_quarantine(MLG_QUARANTINE_RAW_BAR_MAPPING, 0);
@@ -826,7 +833,7 @@ static void close_session(MacLinuxGPU *driver)
if (!s_dmaQuarantined) {
const int stopped = dext_compute_stop();
if (stopped != 0 && s_deviceRemoved) {
MACLINUXGPU_LOG("session close: compute stop after removal returned %d; nothing can run", stopped);
MACLINUXGPU_EVENT("session close: compute stop after removal returned %d; nothing can run", stopped);
} else if (stopped != 0) {
s_dmaQuarantined = true;
note_quarantine(MLG_QUARANTINE_COMPUTE_UNCERTAIN, stopped);
@@ -860,7 +867,7 @@ static void close_session(MacLinuxGPU *driver)
s_irqDrainFailed = true;
note_quarantine(MLG_QUARANTINE_IRQ_CANCEL, drained);
quarantine_session(driver);
MACLINUXGPU_LOG("session close blocked: interrupt cancellation failed (%d)", drained);
MACLINUXGPU_EVENT("session close blocked: interrupt cancellation failed (%d)", drained);
}
}
@@ -878,7 +885,7 @@ static void release_removed(MacLinuxGPU *driver)
return;
}
if (s_irqDrainFailed) {
MACLINUXGPU_LOG("removal: interrupt sources still own callbacks; the session stays quarantined");
MACLINUXGPU_EVENT("removal: interrupt sources still own callbacks; the session stays quarantined");
return;
}
s_dmaQuarantined = false;
@@ -901,10 +908,10 @@ static void release_removed(MacLinuxGPU *driver)
(void)dext_dma_device_removed();
const int released = dext_dma_fini();
if (released)
MACLINUXGPU_LOG("removal: DMA backing still owned (%d) is kept; the provider closes", released);
MACLINUXGPU_EVENT("removal: DMA backing still owned (%d) is kept; the provider closes", released);
dext_compute_set_pci_open(false);
dext_compute_set_stage(DEXT_COMPUTE_STAGE_NONE);
MACLINUXGPU_LOG("removal: session released after the device left the bus");
MACLINUXGPU_EVENT("removal: session released after the device left the bus");
complete_session_close(driver);
}
@@ -1364,7 +1371,7 @@ static void power_fail(MacLinuxGPU *driver, uint32_t cause, int error)
MACLINUXGPU_LOG("power: KFD suspend handed back before the close (%d)", resumed);
}
power_set(MLG_POWER_LOST, cause, error);
MACLINUXGPU_LOG("power: closing the compute session (cause %u, error %d); the next client re-probes",
MACLINUXGPU_EVENT("power: closing the compute session (cause %u, error %d); the next client re-probes",
cause, error);
close_session(driver);
}
@@ -1397,7 +1404,7 @@ static void power_quiesce(MacLinuxGPU *driver, uint32_t cause)
// whether or not every queue came off MES.
s_power.flags |= MLG_POWER_FLAG_KFD_QUIESCED;
if (r && r != -37 /* EALREADY: already held */) {
MACLINUXGPU_LOG("power: upstream KFD suspend failed (%d): %u of %u queues mapped, "
MACLINUXGPU_EVENT("power: upstream KFD suspend failed (%d): %u of %u queues mapped, "
"%u processes marked for reset", r, report.active, report.queues,
report.reset_marked);
power_fail(driver, MLG_POWER_CAUSE_QUIESCE_FAILED, r);
@@ -1667,18 +1674,23 @@ IMPL(MacLinuxGPU, Start)
MACLINUXGPU_LOG("provider is not an IOPCIDevice");
return kIOReturnUnsupported;
}
{
uint64_t build[4] = {0, 0, 0, 0};
(void)dext_compute_runtime_build_cached(build);
MACLINUXGPU_EVENT("driver start (build %llu)", build[3]);
}
// Optional embedded fallback; may be empty and is never assumed complete.
int fw_result = fw_table_register_embedded();
if (fw_result != 0) {
MACLINUXGPU_LOG("firmware registration failed: %d", fw_result);
MACLINUXGPU_EVENT("firmware registration failed: %d", fw_result);
return kIOReturnNoMemory;
}
IODispatchQueue *bqueue = nullptr;
kern_return_t qret = IODispatchQueue::Create("MacLinuxGPUBringup", 0, 0, &bqueue);
if (qret != kIOReturnSuccess || bqueue == nullptr) {
MACLINUXGPU_LOG("IODispatchQueue::Create failed: %#x", qret);
MACLINUXGPU_EVENT("IODispatchQueue::Create failed: %#x", qret);
return qret != kIOReturnSuccess ? qret : kIOReturnNoMemory;
}
s_bringupQueue = bqueue;
@@ -1823,7 +1835,7 @@ MacLinuxGPU::FinishSession()
if (isolated != 0) {
s_dmaQuarantined = true;
note_quarantine(MLG_QUARANTINE_ENDPOINT_ISOLATION, isolated);
MACLINUXGPU_LOG("session close: endpoint isolation failed (%d); DMA backing retained", isolated);
MACLINUXGPU_EVENT("session close: endpoint isolation failed (%d); DMA backing retained", isolated);
}
}
dext_compute_set_pci_open(false);
@@ -1833,7 +1845,7 @@ MacLinuxGPU::FinishSession()
if (released != 0 && s_deviceRemoved) {
// Nothing on the bus can use what is left: keep the backing,
// but never the provider of a device that is gone.
MACLINUXGPU_LOG("removal: DMA backing still owned (%d) is kept; the provider closes", released);
MACLINUXGPU_EVENT("removal: DMA backing still owned (%d) is kept; the provider closes", released);
} else if (released != 0) {
s_dmaQuarantined = true;
note_quarantine(MLG_QUARANTINE_DMA_RETAINED, released);
@@ -1842,14 +1854,14 @@ MacLinuxGPU::FinishSession()
}
if (s_dmaQuarantined) {
quarantine_session(this);
MACLINUXGPU_LOG("session quarantined: retaining clients, provider and runtime owners");
MACLINUXGPU_EVENT("session quarantined: retaining clients, provider and runtime owners");
// Superclass Stop invalidates the provider. Pending Stop requests
// retain their objects until quiescence can actually be established;
// a stopping driver releases at once when cached state proves it.
if (s_stopping) (void)release_quarantine(this);
return;
}
MACLINUXGPU_LOG("session closed after upstream removal, interrupt drain and endpoint isolation");
MACLINUXGPU_EVENT("session closed after upstream removal, interrupt drain and endpoint isolation");
complete_session_close(this);
}
@@ -2091,12 +2103,49 @@ static void lx_finish_stop(MacLinuxGPUUserClient *client, IOService *provider)
}
}
// On the client's own queue, so no call of its own is in flight: its process
// exits first (async waits return, files close) while the driver runs.
// The client's process exits (async calls return, files close through
// upstream postclose) on a thread of its own, never on this one: a call of
// the process that does not return (a wait on a GPU that stopped) would
// otherwise hold the incoming-call thread, and with it every client's
// calls and the driver's own Stop. On an unplug this Stop began removal
// first (device_removed), which completes the GPU's fences, so the
// process's calls return. Its session membership ends after it, on the
// owner's queue.
struct LxStop {
MacLinuxGPUUserClient *client;
IOService *provider;
};
static void lx_stop_finished(void *arg)
{
auto *stop = static_cast<LxStop *>(arg);
MacLinuxGPUUserClient *client = stop->client;
IOService *provider = stop->provider;
IOFree(stop, sizeof(*stop));
s_lxCalls.leave();
client->ivars->ownerQueue->DispatchAsync(^{ lx_finish_stop(client, provider); });
}
static void lx_client_stop(MacLinuxGPUUserClient *client, IOService *provider)
{
if (s_lxCalls.enter()) {
if (struct rt_lx_client *lx = lx_take(client)) rt_lx_client_destroy(lx);
struct rt_lx_client *lx = lx_take(client);
auto *stop = lx ? static_cast<LxStop *>(IOMallocZero(sizeof(LxStop))) : nullptr;
if (lx) {
if (stop) {
stop->client = client;
stop->provider = provider;
}
// Its exit runs on a thread of its own, or (no thread: logged)
// at the session's close (rt_lx_retire_drain); never here.
if (!rt_lx_client_retire(lx, stop ? lx_stop_finished : nullptr, stop)) {
if (stop) return; // lx_stop_finished finishes the Stop
} else if (stop) {
IOFree(stop, sizeof(*stop));
}
if (!stop)
MACLINUXGPU_LOG("client %llu: no memory to follow its process's exit; "
"its Stop finishes now", client->ivars->clientID);
}
s_lxCalls.leave();
}
// Otherwise a session close owns the teardown (lx_teardown_all).
@@ -2132,11 +2181,11 @@ IMPL(MacLinuxGPUUserClient, Stop)
// IRQ delivery stays active while this client's queues are removed.
const int released = dext_compute_release_client(ivars->clientID);
if (released != 0 && s_deviceRemoved) {
MACLINUXGPU_LOG("client close after removal: cleanup returned %d; nothing can run", released);
MACLINUXGPU_EVENT("client close after removal: cleanup returned %d; nothing can run", released);
} else if (released != 0) {
s_dmaQuarantined = true;
note_quarantine(MLG_QUARANTINE_CLIENT_RELEASE, released);
MACLINUXGPU_LOG("client close: cleanup failed (%d); retaining uncertain shared-session backing", released);
MACLINUXGPU_EVENT("client close: cleanup failed (%d); retaining uncertain shared-session backing", released);
}
}
if (participant) {
@@ -2263,6 +2312,7 @@ static kern_return_t lx_transport_error(int r)
case -MLG_LX_ENOSPC: return kIOReturnNoSpace;
case -MLG_LX_ESRCH: return kIOReturnNotAttached;
case -MLG_LX_EAGAIN: return kIOReturnBusy;
case -MLG_LX_EDEADLK: return kIOReturnNotPermitted; // can sleep: async only
case -MLG_LX_EINVAL:
case -MLG_LX_E2BIG:
case -MLG_LX_EFAULT: return kIOReturnBadArgument;
@@ -2334,17 +2384,16 @@ struct LxAsync {
MacLinuxGPUUserClient *client;
OSAction *action;
};
static int lx_async_done(void *ctx, uint64_t token, int64_t result, const void *rbuf,
size_t reply_bytes)
static void lx_async_done(void *ctx, uint64_t token, int64_t result, const void *rbuf,
size_t reply_bytes)
{
auto *a = static_cast<LxAsync *>(ctx);
IOUserClientAsyncArgumentsArray data = {};
uint32_t count = 3;
const bool inline_reply = reply_bytes <= MLG_LX_ASYNC_INLINE_BYTES;
data[0] = token;
data[1] = (uint64_t)result;
data[2] = reply_bytes;
if (inline_reply) {
if (rbuf && reply_bytes && reply_bytes <= MLG_LX_ASYNC_INLINE_BYTES) {
memcpy(&data[3], rbuf, reply_bytes);
count += (uint32_t)((reply_bytes + 7) / 8);
}
@@ -2352,7 +2401,25 @@ static int lx_async_done(void *ctx, uint64_t token, int64_t result, const void *
a->action->release();
a->client->release();
IOFree(a, sizeof(*a));
return inline_reply;
}
// An async call's context: the client and its completion, retained until
// the worker completes it (it may finish after the client stopped).
static LxAsync *lx_async_begin(MacLinuxGPUUserClient *client, OSAction *action)
{
auto *ctx = static_cast<LxAsync *>(IOMallocZero(sizeof(LxAsync)));
if (!ctx) return nullptr;
ctx->client = client;
ctx->action = action;
client->retain();
action->retain();
return ctx;
}
static void lx_async_abandon(LxAsync *ctx)
{
ctx->action->release();
ctx->client->release();
IOFree(ctx, sizeof(*ctx));
}
// Interrupt-driven waits (selectors 86 and 87, session_state.h).
@@ -2402,18 +2469,28 @@ static kern_return_t lx_call(MacLinuxGPUUserClient *client, struct rt_lx_client
const uint32_t nin = a->scalarInputCount;
if (!in || !out) return kIOReturnBadArgument;
switch (selector) {
case MLG_SELECTOR_LX_OPEN:
if (nin != 2 || a->scalarOutputCount < 1 || in[0] > UINT32_MAX || in[1] > UINT32_MAX)
case MLG_SELECTOR_LX_RETIRED_OPEN:
case MLG_SELECTOR_LX_RETIRED_CLOSE:
case MLG_SELECTOR_LX_RETIRED_MMAP:
case MLG_SELECTOR_LX_RETIRED_MUNMAP:
MACLINUXGPU_LOG("client %llu: selector %llu (a synchronous open, close, mmap or munmap) "
"is retired: those can sleep and go through LX_CALL_ASYNC; the client "
"library is older than the driver and must be rebuilt",
client->ivars->clientID, selector);
return kIOReturnUnsupported;
case MLG_SELECTOR_LX_CALL_ASYNC: {
if (!a->completion || nin < 1 || nin > MLG_LX_OP_MMAP_ARGS || a->scalarOutputCount < 2)
return kIOReturnBadArgument;
out[0] = (uint64_t)(int64_t)rt_lx_open(lx, (uint32_t)in[0], (uint32_t)in[1]);
a->scalarOutputCount = 1;
return kIOReturnSuccess;
case MLG_SELECTOR_LX_CLOSE:
if (nin != 1 || a->scalarOutputCount < 1 || in[0] > INT32_MAX)
return kIOReturnBadArgument;
out[0] = (uint64_t)(int64_t)rt_lx_close(lx, (int)in[0]);
a->scalarOutputCount = 1;
LxAsync *ctx = lx_async_begin(client, a->completion);
if (!ctx) return kIOReturnNoMemory;
uint64_t token = 0;
const int r = rt_lx_op_async(lx, in, nin, lx_async_done, ctx, &token);
if (r) lx_async_abandon(ctx);
out[0] = (uint64_t)(int64_t)r; // not started: nothing will complete
out[1] = token;
a->scalarOutputCount = 2;
return kIOReturnSuccess;
}
case MLG_SELECTOR_LX_IOCTL:
case MLG_SELECTOR_LX_IOCTL_ASYNC: {
if (nin != 2 || a->scalarOutputCount < 2 || in[0] > INT32_MAX || in[1] > UINT32_MAX)
@@ -2422,20 +2499,12 @@ static kern_return_t lx_call(MacLinuxGPUUserClient *client, struct rt_lx_client
if (!lx_input(a, frame)) return kIOReturnBadArgument;
if (selector == MLG_SELECTOR_LX_IOCTL_ASYNC) {
if (!a->completion) return kIOReturnBadArgument;
auto *ctx = static_cast<LxAsync *>(IOMallocZero(sizeof(LxAsync)));
LxAsync *ctx = lx_async_begin(client, a->completion);
if (!ctx) return kIOReturnNoMemory;
ctx->client = client;
ctx->action = a->completion;
client->retain();
ctx->action->retain();
uint64_t token = 0;
const int r = rt_lx_ioctl_async(lx, (int)in[0], (uint32_t)in[1], frame.bytes,
frame.length, lx_async_done, ctx, &token);
if (r) {
ctx->action->release();
client->release();
IOFree(ctx, sizeof(*ctx));
}
if (r) lx_async_abandon(ctx);
out[0] = (uint64_t)(int64_t)r; // not started: nothing will complete
out[1] = token;
a->scalarOutputCount = 2;
@@ -2449,8 +2518,10 @@ static kern_return_t lx_call(MacLinuxGPUUserClient *client, struct rt_lx_client
rt_lx_timing_add(cmd, RT_LX_HOP_ARGS, args_ns - admitted_ns);
size_t bytes = 0;
int64_t result = 0;
const int r = rt_lx_ioctl(lx, (int)in[0], cmd, frame.bytes, frame.length,
reply.bytes, reply.capacity, &bytes, &result);
// This thread is every client's: only requests that cannot sleep
// run on it (rt_lx_ioctl_nosleep refuses the rest, logged).
const int r = rt_lx_ioctl_nosleep(lx, (int)in[0], cmd, frame.bytes, frame.length,
reply.bytes, reply.capacity, &bytes, &result);
if (r) return lx_transport_error(r);
const uint64_t ran_ns = rt_lx_time_ns();
out[0] = (uint64_t)result;
@@ -2477,30 +2548,11 @@ static kern_return_t lx_call(MacLinuxGPUUserClient *client, struct rt_lx_client
a->scalarOutputCount = 2;
return lx_output_done(a, reply, bytes);
}
case MLG_SELECTOR_LX_MMAP: {
if (nin != 5 || a->scalarOutputCount < 4 || in[0] > INT32_MAX || in[3] > UINT32_MAX ||
in[4] > UINT32_MAX)
return kIOReturnBadArgument;
struct rt_lx_map_info info = {};
const int r = rt_lx_mmap(lx, (int)in[0], in[1], in[2], (uint32_t)in[3], (uint32_t)in[4],
&info);
out[0] = (uint64_t)(int64_t)r;
out[1] = r ? 0 : info.type;
out[2] = r ? 0 : info.length;
out[3] = r ? 0 : info.cache;
a->scalarOutputCount = 4;
return kIOReturnSuccess;
}
case MLG_SELECTOR_LX_MMAP_COMMIT:
if (nin != 2 || a->scalarOutputCount < 1) return kIOReturnBadArgument;
out[0] = (uint64_t)(int64_t)rt_lx_mmap_commit(lx, in[0], in[1]);
a->scalarOutputCount = 1;
return kIOReturnSuccess;
case MLG_SELECTOR_LX_MUNMAP:
if (nin != 1 || a->scalarOutputCount < 1) return kIOReturnBadArgument;
out[0] = (uint64_t)(int64_t)rt_lx_munmap(lx, in[0]);
a->scalarOutputCount = 1;
return kIOReturnSuccess;
default:
return kIOReturnUnsupported;
}
@@ -3176,7 +3228,7 @@ MacLinuxGPUUserClient::ExternalMethod(uint64_t selector,
// HostWindow comes with InitDevice: the probe maps the GART at the
// host window the client placed (libmlg_drm/src/mlg_init.c).
if (ivars->stopping) return kIOReturnNotAttached;
if (selector >= MLG_SELECTOR_LX_OPEN && selector <= MLG_SELECTOR_LX_SCANOUT)
if (selector >= MLG_SELECTOR_LX_FIRST && selector <= MLG_SELECTOR_LX_LAST)
return lx_external_method(this, selector, arguments);
if (selector != kMacAMDGPUMethodPing && selector != kMacAMDGPUMethodRuntimeBuild &&
selector != kMacAMDGPUMethodQueryInfo && selector != kMacAMDGPUMethodInitDevice &&
@@ -3366,13 +3418,13 @@ MacLinuxGPUUserClient::ExternalMethod(uint64_t selector,
if (!s_rtDevice) s_rtDevice = rt_device_alloc();
if (!s_rtDevice) {
MACLINUXGPU_LOG("initialization: runtime device allocation failed");
MACLINUXGPU_EVENT("initialization: runtime device allocation failed");
close_session(ivars->ownerDriver);
return kIOReturnNotReady;
}
ret = prepare_interrupts(ivars->ownerDriver);
if (ret != kIOReturnSuccess) {
MACLINUXGPU_LOG("initialization: interrupt preparation failed (%#x)", ret);
MACLINUXGPU_EVENT("initialization: interrupt preparation failed (%#x)", ret);
close_session(ivars->ownerDriver);
return ret;
}
@@ -3383,7 +3435,7 @@ MacLinuxGPUUserClient::ExternalMethod(uint64_t selector,
if (probeHeld != 0) {
s_dmaQuarantined = true;
note_quarantine(MLG_QUARANTINE_PROBE_HOLD, probeHeld);
MACLINUXGPU_LOG("initialization: cannot reserve probe DMA backing (%d)", probeHeld);
MACLINUXGPU_EVENT("initialization: cannot reserve probe DMA backing (%d)", probeHeld);
close_session(ivars->ownerDriver);
return kIOReturnNotReady;
}
@@ -3395,16 +3447,16 @@ MacLinuxGPUUserClient::ExternalMethod(uint64_t selector,
s_probeResult = rt_pci_probe_result(rt_device_get_pdev(s_rtDevice));
}
if (s_probeResult != 0) {
MACLINUXGPU_LOG("upstream PCI probe failed: %d", s_probeResult);
MACLINUXGPU_EVENT("upstream PCI probe failed: %d", s_probeResult);
if (rt_pci_probe_cleanup_retained(rt_device_get_pdev(s_rtDevice))) {
s_dmaQuarantined = true;
note_quarantine(MLG_QUARANTINE_PROBE_RETAINED, s_probeResult);
MACLINUXGPU_LOG("upstream failed-probe ownership retained; preserving modules, device and DMA backing");
MACLINUXGPU_EVENT("upstream failed-probe ownership retained; preserving modules, device and DMA backing");
}
close_session(ivars->ownerDriver);
return kIOReturnError;
}
MACLINUXGPU_LOG("upstream AMDGPU PCI probe completed");
MACLINUXGPU_EVENT("upstream AMDGPU PCI probe completed");
identity_after_probe(ivars->ownerDriver,
static_cast<struct pci_dev *>(rt_device_get_pdev(s_rtDevice)));
int computeResult = dext_compute_start(
@@ -3413,7 +3465,7 @@ MacLinuxGPUUserClient::ExternalMethod(uint64_t selector,
const char *failedStep = NULL;
int failedError = 0;
dext_compute_start_failure(&failedStep, &failedError);
MACLINUXGPU_LOG("compute initialization failed: %d (%s: %d)", computeResult,
MACLINUXGPU_EVENT("compute initialization failed: %d (%s: %d)", computeResult,
failedStep ? failedStep : "unknown", failedError);
close_session(ivars->ownerDriver);
return kIOReturnNotReady;
@@ -3422,7 +3474,7 @@ MacLinuxGPUUserClient::ExternalMethod(uint64_t selector,
if (probeCommitted != 0) {
s_dmaQuarantined = true;
note_quarantine(MLG_QUARANTINE_PROBE_COMMIT, probeCommitted);
MACLINUXGPU_LOG("probe DMA cleanup failed (%d); session quarantined", probeCommitted);
MACLINUXGPU_EVENT("probe DMA cleanup failed (%d); session quarantined", probeCommitted);
close_session(ivars->ownerDriver);
return kIOReturnError;
}
+7 -4
View File
@@ -149,8 +149,11 @@ public:
#import <PCIDriverKit/IOPCIDevice.h>
#include "retained_log.h"
static void dext_dma_log_sink(const char *text) { IOLog("%s", text); }
#define DEXT_DMA_LOG(...) maclinuxgpu::RetainedLog(dext_dma_log_sink, __VA_ARGS__)
// Routine DMA lines stay in the retained ring; only events reach the
// unified log (retained_log.h).
static void dext_dma_event_sink(const char *text) { IOLog("%s", text); }
#define DEXT_DMA_LOG(...) maclinuxgpu::RetainedLog(nullptr, __VA_ARGS__)
#define DEXT_DMA_EVENT(...) maclinuxgpu::RetainedEvent(dext_dma_event_sink, __VA_ARGS__)
/* 16 KB coherent alignment (firmware/ucode load
* needs it, matching DART_COHERENT_ALIGN in dart.c). */
@@ -269,7 +272,7 @@ static int dext_dma_complete_now(IODMACommand *dma, IOMemoryDescriptor *buf)
dext_dma_acquire();
g_dma_cleanup_failed = true;
dext_dma_release();
DEXT_DMA_LOG("DMA completion failed (%#x); backing retained", completed);
DEXT_DMA_EVENT("DMA completion failed (%#x); backing retained", completed);
return -1;
}
/* A quarantine request may arrive while CompleteDMA is in flight. The
@@ -639,7 +642,7 @@ static void dext_dma_refused(const char *call, kern_return_t result, uint64_t by
const uint64_t n = repeats;
dext_dma_release();
if (n & 255) return;
DEXT_DMA_LOG("DMA: mapping %llu bytes for the device failed: %s returned %#x (%llu bytes in %u mappings already mapped%s)",
DEXT_DMA_EVENT("DMA: mapping %llu bytes for the device failed: %s returned %#x (%llu bytes in %u mappings already mapped%s)",
(unsigned long long)bytes, call, result, (unsigned long long)mapped, live,
n ? "; the same refusal repeats" : "");
}
+30 -9
View File
@@ -12,20 +12,14 @@ namespace maclinuxgpu {
* ring and platform sink. The sink treats the result as data, so percent signs
* in messages cannot become os_log format directives. No allocation or driver
* operation is involved, including while a session is quarantined. */
static inline void RetainedLog(void (*sink)(const char *), const char *format, ...)
__attribute__((format(printf, 2, 3)));
static inline void RetainedLog(void (*sink)(const char *), const char *format, ...)
static inline void RetainedLogV(void (*sink)(const char *), const char *prefix,
const char *format, va_list arguments)
{
char record[LINUXU_KLOG_MESSAGE_CAPACITY];
static const char prefix[] = "mac.linuxgpu: ";
constexpr size_t prefixLength = sizeof(prefix) - 1;
const size_t prefixLength = strlen(prefix);
memcpy(record, prefix, prefixLength);
va_list arguments;
va_start(arguments, format);
const int formatted = vsnprintf(record + prefixLength,
sizeof(record) - prefixLength, format, arguments);
va_end(arguments);
size_t length;
if (formatted < 0) {
static const char error[] = "[format error]\n";
@@ -45,6 +39,33 @@ static inline void RetainedLog(void (*sink)(const char *), const char *format, .
if (sink) sink(record);
}
/* A routine line: the retained ring (scripts/read-driver-log.py), and the
* platform sink when one is given. */
static inline void RetainedLog(void (*sink)(const char *), const char *format, ...)
__attribute__((format(printf, 2, 3)));
static inline void RetainedLog(void (*sink)(const char *), const char *format, ...)
{
va_list arguments;
va_start(arguments, format);
RetainedLogV(sink, "mac.linuxgpu: ", format, arguments);
va_end(arguments);
}
/* An event that must outlive the driver (a hang, a reset, a removal, a
* quarantine): the ring and the platform's unified log, prefixed so
* log show --predicate 'eventMessage BEGINSWITH "mac.linuxgpu: EVENT"'
* finds every one after a hang or a reboot. Rare by construction: never
* per request. */
static inline void RetainedEvent(void (*sink)(const char *), const char *format, ...)
__attribute__((format(printf, 2, 3)));
static inline void RetainedEvent(void (*sink)(const char *), const char *format, ...)
{
va_list arguments;
va_start(arguments, format);
RetainedLogV(sink, "mac.linuxgpu: EVENT ", format, arguments);
va_end(arguments);
}
} // namespace maclinuxgpu
#endif
+7 -9
View File
@@ -17,6 +17,9 @@
#include "mlg_uapi.h"
#include <rt/lx_abi.h>
/* The transport revision this library speaks, findable in the file. */
__attribute__((used)) static const char abi_tag[] = MLG_LX_ABI_TAG;
/* What each descriptor is: indexed by descriptor, MLG_LX_DEV_* or 0. */
static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
static struct mlg_transport transport;
@@ -372,15 +375,10 @@ int mlg_ioctl(int fd, unsigned long request, void *arg)
r = (int)len;
goto out;
}
/* A wait goes to a worker of the driver's process, unless it only
* polls (a zero deadline). */
async = mlg_lx_cmd_blocks(dev, cmd);
if (async && timeout_va) {
int64_t deadline;
memcpy(&deadline, (const void *)(uintptr_t)timeout_va, sizeof(deadline));
async = deadline != 0;
}
/* Anything that can sleep goes to a worker of the driver's process;
* the driver runs only the rest on the call itself (and refuses a
* sleeping one there). */
async = mlg_lx_cmd_sleeps(dev, cmd, frame, (size_t)len);
r = t.ioctl(t.ctx, fd, cmd, frame, (size_t)len, reply, mlg_lx_reply_bytes(out_bytes),
&reply_bytes, &result, async);
if (!r && mlg_lx_apply_reply(frame, (size_t)len, reply, reply_bytes, NULL))
+165 -68
View File
@@ -115,35 +115,6 @@ static int scalar_call(void *ctx, uint32_t selector, const uint64_t *in, uint32_
return scalar(selector, in, nin, out, nout);
}
static int t_open(void *ctx, uint32_t dev, uint32_t flags)
{
uint64_t in[2] = { dev, flags }, out[1] = { 0 };
int r;
(void)ctx;
r = scalar(MLG_SELECTOR_LX_OPEN, in, 2, out, 1);
if (r == -MLG_LX_ENODEV) {
/* The driver is attached but the GPU is not initialized yet:
* initialize it, as a session client does (host window, then
* InitDevice), then retry; the open fails with the reason the
* initialization did. */
r = mlg_init_device(scalar_call, NULL);
if (!r)
r = scalar(MLG_SELECTOR_LX_OPEN, in, 2, out, 1);
}
return r ? r : (int)(int64_t)out[0];
}
static int t_close(void *ctx, int fd)
{
uint64_t in[1] = { (uint64_t)(int64_t)fd }, out[1] = { 0 };
int r;
(void)ctx;
r = scalar(MLG_SELECTOR_LX_CLOSE, in, 1, out, 1);
return r ? r : (int)(int64_t)out[0];
}
/* ---- async completions ---- */
struct waiter {
@@ -223,6 +194,65 @@ static int wait_completion(io_connect_t c, IONotificationPortRef port, struct wa
return 0;
}
/* The driver admits MLG_LX_MAX_ASYNC async calls per client; a call holds
* its place until its completion arrives with the result inline, or until
* LX_RESULT fetches it. Threads beyond that wait here, on their own
* thread, for one to finish. */
static pthread_mutex_t slots_lock = PTHREAD_MUTEX_INITIALIZER;
static pthread_cond_t slots_free = PTHREAD_COND_INITIALIZER;
static unsigned int slots_used;
static void slot_take(void)
{
pthread_mutex_lock(&slots_lock);
while (slots_used >= MLG_LX_MAX_ASYNC)
pthread_cond_wait(&slots_free, &slots_lock);
slots_used++;
pthread_mutex_unlock(&slots_lock);
}
static void slot_put(void)
{
pthread_mutex_lock(&slots_lock);
slots_used--;
pthread_cond_signal(&slots_free);
pthread_mutex_unlock(&slots_lock);
}
/* One async call (@selector with @in and an optional request frame) up to
* its completion, in @w. 0, or -errno when it did not start or the driver
* went away; *token is its token. The caller holds a slot. */
static int call_async(io_connect_t c, uint32_t selector, const uint64_t *in, uint32_t nin,
const void *frame, size_t frame_bytes, struct waiter *w, uint64_t *token)
{
IONotificationPortRef port = thread_port();
io_user_reference_t ref[kIOAsyncCalloutCount] = { 0 };
uint64_t out[2] = { 0, 0 };
uint32_t n = 2;
int r;
if (!port)
return -MLG_LX_ENOMEM;
ref[kIOAsyncCalloutFuncIndex] = (io_user_reference_t)(uintptr_t)completed;
ref[kIOAsyncCalloutRefconIndex] = (io_user_reference_t)(uintptr_t)w;
r = from_ioreturn(IOConnectCallAsyncMethod(c, selector, IONotificationPortGetMachPort(port),
ref, kIOAsyncCalloutCount, in, nin, frame,
frame_bytes, out, &n, NULL, NULL));
if (!r && (int64_t)out[0] < 0)
r = (int)(int64_t)out[0]; /* not started */
if (r)
return r;
*token = out[1];
r = wait_completion(c, port, w);
if (r)
return r;
if (w->status != kIOReturnSuccess)
return w->status == kIOReturnAborted ? -MLG_LX_EINTR : from_ioreturn(w->status);
if (w->nargs < 3 || w->args[0] != *token)
return -5; /* EIO */
return 0;
}
static int t_ioctl(void *ctx, int fd, uint32_t cmd, const void *frame, size_t frame_bytes,
void *reply, size_t reply_cap, size_t *reply_bytes, int64_t *result, int async)
{
@@ -236,6 +266,7 @@ static int t_ioctl(void *ctx, int fd, uint32_t cmd, const void *frame, size_t fr
if (r)
return r;
if (!async) {
/* Only requests that cannot sleep (mlg_lx_cmd_sleeps). */
r = from_ioreturn(IOConnectCallMethod(c, MLG_SELECTOR_LX_IOCTL, in, 2, frame, frame_bytes,
out, &n, reply, &size));
if (r)
@@ -245,42 +276,36 @@ static int t_ioctl(void *ctx, int fd, uint32_t cmd, const void *frame, size_t fr
return *reply_bytes <= reply_cap ? 0 : -MLG_LX_EINVAL;
}
IONotificationPortRef port = thread_port();
struct waiter w = { 0 };
io_user_reference_t ref[kIOAsyncCalloutCount] = { 0 };
uint64_t token = 0;
if (!port)
return -MLG_LX_ENOMEM;
ref[kIOAsyncCalloutFuncIndex] = (io_user_reference_t)(uintptr_t)completed;
ref[kIOAsyncCalloutRefconIndex] = (io_user_reference_t)(uintptr_t)&w;
r = from_ioreturn(IOConnectCallAsyncMethod(c, MLG_SELECTOR_LX_IOCTL_ASYNC,
IONotificationPortGetMachPort(port), ref,
kIOAsyncCalloutCount, in, 2, frame, frame_bytes,
out, &n, NULL, NULL));
if (!r && (int64_t)out[0] < 0)
r = (int)(int64_t)out[0]; /* not started */
if (r)
slot_take();
r = call_async(c, MLG_SELECTOR_LX_IOCTL_ASYNC, in, 2, frame, frame_bytes, &w, &token);
if (!r && w.args[2] > reply_cap)
r = -5;
if (r) {
slot_put();
return r;
r = wait_completion(c, port, &w);
if (r)
return r;
if (w.status != kIOReturnSuccess)
return w.status == kIOReturnAborted ? -MLG_LX_EINTR : from_ioreturn(w.status);
if (w.nargs < 3 || w.args[0] != out[1] || w.args[2] > reply_cap)
return -5;
}
*result = (int64_t)w.args[1];
*reply_bytes = (size_t)w.args[2];
if (*reply_bytes <= MLG_LX_ASYNC_INLINE_BYTES && w.nargs >= 3 + (*reply_bytes + 7) / 8) {
if (*reply_bytes <= MLG_LX_ASYNC_INLINE_BYTES) {
if (w.nargs < 3 + (*reply_bytes + 7) / 8) {
slot_put();
return -5;
}
memcpy(reply, &w.args[3], *reply_bytes);
slot_put();
return 0;
}
/* Too long for the completion: fetch it. */
uint64_t token[1] = { out[1] };
/* Too long for the completion: fetch it, which frees its place. */
uint64_t fetch[1] = { token };
n = 2;
size = reply_cap;
r = from_ioreturn(IOConnectCallMethod(c, MLG_SELECTOR_LX_RESULT, token, 1, NULL, 0, out, &n,
r = from_ioreturn(IOConnectCallMethod(c, MLG_SELECTOR_LX_RESULT, fetch, 1, NULL, 0, out, &n,
reply, &size));
slot_put();
if (r)
return r;
*result = (int64_t)out[0];
@@ -288,12 +313,88 @@ static int t_ioctl(void *ctx, int fd, uint32_t cmd, const void *frame, size_t fr
return 0;
}
/* LX_CALL_ASYNC: an open, close, mmap or munmap runs on a worker of the
* driver's process (each can sleep). *result is its result; an MMAP's
* reply words land in @words. */
static int call_op(io_connect_t c, const uint64_t *in, uint32_t nin, int64_t *result,
uint64_t *words)
{
struct waiter w = { 0 };
uint64_t token = 0;
int r;
slot_take();
r = call_async(c, MLG_SELECTOR_LX_CALL_ASYNC, in, nin, NULL, 0, &w, &token);
slot_put(); /* an operation's reply always comes inline */
if (r)
return r;
*result = (int64_t)w.args[1];
if (words) {
if (*result == 0 && (w.args[2] != MLG_LX_OP_MMAP_WORDS * 8 ||
w.nargs < 3 + MLG_LX_OP_MMAP_WORDS))
return -5;
memcpy(words, &w.args[3], MLG_LX_OP_MMAP_WORDS * 8);
}
return 0;
}
static int op(const uint64_t *in, uint32_t nin, int64_t *result, uint64_t *words)
{
io_connect_t c;
int r = conn(&c);
return r ? r : call_op(c, in, nin, result, words);
}
static int t_open(void *ctx, uint32_t dev, uint32_t flags)
{
uint64_t in[MLG_LX_OP_OPEN_ARGS] = { MLG_LX_OP_OPEN, dev, flags };
int64_t result = 0;
int r;
(void)ctx;
r = op(in, MLG_LX_OP_OPEN_ARGS, &result, NULL);
if (r == -MLG_LX_ENODEV) {
/* The driver is attached but the GPU is not initialized yet:
* initialize it, as a session client does (host window, then
* InitDevice), then retry; the open fails with the reason the
* initialization did. */
r = mlg_init_device(scalar_call, NULL);
if (!r)
r = op(in, MLG_LX_OP_OPEN_ARGS, &result, NULL);
}
return r ? r : (int)result;
}
static int t_close(void *ctx, int fd)
{
uint64_t in[MLG_LX_OP_CLOSE_ARGS] = { MLG_LX_OP_CLOSE, (uint64_t)(int64_t)fd };
int64_t result = 0;
int r;
(void)ctx;
r = op(in, MLG_LX_OP_CLOSE_ARGS, &result, NULL);
return r ? r : (int)result;
}
/* ---- mmap ---- */
static int unmap_type(io_connect_t c, uint64_t type)
{
uint64_t in[MLG_LX_OP_MUNMAP_ARGS] = { MLG_LX_OP_MUNMAP, type };
int64_t result = 0;
int r = call_op(c, in, MLG_LX_OP_MUNMAP_ARGS, &result, NULL);
return r ? r : (int)result;
}
static int t_mmap(void *ctx, int fd, uint64_t offset, uint64_t length, uint32_t prot,
uint32_t flags, void **addr, uint64_t *handle)
{
uint64_t in[5] = { (uint64_t)(int64_t)fd, offset, length, prot, flags }, out[4] = { 0 };
uint64_t in[MLG_LX_OP_MMAP_ARGS] = { MLG_LX_OP_MMAP, (uint64_t)(int64_t)fd, offset, length,
prot, flags };
uint64_t words[MLG_LX_OP_MMAP_WORDS] = { 0 };
int64_t result = 0;
mach_vm_address_t at = 0;
mach_vm_size_t size = 0;
IOOptionBits options = kIOMapAnywhere;
@@ -303,42 +404,39 @@ static int t_mmap(void *ctx, int fd, uint64_t offset, uint64_t length, uint32_t
(void)ctx;
if (r)
return r;
r = scalar(MLG_SELECTOR_LX_MMAP, in, 5, out, 4);
r = call_op(c, in, MLG_LX_OP_MMAP_ARGS, &result, words);
if (!r)
r = (int)(int64_t)out[0];
r = (int)result;
if (r)
return r;
if (out[3] == 1)
if (words[2] == 1)
options |= kIOMapWriteCombineCache;
else if (out[3] == 2)
else if (words[2] == 2)
options |= kIOMapInhibitCache;
else
options |= kIOMapDefaultCache;
r = from_ioreturn(IOConnectMapMemory64(c, (uint32_t)out[1], mach_task_self(), &at, &size,
r = from_ioreturn(IOConnectMapMemory64(c, (uint32_t)words[0], mach_task_self(), &at, &size,
options));
if (r || size < length) {
uint64_t type[1] = { out[1] }, ignored[1];
if (!r)
IOConnectUnmapMemory64(c, (uint32_t)out[1], mach_task_self(), at);
(void)scalar(MLG_SELECTOR_LX_MUNMAP, type, 1, ignored, 1);
IOConnectUnmapMemory64(c, (uint32_t)words[0], mach_task_self(), at);
(void)unmap_type(c, words[0]);
return r ? r : -MLG_LX_EINVAL;
}
/* Place it at the same address in the driver's process too (best
* effort: the mapping works either way). */
{
uint64_t commit[2] = { out[1], at }, ignored[1];
uint64_t commit[2] = { words[0], at }, ignored[1];
(void)scalar(MLG_SELECTOR_LX_MMAP_COMMIT, commit, 2, ignored, 1);
}
*addr = (void *)(uintptr_t)at;
*handle = out[1];
*handle = words[0];
return 0;
}
static int t_munmap(void *ctx, uint64_t handle, void *addr, uint64_t length)
{
uint64_t type[1] = { handle }, out[1] = { 0 };
io_connect_t c;
int r = conn(&c);
@@ -350,8 +448,7 @@ static int t_munmap(void *ctx, uint64_t handle, void *addr, uint64_t length)
(mach_vm_address_t)(uintptr_t)addr));
if (r)
return r;
r = scalar(MLG_SELECTOR_LX_MUNMAP, type, 1, out, 1);
return r ? r : (int)(int64_t)out[0];
return unmap_type(c, handle);
}
/* ---- identity: the IOPCIDevice the driver matched ---- */
+3 -1
View File
@@ -237,7 +237,8 @@ int main(void)
rec.out_fill = 0x5a;
CHECK(mlg_ioctl(fd, DRM_IOCTL_AMDGPU_INFO, &info) == 0);
n = segments(seg, 64);
CHECK(rec.cmd == DRM_IOCTL_AMDGPU_INFO && !rec.async);
/* INFO can sleep (SMU messages): a worker's. */
CHECK(rec.cmd == DRM_IOCTL_AMDGPU_INFO && rec.async);
CHECK(covered(seg, n, &info, sizeof(info), MLG_LX_SEG_IN));
CHECK(covered(seg, n, result, sizeof(result), MLG_LX_SEG_OUT));
CHECK(result[0] == 0x5a && result[39] == 0x5a);
@@ -263,6 +264,7 @@ int main(void)
.chunks = (uint64_t)(uintptr_t)ptrs } };
rec.out_fill = 0;
CHECK(mlg_ioctl(fd, DRM_IOCTL_AMDGPU_CS, &cs) == 0);
CHECK(rec.async); /* a submission can wait for its context's earlier jobs */
n = segments(seg, 64);
CHECK(covered(seg, n, &cs, sizeof(cs), MLG_LX_SEG_INOUT));
CHECK(covered(seg, n, ptrs, 3 * sizeof(*ptrs), MLG_LX_SEG_IN));
+8 -2
View File
@@ -170,11 +170,12 @@ int main(void)
CHECK(mlg_ioctl(fd, DRM_IOCTL_AMDGPU_WAIT_CS, &wcs) == 0 && wcs.out.status == 0);
CHECK(lx_loopback_async_calls() == before + 1);
CHECK(cpu[0] == 0xfeed0000u && cpu[16] == 0xfeed0001u);
/* ... and a poll (no worker). */
/* ... and a poll, a worker's too: it takes the context manager's
* lock, which a context's release holds while it flushes. */
wcs = (union drm_amdgpu_wait_cs){ .in = { .handle = seq, .ip_type = AMDGPU_HW_IP_COMPUTE,
.ctx_id = ctx_id, .timeout = 0 } };
CHECK(mlg_ioctl(fd, DRM_IOCTL_AMDGPU_WAIT_CS, &wcs) == 0 && wcs.out.status == 0);
CHECK(lx_loopback_async_calls() == before + 1);
CHECK(lx_loopback_async_calls() == before + 2);
/* AMDGPU_WAIT_FENCES: the fence array behind the block. */
struct drm_amdgpu_fence fences[1] = { { .ctx_id = ctx_id, .ip_type = AMDGPU_HW_IP_COMPUTE,
@@ -188,6 +189,11 @@ int main(void)
struct drm_syncobj_wait sw = { .handles = (uint64_t)(uintptr_t)handles, .count_handles = 1,
.timeout_nsec = deadline_ns(2000), .flags = DRM_SYNCOBJ_WAIT_FLAGS_WAIT_ALL };
CHECK(mlg_ioctl(fd, DRM_IOCTL_SYNCOBJ_WAIT, &sw) == 0);
/* A syncobj poll never sleeps: it runs on the call itself. */
before = lx_loopback_async_calls();
sw.timeout_nsec = 0;
CHECK(mlg_ioctl(fd, DRM_IOCTL_SYNCOBJ_WAIT, &sw) == 0);
CHECK(lx_loopback_async_calls() == before);
uint64_t points[1] = { 99 };
struct drm_syncobj_timeline_array query = { .handles = (uint64_t)(uintptr_t)handles,
.points = (uint64_t)(uintptr_t)points, .count_handles = 1 };
+9 -10
View File
@@ -31,15 +31,14 @@ static inline void devcd_free(struct devcd_info *info)
(void)info;
}
static inline void dev_coredumpm(struct device *dev, struct module *owner,
void *data, size_t datalen, gfp_t gfp,
ssize_t (*read)(char *buffer, loff_t offset, size_t count,
void *data, size_t datalen),
void (*free)(void *data))
{
(void)dev; (void)owner; (void)datalen; (void)gfp; (void)read;
/* No exporter retains this payload; honor the transferred ownership. */
if (free) free(data);
}
/* No exporter retains the payload: its head (the device, the ring and
* process that hung) goes to the kernel log at error level, which reaches
* the unified log as events (linuxu/src/shims/dev_coredump.c); then the
* transferred ownership is honored. */
void dev_coredumpm(struct device *dev, struct module *owner,
void *data, size_t datalen, gfp_t gfp,
ssize_t (*read)(char *buffer, loff_t offset, size_t count,
void *data, size_t datalen),
void (*free)(void *data));
#endif /* __LINUX_DEVCOREDUMP_H */
+70 -20
View File
@@ -63,46 +63,86 @@ extern "C" {
* >= 0 or a negative errno, sign-extended). Any other IOReturn is a
* transport failure: the call did not run.
*
* LX_OPEN in: [0] MLG_LX_DEV_*, [1] Linux open flags (O_RDWR,
* O_CLOEXEC, O_NONBLOCK; others are refused)
* out: [0] the descriptor or -errno
* LX_CLOSE in: [0] fd out: [0] 0 or -errno
* No request that can sleep (wait for the GPU, a fence, a lock that is
* held across one, memory) runs on the driver's incoming-call thread: one
* that blocked there would block every client's calls and the driver's own
* Stop. Such requests are asynchronous and run on a worker of the
* client's process; only those mlg_lx_cmd_sleeps() calls non-sleeping
* take the synchronous LX_IOCTL.
*
* LX_CALL_ASYNC called with IOConnectCallAsyncScalarMethod.
* in: [0] MLG_LX_OP_*, then the operation's arguments:
* OPEN [1] MLG_LX_DEV_*, [2] Linux open flags (O_RDWR,
* O_CLOEXEC, O_NONBLOCK; others are refused)
* CLOSE [1] fd
* MMAP [1] fd, [2] offset (bytes, page aligned),
* [3] length, [4] PROT_* (Linux values),
* [5] MAP_SHARED (only)
* MUNMAP [1] memory type (after IOConnectUnmapMemory64)
* out: [0] 0 or -errno (not started), [1] its token
* Completion: async data [0] token, [1] the result (OPEN: the
* descriptor; others 0; or -errno), [2] reply bytes, [3...]
* the reply: for MMAP MLG_LX_OP_MMAP_WORDS words, the
* memory type for IOConnectMapMemory64, the mapped length
* and its RT_LX_CACHE_* mode; none for the others.
* LX_IOCTL in: [0] fd, [1] cmd; struct in: the request frame
* (structure input, or an input descriptor above 4096
* bytes)
* out: [0] the ioctl's result, [1] reply bytes; struct out:
* the reply frame (the client sizes its buffer to
* mlg_lx_reply_bytes() of its request)
* Only for requests mlg_lx_cmd_sleeps() says do not sleep;
* any other is refused (kIOReturnNotPermitted, logged).
* LX_IOCTL_ASYNC as LX_IOCTL, called with IOConnectCallAsync*: the call
* runs on a worker of the client's process and returns at
* once with out [0] 0 or -errno (not started), [1] its
* token. Completion: async data [0] token, [1] the ioctl's
* result, [2] reply bytes, [3...] the reply frame when it
* fits MLG_LX_ASYNC_INLINE_BYTES, else LX_RESULT fetches
* it. Used for calls that block (waits).
* it. Every request that can sleep goes this way.
* LX_RESULT in: [0] token; struct out: the reply frame
* out: [0] the ioctl's result, [1] reply bytes
* LX_MMAP in: [0] fd, [1] offset (bytes, page aligned), [2] length,
* [3] PROT_* (Linux values), [4] MAP_SHARED (only)
* out: [0] 0 or -errno, [1] memory type for
* IOConnectMapMemory64, [2] mapped length
* LX_MMAP_COMMIT in: [0] memory type, [1] the client address the type
* was mapped at out: [0] 0 or -errno
* (places the mapping in the Linux process's address
* space at that address; optional)
* LX_MUNMAP in: [0] memory type out: [0] 0 or -errno
* (after IOConnectUnmapMemory64)
* LX_SCANOUT struct in: struct mlg_lx_scanout; out: [0] 0 or -errno;
* struct out: struct mlg_lx_scanout_state (below) */
#define MLG_SELECTOR_LX_OPEN 96u
#define MLG_SELECTOR_LX_CLOSE 97u
* struct out: struct mlg_lx_scanout_state (below)
*
* Selectors 96 (LX_OPEN), 97 (LX_CLOSE), 101 (LX_MMAP) and 103 (LX_MUNMAP)
* were synchronous and can sleep; they are retired (kIOReturnUnsupported)
* in favour of LX_CALL_ASYNC and their numbers are not reused. */
/* The transport's revision: 2 since every request that can sleep is
* asynchronous (LX_CALL_ASYNC, the synchronous LX_IOCTL refusing them).
* The client library carries it as its dylib compatibility version and as
* the text MLG_LX_ABI_TAG, which a launcher can look for in the file. */
#define MLG_LX_ABI 2
#define MLG_LX_ABI_TAG "libmlg_drm Linux-file ABI 2"
#define MLG_SELECTOR_LX_FIRST 96u /* the range's first number */
#define MLG_SELECTOR_LX_RETIRED_OPEN 96u
#define MLG_SELECTOR_LX_RETIRED_CLOSE 97u
#define MLG_SELECTOR_LX_IOCTL 98u
#define MLG_SELECTOR_LX_IOCTL_ASYNC 99u
#define MLG_SELECTOR_LX_RESULT 100u
#define MLG_SELECTOR_LX_MMAP 101u
#define MLG_SELECTOR_LX_RETIRED_MMAP 101u
#define MLG_SELECTOR_LX_MMAP_COMMIT 102u
#define MLG_SELECTOR_LX_MUNMAP 103u
#define MLG_SELECTOR_LX_RETIRED_MUNMAP 103u
#define MLG_SELECTOR_LX_SCANOUT 104u
#define MLG_SELECTOR_LX_CALL_ASYNC 105u
#define MLG_SELECTOR_LX_LAST 105u
/* LX_CALL_ASYNC operations, and the scalar inputs each takes (the
* operation number included). */
#define MLG_LX_OP_OPEN 1u
#define MLG_LX_OP_CLOSE 2u
#define MLG_LX_OP_MMAP 3u
#define MLG_LX_OP_MUNMAP 4u
#define MLG_LX_OP_OPEN_ARGS 3u
#define MLG_LX_OP_CLOSE_ARGS 2u
#define MLG_LX_OP_MMAP_ARGS 6u
#define MLG_LX_OP_MUNMAP_ARGS 2u
#define MLG_LX_OP_MMAP_WORDS 3u /* type, length, cache */
/* LX_OPEN devices. */
#define MLG_LX_DEV_RENDER 1u /* the GPU's DRM render node */
@@ -230,8 +270,10 @@ _Static_assert(sizeof(struct mlg_lx_scanout_state) == 120, "mlg_lx_scanout_state
#define MLG_LX_INLINE_STRUCT_BYTES 4096u
#define MLG_LX_ASYNC_WORDS 16u
#define MLG_LX_ASYNC_INLINE_BYTES ((MLG_LX_ASYNC_WORDS - 3u) * 8u)
/* Async calls in flight per client; LX_IOCTL_ASYNC beyond it is -EAGAIN.
* Completed results not yet fetched with LX_RESULT count too. */
/* Async calls in flight per client (LX_IOCTL_ASYNC and LX_CALL_ASYNC);
* beyond it a call is -EAGAIN. A call counts until its completion is sent
* with its result inline, or until LX_RESULT fetches it. The client library
* keeps its own calls within it. */
#define MLG_LX_MAX_ASYNC 16u
/* The Linux errno values the transport itself reports, spelled out so a
@@ -249,6 +291,7 @@ _Static_assert(sizeof(struct mlg_lx_scanout_state) == 120, "mlg_lx_scanout_state
#define MLG_LX_EINVAL 22
#define MLG_LX_ENOTTY 25
#define MLG_LX_ENOSPC 28
#define MLG_LX_EDEADLK 35 /* a request that can sleep, sent synchronously */
/* Segment directions. */
#define MLG_LX_SEG_IN 1u
@@ -335,8 +378,15 @@ struct mlg_lx_span {
* (MLG_LX_DEV_*): the DRM core and amdgpu ioctls of a render-node client,
* the KFD ioctls of a compute runtime. The dext admits nothing else. */
int mlg_lx_cmd_known(uint32_t dev, uint32_t cmd);
/* Whether @cmd may wait (sent through LX_IOCTL_ASYNC). */
int mlg_lx_cmd_blocks(uint32_t dev, uint32_t cmd);
/* Whether request @frame (@bytes, a frame mlg_lx_encode built, or one
* mlg_lx_frame_check accepted) of @cmd on device @dev can sleep: 1 for
* every request except the few that provably do not (no fence wait, no
* lock held across one, no allocation that can evict, no final buffer
* release), which take the synchronous LX_IOCTL; 0 for those. A syncobj
* wait that only polls (no deadline, or one already past) does not sleep.
* The client picks its selector with it and the driver refuses a sleeping
* request on LX_IOCTL with it, so both read the same table. */
int mlg_lx_cmd_sleeps(uint32_t dev, uint32_t cmd, const void *frame, size_t bytes);
/* The memory ioctl @cmd with argument @arg reads and writes: its argument
* block and every range a pointer in it (or in the ranges it points to)
* names, read from the caller's memory. *@timeout_va is set to the address
+30 -6
View File
@@ -58,6 +58,17 @@ struct rt_lx_client;
int rt_lx_client_create(struct pci_dev *pdev, int pid, const char *comm,
struct rt_lx_client **out);
void rt_lx_client_destroy(struct rt_lx_client *c);
/* rt_lx_client_destroy on a thread of its own, then @then(@arg) there: for
* a caller that must not wait (the driver's incoming-call thread, which a
* call that never returns would otherwise hold). Takes @c in every case:
* 0, or -EAGAIN when no thread could start, logged; then the client is
* destroyed by rt_lx_retire_drain and @then is not called. */
int rt_lx_client_retire(struct rt_lx_client *c, void (*then)(void *arg), void *arg);
/* Wait until every retiring client is destroyed (a session close, before
* the driver goes). */
void rt_lx_retire_drain(void);
/* Clients still being destroyed by rt_lx_client_retire. */
unsigned int rt_lx_retiring(void);
int rt_lx_client_pid(const struct rt_lx_client *c);
/* The display hooks for the client's primary-node files and LX_SCANOUT
@@ -83,18 +94,31 @@ unsigned int rt_lx_open_files(struct rt_lx_client *c);
int rt_lx_ioctl(struct rt_lx_client *c, int fd, uint32_t cmd,
const void *frame, size_t frame_bytes, void *rbuf,
size_t rbuf_cap, size_t *reply_bytes, int64_t *result);
/* rt_lx_ioctl for the driver's incoming-call thread (LX_IOCTL): a request
* that can sleep (mlg_lx_cmd_sleeps) does not run; -EDEADLK, logged. */
int rt_lx_ioctl_nosleep(struct rt_lx_client *c, int fd, uint32_t cmd,
const void *frame, size_t frame_bytes, void *rbuf,
size_t rbuf_cap, size_t *reply_bytes, int64_t *result);
/* Called on the worker once the call has finished. @rbuf holds
* @reply_bytes until it returns. Return nonzero when the reply was
* delivered (the result is then forgotten), zero to keep it for
* rt_lx_result. */
typedef int (*rt_lx_done_fn)(void *ctx, uint64_t token, int64_t result,
const void *rbuf, size_t reply_bytes);
/* Called on the worker once the call has finished, to send its
* completion. A reply of at most MLG_LX_ASYNC_INLINE_BYTES is in @rbuf
* until it returns and is then forgotten: the completion carries it. A
* longer one comes with @rbuf NULL and is kept for rt_lx_result, which
* finds it from the moment this is called. */
typedef void (*rt_lx_done_fn)(void *ctx, uint64_t token, int64_t result,
const void *rbuf, size_t reply_bytes);
/* Start the call on a worker. 0 with *token, or -errno (not started;
* -EAGAIN when MLG_LX_MAX_ASYNC calls are outstanding). */
int rt_lx_ioctl_async(struct rt_lx_client *c, int fd, uint32_t cmd,
const void *frame, size_t frame_bytes, rt_lx_done_fn done,
void *ctx, uint64_t *token);
/* LX_CALL_ASYNC: operation @in[0] (MLG_LX_OP_*) with its scalars, @nin of
* them in all, on a worker, as rt_lx_open, rt_lx_close, rt_lx_mmap and
* rt_lx_munmap run them. Its result is the function's; an MMAP's reply is
* MLG_LX_OP_MMAP_WORDS words (type, length, cache). 0 with *token, or
* -errno (not started: -EINVAL for a malformed call, -EAGAIN as above). */
int rt_lx_op_async(struct rt_lx_client *c, const uint64_t *in, uint32_t nin,
rt_lx_done_fn done, void *ctx, uint64_t *token);
/* The kept result of a finished async call; frees it. -ENOENT for an
* unknown token, -EBUSY while it still runs, -ENOSPC when @cap is short
* (the result is kept). */
+8 -4
View File
@@ -168,18 +168,18 @@ static long st_ioctl(struct st *s, uint32_t cmd, void *arg)
return r;
}
static int async_done(void *ctx, uint64_t token, int64_t result, const void *rbuf,
size_t reply_bytes)
static void async_done(void *ctx, uint64_t token, int64_t result, const void *rbuf,
size_t reply_bytes)
{
struct st *s = ctx;
(void)token;
s->async_result = result;
s->async_reply_bytes = reply_bytes <= sizeof(s->async_reply) ? reply_bytes : 0;
/* A reply too long for the completion is kept for rt_lx_result. */
s->async_reply_bytes = rbuf && reply_bytes <= sizeof(s->async_reply) ? reply_bytes : 0;
if (s->async_reply_bytes)
memcpy(s->async_reply, rbuf, reply_bytes);
complete(&s->done);
return 1;
}
/* A wait run as the async RPC runs it: on a worker of the process. */
@@ -201,6 +201,10 @@ static long st_ioctl_async(struct st *s, uint32_t cmd, void *arg)
if (!wait_for_completion_timeout(&s->done,
msecs_to_jiffies(RT_CS_SELFTEST_WAIT_MS * 4)))
r = -ETIME;
else if (!s->async_reply_bytes &&
rt_lx_result(s->c, token, s->async_reply, sizeof(s->async_reply),
&s->async_reply_bytes, &s->async_result))
r = -EPROTO;
else if (!s->async_reply_bytes ||
mlg_lx_apply_reply(frame, bytes, s->async_reply, s->async_reply_bytes, NULL))
r = -EPROTO;
+82 -11
View File
@@ -178,21 +178,92 @@ int mlg_lx_cmd_known(uint32_t dev, uint32_t cmd)
}
}
int mlg_lx_cmd_blocks(uint32_t dev, uint32_t cmd)
/* The 8 bytes at client address @va as the frame carries them (an IN
* segment), or -1 when no IN segment holds them. */
static int frame_u64(const void *frame, size_t bytes, uint64_t va, int64_t *out)
{
if (dev == MLG_LX_DEV_KFD)
return cmd == AMDKFD_IOC_WAIT_EVENTS;
if (dev != MLG_LX_DEV_RENDER && dev != MLG_LX_DEV_PRIMARY)
const struct mlg_lx_frame *head = frame;
const struct mlg_lx_segment *segs =
(const struct mlg_lx_segment *)((const uint8_t *)frame + sizeof(*head));
if (bytes < sizeof(*head) || head->nsegs > MLG_LX_MAX_SEGMENTS ||
bytes < sizeof(*head) + (size_t)head->nsegs * sizeof(*segs))
return -1;
for (uint32_t i = 0; i < head->nsegs; ++i) {
const struct mlg_lx_segment *seg = &segs[i];
if (!(seg->dir & MLG_LX_SEG_IN) || seg->size < 8 || va < seg->va ||
va - seg->va > seg->size - 8u ||
(uint64_t)seg->data_offset + seg->size > bytes)
continue;
memcpy(out, (const uint8_t *)frame + seg->data_offset + (va - seg->va), 8);
return 0;
switch (cmd) {
case DRM_IOCTL_AMDGPU_WAIT_CS:
case DRM_IOCTL_AMDGPU_WAIT_FENCES:
case DRM_IOCTL_AMDGPU_GEM_WAIT_IDLE:
case DRM_IOCTL_SYNCOBJ_WAIT:
case DRM_IOCTL_SYNCOBJ_TIMELINE_WAIT:
}
return -1;
}
/* A syncobj wait whose deadline (an absolute CLOCK_MONOTONIC time at
* @timeout_va) has passed or is none: drm_timeout_abs_to_jiffies makes it a
* zero timeout, and drm_syncobj_array_wait_timeout returns without
* sleeping. With MLG_LX_FRAME_TIMEOUT the driver writes now + timeout_ns
* there before the call; without it the client's value goes unchanged,
* and only one at or below zero is a deadline the driver's clock agrees
* has passed. */
static int syncobj_polls(const void *frame, size_t bytes, uint64_t timeout_va)
{
const struct mlg_lx_frame *head = frame;
int64_t deadline;
if (bytes < sizeof(*head))
return 0;
if (head->flags & MLG_LX_FRAME_TIMEOUT)
return head->timeout_va == timeout_va && head->timeout_ns == 0;
return !frame_u64(frame, bytes, timeout_va, &deadline) && deadline <= 0;
}
/* Every request here was read against upstream for what it can wait on;
* anything else sleeps. Not here, though they rarely wait: GEM_CLOSE and
* GEM_MMAP (a final buffer release can clear VRAM through the SDMA ring),
* every amdgpu request that takes a context (the context manager's lock is
* held while a context's scheduler entities flush), reserves a buffer or
* allocates one (eviction), INFO (SMU messages, GFXOFF), the KMS requests
* (modeset locks held across commits, connector probes over AUX/DDC),
* PRIME (dma-buf import reserves), SYNCOBJ_TRANSFER (it can wait for a
* submission), and every KFD request but GET_VERSION (the KFD process
* mutex is held across GPU mappings that wait). */
int mlg_lx_cmd_sleeps(uint32_t dev, uint32_t cmd, const void *frame, size_t bytes)
{
const struct mlg_lx_frame *head = frame;
if (!frame || bytes < sizeof(*head))
return 1;
default:
if (dev == MLG_LX_DEV_KFD)
return cmd != AMDKFD_IOC_GET_VERSION;
if (dev != MLG_LX_DEV_RENDER && dev != MLG_LX_DEV_PRIMARY)
return 1;
switch (cmd) {
case DRM_IOCTL_VERSION:
case DRM_IOCTL_GET_CAP:
case DRM_IOCTL_SET_CLIENT_CAP:
case DRM_IOCTL_SYNCOBJ_CREATE:
case DRM_IOCTL_SYNCOBJ_DESTROY:
case DRM_IOCTL_SYNCOBJ_HANDLE_TO_FD:
case DRM_IOCTL_SYNCOBJ_FD_TO_HANDLE:
case DRM_IOCTL_SYNCOBJ_RESET:
case DRM_IOCTL_SYNCOBJ_SIGNAL:
case DRM_IOCTL_SYNCOBJ_TIMELINE_SIGNAL:
case DRM_IOCTL_SYNCOBJ_QUERY:
case DRM_IOCTL_SYNCOBJ_EVENTFD:
return 0;
case DRM_IOCTL_SYNCOBJ_WAIT:
return !syncobj_polls(frame, bytes,
head->arg + offsetof(struct drm_syncobj_wait, timeout_nsec));
case DRM_IOCTL_SYNCOBJ_TIMELINE_WAIT:
return !syncobj_polls(frame, bytes,
head->arg + offsetof(struct drm_syncobj_timeline_wait,
timeout_nsec));
default:
return 1;
}
}
+329 -56
View File
@@ -66,6 +66,8 @@ struct lx_async {
struct lx_async *queued_next; /* waiting for a worker */
struct rt_lx_client *c;
uint64_t token;
uint32_t op; /* 0: an ioctl; else MLG_LX_OP_* */
uint64_t args[MLG_LX_OP_MMAP_ARGS]; /* the operation's scalars */
int fd;
uint32_t cmd;
void *frame;
@@ -73,9 +75,11 @@ struct lx_async {
uint64_t queued_ns; /* when the request arrived (rt/lx_timing.h) */
rt_lx_done_fn done;
void *ctx;
bool finished;
bool finished; /* its result is there */
bool completing; /* its worker is still in done() */
bool slot; /* counts in slots */
int64_t result;
void *rep;
void *rep; /* kept for rt_lx_result */
size_t reply_bytes;
int status; /* 0, or why the call did not run */
};
@@ -92,7 +96,8 @@ struct rt_lx_client {
bool dying;
unsigned int calls; /* calls inside the process */
struct lx_async *async;
unsigned int async_count;
unsigned int async_count; /* entries of the async list */
unsigned int slots; /* calls counting in MLG_LX_MAX_ASYNC */
/* The workers that run async calls: they stay for the client's next
* calls (starting a thread per wait costs more than the wait's round
* trip), at most MLG_LX_MAX_ASYNC, as many as calls ever overlapped. */
@@ -107,6 +112,12 @@ struct rt_lx_client {
uint64_t next_map;
uint64_t pending_va;
const struct rt_lx_display_hooks *display; /* primary node and LX_SCANOUT */
/* rt_lx_client_retire, under retire_lock. */
struct rt_lx_client *retire_next;
pthread_t retire_thread;
void (*retire_then)(void *arg);
void *retire_arg;
bool retire_started, retire_finished;
};
/* ---- client ---- */
@@ -540,10 +551,12 @@ static void pages_copy(struct lx_call_pages *p, uint64_t va, void *bytes, uint64
/* ---- ioctl ---- */
/* Run one validated frame. Caller holds a call reference. */
/* Run one validated frame. Caller holds a call reference. With @nosleep
* (the caller is the driver's incoming-call thread), a request that can
* sleep is refused with -EDEADLK and does not run. */
static int run_ioctl(struct rt_lx_client *c, int fd, uint32_t cmd, const void *frame,
size_t frame_bytes, uint64_t out_bytes, void *rep, size_t *reply_bytes,
int64_t *result)
int64_t *result, bool nosleep)
{
const struct mlg_lx_frame *head = frame;
const struct mlg_lx_segment *segs =
@@ -555,9 +568,9 @@ static int run_ioctl(struct rt_lx_client *c, int fd, uint32_t cmd, const void *f
uint8_t *out;
long ret;
int r;
bool refused = false;
uint64_t t0 = rt_lx_time_ns(), t1;
(void)frame_bytes;
r = pages_acquire(c, segs, head->nsegs, &pages);
if (r)
return r;
@@ -596,6 +609,8 @@ static int run_ioctl(struct rt_lx_client *c, int fd, uint32_t cmd, const void *f
ret = -ENOTTY;
else if (!file->f_op || !file->f_op->unlocked_ioctl)
ret = -ENOTTY;
else if (nosleep && mlg_lx_cmd_sleeps(dev, cmd, frame, frame_bytes))
refused = true;
else
ret = file->f_op->unlocked_ioctl(file, cmd, (unsigned long)head->arg);
t1 = rt_lx_time_ns();
@@ -604,6 +619,13 @@ static int run_ioctl(struct rt_lx_client *c, int fd, uint32_t cmd, const void *f
fput(file);
}
linuxu_process_leave(&saved);
if (refused) {
pages_release(c, &pages);
pr_err("lx: pid %d (%s): request 0x%08x can sleep and was sent synchronously; "
"it did not run (a client library older than the driver: rebuild it)\n",
rt_lx_client_pid(c), linuxu_process_leader(c->proc)->comm, cmd);
return -EDEADLK;
}
ret = lx_errno(ret);
t1 = rt_lx_time_ns();
rt_lx_timing_add(cmd, RT_LX_HOP_LEAVE, t1 - t0);
@@ -636,9 +658,9 @@ static int run_ioctl(struct rt_lx_client *c, int fd, uint32_t cmd, const void *f
return 0;
}
int rt_lx_ioctl(struct rt_lx_client *c, int fd, uint32_t cmd,
const void *frame, size_t frame_bytes, void *rep,
size_t rep_cap, size_t *reply_bytes, int64_t *result)
static int lx_ioctl(struct rt_lx_client *c, int fd, uint32_t cmd,
const void *frame, size_t frame_bytes, void *rep,
size_t rep_cap, size_t *reply_bytes, int64_t *result, bool nosleep)
{
uint64_t out_bytes = 0, t0 = rt_lx_time_ns(), t1;
void *copy;
@@ -665,7 +687,8 @@ int rt_lx_ioctl(struct rt_lx_client *c, int fd, uint32_t cmd,
t1 = rt_lx_time_ns();
rt_lx_timing_add(cmd, RT_LX_HOP_FRAME, t1 - t0);
if (!r) {
r = run_ioctl(c, fd, cmd, copy, frame_bytes, out_bytes, rep, reply_bytes, result);
r = run_ioctl(c, fd, cmd, copy, frame_bytes, out_bytes, rep, reply_bytes, result,
nosleep);
t1 = rt_lx_time_ns();
call_end(c);
}
@@ -674,15 +697,36 @@ int rt_lx_ioctl(struct rt_lx_client *c, int fd, uint32_t cmd,
return r;
}
/* ---- async ---- */
int rt_lx_ioctl(struct rt_lx_client *c, int fd, uint32_t cmd,
const void *frame, size_t frame_bytes, void *rep,
size_t rep_cap, size_t *reply_bytes, int64_t *result)
{
return lx_ioctl(c, fd, cmd, frame, frame_bytes, rep, rep_cap, reply_bytes, result, false);
}
static void async_run(struct lx_async *a)
int rt_lx_ioctl_nosleep(struct rt_lx_client *c, int fd, uint32_t cmd,
const void *frame, size_t frame_bytes, void *rep,
size_t rep_cap, size_t *reply_bytes, int64_t *result)
{
return lx_ioctl(c, fd, cmd, frame, frame_bytes, rep, rep_cap, reply_bytes, result, true);
}
/* ---- async ----
*
* Every call that can sleep runs here, on a worker of the client, never on
* the thread the call arrived on. A call holds a slot (MLG_LX_MAX_ASYNC per
* client) from its admission until its result is delivered: inline with
* its completion (the slot is free before the completion is sent, so a
* client that waits for completions before calling again never finds the
* slots full), or by rt_lx_result. */
/* A result of at most this many bytes goes with the completion. */
#define LX_INLINE_BYTES MLG_LX_ASYNC_INLINE_BYTES
static void async_run_ioctl(struct lx_async *a)
{
struct rt_lx_client *c = a->c;
uint64_t out_bytes = 0;
int consumed = 0;
rt_lx_timing_add(a->cmd, RT_LX_HOP_SPAWN, rt_lx_time_ns() - a->queued_ns);
a->status = mlg_lx_frame_check(a->frame, a->frame_bytes, a->cmd, &out_bytes);
if (!a->status) {
@@ -691,7 +735,7 @@ static void async_run(struct lx_async *a)
}
if (!a->status)
a->status = run_ioctl(c, a->fd, a->cmd, a->frame, a->frame_bytes, out_bytes,
a->rep, &a->reply_bytes, &a->result);
a->rep, &a->reply_bytes, &a->result, false);
if (a->status) {
/* The call did not run: report the transport error as its result. */
struct mlg_lx_reply rh = {
@@ -709,16 +753,86 @@ static void async_run(struct lx_async *a)
}
kvfree(a->frame);
a->frame = NULL;
if (a->done)
consumed = a->done(a->ctx, a->token, a->result, a->rep, a->reply_bytes);
}
static void async_run_op(struct lx_async *a)
{
struct rt_lx_client *c = a->c;
const uint64_t *in = a->args;
struct rt_lx_map_info info;
uint64_t *words;
a->reply_bytes = 0;
switch (a->op) {
case MLG_LX_OP_OPEN:
a->result = rt_lx_open(c, (uint32_t)in[1], (uint32_t)in[2]);
break;
case MLG_LX_OP_CLOSE:
a->result = rt_lx_close(c, (int)in[1]);
break;
case MLG_LX_OP_MMAP:
a->result = rt_lx_mmap(c, (int)in[1], in[2], in[3], (uint32_t)in[4],
(uint32_t)in[5], &info);
if (a->result)
break;
words = kvzalloc(MLG_LX_OP_MMAP_WORDS * sizeof(uint64_t), GFP_KERNEL);
if (!words) {
/* No reply to carry the mapping: undo it. */
rt_lx_munmap(c, info.type);
a->result = -ENOMEM;
break;
}
words[0] = info.type;
words[1] = info.length;
words[2] = info.cache;
a->rep = words;
a->reply_bytes = MLG_LX_OP_MMAP_WORDS * sizeof(uint64_t);
break;
case MLG_LX_OP_MUNMAP:
a->result = rt_lx_munmap(c, in[1]);
break;
default:
a->result = -EINVAL; /* refused at admission */
break;
}
}
static void async_run(struct lx_async *a)
{
struct rt_lx_client *c = a->c;
const void *inline_rep = NULL;
bool inline_result;
if (a->op) {
async_run_op(a);
} else {
rt_lx_timing_add(a->cmd, RT_LX_HOP_SPAWN, rt_lx_time_ns() - a->queued_ns);
async_run_ioctl(a);
}
/* The result is there before the completion goes out, so a fetch
* that follows the completion finds it. */
inline_result = a->reply_bytes <= LX_INLINE_BYTES;
pthread_mutex_lock(&c->lock);
a->finished = true;
if (consumed) {
kvfree(a->rep);
a->completing = true;
if (inline_result) {
/* Delivered with the completion: the slot frees now, and
* nothing can fetch the result. */
inline_rep = a->rep;
a->rep = NULL;
a->reply_bytes = 0;
a->done = NULL; /* nothing left to fetch */
if (a->slot) {
a->slot = false;
c->slots--;
}
}
pthread_mutex_unlock(&c->lock);
if (a->done)
a->done(a->ctx, a->token, a->result, inline_result ? inline_rep : NULL,
a->reply_bytes);
kvfree((void *)inline_rep);
pthread_mutex_lock(&c->lock);
a->completing = false;
c->calls--;
pthread_cond_broadcast(&c->changed);
pthread_mutex_unlock(&c->lock);
@@ -759,7 +873,7 @@ static void async_reap_locked(struct rt_lx_client *c)
for (struct lx_async **link = &c->async; *link;) {
struct lx_async *a = *link;
if (a->finished && !a->rep && !a->done) {
if (a->finished && !a->completing && !a->rep) {
*link = a->next;
c->async_count--;
kfree(a);
@@ -769,6 +883,49 @@ static void async_reap_locked(struct rt_lx_client *c)
}
}
/* Admit @a (its request copied in) and hand it to a worker. */
static int async_queue(struct rt_lx_client *c, struct lx_async *a, uint64_t *token)
{
int r = 0;
a->queued_ns = rt_lx_time_ns();
a->c = c;
pthread_mutex_lock(&c->lock);
async_reap_locked(c);
if (c->dying) {
r = -ESRCH;
} else if (c->slots >= MLG_LX_MAX_ASYNC) {
r = -EAGAIN;
} else if (c->queued_count + 1 > c->idle_workers && c->workers < MLG_LX_MAX_ASYNC &&
pthread_create(&c->worker_threads[c->workers], NULL, async_worker, c)) {
r = -ENOMEM;
} else {
/* An idle worker takes it, or the one just started, or, with
* every worker made, the next to finish: at most
* MLG_LX_MAX_ASYNC calls hold slots, and a worker still
* completing a call holds none. */
if (c->queued_count + 1 > c->idle_workers) {
if (c->workers < MLG_LX_MAX_ASYNC)
c->workers++;
} else {
pthread_cond_signal(&c->work);
}
a->token = c->next_token++;
a->slot = true;
c->slots++;
c->calls++;
*c->queued_tail = a;
c->queued_tail = &a->queued_next;
c->queued_count++;
a->next = c->async;
c->async = a;
c->async_count++;
*token = a->token;
}
pthread_mutex_unlock(&c->lock);
return r;
}
int rt_lx_ioctl_async(struct rt_lx_client *c, int fd, uint32_t cmd,
const void *frame, size_t frame_bytes, rt_lx_done_fn done,
void *ctx, uint64_t *token)
@@ -792,40 +949,11 @@ int rt_lx_ioctl_async(struct rt_lx_client *c, int fd, uint32_t cmd,
}
memcpy(a->frame, frame, frame_bytes);
a->frame_bytes = frame_bytes;
a->queued_ns = rt_lx_time_ns();
a->c = c;
a->fd = fd;
a->cmd = cmd;
a->done = done;
a->ctx = ctx;
pthread_mutex_lock(&c->lock);
async_reap_locked(c);
if (c->dying) {
r = -ESRCH;
} else if (c->async_count >= MLG_LX_MAX_ASYNC) {
r = -EAGAIN;
} else if (c->queued_count + 1 > c->idle_workers &&
(c->workers >= MLG_LX_MAX_ASYNC ||
pthread_create(&c->worker_threads[c->workers], NULL, async_worker, c))) {
/* Every worker is busy and no other can start. Not reached while
* fewer than MLG_LX_MAX_ASYNC calls are out (one worker each). */
r = -EAGAIN;
} else {
if (c->queued_count + 1 > c->idle_workers)
c->workers++; /* the one just started takes it */
else
pthread_cond_signal(&c->work);
a->token = c->next_token++;
c->calls++;
*c->queued_tail = a;
c->queued_tail = &a->queued_next;
c->queued_count++;
a->next = c->async;
c->async = a;
c->async_count++;
*token = a->token;
}
pthread_mutex_unlock(&c->lock);
r = async_queue(c, a, token);
if (r) {
kvfree(a->frame);
kfree(a);
@@ -833,6 +961,51 @@ int rt_lx_ioctl_async(struct rt_lx_client *c, int fd, uint32_t cmd,
return r;
}
int rt_lx_op_async(struct rt_lx_client *c, const uint64_t *in, uint32_t nin,
rt_lx_done_fn done, void *ctx, uint64_t *token)
{
struct lx_async *a;
uint32_t want;
int r;
if (!c || !in || !nin || !token)
return -EINVAL;
switch (in[0]) {
case MLG_LX_OP_OPEN:
want = MLG_LX_OP_OPEN_ARGS;
break;
case MLG_LX_OP_CLOSE:
want = MLG_LX_OP_CLOSE_ARGS;
break;
case MLG_LX_OP_MMAP:
want = MLG_LX_OP_MMAP_ARGS;
break;
case MLG_LX_OP_MUNMAP:
want = MLG_LX_OP_MUNMAP_ARGS;
break;
default:
return -EINVAL;
}
if (nin != want)
return -EINVAL;
/* The values each operation narrows to an int or a 32-bit field. */
if ((in[0] == MLG_LX_OP_OPEN && (in[1] > UINT32_MAX || in[2] > UINT32_MAX)) ||
((in[0] == MLG_LX_OP_CLOSE || in[0] == MLG_LX_OP_MMAP) && in[1] > INT32_MAX) ||
(in[0] == MLG_LX_OP_MMAP && (in[4] > UINT32_MAX || in[5] > UINT32_MAX)))
return -EINVAL;
a = kzalloc(sizeof(*a), GFP_KERNEL);
if (!a)
return -ENOMEM;
a->op = (uint32_t)in[0];
memcpy(a->args, in, nin * sizeof(*in));
a->done = done;
a->ctx = ctx;
r = async_queue(c, a, token);
if (r)
kfree(a);
return r;
}
int rt_lx_result(struct rt_lx_client *c, uint64_t token, void *rep,
size_t cap, size_t *reply_bytes, int64_t *result)
{
@@ -857,7 +1030,10 @@ int rt_lx_result(struct rt_lx_client *c, uint64_t token, void *rep,
*result = a->result;
kvfree(a->rep);
a->rep = NULL;
a->done = NULL;
if (a->slot) {
a->slot = false;
c->slots--;
}
r = 0;
}
break;
@@ -1234,10 +1410,100 @@ unsigned int rt_lx_mappings(struct rt_lx_client *c)
/* ---- teardown ---- */
void rt_lx_client_destroy(struct rt_lx_client *c)
/* Clients being destroyed on threads of their own (rt_lx_client_retire),
* linked through their retire fields. */
static pthread_mutex_t retire_lock = PTHREAD_MUTEX_INITIALIZER;
static pthread_cond_t retire_changed = PTHREAD_COND_INITIALIZER;
static struct rt_lx_client *retiring;
static void client_teardown(struct rt_lx_client *c);
static void *retire_main(void *p)
{
struct rt_lx_client *c = p;
client_teardown(c);
if (c->retire_then)
c->retire_then(c->retire_arg);
pthread_mutex_lock(&retire_lock);
c->retire_finished = true;
pthread_cond_broadcast(&retire_changed);
pthread_mutex_unlock(&retire_lock);
return NULL;
}
/* Join the finished ones; with @all, also destroy those no thread took and
* wait for every one. Caller holds retire_lock. */
static void retire_reap_locked(bool all)
{
for (;;) {
struct rt_lx_client **link = &retiring, *done = NULL;
for (; *link; link = &(*link)->retire_next) {
if ((*link)->retire_finished || (all && !(*link)->retire_started)) {
done = *link;
*link = done->retire_next;
break;
}
}
if (done) {
pthread_mutex_unlock(&retire_lock);
if (done->retire_started)
pthread_join(done->retire_thread, NULL);
else
client_teardown(done); /* on the drain's thread */
kfree(done);
pthread_mutex_lock(&retire_lock);
continue;
}
if (!all || !retiring)
return;
pthread_cond_wait(&retire_changed, &retire_lock);
}
}
int rt_lx_client_retire(struct rt_lx_client *c, void (*then)(void *arg), void *arg)
{
int err;
if (!c)
return;
return -EINVAL;
c->retire_then = then;
c->retire_arg = arg;
pthread_mutex_lock(&retire_lock);
retire_reap_locked(false);
err = pthread_create(&c->retire_thread, NULL, retire_main, c) ? -EAGAIN : 0;
c->retire_started = !err;
c->retire_next = retiring;
retiring = c;
pthread_mutex_unlock(&retire_lock);
if (err)
pr_err("lx: pid %d: no thread for the process's exit; it exits when the session "
"closes\n", rt_lx_client_pid(c));
return err;
}
void rt_lx_retire_drain(void)
{
pthread_mutex_lock(&retire_lock);
retire_reap_locked(true);
pthread_mutex_unlock(&retire_lock);
}
unsigned int rt_lx_retiring(void)
{
unsigned int n = 0;
pthread_mutex_lock(&retire_lock);
for (struct rt_lx_client *c = retiring; c; c = c->retire_next)
n += !c->retire_finished;
pthread_mutex_unlock(&retire_lock);
return n;
}
/* Everything rt_lx_client_destroy does but free @c. */
static void client_teardown(struct rt_lx_client *c)
{
/* Whatever the client shows goes off the screen while its
* framebuffers still exist. */
if (c->display)
@@ -1283,5 +1549,12 @@ void rt_lx_client_destroy(struct rt_lx_client *c)
pthread_cond_destroy(&c->work);
pthread_cond_destroy(&c->changed);
pthread_mutex_destroy(&c->lock);
}
void rt_lx_client_destroy(struct rt_lx_client *c)
{
if (!c)
return;
client_teardown(c);
kfree(c);
}
+51 -2
View File
@@ -1,6 +1,55 @@
/* linuxu shim: dev_coredump — coredump no-op
* (ENOSYS/NOOP: devm_devcoredump_setup no-op). */
/* linuxu shim: dev_coredump — no exporter (devm_devcoredump_setup no-op);
* dev_coredumpm logs the dump's head, which names the device, the ring that
* hung and its process, at error level. */
#include <pthread.h>
#include <linux/device.h>
#include <linux/devcoredump.h>
#include <linux/printk.h>
#include <linux/string.h>
/* The dump's first bytes: amdgpu's header, time, process, ring and IP
* state summary come first. */
#define COREDUMP_HEAD_BYTES 3072
#define COREDUMP_HEAD_LINES 48
void dev_coredumpm(struct device *dev, struct module *owner,
void *data, size_t datalen, gfp_t gfp,
ssize_t (*read)(char *buffer, loff_t offset, size_t count,
void *data, size_t datalen),
void (*free)(void *data))
{
/* Rare (a GPU hang), and on the reset domain's single worker: one
* static buffer, so a dump never needs memory it may not get. */
static pthread_mutex_t head_lock = PTHREAD_MUTEX_INITIALIZER;
static char head[COREDUMP_HEAD_BYTES + 1];
ssize_t n = 0;
(void)owner;
pthread_mutex_lock(&head_lock);
if (dev && read)
n = read(head, 0, COREDUMP_HEAD_BYTES, data, datalen);
(void)gfp;
if (dev)
dev_err(dev, "devcoredump: the device dumped its state (head follows)\n");
if (n > 0) {
char *line = head;
int lines = 0;
head[n] = '\0';
while (line && *line && lines++ < COREDUMP_HEAD_LINES) {
char *end = strchr(line, '\n');
if (end)
*end = '\0';
if (*line)
dev_err(dev, "devcoredump: %s\n", line);
line = end ? end + 1 : NULL;
}
}
pthread_mutex_unlock(&head_lock);
if (free)
free(data);
}
struct dev_coredump_mmap;
+13 -2
View File
@@ -16,7 +16,7 @@
#ifdef LINUXU_DEXT_DK
/* Public DriverKit logging entry point; no stdio stream exists in a dext. */
extern int IOLogv(const char *format, va_list arguments);
extern int IOLog(const char *format, ...) __attribute__((format(printf, 1, 2)));
#endif
/* ---- debug level gate (0=emerg .. 7=debug) ---- */
@@ -152,7 +152,18 @@ static int klog_vemit(int level, const char *f, va_list ap)
}
klog_append(record, length);
#ifdef LINUXU_DEXT_DK
return IOLogv(f, ap);
/* Errors and worse are events (a ring timeout, a failed reset, a
* device dump): they reach the unified log, prefixed as the driver's
* own events are. Everything else stays in the retained ring: a dext
* that logs every line there gets its logging quarantined by the
* system for high volume. */
(void)ap;
if (level > 3)
return 0;
if (length >= sizeof(record))
length = sizeof(record) - 1;
record[length] = '\0';
return IOLog("mac.linuxgpu: EVENT %s", record);
#else
pthread_mutex_lock(&klog_lock);
fprintf(stderr, "%s ", level_tag(level));
+405
View File
@@ -0,0 +1,405 @@
/* A Linux-file call that does not return must hold nothing but its own
* worker (blocked_call_check.h), on the CS fixture's device.
*
* On build 241 a request that waited on a GPU ring that had stopped ran on
* the driver's incoming-call thread, the one thread every client's calls
* and the driver's own Stop arrive on: every client froze, and the driver
* could not take its Stop after the GPU was powered off. Here a client's
* AMDGPU_CS blocks the way one does on a stopped ring (its context has
* amdgpu_sched_jobs submissions the compute engine never runs, so the next
* waits in amdgpu_ctx_wait_prev_fence), and while it does:
* - every call the test makes as the incoming-call thread would (start
* an async call, a synchronous call, a Stop) returns at once;
* - the blocked client's own synchronous request runs, and its sleeping
* request on the synchronous path is refused without running;
* - another client opens the render node, allocates and submits, and its
* work completes;
* - the blocked client's Stop hands its exit to a thread of its own and
* returns; the exit finishes once its work completes.
* blocked_call_park and blocked_call_after_removal put a blocked client
* through a surprise removal (removal_check.c): removal ends the blocked
* call, and the client's exit completes. */
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <linux/completion.h>
#include <linux/jiffies.h>
#include <linux/ktime.h>
#include <linux/pci.h>
#include <linux/slab.h>
#include <drm/amdgpu_drm.h>
#include <drm/drm.h>
#include <rt/lx_abi.h>
#include <rt/lx_files.h>
#include "amdgpu.h"
#include "cs_fixture.h"
#include "blocked_call_check.h"
extern int usleep(unsigned int usec);
#define CHECK(c) do { if (!(c)) { fprintf(stderr, "%s:%d: CHECK failed: %s\n", \
__FILE__, __LINE__, #c); abort(); } } while (0)
/* What "at once" means for a call on the incoming-call thread: it queues
* work or runs a request that cannot sleep. Generous for a loaded host. */
#define CALL_MS_MAX 200
#define BO_BYTES (64u << 10)
struct bc_call {
struct completion done;
int64_t result;
uint8_t rep[256];
size_t bytes;
int kept;
uint64_t token;
void *frame;
size_t frame_bytes;
void *arg;
};
struct bc_client {
struct rt_lx_client *c;
int fd;
uint32_t ctx, bo;
uint64_t va;
uint32_t *ib;
uint32_t ib_dw;
struct drm_amdgpu_bo_list_entry list[1];
struct drm_amdgpu_bo_list_in list_in;
struct drm_amdgpu_cs_chunk_ib chunk_ib;
struct drm_amdgpu_cs_chunk chunks[2];
uint64_t chunk_ptrs[2];
union drm_amdgpu_cs cs;
struct bc_call blocked; /* the submission that waits */
};
static void bc_done(void *ctx, uint64_t token, int64_t result, const void *rbuf, size_t bytes)
{
struct bc_call *call = ctx;
CHECK(token == call->token || !call->token);
call->result = result;
call->bytes = bytes;
if (!rbuf && bytes)
call->kept = 1;
else if (bytes) {
CHECK(bytes <= sizeof(call->rep));
memcpy(call->rep, rbuf, bytes);
}
complete(&call->done);
}
static ktime_t call_start;
static void on_call_thread(void)
{
call_start = ktime_get();
}
static void returned_at_once(void)
{
CHECK(ktime_ms_delta(ktime_get(), call_start) < CALL_MS_MAX);
}
static void *build(uint32_t cmd, void *arg, size_t *bytes, uint64_t *out_bytes)
{
struct mlg_lx_span *spans = calloc(MLG_LX_DESCRIBE_MAX, sizeof(*spans));
uint64_t timeout_va = 0;
uint32_t n = 0;
void *frame;
long len;
CHECK(spans);
CHECK(!mlg_lx_describe(MLG_LX_DEV_RENDER, cmd, (uint64_t)(uintptr_t)arg, spans,
MLG_LX_DESCRIBE_MAX, &n, &timeout_va));
len = mlg_lx_encode(cmd, (uint64_t)(uintptr_t)arg, spans, n, timeout_va, ktime_get_ns(),
NULL, 0, out_bytes);
CHECK(len > 0);
frame = malloc((size_t)len);
CHECK(frame);
CHECK(mlg_lx_encode(cmd, (uint64_t)(uintptr_t)arg, spans, n, timeout_va, ktime_get_ns(),
frame, (size_t)len, out_bytes) == len);
free(spans);
*bytes = (size_t)len;
return frame;
}
/* The synchronous LX_IOCTL, as the incoming-call thread runs it. */
static long call_sync(struct bc_client *k, uint32_t cmd, void *arg)
{
uint64_t out_bytes = 0;
size_t bytes = 0, rep_bytes = 0;
void *frame = build(cmd, arg, &bytes, &out_bytes);
void *rep = malloc(mlg_lx_reply_bytes(out_bytes));
int64_t result = 0;
int r;
CHECK(rep);
on_call_thread();
r = rt_lx_ioctl_nosleep(k->c, k->fd, cmd, frame, bytes, rep, mlg_lx_reply_bytes(out_bytes),
&rep_bytes, &result);
returned_at_once();
if (!r)
CHECK(!mlg_lx_apply_reply(frame, bytes, rep, rep_bytes, NULL));
free(rep);
free(frame);
return r ? r : (long)result;
}
/* LX_IOCTL_ASYNC: started on the incoming-call thread, which returns. */
static void call_start_async(struct bc_client *k, uint32_t cmd, void *arg, struct bc_call *call)
{
uint64_t out_bytes = 0;
memset(call, 0, sizeof(*call));
init_completion(&call->done);
call->arg = arg;
call->frame = build(cmd, arg, &call->frame_bytes, &out_bytes);
on_call_thread();
CHECK(!rt_lx_ioctl_async(k->c, k->fd, cmd, call->frame, call->frame_bytes, bc_done, call,
&call->token));
returned_at_once();
}
/* Whether the call completed within @ms; its reply applied, as the client
* library applies it. */
static int call_finished(struct bc_client *k, struct bc_call *call, unsigned int ms)
{
if (!wait_for_completion_timeout(&call->done, msecs_to_jiffies(ms)))
return 0;
if (call->kept) {
static uint8_t rep[1 << 16];
size_t rep_bytes = 0;
int64_t result = 0;
CHECK(!rt_lx_result(k->c, call->token, rep, sizeof(rep), &rep_bytes, &result));
CHECK(!mlg_lx_apply_reply(call->frame, call->frame_bytes, rep, rep_bytes, NULL));
} else if (call->bytes) {
CHECK(!mlg_lx_apply_reply(call->frame, call->frame_bytes, call->rep, call->bytes,
NULL));
}
free(call->frame);
call->frame = NULL;
return 1;
}
static long call_async(struct bc_client *k, uint32_t cmd, void *arg)
{
struct bc_call call;
call_start_async(k, cmd, arg, &call);
CHECK(call_finished(k, &call, 5000));
return (long)call.result;
}
/* LX_CALL_ASYNC. */
static int64_t op(struct bc_client *k, const uint64_t *in, uint32_t nin, uint64_t *words)
{
struct bc_call call;
memset(&call, 0, sizeof(call));
init_completion(&call.done);
on_call_thread();
CHECK(!rt_lx_op_async(k->c, in, nin, bc_done, &call, &call.token));
returned_at_once();
CHECK(wait_for_completion_timeout(&call.done, msecs_to_jiffies(5000)));
if (words && !call.result) {
CHECK(call.bytes == MLG_LX_OP_MMAP_WORDS * 8);
memcpy(words, call.rep, call.bytes);
}
return call.result;
}
/* A client with the render node open, a context and an IB buffer of
* compute NOPs mapped at a GPU address. */
static void client_open(struct pci_dev *pdev, const char *name, struct bc_client *k)
{
struct amdgpu_device *adev = cs_fixture_adev();
uint64_t open_in[] = { MLG_LX_OP_OPEN, MLG_LX_DEV_RENDER, MLG_LX_O_RDWR | MLG_LX_O_CLOEXEC };
struct drm_amdgpu_info_device dev = { 0 };
struct drm_amdgpu_info info = { .return_pointer = (uint64_t)(uintptr_t)&dev,
.return_size = sizeof(dev), .query = AMDGPU_INFO_DEV_INFO };
union drm_amdgpu_ctx ctx = { .in = { .op = AMDGPU_CTX_OP_ALLOC_CTX,
.priority = AMDGPU_CTX_PRIORITY_NORMAL } };
union drm_amdgpu_gem_create create = { .in = { .bo_size = BO_BYTES, .alignment = PAGE_SIZE,
.domains = AMDGPU_GEM_DOMAIN_GTT, .domain_flags = AMDGPU_GEM_CREATE_CPU_GTT_USWC } };
struct drm_amdgpu_gem_va va = { 0 };
union drm_amdgpu_gem_mmap gmap = { 0 };
uint64_t words[MLG_LX_OP_MMAP_WORDS], contiguous = 0;
const uint32_t nop = adev->gfx.compute_ring[0].funcs->nop;
memset(k, 0, sizeof(*k));
CHECK(!rt_lx_client_create(pdev, 0, name, &k->c));
k->fd = (int)op(k, open_in, MLG_LX_OP_OPEN_ARGS, NULL);
CHECK(k->fd >= 0);
CHECK(call_async(k, DRM_IOCTL_AMDGPU_INFO, &info) == 0);
CHECK(call_async(k, DRM_IOCTL_AMDGPU_CTX, &ctx) == 0);
k->ctx = ctx.out.alloc.ctx_id;
CHECK(call_async(k, DRM_IOCTL_AMDGPU_GEM_CREATE, &create) == 0);
k->bo = create.out.handle;
k->va = ALIGN(dev.virtual_address_offset, 2ull << 20) + (2ull << 20);
va = (struct drm_amdgpu_gem_va){ .handle = k->bo, .operation = AMDGPU_VA_OP_MAP,
.flags = AMDGPU_VM_PAGE_READABLE | AMDGPU_VM_PAGE_WRITEABLE |
AMDGPU_VM_PAGE_EXECUTABLE,
.va_address = k->va, .map_size = BO_BYTES };
CHECK(call_async(k, DRM_IOCTL_AMDGPU_GEM_VA, &va) == 0);
gmap.in.handle = k->bo;
CHECK(call_async(k, DRM_IOCTL_AMDGPU_GEM_MMAP, &gmap) == 0);
uint64_t mmap_in[] = { MLG_LX_OP_MMAP, (uint64_t)k->fd, gmap.out.addr_ptr, BO_BYTES,
MLG_LX_PROT_READ | MLG_LX_PROT_WRITE, MLG_LX_MAP_SHARED };
CHECK(op(k, mmap_in, MLG_LX_OP_MMAP_ARGS, words) == 0);
k->ib = rt_lx_map_cpu(k->c, words[0], 0, &contiguous);
CHECK(k->ib && contiguous >= BO_BYTES);
/* Eight NOPs: whatever runs them (once the queue does) does nothing. */
k->ib_dw = 8;
for (uint32_t i = 0; i < k->ib_dw; ++i)
k->ib[i] = nop;
}
/* One AMDGPU_CS of the NOP IB on compute. */
static void cs_args(struct bc_client *k)
{
k->list[0] = (struct drm_amdgpu_bo_list_entry){ .bo_handle = k->bo };
k->list_in = (struct drm_amdgpu_bo_list_in){ .operation = ~0u, .list_handle = ~0u,
.bo_number = 1, .bo_info_size = sizeof(k->list[0]),
.bo_info_ptr = (uint64_t)(uintptr_t)k->list };
k->chunk_ib = (struct drm_amdgpu_cs_chunk_ib){ .ip_type = AMDGPU_HW_IP_COMPUTE,
.va_start = k->va, .ib_bytes = k->ib_dw * 4 };
k->chunks[0] = (struct drm_amdgpu_cs_chunk){ AMDGPU_CHUNK_ID_BO_HANDLES,
sizeof(k->list_in) / 4, (uint64_t)(uintptr_t)&k->list_in };
k->chunks[1] = (struct drm_amdgpu_cs_chunk){ AMDGPU_CHUNK_ID_IB, sizeof(k->chunk_ib) / 4,
(uint64_t)(uintptr_t)&k->chunk_ib };
k->chunk_ptrs[0] = (uint64_t)(uintptr_t)&k->chunks[0];
k->chunk_ptrs[1] = (uint64_t)(uintptr_t)&k->chunks[1];
k->cs = (union drm_amdgpu_cs){ .in = { .ctx_id = k->ctx, .num_chunks = 2,
.chunks = (uint64_t)(uintptr_t)k->chunk_ptrs } };
}
/* With the compute engine held: amdgpu_sched_jobs submissions are taken,
* and the next waits for the first, which never runs. */
static void block_a_submission(struct bc_client *k)
{
extern int amdgpu_sched_jobs;
for (int i = 0; i < amdgpu_sched_jobs; ++i) {
cs_args(k);
CHECK(call_async(k, DRM_IOCTL_AMDGPU_CS, &k->cs) == 0);
}
cs_args(k);
call_start_async(k, DRM_IOCTL_AMDGPU_CS, &k->cs, &k->blocked);
CHECK(!call_finished(k, &k->blocked, 300));
}
struct stop_done {
volatile int finished;
};
static void stop_finished(void *arg)
{
__atomic_store_n(&((struct stop_done *)arg)->finished, 1, __ATOMIC_RELEASE);
}
void blocked_call_check(struct pci_dev *pdev)
{
struct bc_client a, b;
struct stop_done stopped = { 0 };
ktime_t start = ktime_get();
client_open(pdev, "blocked-client", &a);
cs_fixture_hold_compute(1);
block_a_submission(&a);
/* The blocked client's process still takes a request that cannot
* sleep, and refuses one that can on the synchronous path. */
struct drm_syncobj_create sc = { 0 };
CHECK(call_sync(&a, DRM_IOCTL_SYNCOBJ_CREATE, &sc) == 0 && sc.handle);
cs_args(&a);
CHECK(call_sync(&a, DRM_IOCTL_AMDGPU_CS, &a.cs) == -EDEADLK);
union drm_amdgpu_ctx query = { .in = { .op = AMDGPU_CTX_OP_QUERY_STATE2, .ctx_id = a.ctx } };
CHECK(call_sync(&a, DRM_IOCTL_AMDGPU_CTX, &query) == -EDEADLK);
/* Another client works meanwhile: open, allocate, submit to the SDMA
* engine (the compute one is held) and see it complete. */
client_open(pdev, "other-client", &b);
struct drm_syncobj_create done = { 0 };
CHECK(call_sync(&b, DRM_IOCTL_SYNCOBJ_CREATE, &done) == 0);
cs_args(&b);
/* SDMA NOP (the fixture's SDMA NOP is a zero dword). */
uint32_t *sdma_ib = b.ib + 256;
memset(sdma_ib, 0, 8 * 4);
b.chunk_ib = (struct drm_amdgpu_cs_chunk_ib){ .ip_type = AMDGPU_HW_IP_DMA,
.va_start = b.va + 1024, .ib_bytes = 8 * 4 };
struct drm_amdgpu_cs_chunk_sem out = { .handle = done.handle };
struct drm_amdgpu_cs_chunk chunks[3] = { b.chunks[0], b.chunks[1],
{ AMDGPU_CHUNK_ID_SYNCOBJ_OUT, sizeof(out) / 4, (uint64_t)(uintptr_t)&out } };
uint64_t ptrs[3] = { (uint64_t)(uintptr_t)&chunks[0], (uint64_t)(uintptr_t)&chunks[1],
(uint64_t)(uintptr_t)&chunks[2] };
b.cs.in.num_chunks = 3;
b.cs.in.chunks = (uint64_t)(uintptr_t)ptrs;
CHECK(call_async(&b, DRM_IOCTL_AMDGPU_CS, &b.cs) == 0);
uint32_t handles[1] = { done.handle };
struct drm_syncobj_wait wait = { .handles = (uint64_t)(uintptr_t)handles,
.count_handles = 1, .flags = DRM_SYNCOBJ_WAIT_FLAGS_WAIT_ALL,
.timeout_nsec = (int64_t)(ktime_get_ns() + 5000000000ull) };
CHECK(call_async(&b, DRM_IOCTL_SYNCOBJ_WAIT, &wait) == 0);
/* Polling it is a request that cannot sleep. */
wait.timeout_nsec = 0;
CHECK(call_sync(&b, DRM_IOCTL_SYNCOBJ_WAIT, &wait) == 0);
CHECK(!completion_done(&a.blocked.done));
/* The blocked client stops (its process exits on a thread of its
* own); the Stop returns at once. */
on_call_thread();
CHECK(!rt_lx_client_retire(a.c, stop_finished, &stopped));
returned_at_once();
/* Its blocked call ends with the exit (the kill interrupts the
* wait); its work on the held engine keeps the exit going until
* the engine runs. Client b is unaffected. */
CHECK(wait_for_completion_timeout(&a.blocked.done, msecs_to_jiffies(5000)));
free(a.blocked.frame);
CHECK(call_sync(&b, DRM_IOCTL_SYNCOBJ_WAIT, &wait) == 0);
cs_fixture_hold_compute(0);
for (int i = 0; i < 1000 && !__atomic_load_n(&stopped.finished, __ATOMIC_ACQUIRE); ++i)
usleep(5000);
CHECK(__atomic_load_n(&stopped.finished, __ATOMIC_ACQUIRE));
rt_lx_retire_drain();
CHECK(rt_lx_retiring() == 0);
rt_lx_client_destroy(b.c);
printf("PASS blocked call: a submission waiting on a held queue keeps only its worker; "
"calls return at once, the blocked client's non-sleeping request runs and its "
"sleeping one is refused synchronously, another client opens, allocates and "
"completes work, the blocked client's Stop returns at once and its exit "
"finishes when its work does (%lld ms)\n",
(long long)ktime_ms_delta(ktime_get(), start));
}
/* ---- through a surprise removal (removal_check.c) ---- */
static struct bc_client parked;
static struct stop_done parked_stopped;
void blocked_call_park(struct pci_dev *pdev)
{
client_open(pdev, "removal-blocked", &parked);
/* The caller holds the compute engine. */
block_a_submission(&parked);
}
void blocked_call_after_removal(void)
{
/* Removal completed the held work, so the blocked submission went on
* (and failed against a device that is gone, or ran to nothing). */
CHECK(wait_for_completion_timeout(&parked.blocked.done, msecs_to_jiffies(2000)));
free(parked.blocked.frame);
on_call_thread();
CHECK(!rt_lx_client_retire(parked.c, stop_finished, &parked_stopped));
returned_at_once();
for (int i = 0; i < 400 && !__atomic_load_n(&parked_stopped.finished, __ATOMIC_ACQUIRE); ++i)
usleep(5000);
CHECK(__atomic_load_n(&parked_stopped.finished, __ATOMIC_ACQUIRE));
rt_lx_retire_drain();
CHECK(rt_lx_retiring() == 0);
printf("PASS blocked call through removal: the removal ends a submission blocked on a "
"held queue (result %lld) and the client's exit completes\n",
(long long)parked.blocked.result);
}
+16
View File
@@ -0,0 +1,16 @@
/* A Linux-file call blocked on a held GPU queue holds nothing but its own
* worker (blocked_call_check.c), on the CS fixture's device. */
#ifndef BLOCKED_CALL_CHECK_H
#define BLOCKED_CALL_CHECK_H
struct pci_dev;
/* The whole check; leaves the compute engine running. */
void blocked_call_check(struct pci_dev *pdev);
/* For removal_check: a client whose submission blocks on the (already
* held) compute engine, and, once the device is removed, the check that
* removal ended it and the client's exit completes. */
void blocked_call_park(struct pci_dev *pdev);
void blocked_call_after_removal(void);
#endif
+68 -21
View File
@@ -135,31 +135,63 @@ static void release_gathered(uint64_t type)
}
}
static int lb_open(void *ctx, uint32_t dev, uint32_t flags)
{
(void)ctx;
return rt_lx_open(client, dev, flags);
}
static int lb_close(void *ctx, int fd)
{
(void)ctx;
return rt_lx_close(client, fd);
}
static int lb_done(void *ctx, uint64_t token, int64_t result, const void *rbuf, size_t bytes)
static void lb_done(void *ctx, uint64_t token, int64_t result, const void *rbuf, size_t bytes)
{
struct waiter *w = ctx;
(void)token;
w->result = result;
w->bytes = bytes;
if (bytes <= w->cap)
if (!rbuf && bytes)
w->kept = 1; /* longer than the completion carries */
else if (bytes && bytes <= w->cap)
memcpy(w->rbuf, rbuf, bytes);
else
w->kept = 1;
complete(&w->done);
return !w->kept;
}
/* LX_CALL_ASYNC, as the IOKit transport makes it: on a worker, the reply
* (an MMAP's words) in @words. */
static int lb_op(const uint64_t *in, uint32_t nin, int64_t *result, uint64_t *words)
{
uint64_t reply[MLG_LX_OP_MMAP_WORDS] = { 0 };
struct waiter w = { .rbuf = reply, .cap = sizeof(reply) };
uint64_t token = 0;
int r;
__atomic_add_fetch(&async_calls, 1, __ATOMIC_SEQ_CST);
init_completion(&w.done);
r = rt_lx_op_async(client, in, nin, lb_done, &w, &token);
if (r)
return r;
wait_for_completion(&w.done);
if (w.kept)
return -EIO;
*result = w.result;
if (words)
memcpy(words, reply, sizeof(reply));
return 0;
}
static int lb_open(void *ctx, uint32_t dev, uint32_t flags)
{
uint64_t in[MLG_LX_OP_OPEN_ARGS] = { MLG_LX_OP_OPEN, dev, flags };
int64_t result = 0;
int r;
(void)ctx;
r = lb_op(in, MLG_LX_OP_OPEN_ARGS, &result, NULL);
return r ? r : (int)result;
}
static int lb_close(void *ctx, int fd)
{
uint64_t in[MLG_LX_OP_CLOSE_ARGS] = { MLG_LX_OP_CLOSE, (uint64_t)(int64_t)fd };
int64_t result = 0;
int r;
(void)ctx;
r = lb_op(in, MLG_LX_OP_CLOSE_ARGS, &result, NULL);
return r ? r : (int)result;
}
static int lb_ioctl(void *ctx, int fd, uint32_t cmd, const void *frame, size_t bytes, void *rbuf,
@@ -171,7 +203,8 @@ static int lb_ioctl(void *ctx, int fd, uint32_t cmd, const void *frame, size_t b
(void)ctx;
if (!async)
return rt_lx_ioctl(client, fd, cmd, frame, bytes, rbuf, cap, reply_bytes, result);
return rt_lx_ioctl_nosleep(client, fd, cmd, frame, bytes, rbuf, cap, reply_bytes,
result);
__atomic_add_fetch(&async_calls, 1, __ATOMIC_SEQ_CST);
init_completion(&w.done);
r = rt_lx_ioctl_async(client, fd, cmd, frame, bytes, lb_done, &w, &token);
@@ -188,22 +221,31 @@ static int lb_ioctl(void *ctx, int fd, uint32_t cmd, const void *frame, size_t b
static int lb_mmap(void *ctx, int fd, uint64_t offset, uint64_t length, uint32_t prot,
uint32_t flags, void **addr, uint64_t *handle)
{
uint64_t in[MLG_LX_OP_MMAP_ARGS] = { MLG_LX_OP_MMAP, (uint64_t)(int64_t)fd, offset, length,
prot, flags };
uint64_t words[MLG_LX_OP_MMAP_WORDS];
struct rt_lx_map_info info;
uint64_t contiguous = 0;
int64_t result = 0;
void *cpu;
int r;
(void)ctx;
r = rt_lx_mmap(client, fd, offset, length, prot, flags, &info);
r = lb_op(in, MLG_LX_OP_MMAP_ARGS, &result, words);
if (!r)
r = (int)result;
if (r)
return r;
info.type = words[0];
cpu = rt_lx_map_cpu(client, info.type, 0, &contiguous);
if (!cpu || contiguous < length) {
/* A BAR range or scattered pages: the dext maps those as a
* descriptor; the loopback gathers them with Mach VM. */
cpu = gather_mapping(info.type, length);
if (!cpu) {
rt_lx_munmap(client, info.type);
uint64_t un[MLG_LX_OP_MUNMAP_ARGS] = { MLG_LX_OP_MUNMAP, info.type };
(void)lb_op(un, MLG_LX_OP_MUNMAP_ARGS, &result, NULL);
return -ENODEV;
}
}
@@ -215,11 +257,16 @@ static int lb_mmap(void *ctx, int fd, uint64_t offset, uint64_t length, uint32_t
static int lb_munmap(void *ctx, uint64_t handle, void *addr, uint64_t length)
{
uint64_t in[MLG_LX_OP_MUNMAP_ARGS] = { MLG_LX_OP_MUNMAP, handle };
int64_t result = 0;
int r;
(void)ctx;
(void)addr;
(void)length;
release_gathered(handle);
return rt_lx_munmap(client, handle);
r = lb_op(in, MLG_LX_OP_MUNMAP_ARGS, &result, NULL);
return r ? r : (int)result;
}
static int lb_scanout(void *ctx, const struct mlg_lx_scanout *req, struct mlg_lx_scanout_state *state,
+5
View File
@@ -26,6 +26,7 @@
#include "amdgpu.h"
#include "amdgpu_ttm.h"
#include "cs_fixture.h"
#include "blocked_call_check.h"
extern int usleep(unsigned int usec);
@@ -70,6 +71,8 @@ void removal_check(struct pci_dev *pdev)
r = rt_cs_selftest_run(pdev, &res);
CHECK(r == -62 && res.status[RT_CS_STEP_TEARDOWN] == RT_CS_PARKED);
CHECK(rt_cs_selftest_parked() == 1);
/* A client's submission blocked behind that work. */
blocked_call_park(pdev);
/* A kernel copy on an engine that never runs it, waited for. */
CHECK(!amdgpu_bo_create_kernel(adev, 1 << 20, PAGE_SIZE, AMDGPU_GEM_DOMAIN_GTT,
@@ -101,6 +104,8 @@ void removal_check(struct pci_dev *pdev)
for (int i = 0; i < 200 && rt_cs_selftest_reap(); ++i)
usleep(5000);
CHECK(rt_cs_selftest_parked() == 0);
/* The blocked submission ended; its client's exit completes. */
blocked_call_after_removal();
/* The open client exits; a new one cannot open the render node. */
rt_lx_client_destroy(open_client);
CHECK(!rt_lx_client_create(pdev, 0, "late-client", &late));
+4
View File
@@ -10,6 +10,7 @@
extern int usleep(unsigned int usec);
#include <rt/cs_selftest.h>
#include "cs_fixture.h"
#include "blocked_call_check.h"
#define CHECK(c) do { if (!(c)) { fprintf(stderr, "%s:%d: CHECK failed: %s\n", \
__FILE__, __LINE__, #c); abort(); } } while (0)
@@ -91,6 +92,9 @@ int main(void)
usleep(10000);
CHECK(rt_cs_selftest_parked() == 0);
/* A call blocked on a held queue holds only its own worker. */
blocked_call_check(pdev);
/* Last: the device leaves the bus with work outstanding. */
removal_check(pdev);
+11 -5
View File
@@ -15,13 +15,17 @@ extern void klog_set_level(int);
extern void dev_printk_impl(const char *, const char *, const char *, ...);
#ifdef LINUXU_DEXT_DK
int IOLogv(const char *format, va_list arguments)
int IOLog(const char *format, ...)
{
// The platform sink may reenter diagnostics: the ring lock must already
// be released, and formatting must not have consumed the original args.
// be released.
uint64_t cursor = UINT64_MAX, end;
assert(!klog_read(&cursor, NULL, 0, &end) && cursor == end);
return vfprintf(stderr, format, arguments);
va_list arguments;
va_start(arguments, format);
int n = vfprintf(stderr, format, arguments);
va_end(arguments);
return n;
}
#endif
@@ -94,7 +98,8 @@ static void basic(void)
char emitted[128] = {0};
assert(pread(fileno(stderr), emitted, sizeof(emitted) - 1, 0) > 0);
#ifdef LINUXU_DEXT_DK
assert(!strcmp(emitted, "probe failed r=-19 fw=gc12"));
/* An error is an event: the unified log gets the retained record. */
assert(!strcmp(emitted, "mac.linuxgpu: EVENT <3> probe failed r=-19 fw=gc12\n"));
#else
assert(!strcmp(emitted, "<3> probe failed r=-19 fw=gc12\n"));
#endif
@@ -161,7 +166,8 @@ static void truncation(void)
fflush(stderr);
assert(!fstat(fileno(stderr), &after));
#ifdef LINUXU_DEXT_DK
assert(after.st_size - before.st_size == sizeof(oversized) - 1);
/* A warning is not an event: retained only. */
assert(after.st_size == before.st_size);
#else
assert(after.st_size - before.st_size == sizeof(oversized) + 4);
#endif
+157 -18
View File
@@ -262,6 +262,9 @@ void rt_lx_gem_unpin(void *pinned)
/* ---- the client side ---- */
/* Whether client_ioctl goes the way the driver's LX_IOCTL does. */
static int use_nosleep;
/* ioctl(2) as libmlg_drm issues it: describe, frame, call, copy back. */
static long client_ioctl(struct rt_lx_client *c, uint32_t dev, int fd, uint32_t cmd, void *arg)
{
@@ -282,7 +285,10 @@ static long client_ioctl(struct rt_lx_client *c, uint32_t dev, int fd, uint32_t
ktime_get_ns(), frame, sizeof(frame), &out_bytes);
if (len < 0)
return len;
r = rt_lx_ioctl(c, fd, cmd, frame, (size_t)len, rep, sizeof(rep), &rep_bytes, &result);
r = use_nosleep ?
rt_lx_ioctl_nosleep(c, fd, cmd, frame, (size_t)len, rep, sizeof(rep), &rep_bytes,
&result) :
rt_lx_ioctl(c, fd, cmd, frame, (size_t)len, rep, sizeof(rep), &rep_bytes, &result);
if (r)
return r;
CHECK(rep_bytes == mlg_lx_reply_bytes(out_bytes));
@@ -295,24 +301,29 @@ struct async_call {
long len;
uint64_t token;
int done;
int keep;
int kept; /* the reply did not come inline */
int64_t result;
uint8_t inline_rep[256];
size_t rep_bytes;
};
static int async_done(void *ctx, uint64_t token, int64_t result, const void *rbuf,
size_t reply_bytes)
static void async_done(void *ctx, uint64_t token, int64_t result, const void *rbuf,
size_t reply_bytes)
{
struct async_call *a = ctx;
CHECK(token);
a->result = result;
a->rep_bytes = reply_bytes;
if (!a->keep && reply_bytes <= sizeof(a->inline_rep))
memcpy(a->inline_rep, rbuf, reply_bytes);
if (rbuf || !reply_bytes) {
CHECK(reply_bytes <= MLG_LX_ASYNC_INLINE_BYTES && reply_bytes <= sizeof(a->inline_rep));
if (reply_bytes)
memcpy(a->inline_rep, rbuf, reply_bytes);
} else {
CHECK(reply_bytes > MLG_LX_ASYNC_INLINE_BYTES);
a->kept = 1;
}
__atomic_store_n(&a->done, 1, __ATOMIC_SEQ_CST);
return !a->keep;
}
static int start_async(struct rt_lx_client *c, int fd, uint32_t cmd, void *arg,
@@ -322,7 +333,6 @@ static int start_async(struct rt_lx_client *c, int fd, uint32_t cmd, void *arg,
uint64_t timeout_va = 0;
uint32_t n = 0;
CHECK(mlg_lx_cmd_blocks(MLG_LX_DEV_RENDER, cmd));
CHECK(!mlg_lx_describe(MLG_LX_DEV_RENDER, cmd, (uint64_t)(uintptr_t)arg, spans, 16, &n,
&timeout_va));
a->len = mlg_lx_encode(cmd, (uint64_t)(uintptr_t)arg, spans, n, timeout_va,
@@ -481,35 +491,166 @@ int main(void)
CHECK(client_ioctl(b, MLG_LX_DEV_RENDER, 1, DRM_IOCTL_GEM_CLOSE, &gc) == -EBADF);
}
/* Async waits: a signal ends one; the result waits to be fetched. */
/* Async waits: a signal ends one; its result comes with the
* completion. A longer result waits to be fetched. */
{
uint32_t handle = 5;
struct drm_syncobj_wait w = { .handles = (uint64_t)(uintptr_t)&handle,
.timeout_nsec = (int64_t)ms_from_now(10000),
.count_handles = 1, .first_signaled = 77 };
struct async_call *call = calloc(1, sizeof(*call));
call->keep = 1;
CHECK(mlg_lx_cmd_sleeps(MLG_LX_DEV_RENDER, DRM_IOCTL_SYNCOBJ_WAIT, NULL, 0));
CHECK(!start_async(a, fd_a, DRM_IOCTL_SYNCOBJ_WAIT, &w, call));
CHECK(mlg_lx_cmd_sleeps(MLG_LX_DEV_RENDER, DRM_IOCTL_SYNCOBJ_WAIT, call->frame,
(size_t)call->len));
wait_waiters(1);
CHECK(!call->done && rt_lx_async_outstanding(a) == 1);
uint8_t rep[256];
uint8_t rep[512];
size_t rep_bytes = 0;
int64_t result = 1;
CHECK(rt_lx_result(a, call->token, rep, sizeof(rep), &rep_bytes, &result) == -EBUSY);
__atomic_store_n(&signaled, 5, __ATOMIC_SEQ_CST);
wake_up_all(&syncobj_wq);
wait_done(call);
CHECK(call->result == 0);
CHECK(call->result == 0 && !call->kept);
CHECK(!mlg_lx_apply_reply(call->frame, (size_t)call->len, call->inline_rep,
call->rep_bytes, &result));
CHECK(w.first_signaled == 0);
CHECK(rt_lx_result(a, call->token, rep, sizeof(rep), &rep_bytes, &result) == -ENOENT);
CHECK(rt_lx_async_outstanding(a) == 0);
/* DRM_IOCTL_VERSION with long strings: a reply past the
* completion's inline bytes, kept until fetched. */
char vname[200] = {0}, vdate[16] = {0}, vdesc[16] = {0};
struct drm_version v = { .name_len = sizeof(vname), .name = vname,
.date_len = sizeof(vdate), .date = vdate,
.desc_len = sizeof(vdesc), .desc = vdesc };
memset(call, 0, sizeof(*call));
CHECK(!start_async(a, fd_a, DRM_IOCTL_VERSION, &v, call));
wait_done(call);
CHECK(call->kept && call->result == 0);
CHECK(rt_lx_async_outstanding(a) == 1);
CHECK(rt_lx_result(a, call->token, rep, 8, &rep_bytes, &result) == -ENOSPC);
CHECK(!rt_lx_result(a, call->token, rep, sizeof(rep), &rep_bytes, &result));
CHECK(result == 0 && rep_bytes == call->rep_bytes);
CHECK(!mlg_lx_apply_reply(call->frame, (size_t)call->len, rep, rep_bytes, &result));
CHECK(w.first_signaled == 0);
CHECK(!strcmp(vname, "fixture") && v.name_len == 7);
CHECK(rt_lx_result(a, call->token, rep, sizeof(rep), &rep_bytes, &result) == -ENOENT);
CHECK(rt_lx_async_outstanding(a) == 0);
free(call);
}
/* The incoming-call thread runs only requests that cannot sleep:
* a syncobj wait that polls does, one with a deadline is refused
* without running, and so is anything not on the list. */
{
uint32_t handle = 5;
struct drm_syncobj_wait w = { .handles = (uint64_t)(uintptr_t)&handle,
.count_handles = 1, .first_signaled = 77 };
struct drm_gem_close gc = { .handle = 7 };
char vname[16] = {0};
struct drm_version v = { .name_len = sizeof(vname), .name = vname };
uint8_t out[8];
struct drm_amdgpu_info info = { .return_pointer = (uint64_t)(uintptr_t)out,
.return_size = 8, .query = AMDGPU_INFO_DEV_INFO };
int64_t past = (int64_t)ktime_get_ns() - 1000000;
use_nosleep = 1;
__atomic_store_n(&signaled, 0, __ATOMIC_SEQ_CST);
/* Zero, negative and past deadlines poll. */
w.timeout_nsec = 0;
CHECK(client_ioctl(a, MLG_LX_DEV_RENDER, fd_a, DRM_IOCTL_SYNCOBJ_WAIT, &w) == -ETIME);
w.timeout_nsec = -1;
CHECK(client_ioctl(a, MLG_LX_DEV_RENDER, fd_a, DRM_IOCTL_SYNCOBJ_WAIT, &w) == -ETIME);
w.timeout_nsec = past;
CHECK(client_ioctl(a, MLG_LX_DEV_RENDER, fd_a, DRM_IOCTL_SYNCOBJ_WAIT, &w) == -ETIME);
CHECK(client_ioctl(a, MLG_LX_DEV_RENDER, fd_a, DRM_IOCTL_VERSION, &v) == 0);
/* A future deadline, a GEM close, an INFO: refused, not run. */
w.timeout_nsec = (int64_t)ms_from_now(10000);
CHECK(client_ioctl(a, MLG_LX_DEV_RENDER, fd_a, DRM_IOCTL_SYNCOBJ_WAIT, &w) == -EDEADLK);
CHECK(__atomic_load_n(&waiters, __ATOMIC_SEQ_CST) == 0);
CHECK(client_ioctl(a, MLG_LX_DEV_RENDER, fd_a, DRM_IOCTL_GEM_CLOSE, &gc) == -EDEADLK);
memset(out, 0xee, sizeof(out));
CHECK(client_ioctl(a, MLG_LX_DEV_RENDER, fd_a, DRM_IOCTL_AMDGPU_INFO, &info) == -EDEADLK);
CHECK(out[0] == 0xee);
use_nosleep = 0;
/* The table itself, on frames as the client builds them (the
* fixture left VERSION's lengths at its strings'). */
v = (struct drm_version){ .name_len = sizeof(vname), .name = vname };
struct { uint32_t cmd; void *arg; int sleeps; } table[] = {
{ DRM_IOCTL_VERSION, &v, 0 },
{ DRM_IOCTL_GEM_CLOSE, &gc, 1 },
{ DRM_IOCTL_AMDGPU_INFO, &info, 1 },
};
for (unsigned i = 0; i < sizeof(table) / sizeof(table[0]); ++i) {
struct async_call *call = calloc(1, sizeof(*call));
struct mlg_lx_span spans[16];
uint64_t tva = 0;
uint32_t n = 0;
CHECK(!mlg_lx_describe(MLG_LX_DEV_RENDER, table[i].cmd,
(uint64_t)(uintptr_t)table[i].arg, spans, 16, &n, &tva));
call->len = mlg_lx_encode(table[i].cmd, (uint64_t)(uintptr_t)table[i].arg, spans,
n, tva, ktime_get_ns(), call->frame,
sizeof(call->frame), NULL);
CHECK(call->len > 0);
CHECK(mlg_lx_cmd_sleeps(MLG_LX_DEV_RENDER, table[i].cmd, call->frame,
(size_t)call->len) == table[i].sleeps);
free(call);
}
CHECK(!mlg_lx_cmd_sleeps(MLG_LX_DEV_KFD, AMDKFD_IOC_GET_VERSION, &w, sizeof(struct mlg_lx_frame)));
CHECK(mlg_lx_cmd_sleeps(MLG_LX_DEV_KFD, AMDKFD_IOC_CREATE_QUEUE, &w, sizeof(struct mlg_lx_frame)));
CHECK(mlg_lx_cmd_sleeps(MLG_LX_DEV_RENDER, DRM_IOCTL_AMDGPU_CS, &w, sizeof(struct mlg_lx_frame)));
}
/* LX_CALL_ASYNC: open, mmap, munmap and close on workers. */
{
struct async_call *call = calloc(1, sizeof(*call));
uint64_t open_in[] = { MLG_LX_OP_OPEN, MLG_LX_DEV_KFD, MLG_LX_O_RDWR };
uint64_t bad[] = { MLG_LX_OP_OPEN, MLG_LX_DEV_KFD };
uint64_t unknown[] = { 9, 0 };
uint64_t token = 0;
int fd;
CHECK(rt_lx_op_async(a, bad, 2, async_done, call, &token) == -EINVAL);
CHECK(rt_lx_op_async(a, unknown, 2, async_done, call, &token) == -EINVAL);
CHECK(!rt_lx_op_async(a, open_in, 3, async_done, call, &call->token));
wait_done(call);
fd = (int)call->result;
CHECK(fd >= 2 && call->rep_bytes == 0);
uint64_t mmap_in[] = { MLG_LX_OP_MMAP, (uint64_t)fd, 0, PAGE_SIZE,
MLG_LX_PROT_READ | MLG_LX_PROT_WRITE, MLG_LX_MAP_SHARED };
memset(call, 0, sizeof(*call));
CHECK(!rt_lx_op_async(a, mmap_in, 6, async_done, call, &call->token));
wait_done(call);
CHECK(call->result == 0 && call->rep_bytes == MLG_LX_OP_MMAP_WORDS * 8);
uint64_t words[MLG_LX_OP_MMAP_WORDS];
memcpy(words, call->inline_rep, sizeof(words));
CHECK(words[0] >= MLG_LX_MMAP_TYPE_BASE && words[1] == PAGE_SIZE);
struct rt_lx_map_info mi;
CHECK(!rt_lx_map_info(a, words[0], &mi) && mi.backing == RT_LX_RANGE_BAR);
uint64_t munmap_in[] = { MLG_LX_OP_MUNMAP, words[0] };
memset(call, 0, sizeof(*call));
CHECK(!rt_lx_op_async(a, munmap_in, 2, async_done, call, &call->token));
wait_done(call);
CHECK(call->result == 0 && rt_lx_map_info(a, words[0], &mi) == -ENOENT);
uint64_t close_in[] = { MLG_LX_OP_CLOSE, (uint64_t)fd };
memset(call, 0, sizeof(*call));
CHECK(!rt_lx_op_async(a, close_in, 2, async_done, call, &call->token));
wait_done(call);
CHECK(call->result == 0);
memset(call, 0, sizeof(*call));
CHECK(!rt_lx_op_async(a, close_in, 2, async_done, call, &call->token));
wait_done(call);
CHECK(call->result == -EBADF);
CHECK(rt_lx_async_outstanding(a) == 0);
free(call);
}
/* The deadline crosses clocks as time left: 60 ms from now on ours
* expires about 60 ms later in the process. */
{
@@ -544,7 +685,6 @@ int main(void)
s->w[i] = (struct drm_syncobj_wait){ .handles = (uint64_t)(uintptr_t)&s->handle[i],
.timeout_nsec = (int64_t)ms_from_now(10000), .count_handles = 1,
.first_signaled = 99 };
calls[i].keep = 0;
}
for (unsigned i = 0; i < MLG_LX_MAX_ASYNC; ++i)
CHECK(!start_async(a, fd_a, DRM_IOCTL_SYNCOBJ_WAIT, &s->w[i], &calls[i]));
@@ -637,7 +777,7 @@ int main(void)
}
/* close(2) runs the file's release once its last reference goes. */
CHECK(rt_lx_close(a, fd_kfd) == 0 && releases == 1);
CHECK(rt_lx_close(a, fd_kfd) == 0 && releases == 2);
CHECK(rt_lx_close(a, fd_kfd) == -EBADF);
/* Teardown with a wait in flight: the kill ends it (EINTR), its
@@ -648,12 +788,11 @@ int main(void)
.timeout_nsec = (int64_t)ms_from_now(60000),
.count_handles = 1 };
struct async_call *call = calloc(1, sizeof(*call));
call->keep = 1; /* never fetched: dropped by the teardown */
CHECK(!start_async(a, fd_a, DRM_IOCTL_SYNCOBJ_WAIT, &w, call));
wait_waiters(1);
rt_lx_client_destroy(a);
CHECK(call->done && call->result == -EINTR);
CHECK(releases == 2); /* a's render file; b's stays open */
CHECK(releases == 3); /* a's render file; b's stays open */
free(call);
}
/* Hop timing: the device's mlg_lx_timing file, added once, shows the
@@ -672,7 +811,7 @@ int main(void)
CHECK(rt_lx_timing_show(text, 8) < 8); /* bounded */
}
rt_lx_client_destroy(b);
CHECK(releases == 3 && opens == 3);
CHECK(releases == 4 && opens == 4);
unregister_chrdev(DRM_MAJOR, "drm");
puts("PASS lx files: per-client processes and descriptors, nested ioctl memory, faults, "
"admission, async waits (signal, timeout, kill), shared argument pages, mmap, teardown");
+4
View File
@@ -32,6 +32,7 @@ static void platformLogSink(const char *text) {
platformLog += text;
}
#define MACLINUXGPU_LOG(...) maclinuxgpu::RetainedLog(platformLogSink, __VA_ARGS__)
#define MACLINUXGPU_EVENT(...) maclinuxgpu::RetainedEvent(platformLogSink, __VA_ARGS__)
static std::string retainedLog() {
char bytes[LINUXU_KLOG_CAPACITY];
@@ -54,6 +55,9 @@ static void checkLogFormat() {
MACLINUXGPU_LOG("%s", large.c_str());
assert(platformLog.size() - before == LINUXU_KLOG_MESSAGE_CAPACITY - 1);
expectLog("... [truncated]\n");
// Events carry the prefix the unified-log predicate matches.
MACLINUXGPU_EVENT("device removed (%s)", "test");
expectLog("mac.linuxgpu: EVENT device removed (test)\n");
}
static std::vector<std::string> events;
+1 -1
View File
@@ -36,7 +36,7 @@ for source in third_party/linux/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c \
done
clang "${cflags[@]}" -fsanitize=address \
linuxu/tests/test_cs_selftest.c linuxu/tests/cs_fixture.c linuxu/tests/ttm_evict_check.c \
linuxu/tests/removal_check.c \
linuxu/tests/removal_check.c linuxu/tests/blocked_call_check.c \
"${plain[@]}" build/libmacamgdu.a \
-lpthread -o "$work/test_cs_selftest"
# CS_SELFTEST_KEEP=<path> keeps the binary for a debugger; CS_FIXTURE_TRACE=1
+2 -1
View File
@@ -5,7 +5,8 @@ test_dir=$(mktemp -d)
trap 'rm -rf "$test_dir"' EXIT
clang -w -std=gnu11 -D__KERNEL__ -include linux/autoconf.h -include linux/compiler.h -g -O1 -fsanitize=address,undefined \
-fno-sanitize-recover=all -ffunction-sections -fdata-sections -Ilinuxu/headers \
linuxu/tests/test_primitive_headers.c linuxu/src/shims/printk.c third_party/linux/lib/sort.c \
linuxu/tests/test_primitive_headers.c linuxu/src/shims/printk.c linuxu/src/shims/dev_coredump.c \
third_party/linux/lib/sort.c \
-Wl,-dead_strip -lpthread -o "$test_dir/test_primitive_headers"
"$test_dir/test_primitive_headers"
cat > "$test_dir/assertion.c" <<'SRC'
+1 -1
View File
@@ -22,7 +22,7 @@ driver_stop = section("kern_return_t\nIMPL(MacLinuxGPU, Stop)", "void\nMacLinuxG
finish = section("void\nMacLinuxGPU::FinishSession()", "void\nMacLinuxGPU::FinishStop(IOService *provider)", 100)
client_stop = section("kern_return_t\nIMPL(MacLinuxGPUUserClient, Stop)", "void\nMacLinuxGPUUserClient::FinishStop(IOService *provider)", 50)
shutdown = section(" case kMacAMDGPUMethodShutdownGPU: {", " case kMacAMDGPUMethodGetReBARInfo: {", 40)
probe_failure = section(" if (s_probeResult != 0) {", ' MACLINUXGPU_LOG("upstream AMDGPU PCI probe completed");', 20)
probe_failure = section(" if (s_probeResult != 0) {", ' MACLINUXGPU_EVENT("upstream AMDGPU PCI probe completed");', 20)
wrapper = """
kern_return_t MacLinuxGPUUserClient::shutdown(IOUserClientMethodArguments *arguments)
{