Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp4628949pxf; Tue, 30 Mar 2021 12:36:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxBhv5hZo3qbHZlkJ0mc4hfVfkOVNPt7ZlzsaYExgnj1r/rEnSxE0u/s1HVMRCi42KfRlg5 X-Received: by 2002:a17:906:2a50:: with SMTP id k16mr24058873eje.537.1617132983115; Tue, 30 Mar 2021 12:36:23 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1617132983; cv=pass; d=google.com; s=arc-20160816; b=E52P527e3W47Um7aWXRCGqhFvVSjmn7N+5HesHmVsGQedX82e6fQhQT6kaxJ8XzwnK iP4l0Ca4ZYacAHHOnl2UG7n6mEq20lvfXp1tzPCi/WVLR7oi18m52HVi5yDlDzv7EtDy Ld4M4GTKE5grcoQ/BzxnoYaa5MuzBUeS7s4aafVzpu5GcuzG6mR/QJPiW5u2/0oMT4Fj Oki+wTKNVSfQcQOFaV56FtNLAtJkLTqdFB0kRZFcwPPcW352jO3QovynbJG7c18Gyrgh MywFek00tIxYs819P5pQN6ezb6jSNCXaKi5NU1P7pIVwZm7JBVgJPj1Rs+wgY+WMmIeu qojQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:in-reply-to:content-disposition :references:message-id:subject:cc:to:from:date:dkim-signature; bh=7PhcGFNlYjLV9XW95SmKtHxN8eoffs4BbapQaYBQ1UA=; b=W+a3Jc23DuVDh0z/PNgNYL3BdMESRv1rBOHACH7HdvfeOAeqIoN+FC8rekv4jywg5N XLMPPDZKPB0BTk0Smi+TYHttHtI6+B+kb4CKft22uSqOyTXo0Iux3BMClAvG5UNoI0Y3 fRIM0lwqf7iE1g8kpEvLzB1CthcIcYJjNQXK3ibokAsRfguxNvEPgAu38vV8gZZcWLtU prcLn5Ka399c2r1dQH9y1pkj0oGNkC5w38nG7/RarZwGwvgtCAXF5sJog3ktsCRBd5rN FdYphC/joL/ID5XpZ6NRXXMDQcUY+YQBVvYc8huPRZ605O6fbNK2bvrDAValUoL8xPo1 BPFQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@Nvidia.com header.s=selector2 header.b=c33WOS1+; arc=pass (i=1 spf=pass spfdomain=nvidia.com dkim=pass dkdomain=nvidia.com dmarc=pass fromdomain=nvidia.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nvidia.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z15si16038775edr.361.2021.03.30.12.36.00; Tue, 30 Mar 2021 12:36:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@Nvidia.com header.s=selector2 header.b=c33WOS1+; arc=pass (i=1 spf=pass spfdomain=nvidia.com dkim=pass dkdomain=nvidia.com dmarc=pass fromdomain=nvidia.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nvidia.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233113AbhC3Tcv (ORCPT + 99 others); Tue, 30 Mar 2021 15:32:51 -0400 Received: from mail-dm6nam12on2074.outbound.protection.outlook.com ([40.107.243.74]:61152 "EHLO NAM12-DM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S233110AbhC3Tck (ORCPT ); Tue, 30 Mar 2021 15:32:40 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=J4mcptxhUrD5agO8aP1Ket9xR1Fb3XuYV76TCuyMEpx3x1XE0/w54Hht4mBhJQQNooAWmoAs4GFPMsqG2+Oqc1kX+vslCUWRFC3m+KU88VDFGTDCPeXWAZhkrO+r/rMsu3x7o0SckEpLEPCjMSvAz57ks1sMYplSPS4TEYSHe2uuGqTQfkwu5ph+q8k0ZO++53oMPtRXfovH1twIJXX3y1Kb/fjF8FCUE1fcr5CqpDsALfPz9zPhqwDgglGnIBbdox+gdV2o0xf5nY8JXevhGlywEgmECeF8d5Rroqg6/yDhq8ldBX5wfSgoY5OnNLIie2n1Zh4oJDCBAYVLZvgk3A== 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=7PhcGFNlYjLV9XW95SmKtHxN8eoffs4BbapQaYBQ1UA=; b=ROhwzOImRxDMu8iUUztUR80UIUnAZmwXKkxkNJmCgMWMM0MYaXKqIZ48PdAnGUONdrj12NuE6S5S71qoNpEO92ayq0K3vFPiOPYAWVhWY8qFS/U6/jXQPxTFUdhyUTgWPoXpm59WpSmn6bn+sQX0zLv07gWL4J+VFX7DZdY6HU3gSem9sDKkAZTZgMQRN7YsN80o9NwT943dFyM7VBwgMJFRimwmL4HGrBfX1HMa3ylGO6VB5XK5LzlCQ6feGhB61L/0r5LSVDhudOnJ7haD2KnyIP/Vbe7vSPHRYL/EyRF3SatxdsG5KmYvbjpgY9z9RZxL3xsAtGeFr8G5MqZLeg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; 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=7PhcGFNlYjLV9XW95SmKtHxN8eoffs4BbapQaYBQ1UA=; b=c33WOS1+64r9W829u0ONKjgNrUnWqFQZGECxx8j47q6kqkSOf9rlmZcLVQGw/TJyNxkZS+3y7sMBCtNrpggCb6XNm8k3qqHxeE5s8uQSSQk8sJBeK8IeEgGAwx+Xw7v+QAONqXzMIuFpmxglwkS6FXyFTJleKSdIz0rnEufoCOD8lHj/iT3pFTDDB9YCxIwZTWKjHc48AhA0+QsSPH9LFQ57+bfu0cjCXfue0Ah2GKzKJLXmUCoOQaPNkOVikTSfR+5UkgI4bAJq2mol5E0b+AydzIX0eLtfLdvZaqwS6MITU1AbqtR6NfZFHDpZE4zL1qZbpwtDPc+uNTb9v5bAnw== Authentication-Results: nvidia.com; dkim=none (message not signed) header.d=none;nvidia.com; dmarc=none action=none header.from=nvidia.com; Received: from DM6PR12MB3834.namprd12.prod.outlook.com (2603:10b6:5:14a::12) by DM5PR12MB1146.namprd12.prod.outlook.com (2603:10b6:3:73::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3977.24; Tue, 30 Mar 2021 19:32:36 +0000 Received: from DM6PR12MB3834.namprd12.prod.outlook.com ([fe80::1c62:7fa3:617b:ab87]) by DM6PR12MB3834.namprd12.prod.outlook.com ([fe80::1c62:7fa3:617b:ab87%6]) with mapi id 15.20.3977.033; Tue, 30 Mar 2021 19:32:36 +0000 Date: Tue, 30 Mar 2021 16:32:34 -0300 From: Jason Gunthorpe To: Alistair Popple Cc: linux-mm@kvack.org, nouveau@lists.freedesktop.org, bskeggs@redhat.com, akpm@linux-foundation.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, kvm-ppc@vger.kernel.org, dri-devel@lists.freedesktop.org, jhubbard@nvidia.com, rcampbell@nvidia.com, jglisse@redhat.com, hch@infradead.org, daniel@ffwll.ch, willy@infradead.org, Christoph Hellwig Subject: Re: [PATCH v7 5/8] mm: Device exclusive memory access Message-ID: <20210330193234.GA2356281@nvidia.com> References: <20210326000805.2518-1-apopple@nvidia.com> <20210326000805.2518-6-apopple@nvidia.com> Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210326000805.2518-6-apopple@nvidia.com> X-Originating-IP: [142.162.115.133] X-ClientProxiedBy: BLAPR03CA0141.namprd03.prod.outlook.com (2603:10b6:208:32e::26) To DM6PR12MB3834.namprd12.prod.outlook.com (2603:10b6:5:14a::12) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from mlx.ziepe.ca (142.162.115.133) by BLAPR03CA0141.namprd03.prod.outlook.com (2603:10b6:208:32e::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3977.29 via Frontend Transport; Tue, 30 Mar 2021 19:32:36 +0000 Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1lRK6M-0060w4-Is; Tue, 30 Mar 2021 16:32:34 -0300 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 37fe68d8-06b5-4a41-ad3c-08d8f3b29286 X-MS-TrafficTypeDiagnostic: DM5PR12MB1146: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:3968; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Rw/XrX6AXfYloHbskeYOeLPsHyNYLcxZg9mqf7xSYK5QvP/2wB0rK1h9GRcaV4R83EbtXfuKzolT/Lh684mkIuexpNIGyZdwIJErVeb6cki6DpsKlwlVoZrNgZPh1xPS7Q99L9YIXl6qcaPxJHbgqFYFFvDBq7JCiWNUyvfw2CGtYSIRvOipeSlsyb0mHsSu4PkLdbDLPgBOJZ5UMt1R+CQ3Lo34FUH3OrraCBAJhiFRWNh9TUCNZuYaVV/5xJThKJeWJp8b/EEx8N6Y68/A+lomGLLXvaBN6Rgw0z1i6QWKDuzSOXkpuBI+HYf+u70I54VwfFnqkIclGW0W0MFWoZJHqGXx4A5CyNKm4sOG0HIRfglCCs2pIhIbzF47OnSLepaeU0buxBi2/y95+P+EVHNcH59HgYTJu8AKfhtCMcBxjNWEq17qTyU8xynJ4iLSDQH0IuU0yyaYbVO4LkxYvxwhpRKTiaF7UogRTIHdrmcqhxVfUuHAM66DZaV0X+ztYYolJPGmxGCvPMPyDTvzFaDPVRuQNxoq24TCJ2oQ+Wni4aCUquwML9BjJYSFQL0lPwq0v8GHnSDsQNI1uFA+QNOgv1XY2uKyh5OptlmCjNj2a2st6lwrJEILCJCrNBi7foqt8LoM3VyHHyU3kdAjU9dei/nXn662l6fnNNXlZqI= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR12MB3834.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(376002)(39860400002)(136003)(366004)(346002)(396003)(4326008)(6636002)(8936002)(316002)(37006003)(26005)(38100700001)(7416002)(2906002)(2616005)(86362001)(33656002)(426003)(186003)(6862004)(8676002)(478600001)(5660300002)(9746002)(66476007)(1076003)(66946007)(66556008)(9786002)(36756003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?us-ascii?Q?MDIS8/wu7soJaecqBUztEe5bkfyPOy1ItblRAEcrwsMe1HIcz85kqW3pkqZ9?= =?us-ascii?Q?sa4ANWUN879JGxX4Un77YY8CV9YrilOuGQ3wOtLNeMat9qMS1jJ99KTiPftJ?= =?us-ascii?Q?oe7A1jnUuuX5vaACnJx0OxokihEtyhYfpdb0HRO2JPgcAkcaxru4ZaAJLasW?= =?us-ascii?Q?gKPpKCmpQS1GmZVYY6pXe1Jj7y/aVaJ4o6WqvYRdGVfOODvFKG+a3/v9nmMx?= =?us-ascii?Q?fuzjpBQsKstz6bopnbiePCtiGV5BHseYI+ZX3kDPobW4tSK30px63QSWRt8j?= =?us-ascii?Q?VOnnzikj2xCtFFyVLjfWAsY70MUwjT0uFtgmrPKq6p6KIbUIiDEz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m/MywO7NHmbCUxYTuZGz5GUa/vhzmTlRmdJEhLuuJU?= =?us-ascii?Q?rLi+3aTd9ErUBtmZ9ByqpiGAn0Nadrp2rL4nLNPA0xJzCyRuy0JdszxQqhZy?= =?us-ascii?Q?6fcsLtMVgtre0Gbku48lgZC1PMDBOtGV9cbT800G1oIpPg=3D=3D?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 37fe68d8-06b5-4a41-ad3c-08d8f3b29286 X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB3834.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Mar 2021 19:32:36.8209 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: JImXeaAgtp/05FnYQTtLdXkback4yZpTgLANfcnB+9nF2JnHckQagdb/Xg1bpjaJ X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1146 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Mar 26, 2021 at 11:08:02AM +1100, Alistair Popple wrote: > diff --git a/mm/memory.c b/mm/memory.c > index 3a5705cfc891..33d11527ef77 100644 > +++ b/mm/memory.c > @@ -781,6 +781,27 @@ copy_nonpresent_pte(struct mm_struct *dst_mm, struct mm_struct *src_mm, > pte = pte_swp_mkuffd_wp(pte); > set_pte_at(src_mm, addr, src_pte, pte); > } > + } else if (is_device_exclusive_entry(entry)) { > + page = pfn_swap_entry_to_page(entry); > + > + get_page(page); > + rss[mm_counter(page)]++; > + > + if (is_writable_device_exclusive_entry(entry) && > + is_cow_mapping(vm_flags)) { > + /* > + * COW mappings require pages in both > + * parent and child to be set to read. > + */ > + entry = make_readable_device_exclusive_entry( > + swp_offset(entry)); > + pte = swp_entry_to_pte(entry); > + if (pte_swp_soft_dirty(*src_pte)) > + pte = pte_swp_mksoft_dirty(pte); > + if (pte_swp_uffd_wp(*src_pte)) > + pte = pte_swp_mkuffd_wp(pte); > + set_pte_at(src_mm, addr, src_pte, pte); > + } This needs to have the same logic as we now have in copy_present_page(). The page *is* present and we can't copy the PTE value hidden in a swap entry if we can't copy the PTE normally. The code should be shared because nobody is going to remember about this corner case. Jason