Received: by 10.192.245.15 with SMTP id i15csp1076478imn; Sat, 10 Mar 2018 23:57:23 -0800 (PST) X-Google-Smtp-Source: AG47ELuRNzuvRPgcmQHCBFB30brB0QwhbdgVnES8KGflixHkIeG4ZFAxFVoZUjm7RL9WuHnKqbb4 X-Received: by 2002:a17:902:9883:: with SMTP id s3-v6mr4187037plp.96.1520755043694; Sat, 10 Mar 2018 23:57:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520755043; cv=none; d=google.com; s=arc-20160816; b=MX/2+CNaCGBLz2Hj4h9UfOArSyzTIr+jF92Nwj7g8e/kYAyZUXRy2oB1GJ4rJACZR2 Rfjd4oYOzX0SABrOj4QLYtIl86U8d0H8aGfNYWFW7vmOP20o2J6WJOA7xdU75ub+xxHJ iIqDfWpVogbhAU29ILbo/5QQf6+5jWztTJNGoByUzRaMYVTLXkj9QCKxUHl4JQYhRSA2 C7KchYD3uJnl05Mgq5aF2lYp5HLyL0erYVCSkDeXDjmQQtu9bL4Mv+R+V0gQ1suY+dgg wDNBkTNdVksvQeoHKfqLtvC/djBZe/dBATyZa6oDAm/J7zPkChH0vRDko2udcsFzarYQ 2Y2Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :mime-version:dkim-signature:arc-authentication-results; bh=3BV04Ck8OsGlAyvlAqDT3CT+58bhHcn0+6LiMwwXBME=; b=LbGkAW4dfAH7kSDWWmbHDcYYGNNOnhvKuFNNcR4uF+evgyXrzaYS5HVfZlgr8OKITt y2jn02vpiNGmWVvCyAJMxpnZcI/g/qv3HfCs0GiiqMZuUknzH1kYG9K27iTjnPdespSI vw5TSqDpOp0UCE2MxMdgaIGaTTvoV8kj7V4tbiFMe5242ZSHJypzV0Kp5qeGiNZDyZVW 9mq0X9gYaJHFM3x0yG4pqO4Zgv/ANsrpLcWGqLe6B46BMOTidd1FtrwR0NxQCuvfxFNz apa9hH4YaL0KwVYWtgmC/lTO+N5eQt8HdP15Fprmjr2L5flkKM2vO2v3SwYirr+CTJh/ mZlA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=b1MROi6+; 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 f1si3399617pgr.761.2018.03.10.23.57.07; Sat, 10 Mar 2018 23:57:23 -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=b1MROi6+; 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 S932118AbeCKHzo (ORCPT + 99 others); Sun, 11 Mar 2018 03:55:44 -0400 Received: from mail-oi0-f47.google.com ([209.85.218.47]:42656 "EHLO mail-oi0-f47.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932087AbeCKHzn (ORCPT ); Sun, 11 Mar 2018 03:55:43 -0400 Received: by mail-oi0-f47.google.com with SMTP id c18so10011810oiy.9 for ; Sat, 10 Mar 2018 23:55:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to:cc; bh=3BV04Ck8OsGlAyvlAqDT3CT+58bhHcn0+6LiMwwXBME=; b=b1MROi6+DGMyY/mPlZrx5uZC55xBxzia8CS9iRRvrXCHlUPwB7cotP3uv5nLKsTC3A qPqxmFyN4+QzcW2V4J8x5AjzvPzUbv6SZDcpV3+hyJKnNBNZTTl+uVb1/17bG7lhr5b4 5u5mMhKVHKg7Wg0968TNiRLC4xQUZoo2XVO/Dd1jGmZUIlY2TPh2lvpVDi4z8u0p+4V1 pPQjU6fqQya7Lbwr9xTM8XC/q8fEUjiWDYihlADlqDncjMIXgBvQBdJBriAC9E6FWBli vjxHVb1YrICNTZ2Wrz+aiSFt+VKb9fRPw1oWdnGV8OqMCCY7NVQgWQEZmfWzGDcWXVZU 9u6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to:cc; bh=3BV04Ck8OsGlAyvlAqDT3CT+58bhHcn0+6LiMwwXBME=; b=h2ivvF3sZi6G6BkNFtc1nyc0+aH53iuzO6UXbjl5rcOmkSannbEVeJ2uxadixgWYIe KTncy/Im53hYQbY7O3DL1d/hnqAgjKAYvcIPbu2DVuoMSXMtKHvi9rP3CvU1Ho22rGd/ W1I6MIE6EIbPwtCShPL+WiQoHUVzPfbxRbQEoGw5/iFAfbOCyWL/V7d8fG+nwG+YI9Cw 1crk3R1O6gl80VwQQ6E1/u2Jkp7d8+kTU21MbBODwstO8S4f5kT7Ygeype+eE11azM08 GDPIcQjwfKTXQZp7Prhouh/YCW5gpQ9rZ86irHMF3sCVlK15Evklsk2sK9x7SqAP3lR8 rdoQ== X-Gm-Message-State: AElRT7H7XlREiFDxwZOXm/yiT1HO+aPKx9Uwv/28J3pXzJSGlFDuLFCF q2txGUy+m3VBveE21/sKEL9E3tJaWn5wYXFfM6v8+zj0 X-Received: by 10.202.9.19 with SMTP id 19mr2600469oij.152.1520754942247; Sat, 10 Mar 2018 23:55:42 -0800 (PST) MIME-Version: 1.0 Received: by 10.74.151.230 with HTTP; Sat, 10 Mar 2018 23:55:41 -0800 (PST) From: =?UTF-8?B?54Sm5pmT5Yas?= Date: Sun, 11 Mar 2018 15:55:41 +0800 Message-ID: Subject: smp_mb__after_spinlock requirement too strong? To: linux-kernel@vger.kernel.org Cc: peterz@infradead.org, stern@rowland.harvard.edu, will.deacon@arm.com, torvalds@linux-foundation.org, npiggin@gmail.com, mingo@kernel.org, mpe@ellerman.id.au, oleg@redhat.com, benh@kernel.crashing.org, paulmck@linux.vnet.ibm.com Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Peter pointed out in this patch https://patchwork.kernel.org/patch/9771921/ that the spinning-lock used at __schedule() should be RCsc to ensure visibility of writes prior to __schedule when the task is to be migrated to another CPU. And this is emphasized at the comment of the newly introduced smp_mb__after_spinlock(), * This barrier must provide two things: * * - it must guarantee a STORE before the spin_lock() is ordered against a * LOAD after it, see the comments at its two usage sites. * * - it must ensure the critical section is RCsc. * * The latter is important for cases where we observe values written by other * CPUs in spin-loops, without barriers, while being subject to scheduling. * * CPU0 CPU1 CPU2 * * for (;;) { * if (READ_ONCE(X)) * break; * } * X=1 * * * r = X; * * without transitivity it could be that CPU1 observes X!=0 breaks the loop, * we get migrated and CPU2 sees X==0. which is used at, __schedule(bool preempt) { ... rq_lock(rq, &rf); smp_mb__after_spinlock(); ... } . If I didn't miss something, I found this kind of visibility is __not__ necessarily depends on the spinning-lock at __schedule being RCsc. In fact, as for runnable task A, the migration would be, CPU0 CPU1 CPU2 lock(rq0) schedule out A unock(rq0) lock(rq0) remove A from rq0 unlock(rq0) lock(rq2) add A into rq2 unlock(rq2) lock(rq2) schedule in A unlock(rq2) happens-before unlock(rq0) happends-before lock(rq0) happends-before unlock(rq2) happens-before lock(rq2) happens-before And for stopped tasks, CPU0 CPU1 CPU2 lock(rq0) schedule out A remove A from rq0 store-release(A->on_cpu) unock(rq0) load_acquire(A->on_cpu) set_task_cpu(A, 2) lock(rq2) add A into rq2 unlock(rq2) lock(rq2) schedule in A unlock(rq2) happens-before store-release(A->on_cpu) happens-before load_acquire(A->on_cpu) happens-before unlock(rq2) happens-before lock(rq2) happens-before So, I think the only requirement to smp_mb__after_spinlock is to guarantee a STORE before the spin_lock() is ordered against a LOAD after it. So we could remove the RCsc requirement to allow more efficient implementation. Did I miss something or this RCsc requirement does not really matter?