Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp1296709rdb; Sat, 23 Dec 2023 01:07:48 -0800 (PST) X-Google-Smtp-Source: AGHT+IFz4Xnin2I9sxa+clE3HpflxJqqRy9XXkY2PjZ68g5Gso1LMc9Il5Dfn+jPdGxedcj0PWeT X-Received: by 2002:a17:902:dacb:b0:1d4:3012:f4ca with SMTP id q11-20020a170902dacb00b001d43012f4camr1388346plx.56.1703322467907; Sat, 23 Dec 2023 01:07:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703322467; cv=none; d=google.com; s=arc-20160816; b=ZmfJwijB/CKvM+5Iqd3uxvaov6zN6U1p4jHmPddA07eOk04yivYCwatDA9vrBtlOYK BX3ORRhzD2MwDbaCat8E4vlTqRAr/0FG7FqUIEFYS+ogOvIBKsuZCzBDw7BQgtCK5HG/ E1hISLRNcA+3lRL8OT+blEifc+iiakUH0hwyV4boFCKhYZCNpC/un/RLzfyojvspiwjU rCT7tw6mWjnyWal+hEFJufIm5ce62MgWrZJsk8nZYo+7H2uM7jAVy7nQlJM6GAVtBThr khV/848XGyAFQGAMgmF7KIYw5wStZfat7PRvVMFJRIifUM//Gwdx6OVJ2/dUMkZ0e3Qv GEeg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :dkim-signature; bh=o3qBDWKNLuMDa0UhHV+jKTkyBtD8xXFnzgQzoDr0mNw=; fh=DsBlhi+xFHOUpLNfqVvixkuj/4NQYWpQDurUZBktgGY=; b=ZZjAI8xBOe5JLlHND+ncMIbwb8+XCdkEKY9YWsxuHAjGSizMGPxfNIf2VL3qSxYGUY diPWRxfqEqQ4qYwJroFaub6tYNy2NKIbaM9Bv9g8Tzx5q8q5VZhxuPIEUFEg0aKJUg6i MOJ5S2md2SunP1uK6xlRj5n3VRL2rzps5npAfKnken01wLaQMTfc0+L2y/Gk4mj6t951 3271o9ZpWyLOIFuk8r6FSXY2HXdhDisI7MewIWyVyqG2tFsXJJjHFcdINvGAWnyhQW7n TlNVMmJI3eBaBnjDFlD30YEEIAvjGGmdC/HZmnnb46dK/Ri+MJbRP+3/PYYYWsw6sNr7 E8Ow== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=ePhiTCGy; spf=pass (google.com: domain of linux-kernel+bounces-10353-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-10353-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id pv10-20020a17090b3c8a00b0028c2b5f71c0si1050650pjb.54.2023.12.23.01.07.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Dec 2023 01:07:47 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-10353-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=ePhiTCGy; spf=pass (google.com: domain of linux-kernel+bounces-10353-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-10353-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 4C76D28542E for ; Sat, 23 Dec 2023 09:07:47 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 303D78F61; Sat, 23 Dec 2023 09:07:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ePhiTCGy" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-qk1-f173.google.com (mail-qk1-f173.google.com [209.85.222.173]) (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 02F578BF2 for ; Sat, 23 Dec 2023 09:07:38 +0000 (UTC) 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-qk1-f173.google.com with SMTP id af79cd13be357-78106c385a1so190104485a.0 for ; Sat, 23 Dec 2023 01:07:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1703322458; x=1703927258; darn=vger.kernel.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=o3qBDWKNLuMDa0UhHV+jKTkyBtD8xXFnzgQzoDr0mNw=; b=ePhiTCGyCgJA2KZqL6qrFtJRDbQYXqSS3Xk0SMoS4nBXoM+aLnYqTDY3znAgiBKyyL OShaDgQnoY+lLkffxKnkP6yDBXIR7+E+ddlT2ti4O2CQkzrrRK1QM7cDbn/7DV96ZnGS CeWiGFXDf+v7zqu1sMZduxyAXDM6CRRPX50lJLxfEk+KJL4LG5eBapC2r/dCuxrHmyQW jxMU4vWsVfaXF7HQ+wBVxYGOioLY68pfEnSwi3mrK61w/BsjwO4E1VI/fJ7Xr0ng4/92 Vk39dJL5v+gPruZb8fpgCcmHsbjeV/PHP12nCeQSQ+QWlC8cOuoAiFFFvYwbpzDrgtXI DhZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703322458; x=1703927258; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=o3qBDWKNLuMDa0UhHV+jKTkyBtD8xXFnzgQzoDr0mNw=; b=QbdkwBzeVJUV3t7WsdeOlVwyyWtppDVu49GEHL8pvHODCcHqq9K48Go/27K0DibbmY rd3rF+tmUeTpeK7dgiXEHMMJyiUDeYc98wxRpfIhSbdoc8CuArWe0z3+oHZSR++sxVpM S1T1yc+qh+WWS8xkVllMO+eAVTmt/v4oklFzVIWgKESbh+mDVUxBUo6InxJFY60x2zZe LgooN0iJBYbqN0SMd3KRLPKHThTCLfgrRNNOHnKOcKwO/k6hEfA3z6gLGRDOjFcYNJK4 ruTHU1rN1jypKVivW0nocCu+oBUIpb+zMuEBF1nEFMsNBPwLAfu9e7jW5hJdtU0kKyHX sndQ== X-Gm-Message-State: AOJu0YxVWhxQiczMXFX43vq/6rQ7ybGzyImsH3VMikjjpd20uPcqyzqG GhMit1Ecc4QQGEqKTp8/WIo0F1/EAFajlGYGGAY= X-Received: by 2002:a37:ad02:0:b0:77e:fba3:9d24 with SMTP id f2-20020a37ad02000000b0077efba39d24mr3020303qkm.136.1703322457686; Sat, 23 Dec 2023 01:07:37 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20231116173849.210205-1-kdipendra88@gmail.com> <3ff3e05a-8377-4b38-84ae-be24b6cae6a4@intel.com> In-Reply-To: From: Dipendra Khadka Date: Sat, 23 Dec 2023 14:52:26 +0545 Message-ID: Subject: Re: [PATCH] x86: Fixes warning: cast removes address space '__user' of expression in uaccess_64.h To: Dave Hansen Cc: 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 Content-Type: text/plain; charset="UTF-8" Hi, On Sat, 18 Nov 2023 at 01:32, Dipendra Khadka wrote: > > I am sorry for the formatting of the text as it was due to changing to text > from html and also I wrote "why spare did not find the difference between > 'long' and 'unsigned long' in this particular case." instead of "why Sparse > found the difference between 'long' and 'unsigned long' in this > particular case." > > Thank you for your consideration. > > On Sat, 18 Nov 2023 at 01:16, Dipendra Khadka wrote: > > > > Hi, > > > > I am not sure why spare did not find the difference between 'long' and > > 'unsigned long' > > in this particular case. I saw that in else case,there is use of > > unsigned long and sparse > > does not report a warning .Hence I thought casting to unsigned long > > will solve the problem. > > Also, there are not any other warnings thrown by spare in the uaccess_64.h file. > > > > I think casting x to 'void __user *'before checking whether it is > > greater than or equal to zero > > in valid_user_address() will be more sensible and fix the warning either. > > > > Is this ok for you? Or have to cast to 'unsigned long' or other > > changes or no need to do anything? I thought it would be a good time to ask again whether I need patching or not for this warning? Thanks > > > > > > > > On Sat, 18 Nov 2023 at 00:00, Dipendra Khadka wrote: > > > > > > Hi, > > > > > > I am not sure why spare did not find the difference between 'long' and 'unsigned long' > > > in this particular case. I saw that in else case,there is use of unsigned long and sparse > > > does not report a warning .Hence I thought casting to unsigned long will solve the problem. > > > Also, there are not any other warnings thrown by spare in the uaccess_64.h file. > > > > > > I think casting x to 'void __user *'before checking whether it is greater than or equal to zero > > > in valid_user_address() will be more sensible and fix the warning either. > > > > > > Is this ok for you? Or have to cast to 'unsigned long' or no need to do anything? > > > > > > > > > On Fri, 17 Nov 2023 at 21:04, 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'? > > >> > > >> Either way, if we're going to fix it it seems like it would be better to > > >> valid_user_address() actually handle, well, __user addresses rather than > > >> expecting callers to do it. -- #Dipendra Khadka