On Wed, Mar 18, 2020 at 05:50:43PM +0200, Jarkko Sakkinen wrote: > On Wed, Mar 18, 2020 at 05:39:07PM +0200, Jarkko Sakkinen wrote: > > On Mon, Mar 16, 2020 at 10:15:39PM -0700, Sean Christopherson wrote: > > > @@ -223,10 +229,22 @@ int sgx_encl_mm_add(struct sgx_encl *encl, struct mm_struct *mm) > > > > > > spin_lock(&encl->mm_lock); > > > list_add_rcu(&encl_mm->list, &encl->mm_list); > > > + /* > > > + * Ensure the mm is added to the list before updating the version. > > > + * Pairs with the smp_rmb() in sgx_reclaimer_block(). > > > + */ > > > + smp_wmb(); > > > + encl->mm_list_version++; > > > spin_unlock(&encl->mm_lock); > > > > > > - synchronize_srcu(&encl->srcu); > > > - > > > + /* > > > + * DO NOT call synchronize_srcu()! When this is called via dup_mmap(), > > > + * mmap_sem is held for write in both the old mm and new mm, and the > > > + * reclaimer may be holding srcu for read while waiting on down_read() > > > + * for the old mm's mmap_sem, i.e. synchronizing will deadlock. > > > + * Incrementing the list version ensures readers that must not race > > > + * with a mm being added will see the updated list. > > > + */ > > For this comment, please completely remove it. We either call something > or do not call it. We do !call anything. How on earth is someone doing to dredge up the above information without a comment? Anyone looking at this code without a priori knowledge of the development history will assume the missing synchronize_srcu() is a bug. > > > return 0; > > > } > > > > > > diff --git a/arch/x86/kernel/cpu/sgx/encl.h b/arch/x86/kernel/cpu/sgx/encl.h > > > index 44b353aa8866..f0f72e591244 100644 > > > --- a/arch/x86/kernel/cpu/sgx/encl.h > > > +++ b/arch/x86/kernel/cpu/sgx/encl.h > > > @@ -74,6 +74,7 @@ struct sgx_encl { > > > struct mutex lock; > > > struct list_head mm_list; > > > spinlock_t mm_lock; > > > + unsigned long mm_list_version; > > > struct file *backing; > > > struct kref refcount; > > > struct srcu_struct srcu;