Netdev List
 help / color / mirror / Atom feed
* Re: [PATCH v3] tun: fix use-after-free when register netdev failed
From: Jason Wang @ 2019-09-10  2:36 UTC (permalink / raw)
  To: Yang Yingliang
  Cc: David Miller, netdev, eric dumazet, xiyou wangcong, weiyongjun1
In-Reply-To: <5D770AF6.1060902@huawei.com>


On 2019/9/10 上午10:31, Yang Yingliang wrote:
>>>
>>>               if (!(tun->flags & IFF_PERSIST) &&
>>> -                tun->dev->reg_state == NETREG_REGISTERED)
>>> +                tun->dev->reg_state == NETREG_REGISTERED) {
>>> +                tun->flags &= ~TUN_DEV_REGISTERED;
>>
>> As I said for previous versions. It's not good that try to invent new
>> internal state like this, and you need carefully to deal with the
>> synchronization, it could be lock or barriers. Consider the
>> synchronization of tun is already complex, let's better try to avoid
>> adding more but using exist mechanism, e.g pointer publishing through 
>> RCU.
> OK, need I post a V4 by using the diff file you sent ? 


Yes, please.

Thanks


^ permalink raw reply

* Re: [PATCH v3 0/3] kernel/notifier.c: avoid duplicate registration
From: Xiaoming Ni @ 2019-09-10  3:57 UTC (permalink / raw)
  To: Vasily Averin, gregkh@linuxfoundation.org
  Cc: adobriyan@gmail.com, akpm@linux-foundation.org,
	anna.schumaker@netapp.com, arjan@linux.intel.com,
	bfields@fieldses.org, chuck.lever@oracle.com, davem@davemloft.net,
	jlayton@kernel.org, luto@kernel.org, mingo@kernel.org,
	Nadia.Derbey@bull.net, paulmck@linux.vnet.ibm.com,
	semen.protsenko@linaro.org, stable@kernel.org,
	stern@rowland.harvard.edu, tglx@linutronix.de,
	torvalds@linux-foundation.org, trond.myklebust@hammerspace.com,
	viresh.kumar@linaro.org, Huangjianhui (Alex), Dailei,
	linux-kernel@vger.kernel.org, linux-nfs@vger.kernel.org,
	netdev@vger.kernel.org
In-Reply-To: <0d245a97-1169-9ef2-e502-043ba80eaa8c@virtuozzo.com>


On 2019/7/17 19:15, Vasily Averin wrote:
> On 7/16/19 5:07 PM, Xiaoming Ni wrote:
>> On 2019/7/16 18:20, Vasily Averin wrote:
>>> On 7/16/19 5:00 AM, Xiaoming Ni wrote:
>>>> On 2019/7/15 13:38, Vasily Averin wrote:
>>>>> On 7/14/19 5:45 AM, Xiaoming Ni wrote:
>>>>>> On 2019/7/12 22:07, gregkh@linuxfoundation.org wrote:
>>>>>>> On Fri, Jul 12, 2019 at 09:11:57PM +0800, Xiaoming Ni wrote:
>>>>>>>> On 2019/7/11 21:57, Vasily Averin wrote:
>>>>>>>>> On 7/11/19 4:55 AM, Nixiaoming wrote:
>>>>>>>>>> On Wed, July 10, 2019 1:49 PM Vasily Averin wrote:
>>>>>>>>>>> On 7/10/19 6:09 AM, Xiaoming Ni wrote:
....
...
>>>>>>>> So in these two cases, is it more reasonable to trigger BUG() directly when checking for duplicate registration ?
>>>>>>>> But why does current notifier_chain_register() just trigger WARN() without exiting ?
>>>>>>>> notifier_chain_cond_register() direct exit without triggering WARN() ?
>>>>>>>
>>>>>>> It should recover from this, if it can be detected.  The main point is
>>>>>>> that not all apis have to be this "robust" when used within the kernel
>>>>>>> as we do allow for the callers to know what they are doing :)
>>>>>>>
>>>>>> In the notifier_chain_register(), the condition ( (*nl) == n) is the same registration of the same hook.
>>>>>>  We can intercept this situation and avoid forming a linked list ring to make the API more rob
...
...

> Yes, I'm agree, at present there are no difference between
> notifier_chain_cond_register() and notifier_chain_register()
> 
> Question is -- how to improve it.
> You propose to remove notifier_chain_cond_register() by some way.
> Another option is return an error, for some abstract callers who expect possible double registration.
> 
> Frankly speaking I prefer second one,
> however because of kernel do not have any such callers right now seems you are right, 
> and we can delete notifier_chain_cond_register().
> 
> So let me finally accept your patch-set.
> 
> Thank you,
> 	Vasily Averin
> 
> .
>

Dear Greg Kroah-Hartman
is there any other opinion on this patch set?
can you pick this series?

thanks
	Xiaoming Ni


^ permalink raw reply

* Re: [PATCH net-next 2/5] sctp: add pf_expose per netns and sock and asoc
From: Xin Long @ 2019-09-10  6:26 UTC (permalink / raw)
  To: Nathan Chancellor, linux-sctp, network dev
  Cc: kbuild, Nick Desaulniers, clang-built-linux, kbuild test robot
In-Reply-To: <20190910035421.GB1778@archlinux-threadripper>

On Tue, Sep 10, 2019 at 11:54 AM Nathan Chancellor
<natechancellor@gmail.com> wrote:
>
> Hi Xin,
>
> The 0day team has been doing clang builds for us and this warning popped
> up. Let me know if you have any questions.
>
> On Mon, Sep 09, 2019 at 06:44:47PM +0800, kbuild test robot wrote:
> > CC: kbuild-all@01.org
> > In-Reply-To: <00fb06e74d8eedeb033dad83de18380bf6261231.1568015756.git.lucien.xin@gmail.com>
> > References: <00fb06e74d8eedeb033dad83de18380bf6261231.1568015756.git.lucien.xin@gmail.com>
> > TO: Xin Long <lucien.xin@gmail.com>
> > CC: network dev <netdev@vger.kernel.org>, linux-sctp@vger.kernel.org
> > CC: Marcelo Ricardo Leitner <marcelo.leitner@gmail.com>, Neil Horman <nhorman@tuxdriver.com>, davem@davemloft.net
> >
> > Hi Xin,
> >
> > Thank you for the patch! Perhaps something to improve:
> >
> > [auto build test WARNING on net-next/master]
> >
> > url:    https://github.com/0day-ci/linux/commits/Xin-Long/sctp-update-from-rfc7829/20190909-160115
> > config: x86_64-rhel-7.6 (attached as .config)
> > compiler: clang version 10.0.0 (git://gitmirror/llvm_project 45a3fd206fb06f77a08968c99a8172cbf2ccdd0f)
> > reproduce:
> >         # save the attached .config to linux build tree
> >         make ARCH=x86_64
> >
> > If you fix the issue, kindly add following tag
> > Reported-by: kbuild test robot <lkp@intel.com>
> >
> > All warnings (new ones prefixed by >>):
> >
> > >> net/sctp/associola.c:799:24: warning: use of logical '&&' with constant operand [-Wconstant-logical-operand]
> >                    if (transport->state && SCTP_UNCONFIRMED &&
> >                                         ^  ~~~~~~~~~~~~~~~~
> >    net/sctp/associola.c:799:24: note: use '&' for a bitwise operation
> >                    if (transport->state && SCTP_UNCONFIRMED &&
> >                                         ^~
> >                                         &
> >    net/sctp/associola.c:799:24: note: remove constant to silence this warning
> >                    if (transport->state && SCTP_UNCONFIRMED &&
> >                                        ~^~~~~~~~~~~~~~~~~~~
> >    1 warning generated.
> >
> > vim +799 net/sctp/associola.c
> >
> >    775
> >    776        /* Engage in transport control operations.
> >    777         * Mark the transport up or down and send a notification to the user.
> >    778         * Select and update the new active and retran paths.
> >    779         */
> >    780        void sctp_assoc_control_transport(struct sctp_association *asoc,
> >    781                                          struct sctp_transport *transport,
> >    782                                          enum sctp_transport_cmd command,
> >    783                                          sctp_sn_error_t error)
> >    784        {
> >    785                struct sctp_ulpevent *event;
> >    786                struct sockaddr_storage addr;
> >    787                int spc_state = 0;
> >    788                bool ulp_notify = true;
> >    789
> >    790                /* Record the transition on the transport.  */
> >    791                switch (command) {
> >    792                case SCTP_TRANSPORT_UP:
> >    793                        /* If we are moving from UNCONFIRMED state due
> >    794                         * to heartbeat success, report the SCTP_ADDR_CONFIRMED
> >    795                         * state to the user, otherwise report SCTP_ADDR_AVAILABLE.
> >    796                         */
> >    797                        if (transport->state == SCTP_PF && !asoc->pf_expose)
> >    798                                ulp_notify = false;
> >  > 799                        if (transport->state && SCTP_UNCONFIRMED &&
>
> I assume this && should either be a '&' or '=='?
Right, it should have been "==". It was changed unintentionally
when I swapped the position of 'state' and 'SCTP_UNCONFIRMED'.

Thanks, will post v2 after others' review.

>
> >    800                            SCTP_HEARTBEAT_SUCCESS == error)
> >    801                                spc_state = SCTP_ADDR_CONFIRMED;
> >    802                        else
> >    803                                spc_state = SCTP_ADDR_AVAILABLE;
> >    804                        transport->state = SCTP_ACTIVE;
> >    805                        break;
> >    806
> >    807                case SCTP_TRANSPORT_DOWN:
> >    808                        /* If the transport was never confirmed, do not transition it
> >    809                         * to inactive state.  Also, release the cached route since
> >    810                         * there may be a better route next time.
> >    811                         */
> >    812                        if (transport->state != SCTP_UNCONFIRMED) {
> >    813                                transport->state = SCTP_INACTIVE;
> >    814                                spc_state = SCTP_ADDR_UNREACHABLE;
> >    815                        } else {
> >    816                                sctp_transport_dst_release(transport);
> >    817                                ulp_notify = false;
> >    818                        }
> >    819                        break;
> >    820
> >    821                case SCTP_TRANSPORT_PF:
> >    822                        transport->state = SCTP_PF;
> >    823                        if (!asoc->pf_expose)
> >    824                                ulp_notify = false;
> >    825                        else
> >    826                                spc_state = SCTP_ADDR_POTENTIALLY_FAILED;
> >    827                        break;
> >    828
> >    829                default:
> >    830                        return;
> >    831                }
> >    832
> >    833                /* Generate and send a SCTP_PEER_ADDR_CHANGE notification
> >    834                 * to the user.
> >    835                 */
> >    836                if (ulp_notify) {
> >    837                        memset(&addr, 0, sizeof(struct sockaddr_storage));
> >    838                        memcpy(&addr, &transport->ipaddr,
> >    839                               transport->af_specific->sockaddr_len);
> >    840
> >    841                        event = sctp_ulpevent_make_peer_addr_change(asoc, &addr,
> >    842                                                0, spc_state, error, GFP_ATOMIC);
> >    843                        if (event)
> >    844                                asoc->stream.si->enqueue_event(&asoc->ulpq, event);
> >    845                }
> >    846
> >    847                /* Select new active and retran paths. */
> >    848                sctp_select_active_and_retran_path(asoc);
> >    849        }
> >    850
> >
> > ---
> > 0-DAY kernel test infrastructure                Open Source Technology Center
> > https://lists.01.org/pipermail/kbuild-all                   Intel Corporation
>
> Cheers,
> Nathan

^ permalink raw reply

* Re: [PATCH] lib/Kconfig: fix OBJAGG in lib/ menu structure
From: Ido Schimmel @ 2019-09-10  6:47 UTC (permalink / raw)
  To: Randy Dunlap; +Cc: netdev@vger.kernel.org, LKML, David Miller, Jiri Pirko
In-Reply-To: <34674398-54dc-a4d1-6052-67ad1a3b2fe9@infradead.org>

On Mon, Sep 09, 2019 at 02:54:21PM -0700, Randy Dunlap wrote:
> From: Randy Dunlap <rdunlap@infradead.org>
> 
> Keep the "Library routines" menu intact by moving OBJAGG into it.
> Otherwise OBJAGG is displayed/presented as an orphan in the
> various config menus.
> 
> Fixes: 0a020d416d0a ("lib: introduce initial implementation of object aggregation manager")
> Signed-off-by: Randy Dunlap <rdunlap@infradead.org>
> Cc: Jiri Pirko <jiri@mellanox.com>
> Cc: Ido Schimmel <idosch@mellanox.com>
> Cc: David S. Miller <davem@davemloft.net>

Tested-by: Ido Schimmel <idosch@mellanox.com>

Thanks!

^ permalink raw reply

* Re: [RFC PATCH untested] vhost: block speculation of translated descriptors
From: Michael S. Tsirkin @ 2019-09-10  6:48 UTC (permalink / raw)
  To: Jason Wang; +Cc: linux-kernel, kvm, virtualization, netdev
In-Reply-To: <9ab48e0f-50a9-bed4-1801-73c37a7da27c@redhat.com>

On Tue, Sep 10, 2019 at 09:52:10AM +0800, Jason Wang wrote:
> 
> On 2019/9/9 下午10:45, Michael S. Tsirkin wrote:
> > On Mon, Sep 09, 2019 at 03:19:55PM +0800, Jason Wang wrote:
> > > On 2019/9/8 下午7:05, Michael S. Tsirkin wrote:
> > > > iovec addresses coming from vhost are assumed to be
> > > > pre-validated, but in fact can be speculated to a value
> > > > out of range.
> > > > 
> > > > Userspace address are later validated with array_index_nospec so we can
> > > > be sure kernel info does not leak through these addresses, but vhost
> > > > must also not leak userspace info outside the allowed memory table to
> > > > guests.
> > > > 
> > > > Following the defence in depth principle, make sure
> > > > the address is not validated out of node range.
> > > > 
> > > > Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> > > > ---
> > > >    drivers/vhost/vhost.c | 4 +++-
> > > >    1 file changed, 3 insertions(+), 1 deletion(-)
> > > > 
> > > > diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
> > > > index 5dc174ac8cac..0ee375fb7145 100644
> > > > --- a/drivers/vhost/vhost.c
> > > > +++ b/drivers/vhost/vhost.c
> > > > @@ -2072,7 +2072,9 @@ static int translate_desc(struct vhost_virtqueue *vq, u64 addr, u32 len,
> > > >    		size = node->size - addr + node->start;
> > > >    		_iov->iov_len = min((u64)len - s, size);
> > > >    		_iov->iov_base = (void __user *)(unsigned long)
> > > > -			(node->userspace_addr + addr - node->start);
> > > > +			(node->userspace_addr +
> > > > +			 array_index_nospec(addr - node->start,
> > > > +					    node->size));
> > > >    		s += size;
> > > >    		addr += size;
> > > >    		++ret;
> > > 
> > > I've tried this on Kaby Lake smap off metadata acceleration off using
> > > testpmd (virtio-user) + vhost_net. I don't see obvious performance
> > > difference with TX PPS.
> > > 
> > > Thanks
> > Should I push this to Linus right now then? It's a security thing so
> > maybe we better do it ASAP ... what's your opinion?
> 
> 
> Yes, you can.
> 
> Acked-by: Jason Wang <jasowang@redhat.com>


And should I include

Tested-by: Jason Wang <jasowang@redhat.com>

?

> 
> 
> > 

^ permalink raw reply

* [PATCH net 2/2] sctp: destroy bucket if failed to bind addr
From: Mao Wenan @ 2019-09-10  7:13 UTC (permalink / raw)
  To: vyasevich, nhorman, marcelo.leitner, davem
  Cc: linux-sctp, netdev, linux-kernel, kernel-janitors, Mao Wenan,
	Hulk Robot
In-Reply-To: <20190910071343.18808-1-maowenan@huawei.com>

There is one memory leak bug report:
BUG: memory leak
unreferenced object 0xffff8881dc4c5ec0 (size 40):
  comm "syz-executor.0", pid 5673, jiffies 4298198457 (age 27.578s)
  hex dump (first 32 bytes):
    02 00 00 00 81 88 ff ff 00 00 00 00 00 00 00 00  ................
    f8 63 3d c1 81 88 ff ff 00 00 00 00 00 00 00 00  .c=.............
  backtrace:
    [<0000000072006339>] sctp_get_port_local+0x2a1/0xa00 [sctp]
    [<00000000c7b379ec>] sctp_do_bind+0x176/0x2c0 [sctp]
    [<000000005be274a2>] sctp_bind+0x5a/0x80 [sctp]
    [<00000000b66b4044>] inet6_bind+0x59/0xd0 [ipv6]
    [<00000000c68c7f42>] __sys_bind+0x120/0x1f0 net/socket.c:1647
    [<000000004513635b>] __do_sys_bind net/socket.c:1658 [inline]
    [<000000004513635b>] __se_sys_bind net/socket.c:1656 [inline]
    [<000000004513635b>] __x64_sys_bind+0x3e/0x50 net/socket.c:1656
    [<0000000061f2501e>] do_syscall_64+0x72/0x2e0 arch/x86/entry/common.c:296
    [<0000000003d1e05e>] entry_SYSCALL_64_after_hwframe+0x49/0xbe

This is because in sctp_do_bind, if sctp_get_port_local is to
create hash bucket successfully, and sctp_add_bind_addr failed
to bind address, e.g return -ENOMEM, so memory leak found, it
needs to destroy allocated bucket.

Reported-by: Hulk Robot <hulkci@huawei.com>
Signed-off-by: Mao Wenan <maowenan@huawei.com>
---
 net/sctp/socket.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/net/sctp/socket.c b/net/sctp/socket.c
index 766b68b55ebe..ab37fc1f7bb6 100644
--- a/net/sctp/socket.c
+++ b/net/sctp/socket.c
@@ -412,11 +412,13 @@ static int sctp_do_bind(struct sock *sk, union sctp_addr *addr, int len)
 	ret = sctp_add_bind_addr(bp, addr, af->sockaddr_len,
 				 SCTP_ADDR_SRC, GFP_ATOMIC);
 
-	/* Copy back into socket for getsockname() use. */
-	if (!ret) {
-		inet_sk(sk)->inet_sport = htons(inet_sk(sk)->inet_num);
-		sp->pf->to_sk_saddr(addr, sk);
+	if (ret) {
+		sctp_put_port(sk);
+		return ret;
 	}
+	/* Copy back into socket for getsockname() use. */
+	inet_sk(sk)->inet_sport = htons(inet_sk(sk)->inet_num);
+	sp->pf->to_sk_saddr(addr, sk);
 
 	return ret;
 }
-- 
2.20.1


^ permalink raw reply related

* [PATCH net 0/2] fix memory leak for sctp_do_bind
From: Mao Wenan @ 2019-09-10  7:13 UTC (permalink / raw)
  To: vyasevich, nhorman, marcelo.leitner, davem
  Cc: linux-sctp, netdev, linux-kernel, kernel-janitors, Mao Wenan

First patch is to do cleanup, remove redundant assignment,
second patch is to fix memory leak for sctp_do_bind if failed
to bind address.

Mao Wenan (2):
  sctp: remove redundant assignment when call sctp_get_port_local
  sctp: destroy bucket if failed to bind addr

 net/sctp/socket.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

-- 
2.20.1


^ permalink raw reply

* [PATCH net 1/2] sctp: remove redundant assignment when call sctp_get_port_local
From: Mao Wenan @ 2019-09-10  7:13 UTC (permalink / raw)
  To: vyasevich, nhorman, marcelo.leitner, davem
  Cc: linux-sctp, netdev, linux-kernel, kernel-janitors, Mao Wenan
In-Reply-To: <20190910071343.18808-1-maowenan@huawei.com>

There are more parentheses in if clause when call sctp_get_port_local
in sctp_do_bind, and redundant assignment to 'ret'. This patch is to
do cleanup.

Signed-off-by: Mao Wenan <maowenan@huawei.com>
---
 net/sctp/socket.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/net/sctp/socket.c b/net/sctp/socket.c
index 9d1f83b10c0a..766b68b55ebe 100644
--- a/net/sctp/socket.c
+++ b/net/sctp/socket.c
@@ -399,9 +399,8 @@ static int sctp_do_bind(struct sock *sk, union sctp_addr *addr, int len)
 	 * detection.
 	 */
 	addr->v4.sin_port = htons(snum);
-	if ((ret = sctp_get_port_local(sk, addr))) {
+	if (sctp_get_port_local(sk, addr))
 		return -EADDRINUSE;
-	}
 
 	/* Refresh ephemeral port.  */
 	if (!bp->port)
-- 
2.20.1


^ permalink raw reply related

* Re: [PATCH net] sctp: fix the missing put_user when dumping transport thresholds
From: Neil Horman @ 2019-09-10  7:15 UTC (permalink / raw)
  To: Xin Long; +Cc: network dev, linux-sctp, davem, Marcelo Ricardo Leitner
In-Reply-To: <3fa4f7700c93f06530c80bc666d1696cb7c077de.1568014409.git.lucien.xin@gmail.com>

On Mon, Sep 09, 2019 at 03:33:29PM +0800, Xin Long wrote:
> This issue causes SCTP_PEER_ADDR_THLDS sockopt not to be able to dump
> a transport thresholds info.
> 
> Fix it by adding 'goto' put_user in sctp_getsockopt_paddr_thresholds.
> 
> Fixes: 8add543e369d ("sctp: add SCTP_FUTURE_ASSOC for SCTP_PEER_ADDR_THLDS sockopt")
> Signed-off-by: Xin Long <lucien.xin@gmail.com>
> ---
>  net/sctp/socket.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/net/sctp/socket.c b/net/sctp/socket.c
> index 9d1f83b..ad87518 100644
> --- a/net/sctp/socket.c
> +++ b/net/sctp/socket.c
> @@ -7173,7 +7173,7 @@ static int sctp_getsockopt_paddr_thresholds(struct sock *sk,
>  		val.spt_pathmaxrxt = trans->pathmaxrxt;
>  		val.spt_pathpfthld = trans->pf_retrans;
>  
> -		return 0;
> +		goto out;
>  	}
>  
>  	asoc = sctp_id2assoc(sk, val.spt_assoc_id);
> @@ -7191,6 +7191,7 @@ static int sctp_getsockopt_paddr_thresholds(struct sock *sk,
>  		val.spt_pathmaxrxt = sp->pathmaxrxt;
>  	}
>  
> +out:
>  	if (put_user(len, optlen) || copy_to_user(optval, &val, len))
>  		return -EFAULT;
>  
> -- 
> 2.1.0
> 
> 
Acked-by: Neil Horman <nhorman@tuxdriver.com>


^ permalink raw reply

* Re: [PATCH net 0/2] fix memory leak for sctp_do_bind
From: Neil Horman @ 2019-09-10  7:16 UTC (permalink / raw)
  To: Mao Wenan
  Cc: vyasevich, marcelo.leitner, davem, linux-sctp, netdev,
	linux-kernel, kernel-janitors
In-Reply-To: <20190910071343.18808-1-maowenan@huawei.com>

On Tue, Sep 10, 2019 at 03:13:41PM +0800, Mao Wenan wrote:
> First patch is to do cleanup, remove redundant assignment,
> second patch is to fix memory leak for sctp_do_bind if failed
> to bind address.
> 
> Mao Wenan (2):
>   sctp: remove redundant assignment when call sctp_get_port_local
>   sctp: destroy bucket if failed to bind addr
> 
>  net/sctp/socket.c | 13 +++++++------
>  1 file changed, 7 insertions(+), 6 deletions(-)
> 
> -- 
> 2.20.1
> 
> 
Series
Acked-by: Neil Horman <nhorman@tuxdriver.com>


^ permalink raw reply

* Re: [RFC PATCH untested] vhost: block speculation of translated descriptors
From: Jason Wang @ 2019-09-10  7:28 UTC (permalink / raw)
  To: Michael S. Tsirkin; +Cc: linux-kernel, kvm, virtualization, netdev
In-Reply-To: <20190910024814-mutt-send-email-mst@kernel.org>


On 2019/9/10 下午2:48, Michael S. Tsirkin wrote:
> On Tue, Sep 10, 2019 at 09:52:10AM +0800, Jason Wang wrote:
>> On 2019/9/9 下午10:45, Michael S. Tsirkin wrote:
>>> On Mon, Sep 09, 2019 at 03:19:55PM +0800, Jason Wang wrote:
>>>> On 2019/9/8 下午7:05, Michael S. Tsirkin wrote:
>>>>> iovec addresses coming from vhost are assumed to be
>>>>> pre-validated, but in fact can be speculated to a value
>>>>> out of range.
>>>>>
>>>>> Userspace address are later validated with array_index_nospec so we can
>>>>> be sure kernel info does not leak through these addresses, but vhost
>>>>> must also not leak userspace info outside the allowed memory table to
>>>>> guests.
>>>>>
>>>>> Following the defence in depth principle, make sure
>>>>> the address is not validated out of node range.
>>>>>
>>>>> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
>>>>> ---
>>>>>     drivers/vhost/vhost.c | 4 +++-
>>>>>     1 file changed, 3 insertions(+), 1 deletion(-)
>>>>>
>>>>> diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
>>>>> index 5dc174ac8cac..0ee375fb7145 100644
>>>>> --- a/drivers/vhost/vhost.c
>>>>> +++ b/drivers/vhost/vhost.c
>>>>> @@ -2072,7 +2072,9 @@ static int translate_desc(struct vhost_virtqueue *vq, u64 addr, u32 len,
>>>>>     		size = node->size - addr + node->start;
>>>>>     		_iov->iov_len = min((u64)len - s, size);
>>>>>     		_iov->iov_base = (void __user *)(unsigned long)
>>>>> -			(node->userspace_addr + addr - node->start);
>>>>> +			(node->userspace_addr +
>>>>> +			 array_index_nospec(addr - node->start,
>>>>> +					    node->size));
>>>>>     		s += size;
>>>>>     		addr += size;
>>>>>     		++ret;
>>>> I've tried this on Kaby Lake smap off metadata acceleration off using
>>>> testpmd (virtio-user) + vhost_net. I don't see obvious performance
>>>> difference with TX PPS.
>>>>
>>>> Thanks
>>> Should I push this to Linus right now then? It's a security thing so
>>> maybe we better do it ASAP ... what's your opinion?
>>
>> Yes, you can.
>>
>> Acked-by: Jason Wang <jasowang@redhat.com>
>
> And should I include
>
> Tested-by: Jason Wang <jasowang@redhat.com>
>
> ?


Yes.

Thanks


>
>>

^ permalink raw reply

* Re: [PATCH net-next 1/5] enetc: Fix if_mode extraction
From: Andrew Lunn @ 2019-09-10  7:44 UTC (permalink / raw)
  To: Claudiu Manoil
  Cc: David S . Miller, Alexandru Marginean, netdev@vger.kernel.org
In-Reply-To: <VI1PR04MB48803DB044AB6CF66CACB89E96B70@VI1PR04MB4880.eurprd04.prod.outlook.com>

On Mon, Sep 09, 2019 at 04:24:01PM +0000, Claudiu Manoil wrote:
> >-----Original Message-----
> >From: Andrew Lunn <andrew@lunn.ch>
> >Sent: Friday, September 6, 2019 10:58 PM
> >To: Claudiu Manoil <claudiu.manoil@nxp.com>
> >Cc: David S . Miller <davem@davemloft.net>; Alexandru Marginean
> ><alexandru.marginean@nxp.com>; netdev@vger.kernel.org
> >Subject: Re: [PATCH net-next 1/5] enetc: Fix if_mode extraction
> >
> >On Fri, Sep 06, 2019 at 05:15:40PM +0300, Claudiu Manoil wrote:
> >> Fix handling of error return code. Before this fix,
> >> the error code was handled as unsigned type.
> >> Also, on this path if if_mode not found then just handle
> >> it as fixed link (i.e mac2mac connection).
> >>
> >> Signed-off-by: Claudiu Manoil <claudiu.manoil@nxp.com>
> >> ---
> >>  drivers/net/ethernet/freescale/enetc/enetc_pf.c | 17 ++++++-----------
> >>  1 file changed, 6 insertions(+), 11 deletions(-)
> >>
> >> diff --git a/drivers/net/ethernet/freescale/enetc/enetc_pf.c
> >b/drivers/net/ethernet/freescale/enetc/enetc_pf.c
> >> index 7d6513ff8507..3a556646a2fb 100644
> >> --- a/drivers/net/ethernet/freescale/enetc/enetc_pf.c
> >> +++ b/drivers/net/ethernet/freescale/enetc/enetc_pf.c
> >> @@ -751,6 +751,7 @@ static int enetc_of_get_phy(struct enetc_ndev_priv
> >*priv)
> >>  	struct enetc_pf *pf = enetc_si_priv(priv->si);
> >>  	struct device_node *np = priv->dev->of_node;
> >>  	struct device_node *mdio_np;
> >> +	int phy_mode;
> >>  	int err;
> >>
> >>  	if (!np) {
> >> @@ -784,17 +785,11 @@ static int enetc_of_get_phy(struct enetc_ndev_priv
> >*priv)
> >>  		}
> >>  	}
> >>
> >> -	priv->if_mode = of_get_phy_mode(np);
> >> -	if (priv->if_mode < 0) {
> >> -		dev_err(priv->dev, "missing phy type\n");
> >> -		of_node_put(priv->phy_node);
> >> -		if (of_phy_is_fixed_link(np))
> >> -			of_phy_deregister_fixed_link(np);
> >> -		else
> >> -			enetc_mdio_remove(pf);
> >> -
> >> -		return -EINVAL;
> >> -	}
> >
> >Hi Claudiu
> >
> >It is not clear to me why it is no longer necessary to deregister the
> >fixed link, or remove the mdio bus?
> >
> >> +	phy_mode = of_get_phy_mode(np);
> >> +	if (phy_mode < 0)
> >> +		priv->if_mode = PHY_INTERFACE_MODE_NA; /* fixed link */
> >> +	else
> >> +		priv->if_mode = phy_mode;
> >
> 
> Hi Andrew,
> 
> The MAC2MAC connections are defined as fixed-link too, but without
> phy-mode/phy-connection-type properties.  We don't want to de-register
> these links.  Initial code was bogus in this regard.

Hi Claudiu

This is what is not clear in the change log. That this code is removed
because it is wrong. Please could you expand the explanation to make
this clearer.

> Current proposal is:
> 			ethernet@0,2 { /* SoC internal, connected to switch port 4 */
> 				compatible = "fsl,enetc";
> 				reg = <0x000200 0 0 0 0>;
> 				fixed-link {
> 					speed = <1000>;
> 					full-duplex;
> 				};
> 			};
> 			switch@0,5 {
> 				compatible = "mscc,felix-switch";
> 				[...]
> 				ports {
> 					#address-cells = <1>;
> 					#size-cells = <0>;
> 
> 					/* external ports */
> 					[...]
> 					/* internal SoC ports */
> 					port@4 { /* connected to ENETC port2 */
> 						reg = <4>;
> 						fixed-link {
> 							speed = <1000>;
> 							full-duplex;
> 						};
> 					};

So this connection between the SoC and the switch does not use tags?
Can it use tags? Does the hardware allow you to have two CPU ports,
and load balance over them?

This second half is just standard DSA. This looks good.

     Andrew



> 					port@5 { /* CPU port, connected to ENETC port3 */
> 						reg = <5>;
> 						ethernet = <&enetc_port3>;
> 						fixed-link {
> 							speed = <1000>;
> 							full-duplex;
> 						};
> 					};
> 				};
> 			};
> 			enetc_port3: ethernet@0,6 { /* SoC internal connected to switch port 5 */
> 				compatible = "fsl,enetc";
> 				reg = <0x000600 0 0 0 0>;
> 				fixed-link {
> 					speed = <1000>;
> 					full-duplex;
> 				};
> 			};
> 		};
> 
> Thanks.
> 
> Claudiu

^ permalink raw reply

* Re: [RFC bpf-next 2/7] bpf: extend bpf_pcap support to tracing programs
From: Yonghong Song @ 2019-09-10  7:43 UTC (permalink / raw)
  To: Alan Maguire
  Cc: ast@kernel.org, daniel@iogearbox.net, Martin Lau, Song Liu,
	davem@davemloft.net, jakub.kicinski@netronome.com,
	hawk@kernel.org, john.fastabend@gmail.com, rostedt@goodmis.org,
	mingo@redhat.com, quentin.monnet@netronome.com, Andrey Ignatov,
	joe@wand.net.nz, acme@redhat.com, jolsa@kernel.org,
	alexey.budankov@linux.intel.com, gregkh@linuxfoundation.org,
	namhyung@kernel.org, sdf@google.com, f.fainelli@gmail.com,
	shuah@kernel.org, peter@lekensteyn.nl, ivan@cloudflare.com,
	Andrii Nakryiko, bhole_prashant_q7@lab.ntt.co.jp,
	david.calavera@gmail.com, danieltimlee@gmail.com,
	Takshak Chahande, netdev@vger.kernel.org, bpf@vger.kernel.org,
	linux-kselftest@vger.kernel.org, toke@redhat.com,
	jbenc@redhat.com
In-Reply-To: <alpine.LRH.2.20.1909092236490.10757@dhcp-10-175-172-139.vpn.oracle.com>



On 9/9/19 11:25 PM, Alan Maguire wrote:
> On Sun, 8 Sep 2019, Yonghong Song wrote:
>   
>> For net side bpf_perf_event_output, we have
>> static unsigned long bpf_skb_copy(void *dst_buff, const void *skb,
>>                                     unsigned long off, unsigned long len)
>> {
>>           void *ptr = skb_header_pointer(skb, off, len, dst_buff);
>>
>>           if (unlikely(!ptr))
>>                   return len;
>>           if (ptr != dst_buff)
>>                   memcpy(dst_buff, ptr, len);
>>
>>           return 0;
>> }
>>
>> BPF_CALL_5(bpf_skb_event_output, struct sk_buff *, skb, struct bpf_map
>> *, map,
>>              u64, flags, void *, meta, u64, meta_size)
>> {
>>           u64 skb_size = (flags & BPF_F_CTXLEN_MASK) >> 32;
>>
>>           if (unlikely(flags & ~(BPF_F_CTXLEN_MASK | BPF_F_INDEX_MASK)))
>>                   return -EINVAL;
>>           if (unlikely(skb_size > skb->len))
>>                   return -EFAULT;
>>
>>           return bpf_event_output(map, flags, meta, meta_size, skb, skb_size,
>>                                   bpf_skb_copy);
>> }
>>
>> It does not really consider output all the frags.
>> I understand that to get truly all packet data, frags should be
>> considered, but seems we did not do it before? I am wondering
>> whether we need to do here.
> 
> Thanks for the feedback! In experimenting with packet capture,
> my original hope was to keep things simple and avoid fragment parsing
> if possible. However if scatter-gather is enabled for the networking
> device, or indeed if it's running in a VM it turns out a lot of the
> interesting packet data ends up in the fragments on transmit (ssh
> headers, http headers etc).  So I think it would be worth considering
> adding support for fragment traversal.  It's not needed as much
> in the skb program case - we can always pullup the skb - but in
> the tracing situation we probably wouldn't want to do something
> that invasive in tracing context.

Agree that in tracing context, we should avoid push/pull skb. It is
indeed invasive.

> 
> Fragment traversal might be worth breaking out as a separate patchset,
> perhaps triggered by a specific flag to bpf_skb_event_output?

This can be done for bpf_skb_event_output as the context is a sk_buff.
And you can just follow the frags to copy the whole thing without
bpf_probe_read().

> 
> Feedback from folks at Linux Plumbers (I hope I'm summarizing correctly)
> seemed to agree with what you mentioned WRT the first patch in this
> series.  The gist was we probably don't want to force the metadata to be a
> specific packet capture type; we'd rather use the existing perf event
> mechanisms and if we are indeed doing packet capture, simply specify that
> data in the program as metadata.

Agree, you can have whatever metadata you have for bpf_perf_event_output.

> 
> I'd be happy with that approach myself if I could capture skb
> fragments in tracing programs - being able to do that would give
> equivalent functionality to what I proposed but without having a packet
> capture-specific helper.

That won't work for tracing program. Full of bpf_probe_read()
in tracing version of packet copying is not nice either.

We may still need a different helper for tracing programs.

I think we need something like below:
   - vmlinux BTF at /sys/kernel/btf/kernel, is loaded into kernel.
     (/sys/kernel/btf/kernel is the source of truth)
   - For a tracing bpf program, if that function eventually
     copy  helper
         bpf_skb_event_output(..., skb, ...)
     the verifier needs to verify skb is indeed a valid skb
     by tracing back to one of parameters.

     Here, I use skb as an example, maybe it can be extended
     to other data structures as well.

With this approach, you can reuse some of functions from
tracing side to deal with frag copying and no bpf_probe_read()
is needed.

Here, I use skb as an example, maybe it can be extended
to other data structures as well if needed.

>>
>> If we indeed do not need to handle frags here, I think maybe
>> bpf_probe_read() in existing bpf kprobe function should be
>> enough, we do not need this helper?
>>
> 
> Certainly for many use cases, that will get you most of what you need -
> particularly if you're just looking at L2 to L4 data. For full packet
> capture however I think we may need to think about fragment traversal.
> 
>>> +
>>> +/* Derive protocol for some of the easier cases.  For tracing, a probe point
>>> + * may be dealing with packets in various states. Common cases are IP
>>> + * packets prior to adding MAC header (_PCAP_TYPE_IP) and a full packet
>>> + * (_PCAP_TYPE_ETH).  For other cases the caller must specify the
>>> + * protocol they expect.  Other heuristics for packet identification
>>> + * should be added here as needed, since determining the packet type
>>> + * ensures we do not capture packets that fail to match the desired
>>> + * pcap type in BPF_F_PCAP_STRICT_TYPE mode.
>>> + */
>>> +static inline int bpf_skb_protocol_get(struct sk_buff *skb)
>>> +{
>>> +	switch (htons(skb->protocol)) {
>>> +	case ETH_P_IP:
>>> +	case ETH_P_IPV6:
>>> +		if (skb_network_header(skb) == skb->data)
>>> +			return BPF_PCAP_TYPE_IP;
>>> +		else
>>> +			return BPF_PCAP_TYPE_ETH;
>>> +	default:
>>> +		return BPF_PCAP_TYPE_UNSET;
>>> +	}
>>> +}
>>> +
>>> +BPF_CALL_5(bpf_trace_pcap, void *, data, u32, size, struct bpf_map *, map,
>>> +	   int, protocol_wanted, u64, flags)
>>
>> Up to now, for helpers, verifier has a way to verifier it is used
>> properly regarding to the context. For example, for xdp version
>> perf_event_output, the help prototype,
>>     BPF_CALL_5(bpf_xdp_event_output, struct xdp_buff *, xdp, struct
>> bpf_map *, map,
>>              u64, flags, void *, meta, u64, meta_size)
>> the verifier is able to guarantee that the first parameter
>> has correct type xdp_buff, not something from type cast.
>>     .arg1_type      = ARG_PTR_TO_CTX,
>>
>> This helper, in the below we have
>>     .arg1_type	= ARG_ANYTHING,
>>
>> So it is not really enforced. Bringing BTF can help, but type
>> name matching typically bad.
>>
>>
> One thing we were discussing - and I think this is similar to what
> you're suggesting - is to investigate if there might be a way to
> leverage BTF to provide additional guarantees that the tracing
> data we are handling is indeed an skb.  Specifically if we
> trace a kprobe function argument or a tracepoint function, and
> if we had that guarantee, we could perhaps invoke the skb-style
> perf event output function (trace both the skb data and the metadata).
> The challenge would be how to do that type-based matching; we'd
> need the function argument information from BTF _and_ need to
> somehow associate it at probe attach time.
> 
> Thanks again for looking at the code!
> 
> Alan
> 

^ permalink raw reply

* Re: [net-next v2 00/15][pull request] Intel Wired LAN Driver Updates 2019-09-09
From: David Miller @ 2019-09-10  7:45 UTC (permalink / raw)
  To: jeffrey.t.kirsher; +Cc: netdev, nhorman, sassmann
In-Reply-To: <20190909224802.29595-1-jeffrey.t.kirsher@intel.com>

From: Jeff Kirsher <jeffrey.t.kirsher@intel.com>
Date: Mon,  9 Sep 2019 15:47:47 -0700

> This series contains a variety of cold and hot savoury changes to Intel
> drivers.  Some of the fixes could be considered for stable even though
> the author did not request it.
 ...

Pulled.

^ permalink raw reply

* Re: [PATCH] net/ibmvnic: Fix missing { in __ibmvnic_reset
From: David Miller @ 2019-09-10  7:45 UTC (permalink / raw)
  To: msuchanek
  Cc: netdev, julietk, benh, paulus, mpe, tlfalcon, jallen,
	linuxppc-dev, linux-kernel
In-Reply-To: <20190909204451.7929-1-msuchanek@suse.de>

From: Michal Suchanek <msuchanek@suse.de>
Date: Mon,  9 Sep 2019 22:44:51 +0200

> Commit 1c2977c09499 ("net/ibmvnic: free reset work of removed device from queue")
> adds a } without corresponding { causing build break.
> 
> Fixes: 1c2977c09499 ("net/ibmvnic: free reset work of removed device from queue")
> Signed-off-by: Michal Suchanek <msuchanek@suse.de>

Applied.

^ permalink raw reply

* Re: [PATCH REPOST 1/2] can: flexcan: fix deadlock when using self wakeup
From: Sean Nyekjaer @ 2019-09-10  7:52 UTC (permalink / raw)
  To: Joakim Zhang, mkl@pengutronix.de, linux-can@vger.kernel.org
  Cc: wg@grandegger.com, netdev@vger.kernel.org, dl-linux-imx,
	Martin Hundebøll
In-Reply-To: <DB7PR04MB461868320DA0B25CC8255213E6BB0@DB7PR04MB4618.eurprd04.prod.outlook.com>



On 05/09/2019 09.10, Joakim Zhang wrote:
> Hi Sean,
> 
> Could you update lastest flexcan driver using linux-can-next/flexcan and then merge below two patches from linux-can/testing?
> d0b53616716e (HEAD -> testing, origin/testing) can: flexcan: add LPSR mode support for i.MX7D
> 803eb6bad65b can: flexcan: fix deadlock when using self wakeup
> 
> Best Regards,
> Joakim Zhang

Hi

I reverted 2 commits on thw nand driver and got the testing kernel to work.

I can confirm the issue is resolved with this patch :-)

/Sean

^ permalink raw reply

* Re: [PATCH v3 1/2] ethtool: implement Energy Detect Powerdown support via phy-tunable
From: Michal Kubecek @ 2019-09-10  8:00 UTC (permalink / raw)
  To: netdev
  Cc: Alexandru Ardelean, devicetree, linux-kernel, davem, robh+dt,
	mark.rutland, f.fainelli, hkallweit1, andrew
In-Reply-To: <20190909131251.3634-2-alexandru.ardelean@analog.com>

On Mon, Sep 09, 2019 at 04:12:50PM +0300, Alexandru Ardelean wrote:
> The `phy_tunable_id` has been named `ETHTOOL_PHY_EDPD` since it looks like
> this feature is common across other PHYs (like EEE), and defining
> `ETHTOOL_PHY_ENERGY_DETECT_POWER_DOWN` seems too long.
> 
> The way EDPD works, is that the RX block is put to a lower power mode,
> except for link-pulse detection circuits. The TX block is also put to low
> power mode, but the PHY wakes-up periodically to send link pulses, to avoid
> lock-ups in case the other side is also in EDPD mode.
> 
> Currently, there are 2 PHY drivers that look like they could use this new
> PHY tunable feature: the `adin` && `micrel` PHYs.
> 
> The ADIN's datasheet mentions that TX pulses are at intervals of 1 second
> default each, and they can be disabled. For the Micrel KSZ9031 PHY, the
> datasheet does not mention whether they can be disabled, but mentions that
> they can modified.
> 
> The way this change is structured, is similar to the PHY tunable downshift
> control:
> * a `ETHTOOL_PHY_EDPD_DFLT_TX_INTERVAL` value is exposed to cover a default
>   TX interval; some PHYs could specify a certain value that makes sense
> * `ETHTOOL_PHY_EDPD_NO_TX` would disable TX when EDPD is enabled
> * `ETHTOOL_PHY_EDPD_DISABLE` will disable EDPD
> 
> This should allow PHYs to:
> * enable EDPD and not enable TX pulses (interval would be 0)
> * enable EDPD and configure TX pulse interval; note that TX interval units
>   would be PHY specific; we could consider `seconds` as units, but it could
>   happen that some PHYs would be prefer milliseconds as a unit;
>   a maximum of 65533 units should be sufficient

Sorry for missing the discussion on previous version but I don't really
like the idea of leaving the choice of units to PHY. Both for manual
setting and system configuration, it would be IMHO much more convenient
to have the interpretation universal for all NICs.

Seconds as units seem too coarse and maximum of ~18 hours way too big.
Milliseconds would be more practical from granularity point of view,
would maximum of ~65 seconds be sufficient?

Michal Kubecek

> * disable EDPD
> 
> Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>

^ permalink raw reply

* Re: [PATCH] tcp: fix tcp_disconnect() not clear tp->fastopen_rsk sometimes
From: David Miller @ 2019-09-10  8:09 UTC (permalink / raw)
  To: chunguo.feng
  Cc: edumazet, kuznet, yoshfuji, ast, daniel, netdev, kafai,
	songliubraving, yhs, linux-kernel, bpf
In-Reply-To: <20190906093429.930-1-chunguo.feng@amlogic.com>

From: chunguo feng <chunguo.feng@amlogic.com>
Date: Fri, 6 Sep 2019 17:34:29 +0800

> From: fengchunguo <chunguo.feng@amlogic.com>
> 
> This patch avoids fastopen_rsk not be cleared every times, then occur 
> the below BUG_ON:
> tcp_v4_destroy_sock
> 	->BUG_ON(tp->fastopen_rsk);
> 
> When playback some videos from netwrok,used tcp_disconnect continually.
 ...
> Signed-off-by: fengchunguo <chunguo.feng@amlogic.com>

This still needs review.

^ permalink raw reply

* Re: [PATCH net v2] bridge/mdb: remove wrong use of NLM_F_MULTI
From: David Miller @ 2019-09-10  8:13 UTC (permalink / raw)
  To: nicolas.dichtel; +Cc: roopa, netdev, bridge, nikolay
In-Reply-To: <20190906094703.21300-1-nicolas.dichtel@6wind.com>

From: Nicolas Dichtel <nicolas.dichtel@6wind.com>
Date: Fri,  6 Sep 2019 11:47:02 +0200

> NLM_F_MULTI must be used only when a NLMSG_DONE message is sent at the end.
> In fact, NLMSG_DONE is sent only at the end of a dump.
> 
> Libraries like libnl will wait forever for NLMSG_DONE.
> 
> Fixes: 949f1e39a617 ("bridge: mdb: notify on router port add and del")
> CC: Nikolay Aleksandrov <nikolay@cumulusnetworks.com>
> Signed-off-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>
> Acked-by: Nikolay Aleksandrov <nikolay@cumulusnetworks.com>

Applied and queued up for -stable.

^ permalink raw reply

* Re: [PATCH] net/mlx5: reduce stack usage in FW tracer
From: Arnd Bergmann @ 2019-09-10  8:14 UTC (permalink / raw)
  To: Saeed Mahameed
  Cc: cai@lca.pw, linux-rdma@vger.kernel.org, davem@davemloft.net,
	Moshe Shemesh, Feras Daoud, linux-kernel@vger.kernel.org,
	Eran Ben Elisha, netdev@vger.kernel.org, leon@kernel.org,
	Erez Shitrit
In-Reply-To: <5abccf6452a9d4efa2a1593c0af6d41703d4f16f.camel@mellanox.com>

On Mon, Sep 9, 2019 at 11:53 PM Saeed Mahameed <saeedm@mellanox.com> wrote:
> On Mon, 2019-09-09 at 22:18 +0200, Arnd Bergmann wrote:

> > To do this right, a better approach may be to just rely on ftrace,
> > storing
> > the (pointer to the) format string and the arguments in the buffer
> > without
> > creating a string. Would that be an option here?
>
> I am not sure how this would work, since the format parameters can
> changes depending on the FW string and the specific traces.

Ah, so the format string comes from the firmware? I didn't look
at the code in enough detail to understand why it's done like this,
only enough to notice that it's rather unusual.

Possibly trace_mlx5_fw might still get away with copying the format
string and the arguments, leaving the snprintf() to the time we read
the buffer, but I don't know enough about ftrace to be sure that
would actually work, and you'd need to duplicate it in
mlx5_devlink_fmsg_fill_trace().

> > A more minimal approach might be to move what is now the on-stack
> > buffer into the mlx5_fw_tracer function. I see that you already store
> > a copy of the string in there from mlx5_fw_tracer_save_trace(),
> > which conveniently also holds a mutex already that protects
> > it from concurrent access.
> >
>
> This sounds plausible.
>
> So for now let's do this or the noinline approach, Please let me know
> which one do you prefer, if it is the mutex protected buffer, i can do
> it myself.
>
> I will open an internal task and discussion then address your valuable
> points in a future submission, since we already in rc8 I don't want to
> take the risk now.

Yes, that sounds like a good plan. If you can't avoid the snprintf
entirely, then the mutex protected buffer should be helpful, and
also avoid a strncpy() along with the stack buffer.

      Arnd

^ permalink raw reply

* [RFC PATCH 0/4] mdev based hardware virtio offloading support
From: Jason Wang @ 2019-09-10  8:19 UTC (permalink / raw)
  To: mst, jasowang, kvm, virtualization, netdev
  Cc: linux-kernel, kwankhede, alex.williamson, cohuck, tiwei.bie,
	maxime.coquelin, cunming.liang, zhihong.wang, rob.miller, idos,
	xiao.w.wang, haotian.wang

Hi all:

There are hardware that can do virtio datapath offloading while having
its own control path. This path tries to implement a mdev based
unified API to support using kernel virtio driver to drive those
devices. This is done by introducing a new mdev transport for virtio
(virtio_mdev) and register itself as a new kind of mdev driver. Then
it provides a unified way for kernel virtio driver to talk with mdev
device implementation.

Though the series only contain kernel driver support, the goal is to
make the transport generic enough to support userspace drivers. This
means vhost-mdev[1] could be built on top as well by resuing the
transport.

A sample driver is also implemented which simulate a virito-net
loopback ethernet device on top of vringh + workqueue. This could be
used as a reference implementation for real hardware driver.

Notes:

- Some of the key transport command for vhost-mdev(userspace driver)
  is not introduced. This includes:
  1) set/get virtqueue state (idx etc), this could be simply done by
     introducing new transport command
  2) dirty pages tracking, could be simply done by introducing new
     transport command
  3) set/get device internal state, this requires more thought, of
     course we can introduce device specific transport command, but it
     would be better to have a unified API
- Current mdev_parent_ops assumes all pointers are userspace pointer,
  this block the kernel driver, this series just abuse those as kernel
  pointer and this could be addressed by inventing new parent_ops.
- For quick POC, mdev transport was just derived from virtio-MMIO,
  I'm pretty sure it has lots of space to be optimized, please share
  your thought.

Please review.

[1] https://lkml.org/lkml/2019/8/28/35

Jason Wang (4):
  vringh: fix copy direction of vringh_iov_push_kern()
  mdev: introduce helper to set per device dma ops
  virtio: introudce a mdev based transport
  docs: Sample driver to demonstrate how to implement virtio-mdev
    framework

 drivers/vfio/mdev/Kconfig        |   7 +
 drivers/vfio/mdev/Makefile       |   1 +
 drivers/vfio/mdev/mdev_core.c    |   7 +
 drivers/vfio/mdev/virtio_mdev.c  | 500 ++++++++++++++++++++
 drivers/vhost/vringh.c           |   8 +-
 include/linux/mdev.h             |   2 +
 include/uapi/linux/virtio_mdev.h | 131 ++++++
 samples/Kconfig                  |   7 +
 samples/vfio-mdev/Makefile       |   1 +
 samples/vfio-mdev/mvnet.c        | 766 +++++++++++++++++++++++++++++++
 10 files changed, 1429 insertions(+), 1 deletion(-)
 create mode 100644 drivers/vfio/mdev/virtio_mdev.c
 create mode 100644 include/uapi/linux/virtio_mdev.h
 create mode 100644 samples/vfio-mdev/mvnet.c

-- 
2.19.1


^ permalink raw reply

* [RFC PATCH 1/4] vringh: fix copy direction of vringh_iov_push_kern()
From: Jason Wang @ 2019-09-10  8:19 UTC (permalink / raw)
  To: mst, jasowang, kvm, virtualization, netdev
  Cc: linux-kernel, kwankhede, alex.williamson, cohuck, tiwei.bie,
	maxime.coquelin, cunming.liang, zhihong.wang, rob.miller, idos,
	xiao.w.wang, haotian.wang
In-Reply-To: <20190910081935.30516-1-jasowang@redhat.com>

We want to copy from iov to buf, so the direction was wrong.

Signed-off-by: Jason Wang <jasowang@redhat.com>
---
 drivers/vhost/vringh.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/drivers/vhost/vringh.c b/drivers/vhost/vringh.c
index 08ad0d1f0476..a0a2d74967ef 100644
--- a/drivers/vhost/vringh.c
+++ b/drivers/vhost/vringh.c
@@ -852,6 +852,12 @@ static inline int xfer_kern(void *src, void *dst, size_t len)
 	return 0;
 }
 
+static inline int kern_xfer(void *dst, void *src, size_t len)
+{
+	memcpy(dst, src, len);
+	return 0;
+}
+
 /**
  * vringh_init_kern - initialize a vringh for a kernelspace vring.
  * @vrh: the vringh to initialize.
@@ -958,7 +964,7 @@ EXPORT_SYMBOL(vringh_iov_pull_kern);
 ssize_t vringh_iov_push_kern(struct vringh_kiov *wiov,
 			     const void *src, size_t len)
 {
-	return vringh_iov_xfer(wiov, (void *)src, len, xfer_kern);
+	return vringh_iov_xfer(wiov, (void *)src, len, kern_xfer);
 }
 EXPORT_SYMBOL(vringh_iov_push_kern);
 
-- 
2.19.1


^ permalink raw reply related

* Re: ❌ FAIL: Stable queue: queue-5.2
From: Hangbin Liu @ 2019-09-10  8:19 UTC (permalink / raw)
  To: CKI Project
  Cc: Linux Stable maillist, netdev, Jan Stancek, Xiumei Mu,
	David Howells, linux-afs
In-Reply-To: <cki.77A5953448.UY7ROQ6BKT@redhat.com>

On Wed, Aug 28, 2019 at 08:36:14AM -0400, CKI Project wrote:
> 
> Hello,
> 
> We ran automated tests on a patchset that was proposed for merging into this
> kernel tree. The patches were applied to:
> 
>        Kernel repo: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
>             Commit: f7d5b3dc4792 - Linux 5.2.10
> 
> The results of these automated tests are provided below.
> 
>     Overall result: FAILED (see details below)
>              Merge: OK
>            Compile: OK
>              Tests: FAILED
> 
> All kernel binaries, config files, and logs are available for download here:
> 
>   https://artifacts.cki-project.org/pipelines/128519
> 
> 
> 
> One or more kernel tests failed:
> 
>   x86_64:
>     ❌ Networking socket: fuzz

Sorry, maybe the info is a little late, I just found the call traces for this
failure.


[ 9492.446228] BUG: kernel NULL pointer dereference, address: 0000000000000010 
[ 9492.447493] #PF: supervisor write access in kernel mode 
[ 9492.448489] #PF: error_code(0x0002) - not-present page 
[ 9492.449410] PGD 800000010902c067 P4D 800000010902c067 PUD 104202067 PMD 0  
[ 9492.450663] Oops: 0002 [#1] SMP PTI 
[ 9492.451348] CPU: 0 PID: 19353 Comm: socket Tainted: G        W         5.2.10-f7d5b3d.cki #1 
[ 9492.453040] Hardware name: Red Hat KVM, BIOS 0.5.1 01/01/2011 
[ 9492.454153] RIP: 0010:rxrpc_unuse_local+0xa/0x20 [rxrpc] 
[ 9492.455110] Code: ce e9 c4 fe ff ff 0f 0b e9 34 dd 00 00 e9 95 dd 00 00 66 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 00 0f 1f 44 00 00 b8 ff ff ff ff <3e> 0f c1 47 10 83 f8 01 74 05 e9 a7 f5 ff ff e9 e2 f7 ff ff 66 90 
[ 9492.458362] RSP: 0018:ffffa756008bbeb0 EFLAGS: 00010246 
[ 9492.459329] RAX: 00000000ffffffff RBX: ffff95fed42c0000 RCX: ffffc755ffc63b37 
[ 9492.460690] RDX: 0000000000000001 RSI: 0000000000000046 RDI: 0000000000000000 
[ 9492.461940] RBP: ffff95ff04fed000 R08: 0000000000000001 R09: ffffc755ffc63b60 
[ 9492.463220] R10: 0000000000000060 R11: 0000000000000000 R12: ffff95ff04fed0e4 
[ 9492.464508] R13: ffff95feaa84c780 R14: 0000000000000000 R15: 0000000000000000 
[ 9492.465781] FS:  00007f86bd101740(0000) GS:ffff95ffbba00000(0000) knlGS:0000000000000000 
[ 9492.467156] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033 
[ 9492.468185] CR2: 0000000000000010 CR3: 000000002e34a004 CR4: 00000000007606f0 
[ 9492.469435] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 
[ 9492.470754] DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 
[ 9492.472050] PKRU: 55555554 
[ 9492.472562] Call Trace: 
[ 9492.473025]  rxrpc_release+0x138/0x1e0 [rxrpc] 
[ 9492.473885]  __sock_release+0x89/0xa0 
[ 9492.474564]  __sys_socket+0xd4/0xf0 
[ 9492.475200]  __x64_sys_socket+0x16/0x20 
[ 9492.475903]  do_syscall_64+0x5f/0x1a0 
[ 9492.476551]  entry_SYSCALL_64_after_hwframe+0x44/0xa9 
[ 9492.477446] RIP: 0033:0x7f86bd20069b 
[ 9492.478094] Code: 73 01 c3 48 8b 0d ed 37 0c 00 f7 d8 64 89 01 48 83 c8 ff c3 66 2e 0f 1f 84 00 00 00 00 00 90 f3 0f 1e fa b8 29 00 00 00 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 8b 0d bd 37 0c 00 f7 d8 64 89 01 48 
[ 9492.481381] RSP: 002b:00007ffcbb797dc8 EFLAGS: 00000217 ORIG_RAX: 0000000000000029 
[ 9492.482744] RAX: ffffffffffffffda RBX: 0000000000000000 RCX: 00007f86bd20069b 
[ 9492.483945] RDX: 000000000000000a RSI: 0000000000000002 RDI: 0000000000000021 
[ 9492.485220] RBP: 00007ffcbb797e10 R08: 00007f86bd2c41f4 R09: 00007f86bd2c4260 
[ 9492.486505] R10: 00000000ffffffff R11: 0000000000000217 R12: 00000000004012b0 
[ 9492.487769] R13: 00007ffcbb797ef0 R14: 0000000000000000 R15: 0000000000000000 
[ 9492.489048] Modules linked in: nfnetlink cmtp kernelcapi l2tp_ip6 l2tp_ip rfcomm pptp gre l2tp_ppp l2tp_netlink l2tp_core ip6_udp_tunnel udp_tunnel bnep can_bcm hidp can_raw kcm pppoe pppox ppp_generic slhc vmw_vsock_vmci_transport vsock vmw_vmci psnap ieee802154_socket ieee802154 rose bluetooth ecdh_generic ecc mpls_router ip_tunnel netrom ax25 smc ib_core af_key fcrypt pcbc rxrpc nfc rfkill atm can mlx4_en mlx4_core nls_utf8 isofs dummy minix binfmt_misc nfsv3 nfs_acl nfs lockd grace fscache sctp rds brd vfat fat btrfs xor zstd_compress raid6_pq zstd_decompress loop tun ip6table_nat ip6_tables xt_conntrack iptable_filter xt_MASQUERADE xt_comment iptable_nat nf_nat nf_conntrack nf_defrag_ipv6 nf_defrag_ipv4 veth bridge stp llc overlay fuse nfit libnvdimm sunrpc crct10dif_pclmul crc32_pclmul ghash_clmulni_intel virtio_net pcspkr net_failover joydev failover virtio_balloon i2c_piix4 ip_tables xfs libcrc32c qxl drm_kms_helper ttm drm crc32c_intel virtio_blk serio_raw ata_generic pat
 a_acpi 
[ 9492.489083]  floppy qemu_fw_cfg [last unloaded: can] 
[ 9492.505349] CR2: 0000000000000010 
[ 9492.505948] ---[ end trace afa9902ac3c49830 ]--- 

Thanks
Hangbin
> 
> We hope that these logs can help you find the problem quickly. For the full
> detail on our testing procedures, please scroll to the bottom of this message.
> 
> Please reply to this email if you have any questions about the tests that we
> ran or if you have any suggestions on how to make future tests more effective.
> 
>         ,-.   ,-.
>        ( C ) ( K )  Continuous
>         `-',-.`-'   Kernel
>           ( I )     Integration
>            `-'
> ______________________________________________________________________________
> 
> Merge testing
> -------------
> 
> We cloned this repository and checked out the following commit:
> 
>   Repo: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
>   Commit: f7d5b3dc4792 - Linux 5.2.10
> 
> 
> We grabbed the 54831dad38d2 commit of the stable queue repository.
> 
> We then merged the patchset with `git am`:
> 
>   asoc-simple_card_utils.h-care-null-dai-at-asoc_simpl.patch
>   asoc-simple-card-fix-an-use-after-free-in-simple_dai.patch
>   asoc-simple-card-fix-an-use-after-free-in-simple_for.patch
>   asoc-audio-graph-card-fix-use-after-free-in-graph_da.patch
>   asoc-audio-graph-card-fix-an-use-after-free-in-graph.patch
>   asoc-audio-graph-card-add-missing-const-at-graph_get.patch
>   regulator-axp20x-fix-dcdca-and-dcdcd-for-axp806.patch
>   regulator-axp20x-fix-dcdc5-and-dcdc6-for-axp803.patch
>   asoc-samsung-odroid-fix-an-use-after-free-issue-for-.patch
>   asoc-samsung-odroid-fix-a-double-free-issue-for-cpu_.patch
>   asoc-intel-bytcht_es8316-add-quirk-for-irbis-nb41-ne.patch
>   hid-logitech-hidpp-add-usb-pid-for-a-few-more-suppor.patch
>   hid-add-044f-b320-thrustmaster-inc.-2-in-1-dt.patch
>   mips-kernel-only-use-i8253-clocksource-with-periodic.patch
>   mips-fix-cacheinfo.patch
>   libbpf-sanitize-var-to-conservative-1-byte-int.patch
>   netfilter-ebtables-fix-a-memory-leak-bug-in-compat.patch
>   asoc-dapm-fix-handling-of-custom_stop_condition-on-d.patch
>   asoc-sof-use-__u32-instead-of-uint32_t-in-uapi-heade.patch
>   spi-pxa2xx-balance-runtime-pm-enable-disable-on-erro.patch
>   bpf-sockmap-sock_map_delete-needs-to-use-xchg.patch
>   bpf-sockmap-synchronize_rcu-before-free-ing-map.patch
>   bpf-sockmap-only-create-entry-if-ulp-is-not-already-.patch
>   selftests-bpf-fix-sendmsg6_prog-on-s390.patch
>   asoc-dapm-fix-a-memory-leak-bug.patch
>   bonding-force-slave-speed-check-after-link-state-rec.patch
>   net-mvpp2-don-t-check-for-3-consecutive-idle-frames-.patch
>   selftests-forwarding-gre_multipath-enable-ipv4-forwa.patch
>   selftests-forwarding-gre_multipath-fix-flower-filter.patch
>   selftests-bpf-add-another-gso_segs-access.patch
>   libbpf-fix-using-uninitialized-ioctl-results.patch
>   can-dev-call-netif_carrier_off-in-register_candev.patch
>   can-mcp251x-add-error-check-when-wq-alloc-failed.patch
>   can-gw-fix-error-path-of-cgw_module_init.patch
>   asoc-fail-card-instantiation-if-dai-format-setup-fai.patch
>   staging-fbtft-fix-gpio-handling.patch
>   libbpf-silence-gcc8-warning-about-string-truncation.patch
>   st21nfca_connectivity_event_received-null-check-the-.patch
>   st_nci_hci_connectivity_event_received-null-check-th.patch
>   nl-mac-80211-fix-interface-combinations-on-crypto-co.patch
>   asoc-ti-davinci-mcasp-fix-clk-pdir-handling-for-i2s-.patch
>   asoc-rockchip-fix-mono-capture.patch
>   asoc-ti-davinci-mcasp-correct-slot_width-posed-const.patch
>   net-usb-qmi_wwan-add-the-broadmobi-bm818-card.patch
>   qed-rdma-fix-the-hw_ver-returned-in-device-attribute.patch
>   isdn-misdn-hfcsusb-fix-possible-null-pointer-derefer.patch
>   habanalabs-fix-f-w-download-in-be-architecture.patch
>   mac80211_hwsim-fix-possible-null-pointer-dereference.patch
>   net-stmmac-manage-errors-returned-by-of_get_mac_addr.patch
>   netfilter-ipset-actually-allow-destination-mac-addre.patch
>   netfilter-ipset-copy-the-right-mac-address-in-bitmap.patch
>   netfilter-ipset-fix-rename-concurrency-with-listing.patch
>   rxrpc-fix-potential-deadlock.patch
>   rxrpc-fix-the-lack-of-notification-when-sendmsg-fail.patch
>   nvmem-use-the-same-permissions-for-eeprom-as-for-nvm.patch
>   iwlwifi-mvm-avoid-races-in-rate-init-and-rate-perfor.patch
>   iwlwifi-dbg_ini-move-iwl_dbg_tlv_load_bin-out-of-deb.patch
>   iwlwifi-dbg_ini-move-iwl_dbg_tlv_free-outside-of-deb.patch
>   iwlwifi-fix-locking-in-delayed-gtk-setting.patch
>   iwlwifi-mvm-send-lq-command-always-async.patch
>   enetc-fix-build-error-without-phylib.patch
>   isdn-hfcsusb-fix-misdn-driver-crash-caused-by-transf.patch
>   net-phy-phy_led_triggers-fix-a-possible-null-pointer.patch
>   perf-bench-numa-fix-cpu0-binding.patch
>   spi-pxa2xx-add-support-for-intel-tiger-lake.patch
>   can-sja1000-force-the-string-buffer-null-terminated.patch
>   can-peak_usb-force-the-string-buffer-null-terminated.patch
>   asoc-amd-acp3x-use-dma_ops-of-parent-device-for-acp3.patch
>   net-ethernet-qlogic-qed-force-the-string-buffer-null.patch
>   enetc-select-phylib-while-config_fsl_enetc_vf-is-set.patch
>   nfsv4-fix-a-credential-refcount-leak-in-nfs41_check_.patch
>   nfsv4-when-recovering-state-fails-with-eagain-retry-.patch
>   nfsv4.1-fix-open-stateid-recovery.patch
>   nfsv4.1-only-reap-expired-delegations.patch
>   nfsv4-fix-a-potential-sleep-while-atomic-in-nfs4_do_.patch
>   nfs-fix-regression-whereby-fscache-errors-are-appear.patch
>   hid-quirks-set-the-increment_usage_on_duplicate-quir.patch
>   hid-input-fix-a4tech-horizontal-wheel-custom-usage.patch
>   drm-rockchip-suspend-dp-late.patch
>   smb3-fix-potential-memory-leak-when-processing-compo.patch
>   smb3-kernel-oops-mounting-a-encryptdata-share-with-c.patch
>   sched-deadline-fix-double-accounting-of-rq-running-b.patch
>   sched-psi-reduce-psimon-fifo-priority.patch
>   sched-psi-do-not-require-setsched-permission-from-th.patch
>   s390-protvirt-avoid-memory-sharing-for-diag-308-set-.patch
>   s390-mm-fix-dump_pagetables-top-level-page-table-wal.patch
>   s390-put-_stext-and-_etext-into-.text-section.patch
>   ata-rb532_cf-fix-unused-variable-warning-in-rb532_pa.patch
>   net-cxgb3_main-fix-a-resource-leak-in-a-error-path-i.patch
>   net-stmmac-fix-issues-when-number-of-queues-4.patch
>   net-stmmac-tc-do-not-return-a-fragment-entry.patch
>   drm-amdgpu-pin-the-csb-buffer-on-hw-init-for-gfx-v8.patch
>   net-hisilicon-make-hip04_tx_reclaim-non-reentrant.patch
>   net-hisilicon-fix-hip04-xmit-never-return-tx_busy.patch
>   net-hisilicon-fix-dma_map_single-failed-on-arm64.patch
>   nfsv4-ensure-state-recovery-handles-etimedout-correc.patch
>   libata-have-ata_scsi_rw_xlat-fail-invalid-passthroug.patch
>   libata-add-sg-safety-checks-in-sff-pio-transfers.patch
>   x86-lib-cpu-address-missing-prototypes-warning.patch
>   drm-vmwgfx-fix-memory-leak-when-too-many-retries-hav.patch
>   block-aoe-fix-kernel-crash-due-to-atomic-sleep-when-.patch
>   block-bfq-handle-null-return-value-by-bfq_init_rq.patch
>   perf-ftrace-fix-failure-to-set-cpumask-when-only-one.patch
>   perf-cpumap-fix-writing-to-illegal-memory-in-handlin.patch
>   perf-pmu-events-fix-missing-cpu_clk_unhalted.core-ev.patch
>   dt-bindings-riscv-fix-the-schema-compatible-string-f.patch
>   kvm-arm64-don-t-write-junk-to-sysregs-on-reset.patch
>   kvm-arm-don-t-write-junk-to-cp15-registers-on-reset.patch
>   selftests-kvm-adding-config-fragments.patch
>   iwlwifi-mvm-disable-tx-amsdu-on-older-nics.patch
>   hid-wacom-correct-misreported-ekr-ring-values.patch
>   hid-wacom-correct-distance-scale-for-2nd-gen-intuos-devices.patch
>   revert-kvm-x86-mmu-zap-only-the-relevant-pages-when-removing-a-memslot.patch
>   revert-dm-bufio-fix-deadlock-with-loop-device.patch
>   clk-socfpga-stratix10-fix-rate-caclulationg-for-cnt_clks.patch
>   ceph-clear-page-dirty-before-invalidate-page.patch
>   ceph-don-t-try-fill-file_lock-on-unsuccessful-getfilelock-reply.patch
>   libceph-fix-pg-split-vs-osd-re-connect-race.patch
>   drm-amdgpu-gfx9-update-pg_flags-after-determining-if-gfx-off-is-possible.patch
>   drm-nouveau-don-t-retry-infinitely-when-receiving-no-data-on-i2c-over-aux.patch
>   scsi-ufs-fix-null-pointer-dereference-in-ufshcd_config_vreg_hpm.patch
>   gpiolib-never-report-open-drain-source-lines-as-input-to-user-space.patch
>   drivers-hv-vmbus-fix-virt_to_hvpfn-for-x86_pae.patch
>   userfaultfd_release-always-remove-uffd-flags-and-clear-vm_userfaultfd_ctx.patch
>   x86-retpoline-don-t-clobber-rflags-during-call_nospec-on-i386.patch
>   x86-apic-handle-missing-global-clockevent-gracefully.patch
>   x86-cpu-amd-clear-rdrand-cpuid-bit-on-amd-family-15h-16h.patch
>   x86-boot-save-fields-explicitly-zero-out-everything-else.patch
>   x86-boot-fix-boot-regression-caused-by-bootparam-sanitizing.patch
>   ib-hfi1-unsafe-psn-checking-for-tid-rdma-read-resp-packet.patch
>   ib-hfi1-add-additional-checks-when-handling-tid-rdma-read-resp-packet.patch
>   ib-hfi1-add-additional-checks-when-handling-tid-rdma-write-data-packet.patch
>   ib-hfi1-drop-stale-tid-rdma-packets-that-cause-tiderr.patch
>   psi-get-poll_work-to-run-when-calling-poll-syscall-next-time.patch
>   dm-kcopyd-always-complete-failed-jobs.patch
>   dm-dust-use-dust-block-size-for-badblocklist-index.patch
>   dm-btree-fix-order-of-block-initialization-in-btree_split_beneath.patch
>   dm-integrity-fix-a-crash-due-to-bug_on-in-__journal_read_write.patch
>   dm-raid-add-missing-cleanup-in-raid_ctr.patch
>   dm-space-map-metadata-fix-missing-store-of-apply_bops-return-value.patch
>   dm-table-fix-invalid-memory-accesses-with-too-high-sector-number.patch
>   dm-zoned-improve-error-handling-in-reclaim.patch
>   dm-zoned-improve-error-handling-in-i-o-map-code.patch
>   dm-zoned-properly-handle-backing-device-failure.patch
>   genirq-properly-pair-kobject_del-with-kobject_add.patch
>   mm-z3fold.c-fix-race-between-migration-and-destruction.patch
>   mm-page_alloc-move_freepages-should-not-examine-struct-page-of-reserved-memory.patch
>   mm-memcontrol-flush-percpu-vmstats-before-releasing-memcg.patch
>   mm-memcontrol-flush-percpu-vmevents-before-releasing-memcg.patch
>   mm-page_owner-handle-thp-splits-correctly.patch
>   mm-zsmalloc.c-migration-can-leave-pages-in-zs_empty-indefinitely.patch
>   mm-zsmalloc.c-fix-race-condition-in-zs_destroy_pool.patch
>   mm-kasan-fix-false-positive-invalid-free-reports-with-config_kasan_sw_tags-y.patch
>   xfs-fix-missing-ilock-unlock-when-xfs_setattr_nonsize-fails-due-to-edquot.patch
>   ib-hfi1-drop-stale-tid-rdma-packets.patch
>   dm-zoned-fix-potential-null-dereference-in-dmz_do_re.patch
>   io_uring-fix-potential-hang-with-polled-io.patch
>   io_uring-don-t-enter-poll-loop-if-we-have-cqes-pendi.patch
>   io_uring-add-need_resched-check-in-inner-poll-loop.patch
>   powerpc-allow-flush_-inval_-dcache_range-to-work-across-ranges-4gb.patch
>   rxrpc-fix-local-endpoint-refcounting.patch
>   rxrpc-fix-read-after-free-in-rxrpc_queue_local.patch
>   rxrpc-fix-local-endpoint-replacement.patch
> 
> Compile testing
> ---------------
> 
> We compiled the kernel for 3 architectures:
> 
>     aarch64:
>       make options: -j30 INSTALL_MOD_STRIP=1 targz-pkg
> 
>     ppc64le:
>       make options: -j30 INSTALL_MOD_STRIP=1 targz-pkg
> 
>     x86_64:
>       make options: -j30 INSTALL_MOD_STRIP=1 targz-pkg
> 
> 
> Hardware testing
> ----------------
> We booted each kernel and ran the following tests:
> 
>   aarch64:
>       Host 1:
>          ✅ Boot test [0]
>          ✅ xfstests: xfs [1]
>          ✅ selinux-policy: serge-testsuite [2]
>          ✅ lvm thinp sanity [3]
>          ✅ storage: software RAID testing [4]
>          🚧 ✅ Storage blktests [5]
> 
>       Host 2:
> 
>          ⚡ Internal infrastructure issues prevented one or more tests (marked
>          with ⚡⚡⚡) from running on this architecture.
>          This is not the fault of the kernel that was tested.
> 
>          ⚡⚡⚡ Boot test [0]
>          ⚡⚡⚡ Podman system integration test (as root) [6]
>          ⚡⚡⚡ Podman system integration test (as user) [6]
>          ⚡⚡⚡ Loopdev Sanity [7]
>          ⚡⚡⚡ jvm test suite [8]
>          ⚡⚡⚡ AMTU (Abstract Machine Test Utility) [9]
>          ⚡⚡⚡ LTP: openposix test suite [10]
>          ⚡⚡⚡ Ethernet drivers sanity [11]
>          ⚡⚡⚡ Networking socket: fuzz [12]
>          ⚡⚡⚡ audit: audit testsuite test [13]
>          ⚡⚡⚡ httpd: mod_ssl smoke sanity [14]
>          ⚡⚡⚡ iotop: sanity [15]
>          ⚡⚡⚡ tuned: tune-processes-through-perf [16]
>          ⚡⚡⚡ Usex - version 1.9-29 [17]
>          ⚡⚡⚡ storage: SCSI VPD [18]
>          ⚡⚡⚡ stress: stress-ng [19]
>          🚧 ⚡⚡⚡ LTP lite [20]
> 
> 
>   ppc64le:
>       Host 1:
>          ✅ Boot test [0]
>          ✅ xfstests: xfs [1]
>          ✅ selinux-policy: serge-testsuite [2]
>          ✅ lvm thinp sanity [3]
>          ✅ storage: software RAID testing [4]
>          🚧 ✅ Storage blktests [5]
> 
>       Host 2:
>          ✅ Boot test [0]
>          ✅ Podman system integration test (as root) [6]
>          ✅ Podman system integration test (as user) [6]
>          ✅ Loopdev Sanity [7]
>          ✅ jvm test suite [8]
>          ✅ AMTU (Abstract Machine Test Utility) [9]
>          ✅ LTP: openposix test suite [10]
>          ✅ Ethernet drivers sanity [11]
>          ✅ Networking socket: fuzz [12]
>          ✅ audit: audit testsuite test [13]
>          ✅ httpd: mod_ssl smoke sanity [14]
>          ✅ iotop: sanity [15]
>          ✅ tuned: tune-processes-through-perf [16]
>          ✅ Usex - version 1.9-29 [17]
>          🚧 ✅ LTP lite [20]
> 
> 
>   x86_64:
>       Host 1:
>          ✅ Boot test [0]
>          ✅ Podman system integration test (as root) [6]
>          ✅ Podman system integration test (as user) [6]
>          ✅ Loopdev Sanity [7]
>          ✅ jvm test suite [8]
>          ✅ AMTU (Abstract Machine Test Utility) [9]
>          ✅ LTP: openposix test suite [10]
>          ✅ Ethernet drivers sanity [11]
>          ❌ Networking socket: fuzz [12]
>          ⚡⚡⚡ audit: audit testsuite test [13]
>          ⚡⚡⚡ httpd: mod_ssl smoke sanity [14]
>          ⚡⚡⚡ iotop: sanity [15]
>          ⚡⚡⚡ tuned: tune-processes-through-perf [16]
>          ⚡⚡⚡ pciutils: sanity smoke test [21]
>          ⚡⚡⚡ Usex - version 1.9-29 [17]
>          ⚡⚡⚡ storage: SCSI VPD [18]
>          ⚡⚡⚡ stress: stress-ng [19]
>          🚧 ❌ LTP lite [20]
> 
>       Host 2:
>          ✅ Boot test [0]
>          ✅ xfstests: xfs [1]
>          ✅ selinux-policy: serge-testsuite [2]
>          ✅ lvm thinp sanity [3]
>          ✅ storage: software RAID testing [4]
>          🚧 ✅ Storage blktests [5]
> 
> 
>   Test source:
>     💚 Pull requests are welcome for new tests or improvements to existing tests!
>     [0]: https://github.com/CKI-project/tests-beaker/archive/master.zip#distribution/kpkginstall
>     [1]: https://github.com/CKI-project/tests-beaker/archive/master.zip#/filesystems/xfs/xfstests
>     [2]: https://github.com/CKI-project/tests-beaker/archive/master.zip#/packages/selinux-policy/serge-testsuite
>     [3]: https://github.com/CKI-project/tests-beaker/archive/master.zip#storage/lvm/thinp/sanity
>     [4]: https://github.com/CKI-project/tests-beaker/archive/master.zip#storage/swraid/trim
>     [5]: https://github.com/CKI-project/tests-beaker/archive/master.zip#storage/blk
>     [6]: https://github.com/CKI-project/tests-beaker/archive/master.zip#/container/podman
>     [7]: https://github.com/CKI-project/tests-beaker/archive/master.zip#filesystems/loopdev/sanity
>     [8]: https://github.com/CKI-project/tests-beaker/archive/master.zip#/jvm
>     [9]: https://github.com/CKI-project/tests-beaker/archive/master.zip#misc/amtu
>     [10]: https://github.com/CKI-project/tests-beaker/archive/master.zip#distribution/ltp/openposix_testsuite
>     [11]: https://github.com/CKI-project/tests-beaker/archive/master.zip#/networking/driver/sanity
>     [12]: https://github.com/CKI-project/tests-beaker/archive/master.zip#/networking/socket/fuzz
>     [13]: https://github.com/CKI-project/tests-beaker/archive/master.zip#packages/audit/audit-testsuite
>     [14]: https://github.com/CKI-project/tests-beaker/archive/master.zip#packages/httpd/mod_ssl-smoke
>     [15]: https://github.com/CKI-project/tests-beaker/archive/master.zip#packages/iotop/sanity
>     [16]: https://github.com/CKI-project/tests-beaker/archive/master.zip#packages/tuned/tune-processes-through-perf
>     [17]: https://github.com/CKI-project/tests-beaker/archive/master.zip#standards/usex/1.9-29
>     [18]: https://github.com/CKI-project/tests-beaker/archive/master.zip#storage/scsi/vpd
>     [19]: https://github.com/CKI-project/tests-beaker/archive/master.zip#stress/stress-ng
>     [20]: https://github.com/CKI-project/tests-beaker/archive/master.zip#distribution/ltp-upstream/lite
>     [21]: https://github.com/CKI-project/tests-beaker/archive/master.zip#pciutils/sanity-smoke
> 
> Waived tests
> ------------
> If the test run included waived tests, they are marked with 🚧. Such tests are
> executed but their results are not taken into account. Tests are waived when
> their results are not reliable enough, e.g. when they're just introduced or are
> being fixed.

^ permalink raw reply

* [RFC PATCH 2/4] mdev: introduce helper to set per device dma ops
From: Jason Wang @ 2019-09-10  8:19 UTC (permalink / raw)
  To: mst, jasowang, kvm, virtualization, netdev
  Cc: linux-kernel, kwankhede, alex.williamson, cohuck, tiwei.bie,
	maxime.coquelin, cunming.liang, zhihong.wang, rob.miller, idos,
	xiao.w.wang, haotian.wang
In-Reply-To: <20190910081935.30516-1-jasowang@redhat.com>

This patch introduces mdev_set_dma_ops() which allows parent to set
per device DMA ops. This help for the kernel driver to setup a correct
DMA mappings.

Signed-off-by: Jason Wang <jasowang@redhat.com>
---
 drivers/vfio/mdev/mdev_core.c | 7 +++++++
 include/linux/mdev.h          | 2 ++
 2 files changed, 9 insertions(+)

diff --git a/drivers/vfio/mdev/mdev_core.c b/drivers/vfio/mdev/mdev_core.c
index b558d4cfd082..eb28552082d7 100644
--- a/drivers/vfio/mdev/mdev_core.c
+++ b/drivers/vfio/mdev/mdev_core.c
@@ -13,6 +13,7 @@
 #include <linux/uuid.h>
 #include <linux/sysfs.h>
 #include <linux/mdev.h>
+#include <linux/dma-mapping.h>
 
 #include "mdev_private.h"
 
@@ -27,6 +28,12 @@ static struct class_compat *mdev_bus_compat_class;
 static LIST_HEAD(mdev_list);
 static DEFINE_MUTEX(mdev_list_lock);
 
+void mdev_set_dma_ops(struct mdev_device *mdev, struct dma_map_ops *ops)
+{
+	set_dma_ops(&mdev->dev, ops);
+}
+EXPORT_SYMBOL(mdev_set_dma_ops);
+
 struct device *mdev_parent_dev(struct mdev_device *mdev)
 {
 	return mdev->parent->dev;
diff --git a/include/linux/mdev.h b/include/linux/mdev.h
index 0ce30ca78db0..7195f40bf8bf 100644
--- a/include/linux/mdev.h
+++ b/include/linux/mdev.h
@@ -145,4 +145,6 @@ struct device *mdev_parent_dev(struct mdev_device *mdev);
 struct device *mdev_dev(struct mdev_device *mdev);
 struct mdev_device *mdev_from_dev(struct device *dev);
 
+void mdev_set_dma_ops(struct mdev_device *mdev, struct dma_map_ops *ops);
+
 #endif /* MDEV_H */
-- 
2.19.1


^ permalink raw reply related

* [RFC PATCH 3/4] virtio: introudce a mdev based transport
From: Jason Wang @ 2019-09-10  8:19 UTC (permalink / raw)
  To: mst, jasowang, kvm, virtualization, netdev
  Cc: linux-kernel, kwankhede, alex.williamson, cohuck, tiwei.bie,
	maxime.coquelin, cunming.liang, zhihong.wang, rob.miller, idos,
	xiao.w.wang, haotian.wang
In-Reply-To: <20190910081935.30516-1-jasowang@redhat.com>

This path introduces a new mdev transport for virtio. This is used to
use kernel virtio driver to drive the mediated device that is capable
of populating virtqueue directly.

A new virtio-mdev driver will be registered to the mdev bus, when a
new virtio-mdev device is probed, it will register the device with
mdev based config ops. This means, unlike the exist hardware
transport, this is a software transport between mdev driver and mdev
device. The transport was implemented through:

- configuration access was implemented through parent_ops->read()/write()
- vq/config callback was implemented through parent_ops->ioctl()

This transport is derived from virtio MMIO protocol and was wrote for
kernel driver. But for the transport itself, but the design goal is to
be generic enough to support userspace driver (this part will be added
in the future).

Note:
- current mdev assume all the parameter of parent_ops was from
  userspace. This prevents us from implementing the kernel mdev
  driver. For a quick POC, this patch just abuse those parameter and
  assume the mdev device implementation will treat them as kernel
  pointer. This should be addressed in the formal series by extending
  mdev_parent_ops.
- for a quick POC, I just drive the transport from MMIO, I'm pretty
  there's lot of optimization space for this.

Signed-off-by: Jason Wang <jasowang@redhat.com>
---
 drivers/vfio/mdev/Kconfig        |   7 +
 drivers/vfio/mdev/Makefile       |   1 +
 drivers/vfio/mdev/virtio_mdev.c  | 500 +++++++++++++++++++++++++++++++
 include/uapi/linux/virtio_mdev.h | 131 ++++++++
 4 files changed, 639 insertions(+)
 create mode 100644 drivers/vfio/mdev/virtio_mdev.c
 create mode 100644 include/uapi/linux/virtio_mdev.h

diff --git a/drivers/vfio/mdev/Kconfig b/drivers/vfio/mdev/Kconfig
index 5da27f2100f9..c488c31fc137 100644
--- a/drivers/vfio/mdev/Kconfig
+++ b/drivers/vfio/mdev/Kconfig
@@ -16,3 +16,10 @@ config VFIO_MDEV_DEVICE
 	default n
 	help
 	  VFIO based driver for Mediated devices.
+
+config VIRTIO_MDEV_DEVICE
+	tristate "VIRTIO driver for Mediated devices"
+	depends on VFIO_MDEV && VIRTIO
+	default n
+	help
+	  VIRTIO based driver for Mediated devices.
diff --git a/drivers/vfio/mdev/Makefile b/drivers/vfio/mdev/Makefile
index 101516fdf375..99d31e29c23e 100644
--- a/drivers/vfio/mdev/Makefile
+++ b/drivers/vfio/mdev/Makefile
@@ -4,3 +4,4 @@ mdev-y := mdev_core.o mdev_sysfs.o mdev_driver.o
 
 obj-$(CONFIG_VFIO_MDEV) += mdev.o
 obj-$(CONFIG_VFIO_MDEV_DEVICE) += vfio_mdev.o
+obj-$(CONFIG_VIRTIO_MDEV_DEVICE) += virtio_mdev.o
diff --git a/drivers/vfio/mdev/virtio_mdev.c b/drivers/vfio/mdev/virtio_mdev.c
new file mode 100644
index 000000000000..5ff09089297e
--- /dev/null
+++ b/drivers/vfio/mdev/virtio_mdev.c
@@ -0,0 +1,500 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * VIRTIO based driver for Mediated device
+ *
+ * Copyright (c) 2019, Red Hat. All rights reserved.
+ *     Author: Jason Wang <jasowang@redhat.com>
+ *
+ * Based on Virtio MMIO driver.
+ */
+
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/device.h>
+#include <linux/kernel.h>
+#include <linux/slab.h>
+#include <linux/uuid.h>
+#include <linux/mdev.h>
+#include <linux/virtio.h>
+#include <linux/virtio_config.h>
+#include <linux/virtio_ring.h>
+#include <uapi/linux/virtio_mdev.h>
+#include "mdev_private.h"
+
+#define DRIVER_VERSION  "0.1"
+#define DRIVER_AUTHOR   "Red Hat Corporation"
+#define DRIVER_DESC     "VIRTIO based driver for Mediated device"
+
+#define to_virtio_mdev_device(dev) \
+	container_of(dev, struct virtio_mdev_device, vdev)
+
+struct virtio_mdev_device {
+	struct virtio_device vdev;
+	struct mdev_device *mdev;
+	unsigned long version;
+
+	struct virtqueue **vqs;
+	spinlock_t lock;
+};
+
+struct virtio_mdev_vq_info {
+	/* the actual virtqueue */
+	struct virtqueue *vq;
+
+	/* the list node for the virtqueues list */
+	struct list_head node;
+};
+
+static u32 virtio_mdev_readl(struct mdev_device *mdev,
+			     loff_t off)
+{
+	struct mdev_parent *parent = mdev->parent;
+	ssize_t len;
+	u32 val;
+
+	if (unlikely(!parent->ops->read))
+		return 0xFFFFFFFF;
+
+	len = parent->ops->read(mdev, (char *)&val, 4, &off);
+	if (len != 4)
+		return 0xFFFFFFFF;
+
+	return val;
+}
+
+static void virtio_mdev_writel(struct mdev_device *mdev,
+			       loff_t off, u32 val)
+{
+	struct mdev_parent *parent = mdev->parent;
+
+	if (unlikely(!parent->ops->write))
+		return;
+
+	parent->ops->write(mdev, (char *)&val, 4, &off);
+
+	return;
+}
+
+static void virtio_mdev_get(struct virtio_device *vdev, unsigned offset,
+			    void *buf, unsigned len)
+{
+	struct virtio_mdev_device *vm_dev = to_virtio_mdev_device(vdev);
+	struct mdev_device *mdev = vm_dev->mdev;
+	struct mdev_parent *parent = mdev->parent;
+
+	loff_t off = offset + VIRTIO_MDEV_CONFIG;
+
+	switch (len) {
+	case 1:
+		*(u8 *)buf = parent->ops->read(mdev, buf, 1, &off);
+		break;
+	case 2:
+		*(u16 *)buf = parent->ops->read(mdev, buf, 2, &off);
+		break;
+	case 4:
+		*(u32 *)buf = parent->ops->read(mdev, buf, 4, &off);
+		break;
+	case 8:
+		*(u32 *)buf = parent->ops->read(mdev, buf, 4, &off);
+		*((u32 *)buf + 1) = parent->ops->read(mdev, buf, 4, &off);
+		break;
+	default:
+		BUG();
+	}
+
+	return;
+}
+
+static void virtio_mdev_set(struct virtio_device *vdev, unsigned offset,
+			    const void *buf, unsigned len)
+{
+	struct virtio_mdev_device *vm_dev = to_virtio_mdev_device(vdev);
+	struct mdev_device *mdev = vm_dev->mdev;
+	struct mdev_parent *parent = mdev->parent;
+	loff_t off = offset + VIRTIO_MDEV_CONFIG;
+
+	switch (len) {
+	case 1:
+	case 2:
+	case 4:
+	case 8:
+		break;
+	default:
+		BUG();
+	}
+
+	parent->ops->write(mdev, buf, len, &off);
+
+	return;
+}
+
+static u32 virtio_mdev_generation(struct virtio_device *vdev)
+{
+	struct virtio_mdev_device *vm_dev = to_virtio_mdev_device(vdev);
+
+	if (vm_dev->version == 1)
+		return 0;
+	else
+		return virtio_mdev_readl(vm_dev->mdev,
+					 VIRTIO_MDEV_CONFIG_GENERATION);
+}
+
+static u8 virtio_mdev_get_status(struct virtio_device *vdev)
+{
+	struct virtio_mdev_device *vm_dev = to_virtio_mdev_device(vdev);
+
+	return virtio_mdev_readl(vm_dev->mdev, VIRTIO_MDEV_STATUS) & 0xff;
+}
+
+static void virtio_mdev_set_status(struct virtio_device *vdev, u8 status)
+{
+	struct virtio_mdev_device *vm_dev = to_virtio_mdev_device(vdev);
+
+	virtio_mdev_writel(vm_dev->mdev, VIRTIO_MDEV_STATUS, status);
+}
+
+static void virtio_mdev_reset(struct virtio_device *vdev)
+{
+	struct virtio_mdev_device *vm_dev = to_virtio_mdev_device(vdev);
+
+	virtio_mdev_writel(vm_dev->mdev, VIRTIO_MDEV_STATUS, 0);
+}
+
+static bool virtio_mdev_notify(struct virtqueue *vq)
+{
+	struct virtio_mdev_device *vm_dev = to_virtio_mdev_device(vq->vdev);
+
+	/* We write the queue's selector into the notification register to
+	 * signal the other end */
+	virtio_mdev_writel(vm_dev->mdev, VIRTIO_MDEV_QUEUE_NOTIFY,
+			   vq->index);
+	return true;
+}
+
+static irqreturn_t virtio_mdev_config_cb(void *private)
+{
+	struct virtio_mdev_device *vm_dev = private;
+
+	virtio_config_changed(&vm_dev->vdev);
+
+	return IRQ_HANDLED;
+}
+
+static irqreturn_t virtio_mdev_virtqueue_cb(void *private)
+{
+	struct virtio_mdev_vq_info *info = private;
+
+	return vring_interrupt(0, info->vq);
+}
+
+static struct virtqueue *
+virtio_mdev_setup_vq(struct virtio_device *vdev, unsigned index,
+		     void (*callback)(struct virtqueue *vq),
+		     const char *name, bool ctx)
+{
+	struct virtio_mdev_device *vm_dev = to_virtio_mdev_device(vdev);
+	struct mdev_device *mdev= vm_dev->mdev;
+	struct mdev_parent *parent = mdev->parent;
+	struct virtio_mdev_vq_info *info;
+	struct virtio_mdev_callback cb;
+	struct virtqueue *vq;
+	unsigned long flags;
+	u32 align, num;
+	u64 addr;
+	int err;
+
+	if (!name)
+		return NULL;
+
+	/* Select the queue we're interested in */
+	virtio_mdev_writel(vm_dev->mdev, VIRTIO_MDEV_QUEUE_SEL, index);
+
+	/* Queue shouldn't already be set up. */
+	if (virtio_mdev_readl(vm_dev->mdev, VIRTIO_MDEV_QUEUE_READY)) {
+		err = -ENOENT;
+		goto error_available;
+	}
+
+	/* Allocate and fill out our active queue description */
+	info = kmalloc(sizeof(*info), GFP_KERNEL);
+	if (!info) {
+		err = -ENOMEM;
+		goto error_kmalloc;
+	}
+
+	num = virtio_mdev_readl(vm_dev->mdev, VIRTIO_MDEV_QUEUE_NUM_MAX);
+	if (num == 0) {
+		err = -ENOENT;
+		goto error_new_virtqueue;
+	}
+
+	/* Create the vring */
+	align = virtio_mdev_readl(vm_dev->mdev, VIRTIO_MDEV_QUEUE_ALIGN);
+	vq = vring_create_virtqueue(index, num, align, vdev,
+				    true, true, ctx,
+				    virtio_mdev_notify, callback, name);
+	if (!vq) {
+		err = -ENOMEM;
+		goto error_new_virtqueue;
+	}
+
+	/* Setup virtqueue callback */
+	cb.callback = virtio_mdev_virtqueue_cb;
+	cb.private = info;
+	err = parent->ops->ioctl(mdev, VIRTIO_MDEV_SET_VQ_CALLBACK,
+				 (unsigned long)&cb);
+	if (err) {
+		err = -EINVAL;
+		goto error_callback;
+	}
+
+	virtio_mdev_writel(vm_dev->mdev, VIRTIO_MDEV_QUEUE_NUM,
+			   virtqueue_get_vring_size(vq));
+	addr = virtqueue_get_desc_addr(vq);
+	virtio_mdev_writel(vm_dev->mdev, VIRTIO_MDEV_QUEUE_DESC_LOW, (u32)addr);
+	virtio_mdev_writel(vm_dev->mdev, VIRTIO_MDEV_QUEUE_DESC_HIGH,
+			   (u32)(addr >> 32));
+
+	addr = virtqueue_get_avail_addr(vq);
+	virtio_mdev_writel(vm_dev->mdev, VIRTIO_MDEV_QUEUE_AVAIL_LOW, (u32)addr);
+	virtio_mdev_writel(vm_dev->mdev, VIRTIO_MDEV_QUEUE_AVAIL_HIGH,
+			   (u32)(addr >> 32));
+
+	addr = virtqueue_get_used_addr(vq);
+	virtio_mdev_writel(vm_dev->mdev, VIRTIO_MDEV_QUEUE_USED_LOW, (u32)addr);
+	virtio_mdev_writel(vm_dev->mdev, VIRTIO_MDEV_QUEUE_USED_HIGH, (u32)(addr >> 32));
+
+	virtio_mdev_writel(vm_dev->mdev, VIRTIO_MDEV_QUEUE_READY, 1);
+
+	vq->priv = info;
+	info->vq = vq;
+
+	return vq;
+
+error_callback:
+	vring_del_virtqueue(vq);
+error_new_virtqueue:
+	virtio_mdev_writel(vm_dev->mdev, VIRTIO_MDEV_QUEUE_READY, 0);
+	WARN_ON(virtio_mdev_readl(vm_dev->mdev, VIRTIO_MDEV_QUEUE_READY));
+	kfree(info);
+error_kmalloc:
+error_available:
+	return ERR_PTR(err);
+
+}
+
+static void virtio_mdev_del_vq(struct virtqueue *vq)
+{
+	struct virtio_mdev_device *vm_dev = to_virtio_mdev_device(vq->vdev);
+	struct virtio_mdev_vq_info *info = vq->priv;
+	unsigned long flags;
+	unsigned int index = vq->index;
+
+	/* Select and deactivate the queue */
+	virtio_mdev_writel(vm_dev->mdev, VIRTIO_MDEV_QUEUE_SEL, index);
+	virtio_mdev_writel(vm_dev->mdev,VIRTIO_MDEV_QUEUE_READY, 0);
+	WARN_ON(virtio_mdev_readl(vm_dev->mdev, VIRTIO_MDEV_QUEUE_READY));
+
+	vring_del_virtqueue(vq);
+
+	kfree(info);
+}
+
+static void virtio_mdev_del_vqs(struct virtio_device *vdev)
+{
+	struct virtqueue *vq, *n;
+
+	list_for_each_entry_safe(vq, n, &vdev->vqs, list)
+		virtio_mdev_del_vq(vq);
+
+	return;
+}
+
+static int virtio_mdev_find_vqs(struct virtio_device *vdev, unsigned nvqs,
+				struct virtqueue *vqs[],
+				vq_callback_t *callbacks[],
+				const char * const names[],
+				const bool *ctx,
+				struct irq_affinity *desc)
+{
+	struct virtio_mdev_device *vm_dev = to_virtio_mdev_device(vdev);
+	struct mdev_device *mdev = vm_dev->mdev;
+	struct mdev_parent *parent = mdev->parent;
+	struct virtio_mdev_callback cb;
+	int i, err, queue_idx = 0;
+	vm_dev->vqs = kmalloc_array(queue_idx, sizeof(*vm_dev->vqs),
+				    GFP_KERNEL);
+	if (!vm_dev->vqs)
+		return -ENOMEM;
+
+	for (i = 0; i < nvqs; ++i) {
+		if (!names[i]) {
+			vqs[i] = NULL;
+			continue;
+		}
+
+		vqs[i] = virtio_mdev_setup_vq(vdev, queue_idx++,
+					      callbacks[i], names[i], ctx ?
+					      ctx[i] : false);
+		if (IS_ERR(vqs[i])) {
+			err = PTR_ERR(vqs[i]);
+			goto err_setup_vq;
+		}
+	}
+
+	cb.callback = virtio_mdev_config_cb;
+	cb.private = vm_dev;
+	err = parent->ops->ioctl(mdev, VIRTIO_MDEV_SET_CONFIG_CALLBACK,
+				 (unsigned long)&cb);
+	if (err)
+		goto err_setup_vq;
+
+	return 0;
+
+err_setup_vq:
+	kfree(vm_dev->vqs);
+	virtio_mdev_del_vqs(vdev);
+	return err;
+}
+
+static u64 virtio_mdev_get_features(struct virtio_device *vdev)
+{
+	struct virtio_mdev_device *vm_dev = to_virtio_mdev_device(vdev);
+	u64 features;
+
+	virtio_mdev_writel(vm_dev->mdev, VIRTIO_MDEV_DEVICE_FEATURES_SEL, 1);
+	features = virtio_mdev_readl(vm_dev->mdev, VIRTIO_MDEV_DEVICE_FEATURES);
+	features <<= 32;
+
+	virtio_mdev_writel(vm_dev->mdev, VIRTIO_MDEV_DEVICE_FEATURES_SEL, 0);
+	features |= virtio_mdev_readl(vm_dev->mdev, VIRTIO_MDEV_DEVICE_FEATURES);
+
+	return features;
+}
+
+static int virtio_mdev_finalize_features(struct virtio_device *vdev)
+{
+	struct virtio_mdev_device *vm_dev = to_virtio_mdev_device(vdev);
+
+	/* Give virtio_ring a chance to accept features. */
+	vring_transport_features(vdev);
+
+	virtio_mdev_writel(vm_dev->mdev, VIRTIO_MDEV_DRIVER_FEATURES_SEL, 1);
+	virtio_mdev_writel(vm_dev->mdev, VIRTIO_MDEV_DRIVER_FEATURES,
+			   (u32)(vdev->features >> 32));
+
+	virtio_mdev_writel(vm_dev->mdev, VIRTIO_MDEV_DRIVER_FEATURES_SEL, 0);
+	virtio_mdev_writel(vm_dev->mdev, VIRTIO_MDEV_DRIVER_FEATURES,
+			   (u32)vdev->features);
+
+	return 0;
+}
+
+static const char *virtio_mdev_bus_name(struct virtio_device *vdev)
+{
+	struct virtio_mdev_device *vm_dev = to_virtio_mdev_device(vdev);
+	struct mdev_device *mdev = vm_dev->mdev;
+
+	return dev_name(&mdev->dev);
+}
+
+static const struct virtio_config_ops virtio_mdev_config_ops = {
+	.get		= virtio_mdev_get,
+	.set		= virtio_mdev_set,
+	.generation	= virtio_mdev_generation,
+	.get_status	= virtio_mdev_get_status,
+	.set_status	= virtio_mdev_set_status,
+	.reset		= virtio_mdev_reset,
+	.find_vqs	= virtio_mdev_find_vqs,
+	.del_vqs	= virtio_mdev_del_vqs,
+	.get_features	= virtio_mdev_get_features,
+	.finalize_features = virtio_mdev_finalize_features,
+	.bus_name	= virtio_mdev_bus_name,
+};
+
+static void virtio_mdev_release_dev(struct device *_d)
+{
+	struct virtio_device *vdev =
+	       container_of(_d, struct virtio_device, dev);
+	struct virtio_mdev_device *vm_dev =
+	       container_of(vdev, struct virtio_mdev_device, vdev);
+
+	devm_kfree(_d, vm_dev);
+}
+
+static int virtio_mdev_probe(struct device *dev)
+{
+	struct mdev_device *mdev = to_mdev_device(dev);
+	struct virtio_mdev_device *vm_dev;
+	unsigned long magic;
+	int rc;
+
+	magic = virtio_mdev_readl(mdev, VIRTIO_MDEV_MAGIC_VALUE);
+	if (magic != ('v' | 'i' << 8 | 'r' << 16 | 't' << 24)) {
+		dev_warn(dev, "Wrong magic value 0x%08lx!\n", magic);
+		return -ENODEV;
+	}
+
+	vm_dev = devm_kzalloc(dev, sizeof(*vm_dev), GFP_KERNEL);
+	if (!vm_dev)
+		return -ENOMEM;
+
+	vm_dev->vdev.dev.parent = dev;
+	vm_dev->vdev.dev.release = virtio_mdev_release_dev;
+	vm_dev->vdev.config = &virtio_mdev_config_ops;
+	vm_dev->mdev = mdev;
+	vm_dev->vqs = NULL;
+	spin_lock_init(&vm_dev->lock);
+
+	vm_dev->version = virtio_mdev_readl(mdev, VIRTIO_MDEV_VERSION);
+	if (vm_dev->version != 1) {
+		dev_err(dev, "Version %ld not supported!\n",
+			vm_dev->version);
+		return -ENXIO;
+	}
+
+	vm_dev->vdev.id.device = virtio_mdev_readl(mdev, VIRTIO_MDEV_DEVICE_ID);
+	if (vm_dev->vdev.id.device == 0)
+		return -ENODEV;
+
+	vm_dev->vdev.id.vendor = virtio_mdev_readl(mdev, VIRTIO_MDEV_VENDOR_ID);
+	rc = register_virtio_device(&vm_dev->vdev);
+	if (rc)
+		put_device(dev);
+
+	dev_set_drvdata(dev, vm_dev);
+
+	return rc;
+
+}
+
+static void virtio_mdev_remove(struct device *dev)
+{
+	struct virtio_mdev_device *vm_dev = dev_get_drvdata(dev);
+
+	unregister_virtio_device(&vm_dev->vdev);
+}
+
+static struct mdev_driver virtio_mdev_driver = {
+	.name	= "virtio_mdev",
+	.probe	= virtio_mdev_probe,
+	.remove	= virtio_mdev_remove,
+};
+
+static int __init virtio_mdev_init(void)
+{
+	return mdev_register_driver(&virtio_mdev_driver, THIS_MODULE);
+}
+
+static void __exit virtio_mdev_exit(void)
+{
+	mdev_unregister_driver(&virtio_mdev_driver);
+}
+
+module_init(virtio_mdev_init)
+module_exit(virtio_mdev_exit)
+
+MODULE_VERSION(DRIVER_VERSION);
+MODULE_LICENSE("GPL v2");
+MODULE_AUTHOR(DRIVER_AUTHOR);
+MODULE_DESCRIPTION(DRIVER_DESC);
diff --git a/include/uapi/linux/virtio_mdev.h b/include/uapi/linux/virtio_mdev.h
new file mode 100644
index 000000000000..8040de6b960a
--- /dev/null
+++ b/include/uapi/linux/virtio_mdev.h
@@ -0,0 +1,131 @@
+/*
+ * Virtio mediated device driver
+ *
+ * Copyright 2019, Red Hat Corp.
+ *
+ * Based on Virtio MMIO driver by ARM Ltd, copyright ARM Ltd. 2011
+ *
+ * This header is BSD licensed so anyone can use the definitions to implement
+ * compatible drivers/servers.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of IBM nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL IBM OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+#ifndef _LINUX_VIRTIO_MDEV_H
+#define _LINUX_VIRTIO_MDEV_H
+
+#include <linux/interrupt.h>
+#include <linux/vringh.h>
+#include <uapi/linux/virtio_net.h>
+
+/*
+ * Ioctls
+ */
+
+struct virtio_mdev_callback {
+	irqreturn_t (*callback)(void *);
+	void *private;
+};
+
+#define VIRTIO_MDEV 0xAF
+#define VIRTIO_MDEV_SET_VQ_CALLBACK _IOW(VIRTIO_MDEV, 0x00, \
+					 struct virtio_mdev_callback)
+#define VIRTIO_MDEV_SET_CONFIG_CALLBACK _IOW(VIRTIO_MDEV, 0x01, \
+					struct virtio_mdev_callback)
+
+#define VIRTIO_MDEV_DEVICE_API_STRING		"virtio-mdev"
+
+/*
+ * Control registers
+ */
+
+/* Magic value ("virt" string) - Read Only */
+#define VIRTIO_MDEV_MAGIC_VALUE		0x000
+
+/* Virtio device version - Read Only */
+#define VIRTIO_MDEV_VERSION		0x004
+
+/* Virtio device ID - Read Only */
+#define VIRTIO_MDEV_DEVICE_ID		0x008
+
+/* Virtio vendor ID - Read Only */
+#define VIRTIO_MDEV_VENDOR_ID		0x00c
+
+/* Bitmask of the features supported by the device (host)
+ * (32 bits per set) - Read Only */
+#define VIRTIO_MDEV_DEVICE_FEATURES	0x010
+
+/* Device (host) features set selector - Write Only */
+#define VIRTIO_MDEV_DEVICE_FEATURES_SEL	0x014
+
+/* Bitmask of features activated by the driver (guest)
+ * (32 bits per set) - Write Only */
+#define VIRTIO_MDEV_DRIVER_FEATURES	0x020
+
+/* Activated features set selector - Write Only */
+#define VIRTIO_MDEV_DRIVER_FEATURES_SEL	0x024
+
+/* Queue selector - Write Only */
+#define VIRTIO_MDEV_QUEUE_SEL		0x030
+
+/* Maximum size of the currently selected queue - Read Only */
+#define VIRTIO_MDEV_QUEUE_NUM_MAX	0x034
+
+/* Queue size for the currently selected queue - Write Only */
+#define VIRTIO_MDEV_QUEUE_NUM		0x038
+
+/* Ready bit for the currently selected queue - Read Write */
+#define VIRTIO_MDEV_QUEUE_READY		0x044
+
+/* Alignment of virtqueue - Read Only */
+#define VIRTIO_MDEV_QUEUE_ALIGN		0x048
+
+/* Queue notifier - Write Only */
+#define VIRTIO_MDEV_QUEUE_NOTIFY	0x050
+
+/* Device status register - Read Write */
+#define VIRTIO_MDEV_STATUS		0x060
+
+/* Selected queue's Descriptor Table address, 64 bits in two halves */
+#define VIRTIO_MDEV_QUEUE_DESC_LOW	0x080
+#define VIRTIO_MDEV_QUEUE_DESC_HIGH	0x084
+
+/* Selected queue's Available Ring address, 64 bits in two halves */
+#define VIRTIO_MDEV_QUEUE_AVAIL_LOW	0x090
+#define VIRTIO_MDEV_QUEUE_AVAIL_HIGH	0x094
+
+/* Selected queue's Used Ring address, 64 bits in two halves */
+#define VIRTIO_MDEV_QUEUE_USED_LOW	0x0a0
+#define VIRTIO_MDEV_QUEUE_USED_HIGH	0x0a4
+
+/* Configuration atomicity value */
+#define VIRTIO_MDEV_CONFIG_GENERATION	0x0fc
+
+/* The config space is defined by each driver as
+ * the per-driver configuration space - Read Write */
+#define VIRTIO_MDEV_CONFIG		0x100
+
+#endif
+
+
+/* Ready bit for the currently selected queue - Read Write */
-- 
2.19.1


^ permalink raw reply related


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