xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] xen/privcmd: sprinkle around cond_resched() calls in mmap ioctl handling
@ 2016-07-07  7:35 Jan Beulich
  2016-07-07  9:37 ` David Vrabel
  0 siblings, 1 reply; 2+ messages in thread
From: Jan Beulich @ 2016-07-07  7:35 UTC (permalink / raw)
  To: david.vrabel, boris.ostrovsky, Juergen Gross; +Cc: xen-devel, linux-kernel

Many of these operations can take arbitrarily long, which can become a
problem irrespective of them being exposed to privileged users only.

Signed-off-by: Jan Beulich <jbeulich@suse.com>
---
 drivers/xen/privcmd.c |   18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)

--- 4.7-rc6-xen.orig/drivers/xen/privcmd.c
+++ 4.7-rc6-xen/drivers/xen/privcmd.c
@@ -69,9 +69,13 @@ static long privcmd_ioctl_hypercall(void
 static void free_page_list(struct list_head *pages)
 {
 	struct page *p, *n;
+	unsigned idx = 0;
 
-	list_for_each_entry_safe(p, n, pages, lru)
+	list_for_each_entry_safe(p, n, pages, lru) {
+		if (!(++idx & 7))
+			cond_resched();
 		__free_page(p);
+	}
 
 	INIT_LIST_HEAD(pages);
 }
@@ -103,6 +107,8 @@ static int gather_array(struct list_head
 			if (page == NULL)
 				goto fail;
 
+			if (pagedata)
+				cond_resched();
 			pagedata = page_address(page);
 
 			list_add_tail(&page->lru, pagelist);
@@ -144,6 +150,9 @@ static int traverse_pages(unsigned nelem
 	while (nelem--) {
 		if (pageidx > PAGE_SIZE-size) {
 			struct page *page;
+
+			if (pagedata)
+				cond_resched();
 			pos = pos->next;
 			page = list_entry(pos, struct page, lru);
 			pagedata = page_address(page);
@@ -169,16 +178,17 @@ static int traverse_pages_block(unsigned
 				void *state)
 {
 	void *pagedata;
-	unsigned pageidx;
+	unsigned pageidx = 0;
 	int ret = 0;
 
 	BUG_ON(size > PAGE_SIZE);
 
-	pageidx = PAGE_SIZE;
-
 	while (nelem) {
 		int nr = (PAGE_SIZE/size);
 		struct page *page;
+
+		if (pageidx++)
+			cond_resched();
 		if (nr > nelem)
 			nr = nelem;
 		pos = pos->next;




_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

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

* Re: [PATCH] xen/privcmd: sprinkle around cond_resched() calls in mmap ioctl handling
  2016-07-07  7:35 [PATCH] xen/privcmd: sprinkle around cond_resched() calls in mmap ioctl handling Jan Beulich
@ 2016-07-07  9:37 ` David Vrabel
  0 siblings, 0 replies; 2+ messages in thread
From: David Vrabel @ 2016-07-07  9:37 UTC (permalink / raw)
  To: Jan Beulich, david.vrabel, boris.ostrovsky, Juergen Gross
  Cc: xen-devel, linux-kernel

On 07/07/16 08:35, Jan Beulich wrote:
> Many of these operations can take arbitrarily long, which can become a
> problem irrespective of them being exposed to privileged users only.

If this is a concern I would rather see large numbers of mapping
requests processed in smaller batches.  This would also limit the amount
of memory needed.

Note also that xen_remap_domain_gfn() array already has a cond_resched()
after every batch of 16 GFNs.

David

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

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

end of thread, other threads:[~2016-07-07  9:37 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-07-07  7:35 [PATCH] xen/privcmd: sprinkle around cond_resched() calls in mmap ioctl handling Jan Beulich
2016-07-07  9:37 ` David Vrabel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).