From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5A992C2B9F4 for ; Sat, 19 Jun 2021 06:02:31 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id D4FA46113C for ; Sat, 19 Jun 2021 06:02:30 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D4FA46113C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 3A4716B006E; Sat, 19 Jun 2021 02:02:30 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 354CF6B0070; Sat, 19 Jun 2021 02:02:30 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1A7EA6B0072; Sat, 19 Jun 2021 02:02:30 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0049.hostedemail.com [216.40.44.49]) by kanga.kvack.org (Postfix) with ESMTP id D91FF6B006E for ; Sat, 19 Jun 2021 02:02:29 -0400 (EDT) Received: from smtpin23.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 5322B11207 for ; Sat, 19 Jun 2021 06:02:29 +0000 (UTC) X-FDA: 78269428818.23.9320906 Received: from mail-pj1-f48.google.com (mail-pj1-f48.google.com [209.85.216.48]) by imf10.hostedemail.com (Postfix) with ESMTP id CCF554202A2E for ; Sat, 19 Jun 2021 06:02:27 +0000 (UTC) Received: by mail-pj1-f48.google.com with SMTP id z3-20020a17090a3983b029016bc232e40bso7143092pjb.4 for ; Fri, 18 Jun 2021 23:02:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:subject:to:cc:references:in-reply-to:mime-version :message-id:content-transfer-encoding; bh=6wKXgd/ZhGiTUrwlorOP1aKdH3EvNfTZEGLOVoYRfnA=; b=HqTuCzfRgtpxdtQsv5eXBAj6MY60ow4aM/DQATcTOrV/s2Z1lom+u5+UgkGJyFUMrR sBm4Hw8mpm1b2NWuVNjV5HlFClau9nEewZt/h5Noo7Rxilij1QenUcYn5TMTv2ep4BZh dezXiQiqQdwaClkPIiahsQD+wZr7r1cZzkkO94gYiK7GiRmDf84djWdzNhK6Dgtb4qgY OFedJiTkHTSjVlGO0m4koiJ3G1Q/py26GcIKMZ7f2d4P4OipQ7ebZz3xK/obxcf2M4EW TENafsgnBHGZNkqqvs4TCdkFQy6vdlx6ZMaNPOSS9IhtgLW2s2dztU5ieTx1F7/KHX/y Gsfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:subject:to:cc:references:in-reply-to :mime-version:message-id:content-transfer-encoding; bh=6wKXgd/ZhGiTUrwlorOP1aKdH3EvNfTZEGLOVoYRfnA=; b=S6n4bgx1scCuQpJSEN6bhTCmT8HJluStyDUiSZI0+eZ8+jImh10OqQP2MF+z2OTQUP Fp8spHOUT8Ki0Fh0UPCCA236NG/zZF48Re+xISRuvo/Sbjedba4Sq4nLF6Ik59X3255z cE66ZKPNgVBDQLEzQRnMNPPjN3pGndFPXin73pwziy9qwfOMMoLpEdFaAy37MSKRKWxg +eWRgWqYiIoHussBeLHEghQuIilmbnfGs2Ldk6dPC6g6gS6s4BdkskSYDJXsbqjFMjA7 PPb9ZhbUr577Pd1/EQO35DFGzmwamTmstYq2x19VPb+0jse/tGLbWln4OmhMJw5+FZCN FPVw== X-Gm-Message-State: AOAM532jHiRZhcYawmmZoKV1+oWru2uwHVC+WQrpbTOpzIJkYyiaNMxD vmDHYzT84sMpFB9waKr9tgI= X-Google-Smtp-Source: ABdhPJyKMGe6svO1edmje4gRVg+O1L9zIRT6wzOtEKvbi1F4rLOfCjfJ9mjTw5mzRepW9QleX5pgcQ== X-Received: by 2002:a17:902:b218:b029:11a:bf7b:1a80 with SMTP id t24-20020a170902b218b029011abf7b1a80mr8106460plr.82.1624082548020; Fri, 18 Jun 2021 23:02:28 -0700 (PDT) Received: from localhost (60-242-147-73.tpgi.com.au. [60.242.147.73]) by smtp.gmail.com with ESMTPSA id s123sm9246118pfb.78.2021.06.18.23.02.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Jun 2021 23:02:27 -0700 (PDT) Date: Sat, 19 Jun 2021 16:02:21 +1000 From: Nicholas Piggin Subject: Re: [PATCH 8/8] membarrier: Rewrite sync_core_before_usermode() and improve documentation To: Andy Lutomirski , Mathieu Desnoyers Cc: Andrew Morton , Benjamin Herrenschmidt , Catalin Marinas , Dave Hansen , linux-arm-kernel , linux-kernel , linux-mm , linuxppc-dev , Michael Ellerman , Paul Mackerras , Peter Zijlstra , stable , Will Deacon , x86 References: <07a8b963002cb955b7516e61bad19514a3acaa82.1623813516.git.luto@kernel.org> <827549827.10547.1623941277868.JavaMail.zimbra@efficios.com> <26196903-4aee-33c4-bed8-8bf8c7b46793@kernel.org> <593983567.12619.1624033908849.JavaMail.zimbra@efficios.com> <1d617df2-57fa-4953-9c75-6de3909a6f14@www.fastmail.com> <639092151.13266.1624046981084.JavaMail.zimbra@efficios.com> In-Reply-To: <639092151.13266.1624046981084.JavaMail.zimbra@efficios.com> MIME-Version: 1.0 Message-Id: <1624080924.z61zvzi4cq.astroid@bobo.none> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=gmail.com header.s=20161025 header.b=HqTuCzfR; spf=pass (imf10.hostedemail.com: domain of npiggin@gmail.com designates 209.85.216.48 as permitted sender) smtp.mailfrom=npiggin@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Stat-Signature: yx9iyaifbkg7y7pht6hft8khyf5ajwnw X-Rspamd-Queue-Id: CCF554202A2E X-Rspamd-Server: rspam06 X-HE-Tag: 1624082547-585262 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Excerpts from Mathieu Desnoyers's message of June 19, 2021 6:09 am: > ----- On Jun 18, 2021, at 3:58 PM, Andy Lutomirski luto@kernel.org wrote: >=20 >> On Fri, Jun 18, 2021, at 9:31 AM, Mathieu Desnoyers wrote: >>> ----- On Jun 17, 2021, at 8:12 PM, Andy Lutomirski luto@kernel.org wrot= e: >>>=20 >>> > On 6/17/21 7:47 AM, Mathieu Desnoyers wrote: >>> >=20 >>> >> Please change back this #ifndef / #else / #endif within function for >>> >>=20 >>> >> if (!IS_ENABLED(CONFIG_ARCH_HAS_MEMBARRIER_SYNC_CORE)) { >>> >> ... >>> >> } else { >>> >> ... >>> >> } >>> >>=20 >>> >> I don't think mixing up preprocessor and code logic makes it more re= adable. >>> >=20 >>> > I agree, but I don't know how to make the result work well. >>> > membarrier_sync_core_before_usermode() isn't defined in the !IS_ENABL= ED >>> > case, so either I need to fake up a definition or use #ifdef. >>> >=20 >>> > If I faked up a definition, I would want to assert, at build time, th= at >>> > it isn't called. I don't think we can do: >>> >=20 >>> > static void membarrier_sync_core_before_usermode() >>> > { >>> > BUILD_BUG_IF_REACHABLE(); >>> > } >>>=20 >>> Let's look at the context here: >>>=20 >>> static void ipi_sync_core(void *info) >>> { >>> [....] >>> membarrier_sync_core_before_usermode() >>> } >>>=20 >>> ^ this can be within #ifdef / #endif >>>=20 >>> static int membarrier_private_expedited(int flags, int cpu_id) >>> [...] >>> if (!IS_ENABLED(CONFIG_ARCH_HAS_MEMBARRIER_SYNC_CORE)) >>> return -EINVAL; >>> if (!(atomic_read(&mm->membarrier_state) & >>> MEMBARRIER_STATE_PRIVATE_EXPEDITED_SYNC_CORE_READ= Y)) >>> return -EPERM; >>> ipi_func =3D ipi_sync_core; >>>=20 >>> All we need to make the line above work is to define an empty ipi_sync_= core >>> function in the #else case after the ipi_sync_core() function definitio= n. >>>=20 >>> Or am I missing your point ? >>=20 >> Maybe? >>=20 >> My objection is that an empty ipi_sync_core is a lie =E2=80=94 it doesn= =E2=80=99t sync the core. >> I would be fine with that if I could have the compiler statically verify= that >> it=E2=80=99s not called, but I=E2=80=99m uncomfortable having it there i= f the implementation is >> actively incorrect. >=20 > I see. Another approach would be to implement a "setter" function to popu= late > "ipi_func". That setter function would return -EINVAL in its #ifndef CONF= IG_ARCH_HAS_MEMBARRIER_SYNC_CORE > implementation. I still don't get the problem with my suggestion. Sure the=20 ipi is a "lie", but it doesn't get used. That's how a lot of ifdef folding works out. E.g., diff --git a/kernel/sched/membarrier.c b/kernel/sched/membarrier.c index b5add64d9698..54cb32d064af 100644 --- a/kernel/sched/membarrier.c +++ b/kernel/sched/membarrier.c @@ -5,6 +5,15 @@ * membarrier system call */ #include "sched.h" +#ifdef CONFIG_ARCH_HAS_MEMBARRIER_SYNC_CORE +#include +#else +static inline void membarrier_sync_core_before_usermode(void) +{ + compiletime_assert(0, "architecture does not implement membarrier_sync_co= re_before_usermode"); +} + +#endif =20 /* * For documentation purposes, here are some membarrier ordering