Skip to content

Key bar memory map error if key bar starting address is not 4K aligned #351

@fub2

Description

@fub2

Running into root port key bar mapping error for CXL device populated to port2/port4/port6.

Failing environment details:
teeio validator configuration file as below. 0000:b0:06.0 is root port4 of pxp4.
[Main]
debug_level = verbose
pci_log = 0
libspdm_log = 0
pcap_enable = 0
doe_log = 0

[Ports]
rootport_1 = 06.0 ; dev/func of rootport 1
endpoint_1 = 00.0 ; dev/func of endpoint 1

[Topology_1]
type = link_ide ; Link IDE
connection = direct ; Directly connected EP
segment = 0x0000
bus = 0xb0
path1 = rootport_1,endpoint_1
stream_id = 0 ;always 0

[Configuration_1]
type = link_ide ; refer to IdeKmTestConfiguration.LinkIDE.md
category = cxl-ide
cxl_ide_mode = skid ;either skid or containment
default = 1 ; refer to IdeKmTestConfiguration.LinkIDE.md#no_special
pcrc_disable = 0
ide_stop = 0
cxl_get_key = 0

  1. Error message from teeio validator when running command "./teeio_validator -f cxl_skid.ini -t 1 -c 1 -s Test.IdeStream"

[2026-03-04 04:56:18.543][error] Failed to mmap kcbar
TEEIO_ASSERT: /root/repo/tee-io-validator/teeio-validator/library/pcie_ide_lib/intel_rp_pcie.c(321): false

Root cause I believe it is failure in mmap() call in teeio validator, when key bar begins at an address which is not 4K aligned. The last 16-bit of key bar starting addresses usually are 2000h/2400h/2800h/2c00h for port0/2/4/6. While mmap() system call doesn't support non 4K aligned memory map.

I verified the root cause by a quick code change with below. It worked well.

[root@fuxiaogu-mobl1 tee-io-validator]# git diff
diff --git a/teeio-validator/library/pcie_ide_lib/intel_rp_pcie.c b/teeio-validator/library/pcie_ide_lib/intel_rp_pcie.c
index 7a301ac..d691482 100644
--- a/teeio-validator/library/pcie_ide_lib/intel_rp_pcie.c
+++ b/teeio-validator/library/pcie_ide_lib/intel_rp_pcie.c
@@ -201,7 +201,8 @@ uint8_t* map_kcbar_addr(uint64_t addr, int* mapped_fd)
TEEIO_DEBUG ((TEEIO_DEBUG_ERROR, "Failed to open /dev/mem\n"));
return NULL;
}

  • uint8_t * mem_ptr = (uint8_t *)mmap(NULL, KCBAR_MEMORY_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, mem_fd, addr);
  • TEEIO_DEBUG ((TEEIO_DEBUG_INFO, "mmap address = 0x%x, aligning to 0x%x\n", addr, (addr-0x800)));

  • uint8_t * mem_ptr = (uint8_t )mmap(NULL, 3072, PROT_READ | PROT_WRITE, MAP_SHARED, mem_fd, (addr-0x800));
    if (mem_ptr == MAP_FAILED) {
    TEEIO_DEBUG ((TEEIO_DEBUG_ERROR, "Failed to mmap kcbar\n"));
    close(mem_fd);
    @@ -210,7 +211,7 @@ uint8_t
    map_kcbar_addr(uint64_t addr, int* mapped_fd)

    *mapped_fd = mem_fd;

  • return mem_ptr;
  • return(uint8_t *)((uint64_t)mem_ptr+0x800);
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions