Received: by 2002:a05:6a10:c7c6:0:0:0:0 with SMTP id h6csp2015238pxy; Mon, 2 Aug 2021 16:53:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzCFc9G/wlqBh1kM9IFd2W8YjG2PPV29ZK6nWHSeJIIjuOoRNUvpI7NhNJKwVQwjzFvfC9Y X-Received: by 2002:a02:5bc5:: with SMTP id g188mr13937427jab.136.1627948407620; Mon, 02 Aug 2021 16:53:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627948407; cv=none; d=google.com; s=arc-20160816; b=yftWWUxBUi5Wm7YVtTfZHKfo1acqorCEybvsD+Et4hqrDXdtC9DQSMiIhKXo9V0/VG DBpson3FB5sM4qDAC7GOWZ9/rzmcvbTKidkB0nYB4z1rBouFFlZ/4BOsoimnqLtGPNIH 4Fhf54VJhn6GQqZdno2vYu61xezamXE1Et11pRMiPOzv3Y56cwoKW1RbmHn+n5aQ1nWs 4HVQcI2/P64eC60yga2NmfHD248Fdijs3E2r4AISa5XHEl1lE7WP++O5cSCTnxi0vdkN eVCwO7rFNOLrezjTFwbCceYYduGZExXdb0uibr6biTgVH4XFqNBBmSWwhtjitm9SGucd omLw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=5wSlAfcjVYMY/AMbD3y+w2gqEByrt72uWXP5iEKwQWA=; b=XvyeqQSDyedhq/ayDdqyhyi3X1LLiIrs4swPp5m9fhzyIsRRVSlbQLwOl6wHZIX4y8 YGdfBiLQ+7+8RKP+V/no4TMDu9uEtd8bWvN50rgxmM9+/DkeB2j9E/5bKq8vMDVaf5tV o1Kh7xOlDpSYn0ywirsXvFB0MdBqNVtusr87qmhfWPbyNlbXV6XGXL2q4VON8GhSyFYI OGUVSfox8/mxQze7AEHbW9UWExSYkZoqmt9qb0PW+VjdlqfgNlrkI9ol1MX29YO2WJDk vaaoyn/Amsfv3cfXid7IW35yilYnCHjLOvflr8i0i55Bs8UGDo0Ll2m601d3XUmwOMTe pEBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=OAgsx2AO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t13si13091335ilg.9.2021.08.02.16.53.15; Mon, 02 Aug 2021 16:53:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=OAgsx2AO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232634AbhHBXwj (ORCPT + 99 others); Mon, 2 Aug 2021 19:52:39 -0400 Received: from mail.kernel.org ([198.145.29.99]:48894 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232208AbhHBXwi (ORCPT ); Mon, 2 Aug 2021 19:52:38 -0400 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> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 > >