Received: by 10.223.185.116 with SMTP id b49csp5113470wrg; Wed, 7 Mar 2018 06:39:02 -0800 (PST) X-Google-Smtp-Source: AG47ELueKwMbPjFt0T2eBZGbSxAyKFUsFz+30arYl43m0GUvEhTLAH+ZGjL/sgLv+Jh/WgJUZjTW X-Received: by 10.98.34.143 with SMTP id p15mr23010621pfj.101.1520433542361; Wed, 07 Mar 2018 06:39:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520433542; cv=none; d=google.com; s=arc-20160816; b=w2C9xC2lYdDelqwd8eChJCSE7urz0EHGJiG368yi9l4l1Eycx7j+mr+NmDPbAj5OT+ RH6Tjz+MHtiqnBQHj1sjW9x2eklYSEcTSp5hAa2atyW4zi1AInLpuVWJVYC8GioNyc9U noGGBT0CLsNNdZBazxvScssQg/6n+uTfojgG2CqTg1T+DtT8y/xWj0Bl6B/9wmNiDzG7 9QmR7K7EEuhTW8jALeOlblxubVKgEUtvtAIHExgXKb+cUPLvaW6vxBorCoZnnBmn/WCS ClHxwp/oXslHDM8r/+kiDMSPo8c71PZQcgCVb+CQ0FmsVO+6JrjrGS1HVLbOCKSOqGOI 3aUQ== 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=DKt8cIbUzoUqogsOuz0wmdw/nNnK3G6fBCrMZ5Hw9U4=; b=kuKS4HrYgS7c18GdApthpXZbG/WKyZ5K/I/OF+jZqtcI3CXPshb1TzbMonSCV+LOgk +tpRUIsekH9dk0hPSMogS+b7g2+XYpRNzWjck1K4I/bO4Y4Ylp5R9n2uhJ6GUE/c1EeW XlZlGC19leZcfU2rsGNhVhIrGfOGWgBn7i075OoOFrD1XDeK73seQDHGrr3ul1Q0M5Vz VXceeL0jRRuHk4PDvGK4WflULjS2A5Eb5l0ilSDBvt4NkHYEIPUYCNtllaF3ftJAOtI2 vEXRy5JrlYR3Deya85RijBSKMN+WoLGiy1JtdQxhxE/S8UO04BLb1a7ZFJfFQ4KuyAsk IdMQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=XZO4Dw8E; 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=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a9-v6si13323329pln.89.2018.03.07.06.38.48; Wed, 07 Mar 2018 06:39:02 -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=@linaro.org header.s=google header.b=XZO4Dw8E; 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=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754473AbeCGOhg (ORCPT + 99 others); Wed, 7 Mar 2018 09:37:36 -0500 Received: from mail-wr0-f175.google.com ([209.85.128.175]:35966 "EHLO mail-wr0-f175.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751284AbeCGOhf (ORCPT ); Wed, 7 Mar 2018 09:37:35 -0500 Received: by mail-wr0-f175.google.com with SMTP id v111so2410025wrb.3 for ; Wed, 07 Mar 2018 06:37:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=DKt8cIbUzoUqogsOuz0wmdw/nNnK3G6fBCrMZ5Hw9U4=; b=XZO4Dw8E+ov0U6W9x7XsXJ5/dMSu0tIrY2LaoDfw09HnjwAMcecjL3pF2lLhO+lLQS aQ+vYGMs2LZ5DYNzGwQVA/AxTwCDctcPJiOOxn9xipobsPtiZ9l1UL1eo4SbwRCgUVBP 4GNVHwxg6GG8P5Eh+zyk5LyEsXOjiKHdGhGRw= 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=DKt8cIbUzoUqogsOuz0wmdw/nNnK3G6fBCrMZ5Hw9U4=; b=KHKo4DBvsr+XCu8osNm5od3k/G+0070JgTKaJ/y9sIQ1nOINOuSI5w4WNiBUwgCZ3i KvEFDvUbyBr1PQnQ7L5bt5+QIN2t/PzGjZ67HmVgxkyaAZ5GIERC56S+YZ6itzDlgx6K 9ZDi8HcbHNCHvhwQ2caVEWgoApNMWj2eH0uvLpgQYz10pXd9uv8zU4sgPQD3iSqwATpP 5XTR7I2kiPWAsaQ5zUbiJouueLXZwQJI+HiNXvRtwzIlqBCZK3IXJGpTc3H/70FkRhMT /0pocPPoTnYKmmnLfQAfBxuWKNazNEPXe4jbv/XWszG6Br2M0Goby3E9XesGdQ8de+Z4 nQoQ== X-Gm-Message-State: APf1xPD6aAnS88ZHwCAo4SLPPsnOCeElhBgo6RU8JEZTt6B1heVvyQFE 3D00y5qtZasqVHmQRDH/TFOdPg== X-Received: by 10.223.182.2 with SMTP id f2mr17961575wre.117.1520433453828; Wed, 07 Mar 2018 06:37:33 -0800 (PST) Received: from holly.lan (cpc141214-aztw34-2-0-cust773.18-1.cable.virginm.net. [86.9.19.6]) by smtp.gmail.com with ESMTPSA id j126sm11355135wmb.33.2018.03.07.06.37.32 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 07 Mar 2018 06:37:32 -0800 (PST) Date: Wed, 7 Mar 2018 14:37:30 +0000 From: Daniel Thompson To: Andrea Parri Cc: Will Deacon , linux-kernel@vger.kernel.org, Alan Stern , Peter Zijlstra , Boqun Feng , Nicholas Piggin , David Howells , Jade Alglave , Luc Maranget , "Paul E. McKenney" , Akira Yokosawa , Jason Wessel Subject: Re: [PATCH] Documentation/locking: Document the semantics of spin_is_locked() Message-ID: <20180307143730.y7hoo3vjbogx6gmr@holly.lan> 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> <20180307131341.GA28486@andrea> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180307131341.GA28486@andrea> User-Agent: NeoMutt/20180223 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Mar 07, 2018 at 02:13:41PM +0100, Andrea Parri wrote: > 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.) Indeed. Whilst responding to queries from Andrea I certainly saw opportunities to clean things up... and the result of those clean ups would actually be the removal of both calls to raw_spin_is_locked(). Nevertheless, for now lets deal with the code as it is: The calls to raw_spin_is_locked() within debug-core will pretty much always be from cores that did not take the lock because the code is triggered once we have selected a master and are rounding up the other cpus. Thus we do have to analyse the sequencing here. Pretty much every architecture I looked at implements the round up using the IPI machinery (hardly surprising; this is obvious way to implement it). I think this provides the required barriers implicitly so the is-this-round-up code will correctly observe the locks to be locked when triggered via an IPI. It is more difficult to describe the analysis if the is-this-a-round-up code is spuriously triggered before the IPI but so far I've not come up with anything worse than a benign race (which exists even with barriers). The round up code will eventually figure out it has spuriously tried to park and will exit without altering important state. The return value of kgdb_nmicallback() does change in this case but no architecture cares about that[1]. Daniel [1] So one of the clean ups I alluded to above is therefore to remove the return code ;-) . > (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));