Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1268442imu; Wed, 16 Jan 2019 16:04:24 -0800 (PST) X-Google-Smtp-Source: ALg8bN7UJoJhSQJeR8NuuPV2IYWMsH7DSUzwy6EcC2hUNshbbIAotcFG5uK6eeAWi6dT2XXPqF3r X-Received: by 2002:a63:9843:: with SMTP id l3mr11290471pgo.413.1547683464878; Wed, 16 Jan 2019 16:04:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547683464; cv=none; d=google.com; s=arc-20160816; b=WPC2sXp0IeXQ9F7ajzk8lRWbmLyjvm7CkFXL0qTDJ0G9G8E+3AhQuPvrHJ2dShlkXx HOc1dnjy65lU+Cne9SDtUlhFqPdkoFaA/EggwVZMa/X6DNkQgpSrJba5NHIhHAyAmcCa TkM5JEswdlsQvI5OeWRit+3bvqNFkM7AY80VMjfkLxwWYYB83I0iaYUipW7+FueGMjc1 A5socrpkDdHKaOAWnM/tHhk0iciqw6Ykj24ow/I/E8/FpwcdUz/jZOra4z56TvYN3Ll/ 5R2Cb3qstlFz+IgaXp2zrDfHhRvbY1LS8wRrlbHtf+x9rSn6mXkQlqSfTImZ88VxvZQu tLbQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=QcX86HO5efLkf6puBxvbFpxHB6+66GFgK3rJrAkhTQw=; b=daHwL/mzNNa7777FEYj0rITyWNIYe8+HWPFQo38fi4i56+thG10rC24sFuTAWRaPoV 7ErCAjjcCGQK2xxBxJ0z36Uyp7+BpyacFLibHacpXtB0J4Zb4tuapskjDzZ7XM7dnAym 5FpuOctjxtJitxBC5a5KkLImkKVIFfRIHcdlUfubVDpBLWTwpK7F7vcXBCeJnQwUtV1N MpsQ98GbQOR4e9UVgUof8TKyYgwAKRoaZI1gFp26czCv4wjoVb28sPPWaqFWcVzYQP43 YzchhfAj6BZ8chZqr0MT06bMgWgx9GVGXouhFJ+i21p39taJlX+6N6Dkm9fgZSqy4LjF 32KA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=mbmLl44g; 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 y22si8144728pfa.6.2019.01.16.16.04.09; Wed, 16 Jan 2019 16:04:24 -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=@amarulasolutions.com header.s=google header.b=mbmLl44g; 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 S1729587AbfAPSm5 (ORCPT + 99 others); Wed, 16 Jan 2019 13:42:57 -0500 Received: from mail-ed1-f65.google.com ([209.85.208.65]:39737 "EHLO mail-ed1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728621AbfAPSm5 (ORCPT ); Wed, 16 Jan 2019 13:42:57 -0500 Received: by mail-ed1-f65.google.com with SMTP id b14so6267376edt.6 for ; Wed, 16 Jan 2019 10:42:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; h=from:to:cc:subject:date:message-id; bh=QcX86HO5efLkf6puBxvbFpxHB6+66GFgK3rJrAkhTQw=; b=mbmLl44g3r5uAuYroHp36LZZJ2ni1O503MmKwJSZkZ1jl6/sBgUpXOKdzmW1vhXUOH WuSMzqWqYle0zR+BYY2motnWYt+yYOulE+EW4j6aw5MeCptT1gbjK27NfS6Ovf9ELWID 45kIZz0KdnGP6f0Vy4X4UkGuaiyQxjWqAY3vQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=QcX86HO5efLkf6puBxvbFpxHB6+66GFgK3rJrAkhTQw=; b=lcvtVt/iAXd92xJklWKkbTl4T8a2FFgX3yli96Bbh59Al3c45TffbLAfW/PyGO+JZa lcNghyx/+IjoWe+M9nQtIK7ii642NUlU88zUNmiew7k3EGVvNVBW/sAOoMVniAiMPUYj GZkd9bsTp4Ds2xMaGXkyWsjqdAKMOybdE/j/wuEifl5gfuRPRl2ZhjdcY+QI3WLxXT6/ lN5SKV0Wm18oLAmV+4YAdPe0BD4ZCpvZfeky9SL7gUxXOMP+99IH4LlqQO721iwNn7A2 J+ZTJZfs0Z70TWWgdIHgzICrHS+dNsftQzQItj9oiE3WbqtZxYvEx8E8BNGcE81cdEbt cfBQ== X-Gm-Message-State: AJcUukf8etuB8Tjo3lWiqE1p8By7ReFGhkgY7kCIiFsEZ8dxX2OrFhF1 eDaVMhIfJiK7zLjA6lsXDwEhtx6kHG/IXw== X-Received: by 2002:a50:d643:: with SMTP id c3mr8288825edj.178.1547664175186; Wed, 16 Jan 2019 10:42:55 -0800 (PST) Received: from andrea.amarulasolutions.com (85.100.broadband17.iol.cz. [109.80.100.85]) by smtp.gmail.com with ESMTPSA id l18sm5570286edq.87.2019.01.16.10.42.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 16 Jan 2019 10:42:54 -0800 (PST) From: Andrea Parri To: linux-kernel@vger.kernel.org Cc: Andrea Parri , Ingo Molnar , Peter Zijlstra , "Paul E. McKenney" , Alan Stern Subject: [PATCH] sched: Use READ_ONCE()/WRITE_ONCE() in task_cpu()/__set_task_cpu() Date: Wed, 16 Jan 2019 19:42:18 +0100 Message-Id: <20190116184218.13757-1-andrea.parri@amarulasolutions.com> X-Mailer: git-send-email 2.17.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The smp_wmb() in move_queued_task() (c.f., __set_task_cpu()) pairs with the composition of the dependency and the ACQUIRE in task_rq_lock(): move_queued_task() task_rq_lock() [S] ->on_rq = MIGRATING [L] rq = task_rq() WMB (__set_task_cpu()) ACQUIRE (rq->lock); [S] ->cpu = new_cpu [L] ->on_rq where "[L] rq = task_rq()" is ordered before "ACQUIRE (rq->lock)" by an address dependency and, in turn, "ACQUIRE (rq->lock)" is ordered before "[L] ->on_rq" by the ACQUIRE itself. Use READ_ONCE() to load ->cpu in task_rq() (c.f., task_cpu()) to honour this address dependency between loads; also, mark the store to ->cpu in __set_task_cpu() by using WRITE_ONCE() in order to tell the compiler to not mess/tear this (synchronizing) memory access. Signed-off-by: Andrea Parri Cc: Ingo Molnar Cc: Peter Zijlstra Cc: "Paul E. McKenney" Cc: Alan Stern --- include/linux/sched.h | 4 ++-- kernel/sched/sched.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/include/linux/sched.h b/include/linux/sched.h index 224666226e87b..2bb02c9635bd8 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -1753,9 +1753,9 @@ static __always_inline bool need_resched(void) static inline unsigned int task_cpu(const struct task_struct *p) { #ifdef CONFIG_THREAD_INFO_IN_TASK - return p->cpu; + return READ_ONCE(p->cpu); #else - return task_thread_info(p)->cpu; + return READ_ONCE(task_thread_info(p)->cpu); #endif } diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h index d04530bf251fe..270a3333589d2 100644 --- a/kernel/sched/sched.h +++ b/kernel/sched/sched.h @@ -1460,9 +1460,9 @@ static inline void __set_task_cpu(struct task_struct *p, unsigned int cpu) */ smp_wmb(); #ifdef CONFIG_THREAD_INFO_IN_TASK - p->cpu = cpu; + WRITE_ONCE(p->cpu, cpu); #else - task_thread_info(p)->cpu = cpu; + WRITE_ONCE(task_thread_info(p)->cpu, cpu); #endif p->wake_cpu = cpu; #endif -- 2.17.1