All of lore.kernel.org
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: linux-kernel@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	stable@vger.kernel.org, Scott Mayhew <smayhew@redhat.com>,
	Anna Schumaker <Anna.Schumaker@Netapp.com>,
	Qian Lu <luqia@amazon.com>
Subject: [PATCH 4.14 58/63] nfs: fix a deadlock in nfs client initialization
Date: Thu, 24 Jan 2019 20:20:47 +0100	[thread overview]
Message-ID: <20190124190202.138301116@linuxfoundation.org> (raw)
In-Reply-To: <20190124190155.176570028@linuxfoundation.org>

4.14-stable review patch.  If anyone has any objections, please let me know.

------------------

From: Scott Mayhew <smayhew@redhat.com>

commit c156618e15101a9cc8c815108fec0300a0ec6637 upstream.

The following deadlock can occur between a process waiting for a client
to initialize in while walking the client list during nfsv4 server trunking
detection and another process waiting for the nfs_clid_init_mutex so it
can initialize that client:

Process 1                               Process 2
---------                               ---------
spin_lock(&nn->nfs_client_lock);
list_add_tail(&CLIENTA->cl_share_link,
        &nn->nfs_client_list);
spin_unlock(&nn->nfs_client_lock);
                                        spin_lock(&nn->nfs_client_lock);
                                        list_add_tail(&CLIENTB->cl_share_link,
                                                &nn->nfs_client_list);
                                        spin_unlock(&nn->nfs_client_lock);
                                        mutex_lock(&nfs_clid_init_mutex);
                                        nfs41_walk_client_list(clp, result, cred);
                                        nfs_wait_client_init_complete(CLIENTA);
(waiting for nfs_clid_init_mutex)

Make sure nfs_match_client() only evaluates clients that have completed
initialization in order to prevent that deadlock.

This patch also fixes v4.0 trunking behavior by not marking the client
NFS_CS_READY until the clientid has been confirmed.

Signed-off-by: Scott Mayhew <smayhew@redhat.com>
Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com>
Signed-off-by: Qian Lu <luqia@amazon.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
 fs/nfs/client.c     |   11 +++++++++++
 fs/nfs/nfs4client.c |   17 +++++++++++++----
 2 files changed, 24 insertions(+), 4 deletions(-)

--- a/fs/nfs/client.c
+++ b/fs/nfs/client.c
@@ -291,12 +291,23 @@ static struct nfs_client *nfs_match_clie
 	const struct sockaddr *sap = data->addr;
 	struct nfs_net *nn = net_generic(data->net, nfs_net_id);
 
+again:
 	list_for_each_entry(clp, &nn->nfs_client_list, cl_share_link) {
 	        const struct sockaddr *clap = (struct sockaddr *)&clp->cl_addr;
 		/* Don't match clients that failed to initialise properly */
 		if (clp->cl_cons_state < 0)
 			continue;
 
+		/* If a client is still initializing then we need to wait */
+		if (clp->cl_cons_state > NFS_CS_READY) {
+			atomic_inc(&clp->cl_count);
+			spin_unlock(&nn->nfs_client_lock);
+			nfs_wait_client_init_complete(clp);
+			nfs_put_client(clp);
+			spin_lock(&nn->nfs_client_lock);
+			goto again;
+		}
+
 		/* Different NFS versions cannot share the same nfs_client */
 		if (clp->rpc_ops != data->nfs_mod->rpc_ops)
 			continue;
--- a/fs/nfs/nfs4client.c
+++ b/fs/nfs/nfs4client.c
@@ -404,15 +404,19 @@ struct nfs_client *nfs4_init_client(stru
 	if (error < 0)
 		goto error;
 
-	if (!nfs4_has_session(clp))
-		nfs_mark_client_ready(clp, NFS_CS_READY);
-
 	error = nfs4_discover_server_trunking(clp, &old);
 	if (error < 0)
 		goto error;
 
-	if (clp != old)
+	if (clp != old) {
 		clp->cl_preserve_clid = true;
+		/*
+		 * Mark the client as having failed initialization so other
+		 * processes walking the nfs_client_list in nfs_match_client()
+		 * won't try to use it.
+		 */
+		nfs_mark_client_ready(clp, -EPERM);
+	}
 	nfs_put_client(clp);
 	clear_bit(NFS_CS_TSM_POSSIBLE, &clp->cl_flags);
 	return old;
@@ -539,6 +543,9 @@ int nfs40_walk_client_list(struct nfs_cl
 	spin_lock(&nn->nfs_client_lock);
 	list_for_each_entry(pos, &nn->nfs_client_list, cl_share_link) {
 
+		if (pos == new)
+			goto found;
+
 		status = nfs4_match_client(pos, new, &prev, nn);
 		if (status < 0)
 			goto out_unlock;
@@ -559,6 +566,7 @@ int nfs40_walk_client_list(struct nfs_cl
 		 * way that a SETCLIENTID_CONFIRM to pos can succeed is
 		 * if new and pos point to the same server:
 		 */
+found:
 		atomic_inc(&pos->cl_count);
 		spin_unlock(&nn->nfs_client_lock);
 
@@ -572,6 +580,7 @@ int nfs40_walk_client_list(struct nfs_cl
 		case 0:
 			nfs4_swap_callback_idents(pos, new);
 			pos->cl_confirm = new->cl_confirm;
+			nfs_mark_client_ready(pos, NFS_CS_READY);
 
 			prev = NULL;
 			*result = pos;



  parent reply	other threads:[~2019-01-24 20:02 UTC|newest]

Thread overview: 71+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-24 19:19 [PATCH 4.14 00/63] 4.14.96-stable review Greg Kroah-Hartman
2019-01-24 19:19 ` [PATCH 4.14 01/63] ipv6: Consider sk_bound_dev_if when binding a socket to a v4 mapped address Greg Kroah-Hartman
2019-01-24 19:19 ` [PATCH 4.14 02/63] mlxsw: spectrum: Disable lag port TX before removing it Greg Kroah-Hartman
2019-01-24 19:19 ` [PATCH 4.14 03/63] mlxsw: spectrum_switchdev: Set PVID correctly during VLAN deletion Greg Kroah-Hartman
2019-01-24 19:19 ` [PATCH 4.14 04/63] net, skbuff: do not prefer skb allocation fails early Greg Kroah-Hartman
2019-01-24 19:19 ` [PATCH 4.14 05/63] qmi_wwan: add MTU default to qmap network interface Greg Kroah-Hartman
2019-01-24 19:19 ` [PATCH 4.14 06/63] r8169: Add support for new Realtek Ethernet Greg Kroah-Hartman
2019-01-24 19:19 ` [PATCH 4.14 07/63] ipv6: Take rcu_read_lock in __inet6_bind for mapped addresses Greg Kroah-Hartman
2019-01-24 19:19 ` [PATCH 4.14 08/63] net: dsa: mv88x6xxx: mv88e6390 errata Greg Kroah-Hartman
2019-01-24 19:19 ` [PATCH 4.14 09/63] gpio: pl061: Move irq_chip definition inside struct pl061 Greg Kroah-Hartman
2019-01-24 19:19 ` [PATCH 4.14 10/63] platform/x86: asus-wmi: Tell the EC the OS will handle the display off hotkey Greg Kroah-Hartman
2019-01-24 19:20 ` [PATCH 4.14 11/63] e1000e: allow non-monotonic SYSTIM readings Greg Kroah-Hartman
2019-01-24 19:20 ` [PATCH 4.14 12/63] writeback: dont decrement wb->refcnt if !wb->bdi Greg Kroah-Hartman
2019-01-24 19:20 ` [PATCH 4.14 13/63] serial: set suppress_bind_attrs flag only if builtin Greg Kroah-Hartman
2019-01-24 19:20 ` [PATCH 4.14 14/63] ALSA: oxfw: add support for APOGEE duet FireWire Greg Kroah-Hartman
2019-01-24 19:20 ` [PATCH 4.14 15/63] x86/mce: Fix -Wmissing-prototypes warnings Greg Kroah-Hartman
2019-01-24 19:20 ` [PATCH 4.14 16/63] MIPS: SiByte: Enable swiotlb for SWARM, LittleSur and BigSur Greg Kroah-Hartman
2019-01-24 19:20 ` [PATCH 4.14 17/63] arm64: perf: set suppress_bind_attrs flag to true Greg Kroah-Hartman
2019-01-24 19:20 ` [PATCH 4.14 18/63] usb: gadget: udc: renesas_usb3: add a safety connection way for forced_b_device Greg Kroah-Hartman
2019-01-24 19:20 ` [PATCH 4.14 19/63] selinux: always allow mounting submounts Greg Kroah-Hartman
2019-01-24 19:20 ` [PATCH 4.14 20/63] rxe: IB_WR_REG_MR does not capture MRs iova field Greg Kroah-Hartman
2019-01-24 19:20 ` [PATCH 4.14 21/63] jffs2: Fix use of uninitialized delayed_work, lockdep breakage Greg Kroah-Hartman
2019-01-24 19:20 ` [PATCH 4.14 22/63] clk: imx: make mux parent strings const Greg Kroah-Hartman
2019-01-24 19:20 ` [PATCH 4.14 23/63] pstore/ram: Do not treat empty buffers as valid Greg Kroah-Hartman
2019-01-24 19:20 ` [PATCH 4.14 24/63] powerpc/xmon: Fix invocation inside lock region Greg Kroah-Hartman
2019-01-24 19:20 ` [PATCH 4.14 25/63] powerpc/pseries/cpuidle: Fix preempt warning Greg Kroah-Hartman
2019-01-24 19:20 ` [PATCH 4.14 26/63] media: firewire: Fix app_info parameter type in avc_ca{,_app}_info Greg Kroah-Hartman
2019-01-24 19:20 ` [PATCH 4.14 27/63] media: venus: core: Set dma maximum segment size Greg Kroah-Hartman
2019-01-24 19:20 ` [PATCH 4.14 28/63] net: call sk_dst_reset when set SO_DONTROUTE Greg Kroah-Hartman
2019-01-24 19:20 ` [PATCH 4.14 29/63] scsi: target: use consistent left-aligned ASCII INQUIRY data Greg Kroah-Hartman
2019-01-24 19:20 ` [PATCH 4.14 30/63] selftests: do not macro-expand failed assertion expressions Greg Kroah-Hartman
2019-01-24 19:20   ` Greg Kroah-Hartman
2019-01-24 19:20   ` gregkh
2019-01-24 19:20 ` [PATCH 4.14 31/63] clk: imx6q: reset exclusive gates on init Greg Kroah-Hartman
2019-01-24 19:20 ` [PATCH 4.14 32/63] arm64: Fix minor issues with the dcache_by_line_op macro Greg Kroah-Hartman
2019-01-24 19:20 ` [PATCH 4.14 33/63] kconfig: fix file name and line number of warn_ignored_character() Greg Kroah-Hartman
2019-01-24 19:20 ` [PATCH 4.14 34/63] kconfig: fix memory leak when EOF is encountered in quotation Greg Kroah-Hartman
2019-01-24 19:20 ` [PATCH 4.14 35/63] mmc: atmel-mci: do not assume idle after atmci_request_end Greg Kroah-Hartman
2019-01-24 19:20 ` [PATCH 4.14 36/63] btrfs: improve error handling of btrfs_add_link Greg Kroah-Hartman
2019-01-24 19:20 ` [PATCH 4.14 37/63] tty/serial: do not free trasnmit buffer page under port lock Greg Kroah-Hartman
2019-01-24 19:20 ` [PATCH 4.14 38/63] perf intel-pt: Fix error with config term "pt=0" Greg Kroah-Hartman
2019-01-24 19:20 ` [PATCH 4.14 39/63] perf svghelper: Fix unchecked usage of strncpy() Greg Kroah-Hartman
2019-01-24 19:20 ` [PATCH 4.14 40/63] perf parse-events: " Greg Kroah-Hartman
2019-01-24 19:20 ` [PATCH 4.14 41/63] netfilter: ipt_CLUSTERIP: check MAC address when duplicate config is set Greg Kroah-Hartman
2019-01-24 19:20 ` [PATCH 4.14 42/63] dm crypt: use u64 instead of sector_t to store iv_offset Greg Kroah-Hartman
2019-01-24 19:20 ` [PATCH 4.14 43/63] dm kcopyd: Fix bug causing workqueue stalls Greg Kroah-Hartman
2019-01-24 19:20 ` [PATCH 4.14 44/63] tools lib subcmd: Dont add the kernel sources to the include path Greg Kroah-Hartman
2019-01-24 19:20 ` [PATCH 4.14 45/63] dm snapshot: Fix excessive memory usage and workqueue stalls Greg Kroah-Hartman
2019-01-24 19:20 ` [PATCH 4.14 46/63] quota: Lock s_umount in exclusive mode for Q_XQUOTA{ON,OFF} quotactls Greg Kroah-Hartman
2019-01-24 19:20 ` [PATCH 4.14 47/63] clocksource/drivers/integrator-ap: Add missing of_node_put() Greg Kroah-Hartman
2019-01-24 19:20 ` [PATCH 4.14 48/63] ALSA: bebob: fix model-id of unit for Apogee Ensemble Greg Kroah-Hartman
2019-01-24 19:20 ` [PATCH 4.14 49/63] sysfs: Disable lockdep for driver bind/unbind files Greg Kroah-Hartman
2019-01-24 19:20 ` [PATCH 4.14 50/63] IB/usnic: Fix potential deadlock Greg Kroah-Hartman
2019-01-24 19:20 ` [PATCH 4.14 51/63] scsi: smartpqi: correct lun reset issues Greg Kroah-Hartman
2019-01-24 19:20 ` [PATCH 4.14 52/63] scsi: smartpqi: call pqi_free_interrupts() in pqi_shutdown() Greg Kroah-Hartman
2019-01-24 19:20 ` [PATCH 4.14 53/63] scsi: megaraid: fix out-of-bound array accesses Greg Kroah-Hartman
2019-01-24 19:20 ` [PATCH 4.14 54/63] ocfs2: fix panic due to unrecovered local alloc Greg Kroah-Hartman
2019-01-24 19:20 ` [PATCH 4.14 55/63] mm/page-writeback.c: dont break integrity writeback on ->writepage() error Greg Kroah-Hartman
2019-01-24 19:20 ` [PATCH 4.14 56/63] mm/swap: use nr_node_ids for avail_lists in swap_info_struct Greg Kroah-Hartman
2019-01-24 19:20 ` [PATCH 4.14 57/63] mm, proc: be more verbose about unstable VMA flags in /proc/<pid>/smaps Greg Kroah-Hartman
2019-01-24 19:20 ` Greg Kroah-Hartman [this message]
2019-01-24 19:20 ` [PATCH 4.14 59/63] ipmi:pci: Blacklist a Realtek "IPMI" device Greg Kroah-Hartman
2019-01-24 19:20 ` [PATCH 4.14 60/63] cifs: allow disabling insecure dialects in the config Greg Kroah-Hartman
2019-01-24 19:20 ` [PATCH 4.14 61/63] drm/i915/gvt: Fix mmap range check Greg Kroah-Hartman
2019-01-24 19:20 ` [PATCH 4.14 62/63] PCI: dwc: Move interrupt acking into the proper callback Greg Kroah-Hartman
2019-01-24 19:20 ` [PATCH 4.14 63/63] ipmi:ssif: Fix handling of multi-part return messages Greg Kroah-Hartman
2019-01-25 14:46 ` [PATCH 4.14 00/63] 4.14.96-stable review shuah
2019-01-25 16:25 ` Naresh Kamboju
2019-01-25 23:18 ` Guenter Roeck
2019-01-26 12:08 ` Jon Hunter
2019-01-26 12:08   ` Jon Hunter

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=20190124190202.138301116@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=Anna.Schumaker@Netapp.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luqia@amazon.com \
    --cc=smayhew@redhat.com \
    --cc=stable@vger.kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.