From: Markus Armbruster <armbru@redhat.com>
To: qemu-devel@nongnu.org
Cc: Peter Xu <peterx@redhat.com>, Eric Blake <eblake@redhat.com>
Subject: [Qemu-devel] [PULL 1/3] qemu-error: introduce {error|warn}_report_once
Date: Mon, 27 Aug 2018 08:07:42 +0200 [thread overview]
Message-ID: <20180827060744.13770-2-armbru@redhat.com> (raw)
In-Reply-To: <20180827060744.13770-1-armbru@redhat.com>
From: Peter Xu <peterx@redhat.com>
There are many error_report()s that can be used in frequently called
functions, especially on IO paths. That can be unideal in that
malicious guest can try to trigger the error tons of time which might
use up the log space on the host (e.g., libvirt can capture the stderr
of QEMU and put it persistently onto disk). In VT-d emulation code, we
have trace_vtd_error() tracer. AFAIU all those places can be replaced
by something like error_report() but trace points are mostly used to
avoid the DDOS attack that mentioned above. However using trace points
mean that errors are not dumped if trace not enabled.
It's not a big deal in most modern server managements since we have
things like logrotate to maintain the logs and make sure the quota is
expected. However it'll still be nice that we just provide another way
to restrict message generations. In most cases, this kind of
error_report()s will only provide valid information on the first message
sent, and all the rest of similar messages will be mostly talking about
the same thing. This patch introduces *_report_once() helpers to allow
a message to be dumped only once during one QEMU process's life cycle.
It will make sure: (1) it's on by deffault, so we can even get something
without turning the trace on and reproducing, and (2) it won't be
affected by DDOS attack.
To implement it, I stole the printk_once() macro from Linux.
CC: Eric Blake <eblake@redhat.com>
CC: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Peter Xu <peterx@redhat.com>
Message-Id: <20180815095328.32414-2-peterx@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
[Whitespace adjusted, comments improved]
Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
include/qemu/error-report.h | 32 ++++++++++++++++++++++++++++++++
1 file changed, 32 insertions(+)
diff --git a/include/qemu/error-report.h b/include/qemu/error-report.h
index e1c8ae1a52..72fab2b031 100644
--- a/include/qemu/error-report.h
+++ b/include/qemu/error-report.h
@@ -44,6 +44,38 @@ void error_report(const char *fmt, ...) GCC_FMT_ATTR(1, 2);
void warn_report(const char *fmt, ...) GCC_FMT_ATTR(1, 2);
void info_report(const char *fmt, ...) GCC_FMT_ATTR(1, 2);
+/*
+ * Similar to error_report(), except it prints the message just once.
+ * Return true when it prints, false otherwise.
+ */
+#define error_report_once(fmt, ...) \
+ ({ \
+ static bool print_once_; \
+ bool ret_print_once_ = !print_once_; \
+ \
+ if (!print_once_) { \
+ print_once_ = true; \
+ error_report(fmt, ##__VA_ARGS__); \
+ } \
+ unlikely(ret_print_once_); \
+ })
+
+/*
+ * Similar to warn_report(), except it prints the message just once.
+ * Return true when it prints, false otherwise.
+ */
+#define warn_report_once(fmt, ...) \
+ ({ \
+ static bool print_once_; \
+ bool ret_print_once_ = !print_once_; \
+ \
+ if (!print_once_) { \
+ print_once_ = true; \
+ warn_report(fmt, ##__VA_ARGS__); \
+ } \
+ unlikely(ret_print_once_); \
+ })
+
const char *error_get_progname(void);
extern bool enable_timestamp_msg;
--
2.17.1
next prev parent reply other threads:[~2018-08-27 6:14 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-08-27 6:07 [Qemu-devel] [PULL 0/3] Error reporting patches for 2018-08-27 Markus Armbruster
2018-08-27 6:07 ` Markus Armbruster [this message]
2018-08-27 6:07 ` [Qemu-devel] [PULL 2/3] intel-iommu: start to use error_report_once Markus Armbruster
2018-08-27 6:07 ` [Qemu-devel] [PULL 3/3] intel-iommu: replace more vtd_err_* traces Markus Armbruster
2018-08-27 11:30 ` [Qemu-devel] [PULL 0/3] Error reporting patches for 2018-08-27 Peter Maydell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180827060744.13770-2-armbru@redhat.com \
--to=armbru@redhat.com \
--cc=eblake@redhat.com \
--cc=peterx@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).