From patchwork Mon Feb 4 21:17:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 10796645 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4731913B5 for ; Mon, 4 Feb 2019 21:18:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 37B4A2B1EB for ; Mon, 4 Feb 2019 21:18:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2C22B2B500; Mon, 4 Feb 2019 21:18:04 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B5E082B1EB for ; Mon, 4 Feb 2019 21:18:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729486AbfBDVSD (ORCPT ); Mon, 4 Feb 2019 16:18:03 -0500 Received: from mail-pg1-f195.google.com ([209.85.215.195]:33772 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729280AbfBDVSC (ORCPT ); Mon, 4 Feb 2019 16:18:02 -0500 Received: by mail-pg1-f195.google.com with SMTP id z11so495973pgu.0 for ; Mon, 04 Feb 2019 13:18:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ziepe.ca; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=wFKNk0zIu62HpNp5Qv2kIqP9VYmjfZM5PmuNx4HVzEY=; b=nRR7yR8x7r7KogJdYxCRuvaC8v6trh15JVzGSqpP8cXrX22REuZhV4OjgCKN+d8WC6 u5Gl9jUhHRZg8JONK/mkpspUfDojvrUh4CtR70Ck87PIRHO3eBEbHVXcX3yxPEHHYUeS JY1yk0YbAQSLEoL88TM8NYbSIbuVFP0pI16D0n12bEKFc02aC2lCkqbV0xwP1F3lWPlF 9gka1Fk3mP4myTzl0XDxvi8Cj/wcdNhDqmeOe5nyh+OlgjXRrQ82szveEGC3r1PchF8T 7TSkwp1gOVvE4zykgfp+75rBvZjZ03D9rJZAAJ7eFeTKKUEQ9zD+RudxyGEx6B3o4bfs KDaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=wFKNk0zIu62HpNp5Qv2kIqP9VYmjfZM5PmuNx4HVzEY=; b=bdjNZkYnuLRlYrTv67dEJZd9Aglv8xfRuktwUQQpHYaCSTvXrYmnBJxFK87lHOrOSw g69s6C29NqDD6WqiKQQB028YHHSRWr1bWvoLv/uu/HifM9z00na5zRx6BDdp+sbX/zHl Kd+pt9Mii6rJ3OOqyi3b3nBnLMqxTFxa6198v24fbvDjK+9p3K4R+C/YOXcjmOXAWcrP GUIoGPnD0+P8GI+OtfHCVSaQApk2NE1tcX2XfhHCwDGZY3C324wglUKhP9zMUNZUX7sf Gl2wZQBtf7MkGzy7KIuBISKJ+M20rjuDjcYlrwWNxfePxHHft1CrOWBHhUo4zcvlrS7T WOsw== X-Gm-Message-State: AHQUAuYUrHcM5u6N3gQoSfHbf5H2a4/wSU01zLmJQg1zaTPI3mq930V0 0hvNKE3ZWLQkgD4QYIZY07bzT42qmPg= X-Google-Smtp-Source: AHgI3IaoFR4qhVVYNajWFabimUBOa4bOxSw9hZjtLT/DA5/JsheVsg6g9WN2qVOePIhjTyclOpCu1Q== X-Received: by 2002:a65:6094:: with SMTP id t20mr1252093pgu.285.1549315081030; Mon, 04 Feb 2019 13:18:01 -0800 (PST) Received: from ziepe.ca (S010614cc2056d97f.ed.shawcable.net. [174.3.196.123]) by smtp.gmail.com with ESMTPSA id p2sm1474794pfb.28.2019.02.04.13.17.59 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 04 Feb 2019 13:18:00 -0800 (PST) Received: from jgg by mlx.ziepe.ca with local (Exim 4.90_1) (envelope-from ) id 1gqlct-0005KN-Cn; Mon, 04 Feb 2019 14:17:59 -0700 From: Jason Gunthorpe To: linux-rdma@vger.kernel.org Cc: Jason Gunthorpe Subject: [PATCH 2/8] RDMA/device: Ensure that security memory is always freed Date: Mon, 4 Feb 2019 14:17:45 -0700 Message-Id: <20190204211751.19001-3-jgg@ziepe.ca> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190204211751.19001-1-jgg@ziepe.ca> References: <20190204211751.19001-1-jgg@ziepe.ca> MIME-Version: 1.0 Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Jason Gunthorpe Since this only frees memory it should be done during the release callback. Otherwise there are possible error flows where it might not get called if registration aborts. Signed-off-by: Jason Gunthorpe --- drivers/infiniband/core/core_priv.h | 4 ++-- drivers/infiniband/core/device.c | 10 +++------- drivers/infiniband/core/security.c | 4 +--- 3 files changed, 6 insertions(+), 12 deletions(-) diff --git a/drivers/infiniband/core/core_priv.h b/drivers/infiniband/core/core_priv.h index bcb3e3029a9be8..52d17e7eddc35f 100644 --- a/drivers/infiniband/core/core_priv.h +++ b/drivers/infiniband/core/core_priv.h @@ -181,7 +181,7 @@ int ib_get_cached_subnet_prefix(struct ib_device *device, u64 *sn_pfx); #ifdef CONFIG_SECURITY_INFINIBAND -void ib_security_destroy_port_pkey_list(struct ib_device *device); +void ib_security_release_port_pkey_list(struct ib_device *device); void ib_security_cache_change(struct ib_device *device, u8 port_num, @@ -203,7 +203,7 @@ int ib_mad_agent_security_setup(struct ib_mad_agent *agent, void ib_mad_agent_security_cleanup(struct ib_mad_agent *agent); int ib_mad_enforce_security(struct ib_mad_agent_private *map, u16 pkey_index); #else -static inline void ib_security_destroy_port_pkey_list(struct ib_device *device) +static inline void ib_security_release_port_pkey_list(struct ib_device *device) { } diff --git a/drivers/infiniband/core/device.c b/drivers/infiniband/core/device.c index f9f33e842c16b6..b21ea9154cf24d 100644 --- a/drivers/infiniband/core/device.c +++ b/drivers/infiniband/core/device.c @@ -253,6 +253,8 @@ static void ib_device_release(struct device *device) ib_cache_release_one(dev); kfree(dev->port_immutable); } + ib_security_release_port_pkey_list(dev); + kfree(dev->port_pkey_list); kfree(dev); } @@ -521,7 +523,6 @@ static void cleanup_device(struct ib_device *device) { ib_cache_cleanup_one(device); ib_cache_release_one(device); - kfree(device->port_pkey_list); kfree(device->port_immutable); } @@ -559,12 +560,10 @@ static int setup_device(struct ib_device *device) if (ret) { dev_warn(&device->dev, "Couldn't set up InfiniBand P_Key/GID cache\n"); - goto pkey_cleanup; + return ret; } return 0; -pkey_cleanup: - kfree(device->port_pkey_list); port_cleanup: kfree(device->port_immutable); return ret; @@ -681,9 +680,6 @@ void ib_unregister_device(struct ib_device *device) ib_cache_cleanup_one(device); - ib_security_destroy_port_pkey_list(device); - kfree(device->port_pkey_list); - down_write(&lists_rwsem); write_lock_irqsave(&device->client_data_lock, flags); list_for_each_entry_safe(context, tmp, &device->client_data_list, diff --git a/drivers/infiniband/core/security.c b/drivers/infiniband/core/security.c index 1efadbccf394df..df2602a91350e6 100644 --- a/drivers/infiniband/core/security.c +++ b/drivers/infiniband/core/security.c @@ -554,13 +554,12 @@ void ib_security_cache_change(struct ib_device *device, } } -void ib_security_destroy_port_pkey_list(struct ib_device *device) +void ib_security_release_port_pkey_list(struct ib_device *device) { struct pkey_index_qp_list *pkey, *tmp_pkey; int i; for (i = rdma_start_port(device); i <= rdma_end_port(device); i++) { - spin_lock(&device->port_pkey_list[i].list_lock); list_for_each_entry_safe(pkey, tmp_pkey, &device->port_pkey_list[i].pkey_list, @@ -568,7 +567,6 @@ void ib_security_destroy_port_pkey_list(struct ib_device *device) list_del(&pkey->pkey_index_list); kfree(pkey); } - spin_unlock(&device->port_pkey_list[i].list_lock); } }