linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Guy Zadicario <guy.zadicario@intel.com>
To: gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org
Cc: olof@lixom.net, alexander.shishkin@linux.intel.com,
	andriy.shevchenko@intel.com, yochai.shefi-simchon@intel.com,
	guy.zadicario@intel.com
Subject: [PATCH 07/15] misc: nnpi: Disallow host memory resource access if no NNP-I devices exist
Date: Wed, 12 May 2021 10:10:38 +0300	[thread overview]
Message-ID: <20210512071046.34941-8-guy.zadicario@intel.com> (raw)
In-Reply-To: <20210512071046.34941-1-guy.zadicario@intel.com>

There is no point allowing a user application to create host resources
on a system that does not equipped with any NNP-I devices.
Fail openning the nnpi_host character device when no NNP-I devices are
attached.
It is OK to do that check without any synchronization as a race would not
be an issue.

Signed-off-by: Guy Zadicario <guy.zadicario@intel.com>
Reviewed-by: Alexander Shishkin <alexander.shishkin@linux.intel.com>
---
 drivers/misc/intel-nnpi/device.c       | 5 +++++
 drivers/misc/intel-nnpi/device.h       | 2 ++
 drivers/misc/intel-nnpi/host_chardev.c | 7 +++++++
 3 files changed, 14 insertions(+)

diff --git a/drivers/misc/intel-nnpi/device.c b/drivers/misc/intel-nnpi/device.c
index 0f98398..a3c6a1d 100644
--- a/drivers/misc/intel-nnpi/device.c
+++ b/drivers/misc/intel-nnpi/device.c
@@ -13,6 +13,11 @@
 
 static DEFINE_IDA(dev_ida);
 
+bool nnpdev_no_devices(void)
+{
+	return ida_is_empty(&dev_ida);
+}
+
 /**
  * nnpdev_init() - initialize NNP-I device structure.
  * @nnpdev: device to be initialized
diff --git a/drivers/misc/intel-nnpi/device.h b/drivers/misc/intel-nnpi/device.h
index 7d7ef60..562bbc4 100644
--- a/drivers/misc/intel-nnpi/device.h
+++ b/drivers/misc/intel-nnpi/device.h
@@ -36,6 +36,8 @@ struct nnp_device_ops {
 	int (*cmdq_write_mesg)(struct nnp_device *nnpdev, u64 *msg, u32 size);
 };
 
+bool nnpdev_no_devices(void);
+
 /*
  * Functions exported by the device framework module which are
  * called by the lower layer NNP-I device driver module
diff --git a/drivers/misc/intel-nnpi/host_chardev.c b/drivers/misc/intel-nnpi/host_chardev.c
index 6048fda..fad5954 100644
--- a/drivers/misc/intel-nnpi/host_chardev.c
+++ b/drivers/misc/intel-nnpi/host_chardev.c
@@ -217,6 +217,13 @@ static int host_open(struct inode *inode, struct file *f)
 	if (!is_host_file(f))
 		return -EINVAL;
 
+	/*
+	 * No point to serve host resource creation while no
+	 * NNP-I devices exist in the system.
+	 */
+	if (nnpdev_no_devices())
+		return -ENODEV;
+
 	user_info = kzalloc(sizeof(*user_info), GFP_KERNEL);
 	if (!user_info)
 		return -ENOMEM;
-- 
1.8.3.1

---------------------------------------------------------------------
Intel Israel (74) Limited

This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.


  parent reply	other threads:[~2021-05-12  7:12 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-12  7:10 [PATCH 00/15] misc: nnpi: New PCIe driver for Intel's NNP-I pcie device Guy Zadicario
2021-05-12  7:10 ` [PATCH 01/15] misc: nnpi: Document NNP-I's driver overview Guy Zadicario
2021-05-12  7:10 ` [PATCH 02/15] misc: nnpi: Initialize NNP-I framework and PCIe modules Guy Zadicario
2021-05-12 18:07   ` Randy Dunlap
2021-05-12  7:10 ` [PATCH 03/15] misc: nnpi: Manage and schedule messages to device Guy Zadicario
2021-05-12  7:10 ` [PATCH 04/15] misc: nnpi: Define host/card ipc protocol Guy Zadicario
2021-05-12  7:10 ` [PATCH 05/15] misc: nnpi: Manage host memory resources Guy Zadicario
2021-05-12  7:10 ` [PATCH 06/15] misc: nnpi: Allow usermode to manage host resources Guy Zadicario
2021-05-12  7:10 ` Guy Zadicario [this message]
2021-05-12  7:10 ` [PATCH 08/15] misc: nnpi: Boot NNP-I device Guy Zadicario
2021-05-12  7:10 ` [PATCH 09/15] misc: nnpi: Process device response messages Guy Zadicario
2021-05-12  7:10 ` [PATCH 10/15] misc: nnpi: Query and verify device protocol Guy Zadicario
2021-05-12  7:10 ` [PATCH 11/15] misc: nnpi: Create comm channel from app to device Guy Zadicario
2021-05-12  7:10 ` [PATCH 12/15] misc: nnpi: Route device response messages Guy Zadicario
2021-05-12  7:10 ` [PATCH 13/15] misc: nnpi: Expose command channel file interface Guy Zadicario
2021-05-12  7:10 ` [PATCH 14/15] misc: nnpi: Create command channel from userspace Guy Zadicario
2021-05-12  7:10 ` [PATCH 15/15] misc: nnpi: Map host resources to device channel Guy Zadicario
2021-05-12  7:27 ` [PATCH 00/15] misc: nnpi: New PCIe driver for Intel's NNP-I pcie device Greg KH
2021-05-12  7:51   ` Guy Zadicario
2021-05-12  8:07     ` Greg KH

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210512071046.34941-8-guy.zadicario@intel.com \
    --to=guy.zadicario@intel.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=andriy.shevchenko@intel.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=olof@lixom.net \
    --cc=yochai.shefi-simchon@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).