From patchwork Mon Aug 2 18:08:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shakeel Butt X-Patchwork-Id: 12414501 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=-26.2 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT,USER_IN_DEF_DKIM_WL 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 F2161C4338F for ; Mon, 2 Aug 2021 18:08:52 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 90920610A2 for ; Mon, 2 Aug 2021 18:08:52 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 90920610A2 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 9E4996B0033; Mon, 2 Aug 2021 14:08:51 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 994C06B0036; Mon, 2 Aug 2021 14:08:51 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 85CD66B005D; Mon, 2 Aug 2021 14:08:51 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0167.hostedemail.com [216.40.44.167]) by kanga.kvack.org (Postfix) with ESMTP id 692196B0033 for ; Mon, 2 Aug 2021 14:08:51 -0400 (EDT) Received: from smtpin03.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 0E2FF18027679 for ; Mon, 2 Aug 2021 18:08:51 +0000 (UTC) X-FDA: 78430926462.03.11B415A Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) by imf14.hostedemail.com (Postfix) with ESMTP id BDC376004184 for ; Mon, 2 Aug 2021 18:08:50 +0000 (UTC) Received: by mail-pj1-f73.google.com with SMTP id o13-20020a17090a9f8db0290177972c9adeso8554568pjp.5 for ; Mon, 02 Aug 2021 11:08:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:message-id:mime-version:subject:from:to:cc; bh=j+JSAL2TyTO06rmOJxXfenDO1JaBiOx8vJieMlI9pfs=; b=UcuHbh2lDaqGs/MbwByb6nz+B/co5nzT1R6NZhmA9NdIsZ040uo8xyHQh0XBBND7N5 FI3HwlivUGntgnh0D27Em+HiAYwCVDKhqhfH8YZqQr00B7tzgf1u57utnYjG6aBwlvLF zFfPvhhCPnxnqP3fbByF+3iehSxCd4BIkM9ceagxD6y9bOjLtC0LxoDDrFvIVYdK6RUz W6vlGioEeNf8j8C4Zerh4WMqwFyKa206rBGYI+IDnAWVAHEZrfbfIqzVOHQfXRNGygq5 9DkbD0DIugA89cd7d6aIje5OBCTvhjnYkYEirB168/1Atr4V9lq2mK4GRyUBBX6ij9wm +FEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=j+JSAL2TyTO06rmOJxXfenDO1JaBiOx8vJieMlI9pfs=; b=tJDu8K05K8wBNIZZ7sFNYioQx0pR/SJ2X37OWnCJ1rUByyG/Z8IvukWB6zJymPq07q uXuaMoERLGqivONL3GBfTmWkjNguGGlvmMXm4oXnQJjG7PYk2uNAAzs4j+vE8KZ902uo tJxTIaPNysX47CqCLNbdMm2GgkCWO1fer/Hofom1IGxKbcllNYA81vTC+HA4q4+MOiOr pqETa2SeNCzKhkqc10bWAS1t+AiE8LfkARC0PvMLpTncjeSlKm94s0+DDwQxCCRvjxSX 8oJssq52nrC/NrJoKFx4qBm/mSgcC4m3jkoNCxGszS1UCBFivZ0USY9c+wi6jZ3WKMlq TJdw== X-Gm-Message-State: AOAM531yLTDBMfdP7xKy0LkuKpcUadMzzmghPTh0S71M0WdG7X2o92hO JYR1qLDgwgKcin1v7KXGmMBbeWI60eEx/w== X-Google-Smtp-Source: ABdhPJyd4GLuBK30tc+5jzFp8zuC3MlneqxzEE85Lh3H94nGR7V9ZsC5tnunYlguKVQtH2odY7sLIdyuQCtq3Q== X-Received: from shakeelb.svl.corp.google.com ([2620:15c:2cd:202:75f8:2e73:f9c:f799]) (user=shakeelb job=sendgmr) by 2002:a17:90b:3d6:: with SMTP id go22mr18047527pjb.40.1627927729598; Mon, 02 Aug 2021 11:08:49 -0700 (PDT) Date: Mon, 2 Aug 2021 11:08:18 -0700 Message-Id: <20210802180819.1110165-1-shakeelb@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.32.0.554.ge1b32706d8-goog Subject: [PATCH] slub: fix kmalloc_pagealloc_invalid_free unit test From: Shakeel Butt To: Christoph Lameter , Pekka Enberg , David Rientjes , Vlastimil Babka Cc: Michal Hocko , Roman Gushchin , Wang Hai , Muchun Song , Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Shakeel Butt , Nathan Chancellor , Joonsoo Kim Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=google.com header.s=20161025 header.b=UcuHbh2l; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf14.hostedemail.com: domain of 3sTQIYQgKCEo4tmwqqxns00sxq.o0yxuz69-yyw7mow.03s@flex--shakeelb.bounces.google.com designates 209.85.216.73 as permitted sender) smtp.mailfrom=3sTQIYQgKCEo4tmwqqxns00sxq.o0yxuz69-yyw7mow.03s@flex--shakeelb.bounces.google.com X-Stat-Signature: qhokiq6pdxu16dpn96d7nskrpfkey7zt X-Rspamd-Queue-Id: BDC376004184 X-Rspamd-Server: rspam01 X-HE-Tag: 1627927730-785624 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: 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 Tested-by: Nathan Chancellor Acked-by: Roman Gushchin --- 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_);