Permalink
Browse files

vmmon: compatibility with eventpoll switch to poll_mask()

Since commit 11c5ad0ec441 ("eventpoll: switch to ->poll_mask") in
v4.18-rc1, eventpoll switched from ->poll() to ->poll_mask(). Rather than
calling the callback directly (which would result in null pointer
dereference), use vfs_poll() wrapper. As this wrapper is only available
since 4.18-rc1 cycle as well, provide a copy to use when building against
older kernels.
  • Loading branch information...
mkubecek committed Jun 17, 2018
1 parent 89c9198 commit 3f2a6c720f68860e3482c81eb49737ad9a05606d
Showing with 32 additions and 1 deletion.
  1. +30 −0 vmmon-only/include/compat_poll.h
  2. +2 −1 vmmon-only/linux/hostif.c
@@ -0,0 +1,30 @@
#ifndef __COMPAT_POLL_H__
#define __COMPAT_POLL_H__
#include <linux/poll.h>
#if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 18, 0))
#ifndef __poll_t
typedef unsigned int __poll_t;
#endif
static inline __poll_t compat_vfs_poll(struct file *file,
struct poll_table_struct *pt)
{
if (unlikely(!file->f_op->poll))
return DEFAULT_POLLMASK;
return file->f_op->poll(file, pt);
}
#else
static inline __poll_t compat_vfs_poll(struct file *file,
struct poll_table_struct *pt)
{
return vfs_poll(file, pt);
}
#endif
#endif /* __COMPAT_POLL_H__ */
@@ -74,6 +74,7 @@
#include "pgtbl.h"
#include "versioned_atomic.h"
#include "compat_poll.h"
#if !defined(CONFIG_HIGH_RES_TIMERS)
#error CONFIG_HIGH_RES_TIMERS required for acceptable performance
@@ -2373,7 +2374,7 @@ HostIF_SemaphoreWait(VMDriver *vm, // IN:
poll_initwait(&table);
current->state = TASK_INTERRUPTIBLE;
mask = file->f_op->poll(file, &table.pt);
mask = compat_vfs_poll(file, &table.pt);
if (!(mask & (POLLIN | POLLERR | POLLHUP))) {
vm->vmhost->vcpuSemaTask[vcpuid] = current;
schedule_timeout(timeoutms * HZ / 1000); // convert to Hz

4 comments on commit 3f2a6c7

@efferre79

This comment has been minimized.

efferre79 replied Aug 17, 2018

the kernel commit is not included in 4.18 yet

@mkubecek

This comment has been minimized.

Owner

mkubecek replied Aug 18, 2018

Not "not yet", it was added in 4.18-rc1 and reverted in 4.18-rc3. But I still believe calling the callback without checking its presence is a bad practice so I see little point reverting this commit here. I haven't decided yet whether I'm going to omit it in future branches or just update the commit message.

@efferre79

This comment has been minimized.

efferre79 replied Aug 18, 2018

I was not saying to revert the commit, probably just updating the commit message and the kernel version comparison is enough as soon as we know in which kernel version it will appear

@mkubecek

This comment has been minimized.

Owner

mkubecek replied Aug 18, 2018

With git, changing the commit message would result in replacing the commit with a new one (even if the source diff stays the same) and all users would have to make a forced update. I don't think it's worth the trouble. I'm going to update the commit message when cherry picking into a new branch (e.g. workstation-14.1.3).

Please sign in to comment.