Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp1307941imm; Wed, 11 Jul 2018 22:48:07 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcR0tV28Z+DFZM+4o1x2dwFlKjlb32Tv5St3bOchvhL+ZwHlLqp2FF937NyWeSyDaHku0YH X-Received: by 2002:a62:d39b:: with SMTP id z27-v6mr923108pfk.182.1531374487142; Wed, 11 Jul 2018 22:48:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531374487; cv=none; d=google.com; s=arc-20160816; b=HYFPhJYAm4She3PTJSVyrbQSwMCrQj4iAw/U/Gd6255I46XNNOPX748YXTi3Dv3e3i pKJqIzalh02PqyN0aer9TQQPnP7vEUjCl66xXU5IlSU09tshO7UVX+HBtDq6eChu0CTB TD9kwc9r+p3bCSTMs6p+sUOZPm0Wsr9x7QpWe2DvozhvkAJ/SbOnz1eYDbiwBMHvkNfJ LviwQSk++YMqgwkTF87yQdjMKEvWWyt5u09mLUFlVXmQaDg11rR1Ql+HgdonV4r23W35 88Dxt0VMbl0FCdJyUmiOU8gH1itgPLEFBs1il9/fCb/BjO/R2KLCBSnLhn2ZO4FKgMHX anXg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:from:subject:cc:to:message-id:date :arc-authentication-results; bh=jtp/AcVddFnO/4khQaNeNfFRbcvr3OKo/1ZCaKTkHE0=; b=nCjIoXuxQjDed7tYZxyNXajMAd2imsaPUkHw7xuDeUnExgvvKAbZkA/8nvKJYZ7qyp 4MNsyE7lq10zyUGCvauU1meOReDwJNV4ys2Cgoxa3ms+pXv9BgaaPYALH9ma/xs4CUHd xRicMN+IGwBNUbzOn1gmyACq+2hE5q94wQHObp/q2zSoMASXyWYehixZiEdVz4D04mN9 vRGev2un7sloFgf+LEq0lJGWAe78/ybRQt/YIjbTcYsSA6w33niJlO58HobQkjf84M3r mzIOJAUGVHX6HwdNpEETc0T1cm6DNgRhfm1W/J0+bcP4xQ8SfdBQcXP6DLRfJtGA4xZx 3X/w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i13-v6si20256838pgi.277.2018.07.11.22.47.38; Wed, 11 Jul 2018 22:48:07 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726623AbeGLFy5 (ORCPT + 99 others); Thu, 12 Jul 2018 01:54:57 -0400 Received: from shards.monkeyblade.net ([23.128.96.9]:54274 "EHLO shards.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725827AbeGLFy5 (ORCPT ); Thu, 12 Jul 2018 01:54:57 -0400 Received: from localhost (74-93-104-98-Washington.hfc.comcastbusiness.net [74.93.104.98]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) (Authenticated sender: davem-davemloft) by shards.monkeyblade.net (Postfix) with ESMTPSA id 68CCD13FDE78F; Wed, 11 Jul 2018 22:47:01 -0700 (PDT) Date: Wed, 11 Jul 2018 22:46:58 -0700 (PDT) Message-Id: <20180711.224658.2077863065492745521.davem@davemloft.net> To: neilb@suse.com Cc: herbert@gondor.apana.org.au, tgraf@suug.ch, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, eric.dumazet@gmail.com Subject: Re: [PATCH resend] rhashtable: detect when object movement might have invalidated a lookup From: David Miller In-Reply-To: <87k1q8yh70.fsf@notabene.neil.brown.name> References: <152782824943.30340.8224535954517915320.stgit@noble> <20180601160613.7ud25g2ux55k3bma@gondor.apana.org.au> <87k1q8yh70.fsf@notabene.neil.brown.name> X-Mailer: Mew version 6.7 on Emacs 25.3 / Mule 6.0 (HANACHIRUSATO) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.5.12 (shards.monkeyblade.net [149.20.54.216]); Wed, 11 Jul 2018 22:47:01 -0700 (PDT) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: NeilBrown Date: Fri, 06 Jul 2018 17:08:35 +1000 > > Some users of rhashtable might need to change the key > of an object and move it to a different location in the table. > Other users might want to allocate objects using > SLAB_TYPESAFE_BY_RCU which can result in the same memory allocation > being used for a different (type-compatible) purpose and similarly > end up in a different hash-chain. > > To support these, we store a unique NULLS_MARKER at the end of > each chain, and when a search fails to find a match, we check > if the NULLS marker found was the expected one. If not, > the search is repeated. > > The unique NULLS_MARKER is derived from the address of the > head of the chain. > > If an object is removed and re-added to the same hash chain, we won't > notice by looking that the NULLS marker. In this case we must be sure > that it was not re-added *after* its original location, or a lookup may > incorrectly fail. The easiest solution is to ensure it is inserted at > the start of the chain. insert_slow() already does that, > insert_fast() does not. So this patch changes insert_fast to always > insert at the head of the chain. > > Note that such a user must do their own double-checking of > the object found by rhashtable_lookup_fast() after ensuring > mutual exclusion which anything that might change the key, such as > successfully taking a new reference. > > Signed-off-by: NeilBrown Applied to net-next.