Received: by 2002:a05:7412:3784:b0:e2:908c:2ebd with SMTP id jk4csp1054355rdb; Sun, 1 Oct 2023 18:27:02 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEl5pFRYx2OIuI0xwK/tYc/62EJnMR9UpWZGvYjZ+4HYFi270v15LBTzqShSDTlTAWIuH14 X-Received: by 2002:a05:6a20:394e:b0:156:e1ce:d4a1 with SMTP id r14-20020a056a20394e00b00156e1ced4a1mr10668265pzg.9.1696210022122; Sun, 01 Oct 2023 18:27:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696210022; cv=none; d=google.com; s=arc-20160816; b=ryqvwHKxKVSOlZJx9muinEUir6xtpPbyBdm79nSch2tQs1nD8JgELxU5jXjmsztql3 hw2tViMfxGMXvP2r/Cw5fJrGcEcHxffBuEZ3FEOYF4aenTQp4B513IfLyCpCKm2psOSj u1ibqvlyyt1OxvGtkUA1TEf+hkrS1SM1XH5cvhGTrYHfvOxIpbNuPaHznTe0vMMPae5R QMgj1iBie3/OkONqK9b6QNUHcAtDIzykXpsEMXKYjTNphwgpTwiN5ArjRPceEayUbW90 bHWlbZ6TUUuteHHRapguvSP0ANd1/5ft1bJIzJVqQh4RQcpC5zucbus7ND13VDBiSm5e bQcw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=PjxYbmGklZty8oinrDJxmYtW0cYOAsPspyEpyWujfhs=; fh=QteByd+ihGknb5LPfDEqmcfmyroyknGG+az1Jv2i3kM=; b=QsYv0SzZa7zT9qg/MEcn5klYvgDbPa6E5pUjXGwTI2GgadIzd7h/LblCbPhSpWQ4v3 rkzOxp7hEoOS0eblUGPKWlwRuIzbVz5hoRlBMEo4OoWJK0WJBy04/Gj/TiDPzpYfN3z1 yV3J5QdP5q8fquqFKHHJPNmMvUlk++PWAMlS2AJl1Wim/OotB+OM9mpA587LpFGUcmyu nPWIFGE0W/GYDe9+EKGK3Tct1uxjYn9mh0/5LmJRkPVnrt7NZyrEST+/Ah3nmZqbCNWr /Tp7b/XqWPAvEEKAzktG8PMzbONGCZgqmsROMgV6WNPoQJRHKbwrTcJrV1yExg3FVYZc PGXg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=RtO9j2BC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id x1-20020a170902a38100b001bc162f3318si20093412pla.640.2023.10.01.18.27.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 01 Oct 2023 18:27:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=RtO9j2BC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 1134B80293CD; Sun, 1 Oct 2023 12:53:22 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235361AbjJATxV (ORCPT + 99 others); Sun, 1 Oct 2023 15:53:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49676 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235309AbjJATxV (ORCPT ); Sun, 1 Oct 2023 15:53:21 -0400 Received: from mail-ed1-x535.google.com (mail-ed1-x535.google.com [IPv6:2a00:1450:4864:20::535]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 889DAC4 for ; Sun, 1 Oct 2023 12:53:18 -0700 (PDT) Received: by mail-ed1-x535.google.com with SMTP id 4fb4d7f45d1cf-533f193fc8dso16547183a12.2 for ; Sun, 01 Oct 2023 12:53:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1696189997; x=1696794797; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=PjxYbmGklZty8oinrDJxmYtW0cYOAsPspyEpyWujfhs=; b=RtO9j2BC7bZ3xJ9LK3m0G5h3fXH83B/ES483PUgz5qmab4qP1zrDJaIMAGB8y2Uiy1 frZ3kjJ6p6/XNlwiSr5Gzav8j/jB0VsXInnPPsyXZqZJWCokn7yKMFq0ME5C54UofRnj zXq1tqmEcCAXy3q8QfJjtQGn8fTVNjpkFO2IGbFXfuBrXjasuK/fyxJJQitHq0FZFNPW 011G9WRaZaYyf1OlfacJl0T/umCvmtKePrsKWTYSapjXnCLp+tXpBFb5OowKzhvlN6zc M6nboQ6N7v/bqI2Yy5yR8DV4gx+bF9Ww3BHJmCI5cStO9SirUgJhT6ywY7YL5Hqm/ngV zGYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696189997; x=1696794797; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=PjxYbmGklZty8oinrDJxmYtW0cYOAsPspyEpyWujfhs=; b=Q/zUGbFizXhqDuxoT56mpOjeaYCg9JUWbgr5Zw74+fcb+4J67WrO+QL8IlTliG+kF0 fygGiRgJzm2UN1B9A7KbB+m5SCyG2Tgub0xFkdtyWjzgwIZBWiGlZZ9hyXzBe4O/jwx+ +0qaCs6wg5WAGH8t8GP6x1gMShx0kCaJSHatZWLXZJkbzNwOiXok9gbBli7elrxV8Sbz zvCqhG++5fFft8GUdTw9z1fE4ATaqJhnIooXvwNqQviDPKy3CcoyXSsZGXzFBhNkkYc9 0BnstIxnu3LgffMtpP6tF9RHQs9JYD15jV2ti+Ll+ATBTnwwKb4vMngQvP4DoaQRH0kD mmWg== X-Gm-Message-State: AOJu0YzdPWIbfEOyPWJKQRIhCqPrfxl92NqXt05aNZD6XxBt5llCzXpw 77+kbkiSR54KzXIracdSPiuIT96CyedpFr5vkUg= X-Received: by 2002:a05:6402:24a0:b0:538:53f9:44d1 with SMTP id q32-20020a05640224a000b0053853f944d1mr1420243eda.11.1696189996734; Sun, 01 Oct 2023 12:53:16 -0700 (PDT) MIME-Version: 1.0 References: <20231001131620.112484-1-ubizjak@gmail.com> In-Reply-To: From: Uros Bizjak Date: Sun, 1 Oct 2023 21:53:05 +0200 Message-ID: Subject: Re: [RFC PATCH 0/4] x86/percpu: Use segment qualifiers To: Linus Torvalds Cc: x86@kernel.org, linux-kernel@vger.kernel.org, Andy Lutomirski , Ingo Molnar , Nadav Amit , Brian Gerst , Denys Vlasenko , "H . Peter Anvin" , Peter Zijlstra , Thomas Gleixner , Borislav Petkov , Josh Poimboeuf Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Sun, 01 Oct 2023 12:53:22 -0700 (PDT) On Sun, Oct 1, 2023 at 7:07=E2=80=AFPM Linus Torvalds wrote: > > On Sun, 1 Oct 2023 at 06:16, Uros Bizjak wrote: > > > > This patchset resurrect the work of Richard Henderson [1] and Nadav Ami= t [2] > > to introduce named address spaces compiler extension [3,4] into the lin= ux kernel. > > So apparently the extension has been around for a while (since gcc-6), > but I don't actually find any single major _user_ of it. > > Debian code search finds exactly one case of it outside of the > compilers themselves: > > # define THREAD_SELF \ > (*(struct pthread *__seg_fs *) offsetof (struct pthread, header.self)= ) > > in glibc/sysdeps/x86_64/nptl/tls.h, and even that isn't very widely > used (it seems to be a pthread_mutex implementation helper). > > So the coverage testing of this thing seems very weak. Do we have any > other reason to believe that this is likely to actually be reliable > enough to use? The clang manual nicely summarises named address space extension with: "Note that this is a very very low-level feature that should only be used if you know what you=E2=80=99re doing (for example in an OS kernel)." But, at least in GCC, the middle-end code handles many targets, grepping for MEM_ADDR_SPACE in config directories returns avr, ft32, gcn, h8300, i386, m32c, m68k, mn10300, msp430, pru, riscv. rl78, rs6000, sh and vax target. This extension is quite popular with embedded targets. Regarding x86 target specific code, the same functionality used for explicit address space is used internally to handle __thread qualifier. The testcase: __thread int m; int foo (void) { return m; } compiles the memory read to: #(insn:TI 10 2 11 2 (set (reg/i:SI 0 ax) # (mem/c:SI (const:DI (unspec:DI [ # (symbol_ref:DI ("m") [flags 0x2a] ) # ] UNSPEC_NTPOFF)) [1 m+0 S4 A32 AS1])) "thread.c":3:28 81 {*movsi_internal} # (nil)) movl %fs:m@tpoff, %eax # 10 [c=3D5 l=3D8] *movsi_intern= al/0 where AS1 in memory flags represents address space 1 (%fs: prefix). Also, stack protector internally uses the same target specific code: #(insn:TI 6 9 10 2 (parallel [ # (set (mem/v/f/c:DI (plus:DI (reg/f:DI 7 sp) # (const_int 8 [0x8])) [4 D.2009+0 S8 A64]) # (unspec:DI [ # (mem/v/f:DI (const_int 40 [0x28]) [5 MEM[( long unsigned int *)40B]+0 S8 A64 AS1]) # ] UNSPEC_SP_SET)) # (set (reg:DI 0 ax [92]) # (const_int 0 [0])) # (clobber (reg:CC 17 flags)) # ]) "pr111023.c":12:1 1265 {stack_protect_set_1_di} # (expr_list:REG_UNUSED (reg:CC 17 flags) # (expr_list:REG_UNUSED (reg:DI 0 ax [92]) # (nil)))) movq %fs:40, %rax # 6 [c=3D0 l=3D16] stack_protect_set_1_= di Again, AS1 in memory flags defines address space 1 (%fs prefix). Compare this to the following testcase that explicitly defines __seg_gs: __seg_gs int m; int foo (void) { return m; } The testcase compiles the read from memory to: #(insn:TI 10 2 11 2 (set (reg/i:SI 0 ax) # (mem/c:SI (symbol_ref:DI ("m") [flags 0x2] ) [1 m+0 S4 A32 AS2])) "thread.c":3:28 81 {*movsi_internal} # (nil)) movl %gs:m(%rip), %eax # 10 [c=3D5 l=3D7] *movsi_intern= al/0 Please note AS2 in memory flags, this represents address space 2 (%gs: prefix). Otherwise, the memory reference is handled by the compiler as all other memory references. As demonstrated above, the compiler handles memory reference with explicit address space through the same middle-end and target-dependant code as __thread and stack protector memory references. __thread and stack protector are heavily used features of the compiler, so I'm quite confident that explicit address space should work as advertised. Even *if* there are some issues with aliasing, the kernel is immune to them due to KBUILD_CFLAGS +=3D -fno-strict-aliasing Uros.