From patchwork Wed Jun 16 10:59:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Popple X-Patchwork-Id: 12324805 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F399DC49EA2 for ; Wed, 16 Jun 2021 11:01:03 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 9CA8D611CA for ; Wed, 16 Jun 2021 11:01:03 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9CA8D611CA Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=nvidia.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 413626B007B; Wed, 16 Jun 2021 07:01:03 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3E9236B007D; Wed, 16 Jun 2021 07:01:03 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2631D6B007E; Wed, 16 Jun 2021 07:01:03 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0105.hostedemail.com [216.40.44.105]) by kanga.kvack.org (Postfix) with ESMTP id E97656B007B for ; Wed, 16 Jun 2021 07:01:02 -0400 (EDT) Received: from smtpin15.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 859E210F1C for ; Wed, 16 Jun 2021 11:01:02 +0000 (UTC) X-FDA: 78259294764.15.5BAB542 Received: from NAM04-MW2-obe.outbound.protection.outlook.com (mail-mw2nam08on2049.outbound.protection.outlook.com [40.107.101.49]) by imf14.hostedemail.com (Postfix) with ESMTP id A79C9C041633 for ; Wed, 16 Jun 2021 11:00:51 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Pul9xxmGeewSwzVGtbQT4ty8W+Gcutr417HMAXOdJ2fU4kmHAJPj4y99hbwYl8XSNe79BtsIUkWQlmPKq7OAQ//eUk7Amc3DVRdrjG9rp+2CFDxYoLnxpXjZ8M08/AHMbKJmMjcYA1GDbsTCQykD/XAoZNtcGdJqVjdn4HYttjUB7mrdsPcj4rL5utBwlFIgpbLtg1evRp9NE3ziZnUel8d5YmYzuHoiQzXeLcQKZBziGXGVzTeg54PanT9Y3Cmt26knMFDtgIq+NmcXaco8arHNBUa+0MEJ34H1g0cSdBqxf/ksQRi3rRBFjBqaUua21iYkbwL6H4Je1u9EdxEpLg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=52B3lbBbwau5rfAU/qjaAQ1zvtcSq+eH8Qs77Z2GVMU=; b=XbwBDQZ9CnHZZklsYoPY3DWfvyrz9hvVxjbXtmj8C3dGYlCrIMJs4dH1h1Ho4wShiTyyXQAc2lEndjAd1xW6C388FK+t8H8YC2NGlp/U3Ofdbbq9V+I/M8eMGE/hrsyCTiBcKiLcNruOOQuXnUjkk+5f3Gl5zhPm4b2I6Fvl45DmEXkqzIN2DTP41wCa+CniHEKKKrrsu5iVsYwoROcO3AapP7irmUBxwdnaRdIOjXW1jslrUNfiQpNvT49ED924jAG/aoBjnOhxaFCd/4VIGJtiBmt5KWG+1si0Jly9wK24uJUHqYHcILLoxKYdVDjNrdYMulpwRkSKuW+aqM254w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.34) smtp.rcpttodomain=infradead.org smtp.mailfrom=nvidia.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=52B3lbBbwau5rfAU/qjaAQ1zvtcSq+eH8Qs77Z2GVMU=; b=mD+P6iw2WxA8ZK3k3q9XOlwda7OVi4NJlxX7SJnjvtR1Z0MPTWkJOllNvqv0/n7NOsmcOEZ4mvqH3Wt3pO7i1zZN2dJTl8+j2pSF4VwUqguMBczSNiMXafgjIM3ODO7Y4zGlEkV1NBxZlkZ40i/6bfmIu41T6IExh4ii/NvkHv+1ymzQwP37gXHO7+Q3LamrtL9J0mnw/5CzZjeQODiud6sYuESioTweIO8iBUKp6fcOim7HM58DwQjXWfchNw6OPyE2GbhEKLkLpLEqa4vbbWWFIT3riP3fyCSHtzVrGXi9hp/NXBm6lNOTdAkwOIk5zOqz0FvXYdh29MJZDUndrw== Received: from BN6PR19CA0077.namprd19.prod.outlook.com (2603:10b6:404:133::15) by MWHPR1201MB0205.namprd12.prod.outlook.com (2603:10b6:301:4e::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4219.22; Wed, 16 Jun 2021 11:00:59 +0000 Received: from BN8NAM11FT048.eop-nam11.prod.protection.outlook.com (2603:10b6:404:133:cafe::eb) by BN6PR19CA0077.outlook.office365.com (2603:10b6:404:133::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4242.16 via Frontend Transport; Wed, 16 Jun 2021 11:00:59 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.34) smtp.mailfrom=nvidia.com; infradead.org; dkim=none (message not signed) header.d=none;infradead.org; dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.112.34 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.112.34; helo=mail.nvidia.com; Received: from mail.nvidia.com (216.228.112.34) by BN8NAM11FT048.mail.protection.outlook.com (10.13.177.117) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4242.16 via Frontend Transport; Wed, 16 Jun 2021 11:00:59 +0000 Received: from localhost (172.20.187.6) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 16 Jun 2021 11:00:57 +0000 From: Alistair Popple To: CC: , , , , , , , , , , , , , , Alistair Popple Subject: [PATCH v11 06/10] mm/memory.c: Allow different return codes for copy_nonpresent_pte() Date: Wed, 16 Jun 2021 20:59:33 +1000 Message-ID: <20210616105937.23201-7-apopple@nvidia.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210616105937.23201-1-apopple@nvidia.com> References: <20210616105937.23201-1-apopple@nvidia.com> MIME-Version: 1.0 X-Originating-IP: [172.20.187.6] X-ClientProxiedBy: HQMAIL111.nvidia.com (172.20.187.18) To HQMAIL107.nvidia.com (172.20.187.13) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 94b01e04-167d-4e4c-7a6d-08d930b60622 X-MS-TrafficTypeDiagnostic: MWHPR1201MB0205: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7219; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: M02lkGw33resWblEhD10QXzG+LiFrQ23a9PR4s/Hxynz6KjHTpnWSbrFC+QPwH5Z4gND5y4YL9oLwKsbXavnLTa10aD9n5At4AWq8W1wS6sApynJ2PWl5TfeCTeHUZ6ArfiyjCsXxz8LF3lXtEAkhkaJjeBkJjREYXgOCYMJoz04/k+RjRxFwsNL5TdlS6purxGAMK9Lt65JS6D5I3DepGceZV+t1E2vtyuzVzFzYcrFdwx1zvIsiVpKLmBWr/j1vHAGmWJ8k+mo2VMBUUv9IvayqWm5z+Yi/++vYQRY46xpWTlYdlN8iXw7CCLKS+RubNV7HCC71BiS+OumgMXD54mx16VvmWrQS9JjN05JzE8GPVViiYcibhpSTP+hwCYPWZxqcgIwbbE9QOcfQ6SyS4ehbY+15GQhBQxeA0B9AD7HHtOLDRmXxGom1YPgEwRiZ1JnsXNoX0GAEYDIpuAPNDc4D/PBOfPtbplHl3K20n2J2IwTyPeez7ZFh9Dftv/ANocrDUEYZ+H6ohntynaRTJEHhyx6sOkzTbZxk1q8xs6AVIi1H0U3VSymo705ekbnSzaKI8VTUVIhOUaQe+Mxay/JIYF4WY3wEs+Ku/uWAqnPoEdEZn0dzJofmW9wnuI1EvfuSckOQNs4HcKAa7JFHAdLvJrqbu3i1NZmwSEQWNk= X-Forefront-Antispam-Report: CIP:216.228.112.34;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:schybrid03.nvidia.com;CAT:NONE;SFS:(4636009)(396003)(39860400002)(376002)(136003)(346002)(46966006)(36840700001)(47076005)(356005)(8936002)(86362001)(36756003)(7636003)(36860700001)(82310400003)(336012)(70586007)(83380400001)(70206006)(4326008)(8676002)(426003)(2616005)(107886003)(478600001)(6916009)(7416002)(54906003)(26005)(5660300002)(36906005)(16526019)(316002)(186003)(1076003)(2906002)(6666004)(82740400003);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Jun 2021 11:00:59.2950 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 94b01e04-167d-4e4c-7a6d-08d930b60622 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.112.34];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT048.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR1201MB0205 X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: A79C9C041633 Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=mD+P6iw2; spf=none (imf14.hostedemail.com: domain of apopple@nvidia.com has no SPF policy when checking 40.107.101.49) smtp.mailfrom=apopple@nvidia.com; dmarc=pass (policy=none) header.from=nvidia.com X-Stat-Signature: pjnp7hpdp5q49n55x4d7qpwpi5mehqhk X-HE-Tag: 1623841251-512113 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Currently if copy_nonpresent_pte() returns a non-zero value it is assumed to be a swap entry which requires further processing outside the loop in copy_pte_range() after dropping locks. This prevents other values being returned to signal conditions such as failure which a subsequent change requires. Instead make copy_nonpresent_pte() return an error code if further processing is required and read the value for the swap entry in the main loop under the ptl. Signed-off-by: Alistair Popple Reviewed-by: Peter Xu --- v11: Rebase on mmots v10: Use a unique error code and only check return codes for handling. v9: New for v9 to allow device exclusive handling to occur in copy_nonpresent_pte(). --- mm/memory.c | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/mm/memory.c b/mm/memory.c index b4588402b777..1ac4d0b07c99 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -717,7 +717,7 @@ copy_nonpresent_pte(struct mm_struct *dst_mm, struct mm_struct *src_mm, if (likely(!non_swap_entry(entry))) { if (swap_duplicate(entry) < 0) - return entry.val; + return -EIO; /* make sure dst_mm is on swapoff's mmlist. */ if (unlikely(list_empty(&dst_mm->mmlist))) { @@ -973,12 +973,14 @@ copy_pte_range(struct vm_area_struct *dst_vma, struct vm_area_struct *src_vma, continue; } if (unlikely(!pte_present(*src_pte))) { - entry.val = copy_nonpresent_pte(dst_mm, src_mm, - dst_pte, src_pte, - dst_vma, src_vma, - addr, rss); - if (entry.val) + ret = copy_nonpresent_pte(dst_mm, src_mm, + dst_pte, src_pte, + dst_vma, src_vma, + addr, rss); + if (ret == -EIO) { + entry = pte_to_swp_entry(*src_pte); break; + } progress += 8; continue; } @@ -1011,20 +1013,24 @@ copy_pte_range(struct vm_area_struct *dst_vma, struct vm_area_struct *src_vma, pte_unmap_unlock(orig_dst_pte, dst_ptl); cond_resched(); - if (entry.val) { + if (ret == -EIO) { + VM_WARN_ON_ONCE(!entry.val); if (add_swap_count_continuation(entry, GFP_KERNEL) < 0) { ret = -ENOMEM; goto out; } entry.val = 0; - } else if (ret) { - WARN_ON_ONCE(ret != -EAGAIN); + } else if (ret == -EAGAIN) { prealloc = page_copy_prealloc(src_mm, src_vma, addr); if (!prealloc) return -ENOMEM; - /* We've captured and resolved the error. Reset, try again. */ - ret = 0; + } else if (ret) { + VM_WARN_ON_ONCE(1); } + + /* We've captured and resolved the error. Reset, try again. */ + ret = 0; + if (addr != end) goto again; out: