Linux virtualization list
 help / color / mirror / Atom feed
* [PATCH v8 2/5] ptr_ring: ring test
From: Michael S. Tsirkin @ 2016-06-13 20:54 UTC (permalink / raw)
  To: linux-kernel
  Cc: kvm, Eric Dumazet, netdev, Steven Rostedt, virtualization, brouer,
	davem
In-Reply-To: <1465851234-13558-1-git-send-email-mst@redhat.com>

Add ringtest based unit test for ptr ring.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 tools/virtio/ringtest/ptr_ring.c | 192 +++++++++++++++++++++++++++++++++++++++
 tools/virtio/ringtest/Makefile   |   5 +-
 2 files changed, 196 insertions(+), 1 deletion(-)
 create mode 100644 tools/virtio/ringtest/ptr_ring.c

diff --git a/tools/virtio/ringtest/ptr_ring.c b/tools/virtio/ringtest/ptr_ring.c
new file mode 100644
index 0000000..74abd74
--- /dev/null
+++ b/tools/virtio/ringtest/ptr_ring.c
@@ -0,0 +1,192 @@
+#define _GNU_SOURCE
+#include "main.h"
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <pthread.h>
+#include <malloc.h>
+#include <assert.h>
+#include <errno.h>
+#include <limits.h>
+
+#define SMP_CACHE_BYTES 64
+#define cache_line_size() SMP_CACHE_BYTES
+#define ____cacheline_aligned_in_smp __attribute__ ((aligned (SMP_CACHE_BYTES)))
+#define unlikely(x)    (__builtin_expect(!!(x), 0))
+#define ALIGN(x, a) (((x) + (a) - 1) / (a) * (a))
+typedef pthread_spinlock_t  spinlock_t;
+
+typedef int gfp_t;
+static void *kzalloc(unsigned size, gfp_t gfp)
+{
+	void *p = memalign(64, size);
+	if (!p)
+		return p;
+	memset(p, 0, size);
+
+	return p;
+}
+
+static void kfree(void *p)
+{
+	if (p)
+		free(p);
+}
+
+static void spin_lock_init(spinlock_t *lock)
+{
+	int r = pthread_spin_init(lock, 0);
+	assert(!r);
+}
+
+static void spin_lock(spinlock_t *lock)
+{
+	int ret = pthread_spin_lock(lock);
+	assert(!ret);
+}
+
+static void spin_unlock(spinlock_t *lock)
+{
+	int ret = pthread_spin_unlock(lock);
+	assert(!ret);
+}
+
+static void spin_lock_bh(spinlock_t *lock)
+{
+	spin_lock(lock);
+}
+
+static void spin_unlock_bh(spinlock_t *lock)
+{
+	spin_unlock(lock);
+}
+
+static void spin_lock_irq(spinlock_t *lock)
+{
+	spin_lock(lock);
+}
+
+static void spin_unlock_irq(spinlock_t *lock)
+{
+	spin_unlock(lock);
+}
+
+static void spin_lock_irqsave(spinlock_t *lock, unsigned long f)
+{
+	spin_lock(lock);
+}
+
+static void spin_unlock_irqrestore(spinlock_t *lock, unsigned long f)
+{
+	spin_unlock(lock);
+}
+
+#include "../../../include/linux/ptr_ring.h"
+
+static unsigned long long headcnt, tailcnt;
+static struct ptr_ring array ____cacheline_aligned_in_smp;
+
+/* implemented by ring */
+void alloc_ring(void)
+{
+	int ret = ptr_ring_init(&array, ring_size, 0);
+	assert(!ret);
+}
+
+/* guest side */
+int add_inbuf(unsigned len, void *buf, void *datap)
+{
+	int ret;
+
+	ret = __ptr_ring_produce(&array, buf);
+	if (ret >= 0) {
+		ret = 0;
+		headcnt++;
+	}
+
+	return ret;
+}
+
+/*
+ * ptr_ring API provides no way for producer to find out whether a given
+ * buffer was consumed.  Our tests merely require that a successful get_buf
+ * implies that add_inbuf succeed in the past, and that add_inbuf will succeed,
+ * fake it accordingly.
+ */
+void *get_buf(unsigned *lenp, void **bufp)
+{
+	void *datap;
+
+	if (tailcnt == headcnt || __ptr_ring_full(&array))
+		datap = NULL;
+	else {
+		datap = "Buffer\n";
+		++tailcnt;
+	}
+
+	return datap;
+}
+
+void poll_used(void)
+{
+	void *b;
+
+	do {
+		if (tailcnt == headcnt || __ptr_ring_full(&array)) {
+			b = NULL;
+			barrier();
+		} else {
+			b = "Buffer\n";
+		}
+	} while (!b);
+}
+
+void disable_call()
+{
+	assert(0);
+}
+
+bool enable_call()
+{
+	assert(0);
+}
+
+void kick_available(void)
+{
+	assert(0);
+}
+
+/* host side */
+void disable_kick()
+{
+	assert(0);
+}
+
+bool enable_kick()
+{
+	assert(0);
+}
+
+void poll_avail(void)
+{
+	void *b;
+
+	do {
+		barrier();
+		b = __ptr_ring_peek(&array);
+	} while (!b);
+}
+
+bool use_buf(unsigned *lenp, void **bufp)
+{
+	void *ptr;
+
+	ptr = __ptr_ring_consume(&array);
+
+	return ptr;
+}
+
+void call_used(void)
+{
+	assert(0);
+}
diff --git a/tools/virtio/ringtest/Makefile b/tools/virtio/ringtest/Makefile
index 6173ada..877a8a4 100644
--- a/tools/virtio/ringtest/Makefile
+++ b/tools/virtio/ringtest/Makefile
@@ -1,6 +1,6 @@
 all:
 
-all: ring virtio_ring_0_9 virtio_ring_poll virtio_ring_inorder noring
+all: ring virtio_ring_0_9 virtio_ring_poll virtio_ring_inorder ptr_ring noring
 
 CFLAGS += -Wall
 CFLAGS += -pthread -O2 -ggdb
@@ -8,6 +8,7 @@ LDFLAGS += -pthread -O2 -ggdb
 
 main.o: main.c main.h
 ring.o: ring.c main.h
+ptr_ring.o: ptr_ring.c main.h ../../../include/linux/ptr_ring.h
 virtio_ring_0_9.o: virtio_ring_0_9.c main.h
 virtio_ring_poll.o: virtio_ring_poll.c virtio_ring_0_9.c main.h
 virtio_ring_inorder.o: virtio_ring_inorder.c virtio_ring_0_9.c main.h
@@ -15,6 +16,7 @@ ring: ring.o main.o
 virtio_ring_0_9: virtio_ring_0_9.o main.o
 virtio_ring_poll: virtio_ring_poll.o main.o
 virtio_ring_inorder: virtio_ring_inorder.o main.o
+ptr_ring: ptr_ring.o main.o
 noring: noring.o main.o
 clean:
 	-rm main.o
@@ -22,6 +24,7 @@ clean:
 	-rm virtio_ring_0_9.o virtio_ring_0_9
 	-rm virtio_ring_poll.o virtio_ring_poll
 	-rm virtio_ring_inorder.o virtio_ring_inorder
+	-rm ptr_ring.o ptr_ring
 	-rm noring.o noring
 
 .PHONY: all clean
-- 
MST

^ permalink raw reply related

* Re: [PATCH v5 6/6] hwmon: use smp_call_on_cpu() for dell-smm i8k
From: Pali Rohár @ 2016-06-13 19:05 UTC (permalink / raw)
  To: Juergen Gross
  Cc: x86, jeremy, jdelvare, peterz, akataria, linux-kernel,
	virtualization, chrisw, mingo, david.vrabel, Douglas_Warzecha,
	hpa, xen-devel, boris.ostrovsky, tglx, linux
In-Reply-To: <1459952266-3687-7-git-send-email-jgross@suse.com>


[-- Attachment #1.1: Type: Text/Plain, Size: 491 bytes --]

On Wednesday 06 April 2016 16:17:46 Juergen Gross wrote:
> Use the smp_call_on_cpu() function to call system management
> mode on cpu 0.
> Make call secure by adding get_online_cpus() to avoid e.g. suspend
> resume cycles in between.
> 
> Signed-off-by: Juergen Gross <jgross@suse.com>
> ---
> V4: add call to get_online_cpus()
> ---
>  drivers/hwmon/dell-smm-hwmon.c | 35

As mentioned in discussion under V4, you can add my Acked-by.

-- 
Pali Rohár
pali.rohar@gmail.com

[-- Attachment #1.2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

[-- Attachment #2: Type: text/plain, Size: 183 bytes --]

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

^ permalink raw reply

* Re: [PATCH] virtio_balloon: fix PFN format for virtio-1
From: Christian Borntraeger @ 2016-06-13 18:50 UTC (permalink / raw)
  To: Greg KH, Michael S. Tsirkin; +Cc: linux-kernel, stable, virtualization
In-Reply-To: <20160613183559.GA10149@kroah.com>

On 06/13/2016 08:35 PM, Greg KH wrote:
> On Mon, Jun 13, 2016 at 09:08:44PM +0300, Michael S. Tsirkin wrote:
>> On Wed, May 18, 2016 at 03:38:53PM +0300, Michael S. Tsirkin wrote:
>>> Everything should be LE when using virtio-1, but
>>> the linux balloon driver does not seem to care about that.
>>>
>>> Cc: stable@vger.kernel.org
>>> Reported-by: Cornelia Huck <cornelia.huck@de.ibm.com>
>>> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
>>
>> Forgot to CC stable.
>> Please consider this patch for inclusion in the next stable Linux.
> 
> Someone needs to tell stable@ the git comit id of the patch when it hits
> Linus's tree...
> 
> thanks,
> 
> greg k-h
> 

See my mail,
https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit?id=87c9403b0d1de4676b0bd273eea68fcf6de68e68

commit	87c9403b0d1de4676b0bd273eea
virtio_balloon: fix PFN format for virtio-1

^ permalink raw reply

* Re: [PATCH] virtio_balloon: fix PFN format for virtio-1
From: Greg KH @ 2016-06-13 18:35 UTC (permalink / raw)
  To: Michael S. Tsirkin; +Cc: linux-kernel, stable, virtualization
In-Reply-To: <20160613210800-mutt-send-email-mst@redhat.com>

On Mon, Jun 13, 2016 at 09:08:44PM +0300, Michael S. Tsirkin wrote:
> On Wed, May 18, 2016 at 03:38:53PM +0300, Michael S. Tsirkin wrote:
> > Everything should be LE when using virtio-1, but
> > the linux balloon driver does not seem to care about that.
> > 
> > Cc: stable@vger.kernel.org
> > Reported-by: Cornelia Huck <cornelia.huck@de.ibm.com>
> > Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> 
> Forgot to CC stable.
> Please consider this patch for inclusion in the next stable Linux.

Someone needs to tell stable@ the git comit id of the patch when it hits
Linus's tree...

thanks,

greg k-h

^ permalink raw reply

* Re: [PATCH] virtio_balloon: fix PFN format for virtio-1
From: Michael S. Tsirkin @ 2016-06-13 18:08 UTC (permalink / raw)
  To: linux-kernel; +Cc: stable, virtualization
In-Reply-To: <1463574848-15630-1-git-send-email-mst@redhat.com>

On Wed, May 18, 2016 at 03:38:53PM +0300, Michael S. Tsirkin wrote:
> Everything should be LE when using virtio-1, but
> the linux balloon driver does not seem to care about that.
> 
> Cc: stable@vger.kernel.org
> Reported-by: Cornelia Huck <cornelia.huck@de.ibm.com>
> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>

Forgot to CC stable.
Please consider this patch for inclusion in the next stable Linux.


> ---
>  drivers/virtio/virtio_balloon.c | 20 ++++++++++++--------
>  1 file changed, 12 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_balloon.c
> index 7b6d74f..476c0e3 100644
> --- a/drivers/virtio/virtio_balloon.c
> +++ b/drivers/virtio/virtio_balloon.c
> @@ -75,7 +75,7 @@ struct virtio_balloon {
>  
>  	/* The array of pfns we tell the Host about. */
>  	unsigned int num_pfns;
> -	u32 pfns[VIRTIO_BALLOON_ARRAY_PFNS_MAX];
> +	__virtio32 pfns[VIRTIO_BALLOON_ARRAY_PFNS_MAX];
>  
>  	/* Memory statistics */
>  	struct virtio_balloon_stat stats[VIRTIO_BALLOON_S_NR];
> @@ -127,14 +127,16 @@ static void tell_host(struct virtio_balloon *vb, struct virtqueue *vq)
>  
>  }
>  
> -static void set_page_pfns(u32 pfns[], struct page *page)
> +static void set_page_pfns(struct virtio_balloon *vb,
> +			  __virtio32 pfns[], struct page *page)
>  {
>  	unsigned int i;
>  
>  	/* Set balloon pfns pointing at this page.
>  	 * Note that the first pfn points at start of the page. */
>  	for (i = 0; i < VIRTIO_BALLOON_PAGES_PER_PAGE; i++)
> -		pfns[i] = page_to_balloon_pfn(page) + i;
> +		pfns[i] = cpu_to_virtio32(vb->vdev,
> +					  page_to_balloon_pfn(page) + i);
>  }
>  
>  static unsigned fill_balloon(struct virtio_balloon *vb, size_t num)
> @@ -158,7 +160,7 @@ static unsigned fill_balloon(struct virtio_balloon *vb, size_t num)
>  			msleep(200);
>  			break;
>  		}
> -		set_page_pfns(vb->pfns + vb->num_pfns, page);
> +		set_page_pfns(vb, vb->pfns + vb->num_pfns, page);
>  		vb->num_pages += VIRTIO_BALLOON_PAGES_PER_PAGE;
>  		if (!virtio_has_feature(vb->vdev,
>  					VIRTIO_BALLOON_F_DEFLATE_ON_OOM))
> @@ -177,10 +179,12 @@ static unsigned fill_balloon(struct virtio_balloon *vb, size_t num)
>  static void release_pages_balloon(struct virtio_balloon *vb)
>  {
>  	unsigned int i;
> +	struct page *page;
>  
>  	/* Find pfns pointing at start of each page, get pages and free them. */
>  	for (i = 0; i < vb->num_pfns; i += VIRTIO_BALLOON_PAGES_PER_PAGE) {
> -		struct page *page = balloon_pfn_to_page(vb->pfns[i]);
> +		page = balloon_pfn_to_page(virtio32_to_cpu(vb->vdev,
> +							   vb->pfns[i]));
>  		if (!virtio_has_feature(vb->vdev,
>  					VIRTIO_BALLOON_F_DEFLATE_ON_OOM))
>  			adjust_managed_page_count(page, 1);
> @@ -203,7 +207,7 @@ static unsigned leak_balloon(struct virtio_balloon *vb, size_t num)
>  		page = balloon_page_dequeue(vb_dev_info);
>  		if (!page)
>  			break;
> -		set_page_pfns(vb->pfns + vb->num_pfns, page);
> +		set_page_pfns(vb, vb->pfns + vb->num_pfns, page);
>  		vb->num_pages -= VIRTIO_BALLOON_PAGES_PER_PAGE;
>  	}
>  
> @@ -471,13 +475,13 @@ static int virtballoon_migratepage(struct balloon_dev_info *vb_dev_info,
>  	__count_vm_event(BALLOON_MIGRATE);
>  	spin_unlock_irqrestore(&vb_dev_info->pages_lock, flags);
>  	vb->num_pfns = VIRTIO_BALLOON_PAGES_PER_PAGE;
> -	set_page_pfns(vb->pfns, newpage);
> +	set_page_pfns(vb, vb->pfns, newpage);
>  	tell_host(vb, vb->inflate_vq);
>  
>  	/* balloon's page migration 2nd step -- deflate "page" */
>  	balloon_page_delete(page);
>  	vb->num_pfns = VIRTIO_BALLOON_PAGES_PER_PAGE;
> -	set_page_pfns(vb->pfns, page);
> +	set_page_pfns(vb, vb->pfns, page);
>  	tell_host(vb, vb->deflate_vq);
>  
>  	mutex_unlock(&vb->balloon_lock);
> -- 
> MST

^ permalink raw reply

* [PATCH] drivers: virtio_blk: notify blk-core when hw-queue number changes
From: Bob Liu @ 2016-06-13  9:58 UTC (permalink / raw)
  To: linux-kernel; +Cc: Bob Liu, virtualization, mst

A guest might be migrated to other hosts with different num_queues, the
blk-core should aware of that else the reference of &vblk->vqs[qid] may be wrong.

Signed-off-by: Bob Liu <bob.liu@oracle.com>
---
 drivers/block/virtio_blk.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c
index 42758b5..c169238 100644
--- a/drivers/block/virtio_blk.c
+++ b/drivers/block/virtio_blk.c
@@ -819,6 +819,9 @@ static int virtblk_restore(struct virtio_device *vdev)
 	if (ret)
 		return ret;
 
+	if (vblk->num_vqs != vblk->tag_set.nr_hw_queues)
+		blk_mq_update_nr_hw_queues(&vblk->tag_set, vblk->num_vqs);
+
 	virtio_device_ready(vdev);
 
 	blk_mq_start_stopped_hw_queues(vblk->disk->queue, true);
-- 
2.7.4

^ permalink raw reply related

* Re: [PATCH v6v3 02/12] mm: migrate: support non-lru movable page migration
From: Anshuman Khandual @ 2016-06-13  9:38 UTC (permalink / raw)
  To: Minchan Kim, Andrew Morton
  Cc: Rik van Riel, Sergey Senozhatsky, Rafael Aquini, Jonathan Corbet,
	Hugh Dickins, linux-kernel, dri-devel, virtualization,
	John Einar Reitan, linux-mm, Gioh Kim, Mel Gorman, Joonsoo Kim,
	Vlastimil Babka
In-Reply-To: <20160531000117.GB18314@bbox>

On 05/31/2016 05:31 AM, Minchan Kim wrote:
> @@ -791,6 +921,7 @@ static int __unmap_and_move(struct page *page, struct page *newpage,
>  	int rc = -EAGAIN;
>  	int page_was_mapped = 0;
>  	struct anon_vma *anon_vma = NULL;
> +	bool is_lru = !__PageMovable(page);
>  
>  	if (!trylock_page(page)) {
>  		if (!force || mode == MIGRATE_ASYNC)
> @@ -871,6 +1002,11 @@ static int __unmap_and_move(struct page *page, struct page *newpage,
>  		goto out_unlock_both;
>  	}
>  
> +	if (unlikely(!is_lru)) {
> +		rc = move_to_new_page(newpage, page, mode);
> +		goto out_unlock_both;
> +	}
> +

Hello Minchan,

I might be missing something here but does this implementation support the
scenario where these non LRU pages owned by the driver mapped as PTE into
process page table ? Because the "goto out_unlock_both" statement above
skips all the PTE unmap, putting a migration PTE and removing the migration
PTE steps.

Regards
Anshuman

^ permalink raw reply

* Re: [PATCH] virtio_balloon: fix PFN format for virtio-1
From: Christian Borntraeger @ 2016-06-13  7:15 UTC (permalink / raw)
  To: Michael S. Tsirkin, linux-kernel; +Cc: stable, virtualization
In-Reply-To: <1463574848-15630-1-git-send-email-mst@redhat.com>

On 05/18/2016 02:38 PM, Michael S. Tsirkin wrote:
> Everything should be LE when using virtio-1, but
> the linux balloon driver does not seem to care about that.
> 
> Cc: stable@vger.kernel.org
> Reported-by: Cornelia Huck <cornelia.huck@de.ibm.com>
> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>

The final commit in Linus tree does not contain cc stable
see
https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit?id=87c9403b0d1de4676b0bd273eea68fcf6de68e68

But it is certainly table material.

Christian

^ permalink raw reply

* Re: [PATCH 0/6] virtio_net: use common code for virtio_net_hdr and skb GSO conversion
From: David Miller @ 2016-06-11  6:04 UTC (permalink / raw)
  To: rppt; +Cc: netdev, virtualization, linux-kernel, mst
In-Reply-To: <1465391362-18437-1-git-send-email-rppt@linux.vnet.ibm.com>

From: Mike Rapoport <rppt@linux.vnet.ibm.com>
Date: Wed,  8 Jun 2016 16:09:16 +0300

> This patches introduce virtio_net_hdr_{from,to}_skb functions for
> conversion of GSO information between skb and virtio_net_hdr.

Looks like a nice cleanup to me, series applied, thanks Mike.

^ permalink raw reply

* Re: [PATCH v2 06/20] drm: i915: Rely on the default ->best_encoder() behavior where appropriate
From: Daniel Vetter @ 2016-06-10 16:41 UTC (permalink / raw)
  To: Boris Brezillon, David Airlie, dri-devel, Daniel Vetter,
	linux-kernel, linux-arm-kernel, Kukjin Kim, Krzysztof Kozlowski,
	linux-samsung-soc, intel-gfx, Jani Nikula, Alexey Brodkin,
	Inki Dae, Joonyoung Shim, Seung-Woo Kim, Kyungmin Park,
	Stefan Agner, Alison Wang, Matthias Brugger, Rob Clark,
	Laurent Pinchart, Mark Yao, Heiko Stuebner
In-Reply-To: <20160610152412.GL3363@phenom.ffwll.local>

On Fri, Jun 10, 2016 at 05:24:12PM +0200, Daniel Vetter wrote:
> On Tue, Jun 07, 2016 at 01:48:01PM +0200, Boris Brezillon wrote:
> > For all outputs except dp_mst, we have a 1:1 relationship between
> > connectors and encoders and the driver is relying on the atomic helpers:
> > we can drop the custom ->best_encoder() implementation and let the core
> > call drm_atomic_helper_best_encoder() for us.
> > 
> > Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
> 
> You can also drop the best_encoder from intel_dp_mst, we only need the
> atomic_best_encoder. The best_encoder there was needed to help out the
> fbdev emulation. Care to respin?

Boris pointed out on irc that this won't work for the fbdev stuff since
that has a WARN_ON if theres more than 1 possible encoder. Applied this
one here instead.

Thanks, Daniel
-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch

^ permalink raw reply

* Re: [PATCH v2 00/20] drm/atomic: Provide default ->best_encoder() behavior
From: Daniel Vetter @ 2016-06-10 15:25 UTC (permalink / raw)
  To: Boris Brezillon
  Cc: Krzysztof Kozlowski, Heiko Stuebner, David Airlie, dri-devel,
	virtualization, Eric Anholt, Thierry Reding, Laurent Pinchart,
	Benjamin Gaignard, Daniel Vetter, Alexandre Courbot,
	linux-samsung-soc, Joonyoung Shim, Alexey Brodkin, Kyungmin Park,
	linux-rockchip, Chen-Yu Tsai, Kukjin Kim, linux-tegra,
	Stephen Warren, linux-arm-msm, intel-gfx, Jani Nikula
In-Reply-To: <1465300095-16971-1-git-send-email-boris.brezillon@free-electrons.com>

On Tue, Jun 07, 2016 at 01:47:55PM +0200, Boris Brezillon wrote:
> Hello,
> 
> This patch series aims at replacing all dummy ->best_encoder()
> implementations where we have a 1:1 relationship between encoders
> and connectors.
> The core already provides the drm_atomic_helper_best_encoder()
> function which is taking the first encoder attached to the
> connector (after making sure only one encoder was attached to the
> connector), but it's not automatically used, and drivers wanting
> to rely on this default behavior have to explicitly assign their
> ->best_encoder() hook to drm_atomic_helper_best_encoder().
> 
> The first patch fixes remaining places where
> drm_atomic_helper_best_encoder() should be called when ->best_encoder()
> is NULL, so that drivers using the atomic helpers can get rid of the
> explicit ->best_encoder assignment if they need to rely on the default
> drm_atomic_helper_best_encoder() implementation.
> 
> The following patches are killing all open coded ->best_encoder()
> implementations that could be replaced by
> drm_atomic_helper_best_encoder().
> 
> All modifications have been compile tested except for the changed on
> the intel driver.
> I've also tested on an atmel board, but I recommend waiting for DRM
> driver maintainers feedback before applying the associated changes.
> 
> Note that once patch 1 is applied, the other patches can be applied
> independently.

One comment on the i915 patch, all others should now be in drm-misc.
Thanks a lot for doing this.
-Daniel

> 
> Best Regards,
> 
> Boris
> 
> Changes since v1:
> - remove useless ->encoder backpointers in some implementations
> - documented the default behavior in the vtable doc
> - added R-b/A-b tags
> 
> Boris Brezillon (20):
>   drm/atomic: Fix remaining places where !funcs->best_encoder is valid
>   drm: arc: Rely on the default ->best_encoder() behavior
>   drm: atmel-hlcdc: Rely on the default ->best_encoder() behavior
>   drm: exynos: Rely on the default ->best_encoder() behavior
>   drm: fsl-dcu: Rely on the default ->best_encoder() behavior
>   drm: i915: Rely on the default ->best_encoder() behavior where
>     appropriate
>   drm: mediatek: Rely on the default ->best_encoder() behavior
>   drm: msm: Rely on the default ->best_encoder() behavior where
>     appropriate
>   drm: rcar-du: Rely on the default ->best_encoder() behavior
>   drm: rockchip: Rely on the default ->best_encoder() behavior
>   drm: sti: Rely on the default ->best_encoder() behavior
>   drm: sun4i: Rely on the default ->best_encoder() behavior
>   drm: tegra: Rely on the default ->best_encoder() behavior
>   drm: vc4: Rely on the default ->best_encoder() behavior
>   drm: virtgpu: Rely on the default ->best_encoder() behavior
>   drm: omap: Rely on the default ->best_encoder() behavior
>   drm/bridge: anx78xx: Rely on the default ->best_encoder() behavior
>   drm/bridge: ptn3460: Rely on the default ->best_encoder() behavior
>   drm/bridge: ps8622: Rely on the default ->best_encoder() behavior
>   drm/bridge: dw-hdmi: Use drm_atomic_helper_best_encoder()
> 
>  drivers/gpu/drm/arc/arcpgu_hdmi.c                  | 18 ------------------
>  drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_output.c   | 12 ------------
>  drivers/gpu/drm/bridge/analogix-anx78xx.c          |  8 --------
>  drivers/gpu/drm/bridge/dw-hdmi.c                   | 11 +----------
>  drivers/gpu/drm/bridge/nxp-ptn3460.c               |  8 --------
>  drivers/gpu/drm/bridge/parade-ps8622.c             | 10 ----------
>  drivers/gpu/drm/drm_atomic_helper.c                |  4 +++-
>  drivers/gpu/drm/drm_fb_helper.c                    | 13 ++++++++++++-
>  drivers/gpu/drm/exynos/exynos_drm_dpi.c            |  9 ---------
>  drivers/gpu/drm/exynos/exynos_drm_dsi.c            |  9 ---------
>  drivers/gpu/drm/exynos/exynos_drm_vidi.c           |  8 --------
>  drivers/gpu/drm/exynos/exynos_hdmi.c               |  8 --------
>  drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_rgb.c          |  9 ---------
>  drivers/gpu/drm/i915/intel_crt.c                   |  1 -
>  drivers/gpu/drm/i915/intel_display.c               |  8 --------
>  drivers/gpu/drm/i915/intel_dp.c                    |  1 -
>  drivers/gpu/drm/i915/intel_drv.h                   |  1 -
>  drivers/gpu/drm/i915/intel_dsi.c                   |  1 -
>  drivers/gpu/drm/i915/intel_dvo.c                   |  1 -
>  drivers/gpu/drm/i915/intel_hdmi.c                  |  1 -
>  drivers/gpu/drm/i915/intel_lvds.c                  |  1 -
>  drivers/gpu/drm/i915/intel_sdvo.c                  |  1 -
>  drivers/gpu/drm/i915/intel_tv.c                    |  1 -
>  drivers/gpu/drm/mediatek/mtk_dsi.c                 |  9 ---------
>  drivers/gpu/drm/msm/edp/edp_connector.c            | 10 ----------
>  drivers/gpu/drm/msm/hdmi/hdmi_connector.c          |  8 --------
>  drivers/gpu/drm/msm/mdp/mdp4/mdp4_lvds_connector.c |  9 ---------
>  drivers/gpu/drm/omapdrm/omap_connector.c           | 10 ----------
>  drivers/gpu/drm/rcar-du/rcar_du_encoder.c          | 12 ------------
>  drivers/gpu/drm/rcar-du/rcar_du_encoder.h          |  3 ---
>  drivers/gpu/drm/rcar-du/rcar_du_hdmicon.c          |  1 -
>  drivers/gpu/drm/rcar-du/rcar_du_lvdscon.c          |  1 -
>  drivers/gpu/drm/rcar-du/rcar_du_vgacon.c           |  3 ---
>  drivers/gpu/drm/rockchip/dw-mipi-dsi.c             |  9 ---------
>  drivers/gpu/drm/rockchip/inno_hdmi.c               |  9 ---------
>  drivers/gpu/drm/sti/sti_dvo.c                      | 10 ----------
>  drivers/gpu/drm/sti/sti_hda.c                      | 10 ----------
>  drivers/gpu/drm/sti/sti_hdmi.c                     | 10 ----------
>  drivers/gpu/drm/sun4i/sun4i_rgb.c                  | 10 ----------
>  drivers/gpu/drm/sun4i/sun4i_tv.c                   |  9 ---------
>  drivers/gpu/drm/tegra/drm.h                        |  2 --
>  drivers/gpu/drm/tegra/dsi.c                        |  1 -
>  drivers/gpu/drm/tegra/hdmi.c                       |  1 -
>  drivers/gpu/drm/tegra/output.c                     |  8 --------
>  drivers/gpu/drm/tegra/rgb.c                        |  1 -
>  drivers/gpu/drm/tegra/sor.c                        |  1 -
>  drivers/gpu/drm/vc4/vc4_dpi.c                      |  9 ---------
>  drivers/gpu/drm/vc4/vc4_hdmi.c                     |  9 ---------
>  drivers/gpu/drm/virtio/virtgpu_display.c           | 10 ----------
>  include/drm/drm_modeset_helper_vtables.h           | 10 ++++++++--
>  50 files changed, 24 insertions(+), 305 deletions(-)
> 
> -- 
> 2.7.4
> 

-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch

^ permalink raw reply

* Re: [PATCH v2 06/20] drm: i915: Rely on the default ->best_encoder() behavior where appropriate
From: Daniel Vetter @ 2016-06-10 15:24 UTC (permalink / raw)
  To: Boris Brezillon
  Cc: Krzysztof Kozlowski, Heiko Stuebner, David Airlie, dri-devel,
	virtualization, Eric Anholt, Thierry Reding, Laurent Pinchart,
	Benjamin Gaignard, Daniel Vetter, Alexandre Courbot,
	linux-samsung-soc, Joonyoung Shim, Alexey Brodkin, Kyungmin Park,
	linux-rockchip, Chen-Yu Tsai, Kukjin Kim, linux-tegra,
	Stephen Warren, linux-arm-msm, intel-gfx, Jani Nikula
In-Reply-To: <1465300095-16971-7-git-send-email-boris.brezillon@free-electrons.com>

On Tue, Jun 07, 2016 at 01:48:01PM +0200, Boris Brezillon wrote:
> For all outputs except dp_mst, we have a 1:1 relationship between
> connectors and encoders and the driver is relying on the atomic helpers:
> we can drop the custom ->best_encoder() implementation and let the core
> call drm_atomic_helper_best_encoder() for us.
> 
> Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>

You can also drop the best_encoder from intel_dp_mst, we only need the
atomic_best_encoder. The best_encoder there was needed to help out the
fbdev emulation. Care to respin?
-Daniel

> ---
>  drivers/gpu/drm/i915/intel_crt.c     | 1 -
>  drivers/gpu/drm/i915/intel_display.c | 8 --------
>  drivers/gpu/drm/i915/intel_dp.c      | 1 -
>  drivers/gpu/drm/i915/intel_drv.h     | 1 -
>  drivers/gpu/drm/i915/intel_dsi.c     | 1 -
>  drivers/gpu/drm/i915/intel_dvo.c     | 1 -
>  drivers/gpu/drm/i915/intel_hdmi.c    | 1 -
>  drivers/gpu/drm/i915/intel_lvds.c    | 1 -
>  drivers/gpu/drm/i915/intel_sdvo.c    | 1 -
>  drivers/gpu/drm/i915/intel_tv.c      | 1 -
>  10 files changed, 17 deletions(-)
> 
> diff --git a/drivers/gpu/drm/i915/intel_crt.c b/drivers/gpu/drm/i915/intel_crt.c
> index 3fbb6fc..bd0cd68 100644
> --- a/drivers/gpu/drm/i915/intel_crt.c
> +++ b/drivers/gpu/drm/i915/intel_crt.c
> @@ -753,7 +753,6 @@ static const struct drm_connector_funcs intel_crt_connector_funcs = {
>  static const struct drm_connector_helper_funcs intel_crt_connector_helper_funcs = {
>  	.mode_valid = intel_crt_mode_valid,
>  	.get_modes = intel_crt_get_modes,
> -	.best_encoder = intel_best_encoder,
>  };
>  
>  static const struct drm_encoder_funcs intel_crt_enc_funcs = {
> diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
> index 2113f40..77026ce 100644
> --- a/drivers/gpu/drm/i915/intel_display.c
> +++ b/drivers/gpu/drm/i915/intel_display.c
> @@ -16113,14 +16113,6 @@ void intel_modeset_cleanup(struct drm_device *dev)
>  	intel_teardown_gmbus(dev);
>  }
>  
> -/*
> - * Return which encoder is currently attached for connector.
> - */
> -struct drm_encoder *intel_best_encoder(struct drm_connector *connector)
> -{
> -	return &intel_attached_encoder(connector)->base;
> -}
> -
>  void intel_connector_attach_encoder(struct intel_connector *connector,
>  				    struct intel_encoder *encoder)
>  {
> diff --git a/drivers/gpu/drm/i915/intel_dp.c b/drivers/gpu/drm/i915/intel_dp.c
> index f192f58..21b2833 100644
> --- a/drivers/gpu/drm/i915/intel_dp.c
> +++ b/drivers/gpu/drm/i915/intel_dp.c
> @@ -4935,7 +4935,6 @@ static const struct drm_connector_funcs intel_dp_connector_funcs = {
>  static const struct drm_connector_helper_funcs intel_dp_connector_helper_funcs = {
>  	.get_modes = intel_dp_get_modes,
>  	.mode_valid = intel_dp_mode_valid,
> -	.best_encoder = intel_best_encoder,
>  };
>  
>  static const struct drm_encoder_funcs intel_dp_enc_funcs = {
> diff --git a/drivers/gpu/drm/i915/intel_drv.h b/drivers/gpu/drm/i915/intel_drv.h
> index a28b4aa..79a4d6b 100644
> --- a/drivers/gpu/drm/i915/intel_drv.h
> +++ b/drivers/gpu/drm/i915/intel_drv.h
> @@ -1128,7 +1128,6 @@ struct intel_connector *intel_connector_alloc(void);
>  bool intel_connector_get_hw_state(struct intel_connector *connector);
>  void intel_connector_attach_encoder(struct intel_connector *connector,
>  				    struct intel_encoder *encoder);
> -struct drm_encoder *intel_best_encoder(struct drm_connector *connector);
>  struct drm_display_mode *intel_crtc_mode_get(struct drm_device *dev,
>  					     struct drm_crtc *crtc);
>  enum pipe intel_get_pipe_from_connector(struct intel_connector *connector);
> diff --git a/drivers/gpu/drm/i915/intel_dsi.c b/drivers/gpu/drm/i915/intel_dsi.c
> index 366ad6c..ec51952 100644
> --- a/drivers/gpu/drm/i915/intel_dsi.c
> +++ b/drivers/gpu/drm/i915/intel_dsi.c
> @@ -1378,7 +1378,6 @@ static const struct drm_encoder_funcs intel_dsi_funcs = {
>  static const struct drm_connector_helper_funcs intel_dsi_connector_helper_funcs = {
>  	.get_modes = intel_dsi_get_modes,
>  	.mode_valid = intel_dsi_mode_valid,
> -	.best_encoder = intel_best_encoder,
>  };
>  
>  static const struct drm_connector_funcs intel_dsi_connector_funcs = {
> diff --git a/drivers/gpu/drm/i915/intel_dvo.c b/drivers/gpu/drm/i915/intel_dvo.c
> index 286baec..34b7e3f 100644
> --- a/drivers/gpu/drm/i915/intel_dvo.c
> +++ b/drivers/gpu/drm/i915/intel_dvo.c
> @@ -351,7 +351,6 @@ static const struct drm_connector_funcs intel_dvo_connector_funcs = {
>  static const struct drm_connector_helper_funcs intel_dvo_connector_helper_funcs = {
>  	.mode_valid = intel_dvo_mode_valid,
>  	.get_modes = intel_dvo_get_modes,
> -	.best_encoder = intel_best_encoder,
>  };
>  
>  static void intel_dvo_enc_destroy(struct drm_encoder *encoder)
> diff --git a/drivers/gpu/drm/i915/intel_hdmi.c b/drivers/gpu/drm/i915/intel_hdmi.c
> index 2c3bd9c..aef4bc8 100644
> --- a/drivers/gpu/drm/i915/intel_hdmi.c
> +++ b/drivers/gpu/drm/i915/intel_hdmi.c
> @@ -2114,7 +2114,6 @@ static const struct drm_connector_funcs intel_hdmi_connector_funcs = {
>  static const struct drm_connector_helper_funcs intel_hdmi_connector_helper_funcs = {
>  	.get_modes = intel_hdmi_get_modes,
>  	.mode_valid = intel_hdmi_mode_valid,
> -	.best_encoder = intel_best_encoder,
>  };
>  
>  static const struct drm_encoder_funcs intel_hdmi_enc_funcs = {
> diff --git a/drivers/gpu/drm/i915/intel_lvds.c b/drivers/gpu/drm/i915/intel_lvds.c
> index bc53c0d..d4faa5a 100644
> --- a/drivers/gpu/drm/i915/intel_lvds.c
> +++ b/drivers/gpu/drm/i915/intel_lvds.c
> @@ -547,7 +547,6 @@ static int intel_lvds_set_property(struct drm_connector *connector,
>  static const struct drm_connector_helper_funcs intel_lvds_connector_helper_funcs = {
>  	.get_modes = intel_lvds_get_modes,
>  	.mode_valid = intel_lvds_mode_valid,
> -	.best_encoder = intel_best_encoder,
>  };
>  
>  static const struct drm_connector_funcs intel_lvds_connector_funcs = {
> diff --git a/drivers/gpu/drm/i915/intel_sdvo.c b/drivers/gpu/drm/i915/intel_sdvo.c
> index 2128fae..5cd48ff 100644
> --- a/drivers/gpu/drm/i915/intel_sdvo.c
> +++ b/drivers/gpu/drm/i915/intel_sdvo.c
> @@ -2191,7 +2191,6 @@ static const struct drm_connector_funcs intel_sdvo_connector_funcs = {
>  static const struct drm_connector_helper_funcs intel_sdvo_connector_helper_funcs = {
>  	.get_modes = intel_sdvo_get_modes,
>  	.mode_valid = intel_sdvo_mode_valid,
> -	.best_encoder = intel_best_encoder,
>  };
>  
>  static void intel_sdvo_enc_destroy(struct drm_encoder *encoder)
> diff --git a/drivers/gpu/drm/i915/intel_tv.c b/drivers/gpu/drm/i915/intel_tv.c
> index 223129d..47fe241 100644
> --- a/drivers/gpu/drm/i915/intel_tv.c
> +++ b/drivers/gpu/drm/i915/intel_tv.c
> @@ -1512,7 +1512,6 @@ static const struct drm_connector_funcs intel_tv_connector_funcs = {
>  static const struct drm_connector_helper_funcs intel_tv_connector_helper_funcs = {
>  	.mode_valid = intel_tv_mode_valid,
>  	.get_modes = intel_tv_get_modes,
> -	.best_encoder = intel_best_encoder,
>  };
>  
>  static const struct drm_encoder_funcs intel_tv_enc_funcs = {
> -- 
> 2.7.4
> 

-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch

^ permalink raw reply

* Re: [PATCH -next] virtio_net: Update the feature bit to comply with spec
From: David Miller @ 2016-06-10  6:35 UTC (permalink / raw)
  To: aconole; +Cc: netdev, virtualization, linux-kernel, mst
In-Reply-To: <1465494075-31170-1-git-send-email-aconole@redhat.com>

From: Aaron Conole <aconole@redhat.com>
Date: Thu,  9 Jun 2016 13:41:15 -0400

> A draft version of the MTU Advice feature bit was specified as 25.  This
> bit is not within the allowed range for network device feature bits, and
> should be changed to be feature bit 3 to fully comply with the spec.
> 
> Fixes 14de9d114a82 ('virtio-net: Add initial MTU advice feature')
> Signed-off-by: Aaron Conole <aconole@redhat.com>
> Suggested-by: "Michael S. Tsirkin" <mst@redhat.com>

Applied.

^ permalink raw reply

* [PATCH -next] virtio_net: Update the feature bit to comply with spec
From: Aaron Conole @ 2016-06-09 17:41 UTC (permalink / raw)
  To: netdev, Michael S. Tsirkin, virtualization, linux-kernel

A draft version of the MTU Advice feature bit was specified as 25.  This
bit is not within the allowed range for network device feature bits, and
should be changed to be feature bit 3 to fully comply with the spec.

Fixes 14de9d114a82 ('virtio-net: Add initial MTU advice feature')
Signed-off-by: Aaron Conole <aconole@redhat.com>
Suggested-by: "Michael S. Tsirkin" <mst@redhat.com>
---
 include/uapi/linux/virtio_net.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/uapi/linux/virtio_net.h b/include/uapi/linux/virtio_net.h
index 1ab4ea6..0da0e3a 100644
--- a/include/uapi/linux/virtio_net.h
+++ b/include/uapi/linux/virtio_net.h
@@ -35,6 +35,7 @@
 #define VIRTIO_NET_F_CSUM	0	/* Host handles pkts w/ partial csum */
 #define VIRTIO_NET_F_GUEST_CSUM	1	/* Guest handles pkts w/ partial csum */
 #define VIRTIO_NET_F_CTRL_GUEST_OFFLOADS 2 /* Dynamic offload configuration. */
+#define VIRTIO_NET_F_MTU	3	/* Initial MTU advice */
 #define VIRTIO_NET_F_MAC	5	/* Host has given MAC address. */
 #define VIRTIO_NET_F_GUEST_TSO4	7	/* Guest can handle TSOv4 in. */
 #define VIRTIO_NET_F_GUEST_TSO6	8	/* Guest can handle TSOv6 in. */
@@ -55,7 +56,6 @@
 #define VIRTIO_NET_F_MQ	22	/* Device supports Receive Flow
 					 * Steering */
 #define VIRTIO_NET_F_CTRL_MAC_ADDR 23	/* Set MAC address */
-#define VIRTIO_NET_F_MTU 25	/* Initial MTU advice */
 
 #ifndef VIRTIO_NET_NO_LEGACY
 #define VIRTIO_NET_F_GSO	6	/* Host handles pkts w/ any GSO type */
-- 
2.5.5

^ permalink raw reply related

* Re: [PATCH] macvtap: fix bugon.cocci warnings
From: Julia Lawall @ 2016-06-08 20:59 UTC (permalink / raw)
  To: David Miller; +Cc: julia.lawall, rppt, virtualization, netdev, mst
In-Reply-To: <20160608.113026.1097988313259161320.davem@davemloft.net>



On Wed, 8 Jun 2016, David Miller wrote:

> From: Julia Lawall <julia.lawall@lip6.fr>
> Date: Wed, 8 Jun 2016 18:15:29 +0200 (CEST)
> 
> >  Use BUG_ON instead of a if condition followed by BUG.
> > 
> > Generated by: scripts/coccinelle/misc/bugon.cocci
> > 
> > CC: Mike Rapoport <rppt@linux.vnet.ibm.com>
> > Signed-off-by: Julia Lawall <julia.lawall@lip6.fr>
> > Signed-off-by: Fengguang Wu <fengguang.wu@intel.com>
> 
> This doesn't apply cleanly to any of my trees.

Sorry not to have included the source information.  It seems to be from 
here:

https://github.com/0day-ci/linux/commits/Mike-Rapoport/virtio_net-add-_UAPI-prefix-to-virtio_net-header-guards/20160608-211558

julia

^ permalink raw reply

* Re: [PATCH] macvtap: fix bugon.cocci warnings
From: David Miller @ 2016-06-08 18:30 UTC (permalink / raw)
  To: julia.lawall; +Cc: netdev, rppt, virtualization, mst
In-Reply-To: <alpine.DEB.2.10.1606081814180.2890@hadrien>

From: Julia Lawall <julia.lawall@lip6.fr>
Date: Wed, 8 Jun 2016 18:15:29 +0200 (CEST)

>  Use BUG_ON instead of a if condition followed by BUG.
> 
> Generated by: scripts/coccinelle/misc/bugon.cocci
> 
> CC: Mike Rapoport <rppt@linux.vnet.ibm.com>
> Signed-off-by: Julia Lawall <julia.lawall@lip6.fr>
> Signed-off-by: Fengguang Wu <fengguang.wu@intel.com>

This doesn't apply cleanly to any of my trees.

^ permalink raw reply

* [PATCH] macvtap: fix bugon.cocci warnings
From: Julia Lawall @ 2016-06-08 16:15 UTC (permalink / raw)
  To: Mike Rapoport; +Cc: netdev, virtualization, Michael S. Tsirkin

 Use BUG_ON instead of a if condition followed by BUG.

Generated by: scripts/coccinelle/misc/bugon.cocci

CC: Mike Rapoport <rppt@linux.vnet.ibm.com>
Signed-off-by: Julia Lawall <julia.lawall@lip6.fr>
Signed-off-by: Fengguang Wu <fengguang.wu@intel.com>
---

 macvtap.c |    3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

--- a/drivers/net/macvtap.c
+++ b/drivers/net/macvtap.c
@@ -796,8 +796,7 @@ static ssize_t macvtap_put_user(struct m

 		ret = virtio_net_hdr_from_skb(skb, &vnet_hdr,
 					      macvtap_is_little_endian(q));
-		if (ret)
-			BUG();
+		BUG_ON(ret);

 		if (copy_to_iter(&vnet_hdr, sizeof(vnet_hdr), iter) !=
 		    sizeof(vnet_hdr))

^ permalink raw reply

* [PATCH 6/6] packet: use common code for virtio_net_hdr and skb GSO conversion
From: Mike Rapoport @ 2016-06-08 13:09 UTC (permalink / raw)
  To: Michael S. Tsirkin; +Cc: netdev, Mike Rapoport, linux-kernel, virtualization
In-Reply-To: <1465391362-18437-1-git-send-email-rppt@linux.vnet.ibm.com>

Replace open coded conversion between virtio_net_hdr to skb GSO info with
virtio_net_hdr_from_skb

Signed-off-by: Mike Rapoport <rppt@linux.vnet.ibm.com>
---
 net/packet/af_packet.c | 36 ++----------------------------------
 1 file changed, 2 insertions(+), 34 deletions(-)

diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
index 4040eb9..ec35aa9 100644
--- a/net/packet/af_packet.c
+++ b/net/packet/af_packet.c
@@ -1978,40 +1978,8 @@ static int __packet_rcv_vnet(const struct sk_buff *skb,
 {
 	*vnet_hdr = (const struct virtio_net_hdr) { 0 };
 
-	if (skb_is_gso(skb)) {
-		struct skb_shared_info *sinfo = skb_shinfo(skb);
-
-		/* This is a hint as to how much should be linear. */
-		vnet_hdr->hdr_len =
-			__cpu_to_virtio16(vio_le(), skb_headlen(skb));
-		vnet_hdr->gso_size =
-			__cpu_to_virtio16(vio_le(), sinfo->gso_size);
-
-		if (sinfo->gso_type & SKB_GSO_TCPV4)
-			vnet_hdr->gso_type = VIRTIO_NET_HDR_GSO_TCPV4;
-		else if (sinfo->gso_type & SKB_GSO_TCPV6)
-			vnet_hdr->gso_type = VIRTIO_NET_HDR_GSO_TCPV6;
-		else if (sinfo->gso_type & SKB_GSO_UDP)
-			vnet_hdr->gso_type = VIRTIO_NET_HDR_GSO_UDP;
-		else if (sinfo->gso_type & SKB_GSO_FCOE)
-			return -EINVAL;
-		else
-			BUG();
-
-		if (sinfo->gso_type & SKB_GSO_TCP_ECN)
-			vnet_hdr->gso_type |= VIRTIO_NET_HDR_GSO_ECN;
-	} else
-		vnet_hdr->gso_type = VIRTIO_NET_HDR_GSO_NONE;
-
-	if (skb->ip_summed == CHECKSUM_PARTIAL) {
-		vnet_hdr->flags = VIRTIO_NET_HDR_F_NEEDS_CSUM;
-		vnet_hdr->csum_start = __cpu_to_virtio16(vio_le(),
-				  skb_checksum_start_offset(skb));
-		vnet_hdr->csum_offset = __cpu_to_virtio16(vio_le(),
-						 skb->csum_offset);
-	} else if (skb->ip_summed == CHECKSUM_UNNECESSARY) {
-		vnet_hdr->flags = VIRTIO_NET_HDR_F_DATA_VALID;
-	} /* else everything is zero */
+	if (virtio_net_hdr_from_skb(skb, vnet_hdr, vio_le()))
+		BUG();
 
 	return 0;
 }
-- 
1.9.1

^ permalink raw reply related

* [PATCH 5/6] virtio_net: use common code for virtio_net_hdr and skb GSO conversion
From: Mike Rapoport @ 2016-06-08 13:09 UTC (permalink / raw)
  To: Michael S. Tsirkin; +Cc: netdev, Mike Rapoport, linux-kernel, virtualization
In-Reply-To: <1465391362-18437-1-git-send-email-rppt@linux.vnet.ibm.com>

Replace open coded conversion between virtio_net_hdr to skb GSO info with
virtio_net_hdr_{from,to}_skb

Signed-off-by: Mike Rapoport <rppt@linux.vnet.ibm.com>
---
 drivers/net/virtio_net.c | 78 +++++++-----------------------------------------
 1 file changed, 10 insertions(+), 68 deletions(-)

diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
index e0638e5..9af0a98 100644
--- a/drivers/net/virtio_net.c
+++ b/drivers/net/virtio_net.c
@@ -479,51 +479,19 @@ static void receive_buf(struct virtnet_info *vi, struct receive_queue *rq,
 	stats->rx_packets++;
 	u64_stats_update_end(&stats->rx_syncp);
 
-	if (hdr->hdr.flags & VIRTIO_NET_HDR_F_NEEDS_CSUM) {
-		pr_debug("Needs csum!\n");
-		if (!skb_partial_csum_set(skb,
-			  virtio16_to_cpu(vi->vdev, hdr->hdr.csum_start),
-			  virtio16_to_cpu(vi->vdev, hdr->hdr.csum_offset)))
-			goto frame_err;
-	} else if (hdr->hdr.flags & VIRTIO_NET_HDR_F_DATA_VALID) {
+	if (hdr->hdr.flags & VIRTIO_NET_HDR_F_DATA_VALID)
 		skb->ip_summed = CHECKSUM_UNNECESSARY;
-	}
 
 	skb->protocol = eth_type_trans(skb, dev);
 	pr_debug("Receiving skb proto 0x%04x len %i type %i\n",
 		 ntohs(skb->protocol), skb->len, skb->pkt_type);
 
-	if (hdr->hdr.gso_type != VIRTIO_NET_HDR_GSO_NONE) {
-		pr_debug("GSO!\n");
-		switch (hdr->hdr.gso_type & ~VIRTIO_NET_HDR_GSO_ECN) {
-		case VIRTIO_NET_HDR_GSO_TCPV4:
-			skb_shinfo(skb)->gso_type = SKB_GSO_TCPV4;
-			break;
-		case VIRTIO_NET_HDR_GSO_UDP:
-			skb_shinfo(skb)->gso_type = SKB_GSO_UDP;
-			break;
-		case VIRTIO_NET_HDR_GSO_TCPV6:
-			skb_shinfo(skb)->gso_type = SKB_GSO_TCPV6;
-			break;
-		default:
-			net_warn_ratelimited("%s: bad gso type %u.\n",
-					     dev->name, hdr->hdr.gso_type);
-			goto frame_err;
-		}
-
-		if (hdr->hdr.gso_type & VIRTIO_NET_HDR_GSO_ECN)
-			skb_shinfo(skb)->gso_type |= SKB_GSO_TCP_ECN;
-
-		skb_shinfo(skb)->gso_size = virtio16_to_cpu(vi->vdev,
-							    hdr->hdr.gso_size);
-		if (skb_shinfo(skb)->gso_size == 0) {
-			net_warn_ratelimited("%s: zero gso size.\n", dev->name);
-			goto frame_err;
-		}
-
-		/* Header must be checked, and gso_segs computed. */
-		skb_shinfo(skb)->gso_type |= SKB_GSO_DODGY;
-		skb_shinfo(skb)->gso_segs = 0;
+	if (virtio_net_hdr_to_skb(skb, &hdr->hdr,
+				  virtio_is_little_endian(vi->vdev))) {
+		net_warn_ratelimited("%s: bad gso: type: %u, size: %u\n",
+				     dev->name, hdr->hdr.gso_type,
+				     hdr->hdr.gso_size);
+		goto frame_err;
 	}
 
 	napi_gro_receive(&rq->napi, skb);
@@ -868,35 +836,9 @@ static int xmit_skb(struct send_queue *sq, struct sk_buff *skb)
 	else
 		hdr = skb_vnet_hdr(skb);
 
-	if (skb->ip_summed == CHECKSUM_PARTIAL) {
-		hdr->hdr.flags = VIRTIO_NET_HDR_F_NEEDS_CSUM;
-		hdr->hdr.csum_start = cpu_to_virtio16(vi->vdev,
-						skb_checksum_start_offset(skb));
-		hdr->hdr.csum_offset = cpu_to_virtio16(vi->vdev,
-							 skb->csum_offset);
-	} else {
-		hdr->hdr.flags = 0;
-		hdr->hdr.csum_offset = hdr->hdr.csum_start = 0;
-	}
-
-	if (skb_is_gso(skb)) {
-		hdr->hdr.hdr_len = cpu_to_virtio16(vi->vdev, skb_headlen(skb));
-		hdr->hdr.gso_size = cpu_to_virtio16(vi->vdev,
-						    skb_shinfo(skb)->gso_size);
-		if (skb_shinfo(skb)->gso_type & SKB_GSO_TCPV4)
-			hdr->hdr.gso_type = VIRTIO_NET_HDR_GSO_TCPV4;
-		else if (skb_shinfo(skb)->gso_type & SKB_GSO_TCPV6)
-			hdr->hdr.gso_type = VIRTIO_NET_HDR_GSO_TCPV6;
-		else if (skb_shinfo(skb)->gso_type & SKB_GSO_UDP)
-			hdr->hdr.gso_type = VIRTIO_NET_HDR_GSO_UDP;
-		else
-			BUG();
-		if (skb_shinfo(skb)->gso_type & SKB_GSO_TCP_ECN)
-			hdr->hdr.gso_type |= VIRTIO_NET_HDR_GSO_ECN;
-	} else {
-		hdr->hdr.gso_type = VIRTIO_NET_HDR_GSO_NONE;
-		hdr->hdr.gso_size = hdr->hdr.hdr_len = 0;
-	}
+	if (virtio_net_hdr_from_skb(skb, &hdr->hdr,
+				    virtio_is_little_endian(vi->vdev)))
+		BUG();
 
 	if (vi->mergeable_rx_bufs)
 		hdr->num_buffers = 0;
-- 
1.9.1

^ permalink raw reply related

* [PATCH 4/6] tuntap: use common code for virtio_net_hdr and skb GSO conversion
From: Mike Rapoport @ 2016-06-08 13:09 UTC (permalink / raw)
  To: Michael S. Tsirkin; +Cc: netdev, Mike Rapoport, linux-kernel, virtualization
In-Reply-To: <1465391362-18437-1-git-send-email-rppt@linux.vnet.ibm.com>

Replace open coded conversion between virtio_net_hdr to skb GSO info with
virtio_net_hdr_{from,to}_skb

Signed-off-by: Mike Rapoport <rppt@linux.vnet.ibm.com>
---
 drivers/net/tun.c | 97 ++++++++++++-------------------------------------------
 1 file changed, 21 insertions(+), 76 deletions(-)

diff --git a/drivers/net/tun.c b/drivers/net/tun.c
index e16487c..8cc6bf4 100644
--- a/drivers/net/tun.c
+++ b/drivers/net/tun.c
@@ -1254,15 +1254,6 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile,
 		return -EFAULT;
 	}
 
-	if (gso.flags & VIRTIO_NET_HDR_F_NEEDS_CSUM) {
-		if (!skb_partial_csum_set(skb, tun16_to_cpu(tun, gso.csum_start),
-					  tun16_to_cpu(tun, gso.csum_offset))) {
-			this_cpu_inc(tun->pcpu_stats->rx_frame_errors);
-			kfree_skb(skb);
-			return -EINVAL;
-		}
-	}
-
 	switch (tun->flags & TUN_TYPE_MASK) {
 	case IFF_TUN:
 		if (tun->flags & IFF_NO_PI) {
@@ -1289,37 +1280,11 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile,
 		break;
 	}
 
-	if (gso.gso_type != VIRTIO_NET_HDR_GSO_NONE) {
-		pr_debug("GSO!\n");
-		switch (gso.gso_type & ~VIRTIO_NET_HDR_GSO_ECN) {
-		case VIRTIO_NET_HDR_GSO_TCPV4:
-			skb_shinfo(skb)->gso_type = SKB_GSO_TCPV4;
-			break;
-		case VIRTIO_NET_HDR_GSO_TCPV6:
-			skb_shinfo(skb)->gso_type = SKB_GSO_TCPV6;
-			break;
-		case VIRTIO_NET_HDR_GSO_UDP:
-			skb_shinfo(skb)->gso_type = SKB_GSO_UDP;
-			break;
-		default:
-			this_cpu_inc(tun->pcpu_stats->rx_frame_errors);
-			kfree_skb(skb);
-			return -EINVAL;
-		}
-
-		if (gso.gso_type & VIRTIO_NET_HDR_GSO_ECN)
-			skb_shinfo(skb)->gso_type |= SKB_GSO_TCP_ECN;
-
-		skb_shinfo(skb)->gso_size = tun16_to_cpu(tun, gso.gso_size);
-		if (skb_shinfo(skb)->gso_size == 0) {
-			this_cpu_inc(tun->pcpu_stats->rx_frame_errors);
-			kfree_skb(skb);
-			return -EINVAL;
-		}
-
-		/* Header must be checked, and gso_segs computed. */
-		skb_shinfo(skb)->gso_type |= SKB_GSO_DODGY;
-		skb_shinfo(skb)->gso_segs = 0;
+	err = virtio_net_hdr_to_skb(skb, &gso, tun_is_little_endian(tun));
+	if (err) {
+		this_cpu_inc(tun->pcpu_stats->rx_frame_errors);
+		kfree_skb(skb);
+		return -EINVAL;
 	}
 
 	/* copy skb_ubuf_info for callback when skb has no error */
@@ -1399,46 +1364,26 @@ static ssize_t tun_put_user(struct tun_struct *tun,
 
 	if (vnet_hdr_sz) {
 		struct virtio_net_hdr gso = { 0 }; /* no info leak */
+		int ret;
+
 		if (iov_iter_count(iter) < vnet_hdr_sz)
 			return -EINVAL;
 
-		if (skb_is_gso(skb)) {
+		ret = virtio_net_hdr_from_skb(skb, &gso,
+					      tun_is_little_endian(tun));
+		if (ret) {
 			struct skb_shared_info *sinfo = skb_shinfo(skb);
-
-			/* This is a hint as to how much should be linear. */
-			gso.hdr_len = cpu_to_tun16(tun, skb_headlen(skb));
-			gso.gso_size = cpu_to_tun16(tun, sinfo->gso_size);
-			if (sinfo->gso_type & SKB_GSO_TCPV4)
-				gso.gso_type = VIRTIO_NET_HDR_GSO_TCPV4;
-			else if (sinfo->gso_type & SKB_GSO_TCPV6)
-				gso.gso_type = VIRTIO_NET_HDR_GSO_TCPV6;
-			else if (sinfo->gso_type & SKB_GSO_UDP)
-				gso.gso_type = VIRTIO_NET_HDR_GSO_UDP;
-			else {
-				pr_err("unexpected GSO type: "
-				       "0x%x, gso_size %d, hdr_len %d\n",
-				       sinfo->gso_type, tun16_to_cpu(tun, gso.gso_size),
-				       tun16_to_cpu(tun, gso.hdr_len));
-				print_hex_dump(KERN_ERR, "tun: ",
-					       DUMP_PREFIX_NONE,
-					       16, 1, skb->head,
-					       min((int)tun16_to_cpu(tun, gso.hdr_len), 64), true);
-				WARN_ON_ONCE(1);
-				return -EINVAL;
-			}
-			if (sinfo->gso_type & SKB_GSO_TCP_ECN)
-				gso.gso_type |= VIRTIO_NET_HDR_GSO_ECN;
-		} else
-			gso.gso_type = VIRTIO_NET_HDR_GSO_NONE;
-
-		if (skb->ip_summed == CHECKSUM_PARTIAL) {
-			gso.flags = VIRTIO_NET_HDR_F_NEEDS_CSUM;
-			gso.csum_start = cpu_to_tun16(tun, skb_checksum_start_offset(skb) +
-						      vlan_hlen);
-			gso.csum_offset = cpu_to_tun16(tun, skb->csum_offset);
-		} else if (skb->ip_summed == CHECKSUM_UNNECESSARY) {
-			gso.flags = VIRTIO_NET_HDR_F_DATA_VALID;
-		} /* else everything is zero */
+			pr_err("unexpected GSO type: "
+			       "0x%x, gso_size %d, hdr_len %d\n",
+			       sinfo->gso_type, tun16_to_cpu(tun, gso.gso_size),
+			       tun16_to_cpu(tun, gso.hdr_len));
+			print_hex_dump(KERN_ERR, "tun: ",
+				       DUMP_PREFIX_NONE,
+				       16, 1, skb->head,
+				       min((int)tun16_to_cpu(tun, gso.hdr_len), 64), true);
+			WARN_ON_ONCE(1);
+			return -EINVAL;
+		}
 
 		if (copy_to_iter(&gso, sizeof(gso), iter) != sizeof(gso))
 			return -EFAULT;
-- 
1.9.1

^ permalink raw reply related

* [PATCH 3/6] macvtap: use common code for virtio_net_hdr and skb GSO conversion
From: Mike Rapoport @ 2016-06-08 13:09 UTC (permalink / raw)
  To: Michael S. Tsirkin; +Cc: netdev, Mike Rapoport, linux-kernel, virtualization
In-Reply-To: <1465391362-18437-1-git-send-email-rppt@linux.vnet.ibm.com>

Replace open coded conversion between virtio_net_hdr to skb GSO info with
virtio_net_hdr_{from,to}_skb

Signed-off-by: Mike Rapoport <rppt@linux.vnet.ibm.com>
---
 drivers/net/macvtap.c | 95 ++++-----------------------------------------------
 1 file changed, 6 insertions(+), 89 deletions(-)

diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
index bd67209..95a1332 100644
--- a/drivers/net/macvtap.c
+++ b/drivers/net/macvtap.c
@@ -627,93 +627,6 @@ static inline struct sk_buff *macvtap_alloc_skb(struct sock *sk, size_t prepad,
 	return skb;
 }
 
-/*
- * macvtap_skb_from_vnet_hdr and macvtap_skb_to_vnet_hdr should
- * be shared with the tun/tap driver.
- */
-static int macvtap_skb_from_vnet_hdr(struct macvtap_queue *q,
-				     struct sk_buff *skb,
-				     struct virtio_net_hdr *vnet_hdr)
-{
-	unsigned short gso_type = 0;
-	if (vnet_hdr->gso_type != VIRTIO_NET_HDR_GSO_NONE) {
-		switch (vnet_hdr->gso_type & ~VIRTIO_NET_HDR_GSO_ECN) {
-		case VIRTIO_NET_HDR_GSO_TCPV4:
-			gso_type = SKB_GSO_TCPV4;
-			break;
-		case VIRTIO_NET_HDR_GSO_TCPV6:
-			gso_type = SKB_GSO_TCPV6;
-			break;
-		case VIRTIO_NET_HDR_GSO_UDP:
-			gso_type = SKB_GSO_UDP;
-			break;
-		default:
-			return -EINVAL;
-		}
-
-		if (vnet_hdr->gso_type & VIRTIO_NET_HDR_GSO_ECN)
-			gso_type |= SKB_GSO_TCP_ECN;
-
-		if (vnet_hdr->gso_size == 0)
-			return -EINVAL;
-	}
-
-	if (vnet_hdr->flags & VIRTIO_NET_HDR_F_NEEDS_CSUM) {
-		if (!skb_partial_csum_set(skb, macvtap16_to_cpu(q, vnet_hdr->csum_start),
-					  macvtap16_to_cpu(q, vnet_hdr->csum_offset)))
-			return -EINVAL;
-	}
-
-	if (vnet_hdr->gso_type != VIRTIO_NET_HDR_GSO_NONE) {
-		skb_shinfo(skb)->gso_size = macvtap16_to_cpu(q, vnet_hdr->gso_size);
-		skb_shinfo(skb)->gso_type = gso_type;
-
-		/* Header must be checked, and gso_segs computed. */
-		skb_shinfo(skb)->gso_type |= SKB_GSO_DODGY;
-		skb_shinfo(skb)->gso_segs = 0;
-	}
-	return 0;
-}
-
-static void macvtap_skb_to_vnet_hdr(struct macvtap_queue *q,
-				    const struct sk_buff *skb,
-				    struct virtio_net_hdr *vnet_hdr)
-{
-	memset(vnet_hdr, 0, sizeof(*vnet_hdr));
-
-	if (skb_is_gso(skb)) {
-		struct skb_shared_info *sinfo = skb_shinfo(skb);
-
-		/* This is a hint as to how much should be linear. */
-		vnet_hdr->hdr_len = cpu_to_macvtap16(q, skb_headlen(skb));
-		vnet_hdr->gso_size = cpu_to_macvtap16(q, sinfo->gso_size);
-		if (sinfo->gso_type & SKB_GSO_TCPV4)
-			vnet_hdr->gso_type = VIRTIO_NET_HDR_GSO_TCPV4;
-		else if (sinfo->gso_type & SKB_GSO_TCPV6)
-			vnet_hdr->gso_type = VIRTIO_NET_HDR_GSO_TCPV6;
-		else if (sinfo->gso_type & SKB_GSO_UDP)
-			vnet_hdr->gso_type = VIRTIO_NET_HDR_GSO_UDP;
-		else
-			BUG();
-		if (sinfo->gso_type & SKB_GSO_TCP_ECN)
-			vnet_hdr->gso_type |= VIRTIO_NET_HDR_GSO_ECN;
-	} else
-		vnet_hdr->gso_type = VIRTIO_NET_HDR_GSO_NONE;
-
-	if (skb->ip_summed == CHECKSUM_PARTIAL) {
-		vnet_hdr->flags = VIRTIO_NET_HDR_F_NEEDS_CSUM;
-		if (skb_vlan_tag_present(skb))
-			vnet_hdr->csum_start = cpu_to_macvtap16(q,
-				skb_checksum_start_offset(skb) + VLAN_HLEN);
-		else
-			vnet_hdr->csum_start = cpu_to_macvtap16(q,
-				skb_checksum_start_offset(skb));
-		vnet_hdr->csum_offset = cpu_to_macvtap16(q, skb->csum_offset);
-	} else if (skb->ip_summed == CHECKSUM_UNNECESSARY) {
-		vnet_hdr->flags = VIRTIO_NET_HDR_F_DATA_VALID;
-	} /* else everything is zero */
-}
-
 /* Neighbour code has some assumptions on HH_DATA_MOD alignment */
 #define MACVTAP_RESERVE HH_DATA_OFF(ETH_HLEN)
 
@@ -812,7 +725,8 @@ static ssize_t macvtap_get_user(struct macvtap_queue *q, struct msghdr *m,
 	skb->protocol = eth_hdr(skb)->h_proto;
 
 	if (vnet_hdr_len) {
-		err = macvtap_skb_from_vnet_hdr(q, skb, &vnet_hdr);
+		err = virtio_net_hdr_to_skb(skb, &vnet_hdr,
+					    macvtap_is_little_endian(q));
 		if (err)
 			goto err_kfree;
 	}
@@ -880,7 +794,10 @@ static ssize_t macvtap_put_user(struct macvtap_queue *q,
 		if (iov_iter_count(iter) < vnet_hdr_len)
 			return -EINVAL;
 
-		macvtap_skb_to_vnet_hdr(q, skb, &vnet_hdr);
+		ret = virtio_net_hdr_from_skb(skb, &vnet_hdr,
+					      macvtap_is_little_endian(q));
+		if (ret)
+			BUG();
 
 		if (copy_to_iter(&vnet_hdr, sizeof(vnet_hdr), iter) !=
 		    sizeof(vnet_hdr))
-- 
1.9.1

^ permalink raw reply related

* [PATCH 2/6] virtio_net: introduce virtio_net_hdr_{from,to}_skb
From: Mike Rapoport @ 2016-06-08 13:09 UTC (permalink / raw)
  To: Michael S. Tsirkin; +Cc: netdev, Mike Rapoport, linux-kernel, virtualization
In-Reply-To: <1465391362-18437-1-git-send-email-rppt@linux.vnet.ibm.com>

The code for conversion between virtio_net_hdr and skb GSO info is
duplicated at several places. Let's put it to a common place to allow
reuse.

Signed-off-by: Mike Rapoport <rppt@linux.vnet.ibm.com>
---
 include/linux/virtio_net.h | 101 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 101 insertions(+)
 create mode 100644 include/linux/virtio_net.h

diff --git a/include/linux/virtio_net.h b/include/linux/virtio_net.h
new file mode 100644
index 0000000..1c912f8
--- /dev/null
+++ b/include/linux/virtio_net.h
@@ -0,0 +1,101 @@
+#ifndef _LINUX_VIRTIO_NET_H
+#define _LINUX_VIRTIO_NET_H
+
+#include <linux/if_vlan.h>
+#include <uapi/linux/virtio_net.h>
+
+static inline int virtio_net_hdr_to_skb(struct sk_buff *skb,
+					const struct virtio_net_hdr *hdr,
+					bool little_endian)
+{
+	unsigned short gso_type = 0;
+
+	if (hdr->gso_type != VIRTIO_NET_HDR_GSO_NONE) {
+		switch (hdr->gso_type & ~VIRTIO_NET_HDR_GSO_ECN) {
+		case VIRTIO_NET_HDR_GSO_TCPV4:
+			gso_type = SKB_GSO_TCPV4;
+			break;
+		case VIRTIO_NET_HDR_GSO_TCPV6:
+			gso_type = SKB_GSO_TCPV6;
+			break;
+		case VIRTIO_NET_HDR_GSO_UDP:
+			gso_type = SKB_GSO_UDP;
+			break;
+		default:
+			return -EINVAL;
+		}
+
+		if (hdr->gso_type & VIRTIO_NET_HDR_GSO_ECN)
+			gso_type |= SKB_GSO_TCP_ECN;
+
+		if (hdr->gso_size == 0)
+			return -EINVAL;
+	}
+
+	if (hdr->flags & VIRTIO_NET_HDR_F_NEEDS_CSUM) {
+		u16 start = __virtio16_to_cpu(little_endian, hdr->csum_start);
+		u16 off = __virtio16_to_cpu(little_endian, hdr->csum_offset);
+
+		if (!skb_partial_csum_set(skb, start, off))
+			return -EINVAL;
+	}
+
+	if (hdr->gso_type != VIRTIO_NET_HDR_GSO_NONE) {
+		u16 gso_size = __virtio16_to_cpu(little_endian, hdr->gso_size);
+
+		skb_shinfo(skb)->gso_size = gso_size;
+		skb_shinfo(skb)->gso_type = gso_type;
+
+		/* Header must be checked, and gso_segs computed. */
+		skb_shinfo(skb)->gso_type |= SKB_GSO_DODGY;
+		skb_shinfo(skb)->gso_segs = 0;
+	}
+
+	return 0;
+}
+
+static inline int virtio_net_hdr_from_skb(const struct sk_buff *skb,
+					  struct virtio_net_hdr *hdr,
+					  bool little_endian)
+{
+	memset(hdr, 0, sizeof(*hdr));
+
+	if (skb_is_gso(skb)) {
+		struct skb_shared_info *sinfo = skb_shinfo(skb);
+
+		/* This is a hint as to how much should be linear. */
+		hdr->hdr_len = __cpu_to_virtio16(little_endian,
+						 skb_headlen(skb));
+		hdr->gso_size = __cpu_to_virtio16(little_endian,
+						  sinfo->gso_size);
+		if (sinfo->gso_type & SKB_GSO_TCPV4)
+			hdr->gso_type = VIRTIO_NET_HDR_GSO_TCPV4;
+		else if (sinfo->gso_type & SKB_GSO_TCPV6)
+			hdr->gso_type = VIRTIO_NET_HDR_GSO_TCPV6;
+		else if (sinfo->gso_type & SKB_GSO_UDP)
+			hdr->gso_type = VIRTIO_NET_HDR_GSO_UDP;
+		else
+			return -EINVAL;
+		if (sinfo->gso_type & SKB_GSO_TCP_ECN)
+			hdr->gso_type |= VIRTIO_NET_HDR_GSO_ECN;
+	} else
+		hdr->gso_type = VIRTIO_NET_HDR_GSO_NONE;
+
+	if (skb->ip_summed == CHECKSUM_PARTIAL) {
+		hdr->flags = VIRTIO_NET_HDR_F_NEEDS_CSUM;
+		if (skb_vlan_tag_present(skb))
+			hdr->csum_start = __cpu_to_virtio16(little_endian,
+				skb_checksum_start_offset(skb) + VLAN_HLEN);
+		else
+			hdr->csum_start = __cpu_to_virtio16(little_endian,
+				skb_checksum_start_offset(skb));
+		hdr->csum_offset = __cpu_to_virtio16(little_endian,
+				skb->csum_offset);
+	} else if (skb->ip_summed == CHECKSUM_UNNECESSARY) {
+		hdr->flags = VIRTIO_NET_HDR_F_DATA_VALID;
+	} /* else everything is zero */
+
+	return 0;
+}
+
+#endif /* _LINUX_VIRTIO_BYTEORDER */
-- 
1.9.1

^ permalink raw reply related

* [PATCH 1/6] virtio_net: add _UAPI prefix to virtio_net header guards
From: Mike Rapoport @ 2016-06-08 13:09 UTC (permalink / raw)
  To: Michael S. Tsirkin; +Cc: netdev, Mike Rapoport, linux-kernel, virtualization
In-Reply-To: <1465391362-18437-1-git-send-email-rppt@linux.vnet.ibm.com>

This gives better namespacing and prevents conflicts with no-uapi version
of virtio_net header that will be introduced in the following patch.

Signed-off-by: Mike Rapoport <rppt@linux.vnet.ibm.com>
---
 include/uapi/linux/virtio_net.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/include/uapi/linux/virtio_net.h b/include/uapi/linux/virtio_net.h
index ec32293..75cf581 100644
--- a/include/uapi/linux/virtio_net.h
+++ b/include/uapi/linux/virtio_net.h
@@ -1,5 +1,5 @@
-#ifndef _LINUX_VIRTIO_NET_H
-#define _LINUX_VIRTIO_NET_H
+#ifndef _UAPI_LINUX_VIRTIO_NET_H
+#define _UAPI_LINUX_VIRTIO_NET_H
 /* This header is BSD licensed so anyone can use the definitions to implement
  * compatible drivers/servers.
  *
@@ -242,4 +242,4 @@ struct virtio_net_ctrl_mq {
 #define VIRTIO_NET_CTRL_GUEST_OFFLOADS   5
 #define VIRTIO_NET_CTRL_GUEST_OFFLOADS_SET        0
 
-#endif /* _LINUX_VIRTIO_NET_H */
+#endif /* _UAPI_LINUX_VIRTIO_NET_H */
-- 
1.9.1

^ permalink raw reply related

* [PATCH 0/6] virtio_net: use common code for virtio_net_hdr and skb GSO conversion
From: Mike Rapoport @ 2016-06-08 13:09 UTC (permalink / raw)
  To: Michael S. Tsirkin; +Cc: netdev, Mike Rapoport, linux-kernel, virtualization

Hi,

This patches introduce virtio_net_hdr_{from,to}_skb functions for
conversion of GSO information between skb and virtio_net_hdr.

Mike Rapoport (6):
  virtio_net: add _UAPI prefix to virtio_net header guards
  virtio_net: introduce virtio_net_hdr_{from,to}_skb
  macvtap: use common code for virtio_net_hdr and skb GSO conversion
  tuntap: use common code for virtio_net_hdr and skb GSO conversion
  virtio_net: use common code for virtio_net_hdr and skb GSO conversion
  packet: use common code for virtio_net_hdr and skb GSO conversion

 drivers/net/macvtap.c           |  95 +++----------------------------------
 drivers/net/tun.c               |  97 +++++++++-----------------------------
 drivers/net/virtio_net.c        |  78 ++++---------------------------
 include/linux/virtio_net.h      | 101 ++++++++++++++++++++++++++++++++++++++++
 include/uapi/linux/virtio_net.h |   6 +--
 net/packet/af_packet.c          |  36 +-------------
 6 files changed, 143 insertions(+), 270 deletions(-)
 create mode 100644 include/linux/virtio_net.h

-- 
1.9.1

^ permalink raw reply

* Re: [PATCH v2 07/20] drm: mediatek: Rely on the default ->best_encoder() behavior
From: Matthias Brugger @ 2016-06-08 11:17 UTC (permalink / raw)
  To: Boris Brezillon, David Airlie, Daniel Vetter, dri-devel,
	Daniel Vetter
  Cc: Krzysztof Kozlowski, Heiko Stuebner, Stefan Agner, virtualization,
	Eric Anholt, Thierry Reding, Laurent Pinchart, Benjamin Gaignard,
	Alexandre Courbot, linux-samsung-soc, Joonyoung Shim,
	Alexey Brodkin, Kyungmin Park, linux-rockchip, Chen-Yu Tsai,
	Kukjin Kim, Stephen Warren, linux-arm-msm, intel-gfx, Jani Nikula,
	Inki Dae, linux-mediatek, linux-tegra, Vincent
In-Reply-To: <1465300095-16971-8-git-send-email-boris.brezillon@free-electrons.com>



On 07/06/16 13:48, Boris Brezillon wrote:
> We have a 1:1 relationship between connectors and encoders and the
> driver is relying on the atomic helpers: we can drop the custom
> ->best_encoder() implementation and let the core call
> drm_atomic_helper_best_encoder() for us.
>
> Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>

Reviewed-by: Matthias Brugger <matthias.bgg@gmail.com>

> ---
>   drivers/gpu/drm/mediatek/mtk_dsi.c | 9 ---------
>   1 file changed, 9 deletions(-)
>
> diff --git a/drivers/gpu/drm/mediatek/mtk_dsi.c b/drivers/gpu/drm/mediatek/mtk_dsi.c
> index 2d808e5..7343ffc 100644
> --- a/drivers/gpu/drm/mediatek/mtk_dsi.c
> +++ b/drivers/gpu/drm/mediatek/mtk_dsi.c
> @@ -575,14 +575,6 @@ static int mtk_dsi_connector_get_modes(struct drm_connector *connector)
>   	return drm_panel_get_modes(dsi->panel);
>   }
>
> -static struct drm_encoder *mtk_dsi_connector_best_encoder(
> -		struct drm_connector *connector)
> -{
> -	struct mtk_dsi *dsi = connector_to_dsi(connector);
> -
> -	return &dsi->encoder;
> -}
> -
>   static const struct drm_encoder_helper_funcs mtk_dsi_encoder_helper_funcs = {
>   	.mode_fixup = mtk_dsi_encoder_mode_fixup,
>   	.mode_set = mtk_dsi_encoder_mode_set,
> @@ -603,7 +595,6 @@ static const struct drm_connector_funcs mtk_dsi_connector_funcs = {
>   static const struct drm_connector_helper_funcs
>   	mtk_dsi_connector_helper_funcs = {
>   	.get_modes = mtk_dsi_connector_get_modes,
> -	.best_encoder = mtk_dsi_connector_best_encoder,
>   };
>
>   static int mtk_drm_attach_bridge(struct drm_bridge *bridge,
>

^ permalink raw reply


This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox