This patch builds on a previous one to track linear maps
and adds new OSv specific pseudo file /sys/osv/memory/linear_maps:

 x86_64 example)
        0x40200000           0x200000       7c7434 rwxp n kernel
0xffff800000000000                  0     40000000 rwxp n main
0xffff8000000f0000            0xf0000        10000 rwxp n dmi
0xffff8000000f5a00            0xf5a00          247 rwxp n smbios
0xffff800040000000         0x40000000     3ffdd000 rwxp n main
0xffff80007fe00000         0x7fe00000       200000 rwxp n acpi
0xffff8000febd1000         0xfebd1000         1000 rwxp n pci_bar
0xffff8000febd2000         0xfebd2000         1000 rwxp n pci_bar
0xffff8000fec00000         0xfec00000         1000 rwxp n ioapic
0xffff900000000000                  0     40000000 rwxp n page
0xffff900040000000         0x40000000     3ffdd000 rwxp n page
0xffffa00000000000                  0     40000000 rwxp n mempool
0xffffa00040000000         0x40000000     3ffdd000 rwxp n mempool

 aarch64 example)
         0x8000000          0x8000000        10000 rwxp d gic_dist
         0x8010000          0x8010000        10000 rwxp d gic_cpu
         0x9000000          0x9000000         1000 rwxp d pl011
         0x9010000          0x9010000         1000 rwxp d pl031
        0x10000000         0x10000000     2eff0000 rwxp d pci_mem
        0x3eff0000         0x3eff0000        10000 rwxp d pci_io
        0x40000000         0x40000000       6d3000 rwxp n kernel
      0x4010000000       0x4010000000     10000000 rwxp d pci_cfg
0xffff80000a000000          0xa000000          200 rwxp n virtio_mmio_cfg
0xffff80000a000200          0xa000200          200 rwxp n virtio_mmio_cfg
0xffff80000a000400          0xa000400          200 rwxp n virtio_mmio_cfg
0xffff80000a000600          0xa000600          200 rwxp n virtio_mmio_cfg
0xffff80000a000800          0xa000800          200 rwxp n virtio_mmio_cfg
0xffff80000a000a00          0xa000a00          200 rwxp n virtio_mmio_cfg
0xffff80000a000c00          0xa000c00          200 rwxp n virtio_mmio_cfg
0xffff80000a000e00          0xa000e00          200 rwxp n virtio_mmio_cfg
0xffff8000406d3000         0x406d3000     7f92d000 rwxp n main
0xffff9000406d3000         0x406d3000     7f92d000 rwxp n page
0xffffa000406d3000         0x406d3000     7f92d000 rwxp n mempool

Signed-off-by: Waldemar Kozaczuk <jwkozac...@gmail.com>
---
 core/mmu.cc             | 12 ++++++++++++
 fs/sysfs/sysfs_vnops.cc |  1 +
 include/osv/mmu.hh      |  1 +
 3 files changed, 14 insertions(+)

diff --git a/core/mmu.cc b/core/mmu.cc
index 7c78ac5b..a479e5c4 100644
--- a/core/mmu.cc
+++ b/core/mmu.cc
@@ -1879,6 +1879,18 @@ linear_vma::linear_vma(void* virt, phys phys, size_t 
size, mattr mem_attr, const
 linear_vma::~linear_vma() {
 }
 
+std::string sysfs_linear_maps() {
+    std::ostringstream os;
+    WITH_LOCK(linear_vma_set_mutex.for_read()) {
+        for(auto *vma : linear_vma_set) {
+            char mattr = vma->_mem_attr == mmu::mattr::normal ? 'n' : 'd';
+            osv::fprintf(os, "%18x %18x %12x rwxp %c %s\n",
+                vma->_virt_addr, (void*)vma->_phys_addr, vma->_size, mattr, 
vma->_name.c_str());
+        }
+    }
+    return os.str();
+}
+
 void linear_map(void* _virt, phys addr, size_t size, const char* name,
                 size_t slop, mattr mem_attr)
 {
diff --git a/fs/sysfs/sysfs_vnops.cc b/fs/sysfs/sysfs_vnops.cc
index 15636f92..248f16f0 100644
--- a/fs/sysfs/sysfs_vnops.cc
+++ b/fs/sysfs/sysfs_vnops.cc
@@ -95,6 +95,7 @@ sysfs_mount(mount* mp, const char *dev, int flags, const 
void* data)
     auto memory = make_shared<pseudo_dir_node>(inode_count++);
     memory->add("free_page_ranges", inode_count++, sysfs_free_page_ranges);
     memory->add("pools", inode_count++, sysfs_memory_pools);
+    memory->add("linear_maps", inode_count++, mmu::sysfs_linear_maps);
 
     auto osv_extension = make_shared<pseudo_dir_node>(inode_count++);
     osv_extension->add("memory", memory);
diff --git a/include/osv/mmu.hh b/include/osv/mmu.hh
index 463f2001..f4bdaa84 100644
--- a/include/osv/mmu.hh
+++ b/include/osv/mmu.hh
@@ -330,6 +330,7 @@ error  advise(void* addr, size_t size, int advice);
 void vm_fault(uintptr_t addr, exception_frame* ef);
 
 std::string procfs_maps();
+std::string sysfs_linear_maps();
 
 unsigned long all_vmas_size();
 
-- 
2.31.1

-- 
You received this message because you are subscribed to the Google Groups "OSv 
Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to osv-dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/osv-dev/20220317012348.871820-1-jwkozaczuk%40gmail.com.

Reply via email to