From patchwork Tue Aug 13 17:25:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Uros Bizjak X-Patchwork-Id: 13762376 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 EFB4EC52D7B for ; Tue, 13 Aug 2024 17:25:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 685F56B0089; Tue, 13 Aug 2024 13:25:56 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 60CA96B0095; Tue, 13 Aug 2024 13:25:56 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4860E6B0098; Tue, 13 Aug 2024 13:25:56 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 2455A6B0089 for ; Tue, 13 Aug 2024 13:25:56 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id C8276A0911 for ; Tue, 13 Aug 2024 17:25:55 +0000 (UTC) X-FDA: 82447899870.12.CA765AC Received: from mail-lj1-f174.google.com (mail-lj1-f174.google.com [209.85.208.174]) by imf04.hostedemail.com (Postfix) with ESMTP id E275140003 for ; Tue, 13 Aug 2024 17:25:53 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=K6d5xkJ1; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf04.hostedemail.com: domain of ubizjak@gmail.com designates 209.85.208.174 as permitted sender) smtp.mailfrom=ubizjak@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1723569896; a=rsa-sha256; cv=none; b=AUtznKmRg/TxiM2x+UOn6tf6S8PVxdpnxFvGANg2wehS1kiID7pK/agQqfw7uxGm8rPGzn dOwQCfIIwcVibPQV9YVP2Qjx56zuIfllOgyEU9ZrFwTi7h5m6XSEd077f4DPYvzC7e35iS FhFgJfLKwM4Gtcdy57Gvhd3pVgyUmu8= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=K6d5xkJ1; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf04.hostedemail.com: domain of ubizjak@gmail.com designates 209.85.208.174 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=1723569896; 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:references:dkim-signature; bh=bckSAEjpJ5PpYoR7hQwJ/XriJMBaeLy4LvLcHeVeksk=; b=rxBNUWiZmQpLJYzhYgQHEnSDfH94RTGtCySaD6eQ5Kua2/y32WaXLofak67N9ELkGtabwL VOOZ2TIePanX3NiR5PqxnvA94pCl9rrGS+tAgu497nzUqmSu0k7vdOoYpwpmkVBuOaONbn xbJtu5z9Pdy45Y3eGzbONNs/3JmdUZU= Received: by mail-lj1-f174.google.com with SMTP id 38308e7fff4ca-2f189a2a841so55561611fa.3 for ; Tue, 13 Aug 2024 10:25:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1723569952; x=1724174752; darn=kvack.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=bckSAEjpJ5PpYoR7hQwJ/XriJMBaeLy4LvLcHeVeksk=; b=K6d5xkJ1ddqqLGH+lrijLeBxICSQ61ktPjzQLw+iaj0482ovTK7DREHq+xM1s9w8jO 9NT0seOyLvPtMwS/kgTp7UqPlxerI3x3H1lSQcehkj9yBLi7BsYH9iB0WTGRbGsBgA6i WGMzzXSnTwPouDFN9dcZ79hv23n5Vd0ddNCMAObTyCOTGoVUCu72Xdpvnx6/E1eDEgiV DU1lHK5vLpzWrcCMJuQFoOc//pirkGw7LOtuUfm2p9kpNI8g38gV1V11SkM+1Qe2LrI+ zucnRoqitCnnwTt7LOWL3wc36xx/BGWdCAn8fVfxs0wZAqhZfC4VjO+Wh5TGsY81aYjD lRzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723569952; x=1724174752; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=bckSAEjpJ5PpYoR7hQwJ/XriJMBaeLy4LvLcHeVeksk=; b=kNm8mDaN6kqmOK6dteyrtuDoTlG0c+VsESCpSMd/l1qTawrCQv2erjyhWmJqR3FmvD arUxJ7AWaHFKsA+k2qpdgfJ79suXR3DR7EKhBzrAPNqewmZzjVdXY/FANhlg2F0/3RWY w9yN2Uw36rLatDn+CpS7Hqnp0xCLAIO1lE1Dii8Cyo8Cq68ruFuohyQWl1A7UJ9o05ym YBCknTN4VgfwnjL3WXHZW/99xxvhr/EyGrknFeFUh5aPW1197mZyQ94NhRLXhC1C8ooU DwdjDx/evHfKSXUGG8R9VQc0Ze9EpYR7IwJjSgdcIBR+IC2QYsegI9ahI/MK9On0t2M5 WzzQ== X-Gm-Message-State: AOJu0Yypm2jP7pAbPLARpjDAJ/H/JvDloUgULx6QQPramL1v4O9WZMCE 7F2sEruXd2p3DtfzhlQ5KnRv2Cw+xpRggf8isxL1Rcp74jcDazkO4VTKcCRY X-Google-Smtp-Source: AGHT+IEtrrEbrFUqyvWsVDYn/i0zD/QmSZriq6+kJDYHGaNkWu/OFzS6zY1GHBxy1gwb8T33T63Vgw== X-Received: by 2002:a05:651c:b10:b0:2f1:a7f8:810c with SMTP id 38308e7fff4ca-2f3aa2fcd35mr577901fa.33.1723569951313; Tue, 13 Aug 2024 10:25:51 -0700 (PDT) Received: from localhost.localdomain ([46.248.82.114]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5bd187f33cfsm3048343a12.5.2024.08.13.10.25.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Aug 2024 10:25:50 -0700 (PDT) From: Uros Bizjak To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Uros Bizjak , Catalin Marinas , Andrew Morton Subject: [PATCH 1/2] err.h: Add ERR_PTR_PCPU(), PTR_ERR_PCPU() and IS_ERR_PCPU() functions Date: Tue, 13 Aug 2024 19:25:10 +0200 Message-ID: <20240813172543.38411-1-ubizjak@gmail.com> X-Mailer: git-send-email 2.42.0 MIME-Version: 1.0 X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: E275140003 X-Stat-Signature: 6rk6xiteiwcyjtfyowhx3r8nbk3ffmtw X-Rspam-User: X-HE-Tag: 1723569953-625390 X-HE-Meta: U2FsdGVkX19LVFSsWulWGp+atOwSK0ceys+u+l6+ehJedLP0j+gKN7fRXMIk0q88zqq8xZrGXZH/Nj8SxDYponlK1WfPY3cOVryq5lwyRVLx6WzkJZl7jsSsoopRfFcNu33CsrSyazXa/cPBpemlmFKxxjPVbyPeqaAJdwQ5igLr7RiUANGyphP8N61lp5yar0lb5WADOxIWmK/75u49l4UwjUazgyKdCakq+54JLOevTlgQ/1Dxl1NVXP5Kkj6X0nosmpHNzDgZVpaLzQTM+kVu/wSm7TMfjojCnQ/5sBiXSBX69tjYFVZ+NUnMhOK71PsTJ3faHlfMuPpxNJzpdtychrnJdpvV2uz/rIoipM9ZN+QaQqzUcicQ+WpxdZUiLyd3FLiTTQB6mD2EuFMPT1hr/KliGXjvrtkeYWOgKzQmtaTO3yIsoHu15SeN0/FckJfXVOLs4B8xVIJ+uIwCjqN7pE4vPxuKKkcXkboYHVkAV4CMUfg4C30JEl0WdrXaeyKSb847E4u9fclF0AiP82sj+eaGzkv52Y2jI6J+p3VcjkYASeprWaWpx2hUHS31rgZIPSzRipBmthOwJjsxJE9PaVGEduh6gzBF6jVxyh3IMDUk4iqM70n1MaoLON0h/Lht2GbAzl1G/ULHiPLavh2/gOqOtUL6DmIFZ7x2FRHnLXW6AEZSyV5Tb4wNrER5Txr2mJArfV2CtQdwjrNqkIROrQ+Hrs/eeFf2R6MCkaPrQJtVcq2n9eI/SJZuo9BZtLF3Ty1ZD7NznlhWCK/xEzgS28ZTeDOfHBrHENJ3eVKRn6bytZWywW8U3hQqnTcdbwCsuOQYx2cn6KiqA/J6091j2l3ig5FSSYOyXbM07OEBn5YvCyhIGwYD3711JkjadAYeFiaMsxp70nt3VxnwBTgtzmtDGaqtvBpJC1T0xedHNTBW+Q248ojQkFd7cVOegTnCM55pSZpL+5CeM4C AHuB28wL EaXfA8FvzdiuiQuPC+7KIKOuRESpe8fLhT+rvMqZW1sbFz/Yj+QDf3Uy07vFhfET8TMQQxmxxkHosWS4jsne5vMJzTD5tuEnbveAH8UlMiY9okquFQuI8hzvy74XoqisZSncS8RWlVNW4KWrw7hWiBX7z+PIII1iLjfbTm55i57h8V+/nNz3fELf8KaYmiOhjf8L+0geh7u2ixR9fADI+pcaIQJ6Vp+l/fXncL+RFL0krAO4J0nnaXkhdRs/HWMPzPcjQmpqYolzoS/fegjdyPa4k0qzMJ6zgEBpHukoU03Tpodj3ybnRzhfS8ZTOUupejY7S/tMRLNMC+F31+eMgNg3vTncOG7Wk1Fwl/zCKC66hjWI0BryjEDbKALhdjNh6rpdtQZQQw42dWeP5b6uiP1vjOEqVk9ixADbEz9dqEsd6o8r5Rky8CykP87m7pnH5pXf0ry97iyxobrJfY9B46gI38/HY72O5p8DOzGJUq3LD/6tysY/nUCsOMgopi/kqtKlVX9WE/KjRnUs= 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: Add ERR_PTR_PCPU(), PTR_ERR_PCPU() and IS_ERR_PCPU() functions that operate on pointers in the percpu address space. These functions remove the need for (__force void *) function argument casts (to avoid sparse -Wcast-from-as warnings). The patch will also avoid future build errors due to pointer address space mismatch with enabled strict percpu address space checks. Signed-off-by: Uros Bizjak Cc: Catalin Marinas Cc: Andrew Morton Acked-by: Catalin Marinas --- include/linux/err.h | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/include/linux/err.h b/include/linux/err.h index b5d9bb2a2349..997fd6fe1d0c 100644 --- a/include/linux/err.h +++ b/include/linux/err.h @@ -6,6 +6,7 @@ #include #include +#include /* * Kernel pointers have redundant information, so we can use a @@ -41,6 +42,22 @@ static inline void * __must_check ERR_PTR(long error) return (void *) error; } +/** + * ERR_PTR_PCPU - Create an error pointer in the percpu address space. + * @error: A negative error code. + * + * Encodes @error into a pointer value in the percpu address space. + * Users should consider the result opaque and not assume anything + * about how the error is encoded. + * + * Return: A pointer in the percpu address space with @error encoded + * within its value. + */ +static inline void __percpu * __must_check ERR_PTR_PCPU(long error) +{ + return (void __percpu *) error; +} + /** * PTR_ERR - Extract the error code from an error pointer. * @ptr: An error pointer. @@ -51,6 +68,17 @@ static inline long __must_check PTR_ERR(__force const void *ptr) return (long) ptr; } +/** + * PTR_ERR_PCPU - Extract the error code from an error pointer in the + * percpu address space. + * @ptr: An error pointer in the percpu address space. + * Return: The error code within @ptr. + */ +static inline long __must_check PTR_ERR_PCPU(const void __percpu *ptr) +{ + return (__force long) ptr; +} + /** * IS_ERR - Detect an error pointer. * @ptr: The pointer to check. @@ -61,6 +89,16 @@ static inline bool __must_check IS_ERR(__force const void *ptr) return IS_ERR_VALUE((unsigned long)ptr); } +/** + * IS_ERR_PCPU - Detect an error pointer in the percpu address space. + * @ptr: The pointer in the percpu address space to check. + * Return: true if @ptr is an error pointer, false otherwise. + */ +static inline bool __must_check IS_ERR_PCPU(const void __percpu *ptr) +{ + return IS_ERR_VALUE((__force unsigned long)ptr); +} + /** * IS_ERR_OR_NULL - Detect an error pointer or a null pointer. * @ptr: The pointer to check.