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 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 40771C433F5 for ; Tue, 28 Sep 2021 15:09:33 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id BC8BB61209 for ; Tue, 28 Sep 2021 15:09:32 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org BC8BB61209 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 DB95B900003; Tue, 28 Sep 2021 11:09:31 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D691F900002; Tue, 28 Sep 2021 11:09:31 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C31F6900003; Tue, 28 Sep 2021 11:09:31 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0195.hostedemail.com [216.40.44.195]) by kanga.kvack.org (Postfix) with ESMTP id B3AF2900002 for ; Tue, 28 Sep 2021 11:09:31 -0400 (EDT) Received: from smtpin38.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 68248181C195F for ; Tue, 28 Sep 2021 15:09:31 +0000 (UTC) X-FDA: 78637316142.38.EF83844 Received: from mail-lf1-f48.google.com (mail-lf1-f48.google.com [209.85.167.48]) by imf15.hostedemail.com (Postfix) with ESMTP id 1B5D0D00009A for ; Tue, 28 Sep 2021 15:09:30 +0000 (UTC) Received: by mail-lf1-f48.google.com with SMTP id b20so94624237lfv.3 for ; Tue, 28 Sep 2021 08:09:30 -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=Cs2CSVKittCEoWGxpWZQOmFmEuotz2UYAyrWH8g6x02vEkZVqvDi0o8QZhM7T4wHPm HUuwD7xFXHVMk3aOZU6zcuvyMg5LLgF3cSiZu6TppGv80rNwlwt+xsDYN5EGAfFncwyN KCh36lhE4humf0Nx9V6kgxnfEQejPHqu0EKznGpUjm8D0+I9rOHNNd3pYMoioz1ekJKb hpOOr+D5C5UUCAkz3b8EYGRkPff7rxQArqR68SdauantpGprQqqgLob2+lGtNr1/GxqQ Wp5+/ARW57dmfvrtKokOGvfjuPU1EoYKKAuEAIVzXAINv/4cVwXKt2M6neCbuqt0Ha3Y qafg== X-Gm-Message-State: AOAM533lZXQoGKL9lJCrRb3fD3I2/ROB4dh8IRNlAE1sOhLo3GnEBt00 tg0njTdnG1tDbbPgFTRQJ0dRNAeBbLctg9BpnF41Em+YKsh0yw== X-Google-Smtp-Source: ABdhPJz7y7Ri4Kt1pHJT1qGblaLtZEU8d3lQS2bBywZIf/J0eHDf7OnYJ6rXLIspQ2U/kA8XzIkT3OMF6lVZz/F3LD0= 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" X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 1B5D0D00009A X-Stat-Signature: hyxuqsdjesjwfgsw8ehyb6hgome7e9q5 Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=fL1b2vio; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf15.hostedemail.com: domain of shakeelb@google.com designates 209.85.167.48 as permitted sender) smtp.mailfrom=shakeelb@google.com X-HE-Tag: 1632841770-398446 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, 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 >