From patchwork Fri May 19 09:39:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 13248031 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 C0C93C77B7A for ; Fri, 19 May 2023 09:40:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4C8AD28000D; Fri, 19 May 2023 05:40:08 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 477E0280001; Fri, 19 May 2023 05:40:08 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3676E28000D; Fri, 19 May 2023 05:40:08 -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 28552280001 for ; Fri, 19 May 2023 05:40:08 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id EFB5FA0A28 for ; Fri, 19 May 2023 09:40:07 +0000 (UTC) X-FDA: 80806508454.24.1CB0364 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf04.hostedemail.com (Postfix) with ESMTP id 4508F40005 for ; Fri, 19 May 2023 09:40:06 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=r5ynEHQ4; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf04.hostedemail.com: domain of arnd@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=arnd@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1684489206; 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-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=ezp62D7PEgdKiYtNUvBAWKopeE5PIJ1hfgWBtclaTd8=; b=R4oIVRDO5R+icyWdlNuPvdjUw0EI29FfNRTCr1FeSaN/f1HT9ikzkHP1Vs+/+pQpprHky3 UxaZqenwlfBZNgwdkfOpHMXf7uz8RVsU9H0zhtQ4ZX0kY+Yz9hh8tB+jCm5xtIJOtQxLM3 fGACtQysNOFs10XHIrkuuHro4uJ68rE= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=r5ynEHQ4; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf04.hostedemail.com: domain of arnd@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=arnd@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1684489206; a=rsa-sha256; cv=none; b=lnDJwEULPpsLC5S30tTj0yyT/XQZ8Mm51utQUiilnlRrf/4VIe0lSN/IrVZnMSMb8EhsV1 qg0ChsxyAsBqwE2NzgNlLQ82ttkx7DlZO4i8cYViujC2gGBfcFs+uKo5f/WlYFFCtJmOQW XB5A7m9bQiNSrWpxowXDcaFDEP/lLrI= Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 1A7BF655A8; Fri, 19 May 2023 09:40:05 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 00C86C433EF; Fri, 19 May 2023 09:40:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1684489204; bh=62m/R5D6FGhqWG6KoI9PHPEn7TdMdQqLFV3wk0LBtDc=; h=From:To:Cc:Subject:Date:From; b=r5ynEHQ4VnYlo+YQjrf4A6aNXFbJk6j3c64Y7p0QM+DrWvOKJbZh68x46Tqydb38O MzJEmqOAOCv/UjBxt/7hYmy5B5C8xXNk+Pk4slcPAxTzm5btMMHC8Tq4NLUcW99nsw EHkGmjo/iZ9JE/YY1bu16vysaEMjywfEh8dG2cv4T4U7F1sYQWJ137x0R7n1LKD+ug 5o7PlE0O4QN5ybvdtJkliLy1JQG4V3dwzKwfGg4D+x90k9W+F1nhotMLMP+WPAY/so mQGAkaUOWqty6IqB1mzWmq2/FnYe5i3AgFTYmLaxD46SMuJQ7Cr0Ckz7+VFoXphUWy fEs8pclnp2+HQ== From: Arnd Bergmann To: Andrew Morton Cc: 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: [PATCH] [suggestion] mm/gup: avoid IS_ERR_OR_NULL Date: Fri, 19 May 2023 11:39:13 +0200 Message-Id: <20230519093953.10972-1-arnd@kernel.org> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 X-Rspamd-Queue-Id: 4508F40005 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: zze97466gitqhh14es6pwfugbas9ozrs X-HE-Tag: 1684489206-6362 X-HE-Meta: U2FsdGVkX18s5XTqM5kU8BSgIUIj4W4+d1BboCRWsU7Hyn5acnVG9rz+EoPynJZyOsrxMa1WRNTqhWVKFvDO+6mc5lW82v2TMIfnAzIdO9EK5zByJEl7n6H5Su0uRlbr67YNteqGMKUl89tfZk0W+LWVl0FINmuM++kc9dN2bYRvzW4toKsddB2jNdE5KiQERPWal6xU8p2rG6uxvwJEsEnHEG0eM7hFGuFoVYl5PEfQ4uKe/28IrZKE7MiRS5ME4OTkV14mR2Xf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ter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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. Change get_user_page_vma_remote() to return -EIO when no pages were found and adapt the callers to match. Fixes: eca1a00155df ("mm/gup: remove vmas parameter from get_user_pages_remote()") Signed-off-by: Arnd Bergmann --- I see the real bug is already fixed, but this seemed worth pointing out still. Not sure if this is the best way to handle the return types here, but the version in linux-next doesn't look great either. --- arch/arm64/kernel/mte.c | 4 ++-- include/linux/mm.h | 2 +- kernel/events/uprobes.c | 5 ++++- mm/memory.c | 2 +- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/arch/arm64/kernel/mte.c b/arch/arm64/kernel/mte.c index 4c5ef9b20065..6983ba35ce16 100644 --- a/arch/arm64/kernel/mte.c +++ b/arch/arm64/kernel/mte.c @@ -434,8 +434,8 @@ static int __access_remote_tags(struct mm_struct *mm, unsigned long addr, struct page *page = get_user_page_vma_remote(mm, addr, gup_flags, &vma); - if (IS_ERR_OR_NULL(page)) { - err = page == NULL ? -EIO : PTR_ERR(page); + if (IS_ERR(page)) { + err = PTR_ERR(page); break; } diff --git a/include/linux/mm.h b/include/linux/mm.h index 42ff3e04c006..4bb172e4818c 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -2397,7 +2397,7 @@ static inline struct page *get_user_page_vma_remote(struct mm_struct *mm, if (got < 0) return ERR_PTR(got); if (got == 0) - return NULL; + return ERR_PTR(-EIO); vma = vma_lookup(mm, addr); if (WARN_ON_ONCE(!vma)) { diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c index cac3aef7c6f7..9cf2d4ba760e 100644 --- a/kernel/events/uprobes.c +++ b/kernel/events/uprobes.c @@ -474,7 +474,10 @@ int uprobe_write_opcode(struct arch_uprobe *auprobe, struct mm_struct *mm, gup_flags |= FOLL_SPLIT_PMD; /* Read the page with vaddr into memory */ old_page = get_user_page_vma_remote(mm, vaddr, gup_flags, &vma); - if (IS_ERR_OR_NULL(old_page)) + if (old_page == ERR_PTR(-EIO)) + return 0; + + if (IS_ERR(old_page)) return PTR_ERR(old_page); ret = verify_opcode(old_page, vaddr, &opcode); diff --git a/mm/memory.c b/mm/memory.c index 8358f3b853f2..f9a81278e76d 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -5604,7 +5604,7 @@ int __access_remote_vm(struct mm_struct *mm, unsigned long addr, void *buf, struct page *page = get_user_page_vma_remote(mm, addr, gup_flags, &vma); - if (IS_ERR_OR_NULL(page)) { + if (IS_ERR(page)) { #ifndef CONFIG_HAVE_IOREMAP_PROT break; #else