Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp4982696pxb; Tue, 28 Sep 2021 08:12:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyc+A7i9gbontJE28AZ/AnhlSvsfIp4DyJr94OBMffVg6ikdnux0Cqtn6kn20vmSUeCpaDe X-Received: by 2002:a63:e741:: with SMTP id j1mr5127423pgk.86.1632841957800; Tue, 28 Sep 2021 08:12:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632841957; cv=none; d=google.com; s=arc-20160816; b=vWdfrTgeh5+Z6568RVRcuA1otKUjNTiy4C+6qP5w3dJ51SmJXc8LmID7pRoX2nO8Qp LW2cIMAZqHsyX1bJ3SBtNHj1hFkzllO89/q7b9lb89UOLzhA0sdoUJHeP0+Fljpsm3BL bhgR2jNCqK0DUspDKRqmije9c2p091YuiKEMVM8/Mbrd/DVfJjO6K14aqMW6lLRsJml0 dqLco1krSFLwSzSWKmomNAM3XMS4QnVMwI24xdBYzvCkzEEpxmIx/UtKH0owR2pdTaB2 cJRNwY3wfryBQEL46cjpuctUNI6sPcMMPapoE51uhVwGqBmXlKBi/OFNPEOSRpjv4qRD EUWw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=gd9aW239q/YhSWzuMjswj8d/RtAC3PBQOLCe3Y0Z9ys=; b=HWkHnHEb/ySYJJrnK5gZFU7hnF2rlYt34Z5oVdh87nrAzk5bZcnNf5JMyqKzeOwFUl 4h0zjbHJftm/FELKkeponrx6DukQ05aXUeN7vq9fhLR9FbEcINE1VibItDn7sYEA3SsD rnLQU13YrUIT3oVSA4DcMygQqu7FyxzdbYW2Fh83h3h/kJwYHKF7wh0f5QeRAwcRFCvg Jt9496j1nfZQ285ZiuvJwP41fnMTTWuSCCe8jxGuiU3AW6NaqCgPpi77IBC45kd55Ysi QoSlkga/DrL31/d6AyhZ6+ErEVKtAAXKILNvJyqSEMah9NOv59hHDSg/POmfb8FLRUq5 HCLg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=fL1b2vio; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m24si16521257pls.262.2021.09.28.08.12.20; Tue, 28 Sep 2021 08:12:37 -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=@google.com header.s=20210112 header.b=fL1b2vio; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241495AbhI1PLP (ORCPT + 99 others); Tue, 28 Sep 2021 11:11:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33652 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241511AbhI1PLL (ORCPT ); Tue, 28 Sep 2021 11:11:11 -0400 Received: from mail-lf1-x136.google.com (mail-lf1-x136.google.com [IPv6:2a00:1450:4864:20::136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 37026C061746 for ; Tue, 28 Sep 2021 08:09:31 -0700 (PDT) Received: by mail-lf1-x136.google.com with SMTP id y26so54727568lfa.11 for ; Tue, 28 Sep 2021 08:09:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=gd9aW239q/YhSWzuMjswj8d/RtAC3PBQOLCe3Y0Z9ys=; b=fL1b2viol9Jp98joQ5vyJowkZz6IP2I8rZ4pv5qfA6Lg1eYEdwrcLte/1JTWSFPoMp AqgnpWbzqHiSsJbKJrUAmsLif2LBakQaiJwUveTr9YXGY7HLqpghGB9dmrcLZSL11xW8 Ob6xDbiNBUrVlDctmCEpOjsUOsgaBlLpnz9I6fFR7c9R5I7xHNpvwTATvGL1mwyCJfd2 RmGt+c22QiEPp0RYEUuWQqkrra3JTgw6KcFo57jDHyvNqI3k1vW9wlgDvwtLCqvZqeQk WugkiZ6c2yr58uHyW8vfBbND/RSB85tTkCVU/j/IYbQ1RIpCBe2/LcgObWQ9gb93YbsK qf4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=gd9aW239q/YhSWzuMjswj8d/RtAC3PBQOLCe3Y0Z9ys=; b=AJuADUjVd3YkgWtsHiv4T/RyWGxlXyMNDqlsFL7NtkG4edCpkZgE8yv0aTiVT22Lpn 576Ma/LSUOXwhM9jp7Fz2pLFfERjFd79xdezpMkQuk2nAAswVssu8gvnxPfWYopFjp3o KaJxV4fkiU4B8trl+Rqf2L85hfbdXJyrezRxB2A7eNkXhKYJ0kW2k61GRvHLIqj2Qytj WjlZS7kmtrCNXB5uXCfMykOSJbYkFUKaVdOIcNsAWFH8mjNzmwVS4xPbxioF8XZ3yezx 2HVTECgCAtd9r3/KSfvooqRTIhDiHVixHFpQtO5JPKrYHd1XGfvZeXHJgZuHIOaMBOVm 2+kw== X-Gm-Message-State: AOAM530+xuOpp8dWqdHg27Xc/vZnmKSyCoBcEU2whbS1WO6FejHfDcjs hrJUdHxorb9UXvk9zvxwEyijcWZ4lSI1tlpLLtNsNg== X-Received: by 2002:a2e:9591:: with SMTP id w17mr495968ljh.40.1632841769323; Tue, 28 Sep 2021 08:09:29 -0700 (PDT) MIME-Version: 1.0 References: <20210927122646.91934-1-wangkefeng.wang@huawei.com> In-Reply-To: <20210927122646.91934-1-wangkefeng.wang@huawei.com> From: Shakeel Butt Date: Tue, 28 Sep 2021 08:09:17 -0700 Message-ID: Subject: Re: [PATCH v2] slub: Add back check for free nonslab objects To: Kefeng Wang Cc: Vlastimil Babka , Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Andrew Morton , Linux MM , LKML , Matthew Wilcox Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Sep 27, 2021 at 5:24 AM Kefeng Wang wrote: > > After commit ("f227f0faf63b slub: fix unreclaimable slab stat for bulk > free"), the check for free nonslab page is replaced by VM_BUG_ON_PAGE, > which only check with CONFIG_DEBUG_VM enabled, but this config may > impact performance, so it only for debug. > > Commit ("0937502af7c9 slub: Add check for kfree() of non slab objects.") > add the ability, which should be needed in any configs to catch the > invalid free, they even could be potential issue, eg, memory corruption, > use after free and double-free, so replace VM_BUG_ON_PAGE to WARN_ON, add > dump_page() and object address printing to help use to debug the issue. > > Signed-off-by: Kefeng Wang > --- > v2: Add object address printing suggested by Matthew Wilcox > > mm/slub.c | 6 +++++- > 1 file changed, 5 insertions(+), 1 deletion(-) > > diff --git a/mm/slub.c b/mm/slub.c > index 3095b889fab4..157973e22faf 100644 > --- a/mm/slub.c > +++ b/mm/slub.c > @@ -3522,7 +3522,11 @@ static inline void free_nonslab_page(struct page *page, void *object) > { > unsigned int order = compound_order(page); > > - VM_BUG_ON_PAGE(!PageCompound(page), page); > + if (WARN_ON(!PageCompound(page))) { If there is a problem then this would be too noisy. Why not WARN_ON_ONCE()? > + dump_page(page, "invalid free nonslab page"); > + pr_warn("object pointer: 0x%p\n", object); Actually why not add 'once' semantics for the whole if-block? > + } > + > kfree_hook(object); > mod_lruvec_page_state(page, NR_SLAB_UNRECLAIMABLE_B, -(PAGE_SIZE << order)); > __free_pages(page, order); > -- > 2.26.2 >