Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp596927ybh; Tue, 10 Mar 2020 04:51:36 -0700 (PDT) X-Google-Smtp-Source: ADFU+vvah8m9XpsRCk44j/SGjZKCHcLirECKPjHFvaAO3E52XdvjmfmnqDeGBLo50+lVBpJ5wd/C X-Received: by 2002:a9d:4d8f:: with SMTP id u15mr16645171otk.261.1583841095992; Tue, 10 Mar 2020 04:51:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1583841095; cv=none; d=google.com; s=arc-20160816; b=j3CltK3pm5iIlWJUYsoLIELRHk5X908uXvBHC0U94VS+THZBDrPGMCf340HRXqQoUb gJRcNmRFaDpX4LfFvgiz/Raw85D7HwQaCJSExZO/7AfGSGHtQfUCdSoG0a6Mnmw3h0lB 5oSQkgeaCD0cWEVqNEsXN2uKi6JEu+X9s4TjixhTnk9AT39UMUtrQY8RWrz9M4iMbEyH Ln40OX9XSGnto+XKpkHS8PRmc6v0GaTIN6QTPF61SB40Eez/H3IwQPf3+p62q2HXYap0 1e05RDJeqjdcIJ0vaFUxc4cIU3OStA2p3dMYsjB4APez1E0Vp2ZotZEajmqZypunY8qX IQDg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:date:user-agent:message-id:cc:from :subject:to:references:in-reply-to:content-transfer-encoding :mime-version; bh=WghSf6q8cvOnIcbwx4HOX7qRVLGkSFeFEoYDTsHYa9A=; b=0HZ3s1/akYAgFWGx7rzicpkJXPmmm0B3/bpKz3Azb5OE/Qfdt3mM9+byLCK3UVnXp6 qKlEROu5wfUFrE7WVdUBiitCIMdbqoadLsDpjgtwDYnCUZigufEJDy0NXjKhAmsw9yxW 0FaTIcG2bSdGlslwyn90DCspBuytk93ge6bxUBioLSv7PrrIxvxCXcEp4OlpNPmp5DtF urbTOGm1ALmjFQcS7vN7vG8lPxg27NiAHnLE+VFnbaPP3/Du4XpQdL+m9aanFmYZ2XEM J0g/7Fc3QDWQxz1r5LcPAyMd9pBnAT3q9qFFDQnG3UcqRrjh+/9l+ahdILkkGZVIvQ9E B4vQ== 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 r13si235912otd.167.2020.03.10.04.51.24; Tue, 10 Mar 2020 04:51:35 -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 S1726442AbgCJLuP convert rfc822-to-8bit (ORCPT + 99 others); Tue, 10 Mar 2020 07:50:15 -0400 Received: from mail.fireflyinternet.com ([109.228.58.192]:53369 "EHLO fireflyinternet.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726211AbgCJLuP (ORCPT ); Tue, 10 Mar 2020 07:50:15 -0400 X-Default-Received-SPF: pass (skip=forwardok (res=PASS)) x-ip-name=78.156.65.138; Received: from localhost (unverified [78.156.65.138]) by fireflyinternet.com (Firefly Internet (M1)) with ESMTP (TLS) id 20507742-1500050 for multiple; Tue, 10 Mar 2020 11:50:09 +0000 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8BIT In-Reply-To: <2e936d8fd2c445beb08e6dd3ee1f3891@AcuMS.aculab.com> References: <20200310092119.14965-1-chris@chris-wilson.co.uk> <2e936d8fd2c445beb08e6dd3ee1f3891@AcuMS.aculab.com> To: "linux-kernel@vger.kernel.org" , David Laight Subject: RE: [PATCH] list: Prevent compiler reloads inside 'safe' list iteration From: Chris Wilson Cc: "intel-gfx@lists.freedesktop.org" , Andrew Morton , "Paul E. McKenney" , Randy Dunlap , "stable@vger.kernel.org" Message-ID: <158384100886.16414.15741589015363013386@build.alporthouse.com> User-Agent: alot/0.8.1 Date: Tue, 10 Mar 2020 11:50:08 +0000 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Quoting David Laight (2020-03-10 11:36:41) > From: Chris Wilson > > Sent: 10 March 2020 09:21 > > Instruct the compiler to read the next element in the list iteration > > once, and that it is not allowed to reload the value from the stale > > element later. This is important as during the course of the safe > > iteration, the stale element may be poisoned (unbeknownst to the > > compiler). > > Eh? > I thought any function call will stop the compiler being allowed > to reload the value. > The 'safe' loop iterators are only 'safe' against called > code removing the current item from the list. > > > This helps prevent kcsan warnings over 'unsafe' conduct in releasing the > > list elements during list_for_each_entry_safe() and friends. > > Sounds like kcsan is buggy ???? The warning kcsan gave made sense (a strange case where the emptying the list from inside the safe iterator would allow that list to be taken under a global mutex and have one extra request added to it. The list_for_each_entry_safe() should be ok in this scenario, so long as the next element is read before this element is dropped, and the compiler is instructed not to reload the element. kcsan is a little more insistent on having that annotation :) In this instance I would say it was a false positive from kcsan, but I can see why it would complain and suspect that given a sufficiently aggressive compiler, we may be caught out by a late reload of the next element. That's my conjecture, but I leave it to the lkmm experts to decide :) -Chris