Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2567022imu; Thu, 24 Jan 2019 15:24:35 -0800 (PST) X-Google-Smtp-Source: ALg8bN4SkXimcD/b3pD1vR3OCrA5gbgep+MOcwQH1mUOFvfhQKVtq5CmT7dG38XnzmJ5Osw4tBhp X-Received: by 2002:a63:5621:: with SMTP id k33mr7842158pgb.395.1548372275047; Thu, 24 Jan 2019 15:24:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548372275; cv=none; d=google.com; s=arc-20160816; b=MnQM2z2KjJsl/wlEkECruaEMOI24FQPxf3j706OCDxEEdvlj1cvQY+wCwygGHahyEa TuM5FJbRPe6cOipSBUnUi35oOVp/r5Ghguya6Ce4Spd5WGwcMogCioC7D5ZP9jYkZm2E UgpnzqfUxTxi0Dk4J2joUULPZy5BWJXIugbbva7i3RMOfQqTyUkiDSH13sB4Q+ClEyon 8nRYR1p/4MqEeUDUimSeMJUYey6jZM/k5BBVho6/F1ZAvhsdmPyaLtzY357MUfDjF0A+ ZMOIoRG/7svh+LgN2/Wggo7Q3B/3wtDEEW4IHh4ImD1jYiM4bvOs0LXjayunzgpBdP79 IOTw== 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=G4UBwBK1ygZOCj9EDaFANslJEVjpXrkdAT+76ni7PnA=; b=LrtEW+KDdDOBOwL4CyQIM1woRLRE+F0cBmfJyEKGlgYO+GRbn3YX7pvF01cCgyfyLB ke6ON4eVETXgTK4NgXVaXJM52yB0ZORRITelngLC/caNoZ9jkP08pfcsuGfTyENMSkbA 5lLI+o/h9Z8e4GblTd4dBICceiKObL0TLLUXdjAiJN2T+LbTkSKSJMmvW6trSapQVG1g V5/SQNuShWgMycLQqP4C5+Vh0Q+74LgGyRmw2ffEeVrDKkyDXFI/DFVZAWIWZVVCXTBE HiuJhALVzMaaEHDsi3v/jZaA+69PkW7lLh3v7ldr7X2ibh2ySmSIAsTxAvBSsNu6NkNF Ax0A== 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 73si4855919pfm.50.2019.01.24.15.24.19; Thu, 24 Jan 2019 15:24:35 -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 S1727771AbfAXXVz (ORCPT + 99 others); Thu, 24 Jan 2019 18:21:55 -0500 Received: from mga05.intel.com ([192.55.52.43]:15138 "EHLO mga05.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725991AbfAXXVx (ORCPT ); Thu, 24 Jan 2019 18:21:53 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 24 Jan 2019 15:21:52 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,518,1539673200"; d="scan'208";a="121111369" Received: from viggo.jf.intel.com (HELO localhost.localdomain) ([10.54.77.144]) by orsmga003.jf.intel.com with ESMTP; 24 Jan 2019 15:21:52 -0800 Subject: [PATCH 1/5] mm/resource: return real error codes from walk failures To: linux-kernel@vger.kernel.org Cc: Dave Hansen , 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, bhelgaas@google.com, baiyaowei@cmss.chinamobile.com, tiwai@suse.de, jglisse@redhat.com From: Dave Hansen Date: Thu, 24 Jan 2019 15:14:42 -0800 References: <20190124231441.37A4A305@viggo.jf.intel.com> In-Reply-To: <20190124231441.37A4A305@viggo.jf.intel.com> Message-Id: <20190124231442.EFD29EE0@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 is, 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. Signed-off-by: Dave Hansen 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: Bjorn Helgaas Cc: Yaowei Bai Cc: Takashi Iwai Cc: Jerome Glisse --- b/kernel/resource.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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-01-24 15:13:13.950199540 -0800 +++ b/kernel/resource.c 2019-01-24 15:13:13.954199540 -0800 @@ -375,7 +375,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)) { @@ -453,7 +453,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; _