Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp529784rwb; Mon, 26 Sep 2022 02:19:07 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7jT+etTlrWEPkY8/EBBGOu0lKziXKbPL3L2/nXpN3x6EMRMQ4tDU0bGEScHT16yyQ7z8yh X-Received: by 2002:a17:90b:4b49:b0:202:e09c:6662 with SMTP id mi9-20020a17090b4b4900b00202e09c6662mr23283175pjb.138.1664183947672; Mon, 26 Sep 2022 02:19:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664183947; cv=none; d=google.com; s=arc-20160816; b=UFchx8zysx9xx8RZ2+HXq/HjZuTFP+yePpP6Txs5gUJFL6kXhhZj0Dk6TspOjAN1Gl GJYnHvztqCFDmoo8eAHY/27GqLI5oq5kYMgzfBgdEWy4tj77aiPqZZ6w/D/Is3KNxSEW jpY06oG19ZTrzgC2xMTd2VcTExJu+hLNlXpnKl+c6kUf55hy7Wvt4/zgqPFBV82o9XgJ N9oYi8x/T5uwGooLVw1u6A53yd4k9LqbRZLIErhplYajywj13nCqYgTorUdNbSA6VVuu 9NmYRwNqqZC40VEDXrelm0I58UYYAW1tF8CardHCOo6xt0gfqSbgCR3/8RLbZGJZu0bT yYaA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=gRUnHJMUjna+yBrGbPIWqMy91/9oYwtJI1sj1h3QLuk=; b=ONqo2GGgb3c/RNcy+7XbiWv5fIlpFyszKxK+9nZ+Aha/Pf3+UZc5WIyn8Isq17MzZ4 eOh2wvS4kk/EmQWFa8yRzZycDH4pGBxO9yTRywsdKRCvFM4cIOs9dL3Nv0KciwXnVGUx PWoslu5dH4RTbgGbnxRUumlzyso8wMgR5LAdVgnYwcBuQR2jHauDE4C8zST8Kpg6SiMu A9oA1gZSMz+E+VNnynu7Gdr+zt16LXNP1G7iHt+hCg1PpCOMDUy9RBBS1T478WIp/j7k BBWzxB/5kCtRkw5N6bT68vZ61EmHjvjGm0k5y62dX9t1nXgQEaZi49mrdlh7lYqKqU4l ZgBg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e31-20020a630f1f000000b00438f77814b2si16905471pgl.124.2022.09.26.02.18.55; Mon, 26 Sep 2022 02:19:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234406AbiIZIcr (ORCPT + 99 others); Mon, 26 Sep 2022 04:32:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38632 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234353AbiIZIcn (ORCPT ); Mon, 26 Sep 2022 04:32:43 -0400 Received: from Chamillionaire.breakpoint.cc (Chamillionaire.breakpoint.cc [IPv6:2a0a:51c0:0:12e:520::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8FCA736862; Mon, 26 Sep 2022 01:32:41 -0700 (PDT) Received: from fw by Chamillionaire.breakpoint.cc with local (Exim 4.92) (envelope-from ) id 1ocjXL-00030q-0S; Mon, 26 Sep 2022 10:32:23 +0200 From: Florian Westphal To: Cc: tgraf@suug.ch, urezki@gmail.com, Paolo Abeni , "David S. Miller" , Eric Dumazet , Jakub Kicinski , herbert@gondor.apana.org.au, linux-kernel@vger.kernel.org, akpm@linux-foundation.org, Florian Westphal , Martin Zaharinov , Michal Hocko , Paolo Bonzini , kvm@vger.kernel.org Subject: [PATCH net] rhashtable: fix crash due to mm api change Date: Mon, 26 Sep 2022 10:31:39 +0200 Message-Id: <20220926083139.48069-1-fw@strlen.de> X-Mailer: git-send-email 2.37.3 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.0 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_MED,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Martin Zaharinov reports BUG() in mm land for 5.19.10 kernel: kernel BUG at mm/vmalloc.c:2437! invalid opcode: 0000 [#1] SMP CPU: 28 PID: 0 Comm: swapper/28 Tainted: G W O 5.19.9 #1 [..] RIP: 0010:__get_vm_area_node+0x120/0x130 __vmalloc_node_range+0x96/0x1e0 kvmalloc_node+0x92/0xb0 bucket_table_alloc.isra.0+0x47/0x140 rhashtable_try_insert+0x3a4/0x440 rhashtable_insert_slow+0x1b/0x30 [..] bucket_table_alloc uses kvzalloc(GPF_ATOMIC). If kmalloc fails, this now falls through to vmalloc and hits code paths that assume GFP_KERNEL. I sent a patch to restore GFP_ATOMIC support in kvmalloc but mm maintainers rejected it. This patch is partial revert of commit 93f976b5190d ("lib/rhashtable: simplify bucket_table_alloc()"), to avoid kvmalloc for ATOMIC case. As kvmalloc doesn't warn when used with ATOMIC, kernel will only crash once vmalloc fallback occurs, so we may see more crashes in other areas in the future. Most other callers seem ok but kvm_mmu_topup_memory_cache looks like it might be affected by the same breakage, so Cc kvm@. Reported-by: Martin Zaharinov Fixes: a421ef303008 ("mm: allow !GFP_KERNEL allocations for kvmalloc") Link: https://lore.kernel.org/linux-mm/Yy3MS2uhSgjF47dy@pc636/T/#t Cc: Michal Hocko Cc: Paolo Bonzini Cc: kvm@vger.kernel.org Signed-off-by: Florian Westphal --- lib/rhashtable.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/rhashtable.c b/lib/rhashtable.c index e12bbfb240b8..9451f411bc71 100644 --- a/lib/rhashtable.c +++ b/lib/rhashtable.c @@ -181,7 +181,13 @@ static struct bucket_table *bucket_table_alloc(struct rhashtable *ht, int i; static struct lock_class_key __key; - tbl = kvzalloc(struct_size(tbl, buckets, nbuckets), gfp); + size = struct_size(tbl, buckets, nbuckets); + + /* kvmalloc API does not support GFP_KERNEL anymore */ + if ((gfp & GFP_KERNEL) != GFP_KERNEL) + tbl = kzalloc(size, gfp | __GFP_NOWARN | __GFP_NORETRY); + else + tbl = kvzalloc(size, gfp); size = nbuckets; -- 2.37.3