Nouveau Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Jani Nikula <jani.nikula@linux.intel.com>
To: duoming@zju.edu.cn
Cc: Timur Tabi <timur@kernel.org>,
	nouveau@lists.freedesktop.org, dri-devel@lists.freedesktop.org
Subject: Re: [PATCH] nouveau/dmem: handle kcalloc() allocation failure
Date: Tue, 05 Mar 2024 15:26:41 +0200	[thread overview]
Message-ID: <87a5nc3j3i.fsf@intel.com> (raw)
In-Reply-To: <601512f5.b287.18e0ebb25d4.Coremail.duoming@zju.edu.cn>

On Tue, 05 Mar 2024, duoming@zju.edu.cn wrote:
> On Mon, 04 Mar 2024 14:14:52 +0200 Jani Nikula wrote:
>> >> The kcalloc() in nouveau_dmem_evict_chunk() will return null if
>> >> the physical memory has run out. As a result, if we dereference
>> >> src_pfns, dst_pfns or dma_addrs, the null pointer dereference bugs
>> >> will happen.
>> >>
>> >> This patch uses stack variables to replace the kcalloc().
>> >
>> > Won't this blow the stack?  And why not just test the return value of
>> > kcalloc?
>> 
>> VLAs should not be used in the kernel anymore. Building this results in
>> a warning due to -Wvla. See 0bb95f80a38f ("Makefile: Globally enable VLA
>> warning").
>> 
>> Error checking and propagation is the way to go.
>
> The GPU is going away. If the kcalloc() in nouveau_dmem_evict_chunk() fail,
> we could not evict all pages mapping a chunk. Do you think we should add a
> __GFP_NOFAIL flag in kcalloc()? I see the __GFP_NOFAIL flag is used in the
> following code:
>
> /*
> * _GFP_NOFAIL because the GPU is going away and there
> * is nothing sensible we can do if we can't copy the
> * data back.
> */
> dpage = alloc_page(GFP_HIGHUSER | __GFP_NOFAIL);

This is all up to the nouveau maintainers, really. All I'm saying is
that VLA isn't the solution you're looking for.

BR,
Jani.


-- 
Jani Nikula, Intel

  reply	other threads:[~2024-03-05 13:26 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-03  8:13 [PATCH] nouveau/dmem: handle kcalloc() allocation failure Duoming Zhou
2024-03-04  3:02 ` Timur Tabi
2024-03-04 12:14   ` Jani Nikula
2024-03-05 13:08     ` duoming
2024-03-05 13:26       ` Jani Nikula [this message]
     [not found] <20240303075312.56349-1-duoming@zju.edu.cn>
2024-03-05 13:40 ` Danilo Krummrich

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87a5nc3j3i.fsf@intel.com \
    --to=jani.nikula@linux.intel.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=duoming@zju.edu.cn \
    --cc=nouveau@lists.freedesktop.org \
    --cc=timur@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox