Re: [PATCH v5 2/9] scatterlist: Add a flag for the restricted memory

From: AngeloGioacchino Del Regno
Date: Thu May 16 2024 - 05:59:47 EST


Il 15/05/24 13:23, Yong Wu ha scritto:
Introduce a FLAG for the restricted memory which means the memory is
protected by TEE or hypervisor, then it's inaccessiable for kernel.

Currently we don't use sg_dma_unmark_restricted, thus this interface
has not been added.

Signed-off-by: Yong Wu <yong.wu@xxxxxxxxxxxx>
---
include/linux/scatterlist.h | 34 ++++++++++++++++++++++++++++++++++
1 file changed, 34 insertions(+)

diff --git a/include/linux/scatterlist.h b/include/linux/scatterlist.h
index 77df3d7b18a6..a6ad9018eca0 100644
--- a/include/linux/scatterlist.h
+++ b/include/linux/scatterlist.h
@@ -282,6 +282,7 @@ static inline void sg_unmark_end(struct scatterlist *sg)
#define SG_DMA_BUS_ADDRESS (1 << 0)
#define SG_DMA_SWIOTLB (1 << 1)
+#define SG_DMA_RESTRICTED (2 << 1)

I think you wanted to write (1 << 2) here :-)

Cheers,
Angelo

/**
* sg_dma_is_bus_address - Return whether a given segment was marked
@@ -352,6 +353,31 @@ static inline void sg_dma_mark_swiotlb(struct scatterlist *sg)
sg->dma_flags |= SG_DMA_SWIOTLB;
}
+/**
+ * sg_dma_mark_restricted - Mark the scatterlist for restricted buffer.
+ * @sg: SG entry
+ *
+ * Description:
+ * Marks a a scatterlist for the restricted buffer that may be inaccessiable
+ * in kernel if it is protected.
+ */
+static inline void sg_dma_mark_restricted(struct scatterlist *sg)
+{
+ sg->dma_flags |= SG_DMA_RESTRICTED;
+}
+
+/**
+ * sg_dma_is_restricted - Return whether the scatterlist was marked as restricted
+ * buffer.
+ * @sg: SG entry
+ *
+ * Description:
+ * Returns true if the scatterlist was marked as restricted buffer.
+ */
+static inline bool sg_dma_is_restricted(struct scatterlist *sg)
+{
+ return sg->dma_flags & SG_DMA_RESTRICTED;
+}
#else
static inline bool sg_dma_is_bus_address(struct scatterlist *sg)
@@ -372,6 +398,14 @@ static inline void sg_dma_mark_swiotlb(struct scatterlist *sg)
{
}
+static inline bool sg_dma_is_restricted(struct scatterlist *sg)
+{
+ return false;
+}
+
+static inline void sg_dma_mark_restrited(struct scatterlist *sg)
+{
+}
#endif /* CONFIG_NEED_SG_DMA_FLAGS */
/**