Re: [Nouveau] [PATCH v2 1/2] drm/nouveau: Fix ida leak

2021-05-11 Thread Pierre Moreau
Why remove the const modifier on `nb`? On 2021-05-11 — 16:28, Zhen Lei wrote: > When the 'nb' value allocated from 'bl_ida' is greater than or equal to > 100, it will not be released. In fact, we can simplify operations by > limiting the range of idas that can be applied for. > > By the way, dele

Re: [Nouveau] [PATCH v2 2/2] drm/nouveau: Fix error return code in nouveau_backlight_init()

2021-05-11 Thread Pierre Moreau
Reviewed-by: Pierre Moreau On 2021-05-11 — 16:28, Zhen Lei wrote: > Fix to return a negative error code from the error handling case instead > of 0, as done elsewhere in this function. > > Fixes: db1a0ae21461 ("drm/nouveau/bl: Assign different names to interfaces") > Suggested-by: Pierre Moreau

Re: [Nouveau] [PATCH v6 05/15] swiotlb: Add a new get_io_tlb_mem getter

2021-05-11 Thread Claire Chang
On Mon, May 10, 2021 at 11:03 PM Christoph Hellwig wrote: > > > +static inline struct io_tlb_mem *get_io_tlb_mem(struct device *dev) > > +{ > > +#ifdef CONFIG_DMA_RESTRICTED_POOL > > + if (dev && dev->dma_io_tlb_mem) > > + return dev->dma_io_tlb_mem; > > +#endif /* CONFIG_DMA_RESTR

Re: [Nouveau] [PATCH v6 04/15] swiotlb: Add restricted DMA pool initialization

2021-05-11 Thread Claire Chang
On Mon, May 10, 2021 at 11:03 PM Christoph Hellwig wrote: > > > +#ifdef CONFIG_DMA_RESTRICTED_POOL > > +#include > > +#include > > +#include > > +#include > > +#include > > +#endif > > I don't think any of this belongs into swiotlb.c. Marking > swiotlb_init_io_tlb_mem non-static and having a

Re: [Nouveau] [PATCH v6 08/15] swiotlb: Bounce data from/to restricted DMA pool if available

2021-05-11 Thread Claire Chang
On Mon, May 10, 2021 at 11:05 PM Christoph Hellwig wrote: > > > +static inline bool is_dev_swiotlb_force(struct device *dev) > > +{ > > +#ifdef CONFIG_DMA_RESTRICTED_POOL > > + if (dev->dma_io_tlb_mem) > > + return true; > > +#endif /* CONFIG_DMA_RESTRICTED_POOL */ > > + return

[Nouveau] [PATCH] nouveau/gem: fix user-after-free in nouveau_gem_new

2021-05-11 Thread Karol Herbst
If ttm_bo_init fails it will already call ttm_bo_put, so we don't have to do it through nouveau_bo_ref. == BUG: KFENCE: use-after-free write in ttm_bo_put+0x11/0x40 [ttm] Use-after-free write at 0x4dc4663c (in kfence-#44): t

[Nouveau] [PATCH v6 06/15] swiotlb: Update is_swiotlb_buffer to add a struct device argument

2021-05-11 Thread Claire Chang
Update is_swiotlb_buffer to add a struct device argument. This will be useful later to allow for restricted DMA pool. Signed-off-by: Claire Chang --- drivers/iommu/dma-iommu.c | 12 ++-- drivers/xen/swiotlb-xen.c | 2 +- include/linux/swiotlb.h | 6 +++--- kernel/dma/direct.c |

Re: [Nouveau] [PATCH v6 01/15] swiotlb: Refactor swiotlb init functions

2021-05-11 Thread Christoph Hellwig
Looks good, Reviewed-by: Christoph Hellwig ___ Nouveau mailing list Nouveau@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/nouveau

[Nouveau] [PATCH v6 13/15] dma-direct: Allocate memory from restricted DMA pool if available

2021-05-11 Thread Claire Chang
The restricted DMA pool is preferred if available. The restricted DMA pools provide a basic level of protection against the DMA overwriting buffer contents at unexpected times. However, to protect against general data leakage and system memory corruption, the system needs to provide a way to lock

[Nouveau] [PATCH v6 10/15] swiotlb: Refactor swiotlb_tbl_unmap_single

2021-05-11 Thread Claire Chang
Add a new function, release_slots, to make the code reusable for supporting different bounce buffer pools, e.g. restricted DMA pool. Signed-off-by: Claire Chang --- kernel/dma/swiotlb.c | 35 --- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/kern

[Nouveau] [PATCH v6 11/15] dma-direct: Add a new wrapper __dma_direct_free_pages()

2021-05-11 Thread Claire Chang
Add a new wrapper __dma_direct_free_pages() that will be useful later for swiotlb_free(). Signed-off-by: Claire Chang --- kernel/dma/direct.c | 14 ++ 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/kernel/dma/direct.c b/kernel/dma/direct.c index 078f7087e466..eb409832

[Nouveau] [PATCH v6 07/15] swiotlb: Update is_swiotlb_active to add a struct device argument

2021-05-11 Thread Claire Chang
Update is_swiotlb_active to add a struct device argument. This will be useful later to allow for restricted DMA pool. Signed-off-by: Claire Chang --- drivers/gpu/drm/i915/gem/i915_gem_internal.c | 2 +- drivers/gpu/drm/nouveau/nouveau_ttm.c| 2 +- drivers/pci/xen-pcifront.c

Re: [Nouveau] [PATCH v6 04/15] swiotlb: Add restricted DMA pool initialization

2021-05-11 Thread Christoph Hellwig
> +#ifdef CONFIG_DMA_RESTRICTED_POOL > +#include > +#include > +#include > +#include > +#include > +#endif I don't think any of this belongs into swiotlb.c. Marking swiotlb_init_io_tlb_mem non-static and having all this code in a separate file is probably a better idea. > +#ifdef CONFIG_DMA

[Nouveau] [PATCH v6 02/15] swiotlb: Refactor swiotlb_create_debugfs

2021-05-11 Thread Claire Chang
Split the debugfs creation to make the code reusable for supporting different bounce buffer pools, e.g. restricted DMA pool. Signed-off-by: Claire Chang --- kernel/dma/swiotlb.c | 22 -- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/kernel/dma/swiotlb.c b/ker

Re: [Nouveau] [PATCH v6 02/15] swiotlb: Refactor swiotlb_create_debugfs

2021-05-11 Thread Christoph Hellwig
Looks good, Reviewed-by: Christoph Hellwig ___ Nouveau mailing list Nouveau@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/nouveau

[Nouveau] [PATCH v6 15/15] of: Add plumbing for restricted DMA pool

2021-05-11 Thread Claire Chang
If a device is not behind an IOMMU, we look up the device node and set up the restricted DMA when the restricted-dma-pool is presented. Signed-off-by: Claire Chang --- drivers/of/address.c| 25 + drivers/of/device.c | 3 +++ drivers/of/of_private.h | 5 + 3

[Nouveau] [PATCH v6 09/15] swiotlb: Move alloc_size to find_slots

2021-05-11 Thread Claire Chang
Move the maintenance of alloc_size to find_slots for better code reusability later. Signed-off-by: Claire Chang --- kernel/dma/swiotlb.c | 10 +- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c index 3f1ad080a4bc..ef04d8f7708f 100

Re: [Nouveau] [PATCH v6 08/15] swiotlb: Bounce data from/to restricted DMA pool if available

2021-05-11 Thread Christoph Hellwig
> +static inline bool is_dev_swiotlb_force(struct device *dev) > +{ > +#ifdef CONFIG_DMA_RESTRICTED_POOL > + if (dev->dma_io_tlb_mem) > + return true; > +#endif /* CONFIG_DMA_RESTRICTED_POOL */ > + return false; > +} > + > /* If SWIOTLB is active, use its maximum mapping

[Nouveau] [PATCH v6 00/15] Restricted DMA

2021-05-11 Thread Claire Chang
From: Claire Chang This series implements mitigations for lack of DMA access control on systems without an IOMMU, which could result in the DMA accessing the system memory at unexpected times and/or unexpected addresses, possibly leading to data leakage or corruption. For example, we plan to use

Re: [Nouveau] [PATCH v6 05/15] swiotlb: Add a new get_io_tlb_mem getter

2021-05-11 Thread Christoph Hellwig
> +static inline struct io_tlb_mem *get_io_tlb_mem(struct device *dev) > +{ > +#ifdef CONFIG_DMA_RESTRICTED_POOL > + if (dev && dev->dma_io_tlb_mem) > + return dev->dma_io_tlb_mem; > +#endif /* CONFIG_DMA_RESTRICTED_POOL */ > + > + return io_tlb_default_mem; Given that we're al

[Nouveau] [PATCH v6 05/15] swiotlb: Add a new get_io_tlb_mem getter

2021-05-11 Thread Claire Chang
Add a new getter, get_io_tlb_mem, to help select the io_tlb_mem struct. The restricted DMA pool is preferred if available. Signed-off-by: Claire Chang --- include/linux/swiotlb.h | 11 +++ 1 file changed, 11 insertions(+) diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h in

[Nouveau] [PATCH v6 01/15] swiotlb: Refactor swiotlb init functions

2021-05-11 Thread Claire Chang
Add a new function, swiotlb_init_io_tlb_mem, for the io_tlb_mem struct initialization to make the code reusable. Note that we now also call set_memory_decrypted in swiotlb_init_with_tbl. Signed-off-by: Claire Chang --- kernel/dma/swiotlb.c | 51 ++-- 1 fi

[Nouveau] [PATCH v6 12/15] swiotlb: Add restricted DMA alloc/free support.

2021-05-11 Thread Claire Chang
Add the functions, swiotlb_{alloc,free} to support the memory allocation from restricted DMA pool. Signed-off-by: Claire Chang --- include/linux/swiotlb.h | 4 kernel/dma/swiotlb.c| 35 +-- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/

[Nouveau] [PATCH v2 0/2] Fix ida leak and error return code

2021-05-11 Thread Zhen Lei
v1 --> v2: 1. Add Patch 1 to fix ida leak 2. Modifies nouveau_get_backlight_name() to propagate the actual error code Zhen Lei (2): drm/nouveau: Fix ida leak drm/nouveau: Fix error return code in nouveau_backlight_init() drivers/gpu/drm/nouveau/nouveau_backlight.c | 14 -- 1 file

[Nouveau] [PATCH v6 08/15] swiotlb: Bounce data from/to restricted DMA pool if available

2021-05-11 Thread Claire Chang
Regardless of swiotlb setting, the restricted DMA pool is preferred if available. The restricted DMA pools provide a basic level of protection against the DMA overwriting buffer contents at unexpected times. However, to protect against general data leakage and system memory corruption, the system

[Nouveau] [PATCH v2 1/2] drm/nouveau: Fix ida leak

2021-05-11 Thread Zhen Lei
When the 'nb' value allocated from 'bl_ida' is greater than or equal to 100, it will not be released. In fact, we can simplify operations by limiting the range of idas that can be applied for. By the way, delete the const modifier of the local variable 'nb'. Fixes: db1a0ae21461 ("drm/nouveau/bl:

[Nouveau] [PATCH v6 04/15] swiotlb: Add restricted DMA pool initialization

2021-05-11 Thread Claire Chang
Add the initialization function to create restricted DMA pools from matching reserved-memory nodes. Signed-off-by: Claire Chang --- include/linux/device.h | 4 +++ include/linux/swiotlb.h | 3 +- kernel/dma/swiotlb.c| 79 + 3 files changed, 85 inser

[Nouveau] [PATCH v6 14/15] dt-bindings: of: Add restricted DMA pool

2021-05-11 Thread Claire Chang
Introduce the new compatible string, restricted-dma-pool, for restricted DMA. One can specify the address and length of the restricted DMA memory region by restricted-dma-pool in the reserved-memory node. Signed-off-by: Claire Chang --- .../reserved-memory/reserved-memory.txt | 27

[Nouveau] [PATCH v2 2/2] drm/nouveau: Fix error return code in nouveau_backlight_init()

2021-05-11 Thread Zhen Lei
Fix to return a negative error code from the error handling case instead of 0, as done elsewhere in this function. Fixes: db1a0ae21461 ("drm/nouveau/bl: Assign different names to interfaces") Suggested-by: Pierre Moreau Signed-off-by: Zhen Lei --- drivers/gpu/drm/nouveau/nouveau_backlight.c | 9

Re: [Nouveau] [PATCH v5 00/16] Restricted DMA

2021-05-11 Thread Claire Chang
v6: https://lore.kernel.org/patchwork/cover/1423201/ ___ Nouveau mailing list Nouveau@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/nouveau

[Nouveau] [PATCH v6 03/15] swiotlb: Add DMA_RESTRICTED_POOL

2021-05-11 Thread Claire Chang
Add a new kconfig symbol, DMA_RESTRICTED_POOL, for restricted DMA pool. Signed-off-by: Claire Chang --- kernel/dma/Kconfig | 14 ++ 1 file changed, 14 insertions(+) diff --git a/kernel/dma/Kconfig b/kernel/dma/Kconfig index 77b405508743..3e961dc39634 100644 --- a/kernel/dma/Kconfig

Re: [Nouveau] [PATCH] drm/ttm: use dma_alloc_pages for the page pool

2021-05-11 Thread Christian König
Am 11.05.21 um 10:50 schrieb Christoph Hellwig: On Tue, May 11, 2021 at 09:35:20AM +0200, Christian König wrote: We certainly going to need the drm_need_swiotlb() for userptr support (unless we add some approach for drivers to opt out of swiotlb). swiotlb use is driven by three things: 1) ad

Re: [Nouveau] [PATCH] drm/ttm: use dma_alloc_pages for the page pool

2021-05-11 Thread Christoph Hellwig
On Tue, May 11, 2021 at 09:35:20AM +0200, Christian König wrote: > We certainly going to need the drm_need_swiotlb() for userptr support > (unless we add some approach for drivers to opt out of swiotlb). swiotlb use is driven by three things: 1) addressing limitations of the device 2) addressi

Re: [Nouveau] [PATCH] drm/ttm: use dma_alloc_pages for the page pool

2021-05-11 Thread Christian König
Am 11.05.21 um 08:05 schrieb Christoph Hellwig: Use the dma_alloc_pages allocator for the TTM pool allocator. This allocator is a front end to the page allocator which takes the DMA mask of the device into account, thus offering the best of both worlds of the two existing allocator versions. Thi