mirror of
https://github.com/lemonade-sdk/mac_linuxgpu.git
synced 2026-11-25 02:45:47 -10:00
Unplugging the GPU with the display live panicked the Mac on 239 and 240 (LLC bus error, NC write, in the dext). On 240 the panicked thread was in an atomic commit powering the display down after the agent's framebuffers were removed: dmub_srv_fb_cmd_execute, with dmub_rb_push_front having stored the command into DMUB's inbox in VRAM one byte at a time through the dext's user-space mapping of BAR0. The removal was already under way (Stop, removal_main, the aperture gate set); the error is reported only after the store has retired, so no check before a store can prevent it. Register accesses, through the kernel's IOPCIDevice MemoryRead/Write, ran in the same commit after the link went down and never faulted. So every access to the VRAM aperture goes through the kernel: rt/aperture.h's read/write/copy/fill route through ops the dext installs with the PCI device (BAR0 MemoryRead/MemoryWrite 8 to 64 bits, BAR0's index and size read once). linux/io.h's readX/writeX, memcpy_toio, memcpy_fromio and memset_io, the 64-bit MMIO atomics and the string functions (memcpy, memset, memmove, memcmp) route aperture addresses through them; the gate still skips writes and reads all ones once the device is known gone. The GART page table in VRAM, written with writeq on every GTT bind, now goes this way too. dmub_cmd.h's inline dmub_rb_push_front (a byte loop) and dmub_rb_flush_pending (READ_ONCE) reach the inbox with plain pointer accesses no shim can route. A declared compile intervention for dmub_srv.c (rt/dmub_inbox.h) includes dmub_cmd.h first and redirects its two calls to the same operations written with dmub_memcpy, as upstream's dmub_rb_out_push_front copies. Upstream sources stay unchanged. Offline proof: the CS fixture gives the driver VRAM only as a no-access alias of its pages, reached through the aperture's ops; the host library's upstream objects alias the string functions as the dext's do. Any direct load or store through a kernel VRAM pointer now crashes the offline tests. With the two DMUB helpers redirected, every test passes: the display pipeline (with its removal check now on the fixture's real aperture), scanout, surface import, CS selftest, KFD and the rest.
55 lines
2.8 KiB
C
55 lines
2.8 KiB
C
/* The VRAM aperture's accesses (declarations only; device_string.c). Kept
|
|
* apart from rt/device_string.h, which also aliases the string functions,
|
|
* so linux/io.h can route through it without the aliases. */
|
|
#ifndef LINUXU_RT_APERTURE_H
|
|
#define LINUXU_RT_APERTURE_H
|
|
#include <stddef.h>
|
|
#include <stdint.h>
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
/* The VRAM aperture: the address range kernel VRAM mappings (amdgpu's
|
|
* aper_base_kaddr, TTM kmaps) point into. A CPU store or load through a
|
|
* user-space mapping of the BAR to a device that has left the bus (a
|
|
* Thunderbolt unplug) is not an error the process can see: on Apple
|
|
* silicon it is an uncorrectable bus error that panics the Mac, and it is
|
|
* reported only after the store retired, so no check before the store can
|
|
* prevent it (build 240's panic: the DMUB inbox push, with the removal
|
|
* already under way). So no access goes through such a mapping: every
|
|
* access to the aperture goes through @ops (the dext: the kernel's
|
|
* IOPCIDevice MemoryRead/MemoryWrite on BAR0, which register accesses
|
|
* have always used, through unplugs, without a fault). The string
|
|
* functions below and linux/io.h's accessors route through it; a direct
|
|
* dereference of an aperture pointer is a bug (the CS fixture backs the
|
|
* aperture with no-access memory so the offline tests find any).
|
|
*
|
|
* Without @ops the aperture is plain memory (host tests of the gate).
|
|
* Once the device is known gone (linuxu_aperture_gone), writes are
|
|
* skipped and reads return all ones, without a kernel call. */
|
|
struct linuxu_aperture_ops {
|
|
/* @width (1, 2, 4 or 8, aligned) bytes at byte @offset into the aperture. */
|
|
void (*read)(uint64_t offset, void *value, unsigned int width);
|
|
void (*write)(uint64_t offset, const void *value, unsigned int width);
|
|
};
|
|
void linuxu_aperture_set(uintptr_t base, uint64_t size);
|
|
void linuxu_aperture_set_ops(const struct linuxu_aperture_ops *ops);
|
|
void linuxu_aperture_gone(const char *why);
|
|
int linuxu_aperture_is_gone(void);
|
|
int linuxu_aperture_contains(const volatile void *address, size_t size);
|
|
void linuxu_aperture_read(const volatile void *address, void *value, unsigned int width);
|
|
void linuxu_aperture_write(volatile void *address, const void *value, unsigned int width);
|
|
void linuxu_aperture_copy_in(volatile void *destination, const void *source, size_t size);
|
|
void linuxu_aperture_copy_out(void *destination, const volatile void *source, size_t size);
|
|
void linuxu_aperture_fill(volatile void *destination, int value, size_t size);
|
|
struct linuxu_aperture_stats {
|
|
unsigned long long stores, loads; /* operations into and out of it */
|
|
unsigned long long skipped; /* refused once gone */
|
|
unsigned long long calls; /* accesses through the ops */
|
|
};
|
|
void linuxu_aperture_stats(struct linuxu_aperture_stats *out);
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
#endif
|