All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] migration: use eventfd functions instead of bare read/write
@ 2026-05-14  7:51 Aadeshveer Singh
  2026-05-15 14:42 ` Peter Xu
  2026-05-20 19:44 ` Peter Xu
  0 siblings, 2 replies; 4+ messages in thread
From: Aadeshveer Singh @ 2026-05-14  7:51 UTC (permalink / raw)
  To: qemu-devel; +Cc: peterx, farosas, Aadeshveer Singh

Replace read() and write() syscalls on eventfd with glibc wrappers
eventfd_read() and eventfd_write(), to make code more robust, readable
and future-proof.

Signed-off-by: Aadeshveer Singh <aadeshveer07@gmail.com>
---
 migration/postcopy-ram.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/migration/postcopy-ram.c b/migration/postcopy-ram.c
index f5ef93f193..16113b166d 100644
--- a/migration/postcopy-ram.c
+++ b/migration/postcopy-ram.c
@@ -1330,12 +1330,12 @@ static void *postcopy_ram_fault_thread(void *opaque)
         }
 
         if (pfd[1].revents) {
-            uint64_t tmp64 = 0;
+            eventfd_t tmp_event = 0;
 
             /* Consume the signal */
-            if (read(mis->userfault_event_fd, &tmp64, 8) != 8) {
+            if (eventfd_read(mis->userfault_event_fd, &tmp_event)) {
                 /* Nothing obviously nicer than posting this error. */
-                error_report("%s: read() failed", __func__);
+                error_report("%s: eventfd_read() failed", __func__);
             }
 
             if (qatomic_read(&mis->fault_thread_quit)) {
@@ -1773,13 +1773,11 @@ void postcopy_temp_page_reset(PostcopyTmpPage *tmp_page)
 
 void postcopy_fault_thread_notify(MigrationIncomingState *mis)
 {
-    uint64_t tmp64 = 1;
-
     /*
      * Wakeup the fault_thread.  It's an eventfd that should currently
      * be at 0, we're going to increment it to 1
      */
-    if (write(mis->userfault_event_fd, &tmp64, 8) != 8) {
+    if (eventfd_write(mis->userfault_event_fd, 1)) {
         /* Not much we can do here, but may as well report it */
         error_report("%s: incrementing failed: %s", __func__,
                      strerror(errno));
-- 
2.54.0



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] migration: use eventfd functions instead of bare read/write
  2026-05-14  7:51 [PATCH] migration: use eventfd functions instead of bare read/write Aadeshveer Singh
@ 2026-05-15 14:42 ` Peter Xu
  2026-05-20 19:44 ` Peter Xu
  1 sibling, 0 replies; 4+ messages in thread
From: Peter Xu @ 2026-05-15 14:42 UTC (permalink / raw)
  To: Aadeshveer Singh; +Cc: qemu-devel, farosas

On Thu, May 14, 2026 at 01:21:37PM +0530, Aadeshveer Singh wrote:
> Replace read() and write() syscalls on eventfd with glibc wrappers
> eventfd_read() and eventfd_write(), to make code more robust, readable
> and future-proof.
> 
> Signed-off-by: Aadeshveer Singh <aadeshveer07@gmail.com>

queued, thanks

-- 
Peter Xu



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] migration: use eventfd functions instead of bare read/write
  2026-05-14  7:51 [PATCH] migration: use eventfd functions instead of bare read/write Aadeshveer Singh
  2026-05-15 14:42 ` Peter Xu
@ 2026-05-20 19:44 ` Peter Xu
  2026-05-23  3:01   ` Aadeshveer Singh
  1 sibling, 1 reply; 4+ messages in thread
From: Peter Xu @ 2026-05-20 19:44 UTC (permalink / raw)
  To: Aadeshveer Singh; +Cc: qemu-devel, farosas

On Thu, May 14, 2026 at 01:21:37PM +0530, Aadeshveer Singh wrote:
> Replace read() and write() syscalls on eventfd with glibc wrappers
> eventfd_read() and eventfd_write(), to make code more robust, readable
> and future-proof.
> 
> Signed-off-by: Aadeshveer Singh <aadeshveer07@gmail.com>
> ---
>  migration/postcopy-ram.c | 10 ++++------
>  1 file changed, 4 insertions(+), 6 deletions(-)
> 
> diff --git a/migration/postcopy-ram.c b/migration/postcopy-ram.c
> index f5ef93f193..16113b166d 100644
> --- a/migration/postcopy-ram.c
> +++ b/migration/postcopy-ram.c
> @@ -1330,12 +1330,12 @@ static void *postcopy_ram_fault_thread(void *opaque)
>          }
>  
>          if (pfd[1].revents) {
> -            uint64_t tmp64 = 0;
> +            eventfd_t tmp_event = 0;
>  
>              /* Consume the signal */
> -            if (read(mis->userfault_event_fd, &tmp64, 8) != 8) {
> +            if (eventfd_read(mis->userfault_event_fd, &tmp_event)) {
>                  /* Nothing obviously nicer than posting this error. */
> -                error_report("%s: read() failed", __func__);
> +                error_report("%s: eventfd_read() failed", __func__);
>              }
>  
>              if (qatomic_read(&mis->fault_thread_quit)) {
> @@ -1773,13 +1773,11 @@ void postcopy_temp_page_reset(PostcopyTmpPage *tmp_page)
>  
>  void postcopy_fault_thread_notify(MigrationIncomingState *mis)
>  {
> -    uint64_t tmp64 = 1;
> -
>      /*
>       * Wakeup the fault_thread.  It's an eventfd that should currently
>       * be at 0, we're going to increment it to 1
>       */
> -    if (write(mis->userfault_event_fd, &tmp64, 8) != 8) {
> +    if (eventfd_write(mis->userfault_event_fd, 1)) {
>          /* Not much we can do here, but may as well report it */
>          error_report("%s: incrementing failed: %s", __func__,
>                       strerror(errno));
> -- 
> 2.54.0
> 

Unfortunately this will break win builds.  It's because these functions are
compiled even for windows, and windows doesn't have eventfd.

Ideally we shouldn't compile postcopy code in windows at all.  So it's not
really this patch's problem.  But fixing that would either need temporary
CONFIG_LINUX check here just to use the glibc API or a larger refactor to
opt-out compilation of postcopy.

I'll drop this patch for now.  Aadeshveer, if you want you can try to have
a look later on how to not compile postcopy code for windows.  For now, I
suggest you stick with the gsoc project.

Thanks,

-- 
Peter Xu



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] migration: use eventfd functions instead of bare read/write
  2026-05-20 19:44 ` Peter Xu
@ 2026-05-23  3:01   ` Aadeshveer Singh
  0 siblings, 0 replies; 4+ messages in thread
From: Aadeshveer Singh @ 2026-05-23  3:01 UTC (permalink / raw)
  To: Peter Xu; +Cc: qemu-devel, farosas

Hi Peter

Understood about the windows build issue. I will drop this patch for
now and focus on the main GSoC project as suggested.

Thank you,
Aadeshveer

On Thu, May 21, 2026 at 1:14 AM Peter Xu <peterx@redhat.com> wrote:
>
> On Thu, May 14, 2026 at 01:21:37PM +0530, Aadeshveer Singh wrote:
> > Replace read() and write() syscalls on eventfd with glibc wrappers
> > eventfd_read() and eventfd_write(), to make code more robust, readable
> > and future-proof.
> >
> > Signed-off-by: Aadeshveer Singh <aadeshveer07@gmail.com>
> > ---
> >  migration/postcopy-ram.c | 10 ++++------
> >  1 file changed, 4 insertions(+), 6 deletions(-)
> >
> > diff --git a/migration/postcopy-ram.c b/migration/postcopy-ram.c
> > index f5ef93f193..16113b166d 100644
> > --- a/migration/postcopy-ram.c
> > +++ b/migration/postcopy-ram.c
> > @@ -1330,12 +1330,12 @@ static void *postcopy_ram_fault_thread(void *opaque)
> >          }
> >
> >          if (pfd[1].revents) {
> > -            uint64_t tmp64 = 0;
> > +            eventfd_t tmp_event = 0;
> >
> >              /* Consume the signal */
> > -            if (read(mis->userfault_event_fd, &tmp64, 8) != 8) {
> > +            if (eventfd_read(mis->userfault_event_fd, &tmp_event)) {
> >                  /* Nothing obviously nicer than posting this error. */
> > -                error_report("%s: read() failed", __func__);
> > +                error_report("%s: eventfd_read() failed", __func__);
> >              }
> >
> >              if (qatomic_read(&mis->fault_thread_quit)) {
> > @@ -1773,13 +1773,11 @@ void postcopy_temp_page_reset(PostcopyTmpPage *tmp_page)
> >
> >  void postcopy_fault_thread_notify(MigrationIncomingState *mis)
> >  {
> > -    uint64_t tmp64 = 1;
> > -
> >      /*
> >       * Wakeup the fault_thread.  It's an eventfd that should currently
> >       * be at 0, we're going to increment it to 1
> >       */
> > -    if (write(mis->userfault_event_fd, &tmp64, 8) != 8) {
> > +    if (eventfd_write(mis->userfault_event_fd, 1)) {
> >          /* Not much we can do here, but may as well report it */
> >          error_report("%s: incrementing failed: %s", __func__,
> >                       strerror(errno));
> > --
> > 2.54.0
> >
>
> Unfortunately this will break win builds.  It's because these functions are
> compiled even for windows, and windows doesn't have eventfd.
>
> Ideally we shouldn't compile postcopy code in windows at all.  So it's not
> really this patch's problem.  But fixing that would either need temporary
> CONFIG_LINUX check here just to use the glibc API or a larger refactor to
> opt-out compilation of postcopy.
>
> I'll drop this patch for now.  Aadeshveer, if you want you can try to have
> a look later on how to not compile postcopy code for windows.  For now, I
> suggest you stick with the gsoc project.
>
> Thanks,
>
> --
> Peter Xu
>


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-05-23  3:03 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-14  7:51 [PATCH] migration: use eventfd functions instead of bare read/write Aadeshveer Singh
2026-05-15 14:42 ` Peter Xu
2026-05-20 19:44 ` Peter Xu
2026-05-23  3:01   ` Aadeshveer Singh

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.