From patchwork Mon Aug 5 18:39:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Uros Bizjak X-Patchwork-Id: 13753971 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 B57A1C52D70 for ; Mon, 5 Aug 2024 18:40:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2658C6B0098; Mon, 5 Aug 2024 14:40:43 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1F0066B0099; Mon, 5 Aug 2024 14:40:43 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E70676B009A; Mon, 5 Aug 2024 14:40:42 -0400 (EDT) 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 BE1C86B0098 for ; Mon, 5 Aug 2024 14:40:42 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 79C9D1A1BAD for ; Mon, 5 Aug 2024 18:40:42 +0000 (UTC) X-FDA: 82419057924.12.4F79AC8 Received: from mail-ej1-f46.google.com (mail-ej1-f46.google.com [209.85.218.46]) by imf09.hostedemail.com (Postfix) with ESMTP id 9425A140017 for ; Mon, 5 Aug 2024 18:40:40 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=ksLHTDw8; spf=pass (imf09.hostedemail.com: domain of ubizjak@gmail.com designates 209.85.218.46 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=1722883179; 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=zriScYxEubY60jokktbaWFHqZ5TIRBloyPdl3CM/JiM=; b=4jqwFT3BoPUojCdZSLa7CmAr1yj4LKve1OFmzg2p2LWGCh2o6XFhBPoRCpBSwT5MdJ+m56 s7FZJa1r9el/tSXXphK1CDIXP8fbsYLm5iQyi30piPPGmEKtAy0LBWAseu+MGt+AF2Qfgy d2iodSRT9oI13j4m2K53O7YdYGsiXDU= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1722883179; a=rsa-sha256; cv=none; b=hpJfL+i9VXCU5gJplnY69KHPOwslzAHZV0Y5jrRDdGFqXPga2qA1cJkjPQXUpMaX3p20zT PFqc+J1d+Duh4K0e3+c+sLyTgxFgGdv+y4ET6CJJHkW2ah0SCVxtXi7EP3wYjoNKhZu7dU XloVbltt1Ylzljmqh68TLhreUOigPLA= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=ksLHTDw8; spf=pass (imf09.hostedemail.com: domain of ubizjak@gmail.com designates 209.85.218.46 as permitted sender) smtp.mailfrom=ubizjak@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-ej1-f46.google.com with SMTP id a640c23a62f3a-a7a83a968ddso1434767166b.0 for ; Mon, 05 Aug 2024 11:40:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722883238; x=1723488038; 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=zriScYxEubY60jokktbaWFHqZ5TIRBloyPdl3CM/JiM=; b=ksLHTDw8df6ugb1wTJHNuPfSOVc7947M0C5MyE4T56tsgBlDERTIhalAqiyOJa79ha nbAbci3z7dCjIJXbd36AJPhCDiZ4u6LWp6oCpOkMsUMSUwNv+Xu2OvYJrnIxi+qcTiJi 75i4nTu2UHLB/2F+DwfzJpaBwvx8W49SQOL96OIJdUDdxwcXT5LDedzSNi6btBmh2aH5 y53XE4ps+Goyx95Ey7oP4+l5tAho+ch9i3XqC8zWMXg567ZHKNy8YzwrAJDmQBF4lHuD p8AgKBzUhKTUsEVn+FO+6q7+MvPhDictzNVFeg9gpWyykaFq5K9hu2eDznT4FHkg3C6J iivw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722883238; x=1723488038; 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=zriScYxEubY60jokktbaWFHqZ5TIRBloyPdl3CM/JiM=; b=K4JvukA/+Lt9K+t0wpsEt45v+n9EwjkOt49E18cCXxQGQxjKX/prK7qVracEGL715s rWlBcjyyHzu2/SUW33+roP9GXOrrd4bdpAMy57dPFFy3rnlzD4pH5ab8gWyLvzcApKqs NvWCghK5TPR1A/EFLeA04ZahTaJmJpdLjk7edKH0/BPsDOp3lHFt6gpJ8lDR3EoehoFn 4Dgwv15ujs2MyRdMnWF9qVn+84+eLD24BJjyUtSIxdMpJkk0xDrXSUyWL926hUug7Efn gaW7TR/GWkdwrupEl8Oc5+oVwJIYxYqSsfvJQcRy4AAYYVHewQNO93Fc7JGy5eBjW3RI B3+Q== X-Gm-Message-State: AOJu0YzBx0MR7qwl17X1u/0dlmCw5mdDjdFnaTMLaFAWNgUvTay7NOiy NNajgAnwzE7Sw9/vOAdY8v3zWx3p1dtzL/8QTSgfU9l5EvzMy2+KLJFuTK01 X-Google-Smtp-Source: AGHT+IEGo7Vm5zvJp9nEVud6phcEtTDIKhjtj5nfoLZd1H8ajHYipyEgr8snqKHgp24J3b5WtV8biQ== X-Received: by 2002:a17:907:868e:b0:a7d:a29e:5c33 with SMTP id a640c23a62f3a-a7dc4fc9544mr744489266b.28.1722883237795; Mon, 05 Aug 2024 11:40:37 -0700 (PDT) Received: from localhost.localdomain (93-103-32-68.dynamic.t-2.net. [93.103.32.68]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a7dc9c12ad3sm478517266b.88.2024.08.05.11.40.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Aug 2024 11:40:37 -0700 (PDT) From: Uros Bizjak To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Uros Bizjak , Dennis Zhou , Tejun Heo , Christoph Lameter , Andy Lutomirski , Ingo Molnar , Nadav Amit , Brian Gerst , Denys Vlasenko , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Thomas Gleixner , Borislav Petkov , Luc Van Oostenryck Subject: [RFC PATCH 3/3] percpu/x86: [RFH] Enable strict percpu checks via named AS qualifiers Date: Mon, 5 Aug 2024 20:39:01 +0200 Message-ID: <20240805184012.358023-4-ubizjak@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240805184012.358023-1-ubizjak@gmail.com> References: <20240805184012.358023-1-ubizjak@gmail.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 9425A140017 X-Stat-Signature: ky69mkiaqfmc4ei1bka91afcerk1e8b7 X-HE-Tag: 1722883240-194352 X-HE-Meta: U2FsdGVkX1/pmUFDL43jqNlKJ4OX997K24mCJxpUBgE/rgCqxSyBS+XPFnDHpyMkt6jKOALKg+QEFgDg/xqEg/AMV3K81sm6QI4QrH2YPC31ui7lE8cC3zd1Uw8P6ZhcXRFcODytyyhVXj/00mYJgPApguSdC97RhYH3tGYi0S0GZCcEuLqojdniflEY91WSwsfrmAjazmFbY/dSD3ODDm7lR18U/ic/gDQ/DKGpeBYtwUuT1tVhrGYddWPKDI6OlQQwqa1Dt5P/6nbOCxezmPURXnp5O7NZ/H5gybw9yPTYJL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M4cnMNITSn/k2+RcLiUOGCZygMsi6/YiF+gC3bUMmII2M4VmtALsI1etAf8vmQVYqCKIqPAK5exYQ9Q0Jd0HaNPSe7i65LwbxD1TV4R1awUyr99Wntx4+5sTiSPdPbNrGPTyXYkq1Eo4wa7XOL/TmVDMHrRA2PVVj7Z/Wi2tvNTsjiMmyoDsUlhSIAYPu2LbIgrziVoqn0pv080OI1tJbUzho5XGddgKwuXR88a02XZzv/wd7Se3FVv7Jzmid2HXvPyHYrstyP3zIHSLtpgNQONVeLsEikm77WlQqdLffUGS3egJCEaWhD+QrrF12ohmkMZ0Rr+/DSEjAAiDcvRPjKncsopNMbs0vktWbr7n1lTjRTEtnK1wfHtzL+d304U= 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 corss-namespace variable assignments. RFH: The patch hijacks __percpu tag and repurposes it as a named address space qualifier. While this works surprisingly well in this RFC patchset, I would really appreciate some help on how to rewrite this hack into some "production ready" code. Signed-off-by: Uros Bizjak Cc: Dennis Zhou Cc: Tejun Heo Cc: Christoph Lameter Cc: Andy Lutomirski Cc: Ingo Molnar Cc: Nadav Amit Cc: Brian Gerst Cc: Denys Vlasenko Cc: H. Peter Anvin Cc: Linus Torvalds Cc: Peter Zijlstra Cc: Thomas Gleixner Cc: Borislav Petkov Cc: Luc Van Oostenryck --- arch/x86/include/asm/percpu.h | 15 ++++++++++++--- include/linux/compiler_types.h | 2 +- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/arch/x86/include/asm/percpu.h b/arch/x86/include/asm/percpu.h index 4d31203eb0d2..40916bbd2f11 100644 --- a/arch/x86/include/asm/percpu.h +++ b/arch/x86/include/asm/percpu.h @@ -95,9 +95,18 @@ #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) +# 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))) +# define __percpu_qual +#endif + #define __percpu_arg(x) __percpu_prefix "%" #x #define __force_percpu_arg(x) __force_percpu_prefix "%" #x diff --git a/include/linux/compiler_types.h b/include/linux/compiler_types.h index f14c275950b5..47c95a06a0ec 100644 --- a/include/linux/compiler_types.h +++ b/include/linux/compiler_types.h @@ -57,7 +57,7 @@ static inline void __chk_io_ptr(const volatile void __iomem *ptr) { } # define __user BTF_TYPE_TAG(user) # endif # define __iomem -# define __percpu BTF_TYPE_TAG(percpu) +# define __percpu __percpu_qual BTF_TYPE_TAG(percpu) # define __rcu BTF_TYPE_TAG(rcu) # define __chk_user_ptr(x) (void)0