mm-drivers: hw_fence: avoid mem share from rm callback

Avoid from hw-fence driver call to share carved-out memory between
hlos and cpusys vm if the memory has been already shared by the
gh_cpusys_vm_mem_access kernel driver.

Change-Id: I0df0216a6153a8982936885f53bebf7fe83db7e9
Signed-off-by: Ingrid Gallardo <quic_ingridg@quicinc.com>
This commit is contained in:
Ingrid Gallardo
2023-01-17 14:14:27 -08:00
parent e93f7e55ff
commit b39fb22f2d

View File

@@ -10,6 +10,7 @@
#include <linux/gunyah/gh_dbl.h>
#include <linux/qcom_scm.h>
#include <linux/version.h>
#include <linux/gh_cpusys_vm_mem_access.h>
#include <soc/qcom/secure_buffer.h>
#include "hw_fence_drv_priv.h"
@@ -404,8 +405,10 @@ static int hw_fence_rm_cb(struct notifier_block *nb, unsigned long cmd, void *da
{
struct gh_rm_notif_vm_status_payload *vm_status_payload;
struct hw_fence_driver_data *drv_data;
struct resource res;
gh_vmid_t peer_vmid;
gh_vmid_t self_vmid;
int ret;
drv_data = container_of(nb, struct hw_fence_driver_data, rm_nb);
@@ -430,11 +433,25 @@ static int hw_fence_rm_cb(struct notifier_block *nb, unsigned long cmd, void *da
switch (vm_status_payload->vm_status) {
case GH_RM_VM_STATUS_READY:
HWFNC_DBG_INIT("init mem\n");
ret = gh_cpusys_vm_get_share_mem_info(&res);
if (ret) {
HWFNC_DBG_INIT("mem not shared ret:%d, attempt share\n", ret);
if (hw_fence_gunyah_share_mem(drv_data, self_vmid, peer_vmid))
HWFNC_ERR("failed to share memory\n");
else
drv_data->vm_ready = true;
} else {
if (drv_data->res.start == res.start &&
resource_size(&drv_data->res) == resource_size(&res)) {
drv_data->vm_ready = true;
HWFNC_DBG_INIT("mem_ready: add:0x%x size:%d ret:%d\n", res.start,
resource_size(&res), ret);
} else {
HWFNC_ERR("mem-shared mismatch:[0x%x,%d] expected:[0x%x,%d]\n",
res.start, resource_size(&res), drv_data->res.start,
resource_size(&drv_data->res));
}
}
break;
case GH_RM_VM_STATUS_RESET:
HWFNC_DBG_INIT("reset\n");