fix(vmlib): Fix unaligned structure copy

ffa_memory_region_constituents use direct structure copy and does not
use memcpy. In case the pointer to the constituent structure is
unaligned, which is quiet often the case when the memory region
descriptors are being constructed, the structure copy can fail due to
alignment faults. This especially shows up when running EL0 host
applications with VHE, since SCTLR_A bit is set, causing alignment
faults. In the case of test VMs, alignment checking is not enabled by
default due to which the issue is not seen with current tests.
memcpy or memcpy_s is not used and a new helper function is created
since hafnium does not have memcpy, and the linux kernel does not have
memcpy_s.

Signed-off-by: Raghu Krishnamurthy <raghu.ncstate@gmail.com>
Change-Id: Ic5a0cc4c54a7c5b6d877b29cb255caf31f43f348
diff --git a/vmlib/ffa.c b/vmlib/ffa.c
index efa3193..984bf02 100644
--- a/vmlib/ffa.c
+++ b/vmlib/ffa.c
@@ -20,6 +20,15 @@
 #include "hf/std.h"
 #endif
 
+static void ffa_copy_memory_region_constituents(
+	struct ffa_memory_region_constituent *dest,
+	const struct ffa_memory_region_constituent *src)
+{
+	dest->address = src->address;
+	dest->page_count = src->page_count;
+	dest->reserved = 0;
+}
+
 /**
  * Initialises the header of the given `ffa_memory_region`, not including the
  * composite memory region offset.
@@ -116,8 +125,9 @@
 
 	for (i = 0; i < constituent_count; ++i) {
 		if (i < count_to_copy) {
-			composite_memory_region->constituents[i] =
-				constituents[i];
+			ffa_copy_memory_region_constituents(
+				&composite_memory_region->constituents[i],
+				&constituents[i]);
 		}
 		composite_memory_region->page_count +=
 			constituents[i].page_count;
@@ -288,7 +298,8 @@
 	}
 
 	for (i = 0; i < count_to_copy; ++i) {
-		fragment[i] = constituents[i];
+		ffa_copy_memory_region_constituents(&fragment[i],
+						    &constituents[i]);
 	}
 
 	if (fragment_length != NULL) {