* Re: ❌ FAIL: Stable queue: queue-5.2
From: Hangbin Liu @ 2019-09-10 9:30 UTC (permalink / raw)
To: Greg KH
Cc: CKI Project, Linux Stable maillist, netdev, Jan Stancek,
Xiumei Mu, David Howells, linux-afs, Sasha Levin
In-Reply-To: <20190910085810.GA3593@kroah.com>
On Tue, Sep 10, 2019 at 09:58:10AM +0100, Greg KH wrote:
> On Tue, Sep 10, 2019 at 04:19:56PM +0800, Hangbin Liu wrote:
> > 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.
>
> And this is no longer failing?
I haven't seen this issue later. But you know, this was triggered by a fuzz test,
not sure if the bad code still exists.
>
> What is the "fuzz" test?
It's just a socket test that create all kinds of domains/types/protocols and do
some {set,get}sockopt for TCP/UDP/SCTP
https://github.com/CKI-project/tests-beaker/blob/master/networking/socket/fuzz/socket.c#L155
Xiumei Mu also forwarded me a mail. It looks Sasha has fixed something.
But I don't know the details.
----- Forwarded Message -----
> From: "Sasha Levin" <sashal@kernel.org>
> To: "Greg KH" <greg@kroah.com>
> Cc: "Major Hayden" <major@mhtx.net>, "CKI Project" <cki-project@redhat.com>, "Linux Stable maillist"
> <stable@vger.kernel.org>, "Yi Zhang" <yi.zhang@redhat.com>, "Xiumei Mu" <xmu@redhat.com>, "Hangbin Liu"
> <haliu@redhat.com>, "Ying Xu" <yinxu@redhat.com>
> Sent: Wednesday, August 28, 2019 2:25:36 AM
> Subject: Re: ❌ FAIL: Test report for kernel 5.2.11-rc1-9f63171.cki (stable)
>
> On Tue, Aug 27, 2019 at 07:05:18PM +0200, Greg KH wrote:
> >On Tue, Aug 27, 2019 at 09:35:30AM -0500, Major Hayden wrote:
> >> On 8/27/19 7:31 AM, CKI Project wrote:
> >> > x86_64:
> >> > Host 2:
> >> > ❌ Networking socket: fuzz [9]
> >> > ❌ Networking sctp-auth: sockopts test [10]
> >>
> >> It looks like there was an oops when these tests ran on 5.2.11-rc1 and the
> >> last set of patches in stable-queue:
> >
> >Can you bisect?
>
> I think I've fixed it, let's see what happens next run.
>
> --
> Thanks,
> Sasha
^ permalink raw reply
* Re: ❌ FAIL: Stable queue: queue-5.2
From: Hangbin Liu @ 2019-09-10 9:40 UTC (permalink / raw)
To: Greg KH
Cc: CKI Project, Linux Stable maillist, netdev, Jan Stancek,
Xiumei Mu, David Howells, linux-afs, Sasha Levin
In-Reply-To: <20190910093021.GK22496@dhcp-12-139.nay.redhat.com>
On Tue, Sep 10, 2019 at 05:30:21PM +0800, Hangbin Liu wrote:
> Xiumei Mu also forwarded me a mail. It looks Sasha has fixed something.
> But I don't know the details.
Oh, I checked that thread. It's the same issue. So Sasha should has fixed it. I
just wonder the commit id now.
Thanks
Hangbin
>
> ----- Forwarded Message -----
> > From: "Sasha Levin" <sashal@kernel.org>
> > To: "Greg KH" <greg@kroah.com>
> > Cc: "Major Hayden" <major@mhtx.net>, "CKI Project" <cki-project@redhat.com>, "Linux Stable maillist"
> > <stable@vger.kernel.org>, "Yi Zhang" <yi.zhang@redhat.com>, "Xiumei Mu" <xmu@redhat.com>, "Hangbin Liu"
> > <haliu@redhat.com>, "Ying Xu" <yinxu@redhat.com>
> > Sent: Wednesday, August 28, 2019 2:25:36 AM
> > Subject: Re: ❌ FAIL: Test report for kernel 5.2.11-rc1-9f63171.cki (stable)
> >
> > On Tue, Aug 27, 2019 at 07:05:18PM +0200, Greg KH wrote:
> > >On Tue, Aug 27, 2019 at 09:35:30AM -0500, Major Hayden wrote:
> > >> On 8/27/19 7:31 AM, CKI Project wrote:
> > >> > x86_64:
> > >> > Host 2:
> > >> > ❌ Networking socket: fuzz [9]
> > >> > ❌ Networking sctp-auth: sockopts test [10]
> > >>
> > >> It looks like there was an oops when these tests ran on 5.2.11-rc1 and the
> > >> last set of patches in stable-queue:
> > >
> > >Can you bisect?
> >
> > I think I've fixed it, let's see what happens next run.
> >
> > --
> > Thanks,
> > Sasha
^ permalink raw reply
* Re: [RFC PATCH 3/4] virtio: introudce a mdev based transport
From: Michael S. Tsirkin @ 2019-09-10 10:01 UTC (permalink / raw)
To: Jason Wang
Cc: kvm, virtualization, netdev, 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-4-jasowang@redhat.com>
On Tue, Sep 10, 2019 at 04:19:34PM +0800, Jason Wang wrote:
> 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
> + */
Pls add a bit more content here. It's redundant to state these
are ioctls. Much better to document what does each one do.
> +
> +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)
Function pointer in an ioctl parameter? How does this ever make sense?
And can't we use a couple of registers for this, and avoid ioctls?
> +
> +#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
Is this same as started?
> +
> +/* 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
Mixing device and generic config space is what virtio pci did,
caused lots of problems with extensions.
It would be better to reserve much more space.
> +
> +#endif
> +
> +
> +/* Ready bit for the currently selected queue - Read Write */
> --
> 2.19.1
^ permalink raw reply
* [PATCH] ath9k: remove unneeded variable
From: Ding Xiang @ 2019-09-10 9:55 UTC (permalink / raw)
To: kvalo, davem; +Cc: linux-wireless, netdev, linux-kernel
"len" is unneeded,just return 0
Signed-off-by: Ding Xiang <dingxiang@cmss.chinamobile.com>
---
drivers/net/wireless/ath/ath9k/gpio.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/drivers/net/wireless/ath/ath9k/gpio.c b/drivers/net/wireless/ath/ath9k/gpio.c
index b457e52..f3d1bc0 100644
--- a/drivers/net/wireless/ath/ath9k/gpio.c
+++ b/drivers/net/wireless/ath/ath9k/gpio.c
@@ -498,14 +498,13 @@ static int ath9k_dump_legacy_btcoex(struct ath_softc *sc, u8 *buf, u32 size)
{
struct ath_btcoex *btcoex = &sc->btcoex;
- u32 len = 0;
ATH_DUMP_BTCOEX("Stomp Type", btcoex->bt_stomp_type);
ATH_DUMP_BTCOEX("BTCoex Period (msec)", btcoex->btcoex_period);
ATH_DUMP_BTCOEX("Duty Cycle", btcoex->duty_cycle);
ATH_DUMP_BTCOEX("BT Wait time", btcoex->bt_wait_time);
- return len;
+ return 0;
}
int ath9k_dump_btcoex(struct ath_softc *sc, u8 *buf, u32 size)
--
1.9.1
^ permalink raw reply related
* Re: [RFC PATCH 4/4] docs: Sample driver to demonstrate how to implement virtio-mdev framework
From: Michael S. Tsirkin @ 2019-09-10 10:15 UTC (permalink / raw)
To: Jason Wang
Cc: kvm, virtualization, netdev, 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-5-jasowang@redhat.com>
On Tue, Sep 10, 2019 at 04:19:35PM +0800, Jason Wang wrote:
> This sample driver creates mdev device that simulate virtio net device
> over virtio mdev transport. The device is implemented through vringh
> and workqueue.
>
> Signed-off-by: Jason Wang <jasowang@redhat.com>
> ---
> samples/Kconfig | 7 +
> samples/vfio-mdev/Makefile | 1 +
> samples/vfio-mdev/mvnet.c | 766 +++++++++++++++++++++++++++++++++++++
> 3 files changed, 774 insertions(+)
> create mode 100644 samples/vfio-mdev/mvnet.c
So for a POC, this is a bit too rough to be able to judge
whether the approach is workable.
Can you get it a bit more into shape esp wrt UAPI?
> diff --git a/samples/Kconfig b/samples/Kconfig
> index c8dacb4dda80..a1a1ca2c00b7 100644
> --- a/samples/Kconfig
> +++ b/samples/Kconfig
> @@ -131,6 +131,13 @@ config SAMPLE_VFIO_MDEV_MDPY
> mediated device. It is a simple framebuffer and supports
> the region display interface (VFIO_GFX_PLANE_TYPE_REGION).
>
> +config SAMPLE_VIRTIO_MDEV_NET
> + tristate "Build virtio mdev net example mediated device sample code -- loadable modules only"
> + depends on VIRTIO_MDEV_DEVICE && VHOST_RING && m
> + help
> + Build a networking sample device for use as a virtio
> + mediated device.
> +
> config SAMPLE_VFIO_MDEV_MDPY_FB
> tristate "Build VFIO mdpy example guest fbdev driver -- loadable module only"
> depends on FB && m
> diff --git a/samples/vfio-mdev/Makefile b/samples/vfio-mdev/Makefile
> index 10d179c4fdeb..f34af90ed0a0 100644
> --- a/samples/vfio-mdev/Makefile
> +++ b/samples/vfio-mdev/Makefile
> @@ -3,3 +3,4 @@ obj-$(CONFIG_SAMPLE_VFIO_MDEV_MTTY) += mtty.o
> obj-$(CONFIG_SAMPLE_VFIO_MDEV_MDPY) += mdpy.o
> obj-$(CONFIG_SAMPLE_VFIO_MDEV_MDPY_FB) += mdpy-fb.o
> obj-$(CONFIG_SAMPLE_VFIO_MDEV_MBOCHS) += mbochs.o
> +obj-$(CONFIG_SAMPLE_VIRTIO_MDEV_NET) += mvnet.o
> diff --git a/samples/vfio-mdev/mvnet.c b/samples/vfio-mdev/mvnet.c
> new file mode 100644
> index 000000000000..da295b41955e
> --- /dev/null
> +++ b/samples/vfio-mdev/mvnet.c
> @@ -0,0 +1,766 @@
> +// SPDX-License-Identifier: GPL-2.0-only
> +/*
> + * Mediated virtual virtio-net device driver.
> + *
> + * Copyright (c) 2019, Red Hat Inc. All rights reserved.
> + * Author: Jason Wang <jasowang@redhat.com>
> + *
> + * Sample driver
Documentation on how to use this?
> that creates mdev device that simulates ethernet
> + * device virtio mdev transport.
Well not exactly. What it seems to do is short-circuit
RX and TX rings.
> + */
> +
> +#include <linux/init.h>
> +#include <linux/module.h>
> +#include <linux/device.h>
> +#include <linux/kernel.h>
> +#include <linux/fs.h>
> +#include <linux/poll.h>
> +#include <linux/slab.h>
> +#include <linux/sched.h>
> +#include <linux/wait.h>
> +#include <linux/uuid.h>
> +#include <linux/iommu.h>
> +#include <linux/sysfs.h>
> +#include <linux/file.h>
> +#include <linux/etherdevice.h>
> +#include <linux/mdev.h>
> +#include <uapi/linux/virtio_mdev.h>
> +
> +#define VERSION_STRING "0.1"
> +#define DRIVER_AUTHOR "NVIDIA Corporation"
> +
> +#define MVNET_CLASS_NAME "mvnet"
> +
> +#define MVNET_NAME "mvnet"
> +
> +/*
> + * Global Structures
> + */
> +
> +static struct mvnet_dev {
> + struct class *vd_class;
> + struct idr vd_idr;
> + struct device dev;
> +} mvnet_dev;
> +
> +struct mvnet_virtqueue {
> + struct vringh vring;
> + struct vringh_kiov iov;
> + unsigned short head;
> + bool ready;
> + u32 desc_addr_lo;
> + u32 desc_addr_hi;
> + u32 device_addr_lo;
> + u32 device_addr_hi;
> + u32 driver_addr_lo;
> + u32 driver_addr_hi;
> + u64 desc_addr;
> + u64 device_addr;
> + u64 driver_addr;
> + void *private;
> + irqreturn_t (*cb)(void *);
> +};
> +
> +#define MVNET_QUEUE_ALIGN PAGE_SIZE
> +#define MVNET_QUEUE_MAX 256
> +#define MVNET_MAGIC_VALUE ('v' | 'i' << 8 | 'r' << 16 | 't' << 24)
> +#define MVNET_VERSION 0x1 /* Implies virtio 1.0 */
> +#define MVNET_DEVICE_ID 0x1 /* network card */
> +#define MVNET_VENDOR_ID 0 /* is this correct ? */
> +#define MVNET_DEVICE_FEATURES VIRTIO_F_VERSION_1
> +
> +u64 mvnet_features = (1ULL << VIRTIO_F_ANY_LAYOUT) |
> + (1ULL << VIRTIO_F_VERSION_1) |
> + (1ULL << VIRTIO_F_IOMMU_PLATFORM) ;
> +
> +/* State of each mdev device */
> +struct mvnet_state {
> + struct mvnet_virtqueue vqs[2];
> + struct work_struct work;
> + spinlock_t lock;
> + struct mdev_device *mdev;
> + struct virtio_net_config config;
> + struct virtio_mdev_callback *cbs;
> + void *buffer;
> + u32 queue_sel;
> + u32 driver_features_sel;
> + u32 driver_features[2];
> + u32 device_features_sel;
> + u32 status;
> + u32 generation;
> + u32 num;
> + struct list_head next;
> +};
> +
> +static struct mutex mdev_list_lock;
> +static struct list_head mdev_devices_list;
> +
> +static void mvnet_queue_ready(struct mvnet_state *mvnet, unsigned idx)
> +{
> + struct mvnet_virtqueue *vq = &mvnet->vqs[idx];
> + int ret;
> +
> + vq->desc_addr = (u64)vq->desc_addr_hi << 32 | vq->desc_addr_lo;
> + vq->device_addr = (u64)vq->device_addr_hi << 32 | vq->device_addr_lo;
> + vq->driver_addr = (u64)vq->driver_addr_hi << 32 | vq->driver_addr_lo;
> +
> + ret = vringh_init_kern(&vq->vring, mvnet_features, MVNET_QUEUE_MAX,
> + false, (struct vring_desc *)vq->desc_addr,
> + (struct vring_avail *)vq->driver_addr,
> + (struct vring_used *)vq->device_addr);
> +}
> +
> +static ssize_t mvnet_read_config(struct mdev_device *mdev,
> + u32 *val, loff_t pos)
> +{
> + struct mvnet_state *mvnet;
> + struct mvnet_virtqueue *vq;
> + u32 queue_sel;
> +
> + if (!mdev || !val)
> + return -EINVAL;
> +
> + mvnet = mdev_get_drvdata(mdev);
> + if (!mvnet) {
> + pr_err("%s mvnet not found\n", __func__);
> + return -EINVAL;
> + }
> +
> + queue_sel = mvnet->queue_sel;
> + vq = &mvnet->vqs[queue_sel];
> +
> + switch (pos) {
> + case VIRTIO_MDEV_MAGIC_VALUE:
> + *val = MVNET_MAGIC_VALUE;
> + break;
> + case VIRTIO_MDEV_VERSION:
> + *val = MVNET_VERSION;
> + break;
> + case VIRTIO_MDEV_DEVICE_ID:
> + *val = MVNET_DEVICE_ID;
> + break;
> + case VIRTIO_MDEV_VENDOR_ID:
> + *val = MVNET_VENDOR_ID;
> + break;
> + case VIRTIO_MDEV_DEVICE_FEATURES:
> + if (mvnet->device_features_sel)
> + *val = mvnet_features >> 32;
> + else
> + *val = mvnet_features;
> + break;
> + case VIRTIO_MDEV_QUEUE_NUM_MAX:
> + *val = MVNET_QUEUE_MAX;
> + break;
> + case VIRTIO_MDEV_QUEUE_READY:
> + *val = vq->ready;
> + break;
> + case VIRTIO_MDEV_QUEUE_ALIGN:
> + *val = MVNET_QUEUE_ALIGN;
> + break;
> + case VIRTIO_MDEV_STATUS:
> + *val = mvnet->status;
> + break;
> + case VIRTIO_MDEV_QUEUE_DESC_LOW:
> + *val = vq->desc_addr_lo;
> + break;
> + case VIRTIO_MDEV_QUEUE_DESC_HIGH:
> + *val = vq->desc_addr_hi;
> + break;
> + case VIRTIO_MDEV_QUEUE_AVAIL_LOW:
> + *val = vq->driver_addr_lo;
> + break;
> + case VIRTIO_MDEV_QUEUE_AVAIL_HIGH:
> + *val = vq->driver_addr_hi;
> + break;
> + case VIRTIO_MDEV_QUEUE_USED_LOW:
> + *val = vq->device_addr_lo;
> + break;
> + case VIRTIO_MDEV_QUEUE_USED_HIGH:
> + *val = vq->device_addr_hi;
> + break;
> + case VIRTIO_MDEV_CONFIG_GENERATION:
> + *val = 1;
> + break;
> + default:
> + pr_err("Unsupported mdev read offset at 0x%x\n", pos);
> + break;
> + }
> +
> + return 4;
> +}
> +
> +static ssize_t mvnet_read_net_config(struct mdev_device *mdev,
> + char *buf, size_t count, loff_t pos)
> +{
> + struct mvnet_state *mvnet = mdev_get_drvdata(mdev);
> +
> + if (!mvnet) {
> + pr_err("%s mvnet not found\n", __func__);
> + return -EINVAL;
> + }
> +
> + if (pos + count > sizeof(mvnet->config))
> + return -EINVAL;
> +
> + memcpy(buf, &mvnet->config + (unsigned)pos, count);
> +
> + return count;
> +}
> +
> +static void mvnet_vq_reset(struct mvnet_virtqueue *vq)
> +{
> + vq->ready = 0;
> + vq->desc_addr_lo = vq->desc_addr_hi = 0;
> + vq->device_addr_lo = vq->device_addr_hi = 0;
> + vq->driver_addr_lo = vq->driver_addr_hi = 0;
> + vq->desc_addr = 0;
> + vq->driver_addr = 0;
> + vq->device_addr = 0;
> + vringh_init_kern(&vq->vring, mvnet_features, MVNET_QUEUE_MAX,
> + false, 0, 0, 0);
> +}
> +
> +static void mvnet_reset(struct mvnet_state *mvnet)
> +{
> + int i;
> +
> + for (i = 0; i < 2; i++)
> + mvnet_vq_reset(&mvnet->vqs[i]);
> +
> + mvnet->queue_sel = 0;
> + mvnet->driver_features_sel = 0;
> + mvnet->device_features_sel = 0;
> + mvnet->status = 0;
> + ++mvnet->generation;
> +}
> +
> +static ssize_t mvnet_write_config(struct mdev_device *mdev,
> + u32 *val, loff_t pos)
> +{
> + struct mvnet_state *mvnet;
> + struct mvnet_virtqueue *vq;
> + u32 queue_sel;
> +
> + if (!mdev || !val)
> + return -EINVAL;
> +
> + mvnet = mdev_get_drvdata(mdev);
> + if (!mvnet) {
> + pr_err("%s mvnet not found\n", __func__);
> + return -EINVAL;
> + }
> +
> + queue_sel = mvnet->queue_sel;
> + vq = &mvnet->vqs[queue_sel];
> +
> + switch (pos) {
> + case VIRTIO_MDEV_DEVICE_FEATURES_SEL:
> + mvnet->device_features_sel = *val;
> + break;
> + case VIRTIO_MDEV_DRIVER_FEATURES:
> + mvnet->driver_features[mvnet->driver_features_sel] = *val;
> + break;
> + case VIRTIO_MDEV_DRIVER_FEATURES_SEL:
> + mvnet->driver_features_sel = *val;
> + break;
> + case VIRTIO_MDEV_QUEUE_SEL:
> + mvnet->queue_sel = *val;
> + break;
> + case VIRTIO_MDEV_QUEUE_NUM:
> + mvnet->num = *val;
> + break;
> + case VIRTIO_MDEV_QUEUE_READY:
> + vq->ready = *val;
> + if (vq->ready) {
> + spin_lock(&mvnet->lock);
> + mvnet_queue_ready(mvnet, queue_sel);
> + spin_unlock(&mvnet->lock);
> + }
> + break;
> + case VIRTIO_MDEV_QUEUE_NOTIFY:
> + if (vq->ready)
> + schedule_work(&mvnet->work);
> + break;
> + case VIRTIO_MDEV_STATUS:
> + mvnet->status = *val;
> + if (*val == 0) {
> + spin_lock(&mvnet->lock);
> + mvnet_reset(mvnet);
> + spin_unlock(&mvnet->lock);
> + }
> + break;
> + case VIRTIO_MDEV_QUEUE_DESC_LOW:
> + vq->desc_addr_lo = *val;
> + break;
> + case VIRTIO_MDEV_QUEUE_DESC_HIGH:
> + vq->desc_addr_hi = *val;
> + break;
> + case VIRTIO_MDEV_QUEUE_AVAIL_LOW:
> + vq->driver_addr_lo = *val;
> + break;
> + case VIRTIO_MDEV_QUEUE_AVAIL_HIGH:
> + vq->driver_addr_hi = *val;
> + break;
> + case VIRTIO_MDEV_QUEUE_USED_LOW:
> + vq->device_addr_lo = *val;
> + break;
> + case VIRTIO_MDEV_QUEUE_USED_HIGH:
> + vq->device_addr_hi = *val;
> + break;
> + default:
> + pr_err("Unsupported write offset! 0x%x\n", pos);
> + break;
> + }
> + spin_unlock(&mvnet->lock);
> +
> + return 4;
> +}
> +
> +static void mvnet_work(struct work_struct *work)
> +{
> + struct mvnet_state *mvnet = container_of(work, struct
> + mvnet_state, work);
> + struct mvnet_virtqueue *txq = &mvnet->vqs[1];
> + struct mvnet_virtqueue *rxq = &mvnet->vqs[0];
> + size_t read, write, total_write;
> + unsigned long flags;
> + int err;
> + int pkts = 0;
> +
> + spin_lock(&mvnet->lock);
> +
> + if (!txq->ready || !rxq->ready)
> + goto out;
> +
> + while (true) {
> + total_write = 0;
> + err = vringh_getdesc_kern(&txq->vring, &txq->iov, NULL,
> + &txq->head, GFP_KERNEL);
> + if (err <= 0)
> + break;
> +
> + err = vringh_getdesc_kern(&rxq->vring, NULL, &rxq->iov,
> + &rxq->head, GFP_KERNEL);
GFP_KERNEL under a spin_lock will cause deadlocks.
> + if (err <= 0) {
> + vringh_complete_kern(&txq->vring, txq->head, 0);
> + break;
> + }
> +
> + while (true) {
> + read = vringh_iov_pull_kern(&txq->iov, mvnet->buffer,
> + PAGE_SIZE);
> + if (read <= 0)
> + break;
> +
> + write = vringh_iov_push_kern(&rxq->iov, mvnet->buffer,
> + read);
> + if (write <= 0)
> + break;
> +
> + total_write += write;
> + }
> +
> + /* Make sure data is wrote before advancing index */
> + smp_wmb();
> +
> + vringh_complete_kern(&txq->vring, txq->head, 0);
> + vringh_complete_kern(&rxq->vring, rxq->head, total_write);
> +
> + /* Make sure used is visible before rasing the
> + interrupt */
> + smp_wmb();
> +
> + local_bh_disable();
> + if (txq->cb)
> + txq->cb(txq->private);
> + if (rxq->cb)
> + rxq->cb(rxq->private);
> + local_bh_enable();
> +
> + pkts ++;
coding style problem
> + if (pkts > 4) {
> + schedule_work(&mvnet->work);
> + goto out;
> + }
> + }
> +
> +out:
> + spin_unlock(&mvnet->lock);
> +}
> +
> +static dma_addr_t mvnet_map_page(struct device *dev, struct page *page,
> + unsigned long offset, size_t size,
> + enum dma_data_direction dir,
> + unsigned long attrs)
> +{
> + /* Vringh can only use VA */
> + return page_address(page) + offset;
> +}
> +
> +static void mvnet_unmap_page(struct device *dev, dma_addr_t dma_addr,
> + size_t size, enum dma_data_direction dir,
> + unsigned long attrs)
> +{
> + return ;
> +}
> +
> +static void *mvnet_alloc_coherent(struct device *dev, size_t size,
> + dma_addr_t *dma_addr, gfp_t flag,
> + unsigned long attrs)
> +{
> + void *ret = kmalloc(size, flag);
> +
> + if (ret == NULL)
!ret is nicer
> + *dma_addr = DMA_MAPPING_ERROR;
> + else
> + *dma_addr = ret;
Not sure how does this build ... don't we need a cast?
> +
> + return ret;
> +}
> +
> +static void mvnet_free_coherent(struct device *dev, size_t size,
> + void *vaddr, dma_addr_t dma_addr,
> + unsigned long attrs)
> +{
> + kfree(dma_addr);
> +}
> +
> +static const struct dma_map_ops mvnet_dma_ops = {
> + .map_page = mvnet_map_page,
> + .unmap_page = mvnet_unmap_page,
> + .alloc = mvnet_alloc_coherent,
> + .free = mvnet_free_coherent,
> +};
> +
> +static int mvnet_create(struct kobject *kobj, struct mdev_device *mdev)
> +{
> + struct mvnet_state *mvnet;
> + struct virtio_net_config *config;
> +
> + if (!mdev)
> + return -EINVAL;
> +
> + mvnet = kzalloc(sizeof(struct mvnet_state), GFP_KERNEL);
> + if (mvnet == NULL)
> + return -ENOMEM;
> +
> + mvnet->buffer = kmalloc(PAGE_SIZE, GFP_KERNEL);
> + if (!mvnet->buffer) {
> + kfree(mvnet);
> + return -ENOMEM;
> + }
> +
> + config = &mvnet->config;
> + config->mtu = 1500;
> + config->status = VIRTIO_NET_S_LINK_UP;
> + eth_random_addr(config->mac);
> +
> + INIT_WORK(&mvnet->work, mvnet_work);
> +
> + spin_lock_init(&mvnet->lock);
> + mvnet->mdev = mdev;
> + mdev_set_drvdata(mdev, mvnet);
> +
> + mutex_lock(&mdev_list_lock);
> + list_add(&mvnet->next, &mdev_devices_list);
> + mutex_unlock(&mdev_list_lock);
> +
> + mdev_set_dma_ops(mdev, &mvnet_dma_ops);
> +
> + return 0;
> +}
> +
> +static int mvnet_remove(struct mdev_device *mdev)
> +{
> + struct mvnet_state *mds, *tmp_mds;
> + struct mvnet_state *mvnet = mdev_get_drvdata(mdev);
> + int ret = -EINVAL;
> +
> + mutex_lock(&mdev_list_lock);
> + list_for_each_entry_safe(mds, tmp_mds, &mdev_devices_list, next) {
> + if (mvnet == mds) {
> + list_del(&mvnet->next);
> + mdev_set_drvdata(mdev, NULL);
> + kfree(mvnet->buffer);
> + kfree(mvnet);
> + ret = 0;
> + break;
> + }
> + }
> + mutex_unlock(&mdev_list_lock);
> +
> + return ret;
> +}
> +
> +static ssize_t mvnet_read(struct mdev_device *mdev, char __user *buf,
> + size_t count, loff_t *ppos)
> +{
> + ssize_t ret;
> +
> + if (*ppos < VIRTIO_MDEV_CONFIG) {
> + if (count == 4)
> + ret = mvnet_read_config(mdev, (u32 *)buf, *ppos);
> + else
> + ret = -EINVAL;
> + *ppos += 4;
> + } else if (*ppos < VIRTIO_MDEV_CONFIG + sizeof(struct virtio_net_config)) {
> + ret = mvnet_read_net_config(mdev, buf, count,
> + *ppos - VIRTIO_MDEV_CONFIG);
> + *ppos += count;
> + } else {
> + ret = -EINVAL;
> + }
> +
> + return ret;
> +}
> +
> +static ssize_t mvnet_write(struct mdev_device *mdev, const char __user *buf,
> + size_t count, loff_t *ppos)
> +{
> + int ret;
> +
> + if (*ppos < VIRTIO_MDEV_CONFIG) {
> + if (count == 4)
> + ret = mvnet_write_config(mdev, (u32 *)buf, *ppos);
> + else
> + ret = -EINVAL;
> + *ppos += 4;
> + } else {
> + /* No writable net config */
> + ret = -EINVAL;
> + }
> +
> + return ret;
> +}
> +
> +static long mvnet_ioctl(struct mdev_device *mdev, unsigned int cmd,
> + unsigned long arg)
> +{
> + int ret = 0;
> + struct mvnet_state *mvnet;
> + struct virtio_mdev_callback *cb;
> +
> + if (!mdev)
> + return -EINVAL;
> +
> + mvnet = mdev_get_drvdata(mdev);
> + if (!mvnet)
> + return -ENODEV;
> +
> + spin_lock(&mvnet->lock);
> +
> + switch (cmd) {
> + case VIRTIO_MDEV_SET_VQ_CALLBACK:
> + cb = (struct virtio_mdev_callback *)arg;
> + mvnet->vqs[mvnet->queue_sel].cb = cb->callback;
> + mvnet->vqs[mvnet->queue_sel].private = cb->private;
> + break;
> + case VIRTIO_MDEV_SET_CONFIG_CALLBACK:
> + break;
success, but nothing happens.
> + default:
> + pr_err("Not supportted ioctl cmd 0x%x\n", cmd);
> + ret = -ENOTTY;
> + break;
> + }
> +
> + spin_unlock(&mvnet->lock);
> +
> + return ret;
> +}
> +
> +static int mvnet_open(struct mdev_device *mdev)
> +{
> + pr_info("%s\n", __func__);
> + return 0;
> +}
> +
> +static void mvnet_close(struct mdev_device *mdev)
> +{
> + pr_info("%s\n", __func__);
> +}
> +
> +static ssize_t
> +sample_mvnet_dev_show(struct device *dev, struct device_attribute *attr,
> + char *buf)
> +{
> + return sprintf(buf, "This is phy device\n");
what's this?
> +}
> +
> +static DEVICE_ATTR_RO(sample_mvnet_dev);
> +
> +static struct attribute *mvnet_dev_attrs[] = {
> + &dev_attr_sample_mvnet_dev.attr,
> + NULL,
> +};
> +
> +static const struct attribute_group mvnet_dev_group = {
> + .name = "mvnet_dev",
> + .attrs = mvnet_dev_attrs,
> +};
> +
> +static const struct attribute_group *mvnet_dev_groups[] = {
> + &mvnet_dev_group,
> + NULL,
> +};
> +
> +static ssize_t
> +sample_mdev_dev_show(struct device *dev, struct device_attribute *attr,
> + char *buf)
> +{
> + if (mdev_from_dev(dev))
> + return sprintf(buf, "This is MDEV %s\n", dev_name(dev));
> +
> + return sprintf(buf, "\n");
> +}
> +
> +static DEVICE_ATTR_RO(sample_mdev_dev);
> +
> +static struct attribute *mdev_dev_attrs[] = {
> + &dev_attr_sample_mdev_dev.attr,
> + NULL,
> +};
> +
> +static const struct attribute_group mdev_dev_group = {
> + .name = "vendor",
> + .attrs = mdev_dev_attrs,
> +};
> +
> +static const struct attribute_group *mdev_dev_groups[] = {
> + &mdev_dev_group,
> + NULL,
> +};
> +
> +#define MVNET_STRING_LEN 16
> +
> +static ssize_t
> +name_show(struct kobject *kobj, struct device *dev, char *buf)
> +{
> + char name[MVNET_STRING_LEN];
> + const char *name_str = "virtio-net";
> +
> + snprintf(name, MVNET_STRING_LEN, "%s", dev_driver_string(dev));
> + if (!strcmp(kobj->name, name))
> + return sprintf(buf, "%s\n", name_str);
> +
> + return -EINVAL;
> +}
> +
> +static MDEV_TYPE_ATTR_RO(name);
> +
> +static ssize_t
> +available_instances_show(struct kobject *kobj, struct device *dev, char *buf)
> +{
> + return sprintf(buf, "%d\n", INT_MAX);
> +}
> +
> +static MDEV_TYPE_ATTR_RO(available_instances);
?
> +
> +static ssize_t device_api_show(struct kobject *kobj, struct device *dev,
> + char *buf)
> +{
> + return sprintf(buf, "%s\n", VIRTIO_MDEV_DEVICE_API_STRING);
> +}
> +
> +static MDEV_TYPE_ATTR_RO(device_api);
> +
> +static struct attribute *mdev_types_attrs[] = {
> + &mdev_type_attr_name.attr,
> + &mdev_type_attr_device_api.attr,
> + &mdev_type_attr_available_instances.attr,
> + NULL,
> +};
> +
> +static struct attribute_group mdev_type_group = {
> + .name = "",
> + .attrs = mdev_types_attrs,
> +};
> +
> +static struct attribute_group *mdev_type_groups[] = {
> + &mdev_type_group,
> + NULL,
> +};
> +
> +static const struct mdev_parent_ops mdev_fops = {
> + .owner = THIS_MODULE,
> + .dev_attr_groups = mvnet_dev_groups,
> + .mdev_attr_groups = mdev_dev_groups,
> + .supported_type_groups = mdev_type_groups,
> + .create = mvnet_create,
> + .remove = mvnet_remove,
> + .open = mvnet_open,
> + .release = mvnet_close,
> + .read = mvnet_read,
> + .write = mvnet_write,
> + .ioctl = mvnet_ioctl,
> +};
> +
> +static void mvnet_device_release(struct device *dev)
> +{
> + dev_dbg(dev, "mvnet: released\n");
> +}
> +
> +static int __init mvnet_dev_init(void)
> +{
> + int ret = 0;
> +
> + pr_info("mvnet_dev: %s\n", __func__);
> +
> + memset(&mvnet_dev, 0, sizeof(mvnet_dev));
> +
> + idr_init(&mvnet_dev.vd_idr);
> +
> + mvnet_dev.vd_class = class_create(THIS_MODULE, MVNET_CLASS_NAME);
> +
> + if (IS_ERR(mvnet_dev.vd_class)) {
> + pr_err("Error: failed to register mvnet_dev class\n");
> + ret = PTR_ERR(mvnet_dev.vd_class);
> + goto failed1;
> + }
> +
> + mvnet_dev.dev.class = mvnet_dev.vd_class;
> + mvnet_dev.dev.release = mvnet_device_release;
> + dev_set_name(&mvnet_dev.dev, "%s", MVNET_NAME);
> +
> + ret = device_register(&mvnet_dev.dev);
> + if (ret)
> + goto failed2;
> +
> + ret = mdev_register_device(&mvnet_dev.dev, &mdev_fops);
> + if (ret)
> + goto failed3;
> +
> + mutex_init(&mdev_list_lock);
> + INIT_LIST_HEAD(&mdev_devices_list);
> +
> + goto all_done;
> +
> +failed3:
> +
> + device_unregister(&mvnet_dev.dev);
> +failed2:
> + class_destroy(mvnet_dev.vd_class);
> +
> +failed1:
> +all_done:
> + return ret;
> +}
> +
> +static void __exit mvnet_dev_exit(void)
> +{
> + mvnet_dev.dev.bus = NULL;
> + mdev_unregister_device(&mvnet_dev.dev);
> +
> + device_unregister(&mvnet_dev.dev);
> + idr_destroy(&mvnet_dev.vd_idr);
> + class_destroy(mvnet_dev.vd_class);
> + mvnet_dev.vd_class = NULL;
> + pr_info("mvnet_dev: Unloaded!\n");
> +}
> +
> +module_init(mvnet_dev_init)
> +module_exit(mvnet_dev_exit)
> +
> +MODULE_LICENSE("GPL v2");
> +MODULE_INFO(supported, "Test driver that simulate serial port over PCI");
> +MODULE_VERSION(VERSION_STRING);
> +MODULE_AUTHOR(DRIVER_AUTHOR);
> --
> 2.19.1
^ permalink raw reply
* Re: [PATCH net] net: sonic: replace dev_kfree_skb in sonic_send_packet
From: Sergei Shtylyov @ 2019-09-10 10:23 UTC (permalink / raw)
To: Mao Wenan, tsbogend, davem; +Cc: netdev, linux-kernel, kernel-janitors
In-Reply-To: <20190910085848.144780-1-maowenan@huawei.com>
Hello!
On 10.09.2019 11:58, Mao Wenan wrote:
> sonic_send_packet will be processed in irq or none
s/none irq/non-irq/?
> irq context, so it would better use dev_kfree_skb_any
> instead of dev_kfree_skb.
>
> Fixes: d9fb9f384292 ("*sonic/natsemi/ns83829: Move the National Semi-conductor drivers")
> Signed-off-by: Mao Wenan <maowenan@huawei.com>
[...]
MBR, Sergei
^ permalink raw reply
* RE: [RFC PATCH 3/3] Enable ptp_kvm for arm64
From: Jianyong Wu (Arm Technology China) @ 2019-09-10 10:29 UTC (permalink / raw)
To: Marc Zyngier
Cc: netdev@vger.kernel.org, pbonzini@redhat.com,
sean.j.christopherson@intel.com, richardcochran@gmail.com,
Mark Rutland, Will Deacon, Suzuki Poulose,
linux-kernel@vger.kernel.org, Steve Capper,
Kaly Xin (Arm Technology China), Justin He (Arm Technology China)
In-Reply-To: <86blvtsodw.wl-maz@kernel.org>
Hi Marc,
> -----Original Message-----
> From: Marc Zyngier <maz@kernel.org>
> Sent: Monday, September 9, 2019 7:25 PM
> To: Jianyong Wu (Arm Technology China) <Jianyong.Wu@arm.com>
> Cc: netdev@vger.kernel.org; pbonzini@redhat.com;
> sean.j.christopherson@intel.com; richardcochran@gmail.com; Mark Rutland
> <Mark.Rutland@arm.com>; Will Deacon <Will.Deacon@arm.com>; Suzuki
> Poulose <Suzuki.Poulose@arm.com>; linux-kernel@vger.kernel.org; Steve
> Capper <Steve.Capper@arm.com>; Kaly Xin (Arm Technology China)
> <Kaly.Xin@arm.com>; Justin He (Arm Technology China)
> <Justin.He@arm.com>
> Subject: Re: [RFC PATCH 3/3] Enable ptp_kvm for arm64
>
> On Mon, 09 Sep 2019 11:17:24 +0100,
> "Jianyong Wu (Arm Technology China)" <Jianyong.Wu@arm.com> wrote:
>
> Hi Jianyoung,
>
> [...]
>
> > > > > I'm definitely not keen on exposing the internals of the
> > > > > arch_timer driver to random subsystems. Furthermore, you seem to
> > > > > expect that the guest kernel will only use the arch timer as a
> > > > > clocksource, and nothing really guarantees that (in which case
> > > get_device_system_crosststamp will fail).
> > > > >
> > > > The code here is really ugly, I need a better solution to offer a
> > > > clock source For the guest.
> > > >
> > > > > It looks to me that we'd be better off exposing a core
> > > > > timekeeping API that populates a struct system_counterval_t
> > > > > based on the
> > > > > *current* timekeeper monotonic clocksource. This would simplify
> > > > > the split between generic and arch-specific code.
> > > > >
> > > > I think it really necessary.
> > > >
> > > > > Whether or not tglx will be happy with the idea is another
> > > > > problem, but I'm certainly not taking any change to the arch
> > > > > timer code based on
> > > this.
> > > > >
> > > > I can have a try, but the detail is not clear for me now.
> > >
> > > Something along those lines:
> > >
> > > From 5f1c061e55c691d64012bc7c1490a1a8c4432c67 Mon Sep 17 00:00:00
> > > 2001
> > > From: Marc Zyngier <maz@kernel.org>
> > > Date: Sat, 7 Sep 2019 10:11:49 +0100
> > > Subject: [PATCH] timekeeping: Expose API allowing retrival of
> > > current clocksource and counter value
> > >
> > > Signed-off-by: Marc Zyngier <maz@kernel.org>
> > > ---
> > > include/linux/timekeeping.h | 5 +++++
> > > kernel/time/timekeeping.c | 12 ++++++++++++
> > > 2 files changed, 17 insertions(+)
> > >
> > > diff --git a/include/linux/timekeeping.h
> > > b/include/linux/timekeeping.h index
> > > b27e2ffa96c1..6df26a913711 100644
> > > --- a/include/linux/timekeeping.h
> > > +++ b/include/linux/timekeeping.h
> > > @@ -275,6 +275,11 @@ extern int get_device_system_crosststamp(
> > > struct system_time_snapshot *history,
> > > struct system_device_crosststamp *xtstamp);
> > >
> > > +/*
> > > + * Obtain current monotonic clock and its counter value */ extern
> > > +void get_current_counterval(struct system_counterval_t *sc);
> > > +
> > > /*
> > > * Simultaneously snapshot realtime and monotonic raw clocks
> > > */
> > > diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
> > > index
> > > d911c8470149..de689bbd3808 100644
> > > --- a/kernel/time/timekeeping.c
> > > +++ b/kernel/time/timekeeping.c
> > > @@ -1098,6 +1098,18 @@ static bool cycle_between(u64 before, u64
> > > test,
> > > u64 after)
> > > return false;
> > > }
> > >
> > > +/**
> > > + * get_current_counterval - Snapshot the current clocksource and
> > > +counter
> > > value
> > > + * @sc: Pointer to a struct containing the current clocksource and its
> > > value
> > > + */
> > > +void get_current_counterval(struct system_counterval_t *sc) {
> > > + struct timekeeper *tk = &tk_core.timekeeper;
> > > +
> > > + sc->cs = READ_ONCE(tk->tkr_mono.clock);
> > > + sc->cycles = sc->cs->read(sc->cs); }
> > > +
> > > /**
> > > * get_device_system_crosststamp - Synchronously capture
> > > system/device timestamp
> > > * @get_time_fn: Callback to get simultaneous device time and
> > >
> > > which should do the right thing.
> > >
> > It is a good news for me. These code is indeed what I need! So what's
> > your plan about this patch? Is there any problem with you if I
> > include these code into my patch ?
>
> Just add this patch as part of your series (I'll try to write an actual commit log
> for that).
Very kind of you!
>
> [...]
>
> > > > > Other questions: how does this works with VM migration?
> > > > > Specially when moving from a hypervisor that supports the
> > > > > feature to one that
> > > doesn't?
> > > > >
> > > > I think it won't solve the problem generated by VM migration and
> > > > only for VMs in a single machine. Ptp_kvm only works for VMs in
> > > > the same machine. But using ptp (not ptp_kvm) clock, all the
> > > > machines in a low latency network environment can keep time sync
> > > > in high precision, Then VMs move from one machine to another will
> > > > obtain a high precision time sync.
> > >
> > > That's a problem. Migration must be possible from one host to
> > > another, even if that means temporarily loosing some (or a lot of)
> > > precision. The service must be discoverable from userspace on the
> > > host so that the MVV can decie whether a migration is possible or not.
> > >
> > Don't worry, things will be not that bad. ptp_kvm will not trouble
> > the VM migration. This ptp_kvm is one clocksource of the clock pool
> > for chrony. Chrony will choose the highest precision clock from the
> > pool. If host does not support ptp_kvm, the ptp_kvm will not be chosen
> > as the clocksouce of chrony. We have roughly the same logic of
> > implementation of ptp_kvm with x86, and ptp_kvm works well in x86. so
> > I think that will be the case for arm64.
> >
> > Maybe I miss your point, I have no idea of MVV and can't get related
> > info from google. Also I'm not clear of your last words of how to
> > decide VM migration is possible?
>
> Sorry. s/MVV/VMM/. Basically userspace, such as QEMU.
>
> Here's an example: The guest runs on a PTP aware host, starts using the PTP
> service and uses HVC calls to get its clock. We now migrate the guest to a non
> PTP-aware host. The hypercalls are now going to fail unexpectedly. Is that
> something that is acceptable? I don't think it is. Once you've allowed a guest
> to use a service, this service should be preserved. I'd be more confident if we
> gave to userspace the indication that the hypervisor supports PTP. Userspace
> can then decide whether to perform migration or not.
>
It's really a point we should consider. let me check the behavior of chrony in this scenario first.
Thanks
Jianyong Wu
> Thanks,
>
> M.
>
> --
> Jazz is not dead, it just smells funny.
IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.
^ permalink raw reply
* [PATCH bpf-next 04/11] samples: bpf: use own EXTRA_CFLAGS for clang commands
From: Ivan Khoronzhuk @ 2019-09-10 10:38 UTC (permalink / raw)
To: ast, daniel, yhs, davem, jakub.kicinski, hawk, john.fastabend
Cc: linux-kernel, netdev, bpf, clang-built-linux, Ivan Khoronzhuk
In-Reply-To: <20190910103830.20794-1-ivan.khoronzhuk@linaro.org>
It can overlap with CFLAGS used for libraries built with gcc if
not now then in next patches. Correct it here for simplicity.
Signed-off-by: Ivan Khoronzhuk <ivan.khoronzhuk@linaro.org>
---
samples/bpf/Makefile | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/samples/bpf/Makefile b/samples/bpf/Makefile
index b59e77e2250e..8ecc5d0c2d5b 100644
--- a/samples/bpf/Makefile
+++ b/samples/bpf/Makefile
@@ -218,10 +218,10 @@ BTF_LLVM_PROBE := $(shell echo "int main() { return 0; }" | \
/bin/rm -f ./llvm_btf_verify.o)
ifneq ($(BTF_LLVM_PROBE),)
- EXTRA_CFLAGS += -g
+ CLANG_EXTRA_CFLAGS += -g
else
ifneq ($(and $(BTF_LLC_PROBE),$(BTF_PAHOLE_PROBE),$(BTF_OBJCOPY_PROBE)),)
- EXTRA_CFLAGS += -g
+ CLANG_EXTRA_CFLAGS += -g
LLC_FLAGS += -mattr=dwarfris
DWARF2BTF = y
endif
@@ -280,8 +280,8 @@ $(obj)/hbm_edt_kern.o: $(src)/hbm.h $(src)/hbm_kern.h
# useless for BPF samples.
$(obj)/%.o: $(src)/%.c
@echo " CLANG-bpf " $@
- $(Q)$(CLANG) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) $(EXTRA_CFLAGS) -I$(obj) \
- -I$(srctree)/tools/testing/selftests/bpf/ \
+ $(Q)$(CLANG) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) $(CLANG_EXTRA_CFLAGS) \
+ -I$(obj) -I$(srctree)/tools/testing/selftests/bpf/ \
-D__KERNEL__ -D__BPF_TRACING__ -Wno-unused-value -Wno-pointer-sign \
-D__TARGET_ARCH_$(SRCARCH) -Wno-compare-distinct-pointer-types \
-Wno-gnu-variable-sized-type-not-at-end \
--
2.17.1
^ permalink raw reply related
* [PATCH bpf-next 11/11] samples: bpf: makefile: add sysroot support
From: Ivan Khoronzhuk @ 2019-09-10 10:38 UTC (permalink / raw)
To: ast, daniel, yhs, davem, jakub.kicinski, hawk, john.fastabend
Cc: linux-kernel, netdev, bpf, clang-built-linux, Ivan Khoronzhuk
In-Reply-To: <20190910103830.20794-1-ivan.khoronzhuk@linaro.org>
Basically it only enables that was added by previous couple fixes.
For sure, just make tools/include to be included after sysroot
headers.
export ARCH=arm
export CROSS_COMPILE=arm-linux-gnueabihf-
make samples/bpf/ SYSROOT="path/to/sysroot"
Sysroot contains correct libs installed and its headers ofc.
Useful when working with NFC or virtual machine.
Signed-off-by: Ivan Khoronzhuk <ivan.khoronzhuk@linaro.org>
---
samples/bpf/Makefile | 5 +++++
samples/bpf/README.rst | 10 ++++++++++
2 files changed, 15 insertions(+)
diff --git a/samples/bpf/Makefile b/samples/bpf/Makefile
index 4edc5232cfc1..68ba78d1dbbe 100644
--- a/samples/bpf/Makefile
+++ b/samples/bpf/Makefile
@@ -177,6 +177,11 @@ ifeq ($(ARCH), arm)
CLANG_EXTRA_CFLAGS := $(D_OPTIONS)
endif
+ifdef SYSROOT
+ccflags-y += --sysroot=${SYSROOT}
+PROGS_LDFLAGS := -L${SYSROOT}/usr/lib
+endif
+
ccflags-y += -I$(objtree)/usr/include
ccflags-y += -I$(srctree)/tools/lib/bpf/
ccflags-y += -I$(srctree)/tools/testing/selftests/bpf/
diff --git a/samples/bpf/README.rst b/samples/bpf/README.rst
index 5f27e4faca50..786d0ab98e8a 100644
--- a/samples/bpf/README.rst
+++ b/samples/bpf/README.rst
@@ -74,3 +74,13 @@ samples for the cross target.
export ARCH=arm64
export CROSS_COMPILE="aarch64-linux-gnu-"
make samples/bpf/ LLC=~/git/llvm/build/bin/llc CLANG=~/git/llvm/build/bin/clang
+
+If need to use environment of target board (headers and libs), the SYSROOT
+also can be set, pointing on FS of target board:
+
+export ARCH=arm64
+export CROSS_COMPILE="aarch64-linux-gnu-"
+make samples/bpf/ SYSROOT=~/some_sdk/linux-devkit/sysroots/aarch64-linux-gnu
+
+Setting LLC and CLANG is not necessarily if it's installed on HOST and have
+in its targets appropriate arch triple (usually it has several arches).
--
2.17.1
^ permalink raw reply related
* [PATCH bpf-next 10/11] libbpf: makefile: add C/CXX/LDFLAGS to libbpf.so and test_libpf targets
From: Ivan Khoronzhuk @ 2019-09-10 10:38 UTC (permalink / raw)
To: ast, daniel, yhs, davem, jakub.kicinski, hawk, john.fastabend
Cc: linux-kernel, netdev, bpf, clang-built-linux, Ivan Khoronzhuk
In-Reply-To: <20190910103830.20794-1-ivan.khoronzhuk@linaro.org>
In case of LDFLAGS and EXTRA_CC/CXX flags there is no way to pass them
correctly to build command, for instance when --sysroot is used or
external libraries are used, like -lelf, wich can be absent in
toolchain. This is used for samples/bpf cross-compiling allowing to
get elf lib from sysroot.
Signed-off-by: Ivan Khoronzhuk <ivan.khoronzhuk@linaro.org>
---
samples/bpf/Makefile | 8 +++++++-
tools/lib/bpf/Makefile | 11 ++++++++---
2 files changed, 15 insertions(+), 4 deletions(-)
diff --git a/samples/bpf/Makefile b/samples/bpf/Makefile
index 79c9aa41832e..4edc5232cfc1 100644
--- a/samples/bpf/Makefile
+++ b/samples/bpf/Makefile
@@ -186,6 +186,10 @@ ccflags-y += -I$(srctree)/tools/perf
ccflags-y += $(D_OPTIONS)
ccflags-y += -Wall
ccflags-y += -fomit-frame-pointer
+
+EXTRA_CXXFLAGS := $(ccflags-y)
+
+# options not valid for C++
ccflags-y += -Wmissing-prototypes
ccflags-y += -Wstrict-prototypes
@@ -252,7 +256,9 @@ clean:
$(LIBBPF): FORCE
# Fix up variables inherited from Kbuild that tools/ build system won't like
- $(MAKE) -C $(dir $@) RM='rm -rf' LDFLAGS= srctree=$(BPF_SAMPLES_PATH)/../../ O=
+ $(MAKE) -C $(dir $@) RM='rm -rf' EXTRA_CFLAGS="$(PROGS_CFLAGS)" \
+ EXTRA_CXXFLAGS="$(EXTRA_CXXFLAGS)" LDFLAGS=$(PROGS_LDFLAGS) \
+ srctree=$(BPF_SAMPLES_PATH)/../../ O=
$(obj)/syscall_nrs.h: $(obj)/syscall_nrs.s FORCE
$(call filechk,offsets,__SYSCALL_NRS_H__)
diff --git a/tools/lib/bpf/Makefile b/tools/lib/bpf/Makefile
index c6f94cffe06e..bccfa556ef4e 100644
--- a/tools/lib/bpf/Makefile
+++ b/tools/lib/bpf/Makefile
@@ -94,6 +94,10 @@ else
CFLAGS := -g -Wall
endif
+ifdef EXTRA_CXXFLAGS
+ CXXFLAGS := $(EXTRA_CXXFLAGS)
+endif
+
ifeq ($(feature-libelf-mmap), 1)
override CFLAGS += -DHAVE_LIBELF_MMAP_SUPPORT
endif
@@ -176,8 +180,9 @@ $(BPF_IN): force elfdep bpfdep
$(OUTPUT)libbpf.so: $(OUTPUT)libbpf.so.$(LIBBPF_VERSION)
$(OUTPUT)libbpf.so.$(LIBBPF_VERSION): $(BPF_IN)
- $(QUIET_LINK)$(CC) --shared -Wl,-soname,libbpf.so.$(LIBBPF_MAJOR_VERSION) \
- -Wl,--version-script=$(VERSION_SCRIPT) $^ -lelf -o $@
+ $(QUIET_LINK)$(CC) $(LDFLAGS) \
+ --shared -Wl,-soname,libbpf.so.$(LIBBPF_MAJOR_VERSION) \
+ -Wl,--version-script=$(VERSION_SCRIPT) $^ -lelf -o $@
@ln -sf $(@F) $(OUTPUT)libbpf.so
@ln -sf $(@F) $(OUTPUT)libbpf.so.$(LIBBPF_MAJOR_VERSION)
@@ -185,7 +190,7 @@ $(OUTPUT)libbpf.a: $(BPF_IN)
$(QUIET_LINK)$(RM) $@; $(AR) rcs $@ $^
$(OUTPUT)test_libbpf: test_libbpf.cpp $(OUTPUT)libbpf.a
- $(QUIET_LINK)$(CXX) $(INCLUDES) $^ -lelf -o $@
+ $(QUIET_LINK)$(CXX) $(CXXFLAGS) $(LDFLAGS) $(INCLUDES) $^ -lelf -o $@
$(OUTPUT)libbpf.pc:
$(QUIET_GEN)sed -e "s|@PREFIX@|$(prefix)|" \
--
2.17.1
^ permalink raw reply related
* [PATCH bpf-next 09/11] samples: bpf: makefile: use CC environment for HDR_PROBE
From: Ivan Khoronzhuk @ 2019-09-10 10:38 UTC (permalink / raw)
To: ast, daniel, yhs, davem, jakub.kicinski, hawk, john.fastabend
Cc: linux-kernel, netdev, bpf, clang-built-linux, Ivan Khoronzhuk
In-Reply-To: <20190910103830.20794-1-ivan.khoronzhuk@linaro.org>
No need in hacking HOSTCC to be cross-compiler any more, so drop
this trick and use CC for HDR_PROBE
Signed-off-by: Ivan Khoronzhuk <ivan.khoronzhuk@linaro.org>
---
samples/bpf/Makefile | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/samples/bpf/Makefile b/samples/bpf/Makefile
index 625a71f2e9d2..79c9aa41832e 100644
--- a/samples/bpf/Makefile
+++ b/samples/bpf/Makefile
@@ -209,15 +209,14 @@ BTF_PAHOLE ?= pahole
# Detect that we're cross compiling and use the cross compiler
ifdef CROSS_COMPILE
-HOSTCC = $(CROSS_COMPILE)gcc
CLANG_ARCH_ARGS = --target=$(notdir $(CROSS_COMPILE:%-=%))
endif
# Don't evaluate probes and warnings if we need to run make recursively
ifneq ($(src),)
HDR_PROBE := $(shell printf "\#include <linux/types.h>\n struct list_head { int a; }; int main() { return 0; }" | \
- $(HOSTCC) $(KBUILD_HOSTCFLAGS) -x c - -o /dev/null 2>/dev/null && \
- echo okay)
+ $(CC) $(PROGS_CFLAGS) $(PROGS_LDFLAGS) -x c - -o /dev/null 2>/dev/null \
+ && echo okay)
ifeq ($(HDR_PROBE),)
$(warning WARNING: Detected possible issues with include path.)
--
2.17.1
^ permalink raw reply related
* [PATCH bpf-next 06/11] samples: bpf: makefile: drop unnecessarily inclusion for bpf_load
From: Ivan Khoronzhuk @ 2019-09-10 10:38 UTC (permalink / raw)
To: ast, daniel, yhs, davem, jakub.kicinski, hawk, john.fastabend
Cc: linux-kernel, netdev, bpf, clang-built-linux, Ivan Khoronzhuk
In-Reply-To: <20190910103830.20794-1-ivan.khoronzhuk@linaro.org>
Drop inclusion for bpf_load -I$(objtree)/usr/include as it
is included for all objects anyway, with above line:
KBUILD_HOSTCFLAGS += -I$(objtree)/usr/include
Signed-off-by: Ivan Khoronzhuk <ivan.khoronzhuk@linaro.org>
---
samples/bpf/Makefile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/samples/bpf/Makefile b/samples/bpf/Makefile
index 6492b7e65c08..f5dbf3d0c5f3 100644
--- a/samples/bpf/Makefile
+++ b/samples/bpf/Makefile
@@ -176,7 +176,7 @@ KBUILD_HOSTCFLAGS += -I$(srctree)/tools/testing/selftests/bpf/
KBUILD_HOSTCFLAGS += -I$(srctree)/tools/lib/ -I$(srctree)/tools/include
KBUILD_HOSTCFLAGS += -I$(srctree)/tools/perf
-HOSTCFLAGS_bpf_load.o += -I$(objtree)/usr/include -Wno-unused-variable
+HOSTCFLAGS_bpf_load.o += -Wno-unused-variable
KBUILD_HOSTLDLIBS += $(LIBBPF) -lelf
HOSTLDLIBS_tracex4 += -lrt
--
2.17.1
^ permalink raw reply related
* [PATCH bpf-next 08/11] samples: bpf: makefile: base progs build on makefile.progs
From: Ivan Khoronzhuk @ 2019-09-10 10:38 UTC (permalink / raw)
To: ast, daniel, yhs, davem, jakub.kicinski, hawk, john.fastabend
Cc: linux-kernel, netdev, bpf, clang-built-linux, Ivan Khoronzhuk
In-Reply-To: <20190910103830.20794-1-ivan.khoronzhuk@linaro.org>
The main reason for that - HOSTCC and CC have different aims.
It was tested for arm cross compilation, based on linaro toolchain,
but should work for others.
In order to split cross compilation (CC) with host build (HOSTCC),
lets base bpf samples on Makefile.progs. It allows to cross-compile
samples/bpf progs with CC while auxialry tools running on host built
with HOSTCC.
Signed-off-by: Ivan Khoronzhuk <ivan.khoronzhuk@linaro.org>
---
samples/bpf/Makefile | 138 +++++++++++++++++++++++--------------------
1 file changed, 73 insertions(+), 65 deletions(-)
diff --git a/samples/bpf/Makefile b/samples/bpf/Makefile
index f5dbf3d0c5f3..625a71f2e9d2 100644
--- a/samples/bpf/Makefile
+++ b/samples/bpf/Makefile
@@ -4,55 +4,53 @@ BPF_SAMPLES_PATH ?= $(abspath $(srctree)/$(src))
TOOLS_PATH := $(BPF_SAMPLES_PATH)/../../tools
# List of programs to build
-hostprogs-y := test_lru_dist
-hostprogs-y += sock_example
-hostprogs-y += fds_example
-hostprogs-y += sockex1
-hostprogs-y += sockex2
-hostprogs-y += sockex3
-hostprogs-y += tracex1
-hostprogs-y += tracex2
-hostprogs-y += tracex3
-hostprogs-y += tracex4
-hostprogs-y += tracex5
-hostprogs-y += tracex6
-hostprogs-y += tracex7
-hostprogs-y += test_probe_write_user
-hostprogs-y += trace_output
-hostprogs-y += lathist
-hostprogs-y += offwaketime
-hostprogs-y += spintest
-hostprogs-y += map_perf_test
-hostprogs-y += test_overhead
-hostprogs-y += test_cgrp2_array_pin
-hostprogs-y += test_cgrp2_attach
-hostprogs-y += test_cgrp2_sock
-hostprogs-y += test_cgrp2_sock2
-hostprogs-y += xdp1
-hostprogs-y += xdp2
-hostprogs-y += xdp_router_ipv4
-hostprogs-y += test_current_task_under_cgroup
-hostprogs-y += trace_event
-hostprogs-y += sampleip
-hostprogs-y += tc_l2_redirect
-hostprogs-y += lwt_len_hist
-hostprogs-y += xdp_tx_iptunnel
-hostprogs-y += test_map_in_map
-hostprogs-y += per_socket_stats_example
-hostprogs-y += xdp_redirect
-hostprogs-y += xdp_redirect_map
-hostprogs-y += xdp_redirect_cpu
-hostprogs-y += xdp_monitor
-hostprogs-y += xdp_rxq_info
-hostprogs-y += syscall_tp
-hostprogs-y += cpustat
-hostprogs-y += xdp_adjust_tail
-hostprogs-y += xdpsock
-hostprogs-y += xdp_fwd
-hostprogs-y += task_fd_query
-hostprogs-y += xdp_sample_pkts
-hostprogs-y += ibumad
-hostprogs-y += hbm
+progs-y := test_lru_dist
+progs-y += sock_example
+progs-y += fds_example
+progs-y += sockex1
+progs-y += sockex2
+progs-y += sockex3
+progs-y += tracex1
+progs-y += tracex2
+progs-y += tracex3
+progs-y += tracex4
+progs-y += tracex5
+progs-y += tracex6
+progs-y += tracex7
+progs-y += test_probe_write_user
+progs-y += trace_output
+progs-y += lathist
+progs-y += offwaketime
+progs-y += spintest
+progs-y += map_perf_test
+progs-y += test_overhead
+progs-y += test_cgrp2_array_pin
+progs-y += test_cgrp2_attach
+progs-y += test_cgrp2_sock
+progs-y += test_cgrp2_sock2
+progs-y += xdp1
+progs-y += xdp2
+progs-y += xdp_router_ipv4
+progs-y += test_current_task_under_cgroup
+progs-y += trace_event
+progs-y += sampleip
+progs-y += tc_l2_redirect
+progs-y += lwt_len_hist
+progs-y += xdp_tx_iptunnel
+progs-y += test_map_in_map
+progs-y += xdp_redirect_map
+progs-y += xdp_redirect_cpu
+progs-y += xdp_monitor
+progs-y += xdp_rxq_info
+progs-y += syscall_tp
+progs-y += cpustat
+progs-y += xdp_adjust_tail
+progs-y += xdpsock
+progs-y += xdp_fwd
+progs-y += task_fd_query
+progs-y += xdp_sample_pkts
+progs-y += ibumad
+progs-y += hbm
# Libbpf dependencies
LIBBPF = $(TOOLS_PATH)/lib/bpf/libbpf.a
@@ -111,7 +109,7 @@ ibumad-objs := bpf_load.o ibumad_user.o $(TRACE_HELPERS)
hbm-objs := bpf_load.o hbm.o $(CGROUP_HELPERS)
# Tell kbuild to always build the programs
-always := $(hostprogs-y)
+always := $(progs-y)
always += sockex1_kern.o
always += sockex2_kern.o
always += sockex3_kern.o
@@ -170,21 +168,6 @@ always += ibumad_kern.o
always += hbm_out_kern.o
always += hbm_edt_kern.o
-KBUILD_HOSTCFLAGS += -I$(objtree)/usr/include
-KBUILD_HOSTCFLAGS += -I$(srctree)/tools/lib/bpf/
-KBUILD_HOSTCFLAGS += -I$(srctree)/tools/testing/selftests/bpf/
-KBUILD_HOSTCFLAGS += -I$(srctree)/tools/lib/ -I$(srctree)/tools/include
-KBUILD_HOSTCFLAGS += -I$(srctree)/tools/perf
-
-HOSTCFLAGS_bpf_load.o += -Wno-unused-variable
-
-KBUILD_HOSTLDLIBS += $(LIBBPF) -lelf
-HOSTLDLIBS_tracex4 += -lrt
-HOSTLDLIBS_trace_output += -lrt
-HOSTLDLIBS_map_perf_test += -lrt
-HOSTLDLIBS_test_overhead += -lrt
-HOSTLDLIBS_xdpsock += -pthread
-
# Strip all expet -D options needed to handle linux headers
# for arm it's __LINUX_ARM_ARCH__ and potentially others fork vars
D_OPTIONS = $(shell echo "$(KBUILD_CFLAGS) " | sed 's/[[:blank:]]/\n/g' | \
@@ -194,6 +177,29 @@ ifeq ($(ARCH), arm)
CLANG_EXTRA_CFLAGS := $(D_OPTIONS)
endif
+ccflags-y += -I$(objtree)/usr/include
+ccflags-y += -I$(srctree)/tools/lib/bpf/
+ccflags-y += -I$(srctree)/tools/testing/selftests/bpf/
+ccflags-y += -I$(srctree)/tools/lib/
+ccflags-y += -I$(srctree)/tools/include
+ccflags-y += -I$(srctree)/tools/perf
+ccflags-y += $(D_OPTIONS)
+ccflags-y += -Wall
+ccflags-y += -fomit-frame-pointer
+ccflags-y += -Wmissing-prototypes
+ccflags-y += -Wstrict-prototypes
+
+PROGS_CFLAGS := $(ccflags-y)
+
+PROGCFLAGS_bpf_load.o += -Wno-unused-variable
+
+PROGS_LDLIBS := $(LIBBPF) -lelf
+PROGLDLIBS_tracex4 += -lrt
+PROGLDLIBS_trace_output += -lrt
+PROGLDLIBS_map_perf_test += -lrt
+PROGLDLIBS_test_overhead += -lrt
+PROGLDLIBS_xdpsock += -pthread
+
# Allows pointing LLC/CLANG to a LLVM backend with bpf support, redefine on cmdline:
# make samples/bpf/ LLC=~/git/llvm/build/bin/llc CLANG=~/git/llvm/build/bin/clang
LLC ?= llc
@@ -284,6 +290,8 @@ $(obj)/hbm_out_kern.o: $(src)/hbm.h $(src)/hbm_kern.h
$(obj)/hbm.o: $(src)/hbm.h
$(obj)/hbm_edt_kern.o: $(src)/hbm.h $(src)/hbm_kern.h
+-include $(BPF_SAMPLES_PATH)/Makefile.prog
+
# asm/sysreg.h - inline assembly used by it is incompatible with llvm.
# But, there is no easy way to fix it, so just exclude it since it is
# useless for BPF samples.
--
2.17.1
^ permalink raw reply related
* [PATCH bpf-next 07/11] samples: bpf: add makefile.prog for separate CC build
From: Ivan Khoronzhuk @ 2019-09-10 10:38 UTC (permalink / raw)
To: ast, daniel, yhs, davem, jakub.kicinski, hawk, john.fastabend
Cc: linux-kernel, netdev, bpf, clang-built-linux, Ivan Khoronzhuk
In-Reply-To: <20190910103830.20794-1-ivan.khoronzhuk@linaro.org>
The makefile.prog is added only, will be used in sample/bpf/Makefile
later in order to switch cross-compiling on CC from HOSTCC.
The HOSTCC is supposed to build binaries and tools running on the host
afterwards, in order to simplify build or so, like "fixdep" or else.
In case of cross compiling "fixdep" is executed on host when the rest
samples should run on target arch. In order to build binaries for
target arch with CC and tools running on host with HOSTCC, lets add
Makefile.prog for simplicity, having definition and routines similar
to ones, used in script/Makefile.host. This allows later add
cross-compilation to samples/bpf with minimum changes.
Makefile.prog contains only stuff needed for samples/bpf, potentially
can be reused and extended for other prog sets later and now needed
only for unblocking tricky samples/bpf cross compilation.
Signed-off-by: Ivan Khoronzhuk <ivan.khoronzhuk@linaro.org>
---
samples/bpf/Makefile.prog | 77 +++++++++++++++++++++++++++++++++++++++
1 file changed, 77 insertions(+)
create mode 100644 samples/bpf/Makefile.prog
diff --git a/samples/bpf/Makefile.prog b/samples/bpf/Makefile.prog
new file mode 100644
index 000000000000..3781999b9193
--- /dev/null
+++ b/samples/bpf/Makefile.prog
@@ -0,0 +1,77 @@
+# SPDX-License-Identifier: GPL-2.0
+# ==========================================================================
+# Building binaries on the host system
+# Binaries are not used during the compilation of the kernel, and intendent
+# to be build for target board, target board can be host ofc. Added to build
+# binaries to run not on host system.
+#
+# Only C is supported, but can be extended for C++.
+#
+# Sample syntax (see Documentation/kbuild/makefiles.rst for reference)
+# progs-y := xsk_example
+# Will compile xdpsock_example.c and create an executable named xsk_example
+#
+# progs-y := xdpsock
+# xdpsock-objs := xdpsock_1.o xdpsock_2.o
+# Will compile xdpsock_1.c and xdpsock_2.c, and then link the executable
+# xdpsock, based on xdpsock_1.o and xdpsock_2.o
+#
+# Inherited from scripts/Makefile.host
+#
+__progs := $(sort $(progs-y))
+
+# C code
+# Executables compiled from a single .c file
+prog-csingle := $(foreach m,$(__progs), \
+ $(if $($(m)-objs)$($(m)-cxxobjs),,$(m)))
+
+# C executables linked based on several .o files
+prog-cmulti := $(foreach m,$(__progs),\
+ $(if $($(m)-cxxobjs),,$(if $($(m)-objs),$(m))))
+
+# Object (.o) files compiled from .c files
+prog-cobjs := $(sort $(foreach m,$(__progs),$($(m)-objs)))
+
+prog-csingle := $(addprefix $(obj)/,$(prog-csingle))
+prog-cmulti := $(addprefix $(obj)/,$(prog-cmulti))
+prog-cobjs := $(addprefix $(obj)/,$(prog-cobjs))
+
+#####
+# Handle options to gcc. Support building with separate output directory
+
+_progc_flags = $(PROGS_CFLAGS) \
+ $(PROGCFLAGS_$(basetarget).o)
+
+# $(objtree)/$(obj) for including generated headers from checkin source files
+ifeq ($(KBUILD_EXTMOD),)
+ifdef building_out_of_srctree
+_progc_flags += -I $(objtree)/$(obj)
+endif
+endif
+
+progc_flags = -Wp,-MD,$(depfile) $(_progc_flags)
+
+# Create executable from a single .c file
+# prog-csingle -> Executable
+quiet_cmd_prog-csingle = CC $@
+ cmd_prog-csingle = $(CC) $(progc_flags) $(PROGS_LDFLAGS) -o $@ $< \
+ $(PROGS_LDLIBS) $(PROGLDLIBS_$(@F))
+$(prog-csingle): $(obj)/%: $(src)/%.c FORCE
+ $(call if_changed_dep,prog-csingle)
+
+# Link an executable based on list of .o files, all plain c
+# prog-cmulti -> executable
+quiet_cmd_prog-cmulti = LD $@
+ cmd_prog-cmulti = $(CC) $(progc_flags) $(PROGS_LDFLAGS) -o $@ \
+ $(addprefix $(obj)/,$($(@F)-objs)) \
+ $(PROGS_LDLIBS) $(PROGLDLIBS_$(@F))
+$(prog-cmulti): $(prog-cobjs) FORCE
+ $(call if_changed,prog-cmulti)
+$(call multi_depend, $(prog-cmulti), , -objs)
+
+# Create .o file from a single .c file
+# prog-cobjs -> .o
+quiet_cmd_prog-cobjs = CC $@
+ cmd_prog-cobjs = $(CC) $(progc_flags) -c -o $@ $<
+$(prog-cobjs): $(obj)/%.o: $(src)/%.c FORCE
+ $(call if_changed_dep,prog-cobjs)
--
2.17.1
^ permalink raw reply related
* [PATCH bpf-next 05/11] samples: bpf: makefile: use D vars from KBUILD_CFLAGS to handle headers
From: Ivan Khoronzhuk @ 2019-09-10 10:38 UTC (permalink / raw)
To: ast, daniel, yhs, davem, jakub.kicinski, hawk, john.fastabend
Cc: linux-kernel, netdev, bpf, clang-built-linux, Ivan Khoronzhuk
In-Reply-To: <20190910103830.20794-1-ivan.khoronzhuk@linaro.org>
The kernel headers are reused from samples bpf, and autoconf.h is not
enough to reflect complete arch configuration for clang. But CLANG-bpf
cmds are sensitive for assembler part taken from linux headers and -D
vars, usually used in CFLAGS, should be carefully added for each arch.
For that, for CLANG-bpf, lets filter them only for arm arch as it
definitely requires __LINUX_ARM_ARCH__ to be set, but ignore for
others till it's really needed. For arm, -D__LINUX_ARM_ARCH__ is min
version used as instruction set selector. In another case errors
like "SMP is not supported" for arm and bunch of other errors are
issued resulting to incorrect final object.
Later D_OPTIONS can be used for gcc part.
---
samples/bpf/Makefile | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/samples/bpf/Makefile b/samples/bpf/Makefile
index 8ecc5d0c2d5b..6492b7e65c08 100644
--- a/samples/bpf/Makefile
+++ b/samples/bpf/Makefile
@@ -185,6 +185,15 @@ HOSTLDLIBS_map_perf_test += -lrt
HOSTLDLIBS_test_overhead += -lrt
HOSTLDLIBS_xdpsock += -pthread
+# Strip all expet -D options needed to handle linux headers
+# for arm it's __LINUX_ARM_ARCH__ and potentially others fork vars
+D_OPTIONS = $(shell echo "$(KBUILD_CFLAGS) " | sed 's/[[:blank:]]/\n/g' | \
+ sed '/^-D/!d' | tr '\n' ' ')
+
+ifeq ($(ARCH), arm)
+CLANG_EXTRA_CFLAGS := $(D_OPTIONS)
+endif
+
# Allows pointing LLC/CLANG to a LLVM backend with bpf support, redefine on cmdline:
# make samples/bpf/ LLC=~/git/llvm/build/bin/llc CLANG=~/git/llvm/build/bin/clang
LLC ?= llc
--
2.17.1
^ permalink raw reply related
* [PATCH v4] tun: fix use-after-free when register netdev failed
From: Yang Yingliang @ 2019-09-10 10:56 UTC (permalink / raw)
To: netdev
Cc: jasowang, eric.dumazet, xiyou.wangcong, davem, yangyingliang,
weiyongjun1
I got a UAF repport in tun driver when doing fuzzy test:
[ 466.269490] ==================================================================
[ 466.271792] BUG: KASAN: use-after-free in tun_chr_read_iter+0x2ca/0x2d0
[ 466.271806] Read of size 8 at addr ffff888372139250 by task tun-test/2699
[ 466.271810]
[ 466.271824] CPU: 1 PID: 2699 Comm: tun-test Not tainted 5.3.0-rc1-00001-g5a9433db2614-dirty #427
[ 466.271833] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.12.1-0-ga5cab58e9a3f-prebuilt.qemu.org 04/01/2014
[ 466.271838] Call Trace:
[ 466.271858] dump_stack+0xca/0x13e
[ 466.271871] ? tun_chr_read_iter+0x2ca/0x2d0
[ 466.271890] print_address_description+0x79/0x440
[ 466.271906] ? vprintk_func+0x5e/0xf0
[ 466.271920] ? tun_chr_read_iter+0x2ca/0x2d0
[ 466.271935] __kasan_report+0x15c/0x1df
[ 466.271958] ? tun_chr_read_iter+0x2ca/0x2d0
[ 466.271976] kasan_report+0xe/0x20
[ 466.271987] tun_chr_read_iter+0x2ca/0x2d0
[ 466.272013] do_iter_readv_writev+0x4b7/0x740
[ 466.272032] ? default_llseek+0x2d0/0x2d0
[ 466.272072] do_iter_read+0x1c5/0x5e0
[ 466.272110] vfs_readv+0x108/0x180
[ 466.299007] ? compat_rw_copy_check_uvector+0x440/0x440
[ 466.299020] ? fsnotify+0x888/0xd50
[ 466.299040] ? __fsnotify_parent+0xd0/0x350
[ 466.299064] ? fsnotify_first_mark+0x1e0/0x1e0
[ 466.304548] ? vfs_write+0x264/0x510
[ 466.304569] ? ksys_write+0x101/0x210
[ 466.304591] ? do_preadv+0x116/0x1a0
[ 466.304609] do_preadv+0x116/0x1a0
[ 466.309829] do_syscall_64+0xc8/0x600
[ 466.309849] entry_SYSCALL_64_after_hwframe+0x49/0xbe
[ 466.309861] RIP: 0033:0x4560f9
[ 466.309875] Code: 00 00 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 44 00 00 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 b8 ff ff ff f7 d8 64 89 01 48
[ 466.309889] RSP: 002b:00007ffffa5166e8 EFLAGS: 00000206 ORIG_RAX: 0000000000000127
[ 466.322992] RAX: ffffffffffffffda RBX: 0000000000400460 RCX: 00000000004560f9
[ 466.322999] RDX: 0000000000000003 RSI: 00000000200008c0 RDI: 0000000000000003
[ 466.323007] RBP: 00007ffffa516700 R08: 0000000000000004 R09: 0000000000000000
[ 466.323014] R10: 0000000000000000 R11: 0000000000000206 R12: 000000000040cb10
[ 466.323021] R13: 0000000000000000 R14: 00000000006d7018 R15: 0000000000000000
[ 466.323057]
[ 466.323064] Allocated by task 2605:
[ 466.335165] save_stack+0x19/0x80
[ 466.336240] __kasan_kmalloc.constprop.8+0xa0/0xd0
[ 466.337755] kmem_cache_alloc+0xe8/0x320
[ 466.339050] getname_flags+0xca/0x560
[ 466.340229] user_path_at_empty+0x2c/0x50
[ 466.341508] vfs_statx+0xe6/0x190
[ 466.342619] __do_sys_newstat+0x81/0x100
[ 466.343908] do_syscall_64+0xc8/0x600
[ 466.345303] entry_SYSCALL_64_after_hwframe+0x49/0xbe
[ 466.347034]
[ 466.347517] Freed by task 2605:
[ 466.348471] save_stack+0x19/0x80
[ 466.349476] __kasan_slab_free+0x12e/0x180
[ 466.350726] kmem_cache_free+0xc8/0x430
[ 466.351874] putname+0xe2/0x120
[ 466.352921] filename_lookup+0x257/0x3e0
[ 466.354319] vfs_statx+0xe6/0x190
[ 466.355498] __do_sys_newstat+0x81/0x100
[ 466.356889] do_syscall_64+0xc8/0x600
[ 466.358037] entry_SYSCALL_64_after_hwframe+0x49/0xbe
[ 466.359567]
[ 466.360050] The buggy address belongs to the object at ffff888372139100
[ 466.360050] which belongs to the cache names_cache of size 4096
[ 466.363735] The buggy address is located 336 bytes inside of
[ 466.363735] 4096-byte region [ffff888372139100, ffff88837213a100)
[ 466.367179] The buggy address belongs to the page:
[ 466.368604] page:ffffea000dc84e00 refcount:1 mapcount:0 mapping:ffff8883df1b4f00 index:0x0 compound_mapcount: 0
[ 466.371582] flags: 0x2fffff80010200(slab|head)
[ 466.372910] raw: 002fffff80010200 dead000000000100 dead000000000122 ffff8883df1b4f00
[ 466.375209] raw: 0000000000000000 0000000000070007 00000001ffffffff 0000000000000000
[ 466.377778] page dumped because: kasan: bad access detected
[ 466.379730]
[ 466.380288] Memory state around the buggy address:
[ 466.381844] ffff888372139100: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
[ 466.384009] ffff888372139180: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
[ 466.386131] >ffff888372139200: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
[ 466.388257] ^
[ 466.390234] ffff888372139280: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
[ 466.392512] ffff888372139300: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
[ 466.394667] ==================================================================
tun_chr_read_iter() accessed the memory which freed by free_netdev()
called by tun_set_iff():
CPUA CPUB
tun_set_iff()
alloc_netdev_mqs()
tun_attach()
tun_chr_read_iter()
tun_get()
tun_do_read()
tun_ring_recv()
register_netdevice() <-- inject error
goto err_detach
tun_detach_all() <-- set RCV_SHUTDOWN
free_netdev() <-- called from
err_free_dev path
netdev_freemem() <-- free the memory
without check refcount
(In this path, the refcount cannot prevent
freeing the memory of dev, and the memory
will be used by dev_put() called by
tun_chr_read_iter() on CPUB.)
(Break from tun_ring_recv(),
because RCV_SHUTDOWN is set)
tun_put()
dev_put() <-- use the memory
freed by netdev_freemem()
Put the publishing of tfile->tun after register_netdevice(),
so tun_get() won't get the tun pointer that freed by
err_detach path if register_netdevice() failed.
Fixes: eb0fb363f920 ("tuntap: attach queue 0 before registering netdevice")
Reported-by: Hulk Robot <hulkci@huawei.com>
Suggested-by: Jason Wang <jasowang@redhat.com>
Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
---
drivers/net/tun.c | 16 +++++++++++-----
1 file changed, 11 insertions(+), 5 deletions(-)
diff --git a/drivers/net/tun.c b/drivers/net/tun.c
index db16d7a13e00..aab0be40d443 100644
--- a/drivers/net/tun.c
+++ b/drivers/net/tun.c
@@ -787,7 +787,8 @@ static void tun_detach_all(struct net_device *dev)
}
static int tun_attach(struct tun_struct *tun, struct file *file,
- bool skip_filter, bool napi, bool napi_frags)
+ bool skip_filter, bool napi, bool napi_frags,
+ bool publish_tun)
{
struct tun_file *tfile = file->private_data;
struct net_device *dev = tun->dev;
@@ -870,7 +871,8 @@ static int tun_attach(struct tun_struct *tun, struct file *file,
* initialized tfile; otherwise we risk using half-initialized
* object.
*/
- rcu_assign_pointer(tfile->tun, tun);
+ if (publish_tun)
+ rcu_assign_pointer(tfile->tun, tun);
rcu_assign_pointer(tun->tfiles[tun->numqueues], tfile);
tun->numqueues++;
tun_set_real_num_queues(tun);
@@ -2730,7 +2732,7 @@ static int tun_set_iff(struct net *net, struct file *file, struct ifreq *ifr)
err = tun_attach(tun, file, ifr->ifr_flags & IFF_NOFILTER,
ifr->ifr_flags & IFF_NAPI,
- ifr->ifr_flags & IFF_NAPI_FRAGS);
+ ifr->ifr_flags & IFF_NAPI_FRAGS, true);
if (err < 0)
return err;
@@ -2829,13 +2831,17 @@ static int tun_set_iff(struct net *net, struct file *file, struct ifreq *ifr)
INIT_LIST_HEAD(&tun->disabled);
err = tun_attach(tun, file, false, ifr->ifr_flags & IFF_NAPI,
- ifr->ifr_flags & IFF_NAPI_FRAGS);
+ ifr->ifr_flags & IFF_NAPI_FRAGS, false);
if (err < 0)
goto err_free_flow;
err = register_netdevice(tun->dev);
if (err < 0)
goto err_detach;
+ /* free_netdev() won't check refcnt, to aovid race
+ * with dev_put() we need publish tun after registration.
+ */
+ rcu_assign_pointer(tfile->tun, tun);
}
netif_carrier_on(tun->dev);
@@ -2978,7 +2984,7 @@ static int tun_set_queue(struct file *file, struct ifreq *ifr)
if (ret < 0)
goto unlock;
ret = tun_attach(tun, file, false, tun->flags & IFF_NAPI,
- tun->flags & IFF_NAPI_FRAGS);
+ tun->flags & IFF_NAPI_FRAGS, true);
} else if (ifr->ifr_flags & IFF_DETACH_QUEUE) {
tun = rtnl_dereference(tfile->tun);
if (!tun || !(tun->flags & IFF_MULTI_QUEUE) || tfile->detached)
--
2.17.1
^ permalink raw reply related
* [PATCH bpf-next 03/11] samples: bpf: makefile: use --target from cross-compile
From: Ivan Khoronzhuk @ 2019-09-10 10:38 UTC (permalink / raw)
To: ast, daniel, yhs, davem, jakub.kicinski, hawk, john.fastabend
Cc: linux-kernel, netdev, bpf, clang-built-linux, Ivan Khoronzhuk
In-Reply-To: <20190910103830.20794-1-ivan.khoronzhuk@linaro.org>
For cross compiling the target triple can be inherited from
cross-compile prefix as it's done in CLANG_FLAGS from kernel makefile.
So copy-paste this decision from kernel Makefile.
Signed-off-by: Ivan Khoronzhuk <ivan.khoronzhuk@linaro.org>
---
samples/bpf/Makefile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/samples/bpf/Makefile b/samples/bpf/Makefile
index 43dee90dffa4..b59e77e2250e 100644
--- a/samples/bpf/Makefile
+++ b/samples/bpf/Makefile
@@ -195,7 +195,7 @@ BTF_PAHOLE ?= pahole
# Detect that we're cross compiling and use the cross compiler
ifdef CROSS_COMPILE
HOSTCC = $(CROSS_COMPILE)gcc
-CLANG_ARCH_ARGS = -target $(ARCH)
+CLANG_ARCH_ARGS = --target=$(notdir $(CROSS_COMPILE:%-=%))
endif
# Don't evaluate probes and warnings if we need to run make recursively
--
2.17.1
^ permalink raw reply related
* [PATCH bpf-next 02/11] samples: bpf: makefile: fix cookie_uid_helper_example obj build
From: Ivan Khoronzhuk @ 2019-09-10 10:38 UTC (permalink / raw)
To: ast, daniel, yhs, davem, jakub.kicinski, hawk, john.fastabend
Cc: linux-kernel, netdev, bpf, clang-built-linux, Ivan Khoronzhuk
In-Reply-To: <20190910103830.20794-1-ivan.khoronzhuk@linaro.org>
Don't list userspace "cookie_uid_helper_example" object in list for
bpf objects.
per_socket_stats_example-opjs is used to list additional dependencies
for user space binary from hostprogs-y list. Kbuild system creates
rules for objects listed this way anyway and no need to worry about
this. Despite on it, the samples bpf uses logic that hostporgs-y are
build for userspace with includes needed for this, but "always"
target, if it's not in hostprog-y list, uses CLANG-bpf rule and is
intended to create bpf obj but not arch obj and uses only kernel
includes for that. So correct it, as it breaks cross-compiling at
least.
Signed-off-by: Ivan Khoronzhuk <ivan.khoronzhuk@linaro.org>
---
samples/bpf/Makefile | 1 -
1 file changed, 1 deletion(-)
diff --git a/samples/bpf/Makefile b/samples/bpf/Makefile
index f50ca852c2a8..43dee90dffa4 100644
--- a/samples/bpf/Makefile
+++ b/samples/bpf/Makefile
@@ -145,7 +145,6 @@ always += sampleip_kern.o
always += lwt_len_hist_kern.o
always += xdp_tx_iptunnel_kern.o
always += test_map_in_map_kern.o
-always += cookie_uid_helper_example.o
always += tcp_synrto_kern.o
always += tcp_rwnd_kern.o
always += tcp_bufs_kern.o
--
2.17.1
^ permalink raw reply related
* [PATCH bpf-next 01/11] samples: bpf: makefile: fix HDR_PROBE "echo"
From: Ivan Khoronzhuk @ 2019-09-10 10:38 UTC (permalink / raw)
To: ast, daniel, yhs, davem, jakub.kicinski, hawk, john.fastabend
Cc: linux-kernel, netdev, bpf, clang-built-linux, Ivan Khoronzhuk
In-Reply-To: <20190910103830.20794-1-ivan.khoronzhuk@linaro.org>
echo should be replaced on echo -e to handle \n correctly, but instead,
replace it on printf as some systems can't handle echo -e.
Signed-off-by: Ivan Khoronzhuk <ivan.khoronzhuk@linaro.org>
---
samples/bpf/Makefile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/samples/bpf/Makefile b/samples/bpf/Makefile
index 1d9be26b4edd..f50ca852c2a8 100644
--- a/samples/bpf/Makefile
+++ b/samples/bpf/Makefile
@@ -201,7 +201,7 @@ endif
# Don't evaluate probes and warnings if we need to run make recursively
ifneq ($(src),)
-HDR_PROBE := $(shell echo "\#include <linux/types.h>\n struct list_head { int a; }; int main() { return 0; }" | \
+HDR_PROBE := $(shell printf "\#include <linux/types.h>\n struct list_head { int a; }; int main() { return 0; }" | \
$(HOSTCC) $(KBUILD_HOSTCFLAGS) -x c - -o /dev/null 2>/dev/null && \
echo okay)
--
2.17.1
^ permalink raw reply related
* [PATCH bpf-next 00/11] samples: bpf: improve/fix cross-compilation
From: Ivan Khoronzhuk @ 2019-09-10 10:38 UTC (permalink / raw)
To: ast, daniel, yhs, davem, jakub.kicinski, hawk, john.fastabend
Cc: linux-kernel, netdev, bpf, clang-built-linux, Ivan Khoronzhuk
This series contains mainly fixes/improvements for cross-compilation
but not only, tested for arm, arm64, but intended for any arch.
Also verified on native build (not cross compilation) for x86_64
and arm.
Initial RFC link:
https://lkml.org/lkml/2019/8/29/1665
Prev. version:
https://www.spinics.net/lists/netdev/msg597823.html
Besides the patches given here, the RFC also contains couple patches
related to llvm clang
arm: include: asm: swab: mask rev16 instruction for clang
arm: include: asm: unified: mask .syntax unified for clang
They are necessarily to verify arm build.
The change touches not only cross-compilation and can have impact on
other archs and build environments, so might be good idea to verify
it in order to add appropriate changes, some warn options could be
tuned also.
All is tasted on x86-64 with clang installed (has to be built containing
targets for arm, arm64..., see llvm -v, usually it's present already)
Instructions to test native on x86_64
=================================================
Native build on x86_64 is done in usual way and shouldn't have difference
except HOSTCC is now printed as CC wile building the samples.
Instructions to test cross compilation on arm64
=================================================
#Toolchain used for test:
gcc version 8.3.0
(GNU Toolchain for the A-profile Architecture 8.3-2019.03 (arm-rel-8.36))
# Get some arm64 FS, containing at least libelf
I've used sdk for TI am65x got here:
http://downloads.ti.com/processor-sdk-linux/esd/AM65X/latest/exports/\
ti-processor-sdk-linux-am65xx-evm-06.00.00.07-Linux-x86-Install.bin
# Install this binary to some dir, say "sdk".
# Configure kernel (use defconfig as no matter), but clean everything
# before.
make ARCH=arm64 -C tools/ clean
make ARCH=arm64 -C samples/bpf clean
make ARCH=arm64 clean
make ARCH=arm64 defconfig
# The kernel version used in sdk doesn't correspond to checked one,
# but for this verification only headers need to be syched,
# so install them:
make ARCH=arm64 headers_install
# or on SDK if need keep them in sync (not necessarily to verify):
make ARCH=arm64 INSTALL_HDR_PATH=/../sdk/\
ti-processor-sdk-linux-am65xx-evm-06.00.00.07/linux-devkit/sysroots/\
aarch64-linux/usr headers_install
# Build samples
make samples/bpf/ ARCH=arm64 CROSS_COMPILE="aarch64-linux-gnu-"\
SYSROOT="/../sdk/ti-processor-sdk-linux-am65xx-evm-06.00.00.07/\
linux-devkit/sysroots/aarch64-linux"
Instructions to test cross compilation on arm
=================================================
#Toolchains used for test:
arm-linux-gnueabihf-gcc (Linaro GCC 7.2-2017.11) 7.2.1 20171011
or
arm-linux-gnueabihf-gcc
(GNU Toolchain for the A-profile Architecture 8.3-2019.03 \
(arm-rel-8.36)) 8.3.0
# Get some FS, I've used sdk for TI am52xx got here:
http://downloads.ti.com/processor-sdk-linux/esd/AM57X/05_03_00_07/exports/\
ti-processor-sdk-linux-am57xx-evm-05.03.00.07-Linux-x86-Install.bin
# Install this binary to some dir, say "sdk".
# Configure kernel, but clean everything before.
make ARCH=arm -C tools/ clean
make ARCH=arm -C samples/bpf clean
make ARCH=arm clean
make ARCH=arm omap2plus_defconfig
# The kernel version used in sdk doesn't correspond to checked one, but
headers only should be synched, so install them:
make ARCH=arm64 headers_install
# or on SDK if need keep them in sync (not necessarily):
make ARCH=arm INSTALL_HDR_PATH=/../sdk/\
ti-processor-sdk-linux-am57xx-evm-05.03.00.07/linux-devkit/sysroots/\
armv7ahf-neon-linux-gnueabi/usr headers_install
# Build samples
make samples/bpf/ ARCH=arm CROSS_COMPILE="arm-linux-gnueabihf-"\
SYSROOT="/../sdk/ti-processor-sdk-linux-am57xx-evm-05.03\
.00.07/linux-devkit/sysroots/armv7ahf-neon-linux-gnueabi"
Based on bpf-next/master
v2..v1:
- restructured patches order
- split "samples: bpf: Makefile: base progs build on Makefile.progs"
to make change more readable. It added couple nice extra patches.
- removed redundant patch:
"samples: bpf: Makefile: remove target for native build"
- added fix:
"samples: bpf: makefile: fix cookie_uid_helper_example obj build"
- limited -D option filter only for arm
- improved comments
- added couple instructions to verify cross compilation for arm and
arm64 arches based on TI am57xx and am65xx sdks.
- corrected include a little order
Ivan Khoronzhuk (11):
samples: bpf: makefile: fix HDR_PROBE "echo"
samples: bpf: makefile: fix cookie_uid_helper_example obj build
samples: bpf: makefile: use --target from cross-compile
samples: bpf: use own EXTRA_CFLAGS for clang commands
samples: bpf: makefile: use D vars from KBUILD_CFLAGS to handle
headers
samples: bpf: makefile: drop unnecessarily inclusion for bpf_load
samples: bpf: add makefile.prog for separate CC build
samples: bpf: makefile: base progs build on makefile.progs
samples: bpf: makefile: use CC environment for HDR_PROBE
libbpf: makefile: add C/CXX/LDFLAGS to libbpf.so and test_libpf
targets
samples: bpf: makefile: add sysroot support
samples/bpf/Makefile | 172 ++++++++++++++++++++++----------------
samples/bpf/Makefile.prog | 77 +++++++++++++++++
samples/bpf/README.rst | 10 +++
tools/lib/bpf/Makefile | 11 ++-
4 files changed, 194 insertions(+), 76 deletions(-)
create mode 100644 samples/bpf/Makefile.prog
--
2.17.1
^ permalink raw reply
* Re: [PATCH bpf-next 01/11] samples: bpf: makefile: fix HDR_PROBE "echo"
From: Sergei Shtylyov @ 2019-09-10 10:46 UTC (permalink / raw)
To: Ivan Khoronzhuk, ast, daniel, yhs, davem, jakub.kicinski, hawk,
john.fastabend
Cc: linux-kernel, netdev, bpf, clang-built-linux
In-Reply-To: <20190910103830.20794-2-ivan.khoronzhuk@linaro.org>
Hello!
On 10.09.2019 13:38, Ivan Khoronzhuk wrote:
> echo should be replaced on echo -e to handle \n correctly, but instead,
s/on/with/?
> replace it on printf as some systems can't handle echo -e.
Likewise?
> Signed-off-by: Ivan Khoronzhuk <ivan.khoronzhuk@linaro.org>
[...]
MBR, Sergei
^ permalink raw reply
* Re: ❌ FAIL: Stable queue: queue-5.2
From: Sasha Levin @ 2019-09-10 10:52 UTC (permalink / raw)
To: Hangbin Liu
Cc: Greg KH, CKI Project, Linux Stable maillist, netdev, Jan Stancek,
Xiumei Mu, David Howells, linux-afs
In-Reply-To: <20190910094025.GM22496@dhcp-12-139.nay.redhat.com>
On Tue, Sep 10, 2019 at 05:40:25PM +0800, Hangbin Liu wrote:
>On Tue, Sep 10, 2019 at 05:30:21PM +0800, Hangbin Liu wrote:
>> Xiumei Mu also forwarded me a mail. It looks Sasha has fixed something.
>> But I don't know the details.
>
>Oh, I checked that thread. It's the same issue. So Sasha should has fixed it. I
>just wonder the commit id now.
That was fixed by upstream commit
b00df840fb4004b7087940ac5f68801562d0d2de.
--
Thanks,
Sasha
^ permalink raw reply
* [PATCH] ipv6: Fix the link time qualifier of 'ping_v6_proc_exit_net()'
From: Christophe JAILLET @ 2019-09-10 11:29 UTC (permalink / raw)
To: davem, kuznet, yoshfuji
Cc: netdev, linux-kernel, kernel-janitors, Christophe JAILLET
The '.exit' functions from 'pernet_operations' structure should be marked
as __net_exit, not __net_init.
Fixes: d862e5461423 ("net: ipv6: Implement /proc/net/icmp6.")
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
Untested, but using __net_exit looks consistent with other
pernet_operations.exit use case.
---
net/ipv6/ping.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/net/ipv6/ping.c b/net/ipv6/ping.c
index 87d2d8c1db7c..98ac32b49d8c 100644
--- a/net/ipv6/ping.c
+++ b/net/ipv6/ping.c
@@ -223,7 +223,7 @@ static int __net_init ping_v6_proc_init_net(struct net *net)
return 0;
}
-static void __net_init ping_v6_proc_exit_net(struct net *net)
+static void __net_exit ping_v6_proc_exit_net(struct net *net)
{
remove_proc_entry("icmp6", net->proc_net);
}
--
2.20.1
^ permalink raw reply related
* Re: ❌ FAIL: Stable queue: queue-5.2
From: Hangbin Liu @ 2019-09-10 11:39 UTC (permalink / raw)
To: Sasha Levin; +Cc: Greg KH, netdev, Jan Stancek, Xiumei Mu, David Howells
In-Reply-To: <20190910105223.GG2012@sasha-vm>
On Tue, Sep 10, 2019 at 06:52:23AM -0400, Sasha Levin wrote:
> On Tue, Sep 10, 2019 at 05:40:25PM +0800, Hangbin Liu wrote:
> > On Tue, Sep 10, 2019 at 05:30:21PM +0800, Hangbin Liu wrote:
> > > Xiumei Mu also forwarded me a mail. It looks Sasha has fixed something.
> > > But I don't know the details.
> >
> > Oh, I checked that thread. It's the same issue. So Sasha should has fixed it. I
> > just wonder the commit id now.
>
> That was fixed by upstream commit
> b00df840fb4004b7087940ac5f68801562d0d2de.
Got it, thanks for this info.
^ permalink raw reply
* Re: [PATCH v3 1/2] ethtool: implement Energy Detect Powerdown support via phy-tunable
From: Ardelean, Alexandru @ 2019-09-10 12:07 UTC (permalink / raw)
To: mkubecek@suse.cz, netdev@vger.kernel.org
Cc: andrew@lunn.ch, davem@davemloft.net, hkallweit1@gmail.com,
devicetree@vger.kernel.org, mark.rutland@arm.com,
linux-kernel@vger.kernel.org, f.fainelli@gmail.com,
robh+dt@kernel.org
In-Reply-To: <20190910080014.GC24779@unicorn.suse.cz>
On Tue, 2019-09-10 at 10:00 +0200, Michal Kubecek wrote:
> [External]
>
> 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.
>
I was also a bit uncertain/undecided here about letting PHYs decide units.
And I also wasn't sure what to propose.
Not proposing a unit now, would have allowed us to decide later based on what PHYs implement (generally) in the future.
I know that may make me look a bit lazy [for not proposing units in ethtool], but tbh it's more of lack-of-experience
with ethtool (or these APIs) evolve over time.
> 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?
I think 65 seconds is more than enough.
I feel that, if you plug-in an eth cable and don't have a link in a minute, then it's not great (no matter how much of a
power-saver you are).
Actually, voicing out these units makes it simpler for a decision to go in favor for milliseconds.
So: thank you :)
Alex
>
> Michal Kubecek
>
> > * disable EDPD
> >
> > Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
^ permalink raw reply
page: next (older) | prev (newer) | latest
- recent:[subjects (threaded)|topics (new)|topics (active)]
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox