From patchwork Tue Mar 28 09:58:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Muchun Song X-Patchwork-Id: 13190788 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id DA520C76195 for ; Tue, 28 Mar 2023 09:58:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 578E86B0075; Tue, 28 Mar 2023 05:58:41 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5023C6B0078; Tue, 28 Mar 2023 05:58:41 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 37D8E6B007B; Tue, 28 Mar 2023 05:58:41 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 22D016B0075 for ; Tue, 28 Mar 2023 05:58:41 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id E72E6408A5 for ; Tue, 28 Mar 2023 09:58:40 +0000 (UTC) X-FDA: 80617857600.10.AF14137 Received: from mail-pf1-f174.google.com (mail-pf1-f174.google.com [209.85.210.174]) by imf02.hostedemail.com (Postfix) with ESMTP id 169BD8000C for ; Tue, 28 Mar 2023 09:58:38 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=HhbQB+dg; spf=pass (imf02.hostedemail.com: domain of songmuchun@bytedance.com designates 209.85.210.174 as permitted sender) smtp.mailfrom=songmuchun@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1679997519; a=rsa-sha256; cv=none; b=znaGGLZ3/RXKdKskdbfu29B+M/f4MkNzD4Na8GjLeu+Nw5RPZJgTW60pkuVZ2hlEcDfLpm Erwf1se1TOkmNHnBDvvqMkwObVMSqv3OXctwSKZPCzugEasuvTlMYLeXnmM41czmaaxrWo 7KOIiV+JcNW1Nh5MOvY4ZCmN1NbHFLM= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=HhbQB+dg; spf=pass (imf02.hostedemail.com: domain of songmuchun@bytedance.com designates 209.85.210.174 as permitted sender) smtp.mailfrom=songmuchun@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1679997519; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=lBD4yaWYkYDbLkNhZA944C9ObF80BX09B3zGBKkIydI=; b=vJAEXbFXJjYUnwl3VfX39FeI8SfexICQ5FkBdyzp7eKCsfrNEswC7OUA3TtQn6lEVazNy3 XgcFJsabcyWEkSaDRtaufTCyy5dJs/eOAFzyIPd641gaCG+yDMRVtB4IXJx8LgGJaZdvgp FXjAkNS7xXCabBCD3J+vddV3DbqIrrk= Received: by mail-pf1-f174.google.com with SMTP id u38so7565085pfg.10 for ; Tue, 28 Mar 2023 02:58:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1679997517; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=lBD4yaWYkYDbLkNhZA944C9ObF80BX09B3zGBKkIydI=; b=HhbQB+dgFelVX19imcjsNLuo23G94LeWSU/HGZgUiVNfjyKVW+HiToJUnagtKSthBY 5kq+NvO/ctnPo47Twm8reDS0d5f0bC6BH3c9qB+Q9Gjw3RaCZ+yyNCqRN0jzkzO4hh9Z MgZCQ7XZwY1fjVVJrlrFKYiY+51dScHVJrHlEvymXRrBLu2hClZ3UbSwxLjhj/YFxX64 vMWId0i1jE82E/qg7Sr38pLdxec55XLsUoXO4nMH1EQgjTwoGGcRX4UGDsco7eCfVB8d cLv4R1G7yh9yGkneEds787t4phoeg1nJ0GlxivunqwTSMcQ5LysGeIuwdCvjaRqL97IT maTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679997517; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=lBD4yaWYkYDbLkNhZA944C9ObF80BX09B3zGBKkIydI=; b=xo+h8fG84SYO2KTw/zSUzagga2H0WWyrJVHkxk6jo4LmHiOJ4zIxQN8cKKTZv9QVXU ENANQC0kYbV8pPE+wTzXPAT+KiaTwikhwXKHOtnC48fV9wjDaH6acHqDMX8iHS7gy4tR Ro9LoiiucxEXbXe6HtTszW/ONWxDe8vI6VNas/x6nBQhU9NqsuCCsVazQA9BY4pLXqjh jb/NKpRCLw/IZ7Lg6k5DZjGqJyO52iM6vzHVgnDwvZxnIkb8F6WKft9QR/7dMm7crSFn qMNvFamRxQ0XgO9lBvADTT7AfhNUZksw+s7lQgF5cAIvVl0/7OmlQU44KFR93Vtu03ge effw== X-Gm-Message-State: AAQBX9dvaCnE9C3wC9xAnCsyRCO01GbBc396Ln+KzXkdhBy8Cj8CfeHL zouQOHx9AGKibOzejJ8jODtXQg== X-Google-Smtp-Source: AKy350aBkCEiteWTRB8arAPPUAGcyuriJ2lhLAbvPCn/eGNEdVUaJTvoxyZvHgGLTc4pYAyj0IqVBw== X-Received: by 2002:a62:1dca:0:b0:627:de2e:f1a5 with SMTP id d193-20020a621dca000000b00627de2ef1a5mr13507673pfd.4.1679997517751; Tue, 28 Mar 2023 02:58:37 -0700 (PDT) Received: from PXLDJ45XCM.bytedance.net ([139.177.225.236]) by smtp.gmail.com with ESMTPSA id m26-20020aa78a1a000000b005a8a5be96b2sm17207556pfa.104.2023.03.28.02.58.33 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 28 Mar 2023 02:58:37 -0700 (PDT) From: Muchun Song To: glider@google.com, elver@google.com, dvyukov@google.com, akpm@linux-foundation.org, jannh@google.com, sjpark@amazon.de, muchun.song@linux.dev Cc: kasan-dev@googlegroups.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Muchun Song Subject: [PATCH 2/6] mm: kfence: check kfence pool size at building time Date: Tue, 28 Mar 2023 17:58:03 +0800 Message-Id: <20230328095807.7014-3-songmuchun@bytedance.com> X-Mailer: git-send-email 2.37.1 (Apple Git-137.1) In-Reply-To: <20230328095807.7014-1-songmuchun@bytedance.com> References: <20230328095807.7014-1-songmuchun@bytedance.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Queue-Id: 169BD8000C X-Rspamd-Server: rspam01 X-Stat-Signature: t9pqfuw3jo9h4wnyzjzcotfyesb394so X-HE-Tag: 1679997518-401485 X-HE-Meta: U2FsdGVkX18E6fukNfJPleolD+P/fBJ0r809bS6gpaJZ7M6q3Iz45Vb0BbswQKaN9A1dWhIpT5NBalBYOWUcvv9ir2XviwrZV3SHrelNMkMDIyTfVcTHx9VQ0jA+iREDWEhZfF/N2sYJ8k5quIdMzkYimcGtGzE6VqOcMpyxCDSWeluQ9Qe/OItD4U7cjDvZt0XgbzVM51nmocxzF7W4gqrzoLyD1Fr0GmCduGJWxYyrjXIAHiotj1d33xsTd0z3sFl6wypA8CZ6pQRjvy8azp2JvYfolEa/k4QqkSfHEqc9XntqiINf9x1zlxuU8Fu5EamkSbOAV/xqfBdqF4jiSiML/i6XNHShB7LEnT5aeV6tUHTbCb1ekEcWd2JoS0AsMs4GS1MAwDxu0bOW1GhxRYbY1O28oysfH12+kGu6prebBK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loop: owner-majordomo@kvack.org List-ID: Check kfence pool size at building time to expose problem ASAP. Signed-off-by: Muchun Song --- mm/kfence/core.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/mm/kfence/core.c b/mm/kfence/core.c index de62a84d4830..6781af1dfa66 100644 --- a/mm/kfence/core.c +++ b/mm/kfence/core.c @@ -841,10 +841,9 @@ static int kfence_init_late(void) return -ENOMEM; __kfence_pool = page_to_virt(pages); #else - if (nr_pages > MAX_ORDER_NR_PAGES) { - pr_warn("KFENCE_NUM_OBJECTS too large for buddy allocator\n"); - return -EINVAL; - } + BUILD_BUG_ON_MSG(get_order(KFENCE_POOL_SIZE) > MAX_ORDER, + "CONFIG_KFENCE_NUM_OBJECTS is too large for buddy allocator"); + __kfence_pool = alloc_pages_exact(KFENCE_POOL_SIZE, GFP_KERNEL); if (!__kfence_pool) return -ENOMEM;