@@ -1112,7 +1112,7 @@ static int __init assign_shared_memory(struct domain *d,
static int __init borrower_physmap_add_memory(struct domain *d,
struct shm_membank *shm_membank,
- paddr_t gbase)
+ paddr_t gbase, paddr_t offset)
{
int ret;
unsigned int i;
@@ -1141,8 +1141,8 @@ static int __init borrower_physmap_add_memory(struct domain *d,
}
else
{
- start = shm_membank->mem.bank->start;
- size = shm_membank->mem.bank->size;
+ start = shm_membank->mem.bank->start + offset;
+ size = shm_membank->mem.bank->size - offset;
sgfn = _gfn(PFN_UP(gbase));
/* Set up P2M foreign mapping for borrower domain. */
@@ -1157,7 +1157,7 @@ static int __init borrower_physmap_add_memory(struct domain *d,
static int __init append_shm_bank_to_domain(struct kernel_info *kinfo,
paddr_t start, paddr_t size,
- const char *shm_id)
+ const char *shm_id, paddr_t offset)
{
struct membank *membank;
@@ -1170,7 +1170,7 @@ static int __init append_shm_bank_to_domain(struct kernel_info *kinfo,
kinfo->shm_mem.bank[kinfo->shm_mem.nr_banks].mem.bank = membank;
kinfo->shm_mem.bank[kinfo->shm_mem.nr_banks].mem.bank->start = start;
- kinfo->shm_mem.bank[kinfo->shm_mem.nr_banks].mem.bank->size = size;
+ kinfo->shm_mem.bank[kinfo->shm_mem.nr_banks].mem.bank->size = size - offset;
safe_strcpy(kinfo->shm_mem.bank[kinfo->shm_mem.nr_banks].shm_id, shm_id);
kinfo->shm_mem.nr_banks++;
@@ -1265,6 +1265,7 @@ static int __init process_shm(struct domain *d, struct kernel_info *kinfo,
const char *shm_id;
bool owner_dom_io = true, paddr_assigned = true;
struct shm_membank *shm_membank;
+ uint64_t offset = 0UL;
if ( !dt_device_is_compatible(shm_node, "xen,domain-shared-memory-v1") )
continue;
@@ -1288,6 +1289,19 @@ static int __init process_shm(struct domain *d, struct kernel_info *kinfo,
}
BUG_ON((strlen(shm_id) <= 0) || (strlen(shm_id) >= MAX_SHM_ID_LENGTH));
+ /*
+ * If "xen,offset" is provided, then only partial shared memory
+ * shall be mapped to borrower domain.
+ * "xen,offset" is a 64-bit integer and an optional property
+ */
+ dt_property_read_u64(shm_node, "xen,offset", &offset);
+ if ( !IS_ALIGNED(offset, PAGE_SIZE) )
+ {
+ printk("%pd: \"xen,offset\" 0x%lx is not suitably aligned\n",
+ d, offset);
+ return -EINVAL;
+ }
+
shm_membank = acquire_shm_membank(shm_id);
if ( !shm_membank )
{
@@ -1331,7 +1345,8 @@ static int __init process_shm(struct domain *d, struct kernel_info *kinfo,
if ( owner_dom_io || (strcmp(role_str, "borrower") == 0) )
{
- ret = borrower_physmap_add_memory(d, shm_membank, gbase);
+ ret = borrower_physmap_add_memory(d, shm_membank, gbase,
+ (paddr_t)offset);
if ( ret )
{
printk(XENLOG_ERR
@@ -1345,7 +1360,8 @@ static int __init process_shm(struct domain *d, struct kernel_info *kinfo,
* Record static shared memory region info for later setting
* up shm-node in guest device tree.
*/
- ret = append_shm_bank_to_domain(kinfo, gbase, psize, shm_id);
+ ret = append_shm_bank_to_domain(kinfo, gbase, psize, shm_id,
+ (paddr_t)offset);
if ( ret )
return ret;
}
When host address is provided in "xen,shared-mem" property([pbase, gbase, psize]), it is easy to decide where to map to the borrower domain if "xen,offset" is also provided. The partially-shared region shall be starting at pbase + offset, and ending at pbase + size. Signed-off-by: Penny Zheng <penny.zheng@arm.com> --- xen/arch/arm/domain_build.c | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-)