el3_spmc: Set NS bit by default and clear it as needed

Bug: 284057071
Change-Id: I00966a552906ebbe2675b4352afe5e85387e5775
diff --git a/services/std_svc/spm/el3_spmc/spmc_shared_mem.c b/services/std_svc/spm/el3_spmc/spmc_shared_mem.c
index 5263c04..1629b5f 100644
--- a/services/std_svc/spm/el3_spmc/spmc_shared_mem.c
+++ b/services/std_svc/spm/el3_spmc/spmc_shared_mem.c
@@ -1085,6 +1085,9 @@
 
 	/* The full descriptor has been received, perform any final checks. */
 
+	/* Ensure the NS bit is set to 1 since we only allow non-secure senders. */
+	obj->desc.memory_region_attributes |= FFA_MEM_ATTR_NS_BIT;
+
 	ret = spmc_shmem_check_obj(obj, ffa_version);
 	if (ret != 0) {
 		goto err_bad_desc;
@@ -1327,29 +1330,23 @@
 }
 
 /**
- * spmc_ffa_mem_retrieve_set_ns_bit - Set the NS bit in the response descriptor
- *				      if the caller implements a version greater
- *				      than FF-A 1.0 or if they have requested
- *				      the functionality.
- *				      TODO: We are assuming that the caller is
- *				      an SP. To support retrieval from the
- *				      normal world this function will need to be
- *				      expanded accordingly.
+ * spmc_ffa_mem_retrieve_clear_ns_bit - Clear the NS bit in the response descriptor
+ *					if the caller implements a version smaller
+ *					than FF-A 1.1 and if they have not requested
+ *					the functionality.
+ *					TODO: We are assuming that the caller is
+ *					an SP. To support retrieval from the
+ *					normal world this function will need to be
+ *					expanded accordingly.
  * @resp:       Descriptor populated in callers RX buffer.
  * @sp_ctx:     Context of the calling SP.
  */
-void spmc_ffa_mem_retrieve_set_ns_bit(struct ffa_mtd *resp,
+void spmc_ffa_mem_retrieve_clear_ns_bit(struct ffa_mtd *resp,
 			 struct secure_partition_desc *sp_ctx)
 {
-	if (sp_ctx->ffa_version > MAKE_FFA_VERSION(1, 0) ||
-	    sp_ctx->ns_bit_requested) {
-		/*
-		 * Currently memory senders must reside in the normal
-		 * world, and we do not have the functionlaity to change
-		 * the state of memory dynamically. Therefore we can always set
-		 * the NS bit to 1.
-		 */
-		resp->memory_region_attributes |= FFA_MEM_ATTR_NS_BIT;
+	if (sp_ctx->ffa_version < MAKE_FFA_VERSION(1, 1) &&
+	    !sp_ctx->ns_bit_requested) {
+		resp->memory_region_attributes &= ~FFA_MEM_ATTR_NS_BIT;
 	}
 }
 
@@ -1613,8 +1610,8 @@
 		memcpy(resp, &obj->desc, copy_size);
 	}
 
-	/* Set the NS bit in the response if applicable. */
-	spmc_ffa_mem_retrieve_set_ns_bit(resp, sp_ctx);
+	/* Clear the NS bit in the response if applicable. */
+	spmc_ffa_mem_retrieve_clear_ns_bit(resp, sp_ctx);
 
 	spin_unlock(&spmc_shmem_obj_state.lock);
 	spin_unlock(&mbox->lock);