fix: global notifications shall use vCPU ID 0
Calls to FFA_NOTIFICATION_SET for global notifications
must always provide vCPU ID 0.
Signed-off-by: J-Alves <joao.alves@arm.com>
Change-Id: Ib63d88aafb60b7b1d91000aceb4de05be4a69722
diff --git a/src/api.c b/src/api.c
index c733bbf..f86067c 100644
--- a/src/api.c
+++ b/src/api.c
@@ -3883,6 +3883,14 @@
return ffa_error(FFA_INVALID_PARAMETERS);
}
+ /* Global notifications must target any vCPU. */
+ if (!is_per_vcpu && vcpu_id != 0U) {
+ dlog_verbose(
+ "For global notifications vCPU ID MBZ in call to set "
+ "notifications.\n");
+ return ffa_error(FFA_INVALID_PARAMETERS);
+ }
+
if (!plat_ffa_is_notification_set_valid(current, sender_vm_id,
receiver_vm_id)) {
dlog_verbose("Invalid use of notifications set interface.\n");
diff --git a/test/vmapi/ffa_secure_partitions/notifications.c b/test/vmapi/ffa_secure_partitions/notifications.c
index c2585b1..f0bcdb0 100644
--- a/test/vmapi/ffa_secure_partitions/notifications.c
+++ b/test/vmapi/ffa_secure_partitions/notifications.c
@@ -273,6 +273,30 @@
EXPECT_EQ(sp_resp_value(res), FFA_INVALID_PARAMETERS);
}
+/**
+ * Test that setting global notifications, specifying vCPU other than
+ * 0 fails with the appropriate error code.
+ */
+TEST(ffa_notifications, fail_if_global_notif_vcpu_not_zero)
+{
+ struct ffa_value res;
+ const ffa_id_t sender = SP_ID(1);
+ ffa_id_t own_id = hf_vm_get_id();
+
+ /* Arbitrarily bind notification. */
+ res = ffa_notification_bind(sender, own_id, 0,
+ FFA_NOTIFICATION_MASK(1));
+ EXPECT_EQ(res.func, FFA_SUCCESS_32);
+
+ /* Requesting sender to set notification. */
+ res = sp_notif_set_cmd_send(own_id, sender, own_id,
+ FFA_NOTIFICATIONS_FLAGS_VCPU_ID(5),
+ FFA_NOTIFICATION_MASK(1));
+ EXPECT_EQ(res.func, FFA_MSG_SEND_DIRECT_RESP_32);
+ EXPECT_EQ(sp_resp(res), SP_ERROR);
+ EXPECT_EQ(sp_resp_value(res), FFA_INVALID_PARAMETERS);
+}
+
TEST(ffa_notifications, fail_if_mbz_set_in_notifications_bind)
{
struct ffa_value res;