Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp154072imu; Thu, 6 Dec 2018 21:40:50 -0800 (PST) X-Google-Smtp-Source: AFSGD/W0uR9SYvViLL5O+NhH0is04TesgpZUa/9+DIlHgFomd/VplBa/X77ssiGcS15pL4Lq1MuM X-Received: by 2002:a63:b105:: with SMTP id r5mr807829pgf.442.1544161250729; Thu, 06 Dec 2018 21:40:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544161250; cv=none; d=google.com; s=arc-20160816; b=MhQeyltUk0yIOZJFvH1E8+yfTu3aU/yutF5ZQVorQEYVxHka0tIfABFpy0gJhd5U1d SfDM4ek3mzomLW/uGNDklCd4B8g6awjHZHH+UGi0XIiEJh9IhKKbkkoJEz1bbibMRe8L eq8oYuN4luHCg3MqfqYuxJZe9N6TYasSi++jpfiWx+TGlTLLn2V0p/6YN2T0FpobRdoM iqXOMCtMb3DjJSZhQQEntJlSfM/7GO7UNp2QF2tPiq10JmAaP4CQCOo/Maffge2bvYd2 mi5B6iMPrfywgl30bhL5bDG8nCgqBj/UB1JTjzzRifflge7xBMVQ9ghUzsIijzq02Yv+ 8s3Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=Hkkqbq9Yvj8+XBhczH+aAUgqEH8SQuMlvLLPOyWAaFY=; b=LdC3i9QXfRTac6hZ6OSIdCTsG3MPr0yctWxqGDBgWJTMgJ0mvaP7mkZUVOUqzU3Cmg hcLidp4NZIo2LXt2Iwgynp4h9iwMqbPBtk82BC8IJjPw7B3CBQ+v2klDVGQRh1wf/RJR 1gQyb2AXRzENTp/+NxkDaOzlvKi/ysnM59siP5TKe096+pgcAIoG0C1Qy2dies3/R2if h24YGDc45UrKWdcbz8QPQQbBA2Eaa+Gt2t8CffwjWyrOfjz7wuZy+sZaWz2w8mIkyT/d Po88DcDkFd58wDA3e7jnuWAQoAqClmmtnrjqRD5CIj/MMf5DV5bzQ+TBR9Qzpj7IqIlS 6HLg== 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 d19si2395556pfd.281.2018.12.06.21.40.35; Thu, 06 Dec 2018 21:40:50 -0800 (PST) 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 S1726019AbeLGFj7 (ORCPT + 99 others); Fri, 7 Dec 2018 00:39:59 -0500 Received: from orcrist.hmeau.com ([104.223.48.154]:48920 "EHLO deadmen.hmeau.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725963AbeLGFj7 (ORCPT ); Fri, 7 Dec 2018 00:39:59 -0500 Received: from gondobar.mordor.me.apana.org.au ([192.168.128.4] helo=gondobar) by deadmen.hmeau.com with esmtps (Exim 4.89 #2 (Debian)) id 1gV8rc-000496-N2; Fri, 07 Dec 2018 13:39:48 +0800 Received: from herbert by gondobar with local (Exim 4.89) (envelope-from ) id 1gV8rY-00058V-3D; Fri, 07 Dec 2018 13:39:44 +0800 Date: Fri, 7 Dec 2018 13:39:44 +0800 From: Herbert Xu To: NeilBrown Cc: Thomas Graf , Tom Herbert , David Miller , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH net-next] rhashtable: further improve stability of rhashtable_walk Message-ID: <20181207053943.7zacyn5uvqkfnfoi@gondor.apana.org.au> References: <153086101070.2825.6850140624411927465.stgit@noble> <153086109256.2825.15329014177598382684.stgit@noble> <87zhtkeimx.fsf@notabene.neil.brown.name> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87zhtkeimx.fsf@notabene.neil.brown.name> User-Agent: NeoMutt/20170113 (1.7.2) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Dec 05, 2018 at 02:51:02PM +1100, NeilBrown wrote: > > If the sequence: > obj = rhashtable_walk_next(iter); > rhashtable_walk_stop(iter); > rhashtable_remove_fast(ht, &obj->head, params); > rhashtable_walk_start(iter); > > races with another thread inserting or removing > an object on the same hash chain, a subsequent > rhashtable_walk_next() is not guaranteed to get the "next" > object. It is possible that an object could be > repeated, or missed. > > This can be made more reliable by keeping the objects in a hash chain > sorted by memory address. A subsequent rhashtable_walk_next() > call can reliably find the correct position in the list, and thus > find the 'next' object. > > It is not possible to take this approach with an rhltable as keeping > the hash chain in order is not so easy. When the first object with a > given key is removed, it is replaced in the chain with the next > object with the same key, and the address of that object may not be > correctly ordered. > I have not yet found any way to achieve the same stability > with rhltables, that doesn't have a major impact on lookup > or insert. No code currently in Linux would benefit from > such extra stability. > > With this patch: > - a new object is always inserted after the last object with a > smaller address, or at the start. > - when rhashtable_walk_start() is called, it records that 'p' is not > 'safe', meaning that it cannot be dereferenced. The revalidation > that was previously done here is moved to rhashtable_walk_next() > - when rhashtable_walk_next() is called while p is not NULL and not > safe, it walks the chain looking for the first object with an > address greater than p and returns that. If there is none, it moves > to the next hash chain. > > Signed-off-by: NeilBrown > --- > > This is a resend of a patch that I sent back in July. I couldn't > applied then because it assumed another rhashtable patch which hadn't > landed yet - it now has. I thought we had agreed to drop this because nobody needs it currently and it doesn't handle rhlist? Cheers, -- Email: Herbert Xu Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt