Received: by 2002:ac0:b08d:0:0:0:0:0 with SMTP id l13csp4790963imc; Mon, 25 Feb 2019 11:05:02 -0800 (PST) X-Google-Smtp-Source: AHgI3IbNRFm8w5z2oPH8ZZ8oh5DZS3pwUX4tjv42rtMAfuHaHzyHPRhrkNpicSWeTXDyQtTSiN9R X-Received: by 2002:a62:55c4:: with SMTP id j187mr21611255pfb.129.1551121502765; Mon, 25 Feb 2019 11:05:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551121502; cv=none; d=google.com; s=arc-20160816; b=jeGKvtkC1WUUzn6X+12jPDUYlaIQiOEppgPEy5VGXwjvzJhfx0mKBQv8ONhMOwen0Q i1mNUSwGncj13uUu6aT33RU7fdzRU1huVN/qp5RiplOYHGYl7Mi1zbrGxbXKP628HM9U /l3isESjBeRxjgLKFMicp0xLwSXhHLMdIbiAOih0Vr8MhgaBlLsPuCXDTVmY0q1hCfzv bmMVDCnElHl+JJuhe/FyJbcVItg15GPczC/5Jk9RcxDAEIXR3GmJ8JEFFz5+6I1bADvF KI45LcGh8houPXbGQwujblmKntA9kr2QGLtHLBDgqmcyYeLfQWZ9VhYtcQG+ADP0gfAE /jIQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:in-reply-to:references:date :from:cc:to:subject; bh=ddSVWhx5TfNJ/WvyKgYL4bUsHx/Z5PTEAP9KHJe7W9s=; b=zK9VVIq4WGS4vebSvuu/D1vmtweA6Xf53+Xt34uWXuN/OkbWnvSd98CKAgLty+hRhW Eh408f8UZdVYpwFaa9NZagwc2MDbHnNoDexHRYOeNcD2TVabkZmtf5KtgMQAImuyx78u JNO/IqcYy0AgDAUBH0XM/kqmOw3LR6POLFtYvoXl+fi5ywU7D5wilAyeon6wz50Akghy NzhLgG2XvfqHM+hYYYp/zMIfZRZ4QLrfRzsl6O//BQ71oPkhqsx00BPnqnRAXbZIeLsh r3k276G2qq27TbGKHzadBXNfepulNotviwbRwp8MUxVirTol7X1Qyg3osN1zoV2GivGz 9Lsw== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d72si10422648pfm.284.2019.02.25.11.04.47; Mon, 25 Feb 2019 11:05:02 -0800 (PST) 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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726885AbfBYTCl (ORCPT + 99 others); Mon, 25 Feb 2019 14:02:41 -0500 Received: from mga04.intel.com ([192.55.52.120]:21387 "EHLO mga04.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726625AbfBYTCg (ORCPT ); Mon, 25 Feb 2019 14:02:36 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 25 Feb 2019 11:02:35 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.58,412,1544515200"; d="scan'208";a="149861256" Received: from viggo.jf.intel.com (HELO localhost.localdomain) ([10.54.77.144]) by fmsmga001.fm.intel.com with ESMTP; 25 Feb 2019 11:02:34 -0800 Subject: [PATCH 1/5] mm/resource: return real error codes from walk failures To: linux-kernel@vger.kernel.org Cc: Dave Hansen , bhelgaas@google.com, mpe@ellerman.id.au, dan.j.williams@intel.com, dave.jiang@intel.com, zwisler@kernel.org, vishal.l.verma@intel.com, thomas.lendacky@amd.com, akpm@linux-foundation.org, mhocko@suse.com, linux-nvdimm@lists.01.org, linux-mm@kvack.org, ying.huang@intel.com, fengguang.wu@intel.com, bp@suse.de, baiyaowei@cmss.chinamobile.com, tiwai@suse.de, jglisse@redhat.com, benh@kernel.crashing.org, paulus@samba.org, linuxppc-dev@lists.ozlabs.org, keith.busch@intel.com From: Dave Hansen Date: Mon, 25 Feb 2019 10:57:30 -0800 References: <20190225185727.BCBD768C@viggo.jf.intel.com> In-Reply-To: <20190225185727.BCBD768C@viggo.jf.intel.com> Message-Id: <20190225185730.D8AA7812@viggo.jf.intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Dave Hansen walk_system_ram_range() can return an error code either becuase *it* failed, or because the 'func' that it calls returned an error. The memory hotplug does the following: ret = walk_system_ram_range(..., func); if (ret) return ret; and 'ret' makes it out to userspace, eventually. The problem s, walk_system_ram_range() failues that result from *it* failing (as opposed to 'func') return -1. That leads to a very odd -EPERM (-1) return code out to userspace. Make walk_system_ram_range() return -EINVAL for internal failures to keep userspace less confused. This return code is compatible with all the callers that I audited. This changes both the generic mm/ and powerpc-specific implementations to have the same return value. Signed-off-by: Dave Hansen Reviewed-by: Bjorn Helgaas Acked-by: Michael Ellerman (powerpc) Cc: Dan Williams Cc: Dave Jiang Cc: Ross Zwisler Cc: Vishal Verma Cc: Tom Lendacky Cc: Andrew Morton Cc: Michal Hocko Cc: linux-nvdimm@lists.01.org Cc: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org Cc: Huang Ying Cc: Fengguang Wu Cc: Borislav Petkov Cc: Yaowei Bai Cc: Takashi Iwai Cc: Jerome Glisse Cc: Benjamin Herrenschmidt Cc: Paul Mackerras Cc: linuxppc-dev@lists.ozlabs.org Cc: Keith Busch --- b/arch/powerpc/mm/mem.c | 2 +- b/kernel/resource.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff -puN arch/powerpc/mm/mem.c~memory-hotplug-walk_system_ram_range-returns-neg-1 arch/powerpc/mm/mem.c --- a/arch/powerpc/mm/mem.c~memory-hotplug-walk_system_ram_range-returns-neg-1 2019-02-25 10:56:47.452908034 -0800 +++ b/arch/powerpc/mm/mem.c 2019-02-25 10:56:47.458908034 -0800 @@ -189,7 +189,7 @@ walk_system_ram_range(unsigned long star struct memblock_region *reg; unsigned long end_pfn = start_pfn + nr_pages; unsigned long tstart, tend; - int ret = -1; + int ret = -EINVAL; for_each_memblock(memory, reg) { tstart = max(start_pfn, memblock_region_memory_base_pfn(reg)); diff -puN kernel/resource.c~memory-hotplug-walk_system_ram_range-returns-neg-1 kernel/resource.c --- a/kernel/resource.c~memory-hotplug-walk_system_ram_range-returns-neg-1 2019-02-25 10:56:47.454908034 -0800 +++ b/kernel/resource.c 2019-02-25 10:56:47.459908034 -0800 @@ -382,7 +382,7 @@ static int __walk_iomem_res_desc(resourc int (*func)(struct resource *, void *)) { struct resource res; - int ret = -1; + int ret = -EINVAL; while (start < end && !find_next_iomem_res(start, end, flags, desc, first_lvl, &res)) { @@ -462,7 +462,7 @@ int walk_system_ram_range(unsigned long unsigned long flags; struct resource res; unsigned long pfn, end_pfn; - int ret = -1; + int ret = -EINVAL; start = (u64) start_pfn << PAGE_SHIFT; end = ((u64)(start_pfn + nr_pages) << PAGE_SHIFT) - 1; _