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 578CFC32771 for ; Mon, 26 Sep 2022 09:30:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E83FA6B007E; Mon, 26 Sep 2022 05:30:08 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E0C6A8E003A; Mon, 26 Sep 2022 05:30:08 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CAD688E0039; Mon, 26 Sep 2022 05:30:08 -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 B81D96B007E for ; Mon, 26 Sep 2022 05:30:08 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 887301401B8 for ; Mon, 26 Sep 2022 09:30:08 +0000 (UTC) X-FDA: 79953715296.13.BE15FA4 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by imf18.hostedemail.com (Postfix) with ESMTP id 2B43F1C000B for ; Mon, 26 Sep 2022 09:30:08 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id E4BA922100; Mon, 26 Sep 2022 09:30:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1664184606; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=bih9TmuQiIX+2I5xDF+OS0kAuWMZpXGCT3GD+YoKLCM=; b=UFRF8LH7nYOh+cFoa+rPZ4LJVzLAlIMi4omuft9vyKbxhJNE5zH0yffwP/MrJ2NQk858V4 GPXbaFJLat68x/ZhEfKCReJr/gLCecipF+Nl5jADAN3yvxhToNCM14uLMuNHFdw2MEpYaC WTYKdgD2npnLqSUq3t55LFOg4bv76Rg= Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id C2E6D139BD; Mon, 26 Sep 2022 09:30:06 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id JE1nLB5xMWOgdwAAMHmgww (envelope-from ); Mon, 26 Sep 2022 09:30:06 +0000 Date: Mon, 26 Sep 2022 11:30:06 +0200 From: Michal Hocko To: Florian Westphal Cc: 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: References: <20220923103858.26729-1-fw@strlen.de> <20220923133512.GE22541@breakpoint.cc> <20220926075639.GA908@breakpoint.cc> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1664184608; a=rsa-sha256; cv=none; b=QHiHsKNPvbtWjWfSnTM5VXNK6ZIzVifQVDnXZ9qStLvb6mmGwflcslupxCofBC2+BrNZei nF/FjmWW0JvbsokJPzqPZJsgpP0ZmlLo+tDtv/bKG6jCoDQg2Ly6PjoGLHXDDNpSaUgXAw SKr7K7LS5ZktGU6Nk05MUtHsd78imUE= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=suse.com header.s=susede1 header.b=UFRF8LH7; dmarc=pass (policy=quarantine) header.from=suse.com; spf=pass (imf18.hostedemail.com: domain of mhocko@suse.com designates 195.135.220.28 as permitted sender) smtp.mailfrom=mhocko@suse.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1664184608; 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:dkim-signature; bh=bih9TmuQiIX+2I5xDF+OS0kAuWMZpXGCT3GD+YoKLCM=; b=685opVKKDDpAGEGqhDxJfXF2eLfhqzrdpixUDFEIaL9ZO8Lgh8Uk7Y25e9i7jH9U3bVLMN fYBUaZZy1Vd8rNqqMx+a3DcIxZyElBihaVECwpmutr9gYDQ/W3OoYql896fQF5hBRd8X4B KvXV5F54+YlhOD40Y+RmF1rretWzUOE= X-Rspamd-Server: rspam11 X-Rspam-User: X-Rspamd-Queue-Id: 2B43F1C000B Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=suse.com header.s=susede1 header.b=UFRF8LH7; dmarc=pass (policy=quarantine) header.from=suse.com; spf=pass (imf18.hostedemail.com: domain of mhocko@suse.com designates 195.135.220.28 as permitted sender) smtp.mailfrom=mhocko@suse.com X-Stat-Signature: 5sc5cb3qozaxe68pzf3tei4perm4gea8 X-HE-Tag: 1664184608-100024 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 26-09-22 10:58:00, Michal Hocko wrote: [...] > A better option to me seems to be reworking the rhashtable_insert_rehash > to not rely on an atomic allocation. I am not familiar with that code > but it seems to me that the only reason this allocation mode is used is > due to rcu locking around rhashtable_try_insert. Is there any reason we > cannot drop the rcu lock, allocate with the full GFP_KERNEL allocation > power and retry with the pre allocated object? rhashtable_insert_slow is > already doing that to implement its never fail semantic. So a very blunt and likely not 100% correct take on this side of things. But it should give an idea at least. --- diff --git a/lib/rhashtable.c b/lib/rhashtable.c index e12bbfb240b8..fc547c43b05d 100644 --- a/lib/rhashtable.c +++ b/lib/rhashtable.c @@ -437,31 +437,11 @@ static void rht_deferred_worker(struct work_struct *work) } static int rhashtable_insert_rehash(struct rhashtable *ht, - struct bucket_table *tbl) + struct bucket_table *tbl, + struct bucket_table *new_tbl) { - struct bucket_table *old_tbl; - struct bucket_table *new_tbl; - unsigned int size; int err; - old_tbl = rht_dereference_rcu(ht->tbl, ht); - - size = tbl->size; - - err = -EBUSY; - - if (rht_grow_above_75(ht, tbl)) - size *= 2; - /* Do not schedule more than one rehash */ - else if (old_tbl != tbl) - goto fail; - - err = -ENOMEM; - - new_tbl = bucket_table_alloc(ht, size, GFP_ATOMIC | __GFP_NOWARN); - if (new_tbl == NULL) - goto fail; - err = rhashtable_rehash_attach(ht, tbl, new_tbl); if (err) { bucket_table_free(new_tbl); @@ -471,17 +451,6 @@ static int rhashtable_insert_rehash(struct rhashtable *ht, schedule_work(&ht->run_work); return err; - -fail: - /* Do not fail the insert if someone else did a rehash. */ - if (likely(rcu_access_pointer(tbl->future_tbl))) - return 0; - - /* Schedule async rehash to retry allocation in process context. */ - if (err == -ENOMEM) - schedule_work(&ht->run_work); - - return err; } static void *rhashtable_lookup_one(struct rhashtable *ht, @@ -619,9 +588,33 @@ static void *rhashtable_try_insert(struct rhashtable *ht, const void *key, } } while (!IS_ERR_OR_NULL(new_tbl)); - if (PTR_ERR(data) == -EAGAIN) - data = ERR_PTR(rhashtable_insert_rehash(ht, tbl) ?: + if (PTR_ERR(data) == -EAGAIN) { + struct bucket_table *old_tbl; + unsigned int size; + + 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(); + + if (!new_tbl) + return data; + + data = ERR_PTR(rhashtable_insert_rehash(ht, tbl, new_tbl) ?: -EAGAIN); + } return data; } -- Michal Hocko SUSE Labs