Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp1685638pxj; Fri, 18 Jun 2021 12:38:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxCZv9D60oZb7X69ygXQMbydS2nHxKLlG9pXZhnmig1UtdaKgfOmKaSife7cPO9YnHHP6Ck X-Received: by 2002:a17:906:b11:: with SMTP id u17mr9797960ejg.124.1624045104742; Fri, 18 Jun 2021 12:38:24 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1624045104; cv=pass; d=google.com; s=arc-20160816; b=Rw7gUDMC4vHfIMYDvfMLLzcDgKoEMNlRD0f/EpKkiffjEqBwf8HRYbylkmW34aspHC 0Hu+xYYLEuTsstUWV6ZX6nWsddNnaXtasaKPe/c9A4NPrIbKCuDTCaJCsGdzAeF4+pgQ HJA/2JBtZb22SmQuumlum4PlnqWCFFbIsry+TrDZ/+HR8qqKuvu6JH/sWZG7nUBQM++8 J8olqA8yGs1He1tjFcncOCXzP1v4/lcKpOD+eSj2RL0Ik9d16qmWIWITp61R0hqv8H41 WmPvtLKYLhEbY1qroZDEf5SdhxRtS/XA3/AabqsPgbyHgdp24zJQ2aJVwXm3dl9dRjbh t+WQ== 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=VNsmetUqqceg0PLEgGEoEWxBCBKB3+sX8vf/WWtsU+g=; b=DaM59UyW4RJ25SunWq1pNJ5JY3CQPjVnAa2juJLSLzSV8GMUtKfVY3B98X7ezk5hSM he7H/AQXwfYDahtNWN4c+FFmBlIomV3T+ILa/vfKte3YDDBGYtBWjMP4F8JZd86P73aR NEldVVBr72OBjq7Gah9TMiYWxXCJvS2ztIEPhprk9BEL2qhoqEXig0pJePhUJimEqsLK KuczETHq03FsG+4Ykj8gmgg55CIp3ApmrdJo1FGTabRavItN0YFJVL8d92nxdy1wSgTG HL13fqs7+OyUCKO/vN50s3vkSO2qBO+6BHj9aOIDh6N0NxOg9M9wLzC27TQUdC4I9Gmz 4CGQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@Nvidia.com header.s=selector2 header.b=XP1+dVSd; 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 d21si3342330eds.188.2021.06.18.12.38.01; Fri, 18 Jun 2021 12:38:24 -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=XP1+dVSd; 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 S235253AbhFRSZu (ORCPT + 99 others); Fri, 18 Jun 2021 14:25:50 -0400 Received: from mail-bn7nam10on2043.outbound.protection.outlook.com ([40.107.92.43]:6593 "EHLO NAM10-BN7-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S230175AbhFRSZu (ORCPT ); Fri, 18 Jun 2021 14:25:50 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Q1ZXluPkd0iOlr0t2qisSkaRu0U+6NYT1Nt77gUKIpg9nNyEUDzLSRkiuIbaaK5YLbbU6fuy5X4lSs2BkhOQpKxLQrrZED/jk5XAMWQOrdXZNUpN3WfnnN3y14F/sAmQ5hUK/WJq0CFMBxogMO3C5o8s1HUng+J7yaH0oCanAbofKbw5V78/Zx0Uyb27h9VXffc224SYdvxh+O41Wb7SaKN+q+U3aqqMBERw+n6HGqS4y9CTe0jDY4GPRMp2MEucEwt/UR0b7OCux5oZwhtwsxfxbeziVGjka78CvnUwNbFdkmI72OVV74nizqpWRBD5Lv1xRwCj1ED9EAWhYZJwsA== 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=VNsmetUqqceg0PLEgGEoEWxBCBKB3+sX8vf/WWtsU+g=; b=eH0iPyGJVox8HwW5B+cgRC7y2WK5L1B3mLL9NBuxJldhQAibWi2zSS72lbAVzwKc/QIzqZ72c1YuYAsMZ36v+KAliO2oAlfmfknOS9kLFBxQoAwc27zepcGwb81ZM8Sb+peHKQOduazFMoT5wxoPMEhtL//JGS/dRzIn7cNnt96Sq1tzCpP8dLx/KGgQm/80W1vV/spUqSMDzI1S0/tnbXN5m+B0HmDWuDAMGZ3EdhSlKcvM0JAAmy/vobBiyZakDwkOQE5jdg8q9akodjMY/eCFxL+u+hupvdwgItR+3fdQ04DNWfLkytm/NAMw9bU7iZzw/rWw7ULkpJFuycrJCw== 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=VNsmetUqqceg0PLEgGEoEWxBCBKB3+sX8vf/WWtsU+g=; b=XP1+dVSdfk/1j61BSg5y5UZgIoJUKBaGs1gPLQ2oHqBrxXd2YTK2wohO1Asl/n+w9XxeI9vI1sT4//A7f/XVQDien1LTJUqu+oK5MeoCyJS4MnvcDNpsCI7/Bj9GtOODmGNPkU9wUe3qELn1qKKpNIkZCdWzj3vn4WrPhnKrqvf61Z9fdw/EuWHLGt8xr8PouKUUrPbyG5KPYLFAPoxGhN2dZbsYLXcVROdtoYiHBMi1kGxBcpxZfOVU5L71pUUSZP/dURvhq8N7SeIEgfvuGoF2lG2iJJ7IMkyq/Bm7dhtV3sTaonFLs367ClRtVN6GXV6nX6DV8x4rmk9z/LI6vA== Authentication-Results: linux.ibm.com; dkim=none (message not signed) header.d=none;linux.ibm.com; dmarc=none action=none header.from=nvidia.com; Received: from BL0PR12MB5506.namprd12.prod.outlook.com (2603:10b6:208:1cb::22) by BL0PR12MB5508.namprd12.prod.outlook.com (2603:10b6:208:1c1::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4242.16; Fri, 18 Jun 2021 18:23:37 +0000 Received: from BL0PR12MB5506.namprd12.prod.outlook.com ([fe80::3d51:a3b9:8611:684e]) by BL0PR12MB5506.namprd12.prod.outlook.com ([fe80::3d51:a3b9:8611:684e%8]) with mapi id 15.20.4242.021; Fri, 18 Jun 2021 18:23:37 +0000 Date: Fri, 18 Jun 2021 15:23:36 -0300 From: Jason Gunthorpe To: Tony Krowiak Cc: "Jason J. Herne" , linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org, pasic@linux.ibm.com Subject: Re: [PATCH v2] s390/vfio-ap: Fix module unload memory leak of matrix_dev Message-ID: <20210618182336.GJ1002214@nvidia.com> References: <20210618171255.2025-1-jjherne@linux.ibm.com> Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Originating-IP: [47.55.113.94] X-ClientProxiedBy: MN2PR16CA0018.namprd16.prod.outlook.com (2603:10b6:208:134::31) To BL0PR12MB5506.namprd12.prod.outlook.com (2603:10b6:208:1cb::22) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from mlx.ziepe.ca (47.55.113.94) by MN2PR16CA0018.namprd16.prod.outlook.com (2603:10b6:208:134::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4242.16 via Frontend Transport; Fri, 18 Jun 2021 18:23:37 +0000 Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1luJ9U-008dQN-Bp; Fri, 18 Jun 2021 15:23:36 -0300 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 95d0c100-5854-4a77-6b06-08d9328630bc X-MS-TrafficTypeDiagnostic: BL0PR12MB5508: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8882; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 7cTBcN59CzazhZBeCQ2L3iX3rXLMmhnv8WmvFqIA2NyrUIPvpkmEo35IyRsL7+f+4ITnd0dVDk89oZKLzLSKU+dAjSpgEu1b1O/16WrSPEgN/ZwFpZYf5xsNAb0JCECYTJkx6Jk1hAzMiLPn59GFP1C4i7GgxNjCjQWb/GvZ08RPmBmYkYHFh+wxIEMy2g1YtYTyCupHs5UlE6kjhL8OJgKdf+E3nmiqyz0bgZDJPwOh49GFrrqCqYrEHIj/RjPTBx3MZTO/A5tm5QZBvzN4eWZszw5wo663zbAUZPPgKghY3lSwcM+olnh+npc6HMLbVOz5ZlHBD7EWq3Kod6sTo4UDs57AfFexpRGg0JbQwvsXlvKIN1tYwWHuSwcA1aakD/kg99Up8i2Ql5+RQQcattUd8qBas8AN7xXCOw7SapZdfq0s6/vSQwZDtdFSZtP2nLYaYyf5OWQx0ZjUDtJJz9BY0ygXbAUB25xH3kN8FLIhae8HPIJfVH4G8/eBmAg53JHhrImL/6UQNFvCkLjloRhLp/vvMEzAD/X6AV4mS9Bg/l/3dlF4pu7YpgXcbVbhPG5E5Zna5CNRyNU7MJgR3pHF85xzabRaMlO03KKf8xk= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BL0PR12MB5506.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(136003)(396003)(346002)(376002)(39860400002)(366004)(316002)(66556008)(9746002)(426003)(26005)(478600001)(2616005)(36756003)(53546011)(2906002)(66476007)(86362001)(6916009)(9786002)(5660300002)(8936002)(38100700002)(83380400001)(1076003)(186003)(33656002)(66946007)(8676002)(4326008);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?HmPXfbAZTGZmBo4QjxEwFKtytZGIHtwXD8m5NV0pXsXLC4rykkxqstc7e54P?= =?us-ascii?Q?2NTBsp4adMQfijg7jOBVLoHhZM4TfsRgW4/OhWRGk5q2JmIuCV+MB0mBC9PG?= =?us-ascii?Q?7Bs3pe3vBKJmDmJ7aontrRBB9/2BW299L0oCCGsQWc4yHqLpQ/USkpwZrj01?= =?us-ascii?Q?iKlV+rYKsnev/e1k1Sl2/ziyZ++zbJlfH0yD1TYGsZ+Hp4MSAopJaz5u0HXV?= =?us-ascii?Q?RC2ccMmq1NphUiFQTqOPkZ2DuFnAEc+2n+44xjfsE5V2IK9sWaNXgJvkf/bP?= =?us-ascii?Q?4ufsvErOSR0c9Reu6GMyZX+0YePLELzVuL+7oLy0hWNhLE0K3cL71fchWyat?= =?us-ascii?Q?aUtt6kRoLc9LXtd4qxUbD9eSe4fSdp710Q6PYmOVAqilYqqmOaYeEmI6iyDR?= =?us-ascii?Q?AvchELcG0ydKAMmlQJ+RaeS3D6JjHyOQlKy5HIA2ohnJnAYDpbZ8PK4ul5+r?= =?us-ascii?Q?BQKsWr8DG+3SkLe6jWUXnm/U3ygdCA0txOumcO5HXsezbfUUDugH0toz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100-5854-4a77-6b06-08d9328630bc X-MS-Exchange-CrossTenant-AuthSource: BL0PR12MB5506.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Jun 2021 18:23:37.5820 (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: LStG4x76IZl1Z3B2HUZUsfvckfew3zUvLihRRQg2fYd/Gi+iCjPN5d5xEWU4UjTu X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL0PR12MB5508 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jun 18, 2021 at 02:11:23PM -0400, Tony Krowiak wrote: > > > On 6/18/21 1:12 PM, Jason J. Herne wrote: > > vfio_ap_matrix_dev_release is shadowing the global matrix_dev with a NULL > > pointer. Driver data for the matrix device is never set and so > > dev_get_drvdata() always returns NULL. When release is called we end up > > not freeing matrix_dev. The fix is to remove the shadow variable and get > > the correct pointer from the device using container_of. We'll also NULL > > the global to prevent any future use. > > > > Signed-off-by: Jason J. Herne > > drivers/s390/crypto/vfio_ap_drv.c | 5 ++--- > > 1 file changed, 2 insertions(+), 3 deletions(-) > > > > diff --git a/drivers/s390/crypto/vfio_ap_drv.c b/drivers/s390/crypto/vfio_ap_drv.c > > index 7dc72cb718b0..40e66cb363d1 100644 > > +++ b/drivers/s390/crypto/vfio_ap_drv.c > > @@ -82,9 +82,8 @@ static void vfio_ap_queue_dev_remove(struct ap_device *apdev) > > static void vfio_ap_matrix_dev_release(struct device *dev) > > { > > - struct ap_matrix_dev *matrix_dev = dev_get_drvdata(dev); > > - > > - kfree(matrix_dev); > > + kfree(container_of(dev, struct ap_matrix_dev, device)); > > I suppose if we're not going to assume that the release is being > called to free the global matrix_dev, then if you are going to > retrieve it using container_of(), then maybe we should verify > the retrieved pointer is the same as the global matrix_dev? That seems like overkill to me Reviewed-by: Jason Gunthorpe Jason