lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:	Tue, 23 Oct 2012 16:48:03 +0300
From:	Irina Tirdea <irina.tirdea@...el.com>
To:	Anton Vorontsov <cbouatmailru@...il.com>,
	Colin Cross <ccross@...roid.com>,
	Kees Cook <keescook@...omium.org>,
	Tony Luck <tony.luck@...el.com>, Chris Ball <cjb@...top.org>
Cc:	linux-kernel@...r.kernel.org,
	Adrian Hunter <adrian.hunter@...el.com>,
	Octavian Purdila <octavian.purdila@...el.com>,
	Irina Tirdea <irina.tirdea@...el.com>
Subject: [PATCH 05/26] block: add panic write

From: Adrian Hunter <adrian.hunter@...el.com>

Add a small interface to allow block devices to attempt to write
during an oops or panic.

Signed-off-by: Adrian Hunter <adrian.hunter@...el.com>
Signed-off-by: Irina Tirdea <irina.tirdea@...el.com>
---
 drivers/block/Kconfig  |    3 ++
 include/linux/blkdev.h |   77 ++++++++++++++++++++++++++++++++++++++++++++++++
 include/linux/genhd.h  |    3 ++
 3 files changed, 83 insertions(+)

diff --git a/drivers/block/Kconfig b/drivers/block/Kconfig
index 332ba52..f58853c 100644
--- a/drivers/block/Kconfig
+++ b/drivers/block/Kconfig
@@ -553,4 +553,7 @@ config BLK_DEV_OOPS
 
 	  See <file:Documentation/blockdev/blkoops.txt> for more information.
 
+config BLK_DEV_PANIC_WRITE
+	bool
+
 endif # BLK_DEV
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index 1756001..bedfaab 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -1461,6 +1461,83 @@ static inline bool blk_integrity_is_initialized(struct gendisk *g)
 
 #endif /* CONFIG_BLK_DEV_INTEGRITY */
 
+#ifdef CONFIG_BLK_DEV_PANIC_WRITE
+
+/**
+ * struct panic_write_operations - operations to support writing during an oops
+ *				   or panic.
+ * @init: allocate resources
+ * @cleanup: release resources
+ * @write: called in an oops or panic context to write data
+ * @flush: called in an oops or panic context to finish write operations
+ *
+ * @write may need resources that cannot be allocated in a panic or oops
+ * context.  @init can be used to allocate those resources in advance.
+ * @cleanup is called if panic writing becomes disabled.
+ */
+struct panic_write_operations {
+	int (*init)(struct block_device *);
+	void (*cleanup)(struct block_device *);
+	int (*write)(struct block_device *, sector_t, void *, unsigned long);
+	int (*flush)(struct block_device *);
+};
+
+static inline int blk_panic_init(struct block_device *bdev)
+{
+	if (!bdev->bd_disk->pwops || !bdev->bd_disk->pwops->write)
+		return -EOPNOTSUPP;
+	if (bdev->bd_disk->pwops && bdev->bd_disk->pwops->init)
+		return bdev->bd_disk->pwops->init(bdev);
+	return 0;
+}
+
+static inline void blk_panic_cleanup(struct block_device *bdev)
+{
+	if (bdev->bd_disk->pwops && bdev->bd_disk->pwops->cleanup)
+		bdev->bd_disk->pwops->cleanup(bdev);
+}
+
+static inline int blk_panic_write(struct block_device *bdev, sector_t sect,
+				  void *addr, unsigned long len)
+{
+	if (!bdev->bd_disk->pwops || !bdev->bd_disk->pwops->write)
+		return -EOPNOTSUPP;
+	if (bdev != bdev->bd_contains)
+		sect += bdev->bd_part->start_sect;
+	return bdev->bd_disk->pwops->write(bdev, sect, addr, len);
+}
+
+static inline int blk_panic_flush(struct block_device *bdev)
+{
+	if (bdev->bd_disk->pwops && bdev->bd_disk->pwops->flush)
+		return bdev->bd_disk->pwops->flush(bdev);
+	return 0;
+}
+
+#else
+
+static inline int blk_panic_init(struct block_device *bdev)
+{
+	return -EOPNOTSUPP;
+}
+
+static inline void blk_panic_cleanup(struct block_device *bdev)
+{
+}
+
+static inline int blk_panic_write(struct block_device *bdev, sector_t sect,
+				  void *addr, unsigned long len)
+{
+	return -EOPNOTSUPP;
+}
+
+static inline int blk_panic_flush(struct block_device *bdev)
+{
+	return -EOPNOTSUPP;
+}
+
+#endif /* CONFIG_BLK_DEV_PANIC_WRITE */
+
 struct block_device_operations {
 	int (*open) (struct block_device *, fmode_t);
 	int (*release) (struct gendisk *, fmode_t);
diff --git a/include/linux/genhd.h b/include/linux/genhd.h
index 4f440b3..73470af 100644
--- a/include/linux/genhd.h
+++ b/include/linux/genhd.h
@@ -195,6 +195,9 @@ struct gendisk {
 #ifdef  CONFIG_BLK_DEV_INTEGRITY
 	struct blk_integrity *integrity;
 #endif
+#ifdef CONFIG_BLK_DEV_PANIC_WRITE
+	const struct panic_write_operations *pwops;
+#endif
 	int node_id;
 };
 
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ