Skip to content

Commit cdbc697

Browse files
davidhildenbrandmstsirkin
authored andcommitted
fs/proc/vmcore: convert vmcore_cb_lock into vmcore_mutex
We want to protect vmcore modifications from concurrent opening of the vmcore, and also serialize vmcore modification. (a) We can currently modify the vmcore after it was opened. This can happen if a vmcoredd is added after the vmcore module was initialized and already opened by user space. We want to fix that and prepare for new code wanting to serialize against concurrent opening. (b) To handle it cleanly we need to protect the modifications against concurrent opening. As the modifications end up allocating memory and can sleep, we cannot rely on the spinlock. Let's convert the spinlock into a mutex to prepare for further changes. Signed-off-by: David Hildenbrand <[email protected]> Message-Id: <[email protected]> Acked-by: Andrew Morton <[email protected]> Signed-off-by: Michael S. Tsirkin <[email protected]>
1 parent 33bb2d1 commit cdbc697

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

fs/proc/vmcore.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ core_param(novmcoredd, vmcoredd_disabled, bool, 0);
6262
/* Device Dump Size */
6363
static size_t vmcoredd_orig_sz;
6464

65-
static DEFINE_SPINLOCK(vmcore_cb_lock);
65+
static DEFINE_MUTEX(vmcore_mutex);
66+
6667
DEFINE_STATIC_SRCU(vmcore_cb_srcu);
6768
/* List of registered vmcore callbacks. */
6869
static LIST_HEAD(vmcore_cb_list);
@@ -72,21 +73,21 @@ static bool vmcore_opened;
7273
void register_vmcore_cb(struct vmcore_cb *cb)
7374
{
7475
INIT_LIST_HEAD(&cb->next);
75-
spin_lock(&vmcore_cb_lock);
76+
mutex_lock(&vmcore_mutex);
7677
list_add_tail(&cb->next, &vmcore_cb_list);
7778
/*
7879
* Registering a vmcore callback after the vmcore was opened is
7980
* very unusual (e.g., manual driver loading).
8081
*/
8182
if (vmcore_opened)
8283
pr_warn_once("Unexpected vmcore callback registration\n");
83-
spin_unlock(&vmcore_cb_lock);
84+
mutex_unlock(&vmcore_mutex);
8485
}
8586
EXPORT_SYMBOL_GPL(register_vmcore_cb);
8687

8788
void unregister_vmcore_cb(struct vmcore_cb *cb)
8889
{
89-
spin_lock(&vmcore_cb_lock);
90+
mutex_lock(&vmcore_mutex);
9091
list_del_rcu(&cb->next);
9192
/*
9293
* Unregistering a vmcore callback after the vmcore was opened is
@@ -95,7 +96,7 @@ void unregister_vmcore_cb(struct vmcore_cb *cb)
9596
*/
9697
if (vmcore_opened)
9798
pr_warn_once("Unexpected vmcore callback unregistration\n");
98-
spin_unlock(&vmcore_cb_lock);
99+
mutex_unlock(&vmcore_mutex);
99100

100101
synchronize_srcu(&vmcore_cb_srcu);
101102
}
@@ -120,9 +121,9 @@ static bool pfn_is_ram(unsigned long pfn)
120121

121122
static int open_vmcore(struct inode *inode, struct file *file)
122123
{
123-
spin_lock(&vmcore_cb_lock);
124+
mutex_lock(&vmcore_mutex);
124125
vmcore_opened = true;
125-
spin_unlock(&vmcore_cb_lock);
126+
mutex_unlock(&vmcore_mutex);
126127

127128
return 0;
128129
}

0 commit comments

Comments
 (0)