From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: Yang Weijiang <weijiang.yang@intel.com>,
Like Xu <like.xu@linux.intel.com>
Subject: [PULL 05/23] qdev-properties: Add a new macro with bitmask check for uint64_t property
Date: Mon, 16 May 2022 17:55:45 +0200 [thread overview]
Message-ID: <20220516155603.1234712-6-pbonzini@redhat.com> (raw)
In-Reply-To: <20220516155603.1234712-1-pbonzini@redhat.com>
From: Yang Weijiang <weijiang.yang@intel.com>
The DEFINE_PROP_UINT64_CHECKMASK maro applies certain mask check agaist
user-supplied property value, reject the value if it violates the bitmask.
Co-developed-by: Like Xu <like.xu@linux.intel.com>
Signed-off-by: Like Xu <like.xu@linux.intel.com>
Signed-off-by: Yang Weijiang <weijiang.yang@intel.com>
Message-Id: <20220215195258.29149-2-weijiang.yang@intel.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
hw/core/qdev-properties.c | 19 +++++++++++++++++++
include/hw/qdev-properties.h | 12 ++++++++++++
2 files changed, 31 insertions(+)
diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c
index c34aac6ebc..357b8761b5 100644
--- a/hw/core/qdev-properties.c
+++ b/hw/core/qdev-properties.c
@@ -428,6 +428,25 @@ const PropertyInfo qdev_prop_int64 = {
.set_default_value = qdev_propinfo_set_default_value_int,
};
+static void set_uint64_checkmask(Object *obj, Visitor *v, const char *name,
+ void *opaque, Error **errp)
+{
+ Property *prop = opaque;
+ uint64_t *ptr = object_field_prop_ptr(obj, prop);
+
+ visit_type_uint64(v, name, ptr, errp);
+ if (*ptr & ~prop->bitmask) {
+ error_setg(errp, "Property value for '%s' has bits outside mask '0x%" PRIx64 "'",
+ name, prop->bitmask);
+ }
+}
+
+const PropertyInfo qdev_prop_uint64_checkmask = {
+ .name = "uint64",
+ .get = get_uint64,
+ .set = set_uint64_checkmask,
+};
+
/* --- string --- */
static void release_string(Object *obj, const char *name, void *opaque)
diff --git a/include/hw/qdev-properties.h b/include/hw/qdev-properties.h
index f7925f67d0..e1df08876c 100644
--- a/include/hw/qdev-properties.h
+++ b/include/hw/qdev-properties.h
@@ -17,6 +17,7 @@ struct Property {
const PropertyInfo *info;
ptrdiff_t offset;
uint8_t bitnr;
+ uint64_t bitmask;
bool set_default;
union {
int64_t i;
@@ -54,6 +55,7 @@ extern const PropertyInfo qdev_prop_uint16;
extern const PropertyInfo qdev_prop_uint32;
extern const PropertyInfo qdev_prop_int32;
extern const PropertyInfo qdev_prop_uint64;
+extern const PropertyInfo qdev_prop_uint64_checkmask;
extern const PropertyInfo qdev_prop_int64;
extern const PropertyInfo qdev_prop_size;
extern const PropertyInfo qdev_prop_string;
@@ -103,6 +105,16 @@ extern const PropertyInfo qdev_prop_link;
.set_default = true, \
.defval.u = (bool)_defval)
+/**
+ * The DEFINE_PROP_UINT64_CHECKMASK macro checks a user-supplied value
+ * against corresponding bitmask, rejects the value if it violates.
+ * The default value is set in instance_init().
+ */
+#define DEFINE_PROP_UINT64_CHECKMASK(_name, _state, _field, _bitmask) \
+ DEFINE_PROP(_name, _state, _field, qdev_prop_uint64_checkmask, uint64_t, \
+ .bitmask = (_bitmask), \
+ .set_default = false)
+
#define PROP_ARRAY_LEN_PREFIX "len-"
/**
--
2.36.0
next prev parent reply other threads:[~2022-05-16 15:59 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-16 15:55 [PULL 00/23] Misc QEMU patches for 2022-05-16 Paolo Bonzini
2022-05-16 15:55 ` [PULL 01/23] WHPX: fixed TPR/CR8 translation issues affecting VM debugging Paolo Bonzini
2022-05-16 15:55 ` [PULL 02/23] qga-vss: Add auto generated headers to dependencies Paolo Bonzini
2022-05-16 15:55 ` [PULL 03/23] qga-vss: Use the proper operator to free memory Paolo Bonzini
2022-05-16 15:55 ` [PULL 04/23] i386/cpu: Remove the deprecated cpu model 'Icelake-Client' Paolo Bonzini
2022-05-16 15:55 ` Paolo Bonzini [this message]
2022-05-16 15:55 ` [PULL 06/23] target/i386: Add lbr-fmt vPMU option to support guest LBR Paolo Bonzini
2022-05-16 15:55 ` [PULL 07/23] target/i386: Add kvm_get_one_msr helper Paolo Bonzini
2022-05-16 15:55 ` [PULL 08/23] target/i386: Enable support for XSAVES based features Paolo Bonzini
2022-05-16 15:55 ` [PULL 09/23] target/i386: Add XSAVES support for Arch LBR Paolo Bonzini
2022-05-16 15:55 ` [PULL 10/23] target/i386: Add MSR access interface " Paolo Bonzini
2022-05-16 15:55 ` [PULL 11/23] target/i386: Enable Arch LBR migration states in vmstate Paolo Bonzini
2022-05-16 15:55 ` [PULL 12/23] target/i386: introduce helper to access supported CPUID Paolo Bonzini
2022-05-16 15:55 ` [PULL 13/23] target/i386: Support Arch LBR in CPUID enumeration Paolo Bonzini
2022-05-16 15:55 ` [PULL 14/23] crypto: make loaded property read-only Paolo Bonzini
2022-05-16 15:55 ` [PULL 15/23] rng: make opened " Paolo Bonzini
2022-05-16 15:55 ` [PULL 16/23] soundhw: remove ability to create multiple soundcards Paolo Bonzini
2022-05-16 15:55 ` [PULL 17/23] soundhw: extract soundhw help to a separate function Paolo Bonzini
2022-05-16 15:55 ` [PULL 18/23] soundhw: unify initialization for ISA and PCI soundhw Paolo Bonzini
2022-05-16 15:55 ` [PULL 19/23] soundhw: move help handling to vl.c Paolo Bonzini
2022-05-16 15:56 ` [PULL 20/23] introduce -audio as a replacement for -soundhw Paolo Bonzini
2022-05-16 15:56 ` [PULL 21/23] build: remove useless dependency Paolo Bonzini
2022-05-16 15:56 ` [PULL 22/23] configure: remove another dead variable Paolo Bonzini
2022-05-16 15:56 ` [PULL 23/23] configure: remove duplicate help messages Paolo Bonzini
2022-05-16 23:30 ` [PULL 00/23] Misc QEMU patches for 2022-05-16 Richard Henderson
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=20220516155603.1234712-6-pbonzini@redhat.com \
--to=pbonzini@redhat.com \
--cc=like.xu@linux.intel.com \
--cc=qemu-devel@nongnu.org \
--cc=weijiang.yang@intel.com \
/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).