compositor-drm: Met process stuck when do GPU PM Test

drm master was set by systemd in PM test, try to set the master back
This is a workaround patch, we should detect the EPERM error when we try to commit,
cancel the repaint, and wait for the session to be deactivated. When the session is reactivated,
we should make sure that repaint still works from there.

Upstream-Status: Inappropriate [i.MX-specific]

Signed-off-by: Yong Gan <yong.gan@nxp.com>
(cherry picked from commit e2d863784ff7d5d45025463db94c23fffceb9132)
diff --git a/libweston/compositor-drm.c b/libweston/compositor-drm.c
index bf0a227..125e7b1 100644
--- a/libweston/compositor-drm.c
+++ b/libweston/compositor-drm.c
@@ -2553,6 +2553,7 @@
 	drmModeAtomicReq *req = drmModeAtomicAlloc();
 	uint32_t flags = 0;
 	int ret = 0;
+	drm_magic_t magic;
 
 	if (!req)
 		return -1;
@@ -2660,6 +2661,11 @@
 		break;
 	}
 
+	/*drm master was set by systemd in PM test, try to set the master back.*/
+	if (!(drmGetMagic(b->drm.fd, &magic) == 0 &&
+			drmAuthMagic(b->drm.fd, magic) == 0)) {
+		drmSetMaster(b->drm.fd);
+	}
 	ret = drmModeAtomicCommit(b->drm.fd, req, flags, b);
 
 	/* Test commits do not take ownership of the state; return