From patchwork Thu Dec 5 15:40:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Uros Bizjak X-Patchwork-Id: 13895611 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 4FF73E7716D for ; Thu, 5 Dec 2024 15:43:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DCC836B0182; Thu, 5 Dec 2024 10:43:09 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D55206B01AB; Thu, 5 Dec 2024 10:43:09 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B7FC96B01B1; Thu, 5 Dec 2024 10:43:09 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 9245A6B0182 for ; Thu, 5 Dec 2024 10:43:09 -0500 (EST) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 46D38C13EA for ; Thu, 5 Dec 2024 15:43:09 +0000 (UTC) X-FDA: 82861323720.15.5450A8B Received: from mail-wm1-f43.google.com (mail-wm1-f43.google.com [209.85.128.43]) by imf06.hostedemail.com (Postfix) with ESMTP id 3C88718000B for ; Thu, 5 Dec 2024 15:42:55 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=N2AJlwRu; spf=pass (imf06.hostedemail.com: domain of ubizjak@gmail.com designates 209.85.128.43 as permitted sender) smtp.mailfrom=ubizjak@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1733413371; 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=odscJvo7yyRgZdWr5SFETqd0CUulL/qOTPh5EL6fxjU=; b=W54Fk+MjahGbysMdUJhm1O+afqaJSS4Wf5doD5jYCF+DI1TfZBOrfRja8mxpaG/kMblhvY o07P5PEii3pU07bkx27L8dUIUECXY39vUNrFlLxYOnaagyBMphgk/cVz52/CphBiwDWlXl u6uGtYUbrq/INuG5o8X/x1DqzKXHs2M= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1733413371; a=rsa-sha256; cv=none; b=k2zYM90plHYDCkpKOdS6W95ICf4nETqbWB19/CLKVgZGX+dkPGRh5/jI0D894R8PGwOv7B /uCJiq/c6UaYSfj924UHcuRKRqJi8lemaUxl1C1SLvZmuL+JniSiL5HaynQjjkRRPcOXvo 2TL7f9pLKQDu+a2HGEVswjVTq3dkZKk= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=N2AJlwRu; spf=pass (imf06.hostedemail.com: domain of ubizjak@gmail.com designates 209.85.128.43 as permitted sender) smtp.mailfrom=ubizjak@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-wm1-f43.google.com with SMTP id 5b1f17b1804b1-434a099ba95so11275645e9.0 for ; Thu, 05 Dec 2024 07:43:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1733413386; x=1734018186; 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=odscJvo7yyRgZdWr5SFETqd0CUulL/qOTPh5EL6fxjU=; b=N2AJlwRuZ9CtH28BbiD3B9R7X0FjAYY5JUicsGNd8e+MRW51fXSwsnuknf9bpRUZvr jeIaY+b2UZthMBxRnk9InF4CYc8HFzHJ9o6UkBO0NTR3pH3nRA7ulzgpirRPzxKQ63FF 1sgRu3FzallCDwiRk7uBH+GCpnOxbNQdm2s0KWjK9s9+c9oIvfGCYLB0xKZRXXV+cIaA z0EkFivm99KMgxw2NiO8BUn9N0eAVN2Y/PneWhan4P9qmU/+ePPTp5U6J1hi7lWKP8Oz +xtf5HkpmV1CR5zcVeY9PJ2b/VvHYnXthijS8LnaXKFZnPYlkENMOwK1CV1ZeM30lUQW WXCA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733413386; x=1734018186; 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=odscJvo7yyRgZdWr5SFETqd0CUulL/qOTPh5EL6fxjU=; b=ZmYpjC6tQh/UaTOHhefAyWMqHCELuh5fJCGmhTghkuyTClZoT5x27Nyg5B5Uvkkptp TdMD75I8SQrZV6FZapU+Hr8RAbMGsPYCyR6aksRIoOtPWtPugM2F1hOWNh9UVRxg2opL /F0sZBPVjB6VhEWXv6YAbftpdFbB+vmQJjipMNQKvE32D7YCwh/OCsgd824U8Gd+LZR3 L7QyIrABkeqp+qZJgH1ivpfVC1xsPIkE+w4s0s80EYNj2EO5onJrvpfg0JBhPes0c32r AiHeM8SW9sT3HxQNqgLwdsW4NfG//PI5rKtKLwieFBOHrL7iRmmquWr2h7o7V/dIup14 KL0Q== X-Forwarded-Encrypted: i=1; AJvYcCX3TRukx5QVQpN81q7SXIW+vy47xUWowipxIyaASjQWaiAiPDPXcSCnDHY659khQdWkCIVJw0waxg==@kvack.org X-Gm-Message-State: AOJu0YyKq0uoAODJZMLOkYN5xuogqDOLto5nRZp7jZSSLtrqk/LLahLI Gm+xxM43PgQhkZuA8MZEbg86Nn4JjfNAIB20DFdKWP2sWTB4DWp6 X-Gm-Gg: ASbGncudJ4rWB+B1U9PlFzXv3KtDTe7Q7x6zGCLsdxR6Us7U2F5z02r+uJr9hzJwQME e/BG2Du23vkAE5wz8lvE06pfchD4ZkaBoQKy9zX4dQSeu/PHkk5U/5Y2+jTUGfG+v6KLLmOxr6O Q8Vt7rzbCKcn6aMwFId3iXeXanscgomD0lq2VHDZZF/SdZnwJ5IVQkrTlFMJGBYGQOMZ3DS49rW OfflJLFou2XoyOugZ/CmKeitQb9jfxVAB376QiffUi4QPHu8Upt9kYbCyE= X-Google-Smtp-Source: AGHT+IF5RwdGt4iaJz3BNz5kdah1/Sk6wyASmafTW1KvNAjQ+M3+nH5m+qMafwPkfEqTJkWyuAIxsw== X-Received: by 2002:a05:600c:19cc:b0:434:a90b:94fe with SMTP id 5b1f17b1804b1-434d09b4fdfmr111120535e9.10.1733413385757; Thu, 05 Dec 2024 07:43:05 -0800 (PST) Received: from localhost.localdomain ([46.248.82.114]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-434da11387dsm27020185e9.30.2024.12.05.07.43.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Dec 2024 07:43:05 -0800 (PST) From: Uros Bizjak To: x86@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 , Nadav Amit , Dennis Zhou , Tejun Heo , Christoph Lameter , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , Linus Torvalds , Andy Lutomirski , Brian Gerst , Peter Zijlstra Subject: [PATCH v2 6/6] percpu/x86: Enable strict percpu checks via named AS qualifiers Date: Thu, 5 Dec 2024 16:40:56 +0100 Message-ID: <20241205154247.43444-7-ubizjak@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20241205154247.43444-1-ubizjak@gmail.com> References: <20241205154247.43444-1-ubizjak@gmail.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 3C88718000B X-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tt JdxQh6AUHGDr1Vg5Mr77o4zqVRSzx0+RgK1AyWdIMIDhDzOnydUWrZK4fOhEohVSBy65bEgQMc1S5wHMfCsXCcyB8aLKBRhg5YgMmSDgp3d+WjMC7Kb6Hefqh+MUZJBgygTNPPKUO8zNYE/1cX/O/7EKN+rImY0uf/L6Y7uRGypuj6zrE5ohh4e1CbOXtb6wnjbnSiM3RDlvvzlzIbuaQmNhxrLukuRtkCrIuRfsnrWgPj0mVy8vCK/1WVvM+pQOJzsxkz2yi2OeNNzUG8aiJMI6qZYRvK2pQiN/kXn4SrHmw5mHunRFnVzxLws+bVBCnjSOhywgBO6jSeGpbtuGaThXRnbpHthieztM9j4uCjDoBrziUc7224brHrvik+ceJR0JqqDC0Qt87hu0avgDjuBZW+yw8uNVDyussVjjOIEa4WV/7IhysXOEWJnCtkTzzof0UW8a0iZGCfVDPqS+oFATCnY6QDhXAaShRhaj72VK4eYyDsWgAa89cApBcVkgv7n2rEmP8nvjseizVAbOfeJr/rErH3JIz4bza2Oxo1PI6Tu5v06L1GZfzkg8h6BZAhz+VblNzRTE7JDhO64C7hQx2daO3Ygn7ET3RsxYktJ7vlRmsriSq4Cpvvbwug/XcLtdSfbXFL7MKCuzIe613lnmUgVXn1ZT0oYDbCsY6Q68CERW8UG+kaEmbnQ4J56msLPZow8x+TJzcJ+4WCaA7yhvYLfalLBGuwdUK 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 Acked-by: Nadav Amit 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: Brian Gerst Cc: Peter Zijlstra --- v2: - Add comment to remove test for __CHECKER__ once sparse learns about __typeof_unqual__. --- arch/x86/include/asm/percpu.h | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/arch/x86/include/asm/percpu.h b/arch/x86/include/asm/percpu.h index 27f668660abe..6be1eafa76ec 100644 --- a/arch/x86/include/asm/percpu.h +++ b/arch/x86/include/asm/percpu.h @@ -95,9 +95,23 @@ #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))) +/* + * XXX: Remove test for __CHECKER__ once + * sparse learns about __typeof_unqual__. + */ +#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