[PATCH 2/5] ioeventfd: Add helper functions for reading and writing

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Add get_val() and set_val() to help getting and setting a natural
sized variable pointed by a void ptr.

Signed-off-by: Sasha Levin <levinsasha928@xxxxxxxxx>
---
 virt/kvm/eventfd.c |   57 ++++++++++++++++++++++++++++++++++++++-------------
 1 files changed, 42 insertions(+), 15 deletions(-)

diff --git a/virt/kvm/eventfd.c b/virt/kvm/eventfd.c
index 5fb09b4..a1a3f66 100644
--- a/virt/kvm/eventfd.c
+++ b/virt/kvm/eventfd.c
@@ -444,23 +444,10 @@ ioeventfd_release(struct _ioeventfd *p)
 	kfree(p);
 }
 
-static bool
-ioeventfd_in_range(struct _ioeventfd *p, gpa_t addr, int len, const void *val)
+static u64 get_val(const void *val, int len)
 {
 	u64 _val;
 
-	if (!((addr >= p->addr) && ((addr + len) <= (p->addr + p->length))))
-		/* the entire address-range must be within the ioeventfd */
-		return false;
-
-	if (p->wildcard)
-		/* all else equal, wildcard is always a hit */
-		return true;
-
-	/* otherwise, we have to actually compare the data */
-
-	BUG_ON(!IS_ALIGNED((unsigned long)val, len));
-
 	switch (len) {
 	case 1:
 		_val = *(u8 *)val;
@@ -475,8 +462,48 @@ ioeventfd_in_range(struct _ioeventfd *p, gpa_t addr, int len, const void *val)
 		_val = *(u64 *)val;
 		break;
 	default:
-		return false;
+		return 0;
+	}
+
+	return _val;
+}
+
+static void set_val(void *val, int len, u64 new_val)
+{
+	switch (len) {
+	case 1:
+		*(u8 *)val = new_val;
+		break;
+	case 2:
+		*(u16 *)val = new_val;
+		break;
+	case 4:
+		*(u32 *)val = new_val;
+		break;
+	case 8:
+		*(u64 *)val = new_val;
+		break;
 	}
+}
+
+static bool
+ioeventfd_in_range(struct _ioeventfd *p, gpa_t addr, int len, const void *val)
+{
+	u64 _val;
+
+	if (!((addr >= p->addr) && ((addr + len) <= (p->addr + p->length))))
+		/* the entire address-range must be within the ioeventfd */
+		return false;
+
+	if (p->wildcard)
+		/* all else equal, wildcard is always a hit */
+		return true;
+
+	/* otherwise, we have to actually compare the data */
+
+	BUG_ON(!IS_ALIGNED((unsigned long)val, len));
+
+	_val = get_val(val, len);
 
 	return _val == p->datamatch ? true : false;
 }
-- 
1.7.6

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux