From patchwork Mon Sep 2 04:24:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Parav Pandit X-Patchwork-Id: 11125973 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 841891399 for ; Mon, 2 Sep 2019 04:25:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6391A22CF7 for ; Mon, 2 Sep 2019 04:25:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729542AbfIBEYv (ORCPT ); Mon, 2 Sep 2019 00:24:51 -0400 Received: from mail-il-dmz.mellanox.com ([193.47.165.129]:35674 "EHLO mellanox.co.il" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1729341AbfIBEYv (ORCPT ); Mon, 2 Sep 2019 00:24:51 -0400 Received: from Internal Mail-Server by MTLPINE1 (envelope-from parav@mellanox.com) with ESMTPS (AES256-SHA encrypted); 2 Sep 2019 07:24:47 +0300 Received: from sw-mtx-036.mtx.labs.mlnx (sw-mtx-036.mtx.labs.mlnx [10.12.150.149]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id x824OeRM001225; Mon, 2 Sep 2019 07:24:45 +0300 From: Parav Pandit To: alex.williamson@redhat.com, jiri@mellanox.com, kwankhede@nvidia.com, cohuck@redhat.com, davem@davemloft.net Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, Parav Pandit Subject: [PATCH v3 2/5] mdev: Make mdev alias unique among all mdevs Date: Sun, 1 Sep 2019 23:24:33 -0500 Message-Id: <20190902042436.23294-3-parav@mellanox.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190902042436.23294-1-parav@mellanox.com> References: <20190826204119.54386-1-parav@mellanox.com> <20190902042436.23294-1-parav@mellanox.com> MIME-Version: 1.0 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Mdev alias should be unique among all the mdevs, so that when such alias is used by the mdev users to derive other objects, there is no collision in a given system. Signed-off-by: Parav Pandit Reviewed-by: Cornelia Huck --- Changelog: v2->v3: - Changed strcmp() ==0 to !strcmp() v1->v2: - Moved alias NULL check at beginning v0->v1: - Fixed inclusiong of alias for NULL check - Added ratelimited debug print for sha1 hash collision error --- drivers/vfio/mdev/mdev_core.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/vfio/mdev/mdev_core.c b/drivers/vfio/mdev/mdev_core.c index 3bdff0469607..c8cd40366783 100644 --- a/drivers/vfio/mdev/mdev_core.c +++ b/drivers/vfio/mdev/mdev_core.c @@ -388,6 +388,13 @@ int mdev_device_create(struct kobject *kobj, struct device *dev, ret = -EEXIST; goto mdev_fail; } + if (alias && tmp->alias && !strcmp(alias, tmp->alias)) { + mutex_unlock(&mdev_list_lock); + ret = -EEXIST; + dev_dbg_ratelimited(dev, "Hash collision in alias creation for UUID %pUl\n", + uuid); + goto mdev_fail; + } } mdev = kzalloc(sizeof(*mdev), GFP_KERNEL);