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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id CCF78C32771 for ; Mon, 26 Sep 2022 13:08:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 649D78E004A; Mon, 26 Sep 2022 09:08:14 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5F9ED8E0047; Mon, 26 Sep 2022 09:08:14 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4C2968E004A; Mon, 26 Sep 2022 09:08:14 -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 3DABD8E0047 for ; Mon, 26 Sep 2022 09:08:14 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 0AFD31C5DB2 for ; Mon, 26 Sep 2022 13:08:13 +0000 (UTC) X-FDA: 79954264908.20.19A3AE7 Received: from Chamillionaire.breakpoint.cc (Chamillionaire.breakpoint.cc [193.142.43.52]) by imf27.hostedemail.com (Postfix) with ESMTP id A270540008 for ; Mon, 26 Sep 2022 13:08:12 +0000 (UTC) Received: from fw by Chamillionaire.breakpoint.cc with local (Exim 4.92) (envelope-from ) id 1ocnqC-0005Pr-Tl; Mon, 26 Sep 2022 15:08:08 +0200 Date: Mon, 26 Sep 2022 15:08:08 +0200 From: Florian Westphal To: Michal Hocko Cc: Florian Westphal , linux-mm@kvack.org, linux-kernel@vger.kernel.org, vbabka@suse.cz, akpm@linux-foundation.org, urezki@gmail.com, netdev@vger.kernel.org, netfilter-devel@vger.kernel.org, Martin Zaharinov Subject: Re: [PATCH mm] mm: fix BUG with kvzalloc+GFP_ATOMIC Message-ID: <20220926130808.GD12777@breakpoint.cc> References: <20220923103858.26729-1-fw@strlen.de> <20220923133512.GE22541@breakpoint.cc> <20220926075639.GA908@breakpoint.cc> <20220926100800.GB12777@breakpoint.cc> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1664197692; a=rsa-sha256; cv=none; b=l6aXAjFsBEgr+4Eib+IwdBSxFS6XvaY+6+H/CDh21AxctOriJavu/yjeBxXd6ffZe0C+BJ r3KoXpDp1oPLDF1jk7paF5KMzReLsAbFWgr/d8J0BqOconNsp6oghC+mWr+GJN6rMPqKIW o7mP3J+BG1k0qtGQOHqWHhGejQLs5L4= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf27.hostedemail.com: domain of fw@strlen.de designates 193.142.43.52 as permitted sender) smtp.mailfrom=fw@strlen.de ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1664197692; 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-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=I6oCouGFMnDsEwO/e8A7dk3Ru05WyYXW9NNj0RzDuS8=; b=QVFFhYKPYoaV1ECYEd6+GhaP82TkWA9mauLrMMkbm+vffgwMjHntiS+lUtED+GobZy5pWr Wm0wZUxbRewji95BBRBrshmSxY8gtk9n1vXpWdXyq8t6EAE1sqnnBKwi2HnG21L+rCblT4 VtOChUNZRppmpO5PQJgzgNfDzAaV7xU= X-Rspam-User: X-Rspamd-Queue-Id: A270540008 X-Rspamd-Server: rspam08 X-Stat-Signature: ztt5pojbpps6qwmzai7xutonj8do3733 Authentication-Results: imf27.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf27.hostedemail.com: domain of fw@strlen.de designates 193.142.43.52 as permitted sender) smtp.mailfrom=fw@strlen.de X-HE-Tag: 1664197692-344172 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: Michal Hocko wrote: > On Mon 26-09-22 12:08:00, Florian Westphal wrote: > > Michal Hocko wrote: > > > + old_tbl = rht_dereference_rcu(ht->tbl, ht); > > > + size = tbl->size; > > > + > > > + data = ERR_PTR(-EBUSY); > > > + > > > + if (rht_grow_above_75(ht, tbl)) > > > + size *= 2; > > > + /* Do not schedule more than one rehash */ > > > + else if (old_tbl != tbl) > > > + return data; > > > + > > > + data = ERR_PTR(-ENOMEM); > > > + > > > + rcu_read_unlock(); > > > + new_tbl = bucket_table_alloc(ht, size, GFP_KERNEL); > > > + rcu_read_lock(); > > > > I don't think this is going to work, there can be callers that > > rely on rcu protected data structures getting free'd. > > The caller of this function drops RCU for each retry, why should be the > called function any special? I was unfortunately never able to fully understand rhashtable. AFAICS the rcu_read_lock/unlock in the caller is pointless, or at least dubious. To the best of my knowledge there are users of this interface that invoke it with rcu read lock held, and since those always nest, the rcu_read_unlock() won't move us to GFP_KERNEL territory. I guess you can add a might_sleep() and ask kernel to barf at runtime.