Received: by 2002:a05:7412:5112:b0:fa:6e18:a558 with SMTP id fm18csp927184rdb; Tue, 23 Jan 2024 22:09:09 -0800 (PST) X-Google-Smtp-Source: AGHT+IG83BuFqfO2LJLOlLGsgKDZq36lFvQHzK/BgmRT95YbVVtXsEII+qHyNV7I5XO/6or0jyDI X-Received: by 2002:a05:6a00:238d:b0:6d9:8c7a:715d with SMTP id f13-20020a056a00238d00b006d98c7a715dmr4457482pfc.64.1706076548792; Tue, 23 Jan 2024 22:09:08 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706076548; cv=pass; d=google.com; s=arc-20160816; b=N08Cw3TT3vijOUtDsNOhbRPKVPW38AgI5DWHoF9stJIs7f4nDkG1Za7DW57wxRwb+Q 7k6K5dKM5WoWz/cT8oi+wJgF/a0RkQfSZo4BzKb6IRL86nZDSMq+ZVw/g/gXMvDMU+qE 7w+kJrjqqss1gQLGSD3FhpSweOYV+xCoVz3OGgESZSQE+alxztcNbL32DqK/l4Mo++S8 J1QBo5ilMk2UwiSfm14egdl4sLLNx+lEyE5o3mrE+zLGsA4LzrPhnf1rUVpUyV2czGE9 eDgSCo49H/jQ0Nt9HfT+ceiHO2NDQNZMfMrLohU/4Oy3Ujb9anm8+Uai9SypO2g4xthf wstA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=XFGIMxX3KH4mPnJxpq+0pjEUKuZocKr5n4+8ml1MYB4=; fh=bwE5rTT3SzJxfPpQvRf4deCLzGaX1ERCBqudg88BVe8=; b=EEVXzOLfPPNNBMDQXTed3W/nMb/Al2ZNFM5wq/gtu6aX+C4UINSEbYqSe5+dAQa3Nx 24WhKzEePsPjeKMoO+oa6VP10vMe1GlxmDAsWC45zqAjnLNKvMIK3uBexc+JTXp/3nxp ubvIsIm9echN6ZQEY/kqvpV9CUpdYsJ5uAOrEcY0rteFsFqUDipyEzw09IRnhN6MyVrs 5A2vxhvP8/DGGZUmc6mep1B2UMS6M8ZXJjuO/EwnKRn8lgpnITgbyD+n7wj9otmFxZYG 56cXwstBjRjvHb+Re2olGHq/lQdld4GE3y9glFrr70q0E37r1dIUmQYxoD3LFbD8qszk SmOA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=KHsXgqhD; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-36501-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-36501-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id y1-20020a63de41000000b005ced9797d6asi9809486pgi.410.2024.01.23.22.09.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Jan 2024 22:09:08 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-36501-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=KHsXgqhD; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-36501-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-36501-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 45A52B248DD for ; Wed, 24 Jan 2024 06:08:39 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 49793F517; Wed, 24 Jan 2024 06:08:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="KHsXgqhD" Received: from mail-oi1-f182.google.com (mail-oi1-f182.google.com [209.85.167.182]) (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 2FC63C8D2 for ; Wed, 24 Jan 2024 06:08:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.182 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706076510; cv=none; b=d+yocI0AeQvGKfhmXWiFyXky+3jMoGhqP82peeFESZIPSykRzo575NWQ3YUQciLucsALUECwTdG1eC6KShvJRpuXF8rlgjahlS9Of/WwtZBHvQvC5I7KkB9Ze5Uy3VKoaN19oYN/n7TzvW3C+VMcdLUBkJX7PkA+0WCICbgQrM0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706076510; c=relaxed/simple; bh=TGlAgmwHRl/iW+d3270Mbocu0m1PP/EM0jtUyXaUn3U=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=GRPubs5izubPLVqe1ixBQt84hc7MMgwt0paGs2q8ZvtYZxaUPcoAyQakQ1bu04m6hfjPEpqs8xXiGfPRpuatXO//O4u4rNjG4edICBxpoQE/Rydx1QntyCZjJ8x4CFPGhMfZDOAhN3K9pptshoMmo3QxPrQ1su+vJf4P6eJAeVA= 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=KHsXgqhD; arc=none smtp.client-ip=209.85.167.182 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 Received: by mail-oi1-f182.google.com with SMTP id 5614622812f47-3bbbc6bcc78so4127210b6e.1 for ; Tue, 23 Jan 2024 22:08:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1706076508; x=1706681308; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=XFGIMxX3KH4mPnJxpq+0pjEUKuZocKr5n4+8ml1MYB4=; b=KHsXgqhDzeUdzUBzfGuCqYBVtK/yHPbVdwBwUTIOduw0SCZPeRLOovGVHBpHXFDfVD b1Zthp73YX+Zh255L3LZh5JU4hI7Cx64EQvfeS6JeKi4iHqSMyKf3u+HKOQKJtKPpXs1 tBlOQNfs7S4UVsdtV3SzDwli4Iu8RZYPTHHNMY+qlxhIn/zurjmHsZNp6y2sxK0gd4UX Zkv66QCooaZLaIJnXFoNHuqFMm5L5sFkKwgW/qaA6Q6k0DMPYT5hlin3uve91Qhscgng pjmzw8tCqd7f4gkGdpsxyeohSgDJCEu16lFQBHXpgWzVI2LU5wsMzN2lytGxcgGYd0za ZBmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706076508; x=1706681308; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=XFGIMxX3KH4mPnJxpq+0pjEUKuZocKr5n4+8ml1MYB4=; b=MjuRV/hy9hblfk3S2rFVl/i/u27lw39QXMKXEOOnjI3mGHfthlrlOjaBoT5QRwDSsl 0M1i//G0c6XZfU0LVMgwiu0O1sEj9xwOIS4mao6SVxwlqFBRdP+tPgc1WK+M8zNyK+Ev EBpMsgw1q7qjtE1tQaSEbcnxW6tLECc+KlLrFzuA1AjPVJuaI9S/S1qO020Tixd9V6CM fAGBJmse+5HkPSgBt5rg1rCoXB/OzjnwMZkkGK59T0nddZtmY8jEeAFxWERxMJyax5Y5 HEybgC8EpQNxQBiL+TqcPepwxxu9lAc6Z928ft6lwTibVtehIqknF+ISTALNC27zPLe2 /nEg== X-Gm-Message-State: AOJu0YxtLxHHnb3TjLGtOwdgQDqXpWkZKlOg6p/55Wx8CbI44sb9gwZ8 DNP/rKwtRFCSIPjfg73GY5uNsrBXZIxjwjlrJD8+tQBH88wXjSfX X-Received: by 2002:aca:1c0f:0:b0:3bd:b5a9:d824 with SMTP id c15-20020aca1c0f000000b003bdb5a9d824mr1046533oic.62.1706076508118; Tue, 23 Jan 2024 22:08:28 -0800 (PST) Received: from google.com ([2620:15c:9d:2:cddd:d715:19de:f1d8]) by smtp.gmail.com with ESMTPSA id jw21-20020a056a00929500b006dd887e37f0sm770300pfb.210.2024.01.23.22.08.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Jan 2024 22:08:27 -0800 (PST) Date: Tue, 23 Jan 2024 22:08:24 -0800 From: Dmitry Torokhov To: Dave Hansen Cc: Dipendra Khadka , tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, mjguzik@gmail.com, ira.weiny@intel.com, linux-kernel@vger.kernel.org Subject: Re: [PATCH] x86: Fixes warning: cast removes address space '__user' of expression in uaccess_64.h Message-ID: References: <20231116173849.210205-1-kdipendra88@gmail.com> <3ff3e05a-8377-4b38-84ae-be24b6cae6a4@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <3ff3e05a-8377-4b38-84ae-be24b6cae6a4@intel.com> On Fri, Nov 17, 2023 at 07:19:12AM -0800, Dave Hansen wrote: > On 11/16/23 09:38, Dipendra Khadka wrote: > > Sparse has identified a warning as follows: > > > > ./arch/x86/include/asm/uaccess_64.h:88:24: warning: cast removes address space '__user' of expression. > > > > Since the valid_user_address(x) macro implicitly casts the argument > > to long and compares the converted value of x to zero, casting ptr > > to unsigned long has no functional impact and does not trigger a > > Sparse warning either. > > Why does sparse complain about a cast to 'long' but not 'unsigned long'? > Both remove the '__user' address space from the expression. Were there > just so many __user pointers being cast to 'unsigned long' that there's > an exception in sparse for 'void __user *' => 'unsigned long'? Yes, unsigned long is special: commit 7816e4c4a2dba6fef24c9a52c6b17a8cde0c8138 Author: Linus Torvalds Date: Mon May 31 13:18:57 2004 -0700 Allow casting of user pointers to "unsigned long". It's reasonably common to do special pointer arithmetic in unsigned long, and making people force the cast just adds noise. I wonder if we should have: #define valid_user_address(x) ((__force long)(x) >= 0) or #define valid_user_address(x) ((long)(unsigned long)(x) >= 0) Thanks. -- Dmitry