On 9/22/23 22:32, Sean Christopherson wrote:
Unless we can't extend fadvise() for some reason, I think we should pursue FADV_HWPOISION. The enabling should be downright trivial, e.g. just implement file_operations.fadvise() for guest_memfd, have it handle FADV_HWPOISON, and pass everything else to generic_fadvise(). It'll basically be your ioctl() just without a dedicated ioctl(). At the very least, we should run the idea past the fs maintainers.
fadvise() is different from madvise() though and not necessarily a great match. Looking at the list of flags in advise(), something like FADV_POPULATE_READ, FADV_PAGEOUT or FADV_COLD would make sense, but I can't really think of any other flag that would be useful in a general case for fadvise. Everything else would have to be very spcific to memfd or guest_memfd.
In particular FADV_HWPOISON would not make sense for anything that is not backend by memory. There are some flags that could be useful on gmem file descriptors, such as hypothetically {WIPE,KEEP}ONFORK or SOFT_OFFLINE, but again they're not something that can be applied to fadvise().
So a ioctl implementation does have some advantages after all. I suggest that we reuse MADV_* flags in the ioctl arguments, to leave the door open for future extensions and avoid ioctl proliferation. The ioctl could be implemented by memfd, too, and perhaps even by /dev/zero.
Paolo