Received: by 10.192.165.148 with SMTP id m20csp1000655imm; Sat, 5 May 2018 02:42:50 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpXbdk3chjxdU837TAF/6ToDQ76ucTE+9zwNTEXhgx7YaMOpsYqTlQaVSzvrYGvG1kHIsvm X-Received: by 2002:a65:5a81:: with SMTP id c1-v6mr24943281pgt.20.1525513370424; Sat, 05 May 2018 02:42:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525513370; cv=none; d=google.com; s=arc-20160816; b=weLH6tUjQMjfy64H0rRck/ZWnZ+nBJtebM4oUepzbMO2crlabI6cpCVe0Jqy19Yz3x 8Hno/1frRrag//zqy3eFlOM8th4hv6/CjShoxWvrRToEyc9eVZnEvjMXosRjJny0dJ3o Zw+951aFMhbSuiEP0/8zqZVhbhu22CYoO0IZvGZWEDWZeuqV/dzw3xuD6KQ1FIHgFbYn S+ShAthVUCJJuH3139BIPM7vf5CAfItFVcdfWhKfYVP++fiOSZgSRCeAA6mt5qyKMpJL AcF+5SzrxnffsXZ+JUyBblO2ap7tkgl/2uubUa8AjLbNyBOMsLdWWzieG2md50oYXw95 E+Lw== 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:arc-authentication-results; bh=Pkh5RaI44KEV9P/pYdluQTMxTs8WOOVWiAVgziFNwrQ=; b=L2KG/nzw++U+HXu7+KZDkwsSBy8f5tLFWxXHvUTkfms27KT42FjdIAfVhqq+fLFqgf 5kbX6lU8b7haW5xW0j5MoOdxanvAhoeBoRgrs+Q9cvqfWPXJIi3IhRaOSHmhFInOXGMr /v9M+GGiMiYxvzes2OpX2QOJ0ToTbep/lmIz8Ph7QUItIDjfR1ozm6gJqQMTnE0ZxqCE +nJbsM2E/s1utqW9IYt4QQVcoMCzc7k9lFmgMbfCDN9T+vrg3VMTqZWcw8OlDBIg1lNj R6fAGtaPGBB4W0cCWtXx6jusO98+eKwNGmoZNI/de6K6yEQcQ8d+lUe+ujPSnvnRu5zC ylkg== 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 b6-v6si16746675plx.211.2018.05.05.02.42.36; Sat, 05 May 2018 02:42:50 -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 S1751573AbeEEJmR (ORCPT + 99 others); Sat, 5 May 2018 05:42:17 -0400 Received: from orcrist.hmeau.com ([104.223.48.154]:35446 "EHLO deadmen.hmeau.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751211AbeEEJmQ (ORCPT ); Sat, 5 May 2018 05:42:16 -0400 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 1fEthk-00022q-ON; Sat, 05 May 2018 17:42:12 +0800 Received: from herbert by gondobar with local (Exim 4.89) (envelope-from ) id 1fEthk-0005zn-FT; Sat, 05 May 2018 17:42:12 +0800 Date: Sat, 5 May 2018 17:42:12 +0800 From: Herbert Xu To: NeilBrown Cc: Thomas Graf , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 6/8] rhashtable: further improve stability of rhashtable_walk Message-ID: <20180505094212.hpqjyv5ijibviuwh@gondor.apana.org.au> References: <152540595840.18473.11298241115621799037.stgit@noble> <152540605438.18473.4797800779538116583.stgit@noble> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <152540605438.18473.4797800779538116583.stgit@noble> 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 Fri, May 04, 2018 at 01:54:14PM +1000, 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 (certainly not so easy) to achieve this 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. > No current user of rhltable_walk_enter() calls > rhashtable_walk_start() more than once, so no current code > could benefit from a more reliable walk of rhltables. > > This patch only attempts to improve walks for rhashtables. > - 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 I'm a bit torn on this. On the hand this is definitely an improvement over the status quo. On the other this does not work on rhltable and we do have a way of fixing it for both rhashtable and rhltable. Cheers, -- Email: Herbert Xu Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt