dma-buf: heaps: Add Tegra VPR support
Subsystems (11)
cover dma-buf: heaps: Add Tegra VPR support
From: Thierry Reding <[email protected]>
Hi,
This series adds support for the video protection region (VPR) used on Tegra SoC devices. It's a special region of memory that is protected from accesses by the CPU and used to store DRM protected content (both decrypted stream data as well as decoded video frames).
Patches 1 and 2 add DT binding documentation for the VPR and add the VPR to the list of memory-region items for display and host1x.
Patch 3 introduces new APIs needed by the Tegra VPR implementation that allow CMA areas to be dynamically created at runtime rather than using the fixed, system-wide list. This is used in this driver specifically because it can use an arbitrary number of these areas (though they are currently limited to 4).
Patch 4 adds some infrastructure for DMA heap implementations to provide information through debugfs.
The Tegra VPR implementation is added in patch 5. See its commit message for more details about the specifics of this implementation.
Finally, patches 6-9 add the VPR placeholder node on Tegra234 and hook it up to the host1x and GPU nodes so that they can make use of this region.
Thierry
Thierry Reding (9):
dt-bindings: reserved-memory: Document Tegra VPR
dt-bindings: display: tegra: Document memory regions mm/cma: Allow dynamically creating CMA areas
dma-buf: heaps: Add debugfs support
dma-buf: heaps: Add support for Tegra VPR
arm64: tegra: Add VPR placeholder node on Tegra234
arm64: tegra: Add GPU node on Tegra234
arm64: tegra: Hook up VPR to host1x
arm64: tegra: Hook up VPR to the GPU
.../display/tegra/nvidia,tegra186-dc.yaml | 10 + .../display/tegra/nvidia,tegra20-dc.yaml | 10 +- .../display/tegra/nvidia,tegra20-host1x.yaml | 7 + .../nvidia,tegra-video-protection-region.yaml | 55 ++ arch/arm64/boot/dts/nvidia/tegra234.dtsi | 57 ++ drivers/dma-buf/dma-heap.c | 56 ++ drivers/dma-buf/heaps/Kconfig | 7 + drivers/dma-buf/heaps/Makefile | 1 + drivers/dma-buf/heaps/tegra-vpr.c | 831 ++++++++++++++++++ include/linux/cma.h | 16 + include/linux/dma-heap.h | 2 + include/trace/events/tegra_vpr.h | 57 ++ mm/cma.c | 89 +- 13 files changed, 1175 insertions(+), 23 deletions(-) create mode 100644 Documentation/devicetree/bindings/reserved-memory/nvidia,tegra-video-protection-region.yaml create mode 100644 drivers/dma-buf/heaps/tegra-vpr.c create mode 100644 include/trace/events/tegra_vpr.h
Signature · 1 line
2.50.0
PATCH 1/9 dt-bindings: reserved-memory: Document Tegra VPR
From: Thierry Reding <[email protected]>
The Video Protection Region (VPR) found on NVIDIA Tegra chips is a region of memory that is protected from CPU accesses. It is used to decode and play back DRM protected content.
It is a standard reserved memory region that can exist in two forms:
static VPR where the base address and size are fixed (uses the "reg" property to describe the memory) and a resizable VPR where only the size is known upfront and the OS can allocate it wherever it can be accomodated.
--- .../nvidia,tegra-video-protection-region.yaml | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 Documentation/devicetree/bindings/reserved-memory/nvidia,tegra-video-protection-region.yaml
Documentation/devicetree/bindings/reserved-memory/nvidia,tegra-video-protection-region.yaml new file +55 -0
@@ -0,0 +1,55 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/reserved-memory/nvidia,tegra-video-protection-region.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: NVIDIA Tegra Video Protection Region (VPR) + +maintainers: + - Thierry Reding <[email protected]> + - Jon Hunter <[email protected]> + +description: | + NVIDIA Tegra chips have long supported a mechanism to protect a single, + contiguous memory region from non-secure memory accesses. Typically this + region is used for decoding and playback of DRM protected content. Various + devices, such as the display controller and multimedia engines (video + decoder) can access this region in a secure way. Access from the CPU is + generally forbidden. + + Two variants exist for VPR: one is fixed in both the base address and size, + while the other is resizable. Fixed VPR can be described by just a "reg" + property specifying the base address and size, whereas the resizable VPR + is defined by a size/alignment pair of properties. For resizable VPR the + memory is reusable by the rest of the system when it's unused for VPR and + therefore the "reusable" property must be specified along with it. For a + fixed VPR, the memory is permanently protected, and therefore it's not + reusable and must also be marked as "no-map" to prevent any (including + speculative) accesses to it. + +allOf: + - $ref: reserved-memory.yaml + +properties: + compatible: + const: nvidia,tegra-video-protection-region + +dependencies: + size: [alignment, reusable] + alignment: [size, reusable] + reusable: [alignment, size] + + reg: [no-map] + no-map: [reg] + +unevaluatedProperties: false + +oneOf: + - required: + - compatible + - reg + + - required: + - compatible + - size
Signature · 1 line
2.50.0
Re: [PATCH 1/9] dt-bindings: reserved-memory: Document Tegra VPR
Quoted 12 lines · Thierry Reding
From: Thierry Reding <[email protected]>
The Video Protection Region (VPR) found on NVIDIA Tegra chips is a region of memory that is protected from CPU accesses. It is used to decode and play back DRM protected content.
It is a standard reserved memory region that can exist in two forms:
static VPR where the base address and size are fixed (uses the "reg" property to describe the memory) and a resizable VPR where only the size is known upfront and the OS can allocate it wherever it can be accomodated.
Quoted 6 lines
Signed-off-by Thierry Reding <[email protected]>--- .../nvidia,tegra-video-protection-region.yaml | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 Documentation/devicetree/bindings/reserved-memory/nvidia,tegra-video-protection-region.yaml
PATCH 2/9 dt-bindings: display: tegra: Document memory regions
In reply to Thierry RedingFrom: Thierry Reding <[email protected]>
Add the memory-region and memory-region-names properties to the bindings for the display controllers and the host1x engine found on various Tegra generations. These memory regions are used to access firmware-provided framebuffer memory as well as the video protection region.
--- .../bindings/display/tegra/nvidia,tegra186-dc.yaml | 10 ++++++++++ .../bindings/display/tegra/nvidia,tegra20-dc.yaml | 10 +++++++++- .../bindings/display/tegra/nvidia,tegra20-host1x.yaml | 7 +++++++ 3 files changed, 26 insertions(+), 1 deletion(-)
Documentation/devicetree/bindings/display/tegra/nvidia,tegra186-dc.yaml +10 -0
@@ -57,6 +57,16 @@ properties: - const: dma-mem # read-0 - const: read-1 + memory-region: + minItems: 1 + maxItems: 2 + + memory-region-names: + items: + enum: [ framebuffer, protected ] + minItems: 1 + maxItems: 2 + nvidia,outputs: description: A list of phandles of outputs that this display controller can drive.
Documentation/devicetree/bindings/display/tegra/nvidia,tegra20-dc.yaml +9 -1
@@ -65,7 +65,15 @@ properties: items: - description: phandle to the core power domain - memory-region: true + memory-region: + minItems: 1 + maxItems: 2 + + memory-region-names: + items: + enum: [ framebuffer, protected ] + minItems: 1 + maxitems: 2 nvidia,head: $ref: /schemas/types.yaml#/definitions/uint32
Documentation/devicetree/bindings/display/tegra/nvidia,tegra20-host1x.yaml +7 -0
@@ -96,6 +96,13 @@ properties: items: - description: phandle to the HEG or core power domain + memory-region: + maxItems: 1 + + memory-region-names: + items: + - const: protected + required: - compatible - interrupts
Signature · 1 line
2.50.0
PATCH 3/9 mm/cma: Allow dynamically creating CMA areas
In reply to Thierry RedingFrom: Thierry Reding <[email protected]>
There is no technical reason why there should be a limited number of CMA regions, so extract some code into helpers and use them to create extra functions (cma_create() and cma_free()) that allow creating and freeing, respectively, CMA regions dynamically at runtime.
Note that these dynamically created CMA areas are treated specially and do not contribute to the number of total CMA pages so that this count still only applies to the fixed number of CMA areas.
--- include/linux/cma.h | 16 ++++++++ mm/cma.c | 89 ++++++++++++++++++++++++++++++++++----------- 2 files changed, 83 insertions(+), 22 deletions(-)
include/linux/cma.h +16 -0
@@ -61,6 +61,10 @@ extern void cma_reserve_pages_on_error(struct cma *cma);struct folio *cma_alloc_folio (struct cma *cma,int order,gfp_t gfp);bool cma_free_folio (struct cma *cma,const struct folio *folio);bool cma_validate_zones (struct cma *cma); + +struct cma *cma_create (phys_addr_t base,phys_addr_t size, +unsigned int order_per_bit,const char *name); +void cma_free (struct cma *cma);#else static inline struct folio *cma_alloc_folio (struct cma *cma,int order,gfp_t gfp) {
@@ -71,10 +75,22 @@ static inline bool cma_free_folio(struct cma *cma, const struct folio *folio) {return false; } +static inline bool cma_validate_zones (struct cma *cma) {return false; } + +static inline struct cma *cma_create (phys_addr_t base,phys_addr_t size, +unsigned int order_per_bit, +const char *name) +{ +return NULL ; +} + +static inline void cma_free (struct cma *cma) +{ +}#endif #endif
mm/cma.c +67 -22
117 lines not on this page · raw message
Signature · 1 line
2.50.0
Re: [PATCH 3/9] mm/cma: Allow dynamically creating CMA areas
Quoted 183 lines · Thierry Reding
From: Thierry Reding <[email protected]>
There is no technical reason why there should be a limited number of CMA regions, so extract some code into helpers and use them to create extra functions (
cma_create()andcma_free()) that allow creating and freeing, respectively, CMA regions dynamically at runtime.Note that these dynamically created CMA areas are treated specially and do not contribute to the number of total CMA pages so that this count still only applies to the fixed number of CMA areas.
Signed-off-by Thierry Reding <[email protected]>--- include/linux/cma.h | 16 ++++++++ mm/cma.c | 89 ++++++++++++++++++++++++++++++++++----------- 2 files changed, 83 insertions(+), 22 deletions(-)include/linux/cma.h +16
-0@@ -61,6 +61,10 @@ extern void cma_reserve_pages_on_error(struct cma *cma);struct folio *cma_alloc_folio (struct cma *cma,int order,gfp_t gfp);bool cma_free_folio (struct cma *cma,const struct folio *folio);bool cma_validate_zones (struct cma *cma); + +struct cma *cma_create (phys_addr_t base,phys_addr_t size, +unsigned int order_per_bit,const char *name); +void cma_free (struct cma *cma);#else static inline struct folio *cma_alloc_folio (struct cma *cma,int order,gfp_t gfp) {@@ -71,10 +75,22 @@ static inline bool cma_free_folio(struct cma *cma, const struct folio *folio) {return false; } +static inline bool cma_validate_zones (struct cma *cma) {return false; } + +static inline struct cma *cma_create (phys_addr_t base,phys_addr_t size, +unsigned int order_per_bit, +const char *name) +{ +return NULL ; +} + +static inline void cma_free (struct cma *cma) +{ +}#endif #endif mm/cma.c +67
-23@@ -214,6 +214,18 @@ void __init cma_reserve_pages_on_error(struct cma *cma)set_bit (CMA_RESERVE_PAGES_ON_ERROR , &cma->flags); } +static void __init cma_init_area (struct cma *cma,const char *name, +phys_addr_t size,unsigned int order_per_bit) +{ +if (name) +snprintf (cma->name,CMA_MAX_NAME ,"%s" , name); +else +snprintf (cma->name,CMA_MAX_NAME ,"cma%d\n" , cma_area_count); + + cma->available_count = cma->count = size >>PAGE_SHIFT ; + cma->order_per_bit = order_per_bit; +} +static int __init cma_new_area (const char *name,phys_addr_t size,unsigned int order_per_bit,struct cma **res_cma)@@ -232,13 +244,8 @@ static int __init cma_new_area(const char *name, phys_addr_t size, cma = &cma_areas[cma_area_count]; cma_area_count++; -if (name) -snprintf (cma->name,CMA_MAX_NAME ,"%s" , name); -else -snprintf (cma->name,CMA_MAX_NAME ,"cma%d\n" , cma_area_count); +cma_init_area (cma, name, size, order_per_bit); - cma->available_count = cma->count = size >>PAGE_SHIFT ; - cma->order_per_bit = order_per_bit; *res_cma = cma; totalcma_pages += cma->count;@@ -251,6 +258,27 @@ static void __init cma_drop_area(struct cma *cma) cma_area_count--; } +static int __init cma_check_memory (phys_addr_t base,phys_addr_t size) +{ +if (!size || !memblock_is_region_reserved (base, size)) +return -EINVAL ; + +/* +* CMA uses CMA_MIN_ALIGNMENT_BYTES as alignment requirement which +* needs pageblock_order to be initialized. Let's enforce it. +*/ +if (!pageblock_order) { +pr_err ("pageblock_order not yet initialized. Called during early boot?\n" ); +return -EINVAL ; + } + +/* ensure minimal alignment required by mm core */ +if (!IS_ALIGNED (base | size,CMA_MIN_ALIGNMENT_BYTES )) +return -EINVAL ; + +return 0 ; +} +/** * cma_init_reserved_mem() - create custom contiguous area from reserved memory * @base: Base address of the reserved area @@ -271,22 +299,9 @@ int __init cma_init_reserved_mem(phys_addr_t base, phys_addr_t size,struct cma *cma;int ret; -/* Sanity checks */ -if (!size || !memblock_is_region_reserved (base, size)) -return -EINVAL ; - -/* -* CMA uses CMA_MIN_ALIGNMENT_BYTES as alignment requirement which -* needs pageblock_order to be initialized. Let's enforce it. -*/ -if (!pageblock_order) { -pr_err ("pageblock_order not yet initialized. Called during early boot?\n" ); -return -EINVAL ; - } - -/* ensure minimal alignment required by mm core */ -if (!IS_ALIGNED (base | size,CMA_MIN_ALIGNMENT_BYTES )) -return -EINVAL ; + ret =cma_check_memory (base, size); +if (ret <0 ) +return ret; ret =cma_new_area (name, size, order_per_bit, &cma);if (ret !=0 )@@ -1112,3 +1127,33 @@ void __init *cma_reserve_early(struct cma *cma, unsigned long size)return ret; } + +struct cma *__init cma_create (phys_addr_t base,phys_addr_t size, +unsigned int order_per_bit,const char *name) +{ +struct cma *cma; +int ret; + + ret =cma_check_memory (base, size); +if (ret <0 ) +return ERR_PTR (ret); + + cma =kzalloc (sizeof (*cma),GFP_KERNEL ); +if (!cma) +return ERR_PTR (-ENOMEM ); + +cma_init_area (cma, name, size, order_per_bit); + cma->ranges[0 ].base_pfn =PFN_DOWN (base); + cma->ranges[0 ].early_pfn =PFN_DOWN (base); + cma->ranges[0 ].count = cma->count; + cma->nranges =1 ; + +cma_activate_area (cma); + +return cma; +} + +void cma_free (struct cma *cma) +{ +kfree (cma); +} --
Quoted 1 line
2.50.0
I agree that supporting dynamic CMA areas would be good. However, by doing it like this, these CMA areas are invisible to the rest of the system. E.g. cma_for_each_area() does not know about them. It seems a bit inconsistent that there will now be some areas that are globally known, and some that are not.
I am being somewhat selfish here, as I have some WIP code that needs the global list :-) But I think the inconsistency is a more general point than just what I want (and the s390 code does use cma_for_each_area()). Maybe you could keep maintaining a global structure containing all areas? What do you think are the chances of running out of the global count of areas?
Also, you say that "these are treated specially and do not contribute to the number of total CMA pages". But, if I'm reading this right, you do call cma_activate_area(), which will do init_cma_reserved_pageblock() for each pageblock in it. Which adjusts the CMA counters for the zone they are in. But your change does not adjust totalcma_pages for dynamically created areas. That seems inconsistent, too.
- Frank
Re: [PATCH 3/9] mm/cma: Allow dynamically creating CMA areas
Quoted 31 lines
Quoted 31 lines
+>> +struct cma
*__initcma_create(phys_addr_t base,phys_addr_tsize,mm/cma.c +28
-1+ unsigned int order_per_bit, const char *name) +{ + struct cma *cma; +int ret; + + ret =cma_check_memory (base, size); +if (ret <0 ) +return ERR_PTR (ret); + + cma =kzalloc (sizeof (*cma),GFP_KERNEL ); +if (!cma) +return ERR_PTR (-ENOMEM ); + +cma_init_area (cma, name, size, order_per_bit); + cma->ranges[0 ].base_pfn =PFN_DOWN (base); + cma->ranges[0 ].early_pfn =PFN_DOWN (base); + cma->ranges[0 ].count = cma->count; + cma->nranges =1 ; + +cma_activate_area (cma); + +return cma; +} + +void cma_free (struct cma *cma) +{ +kfree (cma); +} --
Quoted 8 lines
Quoted 1 line
2.50.0
I agree that supporting dynamic CMA areas would be good. However, by doing it like this, these CMA areas are invisible to the rest of the system. E.g.
cma_for_each_area()does not know about them. It seems a bit inconsistent that there will now be some areas that are globally known, and some that are not.
Yeah, I'm not a fan of that.
What is the big problem we are trying to solve here? Why do they have to be dynamic, why do they even have to support freeing?
Signature · 3 lines
Cheers David / dhildenb
Re: [PATCH 3/9] mm/cma: Allow dynamically creating CMA areas
Quoted 40 lines · David Hildenbrand
Quoted 31 lines
Quoted 31 lines
+>> +struct cma
*__initcma_create(phys_addr_t base,phys_addr_tsize,mm/cma.c +28
-1+ unsigned int order_per_bit, const char *name) +{ + struct cma *cma; +int ret; + + ret =cma_check_memory (base, size); +if (ret <0 ) +return ERR_PTR (ret); + + cma =kzalloc (sizeof (*cma),GFP_KERNEL ); +if (!cma) +return ERR_PTR (-ENOMEM ); + +cma_init_area (cma, name, size, order_per_bit); + cma->ranges[0 ].base_pfn =PFN_DOWN (base); + cma->ranges[0 ].early_pfn =PFN_DOWN (base); + cma->ranges[0 ].count = cma->count; + cma->nranges =1 ; + +cma_activate_area (cma); + +return cma; +} + +void cma_free (struct cma *cma) +{ +kfree (cma); +} --Quoted 8 lines
Quoted 1 line
2.50.0
I agree that supporting dynamic CMA areas would be good. However, by doing it like this, these CMA areas are invisible to the rest of the system. E.g.
cma_for_each_area()does not know about them. It seems a bit inconsistent that there will now be some areas that are globally known, and some that are not.
Quoted 4 lines
Yeah, I'm not a fan of that.
What is the big problem we are trying to solve here? Why do they have to be dynamic, why do they even have to support freeing?
Freeing isn't necessarily something that I've needed. It just seemed like there wasn't really a good reason not to support it. The current implementation here is not sufficient, though, because we'd need to properly undo everything that cma_activate_area() does. I think the
cleanup: block in cma_activate_area() is probably sufficient.
The problem that I'm trying to solve is that currently, depending on the use-case the kernel configuration needs to be changed and the kernel rebuilt in order to support it. However there doesn't seem to be a good technical reason for that limitation. The only reason it is this way seems to be that, well, it's always been this way.
Thierry
Re: [PATCH 3/9] mm/cma: Allow dynamically creating CMA areas
Quoted 52 lines · Thierry Reding
Quoted 40 lines · David Hildenbrand
Quoted 31 lines
Quoted 31 lines
+>> +struct cma
*__initcma_create(phys_addr_t base,phys_addr_tsize,mm/cma.c +28
-1+ unsigned int order_per_bit, const char *name) +{ + struct cma *cma; +int ret; + + ret =cma_check_memory (base, size); +if (ret <0 ) +return ERR_PTR (ret); + + cma =kzalloc (sizeof (*cma),GFP_KERNEL ); +if (!cma) +return ERR_PTR (-ENOMEM ); + +cma_init_area (cma, name, size, order_per_bit); + cma->ranges[0 ].base_pfn =PFN_DOWN (base); + cma->ranges[0 ].early_pfn =PFN_DOWN (base); + cma->ranges[0 ].count = cma->count; + cma->nranges =1 ; + +cma_activate_area (cma); + +return cma; +} + +void cma_free (struct cma *cma) +{ +kfree (cma); +} --Quoted 8 lines
Quoted 1 line
2.50.0
I agree that supporting dynamic CMA areas would be good. However, by doing it like this, these CMA areas are invisible to the rest of the system. E.g.
cma_for_each_area()does not know about them. It seems a bit inconsistent that there will now be some areas that are globally known, and some that are not.Quoted 4 lines
Yeah, I'm not a fan of that.
What is the big problem we are trying to solve here? Why do they have to be dynamic, why do they even have to support freeing?
Freeing isn't necessarily something that I've needed. It just seemed like there wasn't really a good reason not to support it. The current implementation here is not sufficient, though, because we'd need to properly undo everything that
cma_activate_area()does. I think the
cleanup: block incma_activate_area()is probably sufficient.
Quoted 5 lines
The problem that I'm trying to solve is that currently, depending on the use-case the kernel configuration needs to be changed and the kernel rebuilt in order to support it. However there doesn't seem to be a good technical reason for that limitation. The only reason it is this way seems to be that, well, it's always been this way.
Right, and we can just dynamically grow the array, keep them in a list etc.
Signature · 3 lines
Cheers David / dhildenb
Re: [PATCH 3/9] mm/cma: Allow dynamically creating CMA areas
In reply to Frank van der LindenQuoted 18 lines · Frank van der Linden
Quoted 17 lines · Thierry Reding
From: Thierry Reding <[email protected]>
There is no technical reason why there should be a limited number of CMA regions, so extract some code into helpers and use them to create extra functions (
cma_create()andcma_free()) that allow creating and freeing, respectively, CMA regions dynamically at runtime.Note that these dynamically created CMA areas are treated specially and do not contribute to the number of total CMA pages so that this count still only applies to the fixed number of CMA areas.
Signed-off-by Thierry Reding <[email protected]>--- include/linux/cma.h | 16 ++++++++ mm/cma.c | 89 ++++++++++++++++++++++++++++++++++----------- 2 files changed, 83 insertions(+), 22 deletions(-)
[...]
Quoted 5 lines
I agree that supporting dynamic CMA areas would be good. However, by doing it like this, these CMA areas are invisible to the rest of the system. E.g.
cma_for_each_area()does not know about them. It seems a bit inconsistent that there will now be some areas that are globally known, and some that are not.
That was kind of the point of this experiment. When I started on this I ran into the case where I was running out of predefined CMA areas and as I went looking for ways on how to fix this, I realized that there's not much reason to keep a global list of these areas. And even less reason to limit the number of CMA areas to this predefined list. Very little code outside of the core CMA code even uses this.
There's one instance of cma_for_each_area() that I don't grok. There's another early MMU fixup for CMA areas in 32-bit ARM that. Other than that there's a few places where the total CMA page count is shown for informational purposes and I don't know how useful that really is because totalcma_pages doesn't really track how many pages are used for CMA, but pages that could potentially be used for CMA.
And that's about it.
It seems like there are cases where we might really need to globally know about some of these areas, specifically ones that are allocated very early during boot and then used for very specific purposes.
However, it seems to me like CMA is more universally useful than just for these cases and I don't see the usefulness of tracking these more generic uses.
Quoted 5 lines
I am being somewhat selfish here, as I have some WIP code that needs the global list :-) But I think the inconsistency is a more general point than just what I want (and the s390 code does use
cma_for_each_area()). Maybe you could keep maintaining a global structure containing all areas?
If it's really useful to be able to access all CMA areas, then we could easily just add them all to a global linked list upon activation (we may still want/need to keep the predefined list around for all those early allocation cases). That way we'd get the best of both worlds.
Quoted 2 lines
What do you think are the chances of running out of the global count of areas?
Well, I did run out of CMA areas during the early VPR testing because I was initially testing with 16 areas and a different allocation scheme that turned out to cause too many resizes in common cases.
However, given that the default is 8 on normal systems (20 on NUMA) and is configurable, it means that even with restricting this to 4 for VPR doesn't always guarantee that all 4 are available. Again, yes, we could keep bumping that number, but why not turn this into something a bit more robust where nobody has to know or care about how many there are?
Quoted 7 lines
Also, you say that "these are treated specially and do not contribute to the number of total CMA pages". But, if I'm reading this right, you do call
cma_activate_area(), which will doinit_cma_reserved_pageblock()for each pageblock in it. Which adjusts the CMA counters for the zone they are in. But your change does not adjusttotalcma_pagesfor dynamically created areas. That seems inconsistent, too.
I was referring to just totalcma_pages that isn't impacted by these dynamically allocated regions. This is, again, because I don't see why that information would be useful. It's a fairly easy change to update that value, so if people prefer that, I can add that.
I don't see an immediate connection between totalcma_pages and init_cma_reserved_pageblock(). I thought the latter was primarily useful for making sure that the CMA pages can be migrated, which is still critical for this use-case.
Thierry
Re: [PATCH 3/9] mm/cma: Allow dynamically creating CMA areas
Quoted 88 lines · Thierry Reding
Quoted 18 lines · Frank van der Linden
Quoted 17 lines · Thierry Reding
From: Thierry Reding <[email protected]>
There is no technical reason why there should be a limited number of CMA regions, so extract some code into helpers and use them to create extra functions (
cma_create()andcma_free()) that allow creating and freeing, respectively, CMA regions dynamically at runtime.Note that these dynamically created CMA areas are treated specially and do not contribute to the number of total CMA pages so that this count still only applies to the fixed number of CMA areas.
Signed-off-by Thierry Reding <[email protected]>--- include/linux/cma.h | 16 ++++++++ mm/cma.c | 89 ++++++++++++++++++++++++++++++++++----------- 2 files changed, 83 insertions(+), 22 deletions(-)[...]
Quoted 5 lines
I agree that supporting dynamic CMA areas would be good. However, by doing it like this, these CMA areas are invisible to the rest of the system. E.g.
cma_for_each_area()does not know about them. It seems a bit inconsistent that there will now be some areas that are globally known, and some that are not.That was kind of the point of this experiment. When I started on this I ran into the case where I was running out of predefined CMA areas and as I went looking for ways on how to fix this, I realized that there's not much reason to keep a global list of these areas. And even less reason to limit the number of CMA areas to this predefined list. Very little code outside of the core CMA code even uses this.
There's one instance of
cma_for_each_area()that I don't grok. There's another early MMU fixup for CMA areas in 32-bit ARM that. Other than that there's a few places where the total CMA page count is shown for informational purposes and I don't know how useful that really is becausetotalcma_pagesdoesn't really track how many pages are used for CMA, but pages that could potentially be used for CMA.And that's about it.
It seems like there are cases where we might really need to globally know about some of these areas, specifically ones that are allocated very early during boot and then used for very specific purposes.
However, it seems to me like CMA is more universally useful than just for these cases and I don't see the usefulness of tracking these more generic uses.
Quoted 5 lines
I am being somewhat selfish here, as I have some WIP code that needs the global list :-) But I think the inconsistency is a more general point than just what I want (and the s390 code does use
cma_for_each_area()). Maybe you could keep maintaining a global structure containing all areas?If it's really useful to be able to access all CMA areas, then we could easily just add them all to a global linked list upon activation (we may still want/need to keep the predefined list around for all those early allocation cases). That way we'd get the best of both worlds.
Quoted 2 lines
What do you think are the chances of running out of the global count of areas?
Well, I did run out of CMA areas during the early VPR testing because I was initially testing with 16 areas and a different allocation scheme that turned out to cause too many resizes in common cases.
However, given that the default is 8 on normal systems (20 on NUMA) and is configurable, it means that even with restricting this to 4 for VPR doesn't always guarantee that all 4 are available. Again, yes, we could keep bumping that number, but why not turn this into something a bit more robust where nobody has to know or care about how many there are?
Quoted 7 lines
Also, you say that "these are treated specially and do not contribute to the number of total CMA pages". But, if I'm reading this right, you do call
cma_activate_area(), which will doinit_cma_reserved_pageblock()for each pageblock in it. Which adjusts the CMA counters for the zone they are in. But your change does not adjusttotalcma_pagesfor dynamically created areas. That seems inconsistent, too.I was referring to just
totalcma_pagesthat isn't impacted by these dynamically allocated regions. This is, again, because I don't see why that information would be useful. It's a fairly easy change to update that value, so if people prefer that, I can add that.
Quoted 4 lines
I don't see an immediate connection between
totalcma_pagesandinit_cma_reserved_pageblock(). I thought the latter was primarily useful for making sure that the CMA pages can be migrated, which is still critical for this use-case.
My comment was about statistics, they would be inconsistent after your change. E.g. currently, totalcma_pages is equal to the sum of CMA pages in each zone. But that would no longer be true, and applications / administrators looking at those statistics might see the inconsistency (between meminfo and vmstat) and wonder what's going on. It seems best to keep those numbers in sync.
In general, I think it's fine to support dynamic allocation, and I agree with your arguments that it doesn't seem right to set the number of CMA areas via a config option. I would just like there to be a canonical way to find all CMA areas.
- Frank
Re: [PATCH 3/9] mm/cma: Allow dynamically creating CMA areas
Quoted 101 lines · Frank van der Linden
Quoted 88 lines · Thierry Reding
Quoted 18 lines · Frank van der Linden
Quoted 17 lines · Thierry Reding
From: Thierry Reding <[email protected]>
There is no technical reason why there should be a limited number of CMA regions, so extract some code into helpers and use them to create extra functions (
cma_create()andcma_free()) that allow creating and freeing, respectively, CMA regions dynamically at runtime.Note that these dynamically created CMA areas are treated specially and do not contribute to the number of total CMA pages so that this count still only applies to the fixed number of CMA areas.
Signed-off-by Thierry Reding <[email protected]>--- include/linux/cma.h | 16 ++++++++ mm/cma.c | 89 ++++++++++++++++++++++++++++++++++----------- 2 files changed, 83 insertions(+), 22 deletions(-)[...]
Quoted 5 lines
I agree that supporting dynamic CMA areas would be good. However, by doing it like this, these CMA areas are invisible to the rest of the system. E.g.
cma_for_each_area()does not know about them. It seems a bit inconsistent that there will now be some areas that are globally known, and some that are not.That was kind of the point of this experiment. When I started on this I ran into the case where I was running out of predefined CMA areas and as I went looking for ways on how to fix this, I realized that there's not much reason to keep a global list of these areas. And even less reason to limit the number of CMA areas to this predefined list. Very little code outside of the core CMA code even uses this.
There's one instance of
cma_for_each_area()that I don't grok. There's another early MMU fixup for CMA areas in 32-bit ARM that. Other than that there's a few places where the total CMA page count is shown for informational purposes and I don't know how useful that really is becausetotalcma_pagesdoesn't really track how many pages are used for CMA, but pages that could potentially be used for CMA.And that's about it.
It seems like there are cases where we might really need to globally know about some of these areas, specifically ones that are allocated very early during boot and then used for very specific purposes.
However, it seems to me like CMA is more universally useful than just for these cases and I don't see the usefulness of tracking these more generic uses.
Quoted 5 lines
I am being somewhat selfish here, as I have some WIP code that needs the global list :-) But I think the inconsistency is a more general point than just what I want (and the s390 code does use
cma_for_each_area()). Maybe you could keep maintaining a global structure containing all areas?If it's really useful to be able to access all CMA areas, then we could easily just add them all to a global linked list upon activation (we may still want/need to keep the predefined list around for all those early allocation cases). That way we'd get the best of both worlds.
Quoted 2 lines
What do you think are the chances of running out of the global count of areas?
Well, I did run out of CMA areas during the early VPR testing because I was initially testing with 16 areas and a different allocation scheme that turned out to cause too many resizes in common cases.
However, given that the default is 8 on normal systems (20 on NUMA) and is configurable, it means that even with restricting this to 4 for VPR doesn't always guarantee that all 4 are available. Again, yes, we could keep bumping that number, but why not turn this into something a bit more robust where nobody has to know or care about how many there are?
Quoted 7 lines
Also, you say that "these are treated specially and do not contribute to the number of total CMA pages". But, if I'm reading this right, you do call
cma_activate_area(), which will doinit_cma_reserved_pageblock()for each pageblock in it. Which adjusts the CMA counters for the zone they are in. But your change does not adjusttotalcma_pagesfor dynamically created areas. That seems inconsistent, too.I was referring to just
totalcma_pagesthat isn't impacted by these dynamically allocated regions. This is, again, because I don't see why that information would be useful. It's a fairly easy change to update that value, so if people prefer that, I can add that.Quoted 4 lines
I don't see an immediate connection between
totalcma_pagesandinit_cma_reserved_pageblock(). I thought the latter was primarily useful for making sure that the CMA pages can be migrated, which is still critical for this use-case.My comment was about statistics, they would be inconsistent after your change. E.g. currently,
totalcma_pagesis equal to the sum of CMA pages in each zone. But that would no longer be true, and applications / administrators looking at those statistics might see the inconsistency (between meminfo and vmstat) and wonder what's going on. It seems best to keep those numbers in sync.
Quoted 4 lines
In general, I think it's fine to support dynamic allocation, and I agree with your arguments that it doesn't seem right to set the number of CMA areas via a config option. I would just like there to be a canonical way to find all CMA areas.
Okay, so judging by your and David's feedback, it sounds like I should add a bit of code to track dynamically allocated areas within a global list, along with the existing predefined regions and keep totalcma_pages updated so that the global view is consistent.
I'll look into that. Thanks for the feedback.
Thierry
PATCH 4/9 dma-buf: heaps: Add debugfs support
In reply to Thierry RedingFrom: Thierry Reding <[email protected]>
Add a callback to struct dma_heap_ops that heap providers can implement to show information about the state of the heap in debugfs. A top-level directory named "dma_heap" is created in debugfs and individual files will be named after the heaps.
--- drivers/dma-buf/dma-heap.c | 56 ++++++++++++++++++++++++++++++++++++++ include/linux/dma-heap.h | 2 ++ 2 files changed, 58 insertions(+)
drivers/dma-buf/dma-heap.c +56 -0
@@ -7,6 +7,7 @@*/ #include <linux/cdev.h> +#include <linux/debugfs.h> #include <linux/device.h> #include <linux/dma-buf.h> #include <linux/dma-heap.h>
@@ -217,6 +218,46 @@ const char *dma_heap_get_name(struct dma_heap *heap) }EXPORT_SYMBOL (dma_heap_get_name); +#ifdef CONFIG_DEBUG_FS +static int dma_heap_debug_show (struct seq_file *s,void *unused) +{ +struct dma_heap *heap = s->private; +int err =0 ; + +if (heap->ops && heap->ops->show) + err = heap->ops->show (s, heap); + +return err; +} +DEFINE_SHOW_ATTRIBUTE (dma_heap_debug); + +static struct dentry *dma_heap_debugfs_dir; + +static void dma_heap_init_debugfs (void ) +{ +struct dentry *dir; + + dir =debugfs_create_dir ("dma_heap" ,NULL ); +if (IS_ERR (dir)) +return ; + + dma_heap_debugfs_dir = dir; +} + +static void dma_heap_exit_debugfs (void ) +{ +debugfs_remove_recursive (dma_heap_debugfs_dir); +} +#else +static void dma_heap_init_debugfs (void ) +{ +} + +static void dma_heap_exit_debugfs (void ) +{ +} +#endif +/** * dma_heap_add - adds a heap to dmabuf heaps * @exp_info: information needed to register this heap
@@ -291,6 +332,13 @@ struct dma_heap *dma_heap_add(const struct dma_heap_export_info *exp_info)/* Add heap to the list */ list_add (&heap->list, &heap_list); + +#ifdef CONFIG_DEBUG_FS +if (heap->ops && heap->ops->show) +debugfs_create_file (heap->name,0444 , dma_heap_debugfs_dir, + heap, &dma_heap_debug_fops); +#endif +mutex_unlock (&heap_list_lock);return heap;
@@ -327,6 +375,14 @@ static int dma_heap_init(void) } dma_heap_class->devnode = dma_heap_devnode; +dma_heap_init_debugfs (); +return 0 ; }subsys_initcall (dma_heap_init); + +static void __exit dma_heap_exit(void) +{ +dma_heap_exit_debugfs (); +} +__exitcall (dma_heap_exit);
include/linux/dma-heap.h +2 -0
@@ -12,6 +12,7 @@#include <linux/types.h> struct dma_heap ; +struct seq_file ;/** * struct dma_heap_ops - ops to operate on a given heap
@@ -24,6 +25,7 @@ struct dma_heap_ops {unsigned long len, u32 fd_flags, u64 heap_flags); +int (*show)(struct seq_file *s,struct dma_heap *heap); };/**
Signature · 1 line
2.50.0
John Stultz
reviewerRe: [PATCH 4/9] dma-buf: heaps: Add debugfs support
Quoted 8 lines · Thierry Reding
From: Thierry Reding <[email protected]>
Add a callback to struct
dma_heap_opsthat heap providers can implement to show information about the state of the heap in debugfs. A top-level directory named "dma_heap" is created in debugfs and individual files will be named after the heaps.
I know its debugfs, but this feels a little loosey-goosey as an uAPI. Is there any expected format for the show function?
What would other dmabuf heaps ideally export via this interface?
Is there some consistent dma_heap-ish concept for it to justify it being under a dma_heap directory, and not just an independent debugfs file for the driver implementing the dmabuf heap?
thanks
-john
Re: [PATCH 4/9] dma-buf: heaps: Add debugfs support
Quoted 11 lines · John Stultz
Quoted 8 lines · Thierry Reding
From: Thierry Reding <[email protected]>
Add a callback to struct
dma_heap_opsthat heap providers can implement to show information about the state of the heap in debugfs. A top-level directory named "dma_heap" is created in debugfs and individual files will be named after the heaps.I know its debugfs, but this feels a little loosey-goosey as an uAPI.
Well, the whole point of debugfs is that it's not really an ABI. Nothing should ever rely on the presence of these files.
Quoted 3 lines
Is there any expected format for the show function?
What would other dmabuf heaps ideally export via this interface?
I've thought about this a bit and I'm not sure it makes sense to standardize on this. I think on one hand having a list of buffers exported by the dma-buf heap is probably the lowest common denominator, but then there might be a bunch of other things that are very heap- specific that some heap might want to export.
Quoted 3 lines
Is there some consistent dma_heap-ish concept for it to justify it being under a
dma_heapdirectory, and not just an independent debugfs file for the driver implementing the dmabuf heap?
Well, I think just the fact that it's a dma-heap would qualify its corresponding debugfs to be in a well-known location. We could of course pick some arbitrary location, but that's just a recipe for chaos because then everybody puts these whereever they want. There's really no standard place for driver-specific debugfs files to go, so putting it into some "subsystem"-specific directory seems like the better option.
Thierry
John Stultz
reviewerRe: [PATCH 4/9] dma-buf: heaps: Add debugfs support
Quoted 31 lines · Thierry Reding
Quoted 11 lines · John Stultz
Quoted 8 lines · Thierry Reding
From: Thierry Reding <[email protected]>
Add a callback to struct
dma_heap_opsthat heap providers can implement to show information about the state of the heap in debugfs. A top-level directory named "dma_heap" is created in debugfs and individual files will be named after the heaps.I know its debugfs, but this feels a little loosey-goosey as an uAPI.
Well, the whole point of debugfs is that it's not really an ABI. Nothing should ever rely on the presence of these files.
Quoted 3 lines
Is there any expected format for the show function?
What would other dmabuf heaps ideally export via this interface?
I've thought about this a bit and I'm not sure it makes sense to standardize on this. I think on one hand having a list of buffers exported by the dma-buf heap is probably the lowest common denominator, but then there might be a bunch of other things that are very heap- specific that some heap might want to export.
Quoted 3 lines
Is there some consistent dma_heap-ish concept for it to justify it being under a
dma_heapdirectory, and not just an independent debugfs file for the driver implementing the dmabuf heap?
Quoted 6 lines
Well, I think just the fact that it's a dma-heap would qualify its corresponding debugfs to be in a well-known location. We could of course pick some arbitrary location, but that's just a recipe for chaos because then everybody puts these whereever they want. There's really no standard place for driver-specific debugfs files to go, so putting it into some "subsystem"-specific directory seems like the better option.
Ok, I guess I was thinking if the files are organizationally cohesive to be under the dma-heap directory, they ought to have some consistency between them.
But I can see your perspective here that organizing the driver specific debug files in a directory helps with folks finding and identifying it.
Thanks for clarifying!
-john
Re: [PATCH 4/9] dma-buf: heaps: Add debugfs support
Quoted 39 lines · John Stultz
Quoted 31 lines · Thierry Reding
Quoted 11 lines · John Stultz
Quoted 8 lines · Thierry Reding
From: Thierry Reding <[email protected]>
Add a callback to struct
dma_heap_opsthat heap providers can implement to show information about the state of the heap in debugfs. A top-level directory named "dma_heap" is created in debugfs and individual files will be named after the heaps.I know its debugfs, but this feels a little loosey-goosey as an uAPI.
Well, the whole point of debugfs is that it's not really an ABI. Nothing should ever rely on the presence of these files.
Quoted 3 lines
Is there any expected format for the show function?
What would other dmabuf heaps ideally export via this interface?
I've thought about this a bit and I'm not sure it makes sense to standardize on this. I think on one hand having a list of buffers exported by the dma-buf heap is probably the lowest common denominator, but then there might be a bunch of other things that are very heap- specific that some heap might want to export.
Quoted 3 lines
Is there some consistent dma_heap-ish concept for it to justify it being under a
dma_heapdirectory, and not just an independent debugfs file for the driver implementing the dmabuf heap?Quoted 6 lines
Well, I think just the fact that it's a dma-heap would qualify its corresponding debugfs to be in a well-known location. We could of course pick some arbitrary location, but that's just a recipe for chaos because then everybody puts these whereever they want. There's really no standard place for driver-specific debugfs files to go, so putting it into some "subsystem"-specific directory seems like the better option.
Quoted 3 lines
Ok, I guess I was thinking if the files are organizationally cohesive to be under the dma-heap directory, they ought to have some consistency between them.
As far as I can tell there's not even enough information in a dma-heap to add any common debugfs snippets. As I mentioned earlier, a list of buffers allocated from a dma-heap is about the only generic piece of information that I can think of, but we don't track these buffers in a generic way. None of the existing heaps do so either seem to be interested in this either.
It's also not like it's very useful information most of the time, it's mainly in this driver so that it can be inspected at runtime to see what the allocation pattern looks like at various stages and maybe help tune the division into chunks.
Thierry
Re: [PATCH 4/9] dma-buf: heaps: Add debugfs support
Quoted 51 lines · Thierry Reding
Quoted 39 lines · John Stultz
Quoted 31 lines · Thierry Reding
Quoted 11 lines · John Stultz
Quoted 8 lines · Thierry Reding
From: Thierry Reding <[email protected]>
Add a callback to struct
dma_heap_opsthat heap providers can implement to show information about the state of the heap in debugfs. A top-level directory named "dma_heap" is created in debugfs and individual files will be named after the heaps.I know its debugfs, but this feels a little loosey-goosey as an uAPI.
Well, the whole point of debugfs is that it's not really an ABI. Nothing should ever rely on the presence of these files.
Quoted 3 lines
Is there any expected format for the show function?
What would other dmabuf heaps ideally export via this interface?
I've thought about this a bit and I'm not sure it makes sense to standardize on this. I think on one hand having a list of buffers exported by the dma-buf heap is probably the lowest common denominator, but then there might be a bunch of other things that are very heap- specific that some heap might want to export.
Quoted 3 lines
Is there some consistent dma_heap-ish concept for it to justify it being under a
dma_heapdirectory, and not just an independent debugfs file for the driver implementing the dmabuf heap?Quoted 6 lines
Well, I think just the fact that it's a dma-heap would qualify its corresponding debugfs to be in a well-known location. We could of course pick some arbitrary location, but that's just a recipe for chaos because then everybody puts these whereever they want. There's really no standard place for driver-specific debugfs files to go, so putting it into some "subsystem"-specific directory seems like the better option.
Quoted 3 lines
Ok, I guess I was thinking if the files are organizationally cohesive to be under the dma-heap directory, they ought to have some consistency between them.
As far as I can tell there's not even enough information in a dma-heap to add any common debugfs snippets. As I mentioned earlier, a list of buffers allocated from a dma-heap is about the only generic piece of information that I can think of, but we don't track these buffers in a generic way. None of the existing heaps do so either seem to be interested in this either.
Quoted 4 lines
It's also not like it's very useful information most of the time, it's mainly in this driver so that it can be inspected at runtime to see what the allocation pattern looks like at various stages and maybe help tune the division into chunks.
It is somewhat useful when we're talking about cgroup though :)
I think the buffer tracking / debugging mechanism itself is redundant with what dmem/memcg would provide, so we probably want to just enable dmem (probably?) here?
Of course, it doesn't help with additional heap specific debugging information, so this patch might still have value.
Maxime
PATCH 5/9 dma-buf: heaps: Add support for Tegra VPR
In reply to Thierry RedingFrom: Thierry Reding <[email protected]>
NVIDIA Tegra SoCs commonly define a Video-Protection-Region, which is a region of memory dedicated to content-protected video decode and playback. This memory cannot be accessed by the CPU and only certain hardware devices have access to it.
Expose the VPR as a DMA heap so that applications and drivers can allocate buffers from this region for use-cases that require this kind of protected memory.
VPR has a few very critical peculiarities. First, it must be a single contiguous region of memory (there is a single pair of registers that set the base address and size of the region), which is configured by calling back into the secure monitor. The memory region also needs to quite large for some use-cases because it needs to fit multiple video frames (8K video should be supported), so VPR sizes of ~2 GiB are expected. However, some devices cannot afford to reserve this amount of memory for a particular use-case, and therefore the VPR must be resizable.
Unfortunately, resizing the VPR is slightly tricky because the GPU found on Tegra SoCs must be in reset during the VPR resize operation. This is currently implemented by freezing all userspace processes and calling invoking the GPU's freeze() implementation, resizing and the thawing the GPU and userspace processes. This is quite heavy-handed, so eventually it might be better to implement thawing/freezing in the GPU driver in such a way that they block accesses to the GPU so that the VPR resize operation can happen without suspending all userspace.
In order to balance the memory usage versus the amount of resizing that needs to happen, the VPR is divided into multiple chunks. Each chunk is implemented as a CMA area that is completely allocated on first use to guarantee the contiguity of the VPR. Once all buffers from a chunk have been freed, the CMA area is deallocated and the memory returned to the system.
--- drivers/dma-buf/heaps/Kconfig | 7 + drivers/dma-buf/heaps/Makefile | 1 + drivers/dma-buf/heaps/tegra-vpr.c | 831 ++++++++++++++++++++++++++++++ include/trace/events/tegra_vpr.h | 57 ++ 4 files changed, 896 insertions(+) create mode 100644 drivers/dma-buf/heaps/tegra-vpr.c create mode 100644 include/trace/events/tegra_vpr.h
drivers/dma-buf/heaps/Kconfig +7 -0
@@ -22,3 +22,10 @@ config DMABUF_HEAPS_CMA_LEGACY from the CMA area's devicetree node, or "reserved" if the area is not defined in the devicetree. This uses the same underlying allocator as CONFIG_DMABUF_HEAPS_CMA. + +config DMABUF_HEAPS_TEGRA_VPR + bool "NVIDIA Tegra Video-Protected-Region DMA-BUF Heap" + depends on DMABUF_HEAPS && DMA_CMA + help + Choose this option to enable Video-Protected-Region (VPR) support on + a range of NVIDIA Tegra devices.
drivers/dma-buf/heaps/Makefile +1 -0
@@ -1,3 +1,4 @@ # SPDX-License-Identifier: GPL-2.0 obj-$(CONFIG_DMABUF_HEAPS_SYSTEM) += system_heap.o obj-$(CONFIG_DMABUF_HEAPS_CMA) += cma_heap.o +obj-$(CONFIG_DMABUF_HEAPS_TEGRA_VPR) += tegra-vpr.o
drivers/dma-buf/heaps/tegra-vpr.c new file +831 -0
831 lines not on this page · raw message
include/trace/events/tegra_vpr.h new file +57 -0
57 lines not on this page · raw message
Signature · 1 line
2.50.0
kernel test robot
build botRe: [PATCH 5/9] dma-buf: heaps: Add support for Tegra VPR
kernel test robot noticed the following build warnings:
Hi Thierry,
kernel test robot noticed the following build warnings:
[auto build test WARNING on next-20250902]
[also build test WARNING on v6.17-rc4]
[cannot apply to robh/for-next akpm-mm/mm-everything tegra/for-next linus/master v6.17-rc4 v6.17-rc3 v6.17-rc2] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Thierry-Reding/dt-bindings-reserved-memory-Document-Tegra-VPR/20250902-235038 base: next-20250902 patch link: https://lore.kernel.org/r/20250902154630.4032984-6-thierry.reding%40gmail.com patch subject: [PATCH 5/9] dma-buf: heaps: Add support for Tegra VPR config: i386-allmodconfig (https://download.01.org/0day-ci/archive/20250905/[email protected]/config) compiler: gcc-13 (Debian 13.3.0-16) 13.3.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250905/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All warnings (new ones prefixed by >>):
drivers/dma-buf/heaps/tegra-vpr.c: In function 'tegra_vpr_protect_pages':
drivers/dma-buf/heaps/tegra-vpr.c:192:21: error: implicit declaration of function '__ptep_get'; did you mean 'ptep_get'? [-Werror=implicit-function-declaration]
192 | pte_t pte = __ptep_get(ptep);
| ^~~~~~~~~~
| ptep_get
drivers/dma-buf/heaps/tegra-vpr.c:192:21: error: invalid initializer
drivers/dma-buf/heaps/tegra-vpr.c:194:15: error: implicit declaration of function 'clear_pte_bit'; did you mean 'clear_ptes'? [-Werror=implicit-function-declaration]
194 | pte = clear_pte_bit(pte, __pgprot(PROT_NORMAL));
| ^~~~~~~~~~~~~
| clear_ptes
In file included from arch/x86/include/asm/paravirt_types.h:11,
from arch/x86/include/asm/ptrace.h:175,
from arch/x86/include/asm/math_emu.h:5,
from arch/x86/include/asm/processor.h:13,
from arch/x86/include/asm/cpufeature.h:5,
from arch/x86/include/asm/thread_info.h:59,
from include/linux/thread_info.h:60,
from include/linux/spinlock.h:60,
from include/linux/wait.h:9,
from include/linux/wait_bit.h:8,
from include/linux/fs.h:7,
from include/linux/debugfs.h:15,
from drivers/dma-buf/heaps/tegra-vpr.c:12:
drivers/dma-buf/heaps/tegra-vpr.c:194:43: error: 'PROT_NORMAL' undeclared (first use in this function)
194 | pte = clear_pte_bit(pte, __pgprot(PROT_NORMAL));
| ^~~~~~~~~~~
arch/x86/include/asm/pgtable_types.h:202:48: note: in definition of macro '__pgprot'
202 | #define __pgprot(x) ((pgprot_t) { (x) } )
| ^
drivers/dma-buf/heaps/tegra-vpr.c:194:43: note: each undeclared identifier is reported only once for each function it appears in
194 | pte = clear_pte_bit(pte, __pgprot(PROT_NORMAL));
| ^~~~~~~~~~~
arch/x86/include/asm/pgtable_types.h:202:48: note: in definition of macro '__pgprot'
202 | #define __pgprot(x) ((pgprot_t) { (x) } )
| ^
drivers/dma-buf/heaps/tegra-vpr.c:195:15: error: implicit declaration of function 'set_pte_bit'; did you mean 'set_pte_at'? [-Werror=implicit-function-declaration]
195 | pte = set_pte_bit(pte, __pgprot(PROT_DEVICE_nGnRnE));
| ^~~~~~~~~~~
| set_pte_at
drivers/dma-buf/heaps/tegra-vpr.c:195:41: error: 'PROT_DEVICE_nGnRnE' undeclared (first use in this function)
195 | pte = set_pte_bit(pte, __pgprot(PROT_DEVICE_nGnRnE));
| ^~~~~~~~~~~~~~~~~~
arch/x86/include/asm/pgtable_types.h:202:48: note: in definition of macro '__pgprot'
202 | #define __pgprot(x) ((pgprot_t) { (x) } )
| ^
drivers/dma-buf/heaps/tegra-vpr.c:197:9: error: implicit declaration of function '__set_pte'; did you mean 'set_pte'? [-Werror=implicit-function-declaration]
197 | __set_pte(ptep, pte);
| ^~~~~~~~~
| set_pte
drivers/dma-buf/heaps/tegra-vpr.c: In function 'tegra_vpr_unprotect_pages':
drivers/dma-buf/heaps/tegra-vpr.c:205:21: error: invalid initializer
205 | pte_t pte = __ptep_get(ptep);
| ^~~~~~~~~~
drivers/dma-buf/heaps/tegra-vpr.c:207:43: error: 'PROT_DEVICE_nGnRnE' undeclared (first use in this function)
207 | pte = clear_pte_bit(pte, __pgprot(PROT_DEVICE_nGnRnE));
| ^~~~~~~~~~~~~~~~~~
arch/x86/include/asm/pgtable_types.h:202:48: note: in definition of macro '__pgprot'
202 | #define __pgprot(x) ((pgprot_t) { (x) } )
| ^
drivers/dma-buf/heaps/tegra-vpr.c:208:41: error: 'PROT_NORMAL' undeclared (first use in this function)
208 | pte = set_pte_bit(pte, __pgprot(PROT_NORMAL));
| ^~~~~~~~~~~
arch/x86/include/asm/pgtable_types.h:202:48: note: in definition of macro '__pgprot'
202 | #define __pgprot(x) ((pgprot_t) { (x) } )
| ^
drivers/dma-buf/heaps/tegra-vpr.c: In function 'tegra_vpr_add_heap':
>> drivers/dma-buf/heaps/tegra-vpr.c:8:21: warning: format '%lu' expects argument of type 'long unsigned int', but argument 6 has type 'size_t' {aka 'unsigned int'} [-Wformat=]
8 | #define pr_fmt(fmt) "tegra-vpr: " fmt
| ^~~~~~~~~~~~~
include/linux/dynamic_debug.h:224:29: note: in expansion of macro 'pr_fmt'
224 | func(&id, ##__VA_ARGS__); \
| ^~~~~~~~~~~
include/linux/dynamic_debug.h:248:9: note: in expansion of macro '__dynamic_func_call_cls'
248 | __dynamic_func_call_cls(__UNIQUE_ID(ddebug), cls, fmt, func, ##__VA_ARGS__)
| ^~~~~~~~~~~~~~~~~~~~~~~
include/linux/dynamic_debug.h:250:9: note: in expansion of macro '_dynamic_func_call_cls'
250 | _dynamic_func_call_cls(_DPRINTK_CLASS_DFLT, fmt, func, ##__VA_ARGS__)
| ^~~~~~~~~~~~~~~~~~~~~~
include/linux/dynamic_debug.h:269:9: note: in expansion of macro '_dynamic_func_call'
269 | _dynamic_func_call(fmt, __dynamic_pr_debug, \
| ^~~~~~~~~~~~~~~~~~
include/linux/printk.h:636:9: note: in expansion of macro 'dynamic_pr_debug'
636 | dynamic_pr_debug(fmt, ##__VA_ARGS__)
| ^~~~~~~~~~~~~~~~
drivers/dma-buf/heaps/tegra-vpr.c:715:17: note: in expansion of macro 'pr_debug'
715 | pr_debug(" %2u: %pap-%pap (%lu MiB)\n", i, &start, &end,
| ^~~~~~~~cc1: some warnings being treated as errors
vim +8 drivers/dma-buf/heaps/tegra-vpr.c
> 8 #define pr_fmt(fmt) "tegra-vpr: " fmt
9 Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
kernel test robot
build botRe: [PATCH 5/9] dma-buf: heaps: Add support for Tegra VPR
In reply to Thierry Redingkernel test robot noticed the following build errors:
Hi Thierry,
kernel test robot noticed the following build errors:
[auto build test ERROR on next-20250902]
[also build test ERROR on v6.17-rc4]
[cannot apply to robh/for-next akpm-mm/mm-everything tegra/for-next linus/master v6.17-rc4 v6.17-rc3 v6.17-rc2] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Thierry-Reding/dt-bindings-reserved-memory-Document-Tegra-VPR/20250902-235038 base: next-20250902 patch link: https://lore.kernel.org/r/20250902154630.4032984-6-thierry.reding%40gmail.com patch subject: [PATCH 5/9] dma-buf: heaps: Add support for Tegra VPR config: s390-allmodconfig (https://download.01.org/0day-ci/archive/20250905/[email protected]/config) compiler: clang version 18.1.8 (https://github.com/llvm/llvm-project 3b5b5c1ec4a3095ab096dd780e84d7ab81f3d7ff) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250905/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
>> drivers/dma-buf/heaps/tegra-vpr.c:158:26: error: called object type 'void *' is not a function or function pointer
158 | err = pm_generic_freeze(node->dev);
| ~~~~~~~~~~~~~~~~~^
drivers/dma-buf/heaps/tegra-vpr.c:175:24: error: called object type 'void *' is not a function or function pointer
175 | err = pm_generic_thaw(node->dev);
| ~~~~~~~~~~~~~~~^
drivers/dma-buf/heaps/tegra-vpr.c:192:14: error: call to undeclared function '__ptep_get'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
192 | pte_t pte = __ptep_get(ptep);
| ^
drivers/dma-buf/heaps/tegra-vpr.c:192:14: note: did you mean 'ptep_get'?
include/linux/pgtable.h:338:21: note: 'ptep_get' declared here
338 | static inline pte_t ptep_get(pte_t *ptep)
| ^
drivers/dma-buf/heaps/tegra-vpr.c:192:8: error: initializing 'pte_t' with an expression of incompatible type 'int'
192 | pte_t pte = __ptep_get(ptep);
| ^ ~~~~~~~~~~~~~~~~
drivers/dma-buf/heaps/tegra-vpr.c:194:36: error: use of undeclared identifier 'PROT_NORMAL'; did you mean 'ZONE_NORMAL'?
194 | pte = clear_pte_bit(pte, __pgprot(PROT_NORMAL));
| ^~~~~~~~~~~
| ZONE_NORMAL
arch/s390/include/asm/page.h:122:36: note: expanded from macro '__pgprot'
122 | #define __pgprot(x) ((pgprot_t) { (x) } )
| ^
include/linux/mmzone.h:806:2: note: 'ZONE_NORMAL' declared here
806 | ZONE_NORMAL,
| ^
drivers/dma-buf/heaps/tegra-vpr.c:195:34: error: use of undeclared identifier 'PROT_DEVICE_nGnRnE'
195 | pte = set_pte_bit(pte, __pgprot(PROT_DEVICE_nGnRnE));
| ^
drivers/dma-buf/heaps/tegra-vpr.c:197:2: error: call to undeclared function '__set_pte'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
197 | __set_pte(ptep, pte);
| ^
drivers/dma-buf/heaps/tegra-vpr.c:197:2: note: did you mean 'set_pte'?
arch/s390/include/asm/pgtable.h:1041:20: note: 'set_pte' declared here
1041 | static inline void set_pte(pte_t *ptep, pte_t pte)
| ^
drivers/dma-buf/heaps/tegra-vpr.c:205:14: error: call to undeclared function '__ptep_get'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
205 | pte_t pte = __ptep_get(ptep);
| ^
drivers/dma-buf/heaps/tegra-vpr.c:205:8: error: initializing 'pte_t' with an expression of incompatible type 'int'
205 | pte_t pte = __ptep_get(ptep);
| ^ ~~~~~~~~~~~~~~~~
drivers/dma-buf/heaps/tegra-vpr.c:207:36: error: use of undeclared identifier 'PROT_DEVICE_nGnRnE'
207 | pte = clear_pte_bit(pte, __pgprot(PROT_DEVICE_nGnRnE));
| ^
drivers/dma-buf/heaps/tegra-vpr.c:208:34: error: use of undeclared identifier 'PROT_NORMAL'; did you mean 'ZONE_NORMAL'?
208 | pte = set_pte_bit(pte, __pgprot(PROT_NORMAL));
| ^~~~~~~~~~~
| ZONE_NORMAL
arch/s390/include/asm/page.h:122:36: note: expanded from macro '__pgprot'
122 | #define __pgprot(x) ((pgprot_t) { (x) } )
| ^
include/linux/mmzone.h:806:2: note: 'ZONE_NORMAL' declared here
806 | ZONE_NORMAL,
| ^
drivers/dma-buf/heaps/tegra-vpr.c:210:2: error: call to undeclared function '__set_pte'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
210 | __set_pte(ptep, pte);
| ^12 errors generated.
vim +158 drivers/dma-buf/heaps/tegra-vpr.c
135
136 static int tegra_vpr_resize(struct tegra_vpr *vpr)
137 {
138 struct tegra_vpr_device *node;
139 phys_addr_t base, size;
140 int err;
141
142 err = tegra_vpr_get_extents(vpr, &base, &size);
143 if (err < 0) {
144 pr_err("%s(): failed to get VPR extents: %d\n", __func__, err);
145 return err;
146 }
147
148 if (vpr->use_freezer) {
149 err = freeze_processes();
150 if (err < 0) {
151 pr_err("%s(): failed to freeze processes: %d\n",
152 __func__, err);
153 return err;
154 }
155 }
156
157 list_for_each_entry(node, &vpr->devices, node) {
> 158 err = pm_generic_freeze(node->dev);
159 if (err < 0) {
160 pr_err("failed to runtime suspend %s\n",
161 dev_name(node->dev));
162 continue;
163 }
164 }
165
166 trace_tegra_vpr_set(base, size);
167
168 err = tegra_vpr_set(base, size);
169 if (err < 0) {
170 pr_err("failed to secure VPR: %d\n", err);
171 return err;
172 }
173
174 list_for_each_entry(node, &vpr->devices, node) {
175 err = pm_generic_thaw(node->dev);
176 if (err < 0) {
177 pr_err("failed to runtime resume %s\n",
178 dev_name(node->dev));
179 continue;
180 }
181 }
182
183 if (vpr->use_freezer)
184 thaw_processes();
185
186 return 0;
187 }
188
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
PATCH 6/9 arm64: tegra: Add VPR placeholder node on Tegra234
In reply to Thierry RedingFrom: Thierry Reding <[email protected]>
This node contains two sets of properties, one for the case where the VPR is resizable (in which case the VPR region will be dynamically allocated at boot time) and another case where the VPR is fixed in size and initialized by early firmware.
The firmware running on the device is responsible for updating the node with the real physical address for the fixed VPR case and remove the properties needed only for resizable VPR. Similarly, if the VPR is resizable, the firmware should remove the "reg" property since it is no longer needed.
--- arch/arm64/boot/dts/nvidia/tegra234.dtsi | 34 ++++++++++++++++++++++++ 1 file changed, 34 insertions(+)
arch/arm64/boot/dts/nvidia/tegra234.dtsi +34 -0
@@ -28,6 +28,40 @@ aliases { i2c8 = &dp_aux_ch3_i2c; }; + reserved-memory { + #address-cells = <2>; + #size-cells = <2>; + ranges; + + vpr: video-protection-region@0 { + compatible = "nvidia,tegra-video-protection-region"; + status = "disabled"; + no-map; + + /* + * Two variants exist for this. For fixed VPR, the + * firmware is supposed to update the "reg" property + * with the fixed memory region configured as VPR. + * + * For resizable VPR we don't care about the exact + * address and instead want a reserved region to be + * allocated with a certain size and alignment at + * boot time. + * + * The firmware is responsible for removing the + * unused set of properties. + */ + + /* fixed VPR */ + reg = <0x0 0x0 0x0 0x0>; + + /* resizable VPR */ + size = <0x0 0x70000000>; + alignment = <0x0 0x100000>; + reusable; + }; + }; + bus@0 { compatible = "simple-bus";
Signature · 1 line
2.50.0
Re: [PATCH 6/9] arm64: tegra: Add VPR placeholder node on Tegra234
Quoted 49 lines · Thierry Reding
From: Thierry Reding <[email protected]>
This node contains two sets of properties, one for the case where the VPR is resizable (in which case the VPR region will be dynamically allocated at boot time) and another case where the VPR is fixed in size and initialized by early firmware.
The firmware running on the device is responsible for updating the node with the real physical address for the fixed VPR case and remove the properties needed only for resizable VPR. Similarly, if the VPR is resizable, the firmware should remove the "reg" property since it is no longer needed.
Signed-off-by Thierry Reding <[email protected]>--- arch/arm64/boot/dts/nvidia/tegra234.dtsi | 34 ++++++++++++++++++++++++ 1 file changed, 34 insertions(+)arch/arm64/boot/dts/nvidia/tegra234.dtsi +23
-0@@ -28,6 +28,40 @@ aliases { i2c8 = &dp_aux_ch3_i2c; }; + reserved-memory { + #address-cells = <2>; + #size-cells = <2>; + ranges; + + vpr: video-protection-region@0 { + compatible = "nvidia,tegra-video-protection-region"; + status = "disabled"; + no-map; + + /* + * Two variants exist for this. For fixed VPR, the + * firmware is supposed to update the "reg" property + * with the fixed memory region configured as VPR. + * + * For resizable VPR we don't care about the exact + * address and instead want a reserved region to be + * allocated with a certain size and alignment at + * boot time. + * + * The firmware is responsible for removing the + * unused set of properties. + */
arch/arm64/boot/dts/nvidia/tegra234.dtsi aliases { · line 63
Quoted 10 lines
arch/arm64/boot/dts/nvidia/tegra234.dtsi +10
-0+ + /* fixed VPR */ + reg = <0x0 0x0 0x0 0x0>; + + /* resizable VPR */ + size = <0x0 0x70000000>; + alignment = <0x0 0x100000>; + reusable; + }; + };
Hi DT maintainers,
I wanted to get some feedback on this type of placeholder DT node. This doesn't actually validate properly because it contains properties for both the fixed and resizable VPR variants, which are mutually exclusive. However, the way that this currently works is that UEFI will remove and update whatever properties need to change during boot, so the booted kernel ends up with the correct, non-conflicting information.
The reason why it was done this way is because it simplifies the code in UEFI to update this node. Also, without this being a placeholder I don't know what to put into this. There's no "default" for this. One option is to not have this in the DT at all and completely create it at boot time, but then it becomes quite difficult to create the phandle references.
While at it, I'm not sure if I properly understand how to correctly name a reserved-memory region that is dynamically allocated like in the case of resizable VPR? It doesn't have a base address during boot and the kernel will allocate memory where it sees fit. Do I just leave out the unit-address in that case?
Thanks,
Thierry
PATCH 7/9 arm64: tegra: Add GPU node on Tegra234
In reply to Thierry RedingFrom: Thierry Reding <[email protected]>
--- arch/arm64/boot/dts/nvidia/tegra234.dtsi | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
arch/arm64/boot/dts/nvidia/tegra234.dtsi +17 -0
@@ -5262,6 +5262,23 @@ pcie-ep@141e0000 { }; }; + gpu@17000000 { + compatible = "nvidia,ga10b"; + reg = <0x0 0x17000000 0x0 0x1000000>, + <0x0 0x18000000 0x0 0x1000000>; + interrupts = <GIC_SPI 67 IRQ_TYPE_LEVEL_HIGH>, + <GIC_SPI 68 IRQ_TYPE_LEVEL_HIGH>, + <GIC_SPI 70 IRQ_TYPE_LEVEL_HIGH>, + <GIC_SPI 71 IRQ_TYPE_LEVEL_HIGH>; + interrupt-names = "nonstall", "stall0", "stall1", "stall2"; + power-domains = <&bpmp TEGRA234_POWER_DOMAIN_GPU>; + clocks = <&bpmp TEGRA234_CLK_GPUSYS>, + <&bpmp TEGRA234_CLK_GPC0CLK>, + <&bpmp TEGRA234_CLK_GPC1CLK>; + clock-names = "sys", "gpc0", "gpc1"; + resets = <&bpmp TEGRA234_RESET_GPU>; + }; + sram@40000000 { compatible = "nvidia,tegra234-sysram", "mmio-sram"; reg = <0x0 0x40000000 0x0 0x80000>;
Signature · 1 line
2.50.0
PATCH 8/9 arm64: tegra: Hook up VPR to host1x
In reply to Thierry RedingFrom: Thierry Reding <[email protected]>
The host1x needs access to the VPR region, so make sure to reference it via the memory-region property.
--- arch/arm64/boot/dts/nvidia/tegra234.dtsi | 3 +++ 1 file changed, 3 insertions(+)
arch/arm64/boot/dts/nvidia/tegra234.dtsi +3 -0
@@ -4414,6 +4414,9 @@ host1x@13e00000 { <14 &smmu_niso1 TEGRA234_SID_HOST1X_CTX6 1>, <15 &smmu_niso1 TEGRA234_SID_HOST1X_CTX7 1>; + memory-region = <&vpr>; + memory-region-names = "protected"; + vic@15340000 { compatible = "nvidia,tegra234-vic"; reg = <0x0 0x15340000 0x0 0x00040000>;
Signature · 1 line
2.50.0
PATCH 9/9 arm64: tegra: Hook up VPR to the GPU
In reply to Thierry RedingFrom: Thierry Reding <[email protected]>
The GPU needs to be idled before the VPR can be resized and unidled afterwards. Associate it with the VPR using the standard memory-region device tree property.
--- arch/arm64/boot/dts/nvidia/tegra234.dtsi | 3 +++ 1 file changed, 3 insertions(+)
arch/arm64/boot/dts/nvidia/tegra234.dtsi +3 -0
@@ -5280,6 +5280,9 @@ gpu@17000000 { <&bpmp TEGRA234_CLK_GPC1CLK>; clock-names = "sys", "gpc0", "gpc1"; resets = <&bpmp TEGRA234_RESET_GPU>; + + memory-region-names = "vpr"; + memory-region = <&vpr>; }; sram@40000000 {
Signature · 1 line
2.50.0
Quoted 4 lines · Thierry Reding
From: Thierry Reding <[email protected]>
Hi,
Hi,
Quoted 5 lines
This series adds support for the video protection region (VPR) used on Tegra SoC devices. It's a special region of memory that is protected from accesses by the CPU and used to store DRM protected content (both decrypted stream data as well as decoded video frames).
Quoted 8 lines
Patches 1 and 2 add DT binding documentation for the VPR and add the VPR to the list of memory-region items for display and host1x.
Patch 3 introduces new APIs needed by the Tegra VPR implementation that allow CMA areas to be dynamically created at runtime rather than using the fixed, system-wide list. This is used in this driver specifically because it can use an arbitrary number of these areas (though they are currently limited to 4).
I am pretty sure we want a system-wide list. Currently we maintain all areas in a static array limited by CONFIG_CMA_AREAS.
We can adjsut that to support for more dynamically.
Signature · 3 lines
Cheers David / dhildenb