From patchwork Wed Jul 27 00:08:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ralph Campbell X-Patchwork-Id: 12929935 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 71B09C00144 for ; Wed, 27 Jul 2022 00:08:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 36FB56B0071; Tue, 26 Jul 2022 20:08:50 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 345E1940007; Tue, 26 Jul 2022 20:08:50 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1BF716B0073; Tue, 26 Jul 2022 20:08:50 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 04F426B0071 for ; Tue, 26 Jul 2022 20:08:50 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id DB40DC01BC for ; Wed, 27 Jul 2022 00:08:49 +0000 (UTC) X-FDA: 79730943978.10.2475164 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2079.outbound.protection.outlook.com [40.107.237.79]) by imf07.hostedemail.com (Postfix) with ESMTP id 65DA940087 for ; Wed, 27 Jul 2022 00:08:49 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=iCjIa42huulyhT6q+hJlg4VIelmc86Rq80El65/TsKS31pnNvK/3z1lmzyo3RfylxJ70q3nYkqF1Rggda6q56U9EMyah44QJUrkshYHgUFBIwuTqTo6fZiRNYYpmN43OjT4fBuRAPy4jiAMcXr+5I+jTGYWgG/qod5VGJTMa0gPB0Ss4EjhxdimgGUJS8QPWxJMJRdWOm29oFVUYkvAqU8Z9Xwt0Ql9xUveqQMPHw/1TaDwOEba9S66Cp0ToP708XFhnK8E6HtgFOXM8Sn2of862f4pncahtSnJlXm99A7gKJknD5SXkZduNfaKZn/aprEy1bzPuk6YKzI1SsL63VQ== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=RYfiUhNngmyYnKzZVuTZZbJMpXLp7p37StKkfp0cyCU=; b=bXlYaJhj0DJ2rAM3ib5vg+fQqOS93ZNbvhHpINEB9SB8oLaJu6yJgU05eh5pTnBlxgZw8p24EeEoEX6LBgl+Qea1XEKsVAmQKNL9cdjEfYihTHODEnJX6WxUZa9B4XRDkYEagpnEKSLwXxVmwKA6o6EFokHnBkfmCoiANzpnBQWwd6pVlWr0eS9sh05ApnVGGBIN7xtMFyvFOJy+gcPHfr2DAjwvvWkJvAZZUW+1pACijy+8hWk8hOR68dHZvn84xYECpi/pKWYTWe288Dqh3gLIcwG6RBE3N/FtQJgH3e6Qsi1ePaEHH6FzZJb4e7+v5lb692+Pn0s/k5Z1tLmD7A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 12.22.5.238) smtp.rcpttodomain=linux-foundation.org smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject 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=RYfiUhNngmyYnKzZVuTZZbJMpXLp7p37StKkfp0cyCU=; b=eFI2mNzgioDP7rM+QZ59YO+vBVOvux4rcsO/h4X3WlW0OFega1FNUcWSKpxW86LihpCOSa4a9x5Y7UpAWvkWMfUwetlINzr04LaJLuxX6hXMcIGZU2fuCgWQsIzvQ38Cpz3dgqqrS7Df+3pK7PsqYk5r347VOtBocGrHlBtuqu5+t6ZGRXHE2Ug5+CHO55WUmrhK0RnwwnBcDZC6GFwGV9eT2IFbk3v9cn/7FZkFsgnTRTTznd1wxEntJkwD45F1jVCDigzyywf5H/aSOgER1A3OZKT5isXsRi468+CY/2IOjOeDZ1n2GE/Rkizk983i5XPMcgbDJtmd2XkOzsIWhg== Received: from BN1PR10CA0015.namprd10.prod.outlook.com (2603:10b6:408:e0::20) by BYAPR12MB3479.namprd12.prod.outlook.com (2603:10b6:a03:dc::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5458.24; Wed, 27 Jul 2022 00:08:46 +0000 Received: from BN8NAM11FT047.eop-nam11.prod.protection.outlook.com (2603:10b6:408:e0:cafe::6) by BN1PR10CA0015.outlook.office365.com (2603:10b6:408:e0::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5482.7 via Frontend Transport; Wed, 27 Jul 2022 00:08:46 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 12.22.5.238) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 12.22.5.238 as permitted sender) receiver=protection.outlook.com; client-ip=12.22.5.238; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (12.22.5.238) by BN8NAM11FT047.mail.protection.outlook.com (10.13.177.220) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.5482.10 via Frontend Transport; Wed, 27 Jul 2022 00:08:46 +0000 Received: from drhqmail203.nvidia.com (10.126.190.182) by DRHQMAIL105.nvidia.com (10.27.9.14) with Microsoft SMTP Server (TLS) id 15.0.1497.32; Wed, 27 Jul 2022 00:08:45 +0000 Received: from drhqmail202.nvidia.com (10.126.190.181) by drhqmail203.nvidia.com (10.126.190.182) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.26; Tue, 26 Jul 2022 17:08:45 -0700 Received: from rcampbell-dev.nvidia.com (10.127.8.9) by mail.nvidia.com (10.126.190.181) with Microsoft SMTP Server id 15.2.986.26 via Frontend Transport; Tue, 26 Jul 2022 17:08:45 -0700 From: Ralph Campbell To: CC: Felix Kuehling , Philip Yang , Alistair Popple , John Hubbard , Jason Gunthorpe , Andrew Morton , Ralph Campbell , Subject: [PATCH v3 1/2] mm/hmm: fault non-owner device private entries Date: Tue, 26 Jul 2022 17:08:36 -0700 Message-ID: <20220727000837.4128709-2-rcampbell@nvidia.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220727000837.4128709-1-rcampbell@nvidia.com> References: <20220727000837.4128709-1-rcampbell@nvidia.com> MIME-Version: 1.0 X-NVConfidentiality: public X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 04ca704c-acfc-4210-4eb2-08da6f642ca2 X-MS-TrafficTypeDiagnostic: BYAPR12MB3479:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: cpDIYDI9vRuU91KjE233rZEFjuRbNkAKa+Ja0oyosrRKDin6jUj3KB1IhlZ5wP2IAF74f7kw6WKo7eTovvpl+5Xvbs8ojgAlS88S//t22YDZaCfODvW3u/9fH9B466g8szTpIfcGuP5xEZPHJwp/xNdJFlfGuZd7YfwKyerebfwDnLq64aAlrrUiMCFAAjZo7s2+Q8BX9dXjJ6lN2oNo2JHnBbkqXCnfq4ml3EELn/LBVVo60rRDpEXq613fvf/T+GJPje708eJ7bQqjMmJaS+95mn+dP9KPBLNbTwTD28TxfgyG6aJb2IShxigjmxzQxXG0G+bi7KgPivjtnXEqf16iaE4uXWI6l3TEmxDFrcbIpRS6J54AE41D3WAfNcJq7Xve0yNrEOTCOxxSpiIbEuvrzv1xQB8cfXUQ91f8m7SbeslbwP6K5m0gAh9ZqQ/Q5TrWIUo/okdT/vQLwVJVDKGXAAhZYDTOjcXdoUhU6WYEmNw+xDWmbt0q2TD20k6cF0P062gwEmVDxp0TqCaP/Bv1peca9VR5noc0Cec1D68G2kiSSFwFkQdiWqPQbudefYr+nevH6F3imTgkboaPlbSncvnGayfWX6D7TyKtt0HGd2s4YHOeBJs0KziTc04g5PbjEwt2tYG1z0FVlynay3DWTqdc/bBPWnaIRqhCT7dYGbtdCv8z1fsBZG05zOXFZSTtEB6ChfZlUNPODO4y19+m+xEVreSnsrGCgzYCBGJr3a+ymzDAaoBW52nawOCLHx1l2Ys0xIMj2eBdp4zaWysZ4lxXGWglGRVvUHbxUsqjDAc4E8tt+0cPlmAdSB2zmEgSfVw1XinRWSz5C7rDRQ== X-Forefront-Antispam-Report: CIP:12.22.5.238;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:InfoNoRecords;CAT:NONE;SFS:(13230016)(4636009)(376002)(346002)(39860400002)(396003)(136003)(36840700001)(46966006)(40470700004)(8676002)(82740400003)(40480700001)(70206006)(1076003)(36860700001)(81166007)(186003)(4326008)(70586007)(316002)(356005)(54906003)(6916009)(7696005)(2906002)(36756003)(86362001)(8936002)(41300700001)(6666004)(82310400005)(40460700003)(26005)(478600001)(2616005)(5660300002)(83380400001)(47076005)(336012)(426003)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Jul 2022 00:08:46.1031 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 04ca704c-acfc-4210-4eb2-08da6f642ca2 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[12.22.5.238];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT047.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR12MB3479 ARC-Authentication-Results: i=2; imf07.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=eFI2mNzg; spf=pass (imf07.hostedemail.com: domain of rcampbell@nvidia.com designates 40.107.237.79 as permitted sender) smtp.mailfrom=rcampbell@nvidia.com; dmarc=pass (policy=reject) header.from=nvidia.com; arc=pass ("microsoft.com:s=arcselector9901:i=1") ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1658880529; a=rsa-sha256; cv=pass; b=g7tSNmtRB/xprK/eHs3ZJPVkrvYS4iSlKSpkBF9Ss+69RI+b8LH8THqqtQVxYI3iBqt0hm smmlr4LR5zsCI6icWdOItmyXD5e6G2YLPePUemWxf9jaxqq3GyBdUv3p1/FUHskqX10LMR 8igaJS1XMp2AJ5+FgR6LTdx1WnifrOM= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1658880529; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=RYfiUhNngmyYnKzZVuTZZbJMpXLp7p37StKkfp0cyCU=; b=f+wjpezKo3Inp0Y88NHDtdncu1l6aydJu5NUq04MugGCqqUavEeuC66zn1a+LlAUJEwk1q rqcnibQVbw8ZFgTo2nzAJxj8P4HIaFlh2BtfPuNIuzSGPjshGbCU7UlwnPbrlIdPv8YMMg zFvtVyDohiN8DuVwcPAWH4jFpCD01+0= X-Stat-Signature: jjgmfxywfskin4pctbdfryrgwnmpbg8t X-Rspamd-Queue-Id: 65DA940087 X-Rspam-User: Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=eFI2mNzg; spf=pass (imf07.hostedemail.com: domain of rcampbell@nvidia.com designates 40.107.237.79 as permitted sender) smtp.mailfrom=rcampbell@nvidia.com; dmarc=pass (policy=reject) header.from=nvidia.com; arc=pass ("microsoft.com:s=arcselector9901:i=1") X-Rspamd-Server: rspam12 X-HE-Tag: 1658880529-578471 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: If hmm_range_fault() is called with the HMM_PFN_REQ_FAULT flag and a device private PTE is found, the hmm_range::dev_private_owner page is used to determine if the device private page should not be faulted in. However, if the device private page is not owned by the caller, hmm_range_fault() returns an error instead of calling migrate_to_ram() to fault in the page. For example, if a page is migrated to GPU private memory and a RDMA fault capable NIC tries to read the migrated page, without this patch it will get an error. With this patch, the page will be migrated back to system memory and the NIC will be able to read the data. Cc: stable@vger.kernel.org Fixes: 08ddddda667b ("mm/hmm: check the device private page owner in hmm_range_fault()") Signed-off-by: Ralph Campbell Reported-by: Felix Kuehling Reviewed-by: Alistair Popple Cc: Philip Yang Cc: Alistair Popple Cc: Jason Gunthorpe Cc: Signed-off-by: Andrew Morton --- mm/hmm.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/mm/hmm.c b/mm/hmm.c index 3fd3242c5e50..f2aa63b94d9b 100644 --- a/mm/hmm.c +++ b/mm/hmm.c @@ -212,14 +212,6 @@ int hmm_vma_handle_pmd(struct mm_walk *walk, unsigned long addr, unsigned long end, unsigned long hmm_pfns[], pmd_t pmd); #endif /* CONFIG_TRANSPARENT_HUGEPAGE */ -static inline bool hmm_is_device_private_entry(struct hmm_range *range, - swp_entry_t entry) -{ - return is_device_private_entry(entry) && - pfn_swap_entry_to_page(entry)->pgmap->owner == - range->dev_private_owner; -} - static inline unsigned long pte_to_hmm_pfn_flags(struct hmm_range *range, pte_t pte) { @@ -252,10 +244,12 @@ static int hmm_vma_handle_pte(struct mm_walk *walk, unsigned long addr, swp_entry_t entry = pte_to_swp_entry(pte); /* - * Never fault in device private pages, but just report - * the PFN even if not present. + * Don't fault in device private pages owned by the caller, + * just report the PFN. */ - if (hmm_is_device_private_entry(range, entry)) { + if (is_device_private_entry(entry) && + pfn_swap_entry_to_page(entry)->pgmap->owner == + range->dev_private_owner) { cpu_flags = HMM_PFN_VALID; if (is_writable_device_private_entry(entry)) cpu_flags |= HMM_PFN_WRITE; @@ -273,6 +267,9 @@ static int hmm_vma_handle_pte(struct mm_walk *walk, unsigned long addr, if (!non_swap_entry(entry)) goto fault; + if (is_device_private_entry(entry)) + goto fault; + if (is_device_exclusive_entry(entry)) goto fault; From patchwork Wed Jul 27 00:08:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ralph Campbell X-Patchwork-Id: 12929934 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 D1618C19F28 for ; Wed, 27 Jul 2022 00:08:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4CD4D900002; Tue, 26 Jul 2022 20:08:49 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 47C9C6B0072; Tue, 26 Jul 2022 20:08:49 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2F6CC900003; Tue, 26 Jul 2022 20:08:49 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 19E0B900002 for ; Tue, 26 Jul 2022 20:08:49 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id B3BA1AB04C for ; Wed, 27 Jul 2022 00:08:48 +0000 (UTC) X-FDA: 79730943936.11.26179D3 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2041.outbound.protection.outlook.com [40.107.237.41]) by imf23.hostedemail.com (Postfix) with ESMTP id 54B501400A0 for ; Wed, 27 Jul 2022 00:08:48 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=eBY5w58gsz8qYbIk4XLxLWQJc79ApB9PzC6aTB1mFKa+A6QOBp6RVKr+V5yTWxvdfxtWo82H/TqxRgtfkyAFLcLBfPtcW38TYFe/1tJZXaPGSzDOVDuD8/m7k0g40KSbzrhwbAWvZh3kOfeadyD6LkeaJfUvobmOzJjXfEt62Apx0i5BJff2zq/qt63UJNlK8Lm/FFb/hUiQdnrxpcA40N9hDM4b9z2fbYHqd7j3SQ3IgQzqMpCMZ4yK8zgF4SsYmjzBfr6N5J3NZnD+RhbPvY7gyLcCHK04gRFeJZgpcjtBWyGlfiEyPflSvKkzUI1fsHiiJYSAND2E6aWp4uJOqA== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=1yvx1WWz8TdrJ2KCl9b88mUhn9tYTpLlr3WG6SIaM0k=; b=DzaRQcb1W48nFTNjmy+3//SoFPpIUIHPn9CKfFL0p/k4X7F0cfXLVeQAZcM564UxwFREbban1o0OmEYTQzkt7wEJHcD0zXQmeb+XDsjunAHZ3aUXRwkns8gFc05LUVBaUM2TmDtKEIB3CraLLwW/oreS/u76Pa+JPkebzvu+tbDPuFEcSKUCyLIBkc6ajwqs2Buxd2KyzH5lz/v56TcSUkMXN+naghmga3MVAfaAKCe4sAZczcerbGL47d7O1f4VTn7GsKLFaJGpxWCsjBccQA5ZkTiWN/qC8Aa7V6o6ErPtTCgnq5IhTW/VbcIj1OKfTKmPXUN3XFtcJ3T5F00tDQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 12.22.5.234) smtp.rcpttodomain=amd.com smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject 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=1yvx1WWz8TdrJ2KCl9b88mUhn9tYTpLlr3WG6SIaM0k=; b=iGcddrvF0bHvrPp1bOv3YrY5uqhfoWbkXcNQCI3k9S3Un1XMaslV5z2x7yt560OdLU8GOGyDDcNiDZWOj2Oq96Ne8Pvd8ahCA3W3XnW5oF3BnaijDTi8cpTZA7yai2Ae6t4F07HkeyHkdVY0STX4lkvKRoQ6rofyW/kVb0x40S2mFof3bmj5Z9+wEfcCSpbMQ8R7xBq/Uraoy6tLrGeWSb2heg4BXfBHMX1ug3+d3GXSbpQusx4BW7ex30ax0m+gWavU+b/fcenvxkXhEqGAr/ir5zHPpbfIVSu/9mRcf9yfYLiSOPkyo/tjgYdNXahBdpEvxJq+US/th64xMR7yUA== Received: from BN9PR03CA0350.namprd03.prod.outlook.com (2603:10b6:408:f6::25) by MN2PR12MB3902.namprd12.prod.outlook.com (2603:10b6:208:169::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5458.18; Wed, 27 Jul 2022 00:08:46 +0000 Received: from BN8NAM11FT056.eop-nam11.prod.protection.outlook.com (2603:10b6:408:f6:cafe::4d) by BN9PR03CA0350.outlook.office365.com (2603:10b6:408:f6::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5458.24 via Frontend Transport; Wed, 27 Jul 2022 00:08:46 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 12.22.5.234) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 12.22.5.234 as permitted sender) receiver=protection.outlook.com; client-ip=12.22.5.234; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (12.22.5.234) by BN8NAM11FT056.mail.protection.outlook.com (10.13.177.26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.5482.10 via Frontend Transport; Wed, 27 Jul 2022 00:08:46 +0000 Received: from drhqmail203.nvidia.com (10.126.190.182) by DRHQMAIL101.nvidia.com (10.27.9.10) with Microsoft SMTP Server (TLS) id 15.0.1497.32; Wed, 27 Jul 2022 00:08:45 +0000 Received: from drhqmail202.nvidia.com (10.126.190.181) by drhqmail203.nvidia.com (10.126.190.182) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.26; Tue, 26 Jul 2022 17:08:45 -0700 Received: from rcampbell-dev.nvidia.com (10.127.8.9) by mail.nvidia.com (10.126.190.181) with Microsoft SMTP Server id 15.2.986.26 via Frontend Transport; Tue, 26 Jul 2022 17:08:45 -0700 From: Ralph Campbell To: CC: Felix Kuehling , Philip Yang , Alistair Popple , John Hubbard , Jason Gunthorpe , Andrew Morton , Ralph Campbell Subject: [PATCH v3 2/2] mm/hmm: add a test for cross device private faults Date: Tue, 26 Jul 2022 17:08:37 -0700 Message-ID: <20220727000837.4128709-3-rcampbell@nvidia.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220727000837.4128709-1-rcampbell@nvidia.com> References: <20220727000837.4128709-1-rcampbell@nvidia.com> MIME-Version: 1.0 X-NVConfidentiality: public X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: b46532ce-478e-4a0a-6662-08da6f642cc9 X-MS-TrafficTypeDiagnostic: MN2PR12MB3902:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: acWbPZWGJWlduPEn0pg5XbZEh3BX/MjkJgMYGkIgfcV+O2/dN81/C8HTI31nR7vJapEwV254AuVwg79n+BwGKrPCFLRyxOZy3EXYfuQlFRBAE9+Q2SqAClq+oRXVGsvSyNk6u7ZaNY2viLVtygJBLkyq2R6GrfIpXZddQOUzKJE3DZ3GxM8rvNJrzlOivFG+wT4eG/meOvn+2q3lcFaipe6peuP3Si6UsI6pKBfd7ABSNx98boINhQ/CoFX4EcVcKDxtv+6OiXxXID7AfPgCSEXg5r1SxLs/dDtvcTzF6/0sErIznGGZHQ8Ua14oY056iUQiIQ7js8eLz8KsgVO9vdVJxjkvKRwOcNthrSVGq4DUPRV2QzZkA7jrJSko7CifsZRFw5Z+2kQ4CldvN5g4thNw6zbreNT/HxxtLz97lY6FP2KCMX6pV3/Uf/IPdfAHHKM9NC2iu67DN7+AGeVi3+zyHc0bEFzGM1Y8B2Y4opJ8OBn2ZFJqf++PTE3S1dPrQ1HI94CgLsQfxTPqqZrblRu6bAjkg8OS+f9tOBb1Z01pX4bqVI9v9yTC+Mq/7WwiOAgcVjFjRQzrY2zCUz9TOoDkC9rfEZC3Q6Ih98Rza+DNtUgnTJl1H/zb/rWLQjVuc2BVDaN9bOVa3D0I3bOl+1vhFOjRhyQzbuDo/BV16ZfyeRG7wzjaogaot539N2iXUdTHoLt/biEvo9pvcbX0qYtlofoI3aqs5Cna3TPR3vGIsQoxTG72QBy3/Vg+uC8YpCsnjzYB7REuclIcvRHadWSsfciGYg9wHhGkj5oBOHV6O536vbjEq2XjIiGe4ofQrL7IlxgDpnoIfT2n6asE8w== X-Forefront-Antispam-Report: CIP:12.22.5.234;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:InfoNoRecords;CAT:NONE;SFS:(13230016)(4636009)(136003)(346002)(396003)(39860400002)(376002)(36840700001)(46966006)(40470700004)(2616005)(70586007)(70206006)(82740400003)(107886003)(186003)(81166007)(1076003)(478600001)(7696005)(6666004)(8676002)(41300700001)(26005)(4326008)(40460700003)(356005)(8936002)(36756003)(2906002)(5660300002)(40480700001)(316002)(83380400001)(86362001)(82310400005)(6916009)(36860700001)(426003)(47076005)(336012)(54906003)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Jul 2022 00:08:46.3437 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b46532ce-478e-4a0a-6662-08da6f642cc9 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[12.22.5.234];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT056.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB3902 ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1658880528; a=rsa-sha256; cv=pass; b=3jWuU7rwJ9u5duEcZ+tukdKWJ485zzq3pyBfQWFFM0LeOh8EplADP2aeT5I4mHKn9w+RSb RVvqZ5THA9wnwAL0L12c7jOEADCpe0WnN7Z7Mh8wr4fMuMWP5pSZk670sX9JS+EbFzrdWD R/412gIBA6v5MOzV52m4rtQMkXE9VNg= ARC-Authentication-Results: i=2; imf23.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=iGcddrvF; dmarc=pass (policy=reject) header.from=nvidia.com; arc=pass ("microsoft.com:s=arcselector9901:i=1"); spf=pass (imf23.hostedemail.com: domain of rcampbell@nvidia.com designates 40.107.237.41 as permitted sender) smtp.mailfrom=rcampbell@nvidia.com ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1658880528; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=1yvx1WWz8TdrJ2KCl9b88mUhn9tYTpLlr3WG6SIaM0k=; b=STStn/yyZar7NwgMuiy4AP9fqgmYj1CzDbuOLQKNG2Ey8ASyV2TinKssygKqyAKg/TUiU2 yLR3u66hir7g1mYf7hyG9H8bVzBgBoHf1l2RwXtziWylIwdT0iYlEucYbKoWTxO9ztgeAf 5FWSW1zN05BAoe7SEbOSCNTzBd2ampM= X-Rspamd-Queue-Id: 54B501400A0 X-Rspam-User: Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=iGcddrvF; dmarc=pass (policy=reject) header.from=nvidia.com; arc=pass ("microsoft.com:s=arcselector9901:i=1"); spf=pass (imf23.hostedemail.com: domain of rcampbell@nvidia.com designates 40.107.237.41 as permitted sender) smtp.mailfrom=rcampbell@nvidia.com X-Rspamd-Server: rspam09 X-Stat-Signature: 1i1bq6c5udhdmjesidmuafkzamyzss7j X-HE-Tag: 1658880528-890539 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: Add a simple test case for when hmm_range_fault() is called with the HMM_PFN_REQ_FAULT flag and a device private PTE is found for a device other than the hmm_range::dev_private_owner. This should cause the page to be faulted back to system memory from the other device and the PFN returned in the output array. Also, remove a piece of code that unnecessarily unmaps part of the buffer. Signed-off-by: Ralph Campbell Reviewed-by: Alistair Popple Cc: Felix Kuehling Cc: Philip Yang Cc: Alistair Popple Cc: Jason Gunthorpe Signed-off-by: Andrew Morton --- tools/testing/selftests/vm/hmm-tests.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/vm/hmm-tests.c b/tools/testing/selftests/vm/hmm-tests.c index 203323967b50..a5ce7cc2e7aa 100644 --- a/tools/testing/selftests/vm/hmm-tests.c +++ b/tools/testing/selftests/vm/hmm-tests.c @@ -1520,9 +1520,19 @@ TEST_F(hmm2, double_map) for (i = 0, ptr = buffer->mirror; i < size / sizeof(*ptr); ++i) ASSERT_EQ(ptr[i], i); - /* Punch a hole after the first page address. */ - ret = munmap(buffer->ptr + self->page_size, self->page_size); + /* Migrate pages to device 1 and try to read from device 0. */ + ret = hmm_dmirror_cmd(self->fd1, HMM_DMIRROR_MIGRATE, buffer, npages); + ASSERT_EQ(ret, 0); + ASSERT_EQ(buffer->cpages, npages); + + ret = hmm_dmirror_cmd(self->fd0, HMM_DMIRROR_READ, buffer, npages); ASSERT_EQ(ret, 0); + ASSERT_EQ(buffer->cpages, npages); + ASSERT_EQ(buffer->faults, 1); + + /* Check what device 0 read. */ + for (i = 0, ptr = buffer->mirror; i < size / sizeof(*ptr); ++i) + ASSERT_EQ(ptr[i], i); hmm_buffer_free(buffer); }