Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp390984pxf; Wed, 31 Mar 2021 06:09:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxSjBmZWT7soBFRL+Y7fXqHJ6Gq2Qq+EwXvUnMgtmanMMqRUJP7agJP4bpCSKdK4kysHOuH X-Received: by 2002:a05:6402:168c:: with SMTP id a12mr3660298edv.344.1617196150921; Wed, 31 Mar 2021 06:09:10 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1617196150; cv=pass; d=google.com; s=arc-20160816; b=tCu7QDk6iiqA1ZYDyi5rjQr5I8L77qZtsgTumESJGL4hH4EMiJaCcFhuPl0SMkjihi WNZpS5obC9DN6qhB5mQZeuzGKrix2z+LTFjlZJq1/VY/gxueWeDy2Xc7obBFI2NQbuSx XzspEoSVLnOSJ8S0/ocCM/QcVLtuk65ulvKG90kzO4kJYY3Z8P86E9NGRw7LiywY3bTI w1rkhkLNtVuv6gfBTmmSj8Wci7YibH/qw2LHoHZy8W5PI6YuhI4EFDx9g1+aCvrHqiJJ B+S4XW7D4xy1vQlOAYVIXoq9rdqWkBDk808+XhMogztb8mWxYzk+C8rPOymauMfrpijh pjpA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:in-reply-to:content-disposition :references:message-id:subject:cc:to:from:date:dkim-signature; bh=j7WsDly/Q5HK74Rrtd6EImaXbYNuwpm66+pAbT0/ox8=; b=fIGe/0SKV10wjK3VLc3ciLyxUh3GTi9B0ECC0kdLl2cGPNZhEf2wwLrSvTxJErCMZ+ mqdUaVjONzpEM3h3wxtdF2FEsS8VDPQTHvPMwfSs9jYlY03e/hYwL6yryLugdDIzWik6 D+jyH8H9jyjC5tYWYx4gCAUjuX+bW5Ouuo1atGPF92kBLtC8C00C2StrgjINthVSiS/I hIt3VJT1llOini0C+T9iAOhVZIdxZmjiWIhLOhKDoJH6AX2ITju4Poh08skucjDAflgC 8fiKk3looedfpPTnKDdCSiFTv3Y2IxKoUVQQ2sLCSRx7ZsoPADByIJD+EsPVEr0/AA+7 CkdA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@Nvidia.com header.s=selector2 header.b=jynI6jlQ; arc=pass (i=1 spf=pass spfdomain=nvidia.com dkim=pass dkdomain=nvidia.com dmarc=pass fromdomain=nvidia.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nvidia.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l15si1686400edb.89.2021.03.31.06.08.47; Wed, 31 Mar 2021 06:09:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@Nvidia.com header.s=selector2 header.b=jynI6jlQ; arc=pass (i=1 spf=pass spfdomain=nvidia.com dkim=pass dkdomain=nvidia.com dmarc=pass fromdomain=nvidia.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nvidia.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235663AbhCaNHp (ORCPT + 99 others); Wed, 31 Mar 2021 09:07:45 -0400 Received: from mail-dm6nam10on2084.outbound.protection.outlook.com ([40.107.93.84]:42352 "EHLO NAM10-DM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S235686AbhCaNHZ (ORCPT ); Wed, 31 Mar 2021 09:07:25 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Rk2+FPJlpBoEdJfvRv0euMxIdXo/u2S+o1h5BK+4KjuJk+tnaRvw4LH/0H7YJKrJjOR9tdNK9wuArh+eNY4bNeleGbEMkRB4V0+Gt97CH80cVGJhj4oPBnYaSjmVJPUguCqYn7GyLMiHlbYp9iG4EfOommTMn0qluB6V66qItTt0xqkuCaM2cDBz0IoRx4DWrb9ndQe8WBf5UpOn6xUoR4RxqkfagtXpXJvAsT0nC6G2eEP81whTOTPa4OHYPQWkEEmWZXlGB/0Hja0HRj6kpbq+lYcB0hvtT5ORwbWHERPKP/Hty6ysWAPmCDjUnh+gNjU74hzBJADha7Exty0y+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=j7WsDly/Q5HK74Rrtd6EImaXbYNuwpm66+pAbT0/ox8=; b=FGRHyP6GotX1mnDxsPaxQ8CF1jSPKxD+gQQHCAgT53SPKL1reIPg7bDOreNT5A0LVUemS4tEe79LprFE75k+FCmx4La9ytbrVY2aMsYJEGCwxA94z38cAvErK0uXOivPxoABwegZnt9aSCj49EBNx0B2cMyeqER/8zhsgRIH06IYdNPDbG34P52H8G6vCvaAn3/6zBrwtgEpKi3lqnCaxoi4ChI5i1nhdzXr6jOlvTTzfSfpWAgmlnSLtPLj0PBOLjemDsYpNnzO0+BCUGPwvJNdK2EE8uINKHc46T0TjfdSdHYuaJEQ5UwDL9Wrcc5n1P5S9Q66p3C5D1aopLytJA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=j7WsDly/Q5HK74Rrtd6EImaXbYNuwpm66+pAbT0/ox8=; b=jynI6jlQ+1SSVcKaS/w+6rRMoKimk3hd9WUZ14/9zfBI+53NqR/7tN0+WLkGprv3U0Y1ppK99vaJ5k6fk7jeUhMO6kCayjMfIYqFX2WIJu8L0BkjfNMzGrCCfAxcIhL5T74vp/fzug91XKMPsdY9w7AJ1pbDYusRYtXVSdRO506SYeV1UXT0OFUTVb8FQBm3n9Fau6Bpk+WsBH5lcZM5HNdE5VOok0hDgp2zVSVJGxMfpcRHkCI1Ce29TkrDA7bM0xzYzMRwqLiVmgLGl8l9pEfTixJOmCZ9KsxQzm/zkk9zf9P2EwvfV43eRZfyAo5panHz3HyJ3ysKBJK5nNOPHw== Authentication-Results: intel.com; dkim=none (message not signed) header.d=none;intel.com; dmarc=none action=none header.from=nvidia.com; Received: from BY5PR12MB3827.namprd12.prod.outlook.com (2603:10b6:a03:1ab::16) by BYAPR12MB3351.namprd12.prod.outlook.com (2603:10b6:a03:de::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3999.27; Wed, 31 Mar 2021 13:07:23 +0000 Received: from BY5PR12MB3827.namprd12.prod.outlook.com ([fe80::4c46:77c0:7d7:7e43]) by BY5PR12MB3827.namprd12.prod.outlook.com ([fe80::4c46:77c0:7d7:7e43%6]) with mapi id 15.20.3977.033; Wed, 31 Mar 2021 13:07:23 +0000 Date: Wed, 31 Mar 2021 10:07:20 -0300 From: Jason Gunthorpe To: Dan Williams Cc: linux-cxl@vger.kernel.org, linux-kernel@vger.kernel.org, vishal.l.verma@intel.com, ira.weiny@intel.com, alison.schofield@intel.com Subject: Re: [PATCH v3 2/4] cxl/mem: Fix synchronization mechanism for device removal vs ioctl operations Message-ID: <20210331130720.GF1463678@nvidia.com> References: <161714738634.2168142.10860201861152789544.stgit@dwillia2-desk3.amr.corp.intel.com> <161714739718.2168142.17960000558666300914.stgit@dwillia2-desk3.amr.corp.intel.com> Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <161714739718.2168142.17960000558666300914.stgit@dwillia2-desk3.amr.corp.intel.com> X-Originating-IP: [142.162.115.133] X-ClientProxiedBy: MN2PR14CA0030.namprd14.prod.outlook.com (2603:10b6:208:23e::35) To BY5PR12MB3827.namprd12.prod.outlook.com (2603:10b6:a03:1ab::16) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from mlx.ziepe.ca (142.162.115.133) by MN2PR14CA0030.namprd14.prod.outlook.com (2603:10b6:208:23e::35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3977.30 via Frontend Transport; Wed, 31 Mar 2021 13:07:22 +0000 Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1lRaZ6-006KrP-VO; Wed, 31 Mar 2021 10:07:20 -0300 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 06166ddb-c46a-45f2-b48f-08d8f445ec2c X-MS-TrafficTypeDiagnostic: BYAPR12MB3351: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6790; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 5xg1HpsFqG4Qy3SESZdrVN+Eytmm07MIImnTIguTVSbmHLo1VlUEJk1Fg882KpVnxE7liTHvKb2AAoUNyb8wdWao/dJogtd5I++mEgoGgGGuqm3Jygo2sRuWGcNRrwm6qB8B4C8bm44ppuW1A+F7Iupi8x+9xqLypFJ2wnXAjJvT/aEAMRUJlo8WYHW/3aKDYA1fCbAft3JqMhfbW6fpamVBvK2vCfBC19M4GZkVbvv0akaY7ac34ctbiB7toQAvBBAJeJB+eDHc/A3Oy8IZkCqgH3N87iOadCBiL3cHY3MxJN3zfarKA6Qh4XJhjegaxgJTRzr1JNi22znp8SnKQmETy/6JDcYkvnKBzBauYFg5ZYoIKyDfcFG5mL85TKeBpohbBNtJPIIvdyEASEN//X83dyC/Dewys6VyHsjis/rGKUJmIndb9Pkm1gi1XjcS23Z2xovPIV+u1qa20YZa4WOUY4i/o2X/KOx1bX1nDuFvzZGWlWV/WIsZ8tjGT/oKhWv1emKd/Bu7OdT/VMd96+r2SZQey9DZKKZH3qhAOFonsgZg/0nUkQplkyjmMSLVsmIRmUyL0eM0yYZgOQKh8/msqGAWZ5+lEYzP+myxLprGXb8fcF5fNQDP8gco6qy4Sg1uiATBQfhoGDTHCcfSueiAC5VCN1A7PxVhwEyYZZ8= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BY5PR12MB3827.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(396003)(136003)(376002)(346002)(39860400002)(366004)(8936002)(478600001)(66556008)(66476007)(5660300002)(4326008)(86362001)(26005)(9746002)(9786002)(83380400001)(33656002)(36756003)(316002)(8676002)(38100700001)(2906002)(426003)(1076003)(186003)(4744005)(66946007)(2616005)(6916009);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?us-ascii?Q?2nBfMz/LFA49ewk7u9HHldd0q+IxdX5MFCrFLKNGxKemdb1/J2enyNKVeDnR?= =?us-ascii?Q?J5wUKz73JxmPeNrkItCgaF8+UbIVCzvb/r03gmwptYP9cAZrwEj3fplEaDvi?= =?us-ascii?Q?NMT5fURUVbg9axcDeG37ahtMZmEqybdaWx87tWFzevCbW8VjCaTV+0hewEU4?= =?us-ascii?Q?5awOBDxNTQ4oF7B9+bWRih/1I8GZ2c6eCxXdcPeQwoC7jxlOw/Xn6Mzd5+Ap?= =?us-ascii?Q?hSCTyjt+7nuYhFvwm7VLvsHDyoqE1nj5DWhqHLpPIKgyo9dfap5t766ptDar?= =?us-ascii?Q?pStrRkqWBn3JhIhIXz+XmOj1uslb/qi5Y2yXqwxuuVeihpxijF2S+zpw9yId?= =?us-ascii?Q?WQiCTqovMzNYTdKlkVlE1nZQbebwQBgBOY/T+MY0Bt+Dzx8k11cmrXkJ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ry8iBHdT8XX/CJum8yLtNATaImB17?= =?us-ascii?Q?qH8zcckif/mEpCYvhhG8pVMr4Szq7tIdT1gz1E098JZYQg=3D=3D?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 06166ddb-c46a-45f2-b48f-08d8f445ec2c X-MS-Exchange-CrossTenant-AuthSource: BY5PR12MB3827.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Mar 2021 13:07:23.0015 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: mFngqq6dhvWzymOGUqDCzBgCq73TcWTD98j88pkfTC2WSHYjhq7JPKTGwghbHIb6 X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR12MB3351 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Mar 30, 2021 at 04:36:37PM -0700, Dan Williams wrote: > -static void cxlmdev_unregister(void *_cxlmd) > +static void cxl_memdev_activate(struct cxl_memdev *cxlmd, struct cxl_mem *cxlm) > { > - struct cxl_memdev *cxlmd = _cxlmd; > - struct device *dev = &cxlmd->dev; > + cxlmd->cxlm = cxlm; > + down_write(&cxl_memdev_rwsem); > + up_write(&cxl_memdev_rwsem); > +} No reason not to put the assignment inside the lock. Though using the lock at all is overkill as the pointer hasn't left the local stack frame at this point. > err_add: > - ida_free(&cxl_memdev_ida, cxlmd->id); > -err_id: > /* > - * Theoretically userspace could have already entered the fops, > - * so flush ops_active. > + * The cdev was briefly live, shutdown any ioctl operations that > + * saw that state. > */ Wow it is really subtle that cdev_device_add has this tiny hole where it can fail but have already allowed open() :< Other than the lock it looks OK Reviewed-by: Jason Gunthorpe Jason