From mboxrd@z Thu Jan 1 00:00:00 1970 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 C9525C77B7D for ; Sat, 20 May 2023 05:21:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E5614900004; Sat, 20 May 2023 01:21:53 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E07C3900003; Sat, 20 May 2023 01:21:53 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CCEA5900004; Sat, 20 May 2023 01:21:53 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id BD1A6900003 for ; Sat, 20 May 2023 01:21:53 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 7F7721409F9 for ; Sat, 20 May 2023 05:21:53 +0000 (UTC) X-FDA: 80809486506.18.310C52D Received: from mail-wm1-f42.google.com (mail-wm1-f42.google.com [209.85.128.42]) by imf22.hostedemail.com (Postfix) with ESMTP id 890E1C000A for ; Sat, 20 May 2023 05:21:50 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=gmail.com header.s=20221208 header.b=qJMAA70o; spf=pass (imf22.hostedemail.com: domain of lstoakes@gmail.com designates 209.85.128.42 as permitted sender) smtp.mailfrom=lstoakes@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1684560110; a=rsa-sha256; cv=none; b=KsffaU8/ucB+IEqYz6Wb2xWFDdkukOiK59rFbau65G6SH4akiZNqoOy8lpTTL/G3XqwoJB mTnFQ9PWkoac5v8VuFPLcO9MllLPxpWMeWdyDJiPXsiWVPHnOIn0bXfi7VD/rVDNdKyaaH u7jpvcUaC+EVtHxGaoZZlRl+4j5Nk8o= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=gmail.com header.s=20221208 header.b=qJMAA70o; spf=pass (imf22.hostedemail.com: domain of lstoakes@gmail.com designates 209.85.128.42 as permitted sender) smtp.mailfrom=lstoakes@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1684560110; 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-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=+YCeLgnfdNNLRbQJ3YR4Z/VQhSO2Fn36PmEIuzpNl+A=; b=MTEJiQc+2xP2X00avFOmI36Tn0VmuClIDmYbeqac9N944Y/KSFPVrTbn+dXi/NndwxnubZ ArGCjUce/FWicMtbvrjFC9Y+B7mhRRpogfGEoUDE/ZX39p5C0DwuqDnc7CI7c0R7WxzqCJ zqOrZwOKP+gTPRlyV1YXmlTgrEwBCQA= Received: by mail-wm1-f42.google.com with SMTP id 5b1f17b1804b1-3f41d087b3bso40480305e9.0 for ; Fri, 19 May 2023 22:21:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1684560109; x=1687152109; 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=+YCeLgnfdNNLRbQJ3YR4Z/VQhSO2Fn36PmEIuzpNl+A=; b=qJMAA70oc2XzjFfK6LPciZZQX2UKttbs+TQxY35L4pb79WT5OF3+MZZGqHT4YHfuAM yQ9VXsEnIgwnlo2mLlA+UcY8p7lXlWs3dDK1rjLegS/JB9UMW4dKKr44A+h2KTvBFh2P i3lJ24kUMGsp0l97Sq/Q7+hPMOx/TH+8c1plxCa03LEupDJd9GB7Ff8Mgk9a930xkeWR yhmy9LwdvUrNh9FAyBb+2qNOo2FTi8zAZJZY4MZSjxDkFlJfnhrY6dT2ctcRQPcEvFbC uFlZ8p8+TmykOoeWdT9qmQ/HDEdELlbSRVLyxIb12w9GN0LFjpEaqHCie1vuGi3OhpSl ontg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684560109; x=1687152109; 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=+YCeLgnfdNNLRbQJ3YR4Z/VQhSO2Fn36PmEIuzpNl+A=; b=GY2U1qbdEgFb1V8MucSNXoMOxQEwyKF+MR/Au13MEqfd4d8fajLw8FKh6rR/NpP8O+ ry1UkqXcrnc6HzCPEXOENKKTvjLoE3xE0ywTvgTO7h0H41nVDD/1l1YppiH0GxBaexjM O2ZKPTaws1tLoyOJwYNqFnMJheEwssb8HCwPigZRbM665hVCV+0cPLlEBYjPEyxral4G 35euEKXkrnz9Vj67k1Be23LnEWpf8CBmeJDginnOxaZ7XIl/Kl9JL8EmDpN1lXrVie2e z/IOHvv0VNTbz4RYp3HbyT5lWGxPkACn9MWT4hw+PjJungPH4A+i25BJ89Cg6Y3x2Tet yfjg== X-Gm-Message-State: AC+VfDx3lFkwBE1HGXMQGHORmPaTHDqKZm70EXf7QFkphIC4CezLE32j vO/Oxlr9uvA173MT9bpKj3Y= X-Google-Smtp-Source: ACHHUZ4Eoa9xWVslykQCIhtD+WNpYCFuNO5kU1HN6r6LAMURYRyh8pv+wrNmJ053DffGSdTv1WNVTA== X-Received: by 2002:a1c:7314:0:b0:3f4:2bce:eef8 with SMTP id d20-20020a1c7314000000b003f42bceeef8mr2763578wmb.16.1684560108575; Fri, 19 May 2023 22:21:48 -0700 (PDT) Received: from localhost (host81-154-179-160.range81-154.btcentralplus.com. [81.154.179.160]) by smtp.gmail.com with ESMTPSA id l13-20020a7bc44d000000b003f42328b5d9sm1062855wmi.39.2023.05.19.22.21.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 May 2023 22:21:47 -0700 (PDT) Date: Sat, 20 May 2023 06:19:37 +0100 From: Lorenzo Stoakes To: Jason Gunthorpe Cc: Arnd Bergmann , Andrew Morton , Arnd Bergmann , Catalin Marinas , Will Deacon , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-perf-users@vger.kernel.org Subject: Re: [PATCH] [suggestion] mm/gup: avoid IS_ERR_OR_NULL Message-ID: <1ca47b8a-292c-47ab-aa6f-ca24fdfc0d3c@lucifer.local> References: <20230519093953.10972-1-arnd@kernel.org> <5b071f65-7f87-4a7b-a76a-f4a1c1568ae7@lucifer.local> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 890E1C000A X-Stat-Signature: xsei87dqrwx43iaxdab5hw85abj9bjae X-Rspam-User: X-HE-Tag: 1684560110-630085 X-HE-Meta: U2FsdGVkX1+CmDhvtjPlgUCUS9N2BzR5FeL/eS6zIiseEw+PCioN2J7szFKfZeb5M8dtERBr0cvt1UxfURlyuIUqnyqafsfbPXzATF8ijutJ5Z/sVnWZhNtljwn6Qa58FBHk1hyhRrrONu61wc+QRdG5hVNUJ9MVtcZ+wLH2SeME1xQUALeHMhKEH9WH5qd1bccuSfh65/klvqoY6IZpfkWXXH0K6bSyUdYtIdLLzvPk+NVzpHgviXYO9RzDiiBhe3uByaVV490A0JzIGI9tnHnQQ82vmbcO/h934Pj3R8RLwf1qHJwAl/Cd0gCsq1mUKrwxraHX5OmBlDbCEpBCyeCa/EwJYRuv7j71aGauD9b7LFj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=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Fri, May 19, 2023 at 07:17:41PM -0300, Jason Gunthorpe wrote: > On Fri, May 19, 2023 at 03:51:51PM +0100, Lorenzo Stoakes wrote: > > Given you are sharply criticising the code I authored here, is it too much > > to ask for you to cc- me, the author on commentaries like this? Thanks. > > > > On Fri, May 19, 2023 at 11:39:13AM +0200, Arnd Bergmann wrote: > > > From: Arnd Bergmann > > > > > > While looking at an unused-variable warning, I noticed a new interface coming > > > in that requires the use of IS_ERR_OR_NULL(), which tends to indicate bad > > > interface design and is usually surprising to users. > > > > I am not sure I understand your reasoning, why does it 'tend to indicate > > bad interface design'? You say that as if it is an obvious truth. Not > > obvious to me at all. > > > > There are 3 possible outcomes from the function - an error, the function > > failing to pin a page, or it succeeding in doing so. For some of the > > callers that results in an error, for others it is not an error. > > No, there really isn't. > > Either it pins the page or it doesn't. Returning "NULL" to mean a > specific kind of failure was encountered is crazy.. Especially if we > don't document what that specific failure even was. > It's not a specific kind of failure, it's literally "I didn't pin any pages" which a caller may or may not choose to interpret as a failure. > IIRC if you look really closely the only time get_user_pages() > actually returns 0 is if the input argument validation fails, which I > think is a bug that should be fixed. That can be a reason for gup returning 0 but also if it you look at the main loop in __get_user_pages_locked(), if it can't find the VMA it will bail early, OR if the VMA flags are not as expected it'll bail early. > > get_user_pages() never returns 0, so get_user_page_vma_remote() never > returns NULL. Until we get there collapsing the 0 to EIO is perfectly > fine. Well no, as shown above actually there is a distinct third state, i.e. couldn't pin, which if you see there is at least one case where the caller differentiates between an error and not being able to pin - uprobe_write_opcode() - which treats failure to pin as a non-error state. Also if we decided at some point to return -EIO as an error suddenly we would be treating an error state as not an error state in the proposed code which sounds like a foot gun. > > Jason