From patchwork Sun Dec 8 20:45:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Uros Bizjak X-Patchwork-Id: 13898666 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 A56B6E7717F for ; Sun, 8 Dec 2024 20:47:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5615E6B0393; Sun, 8 Dec 2024 15:47:36 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 511526B0395; Sun, 8 Dec 2024 15:47:36 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 33CE36B0396; Sun, 8 Dec 2024 15:47:36 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 11E316B0393 for ; Sun, 8 Dec 2024 15:47:36 -0500 (EST) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 88812140691 for ; Sun, 8 Dec 2024 20:47:35 +0000 (UTC) X-FDA: 82872977082.22.640D035 Received: from mail-wm1-f42.google.com (mail-wm1-f42.google.com [209.85.128.42]) by imf20.hostedemail.com (Postfix) with ESMTP id 9A2CA1C0002 for ; Sun, 8 Dec 2024 20:47:12 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=G6yqIP4J; spf=pass (imf20.hostedemail.com: domain of ubizjak@gmail.com designates 209.85.128.42 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=1733690840; 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=6KOZI0Av9UpRI0wc6f07qNDNYBakRBN27GYpajM6B9g=; b=8bXXy1n/y5yAzbhnKOxswTQahrgV5HPECspxkPVO7MtLkFcPiWy04rrfaP89DSibwgLZvQ W5Yqg4K/R+VYqgVzm/Z19QKxkSxPObUbNmIbvF34jp9BxTPKlbGaV+aXypIbMaWY6VHYDQ ByUT97kB0rFIJ1nn88Q2lmD72CPQSrE= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=G6yqIP4J; spf=pass (imf20.hostedemail.com: domain of ubizjak@gmail.com designates 209.85.128.42 as permitted sender) smtp.mailfrom=ubizjak@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1733690840; a=rsa-sha256; cv=none; b=IBQSaBYpNsKkhQiljiBDJWaEPbYcrcwUv9xfbXzuhRs5l0lq8VR6KxoOyw0qWFjRRpbTDe DPavZQJfrHj4bKLF7LvBzzVP9yT4ysiCZ4wy/MFaDsYKPAEihhgAFetFa8Rxu0vgkOpCwR dYQa0vsztCUVqcvvVyP4TQcKyQOdVOM= Received: by mail-wm1-f42.google.com with SMTP id 5b1f17b1804b1-434ab938e37so23915135e9.0 for ; Sun, 08 Dec 2024 12:47:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1733690852; x=1734295652; 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=6KOZI0Av9UpRI0wc6f07qNDNYBakRBN27GYpajM6B9g=; b=G6yqIP4JWR8M9CQR5aoNOnj331Ct1dT9AWvPFdcwtm4VgmoRciKTsoVgo3r7mc9dK5 Gt7UkMi84ZuviC9/r17tfA+TKCKLqUQ9ctYih1H9uDotYY/SPjMgu9kVvuTJ6iLiNOw+ PpJGdBguyta0FvdjeCwabIv/xgdP2z84JqWDt8oeOJX2d8ZwW/fTZmeWyxWXH1WRWUVj sRBlU48344bOjQ5y6r0HIFVQmPjwScqvIFzSiCrNb/EqmFV/lHoQ8loAqf983odub9oG LgXkjk5HAtrzdMh+ppY6MBackGfPBFqQ0laBYXvV0NdeZm5ZWZC7wRroqLZJnunEY8Pa VZmg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733690852; x=1734295652; 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=6KOZI0Av9UpRI0wc6f07qNDNYBakRBN27GYpajM6B9g=; b=NyRqMI7RRdXqfPHampJO/zdU2eGYNtnk7hrEe33e7c3kKaZ+gG9Uu5GFtdWQxcKqDu /nCapNt/Z6DAEcLjizsqbUGCoVPRBpUW+ViBn2iPfXYYwhPgStzOCRSeZtLIAJOtBEDn Kj36726obEt+CzIpi946fPVe5mANuKFeAQSIJx6/EzZOS/0tK8hBr2BXxgzZ6Lz9H39i cD3VaPFyKhPhDol/DZ2j5+63P14QtwEP3xxTY9emkPBL9MaR8Qcbp7I9or98CkRXItss Hi54BXVcxZgHsb56PqUs5q1HkPi+1mK2UJTQgOIrStnQVv71X5kDZUWa3GWAOTY0LKvS o1XA== X-Forwarded-Encrypted: i=1; AJvYcCUybXXnQ4WVa8h13yYUflob7pKjPeEkmLo+qO9UeIREMvU9om6SOoxm+JTouLLRp2q1Ejz1zHtRGw==@kvack.org X-Gm-Message-State: AOJu0YwMRBgV9kAHdqf6SAxBUSBBXmjj/UoXVtMgniEVhr7IRH9Rbau2 zrP4KezExWN8g/ARKk+q9n1yQ3vWknVBsao8LzkK8qpYNao/8OhS X-Gm-Gg: ASbGnctRvgzGlEL4U+uu483POgNjbtGSPTWGM9+ItbgVhFxfRqsXYO+GmrjyvNqLy6J yw8JVhmmsnqK+WK+8hK+3I4PnAb5aTG4AubL5RZ5FjK2o+kR90o8HL6fq8VtmFEjA7SSIpaA4Pu k3+9P+Vmu2EdiU9mnYS5UOS3pmm59FzhhHQEET9pp4ffp8XYWbGBkVcFOdREbeeYV6MWaUp2MoU 8KWEEP7MltNyFzQ0d8BJTBaLRkpjYKDKm3WySV4I0H3FuR5zp79qyv9SHk= X-Google-Smtp-Source: AGHT+IFoKEXuuJkWVyc6E+OV4Yi3aleXB7y+UqdQJgSPCnb15ZOKQ6PeUxcw/WuP8movSkRgO7EseQ== X-Received: by 2002:a5d:64ab:0:b0:385:f271:a22c with SMTP id ffacd0b85a97d-3862b3f289emr7788206f8f.59.1733690852077; Sun, 08 Dec 2024 12:47:32 -0800 (PST) Received: from localhost.localdomain ([46.248.82.114]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3861f59cc6fsm10874975f8f.34.2024.12.08.12.47.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 Dec 2024 12:47:31 -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 v3 6/6] percpu/x86: Enable strict percpu checks via named AS qualifiers Date: Sun, 8 Dec 2024 21:45:21 +0100 Message-ID: <20241208204708.3742696-7-ubizjak@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20241208204708.3742696-1-ubizjak@gmail.com> References: <20241208204708.3742696-1-ubizjak@gmail.com> MIME-Version: 1.0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IHm4JMZVJikactW5qpcOFRTsGw 6xfn/ju9 HcPUGlm2B73nInEc401P5uI6I2nFlq57/DlkgHWRrMUmQhc98UNyB+k+eMMwZzX9eQ8pcH6ZrdJjHMGzGupf6Mpps9UGvRmcoj/kXRBoFQVZWPaTbSu8ORRXPTJg1pKjlU19PRPCcV9pV84AvvNvMBheXuYeVV1q2J72iwS9NK6/PVIu7YDv6Ja0B7caIQZ/reXwV43M7QHrw8WL+AWYERT8qwmluZtQ69WRQQjEV11rBItmIbRo6sYOPcTEuSqRGQExsYeFhCu0N+ATp8GGSnl8k5OcRjmPJ79Ejo+Chsa5dXBl3HRUZ0xhCw8aU+q0H5yLX4yD4lFuWdkNVrqhAxdsiW+HC5GECdm+vE60m43A2u4Fi9eQ6LkVQmmQgywQksvo8odvcZBXCc94MNtSV6WykI34eNW8yQEM5OIk+Omhx2jQpYCF5kIK2exDbjELyXnVO+qAZr6Z6fyPS5xqdcWV3HgMZvuJReY3hlCDUG9Rbi0Hsnto+0b5cgBjp4TnOG9uJc+xuY+fy4lEndeYCClyfJbhhRlwrI24aCf5g0Z+hlm5wLEIA0tmCERc7JkgEwJPtbQAzJCMwFmXOKvgbdcoLk1psB3gXZ6rgnph4ooFFpRKfg4pdP2ajvZKtosd9CmcLMb553LUsqEnUUEQxLO3nsmP6saYeK0Mwv1jwktHsL4sSpNzz2vdJZKv4LzWWtEwUZfbq61pYRm05Lzvz6SowQHZgVU0APglV 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..1ef08289e667 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 __percpu_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