Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp325494pxj; Wed, 16 Jun 2021 03:22:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwE7Aa/v+ncDYQXSK45SbyL3Ji2ZIZWLY4yBpzn0xub103TlG3lfFidEC6JfFjV8Y9xr7iT X-Received: by 2002:a17:906:ca17:: with SMTP id jt23mr4565178ejb.334.1623838930438; Wed, 16 Jun 2021 03:22:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623838930; cv=none; d=google.com; s=arc-20160816; b=BGrciHxTcMoctxpowNLF9kX9+vlyYvXlTeJevRcUUkQdiMhFaqWIBatCsaX3Hc0xp0 RlNEZRUtW7f1CKKkA2QH7CDBCL4+6GMODsesxRurKQI/PkJX6Fet2WyPF7FTAcT+RCda o77VFGi0sgTsBrN6FDk/LHTgThFAhD91NQqNX+JZaDyMcNLHqWkB6E1WVmvtzO7fwsA8 zs9+XMatS4JmdPk3q5MVzXsnV6WStq+Ew1o3u3UPgyYrOaHS1hAm9pch/EoJCtTP9KWL MU1MObYJrFXzf83SO4bU2E50ECTELtOwUYFVoLJ7ZguoBHyPqUYkO6QyzBd3fiy6XgY5 iWVA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=it+RVBC2T6MExrvmL/uy+MSjjsnfddFI5ThZB1C5zc0=; b=EI22cUBsAqAUyGOzxWRHURPDT51TgSjEZj8UFZsoVM+wGAyhuA9AmT0HTp6ezXnUQM Rk8bFHjDHwZRcwgEQcY5bfeGa2VI3yKe6zNLefPuG8T7gbVkqHIiTe04eKR7Kvs2S+nR v54/0q1hrH7hX86dprmkhqSlmuUa6k5uArAmwts770uLUFVAoDhdiuVqkGYuN1/vFm0q Zzn58mH/9X8EmWQXTV3SIBQ67id9B6vekfV+oQBxOPCDhFmlHEBRBaxZMB40zsBHOyRx coEOPMhowhGXs7sBkvIkVQEhBGg8gXAdBrLxx1I4A17nriqyaPFTQY5vRTjTvBlomZLn b+7Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ZjywvkZI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id jy16si608802ejc.44.2021.06.16.03.21.47; Wed, 16 Jun 2021 03:22:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ZjywvkZI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232220AbhFPKWo (ORCPT + 99 others); Wed, 16 Jun 2021 06:22:44 -0400 Received: from mail.kernel.org ([198.145.29.99]:45144 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231769AbhFPKWi (ORCPT ); Wed, 16 Jun 2021 06:22:38 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id EF0D261153; Wed, 16 Jun 2021 10:20:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1623838832; bh=Ym1vZEQrl4FAJY3nRQwAl9nRr777Xn5/+ZCgT0X7n8o=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=ZjywvkZIEHr7cruyFpHj70eyFM9ijUIhaAuvYmmopSWlueo/fLaio4NubUX6xnoJx o8ztFiM/vr9zlSHMPNnyHqtWCPfhn0EplH/dMsOk/CkDCXq7XNu4yZkca+ExvW6M/z svHRm9f0cpkHkcRVAwmM74jbiLrhjJhVazJu9F4VL3whpPGTzOHLLKq25Bvd9DEBZC XLQ32bZXu2kgxxjZ3MrcwNC6Ii7Dauc9QMdPRD2f/I9PXJHcznekU243PsMIKz5Skc 2zCtOJD456kw7DB2FcF2DTd9smFB25yvi/SNPP0yujLgqjmIYSfNEADIOjLqNxXptc FEnFGcxf5eI8w== Date: Wed, 16 Jun 2021 11:20:26 +0100 From: Will Deacon To: Andy Lutomirski Cc: x86@kernel.org, Dave Hansen , LKML , linux-mm@kvack.org, Andrew Morton , Michael Ellerman , Benjamin Herrenschmidt , Paul Mackerras , linuxppc-dev@lists.ozlabs.org, Nicholas Piggin , Catalin Marinas , linux-arm-kernel@lists.infradead.org, Mathieu Desnoyers , Peter Zijlstra , stable@vger.kernel.org Subject: Re: [PATCH 8/8] membarrier: Rewrite sync_core_before_usermode() and improve documentation Message-ID: <20210616102026.GB22350@willie-the-truck> References: <07a8b963002cb955b7516e61bad19514a3acaa82.1623813516.git.luto@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <07a8b963002cb955b7516e61bad19514a3acaa82.1623813516.git.luto@kernel.org> User-Agent: Mutt/1.10.1 (2018-07-13) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jun 15, 2021 at 08:21:13PM -0700, Andy Lutomirski wrote: > The old sync_core_before_usermode() comments suggested that a non-icache-syncing > return-to-usermode instruction is x86-specific and that all other > architectures automatically notice cross-modified code on return to > userspace. > > This is misleading. The incantation needed to modify code from one > CPU and execute it on another CPU is highly architecture dependent. > On x86, according to the SDM, one must modify the code, issue SFENCE > if the modification was WC or nontemporal, and then issue a "serializing > instruction" on the CPU that will execute the code. membarrier() can do > the latter. > > On arm64 and powerpc, one must flush the icache and then flush the pipeline > on the target CPU, although the CPU manuals don't necessarily use this > language. > > So let's drop any pretense that we can have a generic way to define or > implement membarrier's SYNC_CORE operation and instead require all > architectures to define the helper and supply their own documentation as to > how to use it. This means x86, arm64, and powerpc for now. Let's also > rename the function from sync_core_before_usermode() to > membarrier_sync_core_before_usermode() because the precise flushing details > may very well be specific to membarrier, and even the concept of > "sync_core" in the kernel is mostly an x86-ism. > > (It may well be the case that, on real x86 processors, synchronizing the > icache (which requires no action at all) and "flushing the pipeline" is > sufficient, but trying to use this language would be confusing at best. > LFENCE does something awfully like "flushing the pipeline", but the SDM > does not permit LFENCE as an alternative to a "serializing instruction" > for this purpose.) > > Cc: Michael Ellerman > Cc: Benjamin Herrenschmidt > Cc: Paul Mackerras > Cc: linuxppc-dev@lists.ozlabs.org > Cc: Nicholas Piggin > Cc: Catalin Marinas > Cc: Will Deacon > Cc: linux-arm-kernel@lists.infradead.org > Cc: Mathieu Desnoyers > Cc: Nicholas Piggin > Cc: Peter Zijlstra > Cc: x86@kernel.org > Cc: stable@vger.kernel.org > Fixes: 70216e18e519 ("membarrier: Provide core serializing command, *_SYNC_CORE") > Signed-off-by: Andy Lutomirski > --- > .../membarrier-sync-core/arch-support.txt | 68 ++++++------------- > arch/arm64/include/asm/sync_core.h | 19 ++++++ > arch/powerpc/include/asm/sync_core.h | 14 ++++ > arch/x86/Kconfig | 1 - > arch/x86/include/asm/sync_core.h | 7 +- > arch/x86/kernel/alternative.c | 2 +- > arch/x86/kernel/cpu/mce/core.c | 2 +- > arch/x86/mm/tlb.c | 3 +- > drivers/misc/sgi-gru/grufault.c | 2 +- > drivers/misc/sgi-gru/gruhandles.c | 2 +- > drivers/misc/sgi-gru/grukservices.c | 2 +- > include/linux/sched/mm.h | 1 - > include/linux/sync_core.h | 21 ------ > init/Kconfig | 3 - > kernel/sched/membarrier.c | 15 ++-- > 15 files changed, 75 insertions(+), 87 deletions(-) > create mode 100644 arch/arm64/include/asm/sync_core.h > create mode 100644 arch/powerpc/include/asm/sync_core.h > delete mode 100644 include/linux/sync_core.h For the arm64 bits (docs and asm/sync_core.h): Acked-by: Will Deacon Will