From patchwork Fri Nov 12 15:08:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joao Martins X-Patchwork-Id: 12616967 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 917D9C4332F for ; Fri, 12 Nov 2021 15:09:39 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 31E4360F4B for ; Fri, 12 Nov 2021 15:09:39 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 31E4360F4B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 6B7436B0082; Fri, 12 Nov 2021 10:09:38 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 63AE26B0083; Fri, 12 Nov 2021 10:09:38 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4675D6B0085; Fri, 12 Nov 2021 10:09:38 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0041.hostedemail.com [216.40.44.41]) by kanga.kvack.org (Postfix) with ESMTP id 29CB06B0082 for ; Fri, 12 Nov 2021 10:09:38 -0500 (EST) Received: from smtpin08.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id C65AC7F717 for ; Fri, 12 Nov 2021 15:09:37 +0000 (UTC) X-FDA: 78800612394.08.1AD8BEC Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by imf25.hostedemail.com (Postfix) with ESMTP id 9663EB0002AA for ; Fri, 12 Nov 2021 15:09:21 +0000 (UTC) Received: from pps.filterd (m0246627.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 1ACDqgVY018116; Fri, 12 Nov 2021 15:09:28 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-type : mime-version; s=corp-2021-07-09; bh=8HFEZphhYZDWiuCy0vyL75HwDr9OvafkX9Jq8eoYs6k=; b=Ftl6KoJiLuNl1RgRNdsfxeKLzT2gGhexPlxw9nvPhWs5dRDK1kL8Xbyd/cVRp0A7OI1U ZZ6lMbn7YzzqJAlFaE/smYkIPcuD2Z88/85pGxbIDLXSlABcNghpCBTcoJt6zVg53Tbv k90tSXq5LADi3isB0FE5KtxcjN7dX/Ubia4074rlKtjIAeVw4qOuQoD5XSOEbq9LMr0z mKgjt4nSn9N9Copap3Qgnj+49o+mw9gsJyOujLudldv9gXKuSvZkap/p72DtTUeMMaLT wg/bEptSCQDbt3txYJzr9VMzpVg/oFrkEofQKordAYMPfy7J21CAgXIVvrFKahhh359V 1Q== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by mx0b-00069f02.pphosted.com with ESMTP id 3c9qx3rujv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 12 Nov 2021 15:09:28 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.1.2/8.16.1.2) with SMTP id 1ACF5wAi196340; Fri, 12 Nov 2021 15:09:26 GMT Received: from nam02-sn1-obe.outbound.protection.outlook.com (mail-sn1anam02lp2046.outbound.protection.outlook.com [104.47.57.46]) by userp3030.oracle.com with ESMTP id 3c842f8xvb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 12 Nov 2021 15:09:26 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Okr4Qaob2azCNsH8mg5Pn9ofSSDwXvfBkI+p+Le3cSEdnnYkRDOJsvl9i2V79bA75S+6A5krAf9LfEFlJwgqSMW74XlwWPGO8/m7TfRspfpZtgtyBZ684xQI+wtQ+sFzBnVzCq67TM8ve/DSdJ0J9vv6yTwnjiXzK1udu0eVE6GYNFlioJDzQpzpppFYJJ0ps9zqtABab3SUQI/l3HkcpWssBgLuPdWx3OJNwOR9W5/O3YJnR3gaboHOs8v8eIwZRVArXnriZR17bFL4Zo9Wm7P9U6e3SYQ8KfpnOimsVIEAnwtlTgAkDcbxaxQJJrU3YQZMva8viBlFg6X8ZdpwsQ== 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=8HFEZphhYZDWiuCy0vyL75HwDr9OvafkX9Jq8eoYs6k=; b=fZyMbu4huXc+mTG6FCBSc6ow+xGFMvqovUjce4tePFQN0iuH3pNjgpbYe4UaPd5bUEQ7LMHFv2rZiDHwfM8ctaV5NVGgxeG0l3auZwng1zLhKtNkANaIGyUwOTNXclDx1qmllydDjHyGtMcxEfjlA90tPIhC5pGiKi44c/aCMVEE0JAhiV+baBLjfasiefkWDjeWZPkteBXD1F1L6a/0UBNjefhZO2Z2UvPPRGNQLwoAwQAVswE913CUmW0ew616H3ZMVTWVyis8TuOk4YxdrIS8rsF0SWpUqz6C0/LIbBCVkrMxrnUw6dQuadQQl5c15vK9aFfvL4ye5ywzLBGYQQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=8HFEZphhYZDWiuCy0vyL75HwDr9OvafkX9Jq8eoYs6k=; b=p0t4wFmUQ0nSadHvxIklIPchLjhXrbRhUhyJWXucEIAgCpEBOrJb5cMYvl7jz+dTXEuRjrqMPcUrgVmR/m1C3qHjgEfvIroA5HuQdD4jso9Y8UhWpXGgmsTwL5R6QGtA7hH+HBShNle5nM83JEPSTppx9iR5i8sHVeMzZxKtXtE= Received: from BLAPR10MB4835.namprd10.prod.outlook.com (2603:10b6:208:331::11) by MN2PR10MB4223.namprd10.prod.outlook.com (2603:10b6:208:1dd::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4669.17; Fri, 12 Nov 2021 15:09:24 +0000 Received: from BLAPR10MB4835.namprd10.prod.outlook.com ([fe80::d809:9016:4511:2bc6]) by BLAPR10MB4835.namprd10.prod.outlook.com ([fe80::d809:9016:4511:2bc6%8]) with mapi id 15.20.4669.016; Fri, 12 Nov 2021 15:09:24 +0000 From: Joao Martins To: linux-mm@kvack.org Cc: Dan Williams , Vishal Verma , Dave Jiang , Naoya Horiguchi , Matthew Wilcox , Jason Gunthorpe , John Hubbard , Jane Chu , Muchun Song , Mike Kravetz , Andrew Morton , Jonathan Corbet , Christoph Hellwig , nvdimm@lists.linux.dev, linux-doc@vger.kernel.org, Joao Martins Subject: [PATCH v5 7/8] device-dax: ensure dev_dax->pgmap is valid for dynamic devices Date: Fri, 12 Nov 2021 16:08:23 +0100 Message-Id: <20211112150824.11028-8-joao.m.martins@oracle.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20211112150824.11028-1-joao.m.martins@oracle.com> References: <20211112150824.11028-1-joao.m.martins@oracle.com> X-ClientProxiedBy: AM3PR07CA0134.eurprd07.prod.outlook.com (2603:10a6:207:8::20) To BLAPR10MB4835.namprd10.prod.outlook.com (2603:10b6:208:331::11) MIME-Version: 1.0 Received: from paddy.uk.oracle.com (138.3.204.9) by AM3PR07CA0134.eurprd07.prod.outlook.com (2603:10a6:207:8::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.20.4690.12 via Frontend Transport; Fri, 12 Nov 2021 15:09:21 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: bd626ec2-f4a6-4509-34b4-08d9a5ee69cd X-MS-TrafficTypeDiagnostic: MN2PR10MB4223: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4941; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: b3CEA/6Ad3CV9bemuMsmJB30Q5RQ4VVKtaCp6o63DX/amAgrh4KSugH4O4ck+g3BlibgAtKemFSkA1N3H2U5k7LnpckljSv3pr5JR2Ug8wWzCSjJHkCSb0Vct11N7LJ4WVVFw9txLlhxqlfpVekmTPpfvQVHqo3qe4HJwB8V3X0Sa4B4zbYAla6qJP6q9mXfJ9j7EMRaUjtUmZb8fMOStwYSzaRvJESIbwd4mQiOJArCW4CUpFj36LDZBEHRLcGihUj6Rkqx2eKrqyfxDMUELNA9ooroxTjSLYmoJG80lsgoxzLJHqk1Da2kvjafU6qmx0BNiE5KU54f+amQZTVir8CV0E7qCxL5fGKgPLYz5yuT0UkGV0HnMROblnrBsq7bvqOQ61m36dysxp22lxQ4Lt8ZDjEnaIPA4asZWpNGQIXEw1FOKa7bNWaIc5zlZMliDH1rC3e80W8yBCwmmEkduPP91z8aNhr1PTojaeTnG4Bo1O4qjEOEOHGg6oqi4h9N1/SbFnW8dHx+QscIPyeDB4S0TYAX1ovXKCtGW4tJX/H+hFyPrtNXV95dcUWo0l3StYRDnjSfw0H4Uje8RzdS2ZJPDLSf7XcgXaG/O9zOYHxj7XYJdp+NofTYfba62B2hpaD8KZNlPNBmJXhVfVdU0JlXsJ5kRBl420bKjiW9aWlCDAPbqh1cZOSWp6xkKB9wsivedy4C8nzyWXwEHJDV+g== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BLAPR10MB4835.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(366004)(7696005)(5660300002)(2616005)(107886003)(2906002)(38350700002)(38100700002)(66946007)(6916009)(6486002)(66476007)(54906003)(1076003)(66556008)(52116002)(4326008)(8936002)(86362001)(36756003)(103116003)(186003)(316002)(26005)(956004)(83380400001)(508600001)(8676002)(7416002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: vyFi6z35zhCoy8Urz3+fMj6JkiPWXYxaitPyCSHl+k2RJwHVonfLx1J+wFGO9jTFFePWjJCfmSDXhZYD78dKmv3mR8188+vO+ShvPXTabrTVMMseblN/47s9VnbTVbkwnBrTFH9u+h8KCveJaF9cTcqpMP16AQQkfbE0A/vQTtEA1fSqQGTX1jhnrG4tM4kyRJns9YjgAAR3jN3SParVWtpaqPYkA0iu1Xv44Z0tHHOCijx3Tjgzvwt85vP+L8Wqd7RiL7p77IzY/ndneyJdfBCtqoIwk1YiyZw2zH/gQB+ytGwdQZq4920KQTKCGRFCB4XvfzT30O5Q/Gx8s4zb45YvxnXA4saFvlMtS+H85BZLS+DlvbDVeQudBbJsaE6ppLdr25QP9n56XFVHwDdRTLT32NnbAcDwhqflMOdQYLt5lKFOMJdOmHQhil4iFTFowCETE7PMyxIsC/mmFHwTRhBv9fnqlKRHAQBITiIGdUbTYSbmAdytJMEX0gjASFph/8R+Mx5QaRC86BgmFKLD4CEMSzajYt7o4rqpZ+vcA4LRxcDf78MfdVKd1Kvy678j8oWViIl5tApkGNrs10E2dbepcVbSC8JmMxpYMaHW+s3nnaq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oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: bd626ec2-f4a6-4509-34b4-08d9a5ee69cd X-MS-Exchange-CrossTenant-AuthSource: BLAPR10MB4835.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Nov 2021 15:09:24.7801 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: nbDGrtPkjDU/q7aehirImxWWqOODiw0ZkjMZyMKh+pj55k0CdiJnJ3jtdUfMK2BAZEy7vS6xojvXGohrTRUCUP4rXEtdU/ruTPr8TRE0NRs= X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR10MB4223 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10165 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 malwarescore=0 spamscore=0 suspectscore=0 adultscore=0 bulkscore=0 mlxlogscore=999 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2110150000 definitions=main-2111120087 X-Proofpoint-ORIG-GUID: qbW8LDSLTyJgXfixe6qoLCmncEGGYIi6 X-Proofpoint-GUID: qbW8LDSLTyJgXfixe6qoLCmncEGGYIi6 X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 9663EB0002AA X-Stat-Signature: wjywyu6i8dek3tc9jh5rn3p8u5ia3r6y Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2021-07-09 header.b=Ftl6KoJi; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=p0t4wFmU; spf=none (imf25.hostedemail.com: domain of joao.m.martins@oracle.com has no SPF policy when checking 205.220.165.32) smtp.mailfrom=joao.m.martins@oracle.com; dmarc=pass (policy=none) header.from=oracle.com X-HE-Tag: 1636729761-446574 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: Right now, only static dax regions have a valid @pgmap pointer in its struct dev_dax. Dynamic dax case however, do not. In preparation for device-dax compound devmap support, make sure that dev_dax pgmap field is set after it has been allocated and initialized. dynamic dax device have the @pgmap is allocated at probe() and it's managed by devm (contrast to static dax region which a pgmap is provided and dax core kfrees it). So in addition to ensure a valid @pgmap, clear the pgmap when the dynamic dax device is released to avoid the same pgmap ranges to be re-requested across multiple region device reconfigs. Add a static_dev_dax() and use that helper in dev_dax_probe() to ensure the initialization differences between dynamic and static regions are more explicit. While at it, consolidate the ranges initialization when we allocate the @pgmap for the dynamic dax region case. Suggested-by: Dan Williams Signed-off-by: Joao Martins --- drivers/dax/bus.c | 14 ++++++++++++++ drivers/dax/bus.h | 1 + drivers/dax/device.c | 26 +++++++++++++++++++------- 3 files changed, 34 insertions(+), 7 deletions(-) diff --git a/drivers/dax/bus.c b/drivers/dax/bus.c index 6cc4da4c713d..19dd83d3f3ea 100644 --- a/drivers/dax/bus.c +++ b/drivers/dax/bus.c @@ -134,6 +134,12 @@ static bool is_static(struct dax_region *dax_region) return (dax_region->res.flags & IORESOURCE_DAX_STATIC) != 0; } +bool static_dev_dax(struct dev_dax *dev_dax) +{ + return is_static(dev_dax->region); +} +EXPORT_SYMBOL_GPL(static_dev_dax); + static u64 dev_dax_size(struct dev_dax *dev_dax) { u64 size = 0; @@ -363,6 +369,14 @@ void kill_dev_dax(struct dev_dax *dev_dax) kill_dax(dax_dev); unmap_mapping_range(inode->i_mapping, 0, 0, 1); + + /* + * Dynamic dax region have the pgmap allocated via dev_kzalloc() + * and thus freed by devm. Clear the pgmap to not have stale pgmap + * ranges on probe() from previous reconfigurations of region devices. + */ + if (!static_dev_dax(dev_dax)) + dev_dax->pgmap = NULL; } EXPORT_SYMBOL_GPL(kill_dev_dax); diff --git a/drivers/dax/bus.h b/drivers/dax/bus.h index 1e946ad7780a..4acdfee7dd59 100644 --- a/drivers/dax/bus.h +++ b/drivers/dax/bus.h @@ -48,6 +48,7 @@ int __dax_driver_register(struct dax_device_driver *dax_drv, __dax_driver_register(driver, THIS_MODULE, KBUILD_MODNAME) void dax_driver_unregister(struct dax_device_driver *dax_drv); void kill_dev_dax(struct dev_dax *dev_dax); +bool static_dev_dax(struct dev_dax *dev_dax); #if IS_ENABLED(CONFIG_DEV_DAX_PMEM_COMPAT) int dev_dax_probe(struct dev_dax *dev_dax); diff --git a/drivers/dax/device.c b/drivers/dax/device.c index d6796a3115a6..a65c67ab5ee0 100644 --- a/drivers/dax/device.c +++ b/drivers/dax/device.c @@ -398,18 +398,33 @@ int dev_dax_probe(struct dev_dax *dev_dax) void *addr; int rc, i; - pgmap = dev_dax->pgmap; - if (dev_WARN_ONCE(dev, pgmap && dev_dax->nr_range > 1, - "static pgmap / multi-range device conflict\n")) + if (static_dev_dax(dev_dax) && dev_dax->nr_range > 1) { + dev_warn(dev, "static pgmap / multi-range device conflict\n"); return -EINVAL; + } + + if (static_dev_dax(dev_dax)) { + pgmap = dev_dax->pgmap; + } else { + if (dev_dax->pgmap) { + dev_warn(dev, + "dynamic-dax with pre-populated page map\n"); + return -EINVAL; + } - if (!pgmap) { pgmap = devm_kzalloc( dev, struct_size(pgmap, ranges, dev_dax->nr_range - 1), GFP_KERNEL); if (!pgmap) return -ENOMEM; + pgmap->nr_range = dev_dax->nr_range; + dev_dax->pgmap = pgmap; + + for (i = 0; i < dev_dax->nr_range; i++) { + struct range *range = &dev_dax->ranges[i].range; + pgmap->ranges[i] = *range; + } } for (i = 0; i < dev_dax->nr_range; i++) { @@ -421,9 +436,6 @@ int dev_dax_probe(struct dev_dax *dev_dax) i, range->start, range->end); return -EBUSY; } - /* don't update the range for static pgmap */ - if (!dev_dax->pgmap) - pgmap->ranges[i] = *range; } pgmap->type = MEMORY_DEVICE_GENERIC;