Files
linux/include/linux
Yan Zhao 67b43038ce KVM: guest_memfd: Remove RCU-protected attribute from slot->gmem.file
Remove the RCU-protected attribute from slot->gmem.file. No need to use RCU
primitives rcu_assign_pointer()/synchronize_rcu() to update this pointer.

- slot->gmem.file is updated in 3 places:
  kvm_gmem_bind(), kvm_gmem_unbind(), kvm_gmem_release().
  All of them are protected by kvm->slots_lock.

- slot->gmem.file is read in 2 paths:
  (1) kvm_gmem_populate
        kvm_gmem_get_file
        __kvm_gmem_get_pfn

  (2) kvm_gmem_get_pfn
         kvm_gmem_get_file
         __kvm_gmem_get_pfn

  Path (1) kvm_gmem_populate() requires holding kvm->slots_lock, so
  slot->gmem.file is protected by the kvm->slots_lock in this path.

  Path (2) kvm_gmem_get_pfn() does not require holding kvm->slots_lock.
  However, it's also not guarded by rcu_read_lock() and rcu_read_unlock().
  So synchronize_rcu() in kvm_gmem_unbind()/kvm_gmem_release() actually
  will not wait for the readers in kvm_gmem_get_pfn() due to lack of RCU
  read-side critical section.

  The path (2) kvm_gmem_get_pfn() is safe without RCU protection because:
  a) kvm_gmem_bind() is called on a new memslot, before the memslot is
     visible to kvm_gmem_get_pfn().
  b) kvm->srcu ensures that kvm_gmem_unbind() and freeing of a memslot
     occur after the memslot is no longer visible to kvm_gmem_get_pfn().
  c) get_file_active() ensures that kvm_gmem_get_pfn() will not access the
     stale file if kvm_gmem_release() sets it to NULL.  This is because if
     kvm_gmem_release() occurs before kvm_gmem_get_pfn(), get_file_active()
     will return NULL; if get_file_active() does not return NULL,
     kvm_gmem_release() should not occur until after kvm_gmem_get_pfn()
     releases the file reference.

Signed-off-by: Yan Zhao <yan.y.zhao@intel.com>
Message-ID: <20241104084303.29909-1-yan.y.zhao@intel.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2024-12-23 08:28:49 -05:00
..
2024-10-22 15:54:11 +02:00
2024-10-11 14:34:11 -04:00
2024-10-13 17:16:57 +02:00
2024-04-24 11:06:26 -07:00
2024-04-25 20:55:49 -07:00
2024-10-11 14:37:29 +05:30
2024-10-14 23:27:57 +05:30
2024-11-11 10:45:03 +01:00
2024-10-09 15:42:48 +01:00
2024-08-28 06:53:58 -07:00
2024-11-07 14:38:07 -08:00
2024-10-14 18:33:04 -07:00
2024-07-08 01:51:05 -06:00
2024-09-03 21:15:36 -07:00
2024-06-24 18:29:20 +02:00
2024-04-23 09:03:37 +09:00
2024-06-11 12:57:49 -05:00
2024-11-05 13:32:21 +01:00
2024-10-22 11:16:56 +02:00
2024-10-19 14:16:45 +02:00
2024-10-01 17:01:40 +02:00
2024-05-19 14:36:17 -07:00
2024-11-09 14:55:33 +01:00
2024-11-28 14:49:28 +01:00
2024-08-29 10:39:37 +02:00
2024-11-24 17:05:27 -08:00
2024-07-31 13:49:48 +01:00
2024-08-08 17:15:02 +02:00
2024-10-16 21:56:59 +02:00
2024-06-24 22:24:56 -07:00
2024-10-30 19:47:20 +01:00
2024-09-03 21:15:46 -07:00
2024-09-20 18:28:26 +03:00
2024-09-01 20:26:03 -07:00
2024-11-05 16:56:26 -08:00
2024-07-03 19:30:23 -07:00
2024-10-14 16:33:24 -05:00
2024-08-11 17:04:29 +01:00
2024-07-31 09:57:18 -07:00
2024-07-28 16:47:51 -06:00
2024-09-23 15:03:30 -04:00
2024-06-24 22:25:02 -07:00
2024-11-05 16:56:26 -08:00
2024-08-30 08:22:38 +02:00
2024-11-16 10:09:30 -06:00
2024-10-02 16:23:10 -05:00
2024-11-05 12:55:38 +01:00
2024-09-11 20:44:31 -07:00
2024-09-11 20:44:32 -07:00
2024-05-04 18:57:21 +02:00
2024-11-30 22:41:35 -05:00
2024-11-11 00:26:44 -08:00
2024-07-10 07:59:03 +02:00
2024-11-06 12:59:44 -05:00
2024-10-02 16:53:38 +02:00
2024-05-06 12:05:00 +02:00
2024-08-06 13:42:40 +02:00
2024-11-18 11:56:21 +00:00
2024-09-12 12:20:39 +02:00
2024-06-24 18:16:44 +01:00
2024-11-06 12:59:44 -05:00
2024-04-25 20:55:48 -07:00