xen/gntdev: fix up blockable calls to mn_invl_range_start
Subsystems (2)
PATCH 1/1 xen/gntdev: fix up blockable calls to mn_invl_range_start
From: Michal Hocko <[email protected]>
93065ac753e4 ("mm, oom: distinguish blockable mode for mmu notifiers") has introduced blockable parameter to all mmu_notifiers and the notifier has to back off when called in !blockable case and it could block down the road.
The above commit implemented that for mn_invl_range_start but both in_range checks are done unconditionally regardless of the blockable mode and as such they would fail all the time for regular calls. Fix this by checking blockable parameter as well.
Once we are there we can remove the stale TODO. The lock has to be sleepable because we wait for completion down in gnttab_unmap_refs_sync.
--- drivers/xen/gntdev.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/xen/gntdev.c +2 -3
@@ -519,21 +519,20 @@ static int mn_invl_range_start(struct mmu_notifier *mn,struct gntdev_grant_map *map;int ret =0 ; -/* TODO do we really need a mutex here? */ if (blockable)mutex_lock (&priv->lock);else if (!mutex_trylock (&priv->lock))return -EAGAIN ;list_for_each_entry (map, &priv->maps, next) { -if (in_range (map, start, end)) { +if (!blockable &&in_range (map, start, end)) { ret = -EAGAIN ; goto out_unlock; }unmap_if_in_range (map, start, end); }list_for_each_entry (map, &priv->freeable_maps, next) { -if (in_range (map, start, end)) { +if (!blockable &&in_range (map, start, end)) { ret = -EAGAIN ; goto out_unlock; }
Signature · 1 line
2.18.0
Quoted 7 lines · Michal Hocko
drivers/xen/gntdev.c +0
-0@@ -519,21 +519,20 @@ static int mn_invl_range_start(struct mmu_notifier *mn,struct gntdev_grant_map *map;int ret =0 ;
drivers/xen/gntdev.c static int mn_invl_range_start(struct mmu_notifier *mn, · line 528
Quoted 10 lines
drivers/xen/gntdev.c +1
-2-/* TODO do we really need a mutex here? */ if (blockable)mutex_lock (&priv->lock);else if (!mutex_trylock (&priv->lock))return -EAGAIN ;list_for_each_entry (map, &priv->maps, next) { -if (in_range (map, start, end)) { +if (!blockable &&in_range (map, start, end)) {
This still looks strange. Prior to 93065ac753e4, in_range() test was inside unmap_if_in_range(). But this patch removes in_range() test if blockable == true. That is, unmap_if_in_range() will unconditionally unmap if blockable == true, which seems to be an unexpected change.
Quoted 5 lines
drivers/xen/gntdev.c +0
-0ret = -EAGAIN ; goto out_unlock; }unmap_if_in_range (map, start, end); }
Quoted 7 lines · Michal Hocko
drivers/xen/gntdev.c +0
-0@@ -519,21 +519,20 @@ static int mn_invl_range_start(struct mmu_notifier *mn,struct gntdev_grant_map *map;int ret =0 ;
drivers/xen/gntdev.c static int mn_invl_range_start(struct mmu_notifier *mn, · line 528
Quoted 10 lines
drivers/xen/gntdev.c +1
-2-/* TODO do we really need a mutex here? */ if (blockable)mutex_lock (&priv->lock);else if (!mutex_trylock (&priv->lock))return -EAGAIN ;list_for_each_entry (map, &priv->maps, next) { -if (in_range (map, start, end)) { +if (!blockable &&in_range (map, start, end)) {
This still looks strange. Prior to 93065ac753e4, in_range() test was inside unmap_if_in_range(). But this patch removes in_range() test if blockable == true. That is, unmap_if_in_range() will unconditionally unmap if blockable == true, which seems to be an unexpected change.
drivers/xen/gntdev.c static int mn_invl_range_start(struct mmu_notifier *mn, · line 533
Quoted 5 lines
drivers/xen/gntdev.c +0
-0ret = -EAGAIN ; goto out_unlock; }unmap_if_in_range (map, start, end); }
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 12 lines · Michal Hocko
From: Michal Hocko <[email protected]>
93065ac753e4("mm, oom: distinguish blockable mode for mmu notifiers") has introduced blockable parameter to allmmu_notifiersand the notifier has to back off when called in !blockable case and it could block down the road.The above commit implemented that for
mn_invl_range_startbut bothin_rangechecks are done unconditionally regardless of the blockable mode and as such they would fail all the time for regular calls. Fix this by checking blockable parameter as well.
Quoted 7 lines
Once we are there we can remove the stale TODO. The lock has to be sleepable because we wait for completion down in
gnttab_unmap_refs_sync.Fixes 93065ac753e4 ("mm, oom: distinguish blockable mode for mmu notifiers")Cc Boris Ostrovsky <[email protected]>Cc Juergen Gross <[email protected]>Signed-off-by Michal Hocko <[email protected]>
Quoted 12 lines · Michal Hocko
From: Michal Hocko <[email protected]>
93065ac753e4("mm, oom: distinguish blockable mode for mmu notifiers") has introduced blockable parameter to allmmu_notifiersand the notifier has to back off when called in !blockable case and it could block down the road.The above commit implemented that for
mn_invl_range_startbut bothin_rangechecks are done unconditionally regardless of the blockable mode and as such they would fail all the time for regular calls. Fix this by checking blockable parameter as well.
Quoted 7 lines
Once we are there we can remove the stale TODO. The lock has to be sleepable because we wait for completion down in
gnttab_unmap_refs_sync.Fixes 93065ac753e4 ("mm, oom: distinguish blockable mode for mmu notifiers")Cc Boris Ostrovsky <[email protected]>Cc Juergen Gross <[email protected]>Signed-off-by Michal Hocko <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 15 lines · Tetsuo Handa
Quoted 14 lines · Michal Hocko
drivers/xen/gntdev.c +0
-1@@ -519,21 +519,20 @@ static int mn_invl_range_start(struct mmu_notifier *mn,struct gntdev_grant_map *map;int ret =0 ; -/* TODO do we really need a mutex here? */ if (blockable)mutex_lock (&priv->lock);else if (!mutex_trylock (&priv->lock))return -EAGAIN ;
Quoted 8 lines
drivers/xen/gntdev.c static int mn_invl_range_start(struct mmu_notifier *mn, · line 528
Quoted 3 lines
drivers/xen/gntdev.c +1
-1list_for_each_entry (map, &priv->maps, next) { -if (in_range (map, start, end)) { +if (!blockable &&in_range (map, start, end)) {This still looks strange. Prior to
93065ac753e4,in_range()test was insideunmap_if_in_range(). But this patch removesin_range()test if blockable == true. That is,unmap_if_in_range()will unconditionally unmap if blockable == true, which seems to be an unexpected change.
You are right. I completely forgot I've removed in_range there. Does this look any better?
drivers/xen/gntdev.c +8 -2
@@ -525,14 +525,20 @@ static int mn_invl_range_start(struct mmu_notifier *mn,return -EAGAIN ;list_for_each_entry (map, &priv->maps, next) { -if (!blockable &&in_range (map, start, end)) { +if (in_range (map, start, end)) { +if (blockable) +continue ; + ret = -EAGAIN ; goto out_unlock; }unmap_if_in_range (map, start, end); }list_for_each_entry (map, &priv->freeable_maps, next) { -if (!blockable &&in_range (map, start, end)) { +if (in_range (map, start, end)) { +if (blockable) +continue ; + ret = -EAGAIN ; goto out_unlock; }
Signature · 2 lines
Michal Hocko SUSE Labs
Quoted 15 lines · Tetsuo Handa
Quoted 14 lines · Michal Hocko
drivers/xen/gntdev.c +0
-1@@ -519,21 +519,20 @@ static int mn_invl_range_start(struct mmu_notifier *mn,struct gntdev_grant_map *map;int ret =0 ; -/* TODO do we really need a mutex here? */ if (blockable)mutex_lock (&priv->lock);else if (!mutex_trylock (&priv->lock))return -EAGAIN ;
Quoted 8 lines
drivers/xen/gntdev.c static int mn_invl_range_start(struct mmu_notifier *mn, · line 528
Quoted 3 lines
drivers/xen/gntdev.c +1
-1list_for_each_entry (map, &priv->maps, next) { -if (in_range (map, start, end)) { +if (!blockable &&in_range (map, start, end)) {This still looks strange. Prior to
93065ac753e4,in_range()test was insideunmap_if_in_range(). But this patch removesin_range()test if blockable == true. That is,unmap_if_in_range()will unconditionally unmap if blockable == true, which seems to be an unexpected change.
You are right. I completely forgot I've removed in_range there. Does this look any better?
drivers/xen/gntdev.c +8 -2
@@ -525,14 +525,20 @@ static int mn_invl_range_start(struct mmu_notifier *mn,return -EAGAIN ;list_for_each_entry (map, &priv->maps, next) { -if (!blockable &&in_range (map, start, end)) { +if (in_range (map, start, end)) { +if (blockable) +continue ; + ret = -EAGAIN ; goto out_unlock; }unmap_if_in_range (map, start, end); }list_for_each_entry (map, &priv->freeable_maps, next) { -if (!blockable &&in_range (map, start, end)) { +if (in_range (map, start, end)) { +if (blockable) +continue ; + ret = -EAGAIN ; goto out_unlock; }
Signature · 7 lines
Michal Hocko SUSE Labs _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 33 lines · Michal Hocko
Quoted 15 lines · Tetsuo Handa
Quoted 14 lines · Michal Hocko
drivers/xen/gntdev.c +0
-1@@ -519,21 +519,20 @@ static int mn_invl_range_start(struct mmu_notifier *mn,struct gntdev_grant_map *map;int ret =0 ; -/* TODO do we really need a mutex here? */ if (blockable)mutex_lock (&priv->lock);else if (!mutex_trylock (&priv->lock))return -EAGAIN ;Quoted 7 lines
drivers/xen/gntdev.c static int mn_invl_range_start(struct mmu_notifier *mn, · line 528
Quoted 3 lines
drivers/xen/gntdev.c +1
-1list_for_each_entry (map, &priv->maps, next) { -if (in_range (map, start, end)) { +if (!blockable &&in_range (map, start, end)) {This still looks strange. Prior to
93065ac753e4,in_range()test was insideunmap_if_in_range(). But this patch removesin_range()test if blockable == true. That is,unmap_if_in_range()will unconditionally unmap if blockable == true, which seems to be an unexpected change.You are right. I completely forgot I've removed
in_rangethere. Does this look any better?drivers/xen/gntdev.c +0
-0@@ -525,14 +525,20 @@ static int mn_invl_range_start(struct mmu_notifier *mn,return -EAGAIN ;
drivers/xen/gntdev.c static int mn_invl_range_start(struct mmu_notifier *mn, · line 535
Quoted 10 lines
drivers/xen/gntdev.c +4
-1list_for_each_entry (map, &priv->maps, next) { -if (!blockable &&in_range (map, start, end)) { +if (in_range (map, start, end)) { +if (blockable) +continue ; + ret = -EAGAIN ; goto out_unlock; }unmap_if_in_range (map, start, end);
(I obviously missed that too with my R-b).
This will never get anything done either. How about
A A A if (in_range()) {
A A A A A A if (!blockable) {
A A A A A A A A A ret = -EGAIN;
A A A A A A A A A goto out_unlock;
A A A A A A }
A A A A A A unmap_range(); // new name since unmap_if_in_range() doesn'tperform any checks now
A A A }
-boris
Quoted 10 lines
drivers/xen/gntdev.c +4
-1}list_for_each_entry (map, &priv->freeable_maps, next) { -if (!blockable &&in_range (map, start, end)) { +if (in_range (map, start, end)) { +if (blockable) +continue ; + ret = -EAGAIN ; goto out_unlock; }
Quoted 33 lines · Michal Hocko
Quoted 15 lines · Tetsuo Handa
Quoted 14 lines · Michal Hocko
drivers/xen/gntdev.c +0
-1@@ -519,21 +519,20 @@ static int mn_invl_range_start(struct mmu_notifier *mn,struct gntdev_grant_map *map;int ret =0 ; -/* TODO do we really need a mutex here? */ if (blockable)mutex_lock (&priv->lock);else if (!mutex_trylock (&priv->lock))return -EAGAIN ;Quoted 7 lines
drivers/xen/gntdev.c static int mn_invl_range_start(struct mmu_notifier *mn, · line 528
Quoted 3 lines
drivers/xen/gntdev.c +1
-1list_for_each_entry (map, &priv->maps, next) { -if (in_range (map, start, end)) { +if (!blockable &&in_range (map, start, end)) {This still looks strange. Prior to
93065ac753e4,in_range()test was insideunmap_if_in_range(). But this patch removesin_range()test if blockable == true. That is,unmap_if_in_range()will unconditionally unmap if blockable == true, which seems to be an unexpected change.You are right. I completely forgot I've removed
in_rangethere. Does this look any better?drivers/xen/gntdev.c +0
-0@@ -525,14 +525,20 @@ static int mn_invl_range_start(struct mmu_notifier *mn,return -EAGAIN ;
drivers/xen/gntdev.c static int mn_invl_range_start(struct mmu_notifier *mn, · line 535
Quoted 10 lines
drivers/xen/gntdev.c +4
-1list_for_each_entry (map, &priv->maps, next) { -if (!blockable &&in_range (map, start, end)) { +if (in_range (map, start, end)) { +if (blockable) +continue ; + ret = -EAGAIN ; goto out_unlock; }unmap_if_in_range (map, start, end);
(I obviously missed that too with my R-b).
This will never get anything done either. How about
if (in_range()) {
if (!blockable) {
ret = -EGAIN;
goto out_unlock;
}
unmap_range(); // new name since unmap_if_in_range() doesn't perform any checks now
}
-boris
drivers/xen/gntdev.c static int mn_invl_range_start(struct mmu_notifier *mn, · line 544
Quoted 10 lines
drivers/xen/gntdev.c +4
-1}list_for_each_entry (map, &priv->freeable_maps, next) { -if (!blockable &&in_range (map, start, end)) { +if (in_range (map, start, end)) { +if (blockable) +continue ; + ret = -EAGAIN ; goto out_unlock; }
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 9 lines · Michal Hocko
You are right. I completely forgot I've removed
in_rangethere. Does this look any better?drivers/xen/gntdev.c +0
-0@@ -525,14 +525,20 @@ static int mn_invl_range_start(struct mmu_notifier *mn,return -EAGAIN ;
drivers/xen/gntdev.c static int mn_invl_range_start(struct mmu_notifier *mn, · line 534
Quoted 10 lines
drivers/xen/gntdev.c +4
-1list_for_each_entry (map, &priv->maps, next) { -if (!blockable &&in_range (map, start, end)) { +if (in_range (map, start, end)) { +if (blockable) +continue ; + ret = -EAGAIN ; goto out_unlock; }
This still looks strange. in_range() returns false if map->vma == NULL. But unmap_if_in_range() unconditionally dereferences map->vma->vm_[start|end] . Suggestion from Boris looks better.
drivers/xen/gntdev.c static int mn_invl_range_start(struct mmu_notifier *mn, · line 544
Quoted 12 lines
drivers/xen/gntdev.c +4
-1unmap_if_in_range (map, start, end); }list_for_each_entry (map, &priv->freeable_maps, next) { -if (!blockable &&in_range (map, start, end)) { +if (in_range (map, start, end)) { +if (blockable) +continue ; + ret = -EAGAIN ; goto out_unlock; }
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 9 lines · Michal Hocko
You are right. I completely forgot I've removed
in_rangethere. Does this look any better?drivers/xen/gntdev.c +0
-0@@ -525,14 +525,20 @@ static int mn_invl_range_start(struct mmu_notifier *mn,return -EAGAIN ;
drivers/xen/gntdev.c static int mn_invl_range_start(struct mmu_notifier *mn, · line 534
Quoted 10 lines
drivers/xen/gntdev.c +4
-1list_for_each_entry (map, &priv->maps, next) { -if (!blockable &&in_range (map, start, end)) { +if (in_range (map, start, end)) { +if (blockable) +continue ; + ret = -EAGAIN ; goto out_unlock; }
This still looks strange. in_range() returns false if map->vma == NULL. But unmap_if_in_range() unconditionally dereferences map->vma->vm_[start|end] . Suggestion from Boris looks better.
Quoted 12 lines
drivers/xen/gntdev.c +4
-1unmap_if_in_range (map, start, end); }list_for_each_entry (map, &priv->freeable_maps, next) { -if (!blockable &&in_range (map, start, end)) { +if (in_range (map, start, end)) { +if (blockable) +continue ; + ret = -EAGAIN ; goto out_unlock; }
Quoted 48 lines · Boris Ostrovsky
Quoted 33 lines · Michal Hocko
Quoted 15 lines · Tetsuo Handa
Quoted 14 lines · Michal Hocko
drivers/xen/gntdev.c +0
-1@@ -519,21 +519,20 @@ static int mn_invl_range_start(struct mmu_notifier *mn,struct gntdev_grant_map *map;int ret =0 ; -/* TODO do we really need a mutex here? */ if (blockable)mutex_lock (&priv->lock);else if (!mutex_trylock (&priv->lock))return -EAGAIN ;Quoted 7 lines
drivers/xen/gntdev.c static int mn_invl_range_start(struct mmu_notifier *mn, · line 528
Quoted 3 lines
drivers/xen/gntdev.c +1
-1list_for_each_entry (map, &priv->maps, next) { -if (in_range (map, start, end)) { +if (!blockable &&in_range (map, start, end)) {This still looks strange. Prior to
93065ac753e4,in_range()test was insideunmap_if_in_range(). But this patch removesin_range()test if blockable == true. That is,unmap_if_in_range()will unconditionally unmap if blockable == true, which seems to be an unexpected change.You are right. I completely forgot I've removed
in_rangethere. Does this look any better?drivers/xen/gntdev.c +0
-0@@ -525,14 +525,20 @@ static int mn_invl_range_start(struct mmu_notifier *mn,return -EAGAIN ;drivers/xen/gntdev.c static int mn_invl_range_start(struct mmu_notifier *mn, · line 535
Quoted 10 lines
drivers/xen/gntdev.c +4
-1list_for_each_entry (map, &priv->maps, next) { -if (!blockable &&in_range (map, start, end)) { +if (in_range (map, start, end)) { +if (blockable) +continue ; + ret = -EAGAIN ; goto out_unlock; }unmap_if_in_range (map, start, end);(I obviously missed that too with my R-b).
Quoted 1 line
This will never get anything done either. How about
Yeah. I was half way out and posted a complete garbage. Sorry about that!
Michal repeat after me
Never post patches when in hurry! Never post patches when in hurry! Never post patches when in hurry! Never post patches when in hurry! Never post patches when in hurry! Never post patches when in hurry! Never post patches when in hurry! Never post patches when in hurry! Never post patches when in hurry! Never post patches when in hurry!
What I really meant was this
drivers/xen/gntdev.c +10 -2
@@ -525,17 +525,25 @@ static int mn_invl_range_start(struct mmu_notifier *mn,return -EAGAIN ;list_for_each_entry (map, &priv->maps, next) { -if (!blockable &&in_range (map, start, end)) { +if (!in_range (map, start, end)) +continue ; + +if (!blockable) { ret = -EAGAIN ; goto out_unlock; } +unmap_if_in_range (map, start, end); }list_for_each_entry (map, &priv->freeable_maps, next) { -if (!blockable &&in_range (map, start, end)) { +if (!in_range (map, start, end)) +continue ; + +if (!blockable) { ret = -EAGAIN ; goto out_unlock; } +unmap_if_in_range (map, start, end); }
Signature · 2 lines
Michal Hocko SUSE Labs
Quoted 48 lines · Boris Ostrovsky
Quoted 33 lines · Michal Hocko
Quoted 15 lines · Tetsuo Handa
Quoted 14 lines · Michal Hocko
drivers/xen/gntdev.c +0
-1@@ -519,21 +519,20 @@ static int mn_invl_range_start(struct mmu_notifier *mn,struct gntdev_grant_map *map;int ret =0 ; -/* TODO do we really need a mutex here? */ if (blockable)mutex_lock (&priv->lock);else if (!mutex_trylock (&priv->lock))return -EAGAIN ;Quoted 7 lines
drivers/xen/gntdev.c static int mn_invl_range_start(struct mmu_notifier *mn, · line 528
Quoted 3 lines
drivers/xen/gntdev.c +1
-1list_for_each_entry (map, &priv->maps, next) { -if (in_range (map, start, end)) { +if (!blockable &&in_range (map, start, end)) {This still looks strange. Prior to
93065ac753e4,in_range()test was insideunmap_if_in_range(). But this patch removesin_range()test if blockable == true. That is,unmap_if_in_range()will unconditionally unmap if blockable == true, which seems to be an unexpected change.You are right. I completely forgot I've removed
in_rangethere. Does this look any better?drivers/xen/gntdev.c +0
-0@@ -525,14 +525,20 @@ static int mn_invl_range_start(struct mmu_notifier *mn,return -EAGAIN ;drivers/xen/gntdev.c static int mn_invl_range_start(struct mmu_notifier *mn, · line 535
Quoted 10 lines
drivers/xen/gntdev.c +4
-1list_for_each_entry (map, &priv->maps, next) { -if (!blockable &&in_range (map, start, end)) { +if (in_range (map, start, end)) { +if (blockable) +continue ; + ret = -EAGAIN ; goto out_unlock; }unmap_if_in_range (map, start, end);(I obviously missed that too with my R-b).
Quoted 1 line
This will never get anything done either. How about
Yeah. I was half way out and posted a complete garbage. Sorry about that!
Michal repeat after me
Never post patches when in hurry! Never post patches when in hurry! Never post patches when in hurry! Never post patches when in hurry! Never post patches when in hurry! Never post patches when in hurry! Never post patches when in hurry! Never post patches when in hurry! Never post patches when in hurry! Never post patches when in hurry!
What I really meant was this
drivers/xen/gntdev.c +10 -2
@@ -525,17 +525,25 @@ static int mn_invl_range_start(struct mmu_notifier *mn,return -EAGAIN ;list_for_each_entry (map, &priv->maps, next) { -if (!blockable &&in_range (map, start, end)) { +if (!in_range (map, start, end)) +continue ; + +if (!blockable) { ret = -EAGAIN ; goto out_unlock; } +unmap_if_in_range (map, start, end); }list_for_each_entry (map, &priv->freeable_maps, next) { -if (!blockable &&in_range (map, start, end)) { +if (!in_range (map, start, end)) +continue ; + +if (!blockable) { ret = -EAGAIN ; goto out_unlock; } +unmap_if_in_range (map, start, end); }
Signature · 7 lines
Michal Hocko SUSE Labs _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Juergen Gross
maintainerQuoted 86 lines · Michal Hocko
Quoted 48 lines · Boris Ostrovsky
Quoted 33 lines · Michal Hocko
Quoted 15 lines · Tetsuo Handa
Quoted 14 lines · Michal Hocko
drivers/xen/gntdev.c +0
-1@@ -519,21 +519,20 @@ static int mn_invl_range_start(struct mmu_notifier *mn,struct gntdev_grant_map *map;int ret =0 ; -/* TODO do we really need a mutex here? */ if (blockable)mutex_lock (&priv->lock);else if (!mutex_trylock (&priv->lock))return -EAGAIN ;Quoted 7 lines
drivers/xen/gntdev.c static int mn_invl_range_start(struct mmu_notifier *mn, · line 528
Quoted 3 lines
drivers/xen/gntdev.c +1
-1list_for_each_entry (map, &priv->maps, next) { -if (in_range (map, start, end)) { +if (!blockable &&in_range (map, start, end)) {This still looks strange. Prior to
93065ac753e4,in_range()test was insideunmap_if_in_range(). But this patch removesin_range()test if blockable == true. That is,unmap_if_in_range()will unconditionally unmap if blockable == true, which seems to be an unexpected change.You are right. I completely forgot I've removed
in_rangethere. Does this look any better?drivers/xen/gntdev.c +0
-0@@ -525,14 +525,20 @@ static int mn_invl_range_start(struct mmu_notifier *mn,return -EAGAIN ;drivers/xen/gntdev.c static int mn_invl_range_start(struct mmu_notifier *mn, · line 535
Quoted 10 lines
drivers/xen/gntdev.c +4
-1list_for_each_entry (map, &priv->maps, next) { -if (!blockable &&in_range (map, start, end)) { +if (in_range (map, start, end)) { +if (blockable) +continue ; + ret = -EAGAIN ; goto out_unlock; }unmap_if_in_range (map, start, end);(I obviously missed that too with my R-b).
Quoted 1 line
This will never get anything done either. How about
Yeah. I was half way out and posted a complete garbage. Sorry about that!
Michal repeat after me
Never post patches when in hurry! Never post patches when in hurry! Never post patches when in hurry! Never post patches when in hurry! Never post patches when in hurry! Never post patches when in hurry! Never post patches when in hurry! Never post patches when in hurry! Never post patches when in hurry! Never post patches when in hurry!What I really meant was this
drivers/xen/gntdev.c +6
-2@@ -525,17 +525,25 @@ static int mn_invl_range_start(struct mmu_notifier *mn,return -EAGAIN ;list_for_each_entry (map, &priv->maps, next) { -if (!blockable &&in_range (map, start, end)) { +if (!in_range (map, start, end)) +continue ; + +if (!blockable) { ret = -EAGAIN ; goto out_unlock; } +unmap_if_in_range (map, start, end); }list_for_each_entry (map, &priv->freeable_maps, next) { -if (!blockable &&in_range (map, start, end)) { +if (!in_range (map, start, end))
drivers/xen/gntdev.c static int mn_invl_range_start(struct mmu_notifier *mn, · line 549
Quoted 10 lines
drivers/xen/gntdev.c +4
-0+continue ; + +if (!blockable) { ret = -EAGAIN ; goto out_unlock; } +unmap_if_in_range (map, start, end); }
I liked the general structure before 93065ac753e4 better.
Why don't you return to that, add blockable parameter to unmap_if_in_range() and let unmap_if_in_range() return a value (0 or -EAGAIN)? This will avoid repeating the very same code.
So:
drivers/xen/gntdev.c +0 -0
@@ -479,25 +479,21 @@ static const struct vm_operations_struct
gntdev_vmops = {
/* ------------------------------------------------------------------ */
-static bool in_range(struct gntdev_grant_map *map,
- unsigned long start, unsigned long end)
-{
- if (!map->vma)
- return false;
- if (map->vma->vm_start >= end)
- return false;
- if (map->vma->vm_end <= start)
- return false;
-
- return true;
-}
-
-static void unmap_if_in_range(struct gntdev_grant_map *map,
- unsigned long start, unsigned long end)
+static int unmap_if_in_range(struct gntdev_grant_map *map,
+ unsigned long start, unsigned long end,
+ bool blockable)
{
unsigned long mstart, mend;
int err;+ if (!map->vma)
+ return 0;
+ if (map->vma->vm_start >= end)
+ return 0;
+ if (map->vma->vm_end <= start)
+ return 0;
+ if (!blockable)
+ return -EAGAIN;
mstart = max(start, map->vma->vm_start);
mend = min(end, map->vma->vm_end);
pr_debug("map %d+%d (%lx %lx), range %lx %lx, mrange %lx %lx\n",
@@ -508,6 +504,8 @@ static void unmap_if_in_range(struct
gntdev_grant_map *map,
(mstart - map->vma->vm_start) >> PAGE_SHIFT,
(mend - mstart) >> PAGE_SHIFT);
WARN_ON(err);+
+ return 0;
}
static int mn_invl_range_start(struct mmu_notifier *mn,
@@ -519,25 +517,20 @@ static int mn_invl_range_start(struct mmu_notifier *mn,
struct gntdev_grant_map *map;
int ret = 0;- /* TODO do we really need a mutex here? */
if (blockable)
mutex_lock(&priv->lock);
else if (!mutex_trylock(&priv->lock))
return -EAGAIN;
list_for_each_entry(map, &priv->maps, next) {- if (in_range(map, start, end)) {
- ret = -EAGAIN;
+ ret = unmap_if_in_range(map, start, end, blockable);
+ if (ret)
goto out_unlock;
- }
- unmap_if_in_range(map, start, end);
}
list_for_each_entry(map, &priv->freeable_maps, next) {- if (in_range(map, start, end)) {
- ret = -EAGAIN;
+ ret = unmap_if_in_range(map, start, end, blockable);
+ if (ret)
goto out_unlock;
- }
- unmap_if_in_range(map, start, end);
} out_unlock:
Juergen
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Juergen Gross
maintainerQuoted 86 lines · Michal Hocko
Quoted 48 lines · Boris Ostrovsky
Quoted 33 lines · Michal Hocko
Quoted 15 lines · Tetsuo Handa
Quoted 14 lines · Michal Hocko
drivers/xen/gntdev.c +0
-1@@ -519,21 +519,20 @@ static int mn_invl_range_start(struct mmu_notifier *mn,struct gntdev_grant_map *map;int ret =0 ; -/* TODO do we really need a mutex here? */ if (blockable)mutex_lock (&priv->lock);else if (!mutex_trylock (&priv->lock))return -EAGAIN ;Quoted 7 lines
drivers/xen/gntdev.c static int mn_invl_range_start(struct mmu_notifier *mn, · line 528
Quoted 3 lines
drivers/xen/gntdev.c +1
-1list_for_each_entry (map, &priv->maps, next) { -if (in_range (map, start, end)) { +if (!blockable &&in_range (map, start, end)) {This still looks strange. Prior to
93065ac753e4,in_range()test was insideunmap_if_in_range(). But this patch removesin_range()test if blockable == true. That is,unmap_if_in_range()will unconditionally unmap if blockable == true, which seems to be an unexpected change.You are right. I completely forgot I've removed
in_rangethere. Does this look any better?drivers/xen/gntdev.c +0
-0@@ -525,14 +525,20 @@ static int mn_invl_range_start(struct mmu_notifier *mn,return -EAGAIN ;drivers/xen/gntdev.c static int mn_invl_range_start(struct mmu_notifier *mn, · line 535
Quoted 10 lines
drivers/xen/gntdev.c +4
-1list_for_each_entry (map, &priv->maps, next) { -if (!blockable &&in_range (map, start, end)) { +if (in_range (map, start, end)) { +if (blockable) +continue ; + ret = -EAGAIN ; goto out_unlock; }unmap_if_in_range (map, start, end);(I obviously missed that too with my R-b).
Quoted 1 line
This will never get anything done either. How about
Yeah. I was half way out and posted a complete garbage. Sorry about that!
Michal repeat after me
Never post patches when in hurry! Never post patches when in hurry! Never post patches when in hurry! Never post patches when in hurry! Never post patches when in hurry! Never post patches when in hurry! Never post patches when in hurry! Never post patches when in hurry! Never post patches when in hurry! Never post patches when in hurry!What I really meant was this
drivers/xen/gntdev.c +6
-2@@ -525,17 +525,25 @@ static int mn_invl_range_start(struct mmu_notifier *mn,return -EAGAIN ;list_for_each_entry (map, &priv->maps, next) { -if (!blockable &&in_range (map, start, end)) { +if (!in_range (map, start, end)) +continue ; + +if (!blockable) { ret = -EAGAIN ; goto out_unlock; } +unmap_if_in_range (map, start, end); }list_for_each_entry (map, &priv->freeable_maps, next) { -if (!blockable &&in_range (map, start, end)) { +if (!in_range (map, start, end))
drivers/xen/gntdev.c static int mn_invl_range_start(struct mmu_notifier *mn, · line 549
Quoted 10 lines
drivers/xen/gntdev.c +4
-0+continue ; + +if (!blockable) { ret = -EAGAIN ; goto out_unlock; } +unmap_if_in_range (map, start, end); }
I liked the general structure before 93065ac753e4 better.
Why don't you return to that, add blockable parameter to unmap_if_in_range() and let unmap_if_in_range() return a value (0 or -EAGAIN)? This will avoid repeating the very same code.
So:
drivers/xen/gntdev.c +0 -0
@@ -479,25 +479,21 @@ static const struct vm_operations_struct
gntdev_vmops = {
/* ------------------------------------------------------------------ */
-static bool in_range(struct gntdev_grant_map *map,
- unsigned long start, unsigned long end)
-{
- if (!map->vma)
- return false;
- if (map->vma->vm_start >= end)
- return false;
- if (map->vma->vm_end <= start)
- return false;
-
- return true;
-}
-
-static void unmap_if_in_range(struct gntdev_grant_map *map,
- unsigned long start, unsigned long end)
+static int unmap_if_in_range(struct gntdev_grant_map *map,
+ unsigned long start, unsigned long end,
+ bool blockable)
{
unsigned long mstart, mend;
int err;+ if (!map->vma)
+ return 0;
+ if (map->vma->vm_start >= end)
+ return 0;
+ if (map->vma->vm_end <= start)
+ return 0;
+ if (!blockable)
+ return -EAGAIN;
mstart = max(start, map->vma->vm_start);
mend = min(end, map->vma->vm_end);
pr_debug("map %d+%d (%lx %lx), range %lx %lx, mrange %lx %lx\n",
@@ -508,6 +504,8 @@ static void unmap_if_in_range(struct
gntdev_grant_map *map,
(mstart - map->vma->vm_start) >> PAGE_SHIFT,
(mend - mstart) >> PAGE_SHIFT);
WARN_ON(err);+
+ return 0;
}
static int mn_invl_range_start(struct mmu_notifier *mn,
@@ -519,25 +517,20 @@ static int mn_invl_range_start(struct mmu_notifier *mn,
struct gntdev_grant_map *map;
int ret = 0;- /* TODO do we really need a mutex here? */
if (blockable)
mutex_lock(&priv->lock);
else if (!mutex_trylock(&priv->lock))
return -EAGAIN;
list_for_each_entry(map, &priv->maps, next) {- if (in_range(map, start, end)) {
- ret = -EAGAIN;
+ ret = unmap_if_in_range(map, start, end, blockable);
+ if (ret)
goto out_unlock;
- }
- unmap_if_in_range(map, start, end);
}
list_for_each_entry(map, &priv->freeable_maps, next) {- if (in_range(map, start, end)) {
- ret = -EAGAIN;
+ ret = unmap_if_in_range(map, start, end, blockable);
+ if (ret)
goto out_unlock;
- }
- unmap_if_in_range(map, start, end);
} out_unlock:
Juergen
Quoted 100 lines · Juergen Gross
Quoted 86 lines · Michal Hocko
Quoted 48 lines · Boris Ostrovsky
Quoted 33 lines · Michal Hocko
Quoted 15 lines · Tetsuo Handa
Quoted 14 lines · Michal Hocko
drivers/xen/gntdev.c +0
-1@@ -519,21 +519,20 @@ static int mn_invl_range_start(struct mmu_notifier *mn,struct gntdev_grant_map *map;int ret =0 ; -/* TODO do we really need a mutex here? */ if (blockable)mutex_lock (&priv->lock);else if (!mutex_trylock (&priv->lock))return -EAGAIN ;Quoted 7 lines
drivers/xen/gntdev.c static int mn_invl_range_start(struct mmu_notifier *mn, · line 528
Quoted 3 lines
drivers/xen/gntdev.c +1
-1list_for_each_entry (map, &priv->maps, next) { -if (in_range (map, start, end)) { +if (!blockable &&in_range (map, start, end)) {This still looks strange. Prior to
93065ac753e4,in_range()test was insideunmap_if_in_range(). But this patch removesin_range()test if blockable == true. That is,unmap_if_in_range()will unconditionally unmap if blockable == true, which seems to be an unexpected change.You are right. I completely forgot I've removed
in_rangethere. Does this look any better?drivers/xen/gntdev.c +0
-0@@ -525,14 +525,20 @@ static int mn_invl_range_start(struct mmu_notifier *mn,return -EAGAIN ;drivers/xen/gntdev.c static int mn_invl_range_start(struct mmu_notifier *mn, · line 535
Quoted 10 lines
drivers/xen/gntdev.c +4
-1list_for_each_entry (map, &priv->maps, next) { -if (!blockable &&in_range (map, start, end)) { +if (in_range (map, start, end)) { +if (blockable) +continue ; + ret = -EAGAIN ; goto out_unlock; }unmap_if_in_range (map, start, end);(I obviously missed that too with my R-b).
Quoted 1 line
This will never get anything done either. How about
Yeah. I was half way out and posted a complete garbage. Sorry about that!
Michal repeat after me
Never post patches when in hurry! Never post patches when in hurry! Never post patches when in hurry! Never post patches when in hurry! Never post patches when in hurry! Never post patches when in hurry! Never post patches when in hurry! Never post patches when in hurry! Never post patches when in hurry! Never post patches when in hurry!What I really meant was this
drivers/xen/gntdev.c +6
-2@@ -525,17 +525,25 @@ static int mn_invl_range_start(struct mmu_notifier *mn,return -EAGAIN ;list_for_each_entry (map, &priv->maps, next) { -if (!blockable &&in_range (map, start, end)) { +if (!in_range (map, start, end)) +continue ; + +if (!blockable) { ret = -EAGAIN ; goto out_unlock; } +unmap_if_in_range (map, start, end); }list_for_each_entry (map, &priv->freeable_maps, next) { -if (!blockable &&in_range (map, start, end)) { +if (!in_range (map, start, end))drivers/xen/gntdev.c static int mn_invl_range_start(struct mmu_notifier *mn, · line 549
Quoted 10 lines
drivers/xen/gntdev.c +4
-0+continue ; + +if (!blockable) { ret = -EAGAIN ; goto out_unlock; } +unmap_if_in_range (map, start, end); }I liked the general structure before
93065ac753e4better.
Quoted 3 lines
Why don't you return to that, add blockable parameter to
unmap_if_in_range()and letunmap_if_in_range()return a value (0 or-EAGAIN)? This will avoid repeating the very same code.
I can do that if that is your preference of course. I have even considered that but then I have got to this...
Review static void unmap_if_in_range(struct · line 510
Quoted 8 lines
(quoted diff) +2
-0@@ -508,6 +504,8 @@ static void unmap_if_in_range(struct gntdev_grant_map *map, (mstart - map->vma->vm_start) >> PAGE_SHIFT, (mend - mstart) >> PAGE_SHIFT); WARN_ON(err); + + return 0; }
and I really didn't know what to do about that. On one hand the error has been ignored already, on the other hand it is just too ugly to ignore it when we do provide a return value. Moreover I can see how somebody would like to clean that up later and I am not sure what are we going to do about it in callers.
But by all means, I will go the way you maintainers prefer.
Signature · 2 lines
Michal Hocko SUSE Labs
Quoted 100 lines · Juergen Gross
Quoted 86 lines · Michal Hocko
Quoted 48 lines · Boris Ostrovsky
Quoted 33 lines · Michal Hocko
Quoted 15 lines · Tetsuo Handa
Quoted 14 lines · Michal Hocko
drivers/xen/gntdev.c +0
-1@@ -519,21 +519,20 @@ static int mn_invl_range_start(struct mmu_notifier *mn,struct gntdev_grant_map *map;int ret =0 ; -/* TODO do we really need a mutex here? */ if (blockable)mutex_lock (&priv->lock);else if (!mutex_trylock (&priv->lock))return -EAGAIN ;Quoted 7 lines
drivers/xen/gntdev.c static int mn_invl_range_start(struct mmu_notifier *mn, · line 528
Quoted 3 lines
drivers/xen/gntdev.c +1
-1list_for_each_entry (map, &priv->maps, next) { -if (in_range (map, start, end)) { +if (!blockable &&in_range (map, start, end)) {This still looks strange. Prior to
93065ac753e4,in_range()test was insideunmap_if_in_range(). But this patch removesin_range()test if blockable == true. That is,unmap_if_in_range()will unconditionally unmap if blockable == true, which seems to be an unexpected change.You are right. I completely forgot I've removed
in_rangethere. Does this look any better?drivers/xen/gntdev.c +0
-0@@ -525,14 +525,20 @@ static int mn_invl_range_start(struct mmu_notifier *mn,return -EAGAIN ;drivers/xen/gntdev.c static int mn_invl_range_start(struct mmu_notifier *mn, · line 535
Quoted 10 lines
drivers/xen/gntdev.c +4
-1list_for_each_entry (map, &priv->maps, next) { -if (!blockable &&in_range (map, start, end)) { +if (in_range (map, start, end)) { +if (blockable) +continue ; + ret = -EAGAIN ; goto out_unlock; }unmap_if_in_range (map, start, end);(I obviously missed that too with my R-b).
Quoted 1 line
This will never get anything done either. How about
Yeah. I was half way out and posted a complete garbage. Sorry about that!
Michal repeat after me
Never post patches when in hurry! Never post patches when in hurry! Never post patches when in hurry! Never post patches when in hurry! Never post patches when in hurry! Never post patches when in hurry! Never post patches when in hurry! Never post patches when in hurry! Never post patches when in hurry! Never post patches when in hurry!What I really meant was this
drivers/xen/gntdev.c +6
-2@@ -525,17 +525,25 @@ static int mn_invl_range_start(struct mmu_notifier *mn,return -EAGAIN ;list_for_each_entry (map, &priv->maps, next) { -if (!blockable &&in_range (map, start, end)) { +if (!in_range (map, start, end)) +continue ; + +if (!blockable) { ret = -EAGAIN ; goto out_unlock; } +unmap_if_in_range (map, start, end); }list_for_each_entry (map, &priv->freeable_maps, next) { -if (!blockable &&in_range (map, start, end)) { +if (!in_range (map, start, end))drivers/xen/gntdev.c static int mn_invl_range_start(struct mmu_notifier *mn, · line 549
Quoted 10 lines
drivers/xen/gntdev.c +4
-0+continue ; + +if (!blockable) { ret = -EAGAIN ; goto out_unlock; } +unmap_if_in_range (map, start, end); }I liked the general structure before
93065ac753e4better.
Quoted 3 lines
Why don't you return to that, add blockable parameter to
unmap_if_in_range()and letunmap_if_in_range()return a value (0 or-EAGAIN)? This will avoid repeating the very same code.
I can do that if that is your preference of course. I have even considered that but then I have got to this...
Review static void unmap_if_in_range(struct · line 510
Quoted 8 lines
(quoted diff) +2
-0@@ -508,6 +504,8 @@ static void unmap_if_in_range(struct gntdev_grant_map *map, (mstart - map->vma->vm_start) >> PAGE_SHIFT, (mend - mstart) >> PAGE_SHIFT); WARN_ON(err); + + return 0; }
and I really didn't know what to do about that. On one hand the error has been ignored already, on the other hand it is just too ugly to ignore it when we do provide a return value. Moreover I can see how somebody would like to clean that up later and I am not sure what are we going to do about it in callers.
But by all means, I will go the way you maintainers prefer.
Signature · 7 lines
Michal Hocko SUSE Labs _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel