From patchwork Tue Oct 12 17:12:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Sierra Guiza, Alejandro (Alex)" X-Patchwork-Id: 12553265 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 27465C4321E for ; Tue, 12 Oct 2021 17:13:07 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id B433660F38 for ; Tue, 12 Oct 2021 17:13:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org B433660F38 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=amd.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 5A56C900004; Tue, 12 Oct 2021 13:13:06 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 52C95900002; Tue, 12 Oct 2021 13:13:06 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3CD50900004; Tue, 12 Oct 2021 13:13:06 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0158.hostedemail.com [216.40.44.158]) by kanga.kvack.org (Postfix) with ESMTP id 2F230900002 for ; Tue, 12 Oct 2021 13:13:06 -0400 (EDT) Received: from smtpin28.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id C2D3B39B2D for ; Tue, 12 Oct 2021 17:13:05 +0000 (UTC) X-FDA: 78688430730.28.5BD3AB7 Received: from NAM04-MW2-obe.outbound.protection.outlook.com (mail-mw2nam08on2051.outbound.protection.outlook.com [40.107.101.51]) by imf19.hostedemail.com (Postfix) with ESMTP id 4ADD6B0000AD for ; Tue, 12 Oct 2021 17:13:05 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Q2VPpTvDvyxWPkGTVFwOSf/gV96ZUfijuM3e2pD7yiqQiEudvKDhkt9skX1kNGoqmhEC0zZ32ok0xPC2EFGiHIuVxa6i3u4PTAh/Gdiz93oESsdKarPFPfILEqxlGNVDmYtxsu8lkR8VYT08zjcjKRSq5wPxtrVvaJ8/Jr1ujrZJ9cGqOj9WLVRUYKbs3pQJmPkVxTdpe9We3k+cs1Rr6C9maV2JPxR+AJ+p9/KxavD6HOma1X570Eh8qc0P34VJP2GYztlxjV0eG/c5N2hhVG+xWlRVR9n6zXrEd7i7m8PXDiPbnibVo4H0oACVfmGb+MJLEhv0Tp6hnXVEnMAX2g== 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=prqqgRWlNmUY+FCzPMwMlLKkTVbC2ZOWpWdIq8n/6hw=; b=Lb5Qg+CPF4sDaEJkxridy8L2rJnXquolU+UL/QMcHfoVoYP46tGr1krZhJ7NAMHmL86YzwrymoujchfK4JW6owAq9XxaTpz/7PW2gYA3dw1Xv0foWOlxRDgqOKuYWmOWsKu+KHzYRPpVYvV4T6wpVoJk2jrOZAa62dQYPu37no5WJQ4rAmG7neOMP+ktgqeR9okjRFFecVqOODjM92vgNYQayyqwE1eEwTE9FagTJFardbNcLcqUpUKLJGvo4PrWpYwf2P8PaHwFOhy2TLOCHXA0yVZgNvqPIg3mZbmJeySP5XZOeOwgXnq1jf+T2ppS6pYYCo3Inke19QpCg6lt4A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=linux-foundation.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=prqqgRWlNmUY+FCzPMwMlLKkTVbC2ZOWpWdIq8n/6hw=; b=W299mrfcLzyYpKyLdyQ0Quo0yXPX3ylduTuyWyZQcFDnirtn7NucX5b4ebrTdrrS2UdDRJa0/6sfZ+lWohnNoNAeOk9wj6nbNGAhalU+g+TzwhT3IOW8HX0BoWhf7RKAei6EMgCh6v0PfaSOGS9cq3n4RgOmUJgSzy4R7V6n0ts= Received: from MW4PR04CA0284.namprd04.prod.outlook.com (2603:10b6:303:89::19) by SA0PR12MB4512.namprd12.prod.outlook.com (2603:10b6:806:71::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4587.20; Tue, 12 Oct 2021 17:13:01 +0000 Received: from CO1NAM11FT005.eop-nam11.prod.protection.outlook.com (2603:10b6:303:89:cafe::43) by MW4PR04CA0284.outlook.office365.com (2603:10b6:303:89::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4587.25 via Frontend Transport; Tue, 12 Oct 2021 17:13:01 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; linux-foundation.org; dkim=none (message not signed) header.d=none;linux-foundation.org; dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; Received: from SATLEXMB04.amd.com (165.204.84.17) by CO1NAM11FT005.mail.protection.outlook.com (10.13.174.147) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4587.18 via Frontend Transport; Tue, 12 Oct 2021 17:13:01 +0000 Received: from alex-MS-7B09.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.8; Tue, 12 Oct 2021 12:12:58 -0500 From: Alex Sierra To: , , , , , CC: , , , , , Subject: [PATCH v1 01/12] ext4/xfs: add page refcount helper Date: Tue, 12 Oct 2021 12:12:36 -0500 Message-ID: <20211012171247.2861-2-alex.sierra@amd.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20211012171247.2861-1-alex.sierra@amd.com> References: <20211012171247.2861-1-alex.sierra@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 8e3ea715-00a1-4afb-5580-08d98da38bac X-MS-TrafficTypeDiagnostic: SA0PR12MB4512: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:3044; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 0jtMTfNAceBhf8FQmAGtJoBdU7jveQ/4yan0XVhsAoqNyHR3XrSzcIs+JJ3kPYTiKPJuGd5HcRq1ysyXZ8Uzv81vreesR+Bl2pCHx6/FpiTx4HYu167XAkqfyaIBaEnWx5p3U22UFDg/1dwaF+7xkQOlr5QlojKUUCO8IbJ+8iRr+gxrJBGm92OHNFUKj5ZJCK+H3U32xXMxyqzMEQRhFwNDRwqp3VgWt7Hsj01+ywBKjE4h8KwOLUe8UIM6EYse0WUygxM5M5hWlJyYH/vejVnMdzpcqVU/lyRGEv/8nMKc+uVUn6zK/LvBuMT6L+HJY2Mzof4Yql+tSxRwNR5UUNUboCRg4dV/jDic7Q0vcI7f8/87dOTtW0jTSR7BZ229aX2LpQIpJPX3JYcte4jjcopgzH6Xb5eb5Quuc62whqZYs8B+kONoPdbFlS9HfQW77ubcvzUxD9mt2rOLP1DL/wjGvQqXIoXm3fydffjyMhczopYa8eKmIYuGQhr+NeH3MPNfRM/4ZLM8TvbcGwqCfJCEtAlEGWSNb7MTXTCwxD19GoGAJedDDB7bmc7BluurpwHpodgqPQ9sWdaku6gcctXLAe3/seVQu+xz8sGirqavCT6mIvC9x5XiFpxHZO6hnDfKRDMZEw1SMaTIgCXvBumPfKNFAohxf4YUiBUuJJD6h9s2YiaEMOjQ4kYahKTnV6sqFfOoAZRzTCW8vWSO3MfvcQbPLkFuFzlJpIaz4AE= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(4636009)(36840700001)(46966006)(8676002)(336012)(7416002)(7696005)(86362001)(36860700001)(4326008)(83380400001)(1076003)(2906002)(316002)(44832011)(5660300002)(81166007)(2616005)(426003)(54906003)(186003)(16526019)(82310400003)(8936002)(6666004)(508600001)(70586007)(70206006)(47076005)(26005)(110136005)(356005)(36756003)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Oct 2021 17:13:01.0389 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 8e3ea715-00a1-4afb-5580-08d98da38bac X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT005.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA0PR12MB4512 Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=W299mrfc; spf=pass (imf19.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.101.51 as permitted sender) smtp.mailfrom=Alex.Sierra@amd.com; dmarc=pass (policy=quarantine) header.from=amd.com X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 4ADD6B0000AD X-Stat-Signature: gr45xxd367m59kc4wjz75ztkirjo6sif X-HE-Tag: 1634058785-594264 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: From: Ralph Campbell There are several places where ZONE_DEVICE struct pages assume a reference count == 1 means the page is idle and free. Instead of open coding this, add a helper function to hide this detail. Signed-off-by: Ralph Campbell Signed-off-by: Alex Sierra Reviewed-by: Christoph Hellwig Acked-by: Theodore Ts'o Acked-by: Darrick J. Wong --- v3: [AS]: rename dax_layout_is_idle_page func to dax_page_unused v4: [AS]: This ref count functionality was missing on fuse/dax.c. --- fs/dax.c | 4 ++-- fs/ext4/inode.c | 5 +---- fs/fuse/dax.c | 4 +--- fs/xfs/xfs_file.c | 4 +--- include/linux/dax.h | 10 ++++++++++ 5 files changed, 15 insertions(+), 12 deletions(-) diff --git a/fs/dax.c b/fs/dax.c index 62352cbcf0f4..c387d09e3e5a 100644 --- a/fs/dax.c +++ b/fs/dax.c @@ -369,7 +369,7 @@ static void dax_disassociate_entry(void *entry, struct address_space *mapping, for_each_mapped_pfn(entry, pfn) { struct page *page = pfn_to_page(pfn); - WARN_ON_ONCE(trunc && page_ref_count(page) > 1); + WARN_ON_ONCE(trunc && !dax_page_unused(page)); WARN_ON_ONCE(page->mapping && page->mapping != mapping); page->mapping = NULL; page->index = 0; @@ -383,7 +383,7 @@ static struct page *dax_busy_page(void *entry) for_each_mapped_pfn(entry, pfn) { struct page *page = pfn_to_page(pfn); - if (page_ref_count(page) > 1) + if (!dax_page_unused(page)) return page; } return NULL; diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index fe6045a46599..05ffe6875cb1 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -3971,10 +3971,7 @@ int ext4_break_layouts(struct inode *inode) if (!page) return 0; - error = ___wait_var_event(&page->_refcount, - atomic_read(&page->_refcount) == 1, - TASK_INTERRUPTIBLE, 0, 0, - ext4_wait_dax_page(ei)); + error = dax_wait_page(ei, page, ext4_wait_dax_page); } while (error == 0); return error; diff --git a/fs/fuse/dax.c b/fs/fuse/dax.c index ff99ab2a3c43..2b1f190ba78a 100644 --- a/fs/fuse/dax.c +++ b/fs/fuse/dax.c @@ -677,9 +677,7 @@ static int __fuse_dax_break_layouts(struct inode *inode, bool *retry, return 0; *retry = true; - return ___wait_var_event(&page->_refcount, - atomic_read(&page->_refcount) == 1, TASK_INTERRUPTIBLE, - 0, 0, fuse_wait_dax_page(inode)); + return dax_wait_page(inode, page, fuse_wait_dax_page); } /* dmap_end == 0 leads to unmapping of whole file */ diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c index 396ef36dcd0a..182057281086 100644 --- a/fs/xfs/xfs_file.c +++ b/fs/xfs/xfs_file.c @@ -840,9 +840,7 @@ xfs_break_dax_layouts( return 0; *retry = true; - return ___wait_var_event(&page->_refcount, - atomic_read(&page->_refcount) == 1, TASK_INTERRUPTIBLE, - 0, 0, xfs_wait_dax_page(inode)); + return dax_wait_page(inode, page, xfs_wait_dax_page); } int diff --git a/include/linux/dax.h b/include/linux/dax.h index b52f084aa643..8b5da1d60dbc 100644 --- a/include/linux/dax.h +++ b/include/linux/dax.h @@ -243,6 +243,16 @@ static inline bool dax_mapping(struct address_space *mapping) return mapping->host && IS_DAX(mapping->host); } +static inline bool dax_page_unused(struct page *page) +{ + return page_ref_count(page) == 1; +} + +#define dax_wait_page(_inode, _page, _wait_cb) \ + ___wait_var_event(&(_page)->_refcount, \ + dax_page_unused(_page), \ + TASK_INTERRUPTIBLE, 0, 0, _wait_cb(_inode)) + #ifdef CONFIG_DEV_DAX_HMEM_DEVICES void hmem_register_device(int target_nid, struct resource *r); #else From patchwork Tue Oct 12 17:12:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Sierra Guiza, Alejandro (Alex)" X-Patchwork-Id: 12553267 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7E578C433FE for ; Tue, 12 Oct 2021 17:13:08 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 21CC860F21 for ; Tue, 12 Oct 2021 17:13:08 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 21CC860F21 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=amd.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id A600E900002; Tue, 12 Oct 2021 13:13:06 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A0F2F900005; Tue, 12 Oct 2021 13:13:06 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 887DA900002; Tue, 12 Oct 2021 13:13:06 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0204.hostedemail.com [216.40.44.204]) by kanga.kvack.org (Postfix) with ESMTP id 6E1F2900005 for ; Tue, 12 Oct 2021 13:13:06 -0400 (EDT) Received: from smtpin31.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 1DDAC183E39A8 for ; Tue, 12 Oct 2021 17:13:06 +0000 (UTC) X-FDA: 78688430772.31.42C154A Received: from NAM02-BN1-obe.outbound.protection.outlook.com (mail-bn1nam07on2051.outbound.protection.outlook.com [40.107.212.51]) by imf26.hostedemail.com (Postfix) with ESMTP id 76B3A20019C6 for ; Tue, 12 Oct 2021 17:13:05 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fKZMvkNcs+k7FTQOHyJCb7mTllQlpvI5j0srXqlRkRKrp3P6Y4a4nCLP5efBoOUnOLNSihNIAB3AgLfRJkRVbC28l63q8mMyNRmC7SAJQKSrimfHLrtq+8EyPG/u2fkBgcEf7rhXuThF1kLjSvVdRuSU8NwRPy7gdN9lhHtr7WVgjkg9XWokeR50Uy7IhMdc0Y8WZaXOAqOElPriRe8H1AtL1N453iF3Hk+a+hCO5FP3Ba60K1pQJ990ECbwEVlZjr8CzDf3UW43AcIJjdktcYCg7xEosw4nRi58EsGXUzUroX/qHmWscWYkwxCKOUVMEZ2csKeFFEX08KuXZ3uI6g== 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=YOpucbc/fJ96/axSQRUqL6YobnSoy0nbWQSNVNqOGY4=; b=U1GS8qq4ah7E2/6/Pdh78gF5GmmCSzBkW1UBIFko8nQkyiCt4KFTEiaj3+/D8iWL1E6uymPgR41asFV9xgbWF0aPiRXHVRGGNExTWcbUzQhcyGLFsnyHV/Q6w87tls8mE7/OfPZZPXNcL66MeLR6+CiEqmEyKYWq6ZU4orpC2WFiQv+kdpTQ4lOOxT6yybntXTP5R2buY5KUxWYXJpzK36cCWMjQR6aReKI5sSZbTjxw+uUUxR8OP78DqLKw9vdpmAQAnCHuhwRaS+b2ZZNUQFWVTOpUc5kBFunbph0ntgb+pGABNSJBsawwh2E5jtjfyUrZ7gPhmczZTKnch+hVGg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=linux-foundation.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=YOpucbc/fJ96/axSQRUqL6YobnSoy0nbWQSNVNqOGY4=; b=KH+TBfdUo0htyY1nfbwE1mP2gJvQzCrkbkLm4kYxRgNJYZnM1kAhT3jxdVvr6jdsEgicgPRJ82FkTgUwBR1igzoQT+xV/TuYxGtDAV+6f7/LPGh5GAljKLY3hwE/aiTSsRRjUXhwNIrpQsguoplpESRzW3NtJeo/vYzG0fr/zeM= Received: from MW4PR04CA0278.namprd04.prod.outlook.com (2603:10b6:303:89::13) by MWHPR1201MB0125.namprd12.prod.outlook.com (2603:10b6:301:55::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4587.25; Tue, 12 Oct 2021 17:13:02 +0000 Received: from CO1NAM11FT005.eop-nam11.prod.protection.outlook.com (2603:10b6:303:89:cafe::85) by MW4PR04CA0278.outlook.office365.com (2603:10b6:303:89::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4608.14 via Frontend Transport; Tue, 12 Oct 2021 17:13:02 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; linux-foundation.org; dkim=none (message not signed) header.d=none;linux-foundation.org; dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; Received: from SATLEXMB04.amd.com (165.204.84.17) by CO1NAM11FT005.mail.protection.outlook.com (10.13.174.147) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4587.18 via Frontend Transport; Tue, 12 Oct 2021 17:13:01 +0000 Received: from alex-MS-7B09.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.8; Tue, 12 Oct 2021 12:12:59 -0500 From: Alex Sierra To: , , , , , CC: , , , , , Subject: [PATCH v1 02/12] mm: remove extra ZONE_DEVICE struct page refcount Date: Tue, 12 Oct 2021 12:12:37 -0500 Message-ID: <20211012171247.2861-3-alex.sierra@amd.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20211012171247.2861-1-alex.sierra@amd.com> References: <20211012171247.2861-1-alex.sierra@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 8c2fa014-4974-4dca-daa1-08d98da38c39 X-MS-TrafficTypeDiagnostic: MWHPR1201MB0125: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8882; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: SnOREwGvCCU510shuhN2tqejHQeQi5JapATL2xb58QxTOQe5no5L5QHmLaNAVzJC6FgZQwTefQ4ERZaVBjnsFWoP5w7+uqMQPSl6SDo5Xt3VdoAKiz7zf32tQnrQ7V1y9tjjr59jJu1W1sy0W7v1tm0B7HVArhnSYsD7lATv+QeTD9THb053kgG4eD0g2dvGnViqZEcla4YuNsmme8HneeiLcTiB3sqrsX47QGMWuCF5AZpXwdRg4Zt4IekpXgcAjIwEO7W0IikCtMdTpCjfke8H7c6so3BJLXwaV/SIWIzkFfuvVt3GthH+gqPI8bJ/WTRpu3PeATTtKuP19IjexD+pyc4+WnJA8pip4BczmWdKvrg1IoMDZaBhHvcTIHcz0tWIn1Gj++bDuxTVXfafHi6qNdZTRf/L2pLVQ8sK8XmVyDNa9C+cPWBId/GiE5p+48X3hrMS1oEcv6IkPo4fLFS3OlUktTZb4rfkKSX0zWfTtVpfVw8ENnTF7Q1m01+Bb+ZJFQ2rmrwq9cnmQ3sWQbm53a494Gp3mck2ZjdsL8L13ZFczdc1ri70+l61JiR7EqZm8SOUb/as7kBGtsmGbPClxfmQMLwDdrYb0ly8Wy9xxeUMKGAifjgSVkb2aIaNNdDFfvYZpLgMKgxScg1sAjseBVa+SuedafihhjVyarLallM0KMpjYSAuZRko+nbdEkF15b6KTgivSdoYr66yLIcLJTARXDMbgLpjPYl/WRBCPDd9yF7teddNiakybLifgyipX47FUwtuA/auOZ2DQ5/X3cKNfJqQeslIY2Xlz+SpGsR4itVSmeI5xxvpvVmsCKXTpd6z8CPpQIZhiSl0waSPDlLSHJs3ODiv/pp9mfg= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(4636009)(36840700001)(46966006)(44832011)(81166007)(26005)(36756003)(54906003)(356005)(30864003)(47076005)(508600001)(7696005)(2906002)(82310400003)(966005)(5660300002)(110136005)(36860700001)(16526019)(6666004)(1076003)(186003)(4326008)(8676002)(8936002)(7416002)(83380400001)(2616005)(336012)(70586007)(70206006)(86362001)(426003)(316002)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Oct 2021 17:13:01.9584 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 8c2fa014-4974-4dca-daa1-08d98da38c39 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT005.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR1201MB0125 X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 76B3A20019C6 X-Stat-Signature: rrtnau7ms1ioksc9d478j47jmb9zsqew Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=KH+TBfdU; dmarc=pass (policy=quarantine) header.from=amd.com; spf=pass (imf26.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.212.51 as permitted sender) smtp.mailfrom=Alex.Sierra@amd.com X-HE-Tag: 1634058785-697516 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: From: Ralph Campbell ZONE_DEVICE struct pages have an extra reference count that complicates the code for put_page() and several places in the kernel that need to check the reference count to see that a page is not being used (gup, compaction, migration, etc.). Clean up the code so the reference count doesn't need to be treated specially for ZONE_DEVICE. Signed-off-by: Ralph Campbell Signed-off-by: Alex Sierra Reviewed-by: Christoph Hellwig --- v2: AS: merged this patch in linux 5.11 version v5: AS: add condition at try_grab_page to check for the zone device type, while page ref counter is checked less/equal to zero. In case of device zone, pages ref counter are initialized to zero. v7: AS: fix condition at try_grab_page added at v5, is invalid. It supposed to fix xfstests/generic/413 test, however, there's a known issue on this test where DAX mapped area DIO to non-DAX expect to fail. https://patchwork.kernel.org/project/fstests/patch/1489463960-3579-1-git-send-email-xzhou@redhat.com This condition was removed after rebase over patch series https://lore.kernel.org/r/20210813044133.1536842-4-jhubbard@nvidia.com --- arch/powerpc/kvm/book3s_hv_uvmem.c | 2 +- drivers/gpu/drm/nouveau/nouveau_dmem.c | 2 +- fs/dax.c | 4 +- include/linux/dax.h | 2 +- include/linux/memremap.h | 7 +-- include/linux/mm.h | 11 ---- lib/test_hmm.c | 2 +- mm/internal.h | 8 +++ mm/memcontrol.c | 6 +-- mm/memremap.c | 69 +++++++------------------- mm/migrate.c | 5 -- mm/page_alloc.c | 3 ++ mm/swap.c | 45 ++--------------- 13 files changed, 46 insertions(+), 120 deletions(-) diff --git a/arch/powerpc/kvm/book3s_hv_uvmem.c b/arch/powerpc/kvm/book3s_hv_uvmem.c index 84e5a2dc8be5..acee67710620 100644 --- a/arch/powerpc/kvm/book3s_hv_uvmem.c +++ b/arch/powerpc/kvm/book3s_hv_uvmem.c @@ -711,7 +711,7 @@ static struct page *kvmppc_uvmem_get_page(unsigned long gpa, struct kvm *kvm) dpage = pfn_to_page(uvmem_pfn); dpage->zone_device_data = pvt; - get_page(dpage); + init_page_count(dpage); lock_page(dpage); return dpage; out_clear: diff --git a/drivers/gpu/drm/nouveau/nouveau_dmem.c b/drivers/gpu/drm/nouveau/nouveau_dmem.c index 92987daa5e17..8bc7120e1216 100644 --- a/drivers/gpu/drm/nouveau/nouveau_dmem.c +++ b/drivers/gpu/drm/nouveau/nouveau_dmem.c @@ -324,7 +324,7 @@ nouveau_dmem_page_alloc_locked(struct nouveau_drm *drm) return NULL; } - get_page(page); + init_page_count(page); lock_page(page); return page; } diff --git a/fs/dax.c b/fs/dax.c index c387d09e3e5a..1166630b7190 100644 --- a/fs/dax.c +++ b/fs/dax.c @@ -571,14 +571,14 @@ static void *grab_mapping_entry(struct xa_state *xas, /** * dax_layout_busy_page_range - find first pinned page in @mapping - * @mapping: address space to scan for a page with ref count > 1 + * @mapping: address space to scan for a page with ref count > 0 * @start: Starting offset. Page containing 'start' is included. * @end: End offset. Page containing 'end' is included. If 'end' is LLONG_MAX, * pages from 'start' till the end of file are included. * * DAX requires ZONE_DEVICE mapped pages. These pages are never * 'onlined' to the page allocator so they are considered idle when - * page->count == 1. A filesystem uses this interface to determine if + * page->count == 0. A filesystem uses this interface to determine if * any page in the mapping is busy, i.e. for DMA, or other * get_user_pages() usages. * diff --git a/include/linux/dax.h b/include/linux/dax.h index 8b5da1d60dbc..05fc982ce153 100644 --- a/include/linux/dax.h +++ b/include/linux/dax.h @@ -245,7 +245,7 @@ static inline bool dax_mapping(struct address_space *mapping) static inline bool dax_page_unused(struct page *page) { - return page_ref_count(page) == 1; + return page_ref_count(page) == 0; } #define dax_wait_page(_inode, _page, _wait_cb) \ diff --git a/include/linux/memremap.h b/include/linux/memremap.h index 45a79da89c5f..77ff5fd0685f 100644 --- a/include/linux/memremap.h +++ b/include/linux/memremap.h @@ -66,9 +66,10 @@ enum memory_type { struct dev_pagemap_ops { /* - * Called once the page refcount reaches 1. (ZONE_DEVICE pages never - * reach 0 refcount unless there is a refcount bug. This allows the - * device driver to implement its own memory management.) + * Called once the page refcount reaches 0. The reference count + * should be reset to one with init_page_count(page) before reusing + * the page. This allows the device driver to implement its own + * memory management. */ void (*page_free)(struct page *page); diff --git a/include/linux/mm.h b/include/linux/mm.h index d8f98d652164..e24c904deeec 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -1220,17 +1220,6 @@ static inline void put_page(struct page *page) { page = compound_head(page); - /* - * For devmap managed pages we need to catch refcount transition from - * 2 to 1, when refcount reach one it means the page is free and we - * need to inform the device driver through callback. See - * include/linux/memremap.h and HMM for details. - */ - if (page_is_devmap_managed(page)) { - put_devmap_managed_page(page); - return; - } - if (put_page_testzero(page)) __put_page(page); } diff --git a/lib/test_hmm.c b/lib/test_hmm.c index 80a78877bd93..6998f10350ea 100644 --- a/lib/test_hmm.c +++ b/lib/test_hmm.c @@ -561,7 +561,7 @@ static struct page *dmirror_devmem_alloc_page(struct dmirror_device *mdevice) } dpage->zone_device_data = rpage; - get_page(dpage); + init_page_count(dpage); lock_page(dpage); return dpage; diff --git a/mm/internal.h b/mm/internal.h index e8fdb531f887..5438cceca4b9 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -667,4 +667,12 @@ int vmap_pages_range_noflush(unsigned long addr, unsigned long end, void vunmap_range_noflush(unsigned long start, unsigned long end); +#ifdef CONFIG_DEV_PAGEMAP_OPS +void free_zone_device_page(struct page *page); +#else +static inline void free_zone_device_page(struct page *page) +{ +} +#endif + #endif /* __MM_INTERNAL_H */ diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 64ada9e650a5..9a6bfb4fd36c 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -5350,11 +5350,7 @@ static struct page *mc_handle_swap_pte(struct vm_area_struct *vma, */ if (is_device_private_entry(ent)) { page = device_private_entry_to_page(ent); - /* - * MEMORY_DEVICE_PRIVATE means ZONE_DEVICE page and which have - * a refcount of 1 when free (unlike normal page) - */ - if (!page_ref_add_unless(page, 1, 1)) + if (!get_page_unless_zero(page)) return NULL; return page; } diff --git a/mm/memremap.c b/mm/memremap.c index 15a074ffb8d7..ab949a571e78 100644 --- a/mm/memremap.c +++ b/mm/memremap.c @@ -12,6 +12,7 @@ #include #include #include +#include "internal.h" static DEFINE_XARRAY(pgmap_array); @@ -37,32 +38,6 @@ unsigned long memremap_compat_align(void) EXPORT_SYMBOL_GPL(memremap_compat_align); #endif -#ifdef CONFIG_DEV_PAGEMAP_OPS -DEFINE_STATIC_KEY_FALSE(devmap_managed_key); -EXPORT_SYMBOL(devmap_managed_key); - -static void devmap_managed_enable_put(struct dev_pagemap *pgmap) -{ - if (pgmap->type == MEMORY_DEVICE_PRIVATE || - pgmap->type == MEMORY_DEVICE_FS_DAX) - static_branch_dec(&devmap_managed_key); -} - -static void devmap_managed_enable_get(struct dev_pagemap *pgmap) -{ - if (pgmap->type == MEMORY_DEVICE_PRIVATE || - pgmap->type == MEMORY_DEVICE_FS_DAX) - static_branch_inc(&devmap_managed_key); -} -#else -static void devmap_managed_enable_get(struct dev_pagemap *pgmap) -{ -} -static void devmap_managed_enable_put(struct dev_pagemap *pgmap) -{ -} -#endif /* CONFIG_DEV_PAGEMAP_OPS */ - static void pgmap_array_delete(struct range *range) { xa_store_range(&pgmap_array, PHYS_PFN(range->start), PHYS_PFN(range->end), @@ -102,16 +77,6 @@ static unsigned long pfn_end(struct dev_pagemap *pgmap, int range_id) return (range->start + range_len(range)) >> PAGE_SHIFT; } -static unsigned long pfn_next(unsigned long pfn) -{ - if (pfn % 1024 == 0) - cond_resched(); - return pfn + 1; -} - -#define for_each_device_pfn(pfn, map, i) \ - for (pfn = pfn_first(map, i); pfn < pfn_end(map, i); pfn = pfn_next(pfn)) - static void dev_pagemap_kill(struct dev_pagemap *pgmap) { if (pgmap->ops && pgmap->ops->kill) @@ -167,20 +132,18 @@ static void pageunmap_range(struct dev_pagemap *pgmap, int range_id) void memunmap_pages(struct dev_pagemap *pgmap) { - unsigned long pfn; int i; dev_pagemap_kill(pgmap); for (i = 0; i < pgmap->nr_range; i++) - for_each_device_pfn(pfn, pgmap, i) - put_page(pfn_to_page(pfn)); + percpu_ref_put_many(pgmap->ref, pfn_end(pgmap, i) - + pfn_first(pgmap, i)); dev_pagemap_cleanup(pgmap); for (i = 0; i < pgmap->nr_range; i++) pageunmap_range(pgmap, i); WARN_ONCE(pgmap->altmap.alloc, "failed to free all reserved pages\n"); - devmap_managed_enable_put(pgmap); } EXPORT_SYMBOL_GPL(memunmap_pages); @@ -382,8 +345,6 @@ void *memremap_pages(struct dev_pagemap *pgmap, int nid) } } - devmap_managed_enable_get(pgmap); - /* * Clear the pgmap nr_range as it will be incremented for each * successfully processed range. This communicates how many @@ -498,16 +459,9 @@ struct dev_pagemap *get_dev_pagemap(unsigned long pfn, EXPORT_SYMBOL_GPL(get_dev_pagemap); #ifdef CONFIG_DEV_PAGEMAP_OPS -void free_devmap_managed_page(struct page *page) +static void free_device_page(struct page *page) { - /* notify page idle for dax */ - if (!is_device_private_page(page)) { - wake_up_var(&page->_refcount); - return; - } - __ClearPageWaiters(page); - mem_cgroup_uncharge(page); /* @@ -534,4 +488,19 @@ void free_devmap_managed_page(struct page *page) page->mapping = NULL; page->pgmap->ops->page_free(page); } + +void free_zone_device_page(struct page *page) +{ + switch (page->pgmap->type) { + case MEMORY_DEVICE_PRIVATE: + free_device_page(page); + return; + case MEMORY_DEVICE_FS_DAX: + /* notify page idle */ + wake_up_var(&page->_refcount); + return; + default: + return; + } +} #endif /* CONFIG_DEV_PAGEMAP_OPS */ diff --git a/mm/migrate.c b/mm/migrate.c index 41ff2c9896c4..e3a10e2a1bb3 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -350,11 +350,6 @@ static int expected_page_refs(struct address_space *mapping, struct page *page) { int expected_count = 1; - /* - * Device private pages have an extra refcount as they are - * ZONE_DEVICE pages. - */ - expected_count += is_device_private_page(page); if (mapping) expected_count += thp_nr_pages(page) + page_has_private(page); diff --git a/mm/page_alloc.c b/mm/page_alloc.c index ef2265f86b91..1ef1f733af5b 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -6414,6 +6414,9 @@ void __ref memmap_init_zone_device(struct zone *zone, __init_single_page(page, pfn, zone_idx, nid); + /* ZONE_DEVICE pages start with a zero reference count. */ + set_page_count(page, 0); + /* * Mark page reserved as it will need to wait for onlining * phase for it to be fully associated with a zone. diff --git a/mm/swap.c b/mm/swap.c index dfb48cf9c2c9..9e821f1951c5 100644 --- a/mm/swap.c +++ b/mm/swap.c @@ -114,12 +114,11 @@ static void __put_compound_page(struct page *page) void __put_page(struct page *page) { if (is_zone_device_page(page)) { - put_dev_pagemap(page->pgmap); - /* * The page belongs to the device that created pgmap. Do * not return it to page allocator. */ + free_zone_device_page(page); return; } @@ -917,29 +916,18 @@ void release_pages(struct page **pages, int nr) if (is_huge_zero_page(page)) continue; + if (!put_page_testzero(page)) + continue; + if (is_zone_device_page(page)) { if (lruvec) { unlock_page_lruvec_irqrestore(lruvec, flags); lruvec = NULL; } - /* - * ZONE_DEVICE pages that return 'false' from - * page_is_devmap_managed() do not require special - * processing, and instead, expect a call to - * put_page_testzero(). - */ - if (page_is_devmap_managed(page)) { - put_devmap_managed_page(page); - continue; - } - if (put_page_testzero(page)) - put_dev_pagemap(page->pgmap); + free_zone_device_page(page); continue; } - if (!put_page_testzero(page)) - continue; - if (PageCompound(page)) { if (lruvec) { unlock_page_lruvec_irqrestore(lruvec, flags); @@ -1143,26 +1131,3 @@ void __init swap_setup(void) * _really_ don't want to cluster much more */ } - -#ifdef CONFIG_DEV_PAGEMAP_OPS -void put_devmap_managed_page(struct page *page) -{ - int count; - - if (WARN_ON_ONCE(!page_is_devmap_managed(page))) - return; - - count = page_ref_dec_return(page); - - /* - * devmap page refcounts are 1-based, rather than 0-based: if - * refcount is 1, then the page is free and the refcount is - * stable because nobody holds a reference on the page. - */ - if (count == 1) - free_devmap_managed_page(page); - else if (!count) - __put_page(page); -} -EXPORT_SYMBOL(put_devmap_managed_page); -#endif From patchwork Tue Oct 12 17:12:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Sierra Guiza, Alejandro (Alex)" X-Patchwork-Id: 12553269 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C7689C433F5 for ; Tue, 12 Oct 2021 17:13:10 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 79A5560F21 for ; Tue, 12 Oct 2021 17:13:10 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 79A5560F21 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=amd.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 4E37C900006; Tue, 12 Oct 2021 13:13:07 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3CD76900005; Tue, 12 Oct 2021 13:13:07 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2217A900006; Tue, 12 Oct 2021 13:13:07 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0164.hostedemail.com [216.40.44.164]) by kanga.kvack.org (Postfix) with ESMTP id 0C2B1900005 for ; Tue, 12 Oct 2021 13:13:07 -0400 (EDT) Received: from smtpin24.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id B9F28183E603C for ; Tue, 12 Oct 2021 17:13:06 +0000 (UTC) X-FDA: 78688430772.24.EE08F07 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2055.outbound.protection.outlook.com [40.107.220.55]) by imf14.hostedemail.com (Postfix) with ESMTP id 414BE6001991 for ; Tue, 12 Oct 2021 17:13:06 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=flxfKHN2zpfAsuKbV21hvaQA6xo350N6RW58Tt3BlSgEJtShX9apzUMzPl97U9R3mLk5PoyKKjCOXl0ZwpaGhM0gSzON28L7Wj5Dvk1g0U4fGBCLL836tTB/CL/BEdCsSLIDRDcQZARKsd//miLvJMhb0TXyFMmAakG1dXh1jl1asAZWWaQW9vp2YmowPlSY4hdOqBg7O+xnJGM833xn32iVk2kwY7v+245HWrjHWmlJH92G/a/b+mEtb3oA3ZPgTYj/vJrtJstdevxUPu00tE54aXujedCnAkzN/jo28w7C8RZjr1cNWhIzCOqPSk1bQDOfPZOGafxVUv0GKkl2Wg== 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=w3JARPoydLGt1UDbIwVdt/aNNvnM7zBb7jbo/f49f+o=; b=YoJguOy7WsdsFLjaHPFJ4HGmP1lCwrbe9fUEZDYUs4mvMHlQPsmpsHY71GHkynFyrzEttrzdM0kEqSHPFwXa9sD5pJGlEMm9OJ4kHwHm25+jEEuXWDfmux77g+kXx/350TdEsIefuX/sYy1Joe/LnZjmQBb0PEl91Fsk2vsPYG1nUOoD2rnHCv61L9KLuyP5txUV6pd94v/s1r6KJpG+RE3sW/RnsUXSwDlhjcasZGn8n18rjDuqrXMivp0FuqUb+gG4OXJtd2clLc8fewILU4avar43eHei5gJq1jm9MQjeS0ScYIxVDsI6p5XDCkCDrxmazaBe4v1Xa9d6SS+hCA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=linux-foundation.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=w3JARPoydLGt1UDbIwVdt/aNNvnM7zBb7jbo/f49f+o=; b=Y4nkbjZIJjPGJCDkXZYncRUwvZs0dfaUNWsLT885bEimkPFx9i8vBUNYPlcfc6y0nuzKEQNuaKz+dCGou3yzuWz3X5SS/RnRhGM673pVS2ttNiw2IvIrLFALHKiNBzaJa+uwp8grefi7UtWq1MD17hdHUh1WHsG+3NJ0CqkeXGs= Received: from MW4PR04CA0285.namprd04.prod.outlook.com (2603:10b6:303:89::20) by MN2PR12MB3423.namprd12.prod.outlook.com (2603:10b6:208:cb::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4587.19; Tue, 12 Oct 2021 17:13:03 +0000 Received: from CO1NAM11FT005.eop-nam11.prod.protection.outlook.com (2603:10b6:303:89:cafe::f2) by MW4PR04CA0285.outlook.office365.com (2603:10b6:303:89::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4587.19 via Frontend Transport; Tue, 12 Oct 2021 17:13:03 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; linux-foundation.org; dkim=none (message not signed) header.d=none;linux-foundation.org; dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; Received: from SATLEXMB04.amd.com (165.204.84.17) by CO1NAM11FT005.mail.protection.outlook.com (10.13.174.147) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4587.18 via Frontend Transport; Tue, 12 Oct 2021 17:13:02 +0000 Received: from alex-MS-7B09.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.8; Tue, 12 Oct 2021 12:13:00 -0500 From: Alex Sierra To: , , , , , CC: , , , , , Subject: [PATCH v1 03/12] mm: add zone device coherent type memory support Date: Tue, 12 Oct 2021 12:12:38 -0500 Message-ID: <20211012171247.2861-4-alex.sierra@amd.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20211012171247.2861-1-alex.sierra@amd.com> References: <20211012171247.2861-1-alex.sierra@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 236139f5-bc16-4995-8fc3-08d98da38cc3 X-MS-TrafficTypeDiagnostic: MN2PR12MB3423: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8882; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: wkG+W1gtKysYliQM0nqipM15O89mNmHuRRCXW9pKjvmWMoKP3kPwvfzfXYAJcHvTe+WZBd6XF1e6yTaeZoOrf7MmCDKKb9XnFMjdH7QdZzWyy9p9lNIqKq4F9dnP3Eg0sIfF5xd2jAessoJKC77c/yHgbydmf93F21HGwzBcDhDf0jrMCg/NDkXwugh6u73HT6UahUCyZg0XJcmLwDEEnGadZ8Z47ATezfX8hF+vYhXjfE6HgQlNBEhT55cFNij6eeuW6pKdaVapmKzgnQXF3Vk2gJUP+3B5TdJC0tpV+QcD/YudOfBbvQs4g/Xfi4ejzdprMcEsVLeDMqrNpDdrUnJa9zWtnX5V7qwtKuEWHIxyz1YO84rwB3LLY8zQr+sOTuE6xnDZfiFleoHcSmbamXEDIMswKsE+PBcNnqnT5CYOTtnLxEdwhmJLlyXTGLKC4fHtGEdnO0YpzrbG77rnHRlU3F6HAPEIAkRF12vyThC03sfcaCZrdj7TuIMX1oR/3UpgZ0TfJZzs64iP6OKGRlZ3JERPz4zO+R870n4V0ixEUun7Xd6s1dqBOnv7cU4v2+zKOmI2iwkMvwphRzCurHzpsHqsPAzeyORjgpscBUl9U1Y0wjar6R96dBQUYx7apHTBzw4+YmgTPuT0IjwiBT4lhrThi6QWJ9SsefDG5woATJx8otALv8JWUpUZHh5H+g7Ohqf178Svx7jFEWDURlvPgfpokB7GTP+hjfo0DM4= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(4636009)(46966006)(36840700001)(86362001)(36860700001)(83380400001)(7696005)(316002)(70206006)(16526019)(186003)(1076003)(36756003)(47076005)(8936002)(82310400003)(4326008)(7416002)(336012)(356005)(5660300002)(26005)(2616005)(2906002)(8676002)(6666004)(81166007)(508600001)(110136005)(426003)(44832011)(54906003)(70586007)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Oct 2021 17:13:02.8379 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 236139f5-bc16-4995-8fc3-08d98da38cc3 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT005.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB3423 X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 414BE6001991 X-Stat-Signature: gqcyjqb759ts49dmo4c8ysrqxfqa1em9 Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=Y4nkbjZI; spf=pass (imf14.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.220.55 as permitted sender) smtp.mailfrom=Alex.Sierra@amd.com; dmarc=pass (policy=quarantine) header.from=amd.com X-HE-Tag: 1634058786-134519 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: Device memory that is cache coherent from device and CPU point of view. This is use on platform that have an advance system bus (like CAPI or CCIX). Any page of a process can be migrated to such memory. However, no one should be allow to pin such memory so that it can always be evicted. Signed-off-by: Alex Sierra --- include/linux/memremap.h | 8 ++++++++ include/linux/mm.h | 8 ++++++++ mm/memcontrol.c | 6 +++--- mm/memory-failure.c | 6 +++++- mm/memremap.c | 2 ++ mm/migrate.c | 19 ++++++++++++------- 6 files changed, 38 insertions(+), 11 deletions(-) diff --git a/include/linux/memremap.h b/include/linux/memremap.h index 77ff5fd0685f..d64cd2e8147a 100644 --- a/include/linux/memremap.h +++ b/include/linux/memremap.h @@ -39,6 +39,13 @@ struct vmem_altmap { * A more complete discussion of unaddressable memory may be found in * include/linux/hmm.h and Documentation/vm/hmm.rst. * + * MEMORY_DEVICE_COHERENT: + * Device memory that is cache coherent from device and CPU point of view. This + * is use on platform that have an advance system bus (like CAPI or CCIX). A + * driver can hotplug the device memory using ZONE_DEVICE and with that memory + * type. Any page of a process can be migrated to such memory. However no one + * should be allow to pin such memory so that it can always be evicted. + * * MEMORY_DEVICE_FS_DAX: * Host memory that has similar access semantics as System RAM i.e. DMA * coherent and supports page pinning. In support of coordinating page @@ -59,6 +66,7 @@ struct vmem_altmap { enum memory_type { /* 0 is reserved to catch uninitialized type fields */ MEMORY_DEVICE_PRIVATE = 1, + MEMORY_DEVICE_COHERENT, MEMORY_DEVICE_FS_DAX, MEMORY_DEVICE_GENERIC, MEMORY_DEVICE_PCI_P2PDMA, diff --git a/include/linux/mm.h b/include/linux/mm.h index e24c904deeec..8bc697006a5c 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -1187,6 +1187,14 @@ static inline bool is_device_private_page(const struct page *page) page->pgmap->type == MEMORY_DEVICE_PRIVATE; } +static inline bool is_device_page(const struct page *page) +{ + return IS_ENABLED(CONFIG_DEV_PAGEMAP_OPS) && + is_zone_device_page(page) && + (page->pgmap->type == MEMORY_DEVICE_PRIVATE || + page->pgmap->type == MEMORY_DEVICE_COHERENT); +} + static inline bool is_pci_p2pdma_page(const struct page *page) { return IS_ENABLED(CONFIG_DEV_PAGEMAP_OPS) && diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 9a6bfb4fd36c..fe5a96428dce 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -5526,8 +5526,8 @@ static int mem_cgroup_move_account(struct page *page, * 2(MC_TARGET_SWAP): if the swap entry corresponding to this pte is a * target for charge migration. if @target is not NULL, the entry is stored * in target->ent. - * 3(MC_TARGET_DEVICE): like MC_TARGET_PAGE but page is MEMORY_DEVICE_PRIVATE - * (so ZONE_DEVICE page and thus not on the lru). + * 3(MC_TARGET_DEVICE): like MC_TARGET_PAGE but page is MEMORY_DEVICE_COHERENT + * or MEMORY_DEVICE_PRIVATE (so ZONE_DEVICE page and thus not on the lru). * For now we such page is charge like a regular page would be as for all * intent and purposes it is just special memory taking the place of a * regular page. @@ -5561,7 +5561,7 @@ static enum mc_target_type get_mctgt_type(struct vm_area_struct *vma, */ if (page_memcg(page) == mc.from) { ret = MC_TARGET_PAGE; - if (is_device_private_page(page)) + if (is_device_page(page)) ret = MC_TARGET_DEVICE; if (target) target->page = page; diff --git a/mm/memory-failure.c b/mm/memory-failure.c index 6f5f78885ab4..1076f5a07370 100644 --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -1373,12 +1373,16 @@ static int memory_failure_dev_pagemap(unsigned long pfn, int flags, goto unlock; } - if (pgmap->type == MEMORY_DEVICE_PRIVATE) { + switch (pgmap->type) { + case MEMORY_DEVICE_PRIVATE: + case MEMORY_DEVICE_COHERENT: /* * TODO: Handle HMM pages which may need coordination * with device-side memory. */ goto unlock; + default: + break; } /* diff --git a/mm/memremap.c b/mm/memremap.c index ab949a571e78..56033955d1f4 100644 --- a/mm/memremap.c +++ b/mm/memremap.c @@ -294,6 +294,7 @@ void *memremap_pages(struct dev_pagemap *pgmap, int nid) switch (pgmap->type) { case MEMORY_DEVICE_PRIVATE: + case MEMORY_DEVICE_COHERENT: if (!IS_ENABLED(CONFIG_DEVICE_PRIVATE)) { WARN(1, "Device private memory not supported\n"); return ERR_PTR(-EINVAL); @@ -493,6 +494,7 @@ void free_zone_device_page(struct page *page) { switch (page->pgmap->type) { case MEMORY_DEVICE_PRIVATE: + case MEMORY_DEVICE_COHERENT: free_device_page(page); return; case MEMORY_DEVICE_FS_DAX: diff --git a/mm/migrate.c b/mm/migrate.c index e3a10e2a1bb3..2bda612f3650 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -2565,7 +2565,7 @@ static bool migrate_vma_check_page(struct page *page) * FIXME proper solution is to rework migration_entry_wait() so * it does not need to take a reference on page. */ - return is_device_private_page(page); + return is_device_page(page); } /* For file back page */ @@ -2854,7 +2854,7 @@ EXPORT_SYMBOL(migrate_vma_setup); * handle_pte_fault() * do_anonymous_page() * to map in an anonymous zero page but the struct page will be a ZONE_DEVICE - * private page. + * private or coherent page. */ static void migrate_vma_insert_page(struct migrate_vma *migrate, unsigned long addr, @@ -2925,10 +2925,15 @@ static void migrate_vma_insert_page(struct migrate_vma *migrate, swp_entry = make_device_private_entry(page, vma->vm_flags & VM_WRITE); entry = swp_entry_to_pte(swp_entry); + } else if (is_device_page(page)) { + entry = pte_mkold(mk_pte(page, + READ_ONCE(vma->vm_page_prot))); + if (vma->vm_flags & VM_WRITE) + entry = pte_mkwrite(pte_mkdirty(entry)); } else { /* - * For now we only support migrating to un-addressable - * device memory. + * We support migrating to private and coherent types + * for device zone memory. */ pr_warn_once("Unsupported ZONE_DEVICE page type.\n"); goto abort; @@ -3034,10 +3039,10 @@ void migrate_vma_pages(struct migrate_vma *migrate) mapping = page_mapping(page); if (is_zone_device_page(newpage)) { - if (is_device_private_page(newpage)) { + if (is_device_page(newpage)) { /* - * For now only support private anonymous when - * migrating to un-addressable device memory. + * For now only support private and coherent + * anonymous when migrating to device memory. */ if (mapping) { migrate->src[i] &= ~MIGRATE_PFN_MIGRATE; From patchwork Tue Oct 12 17:12:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Sierra Guiza, Alejandro (Alex)" X-Patchwork-Id: 12553271 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EEB0EC4167E for ; Tue, 12 Oct 2021 17:13:12 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 9EF6E6108F for ; Tue, 12 Oct 2021 17:13:12 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 9EF6E6108F Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=amd.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id C375F900007; Tue, 12 Oct 2021 13:13:07 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BBCFE900005; Tue, 12 Oct 2021 13:13:07 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A350E900007; Tue, 12 Oct 2021 13:13:07 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0128.hostedemail.com [216.40.44.128]) by kanga.kvack.org (Postfix) with ESMTP id 8EDD2900005 for ; Tue, 12 Oct 2021 13:13:07 -0400 (EDT) Received: from smtpin07.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 4CC44183E6C68 for ; Tue, 12 Oct 2021 17:13:07 +0000 (UTC) X-FDA: 78688430814.07.79826E4 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2076.outbound.protection.outlook.com [40.107.236.76]) by imf28.hostedemail.com (Postfix) with ESMTP id E3D8990000AC for ; Tue, 12 Oct 2021 17:13:06 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=d6AmOJ0eJpGlYTQLdna7XWpsT+H9XAhYgfAzrL8mhgD9H0uM8OJ5rGXSyC0GLeqH6HoGO8L6zlGP0tiAHEToZkJvUKMBwRx2wnBn/ax9drn1I52qLhPjN/r85irq58opn2LTEPfTGvLDGUVdS9GMY+FtAJaJ9g+lcAQpODNTOX2LEgbpxDtfz6gLcAXugzqygRRv9956vXIdSsSwWmFirNFtBFQAPR07nrcF8cwD0F6NVL+QZn3e0oNRALuBFphwN/Atf7gfRKz7eb8dY4M0U1AXEy3VlZrfLVSkqTJMCxp4AKm5f7sABes/Puo+ne3yDYxkZSy9sUd/mPJDWBn30Q== 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=2387Ecpm50AyQpEEPgaG085PdkylS2jbP2iC7VmUXaQ=; b=CcSJEEmKX/6b3pW20+l+6zZq9rckFrxE7nI9oDcHR9q7mMxC6O2L3rWUb0GIrnU0CdXKpqZ7NSnHMNJTWzCQWqOqcM2tiqLKdT1VLn8lt90g9xTq8Xtbqe5aAnooDYK3cBzRvgvWzYRr81aTiPY/nfZyNssdr0owJUWWn/YsDqiOqCH+biSYNEZHd7QqDiTJv1j7bKJXddXxvm2u/JZ4iblMOkB4VK5whxgLasKv9GSEiZMiqtICPbfcMCeozdECQLjRofuGa0FYiHY9iZHQudfA9VXaZB+k2o0l8x4m54R0eJMDSKCPEI1oIIWg6VtswsBx2nm7mhw0c09njJl8tA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=linux-foundation.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=2387Ecpm50AyQpEEPgaG085PdkylS2jbP2iC7VmUXaQ=; b=ZCGAj1YJOxPDsbQKkRo6BA2SbTrLnKk0gzQciJ6AaqsPO6oi3kyt3sZCJvi1DCB8+yTVNfrdWTAOKn07YBsN4fy9o5pItPZvHEQptqd/xBYSfpX5Ui0loKJmqG2qHgQDlX/F4RCDDNW9VOieUqHVUeLGu63L3mSE7fh7SLpbxiI= Received: from MW4PR04CA0299.namprd04.prod.outlook.com (2603:10b6:303:89::34) by BN6PR12MB1779.namprd12.prod.outlook.com (2603:10b6:404:108::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4587.20; Tue, 12 Oct 2021 17:13:04 +0000 Received: from CO1NAM11FT005.eop-nam11.prod.protection.outlook.com (2603:10b6:303:89:cafe::af) by MW4PR04CA0299.outlook.office365.com (2603:10b6:303:89::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4587.18 via Frontend Transport; Tue, 12 Oct 2021 17:13:04 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; linux-foundation.org; dkim=none (message not signed) header.d=none;linux-foundation.org; dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; Received: from SATLEXMB04.amd.com (165.204.84.17) by CO1NAM11FT005.mail.protection.outlook.com (10.13.174.147) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4587.18 via Frontend Transport; Tue, 12 Oct 2021 17:13:04 +0000 Received: from alex-MS-7B09.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.8; Tue, 12 Oct 2021 12:13:00 -0500 From: Alex Sierra To: , , , , , CC: , , , , , Subject: [PATCH v1 04/12] mm: add device coherent vma selection for memory migration Date: Tue, 12 Oct 2021 12:12:39 -0500 Message-ID: <20211012171247.2861-5-alex.sierra@amd.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20211012171247.2861-1-alex.sierra@amd.com> References: <20211012171247.2861-1-alex.sierra@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: a1a9b0e1-7f71-453c-a073-08d98da38d84 X-MS-TrafficTypeDiagnostic: BN6PR12MB1779: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:635; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: dkptXdbxVq06w0dR/YprwieV8oRRqDmloEl19FQRlT7wkE+7spI31vuJPrlsr1O8PDqA7PqDZ/yj6jK4Fd6BWWStSq52nVQa3YhZhP7x9aVFd6InEIt75H1jIr1Ppa1szFoWZ2WeGEg3Q0Kv37a14EWX/F7aAqMfqZivsfPDKFrocfwIM9u5B8u5UIlzpb9HtwRPv2xLRMwrAcyNikwa+ikct9+2rVlStzWaeNPcYhNzY45efXqR5Zz85Ey5ztz6edgEYTIH4Se/7eOkr/kfr0b/onhV3dWarXIqI49PHVn/otpBrYRdYNydZ1yKrxZ4dsBxHvyDpJq3LHuMr0yrMz1TZNeTZIQlR+S2FWEwK7ObhhlBgd0i9PO0NyoGyPY7AOm5YDdDD0m0X4ys2KRul49uUyAumWjeVGTOJRK6YlSFY04jdc9cquEjRZQ089EDTCWhUhM7Qmk/WT8VKMxaCV/kWchAiLrOyZy8LYm/3pZ8T26nrFapk/Itt5PmlAA6m6z+pc/YC+Y7JhqoyuAHp1FQKq7m3uqOQdd1JmvmhRGfUPY/lo/R3XBTbWfccrEHWUoBUlEeVvfvHNeqZgmMIkZ1W25Z3c+CDeL8feJciJg1Xfs6pJ/u0ck6RKf6vrswgPMaNCj/cLQdshJ0Oq2DswjqDye7bYcOyt2HCJ/eWKxRcBcBYlXqXWjJSxadu2VaRncXiXN7ezxB2HdWjs+dK9tzHwtHEms4VhOlAmwb/tE= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(4636009)(46966006)(36840700001)(86362001)(26005)(8936002)(81166007)(1076003)(508600001)(7696005)(336012)(70206006)(83380400001)(82310400003)(6666004)(2616005)(8676002)(16526019)(4326008)(186003)(70586007)(356005)(426003)(36756003)(36860700001)(2906002)(5660300002)(7416002)(54906003)(47076005)(110136005)(44832011)(316002)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Oct 2021 17:13:04.1251 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a1a9b0e1-7f71-453c-a073-08d98da38d84 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT005.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR12MB1779 Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=ZCGAj1YJ; spf=pass (imf28.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.236.76 as permitted sender) smtp.mailfrom=Alex.Sierra@amd.com; dmarc=pass (policy=quarantine) header.from=amd.com X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: E3D8990000AC X-Stat-Signature: twm9jgf4kyg9x96ga39trxnkq9gajxtz X-HE-Tag: 1634058786-137840 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: This case is used to migrate pages from device memory, back to system memory. Device coherent type memory is cache coherent from device and CPU point of view. Signed-off-by: Alex Sierra --- v2: condition added when migrations from device coherent pages. --- include/linux/migrate.h | 1 + mm/migrate.c | 9 +++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/include/linux/migrate.h b/include/linux/migrate.h index 4bb4e519e3f5..b1cae5073d69 100644 --- a/include/linux/migrate.h +++ b/include/linux/migrate.h @@ -156,6 +156,7 @@ static inline unsigned long migrate_pfn(unsigned long pfn) enum migrate_vma_direction { MIGRATE_VMA_SELECT_SYSTEM = 1 << 0, MIGRATE_VMA_SELECT_DEVICE_PRIVATE = 1 << 1, + MIGRATE_VMA_SELECT_DEVICE_COHERENT = 1 << 2, }; struct migrate_vma { diff --git a/mm/migrate.c b/mm/migrate.c index 2bda612f3650..b40cd5a69f65 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -2406,8 +2406,6 @@ static int migrate_vma_collect_pmd(pmd_t *pmdp, if (is_write_device_private_entry(entry)) mpfn |= MIGRATE_PFN_WRITE; } else { - if (!(migrate->flags & MIGRATE_VMA_SELECT_SYSTEM)) - goto next; pfn = pte_pfn(pte); if (is_zero_pfn(pfn)) { mpfn = MIGRATE_PFN_MIGRATE; @@ -2415,6 +2413,13 @@ static int migrate_vma_collect_pmd(pmd_t *pmdp, goto next; } page = vm_normal_page(migrate->vma, addr, pte); + if (!is_zone_device_page(page) && + !(migrate->flags & MIGRATE_VMA_SELECT_SYSTEM)) + goto next; + if (is_zone_device_page(page) && + (!(migrate->flags & MIGRATE_VMA_SELECT_DEVICE_COHERENT) || + page->pgmap->owner != migrate->pgmap_owner)) + goto next; mpfn = migrate_pfn(pfn) | MIGRATE_PFN_MIGRATE; mpfn |= pte_write(pte) ? MIGRATE_PFN_WRITE : 0; } From patchwork Tue Oct 12 17:12:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Sierra Guiza, Alejandro (Alex)" X-Patchwork-Id: 12553275 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8089FC4167D for ; Tue, 12 Oct 2021 17:13:17 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 376F960F21 for ; Tue, 12 Oct 2021 17:13:17 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 376F960F21 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=amd.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 4499E900008; Tue, 12 Oct 2021 13:13:09 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 30BF4900005; Tue, 12 Oct 2021 13:13:09 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E56C0900008; Tue, 12 Oct 2021 13:13:08 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0176.hostedemail.com [216.40.44.176]) by kanga.kvack.org (Postfix) with ESMTP id C4984900005 for ; Tue, 12 Oct 2021 13:13:08 -0400 (EDT) Received: from smtpin36.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 7826882499B9 for ; Tue, 12 Oct 2021 17:13:08 +0000 (UTC) X-FDA: 78688430856.36.240370D Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2041.outbound.protection.outlook.com [40.107.237.41]) by imf19.hostedemail.com (Postfix) with ESMTP id DF6B9B0000A3 for ; Tue, 12 Oct 2021 17:13:07 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DxT7Tw/YHBWwscOTW0ilEmzwNqPVraCh+nXwflV6bbOgCKSc9BqEmdZK7BnPzI0yiDlPLbeo0UuTgmG8IFQJL4UH670W0Bk/Y08nejPvcuuoE3rIFUlOrhlRXbUVW0IRkDGbOn5mbDq3cQ+A+ZVQRfCjk+Q3ApouK5xZ2Ivh2bgzP3+yzg6uU5mX/CcpY6knKtHsZ7+v/YTG+cnz34ptHQfv8mho/Qt/DHempeX1pDux8GxX92TyeoqpVMb3SacCOsJNnj/53Rf9itjWYgdLzyqrJ9SX2QsmxRccp7hmrlh1R5DMtFRVx4N6X30D8GXGYxsd9szWvU2uANDRBkRstw== 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=DtslbnmgwcmVuw3/IJPuNMBAqQP2tzGnRh8lFmQvcmg=; b=f+7UMhoys0ApBE7c4PxiS8LZquJVqJAyfdMyVZ/7qFXXmkWYamlUC/jFOKLS1qp8ps0SV+s0oWiwOs1uK8tL/LIRDSrHqtlQcw2dYnjmTZU4Rur9cK9cCNZ3Zal793PJw34ccNH3DIiv0N3bxSNoZb0enAKawyPomOxVA4292Ry6qeq4yXin0okINTRNf/PHqqGQjKz8RXosa39tyKQs3VpMEeZF1PVBB4P9G8pu5HaOFZ1TfBYFX3cnKEGIPZ5N7hmBsVmsgI/hlpNrL56wgnYEhf+lnqPQZlig4mOXMqQqa78g8LFQ9h3QsIIMjq7khm1nJ4Di6MBW83xgOf6dAg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=linux-foundation.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=DtslbnmgwcmVuw3/IJPuNMBAqQP2tzGnRh8lFmQvcmg=; b=OPj7eoDwJoIzd/lMBQTq0Q7YPkdQ1CG7vWUnAXG9A3FFK66OS4QWmW1RhwDoAXY3R0Nk9WvuZlyeV0BdXC1agj8YaYk6CpDle8PpqXHBxVxjL45ntH24qbN7v2aaGaodpjODO9jXx1yuCy7PLpCca60LDRUDwsi2zGMI5zs+L/g= Received: from MWHPR14CA0008.namprd14.prod.outlook.com (2603:10b6:300:ae::18) by DM6PR12MB3594.namprd12.prod.outlook.com (2603:10b6:5:11f::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4587.24; Tue, 12 Oct 2021 17:13:05 +0000 Received: from CO1NAM11FT018.eop-nam11.prod.protection.outlook.com (2603:10b6:300:ae:cafe::84) by MWHPR14CA0008.outlook.office365.com (2603:10b6:300:ae::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4608.14 via Frontend Transport; Tue, 12 Oct 2021 17:13:05 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; linux-foundation.org; dkim=none (message not signed) header.d=none;linux-foundation.org; dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; Received: from SATLEXMB04.amd.com (165.204.84.17) by CO1NAM11FT018.mail.protection.outlook.com (10.13.175.16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4587.18 via Frontend Transport; Tue, 12 Oct 2021 17:13:05 +0000 Received: from alex-MS-7B09.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.8; Tue, 12 Oct 2021 12:13:01 -0500 From: Alex Sierra To: , , , , , CC: , , , , , Subject: [PATCH v1 05/12] drm/amdkfd: ref count init for device pages Date: Tue, 12 Oct 2021 12:12:40 -0500 Message-ID: <20211012171247.2861-6-alex.sierra@amd.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20211012171247.2861-1-alex.sierra@amd.com> References: <20211012171247.2861-1-alex.sierra@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: bc95e13f-c8a8-4adc-1f4c-08d98da38e1a X-MS-TrafficTypeDiagnostic: DM6PR12MB3594: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:1265; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: /tKsKzOAYs1JQQa1w5DuhDViXpEtvodwEajnH32omiP9w6Nvpd1dNAIKcAp5AUOwYuJFCeUsX28GHArFKJ5dP1n3QliI/wHa96xYGJhpTbaOtY9p23sHsN833R6XqgDRFA57deHpYkrbAYhQz4HzAH9i/lsDrTxgFbh1qkSACYp2jtDo2CAwofUreSRMKvx8Yoju/FgdO/OsFwpr1t5vVgv2QXsEoBmO5CqqYcnUDqtJYhb49Z99r00kWa8Z+BVdGz/KQnUhvevcAi6NwZzZLBh6h1oi9SaAUjqAZ1j6sFLXRZj4FgyP135ty23rIVZ67ibLobtMtVUn0pYEFgBvMCYp8DD0oUX8N11SlzfFg2NKXVI7jhKQtdA3/Zeg5BLWnr5SfOr2607lTm1I0tQ0Et5LxUEuHUxeTcvSZbxFB8UXvpMBSfdtGNj/FGDRnr3VlzftpSEVEN92j50htxffVWFzbP/2WtiKZZONRl1tkku8hLj7/Lkn9e3T6lrZ5yu9xlaKXls9Nt8BSkubguWXwyKXlb9TWn+u1z1mB5xQGH12aiTBSdoJtIosVgg29Ghq1Ag0HWPFnXFzHVeKQl6K5wgVOEJWp1xEFLH5ybyhXFHgkOUehx7y2GxyeAp6n7f2G2RBodfXykmJTShF4LC1v2mPWIg91cKl/1Hc4ISoXdWH8aKXpxU7c8h98Ohy5IWClxuz117153DxaDEoa1TKQ0tHa1jFulqfpOaZDaoYhag= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(4636009)(46966006)(36840700001)(2616005)(4744005)(508600001)(82310400003)(8936002)(2906002)(6666004)(316002)(36756003)(5660300002)(4326008)(70206006)(7416002)(36860700001)(356005)(7696005)(86362001)(26005)(16526019)(1076003)(70586007)(8676002)(336012)(47076005)(426003)(81166007)(186003)(83380400001)(54906003)(110136005)(44832011)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Oct 2021 17:13:05.1111 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: bc95e13f-c8a8-4adc-1f4c-08d98da38e1a X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT018.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3594 X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: DF6B9B0000A3 X-Stat-Signature: bniz4754rdorimoe19pe6di1hzmguynu Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=OPj7eoDw; dmarc=pass (policy=quarantine) header.from=amd.com; spf=pass (imf19.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.237.41 as permitted sender) smtp.mailfrom=Alex.Sierra@amd.com X-HE-Tag: 1634058787-723496 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: Ref counter from device pages is init to zero during memmap init zone. The first time a new device page is allocated to migrate data into it, its ref counter needs to be initialized to one. Signed-off-by: Alex Sierra --- drivers/gpu/drm/amd/amdkfd/kfd_migrate.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c b/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c index dab290a4d19d..ffad39ffa8c6 100644 --- a/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c +++ b/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c @@ -220,7 +220,8 @@ svm_migrate_get_vram_page(struct svm_range *prange, unsigned long pfn) page = pfn_to_page(pfn); svm_range_bo_ref(prange->svm_bo); page->zone_device_data = prange->svm_bo; - get_page(page); + VM_BUG_ON_PAGE(page_ref_count(page), page); + init_page_count(page); lock_page(page); } From patchwork Tue Oct 12 17:12:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Sierra Guiza, Alejandro (Alex)" X-Patchwork-Id: 12553273 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 62DD0C43219 for ; Tue, 12 Oct 2021 17:13:15 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 0172660EFE for ; Tue, 12 Oct 2021 17:13:14 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 0172660EFE Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=amd.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id E5A4090000A; Tue, 12 Oct 2021 13:13:08 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D9F75900009; Tue, 12 Oct 2021 13:13:08 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BBFC2900008; Tue, 12 Oct 2021 13:13:08 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0171.hostedemail.com [216.40.44.171]) by kanga.kvack.org (Postfix) with ESMTP id A4715900005 for ; Tue, 12 Oct 2021 13:13:08 -0400 (EDT) Received: from smtpin40.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 60E4B82499A8 for ; Tue, 12 Oct 2021 17:13:08 +0000 (UTC) X-FDA: 78688430856.40.41FB891 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2083.outbound.protection.outlook.com [40.107.236.83]) by imf03.hostedemail.com (Postfix) with ESMTP id 0305F30000AC for ; Tue, 12 Oct 2021 17:13:07 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BlkuV9KWxg9mboj/JoY3RF1CdXpKq6WXLr9fK8b+yOjUsVtA8nlKpFD3xbDG8dC/iMMD8McXqSjpeGt5aI6XOhOZAHAtBsMxHKXs05ADGgjvpEg4zkn20CYGqPxhmRYhoaEQ8VjxKK+VPjzzQG7Alf8t3I3a+EisgzuM+Yf1n6j2H1iMAODpyHzXPowc2AVMAOcSjRXKJhcYvHgKQ9Jj2F9lVrI7ejIcC36WPjGaizZSJX1Ii2FUUS5KojP1bSQOQW8FROpaOk8SB3kZRswZGJvGWXHYS6viznJM7L59aC6i+fzMdNHFVs2inIhTSBnVAJYgpSpKASTqkYWIxovjZg== 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=QonVs1R9b3x7Zh59B2aYhKR/KBbOi/+fBz9YOjTr6tQ=; b=WCvneb3JYRvKyy+DPRbz/6llWiwGmGJz66Ho4KyMPkpXE1ljdin0AWf7K235Smm2sZ/PFKraPuv8/HaR2J1QrFh/wib0yGVPWm+NaoHT+86MNUEA6OQACcxoi20IlirkxCPjmR+54hrGoW8weYPR5+ww5CpdMBv/ORuyNwuKuCBnEwTaO4guRWSyT7hId2nI+OuQNHfbTUtt0y0BpVOUXXjK1VYzYDlXxjbxRBRVCXmElQxYdPvgxQccr5vEYZZwd07wFBlvBlbNvfHoBjeM/RQ8ojB6HNmhK5HHs9EyD38V6IswPWEqB8vniNDcKLeFVGQo328AbUP9p/Dw0vH8fQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=linux-foundation.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=QonVs1R9b3x7Zh59B2aYhKR/KBbOi/+fBz9YOjTr6tQ=; b=KOdecjNpcYHO4eqiec4yQzxRzNE+rKsDZPywHVSUz9l6M1WnUjSrQS/QVEyQuP5DYmvWg7/mjj0iGTLmZVEhumBkxMCy7Kh1SFkuzCGGk7LMsfijdkzMWezzS+V7Jqf8b9vXnOVaOUiBek1TN+pM/twJSsa2c/055N35FWX7k1Y= Received: from MW4PR04CA0286.namprd04.prod.outlook.com (2603:10b6:303:89::21) by CH2PR12MB4969.namprd12.prod.outlook.com (2603:10b6:610:68::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4587.22; Tue, 12 Oct 2021 17:13:05 +0000 Received: from CO1NAM11FT005.eop-nam11.prod.protection.outlook.com (2603:10b6:303:89:cafe::f7) by MW4PR04CA0286.outlook.office365.com (2603:10b6:303:89::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4587.25 via Frontend Transport; Tue, 12 Oct 2021 17:13:05 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; linux-foundation.org; dkim=none (message not signed) header.d=none;linux-foundation.org; dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; Received: from SATLEXMB04.amd.com (165.204.84.17) by CO1NAM11FT005.mail.protection.outlook.com (10.13.174.147) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4587.18 via Frontend Transport; Tue, 12 Oct 2021 17:13:05 +0000 Received: from alex-MS-7B09.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.8; Tue, 12 Oct 2021 12:13:02 -0500 From: Alex Sierra To: , , , , , CC: , , , , , Subject: [PATCH v1 06/12] drm/amdkfd: add SPM support for SVM Date: Tue, 12 Oct 2021 12:12:41 -0500 Message-ID: <20211012171247.2861-7-alex.sierra@amd.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20211012171247.2861-1-alex.sierra@amd.com> References: <20211012171247.2861-1-alex.sierra@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 9cd2665f-0967-4574-7f31-08d98da38e27 X-MS-TrafficTypeDiagnostic: CH2PR12MB4969: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:5797; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: HjkojzLIhrgVCd9gq/1w2gnD0blX2fjS0XErLiNr7xdv7GYnni9l/yy3csi5M6IbTRhzOcCqPll4nfB6JJeGHPbk3H0tqjwv9RE9eNv1Z2E6ttcwmL/GbVUjDB41TZtmGwGIdw5xs1F6C46ujtU6gLipstQ+2Sqi+Xm8M11Z92xGWRaLeq6fNIjYpBckwJ6bRG3gWNqMufaRONhdYMYQHM5jh90xIlY8hnKvOLQttj34LQm/08VGTc9vvxQhRBmWq8KAMjN/hOhwh0i9o7Et+jQ/Y1ah5qN1iYXd2+eKuJUpPnKiCdDHhlRrPtwYGCtip1S62tOkV0somj3n+mF4KSHZYgm7koUiSNXSF8yEHlid6oFZp/doc6538r5/xJ5Uvr1cBc4cX1ekvydKz2ZYVt5c3bI1/Lch90/Px+E2v9KgQ5EQKwFmKw1cotKLPQo4EuSK3trvF6H9SARjO8pxud9Qc8uNQDkL/cUxAguIMWPfsh0NSrbYt+C2iSOEPNdHUHprn6DKplgebW25PqO3lQXqi6ITZGHD1wYtQQpzoqkYTqB3dCR5yzrOWQrodIu1pbYaqiOeqCN2iR4akp5aVBtKr3JVYH2vijvTh1yOGo7WCZMeiYOSA1oSwjNPH9OfgBSkdNxpgNNgKVpVCYceVCViXjUVjp9akNny5LGMp1sd6FPzudfNBwZVTPNhqe7xN16o6UR6Oc19ggbItm8MxvU+Hbrah0+jbBQYPYUFs0c= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(4636009)(36840700001)(46966006)(47076005)(316002)(5660300002)(16526019)(36756003)(336012)(7416002)(6666004)(8676002)(82310400003)(54906003)(86362001)(186003)(8936002)(356005)(81166007)(426003)(26005)(7696005)(70586007)(44832011)(4326008)(110136005)(508600001)(1076003)(70206006)(2906002)(2616005)(36860700001)(83380400001)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Oct 2021 17:13:05.1895 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 9cd2665f-0967-4574-7f31-08d98da38e27 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT005.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR12MB4969 X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 0305F30000AC X-Stat-Signature: 7sdtw84cmy9e6yjmqh5bgxfh3cwqesza Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=KOdecjNp; dmarc=pass (policy=quarantine) header.from=amd.com; spf=pass (imf03.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.236.83 as permitted sender) smtp.mailfrom=Alex.Sierra@amd.com X-HE-Tag: 1634058787-787200 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: When CPU is connected throug XGMI, it has coherent access to VRAM resource. In this case that resource is taken from a table in the device gmc aperture base. This resource is used along with the device type, which could be DEVICE_PRIVATE or DEVICE_COHERENT to create the device page map region. Signed-off-by: Alex Sierra Reviewed-by: Felix Kuehling --- v7: Remove lookup_resource call, so export symbol for this function is not longer required. Patch dropped "kernel: resource: lookup_resource as exported symbol" --- drivers/gpu/drm/amd/amdkfd/kfd_migrate.c | 32 +++++++++++++++--------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c b/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c index ffad39ffa8c6..9efc97d55077 100644 --- a/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c +++ b/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c @@ -866,7 +866,7 @@ int svm_migrate_init(struct amdgpu_device *adev) { struct kfd_dev *kfddev = adev->kfd.dev; struct dev_pagemap *pgmap; - struct resource *res; + struct resource *res = NULL; unsigned long size; void *r; @@ -881,22 +881,29 @@ int svm_migrate_init(struct amdgpu_device *adev) * should remove reserved size */ size = ALIGN(adev->gmc.real_vram_size, 2ULL << 20); - res = devm_request_free_mem_region(adev->dev, &iomem_resource, size); - if (IS_ERR(res)) - return -ENOMEM; + if (adev->gmc.xgmi.connected_to_cpu) { + pgmap->range.start = adev->gmc.aper_base; + pgmap->range.end = adev->gmc.aper_base + adev->gmc.aper_size - 1; + pgmap->type = MEMORY_DEVICE_COHERENT; + } else { + res = devm_request_free_mem_region(adev->dev, &iomem_resource, size); + if (IS_ERR(res)) + return -ENOMEM; + pgmap->range.start = res->start; + pgmap->range.end = res->end; + pgmap->type = MEMORY_DEVICE_PRIVATE; + } - pgmap->type = MEMORY_DEVICE_PRIVATE; pgmap->nr_range = 1; - pgmap->range.start = res->start; - pgmap->range.end = res->end; pgmap->ops = &svm_migrate_pgmap_ops; pgmap->owner = SVM_ADEV_PGMAP_OWNER(adev); - pgmap->flags = MIGRATE_VMA_SELECT_DEVICE_PRIVATE; + pgmap->flags = 0; r = devm_memremap_pages(adev->dev, pgmap); if (IS_ERR(r)) { pr_err("failed to register HMM device memory\n"); - devm_release_mem_region(adev->dev, res->start, - res->end - res->start + 1); + if (pgmap->type == MEMORY_DEVICE_PRIVATE) + devm_release_mem_region(adev->dev, res->start, + res->end - res->start + 1); return PTR_ERR(r); } @@ -915,6 +922,7 @@ void svm_migrate_fini(struct amdgpu_device *adev) struct dev_pagemap *pgmap = &adev->kfd.dev->pgmap; devm_memunmap_pages(adev->dev, pgmap); - devm_release_mem_region(adev->dev, pgmap->range.start, - pgmap->range.end - pgmap->range.start + 1); + if (pgmap->type == MEMORY_DEVICE_PRIVATE) + devm_release_mem_region(adev->dev, pgmap->range.start, + pgmap->range.end - pgmap->range.start + 1); } From patchwork Tue Oct 12 17:12:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Sierra Guiza, Alejandro (Alex)" X-Patchwork-Id: 12553279 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0C3EEC433FE for ; Tue, 12 Oct 2021 17:13:22 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id B4B7660F38 for ; Tue, 12 Oct 2021 17:13:21 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org B4B7660F38 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=amd.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id AD41790000B; Tue, 12 Oct 2021 13:13:10 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A8552900005; Tue, 12 Oct 2021 13:13:10 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9261E90000B; Tue, 12 Oct 2021 13:13:10 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0236.hostedemail.com [216.40.44.236]) by kanga.kvack.org (Postfix) with ESMTP id 7E69C900005 for ; Tue, 12 Oct 2021 13:13:10 -0400 (EDT) Received: from smtpin32.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 3B3C639B0F for ; Tue, 12 Oct 2021 17:13:10 +0000 (UTC) X-FDA: 78688430940.32.6ECC214 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2058.outbound.protection.outlook.com [40.107.244.58]) by imf24.hostedemail.com (Postfix) with ESMTP id C27FFB0000A7 for ; Tue, 12 Oct 2021 17:13:09 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ElxrFIKixq4P/YTLDcvbR9geyFyuLV8vmVdpb+QCzvoZVNXed+YmlQdvX9ZC81ttnNkVmH7hUK8ujOygrUC6lUSAAt3ENFV1FD9Yq47WC0e7cdqz/Lw6lhJMA0GBBTO+F/Z3yzAcoWE6uGzupAWHTyB3iAPRe85sPJ7pOqbQdNjYdPWbRMhY5BMKKuS/g1ILRA+h/eSZpzYy0Kx8AiGb00kHJohlwFxbwyifqvnm5YWMHelQdr4Xj51rB8Qsf3NtDvx225B2oEAHLU+4eaFleTAoaqtC2wwQwqvsTD45NDNLkA2vOvSLjLzI2iuRgIJVTm9B6s5tLZJF3c+aCQ2UQA== 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=NpwMDrMZOL20IsyI4cMiYJ6Nkzt8TdtjHg3iBTGaHag=; b=XG/IXnW6plnJG5S1k/kcueRGFIUzjbyf6ekfyeve9Xal3s+EJ2XwNo8znIxuhf+Me93e6oeFxg3+912INmzBr9d1E9SEZfwxF0BO4hk+zQTdUsYwE0HmElytfYrNiYsmahas1Wl3YBblByERI4AXg6oV5Kd5v6It5F7l/z/W/+4p6/C6H6gmi8yumh6WmPdw7tqa3my5aazxxS2nXdxBrYFXRW86SUliNWtwtzpY3ljMKU8sC58xo5rV6YXcx1pTDgSZHEQ+IAIq1Tnlr2So2wqQx86twuS/V5lrvq6FhwZl9NPXnQjiNKwAYlBoIpCEuUZvWcyRs82MVHKG9rfmBg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=linux-foundation.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=NpwMDrMZOL20IsyI4cMiYJ6Nkzt8TdtjHg3iBTGaHag=; b=XyqPE50mOpcnzHpCK0mwez1uSfgH5dmuqBqPgN4muRqtyLBhA0eHQ4kO9jqRNWrzaNHkLqhdMqZwJPcL4wrx5EHTJ6xnybm/zg6dMHt366SFhmzBOR1lbmkvD8gvoBlOjS6cvC9wFueEZeHJuPoVxwKYrtPdQC8uQcFSIlNnApw= Received: from MW4PR04CA0276.namprd04.prod.outlook.com (2603:10b6:303:89::11) by MN2PR12MB3071.namprd12.prod.outlook.com (2603:10b6:208:cc::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4587.18; Tue, 12 Oct 2021 17:13:06 +0000 Received: from CO1NAM11FT005.eop-nam11.prod.protection.outlook.com (2603:10b6:303:89:cafe::14) by MW4PR04CA0276.outlook.office365.com (2603:10b6:303:89::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4587.19 via Frontend Transport; Tue, 12 Oct 2021 17:13:06 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; linux-foundation.org; dkim=none (message not signed) header.d=none;linux-foundation.org; dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; Received: from SATLEXMB04.amd.com (165.204.84.17) by CO1NAM11FT005.mail.protection.outlook.com (10.13.174.147) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4587.18 via Frontend Transport; Tue, 12 Oct 2021 17:13:06 +0000 Received: from alex-MS-7B09.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.8; Tue, 12 Oct 2021 12:13:02 -0500 From: Alex Sierra To: , , , , , CC: , , , , , Subject: [PATCH v1 07/12] drm/amdkfd: coherent type as sys mem on migration to ram Date: Tue, 12 Oct 2021 12:12:42 -0500 Message-ID: <20211012171247.2861-8-alex.sierra@amd.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20211012171247.2861-1-alex.sierra@amd.com> References: <20211012171247.2861-1-alex.sierra@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: ef5a3ab4-7f37-4c2d-630f-08d98da38ebf X-MS-TrafficTypeDiagnostic: MN2PR12MB3071: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7219; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: aSzRj57sfXzgGxoQpWnRXV998YZ5cE7gS2ZNjc2rxrFb2PWasoNdskMs7aheyckkatE6Pfc1fDo8Yg2+JN/Su6pPcYqR+n4zSq9YHMDXM3PWJtWtAD4EQ0zxyo5e5vtVQd7Jw3AZBlyMwq4qNp6W8/uTaNrn6Ht6HflEBEfzSDdyg6jnaOcu8tgi6EkyeT+Cu9ZMLpDsOYWxVxWtXGb8AEu5RyEHcqM4SJJyMC6WhoFza9+XKIU0pqV6zwSWwqwTFmdK06BTShQmfaTNYatAQ6hRj//hb/4RZOCTI7O1XL0JpzHLTtHEdkTrlC9nP8oQiUQwUEWkyaCNXzKAhzn8ToeAq3J4ASRQfVj3UjuTfdmwXT1nxStR5fLj56m5GUnm1OhUgG/ioZmls+sVLMLEhjCkEuPU8L1S4koz4xIj6X3wFy8z3Vn9r2QoKeb4q5Ux2xGRAmt4G6/fGIKUxhehEzLcobzx14DeO1XwBwWrWXjukEtSHWrwNm+WNQsONiBkC9XVuxL3nPHi5dMLjLd3+MhwsMp5b9L9L2atYOWLgc6a8hQYoTTHOwkOceCQ8EzyyVux0p8Qj5cPMhMGtgGDbI0FrP4X0F6ypnKBzXfuxLpQiIpxYxZ9NTIdoucFg8Rnxa5zM1lmY6m3rpBhjsENLoXBSBDow/eNqWXPsOzcC6yrLMlHSCVzKBHDSE4v5eZmVA9Nf9oGZ69cCh00A5b6rLO7YO8yyoXTvZiW1mphTEE= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(4636009)(36840700001)(46966006)(81166007)(5660300002)(426003)(47076005)(1076003)(86362001)(54906003)(110136005)(4326008)(336012)(70586007)(44832011)(7416002)(316002)(356005)(7696005)(2616005)(70206006)(186003)(16526019)(2906002)(508600001)(36756003)(6666004)(26005)(82310400003)(8676002)(36860700001)(8936002)(83380400001)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Oct 2021 17:13:06.1830 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ef5a3ab4-7f37-4c2d-630f-08d98da38ebf X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT005.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB3071 X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: C27FFB0000A7 X-Stat-Signature: 9gq9xskzx5jw5h4f9prxfia1ke8a8kxf Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=XyqPE50m; dmarc=pass (policy=quarantine) header.from=amd.com; spf=pass (imf24.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.244.58 as permitted sender) smtp.mailfrom=Alex.Sierra@amd.com X-HE-Tag: 1634058789-738783 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: Coherent device type memory on VRAM to RAM migration, has similar access as System RAM from the CPU. This flag sets the source from the sender. Which in Coherent type case, should be set as MIGRATE_VMA_SELECT_DEVICE_COHERENT. Signed-off-by: Alex Sierra Reviewed-by: Felix Kuehling --- drivers/gpu/drm/amd/amdkfd/kfd_migrate.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c b/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c index 9efc97d55077..4ec7ac13f2b7 100644 --- a/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c +++ b/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c @@ -617,9 +617,12 @@ svm_migrate_vma_to_ram(struct amdgpu_device *adev, struct svm_range *prange, migrate.vma = vma; migrate.start = start; migrate.end = end; - migrate.flags = MIGRATE_VMA_SELECT_DEVICE_PRIVATE; migrate.pgmap_owner = SVM_ADEV_PGMAP_OWNER(adev); + if (adev->gmc.xgmi.connected_to_cpu) + migrate.flags = MIGRATE_VMA_SELECT_DEVICE_COHERENT; + else + migrate.flags = MIGRATE_VMA_SELECT_DEVICE_PRIVATE; size = 2 * sizeof(*migrate.src) + sizeof(uint64_t) + sizeof(dma_addr_t); size *= npages; buf = kvmalloc(size, GFP_KERNEL | __GFP_ZERO); From patchwork Tue Oct 12 17:12:43 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Sierra Guiza, Alejandro (Alex)" X-Patchwork-Id: 12553277 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BE18EC4332F for ; Tue, 12 Oct 2021 17:13:19 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 6EF6961076 for ; Tue, 12 Oct 2021 17:13:19 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 6EF6961076 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=amd.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 4B9A6900009; Tue, 12 Oct 2021 13:13:10 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 44439900005; Tue, 12 Oct 2021 13:13:10 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 24803900009; Tue, 12 Oct 2021 13:13:10 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0175.hostedemail.com [216.40.44.175]) by kanga.kvack.org (Postfix) with ESMTP id 04976900005 for ; Tue, 12 Oct 2021 13:13:10 -0400 (EDT) Received: from smtpin25.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id AC5AF284A8 for ; Tue, 12 Oct 2021 17:13:09 +0000 (UTC) X-FDA: 78688430898.25.752AB8C Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2054.outbound.protection.outlook.com [40.107.223.54]) by imf05.hostedemail.com (Postfix) with ESMTP id 49C70506CBFC for ; Tue, 12 Oct 2021 17:13:09 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=aM55t3HsFnBDOUfHT/Bw+1GieXwkZW+nh+AhsBJl+yY4oPd7WyoTR6mLRhoct89oZ1NxRfzgxhzJf1sicsjiOrfECMz7aI517uGSA4l+VmBETcLxZ7oJmdWouxlp69ks6PqXFqnkb0xQXz6DY5QNj6X0R+HsVrRFg4tOOrPQKWxJUrbxO3ukurXpKXtvSU9rGK/T3yaegBCAXWiIA6Dq7PNRU9Wy5hKgb+PWD4kJLaXKr7n/5ZBIbijAaor/v0ZuUyKet5x6soSAk+Pxr5uJaHx3AZD4CST0gVfiUnh2jxxPZ82/PrQJnCmzCjWxFUVVx4xgThuwQ70IwbfR+apR/w== 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=G0e5/2mK5mcvCb8srP5epOKMau+W+DCd3ch7Z+X/cOk=; b=V5sA5ApOkRwQAV5sybTQ63aiuTNko0by1NrlfZdkRCHkeVc3tDSkIjqnMgQkX4dB6DNH36qx6STQg/5lJZb7qB/yRd0CW5itW6MPuREvIw4j/q5oAV1w4vR0z3mBrx/J/QEBhu59JMGOy6k2aawRev7voKt7o3CRFukNPNA3jwaP9ULttmJPTWXZWKYdhdOlzSfp+tcFMkze/+SHav01OiUJfQ5bkpXHYhO8AU4U5+fJqVNqcIqJHr7mAsSDEhAkK0XMoo+OkS9La8fz596V6ENxlqtz7qPUkbw22TgW1NM8wM6FPLBN3Iu7I2eZ7cc7qIeh96sBpbRZU+MUqcNIww== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=linux-foundation.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=G0e5/2mK5mcvCb8srP5epOKMau+W+DCd3ch7Z+X/cOk=; b=cbCscQzSerDSLk6XDk11y5KphJCBsfiZk+cXVBoYtcZzx5quDylo5AsemrPNyi1UlS324FzJU4bJjr+b1DD34TQJKVjwlon8ZpJu8daXA44A7xguhYUCFHI4QMuAFW4u+7ZGYp+a3QVYaZVwAFdUa4eJdDz2gldE3ka2goAuiSg= Received: from MWHPR14CA0012.namprd14.prod.outlook.com (2603:10b6:300:ae::22) by BN7PR12MB2739.namprd12.prod.outlook.com (2603:10b6:408:31::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4587.25; Tue, 12 Oct 2021 17:13:07 +0000 Received: from CO1NAM11FT018.eop-nam11.prod.protection.outlook.com (2603:10b6:300:ae:cafe::a6) by MWHPR14CA0012.outlook.office365.com (2603:10b6:300:ae::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4587.24 via Frontend Transport; Tue, 12 Oct 2021 17:13:06 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; linux-foundation.org; dkim=none (message not signed) header.d=none;linux-foundation.org; dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; Received: from SATLEXMB04.amd.com (165.204.84.17) by CO1NAM11FT018.mail.protection.outlook.com (10.13.175.16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4587.18 via Frontend Transport; Tue, 12 Oct 2021 17:13:06 +0000 Received: from alex-MS-7B09.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.8; Tue, 12 Oct 2021 12:13:03 -0500 From: Alex Sierra To: , , , , , CC: , , , , , Subject: [PATCH v1 08/12] lib: test_hmm add ioctl to get zone device type Date: Tue, 12 Oct 2021 12:12:43 -0500 Message-ID: <20211012171247.2861-9-alex.sierra@amd.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20211012171247.2861-1-alex.sierra@amd.com> References: <20211012171247.2861-1-alex.sierra@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 10ceba12-e2ed-4213-0baf-08d98da38ec9 X-MS-TrafficTypeDiagnostic: BN7PR12MB2739: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:2399; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: HruBCQ5hDGDpR3lk82TA3JvvxiGPlz6rE3LSP4hXKBJ7PpDcOIwscjqr6alhpUwC3EzZFNgjwltk8qvxWjeivXLPp8peqXhl1J/HoNdrYZ+yilVb8cCZm+aYOImDKn7TD1UnRqOSv+e0UOwcVWzE7ESGMYFyuMjIRYJMvyh4YSxf5IWPII0fb+Q2bMQgffahuXX5ROjFgonDqKLHFaZM1v1FwKufAG2I8xMYuj/6Th3IEUAtRiUabaF4ZSRazuQx/hO8Aahske9US9aBtT/j3ngARhPFwWy6mIENrUyJ7r9Tvz+shJg9pz+gM/jwokK2zPS2zXKdTYLnNylqcf8ptHbYUEwfFqaU3tbdjwl9lIpf/PP9FHQ+rPXNwPqzX0ktI2a7lu9likjFBm7ms6ISg2Mo6cpgklaKrojwIAHmnVKS4/D1UgmLEgtXnUTfON5RSmvDQQ2pjpoZon914TnmqAtmBqJJQaFemR92VBGCMbrIF2GUaRShHMa9RhNK7LQJI68WwmTJmLJSIY/fCk/f2V0BubKo9pYQodXaKd9C8Fu89g56ADtTJxEzupFdK72m+9gYtJhxdQ7UO2sPo38+WK320fF2GbNujsDM8sdTk94ti6csaGm6J7rcq2+anmy8vU1RWsec/PA5TJPh5zPubq43ljc+4ATm6+1/EOhgiWryCiRJPgk4s9FGiVo4IU5Nzz7bo7BGHznQfStqgJxbT/z+SpZJBLstqSOuwVo01aw= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(4636009)(36840700001)(46966006)(44832011)(81166007)(26005)(54906003)(36756003)(356005)(47076005)(508600001)(7696005)(82310400003)(2906002)(5660300002)(110136005)(36860700001)(8936002)(186003)(16526019)(6666004)(1076003)(8676002)(2616005)(83380400001)(7416002)(336012)(70206006)(86362001)(70586007)(4326008)(316002)(426003)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Oct 2021 17:13:06.2575 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 10ceba12-e2ed-4213-0baf-08d98da38ec9 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT018.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN7PR12MB2739 X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 49C70506CBFC X-Stat-Signature: ccptjck93f1dadkoia7rb3mze6eqjrrr Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=cbCscQzS; dmarc=pass (policy=quarantine) header.from=amd.com; spf=pass (imf05.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.223.54 as permitted sender) smtp.mailfrom=Alex.Sierra@amd.com X-HE-Tag: 1634058789-610200 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: new ioctl cmd added to query zone device type. This will be used once the test_hmm adds zone device coherent type. Signed-off-by: Alex Sierra --- lib/test_hmm.c | 15 ++++++++++++++- lib/test_hmm_uapi.h | 7 +++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/lib/test_hmm.c b/lib/test_hmm.c index 6998f10350ea..3cd91ca31dd7 100644 --- a/lib/test_hmm.c +++ b/lib/test_hmm.c @@ -82,6 +82,7 @@ struct dmirror_chunk { struct dmirror_device { struct cdev cdevice; struct hmm_devmem *devmem; + unsigned int zone_device_type; unsigned int devmem_capacity; unsigned int devmem_count; @@ -468,6 +469,7 @@ static bool dmirror_allocate_chunk(struct dmirror_device *mdevice, if (IS_ERR(res)) goto err_devmem; + mdevice->zone_device_type = HMM_DMIRROR_MEMORY_DEVICE_PRIVATE; devmem->pagemap.type = MEMORY_DEVICE_PRIVATE; devmem->pagemap.range.start = res->start; devmem->pagemap.range.end = res->end; @@ -912,6 +914,15 @@ static int dmirror_snapshot(struct dmirror *dmirror, return ret; } +static int dmirror_get_device_type(struct dmirror *dmirror, + struct hmm_dmirror_cmd *cmd) +{ + mutex_lock(&dmirror->mutex); + cmd->zone_device_type = dmirror->mdevice->zone_device_type; + mutex_unlock(&dmirror->mutex); + + return 0; +} static long dmirror_fops_unlocked_ioctl(struct file *filp, unsigned int command, unsigned long arg) @@ -952,7 +963,9 @@ static long dmirror_fops_unlocked_ioctl(struct file *filp, case HMM_DMIRROR_SNAPSHOT: ret = dmirror_snapshot(dmirror, &cmd); break; - + case HMM_DMIRROR_GET_MEM_DEV_TYPE: + ret = dmirror_get_device_type(dmirror, &cmd); + break; default: return -EINVAL; } diff --git a/lib/test_hmm_uapi.h b/lib/test_hmm_uapi.h index 670b4ef2a5b6..ee88701793d5 100644 --- a/lib/test_hmm_uapi.h +++ b/lib/test_hmm_uapi.h @@ -26,6 +26,7 @@ struct hmm_dmirror_cmd { __u64 npages; __u64 cpages; __u64 faults; + __u64 zone_device_type; }; /* Expose the address space of the calling process through hmm device file */ @@ -33,6 +34,7 @@ struct hmm_dmirror_cmd { #define HMM_DMIRROR_WRITE _IOWR('H', 0x01, struct hmm_dmirror_cmd) #define HMM_DMIRROR_MIGRATE _IOWR('H', 0x02, struct hmm_dmirror_cmd) #define HMM_DMIRROR_SNAPSHOT _IOWR('H', 0x03, struct hmm_dmirror_cmd) +#define HMM_DMIRROR_GET_MEM_DEV_TYPE _IOWR('H', 0x04, struct hmm_dmirror_cmd) /* * Values returned in hmm_dmirror_cmd.ptr for HMM_DMIRROR_SNAPSHOT. @@ -60,4 +62,9 @@ enum { HMM_DMIRROR_PROT_DEV_PRIVATE_REMOTE = 0x30, }; +enum { + /* 0 is reserved to catch uninitialized type fields */ + HMM_DMIRROR_MEMORY_DEVICE_PRIVATE = 1, +}; + #endif /* _LIB_TEST_HMM_UAPI_H */ From patchwork Tue Oct 12 17:12:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Sierra Guiza, Alejandro (Alex)" X-Patchwork-Id: 12553283 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AEB67C43217 for ; Tue, 12 Oct 2021 17:13:26 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 6234960F21 for ; Tue, 12 Oct 2021 17:13:26 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 6234960F21 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=amd.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 0EAE790000D; Tue, 12 Oct 2021 13:13:12 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 09A40900005; Tue, 12 Oct 2021 13:13:12 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DDE5C90000D; Tue, 12 Oct 2021 13:13:11 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0078.hostedemail.com [216.40.44.78]) by kanga.kvack.org (Postfix) with ESMTP id C8519900005 for ; Tue, 12 Oct 2021 13:13:11 -0400 (EDT) Received: from smtpin16.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 879021802EC3D for ; Tue, 12 Oct 2021 17:13:11 +0000 (UTC) X-FDA: 78688430982.16.504F15B Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2086.outbound.protection.outlook.com [40.107.220.86]) by imf18.hostedemail.com (Postfix) with ESMTP id E8F164002085 for ; Tue, 12 Oct 2021 17:13:10 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YJi962tOERRbK0ZBC9pCPvbzfodx8WBvAvFVcTThxvZSbh80+EvlAaj74iKnEAmEEeXZjtHfASaZpXbNbePITPGEoOvTRRxnEmBCZtG+/XGaluowraU45/v5JbIwu298ip6J4XQB7WAsaj7C9hsKgxV3mdacb/F5hsgsTSd3QWyb5JFXivn4s4woIjGG0beXhb8pBvl9bAGK3Oerv9/3j211kRYqx6UDFZhNgKTwn8sYWzYHZp0pZToqSDaHWMc8Gkmxm4vNqasyBkqCNgWo/PBYWU4g6+Z3tkszwEzZmrLKZ9NCXew76ZACFhlWcXbq0AdOKAxyJDRUukHL2c+yuw== 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=4e2qtL9BL+WvMFXurkxezMwAa0e75BY1DPU7BROdNpc=; b=Olcbp5RPoyICpjsuNRh3SZKxlgRK3HCbr0eVjxRPSE7PzF59NeDE6jYVzoedyVMqEuhGu6bXBtRsFaFTdNWHcYUrI72A1rC+Cz8jpqlnP1gs8w/yYit2QP/cS44J2bKornpyN1dtnAcgllQlK1XvU1MSEwQK/bEkDJAEezLj+cTgk/0gP5RUOkXp4r02Jzb+f9ll7Y7eK68efhle3JiNw0rIcXDxVIcJDFCaPHMMcu8+OohDg9ykdtcQLuZNydPF2QzNKKd5cxpsewwVD9gz/CQIyJf8ID3RLw7c7A12t32TtfA5TUHTncxrT82jA8JTVXxl36ao5OhSVUyPN+qNQA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=linux-foundation.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=4e2qtL9BL+WvMFXurkxezMwAa0e75BY1DPU7BROdNpc=; b=y/oG7tw1orLN7YpQ5PDOHvwc7NVnC910UPuWTSGTfPOV/vqAjvDLqC6e2WHeY/KUUlCQMUPeB4Ge/ZT5SjbVYVPdBy+VqGqb25iNxugtoI2OD4xPmSZTZabAu5U3E3I84a3fJvgIf2UB4cTjoccbBMPb8uF77/8saVRs3lp7d3k= Received: from MW4PR04CA0281.namprd04.prod.outlook.com (2603:10b6:303:89::16) by MN2PR12MB3005.namprd12.prod.outlook.com (2603:10b6:208:c5::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4587.22; Tue, 12 Oct 2021 17:13:07 +0000 Received: from CO1NAM11FT005.eop-nam11.prod.protection.outlook.com (2603:10b6:303:89:cafe::d1) by MW4PR04CA0281.outlook.office365.com (2603:10b6:303:89::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4587.25 via Frontend Transport; Tue, 12 Oct 2021 17:13:07 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; linux-foundation.org; dkim=none (message not signed) header.d=none;linux-foundation.org; dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; Received: from SATLEXMB04.amd.com (165.204.84.17) by CO1NAM11FT005.mail.protection.outlook.com (10.13.174.147) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4587.18 via Frontend Transport; Tue, 12 Oct 2021 17:13:07 +0000 Received: from alex-MS-7B09.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.8; Tue, 12 Oct 2021 12:13:04 -0500 From: Alex Sierra To: , , , , , CC: , , , , , Subject: [PATCH v1 09/12] lib: test_hmm add module param for zone device type Date: Tue, 12 Oct 2021 12:12:44 -0500 Message-ID: <20211012171247.2861-10-alex.sierra@amd.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20211012171247.2861-1-alex.sierra@amd.com> References: <20211012171247.2861-1-alex.sierra@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 3865903e-9f37-4b5e-3087-08d98da38f61 X-MS-TrafficTypeDiagnostic: MN2PR12MB3005: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:1923; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: nC6OsJPcihZiuApiBkMugZby4z/h+bgAeCxCvQ/q2HzE/EqlZp1d7Wdj9c9YxFpj1XCZTDFOhWdDryQ/4pQkJcT5o69oENJGQoY43NKupF299KlCB7t5N0ca/SpgQwfUGVa5DUaeq0nCysa0KfSKDKObc2+CPwy0uiJAR7cGTg/mW8sSPtBDv+D3uagFD6Yc2lya0+Pv3FouJYvIHVbr/wuE3UFp2JeK5C/dCELoAQOMZDfV1ZAlvegGwzaR6HKSRoN6fiF3hlQ3Qjk/8wHipW3yXeNMfxp1Dzj5/iU2z/ah0vdnDITEErdSAOMjs1dJIRvY0Q7/Bvfq0IIMIt647M2LZF0S8lSFOLa1PUo0uez8CUy0bPCFrEYcQeYTNYZUdreiCr0NQjS5ODMDywKUAcsQtr05UzTEKJTAPPGguFIaR4i46ZuxWcl9N19giiNgKAO5MuwHKvTIQeIIMczAQH6nlcdL+ymq7tLgEj3HcU4mcOJCBRYkxCK/qFtZtcmu0Lc4BP/yZGSEJ+YVNwK+oHkKo1l4lsqpwylN82tYTIWIQMCE0S1UWnXPrKG0f2h4ov5kgWdYCAqkH194RzdAGqcowKg83YOPovLUO4UQ+3HPPf8MCmtGzbT1L4SbQPIH+HuCpTMk+CWzFzA4sAWkyiGrwIX+/EA5jO4RtDNk/pr0Rd55vtxwignR4HXZT6hHBtMvEkLez5FQNeLowlvjKeoBbNhc+dTenpOkILiJZCY= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(4636009)(36840700001)(46966006)(36756003)(5660300002)(47076005)(82310400003)(83380400001)(26005)(16526019)(54906003)(426003)(2616005)(8676002)(86362001)(316002)(6666004)(110136005)(81166007)(336012)(186003)(44832011)(8936002)(2906002)(7416002)(70586007)(356005)(70206006)(1076003)(36860700001)(7696005)(508600001)(4326008)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Oct 2021 17:13:07.2513 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3865903e-9f37-4b5e-3087-08d98da38f61 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT005.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB3005 X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: E8F164002085 X-Stat-Signature: ixm3mbwju15ixirc1yaqw9kpes5uwapk Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b="y/oG7tw1"; dmarc=pass (policy=quarantine) header.from=amd.com; spf=pass (imf18.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.220.86 as permitted sender) smtp.mailfrom=Alex.Sierra@amd.com X-HE-Tag: 1634058790-808463 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: In order to configure device coherent in test_hmm, two module parameters should be passed, which correspond to the SP start address of each device (2) spm_addr_dev0 & spm_addr_dev1. If no parameters are passed, private device type is configured. Signed-off-by: Alex Sierra --- lib/test_hmm.c | 66 +++++++++++++++++++++++++++++++-------------- lib/test_hmm_uapi.h | 1 + 2 files changed, 47 insertions(+), 20 deletions(-) diff --git a/lib/test_hmm.c b/lib/test_hmm.c index 3cd91ca31dd7..70a9be0efa00 100644 --- a/lib/test_hmm.c +++ b/lib/test_hmm.c @@ -33,6 +33,16 @@ #define DEVMEM_CHUNK_SIZE (256 * 1024 * 1024U) #define DEVMEM_CHUNKS_RESERVE 16 +static unsigned long spm_addr_dev0; +module_param(spm_addr_dev0, long, 0644); +MODULE_PARM_DESC(spm_addr_dev0, + "Specify start address for SPM (special purpose memory) used for device 0. By setting this Coherent device type will be used. Make sure spm_addr_dev1 is set too"); + +static unsigned long spm_addr_dev1; +module_param(spm_addr_dev1, long, 0644); +MODULE_PARM_DESC(spm_addr_dev1, + "Specify start address for SPM (special purpose memory) used for device 1. By setting this Coherent device type will be used. Make sure spm_addr_dev0 is set too"); + static const struct dev_pagemap_ops dmirror_devmem_ops; static const struct mmu_interval_notifier_ops dmirror_min_ops; static dev_t dmirror_dev; @@ -450,11 +460,11 @@ static int dmirror_write(struct dmirror *dmirror, struct hmm_dmirror_cmd *cmd) return ret; } -static bool dmirror_allocate_chunk(struct dmirror_device *mdevice, +static int dmirror_allocate_chunk(struct dmirror_device *mdevice, struct page **ppage) { struct dmirror_chunk *devmem; - struct resource *res; + struct resource *res = NULL; unsigned long pfn; unsigned long pfn_first; unsigned long pfn_last; @@ -462,17 +472,29 @@ static bool dmirror_allocate_chunk(struct dmirror_device *mdevice, devmem = kzalloc(sizeof(*devmem), GFP_KERNEL); if (!devmem) - return false; + return -ENOMEM; - res = request_free_mem_region(&iomem_resource, DEVMEM_CHUNK_SIZE, - "hmm_dmirror"); - if (IS_ERR(res)) - goto err_devmem; + if (!spm_addr_dev0 && !spm_addr_dev1) { + res = request_free_mem_region(&iomem_resource, DEVMEM_CHUNK_SIZE, + "hmm_dmirror"); + if (IS_ERR_OR_NULL(res)) + goto err_devmem; + devmem->pagemap.range.start = res->start; + devmem->pagemap.range.end = res->end; + devmem->pagemap.type = MEMORY_DEVICE_PRIVATE; + mdevice->zone_device_type = HMM_DMIRROR_MEMORY_DEVICE_PRIVATE; + } else if (spm_addr_dev0 && spm_addr_dev1) { + devmem->pagemap.range.start = MINOR(mdevice->cdevice.dev) ? + spm_addr_dev0 : + spm_addr_dev1; + devmem->pagemap.range.end = devmem->pagemap.range.start + + DEVMEM_CHUNK_SIZE - 1; + devmem->pagemap.type = MEMORY_DEVICE_COHERENT; + mdevice->zone_device_type = HMM_DMIRROR_MEMORY_DEVICE_COHERENT; + } else { + pr_err("Both spm_addr_dev parameters should be set\n"); + } - mdevice->zone_device_type = HMM_DMIRROR_MEMORY_DEVICE_PRIVATE; - devmem->pagemap.type = MEMORY_DEVICE_PRIVATE; - devmem->pagemap.range.start = res->start; - devmem->pagemap.range.end = res->end; devmem->pagemap.nr_range = 1; devmem->pagemap.ops = &dmirror_devmem_ops; devmem->pagemap.owner = mdevice; @@ -493,10 +515,14 @@ static bool dmirror_allocate_chunk(struct dmirror_device *mdevice, mdevice->devmem_capacity = new_capacity; mdevice->devmem_chunks = new_chunks; } - ptr = memremap_pages(&devmem->pagemap, numa_node_id()); - if (IS_ERR(ptr)) + if (IS_ERR_OR_NULL(ptr)) { + if (ptr) + ret = PTR_ERR(ptr); + else + ret = -EFAULT; goto err_release; + } devmem->mdevice = mdevice; pfn_first = devmem->pagemap.range.start >> PAGE_SHIFT; @@ -529,7 +555,8 @@ static bool dmirror_allocate_chunk(struct dmirror_device *mdevice, err_release: mutex_unlock(&mdevice->devmem_lock); - release_mem_region(devmem->pagemap.range.start, range_len(&devmem->pagemap.range)); + if (res) + release_mem_region(devmem->pagemap.range.start, range_len(&devmem->pagemap.range)); err_devmem: kfree(devmem); @@ -1097,10 +1124,8 @@ static int dmirror_device_init(struct dmirror_device *mdevice, int id) if (ret) return ret; - /* Build a list of free ZONE_DEVICE private struct pages */ - dmirror_allocate_chunk(mdevice, NULL); - - return 0; + /* Build a list of free ZONE_DEVICE struct pages */ + return dmirror_allocate_chunk(mdevice, NULL); } static void dmirror_device_remove(struct dmirror_device *mdevice) @@ -1113,8 +1138,9 @@ static void dmirror_device_remove(struct dmirror_device *mdevice) mdevice->devmem_chunks[i]; memunmap_pages(&devmem->pagemap); - release_mem_region(devmem->pagemap.range.start, - range_len(&devmem->pagemap.range)); + if (devmem->pagemap.type == MEMORY_DEVICE_PRIVATE) + release_mem_region(devmem->pagemap.range.start, + range_len(&devmem->pagemap.range)); kfree(devmem); } kfree(mdevice->devmem_chunks); diff --git a/lib/test_hmm_uapi.h b/lib/test_hmm_uapi.h index ee88701793d5..f86754be64fd 100644 --- a/lib/test_hmm_uapi.h +++ b/lib/test_hmm_uapi.h @@ -65,6 +65,7 @@ enum { enum { /* 0 is reserved to catch uninitialized type fields */ HMM_DMIRROR_MEMORY_DEVICE_PRIVATE = 1, + HMM_DMIRROR_MEMORY_DEVICE_COHERENT, }; #endif /* _LIB_TEST_HMM_UAPI_H */ From patchwork Tue Oct 12 17:12:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Sierra Guiza, Alejandro (Alex)" X-Patchwork-Id: 12553281 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 70766C433EF for ; Tue, 12 Oct 2021 17:13:24 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 0FEB2610C9 for ; Tue, 12 Oct 2021 17:13:24 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 0FEB2610C9 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=amd.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id A127490000C; Tue, 12 Oct 2021 13:13:11 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9C26E900005; Tue, 12 Oct 2021 13:13:11 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 83C0290000C; Tue, 12 Oct 2021 13:13:11 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0175.hostedemail.com [216.40.44.175]) by kanga.kvack.org (Postfix) with ESMTP id 6A80A900005 for ; Tue, 12 Oct 2021 13:13:11 -0400 (EDT) Received: from smtpin19.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 3061E1802EC3D for ; Tue, 12 Oct 2021 17:13:11 +0000 (UTC) X-FDA: 78688430982.19.1D28A17 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2078.outbound.protection.outlook.com [40.107.237.78]) by imf10.hostedemail.com (Postfix) with ESMTP id A4C9F6001987 for ; Tue, 12 Oct 2021 17:13:10 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bYuc6nPCRdHqQljtSwaei3Aur5OopUXtHwO1SiYiqylgKGvIj+4S5lApenyq4jR2KYwTwhOpbMYjFv5IUj/xAwyxCpc86SNHmlefWHRJsNECw3MQBjAg/hBUxwg0o43kgpuCPHU3qTaFR7VSN/AVuHSJyOOeKOO7b2YSIfzFQG0eKmfrecNshVR1O43S9H8/MdsChFJW6yS8n2IQ6XTlF1sqkmdUFHNdSIwFD+seVO3SMqAbY9GIe2GKV57mBvHzsYTYlq71W8iep4K3EY6MVK9qxE6W6/TE5CEF4OwswsaKA9YnJI+IC11NSPV3IXoVHH6YBtLhKvir/2jdp3ubcA== 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=1ZOiCyZwhLuHxcR5uQwpzd4k0pBr38tyPpHPo6FypKE=; b=D9uM5OOCr+HasHrtkySYt7rDhufw/+yGHSyc1JZUXwWLQLa0dnXxh45pB9v6hbMgkk/CVzSt+ATqNkmo1SxMRgZvbdTCXXggfQhIKws3USJG7SV0nFO7lGZGVqgJgTb5smbTAmjlIZMvwDH8LzcbMsPO+PtcqcHpDACeGirFytQq+lvp+R+Rx7A9ZA7A/pYIZw8LprsFkCuqqyFDL9oPQ6RrZnpPzkOkRJ56sY4BdeJjkNrnJApnXEj5rUzMvjNNJSHheH/9nsd5rwD2EX1eYsUIpMsSERleuTMXRLxHaW4g/+reP/QLC4Ci+vd3doDRYGZ/+OpIO+3MPTCY1PugPQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=linux-foundation.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=1ZOiCyZwhLuHxcR5uQwpzd4k0pBr38tyPpHPo6FypKE=; b=BLryTInlrrBdab1Exje+WMrBO4GXAOitMAdTL78t0Ba3OQUK1CBLgA14fGSMZBB/uUI2jJcA4YTh1VLfxm6ZfFJBLGN9OcMOdN4/Tim4ZhHM4kDtghs/hZB2XATY2VadmuMM8xjiDLW1zA8P1tzmb13bOUW7HjeY3VWp8H5HrWc= Received: from MWHPR14CA0012.namprd14.prod.outlook.com (2603:10b6:300:ae::22) by DM6PR12MB2716.namprd12.prod.outlook.com (2603:10b6:5:49::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4587.25; Tue, 12 Oct 2021 17:13:08 +0000 Received: from CO1NAM11FT018.eop-nam11.prod.protection.outlook.com (2603:10b6:300:ae:cafe::a6) by MWHPR14CA0012.outlook.office365.com (2603:10b6:300:ae::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4587.24 via Frontend Transport; Tue, 12 Oct 2021 17:13:08 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; linux-foundation.org; dkim=none (message not signed) header.d=none;linux-foundation.org; dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; Received: from SATLEXMB04.amd.com (165.204.84.17) by CO1NAM11FT018.mail.protection.outlook.com (10.13.175.16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4587.18 via Frontend Transport; Tue, 12 Oct 2021 17:13:07 +0000 Received: from alex-MS-7B09.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.8; Tue, 12 Oct 2021 12:13:04 -0500 From: Alex Sierra To: , , , , , CC: , , , , , Subject: [PATCH v1 10/12] lib: add support for device coherent type in test_hmm Date: Tue, 12 Oct 2021 12:12:45 -0500 Message-ID: <20211012171247.2861-11-alex.sierra@amd.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20211012171247.2861-1-alex.sierra@amd.com> References: <20211012171247.2861-1-alex.sierra@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 9ea873c8-9c64-49bf-a066-08d98da38f8a X-MS-TrafficTypeDiagnostic: DM6PR12MB2716: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7691; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 4sIcHxhKHeHvWkwJY8NT8nwh2WQaY1WHLxJZmm4z8tlyyqHKU8rcRy1ZO+4yRrRdf/Yukh3c5fvTL+hJOyCW1x2RItUg1LRXuZQ4P8JsdZkdUP/NLpO05JjBcib7ivLqiQ3h9MVTpqDl5NVxgF+vnv9pNZMWonsCREPT6CIH9lO1Qvo4lPyZpVH4ponEAFWYjq4v/UXY0XYPoLzKZo5e8HKZvjoPA+WC3wGICOrQr1V3XD4mv4iHZsnGFbtByaeq6C7oey7bBFO5RnxTu8R7OVRThg3LyoGMXG+r6dZ9trZzUu9ODktqetDJAxGEDq+TVIfl977CvTDDQveEV6zQ+4XVXptFdPY1uk3/PiJM5AWx/MurlL2A0chczibHYPH6swdVvjgqZ+xkZ5qrRxDVxfU9HRHAd2GU2iI0mZv2eg0XsSmA+NNgybSpfI9tcR6wIrnmrN/oW6cb9Xlgi293B4AzrEmrLrHNUell0Pupxq1ZCGaqc992rXnIkNK+zB3F6qicgNm9Euu4elDLrF9nPBnDqlEiTqFeDtcqsUvm0WFpxJmHgDcT17Zcw+y5f7WjEmqiOEKm2EvGIXpG8/qc+L5D9zRyUAgaUYNfFwnff9Xxtb85zJCAw5yBRExRNoXDO9NpTWs+ePN86FW2dLufprwy5azLezTB+m4bbPe/HRsTly8jmKcLvDguAU+7XMh9ON6FNYRG41IJE7mT89hE0083YJ3fRQb1hYGzvYuCjD8= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(4636009)(36840700001)(46966006)(54906003)(86362001)(30864003)(508600001)(81166007)(6666004)(7416002)(82310400003)(1076003)(316002)(70206006)(83380400001)(70586007)(356005)(8676002)(110136005)(426003)(5660300002)(2616005)(336012)(36860700001)(26005)(44832011)(4326008)(16526019)(186003)(36756003)(8936002)(7696005)(47076005)(2906002)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Oct 2021 17:13:07.5301 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 9ea873c8-9c64-49bf-a066-08d98da38f8a X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT018.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB2716 X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: A4C9F6001987 X-Stat-Signature: x7hz4s6uudrdprfyo4jo6xi7esderrna Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=BLryTInl; spf=pass (imf10.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.237.78 as permitted sender) smtp.mailfrom=Alex.Sierra@amd.com; dmarc=pass (policy=quarantine) header.from=amd.com X-HE-Tag: 1634058790-225302 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: Device Coherent type uses device memory that is coherently accesible by the CPU. This could be shown as SP (special purpose) memory range at the BIOS-e820 memory enumeration. If no SP memory is supported in system, this could be faked by setting CONFIG_EFI_FAKE_MEMMAP. Currently, test_hmm only supports two different SP ranges of at least 256MB size. This could be specified in the kernel parameter variable efi_fake_mem. Ex. Two SP ranges of 1GB starting at 0x100000000 & 0x140000000 physical address. Ex. efi_fake_mem=1G@0x100000000:0x40000,1G@0x140000000:0x40000 Signed-off-by: Alex Sierra --- lib/test_hmm.c | 195 ++++++++++++++++++++++++++++++++------------ lib/test_hmm_uapi.h | 16 +++- 2 files changed, 157 insertions(+), 54 deletions(-) diff --git a/lib/test_hmm.c b/lib/test_hmm.c index 70a9be0efa00..b349dd920f04 100644 --- a/lib/test_hmm.c +++ b/lib/test_hmm.c @@ -469,6 +469,7 @@ static int dmirror_allocate_chunk(struct dmirror_device *mdevice, unsigned long pfn_first; unsigned long pfn_last; void *ptr; + int ret = -ENOMEM; devmem = kzalloc(sizeof(*devmem), GFP_KERNEL); if (!devmem) @@ -551,7 +552,7 @@ static int dmirror_allocate_chunk(struct dmirror_device *mdevice, } spin_unlock(&mdevice->lock); - return true; + return 0; err_release: mutex_unlock(&mdevice->devmem_lock); @@ -560,7 +561,7 @@ static int dmirror_allocate_chunk(struct dmirror_device *mdevice, err_devmem: kfree(devmem); - return false; + return ret; } static struct page *dmirror_devmem_alloc_page(struct dmirror_device *mdevice) @@ -569,13 +570,14 @@ static struct page *dmirror_devmem_alloc_page(struct dmirror_device *mdevice) struct page *rpage; /* - * This is a fake device so we alloc real system memory to store - * our device memory. + * For ZONE_DEVICE private type, this is a fake device so we alloc real + * system memory to store our device memory. + * For ZONE_DEVICE coherent type we use the actual dpage to store the data + * and ignore rpage. */ rpage = alloc_page(GFP_HIGHUSER); if (!rpage) return NULL; - spin_lock(&mdevice->lock); if (mdevice->free_pages) { @@ -603,7 +605,7 @@ static void dmirror_migrate_alloc_and_copy(struct migrate_vma *args, struct dmirror *dmirror) { struct dmirror_device *mdevice = dmirror->mdevice; - const unsigned long *src = args->src; + unsigned long *src = args->src; unsigned long *dst = args->dst; unsigned long addr; @@ -621,12 +623,17 @@ static void dmirror_migrate_alloc_and_copy(struct migrate_vma *args, * unallocated pte_none() or read-only zero page. */ spage = migrate_pfn_to_page(*src); + if (spage && is_zone_device_page(spage)) + pr_err("page already in device spage pfn: 0x%lx\n", + page_to_pfn(spage)); + BUG_ON(spage && is_zone_device_page(spage)); dpage = dmirror_devmem_alloc_page(mdevice); if (!dpage) continue; - rpage = dpage->zone_device_data; + rpage = is_device_private_page(dpage) ? dpage->zone_device_data : + dpage; if (spage) copy_highpage(rpage, spage); else @@ -638,8 +645,10 @@ static void dmirror_migrate_alloc_and_copy(struct migrate_vma *args, * the simulated device memory and that page holds the pointer * to the mirror. */ + rpage = dpage->zone_device_data; rpage->zone_device_data = dmirror; - + pr_debug("migrating from sys to dev pfn src: 0x%lx pfn dst: 0x%lx\n", + page_to_pfn(spage), page_to_pfn(dpage)); *dst = migrate_pfn(page_to_pfn(dpage)) | MIGRATE_PFN_LOCKED; if ((*src & MIGRATE_PFN_WRITE) || @@ -673,10 +682,13 @@ static int dmirror_migrate_finalize_and_map(struct migrate_vma *args, continue; /* - * Store the page that holds the data so the page table - * doesn't have to deal with ZONE_DEVICE private pages. + * For ZONE_DEVICE private pages we store the page that + * holds the data so the page table doesn't have to deal it. + * For ZONE_DEVICE coherent pages we store the actual page, since + * the CPU has coherent access to the page. */ - entry = dpage->zone_device_data; + entry = is_device_private_page(dpage) ? dpage->zone_device_data : + dpage; if (*dst & MIGRATE_PFN_WRITE) entry = xa_tag_pointer(entry, DPT_XA_TAG_WRITE); entry = xa_store(&dmirror->pt, pfn, entry, GFP_ATOMIC); @@ -690,7 +702,110 @@ static int dmirror_migrate_finalize_and_map(struct migrate_vma *args, return 0; } -static int dmirror_migrate(struct dmirror *dmirror, +static vm_fault_t dmirror_devmem_fault_alloc_and_copy(struct migrate_vma *args, + struct dmirror *dmirror) +{ + unsigned long *src = args->src; + unsigned long *dst = args->dst; + unsigned long start = args->start; + unsigned long end = args->end; + unsigned long addr; + + for (addr = start; addr < end; addr += PAGE_SIZE, + src++, dst++) { + struct page *dpage, *spage; + + spage = migrate_pfn_to_page(*src); + if (!spage || !(*src & MIGRATE_PFN_MIGRATE)) + continue; + + BUG_ON(!is_device_page(spage)); + spage = is_device_private_page(spage) ? spage->zone_device_data: + spage; + dpage = alloc_page_vma(GFP_HIGHUSER_MOVABLE, args->vma, addr); + if (!dpage) + continue; + pr_debug("migrating from dev to sys pfn src: 0x%lx pfn dst: 0x%lx\n", + page_to_pfn(spage), page_to_pfn(dpage)); + + lock_page(dpage); + xa_erase(&dmirror->pt, addr >> PAGE_SHIFT); + copy_highpage(dpage, spage); + *dst = migrate_pfn(page_to_pfn(dpage)) | MIGRATE_PFN_LOCKED; + if (*src & MIGRATE_PFN_WRITE) + *dst |= MIGRATE_PFN_WRITE; + } + return 0; +} + +static int dmirror_migrate_to_system(struct dmirror *dmirror, + struct hmm_dmirror_cmd *cmd) +{ + unsigned long start, end, addr; + unsigned long size = cmd->npages << PAGE_SHIFT; + struct mm_struct *mm = dmirror->notifier.mm; + struct vm_area_struct *vma; + unsigned long src_pfns[64]; + unsigned long dst_pfns[64]; + struct migrate_vma args; + unsigned long next; + int ret; + + start = cmd->addr; + end = start + size; + if (end < start) + return -EINVAL; + + /* Since the mm is for the mirrored process, get a reference first. */ + if (!mmget_not_zero(mm)) + return -EINVAL; + + mmap_read_lock(mm); + for (addr = start; addr < end; addr = next) { + vma = find_vma(mm, addr); + if (!vma || addr < vma->vm_start || + !(vma->vm_flags & VM_READ)) { + ret = -EINVAL; + goto out; + } + next = min(end, addr + (ARRAY_SIZE(src_pfns) << PAGE_SHIFT)); + if (next > vma->vm_end) + next = vma->vm_end; + + args.vma = vma; + args.src = src_pfns; + args.dst = dst_pfns; + args.start = addr; + args.end = next; + args.pgmap_owner = dmirror->mdevice; + args.flags = (dmirror->mdevice->zone_device_type == + HMM_DMIRROR_MEMORY_DEVICE_PRIVATE) ? + MIGRATE_VMA_SELECT_DEVICE_PRIVATE : + MIGRATE_VMA_SELECT_DEVICE_COHERENT; + + ret = migrate_vma_setup(&args); + if (ret) + goto out; + + pr_debug("Migrating from device mem to sys mem\n"); + dmirror_devmem_fault_alloc_and_copy(&args, dmirror); + + migrate_vma_pages(&args); + migrate_vma_finalize(&args); + } + mmap_read_unlock(mm); + mmput(mm); + + return ret; + +out: + mmap_read_unlock(mm); + mmput(mm); + return ret; +} + + +static int dmirror_migrate_to_device(struct dmirror *dmirror, struct hmm_dmirror_cmd *cmd) { unsigned long start, end, addr; @@ -736,6 +851,7 @@ static int dmirror_migrate(struct dmirror *dmirror, if (ret) goto out; + pr_debug("Migrating from sys mem to device mem\n"); dmirror_migrate_alloc_and_copy(&args, dmirror); migrate_vma_pages(&args); dmirror_migrate_finalize_and_map(&args, dmirror); @@ -744,7 +860,7 @@ static int dmirror_migrate(struct dmirror *dmirror, mmap_read_unlock(mm); mmput(mm); - /* Return the migrated data for verification. */ + /* Return the migrated data for verification. only for pages in device zone */ ret = dmirror_bounce_init(&bounce, start, size); if (ret) return ret; @@ -758,6 +874,7 @@ static int dmirror_migrate(struct dmirror *dmirror, } cmd->cpages = bounce.cpages; dmirror_bounce_fini(&bounce); + return ret; out: @@ -781,9 +898,15 @@ static void dmirror_mkentry(struct dmirror *dmirror, struct hmm_range *range, } page = hmm_pfn_to_page(entry); - if (is_device_private_page(page)) { - /* Is the page migrated to this device or some other? */ - if (dmirror->mdevice == dmirror_page_to_device(page)) + if (is_device_page(page)) { + /* Is page ZONE_DEVICE coherent? */ + if (!is_device_private_page(page)) + *perm = HMM_DMIRROR_PROT_DEV_COHERENT; + /* + * Is page ZONE_DEVICE private migrated to + * this device or some other? + */ + else if (dmirror->mdevice == dmirror_page_to_device(page)) *perm = HMM_DMIRROR_PROT_DEV_PRIVATE_LOCAL; else *perm = HMM_DMIRROR_PROT_DEV_PRIVATE_REMOTE; @@ -983,8 +1106,12 @@ static long dmirror_fops_unlocked_ioctl(struct file *filp, ret = dmirror_write(dmirror, &cmd); break; - case HMM_DMIRROR_MIGRATE: - ret = dmirror_migrate(dmirror, &cmd); + case HMM_DMIRROR_MIGRATE_TO_DEV: + ret = dmirror_migrate_to_device(dmirror, &cmd); + break; + + case HMM_DMIRROR_MIGRATE_TO_SYS: + ret = dmirror_migrate_to_system(dmirror, &cmd); break; case HMM_DMIRROR_SNAPSHOT: @@ -1030,38 +1157,6 @@ static void dmirror_devmem_free(struct page *page) spin_unlock(&mdevice->lock); } -static vm_fault_t dmirror_devmem_fault_alloc_and_copy(struct migrate_vma *args, - struct dmirror *dmirror) -{ - const unsigned long *src = args->src; - unsigned long *dst = args->dst; - unsigned long start = args->start; - unsigned long end = args->end; - unsigned long addr; - - for (addr = start; addr < end; addr += PAGE_SIZE, - src++, dst++) { - struct page *dpage, *spage; - - spage = migrate_pfn_to_page(*src); - if (!spage || !(*src & MIGRATE_PFN_MIGRATE)) - continue; - spage = spage->zone_device_data; - - dpage = alloc_page_vma(GFP_HIGHUSER_MOVABLE, args->vma, addr); - if (!dpage) - continue; - - lock_page(dpage); - xa_erase(&dmirror->pt, addr >> PAGE_SHIFT); - copy_highpage(dpage, spage); - *dst = migrate_pfn(page_to_pfn(dpage)) | MIGRATE_PFN_LOCKED; - if (*src & MIGRATE_PFN_WRITE) - *dst |= MIGRATE_PFN_WRITE; - } - return 0; -} - static vm_fault_t dmirror_devmem_fault(struct vm_fault *vmf) { struct migrate_vma args; diff --git a/lib/test_hmm_uapi.h b/lib/test_hmm_uapi.h index f86754be64fd..13cec485328d 100644 --- a/lib/test_hmm_uapi.h +++ b/lib/test_hmm_uapi.h @@ -17,8 +17,12 @@ * @addr: (in) user address the device will read/write * @ptr: (in) user address where device data is copied to/from * @npages: (in) number of pages to read/write + * @alloc_to_devmem: (in) desired allocation destination during migration. + * True if allocation is to device memory. + * False if allocation is to system memory. * @cpages: (out) number of pages copied * @faults: (out) number of device page faults seen + * @zone_device_type: (out) zone device memory type */ struct hmm_dmirror_cmd { __u64 addr; @@ -26,15 +30,16 @@ struct hmm_dmirror_cmd { __u64 npages; __u64 cpages; __u64 faults; - __u64 zone_device_type; + __u32 zone_device_type; }; /* Expose the address space of the calling process through hmm device file */ #define HMM_DMIRROR_READ _IOWR('H', 0x00, struct hmm_dmirror_cmd) #define HMM_DMIRROR_WRITE _IOWR('H', 0x01, struct hmm_dmirror_cmd) -#define HMM_DMIRROR_MIGRATE _IOWR('H', 0x02, struct hmm_dmirror_cmd) -#define HMM_DMIRROR_SNAPSHOT _IOWR('H', 0x03, struct hmm_dmirror_cmd) -#define HMM_DMIRROR_GET_MEM_DEV_TYPE _IOWR('H', 0x04, struct hmm_dmirror_cmd) +#define HMM_DMIRROR_MIGRATE_TO_DEV _IOWR('H', 0x02, struct hmm_dmirror_cmd) +#define HMM_DMIRROR_MIGRATE_TO_SYS _IOWR('H', 0x03, struct hmm_dmirror_cmd) +#define HMM_DMIRROR_SNAPSHOT _IOWR('H', 0x04, struct hmm_dmirror_cmd) +#define HMM_DMIRROR_GET_MEM_DEV_TYPE _IOWR('H', 0x05, struct hmm_dmirror_cmd) /* * Values returned in hmm_dmirror_cmd.ptr for HMM_DMIRROR_SNAPSHOT. @@ -49,6 +54,8 @@ struct hmm_dmirror_cmd { * device the ioctl() is made * HMM_DMIRROR_PROT_DEV_PRIVATE_REMOTE: Migrated device private page on some * other device + * HMM_DMIRROR_PROT_DEV_COHERENT: Migrate device coherent page on the device + * the ioctl() is made */ enum { HMM_DMIRROR_PROT_ERROR = 0xFF, @@ -60,6 +67,7 @@ enum { HMM_DMIRROR_PROT_ZERO = 0x10, HMM_DMIRROR_PROT_DEV_PRIVATE_LOCAL = 0x20, HMM_DMIRROR_PROT_DEV_PRIVATE_REMOTE = 0x30, + HMM_DMIRROR_PROT_DEV_COHERENT = 0x40, }; enum { From patchwork Tue Oct 12 17:12:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Sierra Guiza, Alejandro (Alex)" X-Patchwork-Id: 12553287 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D31A0C433F5 for ; Tue, 12 Oct 2021 17:13:31 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 74A1761076 for ; Tue, 12 Oct 2021 17:13:31 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 74A1761076 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=amd.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id BC05F90000F; Tue, 12 Oct 2021 13:13:13 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B70DB900005; Tue, 12 Oct 2021 13:13:13 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A0F5A90000F; Tue, 12 Oct 2021 13:13:13 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0241.hostedemail.com [216.40.44.241]) by kanga.kvack.org (Postfix) with ESMTP id 87F47900005 for ; Tue, 12 Oct 2021 13:13:13 -0400 (EDT) Received: from smtpin02.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 45D462A016 for ; Tue, 12 Oct 2021 17:13:13 +0000 (UTC) X-FDA: 78688431066.02.69F2D18 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2061.outbound.protection.outlook.com [40.107.237.61]) by imf11.hostedemail.com (Postfix) with ESMTP id B962AF0000A1 for ; Tue, 12 Oct 2021 17:13:12 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=JBr3PTy2iWQRBXbM+7OOl+T15P1U+n6qoc2K+wcwjIiY8ZynzOlH9cK0xu2ouzEreeZX5u9z3sZFXXeOaHxLIXaQNeusPcILo47yvKha/4J1C1zTssMVFjO1g02TeNV/ZUJ4WMtve9nsSO+l9+0N5RCzNWrDVSQF1FMzALmaezvE3yu0en+e+PNxW0B8HUwSWD8EA9TpFRqqHJO2iATjvQiu4zIfrPHMoSQtlG2Qmk3Lx3FfTx/eTHaZJ4Fy6lKyMe1JEvqJWHeL8DzxX977h3B90BBFytJHSIErVtPjizQ4VOrp3PKX4ES6KvPX/0UzZN+TFg8McpI2fxuxsS/3mA== 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=iamvFjgRjIMJB2I8jh9CLmBei2xz89JvGnkoZQXu/y8=; b=bXD+0aguYWgI3p6mGF+yxlMkj7isbLaHG3P4Nn0qoZNw6zrMIUe1WVQBaDpprl7h38ZjLrgbbQJ2mg+kus8qWEcuSOaNkKGU+byr6ghzRpmRAZcka73R6r9z1iEFDg/aEqeGmQmSOCNASy9ffDdltuUTpbyD4WsrDNQK0romIjzY0xwDY9tgBAHxyfEfWGKEiJa/0V42g+D0aXkXcICeDza9glM1FAu8qqq96UhrpT+Rt/RI16XW8lsBEQwrMzB/IgwhhPNeu/DMjHKr2Pbvh+QQ11t/deP/hRfafxWoZ7B2kws2xstRYBKxY9wxZ/gk+nZ1Qvb1HzHhT5QkPGhFmg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=linux-foundation.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=iamvFjgRjIMJB2I8jh9CLmBei2xz89JvGnkoZQXu/y8=; b=FYgeq99m8DVnSrxEqyStM2vjzUmmHTK8EHdT45fedBGZ8/czBENIM5w3KWcUZccfFX3a3WexY8BdOP6zhrmTt9F42+GSE4B/QUeobwpOOr0mJSErII4iB86rFY6wK9ulw+SKEGl+gUDiX71XgAWIPo24mAe8RqyXkzT7tPMSNq4= Received: from MW4PR04CA0276.namprd04.prod.outlook.com (2603:10b6:303:89::11) by DM6PR12MB4266.namprd12.prod.outlook.com (2603:10b6:5:21a::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4587.20; Tue, 12 Oct 2021 17:13:08 +0000 Received: from CO1NAM11FT005.eop-nam11.prod.protection.outlook.com (2603:10b6:303:89:cafe::14) by MW4PR04CA0276.outlook.office365.com (2603:10b6:303:89::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4587.19 via Frontend Transport; Tue, 12 Oct 2021 17:13:08 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; linux-foundation.org; dkim=none (message not signed) header.d=none;linux-foundation.org; dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; Received: from SATLEXMB04.amd.com (165.204.84.17) by CO1NAM11FT005.mail.protection.outlook.com (10.13.174.147) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4587.18 via Frontend Transport; Tue, 12 Oct 2021 17:13:08 +0000 Received: from alex-MS-7B09.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.8; Tue, 12 Oct 2021 12:13:05 -0500 From: Alex Sierra To: , , , , , CC: , , , , , Subject: [PATCH v1 11/12] tools: update hmm-test to support device coherent type Date: Tue, 12 Oct 2021 12:12:46 -0500 Message-ID: <20211012171247.2861-12-alex.sierra@amd.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20211012171247.2861-1-alex.sierra@amd.com> References: <20211012171247.2861-1-alex.sierra@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 4d74ac4b-2c88-41e9-c1d8-08d98da38ffa X-MS-TrafficTypeDiagnostic: DM6PR12MB4266: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:5797; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: pKz/4+p+mEMWWie870AMayz4cI1RTtDSFVbDFgm+T5J+mfwQ6If0OgoDMyTIvsF/X23I6vXmQFJbT+IyY323YKF+MdR29CzSA6/A/ZyebYbI2wuOz/VNzuNlvrvsq2yuuEh281SowlUSu55/t4dUTRO8tgKOR3RU8awrITBmRIzKJROxvK7v/MZRmsXPmmwRC+u0nfHut6lDw5+vMlIeucAOAOyrajMMk+SklFDpCChceX4OsLQQWgByWTdZPXE9VUg3YRKTYzlg/TiQikosLqJ2xf5diLnmkjU9xAsjpdlvTxrSH1/VrqWgOqXOy5LJ8aAqGO5XmDMPfZzlFGy6Ri5vITr/J1ES2BLNgCDl9LBVeSW8b2pSwdnXZrCJKP2hhHzTgF5TsOe6AHNR+2lyaIk4fAkOHteIOABHS053r3iwutXSMaJRxJouJLpUMfb0LtkTH/ubZ814hG4gA9pRYly2mGyG/7Rgpm0mip+tAxuedAebcGHz0atpf7H0IrkoTkM82AW5X4Bb5MKIxOTtfKZb2k2slN0VMFyUbFfzMoQ7Gj6pJbnNkoTYnBN6TY8VVyUHmLr6hhxheYzBLa6jDmNOOM+FveH2rXZpHTTCPlenNdwZhhFpFrs4axalDONW/eV+LB+gxPwTsIg3ip5MCVW94hJdRq6VLwMoHWeMpjuMGDD/e0c+5FC/f3vCpSEujnwtdRRu6eFNb+i5fJdcBe1gCp8h7iRExHOG7Dr0FFY= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(4636009)(46966006)(36840700001)(16526019)(316002)(186003)(6666004)(356005)(36756003)(81166007)(83380400001)(8676002)(8936002)(2906002)(36860700001)(7696005)(4326008)(336012)(47076005)(2616005)(82310400003)(5660300002)(426003)(86362001)(70586007)(110136005)(26005)(1076003)(7416002)(70206006)(54906003)(44832011)(15650500001)(508600001)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Oct 2021 17:13:08.2628 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 4d74ac4b-2c88-41e9-c1d8-08d98da38ffa X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT005.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4266 X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: B962AF0000A1 X-Stat-Signature: kg8azs17f7sn6ytizkyi3feebz1mcot4 Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=FYgeq99m; dmarc=pass (policy=quarantine) header.from=amd.com; spf=pass (imf11.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.237.61 as permitted sender) smtp.mailfrom=Alex.Sierra@amd.com X-HE-Tag: 1634058792-462156 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: Test cases such as migrate_fault and migrate_multiple, were modified to explicit migrate from device to sys memory without the need of page faults, when using device coherent type. Snapshot test case updated to read memory device type first and based on that, get the proper returned results migrate_ping_pong test case added to test explicit migration from device to sys memory for both private and coherent zone types. Helpers to migrate from device to sys memory and vicerversa were also added. Signed-off-by: Alex Sierra --- tools/testing/selftests/vm/hmm-tests.c | 137 +++++++++++++++++++++---- 1 file changed, 119 insertions(+), 18 deletions(-) diff --git a/tools/testing/selftests/vm/hmm-tests.c b/tools/testing/selftests/vm/hmm-tests.c index 5d1ac691b9f4..e7fa87618dd5 100644 --- a/tools/testing/selftests/vm/hmm-tests.c +++ b/tools/testing/selftests/vm/hmm-tests.c @@ -44,6 +44,7 @@ struct hmm_buffer { int fd; uint64_t cpages; uint64_t faults; + int zone_device_type; }; #define TWOMEG (1 << 21) @@ -144,6 +145,7 @@ static int hmm_dmirror_cmd(int fd, } buffer->cpages = cmd.cpages; buffer->faults = cmd.faults; + buffer->zone_device_type = cmd.zone_device_type; return 0; } @@ -211,6 +213,32 @@ static void hmm_nanosleep(unsigned int n) nanosleep(&t, NULL); } +static int hmm_migrate_sys_to_dev(int fd, + struct hmm_buffer *buffer, + unsigned long npages) +{ + return hmm_dmirror_cmd(fd, HMM_DMIRROR_MIGRATE_TO_DEV, buffer, npages); +} + +static int hmm_migrate_dev_to_sys(int fd, + struct hmm_buffer *buffer, + unsigned long npages) +{ + return hmm_dmirror_cmd(fd, HMM_DMIRROR_MIGRATE_TO_SYS, buffer, npages); +} + +static int hmm_is_private_device(int fd, bool *res) +{ + struct hmm_buffer buffer; + int ret; + + buffer.ptr = 0; + ret = hmm_dmirror_cmd(fd, HMM_DMIRROR_GET_MEM_DEV_TYPE, &buffer, 1); + *res = (buffer.zone_device_type == HMM_DMIRROR_MEMORY_DEVICE_PRIVATE); + + return ret; +} + /* * Simple NULL test of device open/close. */ @@ -875,7 +903,7 @@ TEST_F(hmm, migrate) ptr[i] = i; /* Migrate memory to device. */ - ret = hmm_dmirror_cmd(self->fd, HMM_DMIRROR_MIGRATE, buffer, npages); + ret = hmm_migrate_sys_to_dev(self->fd, buffer, npages); ASSERT_EQ(ret, 0); ASSERT_EQ(buffer->cpages, npages); @@ -923,7 +951,7 @@ TEST_F(hmm, migrate_fault) ptr[i] = i; /* Migrate memory to device. */ - ret = hmm_dmirror_cmd(self->fd, HMM_DMIRROR_MIGRATE, buffer, npages); + ret = hmm_migrate_sys_to_dev(self->fd, buffer, npages); ASSERT_EQ(ret, 0); ASSERT_EQ(buffer->cpages, npages); @@ -936,7 +964,7 @@ TEST_F(hmm, migrate_fault) ASSERT_EQ(ptr[i], i); /* Migrate memory to the device again. */ - ret = hmm_dmirror_cmd(self->fd, HMM_DMIRROR_MIGRATE, buffer, npages); + ret = hmm_migrate_sys_to_dev(self->fd, buffer, npages); ASSERT_EQ(ret, 0); ASSERT_EQ(buffer->cpages, npages); @@ -976,7 +1004,7 @@ TEST_F(hmm, migrate_shared) ASSERT_NE(buffer->ptr, MAP_FAILED); /* Migrate memory to device. */ - ret = hmm_dmirror_cmd(self->fd, HMM_DMIRROR_MIGRATE, buffer, npages); + ret = hmm_migrate_sys_to_dev(self->fd, buffer, npages); ASSERT_EQ(ret, -ENOENT); hmm_buffer_free(buffer); @@ -1015,7 +1043,7 @@ TEST_F(hmm2, migrate_mixed) p = buffer->ptr; /* Migrating a protected area should be an error. */ - ret = hmm_dmirror_cmd(self->fd1, HMM_DMIRROR_MIGRATE, buffer, npages); + ret = hmm_migrate_sys_to_dev(self->fd1, buffer, npages); ASSERT_EQ(ret, -EINVAL); /* Punch a hole after the first page address. */ @@ -1023,7 +1051,7 @@ TEST_F(hmm2, migrate_mixed) ASSERT_EQ(ret, 0); /* We expect an error if the vma doesn't cover the range. */ - ret = hmm_dmirror_cmd(self->fd1, HMM_DMIRROR_MIGRATE, buffer, 3); + ret = hmm_migrate_sys_to_dev(self->fd1, buffer, 3); ASSERT_EQ(ret, -EINVAL); /* Page 2 will be a read-only zero page. */ @@ -1055,13 +1083,13 @@ TEST_F(hmm2, migrate_mixed) /* Now try to migrate pages 2-5 to device 1. */ buffer->ptr = p + 2 * self->page_size; - ret = hmm_dmirror_cmd(self->fd1, HMM_DMIRROR_MIGRATE, buffer, 4); + ret = hmm_migrate_sys_to_dev(self->fd1, buffer, 4); ASSERT_EQ(ret, 0); ASSERT_EQ(buffer->cpages, 4); /* Page 5 won't be migrated to device 0 because it's on device 1. */ buffer->ptr = p + 5 * self->page_size; - ret = hmm_dmirror_cmd(self->fd0, HMM_DMIRROR_MIGRATE, buffer, 1); + ret = hmm_migrate_sys_to_dev(self->fd0, buffer, 1); ASSERT_EQ(ret, -ENOENT); buffer->ptr = p; @@ -1070,8 +1098,12 @@ TEST_F(hmm2, migrate_mixed) } /* - * Migrate anonymous memory to device private memory and fault it back to system - * memory multiple times. + * Migrate anonymous memory to device memory and back to system memory + * multiple times. In case of private zone configuration, this is done + * through fault pages accessed by CPU. In case of coherent zone configuration, + * the pages from the device should be explicitly migrated back to system memory. + * The reason is Coherent device zone has coherent access to CPU, therefore + * it will not generate any page fault. */ TEST_F(hmm, migrate_multiple) { @@ -1082,7 +1114,9 @@ TEST_F(hmm, migrate_multiple) unsigned long c; int *ptr; int ret; + bool is_private; + ASSERT_EQ(hmm_is_private_device(self->fd, &is_private), 0); npages = ALIGN(HMM_BUFFER_SIZE, self->page_size) >> self->page_shift; ASSERT_NE(npages, 0); size = npages << self->page_shift; @@ -1107,8 +1141,7 @@ TEST_F(hmm, migrate_multiple) ptr[i] = i; /* Migrate memory to device. */ - ret = hmm_dmirror_cmd(self->fd, HMM_DMIRROR_MIGRATE, buffer, - npages); + ret = hmm_migrate_sys_to_dev(self->fd, buffer, npages); ASSERT_EQ(ret, 0); ASSERT_EQ(buffer->cpages, npages); @@ -1116,7 +1149,12 @@ TEST_F(hmm, migrate_multiple) for (i = 0, ptr = buffer->mirror; i < size / sizeof(*ptr); ++i) ASSERT_EQ(ptr[i], i); - /* Fault pages back to system memory and check them. */ + /* Migrate back to system memory and check them. */ + if (!is_private) { + ret = hmm_migrate_dev_to_sys(self->fd, buffer, npages); + ASSERT_EQ(ret, 0); + } + for (i = 0, ptr = buffer->ptr; i < size / sizeof(*ptr); ++i) ASSERT_EQ(ptr[i], i); @@ -1261,10 +1299,12 @@ TEST_F(hmm2, snapshot) unsigned char *m; int ret; int val; + bool is_private; npages = 7; size = npages << self->page_shift; + ASSERT_EQ(hmm_is_private_device(self->fd0, &is_private), 0); buffer = malloc(sizeof(*buffer)); ASSERT_NE(buffer, NULL); @@ -1312,13 +1352,13 @@ TEST_F(hmm2, snapshot) /* Page 5 will be migrated to device 0. */ buffer->ptr = p + 5 * self->page_size; - ret = hmm_dmirror_cmd(self->fd0, HMM_DMIRROR_MIGRATE, buffer, 1); + ret = hmm_migrate_sys_to_dev(self->fd0, buffer, 1); ASSERT_EQ(ret, 0); ASSERT_EQ(buffer->cpages, 1); /* Page 6 will be migrated to device 1. */ buffer->ptr = p + 6 * self->page_size; - ret = hmm_dmirror_cmd(self->fd1, HMM_DMIRROR_MIGRATE, buffer, 1); + ret = hmm_migrate_sys_to_dev(self->fd1, buffer, 1); ASSERT_EQ(ret, 0); ASSERT_EQ(buffer->cpages, 1); @@ -1335,9 +1375,16 @@ TEST_F(hmm2, snapshot) ASSERT_EQ(m[2], HMM_DMIRROR_PROT_ZERO | HMM_DMIRROR_PROT_READ); ASSERT_EQ(m[3], HMM_DMIRROR_PROT_READ); ASSERT_EQ(m[4], HMM_DMIRROR_PROT_WRITE); - ASSERT_EQ(m[5], HMM_DMIRROR_PROT_DEV_PRIVATE_LOCAL | - HMM_DMIRROR_PROT_WRITE); - ASSERT_EQ(m[6], HMM_DMIRROR_PROT_NONE); + if (is_private) { + ASSERT_EQ(m[5], HMM_DMIRROR_PROT_DEV_PRIVATE_LOCAL | + HMM_DMIRROR_PROT_WRITE); + ASSERT_EQ(m[6], HMM_DMIRROR_PROT_NONE); + } else { + ASSERT_EQ(m[5], HMM_DMIRROR_PROT_DEV_COHERENT | + HMM_DMIRROR_PROT_WRITE); + ASSERT_EQ(m[6], HMM_DMIRROR_PROT_DEV_COHERENT | + HMM_DMIRROR_PROT_WRITE); + } hmm_buffer_free(buffer); } @@ -1485,4 +1532,58 @@ TEST_F(hmm2, double_map) hmm_buffer_free(buffer); } +/* + * Migrate anonymous memory to device memory and migrate back to system memory + * explicitly, without generating a page fault. + */ +TEST_F(hmm, migrate_ping_pong) +{ + struct hmm_buffer *buffer; + unsigned long npages; + unsigned long size; + unsigned long i; + int *ptr; + int ret; + + npages = ALIGN(HMM_BUFFER_SIZE, self->page_size) >> self->page_shift; + ASSERT_NE(npages, 0); + size = npages << self->page_shift; + + buffer = malloc(sizeof(*buffer)); + ASSERT_NE(buffer, NULL); + + buffer->fd = -1; + buffer->size = size; + buffer->mirror = malloc(size); + ASSERT_NE(buffer->mirror, NULL); + + buffer->ptr = mmap(NULL, size, + PROT_READ | PROT_WRITE, + MAP_PRIVATE | MAP_ANONYMOUS, + buffer->fd, 0); + ASSERT_NE(buffer->ptr, MAP_FAILED); + + /* Initialize buffer in system memory. */ + for (i = 0, ptr = buffer->ptr; i < size / sizeof(*ptr); ++i) + ptr[i] = i; + + /* Migrate memory to device. */ + ret = hmm_migrate_sys_to_dev(self->fd, buffer, npages); + ASSERT_EQ(ret, 0); + ASSERT_EQ(buffer->cpages, npages); + /* Check what the device read. */ + for (i = 0, ptr = buffer->mirror; i < size / sizeof(*ptr); ++i) + ASSERT_EQ(ptr[i], i); + + /* Migrate memory back to system mem. */ + ret = hmm_migrate_dev_to_sys(self->fd, buffer, npages); + ASSERT_EQ(ret, 0); + + /* Check the buffer migrated back to system memory. */ + for (i = 0, ptr = buffer->ptr; i < size / sizeof(*ptr); ++i) + ASSERT_EQ(ptr[i], i); + + hmm_buffer_free(buffer); +} + TEST_HARNESS_MAIN From patchwork Tue Oct 12 17:12:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Sierra Guiza, Alejandro (Alex)" X-Patchwork-Id: 12553285 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 78814C433F5 for ; Tue, 12 Oct 2021 17:13:29 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 29F8160F21 for ; Tue, 12 Oct 2021 17:13:29 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 29F8160F21 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=amd.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 68EA890000E; Tue, 12 Oct 2021 13:13:12 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 63DE7900005; Tue, 12 Oct 2021 13:13:12 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4C3A290000E; Tue, 12 Oct 2021 13:13:12 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 3CEF3900005 for ; Tue, 12 Oct 2021 13:13:12 -0400 (EDT) Received: from smtpin10.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 0114982499A8 for ; Tue, 12 Oct 2021 17:13:11 +0000 (UTC) X-FDA: 78688431024.10.1398786 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2089.outbound.protection.outlook.com [40.107.237.89]) by imf25.hostedemail.com (Postfix) with ESMTP id 8743DB000181 for ; Tue, 12 Oct 2021 17:13:11 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MidAhIUk94iimxJrp5a4ElPHGPX0p+HYvsliDBIOykluI5unwxEYCInu0oC+5+CDFpYbQOaVxZCZt0jTM513qLPnU988vUsNcuGCzNHvERsN3s6bwZBAxjhKgEpLqwncPp9chndz0xVMy6uR0HlJsakf8NTALUqI9wnhrTnEnGdPUzoFipgEnqNZlaE4BaC6tihqwL3pio33Pvld1Hyol91zfIHL+NEAV9tQroc9CwDf0AA85STPGqWwE0gQvj3osJy3Mu8nC4stGQbcJfl4+Nxn1uiWOpf32hE8LH+GPOvKrc5dVaB6uecN/l/8qSJZp58dPm4E1tWCrY4qSJ3/6w== 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=wsrkpUVi3WNypHl5pcq6GxPYH8jyCkc8S9h4vZu1cNY=; b=Ozba9FL0hIgpChSvfQvNj0aXwwEUIShKoirtd/aGOJSDnUpWDb+apR6UCpv3NaasBOD3Q9ozf8CEs9QLOwTotVNOrB/9nQieUSETlhDKaVgjHtyq/umUIVlbraFdLMt8izfVYVvA77MvfbrNtWtm8k2Y60M1nIsJC9UgVeHjsNnFtRUgmct47kHNqsslqBey9YUpke5TqHySxexLsFAilEuUXm1HUxscf1lL42bzjjk2MSkxAHH7foEUVic1RaHnfF0MOL68zI32FN1qKFiZlU3bHZNPd06lw74cQTAcz+GwDbW+OvI2S58sSl3VLXcuMfHHQP4Y3BBiDfLpOGP3Nw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=linux-foundation.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=wsrkpUVi3WNypHl5pcq6GxPYH8jyCkc8S9h4vZu1cNY=; b=fOxFy4A0+aSEk8/U8WSquGzLWQXv6yRSo43ZZQEveGU5S92Ad6liZ2KZu06KUSfgmOr68R5DsLmeBw1g3MeYtTEdJsn1OJxRf2N4DQrnTo0OxAVFU64ogTdsNPRwx8l6jM0MtPLMZ0I5Lay3noa8IOnAf85qC9eDs5eYladLmcA= Received: from MWHPR14CA0008.namprd14.prod.outlook.com (2603:10b6:300:ae::18) by BYAPR12MB3478.namprd12.prod.outlook.com (2603:10b6:a03:ad::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4587.18; Tue, 12 Oct 2021 17:13:09 +0000 Received: from CO1NAM11FT018.eop-nam11.prod.protection.outlook.com (2603:10b6:300:ae:cafe::84) by MWHPR14CA0008.outlook.office365.com (2603:10b6:300:ae::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4608.14 via Frontend Transport; Tue, 12 Oct 2021 17:13:09 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; linux-foundation.org; dkim=none (message not signed) header.d=none;linux-foundation.org; dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; Received: from SATLEXMB04.amd.com (165.204.84.17) by CO1NAM11FT018.mail.protection.outlook.com (10.13.175.16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4587.18 via Frontend Transport; Tue, 12 Oct 2021 17:13:08 +0000 Received: from alex-MS-7B09.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.8; Tue, 12 Oct 2021 12:13:06 -0500 From: Alex Sierra To: , , , , , CC: , , , , , Subject: [PATCH v1 12/12] tools: update test_hmm script to support SP config Date: Tue, 12 Oct 2021 12:12:47 -0500 Message-ID: <20211012171247.2861-13-alex.sierra@amd.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20211012171247.2861-1-alex.sierra@amd.com> References: <20211012171247.2861-1-alex.sierra@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 21cc2f9c-b1c4-43ae-9b9a-08d98da39024 X-MS-TrafficTypeDiagnostic: BYAPR12MB3478: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4714; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: H/DkEskfCZ8WEoSjwiYli78ny/x0BlU3QJ8N8RYZ+/TzPfDy6KVOo4vlq3ZJHyEvSHDdBs9VT+/4U7KMsast4Eg+qbwj7B8sNj4A/vGTGy718i7Jwro243sYk5YBTuwlaskvi8YST19LWTClDR1HJgfcev59sDKuQ/oXIZ/5MlT3COWp3UydMaQofJyxw23V9CNfa8q9ER2ELU0TjAiHb4ZR1bqmlJ3Bn7ZHbGLVInAKXAifdzcODry56gpuVWqJlO6+v+KPZ4SssF2Rau1aRN9HxT8oxR0SIcIpdCgRJidNmIqJ4c447NFtELTjXzy2ZbrZX1gJlCrXkjHM7CkEclQgPeENZo2k9bE0qgeG+ROCksRE5mEdFWB6uHEPIDEX2keBSWz9SHOaGiiOS168WMx+0yhzKt19U+o3XZrTjgVchYOS9zEQrkCiFXoNr3NJpStRyFvYQTZrMGxfWh4s2JioJomkLAQZuxCGGObHTIqVaPaKbfweYe7VLMCDBjPpEBAyKAxiXqCYNS6Vdb7NldtrUBzCDrVQoN1C5OjOJWjwML8m/J0hj/gvrlX8XyBwysJtcHa+TuuqxDPYnc1TckfkYurAjqOmzQspgWCIf8UCxEBSKglJyG14PGfhz+cR+g16JxK14e0PfJrrNObqMuUHIjdOV4P8qupdpPpp4tSmu6R9AErxyQNs6KP/DJcEvZyWP5TaD/YpWT0poaDx0O2KjY4V5G4J8+k9FJEQCAs= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(4636009)(46966006)(36840700001)(82310400003)(426003)(86362001)(1076003)(5660300002)(2616005)(7696005)(4326008)(7416002)(110136005)(36756003)(2906002)(8676002)(54906003)(70206006)(16526019)(70586007)(6666004)(83380400001)(8936002)(336012)(44832011)(316002)(508600001)(26005)(81166007)(47076005)(36860700001)(186003)(356005)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Oct 2021 17:13:08.5472 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 21cc2f9c-b1c4-43ae-9b9a-08d98da39024 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT018.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR12MB3478 X-Rspamd-Queue-Id: 8743DB000181 X-Stat-Signature: ytr1w9spos7p6yst95nmqi8xaqjt8ffz Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=fOxFy4A0; spf=pass (imf25.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.237.89 as permitted sender) smtp.mailfrom=Alex.Sierra@amd.com; dmarc=pass (policy=quarantine) header.from=amd.com X-Rspamd-Server: rspam06 X-HE-Tag: 1634058791-298490 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 two more parameters to set spm_addr_dev0 & spm_addr_dev1 addresses. These two parameters configure the start SP addresses for each device in test_hmm driver. Consequently, this configures zone device type as coherent. Signed-off-by: Alex Sierra --- tools/testing/selftests/vm/test_hmm.sh | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/tools/testing/selftests/vm/test_hmm.sh b/tools/testing/selftests/vm/test_hmm.sh index 0647b525a625..3eeabe94399f 100755 --- a/tools/testing/selftests/vm/test_hmm.sh +++ b/tools/testing/selftests/vm/test_hmm.sh @@ -40,7 +40,18 @@ check_test_requirements() load_driver() { - modprobe $DRIVER > /dev/null 2>&1 + if [ $# -eq 0 ]; then + modprobe $DRIVER > /dev/null 2>&1 + else + if [ $# -eq 2 ]; then + modprobe $DRIVER spm_addr_dev0=$1 spm_addr_dev1=$2 + > /dev/null 2>&1 + else + echo "Missing module parameters. Make sure pass"\ + "spm_addr_dev0 and spm_addr_dev1" + usage + fi + fi if [ $? == 0 ]; then major=$(awk "\$2==\"HMM_DMIRROR\" {print \$1}" /proc/devices) mknod /dev/hmm_dmirror0 c $major 0 @@ -58,7 +69,7 @@ run_smoke() { echo "Running smoke test. Note, this test provides basic coverage." - load_driver + load_driver $1 $2 $(dirname "${BASH_SOURCE[0]}")/hmm-tests unload_driver } @@ -75,6 +86,9 @@ usage() echo "# Smoke testing" echo "./${TEST_NAME}.sh smoke" echo + echo "# Smoke testing with SPM enabled" + echo "./${TEST_NAME}.sh smoke " + echo exit 0 } @@ -84,7 +98,7 @@ function run_test() usage else if [ "$1" = "smoke" ]; then - run_smoke + run_smoke $2 $3 else usage fi