* [PATCH V2 3/8] mdev: bus uevent support
From: Jason Wang @ 2019-09-24 13:53 UTC (permalink / raw)
To: kvm, linux-s390, linux-kernel, dri-devel, intel-gfx,
intel-gvt-dev, kwankhede, alex.williamson, mst, tiwei.bie
Cc: virtualization, netdev, cohuck, maxime.coquelin, cunming.liang,
zhihong.wang, rob.miller, xiao.w.wang, haotian.wang, zhenyuw,
zhi.a.wang, jani.nikula, joonas.lahtinen, rodrigo.vivi, airlied,
daniel, farman, pasic, sebott, oberpar, heiko.carstens, gor,
borntraeger, akrowiak, freude, lingshan.zhu, idos, eperezma, lulu,
parav, christophe.de.dinechin, kevin.tian, Jason Wang
In-Reply-To: <20190924135332.14160-1-jasowang@redhat.com>
This patch adds bus uevent support for mdev bus in order to allow
cooperation with userspace.
Signed-off-by: Jason Wang <jasowang@redhat.com>
---
drivers/vfio/mdev/mdev_driver.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/drivers/vfio/mdev/mdev_driver.c b/drivers/vfio/mdev/mdev_driver.c
index b7c40ce86ee3..319d886ffaf7 100644
--- a/drivers/vfio/mdev/mdev_driver.c
+++ b/drivers/vfio/mdev/mdev_driver.c
@@ -82,9 +82,17 @@ static int mdev_match(struct device *dev, struct device_driver *drv)
return 0;
}
+static int mdev_uevent(struct device *dev, struct kobj_uevent_env *env)
+{
+ struct mdev_device *mdev = to_mdev_device(dev);
+
+ return add_uevent_var(env, "MODALIAS=mdev:c%02X", mdev->class_id);
+}
+
struct bus_type mdev_bus_type = {
.name = "mdev",
.match = mdev_match,
+ .uevent = mdev_uevent,
.probe = mdev_probe,
.remove = mdev_remove,
};
--
2.19.1
^ permalink raw reply related
* [PATCH V2 4/8] modpost: add support for mdev class id
From: Jason Wang @ 2019-09-24 13:53 UTC (permalink / raw)
To: kvm, linux-s390, linux-kernel, dri-devel, intel-gfx,
intel-gvt-dev, kwankhede, alex.williamson, mst, tiwei.bie
Cc: virtualization, netdev, cohuck, maxime.coquelin, cunming.liang,
zhihong.wang, rob.miller, xiao.w.wang, haotian.wang, zhenyuw,
zhi.a.wang, jani.nikula, joonas.lahtinen, rodrigo.vivi, airlied,
daniel, farman, pasic, sebott, oberpar, heiko.carstens, gor,
borntraeger, akrowiak, freude, lingshan.zhu, idos, eperezma, lulu,
parav, christophe.de.dinechin, kevin.tian, Jason Wang
In-Reply-To: <20190924135332.14160-1-jasowang@redhat.com>
Add support to parse mdev class id table.
Signed-off-by: Jason Wang <jasowang@redhat.com>
---
drivers/vfio/mdev/vfio_mdev.c | 2 ++
scripts/mod/devicetable-offsets.c | 3 +++
scripts/mod/file2alias.c | 10 ++++++++++
3 files changed, 15 insertions(+)
diff --git a/drivers/vfio/mdev/vfio_mdev.c b/drivers/vfio/mdev/vfio_mdev.c
index fd2a4d9a3f26..891cf83a2d9a 100644
--- a/drivers/vfio/mdev/vfio_mdev.c
+++ b/drivers/vfio/mdev/vfio_mdev.c
@@ -125,6 +125,8 @@ static struct mdev_class_id id_table[] = {
{ 0 },
};
+MODULE_DEVICE_TABLE(mdev, id_table);
+
static struct mdev_driver vfio_mdev_driver = {
.name = "vfio_mdev",
.probe = vfio_mdev_probe,
diff --git a/scripts/mod/devicetable-offsets.c b/scripts/mod/devicetable-offsets.c
index 054405b90ba4..6cbb1062488a 100644
--- a/scripts/mod/devicetable-offsets.c
+++ b/scripts/mod/devicetable-offsets.c
@@ -231,5 +231,8 @@ int main(void)
DEVID(wmi_device_id);
DEVID_FIELD(wmi_device_id, guid_string);
+ DEVID(mdev_class_id);
+ DEVID_FIELD(mdev_class_id, id);
+
return 0;
}
diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
index e17a29ae2e97..6805f87a1149 100644
--- a/scripts/mod/file2alias.c
+++ b/scripts/mod/file2alias.c
@@ -1330,6 +1330,15 @@ static int do_wmi_entry(const char *filename, void *symval, char *alias)
return 1;
}
+/* looks like: "mdev:cN" */
+static int do_mdev_entry(const char *filename, void *symval, char *alias)
+{
+ DEF_FIELD(symval, mdev_class_id, id);
+
+ sprintf(alias, "mdev:c%02X", id);
+ return 1;
+}
+
/* Does namelen bytes of name exactly match the symbol? */
static bool sym_is(const char *name, unsigned namelen, const char *symbol)
{
@@ -1402,6 +1411,7 @@ static const struct devtable devtable[] = {
{"typec", SIZE_typec_device_id, do_typec_entry},
{"tee", SIZE_tee_client_device_id, do_tee_entry},
{"wmi", SIZE_wmi_device_id, do_wmi_entry},
+ {"mdev", SIZE_mdev_class_id, do_mdev_entry},
};
/* Create MODULE_ALIAS() statements.
--
2.19.1
^ permalink raw reply related
* [PATCH V2 5/8] mdev: introduce device specific ops
From: Jason Wang @ 2019-09-24 13:53 UTC (permalink / raw)
To: kvm, linux-s390, linux-kernel, dri-devel, intel-gfx,
intel-gvt-dev, kwankhede, alex.williamson, mst, tiwei.bie
Cc: virtualization, netdev, cohuck, maxime.coquelin, cunming.liang,
zhihong.wang, rob.miller, xiao.w.wang, haotian.wang, zhenyuw,
zhi.a.wang, jani.nikula, joonas.lahtinen, rodrigo.vivi, airlied,
daniel, farman, pasic, sebott, oberpar, heiko.carstens, gor,
borntraeger, akrowiak, freude, lingshan.zhu, idos, eperezma, lulu,
parav, christophe.de.dinechin, kevin.tian, Jason Wang
In-Reply-To: <20190924135332.14160-1-jasowang@redhat.com>
Currently, except for the create and remove, the rest of
mdev_parent_ops is designed for vfio-mdev driver only and may not help
for kernel mdev driver. With the help of class id, this patch
introduces device specific callbacks inside mdev_device
structure. This allows different set of callback to be used by
vfio-mdev and virtio-mdev.
Signed-off-by: Jason Wang <jasowang@redhat.com>
---
.../driver-api/vfio-mediated-device.rst | 4 +-
MAINTAINERS | 1 +
drivers/gpu/drm/i915/gvt/kvmgt.c | 17 +++---
drivers/s390/cio/vfio_ccw_ops.c | 17 ++++--
drivers/s390/crypto/vfio_ap_ops.c | 13 +++--
drivers/vfio/mdev/mdev_core.c | 12 +++++
drivers/vfio/mdev/mdev_private.h | 1 +
drivers/vfio/mdev/vfio_mdev.c | 37 ++++++-------
include/linux/mdev.h | 42 ++++-----------
include/linux/vfio_mdev.h | 52 +++++++++++++++++++
samples/vfio-mdev/mbochs.c | 19 ++++---
samples/vfio-mdev/mdpy.c | 19 ++++---
samples/vfio-mdev/mtty.c | 17 ++++--
13 files changed, 168 insertions(+), 83 deletions(-)
create mode 100644 include/linux/vfio_mdev.h
diff --git a/Documentation/driver-api/vfio-mediated-device.rst b/Documentation/driver-api/vfio-mediated-device.rst
index a5bdc60d62a1..d50425b368bb 100644
--- a/Documentation/driver-api/vfio-mediated-device.rst
+++ b/Documentation/driver-api/vfio-mediated-device.rst
@@ -152,7 +152,9 @@ callbacks per mdev parent device, per mdev type, or any other categorization.
Vendor drivers are expected to be fully asynchronous in this respect or
provide their own internal resource protection.)
-The callbacks in the mdev_parent_ops structure are as follows:
+The device specific callbacks are referred through device_ops pointer
+in mdev_parent_ops. For vfio-mdev device, its callbacks in device_ops
+are as follows:
* open: open callback of mediated device
* close: close callback of mediated device
diff --git a/MAINTAINERS b/MAINTAINERS
index b2326dece28e..89832b316500 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -17075,6 +17075,7 @@ S: Maintained
F: Documentation/driver-api/vfio-mediated-device.rst
F: drivers/vfio/mdev/
F: include/linux/mdev.h
+F: include/linux/vfio_mdev.h
F: samples/vfio-mdev/
VFIO PLATFORM DRIVER
diff --git a/drivers/gpu/drm/i915/gvt/kvmgt.c b/drivers/gpu/drm/i915/gvt/kvmgt.c
index f793252a3d2a..b274f5ee481f 100644
--- a/drivers/gpu/drm/i915/gvt/kvmgt.c
+++ b/drivers/gpu/drm/i915/gvt/kvmgt.c
@@ -42,6 +42,7 @@
#include <linux/kvm_host.h>
#include <linux/vfio.h>
#include <linux/mdev.h>
+#include <linux/vfio_mdev.h>
#include <linux/debugfs.h>
#include <linux/nospec.h>
@@ -643,6 +644,8 @@ static void kvmgt_put_vfio_device(void *vgpu)
vfio_device_put(((struct intel_vgpu *)vgpu)->vdev.vfio_device);
}
+static struct vfio_mdev_device_ops intel_vfio_vgpu_dev_ops;
+
static int intel_vgpu_create(struct kobject *kobj, struct mdev_device *mdev)
{
struct intel_vgpu *vgpu = NULL;
@@ -679,6 +682,7 @@ static int intel_vgpu_create(struct kobject *kobj, struct mdev_device *mdev)
ret = 0;
mdev_set_class_id(mdev, MDEV_ID_VFIO);
+ mdev_set_dev_ops(mdev, &intel_vfio_vgpu_dev_ops);
out:
return ret;
}
@@ -1601,20 +1605,21 @@ static const struct attribute_group *intel_vgpu_groups[] = {
NULL,
};
-static struct mdev_parent_ops intel_vgpu_ops = {
- .mdev_attr_groups = intel_vgpu_groups,
- .create = intel_vgpu_create,
- .remove = intel_vgpu_remove,
-
+static struct vfio_mdev_device_ops intel_vfio_vgpu_dev_ops = {
.open = intel_vgpu_open,
.release = intel_vgpu_release,
-
.read = intel_vgpu_read,
.write = intel_vgpu_write,
.mmap = intel_vgpu_mmap,
.ioctl = intel_vgpu_ioctl,
};
+static struct mdev_parent_ops intel_vgpu_ops = {
+ .mdev_attr_groups = intel_vgpu_groups,
+ .create = intel_vgpu_create,
+ .remove = intel_vgpu_remove,
+};
+
static int kvmgt_host_init(struct device *dev, void *gvt, const void *ops)
{
struct attribute **kvm_type_attrs;
diff --git a/drivers/s390/cio/vfio_ccw_ops.c b/drivers/s390/cio/vfio_ccw_ops.c
index d258ef1fedb9..329d53c1f46b 100644
--- a/drivers/s390/cio/vfio_ccw_ops.c
+++ b/drivers/s390/cio/vfio_ccw_ops.c
@@ -12,6 +12,7 @@
#include <linux/vfio.h>
#include <linux/mdev.h>
+#include <linux/vfio_mdev.h>
#include <linux/nospec.h>
#include <linux/slab.h>
@@ -110,6 +111,8 @@ static struct attribute_group *mdev_type_groups[] = {
NULL,
};
+static const struct vfio_mdev_device_ops vfio_mdev_ops;
+
static int vfio_ccw_mdev_create(struct kobject *kobj, struct mdev_device *mdev)
{
struct vfio_ccw_private *private =
@@ -130,6 +133,7 @@ static int vfio_ccw_mdev_create(struct kobject *kobj, struct mdev_device *mdev)
private->sch->schid.sch_no);
mdev_set_class_id(mdev, MDEV_ID_VFIO);
+ mdev_set_dev_ops(mdev, &vfio_mdev_ops);
return 0;
}
@@ -575,11 +579,7 @@ static ssize_t vfio_ccw_mdev_ioctl(struct mdev_device *mdev,
}
}
-static const struct mdev_parent_ops vfio_ccw_mdev_ops = {
- .owner = THIS_MODULE,
- .supported_type_groups = mdev_type_groups,
- .create = vfio_ccw_mdev_create,
- .remove = vfio_ccw_mdev_remove,
+static const struct vfio_mdev_device_ops vfio_mdev_ops = {
.open = vfio_ccw_mdev_open,
.release = vfio_ccw_mdev_release,
.read = vfio_ccw_mdev_read,
@@ -587,6 +587,13 @@ static const struct mdev_parent_ops vfio_ccw_mdev_ops = {
.ioctl = vfio_ccw_mdev_ioctl,
};
+static const struct mdev_parent_ops vfio_ccw_mdev_ops = {
+ .owner = THIS_MODULE,
+ .supported_type_groups = mdev_type_groups,
+ .create = vfio_ccw_mdev_create,
+ .remove = vfio_ccw_mdev_remove,
+};
+
int vfio_ccw_mdev_reg(struct subchannel *sch)
{
return mdev_register_device(&sch->dev, &vfio_ccw_mdev_ops);
diff --git a/drivers/s390/crypto/vfio_ap_ops.c b/drivers/s390/crypto/vfio_ap_ops.c
index 2cfd96112aa0..3a89933f0d3e 100644
--- a/drivers/s390/crypto/vfio_ap_ops.c
+++ b/drivers/s390/crypto/vfio_ap_ops.c
@@ -16,6 +16,7 @@
#include <linux/bitops.h>
#include <linux/kvm_host.h>
#include <linux/module.h>
+#include <linux/vfio_mdev.h>
#include <asm/kvm.h>
#include <asm/zcrypt.h>
@@ -321,6 +322,8 @@ static void vfio_ap_matrix_init(struct ap_config_info *info,
matrix->adm_max = info->apxa ? info->Nd : 15;
}
+static const struct vfio_mdev_device_ops vfio_mdev_ops;
+
static int vfio_ap_mdev_create(struct kobject *kobj, struct mdev_device *mdev)
{
struct ap_matrix_mdev *matrix_mdev;
@@ -344,6 +347,7 @@ static int vfio_ap_mdev_create(struct kobject *kobj, struct mdev_device *mdev)
mutex_unlock(&matrix_dev->lock);
mdev_set_class_id(mdev, MDEV_ID_VFIO);
+ mdev_set_dev_ops(mdev, &vfio_mdev_ops);
return 0;
}
@@ -1281,15 +1285,18 @@ static ssize_t vfio_ap_mdev_ioctl(struct mdev_device *mdev,
return ret;
}
+static const struct vfio_mdev_device_ops vfio_mdev_ops = {
+ .open = vfio_ap_mdev_open,
+ .release = vfio_ap_mdev_release,
+ .ioctl = vfio_ap_mdev_ioctl,
+};
+
static const struct mdev_parent_ops vfio_ap_matrix_ops = {
.owner = THIS_MODULE,
.supported_type_groups = vfio_ap_mdev_type_groups,
.mdev_attr_groups = vfio_ap_mdev_attr_groups,
.create = vfio_ap_mdev_create,
.remove = vfio_ap_mdev_remove,
- .open = vfio_ap_mdev_open,
- .release = vfio_ap_mdev_release,
- .ioctl = vfio_ap_mdev_ioctl,
};
int vfio_ap_mdev_register(void)
diff --git a/drivers/vfio/mdev/mdev_core.c b/drivers/vfio/mdev/mdev_core.c
index 8764cf4a276d..6f35f2ced2c9 100644
--- a/drivers/vfio/mdev/mdev_core.c
+++ b/drivers/vfio/mdev/mdev_core.c
@@ -51,6 +51,18 @@ void mdev_set_class_id(struct mdev_device *mdev, u16 id)
}
EXPORT_SYMBOL(mdev_set_class_id);
+const void *mdev_get_dev_ops(struct mdev_device *mdev)
+{
+ return mdev->device_ops;
+}
+EXPORT_SYMBOL(mdev_get_dev_ops);
+
+void mdev_set_dev_ops(struct mdev_device *mdev, const void *ops)
+{
+ mdev->device_ops = ops;
+}
+EXPORT_SYMBOL(mdev_set_dev_ops);
+
struct device *mdev_dev(struct mdev_device *mdev)
{
return &mdev->dev;
diff --git a/drivers/vfio/mdev/mdev_private.h b/drivers/vfio/mdev/mdev_private.h
index c65f436c1869..b666805f0b1f 100644
--- a/drivers/vfio/mdev/mdev_private.h
+++ b/drivers/vfio/mdev/mdev_private.h
@@ -34,6 +34,7 @@ struct mdev_device {
struct device *iommu_device;
bool active;
u16 class_id;
+ const void *device_ops;
};
#define to_mdev_device(dev) container_of(dev, struct mdev_device, dev)
diff --git a/drivers/vfio/mdev/vfio_mdev.c b/drivers/vfio/mdev/vfio_mdev.c
index 891cf83a2d9a..95efa054442f 100644
--- a/drivers/vfio/mdev/vfio_mdev.c
+++ b/drivers/vfio/mdev/vfio_mdev.c
@@ -14,6 +14,7 @@
#include <linux/slab.h>
#include <linux/vfio.h>
#include <linux/mdev.h>
+#include <linux/vfio_mdev.h>
#include "mdev_private.h"
@@ -24,16 +25,16 @@
static int vfio_mdev_open(void *device_data)
{
struct mdev_device *mdev = device_data;
- struct mdev_parent *parent = mdev->parent;
+ const struct vfio_mdev_device_ops *ops = mdev_get_dev_ops(mdev);
int ret;
- if (unlikely(!parent->ops->open))
+ if (unlikely(!ops->open))
return -EINVAL;
if (!try_module_get(THIS_MODULE))
return -ENODEV;
- ret = parent->ops->open(mdev);
+ ret = ops->open(mdev);
if (ret)
module_put(THIS_MODULE);
@@ -43,10 +44,10 @@ static int vfio_mdev_open(void *device_data)
static void vfio_mdev_release(void *device_data)
{
struct mdev_device *mdev = device_data;
- struct mdev_parent *parent = mdev->parent;
+ const struct vfio_mdev_device_ops *ops = mdev_get_dev_ops(mdev);
- if (likely(parent->ops->release))
- parent->ops->release(mdev);
+ if (likely(ops->release))
+ ops->release(mdev);
module_put(THIS_MODULE);
}
@@ -55,47 +56,47 @@ static long vfio_mdev_unlocked_ioctl(void *device_data,
unsigned int cmd, unsigned long arg)
{
struct mdev_device *mdev = device_data;
- struct mdev_parent *parent = mdev->parent;
+ const struct vfio_mdev_device_ops *ops = mdev_get_dev_ops(mdev);
- if (unlikely(!parent->ops->ioctl))
+ if (unlikely(!ops->ioctl))
return -EINVAL;
- return parent->ops->ioctl(mdev, cmd, arg);
+ return ops->ioctl(mdev, cmd, arg);
}
static ssize_t vfio_mdev_read(void *device_data, char __user *buf,
size_t count, loff_t *ppos)
{
struct mdev_device *mdev = device_data;
- struct mdev_parent *parent = mdev->parent;
+ const struct vfio_mdev_device_ops *ops = mdev_get_dev_ops(mdev);
- if (unlikely(!parent->ops->read))
+ if (unlikely(!ops->read))
return -EINVAL;
- return parent->ops->read(mdev, buf, count, ppos);
+ return ops->read(mdev, buf, count, ppos);
}
static ssize_t vfio_mdev_write(void *device_data, const char __user *buf,
size_t count, loff_t *ppos)
{
struct mdev_device *mdev = device_data;
- struct mdev_parent *parent = mdev->parent;
+ const struct vfio_mdev_device_ops *ops = mdev_get_dev_ops(mdev);
- if (unlikely(!parent->ops->write))
+ if (unlikely(!ops->write))
return -EINVAL;
- return parent->ops->write(mdev, buf, count, ppos);
+ return ops->write(mdev, buf, count, ppos);
}
static int vfio_mdev_mmap(void *device_data, struct vm_area_struct *vma)
{
struct mdev_device *mdev = device_data;
- struct mdev_parent *parent = mdev->parent;
+ const struct vfio_mdev_device_ops *ops = mdev_get_dev_ops(mdev);
- if (unlikely(!parent->ops->mmap))
+ if (unlikely(!ops->mmap))
return -EINVAL;
- return parent->ops->mmap(mdev, vma);
+ return ops->mmap(mdev, vma);
}
static const struct vfio_device_ops vfio_mdev_dev_ops = {
diff --git a/include/linux/mdev.h b/include/linux/mdev.h
index 3974650c074f..3414307311f1 100644
--- a/include/linux/mdev.h
+++ b/include/linux/mdev.h
@@ -10,6 +10,11 @@
#ifndef MDEV_H
#define MDEV_H
+#include <linux/types.h>
+#include <linux/device.h>
+#include <linux/mdev.h>
+#include <uapi/linux/uuid.h>
+
struct mdev_device;
/*
@@ -48,30 +53,8 @@ struct device *mdev_get_iommu_device(struct device *dev);
* @mdev: mdev_device device structure which is being
* destroyed
* Returns integer: success (0) or error (< 0)
- * @open: Open mediated device.
- * @mdev: mediated device.
- * Returns integer: success (0) or error (< 0)
- * @release: release mediated device
- * @mdev: mediated device.
- * @read: Read emulation callback
- * @mdev: mediated device structure
- * @buf: read buffer
- * @count: number of bytes to read
- * @ppos: address.
- * Retuns number on bytes read on success or error.
- * @write: Write emulation callback
- * @mdev: mediated device structure
- * @buf: write buffer
- * @count: number of bytes to be written
- * @ppos: address.
- * Retuns number on bytes written on success or error.
- * @ioctl: IOCTL callback
- * @mdev: mediated device structure
- * @cmd: ioctl command
- * @arg: arguments to ioctl
- * @mmap: mmap callback
- * @mdev: mediated device structure
- * @vma: vma structure
+ * @device_ops: Device specific emulation callback.
+ *
* Parent device that support mediated device should be registered with mdev
* module with mdev_parent_ops structure.
**/
@@ -83,15 +66,6 @@ struct mdev_parent_ops {
int (*create)(struct kobject *kobj, struct mdev_device *mdev);
int (*remove)(struct mdev_device *mdev);
- int (*open)(struct mdev_device *mdev);
- void (*release)(struct mdev_device *mdev);
- ssize_t (*read)(struct mdev_device *mdev, char __user *buf,
- size_t count, loff_t *ppos);
- ssize_t (*write)(struct mdev_device *mdev, const char __user *buf,
- size_t count, loff_t *ppos);
- long (*ioctl)(struct mdev_device *mdev, unsigned int cmd,
- unsigned long arg);
- int (*mmap)(struct mdev_device *mdev, struct vm_area_struct *vma);
};
/* interface for exporting mdev supported type attributes */
@@ -133,6 +107,8 @@ struct mdev_driver {
void *mdev_get_drvdata(struct mdev_device *mdev);
void mdev_set_drvdata(struct mdev_device *mdev, void *data);
+const void *mdev_get_dev_ops(struct mdev_device *mdev);
+void mdev_set_dev_ops(struct mdev_device *mdev, const void *ops);
void mdev_set_class_id(struct mdev_device *mdev, u16 id);
const guid_t *mdev_uuid(struct mdev_device *mdev);
diff --git a/include/linux/vfio_mdev.h b/include/linux/vfio_mdev.h
new file mode 100644
index 000000000000..3907c5371c2b
--- /dev/null
+++ b/include/linux/vfio_mdev.h
@@ -0,0 +1,52 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * VFIO Mediated device definition
+ */
+
+#ifndef VFIO_MDEV_H
+#define VFIO_MDEV_H
+
+#include <linux/mdev.h>
+
+/**
+ * struct vfio_mdev_device_ops - Structure to be registered for each
+ * mdev device to register the device to vfio-mdev module.
+ *
+ * @open: Open mediated device.
+ * @mdev: mediated device.
+ * Returns integer: success (0) or error (< 0)
+ * @release: release mediated device
+ * @mdev: mediated device.
+ * @read: Read emulation callback
+ * @mdev: mediated device structure
+ * @buf: read buffer
+ * @count: number of bytes to read
+ * @ppos: address.
+ * Retuns number on bytes read on success or error.
+ * @write: Write emulation callback
+ * @mdev: mediated device structure
+ * @buf: write buffer
+ * @count: number of bytes to be written
+ * @ppos: address.
+ * Retuns number on bytes written on success or error.
+ * @ioctl: IOCTL callback
+ * @mdev: mediated device structure
+ * @cmd: ioctl command
+ * @arg: arguments to ioctl
+ * @mmap: mmap callback
+ * @mdev: mediated device structure
+ * @vma: vma structure
+ */
+struct vfio_mdev_device_ops {
+ int (*open)(struct mdev_device *mdev);
+ void (*release)(struct mdev_device *mdev);
+ ssize_t (*read)(struct mdev_device *mdev, char __user *buf,
+ size_t count, loff_t *ppos);
+ ssize_t (*write)(struct mdev_device *mdev, const char __user *buf,
+ size_t count, loff_t *ppos);
+ long (*ioctl)(struct mdev_device *mdev, unsigned int cmd,
+ unsigned long arg);
+ int (*mmap)(struct mdev_device *mdev, struct vm_area_struct *vma);
+};
+
+#endif
diff --git a/samples/vfio-mdev/mbochs.c b/samples/vfio-mdev/mbochs.c
index 8a8583c892b2..b4bf29c6136c 100644
--- a/samples/vfio-mdev/mbochs.c
+++ b/samples/vfio-mdev/mbochs.c
@@ -30,6 +30,7 @@
#include <linux/iommu.h>
#include <linux/sysfs.h>
#include <linux/mdev.h>
+#include <linux/vfio_mdev.h>
#include <linux/pci.h>
#include <linux/dma-buf.h>
#include <linux/highmem.h>
@@ -516,6 +517,8 @@ static int mbochs_reset(struct mdev_device *mdev)
return 0;
}
+static const struct vfio_mdev_device_ops vfio_mdev_ops;
+
static int mbochs_create(struct kobject *kobj, struct mdev_device *mdev)
{
const struct mbochs_type *type = mbochs_find_type(kobj);
@@ -562,6 +565,7 @@ static int mbochs_create(struct kobject *kobj, struct mdev_device *mdev)
mbochs_used_mbytes += type->mbytes;
mdev_set_class_id(mdev, MDEV_ID_VFIO);
+ mdev_set_dev_ops(mdev, &vfio_mdev_ops);
return 0;
err_mem:
@@ -1419,12 +1423,7 @@ static struct attribute_group *mdev_type_groups[] = {
NULL,
};
-static const struct mdev_parent_ops mdev_fops = {
- .owner = THIS_MODULE,
- .mdev_attr_groups = mdev_dev_groups,
- .supported_type_groups = mdev_type_groups,
- .create = mbochs_create,
- .remove = mbochs_remove,
+static const struct vfio_mdev_device_ops vfio_mdev_ops = {
.open = mbochs_open,
.release = mbochs_close,
.read = mbochs_read,
@@ -1433,6 +1432,14 @@ static const struct mdev_parent_ops mdev_fops = {
.mmap = mbochs_mmap,
};
+static const struct mdev_parent_ops mdev_fops = {
+ .owner = THIS_MODULE,
+ .mdev_attr_groups = mdev_dev_groups,
+ .supported_type_groups = mdev_type_groups,
+ .create = mbochs_create,
+ .remove = mbochs_remove,
+};
+
static const struct file_operations vd_fops = {
.owner = THIS_MODULE,
};
diff --git a/samples/vfio-mdev/mdpy.c b/samples/vfio-mdev/mdpy.c
index 88d7e76f3836..80c2df531326 100644
--- a/samples/vfio-mdev/mdpy.c
+++ b/samples/vfio-mdev/mdpy.c
@@ -26,6 +26,7 @@
#include <linux/iommu.h>
#include <linux/sysfs.h>
#include <linux/mdev.h>
+#include <linux/vfio_mdev.h>
#include <linux/pci.h>
#include <drm/drm_fourcc.h>
#include "mdpy-defs.h"
@@ -226,6 +227,8 @@ static int mdpy_reset(struct mdev_device *mdev)
return 0;
}
+static const struct vfio_mdev_device_ops vfio_mdev_ops;
+
static int mdpy_create(struct kobject *kobj, struct mdev_device *mdev)
{
const struct mdpy_type *type = mdpy_find_type(kobj);
@@ -270,6 +273,7 @@ static int mdpy_create(struct kobject *kobj, struct mdev_device *mdev)
mdpy_count++;
mdev_set_class_id(mdev, MDEV_ID_VFIO);
+ mdev_set_dev_ops(mdev, &vfio_mdev_ops);
return 0;
}
@@ -726,12 +730,7 @@ static struct attribute_group *mdev_type_groups[] = {
NULL,
};
-static const struct mdev_parent_ops mdev_fops = {
- .owner = THIS_MODULE,
- .mdev_attr_groups = mdev_dev_groups,
- .supported_type_groups = mdev_type_groups,
- .create = mdpy_create,
- .remove = mdpy_remove,
+static const struct vfio_mdev_device_ops vfio_mdev_ops = {
.open = mdpy_open,
.release = mdpy_close,
.read = mdpy_read,
@@ -740,6 +739,14 @@ static const struct mdev_parent_ops mdev_fops = {
.mmap = mdpy_mmap,
};
+static const struct mdev_parent_ops mdev_fops = {
+ .owner = THIS_MODULE,
+ .mdev_attr_groups = mdev_dev_groups,
+ .supported_type_groups = mdev_type_groups,
+ .create = mdpy_create,
+ .remove = mdpy_remove,
+};
+
static const struct file_operations vd_fops = {
.owner = THIS_MODULE,
};
diff --git a/samples/vfio-mdev/mtty.c b/samples/vfio-mdev/mtty.c
index 4e0735143b69..2db860ccb02c 100644
--- a/samples/vfio-mdev/mtty.c
+++ b/samples/vfio-mdev/mtty.c
@@ -27,6 +27,7 @@
#include <linux/ctype.h>
#include <linux/file.h>
#include <linux/mdev.h>
+#include <linux/vfio_mdev.h>
#include <linux/pci.h>
#include <linux/serial.h>
#include <uapi/linux/serial_reg.h>
@@ -723,6 +724,8 @@ static ssize_t mdev_access(struct mdev_device *mdev, u8 *buf, size_t count,
return ret;
}
+static const struct vfio_mdev_device_ops vfio_dev_ops;
+
static int mtty_create(struct kobject *kobj, struct mdev_device *mdev)
{
struct mdev_state *mdev_state;
@@ -771,6 +774,7 @@ static int mtty_create(struct kobject *kobj, struct mdev_device *mdev)
mutex_unlock(&mdev_list_lock);
mdev_set_class_id(mdev, MDEV_ID_VFIO);
+ mdev_set_dev_ops(mdev, &vfio_dev_ops);
return 0;
}
@@ -1411,6 +1415,14 @@ static struct attribute_group *mdev_type_groups[] = {
NULL,
};
+static const struct vfio_mdev_device_ops vfio_dev_ops = {
+ .open = mtty_open,
+ .release = mtty_close,
+ .read = mtty_read,
+ .write = mtty_write,
+ .ioctl = mtty_ioctl,
+};
+
static const struct mdev_parent_ops mdev_fops = {
.owner = THIS_MODULE,
.dev_attr_groups = mtty_dev_groups,
@@ -1418,11 +1430,6 @@ static const struct mdev_parent_ops mdev_fops = {
.supported_type_groups = mdev_type_groups,
.create = mtty_create,
.remove = mtty_remove,
- .open = mtty_open,
- .release = mtty_close,
- .read = mtty_read,
- .write = mtty_write,
- .ioctl = mtty_ioctl,
};
static void mtty_device_release(struct device *dev)
--
2.19.1
^ permalink raw reply related
* [PATCH V2 6/8] mdev: introduce virtio device and its device ops
From: Jason Wang @ 2019-09-24 13:53 UTC (permalink / raw)
To: kvm, linux-s390, linux-kernel, dri-devel, intel-gfx,
intel-gvt-dev, kwankhede, alex.williamson, mst, tiwei.bie
Cc: virtualization, netdev, cohuck, maxime.coquelin, cunming.liang,
zhihong.wang, rob.miller, xiao.w.wang, haotian.wang, zhenyuw,
zhi.a.wang, jani.nikula, joonas.lahtinen, rodrigo.vivi, airlied,
daniel, farman, pasic, sebott, oberpar, heiko.carstens, gor,
borntraeger, akrowiak, freude, lingshan.zhu, idos, eperezma, lulu,
parav, christophe.de.dinechin, kevin.tian, Jason Wang
In-Reply-To: <20190924135332.14160-1-jasowang@redhat.com>
This patch implements basic support for mdev driver that supports
virtio transport for kernel virtio driver.
Signed-off-by: Jason Wang <jasowang@redhat.com>
---
include/linux/mdev.h | 2 +
include/linux/virtio_mdev.h | 145 ++++++++++++++++++++++++++++++++++++
2 files changed, 147 insertions(+)
create mode 100644 include/linux/virtio_mdev.h
diff --git a/include/linux/mdev.h b/include/linux/mdev.h
index 3414307311f1..73ac27b3b868 100644
--- a/include/linux/mdev.h
+++ b/include/linux/mdev.h
@@ -126,6 +126,8 @@ struct mdev_device *mdev_from_dev(struct device *dev);
enum {
MDEV_ID_VFIO = 1,
+ MDEV_ID_VIRTIO = 2,
+ MDEV_ID_VHOST = 3,
/* New entries must be added here */
};
diff --git a/include/linux/virtio_mdev.h b/include/linux/virtio_mdev.h
new file mode 100644
index 000000000000..d1a40a739266
--- /dev/null
+++ b/include/linux/virtio_mdev.h
@@ -0,0 +1,145 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Virtio mediated device driver
+ *
+ * Copyright 2019, Red Hat Corp.
+ * Author: Jason Wang <jasowang@redhat.com>
+ */
+#ifndef _LINUX_VIRTIO_MDEV_H
+#define _LINUX_VIRTIO_MDEV_H
+
+#include <linux/interrupt.h>
+#include <linux/mdev.h>
+#include <uapi/linux/vhost.h>
+
+#define VIRTIO_MDEV_DEVICE_API_STRING "virtio-mdev"
+#define VIRTIO_MDEV_VERSION 0x1
+
+struct virtio_mdev_callback {
+ irqreturn_t (*callback)(void *data);
+ void *private;
+};
+
+/**
+ * struct vfio_mdev_device_ops - Structure to be registered for each
+ * mdev device to register the device to virtio-mdev module.
+ *
+ * @set_vq_address: Set the address of virtqueue
+ * @mdev: mediated device
+ * @idx: virtqueue index
+ * @desc_area: address of desc area
+ * @driver_area: address of driver area
+ * @device_area: address of device area
+ * Returns integer: success (0) or error (< 0)
+ * @set_vq_num: Set the size of virtqueue
+ * @mdev: mediated device
+ * @idx: virtqueue index
+ * @num: the size of virtqueue
+ * @kick_vq: Kick the virtqueue
+ * @mdev: mediated device
+ * @idx: virtqueue index
+ * @set_vq_cb: Set the interrut calback function for
+ * a virtqueue
+ * @mdev: mediated device
+ * @idx: virtqueue index
+ * @cb: virtio-mdev interrupt callback structure
+ * @set_vq_ready: Set ready status for a virtqueue
+ * @mdev: mediated device
+ * @idx: virtqueue index
+ * @ready: ready (true) not ready(false)
+ * @get_vq_ready: Get ready status for a virtqueue
+ * @mdev: mediated device
+ * @idx: virtqueue index
+ * Returns boolean: ready (true) or not (false)
+ * @set_vq_state: Set the state for a virtqueue
+ * @mdev: mediated device
+ * @idx: virtqueue index
+ * @state: virtqueue state (last_avail_idx)
+ * Returns integer: success (0) or error (< 0)
+ * @get_vq_state: Get the state for a virtqueue
+ * @mdev: mediated device
+ * @idx: virtqueue index
+ * Returns virtqueue state (last_avail_idx)
+ * @get_vq_align: Get the virtqueue align requirement
+ * for the device
+ * @mdev: mediated device
+ * Returns virtqueue algin requirement
+ * @get_features: Get virtio features supported by the device
+ * @mdev: mediated device
+ * Returns the features support by the
+ * device
+ * @get_features: Set virtio features supported by the driver
+ * @mdev: mediated device
+ * @features: feature support by the driver
+ * Returns integer: success (0) or error (< 0)
+ * @set_config_cb: Set the config interrupt callback
+ * @mdev: mediated device
+ * @cb: virtio-mdev interrupt callback structure
+ * @get_device_id: Get virtio device id
+ * @mdev: mediated device
+ * Returns u32: virtio device id
+ * @get_vendor_id: Get virtio vendor id
+ * @mdev: mediated device
+ * Returns u32: virtio vendor id
+ * @get_status: Get the device status
+ * @mdev: mediated device
+ * Returns u8: virtio device status
+ * @set_status: Set the device status
+ * @mdev: mediated device
+ * @status: virtio device status
+ * @get_config: Read from device specific confiugration space
+ * @mdev: mediated device
+ * @offset: offset from the beginning of
+ * configuration space
+ * @buf: buffer used to read to
+ * @len: the length to read from
+ * configration space
+ * @set_config: Write to device specific confiugration space
+ * @mdev: mediated device
+ * @offset: offset from the beginning of
+ * configuration space
+ * @buf: buffer used to write from
+ * @len: the length to write to
+ * configration space
+ * @get_version: Get the version of virtio mdev device
+ * @mdev: mediated device
+ * Returns integer: version of the device
+ * @get_generation: Get device generaton
+ * @mdev: mediated device
+ * Returns u32: device generation
+ */
+struct virtio_mdev_device_ops {
+ /* Virtqueue ops */
+ int (*set_vq_address)(struct mdev_device *mdev,
+ u16 idx, u64 desc_area, u64 driver_area,
+ u64 device_area);
+ void (*set_vq_num)(struct mdev_device *mdev, u16 idx, u32 num);
+ void (*kick_vq)(struct mdev_device *mdev, u16 idx);
+ void (*set_vq_cb)(struct mdev_device *mdev, u16 idx,
+ struct virtio_mdev_callback *cb);
+ void (*set_vq_ready)(struct mdev_device *mdev, u16 idx, bool ready);
+ bool (*get_vq_ready)(struct mdev_device *mdev, u16 idx);
+ int (*set_vq_state)(struct mdev_device *mdev, u16 idx, u64 state);
+ u64 (*get_vq_state)(struct mdev_device *mdev, u16 idx);
+
+ /* Device ops */
+ u16 (*get_vq_align)(struct mdev_device *mdev);
+ u64 (*get_features)(struct mdev_device *mdev);
+ int (*set_features)(struct mdev_device *mdev, u64 features);
+ void (*set_config_cb)(struct mdev_device *mdev,
+ struct virtio_mdev_callback *cb);
+ u16 (*get_queue_max)(struct mdev_device *mdev);
+ u32 (*get_device_id)(struct mdev_device *mdev);
+ u32 (*get_vendor_id)(struct mdev_device *mdev);
+ u8 (*get_status)(struct mdev_device *mdev);
+ void (*set_status)(struct mdev_device *mdev, u8 status);
+ void (*get_config)(struct mdev_device *mdev, unsigned int offset,
+ void *buf, unsigned int len);
+ void (*set_config)(struct mdev_device *mdev, unsigned int offset,
+ const void *buf, unsigned int len);
+ int (*get_version)(struct mdev_device *mdev);
+ u32 (*get_generation)(struct mdev_device *mdev);
+};
+
+#endif
+
--
2.19.1
^ permalink raw reply related
* Re: [PATCH v3] bonding: force enable lacp port after link state recovery for 802.3ad
From: David Miller @ 2019-09-24 13:56 UTC (permalink / raw)
To: zhangsha.zhang
Cc: jay.vosburgh, vfalico, andy, netdev, linux-kernel, yuehaibing,
hunongda, alex.chen
In-Reply-To: <20190918130620.8556-1-zhangsha.zhang@huawei.com>
From: <zhangsha.zhang@huawei.com>
Date: Wed, 18 Sep 2019 21:06:20 +0800
> From: Sha Zhang <zhangsha.zhang@huawei.com>
>
> After the commit 334031219a84 ("bonding/802.3ad: fix slave link
> initialization transition states") merged,
> the slave's link status will be changed to BOND_LINK_FAIL
> from BOND_LINK_DOWN in the following scenario:
> - Driver reports loss of carrier and
> bonding driver receives NETDEV_DOWN notifier
> - slave's duplex and speed is zerod and
> its port->is_enabled is cleard to 'false';
> - Driver reports link recovery and
> bonding driver receives NETDEV_UP notifier;
> - If speed/duplex getting failed here, the link status
> will be changed to BOND_LINK_FAIL;
> - The MII monotor later recover the slave's speed/duplex
> and set link status to BOND_LINK_UP, but remains
> the 'port->is_enabled' to 'false'.
>
> In this scenario, the lacp port will not be enabled even its speed
> and duplex are valid. The bond will not send LACPDU's, and its
> state is 'AD_STATE_DEFAULTED' forever. The simplest fix I think
> is to call bond_3ad_handle_link_change() in bond_miimon_commit,
> this function can enable lacp after port slave speed check.
> As enabled, the lacp port can run its state machine normally
> after link recovery.
>
> Signed-off-by: Sha Zhang <zhangsha.zhang@huawei.com>
Please work out with Jay and Aleksei how to properly fix this.
^ permalink raw reply
* [PATCH V2 7/8] virtio: introduce a mdev based transport
From: Jason Wang @ 2019-09-24 13:53 UTC (permalink / raw)
To: kvm, linux-s390, linux-kernel, dri-devel, intel-gfx,
intel-gvt-dev, kwankhede, alex.williamson, mst, tiwei.bie
Cc: virtualization, netdev, cohuck, maxime.coquelin, cunming.liang,
zhihong.wang, rob.miller, xiao.w.wang, haotian.wang, zhenyuw,
zhi.a.wang, jani.nikula, joonas.lahtinen, rodrigo.vivi, airlied,
daniel, farman, pasic, sebott, oberpar, heiko.carstens, gor,
borntraeger, akrowiak, freude, lingshan.zhu, idos, eperezma, lulu,
parav, christophe.de.dinechin, kevin.tian, Jason Wang
In-Reply-To: <20190924135332.14160-1-jasowang@redhat.com>
This patch 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 it is a software transport between
mdev driver and mdev device. The transport was implemented through
device specific opswhich is a part of mdev_parent_ops now.
Signed-off-by: Jason Wang <jasowang@redhat.com>
---
drivers/virtio/Kconfig | 7 +
drivers/virtio/Makefile | 1 +
drivers/virtio/virtio_mdev.c | 417 +++++++++++++++++++++++++++++++++++
3 files changed, 425 insertions(+)
create mode 100644 drivers/virtio/virtio_mdev.c
diff --git a/drivers/virtio/Kconfig b/drivers/virtio/Kconfig
index 078615cf2afc..8d18722ab572 100644
--- a/drivers/virtio/Kconfig
+++ b/drivers/virtio/Kconfig
@@ -43,6 +43,13 @@ config VIRTIO_PCI_LEGACY
If unsure, say Y.
+config VIRTIO_MDEV_DEVICE
+ tristate "VIRTIO driver for Mediated devices"
+ depends on VFIO_MDEV && VIRTIO
+ default n
+ help
+ VIRTIO based driver for Mediated devices.
+
config VIRTIO_PMEM
tristate "Support for virtio pmem driver"
depends on VIRTIO
diff --git a/drivers/virtio/Makefile b/drivers/virtio/Makefile
index 3a2b5c5dcf46..ebc7fa15ae82 100644
--- a/drivers/virtio/Makefile
+++ b/drivers/virtio/Makefile
@@ -6,3 +6,4 @@ virtio_pci-y := virtio_pci_modern.o virtio_pci_common.o
virtio_pci-$(CONFIG_VIRTIO_PCI_LEGACY) += virtio_pci_legacy.o
obj-$(CONFIG_VIRTIO_BALLOON) += virtio_balloon.o
obj-$(CONFIG_VIRTIO_INPUT) += virtio_input.o
+obj-$(CONFIG_VIRTIO_MDEV_DEVICE) += virtio_mdev.o
diff --git a/drivers/virtio/virtio_mdev.c b/drivers/virtio/virtio_mdev.c
new file mode 100644
index 000000000000..c2f3cb2738bd
--- /dev/null
+++ b/drivers/virtio/virtio_mdev.c
@@ -0,0 +1,417 @@
+// 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>
+ *
+ */
+
+#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_mdev.h>
+#include <linux/virtio.h>
+#include <linux/virtio_config.h>
+#include <linux/virtio_ring.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;
+ /* The lock to protect virtqueue list */
+ spinlock_t lock;
+ struct list_head virtqueues;
+};
+
+struct virtio_mdev_vq_info {
+ /* the actual virtqueue */
+ struct virtqueue *vq;
+
+ /* the list node for the virtqueues list */
+ struct list_head node;
+};
+
+static struct mdev_device *vm_get_mdev(struct virtio_device *vdev)
+{
+ struct virtio_mdev_device *vm_dev = to_virtio_mdev_device(vdev);
+ struct mdev_device *mdev = vm_dev->mdev;
+
+ return mdev;
+}
+
+static void virtio_mdev_get(struct virtio_device *vdev, unsigned offset,
+ void *buf, unsigned len)
+{
+ struct mdev_device *mdev = vm_get_mdev(vdev);
+ const struct virtio_mdev_device_ops *ops = mdev_get_dev_ops(mdev);
+
+ ops->get_config(mdev, offset, buf, len);
+}
+
+static void virtio_mdev_set(struct virtio_device *vdev, unsigned offset,
+ const void *buf, unsigned len)
+{
+ struct mdev_device *mdev = vm_get_mdev(vdev);
+ const struct virtio_mdev_device_ops *ops = mdev_get_dev_ops(mdev);
+
+ ops->set_config(mdev, offset, buf, len);
+}
+
+static u32 virtio_mdev_generation(struct virtio_device *vdev)
+{
+ struct mdev_device *mdev = vm_get_mdev(vdev);
+ const struct virtio_mdev_device_ops *ops = mdev_get_dev_ops(mdev);
+
+ return ops->get_generation(mdev);
+}
+
+static u8 virtio_mdev_get_status(struct virtio_device *vdev)
+{
+ struct mdev_device *mdev = vm_get_mdev(vdev);
+ const struct virtio_mdev_device_ops *ops = mdev_get_dev_ops(mdev);
+
+ return ops->get_status(mdev);
+}
+
+static void virtio_mdev_set_status(struct virtio_device *vdev, u8 status)
+{
+ struct mdev_device *mdev = vm_get_mdev(vdev);
+ const struct virtio_mdev_device_ops *ops = mdev_get_dev_ops(mdev);
+
+ return ops->set_status(mdev, status);
+}
+
+static void virtio_mdev_reset(struct virtio_device *vdev)
+{
+ struct mdev_device *mdev = vm_get_mdev(vdev);
+ const struct virtio_mdev_device_ops *ops = mdev_get_dev_ops(mdev);
+
+ return ops->set_status(mdev, 0);
+}
+
+static bool virtio_mdev_notify(struct virtqueue *vq)
+{
+ struct mdev_device *mdev = vm_get_mdev(vq->vdev);
+ const struct virtio_mdev_device_ops *ops = mdev_get_dev_ops(mdev);
+
+ ops->kick_vq(mdev, 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_get_mdev(vdev);
+ const struct virtio_mdev_device_ops *ops = mdev_get_dev_ops(mdev);
+ struct virtio_mdev_vq_info *info;
+ struct virtio_mdev_callback cb;
+ struct virtqueue *vq;
+ u64 desc_addr, driver_addr, device_addr;
+ unsigned long flags;
+ u32 align, num;
+ int err;
+
+ if (!name)
+ return NULL;
+
+ /* Queue shouldn't already be set up. */
+ if (ops->get_vq_ready(mdev, index))
+ return ERR_PTR(-ENOENT);
+
+ /* Allocate and fill out our active queue description */
+ info = kmalloc(sizeof(*info), GFP_KERNEL);
+ if (!info)
+ return ERR_PTR(-ENOMEM);
+
+ num = ops->get_queue_max(mdev);
+ if (num == 0) {
+ err = -ENOENT;
+ goto error_new_virtqueue;
+ }
+
+ /* Create the vring */
+ align = ops->get_vq_align(mdev);
+ 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;
+ ops->set_vq_cb(mdev, index, &cb);
+ ops->set_vq_num(mdev, index, virtqueue_get_vring_size(vq));
+
+ desc_addr = virtqueue_get_desc_addr(vq);
+ driver_addr = virtqueue_get_avail_addr(vq);
+ device_addr = virtqueue_get_used_addr(vq);
+
+ if (ops->set_vq_address(mdev, index,
+ desc_addr, driver_addr,
+ device_addr)) {
+ err = -EINVAL;
+ goto err_vq;
+ }
+
+ ops->set_vq_ready(mdev, index, 1);
+
+ vq->priv = info;
+ info->vq = vq;
+
+ spin_lock_irqsave(&vm_dev->lock, flags);
+ list_add(&info->node, &vm_dev->virtqueues);
+ spin_unlock_irqrestore(&vm_dev->lock, flags);
+
+ return vq;
+
+err_vq:
+ vring_del_virtqueue(vq);
+error_new_virtqueue:
+ ops->set_vq_ready(mdev, index, 0);
+ WARN_ON(ops->get_vq_ready(mdev, index));
+ kfree(info);
+ 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 mdev_device *mdev = vm_dev->mdev;
+ const struct virtio_mdev_device_ops *ops = mdev_get_dev_ops(mdev);
+ struct virtio_mdev_vq_info *info = vq->priv;
+ unsigned int index = vq->index;
+ unsigned long flags;
+
+ spin_lock_irqsave(&vm_dev->lock, flags);
+ list_del(&info->node);
+ spin_unlock_irqrestore(&vm_dev->lock, flags);
+
+ /* Select and deactivate the queue */
+ ops->set_vq_ready(mdev, index, 0);
+ WARN_ON(ops->get_vq_ready(mdev, index));
+
+ 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);
+}
+
+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_get_mdev(vdev);
+ const struct virtio_mdev_device_ops *ops = mdev_get_dev_ops(mdev);
+ 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;
+ ops->set_config_cb(mdev, &cb);
+
+ 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 mdev_device *mdev = vm_get_mdev(vdev);
+ const struct virtio_mdev_device_ops *ops = mdev_get_dev_ops(mdev);
+
+ return ops->get_features(mdev);
+}
+
+static int virtio_mdev_finalize_features(struct virtio_device *vdev)
+{
+ struct mdev_device *mdev = vm_get_mdev(vdev);
+ const struct virtio_mdev_device_ops *ops = mdev_get_dev_ops(mdev);
+
+ /* Give virtio_ring a chance to accept features. */
+ vring_transport_features(vdev);
+
+ return ops->set_features(mdev, vdev->features);
+}
+
+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(mdev));
+}
+
+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 = mdev_from_dev(dev);
+ const struct virtio_mdev_device_ops *ops = mdev_get_dev_ops(mdev);
+ struct virtio_mdev_device *vm_dev;
+ int rc;
+
+ 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;
+ INIT_LIST_HEAD(&vm_dev->virtqueues);
+ spin_lock_init(&vm_dev->lock);
+
+ vm_dev->version = ops->get_version(mdev);
+ if (vm_dev->version != 1) {
+ dev_err(dev, "Version %ld not supported!\n",
+ vm_dev->version);
+ return -ENXIO;
+ }
+
+ vm_dev->vdev.id.device = ops->get_device_id(mdev);
+ if (vm_dev->vdev.id.device == 0)
+ return -ENODEV;
+
+ vm_dev->vdev.id.vendor = ops->get_vendor_id(mdev);
+ rc = register_virtio_device(&vm_dev->vdev);
+ if (rc)
+ put_device(dev);
+ else
+ 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_class_id id_table[] = {
+ { MDEV_ID_VIRTIO },
+ { 0 },
+};
+
+MODULE_DEVICE_TABLE(mdev, id_table);
+
+static struct mdev_driver virtio_mdev_driver = {
+ .name = "virtio_mdev",
+ .probe = virtio_mdev_probe,
+ .remove = virtio_mdev_remove,
+ .id_table = id_table,
+};
+
+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);
--
2.19.1
^ permalink raw reply related
* [PATCH V2 8/8] docs: sample driver to demonstrate how to implement virtio-mdev framework
From: Jason Wang @ 2019-09-24 13:53 UTC (permalink / raw)
To: kvm, linux-s390, linux-kernel, dri-devel, intel-gfx,
intel-gvt-dev, kwankhede, alex.williamson, mst, tiwei.bie
Cc: virtualization, netdev, cohuck, maxime.coquelin, cunming.liang,
zhihong.wang, rob.miller, xiao.w.wang, haotian.wang, zhenyuw,
zhi.a.wang, jani.nikula, joonas.lahtinen, rodrigo.vivi, airlied,
daniel, farman, pasic, sebott, oberpar, heiko.carstens, gor,
borntraeger, akrowiak, freude, lingshan.zhu, idos, eperezma, lulu,
parav, christophe.de.dinechin, kevin.tian, Jason Wang
In-Reply-To: <20190924135332.14160-1-jasowang@redhat.com>
This sample driver creates mdev device that simulate virtio net device
over virtio mdev transport. The device is implemented through vringh
and workqueue. A device specific dma ops is to make sure HVA is used
directly as the IOVA. This should be sufficient for kernel virtio
driver to work.
Only 'virtio' type is supported right now. I plan to add 'vhost' type
on top which requires some virtual IOMMU implemented in this sample
driver.
Signed-off-by: Jason Wang <jasowang@redhat.com>
---
MAINTAINERS | 1 +
samples/Kconfig | 7 +
samples/vfio-mdev/Makefile | 1 +
samples/vfio-mdev/mvnet.c | 692 +++++++++++++++++++++++++++++++++++++
4 files changed, 701 insertions(+)
create mode 100644 samples/vfio-mdev/mvnet.c
diff --git a/MAINTAINERS b/MAINTAINERS
index 89832b316500..347dc64cdc23 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -17202,6 +17202,7 @@ F: include/linux/virtio*.h
F: include/uapi/linux/virtio_*.h
F: drivers/crypto/virtio/
F: mm/balloon_compaction.c
+F: samples/vfio-mdev/mvnet.c
VIRTIO BLOCK AND SCSI DRIVERS
M: "Michael S. Tsirkin" <mst@redhat.com>
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..53a39f0f3460
--- /dev/null
+++ b/samples/vfio-mdev/mvnet.c
@@ -0,0 +1,692 @@
+// 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 that creates mdev device that simulates ethernet loopback
+ * device.
+ *
+ * Usage:
+ *
+ * # modprobe virtio_mdev
+ * # modprobe mvnet
+ * # cd /sys/devices/virtual/mvnet/mvnet/mdev_supported_types/mvnet-virtio
+ * # echo "83b8f4f2-509f-382f-3c1e-e6bfe0fa1001" > ./create
+ * # cd devices/83b8f4f2-509f-382f-3c1e-e6bfe0fa1001
+ * # ls -d virtio0
+ * virtio0
+ */
+
+#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 <linux/vringh.h>
+#include <linux/virtio_mdev.h>
+#include <uapi/linux/virtio_config.h>
+#include <uapi/linux/virtio_net.h>
+
+#define VERSION_STRING "0.1"
+#define DRIVER_AUTHOR "Red Hat 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;
+ u64 desc_addr;
+ u64 device_addr;
+ u64 driver_addr;
+ u32 num;
+ void *private;
+ irqreturn_t (*cb)(void *data);
+};
+
+#define MVNET_QUEUE_ALIGN PAGE_SIZE
+#define MVNET_QUEUE_MAX 256
+#define MVNET_DEVICE_ID 0x1
+#define MVNET_VENDOR_ID 0
+
+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;
+ void *buffer;
+ u32 status;
+ u32 generation;
+ u64 features;
+ 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 int idx)
+{
+ struct mvnet_virtqueue *vq = &mvnet->vqs[idx];
+ int ret;
+
+ 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 void mvnet_vq_reset(struct mvnet_virtqueue *vq)
+{
+ vq->ready = 0;
+ vq->desc_addr = 0;
+ vq->driver_addr = 0;
+ vq->device_addr = 0;
+ vq->cb = NULL;
+ vq->private = NULL;
+ 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->features = 0;
+ mvnet->status = 0;
+ ++mvnet->generation;
+}
+
+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;
+ 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_ATOMIC);
+ if (err <= 0)
+ break;
+
+ err = vringh_getdesc_kern(&rxq->vring, NULL, &rxq->iov,
+ &rxq->head, GFP_ATOMIC);
+ 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();
+
+ 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 HVA */
+ return (dma_addr_t)(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)
+{
+}
+
+static void *mvnet_alloc_coherent(struct device *dev, size_t size,
+ dma_addr_t *dma_addr, gfp_t flag,
+ unsigned long attrs)
+{
+ void *addr = kmalloc(size, flag);
+
+ if (addr == NULL)
+ *dma_addr = DMA_MAPPING_ERROR;
+ else
+ *dma_addr = (dma_addr_t) addr;
+
+ return addr;
+}
+
+static void mvnet_free_coherent(struct device *dev, size_t size,
+ void *vaddr, dma_addr_t dma_addr,
+ unsigned long attrs)
+{
+ kfree((void *)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 const struct virtio_mdev_device_ops virtio_mdev_ops;
+
+static int mvnet_create(struct kobject *kobj, struct mdev_device *mdev)
+{
+ struct mvnet_state *mvnet;
+ struct virtio_net_config *config;
+ struct device *dev = mdev_dev(mdev);
+
+ 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);
+
+ dev->coherent_dma_mask = DMA_BIT_MASK(64);
+ set_dma_ops(dev, &mvnet_dma_ops);
+
+ mdev_set_class_id(mdev, MDEV_ID_VIRTIO);
+ mdev_set_dev_ops(mdev, &virtio_mdev_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
+sample_mvnet_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_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 = "virtio",
+ .attrs = mdev_types_attrs,
+};
+
+/* TBD: "vhost" type */
+
+static struct attribute_group *mdev_type_groups[] = {
+ &mdev_type_group,
+ NULL,
+};
+
+static int mvnet_set_vq_address(struct mdev_device *mdev, u16 idx,
+ u64 desc_area, u64 driver_area, u64 device_area)
+{
+ struct mvnet_state *mvnet = mdev_get_drvdata(mdev);
+ struct mvnet_virtqueue *vq = &mvnet->vqs[idx];
+
+ vq->desc_addr = desc_area;
+ vq->driver_addr = driver_area;
+ vq->device_addr = device_area;
+
+ return 0;
+}
+
+static void mvnet_set_vq_num(struct mdev_device *mdev, u16 idx, u32 num)
+{
+ struct mvnet_state *mvnet = mdev_get_drvdata(mdev);
+ struct mvnet_virtqueue *vq = &mvnet->vqs[idx];
+
+ vq->num = num;
+}
+
+static void mvnet_kick_vq(struct mdev_device *mdev, u16 idx)
+{
+ struct mvnet_state *mvnet = mdev_get_drvdata(mdev);
+ struct mvnet_virtqueue *vq = &mvnet->vqs[idx];
+
+ if (vq->ready)
+ schedule_work(&mvnet->work);
+}
+
+static void mvnet_set_vq_cb(struct mdev_device *mdev, u16 idx,
+ struct virtio_mdev_callback *cb)
+{
+ struct mvnet_state *mvnet = mdev_get_drvdata(mdev);
+ struct mvnet_virtqueue *vq = &mvnet->vqs[idx];
+
+ vq->cb = cb->callback;
+ vq->private = cb->private;
+}
+
+static void mvnet_set_vq_ready(struct mdev_device *mdev, u16 idx, bool ready)
+{
+ struct mvnet_state *mvnet = mdev_get_drvdata(mdev);
+ struct mvnet_virtqueue *vq = &mvnet->vqs[idx];
+
+ spin_lock(&mvnet->lock);
+ vq->ready = ready;
+ if (vq->ready)
+ mvnet_queue_ready(mvnet, idx);
+ spin_unlock(&mvnet->lock);
+}
+
+static bool mvnet_get_vq_ready(struct mdev_device *mdev, u16 idx)
+{
+ struct mvnet_state *mvnet = mdev_get_drvdata(mdev);
+ struct mvnet_virtqueue *vq = &mvnet->vqs[idx];
+
+ return vq->ready;
+}
+
+static int mvnet_set_vq_state(struct mdev_device *mdev, u16 idx, u64 state)
+{
+ struct mvnet_state *mvnet = mdev_get_drvdata(mdev);
+ struct mvnet_virtqueue *vq = &mvnet->vqs[idx];
+ struct vringh *vrh = &vq->vring;
+
+ spin_lock(&mvnet->lock);
+ vrh->last_avail_idx = state;
+ spin_unlock(&mvnet->lock);
+
+ return 0;
+}
+
+static u64 mvnet_get_vq_state(struct mdev_device *mdev, u16 idx)
+{
+ struct mvnet_state *mvnet = mdev_get_drvdata(mdev);
+ struct mvnet_virtqueue *vq = &mvnet->vqs[idx];
+ struct vringh *vrh = &vq->vring;
+
+ return vrh->last_avail_idx;
+}
+
+static u16 mvnet_get_vq_align(struct mdev_device *mdev)
+{
+ return MVNET_QUEUE_ALIGN;
+}
+
+static u64 mvnet_get_features(struct mdev_device *mdev)
+{
+ return mvnet_features;
+}
+
+static int mvnet_set_features(struct mdev_device *mdev, u64 features)
+{
+ struct mvnet_state *mvnet = mdev_get_drvdata(mdev);
+
+ /* DMA mapping must be done by driver */
+ if (!(features & (1ULL << VIRTIO_F_IOMMU_PLATFORM)))
+ return -EINVAL;
+
+ mvnet->features = features & mvnet_features;
+
+ return 0;
+}
+
+static void mvnet_set_config_cb(struct mdev_device *mdev,
+ struct virtio_mdev_callback *cb)
+{
+ /* We don't support config interrupt */
+}
+
+static u16 mvnet_get_queue_max(struct mdev_device *mdev)
+{
+ return MVNET_QUEUE_MAX;
+}
+
+static u32 mvnet_get_device_id(struct mdev_device *mdev)
+{
+ return MVNET_DEVICE_ID;
+}
+
+static u32 mvnet_get_vendor_id(struct mdev_device *mdev)
+{
+ return MVNET_VENDOR_ID;
+}
+
+static u8 mvnet_get_status(struct mdev_device *mdev)
+{
+ struct mvnet_state *mvnet = mdev_get_drvdata(mdev);
+
+ return mvnet->status;
+}
+
+static void mvnet_set_status(struct mdev_device *mdev, u8 status)
+{
+ struct mvnet_state *mvnet = mdev_get_drvdata(mdev);
+
+ mvnet->status = status;
+
+ if (status == 0) {
+ spin_lock(&mvnet->lock);
+ mvnet_reset(mvnet);
+ spin_unlock(&mvnet->lock);
+ }
+}
+
+static void mvnet_get_config(struct mdev_device *mdev, unsigned int offset,
+ void *buf, unsigned int len)
+{
+ struct mvnet_state *mvnet = mdev_get_drvdata(mdev);
+
+ if (offset + len < sizeof(struct virtio_net_config))
+ memcpy(buf, &mvnet->config + offset, len);
+}
+
+static void mvnet_set_config(struct mdev_device *mdev, unsigned int offset,
+ const void *buf, unsigned int len)
+{
+ /* No writable config supportted by mvnet */
+}
+
+static int mvnet_get_version(struct mdev_device *mdev)
+{
+ return 0x1;
+}
+
+static u32 mvnet_get_generation(struct mdev_device *mdev)
+{
+ struct mvnet_state *mvnet = mdev_get_drvdata(mdev);
+
+ return mvnet->generation;
+}
+
+static const struct virtio_mdev_device_ops virtio_mdev_ops = {
+ .set_vq_address = mvnet_set_vq_address,
+ .set_vq_num = mvnet_set_vq_num,
+ .kick_vq = mvnet_kick_vq,
+ .set_vq_cb = mvnet_set_vq_cb,
+ .set_vq_ready = mvnet_set_vq_ready,
+ .get_vq_ready = mvnet_get_vq_ready,
+ .set_vq_state = mvnet_set_vq_state,
+ .get_vq_state = mvnet_get_vq_state,
+ .get_vq_align = mvnet_get_vq_align,
+ .get_features = mvnet_get_features,
+ .set_features = mvnet_set_features,
+ .set_config_cb = mvnet_set_config_cb,
+ .get_queue_max = mvnet_get_queue_max,
+ .get_device_id = mvnet_get_device_id,
+ .get_vendor_id = mvnet_get_vendor_id,
+ .get_status = mvnet_get_status,
+ .set_status = mvnet_set_status,
+ .get_config = mvnet_get_config,
+ .set_config = mvnet_set_config,
+ .get_version = mvnet_get_version,
+ .get_generation = mvnet_get_generation,
+};
+
+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,
+};
+
+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, "Simulate loopback ethernet device over mdev");
+MODULE_VERSION(VERSION_STRING);
+MODULE_AUTHOR(DRIVER_AUTHOR);
--
2.19.1
^ permalink raw reply related
* [PATCH v2] ipv6: do not free rt if FIB_LOOKUP_NOREF is set on suppress rule
From: Jason A. Donenfeld @ 2019-09-24 14:01 UTC (permalink / raw)
To: netdev, linux-kernel, davem, weiwan; +Cc: Jason A. Donenfeld, stable
In-Reply-To: <20190924.145257.2013712373872209531.davem@davemloft.net>
Commit 7d9e5f422150 removed references from certain dsts, but accounting
for this never translated down into the fib6 suppression code. This bug
was triggered by WireGuard users who use wg-quick(8), which uses the
"suppress-prefix" directive to ip-rule(8) for routing all of their
internet traffic without routing loops. The test case added here
causes the reference underflow by causing packets to evaluate a suppress
rule.
Cc: stable@vger.kernel.org
Fixes: 7d9e5f422150 ("ipv6: convert major tx path to use RT6_LOOKUP_F_DST_NOREF")
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
---
net/ipv6/fib6_rules.c | 3 ++-
tools/testing/selftests/net/fib_tests.sh | 17 ++++++++++++++++-
2 files changed, 18 insertions(+), 2 deletions(-)
diff --git a/net/ipv6/fib6_rules.c b/net/ipv6/fib6_rules.c
index d22b6c140f23..f9e8fe3ff0c5 100644
--- a/net/ipv6/fib6_rules.c
+++ b/net/ipv6/fib6_rules.c
@@ -287,7 +287,8 @@ static bool fib6_rule_suppress(struct fib_rule *rule, struct fib_lookup_arg *arg
return false;
suppress_route:
- ip6_rt_put(rt);
+ if (!(arg->flags & FIB_LOOKUP_NOREF))
+ ip6_rt_put(rt);
return true;
}
diff --git a/tools/testing/selftests/net/fib_tests.sh b/tools/testing/selftests/net/fib_tests.sh
index 4465fc2dae14..c2c5f2bf0f95 100755
--- a/tools/testing/selftests/net/fib_tests.sh
+++ b/tools/testing/selftests/net/fib_tests.sh
@@ -9,7 +9,7 @@ ret=0
ksft_skip=4
# all tests in this script. Can be overridden with -t option
-TESTS="unregister down carrier nexthop ipv6_rt ipv4_rt ipv6_addr_metric ipv4_addr_metric ipv6_route_metrics ipv4_route_metrics ipv4_route_v6_gw rp_filter"
+TESTS="unregister down carrier nexthop suppress ipv6_rt ipv4_rt ipv6_addr_metric ipv4_addr_metric ipv6_route_metrics ipv4_route_metrics ipv4_route_v6_gw rp_filter"
VERBOSE=0
PAUSE_ON_FAIL=no
@@ -614,6 +614,20 @@ fib_nexthop_test()
cleanup
}
+fib_suppress_test()
+{
+ $IP link add dummy1 type dummy
+ $IP link set dummy1 up
+ $IP -6 route add default dev dummy1
+ $IP -6 rule add table main suppress_prefixlength 0
+ ping -f -c 1000 -W 1 1234::1 || true
+ $IP -6 rule del table main suppress_prefixlength 0
+ $IP link del dummy1
+
+ # If we got here without crashing, we're good.
+ return 0
+}
+
################################################################################
# Tests on route add and replace
@@ -1591,6 +1605,7 @@ do
fib_carrier_test|carrier) fib_carrier_test;;
fib_rp_filter_test|rp_filter) fib_rp_filter_test;;
fib_nexthop_test|nexthop) fib_nexthop_test;;
+ fib_suppress_test|suppress) fib_suppress_test;;
ipv6_route_test|ipv6_rt) ipv6_route_test;;
ipv4_route_test|ipv4_rt) ipv4_route_test;;
ipv6_addr_metric) ipv6_addr_metric_test;;
--
2.21.0
^ permalink raw reply related
* Re: [PATCH 5/6] vringh: fix copy direction of vringh_iov_push_kern()
From: Alex Williamson @ 2019-09-24 14:04 UTC (permalink / raw)
To: Michael S. Tsirkin
Cc: Jason Wang, kvm, linux-s390, linux-kernel, dri-devel, intel-gfx,
intel-gvt-dev, kwankhede, tiwei.bie, virtualization, netdev,
cohuck, maxime.coquelin, cunming.liang, zhihong.wang, rob.miller,
xiao.w.wang, haotian.wang, zhenyuw, zhi.a.wang, jani.nikula,
joonas.lahtinen, rodrigo.vivi, airlied, daniel, farman, pasic,
sebott, oberpar, heiko.carstens, gor, borntraeger, akrowiak,
freude, lingshan.zhu, idos, eperezma, lulu, parav
In-Reply-To: <20190923115930-mutt-send-email-mst@kernel.org>
On Mon, 23 Sep 2019 12:00:41 -0400
"Michael S. Tsirkin" <mst@redhat.com> wrote:
> On Mon, Sep 23, 2019 at 09:45:59AM -0600, Alex Williamson wrote:
> > On Mon, 23 Sep 2019 21:03:30 +0800
> > Jason Wang <jasowang@redhat.com> wrote:
> >
> > > We want to copy from iov to buf, so the direction was wrong.
> > >
> > > Signed-off-by: Jason Wang <jasowang@redhat.com>
> > > ---
> > > drivers/vhost/vringh.c | 8 +++++++-
> > > 1 file changed, 7 insertions(+), 1 deletion(-)
> >
> >
> > Why is this included in the series? Seems like an unrelated fix being
> > held up within a proposal for a new feature. Thanks,
> >
> > Alex
>
> It's better to have it as patch 1/6, but it's a dependency of the
> example driver in the series. I can reorder when I apply.
It's a fix, please submit it separately through virtio/vhost channels,
then it will already be in the base kernel we use for the rest of the
series. The remainder of the series certainly suggests a workflow
through the vfio tree rather than virtio/vhost. Thanks,
Alex
> > > diff --git a/drivers/vhost/vringh.c b/drivers/vhost/vringh.c
> > > index 08ad0d1f0476..a0a2d74967ef 100644
> > > --- a/drivers/vhost/vringh.c
> > > +++ b/drivers/vhost/vringh.c
> > > @@ -852,6 +852,12 @@ static inline int xfer_kern(void *src, void *dst, size_t len)
> > > return 0;
> > > }
> > >
> > > +static inline int kern_xfer(void *dst, void *src, size_t len)
> > > +{
> > > + memcpy(dst, src, len);
> > > + return 0;
> > > +}
> > > +
> > > /**
> > > * vringh_init_kern - initialize a vringh for a kernelspace vring.
> > > * @vrh: the vringh to initialize.
> > > @@ -958,7 +964,7 @@ EXPORT_SYMBOL(vringh_iov_pull_kern);
> > > ssize_t vringh_iov_push_kern(struct vringh_kiov *wiov,
> > > const void *src, size_t len)
> > > {
> > > - return vringh_iov_xfer(wiov, (void *)src, len, xfer_kern);
> > > + return vringh_iov_xfer(wiov, (void *)src, len, kern_xfer);
> > > }
> > > EXPORT_SYMBOL(vringh_iov_push_kern);
> > >
^ permalink raw reply
* RE: [PATCH 2/3] clk: let init callback return an error code
From: Jerome Brunet @ 2019-09-24 14:10 UTC (permalink / raw)
To: Ankur Tyagi, Michael Turquette, Stephen Boyd
Cc: linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org,
Heiko Stuebner, Tero Kristo, Andrew Lunn, Florian Fainelli,
Heiner Kallweit, David S. Miller, netdev@vger.kernel.org,
linux-amlogic@lists.infradead.org, linux-arm-msm@vger.kernel.org,
linux-rockchip@lists.infradead.org, linux-omap@vger.kernel.org
In-Reply-To: <ME2PR01MB4738B127557AE20F6315AA7FE5840@ME2PR01MB4738.ausprd01.prod.outlook.com>
On Tue 24 Sep 2019 at 13:38, Ankur Tyagi <Ankur.Tyagi@gallagher.com> wrote:
> Hi,
>
> I am no expert here but just looked at the patch and found few
> discrepancy that I have mentioned inline.
>
[...]
>
> Aren't all functions returning 0 always?
>
Yes, on purpose. This patch is an API conversion to let the init()
callback of the clock ops return an error code or 0.
The patch is not meant to change anything in the prior behavior of the
clock drivers which is why every exit path return 0 with this change.
IOW, yes there are all returning 0 for now, but it will eventually
change.
>> *
>> * @debug_init:Set up type-specific debugfs entries for this clock. This
>> *is called once, after the debugfs directory entry for this
>> @@ -243,7 +247,7 @@ struct clk_ops {
>> struct clk_duty *duty);
>> int(*set_duty_cycle)(struct clk_hw *hw,
>> struct clk_duty *duty);
>> -void(*init)(struct clk_hw *hw);
>> +int(*init)(struct clk_hw *hw);
>> void(*debug_init)(struct clk_hw *hw, struct dentry *dentry);
>> };
>>
>> --
>> 2.21.0
>
> ________________________________
> This email is confidential and may contain information subject to legal privilege. If you are not the intended recipient please advise us of our error by return e-mail then delete this email and any attached files. You may not copy, disclose or use the contents in any way. The views expressed in this email may not be those of Gallagher Group Ltd or subsidiary companies thereof.
> ________________________________
^ permalink raw reply
* atlantic: weird hwmon temperature readings with AQC107 NIC (kernel 5.2/5.3)
From: Holger Hoffstätte @ 2019-09-24 14:16 UTC (permalink / raw)
To: Netdev, Igor Russkikh
Hi,
I recently upgraded my home network with two AQ107-based NICs and a
multi-speed switch. Everything works great, but I couldn't help but notice
very weird hwmon temperature output (which I wanted to use for monitoring
and alerting).
Both cards identify as:
$lspci -v -s 06:00.0
06:00.0 Ethernet controller: Aquantia Corp. AQC107 NBase-T/IEEE 802.3bz Ethernet Controller [AQtion] (rev 02)
Subsystem: ASUSTeK Computer Inc. AQC107 NBase-T/IEEE 802.3bz Ethernet Controller [AQtion]
In one machine lm_sensors says:
eth0-pci-0200
Adapter: PCI adapter
PHY Temperature: +315.1°C
This seems quite wrong since the card is only slightly warm to the touch, and
315.1 is exactly 255 + 60.1 - the latter value feels more like the actual
temperature.
On a second machine it says:
eth0-pci-0600
Adapter: PCI adapter
PHY Temperature: +6977.0°C
I feel qualified to say that is definitely wrong as well, since the machine is
currently not melting its way to the earth's core, and also only slightly warm
to the touch. :)
Both cards also reported wrong values with kernel 5.2, but since I'm on 5.3.1
I might as well report the current wrongness.
Do we know who's to blame here - motherboards, NICs, driver, kernel, hwmon
infrastructure? I believe the hwmon patches landed first in 5.2.
Thanks,
Holger
^ permalink raw reply
* Re: [RFC PATCH v3 4/6] psci: Add hvc call service for ptp_kvm.
From: Paolo Bonzini @ 2019-09-24 14:20 UTC (permalink / raw)
To: Jianyong Wu (Arm Technology China), netdev@vger.kernel.org,
yangbo.lu@nxp.com, john.stultz@linaro.org, tglx@linutronix.de,
sean.j.christopherson@intel.com, maz@kernel.org,
richardcochran@gmail.com, Mark Rutland, Will Deacon,
Suzuki Poulose
Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, Steve Capper,
Kaly Xin (Arm Technology China), Justin He (Arm Technology China),
nd, linux-arm-kernel@lists.infradead.org
In-Reply-To: <HE1PR0801MB1676A9D4A58118144F5C7B54F4850@HE1PR0801MB1676.eurprd08.prod.outlook.com>
On 23/09/19 06:57, Jianyong Wu (Arm Technology China) wrote:
>> On 19/09/19 11:46, Jianyong Wu (Arm Technology China) wrote:
>>>> On 18/09/19 11:57, Jianyong Wu (Arm Technology China) wrote:
>>>>> Paolo Bonzini wrote:
>>>>>> This is not Y2038-safe. Please use ktime_get_real_ts64 instead,
>>>>>> and split the 64-bit seconds value between val[0] and val[1].
>>>
>>> Val[] should be long not u32 I think, so in arm64 I can avoid that
>>> Y2038_safe, but also need rewrite for arm32.
>>
>> I don't think there's anything inherently wrong with u32 val[], and as you
>> notice it lets you reuse code between arm and arm64. It's up to you and
>> Marc to decide.
>>
> To compatible 32-bit, Integrates second value and nanosecond value as a nanosecond value then split it into val[0] and val[1] and split cycle value into val[2] and val[3],
> In this way, time will overflow at Y2262.
> WDYT?
So if I understand correctly you'd multiply by 10^9 (or better shift by
30) the nanoseconds.
That works, but why not provide 5 output registers? Alternatively, take
an address as input and write there.
Finally, on x86 we added an argument for the CLOCK_* that is being read
(currently only CLOCK_REALTIME, but having room for extensibility in the
API is always nice).
Paolo
^ permalink raw reply
* Re: atlantic: weird hwmon temperature readings with AQC107 NIC (kernel 5.2/5.3)
From: Holger Hoffstätte @ 2019-09-24 14:30 UTC (permalink / raw)
To: Netdev, Igor Russkikh
In-Reply-To: <0db14339-1b69-8fa4-21fd-6d436037c945@applied-asynchrony.com>
On 9/24/19 4:16 PM, Holger Hoffstätte wrote:
> Hi,
>
> I recently upgraded my home network with two AQ107-based NICs and a
> multi-speed switch. Everything works great, but I couldn't help but notice
> very weird hwmon temperature output (which I wanted to use for monitoring
> and alerting).
>
> Both cards identify as:
>
> $lspci -v -s 06:00.0
> 06:00.0 Ethernet controller: Aquantia Corp. AQC107 NBase-T/IEEE 802.3bz Ethernet Controller [AQtion] (rev 02)
> Subsystem: ASUSTeK Computer Inc. AQC107 NBase-T/IEEE 802.3bz Ethernet Controller [AQtion]
>
> In one machine lm_sensors says:
>
> eth0-pci-0200
> Adapter: PCI adapter
> PHY Temperature: +315.1°C
>
> This seems quite wrong since the card is only slightly warm to the touch, and
> 315.1 is exactly 255 + 60.1 - the latter value feels more like the actual
> temperature.
>
> On a second machine it says:
>
> eth0-pci-0600
> Adapter: PCI adapter
> PHY Temperature: +6977.0°C
>
> I feel qualified to say that is definitely wrong as well, since the machine is
> currently not melting its way to the earth's core, and also only slightly warm
> to the touch. :)
>
> Both cards also reported wrong values with kernel 5.2, but since I'm on 5.3.1
> I might as well report the current wrongness.
>
> Do we know who's to blame here - motherboards, NICs, driver, kernel, hwmon
> infrastructure? I believe the hwmon patches landed first in 5.2.
Another observation: the hwmon output immediately becomes sane (~58°)
when I down the link with ifconfig. As soon as I bring the link back up,
the temperature jumps from 58° to 6976° in one second.
It seems that the presence of the carrier somehow mangles the sensor
readings. I hope this helps to find the issue.
thanks,
Holger
^ permalink raw reply
* Re: atlantic: weird hwmon temperature readings with AQC107 NIC (kernel 5.2/5.3)
From: Igor Russkikh @ 2019-09-24 14:32 UTC (permalink / raw)
To: Holger Hoffstätte, Netdev
In-Reply-To: <4faf7584-860e-6f52-95ab-ea96438af394@applied-asynchrony.com>
On 24.09.2019 17:30, Holger Hoffstätte wrote:
> On 9/24/19 4:16 PM, Holger Hoffstätte wrote:
>> Hi,
>>
>> I recently upgraded my home network with two AQ107-based NICs and a
>> multi-speed switch. Everything works great, but I couldn't help but notice
>> very weird hwmon temperature output (which I wanted to use for monitoring
>> and alerting).
>>
>> Both cards identify as:
>>
>> $lspci -v -s 06:00.0
>> 06:00.0 Ethernet controller: Aquantia Corp. AQC107 NBase-T/IEEE 802.3bz
>> Ethernet Controller [AQtion] (rev 02)
>> Subsystem: ASUSTeK Computer Inc. AQC107 NBase-T/IEEE 802.3bz Ethernet
>> Controller [AQtion]
>>
>> In one machine lm_sensors says:
>>
>> eth0-pci-0200
>> Adapter: PCI adapter
>> PHY Temperature: +315.1°C
>>
>> This seems quite wrong since the card is only slightly warm to the touch, and
>> 315.1 is exactly 255 + 60.1 - the latter value feels more like the actual
>> temperature.
>>
>> On a second machine it says:
>>
>> eth0-pci-0600
>> Adapter: PCI adapter
>> PHY Temperature: +6977.0°C
>>
>> I feel qualified to say that is definitely wrong as well, since the machine is
>> currently not melting its way to the earth's core, and also only slightly warm
>> to the touch. :)
>>
>> Both cards also reported wrong values with kernel 5.2, but since I'm on 5.3.1
>> I might as well report the current wrongness.
>>
>> Do we know who's to blame here - motherboards, NICs, driver, kernel, hwmon
>> infrastructure? I believe the hwmon patches landed first in 5.2.
>
> Another observation: the hwmon output immediately becomes sane (~58°)
> when I down the link with ifconfig. As soon as I bring the link back up,
> the temperature jumps from 58° to 6976° in one second.
> It seems that the presence of the carrier somehow mangles the sensor
> readings. I hope this helps to find the issue.
>
> thanks,
> Holger
Hi Holger,
Thanks for the report,
We've recently found out that as well, could you try applying the following patch:
diff --git a/drivers/net/ethernet/aquantia/atlantic/hw_atl/hw_atl_utils_fw2x.c
b/drivers/net/ethernet/aquantia/atlantic/hw_atl/hw_atl_utils_fw2x.c
index da726489e3c8..08b026b41571 100644
--- a/drivers/net/ethernet/aquantia/atlantic/hw_atl/hw_atl_utils_fw2x.c
+++ b/drivers/net/ethernet/aquantia/atlantic/hw_atl/hw_atl_utils_fw2x.c
@@ -337,7 +337,7 @@ static int aq_fw2x_get_phy_temp(struct aq_hw_s *self, int *temp)
/* Convert PHY temperature from 1/256 degree Celsius
* to 1/1000 degree Celsius.
*/
- *temp = temp_res * 1000 / 256;
+ *temp = (temp_res & 0xFFFF) * 1000 / 256;
return 0;
}
Funny thing is that this value gets readout from HW memory, all the readouts are
done by full dwords, but the value is only word width. High word of that dword
is estimated cable length. On short cables we use it is often zero ;)
As I see from your readings - your cables are abit longer :)
This also explains why temp is good when you do interface down.
Regards,
Igor
^ permalink raw reply related
* Re: [PATCH net] net: sched: fix possible crash in tcf_action_destroy()
From: David Miller @ 2019-09-24 14:36 UTC (permalink / raw)
To: edumazet; +Cc: netdev, eric.dumazet, syzkaller, vladbu, jiri
In-Reply-To: <20190918195704.218413-1-edumazet@google.com>
From: Eric Dumazet <edumazet@google.com>
Date: Wed, 18 Sep 2019 12:57:04 -0700
> If the allocation done in tcf_exts_init() failed,
> we end up with a NULL pointer in exts->actions.
...
> Fixes: 90b73b77d08e ("net: sched: change action API to use array of pointers to actions")
> Signed-off-by: Eric Dumazet <edumazet@google.com>
> Reported-by: syzbot <syzkaller@googlegroups.com>
Applied and queued up for -stable.
^ permalink raw reply
* Re: [PATCH 0/5] Raw socket cleanups
From: David Miller @ 2019-09-24 14:38 UTC (permalink / raw)
To: gregkh; +Cc: netdev, isdn, jreuter, ralf, alex.aring, stefan, orinimron123
In-Reply-To: <20190920073549.517481-1-gregkh@linuxfoundation.org>
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Date: Fri, 20 Sep 2019 09:35:44 +0200
> Ori Nimron pointed out that there are a number of places in the kernel
> where you can create a raw socket, without having to have the
> CAP_NET_RAW permission.
>
> To resolve this, here's a short patch series to test these odd and old
> protocols for this permission before allowing the creation to succeed
>
> All patches are currently against the net tree.
Applied and queued up for -stable.
^ permalink raw reply
* Re: [PATCH] net-icmp: remove ping_group_range sysctl
From: David Miller @ 2019-09-24 14:40 UTC (permalink / raw)
To: zenczykowski; +Cc: maze, netdev, keescook, dvyukov, edumazet, maheshb, lorenzo
In-Reply-To: <20190919103944.129616-1-zenczykowski@gmail.com>
Removing this is going to break things, you can't just remove a sysctl
because "oh it was a bad idea to add this, sorry."
^ permalink raw reply
* Re: [PATCH] dimlib: make DIMLIB a hidden symbol
From: David Miller @ 2019-09-24 14:45 UTC (permalink / raw)
To: uwe; +Cc: talgi, saeedm, linux-kernel, netdev
In-Reply-To: <20190920133115.12802-1-uwe@kleine-koenig.org>
From: Uwe Kleine-König <uwe@kleine-koenig.org>
Date: Fri, 20 Sep 2019 15:31:15 +0200
> According to Tal Gilboa the only benefit from DIM comes from a driver
> that uses it. So it doesn't make sense to make this symbol user visible,
> instead all drivers that use it should select it (as is already the case
> AFAICT).
>
> Signed-off-by: Uwe Kleine-König <uwe@kleine-koenig.org>
Since this doesn't apply due to the moderation typo being elsewhere, I'd
really like you to fix up this submission to properly be against 'net'.
Thank you.
^ permalink raw reply
* Re: [PATCH] net-icmp: remove ping_group_range sysctl
From: Maciej Żenczykowski @ 2019-09-24 14:47 UTC (permalink / raw)
To: David Miller
Cc: Linux NetDev, Kees Cook, Dmitry Vyukov, Eric Dumazet,
Mahesh Bandewar, Lorenzo Colitti
In-Reply-To: <20190924.164016.43204807921728597.davem@davemloft.net>
> Removing this is going to break things, you can't just remove a sysctl
> because "oh it was a bad idea to add this, sorry."
Yeah, I know... but do you have any other suggestions?
Would you take an alternative to make the default wide opened?
The current sysctl just doesn't work. It can even print '1 0' meaning
everyone has access.
Perhaps having it as a non-namespace aware global setting (with a
default of on) would be more palatable?
^ permalink raw reply
* Re: [PATCH] arcnet: provide a buffer big enough to actually receive packets
From: David Miller @ 2019-09-24 14:49 UTC (permalink / raw)
To: u.kleine-koenig; +Cc: m.grzeschik, netdev, labbott, stable
In-Reply-To: <20190920140821.11876-1-u.kleine-koenig@pengutronix.de>
From: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Date: Fri, 20 Sep 2019 16:08:21 +0200
> struct archdr is only big enough to hold the header of various types of
> arcnet packets. So to provide enough space to hold the data read from
> hardware provide a buffer large enough to hold a packet with maximal
> size.
>
> The problem was noticed by the stack protector which makes the kernel
> oops.
>
> Cc: stable@vger.kernel.org # v2.4.0+
Do not CC: stable for networking patches, I take care of it.
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Applied and queued up for -stable.
^ permalink raw reply
* Re: [PATCH net v2 0/3] net/smc: move some definitions to UAPI
From: David Miller @ 2019-09-24 14:52 UTC (permalink / raw)
To: esyr; +Cc: netdev, linux-kernel, ubraun, kgraul
In-Reply-To: <cover.1568993930.git.esyr@redhat.com>
From: Eugene Syromiatnikov <esyr@redhat.com>
Date: Fri, 20 Sep 2019 17:41:47 +0200
> As of now, it's a bit difficult to use SMC protocol, as significant part
> of definitions related to it are defined in private headers and are not
> part of UAPI. The following commits move some definitions to UAPI,
> making them readily available to the user space.
>
> Changes since v1[1]:
> * Patch "provide fallback diagnostic codes in UAPI" is updated
> in accordance with the updated set of diagnostic codes.
>
> [1] https://lkml.org/lkml/2018/10/7/177
Isn't it way too late for this?
These definitions will now be duplicates for userland code that
defines the values on their own.
^ permalink raw reply
* Re: atlantic: weird hwmon temperature readings with AQC107 NIC (kernel 5.2/5.3)
From: Holger Hoffstätte @ 2019-09-24 14:55 UTC (permalink / raw)
To: Igor Russkikh, Netdev
In-Reply-To: <c26f4a9d-df14-c8af-4c99-5a670099e8bc@aquantia.com>
On 9/24/19 4:32 PM, Igor Russkikh wrote:
> We've recently found out that as well, could you try applying the following patch:
>
> diff --git a/drivers/net/ethernet/aquantia/atlantic/hw_atl/hw_atl_utils_fw2x.c
> b/drivers/net/ethernet/aquantia/atlantic/hw_atl/hw_atl_utils_fw2x.c
> index da726489e3c8..08b026b41571 100644
> --- a/drivers/net/ethernet/aquantia/atlantic/hw_atl/hw_atl_utils_fw2x.c
> +++ b/drivers/net/ethernet/aquantia/atlantic/hw_atl/hw_atl_utils_fw2x.c
> @@ -337,7 +337,7 @@ static int aq_fw2x_get_phy_temp(struct aq_hw_s *self, int *temp)
> /* Convert PHY temperature from 1/256 degree Celsius
> * to 1/1000 degree Celsius.
> */
> - *temp = temp_res * 1000 / 256;
> + *temp = (temp_res & 0xFFFF) * 1000 / 256;
>
> return 0;
> }
Well, what do you know!
eth0-pci-0600
Adapter: PCI adapter
PHY Temperature: +63.5°C
This looks like it aligns with reality. :-)
> Funny thing is that this value gets readout from HW memory, all the readouts are
> done by full dwords, but the value is only word width. High word of that dword
I suspected upper-word-garbage but of course don't know internals.
> is estimated cable length. On short cables we use it is often zero ;)
:D
When you send the proper patch feel free to add:
Tested-by: Holger Hoffstätte <holger@applied-asynchrony.com>
Thanks again for the quick help!
Holger
^ permalink raw reply
* Re: [PATCH net] skge: fix checksum byte order
From: David Miller @ 2019-09-24 14:55 UTC (permalink / raw)
To: stephen; +Cc: netdev
In-Reply-To: <20190920161826.15942-1-sthemmin@microsoft.com>
From: Stephen Hemminger <stephen@networkplumber.org>
Date: Fri, 20 Sep 2019 18:18:26 +0200
> From: Stephen Hemminger <stephen@networkplumber.org>
>
> Running old skge driver on PowerPC causes checksum errors
> because hardware reported 1's complement checksum is in little-endian
> byte order.
>
> Reported-by: Benoit <benoit.sansoni@gmail.com>
> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
Applied and queued up for -stable.
^ permalink raw reply
* [PATCH net 1/3] ipv6: add priority parameter to ip6_xmit()
From: Eric Dumazet @ 2019-09-24 15:01 UTC (permalink / raw)
To: David S . Miller; +Cc: netdev, Eric Dumazet, Eric Dumazet
In-Reply-To: <20190924150116.199028-1-edumazet@google.com>
Currently, ip6_xmit() sets skb->priority based on sk->sk_priority
This is not desirable for TCP since TCP shares the same ctl socket
for a given netns. We want to be able to send RST or ACK packets
with a non zero skb->priority.
This patch has no functional change.
Signed-off-by: Eric Dumazet <edumazet@google.com>
---
include/net/ipv6.h | 2 +-
net/dccp/ipv6.c | 5 +++--
net/ipv6/inet6_connection_sock.c | 2 +-
net/ipv6/ip6_output.c | 4 ++--
net/ipv6/tcp_ipv6.c | 6 ++++--
net/sctp/ipv6.c | 2 +-
6 files changed, 12 insertions(+), 9 deletions(-)
diff --git a/include/net/ipv6.h b/include/net/ipv6.h
index 8dfc65639aa4c4dc10277989cf4bfa03ec161354..009605c56f209040d10f4878353aafa66c1a845f 100644
--- a/include/net/ipv6.h
+++ b/include/net/ipv6.h
@@ -981,7 +981,7 @@ int ip6_rcv_finish(struct net *net, struct sock *sk, struct sk_buff *skb);
* upper-layer output functions
*/
int ip6_xmit(const struct sock *sk, struct sk_buff *skb, struct flowi6 *fl6,
- __u32 mark, struct ipv6_txoptions *opt, int tclass);
+ __u32 mark, struct ipv6_txoptions *opt, int tclass, u32 priority);
int ip6_find_1stfragopt(struct sk_buff *skb, u8 **nexthdr);
diff --git a/net/dccp/ipv6.c b/net/dccp/ipv6.c
index 1b7381ff787b388488a8458b6f52760f73a4f22d..25aab672fc9907801f63ff2bd374f6db17fe28d2 100644
--- a/net/dccp/ipv6.c
+++ b/net/dccp/ipv6.c
@@ -230,7 +230,8 @@ static int dccp_v6_send_response(const struct sock *sk, struct request_sock *req
opt = ireq->ipv6_opt;
if (!opt)
opt = rcu_dereference(np->opt);
- err = ip6_xmit(sk, skb, &fl6, sk->sk_mark, opt, np->tclass);
+ err = ip6_xmit(sk, skb, &fl6, sk->sk_mark, opt, np->tclass,
+ sk->sk_priority);
rcu_read_unlock();
err = net_xmit_eval(err);
}
@@ -284,7 +285,7 @@ static void dccp_v6_ctl_send_reset(const struct sock *sk, struct sk_buff *rxskb)
dst = ip6_dst_lookup_flow(ctl_sk, &fl6, NULL);
if (!IS_ERR(dst)) {
skb_dst_set(skb, dst);
- ip6_xmit(ctl_sk, skb, &fl6, 0, NULL, 0);
+ ip6_xmit(ctl_sk, skb, &fl6, 0, NULL, 0, 0);
DCCP_INC_STATS(DCCP_MIB_OUTSEGS);
DCCP_INC_STATS(DCCP_MIB_OUTRSTS);
return;
diff --git a/net/ipv6/inet6_connection_sock.c b/net/ipv6/inet6_connection_sock.c
index 4da24aa6c696dff6867f876b20805f2dd207e8c5..0a0945a5b30da1647aaf1b9f8b46db69102e8ff8 100644
--- a/net/ipv6/inet6_connection_sock.c
+++ b/net/ipv6/inet6_connection_sock.c
@@ -133,7 +133,7 @@ int inet6_csk_xmit(struct sock *sk, struct sk_buff *skb, struct flowi *fl_unused
fl6.daddr = sk->sk_v6_daddr;
res = ip6_xmit(sk, skb, &fl6, sk->sk_mark, rcu_dereference(np->opt),
- np->tclass);
+ np->tclass, sk->sk_priority);
rcu_read_unlock();
return res;
}
diff --git a/net/ipv6/ip6_output.c b/net/ipv6/ip6_output.c
index 89a4c7c2e25d01cc2ef18ae9c407f8f3319590d9..edadee4a7e76105f737d705052db8f5bbc6c0152 100644
--- a/net/ipv6/ip6_output.c
+++ b/net/ipv6/ip6_output.c
@@ -193,7 +193,7 @@ bool ip6_autoflowlabel(struct net *net, const struct ipv6_pinfo *np)
* which are using proper atomic operations or spinlocks.
*/
int ip6_xmit(const struct sock *sk, struct sk_buff *skb, struct flowi6 *fl6,
- __u32 mark, struct ipv6_txoptions *opt, int tclass)
+ __u32 mark, struct ipv6_txoptions *opt, int tclass, u32 priority)
{
struct net *net = sock_net(sk);
const struct ipv6_pinfo *np = inet6_sk(sk);
@@ -258,7 +258,7 @@ int ip6_xmit(const struct sock *sk, struct sk_buff *skb, struct flowi6 *fl6,
hdr->daddr = *first_hop;
skb->protocol = htons(ETH_P_IPV6);
- skb->priority = sk->sk_priority;
+ skb->priority = priority;
skb->mark = mark;
mtu = dst_mtu(dst);
diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
index 87f44d3250ee6844777a000760326d6ad6831de6..806064c2886777ad37a1f0b8406aa8bee7945723 100644
--- a/net/ipv6/tcp_ipv6.c
+++ b/net/ipv6/tcp_ipv6.c
@@ -512,7 +512,8 @@ static int tcp_v6_send_synack(const struct sock *sk, struct dst_entry *dst,
opt = ireq->ipv6_opt;
if (!opt)
opt = rcu_dereference(np->opt);
- err = ip6_xmit(sk, skb, fl6, sk->sk_mark, opt, np->tclass);
+ err = ip6_xmit(sk, skb, fl6, sk->sk_mark, opt, np->tclass,
+ sk->sk_priority);
rcu_read_unlock();
err = net_xmit_eval(err);
}
@@ -907,7 +908,8 @@ static void tcp_v6_send_response(const struct sock *sk, struct sk_buff *skb, u32
dst = ip6_dst_lookup_flow(ctl_sk, &fl6, NULL);
if (!IS_ERR(dst)) {
skb_dst_set(buff, dst);
- ip6_xmit(ctl_sk, buff, &fl6, fl6.flowi6_mark, NULL, tclass);
+ ip6_xmit(ctl_sk, buff, &fl6, fl6.flowi6_mark, NULL, tclass,
+ 0);
TCP_INC_STATS(net, TCP_MIB_OUTSEGS);
if (rst)
TCP_INC_STATS(net, TCP_MIB_OUTRSTS);
diff --git a/net/sctp/ipv6.c b/net/sctp/ipv6.c
index e5f2fc726a983579dddbd201ea5ee5eb371a50ac..dd860fea014843b350fd01108b78b538cb09ecbb 100644
--- a/net/sctp/ipv6.c
+++ b/net/sctp/ipv6.c
@@ -215,7 +215,7 @@ static int sctp_v6_xmit(struct sk_buff *skb, struct sctp_transport *transport)
rcu_read_lock();
res = ip6_xmit(sk, skb, fl6, sk->sk_mark, rcu_dereference(np->opt),
- tclass);
+ tclass, sk->sk_priority);
rcu_read_unlock();
return res;
}
--
2.23.0.351.gc4317032e6-goog
^ permalink raw reply related
* [PATCH net 2/3] ipv6: tcp: provide sk->sk_priority to ctl packets
From: Eric Dumazet @ 2019-09-24 15:01 UTC (permalink / raw)
To: David S . Miller; +Cc: netdev, Eric Dumazet, Eric Dumazet
In-Reply-To: <20190924150116.199028-1-edumazet@google.com>
We can populate skb->priority for some ctl packets
instead of always using zero.
Signed-off-by: Eric Dumazet <edumazet@google.com>
---
net/ipv6/tcp_ipv6.c | 16 +++++++++-------
1 file changed, 9 insertions(+), 7 deletions(-)
diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
index 806064c2886777ad37a1f0b8406aa8bee7945723..5f557bf27da2ba6bcc74034a53a3f76a99fdf9f4 100644
--- a/net/ipv6/tcp_ipv6.c
+++ b/net/ipv6/tcp_ipv6.c
@@ -804,7 +804,7 @@ static const struct tcp_request_sock_ops tcp_request_sock_ipv6_ops = {
static void tcp_v6_send_response(const struct sock *sk, struct sk_buff *skb, u32 seq,
u32 ack, u32 win, u32 tsval, u32 tsecr,
int oif, struct tcp_md5sig_key *key, int rst,
- u8 tclass, __be32 label)
+ u8 tclass, __be32 label, u32 priority)
{
const struct tcphdr *th = tcp_hdr(skb);
struct tcphdr *t1;
@@ -909,7 +909,7 @@ static void tcp_v6_send_response(const struct sock *sk, struct sk_buff *skb, u32
if (!IS_ERR(dst)) {
skb_dst_set(buff, dst);
ip6_xmit(ctl_sk, buff, &fl6, fl6.flowi6_mark, NULL, tclass,
- 0);
+ priority);
TCP_INC_STATS(net, TCP_MIB_OUTSEGS);
if (rst)
TCP_INC_STATS(net, TCP_MIB_OUTRSTS);
@@ -932,6 +932,7 @@ static void tcp_v6_send_reset(const struct sock *sk, struct sk_buff *skb)
struct sock *sk1 = NULL;
#endif
__be32 label = 0;
+ u32 priority = 0;
struct net *net;
int oif = 0;
@@ -992,6 +993,7 @@ static void tcp_v6_send_reset(const struct sock *sk, struct sk_buff *skb)
trace_tcp_send_reset(sk, skb);
if (np->repflow)
label = ip6_flowlabel(ipv6h);
+ priority = sk->sk_priority;
}
if (sk->sk_state == TCP_TIME_WAIT)
label = cpu_to_be32(inet_twsk(sk)->tw_flowlabel);
@@ -1001,7 +1003,7 @@ static void tcp_v6_send_reset(const struct sock *sk, struct sk_buff *skb)
}
tcp_v6_send_response(sk, skb, seq, ack_seq, 0, 0, 0, oif, key, 1, 0,
- label);
+ label, priority);
#ifdef CONFIG_TCP_MD5SIG
out:
@@ -1012,10 +1014,10 @@ static void tcp_v6_send_reset(const struct sock *sk, struct sk_buff *skb)
static void tcp_v6_send_ack(const struct sock *sk, struct sk_buff *skb, u32 seq,
u32 ack, u32 win, u32 tsval, u32 tsecr, int oif,
struct tcp_md5sig_key *key, u8 tclass,
- __be32 label)
+ __be32 label, u32 priority)
{
tcp_v6_send_response(sk, skb, seq, ack, win, tsval, tsecr, oif, key, 0,
- tclass, label);
+ tclass, label, priority);
}
static void tcp_v6_timewait_ack(struct sock *sk, struct sk_buff *skb)
@@ -1027,7 +1029,7 @@ static void tcp_v6_timewait_ack(struct sock *sk, struct sk_buff *skb)
tcptw->tw_rcv_wnd >> tw->tw_rcv_wscale,
tcp_time_stamp_raw() + tcptw->tw_ts_offset,
tcptw->tw_ts_recent, tw->tw_bound_dev_if, tcp_twsk_md5_key(tcptw),
- tw->tw_tclass, cpu_to_be32(tw->tw_flowlabel));
+ tw->tw_tclass, cpu_to_be32(tw->tw_flowlabel), 0);
inet_twsk_put(tw);
}
@@ -1050,7 +1052,7 @@ static void tcp_v6_reqsk_send_ack(const struct sock *sk, struct sk_buff *skb,
tcp_time_stamp_raw() + tcp_rsk(req)->ts_off,
req->ts_recent, sk->sk_bound_dev_if,
tcp_v6_md5_do_lookup(sk, &ipv6_hdr(skb)->saddr),
- 0, 0);
+ 0, 0, sk->sk_priority);
}
--
2.23.0.351.gc4317032e6-goog
^ permalink raw reply related
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