mirror of https://lore.kernel.org/lkml/
 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 v2 07/15] misc: nnpi: Disallow host memory resource access if no NNP-I devices exist
Date: Thu, 13 May 2021 11:57:17 +0300	[thread overview]
Message-ID: <20210513085725.45528-8-guy.zadicario@intel.com> (raw)
In-Reply-To: <20210513085725.45528-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


  parent reply	other threads:[~2021-05-13  8:59 UTC|newest]

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

all inboxes | Powered by JetHome®