From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D59C836A033 for ; Tue, 4 Aug 2026 00:39:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785803978; cv=none; b=b27Lpco5D+gd9Fo6tbRGhd/LZneJ7ch5Ebw2EXMYArvBnaczZRAejWSpgPJxOBhItpmWB4eyGvXxfh9f61a/91FpziWv/0am4ovbwAfIm7nMJfWU4YhAnXYp352jKnQq1CPHUCZ78eyNdynO8asM6brEbXPIDaha3GtgM2LEGT8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785803978; c=relaxed/simple; bh=99V5cKIfESykWuezPvadendt+aYgqTBBT1k+hNNOYC4=; h=Date:From:To:Cc:Subject:Message-Id:In-Reply-To:References: Mime-Version:Content-Type; b=ubFfyX8WrMSzpVJ0+4wZyQfHwRQPa/GtCEryrOO5XiwSltyEM9GRMAG5nsamGTWkYEQ5a3FiWmjx+sA47XEJMmcsbDAc36iY//pVZxf+K+W30CRteYwmivvpsY+Ku1ZQccDOvYNv7bt58IqXt1kjhhDbtHYoorJtusSXaZLt9MY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b=DlvSKUc+; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b="DlvSKUc+" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2DC361F000E9; Tue, 4 Aug 2026 00:39:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=korg; t=1785803976; bh=NBixw/d6HA9fsIHjVOC8TKnF1tclRjfp4GIg/F08u3A=; h=Date:From:To:Cc:Subject:In-Reply-To:References; b=DlvSKUc+Vsrtfye61sNEFPlB3usZCSqALGCQPb1/D5dfxdteOTivfEVFbplTGk0t0 iqeTdvPezt0pEJSH4KqWR97fClBrd6Ql8qdLIrcK4YWVynH+7SgUczzbEpfsMKbmQA zDHJrksbcl7IG1jhy9gzimA7ob9Gz1MZ/8I3RwzA= Date: Mon, 3 Aug 2026 17:39:35 -0700 From: Andrew Morton To: Uladzislau Rezki Cc: Artem Lytkin , linux-mm@kvack.org, willy@infradead.org, shivamkalra98@zohomail.in, linux-kernel@vger.kernel.org Subject: Re: [PATCH v4] mm/vmalloc: make vm_struct.nr_pages an unsigned long Message-Id: <20260803173935.132156ba2b86293ffecb0e8f@linux-foundation.org> In-Reply-To: References: <20260730130923.9e71be5f477ee3db333cf0f8@linux-foundation.org> <20260801114915.115224-1-iprintercanon@gmail.com> <20260801115202.ccba41ddac9f7a4f6fb1ca9f@linux-foundation.org> X-Mailer: Sylpheed 3.8.0beta1 (GTK+ 2.24.33; x86_64-pc-linux-gnu) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Sun, 2 Aug 2026 17:52:26 +0200 Uladzislau Rezki wrote: > On Sat, Aug 01, 2026 at 11:52:02AM -0700, Andrew Morton wrote: > > On Sat, 1 Aug 2026 14:49:15 +0300 Artem Lytkin wrote: > > > > ... > > > Ulad, AI review suggests that vrealloc() has an issue handling > > __GFP_ZERO. Can you please check? > > > > https://sashiko.dev/#/patchset/20260801114915.115224-1-iprintercanon@gmail.com > > > I have checked. I think the AI is missing at least one point. > AI argument which is: > > > If a driver initially allocates memory using vmalloc() without __GFP_ZERO > (leaving spare page capacity uninitialized), and then grows the allocation > using vrealloc() with __GFP_ZERO, the caller expects the newly exposed bytes > to be zeroed. > > > In the vrealloc_node_align_noprof() header documentation there is a statement: > > > * If __GFP_ZERO logic is requested, callers must ensure that, starting with the > * initial memory allocation, every subsequent call to this API for the same > * memory allocation is flagged with __GFP_ZERO. Otherwise, it is possible that > * __GFP_ZERO is not fully honored by this API. > > > AI argument violates the documentation, i.e. mixing __GFP_ZERO is not allowed. Sashiko is talking about the initial allocation not using __GFP_ZERO but vrealloc() *does* use __GFP_ZERO. The documentation you quoted doesn't address that case? Also, developers don't read documentation ;) What happens if some caller *does* use vmalloc(!__GFP_ZERO) then vrealloc(__GFP_ZERO)? Silent misbehavior would be bad - it would be good if vrealloc() were to drop a WARN() then ignore the __GFP_ZERO. > --- a/mm/vmalloc.c > +++ b/mm/vmalloc.c > @@ -4294,11 +4294,6 @@ EXPORT_SYMBOL(vzalloc_node_noprof); > * __GFP_THISNODE flag should be set, otherwise the function will try to avoid > * reallocation and possibly disregard the specified @nid. > * > - * If __GFP_ZERO logic is requested, callers must ensure that, starting with the > - * initial memory allocation, every subsequent call to this API for the same > - * memory allocation is flagged with __GFP_ZERO. Otherwise, it is possible that > - * __GFP_ZERO is not fully honored by this API. > - * > * Requesting an alignment that is bigger than the alignment of the existing > * allocation will fail. > * > @@ -4415,13 +4410,12 @@ void *vrealloc_node_align_noprof(const void *p, size_t size, unsigned long align > * We already have the bytes available in the allocation; use them. > */ > if (size <= vm->nr_pages << PAGE_SHIFT) { > - /* > - * No need to zero memory here, as unused memory will have > - * already been zeroed at initial allocation time or during > - * realloc shrink time. > - */ > - vm->requested_size = size; > kasan_vrealloc(p, old_size, size); > + > + if (want_init_on_alloc(flags)) > + memset((void *)p + old_size, 0, size - old_size); > + > + vm->requested_size = size; > return (void *)p; > } OK, thanks, I'll assume you'll prepare this for real when convenient.