Skip to content

Instantly share code, notes, and snippets.

View victoryang00's full-sized avatar
🔥
Passionate

Yiwei Yang victoryang00

🔥
Passionate
View GitHub Profile

AGX coherency, caching, and TLBs

These are just some notes on my current understanding of the subtleties of the AGX memory model and the TLB/caching issues I'm seeing.

Hypervisor shenanigans

TLBI instructions do not broadcast to the GPU from EL1 with stage 2 translation enabled. That's it. That's what the bug was.

GPU side

@moyix
moyix / ensure_fpu.py
Last active August 13, 2024 21:08
Some handy utils for messing with MXCSR (x86-64 SSE FPU control register)
#!/usr/bin/env python
import sys, os
import platform
import ctypes as ct
import mmap
from enum import Enum
import importlib
import functools
import errno
@Victrid
Victrid / gitgraft.sh
Created August 29, 2022 17:09
Find which commit your no-git friend is working on and generate patches for attaching their works onto git tree.
#!/bin/bash
hash git 2>/dev/null || { echo >&2 "Required command 'git' is not installed. ( hmm... why are you using this? ) Aborting."; exit 1; }
hash realpath 2>/dev/null || { echo >&2 "Required command 'realpath' is not installed. Aborting."; exit 1; }
hash pwd 2>/dev/null || { echo >&2 "Required command 'pwd' is not installed. Aborting."; exit 1; }
hash cd 2>/dev/null || { echo >&2 "Required command 'cd' is not installed. Aborting."; exit 1; }
hash echo 2>/dev/null || { echo >&2 "Required command 'echo' is not installed. Aborting."; exit 1; }
hash mv 2>/dev/null || { echo >&2 "Required command 'mv' is not installed. Aborting."; exit 1; }
hash diff 2>/dev/null || { echo >&2 "Required command 'diff' is not installed. Aborting."; exit 1; }
hash diffstat 2>/dev/null || { echo >&2 "Required command 'diffstat' is not installed. Aborting."; exit 1; }
#include <stdio.h>
#include <stdlib.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <fcntl.h>
int main() {
int fd = shm_open("test-shm", O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
if (fd == -1) {
printf("Unable to open shm\n");

Summary

Panics which happen inside a Drop impl currently unwind as long as the drop was not itself called during unwinding (which would otherwise abort immediated due to a double-panic). This design meeting proposes to change this behavior to always abort if a panic attempts to escape a drop, even if this drop was invoked as part of normal function execution (as opposed to unwinding).

The dicussion on this issue dates back to 2014 (rust-lang/rust#14875) where the decision was made to support unwinding in drops but leave the door open to potentially reversing this decision.

Background reading

rust-lang/rust#86027

@joseluisq
joseluisq / resize_disk_image.md
Last active November 15, 2024 08:13
How to resize a qcow2 disk image on Linux

How to resize a qcow2 disk image on Linux

This example takes olddisk.qcow2 and resizes it into newdisk.qcow2, extending one of the guest's partitions to fill the extra space.

1. qcow2 format

1.1. Verify the filesystems of olddisk.qcow2

# IDA (disassembler) and Hex-Rays (decompiler) plugin for Apple AMX
#
# WIP research. (This was edited to add more info after someone posted it to
# Hacker News. Click "Revisions" to see full changes.)
#
# Copyright (c) 2020 dougallj
# Based on Python port of VMX intrinsics plugin:
# Copyright (c) 2019 w4kfu - Synacktiv
@saagarjha
saagarjha / fixjit.c
Last active July 3, 2024 15:56
Fix applications that use JIT on Apple silicon but don't know about pthread_jit_write_protect_np
// The usual: compile with clang libfixjit.c -arch arm64 -arch arm64e -shared -o libfixjit.dylib, add to DYLD_INSERT_LIBRARIES.
#include <errno.h>
#include <pthread.h>
#include <stdatomic.h>
__attribute__((constructor)) static void fix_jit() {
unsigned long long mask;
__asm__ volatile("mrs %0, s3_4_c15_c2_7" : "=r"(mask): :);
__asm__ volatile("msr s3_4_c15_c2_7, %0" : : "r"(mask & 0xfffffffff0ffffff) :);
@k-amin07
k-amin07 / VFIO.md
Last active October 26, 2024 02:50
VFIO Guide for GPU Passthrough

Introduction:

This guide is for achieving PCI-Passthrough with Intel 7700k and AMD RX 580. My host OS is Manjaro KDE edition, and guest is Windows 10.

Hardware:

Device Type Device
CPU Intel Core i7-7700K
Motherboard ASUS Prime Z270P
RAM Corsair Vengeance (DDR4 3000 MHz)
GPU (Host) Intel HD Graphics
@andyfaff
andyfaff / Python_openmp_notes.md
Last active April 11, 2024 15:09
Investigating openmp on macOS.

Investigating use of openmp on macOS for Python related things

This assumes you have installed the command line tools on macOS. The first two sections look into installing OpenMP from scratch. However, on macOS it might be easier just to use homebrew.

Install cmake

  1. Download source from https://github.com/Kitware/CMake/releases/download/v3.15.1/cmake-3.15.1.tar.gz (there may be a later release).
  2. Untar the files: tar xzvf cmake-3.15.1.tar.gz