Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp954688imm; Fri, 15 Jun 2018 08:50:57 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIpViLUFpbzcw/6+OU8ACgLK5OP6vMA0BE909bmn9NGnmkbfpZMDQe7CRTVmatzOiumNwHq X-Received: by 2002:a62:6f86:: with SMTP id k128-v6mr2574738pfc.150.1529077857805; Fri, 15 Jun 2018 08:50:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529077857; cv=none; d=google.com; s=arc-20160816; b=utkiYgOnpSD8DqhQYOEB9C34dab1dUP0fdkkFrW5t0Om807fP92b3yTlvVIU+6P6Z/ Xj71L8QYxd0bRlmlRI7The1n0htftj2o3CuvHJXvVPfJozxNUhbFOaRvZ8IrRhp76SrX dncrN0BjxsODTCwK3AtBVz3BFhCpwtWxcuChB1y3Be4702SwzcZK6lAYhAIX0rJS0fSt POodirRLHBFaarYIWhmX6TqmITGxYP0lTRSDpfZt5d8vD9xEf60/Pg4lzlEDryCqM+LO oiH/1C45e3FuL96xC4tArE4nVNBePDQAkQBEIiEqe3+UkUmB//AqXCKe6HXf92cFgssC oegQ== 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 :arc-authentication-results; bh=6cFFKlE04ID2lj9t+ZUbM5wCX8u/8rACXpQmk77cVlk=; b=osImjhMZiyo0lmzLJiPCvBazkuj2uHjz8b/T0tSFTam19hn9yfdYX6NjRqunDFOqzK 6qUQwl22hENC/Jb6nxm5TCwHveILLAeOJWMTFPOBu5taOtZqTFZvGkNRO1h8f6gAjUbj WHpQadeJYtzkrJPrLoKl9rn9HC14q4jaCG2V8lRtwsYoJir0hR8AgvMGblWfUmXz0Lnm 3h1d3bke3iot8qatQXutkeE1SiHq1T58TQO9hMZO4jQ/h++XkQQ9NSzgtFREWLMN8KJN VtFQDIXbC8QJAGksE84PR4vywFrooV4LzU2liGZaN+CwT5uKxLV9u+sMI3qXR3F+77Ab t0dQ== ARC-Authentication-Results: i=1; mx.google.com; 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 w10-v6si8436094pfk.14.2018.06.15.08.50.41; Fri, 15 Jun 2018 08:50:57 -0700 (PDT) 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; 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 S965930AbeFOPuQ (ORCPT + 99 others); Fri, 15 Jun 2018 11:50:16 -0400 Received: from mail.bootlin.com ([62.4.15.54]:51712 "EHLO mail.bootlin.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S964778AbeFOPuP (ORCPT ); Fri, 15 Jun 2018 11:50:15 -0400 Received: by mail.bootlin.com (Postfix, from userid 110) id 59EFF20728; Fri, 15 Jun 2018 17:50:14 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on mail.bootlin.com X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,SHORTCIRCUIT, URIBL_BLOCKED shortcircuit=ham autolearn=disabled version=3.4.0 Received: from localhost (AAubervilliers-681-1-37-30.w90-88.abo.wanadoo.fr [90.88.156.30]) by mail.bootlin.com (Postfix) with ESMTPSA id 3287C207A5; Fri, 15 Jun 2018 17:50:14 +0200 (CEST) From: Thomas Petazzoni To: Yoshinori Sato , Rich Felker , linux-sh@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Thomas Petazzoni Subject: [PATCH] arch/sh: fix SH4 flush_dcache_all() for SMP Date: Fri, 15 Jun 2018 17:50:10 +0200 Message-Id: <20180615155010.8019-1-thomas.petazzoni@bootlin.com> X-Mailer: git-send-email 2.14.4 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The SH4 flush_dcache_all() function uses current_cpu_data, which internally uses smp_processor_id(). However, it is incorrect to use smp_processor_id() in a context where migration is enabled, because the processor on which the code is running can change at any point in time. To avoid this, we enclose the code flushing the dcache in a get_cpu() / put_cpu() section so that migration is disabled. Signed-off-by: Thomas Petazzoni --- Note: I am not sure at all this is the best fix. Careful review and suggestions are welcome. arch/sh/mm/cache-sh4.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/arch/sh/mm/cache-sh4.c b/arch/sh/mm/cache-sh4.c index eee911422cf9..cde8d7f8acbb 100644 --- a/arch/sh/mm/cache-sh4.c +++ b/arch/sh/mm/cache-sh4.c @@ -149,13 +149,17 @@ static void flush_icache_all(void) static void flush_dcache_all(void) { unsigned long addr, end_addr, entry_offset; + struct sh_cpuinfo *cpud; + int cpu; + + cpu = get_cpu(); + cpud = &cpu_data[cpu]; end_addr = CACHE_OC_ADDRESS_ARRAY + - (current_cpu_data.dcache.sets << - current_cpu_data.dcache.entry_shift) * - current_cpu_data.dcache.ways; + (cpud->dcache.sets << cpud->dcache.entry_shift) * + cpud->dcache.ways; - entry_offset = 1 << current_cpu_data.dcache.entry_shift; + entry_offset = 1 << cpud->dcache.entry_shift; for (addr = CACHE_OC_ADDRESS_ARRAY; addr < end_addr; ) { __raw_writel(0, addr); addr += entry_offset; @@ -167,6 +171,8 @@ static void flush_dcache_all(void) __raw_writel(0, addr); addr += entry_offset; __raw_writel(0, addr); addr += entry_offset; } + + put_cpu(); } static void sh4_flush_cache_all(void *unused) -- 2.14.4