Received: by 2002:a05:6358:a55:b0:ec:fcf4:3ecf with SMTP id 21csp1120087rwb; Fri, 13 Jan 2023 08:09:28 -0800 (PST) X-Google-Smtp-Source: AMrXdXvvcJo35zpUkSndT7So7Rxknh8LaGktQvkcsj5GHz6ESubssFpiV4qoVxSwd7MfAQ+hDvTP X-Received: by 2002:a17:90a:64cb:b0:229:131:1221 with SMTP id i11-20020a17090a64cb00b0022901311221mr6659872pjm.5.1673626167811; Fri, 13 Jan 2023 08:09:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673626167; cv=none; d=google.com; s=arc-20160816; b=ARF0j8yhaFjv7tODOPZfbaXUBaCeVa/RDLrYUv/P357TDkeMM9wDPEMEc76mkmJwev YDOg3Bs8BRYK9MRPcgerhnw8XTowNl1GFtisUJfxJMCyoXkFcv7uh5JeYgjvTcSAV3ZB nOwc9wcyiAONwGLei78pPMKhVW3fTL0AfnedgiB4B65bbI+gKDwxSZeo7npkT6S6p57v EgTMItr6XZNbDJHiFRYIpSWTHwRSfFW+Toq/g28L1mbQYfCch1+peDc8kS7qSfR9kvGA lt4UsK+MzWq0jW2+uc/dLKKC43mJgkkQcfIY/OablmPkg11X7nfe8lcMcCS+hwW2wGyG 3wyg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=FPu6qBdavJQREs7/EEzUjm6MMn4shw3ml1lXDQ1VGeY=; b=iBB/1QXx7GQx9s8ih13/LSzyDcEuFAFlEFeVFnYzmaCZ2HgViO2079XF4zNv6MFimo dIFOWJ71clBqGSU3oq5zmi17bcq6eu2/W6zqokhf4lUndBfZvAty9n4Iiv/cRFud+6tc U75A42rquTS2uEQdjN7epCBSiIIGfe1O4vxUTO0Ym+xoxGQHVN53uzaBZwit7uI134SU cFfRkBar4x0CTBf8wiRUNJyX2bFpI9tfX4lgqFMUkbDgEeEcq9rFul926FL3JBb7N24L BDrOAJXgBkQ16Ghy+A3UdZMCQMiVtnNfMkEIIHDi24LJKla/xCEh29A0ENg3tmx0JkPT +H5Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id rj14-20020a17090b3e8e00b0022692bdf6c0si4302892pjb.49.2023.01.13.08.09.20; Fri, 13 Jan 2023 08:09:27 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230239AbjAMP3u (ORCPT + 51 others); Fri, 13 Jan 2023 10:29:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46466 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230233AbjAMP22 (ORCPT ); Fri, 13 Jan 2023 10:28:28 -0500 Received: from netrider.rowland.org (netrider.rowland.org [192.131.102.5]) by lindbergh.monkeyblade.net (Postfix) with SMTP id C4CA678250 for ; Fri, 13 Jan 2023 07:22:21 -0800 (PST) Received: (qmail 22532 invoked by uid 1000); 13 Jan 2023 10:22:20 -0500 Date: Fri, 13 Jan 2023 10:22:20 -0500 From: Alan Stern To: Paul =?iso-8859-1?Q?Heidekr=FCger?= Cc: "Paul E. McKenney" , Andrea Parri , Will Deacon , Peter Zijlstra , Boqun Feng , Nicholas Piggin , David Howells , Jade Alglave , Luc Maranget , Akira Yokosawa , Daniel Lustig , Joel Fernandes , linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org, llvm@lists.linux.dev, Marco Elver , Charalampos Mainas , Pramod Bhatotia , Soham Shakraborty , Martin Fink Subject: Re: Broken Address Dependency in mm/ksm.c::cmp_and_merge_page() Message-ID: References: <20220426203254.GJ4285@paulmck-ThinkPad-P17-Gen-1> <20220531150312.GH1790663@paulmck-ThinkPad-P17-Gen-1> <0EC00B0E-554A-4BF3-B012-ED1E36B12FD1@tum.de> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <0EC00B0E-554A-4BF3-B012-ED1E36B12FD1@tum.de> X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,SPF_HELO_PASS,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jan 13, 2023 at 12:11:25PM +0100, Paul Heidekr?ger wrote: > Hi all, > > FWIW, here are two more broken address dependencies, both very similar to the > one discussed in this thread. From what I can tell, both are protected by a > lock, so, again, nothing to worry about right now? Would you agree? FWIW, my opinion is that in both cases the broken dependency can be removed entirely. > Comments marked with "AD:" were added by me for readability. > > 1. drivers/hwtracing/stm/core.c::1050 - 1085 > > /** > * __stm_source_link_drop() - detach stm_source from an stm device > * @src: stm_source device > * @stm: stm device > * > * If @stm is @src::link, disconnect them from one another and put the > * reference on the @stm device. > * > * Caller must hold stm::link_mutex. > */ > static int __stm_source_link_drop(struct stm_source_device *src, > struct stm_device *stm) > { > struct stm_device *link; > int ret = 0; > > lockdep_assert_held(&stm->link_mutex); > > /* for stm::link_list modification, we hold both mutex and spinlock */ > spin_lock(&stm->link_lock); > spin_lock(&src->link_lock); > > /* AD: Beginning of the address dependency. */ > link = srcu_dereference_check(src->link, &stm_source_srcu, 1); > > /* > * The linked device may have changed since we last looked, because > * we weren't holding the src::link_lock back then; if this is the > * case, tell the caller to retry. > */ > if (link != stm) { > ret = -EAGAIN; > goto unlock; > } > > /* AD: Compiler deduces that "link" and "stm" are exchangeable at this point. */ > stm_output_free(link, &src->output); list_del_init(&src->link_entry); > > /* AD: Leads to WRITE_ONCE() to (&link->dev)->power.last_busy. */ > pm_runtime_mark_last_busy(&link->dev); In both of these statements, link can safely be replaced by stm. (There's also a control dependency which the LKMM isn't aware of. This makes it all the more safe.) > 2. kernel/locking/lockdep.c::6319 - 6348 > > /* > * Unregister a dynamically allocated key. > * > * Unlike lockdep_register_key(), a search is always done to find a matching > * key irrespective of debug_locks to avoid potential invalid access to freed > * memory in lock_class entry. > */ > void lockdep_unregister_key(struct lock_class_key *key) > { > struct hlist_head *hash_head = keyhashentry(key); > struct lock_class_key *k; > struct pending_free *pf; > unsigned long flags; > bool found = false; > > might_sleep(); > > if (WARN_ON_ONCE(static_obj(key))) > return; > > raw_local_irq_save(flags); > lockdep_lock(); > > /* AD: Address dependency begins here with an rcu_dereference_raw() into k. */ > hlist_for_each_entry_rcu(k, hash_head, hash_entry) { > /* AD: Compiler deduces that k and key are exchangable iff the if condition evaluates to true. > if (k == key) { > /* AD: Leads to WRITE_ONCE() to (&k->hash_entry)->pprev. */ > hlist_del_rcu(&k->hash_entry); And here k could safely be replaced with key. (And again there is a control dependency, but this is one that the LKMM would detect.) Alan Stern > found = true; > break; > } > } > > Many thanks, > Paul