Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp16859imm; Mon, 4 Jun 2018 12:11:28 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKNuMC2JT9lqsTB5Gant6trZSxUZ6Rd/jCiSu6YVPtbvCEqp3P4vVlGsufAjC6GyiKWq0VB X-Received: by 2002:a17:902:be0b:: with SMTP id r11-v6mr23339142pls.182.1528139488416; Mon, 04 Jun 2018 12:11:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528139488; cv=none; d=google.com; s=arc-20160816; b=DHlU4pFbZGBuM34GWXPmAUliV6ELB/GyvvFWcHpceirI5SSQY4gDxXzE0/DpxcBSST vQ9TtUuoKzIWZKOKw5iD/4k5wRCQKVCUupTyG26K32ztsjKbY73/RkWzGJpAHi880E9e 9h2YD08qghH2DgtX6LtoEQgkigydqNffHVeERpuJx2LVYHLnmvcNOgIgl6o2uuTmPms+ J3QIMZFdZ6RJ10UYut9x6FMpQtRdOjIA1KMTy8UR0MFlnxImBZWLVpqqGlgy+DGjihzS ClRFglKxriXiRsUBLyuK39L1yVGs1y42JPR/PJ87v130rprkPvR+YT4PUvwSpV4FOaCu AYuA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=0Mf6nSrDpgxJ3abaM1bsQmUlkIZogDfZPaQ9h48r1lg=; b=d9Usiev8aSJzMnu7JVXXjsZJi0oR+kftO2KlH0xhLZFlXrsfAJ9HqdCTumU+5pl1hD elwndzw4k5z+bz99GjkPv3ZceUjH1FZLvi3EtEiKcusahoSdnckhWscHMthdgYGkG1Vo soIZqFXcXlNTisszLKSY/ZbqYWBbVYxSIOxmYOb1tuYe09SAZe/c2EICwFZRTTwNtHmA L5wWC9fORqNeBB7E1O4Y2aBc4p0LPcZ2bUlMKTDJ1bN2ikRz4pSvfqrYemt3WiQCf0+w ssLa0o2gzHoZ2xc/uYH3X1b7dspQCTituGlA+5kZl1lM97LDg41pr72DDU7MB7vd4oN+ 5jyw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=dj4oIcb4; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t62-v6si375376pgb.582.2018.06.04.12.11.13; Mon, 04 Jun 2018 12:11:28 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=dj4oIcb4; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751209AbeFDTJb (ORCPT + 99 others); Mon, 4 Jun 2018 15:09:31 -0400 Received: from mail-wm0-f68.google.com ([74.125.82.68]:53378 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751042AbeFDTJa (ORCPT ); Mon, 4 Jun 2018 15:09:30 -0400 Received: by mail-wm0-f68.google.com with SMTP id x6-v6so331118wmc.3 for ; Mon, 04 Jun 2018 12:09:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=0Mf6nSrDpgxJ3abaM1bsQmUlkIZogDfZPaQ9h48r1lg=; b=dj4oIcb4tQPC3kym6weEGj0feSxW+C6bxADE6IvF+x9ro5AEy542U+z3pj691ZtPZW jykLG4IwRRwAj4ZhLCs3Nmn0tvWkbvWq+ovDupC8NxKG2fq212P7B+qQNZO5iNPXo7sp VmOPmjuO8kf62hWLySW3gIwuuVu2EM0K3PyKO4cmcV8D+PeAiyDb0B5SlLg+9+YObiMT a/f78QTwFyab4M+a3rq7ZA+MHJacCEr9oarOlPikl6DYZySWsvmglhqSOc/krT4NV0v1 5dqgLjk0y27gJ+NZYrr+CqpKBvyoDz9JHMs9+LXymhWQsTcAm0m9tEmOaAGfpCEzHFP1 8WzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=0Mf6nSrDpgxJ3abaM1bsQmUlkIZogDfZPaQ9h48r1lg=; b=IdoLAAOBuFEsH/ncFgLOfy/Qk8bNnQD4szLqpHykVfeCu/ZELBem9CYcupMUKv5fF5 Zfws/cjyJDmlIvtMva0fc8LJHvJq3MhhGuj4vaKKnsrkiqXjS7fN/3iyQh177AcVR41n 1cpZluEIe11UbOdiX2BowVkckGdtHUganF4SdtBgSsPteRwa9Omlf201fTw79J6c7Z0G ffTrVPjY2xx1StP/QMPNbp7BeVjHNBVxDa628L5KBQt4rIQW8Hrrot0yVDs1y+8MC4h/ oH9mMKREEYqT/FAZpfqrXP56Z+eAM2KrF0+cJeeH6w2TqqXQHmQteYc3/VCjJ82xFJt8 WYWw== X-Gm-Message-State: ALKqPwcLVFEiuxrVvsOBSPl7WIKmQfIF8lopnFnHbYg8OSH/5y8c/w5w CfG/cFYC02pEaVq0cxZLOCw1jLHM X-Received: by 2002:a50:b376:: with SMTP id r51-v6mr20718042edd.145.1528139369277; Mon, 04 Jun 2018 12:09:29 -0700 (PDT) Received: from ltop.local ([2a02:a03f:4023:8a00:58f3:fa82:4395:5aab]) by smtp.gmail.com with ESMTPSA id k7-v6sm25428899edn.74.2018.06.04.12.09.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 04 Jun 2018 12:09:28 -0700 (PDT) Date: Mon, 4 Jun 2018 21:09:28 +0200 From: Luc Van Oostenryck To: Atish Patra Cc: Palmer Dabbelt , "linux-riscv@lists.infradead.org" , "linux-kernel@vger.kernel.org" , Albert Ou Subject: Re: [PATCH 3/3] riscv: fix __user annotation for __copy_user() Message-ID: <20180604190927.7jrdlulgowt5umce@ltop.local> References: <20180601152123.47256-1-luc.vanoostenryck@gmail.com> <20180601152123.47256-4-luc.vanoostenryck@gmail.com> <235fec3e-be2e-874a-8313-e7390fcdca74@wdc.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <235fec3e-be2e-874a-8313-e7390fcdca74@wdc.com> User-Agent: NeoMutt/20180512 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jun 04, 2018 at 11:46:50AM -0700, Atish Patra wrote: > On 6/1/18 8:22 AM, Luc Van Oostenryck wrote: > > __copy_user() is a function, written in assembly, used to copy > > memory between kernel & user space. As such its to & from args > > may both take a user pointer or a kernel pointer. > > > > However the prototype for this function declare these two args > > as 'void __user *', which is no more & no less correct than > > declaring them as 'void *'. In fact theer is no possible correct > > /s/theer/there > > > annotation for such a function. > > > > The problem is worked around here by declaring these args as > > unsigned long and casting them to the right type in each of > > two callers raw_copy_{to,from}_user() as some kind of cast would > > be needed anyway. > > > > Note: another solution, maybe cleaner but slightly more complex, > > would be to declare two version of __copy_user, > > either in the asm file or via an alias, each having already > > the correct typing for raw_copy_{to,from}_user(). > > > > I feel that would be a better solution as it is implemented similarly > in ARM as well. > > I am unable to understand how "unsigned long" is better than "void*". > x86 implementation has both arguments as void*. Can you please clarify ? "better" is quite relative and it must be understood that sparse allow to cast pointers o fany kinds to and from unsigned long without any warnings (while doing a cast between different address space will emit a warning unless you use '__force'). As I tried to explain here above, the fact that this function is declared as taking 2 __user pointers requires to use of casts (ugly casts with __force) to get over the __user. By declaring them as taking unsigned long, you still have to use casts but, IMO, it's cleaner Note: they're generic pointers/addresses anyway, they can't be dereferenced anyway so unsigned is as good as a plain void* or a void __user* Note: using unsigned long here, fundamentally to bypass the __user, is the same as casting a const pointer back to a plain pointer via an intermediate cast to unsigned long. People can argue that's kinda cheating, and they would be right of course, but using __force or declaring twice the function with two different names and prototype is also a form of cheating. Note: if this would be my code, I would choose the solution with two declarations. Best regards, -- Luc