From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AD8C9C4338F for ; Mon, 2 Aug 2021 23:52:31 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 4370760F01 for ; Mon, 2 Aug 2021 23:52:31 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 4370760F01 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id B98EB6B0033; Mon, 2 Aug 2021 19:52:30 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B6F366B0036; Mon, 2 Aug 2021 19:52:30 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A85616B005D; Mon, 2 Aug 2021 19:52:30 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0144.hostedemail.com [216.40.44.144]) by kanga.kvack.org (Postfix) with ESMTP id 925726B0033 for ; Mon, 2 Aug 2021 19:52:30 -0400 (EDT) Received: from smtpin07.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 34C4D8249980 for ; Mon, 2 Aug 2021 23:52:30 +0000 (UTC) X-FDA: 78431792460.07.616B6DF Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf11.hostedemail.com (Postfix) with ESMTP id C583FF0036D0 for ; Mon, 2 Aug 2021 23:52:29 +0000 (UTC) Received: by mail.kernel.org (Postfix) with ESMTPSA id 91C0560EE6; Mon, 2 Aug 2021 23:52:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1627948348; bh=9vSRnJfBD9lgwL64I4OrHlQlDF+8XGMW3KrAv+VkKj0=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=OAgsx2AOzYLQuNhnaD5z8l1cBuS4mwMxRGJ1FNW72cMu97jxC9Vvm44KfqSNjV8qo rDqHCGffC1zTInM+yutb8XZAEkj1jU/AXjiF8wwpqjbcxlAbP4UpKm/gjxRo/gJ20y lcI0kzdhKCH8N4rfvX/JS2O/M3B//quUMB5NSaM5xDa24Qlvz3Z2KAEBFrbv8F0iwf 74OJJZR7vWzg2EIK8O3bTVECMSoRB+aK2rX7otyGqOQyskHtgRHU4T9II/zo3/OMaE j0nb5EFslvZy1V4x2h2CHxs76ov1SOtpHq9e3NHnmVJ29MbItWhBiXgngUDiJ4owcI K1TWatoBAaF0w== Date: Mon, 2 Aug 2021 16:52:23 -0700 From: Nathan Chancellor To: Shakeel Butt Cc: Christoph Lameter , Pekka Enberg , David Rientjes , Vlastimil Babka , Michal Hocko , Roman Gushchin , Wang Hai , Muchun Song , Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Joonsoo Kim Subject: Re: [PATCH] slub: fix kmalloc_pagealloc_invalid_free unit test Message-ID: References: <20210802180819.1110165-1-shakeelb@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210802180819.1110165-1-shakeelb@google.com> X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: C583FF0036D0 Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=OAgsx2AO; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf11.hostedemail.com: domain of nathan@kernel.org designates 198.145.29.99 as permitted sender) smtp.mailfrom=nathan@kernel.org X-Stat-Signature: s716o3qb1j7a73yjeqjx3gwj3abe8b1g X-HE-Tag: 1627948349-754808 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Mon, Aug 02, 2021 at 11:08:18AM -0700, Shakeel Butt wrote: > The unit test kmalloc_pagealloc_invalid_free makes sure that for the > higher order slub allocation which goes to page allocator, the free is > called with the correct address i.e. the virtual address of the head > page. > > The commit f227f0faf63b ("slub: fix unreclaimable slab stat for bulk > free") unified the free code paths for page allocator based slub > allocations but instead of using the address passed by the caller, it > extracted the address from the page. Thus making the unit test > kmalloc_pagealloc_invalid_free moot. So, fix this by using the address > passed by the caller. > > Should we fix this? I think yes because dev expect kasan to catch these > type of programming bugs. > > Fixes: f227f0faf63b ("slub: fix unreclaimable slab stat for bulk free") > Signed-off-by: Shakeel Butt > Reported-by: Nathan Chancellor > Cc: Michal Hocko > Cc: Roman Gushchin > Cc: Muchun Song > Cc: Christoph Lameter > Cc: Pekka Enberg > Cc: David Rientjes > Cc: Joonsoo Kim > Cc: Vlastimil Babka > Cc: Andrew Morton Thank you for the quick fix! It passes my tests on arm64 and x86_64 in QEMU with a few different clang versions. Tested-by: Nathan Chancellor > --- > mm/slub.c | 8 ++++---- > 1 file changed, 4 insertions(+), 4 deletions(-) > > diff --git a/mm/slub.c b/mm/slub.c > index af984e4990e8..60aeedc436d5 100644 > --- a/mm/slub.c > +++ b/mm/slub.c > @@ -3236,12 +3236,12 @@ struct detached_freelist { > struct kmem_cache *s; > }; > > -static inline void free_nonslab_page(struct page *page) > +static inline void free_nonslab_page(struct page *page, void *object) > { > unsigned int order = compound_order(page); > > VM_BUG_ON_PAGE(!PageCompound(page), page); > - kfree_hook(page_address(page)); > + kfree_hook(object); > mod_lruvec_page_state(page, NR_SLAB_UNRECLAIMABLE_B, -(PAGE_SIZE << order)); > __free_pages(page, order); > } > @@ -3282,7 +3282,7 @@ int build_detached_freelist(struct kmem_cache *s, size_t size, > if (!s) { > /* Handle kalloc'ed objects */ > if (unlikely(!PageSlab(page))) { > - free_nonslab_page(page); > + free_nonslab_page(page, object); > p[size] = NULL; /* mark object processed */ > return size; > } > @@ -4258,7 +4258,7 @@ void kfree(const void *x) > > page = virt_to_head_page(x); > if (unlikely(!PageSlab(page))) { > - free_nonslab_page(page); > + free_nonslab_page(page, object); > return; > } > slab_free(page->slab_cache, page, object, NULL, 1, _RET_IP_); > -- > 2.32.0.554.ge1b32706d8-goog > >