Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp1416686ybl; Thu, 22 Aug 2019 14:17:19 -0700 (PDT) X-Google-Smtp-Source: APXvYqww0IyIsCrQbHMJd+kNgX+WeQW93TdQsej2Tx3DkQuQy4sfHrt4hq4YzFT61aotB54Cpl0G X-Received: by 2002:a63:3805:: with SMTP id f5mr1052593pga.272.1566508639031; Thu, 22 Aug 2019 14:17:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566508639; cv=none; d=google.com; s=arc-20160816; b=rzSviS7qEx1sZ7AQE/26P64v8pKYQJPYHXAKgxxzy0MKmDdp/W7pvc6VsyC2vX6FcE t5ouA1YPL7FSBNHa47ztv9CaHBaGcDwLb3jXnhk/hrnJv+jv3urrt0j1wwaRZQDaZ3Oe m0XA/UIvbJC1Q55/UHWd2yxfwc5Ktolf8EEdgmSFvcBd1vz7Aa0njcxKsHKQ943K2Za+ wKiONhCafcTxhdijOKThYlMK5f70HC4zUr+r/FBBa+Suc9WTqYkPJhea5q+xXsDt4GEW /OGQn+SNqMjW8zpCfb9Rx/L/yZoIL4kyI47P+dM5gGzI5rh8asWrYA8455oElYZuT8xK xSWQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=iDYJ7U3nkVgsQNyTJOd+SzW5VeEmpFyQjCRy1sAmQDA=; b=WKg7FlXMyqETe0ob6jTVKGbV5ge0iTiLPQYJ0iOU3apGv/MN0kxk9Mvth6zT8jmQsF 9kJ5Ee9NbPiSjftcWNurqNsZXh9Oyym6hHVCasr39ZONgP+Iw7hMlFV0jYeZrpVsqO+c 5dPNQJzv26qVQLbZdxOko0DbGPKNArSvM4XGQOclVSOrZNPG3taQ2wfuBr53fmD/o10/ R3Jhm3TA/x4LNgOEpvxF7WR2YrQoxsYdFEUcNEl7iw4XibjJKP7T3DWw4VwkBntr5dOn eIVrNIQPUD7fL9MuSqbuawtsfkkDGuurnxMaDelZcaARqmSm2AzzpQK2YUGL1lo+9+q9 OIMw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=BEsnQIa0; 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=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t14si539851ply.347.2019.08.22.14.17.04; Thu, 22 Aug 2019 14:17:19 -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=@kernel.org header.s=default header.b=BEsnQIa0; 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=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390442AbfHVRIk (ORCPT + 99 others); Thu, 22 Aug 2019 13:08:40 -0400 Received: from mail.kernel.org ([198.145.29.99]:58282 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390392AbfHVRIj (ORCPT ); Thu, 22 Aug 2019 13:08:39 -0400 Received: from sasha-vm.mshome.net (wsip-184-188-36-2.sd.sd.cox.net [184.188.36.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 1EA93233FC; Thu, 22 Aug 2019 17:08:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1566493718; bh=TN/yZ7FjGl5BN0jJpt8bZnFuEvxtK5gvDFA4qWawSi8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BEsnQIa0AAkpNFGTEJE3KmfPSm2xpadpaigdeukAyXv4qp/V2nzrG9VaiWtIrsqYE +PVEFQYItfD88k2FNnXEAgbeMUMoML/OtEnkR6UGpgSrDvKafc/vUdngSZa5bE07WT F6vhOc7a7PWQtXf1KHdKeU4i3h6YAO0/Zb8hSQI0= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Christoph Hellwig , Ralph Campbell , Jason Gunthorpe , Felix Kuehling , Sasha Levin Subject: [PATCH 5.2 045/135] mm/hmm: always return EBUSY for invalid ranges in hmm_range_{fault,snapshot} Date: Thu, 22 Aug 2019 13:06:41 -0400 Message-Id: <20190822170811.13303-46-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190822170811.13303-1-sashal@kernel.org> References: <20190822170811.13303-1-sashal@kernel.org> MIME-Version: 1.0 X-KernelTest-Patch: http://kernel.org/pub/linux/kernel/v5.x/stable-review/patch-5.2.10-rc1.gz X-KernelTest-Tree: git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.git X-KernelTest-Branch: linux-5.2.y X-KernelTest-Patches: git://git.kernel.org/pub/scm/linux/kernel/git/stable/stable-queue.git X-KernelTest-Version: 5.2.10-rc1 X-KernelTest-Deadline: 2019-08-24T17:07+00:00 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Christoph Hellwig [ Upstream commit 2bcbeaefde2f0384d6ad351c151b1a9fe7791a0a ] We should not have two different error codes for the same condition. EAGAIN must be reserved for the FAULT_FLAG_ALLOW_RETRY retry case and signals to the caller that the mmap_sem has been unlocked. Use EBUSY for the !valid case so that callers can get the locking right. Link: https://lore.kernel.org/r/20190724065258.16603-2-hch@lst.de Tested-by: Ralph Campbell Signed-off-by: Christoph Hellwig Reviewed-by: Ralph Campbell Reviewed-by: Jason Gunthorpe Reviewed-by: Felix Kuehling [jgg: elaborated commit message] Signed-off-by: Jason Gunthorpe Signed-off-by: Sasha Levin --- Documentation/vm/hmm.rst | 2 +- mm/hmm.c | 10 ++++------ 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/Documentation/vm/hmm.rst b/Documentation/vm/hmm.rst index 7cdf7282e0229..65b6c1109cc81 100644 --- a/Documentation/vm/hmm.rst +++ b/Documentation/vm/hmm.rst @@ -231,7 +231,7 @@ respect in order to keep things properly synchronized. The usage pattern is:: ret = hmm_range_snapshot(&range); if (ret) { up_read(&mm->mmap_sem); - if (ret == -EAGAIN) { + if (ret == -EBUSY) { /* * No need to check hmm_range_wait_until_valid() return value * on retry we will get proper error with hmm_range_snapshot() diff --git a/mm/hmm.c b/mm/hmm.c index 4c405dfbd2b3d..27dd9a8816272 100644 --- a/mm/hmm.c +++ b/mm/hmm.c @@ -995,7 +995,7 @@ EXPORT_SYMBOL(hmm_range_unregister); * @range: range * Returns: -EINVAL if invalid argument, -ENOMEM out of memory, -EPERM invalid * permission (for instance asking for write and range is read only), - * -EAGAIN if you need to retry, -EFAULT invalid (ie either no valid + * -EBUSY if you need to retry, -EFAULT invalid (ie either no valid * vma or it is illegal to access that range), number of valid pages * in range->pfns[] (from range start address). * @@ -1019,7 +1019,7 @@ long hmm_range_snapshot(struct hmm_range *range) do { /* If range is no longer valid force retry. */ if (!range->valid) - return -EAGAIN; + return -EBUSY; vma = find_vma(hmm->mm, start); if (vma == NULL || (vma->vm_flags & device_vma)) @@ -1117,10 +1117,8 @@ long hmm_range_fault(struct hmm_range *range, bool block) do { /* If range is no longer valid force retry. */ - if (!range->valid) { - up_read(&hmm->mm->mmap_sem); - return -EAGAIN; - } + if (!range->valid) + return -EBUSY; vma = find_vma(hmm->mm, start); if (vma == NULL || (vma->vm_flags & device_vma)) -- 2.20.1