From patchwork Wed Apr 6 23:33:58 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Jurgens X-Patchwork-Id: 8767311 Return-Path: X-Original-To: patchwork-linux-rdma@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id D0CE6C0553 for ; Wed, 6 Apr 2016 23:35:39 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id F0399201C7 for ; Wed, 6 Apr 2016 23:35:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id EDAD7201CD for ; Wed, 6 Apr 2016 23:35:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753639AbcDFXfd (ORCPT ); Wed, 6 Apr 2016 19:35:33 -0400 Received: from [193.47.165.129] ([193.47.165.129]:33925 "EHLO mellanox.co.il" rhost-flags-FAIL-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1753963AbcDFXfc (ORCPT ); Wed, 6 Apr 2016 19:35:32 -0400 Received: from Internal Mail-Server by MTLPINE1 (envelope-from danielj@mellanox.com) with ESMTPS (AES256-SHA encrypted); 7 Apr 2016 02:34:27 +0300 Received: from x-vnc01.mtx.labs.mlnx (x-vnc01.mtx.labs.mlnx [10.12.150.16]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id u36NY4Ts002830; Thu, 7 Apr 2016 02:34:25 +0300 From: Dan Jurgens To: selinux@tycho.nsa.gov, linux-security-module@vger.kernel.org, linux-rdma@vger.kernel.org Cc: yevgenyp@mellanox.com, Daniel Jurgens Subject: [RFC PATCH v2 13/13] ib/core: Implement the Infiniband flush callback. Date: Thu, 7 Apr 2016 02:33:58 +0300 Message-Id: <1459985638-37233-14-git-send-email-danielj@mellanox.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1459985638-37233-1-git-send-email-danielj@mellanox.com> References: <1459985638-37233-1-git-send-email-danielj@mellanox.com> Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Spam-Status: No, score=-7.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Daniel Jurgens Register the callback at init and unregister it at cleanup. When called walk the device list and call ib_security_cache_change for each port on each device. Signed-off-by: Daniel Jurgens Reviewed-by: Eli Cohen --- drivers/infiniband/core/core_priv.h | 3 ++- drivers/infiniband/core/core_security.c | 4 +--- drivers/infiniband/core/device.c | 26 ++++++++++++++++++++++++++ 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/drivers/infiniband/core/core_priv.h b/drivers/infiniband/core/core_priv.h index 216c288..271d1e0 100644 --- a/drivers/infiniband/core/core_priv.h +++ b/drivers/infiniband/core/core_priv.h @@ -230,5 +230,6 @@ static inline int ib_security_open_shared_qp(struct ib_qp *qp, static inline void ib_security_close_shared_qp(struct ib_qp_security *sec) { } -#endif + +#endif /* CONFIG_SECURITY_INFINIBAND */ #endif /* _CORE_PRIV_H */ diff --git a/drivers/infiniband/core/core_security.c b/drivers/infiniband/core/core_security.c index ebc66c1..1426731 100644 --- a/drivers/infiniband/core/core_security.c +++ b/drivers/infiniband/core/core_security.c @@ -581,7 +581,6 @@ void ib_security_cache_change(struct ib_device *device, u64 subnet_prefix) { struct pkey_index_qp_list *pkey; - list_for_each_entry(pkey, &device->port_pkey_list[port_num].pkey_list, pkey_index_list) { @@ -665,5 +664,4 @@ int ib_security_enforce_mad_agent_pkey_access(struct ib_device *dev, return security_mad_agent_pkey_access(subnet_prefix, pkey, mad_agent); } EXPORT_SYMBOL(ib_security_enforce_mad_agent_pkey_access); - -#endif /* CONFIG_SECURITY_INFINIBAND */ +#endif diff --git a/drivers/infiniband/core/device.c b/drivers/infiniband/core/device.c index f39a2a1..3647098 100644 --- a/drivers/infiniband/core/device.c +++ b/drivers/infiniband/core/device.c @@ -335,6 +335,29 @@ static int setup_port_pkey_list(struct ib_device *device) return 0; } +static void ib_security_flush(void) +{ + struct ib_device *dev; + + down_read(&lists_rwsem); + list_for_each_entry(dev, &device_list, core_list) { + int i; + + for (i = rdma_start_port(dev); i <= rdma_end_port(dev); i++) { + u64 sp; + int ret = ib_get_cached_subnet_prefix(dev, + i, + &sp); + + WARN_ONCE(ret, + "ib_get_cached_subnet_prefix err: %d, this should never happen here\n", + ret); + ib_security_cache_change(dev, i, sp); + } + } + up_read(&lists_rwsem); +} + /** * ib_register_device - Register an IB device with IB core * @device:Device to register @@ -1016,6 +1039,8 @@ static int __init ib_core_init(void) goto err_sysfs; } + security_register_ib_flush_callback(&ib_security_flush); + ib_cache_setup(); return 0; @@ -1031,6 +1056,7 @@ err: static void __exit ib_core_cleanup(void) { + security_unregister_ib_flush_callback(); ib_cache_cleanup(); ibnl_cleanup(); class_unregister(&ib_class);