15b25b13aSMathieu Desnoyers #ifndef _UAPI_LINUX_MEMBARRIER_H 25b25b13aSMathieu Desnoyers #define _UAPI_LINUX_MEMBARRIER_H 35b25b13aSMathieu Desnoyers 45b25b13aSMathieu Desnoyers /* 55b25b13aSMathieu Desnoyers * linux/membarrier.h 65b25b13aSMathieu Desnoyers * 75b25b13aSMathieu Desnoyers * membarrier system call API 85b25b13aSMathieu Desnoyers * 95b25b13aSMathieu Desnoyers * Copyright (c) 2010, 2015 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> 105b25b13aSMathieu Desnoyers * 115b25b13aSMathieu Desnoyers * Permission is hereby granted, free of charge, to any person obtaining a copy 125b25b13aSMathieu Desnoyers * of this software and associated documentation files (the "Software"), to deal 135b25b13aSMathieu Desnoyers * in the Software without restriction, including without limitation the rights 145b25b13aSMathieu Desnoyers * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 155b25b13aSMathieu Desnoyers * copies of the Software, and to permit persons to whom the Software is 165b25b13aSMathieu Desnoyers * furnished to do so, subject to the following conditions: 175b25b13aSMathieu Desnoyers * 185b25b13aSMathieu Desnoyers * The above copyright notice and this permission notice shall be included in 195b25b13aSMathieu Desnoyers * all copies or substantial portions of the Software. 205b25b13aSMathieu Desnoyers * 215b25b13aSMathieu Desnoyers * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 225b25b13aSMathieu Desnoyers * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 235b25b13aSMathieu Desnoyers * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 245b25b13aSMathieu Desnoyers * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 255b25b13aSMathieu Desnoyers * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 265b25b13aSMathieu Desnoyers * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 275b25b13aSMathieu Desnoyers * SOFTWARE. 285b25b13aSMathieu Desnoyers */ 295b25b13aSMathieu Desnoyers 305b25b13aSMathieu Desnoyers /** 315b25b13aSMathieu Desnoyers * enum membarrier_cmd - membarrier system call command 325b25b13aSMathieu Desnoyers * @MEMBARRIER_CMD_QUERY: Query the set of supported commands. It returns 335b25b13aSMathieu Desnoyers * a bitmask of valid commands. 34c5f58bd5SMathieu Desnoyers * @MEMBARRIER_CMD_GLOBAL: Execute a memory barrier on all running threads. 355b25b13aSMathieu Desnoyers * Upon return from system call, the caller thread 365b25b13aSMathieu Desnoyers * is ensured that all running threads have passed 375b25b13aSMathieu Desnoyers * through a state where all memory accesses to 385b25b13aSMathieu Desnoyers * user-space addresses match program order between 395b25b13aSMathieu Desnoyers * entry to and return from the system call 405b25b13aSMathieu Desnoyers * (non-running threads are de facto in such a 415b25b13aSMathieu Desnoyers * state). This covers threads from all processes 425b25b13aSMathieu Desnoyers * running on the system. This command returns 0. 43c5f58bd5SMathieu Desnoyers * @MEMBARRIER_CMD_GLOBAL_EXPEDITED: 44c5f58bd5SMathieu Desnoyers * Execute a memory barrier on all running threads 45c5f58bd5SMathieu Desnoyers * of all processes which previously registered 46c5f58bd5SMathieu Desnoyers * with MEMBARRIER_CMD_REGISTER_GLOBAL_EXPEDITED. 47c5f58bd5SMathieu Desnoyers * Upon return from system call, the caller thread 48c5f58bd5SMathieu Desnoyers * is ensured that all running threads have passed 49c5f58bd5SMathieu Desnoyers * through a state where all memory accesses to 50c5f58bd5SMathieu Desnoyers * user-space addresses match program order between 51c5f58bd5SMathieu Desnoyers * entry to and return from the system call 52c5f58bd5SMathieu Desnoyers * (non-running threads are de facto in such a 53c5f58bd5SMathieu Desnoyers * state). This only covers threads from processes 54c5f58bd5SMathieu Desnoyers * which registered with 55c5f58bd5SMathieu Desnoyers * MEMBARRIER_CMD_REGISTER_GLOBAL_EXPEDITED. 56c5f58bd5SMathieu Desnoyers * This command returns 0. Given that 57c5f58bd5SMathieu Desnoyers * registration is about the intent to receive 58c5f58bd5SMathieu Desnoyers * the barriers, it is valid to invoke 59c5f58bd5SMathieu Desnoyers * MEMBARRIER_CMD_GLOBAL_EXPEDITED from a 60c5f58bd5SMathieu Desnoyers * non-registered process. 61c5f58bd5SMathieu Desnoyers * @MEMBARRIER_CMD_REGISTER_GLOBAL_EXPEDITED: 62c5f58bd5SMathieu Desnoyers * Register the process intent to receive 63c5f58bd5SMathieu Desnoyers * MEMBARRIER_CMD_GLOBAL_EXPEDITED memory 64c5f58bd5SMathieu Desnoyers * barriers. Always returns 0. 6522e4ebb9SMathieu Desnoyers * @MEMBARRIER_CMD_PRIVATE_EXPEDITED: 6622e4ebb9SMathieu Desnoyers * Execute a memory barrier on each running 6722e4ebb9SMathieu Desnoyers * thread belonging to the same process as the current 6822e4ebb9SMathieu Desnoyers * thread. Upon return from system call, the 6922e4ebb9SMathieu Desnoyers * caller thread is ensured that all its running 7022e4ebb9SMathieu Desnoyers * threads siblings have passed through a state 7122e4ebb9SMathieu Desnoyers * where all memory accesses to user-space 7222e4ebb9SMathieu Desnoyers * addresses match program order between entry 7322e4ebb9SMathieu Desnoyers * to and return from the system call 7422e4ebb9SMathieu Desnoyers * (non-running threads are de facto in such a 7522e4ebb9SMathieu Desnoyers * state). This only covers threads from the 7670216e18SMathieu Desnoyers * same process as the caller thread. This 77a961e409SMathieu Desnoyers * command returns 0 on success. The 78a961e409SMathieu Desnoyers * "expedited" commands complete faster than 79a961e409SMathieu Desnoyers * the non-expedited ones, they never block, 80a961e409SMathieu Desnoyers * but have the downside of causing extra 81a961e409SMathieu Desnoyers * overhead. A process needs to register its 82a961e409SMathieu Desnoyers * intent to use the private expedited command 83a961e409SMathieu Desnoyers * prior to using it, otherwise this command 84a961e409SMathieu Desnoyers * returns -EPERM. 85a961e409SMathieu Desnoyers * @MEMBARRIER_CMD_REGISTER_PRIVATE_EXPEDITED: 86a961e409SMathieu Desnoyers * Register the process intent to use 87a961e409SMathieu Desnoyers * MEMBARRIER_CMD_PRIVATE_EXPEDITED. Always 88a961e409SMathieu Desnoyers * returns 0. 8970216e18SMathieu Desnoyers * @MEMBARRIER_CMD_PRIVATE_EXPEDITED_SYNC_CORE: 9070216e18SMathieu Desnoyers * In addition to provide memory ordering 9170216e18SMathieu Desnoyers * guarantees described in 9270216e18SMathieu Desnoyers * MEMBARRIER_CMD_PRIVATE_EXPEDITED, ensure 9370216e18SMathieu Desnoyers * the caller thread, upon return from system 9470216e18SMathieu Desnoyers * call, that all its running threads siblings 9570216e18SMathieu Desnoyers * have executed a core serializing 9670216e18SMathieu Desnoyers * instruction. (architectures are required to 9770216e18SMathieu Desnoyers * guarantee that non-running threads issue 9870216e18SMathieu Desnoyers * core serializing instructions before they 9970216e18SMathieu Desnoyers * resume user-space execution). This only 10070216e18SMathieu Desnoyers * covers threads from the same process as the 10170216e18SMathieu Desnoyers * caller thread. This command returns 0 on 10270216e18SMathieu Desnoyers * success. The "expedited" commands complete 10370216e18SMathieu Desnoyers * faster than the non-expedited ones, they 10470216e18SMathieu Desnoyers * never block, but have the downside of 10570216e18SMathieu Desnoyers * causing extra overhead. If this command is 10670216e18SMathieu Desnoyers * not implemented by an architecture, -EINVAL 10770216e18SMathieu Desnoyers * is returned. A process needs to register its 10870216e18SMathieu Desnoyers * intent to use the private expedited sync 10970216e18SMathieu Desnoyers * core command prior to using it, otherwise 11070216e18SMathieu Desnoyers * this command returns -EPERM. 11170216e18SMathieu Desnoyers * @MEMBARRIER_CMD_REGISTER_PRIVATE_EXPEDITED_SYNC_CORE: 11270216e18SMathieu Desnoyers * Register the process intent to use 11370216e18SMathieu Desnoyers * MEMBARRIER_CMD_PRIVATE_EXPEDITED_SYNC_CORE. 11470216e18SMathieu Desnoyers * If this command is not implemented by an 11570216e18SMathieu Desnoyers * architecture, -EINVAL is returned. 11670216e18SMathieu Desnoyers * Returns 0 on success. 1172a36ab71SPeter Oskolkov * @MEMBARRIER_CMD_PRIVATE_EXPEDITED_RSEQ: 1182a36ab71SPeter Oskolkov * Ensure the caller thread, upon return from 1192a36ab71SPeter Oskolkov * system call, that all its running thread 1202a36ab71SPeter Oskolkov * siblings have any currently running rseq 1212a36ab71SPeter Oskolkov * critical sections restarted if @flags 1222a36ab71SPeter Oskolkov * parameter is 0; if @flags parameter is 1232a36ab71SPeter Oskolkov * MEMBARRIER_CMD_FLAG_CPU, 1242a36ab71SPeter Oskolkov * then this operation is performed only 1252a36ab71SPeter Oskolkov * on CPU indicated by @cpu_id. If this command is 1262a36ab71SPeter Oskolkov * not implemented by an architecture, -EINVAL 1272a36ab71SPeter Oskolkov * is returned. A process needs to register its 1282a36ab71SPeter Oskolkov * intent to use the private expedited rseq 1292a36ab71SPeter Oskolkov * command prior to using it, otherwise 1302a36ab71SPeter Oskolkov * this command returns -EPERM. 1312a36ab71SPeter Oskolkov * @MEMBARRIER_CMD_REGISTER_PRIVATE_EXPEDITED_RSEQ: 1322a36ab71SPeter Oskolkov * Register the process intent to use 1332a36ab71SPeter Oskolkov * MEMBARRIER_CMD_PRIVATE_EXPEDITED_RSEQ. 1342a36ab71SPeter Oskolkov * If this command is not implemented by an 1352a36ab71SPeter Oskolkov * architecture, -EINVAL is returned. 1362a36ab71SPeter Oskolkov * Returns 0 on success. 137c5f58bd5SMathieu Desnoyers * @MEMBARRIER_CMD_SHARED: 138c5f58bd5SMathieu Desnoyers * Alias to MEMBARRIER_CMD_GLOBAL. Provided for 139c5f58bd5SMathieu Desnoyers * header backward compatibility. 140*544a4f2eSMichal Clapinski * @MEMBARRIER_CMD_GET_REGISTRATIONS: 141*544a4f2eSMichal Clapinski * Returns a bitmask of previously issued 142*544a4f2eSMichal Clapinski * registration commands. 1435b25b13aSMathieu Desnoyers * 1445b25b13aSMathieu Desnoyers * Command to be passed to the membarrier system call. The commands need to 1455b25b13aSMathieu Desnoyers * be a single bit each, except for MEMBARRIER_CMD_QUERY which is assigned to 1465b25b13aSMathieu Desnoyers * the value 0. 1475b25b13aSMathieu Desnoyers */ 1485b25b13aSMathieu Desnoyers enum membarrier_cmd { 1495b25b13aSMathieu Desnoyers MEMBARRIER_CMD_QUERY = 0, 150c5f58bd5SMathieu Desnoyers MEMBARRIER_CMD_GLOBAL = (1 << 0), 151c5f58bd5SMathieu Desnoyers MEMBARRIER_CMD_GLOBAL_EXPEDITED = (1 << 1), 152c5f58bd5SMathieu Desnoyers MEMBARRIER_CMD_REGISTER_GLOBAL_EXPEDITED = (1 << 2), 15322e4ebb9SMathieu Desnoyers MEMBARRIER_CMD_PRIVATE_EXPEDITED = (1 << 3), 154a961e409SMathieu Desnoyers MEMBARRIER_CMD_REGISTER_PRIVATE_EXPEDITED = (1 << 4), 15570216e18SMathieu Desnoyers MEMBARRIER_CMD_PRIVATE_EXPEDITED_SYNC_CORE = (1 << 5), 15670216e18SMathieu Desnoyers MEMBARRIER_CMD_REGISTER_PRIVATE_EXPEDITED_SYNC_CORE = (1 << 6), 1572a36ab71SPeter Oskolkov MEMBARRIER_CMD_PRIVATE_EXPEDITED_RSEQ = (1 << 7), 1582a36ab71SPeter Oskolkov MEMBARRIER_CMD_REGISTER_PRIVATE_EXPEDITED_RSEQ = (1 << 8), 159*544a4f2eSMichal Clapinski MEMBARRIER_CMD_GET_REGISTRATIONS = (1 << 9), 160c5f58bd5SMathieu Desnoyers 161c5f58bd5SMathieu Desnoyers /* Alias for header backward compatibility. */ 162c5f58bd5SMathieu Desnoyers MEMBARRIER_CMD_SHARED = MEMBARRIER_CMD_GLOBAL, 1635b25b13aSMathieu Desnoyers }; 1645b25b13aSMathieu Desnoyers 1652a36ab71SPeter Oskolkov enum membarrier_cmd_flag { 1662a36ab71SPeter Oskolkov MEMBARRIER_CMD_FLAG_CPU = (1 << 0), 1672a36ab71SPeter Oskolkov }; 1682a36ab71SPeter Oskolkov 1695b25b13aSMathieu Desnoyers #endif /* _UAPI_LINUX_MEMBARRIER_H */ 170