diff mbox series

[-next] cifs: Use GFP_ATOMIC when a lock is held in cifs_mount()

Message ID 1545096879-123632-1-git-send-email-yuehaibing@huawei.com (mailing list archive)
State New, archived
Headers show
Series [-next] cifs: Use GFP_ATOMIC when a lock is held in cifs_mount() | expand

Commit Message

Yue Haibing Dec. 18, 2018, 1:34 a.m. UTC
A spin lock is held before kstrndup, it may sleep with holding
the spinlock, so we should use GFP_ATOMIC instead.

Fixes: e58c31d5e387 ("cifs: Add support for failover in cifs_reconnect()")
Signed-off-by: YueHaibing <yuehaibing@huawei.com>
---
 fs/cifs/connect.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Paulo Alcantara (SUSE) Dec. 18, 2018, 1:51 a.m. UTC | #1
On December 17, 2018 11:34:39 PM GMT-02:00, YueHaibing <yuehaibing@huawei.com> wrote:
>A spin lock is held before kstrndup, it may sleep with holding
>the spinlock, so we should use GFP_ATOMIC instead.
>
>Fixes: e58c31d5e387 ("cifs: Add support for failover in
>cifs_reconnect()")
>Signed-off-by: YueHaibing <yuehaibing@huawei.com>
>---
> fs/cifs/connect.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
>diff --git a/fs/cifs/connect.c b/fs/cifs/connect.c
>index a83aa61..3d5e308 100644
>--- a/fs/cifs/connect.c
>+++ b/fs/cifs/connect.c
>@@ -4574,7 +4574,8 @@ int cifs_mount(struct cifs_sb_info *cifs_sb,
>struct smb_vol *vol)
> 		tcon->remap = cifs_remap(cifs_sb);
> 	}
> 	cifs_sb->origin_fullpath = kstrndup(tcon->dfs_path,
>-					    strlen(tcon->dfs_path), GFP_KERNEL);
>+					    strlen(tcon->dfs_path),
>+					    GFP_ATOMIC);
> 	if (!cifs_sb->origin_fullpath) {
> 		spin_unlock(&cifs_tcp_ses_lock);
> 		rc = -ENOMEM;

Reviewed-by: Paulo Alcantara <palcantara@suse.de>

Thanks
Paulo
Steve French Dec. 18, 2018, 2:05 a.m. UTC | #2
merged into cifs-2.6.git for-next

On Mon, Dec 17, 2018 at 7:58 PM Paulo Alcantara <paulo@paulo.ac> wrote:
>
>
>
> On December 17, 2018 11:34:39 PM GMT-02:00, YueHaibing <yuehaibing@huawei.com> wrote:
> >A spin lock is held before kstrndup, it may sleep with holding
> >the spinlock, so we should use GFP_ATOMIC instead.
> >
> >Fixes: e58c31d5e387 ("cifs: Add support for failover in
> >cifs_reconnect()")
> >Signed-off-by: YueHaibing <yuehaibing@huawei.com>
> >---
> > fs/cifs/connect.c | 3 ++-
> > 1 file changed, 2 insertions(+), 1 deletion(-)
> >
> >diff --git a/fs/cifs/connect.c b/fs/cifs/connect.c
> >index a83aa61..3d5e308 100644
> >--- a/fs/cifs/connect.c
> >+++ b/fs/cifs/connect.c
> >@@ -4574,7 +4574,8 @@ int cifs_mount(struct cifs_sb_info *cifs_sb,
> >struct smb_vol *vol)
> >               tcon->remap = cifs_remap(cifs_sb);
> >       }
> >       cifs_sb->origin_fullpath = kstrndup(tcon->dfs_path,
> >-                                          strlen(tcon->dfs_path), GFP_KERNEL);
> >+                                          strlen(tcon->dfs_path),
> >+                                          GFP_ATOMIC);
> >       if (!cifs_sb->origin_fullpath) {
> >               spin_unlock(&cifs_tcp_ses_lock);
> >               rc = -ENOMEM;
>
> Reviewed-by: Paulo Alcantara <palcantara@suse.de>
>
> Thanks
> Paulo
> --
> Sent from my Android device with K-9 Mail. Please excuse my brevity.
Tom Talpey Dec. 18, 2018, 3:21 p.m. UTC | #3
> -----Original Message-----
> From: linux-cifs-owner@vger.kernel.org <linux-cifs-owner@vger.kernel.org> On
> Behalf Of Steve French
> Sent: Monday, December 17, 2018 9:06 PM
> To: Paulo Alcantara <paulo@paulo.ac>
> Cc: YueHaibing <yuehaibing@huawei.com>; Steve French
> <sfrench@samba.org>; CIFS <linux-cifs@vger.kernel.org>; samba-technical
> <samba-technical@lists.samba.org>; kernel-janitors <kernel-
> janitors@vger.kernel.org>
> Subject: Re: [PATCH -next] cifs: Use GFP_ATOMIC when a lock is held in
> cifs_mount()
> 
> merged into cifs-2.6.git for-next
> 
> On Mon, Dec 17, 2018 at 7:58 PM Paulo Alcantara <paulo@paulo.ac> wrote:
> >
> >
> >
> > On December 17, 2018 11:34:39 PM GMT-02:00, YueHaibing
> <yuehaibing@huawei.com> wrote:
> > >A spin lock is held before kstrndup, it may sleep with holding
> > >the spinlock, so we should use GFP_ATOMIC instead.

Wouldn't it be better to allocate the memory before entering the
spinlock-protected section altogether?

Tom.

> > >Fixes: e58c31d5e387 ("cifs: Add support for failover in
> > >cifs_reconnect()")
> > >Signed-off-by: YueHaibing <yuehaibing@huawei.com>
> > >---
> > > fs/cifs/connect.c | 3 ++-
> > > 1 file changed, 2 insertions(+), 1 deletion(-)
> > >
> > >diff --git a/fs/cifs/connect.c b/fs/cifs/connect.c
> > >index a83aa61..3d5e308 100644
> > >--- a/fs/cifs/connect.c
> > >+++ b/fs/cifs/connect.c
> > >@@ -4574,7 +4574,8 @@ int cifs_mount(struct cifs_sb_info *cifs_sb,
> > >struct smb_vol *vol)
> > >               tcon->remap = cifs_remap(cifs_sb);
> > >       }
> > >       cifs_sb->origin_fullpath = kstrndup(tcon->dfs_path,
> > >-                                          strlen(tcon->dfs_path), GFP_KERNEL);
> > >+                                          strlen(tcon->dfs_path),
> > >+                                          GFP_ATOMIC);
> > >       if (!cifs_sb->origin_fullpath) {
> > >               spin_unlock(&cifs_tcp_ses_lock);
> > >               rc = -ENOMEM;
> >
> > Reviewed-by: Paulo Alcantara <palcantara@suse.de>
> >
> > Thanks
> > Paulo
> > --
> > Sent from my Android device with K-9 Mail. Please excuse my brevity.
> 
> 
> 
> --
> Thanks,
> 
> Steve
diff mbox series

Patch

diff --git a/fs/cifs/connect.c b/fs/cifs/connect.c
index a83aa61..3d5e308 100644
--- a/fs/cifs/connect.c
+++ b/fs/cifs/connect.c
@@ -4574,7 +4574,8 @@  int cifs_mount(struct cifs_sb_info *cifs_sb, struct smb_vol *vol)
 		tcon->remap = cifs_remap(cifs_sb);
 	}
 	cifs_sb->origin_fullpath = kstrndup(tcon->dfs_path,
-					    strlen(tcon->dfs_path), GFP_KERNEL);
+					    strlen(tcon->dfs_path),
+					    GFP_ATOMIC);
 	if (!cifs_sb->origin_fullpath) {
 		spin_unlock(&cifs_tcp_ses_lock);
 		rc = -ENOMEM;