* [PATCH v2] ARM/dma-mapping: use kvcalloc for fallback memory allocation need
@ 2022-12-20 14:16 Deepak R Varma
2022-12-28 10:19 ` Deepak R Varma
0 siblings, 1 reply; 4+ messages in thread
From: Deepak R Varma @ 2022-12-20 14:16 UTC (permalink / raw)
To: Russell King, linux-arm-kernel, linux-kernel
Cc: Praveen Kumar, Saurabh Singh Sengar, Julia Lawall, drv
Current conditional determination of whether to use kzalloc or vzalloc
has known issues such as "indefinite retry" when less than PAGE_SIZE
memory is needed, but is unavailable. This LWN article [1] describes
these issues in greater detail. Use helper function kvcalloc() instead
which is more efficient in terms of performance and security.
[1] https://lwn.net/Articles/711653/
This patch proposal is based on following Coccinelle warning using the
kvmalloc.cocci semantic patch.
arch/arm/mm/dma-mapping.c:858:28-29: WARNING opportunity for kvmalloc
The semantic patch suggests using kvzalloc() helper function, however,
this patch proposes to use kvcalloc instead. kvcalloc() helper function
uses 2-factor argument form which is better from a security perspective
as described in the following KSPP project commit.
Commit 4e3fd7217105 ("wireguard: ratelimiter: use kvcalloc() instead of kvzalloc()")
Signed-off-by: Deepak R Varma <drv@mailo.com>
---
Changes in v2:
1. Update patch subject to use kvcalloc
2. Use kvcalloc instead of kvzalloc helper function. Revise the patch
proposal and the patch description accordingly.
arch/arm/mm/dma-mapping.c | 6 +-----
1 file changed, 1 insertion(+), 5 deletions(-)
diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c
index c135f6e37a00..35092ecd30e1 100644
--- a/arch/arm/mm/dma-mapping.c
+++ b/arch/arm/mm/dma-mapping.c
@@ -851,14 +851,10 @@ static struct page **__iommu_alloc_buffer(struct device *dev, size_t size,
{
struct page **pages;
int count = size >> PAGE_SHIFT;
- int array_size = count * sizeof(struct page *);
int i = 0;
int order_idx = 0;
- if (array_size <= PAGE_SIZE)
- pages = kzalloc(array_size, GFP_KERNEL);
- else
- pages = vzalloc(array_size);
+ pages = kvcalloc(count, sizeof(struct page *), GFP_KERNEL);
if (!pages)
return NULL;
--
2.34.1
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v2] ARM/dma-mapping: use kvcalloc for fallback memory allocation need
2022-12-20 14:16 [PATCH v2] ARM/dma-mapping: use kvcalloc for fallback memory allocation need Deepak R Varma
@ 2022-12-28 10:19 ` Deepak R Varma
2023-01-03 10:19 ` Russell King (Oracle)
0 siblings, 1 reply; 4+ messages in thread
From: Deepak R Varma @ 2022-12-28 10:19 UTC (permalink / raw)
To: Russell King, linux-arm-kernel, linux-kernel
Cc: Praveen Kumar, Saurabh Singh Sengar, Julia Lawall, Deepak R Varma
On Tue, Dec 20, 2022 at 07:46:32PM +0530, Deepak R Varma wrote:
> Current conditional determination of whether to use kzalloc or vzalloc
> has known issues such as "indefinite retry" when less than PAGE_SIZE
> memory is needed, but is unavailable. This LWN article [1] describes
> these issues in greater detail. Use helper function kvcalloc() instead
> which is more efficient in terms of performance and security.
>
> [1] https://lwn.net/Articles/711653/
>
> This patch proposal is based on following Coccinelle warning using the
> kvmalloc.cocci semantic patch.
> arch/arm/mm/dma-mapping.c:858:28-29: WARNING opportunity for kvmalloc
>
> The semantic patch suggests using kvzalloc() helper function, however,
> this patch proposes to use kvcalloc instead. kvcalloc() helper function
> uses 2-factor argument form which is better from a security perspective
> as described in the following KSPP project commit.
>
> Commit 4e3fd7217105 ("wireguard: ratelimiter: use kvcalloc() instead of kvzalloc()")
>
> Signed-off-by: Deepak R Varma <drv@mailo.com>
Hello,
May I please request a review and feedback on this patch proposal?
Thank you,
./drv
> ---
>
> Changes in v2:
> 1. Update patch subject to use kvcalloc
> 2. Use kvcalloc instead of kvzalloc helper function. Revise the patch
> proposal and the patch description accordingly.
>
>
> arch/arm/mm/dma-mapping.c | 6 +-----
> 1 file changed, 1 insertion(+), 5 deletions(-)
>
> diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c
> index c135f6e37a00..35092ecd30e1 100644
> --- a/arch/arm/mm/dma-mapping.c
> +++ b/arch/arm/mm/dma-mapping.c
> @@ -851,14 +851,10 @@ static struct page **__iommu_alloc_buffer(struct device *dev, size_t size,
> {
> struct page **pages;
> int count = size >> PAGE_SHIFT;
> - int array_size = count * sizeof(struct page *);
> int i = 0;
> int order_idx = 0;
>
> - if (array_size <= PAGE_SIZE)
> - pages = kzalloc(array_size, GFP_KERNEL);
> - else
> - pages = vzalloc(array_size);
> + pages = kvcalloc(count, sizeof(struct page *), GFP_KERNEL);
> if (!pages)
> return NULL;
>
> --
> 2.34.1
>
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] ARM/dma-mapping: use kvcalloc for fallback memory allocation need
2022-12-28 10:19 ` Deepak R Varma
@ 2023-01-03 10:19 ` Russell King (Oracle)
2023-01-03 10:48 ` Deepak R Varma
0 siblings, 1 reply; 4+ messages in thread
From: Russell King (Oracle) @ 2023-01-03 10:19 UTC (permalink / raw)
To: Deepak R Varma
Cc: linux-arm-kernel, linux-kernel, Praveen Kumar,
Saurabh Singh Sengar, Julia Lawall
On Wed, Dec 28, 2022 at 03:49:44PM +0530, Deepak R Varma wrote:
> On Tue, Dec 20, 2022 at 07:46:32PM +0530, Deepak R Varma wrote:
> > Current conditional determination of whether to use kzalloc or vzalloc
> > has known issues such as "indefinite retry" when less than PAGE_SIZE
> > memory is needed, but is unavailable. This LWN article [1] describes
> > these issues in greater detail. Use helper function kvcalloc() instead
> > which is more efficient in terms of performance and security.
> >
> > [1] https://lwn.net/Articles/711653/
> >
> > This patch proposal is based on following Coccinelle warning using the
> > kvmalloc.cocci semantic patch.
> > arch/arm/mm/dma-mapping.c:858:28-29: WARNING opportunity for kvmalloc
> >
> > The semantic patch suggests using kvzalloc() helper function, however,
> > this patch proposes to use kvcalloc instead. kvcalloc() helper function
> > uses 2-factor argument form which is better from a security perspective
> > as described in the following KSPP project commit.
> >
> > Commit 4e3fd7217105 ("wireguard: ratelimiter: use kvcalloc() instead of kvzalloc()")
> >
> > Signed-off-by: Deepak R Varma <drv@mailo.com>
>
> Hello,
> May I please request a review and feedback on this patch proposal?
The DMA API on ARM has been maintained by others recently, so it's no
longer up to me. Please include Christoph Hellwig <hch@lst.de> when
sending changes for this. Thanks.
--
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last!
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] ARM/dma-mapping: use kvcalloc for fallback memory allocation need
2023-01-03 10:19 ` Russell King (Oracle)
@ 2023-01-03 10:48 ` Deepak R Varma
0 siblings, 0 replies; 4+ messages in thread
From: Deepak R Varma @ 2023-01-03 10:48 UTC (permalink / raw)
To: Russell King (Oracle)
Cc: linux-arm-kernel, linux-kernel, Praveen Kumar,
Saurabh Singh Sengar, Julia Lawall, Deepak R Varma
On Tue, Jan 03, 2023 at 10:19:20AM +0000, Russell King (Oracle) wrote:
> On Wed, Dec 28, 2022 at 03:49:44PM +0530, Deepak R Varma wrote:
> > On Tue, Dec 20, 2022 at 07:46:32PM +0530, Deepak R Varma wrote:
> > > Current conditional determination of whether to use kzalloc or vzalloc
> > > has known issues such as "indefinite retry" when less than PAGE_SIZE
> > > memory is needed, but is unavailable. This LWN article [1] describes
> > > these issues in greater detail. Use helper function kvcalloc() instead
> > > which is more efficient in terms of performance and security.
> > >
> > > [1] https://lwn.net/Articles/711653/
> > >
> > > This patch proposal is based on following Coccinelle warning using the
> > > kvmalloc.cocci semantic patch.
> > > arch/arm/mm/dma-mapping.c:858:28-29: WARNING opportunity for kvmalloc
> > >
> > > The semantic patch suggests using kvzalloc() helper function, however,
> > > this patch proposes to use kvcalloc instead. kvcalloc() helper function
> > > uses 2-factor argument form which is better from a security perspective
> > > as described in the following KSPP project commit.
> > >
> > > Commit 4e3fd7217105 ("wireguard: ratelimiter: use kvcalloc() instead of kvzalloc()")
> > >
> > > Signed-off-by: Deepak R Varma <drv@mailo.com>
> >
> > Hello,
> > May I please request a review and feedback on this patch proposal?
>
> The DMA API on ARM has been maintained by others recently, so it's no
> longer up to me. Please include Christoph Hellwig <hch@lst.de> when
> sending changes for this. Thanks.
Sure. Actually the get_maintainer.pl scripts still returns yourself as the
maintainer for this driver. Hence the email to you.
I will send a v3 and include the change you asked for. I will keep you in cc if
you don't mind.
Also, let me know if I can help with getting the maintainer list updated for
this core subsystem.
Thank you,
./drv
>
> --
> RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
> FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last!
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-01-03 15:30 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-12-20 14:16 [PATCH v2] ARM/dma-mapping: use kvcalloc for fallback memory allocation need Deepak R Varma
2022-12-28 10:19 ` Deepak R Varma
2023-01-03 10:19 ` Russell King (Oracle)
2023-01-03 10:48 ` Deepak R Varma
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).