Re: [REBASE PATCH net-next v9 0/4] net: vhost: improve performance when enable busyloop

2018-09-26 Thread David Miller
From: xiangxia.m@gmail.com
Date: Tue, 25 Sep 2018 05:36:48 -0700

> From: Tonghao Zhang 
> 
> This patches improve the guest receive performance.
> On the handle_tx side, we poll the sock receive queue
> at the same time. handle_rx do that in the same way.
> 
> For more performance report, see patch 4

Series applied, thank you.
___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization


[PULL 2/2] virtio/s390: fix race in ccw_io_helper()

2018-09-26 Thread Cornelia Huck
From: Halil Pasic 

While ccw_io_helper() seems like intended to be exclusive in a sense that
it is supposed to facilitate I/O for at most one thread at any given
time, there is actually nothing ensuring that threads won't pile up at
vcdev->wait_q. If they do, all threads get woken up and see the status
that belongs to some other request than their own. This can lead to bugs.
For an example see:
https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1788432

This race normally does not cause any problems. The operations provided
by struct virtio_config_ops are usually invoked in a well defined
sequence, normally don't fail, and are normally used quite infrequent
too.

Yet, if some of the these operations are directly triggered via sysfs
attributes, like in the case described by the referenced bug, userspace
is given an opportunity to force races by increasing the frequency of the
given operations.

Let us fix the problem by ensuring, that for each device, we finish
processing the previous request before starting with a new one.

Signed-off-by: Halil Pasic 
Reported-by: Colin Ian King 
Cc: sta...@vger.kernel.org
Message-Id: <20180925121309.58524-3-pa...@linux.ibm.com>
Signed-off-by: Cornelia Huck 
---
 drivers/s390/virtio/virtio_ccw.c | 7 ++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/s390/virtio/virtio_ccw.c b/drivers/s390/virtio/virtio_ccw.c
index a5e8530a3391..b67dc4974f23 100644
--- a/drivers/s390/virtio/virtio_ccw.c
+++ b/drivers/s390/virtio/virtio_ccw.c
@@ -56,6 +56,7 @@ struct virtio_ccw_device {
unsigned int revision; /* Transport revision */
wait_queue_head_t wait_q;
spinlock_t lock;
+   struct mutex io_lock; /* Serializes I/O requests */
struct list_head virtqueues;
unsigned long indicators;
unsigned long indicators2;
@@ -296,6 +297,7 @@ static int ccw_io_helper(struct virtio_ccw_device *vcdev,
unsigned long flags;
int flag = intparm & VIRTIO_CCW_INTPARM_MASK;
 
+   mutex_lock(>io_lock);
do {
spin_lock_irqsave(get_ccwdev_lock(vcdev->cdev), flags);
ret = ccw_device_start(vcdev->cdev, ccw, intparm, 0, 0);
@@ -308,7 +310,9 @@ static int ccw_io_helper(struct virtio_ccw_device *vcdev,
cpu_relax();
} while (ret == -EBUSY);
wait_event(vcdev->wait_q, doing_io(vcdev, flag) == 0);
-   return ret ? ret : vcdev->err;
+   ret = ret ? ret : vcdev->err;
+   mutex_unlock(>io_lock);
+   return ret;
 }
 
 static void virtio_ccw_drop_indicator(struct virtio_ccw_device *vcdev,
@@ -1253,6 +1257,7 @@ static int virtio_ccw_online(struct ccw_device *cdev)
init_waitqueue_head(>wait_q);
INIT_LIST_HEAD(>virtqueues);
spin_lock_init(>lock);
+   mutex_init(>io_lock);
 
spin_lock_irqsave(get_ccwdev_lock(cdev), flags);
dev_set_drvdata(>dev, vcdev);
-- 
2.14.4

___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization


[PULL 0/2] virtio-ccw fixes

2018-09-26 Thread Cornelia Huck
The following changes since commit 8c0f9f5b309d627182d5da72a69246f58bde1026:

  Revert "uapi/linux/keyctl.h: don't use C++ reserved keyword as a struct 
member name" (2018-09-25 13:28:58 +0200)

are available in the Git repository at:

  git://git.kernel.org/pub/scm/linux/kernel/git/kvms390/linux.git 
tags/virtio-ccw-20180926

for you to fetch changes up to 1fd7ccf82385b3b14e4b3f009a82ada17ddc1e6f:

  virtio/s390: fix race in ccw_io_helper() (2018-09-25 15:29:10 +0200)


Two patches fixing races in the virtio-ccw driver.



Halil Pasic (2):
  virtio/s390: avoid race on vcdev->config
  virtio/s390: fix race in ccw_io_helper()

 drivers/s390/virtio/virtio_ccw.c | 17 ++---
 1 file changed, 14 insertions(+), 3 deletions(-)

-- 
2.14.4

___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization


[PULL 1/2] virtio/s390: avoid race on vcdev->config

2018-09-26 Thread Cornelia Huck
From: Halil Pasic 

Currently we have a race on vcdev->config in virtio_ccw_get_config() and
in virtio_ccw_set_config().

This normally does not cause problems, as these are usually infrequent
operations. However, for some devices writing to/reading from the config
space can be triggered through sysfs attributes. For these, userspace can
force the race by increasing the frequency.

Signed-off-by: Halil Pasic 
Cc: sta...@vger.kernel.org
Message-Id: <20180925121309.58524-2-pa...@linux.ibm.com>
Signed-off-by: Cornelia Huck 
---
 drivers/s390/virtio/virtio_ccw.c | 10 --
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/drivers/s390/virtio/virtio_ccw.c b/drivers/s390/virtio/virtio_ccw.c
index 8f5c1d7f751a..a5e8530a3391 100644
--- a/drivers/s390/virtio/virtio_ccw.c
+++ b/drivers/s390/virtio/virtio_ccw.c
@@ -828,6 +828,7 @@ static void virtio_ccw_get_config(struct virtio_device 
*vdev,
int ret;
struct ccw1 *ccw;
void *config_area;
+   unsigned long flags;
 
ccw = kzalloc(sizeof(*ccw), GFP_DMA | GFP_KERNEL);
if (!ccw)
@@ -846,11 +847,13 @@ static void virtio_ccw_get_config(struct virtio_device 
*vdev,
if (ret)
goto out_free;
 
+   spin_lock_irqsave(>lock, flags);
memcpy(vcdev->config, config_area, offset + len);
-   if (buf)
-   memcpy(buf, >config[offset], len);
if (vcdev->config_ready < offset + len)
vcdev->config_ready = offset + len;
+   spin_unlock_irqrestore(>lock, flags);
+   if (buf)
+   memcpy(buf, config_area + offset, len);
 
 out_free:
kfree(config_area);
@@ -864,6 +867,7 @@ static void virtio_ccw_set_config(struct virtio_device 
*vdev,
struct virtio_ccw_device *vcdev = to_vc_device(vdev);
struct ccw1 *ccw;
void *config_area;
+   unsigned long flags;
 
ccw = kzalloc(sizeof(*ccw), GFP_DMA | GFP_KERNEL);
if (!ccw)
@@ -876,9 +880,11 @@ static void virtio_ccw_set_config(struct virtio_device 
*vdev,
/* Make sure we don't overwrite fields. */
if (vcdev->config_ready < offset)
virtio_ccw_get_config(vdev, 0, NULL, offset);
+   spin_lock_irqsave(>lock, flags);
memcpy(>config[offset], buf, len);
/* Write the config area to the host. */
memcpy(config_area, vcdev->config, sizeof(vcdev->config));
+   spin_unlock_irqrestore(>lock, flags);
ccw->cmd_code = CCW_CMD_WRITE_CONF;
ccw->flags = 0;
ccw->count = offset + len;
-- 
2.14.4

___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization


Call for Papers - WorldCIST'19 - La Toja Island, Spain

2018-09-26 Thread ML
*** Best papers published in JCR/SCI/SSCI journals



---

WorldCIST'19 - 7th World Conference on Information Systems and Technologies

16 - 19 April 2019 | La Toja Island, Spain

http://www.worldcist.org/ 





Scope

The WorldCist'19 - 7th World Conference on Information Systems and 
Technologies, to be held at La Toja Island, Galicia, Spain, 16 - 19 April 2019, 
is a global forum for researchers and practitioners to present and discuss the 
most recent innovations, trends, results, experiences and concerns in the 
several perspectives of Information Systems and Technologies.

We are pleased to invite you to submit your papers to WorldCist'18. All 
submissions will be reviewed on the basis of relevance, originality, importance 
and clarity.



Themes

Submitted papers should be related with one or more of the main themes proposed 
for the Conference:

A) Information and Knowledge Management (IKM);

B) Organizational Models and Information Systems (OMIS);

C) Software and Systems Modeling (SSM);

D) Software Systems, Architectures, Applications and Tools (SSAAT);

E) Multimedia Systems and Applications (MSA);

F) Computer Networks, Mobility and Pervasive Systems (CNMPS);

G) Intelligent and Decision Support Systems (IDSS);

H) Big Data Analytics and Applications (BDAA);

I) Human-Computer Interaction (HCI);

J) Ethics, Computers and Security (ECS)

K) Health Informatics (HIS);

L) Information Technologies in Education (ITE);

M) Information Technologies in Radiocommunications (ITR);

N) Technologies for Biomedical Applications (TBA)



Types of Submissions and Decisions

Four types of papers can be submitted:

Full paper: Finished or consolidated R works, to be included in one of the 
Conference themes. These papers are assigned a 10-page limit.

Short paper: Ongoing works with relevant preliminary results, open to 
discussion. These papers are assigned a 7-page limit.

Poster paper: Initial work with relevant ideas, open to discussion. These 
papers are assigned to a 4-page limit.

Company paper: Companies' papers that show practical experience, R & D, tools, 
etc., focused on some topics of the conference. These papers are assigned to a 
4-page limit.

Submitted papers must comply with the format of Advances in Intelligent Systems 
and Computing Series (see Instructions for Authors at Springer Website 

 or download a Word Template 
or 
Latex Package 
) 
be written in English, must not have been published before, not be under review 
for any other conference or publication and not include any information leading 
to the authors’ identification. Therefore, the authors’ names, affiliations and 
bibliographic references should not be included in the version for evaluation 
by the Program Committee. This information should only be included in the 
camera-ready version, saved in Word or Latex format and also in PDF format. 
These files must be accompanied by the Consent to Publish form 
 filled out, in a ZIP file, and uploaded at 
the conference management system.


All papers will be subjected to a “double-blind review” by at least two members 
of the Program Committee.

Based on Program Committee evaluation, a paper can be rejected or accepted by 
the Conference Chairs. In the later case, it can be accepted as the type 
originally submitted or as another type. Thus, full papers can be accepted as 
short papers or poster papers only. Similarly, short papers can be accepted as 
poster papers only. In these cases, the authors will be allowed to maintain the 
original number of pages in the camera-ready version.

The authors of accepted poster papers must also build and print a poster to be 
exhibited during the Conference. This poster must follow an A1 or A2 vertical 
format. The Conference can includes Work Sessions where these posters are 
presented and orally discussed, with a 5 minute limit per poster.

The authors of accepted full papers will have 15 minutes to present their work 
in a Conference Work Session; approximately 5 minutes of discussion will follow 
each presentation. The authors of accepted short papers and company papers will 
have 11 minutes to present their work in a Conference Work Session; 
approximately 4 minutes of discussion will follow each presentation.



Publication and Indexing

To ensure that a full paper, short paper, poster paper or company paper is 
published, at least one of the authors must be fully registered by the 13th of 
January 2019, and the paper must comply with the suggested layout and 
page-limit. 

Re: [PATCH 4/4] drm/virtio: Use IDAs more efficiently

2018-09-26 Thread Matthew Wilcox
On Wed, Sep 26, 2018 at 09:00:31AM -0700, Matthew Wilcox wrote:
> @@ -59,6 +59,7 @@ static int virtio_gpu_context_create(struct 
> virtio_gpu_device *vgdev,
>  
>   if (handle < 0)
>   return handle;
> + handle++;
>   virtio_gpu_cmd_context_create(vgdev, handle, nlen, name);
>   return handle;
>  }

Uh.  This line is missing.

-   int handle = ida_alloc_min(>ctx_id_ida, 1, GFP_KERNEL);
+   int handle = ida_alloc(>ctx_id_ida, GFP_KERNEL);

It'll be there in v2 ;-)
___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization


[PATCH 4/4] drm/virtio: Use IDAs more efficiently

2018-09-26 Thread Matthew Wilcox
0-based IDAs are more efficient than any other base.  Convert the
1-based IDAs to be 0-based.

Signed-off-by: Matthew Wilcox 
---
 drivers/gpu/drm/virtio/virtgpu_kms.c | 3 ++-
 drivers/gpu/drm/virtio/virtgpu_vq.c  | 7 +--
 2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/virtio/virtgpu_kms.c 
b/drivers/gpu/drm/virtio/virtgpu_kms.c
index bf609dcae224..b576c9ef6323 100644
--- a/drivers/gpu/drm/virtio/virtgpu_kms.c
+++ b/drivers/gpu/drm/virtio/virtgpu_kms.c
@@ -59,6 +59,7 @@ static int virtio_gpu_context_create(struct virtio_gpu_device 
*vgdev,
 
if (handle < 0)
return handle;
+   handle++;
virtio_gpu_cmd_context_create(vgdev, handle, nlen, name);
return handle;
 }
@@ -67,7 +68,7 @@ static void virtio_gpu_context_destroy(struct 
virtio_gpu_device *vgdev,
  uint32_t ctx_id)
 {
virtio_gpu_cmd_context_destroy(vgdev, ctx_id);
-   ida_free(>ctx_id_ida, ctx_id);
+   ida_free(>ctx_id_ida, ctx_id - 1);
 }
 
 static void virtio_gpu_init_vq(struct virtio_gpu_queue *vgvq,
diff --git a/drivers/gpu/drm/virtio/virtgpu_vq.c 
b/drivers/gpu/drm/virtio/virtgpu_vq.c
index 387951c971d4..81297fe0147d 100644
--- a/drivers/gpu/drm/virtio/virtgpu_vq.c
+++ b/drivers/gpu/drm/virtio/virtgpu_vq.c
@@ -40,12 +40,15 @@
 
 int virtio_gpu_resource_id_get(struct virtio_gpu_device *vgdev)
 {
-   return ida_alloc_min(>resource_ida, 1, GFP_KERNEL);
+   int handle = ida_alloc(>resource_ida, GFP_KERNEL);
+   if (handle < 0)
+   return handle;
+   return handle + 1;
 }
 
 void virtio_gpu_resource_id_put(struct virtio_gpu_device *vgdev, uint32_t id)
 {
-   ida_free(>resource_ida, id);
+   ida_free(>resource_ida, id - 1);
 }
 
 void virtio_gpu_ctrl_ack(struct virtqueue *vq)
-- 
2.19.0

___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization


[PATCH 3/4] drm/virtio: Handle object ID allocation errors

2018-09-26 Thread Matthew Wilcox
It is possible to run out of memory while allocating IDs.  The current
code would create an object with an invalid ID; change it to return
-ENOMEM to the caller.

Signed-off-by: Matthew Wilcox 
---
 drivers/gpu/drm/virtio/virtgpu_drv.h   |  3 +--
 drivers/gpu/drm/virtio/virtgpu_fb.c| 10 --
 drivers/gpu/drm/virtio/virtgpu_gem.c   | 10 --
 drivers/gpu/drm/virtio/virtgpu_ioctl.c |  5 -
 drivers/gpu/drm/virtio/virtgpu_vq.c|  6 ++
 5 files changed, 23 insertions(+), 11 deletions(-)

diff --git a/drivers/gpu/drm/virtio/virtgpu_drv.h 
b/drivers/gpu/drm/virtio/virtgpu_drv.h
index c4468a4e454e..0a3392f2cda3 100644
--- a/drivers/gpu/drm/virtio/virtgpu_drv.h
+++ b/drivers/gpu/drm/virtio/virtgpu_drv.h
@@ -247,8 +247,7 @@ int virtio_gpu_surface_dirty(struct virtio_gpu_framebuffer 
*qfb,
 /* virtio vg */
 int virtio_gpu_alloc_vbufs(struct virtio_gpu_device *vgdev);
 void virtio_gpu_free_vbufs(struct virtio_gpu_device *vgdev);
-void virtio_gpu_resource_id_get(struct virtio_gpu_device *vgdev,
-  uint32_t *resid);
+int virtio_gpu_resource_id_get(struct virtio_gpu_device *vgdev);
 void virtio_gpu_resource_id_put(struct virtio_gpu_device *vgdev, uint32_t id);
 void virtio_gpu_cmd_create_resource(struct virtio_gpu_device *vgdev,
uint32_t resource_id,
diff --git a/drivers/gpu/drm/virtio/virtgpu_fb.c 
b/drivers/gpu/drm/virtio/virtgpu_fb.c
index a121b1c79522..74d815483487 100644
--- a/drivers/gpu/drm/virtio/virtgpu_fb.c
+++ b/drivers/gpu/drm/virtio/virtgpu_fb.c
@@ -244,14 +244,17 @@ static int virtio_gpufb_create(struct drm_fb_helper 
*helper,
if (IS_ERR(obj))
return PTR_ERR(obj);
 
-   virtio_gpu_resource_id_get(vgdev, );
+   ret = virtio_gpu_resource_id_get(vgdev);
+   if (ret < 0)
+   goto err_obj_vmap;
+   resid = ret;
virtio_gpu_cmd_create_resource(vgdev, resid, format,
   mode_cmd.width, mode_cmd.height);
 
ret = virtio_gpu_vmap_fb(vgdev, obj);
if (ret) {
DRM_ERROR("failed to vmap fb %d\n", ret);
-   goto err_obj_vmap;
+   goto err_obj_id;
}
 
/* attach the object to the resource */
@@ -293,8 +296,11 @@ static int virtio_gpufb_create(struct drm_fb_helper 
*helper,
 err_fb_alloc:
virtio_gpu_cmd_resource_inval_backing(vgdev, resid);
 err_obj_attach:
+err_obj_id:
+   virtio_gpu_resource_id_put(vgdev, resid);
 err_obj_vmap:
virtio_gpu_gem_free_object(>gem_base);
+
return ret;
 }
 
diff --git a/drivers/gpu/drm/virtio/virtgpu_gem.c 
b/drivers/gpu/drm/virtio/virtgpu_gem.c
index 0f2768eacaee..9e3af1ec26db 100644
--- a/drivers/gpu/drm/virtio/virtgpu_gem.c
+++ b/drivers/gpu/drm/virtio/virtgpu_gem.c
@@ -100,7 +100,10 @@ int virtio_gpu_mode_dumb_create(struct drm_file *file_priv,
goto fail;
 
format = virtio_gpu_translate_format(DRM_FORMAT_XRGB);
-   virtio_gpu_resource_id_get(vgdev, );
+   ret = virtio_gpu_resource_id_get(vgdev);
+   if (ret < 0)
+   goto fail;
+   resid = ret;
virtio_gpu_cmd_create_resource(vgdev, resid, format,
   args->width, args->height);
 
@@ -108,13 +111,16 @@ int virtio_gpu_mode_dumb_create(struct drm_file 
*file_priv,
obj = gem_to_virtio_gpu_obj(gobj);
ret = virtio_gpu_object_attach(vgdev, obj, resid, NULL);
if (ret)
-   goto fail;
+   goto fail_id;
 
obj->dumb = true;
args->pitch = pitch;
return ret;
 
+fail_id:
+   virtio_gpu_resource_id_put(vgdev, resid);
 fail:
+   /* Shouldn't we undo virtio_gpu_gem_create()? */
return ret;
 }
 
diff --git a/drivers/gpu/drm/virtio/virtgpu_ioctl.c 
b/drivers/gpu/drm/virtio/virtgpu_ioctl.c
index 7bdf6f0e58a5..eec9f09f01f0 100644
--- a/drivers/gpu/drm/virtio/virtgpu_ioctl.c
+++ b/drivers/gpu/drm/virtio/virtgpu_ioctl.c
@@ -244,7 +244,10 @@ static int virtio_gpu_resource_create_ioctl(struct 
drm_device *dev, void *data,
INIT_LIST_HEAD(_list);
memset(, 0, sizeof(struct ttm_validate_buffer));
 
-   virtio_gpu_resource_id_get(vgdev, _id);
+   ret = virtio_gpu_resource_id_get(vgdev);
+   if (ret < 0)
+   return ret;
+   res_id = ret;
 
size = rc->size;
 
diff --git a/drivers/gpu/drm/virtio/virtgpu_vq.c 
b/drivers/gpu/drm/virtio/virtgpu_vq.c
index 58be09d2eed6..387951c971d4 100644
--- a/drivers/gpu/drm/virtio/virtgpu_vq.c
+++ b/drivers/gpu/drm/virtio/virtgpu_vq.c
@@ -38,11 +38,9 @@
   + MAX_INLINE_CMD_SIZE \
   + MAX_INLINE_RESP_SIZE)
 
-void virtio_gpu_resource_id_get(struct virtio_gpu_device *vgdev,
-   uint32_t *resid)
+int virtio_gpu_resource_id_get(struct virtio_gpu_device *vgdev)
 {
-   int handle = ida_alloc_min(>resource_ida, 1, GFP_KERNEL);
-   

[PATCH 0/4] Improve virtio ID allocation

2018-09-26 Thread Matthew Wilcox
I noticed you were using IDRs where you could be using the more efficient
IDAs, then while fixing that I noticed the lack of error handling,
and I decided to follow that up with an efficiency improvement.

There's probably a v2 of this to follow because I couldn't figure
out how to properly handle one of the error cases ... see the comment
embedded in one of the patches.

Matthew Wilcox (4):
  drm/virtio: Replace IDRs with IDAs
  drm/virtio: Handle context ID allocation errors
  drm/virtio: Handle object ID allocation errors
  drm/virtio: Use IDAs more efficiently

 drivers/gpu/drm/virtio/virtgpu_drv.h   |  9 ++---
 drivers/gpu/drm/virtio/virtgpu_fb.c| 10 --
 drivers/gpu/drm/virtio/virtgpu_gem.c   | 10 --
 drivers/gpu/drm/virtio/virtgpu_ioctl.c |  5 ++-
 drivers/gpu/drm/virtio/virtgpu_kms.c   | 46 +-
 drivers/gpu/drm/virtio/virtgpu_vq.c| 19 ---
 6 files changed, 44 insertions(+), 55 deletions(-)

-- 
2.19.0

___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization


[PATCH 2/4] drm/virtio: Handle context ID allocation errors

2018-09-26 Thread Matthew Wilcox
It is possible to run out of memory while allocating IDs.  The current
code would create a context with an invalid ID; change it to return
-ENOMEM to userspace.

Signed-off-by: Matthew Wilcox 
---
 drivers/gpu/drm/virtio/virtgpu_kms.c | 29 +++-
 1 file changed, 11 insertions(+), 18 deletions(-)

diff --git a/drivers/gpu/drm/virtio/virtgpu_kms.c 
b/drivers/gpu/drm/virtio/virtgpu_kms.c
index e2604fe1b4ae..bf609dcae224 100644
--- a/drivers/gpu/drm/virtio/virtgpu_kms.c
+++ b/drivers/gpu/drm/virtio/virtgpu_kms.c
@@ -52,31 +52,22 @@ static void virtio_gpu_config_changed_work_func(struct 
work_struct *work)
  events_clear, _clear);
 }
 
-static void virtio_gpu_ctx_id_get(struct virtio_gpu_device *vgdev,
- uint32_t *resid)
+static int virtio_gpu_context_create(struct virtio_gpu_device *vgdev,
+ uint32_t nlen, const char *name)
 {
int handle = ida_alloc_min(>ctx_id_ida, 1, GFP_KERNEL);
-   *resid = handle;
-}
 
-static void virtio_gpu_ctx_id_put(struct virtio_gpu_device *vgdev, uint32_t id)
-{
-   ida_free(>ctx_id_ida, id);
-}
-
-static void virtio_gpu_context_create(struct virtio_gpu_device *vgdev,
- uint32_t nlen, const char *name,
- uint32_t *ctx_id)
-{
-   virtio_gpu_ctx_id_get(vgdev, ctx_id);
-   virtio_gpu_cmd_context_create(vgdev, *ctx_id, nlen, name);
+   if (handle < 0)
+   return handle;
+   virtio_gpu_cmd_context_create(vgdev, handle, nlen, name);
+   return handle;
 }
 
 static void virtio_gpu_context_destroy(struct virtio_gpu_device *vgdev,
  uint32_t ctx_id)
 {
virtio_gpu_cmd_context_destroy(vgdev, ctx_id);
-   virtio_gpu_ctx_id_put(vgdev, ctx_id);
+   ida_free(>ctx_id_ida, ctx_id);
 }
 
 static void virtio_gpu_init_vq(struct virtio_gpu_queue *vgvq,
@@ -261,7 +252,7 @@ int virtio_gpu_driver_open(struct drm_device *dev, struct 
drm_file *file)
 {
struct virtio_gpu_device *vgdev = dev->dev_private;
struct virtio_gpu_fpriv *vfpriv;
-   uint32_t id;
+   int id;
char dbgname[TASK_COMM_LEN];
 
/* can't create contexts without 3d renderer */
@@ -274,7 +265,9 @@ int virtio_gpu_driver_open(struct drm_device *dev, struct 
drm_file *file)
return -ENOMEM;
 
get_task_comm(dbgname, current);
-   virtio_gpu_context_create(vgdev, strlen(dbgname), dbgname, );
+   id = virtio_gpu_context_create(vgdev, strlen(dbgname), dbgname);
+   if (id < 0)
+   return id;
 
vfpriv->ctx_id = id;
file->driver_priv = vfpriv;
-- 
2.19.0

___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization


[PATCH 1/4] drm/virtio: Replace IDRs with IDAs

2018-09-26 Thread Matthew Wilcox
These IDRs were only being used to allocate unique numbers, not to look
up pointers, so they can use the more space-efficient IDA instead.

Signed-off-by: Matthew Wilcox 
---
 drivers/gpu/drm/virtio/virtgpu_drv.h |  6 ++
 drivers/gpu/drm/virtio/virtgpu_kms.c | 18 --
 drivers/gpu/drm/virtio/virtgpu_vq.c  | 12 ++--
 3 files changed, 8 insertions(+), 28 deletions(-)

diff --git a/drivers/gpu/drm/virtio/virtgpu_drv.h 
b/drivers/gpu/drm/virtio/virtgpu_drv.h
index 65605e207bbe..c4468a4e454e 100644
--- a/drivers/gpu/drm/virtio/virtgpu_drv.h
+++ b/drivers/gpu/drm/virtio/virtgpu_drv.h
@@ -180,8 +180,7 @@ struct virtio_gpu_device {
struct kmem_cache *vbufs;
bool vqs_ready;
 
-   struct idr  resource_idr;
-   spinlock_t resource_idr_lock;
+   struct ida  resource_ida;
 
wait_queue_head_t resp_wq;
/* current display info */
@@ -190,8 +189,7 @@ struct virtio_gpu_device {
 
struct virtio_gpu_fence_driver fence_drv;
 
-   struct idr  ctx_id_idr;
-   spinlock_t ctx_id_idr_lock;
+   struct ida  ctx_id_ida;
 
bool has_virgl_3d;
 
diff --git a/drivers/gpu/drm/virtio/virtgpu_kms.c 
b/drivers/gpu/drm/virtio/virtgpu_kms.c
index 65060c08522d..e2604fe1b4ae 100644
--- a/drivers/gpu/drm/virtio/virtgpu_kms.c
+++ b/drivers/gpu/drm/virtio/virtgpu_kms.c
@@ -55,21 +55,13 @@ static void virtio_gpu_config_changed_work_func(struct 
work_struct *work)
 static void virtio_gpu_ctx_id_get(struct virtio_gpu_device *vgdev,
  uint32_t *resid)
 {
-   int handle;
-
-   idr_preload(GFP_KERNEL);
-   spin_lock(>ctx_id_idr_lock);
-   handle = idr_alloc(>ctx_id_idr, NULL, 1, 0, 0);
-   spin_unlock(>ctx_id_idr_lock);
-   idr_preload_end();
+   int handle = ida_alloc_min(>ctx_id_ida, 1, GFP_KERNEL);
*resid = handle;
 }
 
 static void virtio_gpu_ctx_id_put(struct virtio_gpu_device *vgdev, uint32_t id)
 {
-   spin_lock(>ctx_id_idr_lock);
-   idr_remove(>ctx_id_idr, id);
-   spin_unlock(>ctx_id_idr_lock);
+   ida_free(>ctx_id_ida, id);
 }
 
 static void virtio_gpu_context_create(struct virtio_gpu_device *vgdev,
@@ -151,10 +143,8 @@ int virtio_gpu_driver_load(struct drm_device *dev, 
unsigned long flags)
vgdev->dev = dev->dev;
 
spin_lock_init(>display_info_lock);
-   spin_lock_init(>ctx_id_idr_lock);
-   idr_init(>ctx_id_idr);
-   spin_lock_init(>resource_idr_lock);
-   idr_init(>resource_idr);
+   ida_init(>ctx_id_ida);
+   ida_init(>resource_ida);
init_waitqueue_head(>resp_wq);
virtio_gpu_init_vq(>ctrlq, virtio_gpu_dequeue_ctrl_func);
virtio_gpu_init_vq(>cursorq, virtio_gpu_dequeue_cursor_func);
diff --git a/drivers/gpu/drm/virtio/virtgpu_vq.c 
b/drivers/gpu/drm/virtio/virtgpu_vq.c
index 020070d483d3..58be09d2eed6 100644
--- a/drivers/gpu/drm/virtio/virtgpu_vq.c
+++ b/drivers/gpu/drm/virtio/virtgpu_vq.c
@@ -41,21 +41,13 @@
 void virtio_gpu_resource_id_get(struct virtio_gpu_device *vgdev,
uint32_t *resid)
 {
-   int handle;
-
-   idr_preload(GFP_KERNEL);
-   spin_lock(>resource_idr_lock);
-   handle = idr_alloc(>resource_idr, NULL, 1, 0, GFP_NOWAIT);
-   spin_unlock(>resource_idr_lock);
-   idr_preload_end();
+   int handle = ida_alloc_min(>resource_ida, 1, GFP_KERNEL);
*resid = handle;
 }
 
 void virtio_gpu_resource_id_put(struct virtio_gpu_device *vgdev, uint32_t id)
 {
-   spin_lock(>resource_idr_lock);
-   idr_remove(>resource_idr, id);
-   spin_unlock(>resource_idr_lock);
+   ida_free(>resource_ida, id);
 }
 
 void virtio_gpu_ctrl_ack(struct virtqueue *vq)
-- 
2.19.0

___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization


Re: [PATCH 0/3] virtio: add vmap support for prime objects

2018-09-26 Thread Gerd Hoffmann
  Hi,

> Having the support for vmapping dmabuf's is required to share
> dmabufs to drivers that want CPU access. This is the case of
> a vivid to virtio-gpu pipeline, where the virtio-gpu driver
> exports dmabufs to the video4linux vivid driver.
> 
> The first patch adds virtio_gpu_object_kunmap() and calls
> it from the TTM object destroy path. This function will be
> used to unmap prime objects.
> 
> The second patch reworks virtio_gpu_object_kmap(), so it's
> balanced with virtio_gpu_object_kunmap.
> 
> Finally, the third patch uses virtio_gpu_object_k{map,unmap}
> to support prime v{map,unmap}.
> 
> Please review!

Pushed to drm-misc-next.

thanks,
  Gerd

___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization