Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp5204900imm; Tue, 18 Sep 2018 06:05:04 -0700 (PDT) X-Google-Smtp-Source: ANB0VdY6ra2GwOi11hNHdmegEXPQU5N1cXX68K+QnduJuvPvAj++8B5cJVaqDduDsfLWWQTdHxbU X-Received: by 2002:a62:234d:: with SMTP id j74-v6mr30460660pfj.106.1537275904304; Tue, 18 Sep 2018 06:05:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537275904; cv=none; d=google.com; s=arc-20160816; b=bkEU3IRYDKBO4tyyJV/fJmyRgbUSoqswM3BjBJvFNebcryubpkpYC8wUl6/ScKzjT5 YKpMx3I72XZZH0IgaDixOSQj3w3X46b6OqQ/EG2sL6E0dKpgOWeSNF+XkHNqFdIF8Z3Q UGfUlEGS3J+S2m2C8pMGOo7GRE2LStuMhef/lLjswTIJaihQDfujk3KXR9UylyexgiOb yL1cp8AHUToAHRtJ0DM+5d3qy5s0EQGxwpzd7Z8C31NGSVogO2QwkfAcdMACXynCjcm0 mR4DxU5Jx5YUtW6etEU9VHlsG1TRF1WUIBDswsLGxXCMTbu0i6CS/cMJyChd3Dxtyufi G/7Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:spamdiagnosticmetadata :spamdiagnosticoutput:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=TVukn6ydEHhRELfxuBYjfdOu5VHNQoIVQiX9YJEWZDo=; b=cmax+urEo8MjQhl7LwqAObEtjcAQFFobZOf6hfV4BdGnUsMznIofQyY84Nwub/Rk1h 33QpKw0NQa/+qAk6+rbsuUFnZaf40HK16uczYHBERckrjRK90Qnh4oeNVK8UvWWYv7jb 7ewThRoOvN8+yPq/NBuathqoOnCypuI4eeYPmW6PM8W+gMEpXUUGHZlTFLKaHYe12zvu 5gf0fP7lJwOcPG/iIQWFmDQw3TAMMg27nmukgE/YK+JnPzGnfv0DA7vPC0dw7clmXq9c JpOU3Fd+DLQ72PG1NlAUV7cvTFHZHTEUqaU5T2XOlgjkIxoUeoUd+hHwcZCTa7km9G3J lGZg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=selector1 header.b="h/LJ3fy7"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=virtuozzo.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p1-v6si17685958pgl.173.2018.09.18.06.04.22; Tue, 18 Sep 2018 06:05:04 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=selector1 header.b="h/LJ3fy7"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=virtuozzo.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729763AbeIRSg1 (ORCPT + 99 others); Tue, 18 Sep 2018 14:36:27 -0400 Received: from mail-eopbgr20093.outbound.protection.outlook.com ([40.107.2.93]:10848 "EHLO EUR02-VE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726037AbeIRSg0 (ORCPT ); Tue, 18 Sep 2018 14:36:26 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtuozzo.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=TVukn6ydEHhRELfxuBYjfdOu5VHNQoIVQiX9YJEWZDo=; b=h/LJ3fy7c7FadE0qH716LelRurWexuJKT4YOMNeg3XOnQFp9Xq/UniCKOt8hFNjqfQiHQI30Erq31u/7DK9SJAWoqW6BR0nLsghTbITAMezSnkaFsjfZvMlCvwddY7GElogIRgVq5huQ1whDwuRdm8P029p5mxtTf+2em6bkzYI= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=jan.dakinevich@virtuozzo.com; Received: from work.sw.ru (185.231.240.5) by VI1PR08MB2782.eurprd08.prod.outlook.com (2603:10a6:802:19::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1143.18; Tue, 18 Sep 2018 13:03:50 +0000 From: Jan Dakinevich To: Doug Ledford , Jason Gunthorpe , Yishai Hadas , Leon Romanovsky , Parav Pandit , Mark Bloch , Daniel Jurgens , Kees Cook , Kamal Heib , Bart Van Assche , linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Denis Lunev , Konstantin Khorenko , Jan Dakinevich Subject: [PATCH 1/4] IB/core: introduce ->release() callback Date: Tue, 18 Sep 2018 16:03:43 +0300 Message-Id: <1537275826-27247-2-git-send-email-jan.dakinevich@virtuozzo.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1537275826-27247-1-git-send-email-jan.dakinevich@virtuozzo.com> References: <1537275826-27247-1-git-send-email-jan.dakinevich@virtuozzo.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [185.231.240.5] X-ClientProxiedBy: VI1P18901CA0005.EURP189.PROD.OUTLOOK.COM (2603:10a6:801::15) To VI1PR08MB2782.eurprd08.prod.outlook.com (2603:10a6:802:19::15) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 71591a45-c4cb-4286-7c76-08d61d672e57 X-Microsoft-Antispam: BCL:0;PCL:0;RULEID:(7020095)(4652040)(8989299)(4534165)(4627221)(201703031133081)(201702281549075)(8990200)(5600074)(711020)(2017052603328)(7153060)(7193020);SRVR:VI1PR08MB2782; X-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lSR/ovRMLqzzj1gqtaOF+nUpuerHde89nV6lYq7wq5xVgd+IU6JABy/tx8cmDsEy661W1xzysXayWkAh+rcfxQCacf1qZsxCgwCz1AcZM6lwFuIh0i3Trfa9YqkUiWgwOOEzwhzHgntms2bD+zpwL2xqi9jb41M8OHHrsz6r8xhz1NzuOJVsS45Uq9fPCQSonF0FajM7zdmx+36yl1PjUZQmG9VLqhUdHQYNvDpA6eM0GH1ptKPsMDkywLDM9TUaxOpjCRuEZ0KvOp0ujOR2eNeE2sFhDAmCIKLSMcRUEhV6ieLyDT3r1/sBraC4tJ+azaoUjk4NXEZZhjD3PsNMi2Gm2RqC9l8v3TX07AUCPDvmgtVOkaMcetp6eDRAhS0ZSz;4:qwIBCN86mw7hXkxlUqW8dRJUuOePYtlrUqwNQqLR1KuPk8aWTPeGza9Rg0gBtvuuLxJ8vwdnKDluHSFZSbZJSf1Bcf0QZcCH84T2ADhHVOwa2gyh3+XUjw8TxM54nJVugT2oPc4r/uemO7IDhfpfSPB4GEGePtsRhDOdXIs7q5SdNyuVvNVXoiYVPJtu0BUcxX3L09YW/IOFdSVs3eLy6rh83MApwfD6/jOust26455nIDnlLwbG7iGRZ1qVoc5zNQ/junv8JeOsMaLSP/cR1Q== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6040522)(2401047)(5005006)(8121501046)(3231355)(944501410)(52105095)(93006095)(93001095)(3002001)(10201501046)(149027)(150027)(6041310)(20161123564045)(20161123558120)(20161123560045)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(201708071742011)(7699050);SRVR:VI1PR08MB2782;BCL:0;PCL:0;RULEID:;SRVR:VI1PR08MB2782; X-Forefront-PRVS: 0799B1B2D7 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(396003)(346002)(366004)(136003)(39850400004)(376002)(189003)(199004)(3846002)(486006)(16526019)(44832011)(7736002)(26005)(68736007)(39060400002)(6116002)(54906003)(186003)(53416004)(81166006)(305945005)(16586007)(7416002)(107886003)(66066001)(2616005)(106356001)(956004)(8676002)(50466002)(8936002)(478600001)(446003)(105586002)(11346002)(476003)(110136005)(81156014)(5660300001)(6486002)(6512007)(14444005)(69596002)(97736004)(4326008)(76176011)(25786009)(47776003)(52116002)(316002)(2906002)(50226002)(386003)(6506007)(48376002)(575784001)(36756003)(6666003)(86362001)(51416003)(53936002)(921003)(1121003);DIR:OUT;SFP:1102;SCL:1;SRVR:VI1PR08MB2782;H:work.sw.ru;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; Received-SPF: None (protection.outlook.com: virtuozzo.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;VI1PR08MB2782;23:hlCm3y2Dw8U9VTI4XTulQ7+kNeMrRVm+XsokvIMOR?= =?us-ascii?Q?UEOWa4HfZZeIndqGvlqjXXg6ruvBa161mvS/4NWpOgkTxTzT3P+IhaozWLqI?= =?us-ascii?Q?n/TWL3cgPFK2z2/pLL+MYjBvZMRgoEOfGx4EcgW6p0VpZwxXAoUVROLCuFtl?= =?us-ascii?Q?9iV8BUKr0hQHkrDyHWydaPrDw1DqakKwgSoJ/dDqbWPsNsrPMssdglDbt/FD?= =?us-ascii?Q?9e+MsR7LBuOW05ShCn7JtIX1b8ItetsfR8WrkCaWsrdh53pffPgvnZTta6DW?= =?us-ascii?Q?2HoRLYltGiidlJl/0PFDZwHDRVTljgT8IPbwvLM5fFmIqi/a6EEFZMHURUmN?= =?us-ascii?Q?Y1tpLWQEGVrdyPCCeoRA7Rg6Eu7LTKsI/qjX/QXMpvFGm+lRDyZ+5fwP4P/X?= =?us-ascii?Q?z9wjqkmwzwrVPh21Ffn7mS+acktW1fu5+SYDay0VFpwmPXGSfacHpvXKC6hv?= =?us-ascii?Q?FsIGF0yZ8bGy/mQGFDIHaU3XeafdbAF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MnxQ5t1UmUN720OPcNUxuRVLCpvQX9elcxlRBXca2Y=;7:3Ugf4CAyesu3FlGBS2VzsxMZEYv1UJ1l7uy8fu7tlqqkX1w7OPySNcPcoEh3IcMU29C4I97F4yEVxrZ0AhMzP2ES/0Nw3epKsZznKFsYxR6+TGy9TJPM+tuX8Vkvfxg20uIPlLlWfV61fu/roGmHBfUN8xyDX7Z4D/Kei8YCtX6h9MhR5XSv3rWal/nQWFYnNtrtxj5pOckw2jX4ekP5WTKi8jHxD9Utndd31+L1xofIMiG0ESpSuhdJGajIf/TN SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;VI1PR08MB2782;20:pTwURjOc5GGPgYGXP0MmG5J4RRry76gIMBWMzrWMf7B9vc6oR66djM2VFwjlKzT2U0xc3FBXc6wIFSZ406ajEcLjyQirKPHf80134RIhkiCrrkf7rN0t3KPhqm1trvHJv/tbkxjGFDdx+LEPklfqmP/kKgBM4WoOwPtJ0ROSA1I= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Sep 2018 13:03:50.5826 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 71591a45-c4cb-4286-7c76-08d61d672e57 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR08MB2782 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org IB infrastructure shares common device instance constructor with reference counting, and it uses kzalloc() to allocate memory for device specific instance with incapsulated ib_device field as one contigous memory block. The issue is that the device specific instances tend to be too large and require high page order memory allocation. Unfortunately, kzalloc() in ib_alloc_device() can not be replaced with kvzalloc() since it would require a lot of review in all IB driver to prove correctness of the replacement. The driver can allocate some heavy partes of their instance for itself and keep pointers for them in own instance. For this it is important that the alocated parts have the same life time as ib_device, thus their deallocation should be based on the same reference counting. Let suppose: struct foo_ib_device { struct ib_device device; void *part; ... }; To properly free memory from .foo_ib_part the driver should provide function for ->release() callback: void foo_ib_release(struct ib_device *device) { struct foo_ib_device *foo = container_of(device, struct foo_ib_device, device); kvfree(foo->part); } ...and initialiaze this callback immediately after foo_ib_device instance allocation. struct foo_ib_device *foo; foo = ib_alloc_device(sizeof(struct foo_ib_device)); foo->device.release = foo_ib_release; /* allocate parts */ foo->part = kvmalloc(65536, GFP_KERNEL); Signed-off-by: Jan Dakinevich --- drivers/infiniband/core/device.c | 2 ++ include/rdma/ib_verbs.h | 2 ++ 2 files changed, 4 insertions(+) diff --git a/drivers/infiniband/core/device.c b/drivers/infiniband/core/device.c index db3b627..a8c8b0d 100644 --- a/drivers/infiniband/core/device.c +++ b/drivers/infiniband/core/device.c @@ -215,6 +215,8 @@ static void ib_device_release(struct device *device) ib_cache_release_one(dev); kfree(dev->port_immutable); } + if (dev->release) + dev->release(dev); kfree(dev); } diff --git a/include/rdma/ib_verbs.h b/include/rdma/ib_verbs.h index e950c2a..fb582bb 100644 --- a/include/rdma/ib_verbs.h +++ b/include/rdma/ib_verbs.h @@ -2271,6 +2271,8 @@ struct ib_device { struct iw_cm_verbs *iwcm; + void (*release)(struct ib_device *device); + /** * alloc_hw_stats - Allocate a struct rdma_hw_stats and fill in the * driver initialized data. The struct is kfree()'ed by the sysfs -- 2.1.4