Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp168762ybe; Sun, 1 Sep 2019 22:51:34 -0700 (PDT) X-Google-Smtp-Source: APXvYqwc4JDU2PyTpajuF7SqY3LdqaT9Lu1On3xWWM1I7efEXW39xYKDjTKm/Alq/nharHdsdc/m X-Received: by 2002:a17:902:524:: with SMTP id 33mr3374804plf.123.1567403494421; Sun, 01 Sep 2019 22:51:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567403494; cv=none; d=google.com; s=arc-20160816; b=hNRjjWWQ6vFWOMG4Dukh6yOeb95hVGQ+DztD8wcaMNIrEfdbKnRJ+QeBXg+cNZUMtb 3pixB38+TgHvoZUImPbU7Ibg4mgft578+HaMjbyfd3GUADdE2naHnM/Z2DdLDUzhZz1u 2NnxaBfSrqhirnDX3rEbXDxrkV7Zfs54tMfVjIDDdsWENalX+MEf1P09YhbVlXAaEfyQ foJyIFBCQ0bGXSkhIwm1oCRKwTPJ25stTxaAkJ2E6LHKXC9rwmtBggiuEaurEfnLX40W N0yAzYYrBU5sd03w6dXBzwHWbwPAxt0gIQ3VKUr8lDn5Thc4PM1zBfwxwx4Dn2glMXzi L2OA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=nEyKU8O51bQbDHmF1Hkd1EXlAZKE4o8DL/mrqNB174c=; b=mejeRUcDKiinw+h12Lm37Q59RHc4pJOiiaSfpyfDKYgqQIQaANkpwIJa2b9L2bt4oE BhV903+6Swifx9w9UhO6tLVlaq6V1C6HF4w3rN/scnZ7Nx1+Qcz1EW8V29pwo9K648iP lbo6NnrUSjxY1E4/rHN7XnKXoeNb2eMm9efaYWMFhLkUoh8ai3QxlUFSLJk0BwgpRxPS eqoEGfJLPi0OX5R8RWBOh2UhjBO9KVd+EVKVj1ejj4nnZ2+oMuvFRJFF9r/5acotfyfL 69R4hy5oaRbV2vOSp2TOIl5LgGOwq6rjmHh+Qqm0Bs0sE4T0VHXps/3TQlsKuhHjzwKg QTQA== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=mellanox.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s14si13425089pfc.35.2019.09.01.22.50.51; Sun, 01 Sep 2019 22:51:34 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=mellanox.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729553AbfIBEYw (ORCPT + 99 others); Mon, 2 Sep 2019 00:24:52 -0400 Received: from mail-il-dmz.mellanox.com ([193.47.165.129]:35675 "EHLO mellanox.co.il" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1729499AbfIBEYv (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 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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: 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); -- 2.19.2