{"id":17944811,"url":"https://github.com/typicalam/ivshmem","last_synced_at":"2025-03-24T18:32:22.762Z","repository":{"id":193622389,"uuid":"689010359","full_name":"TypicalAM/ivshmem","owner":"TypicalAM","description":"Levarage shared memory buffers between QEMU VMs in go","archived":false,"fork":false,"pushed_at":"2024-08-15T11:05:28.000Z","size":35,"stargazers_count":7,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-19T04:05:22.123Z","etag":null,"topics":["golang","ivshmem","qemu","windows"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/TypicalAM.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-09-08T15:26:39.000Z","updated_at":"2024-11-13T12:11:44.000Z","dependencies_parsed_at":"2024-08-11T17:28:27.501Z","dependency_job_id":null,"html_url":"https://github.com/TypicalAM/ivshmem","commit_stats":null,"previous_names":["typicalam/ivshmem"],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TypicalAM%2Fivshmem","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TypicalAM%2Fivshmem/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TypicalAM%2Fivshmem/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TypicalAM%2Fivshmem/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/TypicalAM","download_url":"https://codeload.github.com/TypicalAM/ivshmem/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245328368,"owners_count":20597407,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["golang","ivshmem","qemu","windows"],"created_at":"2024-10-29T06:05:10.848Z","updated_at":"2025-03-24T18:32:22.510Z","avatar_url":"https://github.com/TypicalAM.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Inter-VM Shared Memory\n\nExchange info with very low latency using Inter-VM Shared Memory (IVSHMEM). This project aims to help interface communication between go programs between host machines and `qemu` virtual machine instances.\n\n## Getting started\n\nIn order to use the ivshmem device, we need to enable it. If you are using `libvirt` (`virt-manager`) to manege your `qemu` instances, add the following line to your [xml config](https://libvirt.org/formatdomain.html#shared-memory-device):\n\n```xml\n\u003cshmem name='my-little-shared-memory'\u003e\n  \u003cmodel type='ivshmem-plain'/\u003e\n  \u003csize unit='M'\u003e64\u003c/size\u003e\n\u003c/shmem\u003e\n```\n\nIf you are using raw `qemu`, use the following cmd args:\n\n```bash\n-device ivshmem-plain,memdev=ivshmem,bus=pcie.0 \\\n-object memory-backend-file,id=ivshmem,share=on,mem-path=/dev/shm/my-little-shared-memory,size=64M\n```\n\nAdjust the `size` parameter as needed, in this example we choose 64MB. \n\n### Example host code\n\nFor now only linux hosts are supported, if you want to add windows host support - feel free to contribute.\n\n```go\n//go:build linux\n\npackage main\n\nimport (\n\t\"github.com/TypicalAM/ivshmem\"\n\t\"fmt\"\n)\n\nfunc main() {\n\th, _ := ivshmem.NewHost(\"/dev/shm/my-little-shared-memory\")\n\th.Map()\n\tdefer h.Unmap()\n\n\tfmt.Println(\"Shared mem size:\", h.Size())\n\tfmt.Println(\"Device path: \", h.DevPath())\n\n\tmem := h.SharedMem()\n\tmsg := []byte(\"Hello world!\")\n\tcopy(mem, msg)\n\n\th.Sync()\n\tfmt.Println(\"Write successful\")\n}\n```\n\n### Example guest code (windows)\n\n\u003e [!IMPORTANT]\n\u003e Windows guests communicate with the `ivshmem` device using a special driver. It can be downloaded [here](https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/upstream-virtio/) from the fedora website\n\nExample guest code:\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"github.com/TypicalAM/ivshmem\"\n)\n\nfunc main() {\n\tdevs, _ := ivshmem.ListDevices()\n\tg, _ := ivshmem.NewGuest(devs[0])\n\tg.Map()\n\tdefer g.Unmap()\n\n\tfmt.Println(\"We are on:\", g.System())\n\tfmt.Println(\"Detected IVSHMEM devices:\", devs)\n\tfmt.Println(\"Selected IVSHMEM device:\", g.Location())\n\tfmt.Println(\"Device path:\", g.DevPath())\n\tfmt.Println(\"Shared mem size (in MB):\", g.Size()/1024/1024)\n\n\tmem := g.SharedMem()\n\tbuf := make([]byte, 12)\n\tcopy(buf, mem)\n\n\tfmt.Println(\"Message from host:\", string(buf))\n}\n\n```\n\n**This results in the following output:**\n\nOn host:\n\n```\nShared mem size (in MB): 64\nDevice path: /dev/shm/my-little-shared-memory\nWrite successful\n```\n\nOn guest (linux):\n\n```\nWe are on: Linux\nDetected IVSHMEM devices: [PCI bus 8, device 1, function 0]\nSelected IVSHMEM device: PCI bus 8, device 1, function 0\nDevice path: /sys/bus/pci/devices/0000:08:01.0/resource2\nShared mem size (in MB): 64\nMessage from host: Hello world!\n```\n\nOn guest (windows):\n\n```\nWe are on: Windows\nDetected IVSHMEM devices: [PCI bus 4, device 1, function 0 PCI bus 9, device 1, function 0]\nSelected IVSHMEM device: PCI bus 9, device 1, function 0\nDevice path: \\\\?\\pci#ven_1af4\u0026dev_1110\u0026subsys_1100...\nShared mem size (in MB): 64\nMessage from host: Hello world!\n```\n\n\u003e [!TIP]\n\u003e The emulated PCI bus values will usually be mismatched with the configuration options - they might have different bus numbers. This is normal and you should not rely on bus values from the `qemu` config - instead use the provided `ivshmem.ListDevices()`\n\n### FAQ\n\n- Why no CGO?\n  - We would only need C to map the memory (only on windows). We might as well just use syscalls for that and not require a C compiler. Most of the functions we need are in the `golang.org/x/sys/windows` package, only needing to load one dll.\n\n- Why use this when I can communicate using the network?\n  - Why anything? Also, shared memory is very low latency. If you need speed (I've done transfers over easily 2.4 Gbps on my machine) this could be the solution. \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftypicalam%2Fivshmem","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftypicalam%2Fivshmem","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftypicalam%2Fivshmem/lists"}