All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dexuan Cui <decui@microsoft.com>
To: gregkh@linuxfoundation.org, davem@davemloft.net,
	stephen@networkplumber.org, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	driverdev-devel@linuxdriverproject.org, olaf@aepfle.de,
	apw@canonical.com, jasowang@redhat.com, kys@microsoft.com,
	pebolle@tiscali.nl, stefanha@redhat.com
Subject: [PATCH V3 7/7] Drivers: hv: vmbus: disable local interrupt when hvsock's callback is running
Date: Tue, 21 Jul 2015 03:58:55 -0700	[thread overview]
Message-ID: <1437476335-6974-1-git-send-email-decui@microsoft.com> (raw)

In the SMP guest case, when the per-channel callback hvsock_events() is
running on virtual CPU A, if the guest tries to close the connection on
virtual CPU B: we invoke vmbus_close() -> vmbus_close_internal(),
then we can have trouble: on B, vmbus_close_internal() will send IPI
reset_channel_cb() to A, trying to set channel->onchannel_callbackto NULL;
on A, if the IPI handler happens between
"if (channel->onchannel_callback != NULL)" and invoking
channel->onchannel_callback, we'll invoke a function pointer of NULL.

This is why the patch is necessary.

Signed-off-by: Dexuan Cui <decui@microsoft.com>
---
 drivers/hv/connection.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/drivers/hv/connection.c b/drivers/hv/connection.c
index 4fc2e88..4766fd8 100644
--- a/drivers/hv/connection.c
+++ b/drivers/hv/connection.c
@@ -319,6 +319,9 @@ static void process_chn_event(u32 relid)
 	void *arg;
 	bool read_state;
 	u32 bytes_to_read;
+	bool is_hvsock = false;
+
+	local_irq_disable();
 
 	/*
 	 * Find the channel based on this relid and invokes the
@@ -327,7 +330,11 @@ static void process_chn_event(u32 relid)
 	channel = pcpu_relid2channel(relid);
 
 	if (!channel)
-		return;
+		goto out;
+
+	is_hvsock = is_hvsock_channel(channel);
+	if (!is_hvsock)
+		local_irq_enable();
 
 	/*
 	 * A channel once created is persistent even when there
@@ -363,6 +370,12 @@ static void process_chn_event(u32 relid)
 				bytes_to_read = 0;
 		} while (read_state && (bytes_to_read != 0));
 	}
+
+	/* local_irq_enable() is alredy invoked above */
+	if (!is_hvsock)
+		return;
+out:
+	local_irq_enable();
 }
 
 /*
-- 
2.1.0


WARNING: multiple messages have this Message-ID (diff)
From: Dexuan Cui <decui@microsoft.com>
To: gregkh@linuxfoundation.org, davem@davemloft.net,
	stephen@networkplumber.org, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	driverdev-devel@linuxdriverproject.org, olaf@aepfle.de,
	apw@canonical.com, jasowang@redhat.com, kys@microsoft.com,
	pebolle@tiscali.nl, stefanha@redhat.com
Subject: [PATCH V3 7/7] Drivers: hv: vmbus: disable local interrupt when hvsock's callback is running
Date: Tue, 21 Jul 2015 03:58:55 -0700	[thread overview]
Message-ID: <1437476335-6974-1-git-send-email-decui@microsoft.com> (raw)

In the SMP guest case, when the per-channel callback hvsock_events() is
running on virtual CPU A, if the guest tries to close the connection on
virtual CPU B: we invoke vmbus_close() -> vmbus_close_internal(),
then we can have trouble: on B, vmbus_close_internal() will send IPI
reset_channel_cb() to A, trying to set channel->onchannel_callbackto NULL;
on A, if the IPI handler happens between
"if (channel->onchannel_callback != NULL)" and invoking
channel->onchannel_callback, we'll invoke a function pointer of NULL.

This is why the patch is necessary.

Signed-off-by: Dexuan Cui <decui@microsoft.com>
---
 drivers/hv/connection.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/drivers/hv/connection.c b/drivers/hv/connection.c
index 4fc2e88..4766fd8 100644
--- a/drivers/hv/connection.c
+++ b/drivers/hv/connection.c
@@ -319,6 +319,9 @@ static void process_chn_event(u32 relid)
 	void *arg;
 	bool read_state;
 	u32 bytes_to_read;
+	bool is_hvsock = false;
+
+	local_irq_disable();
 
 	/*
 	 * Find the channel based on this relid and invokes the
@@ -327,7 +330,11 @@ static void process_chn_event(u32 relid)
 	channel = pcpu_relid2channel(relid);
 
 	if (!channel)
-		return;
+		goto out;
+
+	is_hvsock = is_hvsock_channel(channel);
+	if (!is_hvsock)
+		local_irq_enable();
 
 	/*
 	 * A channel once created is persistent even when there
@@ -363,6 +370,12 @@ static void process_chn_event(u32 relid)
 				bytes_to_read = 0;
 		} while (read_state && (bytes_to_read != 0));
 	}
+
+	/* local_irq_enable() is alredy invoked above */
+	if (!is_hvsock)
+		return;
+out:
+	local_irq_enable();
 }
 
 /*
-- 
2.1.0

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

             reply	other threads:[~2015-07-21  9:34 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-21 10:58 Dexuan Cui [this message]
2015-07-21 10:58 ` [PATCH V3 7/7] Drivers: hv: vmbus: disable local interrupt when hvsock's callback is running Dexuan Cui

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=1437476335-6974-1-git-send-email-decui@microsoft.com \
    --to=decui@microsoft.com \
    --cc=apw@canonical.com \
    --cc=davem@davemloft.net \
    --cc=driverdev-devel@linuxdriverproject.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=jasowang@redhat.com \
    --cc=kys@microsoft.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=olaf@aepfle.de \
    --cc=pebolle@tiscali.nl \
    --cc=stefanha@redhat.com \
    --cc=stephen@networkplumber.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.