linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: imran.f.khan@oracle.com
To: Vlastimil Babka <vbabka@suse.cz>,
	geert@linux-m68k.org, akpm@linux-foundation.org
Cc: linux-kernel@vger.kernel.org,
	"linux-mm@kvack.org" <linux-mm@kvack.org>,
	Alexander Potapenko <glider@google.com>
Subject: Re: [RFC PATCH 1/2] lib, stackdepot: check stackdepot handle before accessing slabs.
Date: Thu, 2 Sep 2021 10:12:58 +1000	[thread overview]
Message-ID: <b91439ae-8827-6d03-47be-4fa236cfd1ce@oracle.com> (raw)
In-Reply-To: <78d24243-9d92-43fd-92b5-17b88cc24314@suse.cz>



On 1/9/21 6:58 pm, Vlastimil Babka wrote:
> +CC linux-mm, Alex
> 
> On 9/1/21 07:19, Imran Khan wrote:
>> stack_depot_save allocates slabs that will be used for storing
>> objects in future.If this slab allocation fails we may get to
>> a situation where space allocation for a new stack_record fails,
>> causing stack_depot_save to return 0 as handle.
>> If user of this handle ends up invoking stack_depot_fetch with
>> this handle value, current implementation of stack_depot_fetch
>> will end up using slab from wrong index.
>> To avoid this check handle value at the beginning.
>> Also issue a warning for nil handle values and when slab allocation
>> for stackdepot fails for the first time.
>>
>> Signed-off-by: Imran Khan <imran.f.khan@oracle.com>
>> Suggested-by: Vlastimil Babka <vbabka@suse.cz>
> 
> Agree but without the warnings please, especially the "stack depot handle is
> absent" one. It's just something that can happen e.g. in GFP_NOWAIT contexts
> and no need to spam dmesg.
> 

Okay. I have removed warnings in v2 of patch set.

>> ---
>>   lib/stackdepot.c | 6 ++++++
>>   1 file changed, 6 insertions(+)
>>
>> diff --git a/lib/stackdepot.c b/lib/stackdepot.c
>> index 0a2e417f83cb..1d42ef9ef766 100644
>> --- a/lib/stackdepot.c
>> +++ b/lib/stackdepot.c
>> @@ -232,6 +232,10 @@ unsigned int stack_depot_fetch(depot_stack_handle_t handle,
>>   	struct stack_record *stack;
>>   
>>   	*entries = NULL;
>> +	if (!handle) {
>> +		WARN(1, "stack depot handle is absent.\n");
>> +		return 0;
>> +	}
>>   	if (parts.slabindex > depot_index) {
>>   		WARN(1, "slab index %d out of bounds (%d) for stack id %08x\n",
>>   			parts.slabindex, depot_index, handle);
>> @@ -303,6 +307,8 @@ depot_stack_handle_t stack_depot_save(unsigned long *entries,
>>   		page = alloc_pages(alloc_flags, STACK_ALLOC_ORDER);
>>   		if (page)
>>   			prealloc = page_address(page);
>> +		else
>> +			WARN_ONCE(1, "slab allocation for stack depot failed.\n");
>>   	}
>>   
>>   	raw_spin_lock_irqsave(&depot_lock, flags);
>>
> 
Thanks for reviewing this.

--Imran

  reply	other threads:[~2021-09-02  0:13 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-01  5:19 [RFC PATCH 0/2] lib, stackdepot: check stackdepot handle before accessing slabs Imran Khan
2021-09-01  5:19 ` [RFC PATCH 1/2] " Imran Khan
2021-09-01  8:58   ` Vlastimil Babka
2021-09-02  0:12     ` imran.f.khan [this message]
2021-09-01  5:19 ` [RFC PATCH 2/2] lib, stackdepot: Add helper to print stack entries Imran Khan
2021-09-01  9:07   ` Vlastimil Babka
2021-09-02  0:11     ` imran.f.khan
2021-09-02  8:00       ` Vlastimil Babka

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=b91439ae-8827-6d03-47be-4fa236cfd1ce@oracle.com \
    --to=imran.f.khan@oracle.com \
    --cc=akpm@linux-foundation.org \
    --cc=geert@linux-m68k.org \
    --cc=glider@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=vbabka@suse.cz \
    /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;
as well as URLs for NNTP newsgroup(s).