From patchwork Tue Nov 26 17:21:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Uros Bizjak X-Patchwork-Id: 13886261 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 84830D6552F for ; Tue, 26 Nov 2024 17:24:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A9DC26B009A; Tue, 26 Nov 2024 12:24:05 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 9D6126B009B; Tue, 26 Nov 2024 12:24:05 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 833C46B009C; Tue, 26 Nov 2024 12:24:05 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 609DF6B009A for ; Tue, 26 Nov 2024 12:24:05 -0500 (EST) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 0E80881302 for ; Tue, 26 Nov 2024 17:24:05 +0000 (UTC) X-FDA: 82828918956.09.DBC4600 Received: from mail-ej1-f41.google.com (mail-ej1-f41.google.com [209.85.218.41]) by imf25.hostedemail.com (Postfix) with ESMTP id A78BEA000D for ; Tue, 26 Nov 2024 17:23:59 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=notP5Xfy; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf25.hostedemail.com: domain of ubizjak@gmail.com designates 209.85.218.41 as permitted sender) smtp.mailfrom=ubizjak@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1732641841; a=rsa-sha256; cv=none; b=HZ6AP5gKv44WuaBlwK3VoZB14pnfK9CyddSyBsv2/pvgyYoVcVIy1il0qxmbRwPAXjwTTu mkZ2sVlf19ukKB4RU69PW0nhny4l+EK6T71uFXjFY1Wjy5nS72NnyxOHOM/k1VCqIXOkXw x//3kKwI6LrHFyDTFrgBgVB+u3O0E60= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=notP5Xfy; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf25.hostedemail.com: domain of ubizjak@gmail.com designates 209.85.218.41 as permitted sender) smtp.mailfrom=ubizjak@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1732641841; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=vYQhfY8XS5QoJJ9ROocmWAxArKh2nECE5yY90QqkfaM=; b=AaBXSsXfeOD6Hip0PaFSbrFUYYAwZcgXmytSwjySyCwALndpQDeXfWGKvQuIJ4lJTas0lt zajwCbbBRIrbaL5J57Gkq+g569CjDrnCjm4KrOLVkVFLVziOkUOaGtz5j6aeTHItoIG0vZ kIkjmyhguhDezAc0efKyuccCQi1Q52Y= Received: by mail-ej1-f41.google.com with SMTP id a640c23a62f3a-aa560a65fd6so273259566b.0 for ; Tue, 26 Nov 2024 09:24:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1732641841; x=1733246641; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=vYQhfY8XS5QoJJ9ROocmWAxArKh2nECE5yY90QqkfaM=; b=notP5XfyMMztO08njxFxUOuOOUvUb7LZhUJXZYEklSS9PxDGDgLn6WdMCa6YadiOs5 wv5z8clwGYEAn77fwrSouFAjKIs578yz9psxtIQswsALE0fH3zuxTD/ixPuNhUw3Y6nh uwrmeVL2Sexy9g9lyLHns2UY5bhEZ6p/9suhztdeqoxNTmxJYmcOvzZkPme1c0uDef+z H50kGlgVcWBXFnscnX7eZOI3gHjikX8qB5wS4EHPqvD/B9spoA6QRtl+fBzbYwx9YlGv HJjowMAcIKD6K55nV8RV6tr+PrHm2SqQUCxDPfWrrbdMyUBlgv+th7WtBFeoJwnUBNJ2 xmOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732641841; x=1733246641; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=vYQhfY8XS5QoJJ9ROocmWAxArKh2nECE5yY90QqkfaM=; b=UNiDplSpPRTPsxXmrkNh2f6Bk++n4Lr/7OZyQ8hAPcnN9leR3H2h9Hunk/1PjI0hP3 lh/8w4KwAQYr3d2EHEw9WXOaNg+WQIEiT50YwNwiedVHi3XypET6wzdfTRPp1oKXGpbq IdRqiS6qfAHgNoLyfYAj467g+fE9p6AOSQmB35SH6aDIBwJJxLpApjQJs3Q7pY2PzBGq KyOClclgV4PK5ZA2s2BHDD3j9a0DGnSVZzTBvOLbc5+5jTW1ZXEcGy3RtK2LiFSgmeCY uFIaMkLtaUjpqE20crxIP26d7EA+IMV4VyrwIznICZPC1F+CdOj6xTGx7LNvgJWgjlzW KcEg== X-Forwarded-Encrypted: i=1; AJvYcCUQr+BKY0IMJ17obkZgi6/6nkaIvEN7sdn4tvcy/Ga1jbvw3h7G8ScepzxCbsuKgCt1DQN50eETzg==@kvack.org X-Gm-Message-State: AOJu0Ywj7mFshePliJ9BECE8p+a0zFDofivMvYCAsZS/hrTxmkKRkTJn ZeGfNUdhYvh6mTBHOR8YfntPwt4brvkxGyAj54CWYJqWYr6R14Hm X-Gm-Gg: ASbGnctD6NzVl9lD4gsa8m+ZJELcFgg2SKM2UDhG0KugvPEjGQpCmlJqRQanpB3iJKG ZfW1F3l8aAsaD9bqcwVPcdKNaWygcJxWdWB/egZdqNxteUYJgAceypGjSXwdqdhj1/KbOjOdnSK /xayCPKfbL5ISid5Kw6xgxqbF+tcV5JdXGwmZmyEYJTdWyxHi9nVJfZiUyYDcNjm1WZidtvbRxM abbT2HVZHM32YQDihe/qz5m3WqEzNOwiZMjjwgMKpib8k8lmBtbzlpUgLU= X-Google-Smtp-Source: AGHT+IGyDslpGnIuA7EaGQJjOGzUF02XOkLJcH+fA/4c2TgsR6qaqxDya98ILXBrNs7h8xnzOadyXQ== X-Received: by 2002:a17:906:3d22:b0:aa5:26ac:18e2 with SMTP id a640c23a62f3a-aa57fbba709mr3970966b.23.1732641841517; Tue, 26 Nov 2024 09:24:01 -0800 (PST) Received: from localhost.localdomain ([46.248.82.114]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aa534232086sm473832866b.42.2024.11.26.09.24.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Nov 2024 09:24:01 -0800 (PST) From: Uros Bizjak To: x86@kernel.org, linux-sparse@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-bcachefs@vger.kernel.org, linux-arch@vger.kernel.org, netdev@vger.kernel.org Cc: Uros Bizjak , Dennis Zhou , Tejun Heo , Christoph Lameter , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , Linus Torvalds , Andy Lutomirski , Luc Van Oostenryck , Nadav Amit , Brian Gerst , Peter Zijlstra Subject: [PATCH 6/6] percpu/x86: Enable strict percpu checks via named AS qualifiers Date: Tue, 26 Nov 2024 18:21:23 +0100 Message-ID: <20241126172332.112212-7-ubizjak@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20241126172332.112212-1-ubizjak@gmail.com> References: <20241126172332.112212-1-ubizjak@gmail.com> MIME-Version: 1.0 X-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4Zsm0C9qAt0tv5Q0rIS tN5BTgyV QOswDFaZKNU+gcnUq5IIbC2i9l75XGmvOC39dvKCDSeooEaGEx0k8CA0npT6bhzih3ZjO6imY7nuqwjLKU0i1PWnwVqOqtx5TStRKhDUvZxXIm2Gd54N3+mRduOVuQiOiM7oaCFuoHRIy87px8vdN2PXYEr7J5mikJesFyt7rhmZXzNZi7ja8zq2c+Dbu+XIulrz++2cZQyJK19oX/nQb+SMWdXE6GHlC0sD+JDMXqyiXPF2s7UrYSUh1T/6Zd87i1p7nMRtr3YR7FG3AyBDaqcRqgKuScjVEG2jFwXqSR95ntnbbxMW8TPjojRQtQzzRYUQU1Rwa6z5YW3XlVr24zgOgZtduP+vXgU2RSnveHpYYlu9LoPjlwN88KfDoUe/U29Eb2WwyoMxvoNuwYNlisfn8SosUkoRto0+pnN3+kvuuyrbYsxTabssfY7o5T3cn0eN01Qtny0NrzOMOSmFc2i2VARYp1U1ezgRLUwVZGegnYuAnnfQia1gbUg6svwIjV0gd7l3SK0jaBm9snPRryMUdYqIqr5mwfgQT6kcPX2xJIVBQmtqAIfxkD95UW6tgeoavKPLmwZAYo3SgBkTNrDOUA/I2V42lTlMFDyk0xe3DhHbe8f4ttVUA+THRXgG7jAHghj0wrewbVaAD5jLrObqML2NSC4bP3/J15mXOGn4kQ2Ui7rVFu7D780nnAP23SzxX901holGQYbkM4fQT9dc2yF/vp6wyjxpR 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: List-Subscribe: List-Unsubscribe: This patch declares percpu variables in __seg_gs/__seg_fs named AS and keeps them named AS qualified until they are dereferenced with percpu accessor. This approach enables various compiler check for cross-namespace variable assignments. Signed-off-by: Uros Bizjak Cc: Dennis Zhou Cc: Tejun Heo Cc: Christoph Lameter Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Borislav Petkov Cc: Dave Hansen Cc: "H. Peter Anvin" Cc: Linus Torvalds Cc: Andy Lutomirski Cc: Luc Van Oostenryck Cc: Nadav Amit Cc: Brian Gerst Cc: Peter Zijlstra Acked-by: Nadav Amit > --- arch/x86/include/asm/percpu.h | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/arch/x86/include/asm/percpu.h b/arch/x86/include/asm/percpu.h index 27f668660abe..61b875243ea3 100644 --- a/arch/x86/include/asm/percpu.h +++ b/arch/x86/include/asm/percpu.h @@ -95,9 +95,19 @@ #endif /* CONFIG_SMP */ -#define __my_cpu_type(var) typeof(var) __percpu_seg_override -#define __my_cpu_ptr(ptr) (__my_cpu_type(*(ptr))*)(__force uintptr_t)(ptr) -#define __my_cpu_var(var) (*__my_cpu_ptr(&(var))) +#if defined(CONFIG_USE_X86_SEG_SUPPORT) && \ + defined(CONFIG_CC_HAS_TYPEOF_UNQUAL) && !defined(__CHECKER__) +# define __my_cpu_type(var) typeof(var) +# define __my_cpu_ptr(ptr) (ptr) +# define __my_cpu_var(var) (var) + +# define __per_cpu_qual __percpu_seg_override +#else +# define __my_cpu_type(var) typeof(var) __percpu_seg_override +# define __my_cpu_ptr(ptr) (__my_cpu_type(*(ptr))*)(__force uintptr_t)(ptr) +# define __my_cpu_var(var) (*__my_cpu_ptr(&(var))) +#endif + #define __percpu_arg(x) __percpu_prefix "%" #x #define __force_percpu_arg(x) __force_percpu_prefix "%" #x