From: Kees Cook <keescook@chromium.org>
To: linux-kernel@vger.kernel.org
Cc: Kees Cook <keescook@chromium.org>,
Anton Vorontsov <anton@enomsg.org>,
Colin Cross <ccross@android.com>, Tony Luck <tony.luck@intel.com>,
Luis Henriques <lhenriques@suse.com>
Subject: [PATCH 05/10] pstore: Convert "records_list" locking to mutex
Date: Wed, 6 May 2020 08:21:09 -0700 [thread overview]
Message-ID: <20200506152114.50375-6-keescook@chromium.org> (raw)
In-Reply-To: <20200506152114.50375-1-keescook@chromium.org>
The pstorefs internal list lock doesn't need to be a spinlock and will
create problems when trying to access the list in the subsequent patch
that will walk the pstorefs records during pstore_unregister(). Change
this to a mutex to avoid may_sleep() warnings when unregistering devices.
Signed-off-by: Kees Cook <keescook@chromium.org>
---
fs/pstore/inode.c | 17 +++++++----------
1 file changed, 7 insertions(+), 10 deletions(-)
diff --git a/fs/pstore/inode.c b/fs/pstore/inode.c
index 5cc09cb315f9..92ebcc75434f 100644
--- a/fs/pstore/inode.c
+++ b/fs/pstore/inode.c
@@ -22,14 +22,13 @@
#include <linux/magic.h>
#include <linux/pstore.h>
#include <linux/slab.h>
-#include <linux/spinlock.h>
#include <linux/uaccess.h>
#include "internal.h"
#define PSTORE_NAMELEN 64
-static DEFINE_SPINLOCK(records_list_lock);
+static DEFINE_MUTEX(records_list_lock);
static LIST_HEAD(records_list);
struct pstore_private {
@@ -192,13 +191,12 @@ static int pstore_unlink(struct inode *dir, struct dentry *dentry)
static void pstore_evict_inode(struct inode *inode)
{
struct pstore_private *p = inode->i_private;
- unsigned long flags;
clear_inode(inode);
if (p) {
- spin_lock_irqsave(&records_list_lock, flags);
+ mutex_lock(&records_list_lock);
list_del(&p->list);
- spin_unlock_irqrestore(&records_list_lock, flags);
+ mutex_unlock(&records_list_lock);
free_pstore_private(p);
}
}
@@ -297,12 +295,11 @@ int pstore_mkfile(struct dentry *root, struct pstore_record *record)
int rc = 0;
char name[PSTORE_NAMELEN];
struct pstore_private *private, *pos;
- unsigned long flags;
size_t size = record->size + record->ecc_notice_size;
WARN_ON(!inode_is_locked(d_inode(root)));
- spin_lock_irqsave(&records_list_lock, flags);
+ mutex_lock(&records_list_lock);
list_for_each_entry(pos, &records_list, list) {
if (pos->record->type == record->type &&
pos->record->id == record->id &&
@@ -311,7 +308,7 @@ int pstore_mkfile(struct dentry *root, struct pstore_record *record)
break;
}
}
- spin_unlock_irqrestore(&records_list_lock, flags);
+ mutex_unlock(&records_list_lock);
if (rc)
return rc;
@@ -343,9 +340,9 @@ int pstore_mkfile(struct dentry *root, struct pstore_record *record)
d_add(dentry, inode);
- spin_lock_irqsave(&records_list_lock, flags);
+ mutex_lock(&records_list_lock);
list_add(&private->list, &records_list);
- spin_unlock_irqrestore(&records_list_lock, flags);
+ mutex_unlock(&records_list_lock);
return 0;
--
2.20.1
next prev parent reply other threads:[~2020-05-06 15:21 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-06 15:21 [PATCH 00/10] pstore: Remove filesystem records when backend is unregistered Kees Cook
2020-05-06 15:21 ` [PATCH 01/10] pstore: Drop useless try_module_get() for backend Kees Cook
2020-05-06 15:21 ` [PATCH 02/10] pstore: Rename "pstore_lock" to "psinfo_lock" Kees Cook
2020-05-06 15:21 ` [PATCH 03/10] pstore: Convert "psinfo" locking to mutex Kees Cook
2020-05-06 15:21 ` [PATCH 04/10] pstore: Rename "allpstore" to "records_list" Kees Cook
2020-05-06 15:21 ` Kees Cook [this message]
2020-05-06 15:21 ` [PATCH 06/10] pstore: Add proper unregister lock checking Kees Cook
2020-05-06 15:21 ` [PATCH 07/10] pstore: Refactor pstorefs record list removal Kees Cook
2020-05-06 15:21 ` [PATCH 08/10] pstore: Add locking around superblock changes Kees Cook
2020-05-06 15:21 ` [PATCH 09/10] pstore: Do not leave timer disabled for next backend Kees Cook
2020-05-06 15:21 ` [PATCH 10/10] pstore: Remove filesystem records when backend is unregistered Kees Cook
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200506152114.50375-6-keescook@chromium.org \
--to=keescook@chromium.org \
--cc=anton@enomsg.org \
--cc=ccross@android.com \
--cc=lhenriques@suse.com \
--cc=linux-kernel@vger.kernel.org \
--cc=tony.luck@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).