From patchwork Mon Jul 25 18:36:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ralph Campbell X-Patchwork-Id: 12928308 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 528FDCCA473 for ; Mon, 25 Jul 2022 18:36:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D7FF28E0001; Mon, 25 Jul 2022 14:36:41 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D0751940007; Mon, 25 Jul 2022 14:36:41 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B0C328E0003; Mon, 25 Jul 2022 14:36:41 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 9267B8E0001 for ; Mon, 25 Jul 2022 14:36:41 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 68723AAA06 for ; Mon, 25 Jul 2022 18:36:41 +0000 (UTC) X-FDA: 79726478202.24.1291E0A Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2045.outbound.protection.outlook.com [40.107.92.45]) by imf30.hostedemail.com (Postfix) with ESMTP id EBB54800C2 for ; Mon, 25 Jul 2022 18:36:39 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=iw6jaLBw/ScrodPDbwbq1FaCl63G4+Bcdsc9J6k9LP94fYV99dhHbK0JU9gfiGOu0HFf+UcR1UL58BzN4cXdNJqKlmaGGhSp8Lw1IdorxlYN+fFwQP7BwuMABBRi54c2lv+3hLoEXomUAInad2ZalhYmEw2aenbFOMADQOuG1NTVN/yAJDxP98A8PEiUsrOlUYILXJtc2qbST5QGL/F+iSnlGy6UhASzpa0aY6hj5TCPOCAmpgLZkGxNW8lZAdduD2JKUJvwB06a6UDb2fd7lLMaKr698zl1PzugjegBTY1muNKlq2AE2piKOza92k/VkWwUlb0fOjx1IGYiOwzdtw== 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=oA4be4lqegBXYcIGFJn/IObTLbANwrurBB6qUQrxUms=; b=cgqZzmpb4nBcc5ZOg/nGxXI3wdtv7EOs31fmFxOPp8ukoYNH4Zw1QcdS7HNyBeyAU4h4NyfqDfDONmIWAiZ0syCbHBz2NN4blyp0lW0v6VL9ym3xuGj42mV1Ajvk3gV1/4ZmfU1MrimjlNsma0VZzhOGSaXo6rLXnndFVY0J0mCuTzI1N7MNlpd+163FTXfINXoyBd/H4kT1Oy0i2IMnTFVZy/pqWYipJzB6rbS3GJsitGcb94M8jkhPXElGasCw1RuQlCT4qCc+ZN6/vvFbnK2ulJT2V9FhJlbZ6Kq8UWqcoC4ZBYFCEkZSSP/DazbLziZku8KKfW55iWVAH0dwhA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 12.22.5.234) 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=oA4be4lqegBXYcIGFJn/IObTLbANwrurBB6qUQrxUms=; b=Cfmf/vqgo7uaRE27EAJr1IsfyOclzGdBVjuLyNqdCLwy4NBbxyo+zVd7lR71pG82na8tnhvJvxF/7hp0e8aaXtXHEC4cZW4r5Pv4QIpwOh97Mwfv1/C+dNeXEjqaldwFklvUQSVeyb2CMvNSGTqAeDbyKocYzRtcUEpkGDEJKpEqSqdaLGhVkIrbRwNFwdI2+5ODZG+amKZg4UI0LNO+h3JvLjLPN6DCALC9wfKMfFGH26jC5kyDViPgJjgnkhhxXuOclNEi1Htqa11zT4bhABxWO/Clvsw/apS3RZQtrWtbXeIDNVdojc8RKH+dAomG8KZQPlmAUrT0c0dlwJoG/Q== Received: from DM6PR01CA0022.prod.exchangelabs.com (2603:10b6:5:296::27) by BY5PR12MB3873.namprd12.prod.outlook.com (2603:10b6:a03:1a3::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5458.20; Mon, 25 Jul 2022 18:36:37 +0000 Received: from DM6NAM11FT025.eop-nam11.prod.protection.outlook.com (2603:10b6:5:296:cafe::8e) by DM6PR01CA0022.outlook.office365.com (2603:10b6:5:296::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5458.18 via Frontend Transport; Mon, 25 Jul 2022 18:36:37 +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 DM6NAM11FT025.mail.protection.outlook.com (10.13.172.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.5458.17 via Frontend Transport; Mon, 25 Jul 2022 18:36:37 +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; Mon, 25 Jul 2022 18:36:36 +0000 Received: from drhqmail203.nvidia.com (10.126.190.182) 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; Mon, 25 Jul 2022 11:36:36 -0700 Received: from rcampbell-dev.nvidia.com (10.127.8.9) by mail.nvidia.com (10.126.190.182) with Microsoft SMTP Server id 15.2.986.26 via Frontend Transport; Mon, 25 Jul 2022 11:36:36 -0700 From: Ralph Campbell To: CC: Felix Kuehling , Philip Yang , Alistair Popple , Jason Gunthorpe , Andrew Morton , Ralph Campbell , Subject: [PATCH v2 1/2] mm/hmm: fault non-owner device private entries Date: Mon, 25 Jul 2022 11:36:14 -0700 Message-ID: <20220725183615.4118795-2-rcampbell@nvidia.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220725183615.4118795-1-rcampbell@nvidia.com> References: <20220725183615.4118795-1-rcampbell@nvidia.com> MIME-Version: 1.0 X-NVConfidentiality: public X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 1a00ba4d-4441-4b06-61a0-08da6e6c9b9f X-MS-TrafficTypeDiagnostic: BY5PR12MB3873:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: U/XD7K03jBSHdSoJhOxrtdj2SH2gvpV3C0y3o4vKmI7RK1zuqJ2Cpy4ubxn4+QusJsvi8fpFrkVnP/oScqCGp6baK/9Cyqb4wGG6P7AERceFtv8hxN9LGBvMMGunmYocEr5jGuPUtREgDbINu7MinX+k0wmGSesMuktHH1SUNkNeWGNEiMYDG9zeC0FUlaHGyYsIfxUzlpGIK3UNnreSDLnfUXp8y/2GnmPv7eruUV8gaSPYXFv+hj4Rw8GG54900Rcp79cBHvm84dvr0Q+eByHjpiL0EK2ahKH0+e2bsiAJEwZKFSidjAg9n3A4n3enOBVBMyphFt6IoQlxa2HDv0rex++29H7sIV3XaQ4u2FHsIHIjOrJF/bQ7plim9GfVxfvFpMClM1ln7yYE5Y1ciq9JJpEpDs1HJRMZ2EvUHjz8ic72X+zVZ7EsL0zpHN6jf3I0LLixK1vkEVNIXs9/GHt1trY23CNe/SbXVNB/4Pa2LfERXGyi5DECss8u5rybX11Qgnhj4K0OQ8UNXGslcpAT/aM8TzfFgguWFeypwTlyFgid2HfGWDSTDw4Cx/MLgvlZ7JKANOGxPl6LCtn7BakUJtEwTaz5E7znAtMC+fOydmnKOaUNyTN1ZZYBQhGd5x3HMaYpFhyykphPel30xXAe9DwORw/w40zhb4S8toQoFbWMhVkrjLRKEix7uuZfBq/FWhxMdsfiUOGdG4cC9Nx9ikKKf1UQdyYzTCQI7oGmowlFIS5Rf19ymdhVH832pwKCKenJ1r7bZqxwU1vax8eimLxZDICa3PZhG+2c9XiUrJUrfGHsDerDqwMozbknSRsL6E38rU49iTT/LaESsQ== 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)(396003)(39860400002)(346002)(136003)(376002)(36840700001)(40470700004)(46966006)(1076003)(47076005)(4326008)(2616005)(70586007)(70206006)(426003)(8676002)(5660300002)(186003)(8936002)(336012)(54906003)(86362001)(36860700001)(6916009)(356005)(316002)(40480700001)(7696005)(36756003)(2906002)(82740400003)(6666004)(83380400001)(26005)(478600001)(81166007)(41300700001)(82310400005)(40460700003)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Jul 2022 18:36:37.1533 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 1a00ba4d-4441-4b06-61a0-08da6e6c9b9f 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: DM6NAM11FT025.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR12MB3873 ARC-Authentication-Results: i=2; imf30.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b="Cfmf/vqg"; arc=pass ("microsoft.com:s=arcselector9901:i=1"); dmarc=pass (policy=reject) header.from=nvidia.com; spf=none (imf30.hostedemail.com: domain of rcampbell@nvidia.com has no SPF policy when checking 40.107.92.45) smtp.mailfrom=rcampbell@nvidia.com ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1658774201; 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=oA4be4lqegBXYcIGFJn/IObTLbANwrurBB6qUQrxUms=; b=m7RoN5ms/sn12lGGEfbJQDvxws4eUq39kpAK1fBjQwxXofnImULENNhd74GLBxDoqQTiYW P4rlUp2xoM3aoL8mS+bkePTOaCNvm328IX0jsEsBteh1kWAJCIU155/KgXq7bkanCPkf+N Xbk5xCn5/v3xYh5wDSTeIc04j9j3/do= ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1658774201; a=rsa-sha256; cv=pass; b=DiEC5nb0nIhbGygNViP6DaDb2jlbUCByAOLmyiXXbMeADDNso7TJAdrsjP+VlVgrB5MAZM cY90cVXXFpj7VLoKzkbC2Rly2E2QX29yFPTLNZXUsM375YYetlcUlZ5QAPkIU3iNK3zF/V fkQ9gZUIGh8gM1/uamDGUVexVL29GDs= X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: EBB54800C2 X-Rspam-User: Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b="Cfmf/vqg"; arc=pass ("microsoft.com:s=arcselector9901:i=1"); dmarc=pass (policy=reject) header.from=nvidia.com; spf=none (imf30.hostedemail.com: domain of rcampbell@nvidia.com has no SPF policy when checking 40.107.92.45) smtp.mailfrom=rcampbell@nvidia.com X-Stat-Signature: zwnyffux8bm8totjojbnydekpragdfsa X-HE-Tag: 1658774199-261782 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. Cc: stable@vger.kernel.org Fixes: 76612d6ce4cc ("mm/hmm: reorganize how !pte_present is handled in hmm_vma_handle_pte()") Signed-off-by: Ralph Campbell Reported-by: Felix Kuehling Reviewed-by: Alistair Popple --- 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 Mon Jul 25 18:36:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ralph Campbell X-Patchwork-Id: 12928309 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 8DE5ACCA473 for ; Mon, 25 Jul 2022 18:36:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2F6DB940008; Mon, 25 Jul 2022 14:36:46 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2A6A3940007; Mon, 25 Jul 2022 14:36:46 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0D268940008; Mon, 25 Jul 2022 14:36:46 -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 F06AD940007 for ; Mon, 25 Jul 2022 14:36:45 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id C37BE1C5B38 for ; Mon, 25 Jul 2022 18:36:45 +0000 (UTC) X-FDA: 79726478370.12.242C165 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2050.outbound.protection.outlook.com [40.107.93.50]) by imf03.hostedemail.com (Postfix) with ESMTP id 322BE20091 for ; Mon, 25 Jul 2022 18:36:45 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FNiu1yNfrFB//JjsmiFty0oExU5a89B3ny2ldrSlZP6jYzeFRzCgDwttWsDXMQEgccLA33dXoVYwDJNRZyIk4f4lCAgZ26i2x2EKkrb3JrG/Dhlop2aech4GLdGmAlcdXpRsboybUMl7LynRfgzleuzft0V7GRkxAyN5rqgDxoHtRWkhH/bGzuRggRnQedE1rt/Y3KiD4mN5ydf8g4zu0OgD+otijrme9uiCxXU/2vrx/T7diMDQZAIDEVE6pdB6SJMAAPmPRnJZkIMUqpY/qfIL3jua34ym7EsMAGgINw3tHmYgrGFT3SUrx8Bp9Gn8BnohH+lFqgNbM3zB80VD4A== 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=bdM/+/9b92rfgLEEIFkSbzuTK2+OQDLd+ssuPmHkA8M=; b=YLG9eWegJqSMfyiL+N7PQpnDV4pPzhZIVA205G6YXl8v0wmWBSjESUrnT6BRTMEaSEQjexaCCtb6k4e9P0I3JFJeO9z9HP9t4WhogClQmJkq8qWLydyvZ4JJiYeAjNBFW4DeDS8IX0aKqHuwYWkJ4W5vlSHIJt3+PobFsehf3cYJsy9aY05S3YWe2H3UFUvYA0rUIVrLEtKx+7yleSDM+nu/th57IzExLUJa9pJsUdHotYajf0mZJiuO0Q4SRCUIukwIku608VtS0QnTXV9XoC+ULO7rjC1pITBlkQZDLWErZDhz9eAQ/jcPlv7TIeS1FbGWAgZBGLSpJqVRxkB5QQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 12.22.5.236) 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=bdM/+/9b92rfgLEEIFkSbzuTK2+OQDLd+ssuPmHkA8M=; b=IWyDMESiDjmVek6f5+AzpUF1mxo3h7fGwm7YpgX76y6PvarvkknyBoESAtT7FQ6cXQdrKiHh7cgjsbFIDn+GwCHQf7ZDwbmnju9KXfgxQEBhSoVvkVtTw74EUDLLvnNtvhuJKTs7W3b0fjjwx4l/ogcZK90+UbsgyqYIgXmrbpa63cLruYR6H2R1Du5kn2fr991mJvt6ONmJCwclyFLvzkHqlTSJd5xxAhlXckvKJaqsABq9a0ipQ8rKiXXzjHHY78UsY93okqJE38B1OW5q/OiqOeJn2M4jTjBShvjHtTzpnN5u+D+l4bTJ7yvmxmmInNywgkumNDWecCkfDULudA== Received: from BN8PR15CA0018.namprd15.prod.outlook.com (2603:10b6:408:c0::31) by BY5PR12MB3876.namprd12.prod.outlook.com (2603:10b6:a03:1a7::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5458.20; Mon, 25 Jul 2022 18:36:42 +0000 Received: from BN8NAM11FT011.eop-nam11.prod.protection.outlook.com (2603:10b6:408:c0:cafe::fc) by BN8PR15CA0018.outlook.office365.com (2603:10b6:408:c0::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5458.19 via Frontend Transport; Mon, 25 Jul 2022 18:36:41 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 12.22.5.236) 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.236 as permitted sender) receiver=protection.outlook.com; client-ip=12.22.5.236; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (12.22.5.236) by BN8NAM11FT011.mail.protection.outlook.com (10.13.176.140) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.5458.17 via Frontend Transport; Mon, 25 Jul 2022 18:36:41 +0000 Received: from drhqmail203.nvidia.com (10.126.190.182) by DRHQMAIL109.nvidia.com (10.27.9.19) with Microsoft SMTP Server (TLS) id 15.0.1497.32; Mon, 25 Jul 2022 18:36:36 +0000 Received: from drhqmail203.nvidia.com (10.126.190.182) 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; Mon, 25 Jul 2022 11:36:36 -0700 Received: from rcampbell-dev.nvidia.com (10.127.8.9) by mail.nvidia.com (10.126.190.182) with Microsoft SMTP Server id 15.2.986.26 via Frontend Transport; Mon, 25 Jul 2022 11:36:36 -0700 From: Ralph Campbell To: CC: Felix Kuehling , Philip Yang , Alistair Popple , Jason Gunthorpe , Andrew Morton , Ralph Campbell Subject: [PATCH v2 2/2] mm/hmm: add a test for cross device private faults Date: Mon, 25 Jul 2022 11:36:15 -0700 Message-ID: <20220725183615.4118795-3-rcampbell@nvidia.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220725183615.4118795-1-rcampbell@nvidia.com> References: <20220725183615.4118795-1-rcampbell@nvidia.com> MIME-Version: 1.0 X-NVConfidentiality: public X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 262cc915-45c2-4678-8c10-08da6e6c9e63 X-MS-TrafficTypeDiagnostic: BY5PR12MB3876:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: xNMiOHFYqDFqzSaSHh/EE/C8sUj2BOP8LJnaui1D9WseV+1Sq88btK91y6jSc1kP0TqLNsnVKd233xRnsctUkAthTJl3BCdPOBrfigVlNF4QYt/UxQGS3sxE4DDwImME0oau85FMqt/CZdjyJ1zYfOg1PC7b5hmSVNEChXj78wuE5EGjfXg8jr8EnzJozFYymiNGN3J5BuIls6KKQyHCjOAvJdnL2yOZKOMc6v2Fhdg+0Y8nUhhSjBXKRsw9buM50OTWbpfA57NvkwZrriw7Ded4FJVb8WIwV04r1k7pyVb1VKW5X2nuvxMjuMsGu3Mt9+IX5K22ts0OWDObBX6tjLZxordA9iCvprJYv4mDKCGaagsQBSY85Ie6HRRCnx/+yRewGhcXd34GwKSLlh+5WcC0rV+TkV0//4Q7lH7SP/Ss/62D7f8JWJyQTOcIkJ+7DxA7M9AP5pncFPB3GTGBEsMA6fuhBWLfNO60f72fgAUm0r4/nvSvfx4e/nAHsoO7D7ck+gtIC4pG8NHsPPSjHEeze3N0MsQ1++CUUACc0yrr8xFQpDvHCUxOEg09G4Gf/oPg5Viq8mveOZxETpo2ugddHK8M2/gQHzlA9xWaiYpnxH4sKl2Qv7vV4SaZbrA3j3X5j1C5RmIWvn1VlHgldtB7fIDSZalXNJ2eu58scrTHoxJV0DSFKgymrP5btIUy8Rwb4DPtuFuS84bidsLAsvXU9Gfcug1KRnuUVJQVwre5Ldlmka3wE4OKIYlqraN5noQm58yJyaK+BkdBttsQhxVuWMcsU3HnXDoQLK0SLPgfOVwkEiFokPveTsuFa0QNtFxHUkeG2psqd+3Q1WssBw== X-Forefront-Antispam-Report: CIP:12.22.5.236;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:InfoNoRecords;CAT:NONE;SFS:(13230016)(4636009)(376002)(136003)(396003)(346002)(39860400002)(46966006)(36840700001)(40470700004)(478600001)(40480700001)(8936002)(36860700001)(26005)(5660300002)(40460700003)(336012)(47076005)(6666004)(426003)(86362001)(1076003)(186003)(83380400001)(2616005)(2906002)(7696005)(82310400005)(41300700001)(82740400003)(81166007)(356005)(54906003)(316002)(107886003)(36756003)(70206006)(70586007)(4326008)(8676002)(6916009)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Jul 2022 18:36:41.7475 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 262cc915-45c2-4678-8c10-08da6e6c9e63 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.236];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT011.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR12MB3876 ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1658774205; 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=bdM/+/9b92rfgLEEIFkSbzuTK2+OQDLd+ssuPmHkA8M=; b=xx/ym83OopcDONx5RGFnknH8PQ1UNEdiNyhuqH7b/9r2gbCyDxbzV/uWMFr97mTT39YlWC Pw4+57TVwpw/sOf+3eVT5aShjVuRMhhSeQpF9nszKKkhSfqVlc8/NoFszOvRYSlT38VDGP j9vnquQhxp0fMmtmoV7eJUltDx4bVPw= ARC-Authentication-Results: i=2; imf03.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=IWyDMESi; dmarc=pass (policy=reject) header.from=nvidia.com; arc=pass ("microsoft.com:s=arcselector9901:i=1"); spf=none (imf03.hostedemail.com: domain of rcampbell@nvidia.com has no SPF policy when checking 40.107.93.50) smtp.mailfrom=rcampbell@nvidia.com ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1658774205; a=rsa-sha256; cv=pass; b=0TNqBYDKZGkIgD89MBNm/GS/AFCE3xgigcXCWAu7wIpFbrpHbGAIAlHlpiR+wGb0P9x+e0 q0r7p8qdUU62RnjfK4uaWIeFmqaVOm3EphHYl6Brzhl9IGHZimYNQHDo2quY97Xs5+E7zK dR3k5B7ATCNS059VT8fVzeLw8fZnmiM= X-Stat-Signature: p6igsjc4cbmwpoompm3oisj8kxya4tga X-Rspamd-Queue-Id: 322BE20091 X-Rspam-User: X-Rspamd-Server: rspam12 Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=IWyDMESi; dmarc=pass (policy=reject) header.from=nvidia.com; arc=pass ("microsoft.com:s=arcselector9901:i=1"); spf=none (imf03.hostedemail.com: domain of rcampbell@nvidia.com has no SPF policy when checking 40.107.93.50) smtp.mailfrom=rcampbell@nvidia.com X-HE-Tag: 1658774205-584916 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. Signed-off-by: Ralph Campbell Reviewed-by: Alistair Popple --- 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); }