Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp8627598pxu; Sun, 27 Dec 2020 13:37:56 -0800 (PST) X-Google-Smtp-Source: ABdhPJw1NeG+svWiM6VbW84PGQGu6ZAI4H25+xZ7hxAsd7hTxaDf+bFXMApzFuWvBHxgLHtgqqE9 X-Received: by 2002:a05:6402:1714:: with SMTP id y20mr39406934edu.2.1609105076379; Sun, 27 Dec 2020 13:37:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609105076; cv=none; d=google.com; s=arc-20160816; b=mltOO/VzcoXEr/jeuYyQxAOQR4N/2P8ZFuIrA6VkmfSDgLxOXFgayT3CZIll0ivcLw cZut1Azmo3S1jbO+XvEKtNBta+Arc1WkWHr9GiAbxnoqfJo5PCK4/xTNA3ilkIeeKG3q GDaBxQB/bFBNsqBgYB+8NCxzNFyM7eV3TMGAFepbDTeJMYJUIa5HAM1GDINtTp7RnNNI h6FO1O5t9hinnJLIwp61T/9EfVX5nYSlBni3GMI2NhgME7qvjmsqp6qq+rdhBY88et5F pjBWRw6E1qgad8s0l6K/KKLSfIwihgqekBaUvOitgZfiy+c2+s4PvrvqAXUg5bDL1eON wklA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=nYIkWAhdFmhChlvqWrzb74Hlux06n6OHRLBlpZHJe6U=; b=EaYHrbbwNhgKGqlfa6whsMrGcEO0vICC9dvQDMZ7AH67VIMWa0aqjCamX+mudzj8pY DStJzecsMQcmS7TjcYNtmY9G6A2GIfLfGXXd0tmaaedm8apEbTenB2zJTmVgRe2rGeto LgKIMaCsRkny3vqoTjc6XQ6xROARfHRyeb6Xu25b71y7xPk3OyXg9WkFc9j55Cyfi/hh eknHx2hKrunD3JEDzXXlm1AVk0iVFeDOlHPbHxxy+EkIy8X5RIprMy4I7iPzOG+2bIcL J663EPefHy7s/NvV4qHOza8BuGPTQC22d1pIYVBY2iY3VQJjGZmn3l2ebiAdhBft71zL H5wQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=AqlCdXKH; 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 k10si19636265eds.206.2020.12.27.13.37.34; Sun, 27 Dec 2020 13:37:56 -0800 (PST) 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=AqlCdXKH; 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 S1726354AbgL0VhI (ORCPT + 99 others); Sun, 27 Dec 2020 16:37:08 -0500 Received: from mail.kernel.org ([198.145.29.99]:38922 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726260AbgL0VhI (ORCPT ); Sun, 27 Dec 2020 16:37:08 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 27CC0229F0 for ; Sun, 27 Dec 2020 21:36:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1609104987; bh=xf1xhuCSbIvU6yFstK8GVJEOxP3WIu96vlXc4UxPWjg=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=AqlCdXKHE+ITIKKRlqblXCSPB1fZi8/UDAb1RDKCM1LvBmfFUzWwvmRaxDmO2t3hX Nk6pMZGldD5DaO605Rtt8TjjpOD/gSk58ws/PQ9FMfNSuHWbyzwf58epdI6g3zk8xZ Igbu0xStOGQWdGd9Kogu2VJnNRAWN3zsxS3vBuHZhFn096dU225m4SpqgJdSX6aMov EBd0pc/BjZrshn7beSWmBBUXcEIKmk+336nrsvKpQCdQceJupZ7MtSF8mohlT+MVwl hKrhBGpC7tm8GB4+e/xrihyvUg8Ly26YAqTnggMTfP4n7AumuBvcriGH+eaPw+YB2h jGdZuFrFFMGPQ== Received: by mail-wr1-f44.google.com with SMTP id a12so8945668wrv.8 for ; Sun, 27 Dec 2020 13:36:27 -0800 (PST) X-Gm-Message-State: AOAM532S44puFBjJsT5CiDxGSXybxTuus3QTzlYFZo5sz84sg1EyILzo 9T70TECrfZNDU6onDXIm0X+aL2iNz3aUyrdd4O0o5A== X-Received: by 2002:a5d:4905:: with SMTP id x5mr47749724wrq.75.1609104985693; Sun, 27 Dec 2020 13:36:25 -0800 (PST) MIME-Version: 1.0 References: <1836294649.3345.1609100294833.JavaMail.zimbra@efficios.com> In-Reply-To: <1836294649.3345.1609100294833.JavaMail.zimbra@efficios.com> From: Andy Lutomirski Date: Sun, 27 Dec 2020 13:36:13 -0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [RFC please help] membarrier: Rewrite sync_core_before_usermode() To: Mathieu Desnoyers , Russell King Cc: Andy Lutomirski , x86 , linux-kernel , Nicholas Piggin , Arnd Bergmann , Michael Ellerman , Benjamin Herrenschmidt , Paul Mackerras , linuxppc-dev , Catalin Marinas , Will Deacon , linux-arm-kernel , stable Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Dec 27, 2020 at 12:18 PM Mathieu Desnoyers wrote: > > ----- On Dec 27, 2020, at 1:28 PM, Andy Lutomirski luto@kernel.org wrote: > > > > > I admit that I'm rather surprised that the code worked at all on arm64, > > and I'm suspicious that it has never been very well tested. My apologies > > for not reviewing this more carefully in the first place. > > Please refer to Documentation/features/sched/membarrier-sync-core/arch-support.txt > > It clearly states that only arm, arm64, powerpc and x86 support the membarrier > sync core feature as of now: Sigh, I missed arm (32). Russell or ARM folks, what's the right incantation to make the CPU notice instruction changes initiated by other cores on 32-bit ARM? > > > # Architecture requirements > # > # * arm/arm64/powerpc > # > # Rely on implicit context synchronization as a result of exception return > # when returning from IPI handler, and when returning to user-space. > # > # * x86 > # > # x86-32 uses IRET as return from interrupt, which takes care of the IPI. > # However, it uses both IRET and SYSEXIT to go back to user-space. The IRET > # instruction is core serializing, but not SYSEXIT. > # > # x86-64 uses IRET as return from interrupt, which takes care of the IPI. > # However, it can return to user-space through either SYSRETL (compat code), > # SYSRETQ, or IRET. > # > # Given that neither SYSRET{L,Q}, nor SYSEXIT, are core serializing, we rely > # instead on write_cr3() performed by switch_mm() to provide core serialization > # after changing the current mm, and deal with the special case of kthread -> > # uthread (temporarily keeping current mm into active_mm) by issuing a > # sync_core_before_usermode() in that specific case. > I need to update that document as part of my series. > This is based on direct feedback from the architecture maintainers. > > You seem to have noticed odd cases on arm64 where this guarantee does not > match reality. Where exactly can we find this in the code, and which part > of the architecture manual can you point us to which supports your concern ? > > Based on the notes I have, use of `eret` on aarch64 guarantees a context synchronizing > instruction when returning to user-space. Based on my reading of the manual, ERET on ARM doesn't synchronize anything at all. I can't find any evidence that it synchronizes data or instructions, and I've seen reports that the CPU will happily speculate right past it. --Andy