All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] xen/tmem: Don't over-write tmem_frontswap_poolid after tmem_frontswap_init set it.
@ 2013-06-07 19:29 Konrad Rzeszutek Wilk
  2013-06-07 19:45 ` Konrad Rzeszutek Wilk
  0 siblings, 1 reply; 3+ messages in thread
From: Konrad Rzeszutek Wilk @ 2013-06-07 19:29 UTC (permalink / raw)
  To: linux-kernel, xen-devel; +Cc: dan.magenheimer, Konrad Rzeszutek Wilk

Commit 10a7a0771399a57a297fca9615450dbb3f88081a ("xen: tmem: enable Xen
tmem shim to be built/loaded as a module") allows the tmem module
to be loaded any time. For this work the frontswap API had to
be able to asynchronously to call tmem_frontswap_init before
or after the swap image had been set. That was added in git
commit 905cd0e1bf9ffe82d6906a01fd974ea0f70be97a
("mm: frontswap: lazy initialization to allow tmem backends to build/run as modules").

Which means we could do this (The common case):

 modprobe tmem		[so calls frontswap_register_ops, no ->init]
			 modifies tmem_frontswap_poolid = -1
 swapon /dev/xvda1	[__frontswap_init, calls -> init, tmem_frontswap_poolid is
			 < 0 so tmem hypercall done]

Or the failing one:

 swapon /dev/xvda1	[calls __frontswap_init, sets the need_init bitmap]
 modprobe tmem		[calls frontswap_register_ops, -->init calls, finds out
			tmem_frontswap_poolid is 0, does not make a hypercall.
			Later in the module_init, sets tmem_frontswap_poolid=-1]

Which meant that in the failing case we would not call the hypercall
to initialize the pool and never be able to make any frontswap
backend calls.

Moving the frontswap_register_ops after setting the tmem_frontswap_poolid
fixes it.

Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
---
 drivers/xen/tmem.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/xen/tmem.c b/drivers/xen/tmem.c
index cc072c6..0f0493c 100644
--- a/drivers/xen/tmem.c
+++ b/drivers/xen/tmem.c
@@ -379,10 +379,10 @@ static int xen_tmem_init(void)
 #ifdef CONFIG_FRONTSWAP
 	if (tmem_enabled && frontswap) {
 		char *s = "";
-		struct frontswap_ops *old_ops =
-			frontswap_register_ops(&tmem_frontswap_ops);
+		struct frontswap_ops *old_ops;
 
 		tmem_frontswap_poolid = -1;
+		old_ops = frontswap_register_ops(&tmem_frontswap_ops);
 		if (IS_ERR(old_ops) || old_ops) {
 			if (IS_ERR(old_ops))
 				return PTR_ERR(old_ops);
-- 
1.8.1.4


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] xen/tmem: Don't over-write tmem_frontswap_poolid after tmem_frontswap_init set it.
  2013-06-07 19:29 [PATCH] xen/tmem: Don't over-write tmem_frontswap_poolid after tmem_frontswap_init set it Konrad Rzeszutek Wilk
@ 2013-06-07 19:45 ` Konrad Rzeszutek Wilk
  2013-06-08  1:07   ` Bob Liu
  0 siblings, 1 reply; 3+ messages in thread
From: Konrad Rzeszutek Wilk @ 2013-06-07 19:45 UTC (permalink / raw)
  To: linux-kernel, xen-devel, bob.liu; +Cc: dan.magenheimer

On Fri, Jun 07, 2013 at 12:29:15PM -0700, Konrad Rzeszutek Wilk wrote:

CC-ing Bob.

> Commit 10a7a0771399a57a297fca9615450dbb3f88081a ("xen: tmem: enable Xen
> tmem shim to be built/loaded as a module") allows the tmem module
> to be loaded any time. For this work the frontswap API had to
> be able to asynchronously to call tmem_frontswap_init before
> or after the swap image had been set. That was added in git
> commit 905cd0e1bf9ffe82d6906a01fd974ea0f70be97a
> ("mm: frontswap: lazy initialization to allow tmem backends to build/run as modules").
> 
> Which means we could do this (The common case):
> 
>  modprobe tmem		[so calls frontswap_register_ops, no ->init]
> 			 modifies tmem_frontswap_poolid = -1
>  swapon /dev/xvda1	[__frontswap_init, calls -> init, tmem_frontswap_poolid is
> 			 < 0 so tmem hypercall done]
> 
> Or the failing one:
> 
>  swapon /dev/xvda1	[calls __frontswap_init, sets the need_init bitmap]
>  modprobe tmem		[calls frontswap_register_ops, -->init calls, finds out
> 			tmem_frontswap_poolid is 0, does not make a hypercall.
> 			Later in the module_init, sets tmem_frontswap_poolid=-1]
> 
> Which meant that in the failing case we would not call the hypercall
> to initialize the pool and never be able to make any frontswap
> backend calls.
> 
> Moving the frontswap_register_ops after setting the tmem_frontswap_poolid
> fixes it.
> 
> Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
> ---
>  drivers/xen/tmem.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/xen/tmem.c b/drivers/xen/tmem.c
> index cc072c6..0f0493c 100644
> --- a/drivers/xen/tmem.c
> +++ b/drivers/xen/tmem.c
> @@ -379,10 +379,10 @@ static int xen_tmem_init(void)
>  #ifdef CONFIG_FRONTSWAP
>  	if (tmem_enabled && frontswap) {
>  		char *s = "";
> -		struct frontswap_ops *old_ops =
> -			frontswap_register_ops(&tmem_frontswap_ops);
> +		struct frontswap_ops *old_ops;
>  
>  		tmem_frontswap_poolid = -1;
> +		old_ops = frontswap_register_ops(&tmem_frontswap_ops);
>  		if (IS_ERR(old_ops) || old_ops) {
>  			if (IS_ERR(old_ops))
>  				return PTR_ERR(old_ops);
> -- 
> 1.8.1.4
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] xen/tmem: Don't over-write tmem_frontswap_poolid after tmem_frontswap_init set it.
  2013-06-07 19:45 ` Konrad Rzeszutek Wilk
@ 2013-06-08  1:07   ` Bob Liu
  0 siblings, 0 replies; 3+ messages in thread
From: Bob Liu @ 2013-06-08  1:07 UTC (permalink / raw)
  To: Konrad Rzeszutek Wilk; +Cc: linux-kernel, xen-devel, dan.magenheimer

On 06/08/2013 03:45 AM, Konrad Rzeszutek Wilk wrote:
> On Fri, Jun 07, 2013 at 12:29:15PM -0700, Konrad Rzeszutek Wilk wrote:
> 
> CC-ing Bob.
> 
>> Commit 10a7a0771399a57a297fca9615450dbb3f88081a ("xen: tmem: enable Xen
>> tmem shim to be built/loaded as a module") allows the tmem module
>> to be loaded any time. For this work the frontswap API had to
>> be able to asynchronously to call tmem_frontswap_init before
>> or after the swap image had been set. That was added in git
>> commit 905cd0e1bf9ffe82d6906a01fd974ea0f70be97a
>> ("mm: frontswap: lazy initialization to allow tmem backends to build/run as modules").
>>
>> Which means we could do this (The common case):
>>
>>  modprobe tmem		[so calls frontswap_register_ops, no ->init]
>> 			 modifies tmem_frontswap_poolid = -1
>>  swapon /dev/xvda1	[__frontswap_init, calls -> init, tmem_frontswap_poolid is
>> 			 < 0 so tmem hypercall done]
>>
>> Or the failing one:
>>
>>  swapon /dev/xvda1	[calls __frontswap_init, sets the need_init bitmap]
>>  modprobe tmem		[calls frontswap_register_ops, -->init calls, finds out
>> 			tmem_frontswap_poolid is 0, does not make a hypercall.
>> 			Later in the module_init, sets tmem_frontswap_poolid=-1]
>>
>> Which meant that in the failing case we would not call the hypercall
>> to initialize the pool and never be able to make any frontswap
>> backend calls.
>>
>> Moving the frontswap_register_ops after setting the tmem_frontswap_poolid
>> fixes it.
>>
>> Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>

Nice catch!
Reviewed-by: Bob Liu <bob.liu@oracle.com>

>> ---
>>  drivers/xen/tmem.c | 4 ++--
>>  1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/xen/tmem.c b/drivers/xen/tmem.c
>> index cc072c6..0f0493c 100644
>> --- a/drivers/xen/tmem.c
>> +++ b/drivers/xen/tmem.c
>> @@ -379,10 +379,10 @@ static int xen_tmem_init(void)
>>  #ifdef CONFIG_FRONTSWAP
>>  	if (tmem_enabled && frontswap) {
>>  		char *s = "";
>> -		struct frontswap_ops *old_ops =
>> -			frontswap_register_ops(&tmem_frontswap_ops);
>> +		struct frontswap_ops *old_ops;
>>  
>>  		tmem_frontswap_poolid = -1;
>> +		old_ops = frontswap_register_ops(&tmem_frontswap_ops);
>>  		if (IS_ERR(old_ops) || old_ops) {
>>  			if (IS_ERR(old_ops))
>>  				return PTR_ERR(old_ops);
>> -- 
>> 1.8.1.4
>>

-- 
Regards,
-Bob

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2013-06-08  1:07 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-06-07 19:29 [PATCH] xen/tmem: Don't over-write tmem_frontswap_poolid after tmem_frontswap_init set it Konrad Rzeszutek Wilk
2013-06-07 19:45 ` Konrad Rzeszutek Wilk
2013-06-08  1:07   ` Bob Liu

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.