From 86c6484fba83a1326c5451e66ce62ae5003f920b Mon Sep 17 00:00:00 2001 From: Yiwei Zhang Date: Fri, 3 Feb 2023 10:29:16 +0000 Subject: [PATCH] venus: lazily query and cache gralloc front rendering usage When skiavk is the default system ui renderer, venus icd gets preloaded into Zygote. However, Zygote access to render node is normally denied by selinux except for legacy bootanimation purpose. This change fixes venus icd loading to avoid invoking cros gralloc driver loading by moving the perform op outside, so that we still get the memory footprint win. Signed-off-by: Yiwei Zhang Reviewed-by: Ryan Neph Part-of: --- src/virtio/vulkan/vn_android.c | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/src/virtio/vulkan/vn_android.c b/src/virtio/vulkan/vn_android.c index a4066e41ac0..d5016e8ad4f 100644 --- a/src/virtio/vulkan/vn_android.c +++ b/src/virtio/vulkan/vn_android.c @@ -42,9 +42,13 @@ static struct vn_android_gralloc _vn_android_gralloc; static int vn_android_gralloc_init() { + /* We preload same-process gralloc hw module along with venus icd. When + * venus gets preloaded in Zygote, the unspecialized Zygote process + * defaults to no access to dri nodes. So we MUST NOT invoke any gralloc + * helpers here to avoid initializing cros gralloc driver. + */ static const char CROS_GRALLOC_MODULE_NAME[] = "CrOS Gralloc"; const gralloc_module_t *gralloc = NULL; - uint32_t front_rendering_usage = 0; int ret; /* get gralloc module for gralloc buffer info query */ @@ -61,19 +65,13 @@ vn_android_gralloc_init() return -1; } + /* check the helper without using it here as mentioned above */ if (!gralloc->perform) { dlclose(gralloc->common.dso); vn_log(NULL, "missing required gralloc helper: perform"); return -1; } - if (gralloc->perform(gralloc, CROS_GRALLOC_DRM_GET_USAGE, - CROS_GRALLOC_DRM_GET_USAGE_FRONT_RENDERING_BIT, - &front_rendering_usage) == 0) { - assert(front_rendering_usage); - _vn_android_gralloc.front_rendering_usage = front_rendering_usage; - } - _vn_android_gralloc.module = gralloc; return 0; @@ -85,9 +83,24 @@ vn_android_gralloc_fini() dlclose(_vn_android_gralloc.module->common.dso); } +static void +vn_android_gralloc_shared_present_usage_init_once() +{ + const gralloc_module_t *gralloc = _vn_android_gralloc.module; + uint32_t front_rendering_usage = 0; + if (gralloc->perform(gralloc, CROS_GRALLOC_DRM_GET_USAGE, + CROS_GRALLOC_DRM_GET_USAGE_FRONT_RENDERING_BIT, + &front_rendering_usage) == 0) { + assert(front_rendering_usage); + _vn_android_gralloc.front_rendering_usage = front_rendering_usage; + } +} + uint32_t vn_android_gralloc_get_shared_present_usage() { + static once_flag once = ONCE_FLAG_INIT; + call_once(&once, vn_android_gralloc_shared_present_usage_init_once); return _vn_android_gralloc.front_rendering_usage; }