From patchwork Thu Aug 29 15:29:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Uros Bizjak X-Patchwork-Id: 13783382 Received: from mail-lf1-f44.google.com (mail-lf1-f44.google.com [209.85.167.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A68181922E6; Thu, 29 Aug 2024 15:48:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724946483; cv=none; b=ItZyQx5onZi5gC5La8gEk3sEJM4xh7AFJyWeGRReEaVPLME8RrpbbIWeg2QWxhOXQhwAKg3y/+1ivWVoXY7JshF9EyuRLtMFd2xtAD3jnhv8iTG+gBUdYxuO0m2DhIJV7ykwMVLhXZiO2Bp/vPcCuSqstkV/e/SkGe3zFKc8Ck0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724946483; c=relaxed/simple; bh=nzRGf/HrfmWsavqKa7l/dTAqrBmmjpFAp0Jlj+w/RBw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=niZbRRamUmwmjIpAp8mVBe2OsfMyHy6emrx34WZnIwTAHqu8QzZMX5F4V0FT0MhBzl65pTmgaN8QzMqBB4m7Lw13Lm2V1T2xOMXP3ZFZ1xSlKMhkb+bNMnz0o/x1RI4pXbzDgLyUGjVxz25yLeZIO+KYCtDr/9LrxCK/qvEBbnk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=DlYanXxg; arc=none smtp.client-ip=209.85.167.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="DlYanXxg" Received: by mail-lf1-f44.google.com with SMTP id 2adb3069b0e04-53345dcd377so1038298e87.2; Thu, 29 Aug 2024 08:48:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724946479; x=1725551279; darn=vger.kernel.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=ILHxn7lRblRkiK0Gc7r8TIv6Xv3i9rztGnbYfkb6Dug=; b=DlYanXxgR7Sm02146l9KbyR5K8SiJSOFoMO1j6RNilEs7QsUykgRtx/nEHDz1FmWD0 1KIdcbX/t5Rw/pSRE41lrBYUQskv9UdH1tj9thsE0HHIW0cGgcE073gTaUhSQOG98fqy xteoa61lwZL/5ipgx0g7Ns5xsXRgF5LoThqyKlC7/4RyXv4xyeW/+50vs08XcWpCb6l9 7u7hDnykjb9gf/H0iHm8tePnHAO15QOEbwIobWRqQm4NefkZhPUfZRMiguK448g0xMb/ 7sZrUIm85nUIxaF/hdKwZ4PTfF/Zb/bzRKI4QpdjajTQew3qocCY72ZPOvMXkNjYjvpA onCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724946479; x=1725551279; 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=ILHxn7lRblRkiK0Gc7r8TIv6Xv3i9rztGnbYfkb6Dug=; b=ME28Hg0WgYd0FlnaT+iDFgCjZ8kDQ9v8sA5RFADQ5trG79wGFUdaHNcdkeg/hJkaDA xwDJvie/Lgi0sTZIEFjBeAtEvOx7oU5sHGBACM+LwRR1Eqh3N4EloWUhchk9VzxhHUGc MOR9+SN/iKDcPrqu5j1BdwXNACSfku80sxD6YtcPAt6bDpDcdUT+Bak5PHwrtKPBvef1 2ChWit/FQjL6Uub3E+1A6Nj6r1bJ3DpbbxIwk399PwUINngemHGdZ5yQAdtC3lFif5J7 RkAsTtPWt3pj35OnjCqMVNdI+C7P5sgCzSzJyeqotdcQ+RoaI2/NLBon5RZOeH1B+xQ4 X9Ug== X-Forwarded-Encrypted: i=1; AJvYcCWv+RMTdX+5Yeo8TWuasvBalJ+a811Rhe8z3e7QQ0Jfjy3X0mjTnGeF7HFOLmYoehvh/zglecWh1tKMJNk=@vger.kernel.org, AJvYcCXWrxq73omEhjaNEJ3i4OjBLZEhwTWL0wfziu8AmrPVeZftGwd5YtpDdzM/MixFKyzCjcI3dJA2@vger.kernel.org X-Gm-Message-State: AOJu0YyaPXrE8eR1zFby1c5QL/cyDW0RUq2pLbduWcTdugfZJh6xn3Fl Ukxkohu8Lcxe9puJI9Oc4V9Yf//1xOx6BrsLWksy8YtQSCsnZlHoNRlj7g== X-Google-Smtp-Source: AGHT+IGqi3tSnb4woeE4WPzxGfww2qKwIoAtHvtcT5uNNapseAZNZ4VcqKsxu3Rdp46UFcHwraNPfQ== X-Received: by 2002:a05:6512:2807:b0:52e:be84:225c with SMTP id 2adb3069b0e04-5353e5758a9mr2127153e87.33.1724946478517; Thu, 29 Aug 2024 08:47:58 -0700 (PDT) Received: from localhost.localdomain ([46.248.82.114]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a898900f29csm93489466b.64.2024.08.29.08.47.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Aug 2024 08:47:58 -0700 (PDT) From: Uros Bizjak To: netfilter-devel@vger.kernel.org, coreteam@netfilter.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Uros Bizjak Subject: [PATCH v2 1/2] err.h: Add ERR_PTR_PCPU(), PTR_ERR_PCPU() and IS_ERR_PCPU() macros Date: Thu, 29 Aug 2024 17:29:31 +0200 Message-ID: <20240829154739.16691-2-ubizjak@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240829154739.16691-1-ubizjak@gmail.com> References: <20240829154739.16691-1-ubizjak@gmail.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add ERR_PTR_PCPU(), PTR_ERR_PCPU() and IS_ERR_PCPU() macros that operate on pointers in the percpu address space. These macros 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 --- include/linux/err.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/include/linux/err.h b/include/linux/err.h index b5d9bb2a2349..a4dacd745fcf 100644 --- a/include/linux/err.h +++ b/include/linux/err.h @@ -41,6 +41,9 @@ static inline void * __must_check ERR_PTR(long error) return (void *) error; } +/* Return the pointer in the percpu address space. */ +#define ERR_PTR_PCPU(error) ((void __percpu *)(unsigned long)ERR_PTR(error)) + /** * PTR_ERR - Extract the error code from an error pointer. * @ptr: An error pointer. @@ -51,6 +54,9 @@ static inline long __must_check PTR_ERR(__force const void *ptr) return (long) ptr; } +/* Read an error pointer from the percpu address space. */ +#define PTR_ERR_PCPU(ptr) (PTR_ERR((const void *)(__force const unsigned long)(ptr))) + /** * IS_ERR - Detect an error pointer. * @ptr: The pointer to check. @@ -61,6 +67,9 @@ static inline bool __must_check IS_ERR(__force const void *ptr) return IS_ERR_VALUE((unsigned long)ptr); } +/* Read an error pointer from the percpu address space. */ +#define IS_ERR_PCPU(ptr) (IS_ERR((const void *)(__force const unsigned long)(ptr))) + /** * IS_ERR_OR_NULL - Detect an error pointer or a null pointer. * @ptr: The pointer to check. From patchwork Thu Aug 29 15:29:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Uros Bizjak X-Patchwork-Id: 13783383 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-ej1-f44.google.com (mail-ej1-f44.google.com [209.85.218.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8F9B91B3F0D; Thu, 29 Aug 2024 15:48:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724946485; cv=none; b=J6Z+CiXvdUYCChjdl1N9hv7yxMYDgz2JK+SEhAdbIfLcKXjyDbWv/XzvfFNtY/7GHiQ0asBbzYk06aorDz25isywBbtq7llRd6jGgiwxMuc4XcYvLdX8YZhf1Fu9WpDK2J+EBq0BJ7/Qfj9vouiQXmrC5B8buW3bKIRJEH1QDWQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724946485; c=relaxed/simple; bh=ZdTFyHhOH/KgvRxfGlDREL10X0eEz/rPixae8p3OoBc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FAiKYng4+ma00FZzJfTE9ROwQjVkGdrep3EG72CAeHNQT4QAQVUTw1NcHWazk9aMe7GZXLANffxEimj+I/dNO8u8Hv7TF6JsukTh4qQVnwDWy/5sdzFiYAFNn9KG9lc7YXP9PWC6+vNUhj4exk8bmxC3Gz7j5vnlVwn0XEAoSDI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=AlzwR1JW; arc=none smtp.client-ip=209.85.218.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="AlzwR1JW" Received: by mail-ej1-f44.google.com with SMTP id a640c23a62f3a-a868b8bb0feso106930366b.0; Thu, 29 Aug 2024 08:48:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724946480; x=1725551280; darn=vger.kernel.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=xAx32F/TqiCZPJe3l7MuMeLUWvJtELLjmkRTSYa1sjc=; b=AlzwR1JWibigyRPKOtdjCJUXP+k6jFBQgV58myOV85l3oaB3DtWglK20tVmHvK2Aqh LBfs59yq04A51yekHnljzNA8p53CicqgxRS8avkfaM3nbwBOxZAqxCtEwNyUL38jtxJr uC8hgVWujPtqZXw6OAudd0im5K2Ar842qnifTwtxKgTVBhVz06Zl895xoV4g9Svix6H+ uz2Pr3jsBKltoojYVAMf/ZscULuYUsPcYQ+9UrNaeOuxActidiUiVx/fc+FII1aSV7vp i38LeF2ESLxIXrC+HmTPPXbtXms5SyI4Y74dnvVKMYxzH2n+Mq+PY75XZs7i0HN9CV2K ni8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724946480; x=1725551280; 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=xAx32F/TqiCZPJe3l7MuMeLUWvJtELLjmkRTSYa1sjc=; b=bTDJ7X5kN1w64sLlIgFQapehDmZhQgEi+HfZUu7FpovvkbiQ3j94Qk6Scx6Wet7YwD Hel4L3QryvA7U7qT88c1m31KUlhUfpAjo4nq1uHG17aoF1fivaheme4yJdI/P3L3tbjq YnO8vBva7qQ260EehJVEWqBjyGKtEYQNGRKva84VEc6+/hMHGINhr8oY/qS6bjrekD0B YIKbHe0SADdn0VBU6fb7NhfAEXl3wvyNbuzzQOrJLnrPngsFzZn79lXRKfS0iFcIbTkT elf8445/iZwYyfiZQjlCDR0y5kSjaULjCqL5xeldS7V/03E9GP/2TSFLVN1+Gl/Cc84s OTLQ== X-Forwarded-Encrypted: i=1; AJvYcCXJgksNWRgY6RrCQuCEjKkgiV6+ehm6RnfSYeebZwCIy/OYW+i85l8uHqrtbnGJhH0mhvMmuXAQ@vger.kernel.org, AJvYcCXqN9XflNGp4OsUpmTEI71O9cTzKWSgiAgiVZtk8UK8MVyj2QD9RDFGJy/B+cmn9z66S8RFU66CnIQsZX0=@vger.kernel.org X-Gm-Message-State: AOJu0YwNeTXO7BYZPDhyBDbxrFfvlfqnHuddB6UmnNtYpH6aksg51fUK EZNj8bHtQcnd6ke8Pye/58EekId+epRioD+3qODN9fxpNNR/ZXOy+uM/VQ== X-Google-Smtp-Source: AGHT+IFkbg1eGxyJbeBncyAP4B/tWHtxy5THWiiSaonWl5d5SEsPzMI0wadD4BQGLT91EF2QqwdmcA== X-Received: by 2002:a17:907:97cf:b0:a86:c9f5:68df with SMTP id a640c23a62f3a-a897fa74e79mr197368866b.44.1724946479571; Thu, 29 Aug 2024 08:47:59 -0700 (PDT) Received: from localhost.localdomain ([46.248.82.114]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a898900f29csm93489466b.64.2024.08.29.08.47.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Aug 2024 08:47:59 -0700 (PDT) From: Uros Bizjak To: netfilter-devel@vger.kernel.org, coreteam@netfilter.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Uros Bizjak , Pablo Neira Ayuso , Jozsef Kadlecsik , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Subject: [PATCH v2 2/2] netfilter: nf_tables: Fix percpu address space issues in nf_tables_api.c Date: Thu, 29 Aug 2024 17:29:32 +0200 Message-ID: <20240829154739.16691-3-ubizjak@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240829154739.16691-1-ubizjak@gmail.com> References: <20240829154739.16691-1-ubizjak@gmail.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org Compiling nf_tables_api.c results in several sparse warnings: nf_tables_api.c:2077:31: warning: incorrect type in return expression (different address spaces) nf_tables_api.c:2080:31: warning: incorrect type in return expression (different address spaces) nf_tables_api.c:2084:31: warning: incorrect type in return expression (different address spaces) nf_tables_api.c:2740:23: warning: incorrect type in assignment (different address spaces) nf_tables_api.c:2752:38: warning: incorrect type in assignment (different address spaces) nf_tables_api.c:2798:21: warning: incorrect type in argument 1 (different address spaces) Use {ERR_PTR,IS_ERR,PTR_ERR}_PCPU() macros when crossing between generic and percpu address spaces and add __percpu annotation to *stats pointer to fix these warnings. Found by GCC's named address space checks. There were no changes in the resulting object files. Signed-off-by: Uros Bizjak Cc: Pablo Neira Ayuso Cc: Jozsef Kadlecsik Cc: "David S. Miller" Cc: Eric Dumazet Cc: Jakub Kicinski Cc: Paolo Abeni Reviewed-by: Simon Horman --- v2: Also use {ERR_PTR,IS_ERR,PTR_ERR}_PCPU() macros. --- net/netfilter/nf_tables_api.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c index 0a2f79346958..46f362d4859d 100644 --- a/net/netfilter/nf_tables_api.c +++ b/net/netfilter/nf_tables_api.c @@ -2074,14 +2074,14 @@ static struct nft_stats __percpu *nft_stats_alloc(const struct nlattr *attr) err = nla_parse_nested_deprecated(tb, NFTA_COUNTER_MAX, attr, nft_counter_policy, NULL); if (err < 0) - return ERR_PTR(err); + return ERR_PTR_PCPU(err); if (!tb[NFTA_COUNTER_BYTES] || !tb[NFTA_COUNTER_PACKETS]) - return ERR_PTR(-EINVAL); + return ERR_PTR_PCPU(-EINVAL); newstats = netdev_alloc_pcpu_stats(struct nft_stats); if (newstats == NULL) - return ERR_PTR(-ENOMEM); + return ERR_PTR_PCPU(-ENOMEM); /* Restore old counters on this cpu, no problem. Per-cpu statistics * are not exposed to userspace. @@ -2525,10 +2525,10 @@ static int nf_tables_addchain(struct nft_ctx *ctx, u8 family, u8 genmask, if (nla[NFTA_CHAIN_COUNTERS]) { stats = nft_stats_alloc(nla[NFTA_CHAIN_COUNTERS]); - if (IS_ERR(stats)) { + if (IS_ERR_PCPU(stats)) { nft_chain_release_hook(&hook); kfree(basechain); - return PTR_ERR(stats); + return PTR_ERR_PCPU(stats); } rcu_assign_pointer(basechain->stats, stats); } @@ -2642,7 +2642,7 @@ static int nf_tables_updchain(struct nft_ctx *ctx, u8 genmask, u8 policy, struct nft_table *table = ctx->table; struct nft_chain *chain = ctx->chain; struct nft_chain_hook hook = {}; - struct nft_stats *stats = NULL; + struct nft_stats __percpu *stats = NULL; struct nft_hook *h, *next; struct nf_hook_ops *ops; struct nft_trans *trans; @@ -2738,8 +2738,8 @@ static int nf_tables_updchain(struct nft_ctx *ctx, u8 genmask, u8 policy, } stats = nft_stats_alloc(nla[NFTA_CHAIN_COUNTERS]); - if (IS_ERR(stats)) { - err = PTR_ERR(stats); + if (IS_ERR_PCPU(stats)) { + err = PTR_ERR_PCPU(stats); goto err_hooks; } }