Skip to contentSkip to conversation

use pr_warn_ratelimited() for vq_err()

PATCH Superseded John Levon 3 participants 4 messages Jan 15, 2021 – Feb 23, 2021

Subsystems (3)
lore
Share & tools
lore

John Levon

author
#0 lore raw

PATCH 1/1 use pr_warn_ratelimited() for vq_err()

vq_err() is used to report various failure states in vhost code, but by default uses pr_debug(), and as a result doesn't record anything unless enabled via dynamic debug. We'll change this so we get something recorded in the log in these failure cases. Guest VMs (and userspace) can trigger some of these messages, so we want to use the pr_warn_ratelimited() variant.

---
 drivers/vhost/vhost.h | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/vhost/vhost.h +4 -4
index b063324c7669..cb4ef78c84ba 100644
@@ -228,10 +228,10 @@ int vhost_init_device_iotlb(struct vhost_dev *d, bool enabled);
 void vhost_iotlb_map_free(struct vhost_iotlb *iotlb,
 			  struct vhost_iotlb_map *map);
 
-#define vq_err(vq, fmt, ...) do {                                  \
-		pr_debug(pr_fmt(fmt), ##__VA_ARGS__);       \
-		if ((vq)->error_ctx)                               \
-				eventfd_signal((vq)->error_ctx, 1);\
+#define vq_err(vq, fmt, ...) do {                                \
+		pr_warn_ratelimited(pr_fmt(fmt), ##__VA_ARGS__); \
+		if ((vq)->error_ctx)                             \
+			eventfd_signal((vq)->error_ctx, 1);      \
 	} while (0)
 
 enum {
Signature · 1 line
2.25.1
Acked-by on v1 1/1
#1 lore raw
Quoted 6 lines · John Levon

vq_err() is used to report various failure states in vhost code, but by default uses pr_debug(), and as a result doesn't record anything unless enabled via dynamic debug. We'll change this so we get something recorded in the log in these failure cases. Guest VMs (and userspace) can trigger some of these messages, so we want to use the pr_warn_ratelimited() variant.

It looks to me KVM also use pr_warn_ratelimited().

So

Quoted 15 lines
---
  drivers/vhost/vhost.h | 8 ++++----
  1 file changed, 4 insertions(+), 4 deletions(-)
drivers/vhost/vhost.h +0 -1
index b063324c7669..cb4ef78c84ba 100644
@@ -228,10 +228,10 @@ int vhost_init_device_iotlb(struct vhost_dev *d, bool enabled);
  void vhost_iotlb_map_free(struct vhost_iotlb *iotlb,
  			  struct vhost_iotlb_map *map);
 
-#define vq_err(vq, fmt, ...) do {                                  \

drivers/vhost/vhost.h int vhost_init_device_iotlb(struct vhost_dev *d, bool enabled); · line 237

Quoted 10 lines
drivers/vhost/vhost.h +4 -3
-		pr_debug(pr_fmt(fmt), ##__VA_ARGS__);       \
-		if ((vq)->error_ctx)                               \
-				eventfd_signal((vq)->error_ctx, 1);\
+#define vq_err(vq, fmt, ...) do {                                \
+		pr_warn_ratelimited(pr_fmt(fmt), ##__VA_ARGS__); \
+		if ((vq)->error_ctx)                             \
+			eventfd_signal((vq)->error_ctx, 1);      \
  	} while (0)
 
  enum {

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

author
#2 lore raw

PATCH v2 1/1 use pr_warn_ratelimited() for vq_err()

In reply to John Levon

vq_err() is used to report various failure states in vhost code, but by default uses pr_debug(), and as a result doesn't record anything unless enabled via dynamic debug. We'll change this so we get something recorded in the log in these failure cases. Guest VMs (and userspace) can trigger some of these messages, so we want to use the pr_warn_ratelimited() variant. However, on DEBUG kernels, we'd like to get everything, so we use pr_warn() then.

---
v2: use pr_warn() for DEBUG kernels

---
 drivers/vhost/vhost.h | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)
drivers/vhost/vhost.h +10 -4
index b063324c7669..10007bd49f84 100644
@@ -228,10 +228,16 @@ int vhost_init_device_iotlb(struct vhost_dev *d, bool enabled);
 void vhost_iotlb_map_free(struct vhost_iotlb *iotlb,
 			  struct vhost_iotlb_map *map);
 
-#define vq_err(vq, fmt, ...) do {                                  \
-		pr_debug(pr_fmt(fmt), ##__VA_ARGS__);       \
-		if ((vq)->error_ctx)                               \
-				eventfd_signal((vq)->error_ctx, 1);\
+#ifdef DEBUG
+#define vq_pr_warn pr_warn
+#else
+#define vq_pr_warn pr_warn_ratelimited
+#endif
+
+#define vq_err(vq, fmt, ...) do {                                \
+		vq_pr_warn(pr_fmt(fmt), ##__VA_ARGS__);          \
+		if ((vq)->error_ctx)                             \
+			eventfd_signal((vq)->error_ctx, 1);      \
 	} while (0)
 
 enum {
Signature · 1 line
2.25.1
Reviewed-by on v2 1/1
#3 lore raw
Quoted 9 lines · John Levon

vq_err() is used to report various failure states in vhost code, but by default uses pr_debug(), and as a result doesn't record anything unless enabled via dynamic debug. We'll change this so we get something recorded in the log in these failure cases. Guest VMs (and userspace) can trigger some of these messages, so we want to use the pr_warn_ratelimited() variant. However, on DEBUG kernels, we'd like to get everything, so we use pr_warn() then.

Quoted 33 lines

---
v2: use pr_warn() for DEBUG kernels

---
 drivers/vhost/vhost.h | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)
drivers/vhost/vhost.h +10 -4
index b063324c7669..10007bd49f84 100644
@@ -228,10 +228,16 @@ int vhost_init_device_iotlb(struct vhost_dev *d, bool enabled);
 void vhost_iotlb_map_free(struct vhost_iotlb *iotlb,
 			  struct vhost_iotlb_map *map);
 
-#define vq_err(vq, fmt, ...) do {                                  \
-		pr_debug(pr_fmt(fmt), ##__VA_ARGS__);       \
-		if ((vq)->error_ctx)                               \
-				eventfd_signal((vq)->error_ctx, 1);\
+#ifdef DEBUG
+#define vq_pr_warn pr_warn
+#else
+#define vq_pr_warn pr_warn_ratelimited
+#endif
+
+#define vq_err(vq, fmt, ...) do {                                \
+		vq_pr_warn(pr_fmt(fmt), ##__VA_ARGS__);          \
+		if ((vq)->error_ctx)                             \
+			eventfd_signal((vq)->error_ctx, 1);      \
 	} while (0)
 
 enum {
Signature · 1 line
2.25.1

dme.

Signature · 1 line
Slow me down, it's getting away from me.