From patchwork Tue Aug 27 19:16:51 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Parav Pandit X-Patchwork-Id: 11117395 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 BC05214E5 for ; Tue, 27 Aug 2019 19:17:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9E9ED2189D for ; Tue, 27 Aug 2019 19:17:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731017AbfH0TRJ (ORCPT ); Tue, 27 Aug 2019 15:17:09 -0400 Received: from mail-il-dmz.mellanox.com ([193.47.165.129]:38880 "EHLO mellanox.co.il" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1730965AbfH0TRI (ORCPT ); Tue, 27 Aug 2019 15:17:08 -0400 Received: from Internal Mail-Server by MTLPINE1 (envelope-from parav@mellanox.com) with ESMTPS (AES256-SHA encrypted); 27 Aug 2019 22:17:03 +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 x7RJGuGs026842; Tue, 27 Aug 2019 22:17:01 +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 v1 2/5] mdev: Make mdev alias unique among all mdevs Date: Tue, 27 Aug 2019 14:16:51 -0500 Message-Id: <20190827191654.41161-3-parav@mellanox.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190827191654.41161-1-parav@mellanox.com> References: <20190826204119.54386-1-parav@mellanox.com> <20190827191654.41161-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 --- Changelog: 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 62d29f57fe0c..4b9899e40665 100644 --- a/drivers/vfio/mdev/mdev_core.c +++ b/drivers/vfio/mdev/mdev_core.c @@ -375,6 +375,13 @@ int mdev_device_create(struct kobject *kobj, struct device *dev, ret = -EEXIST; goto mdev_fail; } + if (tmp->alias && alias && strcmp(tmp->alias, alias) == 0) { + 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);