From: Dan Magenheimer <dan.magenheimer@oracle.com>
To: "Xen-Devel (E-mail)" <xen-devel@lists.xensource.com>
Subject: [PATCH] tmem: fix domain shutdown problem/race
Date: Fri, 13 Nov 2009 16:54:18 -0800 (PST) [thread overview]
Message-ID: <03707bb2-cbca-463f-a6c1-8a4e4e1d9eff@default> (raw)
[-- Attachment #1: Type: text/plain, Size: 2351 bytes --]
Tmem fails to put_domain so a dying domain never gets
properly shut down. Also, fix race condition when
domain is dying by not allowing any new ops to succeed.
Signed-off-by: Dan Magenheimer <dan.magenheimer@oracle.com>
diff -r accded2f185f xen/common/tmem.c
--- a/xen/common/tmem.c Thu Nov 12 13:15:40 2009 +0000
+++ b/xen/common/tmem.c Fri Nov 13 17:46:24 2009 -0700
@@ -2229,6 +2229,12 @@ EXPORT long do_tmem_op(tmem_cli_op_t uop
DUP_START_CYC_COUNTER(flush,succ_get);
DUP_START_CYC_COUNTER(flush_obj,succ_get);
+ if ( client != NULL && tmh_client_is_dying(client) )
+ {
+ rc = -ENODEV;
+ goto out;
+ }
+
if ( unlikely(tmh_get_tmemop_from_client(&op, uops) != 0) )
{
printk("tmem: can't get tmem struct from %s\n",client_str);
@@ -2392,6 +2398,12 @@ EXPORT void tmem_destroy(void *v)
if ( client == NULL )
return;
+ if ( !tmh_client_is_dying(client) )
+ {
+ printk("tmem: tmem_destroy can only destroy dying client\n");
+ return;
+ }
+
if ( tmh_lock_all )
spin_lock(&tmem_spinlock);
else
diff -r accded2f185f xen/common/tmem_xen.c
--- a/xen/common/tmem_xen.c Thu Nov 12 13:15:40 2009 +0000
+++ b/xen/common/tmem_xen.c Fri Nov 13 17:46:24 2009 -0700
@@ -314,6 +314,7 @@ EXPORT void tmh_client_destroy(tmh_clien
#ifndef __i386__
xmem_pool_destroy(tmh->persistent_pool);
#endif
+ put_domain(tmh->domain);
xfree(tmh);
}
diff -r accded2f185f xen/include/xen/tmem_xen.h
--- a/xen/include/xen/tmem_xen.h Thu Nov 12 13:15:40 2009 +0000
+++ b/xen/include/xen/tmem_xen.h Fri Nov 13 17:46:24 2009 -0700
@@ -280,7 +280,7 @@ typedef struct page_info pfp_t;
/* this appears to be unreliable when a domain is being shut down */
static inline struct client *tmh_client_from_cli_id(cli_id_t cli_id)
{
- struct domain *d = get_domain_by_id(cli_id);
+ struct domain *d = get_domain_by_id(cli_id); /* incs d->refcnt! */
if (d == NULL)
return NULL;
return (struct client *)(d->tmem);
@@ -290,6 +290,8 @@ static inline struct client *tmh_client_
{
return (struct client *)(current->domain->tmem);
}
+
+#define tmh_client_is_dying(_client) (!!_client->tmh->domain->is_dying)
static inline cli_id_t tmh_get_cli_id_from_current(void)
{
[-- Attachment #2: tmem-race.patch --]
[-- Type: application/octet-stream, Size: 2063 bytes --]
diff -r accded2f185f xen/common/tmem.c
--- a/xen/common/tmem.c Thu Nov 12 13:15:40 2009 +0000
+++ b/xen/common/tmem.c Fri Nov 13 17:46:24 2009 -0700
@@ -2229,6 +2229,12 @@ EXPORT long do_tmem_op(tmem_cli_op_t uop
DUP_START_CYC_COUNTER(flush,succ_get);
DUP_START_CYC_COUNTER(flush_obj,succ_get);
+ if ( client != NULL && tmh_client_is_dying(client) )
+ {
+ rc = -ENODEV;
+ goto out;
+ }
+
if ( unlikely(tmh_get_tmemop_from_client(&op, uops) != 0) )
{
printk("tmem: can't get tmem struct from %s\n",client_str);
@@ -2392,6 +2398,12 @@ EXPORT void tmem_destroy(void *v)
if ( client == NULL )
return;
+ if ( !tmh_client_is_dying(client) )
+ {
+ printk("tmem: tmem_destroy can only destroy dying client\n");
+ return;
+ }
+
if ( tmh_lock_all )
spin_lock(&tmem_spinlock);
else
diff -r accded2f185f xen/common/tmem_xen.c
--- a/xen/common/tmem_xen.c Thu Nov 12 13:15:40 2009 +0000
+++ b/xen/common/tmem_xen.c Fri Nov 13 17:46:24 2009 -0700
@@ -314,6 +314,7 @@ EXPORT void tmh_client_destroy(tmh_clien
#ifndef __i386__
xmem_pool_destroy(tmh->persistent_pool);
#endif
+ put_domain(tmh->domain);
xfree(tmh);
}
diff -r accded2f185f xen/include/xen/tmem_xen.h
--- a/xen/include/xen/tmem_xen.h Thu Nov 12 13:15:40 2009 +0000
+++ b/xen/include/xen/tmem_xen.h Fri Nov 13 17:46:24 2009 -0700
@@ -280,7 +280,7 @@ typedef struct page_info pfp_t;
/* this appears to be unreliable when a domain is being shut down */
static inline struct client *tmh_client_from_cli_id(cli_id_t cli_id)
{
- struct domain *d = get_domain_by_id(cli_id);
+ struct domain *d = get_domain_by_id(cli_id); /* incs d->refcnt! */
if (d == NULL)
return NULL;
return (struct client *)(d->tmem);
@@ -290,6 +290,8 @@ static inline struct client *tmh_client_
{
return (struct client *)(current->domain->tmem);
}
+
+#define tmh_client_is_dying(_client) (!!_client->tmh->domain->is_dying)
static inline cli_id_t tmh_get_cli_id_from_current(void)
{
[-- Attachment #3: Type: text/plain, Size: 138 bytes --]
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xensource.com
http://lists.xensource.com/xen-devel
reply other threads:[~2009-11-14 0:54 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=03707bb2-cbca-463f-a6c1-8a4e4e1d9eff@default \
--to=dan.magenheimer@oracle.com \
--cc=xen-devel@lists.xensource.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 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.