Skip to contentSkip to conversation

KVM: arm64: Add memory length checks and remove inline in do_ffa_mem_xfer

PATCH Applied Snehal Koukuntla 4 participants 8 messages Sep 9, 2024 – Sep 10, 2024

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 KVM: arm64: Add memory length checks and remove inline in do_ffa_mem_xfer

When we share memory through FF-A and the description of the buffers exceeds the size of the mapped buffer, the fragmentation API is used. The fragmentation API allows specifying chunks of descriptors in subsequent FF-A fragment calls and no upper limit has been established for this. The entire memory region transferred is identified by a handle which can be used to reclaim the transferred memory.
To be able to reclaim the memory, the description of the buffers has to fit in the ffa_desc_buf.
Add a bounds check on the FF-A sharing path to prevent the memory reclaim from failing.

Also do_ffa_mem_xfer() does not need __always_inline

Fixes 634d90cf0ac65 ("KVM: arm64: Handle FFA_MEM_LEND calls from the host")
---
 arch/arm64/kvm/hyp/nvhe/ffa.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
arch/arm64/kvm/hyp/nvhe/ffa.c +6 -1
index e715c157c2c4..637425f63fd1 100644
@@ -426,7 +426,7 @@ static void do_ffa_mem_frag_tx(struct arm_smccc_res *res,
 	return;
 }
 
-static __always_inline void do_ffa_mem_xfer(const u64 func_id,
+static void do_ffa_mem_xfer(const u64 func_id,
 					    struct arm_smccc_res *res,
 					    struct kvm_cpu_context *ctxt)
 {
@@ -461,6 +461,11 @@ static __always_inline void do_ffa_mem_xfer(const u64 func_id,
 		goto out_unlock;
 	}
 
+	if (len > ffa_desc_buf.len) {
+		ret = FFA_RET_NO_MEMORY;
+		goto out_unlock;
+	}
+
 	buf = hyp_buffers.tx;
 	memcpy(buf, host_buffers.tx, fraglen);
 
Signature · 1 line
2.46.0.598.g6f2099f65c-goog
Reviewed-by on v3 1/1
#1 lore raw

Hi Snehal,

Quoted 11 lines · Snehal Koukuntla

When we share memory through FF-A and the description of the buffers exceeds the size of the mapped buffer, the fragmentation API is used. The fragmentation API allows specifying chunks of descriptors in subsequent FF-A fragment calls and no upper limit has been established for this. The entire memory region transferred is identified by a handle which can be used to reclaim the transferred memory.
To be able to reclaim the memory, the description of the buffers has to fit in the ffa_desc_buf.
Add a bounds check on the FF-A sharing path to prevent the memory reclaim from failing.

Quoted 7 lines

Also do_ffa_mem_xfer() does not need __always_inline

Fixes 634d90cf0ac65 ("KVM: arm64: Handle FFA_MEM_LEND calls from the host")

---

Next time around, please include some notes on what's changed between versions and ideally a link to the last patch. It helps latecomers (i.e. me) get an idea of what's happening w/ a patch.

Quoted 17 lines
 arch/arm64/kvm/hyp/nvhe/ffa.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
arch/arm64/kvm/hyp/nvhe/ffa.c +1 -1
index e715c157c2c4..637425f63fd1 100644
@@ -426,7 +426,7 @@ static void do_ffa_mem_frag_tx(struct arm_smccc_res *res,
 	return;
 }
 
-static __always_inline void do_ffa_mem_xfer(const u64 func_id,
+static void do_ffa_mem_xfer(const u64 func_id,
 					    struct arm_smccc_res *res,
 					    struct kvm_cpu_context *ctxt)
 {

arch/arm64/kvm/hyp/nvhe/ffa.c static __always_inline void do_ffa_mem_xfer(const u64 func_id, · line 468

Quoted 8 lines
arch/arm64/kvm/hyp/nvhe/ffa.c +5 -0
@@ -461,6 +461,11 @@ static __always_inline void do_ffa_mem_xfer(const u64 func_id,
 		goto out_unlock;
 	}
 
+	if (len > ffa_desc_buf.len) {
+		ret = FFA_RET_NO_MEMORY;
+		goto out_unlock;
+	}
+

This check doesn't need to happen behind the host_buffers spinlock. Of course, keeping it behind the lock is benign, but this sort of thing prompts a reviewer to ask "why?"

Besides that,

Signature · 2 lines
Thanks,
Oliver
maintainer Applied
#2 lore raw
In reply to Snehal Koukuntla
Quoted 11 lines · Snehal Koukuntla

When we share memory through FF-A and the description of the buffers exceeds the size of the mapped buffer, the fragmentation API is used. The fragmentation API allows specifying chunks of descriptors in subsequent FF-A fragment calls and no upper limit has been established for this. The entire memory region transferred is identified by a handle which can be used to reclaim the transferred memory.
To be able to reclaim the memory, the description of the buffers has to fit in the ffa_desc_buf.
Add a bounds check on the FF-A sharing path to prevent the memory reclaim from failing.

Quoted 1 line

[...]

Applied to next, thanks!

[1/1] KVM: arm64: Add memory length checks and remove inline in do_ffa_mem_xfer

      commit: 39dacbeeee703d29140aca7bc2826d4b1936ecb6

Cheers,

	M.
Signature · 1 line
Without deviation from the norm, progress is not possible.
#3 lore raw
In reply to Snehal Koukuntla

Hi everyone,

Quoted 26 lines · Snehal Koukuntla

When we share memory through FF-A and the description of the buffers exceeds the size of the mapped buffer, the fragmentation API is used. The fragmentation API allows specifying chunks of descriptors in subsequent FF-A fragment calls and no upper limit has been established for this. The entire memory region transferred is identified by a handle which can be used to reclaim the transferred memory.
To be able to reclaim the memory, the description of the buffers has to fit in the ffa_desc_buf.
Add a bounds check on the FF-A sharing path to prevent the memory reclaim from failing.

Also do_ffa_mem_xfer() does not need __always_inline

Fixes 634d90cf0ac65 ("KVM: arm64: Handle FFA_MEM_LEND calls from the host")
---
 arch/arm64/kvm/hyp/nvhe/ffa.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
arch/arm64/kvm/hyp/nvhe/ffa.c +0 -0
index e715c157c2c4..637425f63fd1 100644

arch/arm64/kvm/hyp/nvhe/ffa.c static void do_ffa_mem_frag_tx(struct arm_smccc_res *res, · line 429

Quoted 5 lines
arch/arm64/kvm/hyp/nvhe/ffa.c +1 -1
@@ -426,7 +426,7 @@ static void do_ffa_mem_frag_tx(struct arm_smccc_res *res,
 	return;
 }
 
-static __always_inline void do_ffa_mem_xfer(const u64 func_id,
+static void do_ffa_mem_xfer(const u64 func_id,

I am seeing a compilation error because of this.

----- LOG START -----

$ clang --version 
clang version 18.1.8
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
$ make LLVM=1 ARCH=arm64 defconfig
$ make LLVM=1 ARCH=arm64 Image
...
arch/arm64/kvm/hyp/nvhe/ffa.c:443:2: error: call to '__compiletime_assert_776' declared with 'error' attribute: BUILD_BUG_ON failed: func_id != FFA_FN64_MEM_SHARE && func_id != FFA_FN64_MEM_LEND
  443 |         BUILD_BUG_ON(func_id != FFA_FN64_MEM_SHARE &&
      |         ^
./include/linux/build_bug.h:50:2: note: expanded from macro 'BUILD_BUG_ON'
   50 |         BUILD_BUG_ON_MSG(condition, "BUILD_BUG_ON failed: " #condition)
      |         ^
./include/linux/build_bug.h:39:37: note: expanded from macro 'BUILD_BUG_ON_MSG'
   39 | #define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg)
      |                                     ^
././include/linux/compiler_types.h:510:2: note: expanded from macro 'compiletime_assert'
  510 |         _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
      |         ^
././include/linux/compiler_types.h:498:2: note: expanded from macro '_compiletime_assert'
  498 |         __compiletime_assert(condition, msg, prefix, suffix)
      |         ^
././include/linux/compiler_types.h:491:4: note: expanded from macro '__compiletime_assert'
  491 |                         prefix ## suffix();                             \
      |                         ^
<scratch space>:66:1: note: expanded from here
   66 | __compiletime_assert_776
      | ^
1 error generated.
make[6]: *** [arch/arm64/kvm/hyp/nvhe/Makefile:46: arch/arm64/kvm/hyp/nvhe/ffa.nvhe.o] Error 1
make[5]: *** [scripts/Makefile.build:485: arch/arm64/kvm/hyp/nvhe] Error 2
make[4]: *** [scripts/Makefile.build:485: arch/arm64/kvm/hyp] Error 2
make[3]: *** [scripts/Makefile.build:485: arch/arm64/kvm] Error 2
make[3]: *** Waiting for unfinished jobs....
----- LOG END -----

Is this expected? Because when I add back the __always_inline, or change the BUILD_BUG_ON to BUG_ON, it compiles successfully.

Thanks,
Wei-Lin Chang

Quoted 18 lines
arch/arm64/kvm/hyp/nvhe/ffa.c +5 -0
 					    struct arm_smccc_res *res,
 					    struct kvm_cpu_context *ctxt)
 {
@@ -461,6 +461,11 @@ static __always_inline void do_ffa_mem_xfer(const u64 func_id,
 		goto out_unlock;
 	}
 
+	if (len > ffa_desc_buf.len) {
+		ret = FFA_RET_NO_MEMORY;
+		goto out_unlock;
+	}
+
 	buf = hyp_buffers.tx;
 	memcpy(buf, host_buffers.tx, fraglen);
 
Signature · 1 line
2.46.0.598.g6f2099f65c-goog
#4 lore raw
Quoted 32 lines · Wei-Lin Chang

Hi everyone,

Quoted 29 lines · Snehal Koukuntla

When we share memory through FF-A and the description of the buffers exceeds the size of the mapped buffer, the fragmentation API is used. The fragmentation API allows specifying chunks of descriptors in subsequent FF-A fragment calls and no upper limit has been established for this. The entire memory region transferred is identified by a handle which can be used to reclaim the transferred memory.
To be able to reclaim the memory, the description of the buffers has to fit in the ffa_desc_buf.
Add a bounds check on the FF-A sharing path to prevent the memory reclaim from failing.

Also do_ffa_mem_xfer() does not need __always_inline

Fixes 634d90cf0ac65 ("KVM: arm64: Handle FFA_MEM_LEND calls from the host")
---
 arch/arm64/kvm/hyp/nvhe/ffa.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
arch/arm64/kvm/hyp/nvhe/ffa.c +0 -0
index e715c157c2c4..637425f63fd1 100644
@@ -426,7 +426,7 @@ static void do_ffa_mem_frag_tx(struct arm_smccc_res *res,
 	return;
 }
 
Quoted 4 lines

arch/arm64/kvm/hyp/nvhe/ffa.c static void do_ffa_mem_frag_tx(struct arm_smccc_res *res, · line 429

Quoted 2 lines
arch/arm64/kvm/hyp/nvhe/ffa.c +1 -1
-static __always_inline void do_ffa_mem_xfer(const u64 func_id,
+static void do_ffa_mem_xfer(const u64 func_id,

I am seeing a compilation error because of this.

Thanks for reporting this. Looks like the __always_inline was slightly more load bearing...

Marc, can you put something like this on top?

From c2712eaa94989ae6457baad3ec459cf363ec5119 Mon Sep 17 00:00:00 2001
From: Oliver Upton <[email protected]>
Date: Tue, 10 Sep 2024 16:45:30 +0000
Subject: [PATCH] KVM: arm64: Drop BUILD_BUG_ON() from do_ffa_mem_xfer()

__always_inline was recently discarded from do_ffa_mem_xfer() since it appeared to be unnecessary. Of course, this was ~immediately proven wrong, as the compile-time check against @func_id depends on inlining for the value to be known.

Just downgrade to a WARN_ON() instead of putting the old mess back in place. Fix the wrapping/indentation of the function parameters while at it.

Fixes 39dacbeeee70 ("KVM: arm64: Add memory length checks and remove inline in do_ffa_mem_xfer")
---
 arch/arm64/kvm/hyp/nvhe/ffa.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
arch/arm64/kvm/hyp/nvhe/ffa.c +6 -5
index 637425f63fd1..316d269341f3 100644
@@ -426,9 +426,8 @@ static void do_ffa_mem_frag_tx(struct arm_smccc_res *res,
 	return;
 }
 
-static void do_ffa_mem_xfer(const u64 func_id,
-					    struct arm_smccc_res *res,
-					    struct kvm_cpu_context *ctxt)
+static void do_ffa_mem_xfer(const u64 func_id, struct arm_smccc_res *res,
+			    struct kvm_cpu_context *ctxt)
 {
 	DECLARE_REG(u32, len, ctxt, 1);
 	DECLARE_REG(u32, fraglen, ctxt, 2);
@@ -440,8 +439,10 @@ static void do_ffa_mem_xfer(const u64 func_id,
 	u32 offset, nr_ranges;
 	int ret = 0;
 
-	BUILD_BUG_ON(func_id != FFA_FN64_MEM_SHARE &&
-		     func_id != FFA_FN64_MEM_LEND);
+	if (WARN_ON(func_id != FFA_FN64_MEM_SHARE && func_id != FFA_FN64_MEM_LEND)) {
+		ret = SMCCC_RET_NOT_SUPPORTED;
+		goto out;
+	}
 
 	if (addr_mbz || npages_mbz || fraglen > len ||
 	    fraglen > KVM_FFA_MBOX_NR_PAGES * PAGE_SIZE) {
Signature · 6 lines
2.46.0.598.g6f2099f65c-goog


-- 
Thanks,
Oliver
maintainer
#5 lore raw
Quoted 83 lines · Oliver Upton
Quoted 32 lines · Wei-Lin Chang

Hi everyone,

Quoted 29 lines · Snehal Koukuntla

When we share memory through FF-A and the description of the buffers exceeds the size of the mapped buffer, the fragmentation API is used. The fragmentation API allows specifying chunks of descriptors in subsequent FF-A fragment calls and no upper limit has been established for this. The entire memory region transferred is identified by a handle which can be used to reclaim the transferred memory.
To be able to reclaim the memory, the description of the buffers has to fit in the ffa_desc_buf.
Add a bounds check on the FF-A sharing path to prevent the memory reclaim from failing.

Also do_ffa_mem_xfer() does not need __always_inline

Fixes 634d90cf0ac65 ("KVM: arm64: Handle FFA_MEM_LEND calls from the host")
---
 arch/arm64/kvm/hyp/nvhe/ffa.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
arch/arm64/kvm/hyp/nvhe/ffa.c +0 -0
index e715c157c2c4..637425f63fd1 100644
@@ -426,7 +426,7 @@ static void do_ffa_mem_frag_tx(struct arm_smccc_res *res,
 	return;
 }
 
Quoted 4 lines

arch/arm64/kvm/hyp/nvhe/ffa.c static void do_ffa_mem_frag_tx(struct arm_smccc_res *res, · line 429

Quoted 2 lines
arch/arm64/kvm/hyp/nvhe/ffa.c +1 -1
-static __always_inline void do_ffa_mem_xfer(const u64 func_id,
+static void do_ffa_mem_xfer(const u64 func_id,

I am seeing a compilation error because of this.

Thanks for reporting this. Looks like the __always_inline was slightly more load bearing...

Marc, can you put something like this on top?

From c2712eaa94989ae6457baad3ec459cf363ec5119 Mon Sep 17 00:00:00 2001
From: Oliver Upton <[email protected]>
Date: Tue, 10 Sep 2024 16:45:30 +0000
Subject: [PATCH] KVM: arm64: Drop BUILD_BUG_ON() from do_ffa_mem_xfer()

__always_inline was recently discarded from do_ffa_mem_xfer() since it appeared to be unnecessary. Of course, this was ~immediately proven wrong, as the compile-time check against @func_id depends on inlining for the value to be known.

Just downgrade to a WARN_ON() instead of putting the old mess back in place. Fix the wrapping/indentation of the function parameters while at it.

Fixes 39dacbeeee70 ("KVM: arm64: Add memory length checks and remove inline in do_ffa_mem_xfer")
---
 arch/arm64/kvm/hyp/nvhe/ffa.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
arch/arm64/kvm/hyp/nvhe/ffa.c +2 -3
index 637425f63fd1..316d269341f3 100644
@@ -426,9 +426,8 @@ static void do_ffa_mem_frag_tx(struct arm_smccc_res *res,
 	return;
 }
 
-static void do_ffa_mem_xfer(const u64 func_id,
-					    struct arm_smccc_res *res,
-					    struct kvm_cpu_context *ctxt)
+static void do_ffa_mem_xfer(const u64 func_id, struct arm_smccc_res *res,
+			    struct kvm_cpu_context *ctxt)
 {
 	DECLARE_REG(u32, len, ctxt, 1);
 	DECLARE_REG(u32, fraglen, ctxt, 2);

arch/arm64/kvm/hyp/nvhe/ffa.c static void do_ffa_mem_xfer(const u64 func_id, · line 445

Quoted 9 lines
arch/arm64/kvm/hyp/nvhe/ffa.c +4 -2
@@ -440,8 +439,10 @@ static void do_ffa_mem_xfer(const u64 func_id,
 	u32 offset, nr_ranges;
 	int ret = 0;
 
-	BUILD_BUG_ON(func_id != FFA_FN64_MEM_SHARE &&
-		     func_id != FFA_FN64_MEM_LEND);
+	if (WARN_ON(func_id != FFA_FN64_MEM_SHARE && func_id != FFA_FN64_MEM_LEND)) {
+		ret = SMCCC_RET_NOT_SUPPORTED;
+		goto out;
+	}

I'm not overly on the WARN_ON(), as it has pretty fatal effects on pKVM (it simply panics). What do you think of this instead, which compiles with my prehistoric version of clang (14.0.6):

arch/arm64/kvm/hyp/nvhe/ffa.c +10 -6
index 637425f63fd1b..e433dfab882aa 100644
@@ -426,9 +426,9 @@ static void do_ffa_mem_frag_tx(struct arm_smccc_res *res,
 	return;
 }
 
-static void do_ffa_mem_xfer(const u64 func_id,
-					    struct arm_smccc_res *res,
-					    struct kvm_cpu_context *ctxt)
+static void __do_ffa_mem_xfer(const u64 func_id,
+			      struct arm_smccc_res *res,
+			      struct kvm_cpu_context *ctxt)
 {
 	DECLARE_REG(u32, len, ctxt, 1);
 	DECLARE_REG(u32, fraglen, ctxt, 2);
@@ -440,9 +440,6 @@ static void do_ffa_mem_xfer(const u64 func_id,
 	u32 offset, nr_ranges;
 	int ret = 0;
 
-	BUILD_BUG_ON(func_id != FFA_FN64_MEM_SHARE &&
-		     func_id != FFA_FN64_MEM_LEND);
-
 	if (addr_mbz || npages_mbz || fraglen > len ||
 	    fraglen > KVM_FFA_MBOX_NR_PAGES * PAGE_SIZE) {
 		ret = FFA_RET_INVALID_PARAMETERS;
@@ -517,6 +514,13 @@ static void do_ffa_mem_xfer(const u64 func_id,
 	goto out_unlock;
 }
 
+#define do_ffa_mem_xfer(fid, res, ctxt)				\
+	do {							\
+		BUILD_BUG_ON((fid) != FFA_FN64_MEM_SHARE &&	\
+			     (fid) != FFA_FN64_MEM_LEND);	\
+		__do_ffa_mem_xfer((fid), (res), (ctxt));	\
+	} while (0);
+
 static void do_ffa_mem_reclaim(struct arm_smccc_res *res,
 			       struct kvm_cpu_context *ctxt)
 {

It preserves the build-time assertion, which was the intention of the original author.

I can easily squash that in the original commit, avoiding the headache of backporting both patch to stable.

	M.
Signature · 1 line
Without deviation from the norm, progress is not possible.
Reviewed-by
#6 lore raw
Quoted 88 lines · Marc Zyngier
Quoted 86 lines · Oliver Upton
Quoted 32 lines · Wei-Lin Chang

Hi everyone,

Quoted 29 lines · Snehal Koukuntla

When we share memory through FF-A and the description of the buffers exceeds the size of the mapped buffer, the fragmentation API is used. The fragmentation API allows specifying chunks of descriptors in subsequent FF-A fragment calls and no upper limit has been established for this. The entire memory region transferred is identified by a handle which can be used to reclaim the transferred memory.
To be able to reclaim the memory, the description of the buffers has to fit in the ffa_desc_buf.
Add a bounds check on the FF-A sharing path to prevent the memory reclaim from failing.

Also do_ffa_mem_xfer() does not need __always_inline

Fixes 634d90cf0ac65 ("KVM: arm64: Handle FFA_MEM_LEND calls from the host")
---
 arch/arm64/kvm/hyp/nvhe/ffa.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
arch/arm64/kvm/hyp/nvhe/ffa.c +0 -0
index e715c157c2c4..637425f63fd1 100644
@@ -426,7 +426,7 @@ static void do_ffa_mem_frag_tx(struct arm_smccc_res *res,
 	return;
 }
 
Quoted 4 lines

arch/arm64/kvm/hyp/nvhe/ffa.c static void do_ffa_mem_frag_tx(struct arm_smccc_res *res, · line 429

Quoted 2 lines
arch/arm64/kvm/hyp/nvhe/ffa.c +1 -1
-static __always_inline void do_ffa_mem_xfer(const u64 func_id,
+static void do_ffa_mem_xfer(const u64 func_id,

I am seeing a compilation error because of this.

Thanks for reporting this. Looks like the __always_inline was slightly more load bearing...

Marc, can you put something like this on top?

From c2712eaa94989ae6457baad3ec459cf363ec5119 Mon Sep 17 00:00:00 2001
From: Oliver Upton <[email protected]>
Date: Tue, 10 Sep 2024 16:45:30 +0000
Subject: [PATCH] KVM: arm64: Drop BUILD_BUG_ON() from do_ffa_mem_xfer()

__always_inline was recently discarded from do_ffa_mem_xfer() since it appeared to be unnecessary. Of course, this was ~immediately proven wrong, as the compile-time check against @func_id depends on inlining for the value to be known.

Just downgrade to a WARN_ON() instead of putting the old mess back in place. Fix the wrapping/indentation of the function parameters while at it.

Fixes 39dacbeeee70 ("KVM: arm64: Add memory length checks and remove inline in do_ffa_mem_xfer")
---
 arch/arm64/kvm/hyp/nvhe/ffa.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
arch/arm64/kvm/hyp/nvhe/ffa.c +2 -3
index 637425f63fd1..316d269341f3 100644
@@ -426,9 +426,8 @@ static void do_ffa_mem_frag_tx(struct arm_smccc_res *res,
 	return;
 }
 
-static void do_ffa_mem_xfer(const u64 func_id,
-					    struct arm_smccc_res *res,
-					    struct kvm_cpu_context *ctxt)
+static void do_ffa_mem_xfer(const u64 func_id, struct arm_smccc_res *res,
+			    struct kvm_cpu_context *ctxt)
 {
 	DECLARE_REG(u32, len, ctxt, 1);
 	DECLARE_REG(u32, fraglen, ctxt, 2);
@@ -440,8 +439,10 @@ static void do_ffa_mem_xfer(const u64 func_id,
 	u32 offset, nr_ranges;
 	int ret = 0;
 
Quoted 10 lines

arch/arm64/kvm/hyp/nvhe/ffa.c static void do_ffa_mem_xfer(const u64 func_id, · line 445

Quoted 6 lines
arch/arm64/kvm/hyp/nvhe/ffa.c +4 -2
-	BUILD_BUG_ON(func_id != FFA_FN64_MEM_SHARE &&
-		     func_id != FFA_FN64_MEM_LEND);
+	if (WARN_ON(func_id != FFA_FN64_MEM_SHARE && func_id != FFA_FN64_MEM_LEND)) {
+		ret = SMCCC_RET_NOT_SUPPORTED;
+		goto out;
+	}

I'm not overly on the WARN_ON(), as it has pretty fatal effects on pKVM (it simply panics).

It's unexpected, what else are you wanting? :P

Quoted 2 lines

What do you think of this instead, which compiles with my prehistoric version of clang (14.0.6):

LGTM, macro expansion makes the relation a bit more obvious. Feel free to add:

Signature · 2 lines
Thanks,
Oliver
maintainer
#7 lore raw
In reply to Snehal Koukuntla
Quoted 11 lines · Snehal Koukuntla

When we share memory through FF-A and the description of the buffers exceeds the size of the mapped buffer, the fragmentation API is used. The fragmentation API allows specifying chunks of descriptors in subsequent FF-A fragment calls and no upper limit has been established for this. The entire memory region transferred is identified by a handle which can be used to reclaim the transferred memory.
To be able to reclaim the memory, the description of the buffers has to fit in the ffa_desc_buf.
Add a bounds check on the FF-A sharing path to prevent the memory reclaim from failing.

Quoted 1 line

[...]

Applied to next, with the BUILD_BUG_ON() issue fixed.

[1/1] KVM: arm64: Add memory length checks and remove inline in do_ffa_mem_xfer

      commit: f26a525b77e040d584e967369af1e018d2d59112

Cheers,

	M.
Signature · 1 line
Without deviation from the norm, progress is not possible.