Received: by 10.223.185.116 with SMTP id b49csp5023950wrg; Wed, 7 Mar 2018 05:15:23 -0800 (PST) X-Google-Smtp-Source: AG47ELtBRZf6aqrJYT8Tpe+NH5cLmqEB5gyv8GsYf9wyEty/j0wlOhoDcxt/y2n3eyQBa7m8yV7C X-Received: by 10.101.91.199 with SMTP id o7mr18501808pgr.9.1520428522995; Wed, 07 Mar 2018 05:15:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520428522; cv=none; d=google.com; s=arc-20160816; b=fSlk3DkvEgRqRy0/a7UC1TtZFXs/yp+pwMk6VPaNV2fROvpsl+lpnfc13Ee8SSzXmD PS+40be5P8gm1t4fTqLuT/VSe8hp+StrkaB+BMB/M//6B50aSdZVQq6wGWS2oSyYiE9S 7wkjWWRNKg7vmJ+qH6oeHgvtVArqRTjBpsXCHatYWK/O74M+n4huXHNaXxSyVfZTSqKa 667jCltYOLlemJ6MuChb+b5sxJc1jH/twmIp4MQAeAzW+qwc97orQ3FEqIrniFZOl/VU z72BeYFq3X/ZvRrp0fZbiJteqItWIVmZ/Rw/kTc6BKV2H9GO52NWhQ94D6Zw5I1F3a9o MFKQ== 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:dkim-signature:arc-authentication-results; bh=TVprzBq2666NgPb3NLPW0awRPJIBVvLxuiqDp5E+I9E=; b=udHzb8IylaSat0lEZf3vHYohcVdrHTiHelXqG21x3xbbp6PKexgRCy+dFA5Jxk57GA znm3Vz6t3QsZRG1OlAM8tnMIOecOR3E5VyPUdQcW3k4rbstdvs9sGQ0DN3SdRnm8Ltog FzskJDgLppfQO9kBTGIYK4W6H4J1LqA7xZKP/6rR50GCwbHXvzqhqm73Xoi7Io6CNgSG UQBr6PS8toPszi9D2y6b7BiSy/kSLC8EIjKN+mPzUUpUiMx427sdu/6nUYClCS20YTKy fiFFy3r5CAFl32kB7/5mBwMrnRlNkbnLKo/YEJ/aGi3EGyEKemGq6sc7QNFkYSApFEaE 3q4w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=mS1RhyXS; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v5si7678919pfe.59.2018.03.07.05.15.08; Wed, 07 Mar 2018 05:15:22 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=mS1RhyXS; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754424AbeCGNNy (ORCPT + 99 others); Wed, 7 Mar 2018 08:13:54 -0500 Received: from mail-wm0-f66.google.com ([74.125.82.66]:52301 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754331AbeCGNNv (ORCPT ); Wed, 7 Mar 2018 08:13:51 -0500 Received: by mail-wm0-f66.google.com with SMTP id t3so4693398wmc.2 for ; Wed, 07 Mar 2018 05:13:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=TVprzBq2666NgPb3NLPW0awRPJIBVvLxuiqDp5E+I9E=; b=mS1RhyXSLzv5T/IGPCUA8syebytCfP6TNmlf/VD/FmqLCXLY2jXbbnJSd6bAIaPUjY PErT1n7pP6MILyF4wPi+E0B16b5OfOEpHJjflQOJY/l7vvsTLkm/RfbXk7DXjwjC5uVa G8Rse4C8kYYp1HW0odasSCh3pjxUxqyqL5KstQUkqPiQMA7CbDvf5Yu92d8Uc3OiC/wq fSbqg1snCLKJTaPrNSQZn6rk5COUwhou5PeBnJEibSKQ/59+MCjwwPJAk5M180NDgkJV 0eFT56b/H3irA/osBV9NgvtL4zu6yKftFBR7facQAPz8I+abAQtIzCiD9c8WIEsSuHyi 37KQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=TVprzBq2666NgPb3NLPW0awRPJIBVvLxuiqDp5E+I9E=; b=roubEezuUOvG7sYpOdZApgjiQ7qpyyEBuwvFuwyyvgj24dVriDIIwdCi296JbdsDX0 ktBZs2RKn8GgsZ/26lI7WbFJA/z03TUMVDj0jY7owJT7s+jgoZ4iZeOvTozQmJ5urJRJ Wi3DfOr/Y0fQryjTrCQr9TFvvDZRaVX8JDhcg72YqpV1SNlhdXUYmt64rBueOu80gtlg KtyVPG068lcnmplM6KsiLnr7fn/tMMeiJ9H1xxVb+UDhRqlBBEUHIu6CJzviLb0IGkZp JFtMd8fdDeXVkq5Cfdw9W7R0pP00rCoCmh+7gmlb5dx2UsC5j3R9ttnbuKbiNqddCLgu phNQ== X-Gm-Message-State: AElRT7Forw6Joa7mu57iKFHDVL5ZZxZ1NVdr8i1F6eloQz7TIQeSKFpZ dNPePyr+Wf17ukFrGZlVbdo= X-Received: by 10.28.163.5 with SMTP id m5mr13460431wme.7.1520428429506; Wed, 07 Mar 2018 05:13:49 -0800 (PST) Received: from andrea (85.100.broadband17.iol.cz. [109.80.100.85]) by smtp.gmail.com with ESMTPSA id y65sm2620111wmg.25.2018.03.07.05.13.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 07 Mar 2018 05:13:49 -0800 (PST) Date: Wed, 7 Mar 2018 14:13:41 +0100 From: Andrea Parri To: Will Deacon Cc: linux-kernel@vger.kernel.org, Alan Stern , Peter Zijlstra , Boqun Feng , Nicholas Piggin , David Howells , Jade Alglave , Luc Maranget , "Paul E. McKenney" , Akira Yokosawa , Daniel Thompson , Jason Wessel Subject: Re: [PATCH] Documentation/locking: Document the semantics of spin_is_locked() Message-ID: <20180307131341.GA28486@andrea> References: <1519814372-19941-1-git-send-email-parri.andrea@gmail.com> <20180228105631.GA7681@arm.com> <20180228112403.GA32228@andrea> <20180228113456.GC7681@arm.com> <20180228121523.GA354@andrea> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180228121523.GA354@andrea> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Feb 28, 2018 at 01:15:23PM +0100, Andrea Parri wrote: > On Wed, Feb 28, 2018 at 11:34:56AM +0000, Will Deacon wrote: [...] >> only if there's some evidence that you've looked at the callsites >> and determined that they won't break. I looked at the callsites for {,raw_}spin_is_locked() (reported below): In most cases (40+), these primitives are used within BUG_ON/WARN_ON or the like; a handful of other cases using these with no concurrency, for checking "self-lock", or for heuristics. I confirm that the "ipc/sem.c" case, mentioned in the arm64 and powerpc commits adding smp_mb() to their arch_spin_is_locked(), disappeared. And that the "debug_core" case seems to be the only case requiring some thoughts: my understanding (but I Cc the KGDB maintainers, so that they can correct me, or provide other details) is that KGDB does not rely on implicit barriers in raw_spin_is_locked(). (This seems instead to rely on barriers in the IPIs sending/handling, in part., kgdb_roundup_cpus, kgdb_nmicallback; yes, these barriers are not documented, but I've discussed with Daniel, Jason about the eventuality of adding such documentations/inline comments.) (N.B. I have _not_ tested any of these observations, say by removing the smp_mb() from your implementation; so, you know...) Andrea ./mm/khugepaged.c:1222: VM_BUG_ON(NR_CPUS != 1 && !spin_is_locked(&khugepaged_mm_lock)); ./mm/khugepaged.c:1663: VM_BUG_ON(NR_CPUS != 1 && !spin_is_locked(&khugepaged_mm_lock)); ./mm/swap.c:828: VM_BUG_ON(NR_CPUS != 1 && !spin_is_locked(&lruvec_pgdat(lruvec)->lru_lock)); ./security/apparmor/file.c:497: old = rcu_dereference_protected(fctx->label, spin_is_locked(&fctx->lock)); ./net/netfilter/ipset/ip_set_hash_gen.h:18: __ipset_dereference_protected(p, spin_is_locked(&(set)->lock)) ./fs/ocfs2/dlmglue.c:760: mlog_bug_on_msg(spin_is_locked(&res->l_lock), ./fs/ocfs2/inode.c:1194: mlog_bug_on_msg(spin_is_locked(&oi->ip_lock), ./fs/userfaultfd.c:156: VM_BUG_ON(spin_is_locked(&ctx->fault_pending_wqh.lock)); ./fs/userfaultfd.c:158: VM_BUG_ON(spin_is_locked(&ctx->fault_wqh.lock)); ./fs/userfaultfd.c:160: VM_BUG_ON(spin_is_locked(&ctx->event_wqh.lock)); ./fs/userfaultfd.c:162: VM_BUG_ON(spin_is_locked(&ctx->fd_wqh.lock)); ./fs/userfaultfd.c:919: VM_BUG_ON(!spin_is_locked(&wqh->lock)); ./virt/kvm/arm/vgic/vgic.c:192: DEBUG_SPINLOCK_BUG_ON(!spin_is_locked(&irq->irq_lock)); ./virt/kvm/arm/vgic/vgic.c:269: DEBUG_SPINLOCK_BUG_ON(!spin_is_locked(&vgic_cpu->ap_list_lock)); ./virt/kvm/arm/vgic/vgic.c:307: DEBUG_SPINLOCK_BUG_ON(!spin_is_locked(&irq->irq_lock)); ./virt/kvm/arm/vgic/vgic.c:663: DEBUG_SPINLOCK_BUG_ON(!spin_is_locked(&irq->irq_lock)); ./virt/kvm/arm/vgic/vgic.c:694: DEBUG_SPINLOCK_BUG_ON(!spin_is_locked(&vgic_cpu->ap_list_lock)); ./virt/kvm/arm/vgic/vgic.c:715: DEBUG_SPINLOCK_BUG_ON(!spin_is_locked(&vgic_cpu->ap_list_lock)); ./virt/kvm/kvm_main.c:3934: WARN_ON(raw_spin_is_locked(&kvm_count_lock)); ./kernel/debug/debug_core.c:527: if (!raw_spin_is_locked(&dbg_slave_lock)) ./kernel/debug/debug_core.c:755: raw_spin_is_locked(&dbg_master_lock)) { ./kernel/locking/spinlock_debug.c:98: SPIN_BUG_ON(!raw_spin_is_locked(lock), lock, "already unlocked"); ./kernel/locking/mutex-debug.c:39: SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock)); ./kernel/locking/mutex-debug.c:54: SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock)); ./kernel/futex.c:1368: if (WARN_ON_SMP(!q->lock_ptr || !spin_is_locked(q->lock_ptr)) ./kernel/printk/printk_safe.c:281: if (in_nmi() && raw_spin_is_locked(&logbuf_lock)) { // same cpu (printk in nmi) ./kernel/printk/printk_safe.c:314: raw_spin_is_locked(&logbuf_lock)) { // same cpu (printk in nmi) ./include/net/sock.h:1529: return !sk->sk_lock.owned && !spin_is_locked(&sk->sk_lock.slock); // returns in BUG_ON/WARN_ON_ONCE ./arch/x86/pci/i386.c:62: WARN_ON_SMP(!spin_is_locked(&pcibios_fwaddrmap_lock)); ./arch/cris/arch-v32/drivers/cryptocop.c:3446: printk("cryptocop_completed_jobs_lock %d\n", spin_is_locked(&cryptocop_completed_jobs_lock)); ./arch/cris/arch-v32/drivers/cryptocop.c:3447: printk("cryptocop_job_queue_lock %d\n", spin_is_locked(&cryptocop_job_queue_lock)); ./arch/cris/arch-v32/drivers/cryptocop.c:3448: printk("descr_pool_lock %d\n", spin_is_locked(&descr_pool_lock)); ./arch/cris/arch-v32/drivers/cryptocop.c:3449: printk("cryptocop_sessions_lock %d\n", spin_is_locked(cryptocop_sessions_lock)); ./arch/cris/arch-v32/drivers/cryptocop.c:3450: printk("running_job_lock %d\n", spin_is_locked(running_job_lock)); ./arch/cris/arch-v32/drivers/cryptocop.c:3451: printk("cryptocop_process_lock %d\n", spin_is_locked(cryptocop_process_lock)); ./arch/parisc/kernel/firmware.c:208: if (spin_is_locked(&pdc_lock)) // self-lock: if (is_locked) unlock(pdc_lock) ./drivers/staging/irda/drivers/sir_dev.c:637: if(spin_is_locked(&dev->tx_lock)) { // for debug ./drivers/staging/lustre/lustre/osc/osc_cl_internal.h:189: return spin_is_locked(&obj->oo_lock); // for assert ./drivers/tty/serial/sn_console.c:891: if (spin_is_locked(&port->sc_port.lock)) { // single lock ./drivers/tty/serial/sn_console.c:908: if (!spin_is_locked(&port->sc_port.lock) // single lock ./drivers/misc/sgi-xp/xpc_channel.c:31: DBUG_ON(!spin_is_locked(&ch->lock)); ./drivers/misc/sgi-xp/xpc_channel.c:85: DBUG_ON(!spin_is_locked(&ch->lock)); ./drivers/misc/sgi-xp/xpc_channel.c:761: DBUG_ON(!spin_is_locked(&ch->lock)); ./drivers/misc/sgi-xp/xpc_sn2.c:1674: DBUG_ON(!spin_is_locked(&ch->lock)); ./drivers/misc/sgi-xp/xpc_uv.c:1186: DBUG_ON(!spin_is_locked(&ch->lock)); ./drivers/net/ethernet/smsc/smsc911x.h:70: WARN_ON_SMP(!spin_is_locked(&pdata->mac_lock)) ./drivers/net/ethernet/intel/igbvf/mbx.c:267: WARN_ON_ONCE(!spin_is_locked(&hw->mbx_lock)); ./drivers/net/ethernet/intel/igbvf/mbx.c:305: WARN_ON_ONCE(!spin_is_locked(&hw->mbx_lock)); ./drivers/net/ethernet/intel/i40e/i40e_main.c:1527: WARN(!spin_is_locked(&vsi->mac_filter_hash_lock), ./drivers/net/wireless/zydas/zd1211rw/zd_mac.c:238: ZD_ASSERT(!spin_is_locked(&mac->lock)); ./drivers/scsi/fnic/fnic_scsi.c:184: int sh_locked = spin_is_locked(host->host_lock); // self-lock: if (!is_locked) lock(host_lock) ./drivers/scsi/snic/snic_scsi.c:2004: SNIC_BUG_ON(!spin_is_locked(io_lock)); ./drivers/scsi/snic/snic_scsi.c:2607: SNIC_BUG_ON(!spin_is_locked(io_lock)); ./drivers/atm/nicstar.c:2692: if (spin_is_locked(&card->int_lock)) { // optimization ("Probably it isn't worth spinning") ./drivers/hv/hv_balloon.c:644: WARN_ON_ONCE(!spin_is_locked(&dm_device.ha_lock));