Add MMC erase and secure erase V4
Subsystems (6)
v4 cover Add MMC erase and secure erase V4
Hi
Add ability to do MMC erase and secure erase operations from userspace, using the BLKDISCARD ioctl and a newly created BLKSECDISCARD ioctl.
This is version 4 of these patches.
Changes from V3
- rebased on mmotm
- added SD/MMC device attribute documentation to 'mmc: Add erase, secure erase, trim and secure trim operations' patch
Changes from V2
- move the addition of BLKSECDISCARD to a separate patch and implement it using I/O requests
- move the MMC support of secure discard to a separate patch and support the secure discard I/O request
Changes from V1
- use discard I/O requests instead of implementing BLKDISCARD in mmc_block
- do not validate erase size for MMC erases, instead round to erase size
- rename MMC max_erase to pref_erase and expose it through sysfs as preferred_erase_size
Adrian Hunter (5):
mmc: Add erase, secure erase, trim and secure trim operations
mmc_block: Add discard support
omap_hsmmc: Add erase capability
block: Add secure discard
mmc_block: Add support for secure discard
Documentation/00-INDEX | 2 + Documentation/mmc/00-INDEX | 4 + Documentation/mmc/mmc-dev-attrs.txt | 56 ++++++ block/blk-core.c | 5 +- block/blk-lib.c | 6 + block/compat_ioctl.c | 1 + block/elevator.c | 6 + block/ioctl.c | 15 +- drivers/mmc/card/block.c | 82 ++++++++- drivers/mmc/card/queue.c | 19 ++- drivers/mmc/core/core.c | 346 +++++++++++++++++++++++++++++++++++ drivers/mmc/core/core.h | 2 + drivers/mmc/core/mmc.c | 47 +++++- drivers/mmc/core/sd.c | 82 ++++++++ drivers/mmc/core/sd_ops.c | 48 +++++ drivers/mmc/core/sd_ops.h | 1 + drivers/mmc/host/omap_hsmmc.c | 13 +- include/linux/bio.h | 2 + include/linux/blkdev.h | 7 +- include/linux/fs.h | 2 + include/linux/mmc/card.h | 19 ++ include/linux/mmc/core.h | 19 ++ include/linux/mmc/host.h | 1 + include/linux/mmc/mmc.h | 26 ++- include/linux/mmc/sd.h | 5 + kernel/trace/blktrace.c | 8 + 26 files changed, 803 insertions(+), 21 deletions(-) create mode 100644 Documentation/mmc/00-INDEX create mode 100644 Documentation/mmc/mmc-dev-attrs.txt
Regards
Adrian
PATCH v4 1/5 mmc: Add erase, secure erase, trim and secure trim operations
Quoted 1 line
From
7f01ad3c4be6ec09318176db12db66f353b526e0Mon Sep 17 00:00:00 2001
From: Adrian Hunter <[email protected]>
Date: Tue, 1 Jun 2010 13:20:22 +0300
Subject: [PATCH 1/5] mmc: Add erase, secure erase, trim and secure trim operations
SD/MMC cards tend to support an erase operation. In addition, eMMC v4.4 cards can support secure erase, trim and secure trim operations that are all variants of the basic erase command.
SD/MMC device attributes "erase_size" and "preferred_erase_size" have been added.
"erase_size" is the minimum size, in bytes, of an erase operation. For MMC, "erase_size" is the erase group size reported by the card. Note that "erase_size" does not apply to trim or secure trim operations where the minimum size is always one 512 byte sector. For SD, "erase_size" is 512 if the card is block-addressed, 0 otherwise.
SD/MMC cards can erase an arbitrarily large area up to and including the whole card. When erasing a large area it may be desirable to do it in smaller chunks for three reasons:
1. A single erase command will make all other I/O on the card wait. This is not a problem if the whole card is being erased, but erasing one partition will make I/O for another partition on the same card wait for the duration of the erase - which could be a several minutes.
2. To be able to inform the user of erase progress.
3. The erase timeout becomes too large to be very useful. Because the erase timeout contains a margin which is multiplied by the size of the erase area, the value can end up being several minutes for large areas.
"erase_size" is not the most efficient unit to erase (especially for SD where it is just one sector), hence "preferred_erase_size" provides a good chunk size for erasing large areas.
For MMC, "preferred_erase_size" is the high-capacity erase size if a card specifies one, otherwise it is based on the capacity of the card.
For SD, "preferred_erase_size" is the allocation unit size specified by the card.
"preferred_erase_size" is in bytes.
--- Documentation/00-INDEX | 2 + Documentation/mmc/00-INDEX | 4 + Documentation/mmc/mmc-dev-attrs.txt | 56 ++++++ drivers/mmc/core/core.c | 346 +++++++++++++++++++++++++++++++++++ drivers/mmc/core/core.h | 2 + drivers/mmc/core/mmc.c | 47 +++++- drivers/mmc/core/sd.c | 82 ++++++++ drivers/mmc/core/sd_ops.c | 48 +++++ drivers/mmc/core/sd_ops.h | 1 + include/linux/mmc/card.h | 19 ++ include/linux/mmc/core.h | 19 ++ include/linux/mmc/host.h | 1 + include/linux/mmc/mmc.h | 26 ++- include/linux/mmc/sd.h | 5 + 14 files changed, 650 insertions(+), 8 deletions(-) create mode 100644 Documentation/mmc/00-INDEX create mode 100644 Documentation/mmc/mmc-dev-attrs.txt
Documentation/00-INDEX +2 -0
@@ -232,6 +232,8 @@ memory.txt - info on typical Linux memory problems. mips/ - directory with info about Linux on MIPS architecture. +mmc/ + - directory with info about the MMC subsystem mono.txt - how to execute Mono-based .NET binaries with the help of BINFMT_MISC. mutex-design.txt
Documentation/mmc/00-INDEX new file +4 -0
@@ -0,0 +1,4 @@ +00-INDEX + - this file +mmc-dev-attrs.txt + - info on SD and MMC device attributes
Documentation/mmc/mmc-dev-attrs.txt new file +56 -0
56 lines not on this page · raw message
drivers/mmc/core/core.c +346 -0
352 lines not on this page · raw message
drivers/mmc/core/core.h +2 -0
@@ -29,6 +29,8 @@ struct mmc_bus_ops {void mmc_attach_bus (struct mmc_host *host,const struct mmc_bus_ops *ops);void mmc_detach_bus (struct mmc_host *host); +void mmc_init_erase (struct mmc_card *card); +void mmc_set_chip_select (struct mmc_host *host,int mode);void mmc_set_clock (struct mmc_host *host,unsigned int hz);void mmc_set_bus_mode (struct mmc_host *host,unsigned int mode);
drivers/mmc/core/mmc.c +46 -1
91 lines not on this page · raw message
drivers/mmc/core/sd.c +82 -0
128 lines not on this page · raw message
drivers/mmc/core/sd_ops.c +48 -0
51 lines not on this page · raw message
drivers/mmc/core/sd_ops.h +1 -0
@@ -19,6 +19,7 @@ int mmc_send_relative_addr(struct mmc_host *host, unsigned int *rca);int mmc_app_send_scr (struct mmc_card *card,u32 *scr);int mmc_sd_switch (struct mmc_card *card,int mode,int group,u8 value,u8 *resp); +int mmc_app_sd_status (struct mmc_card *card,void *ssr);#endif
include/linux/mmc/card.h +19 -0
@@ -31,6 +31,7 @@ struct mmc_csd {unsigned int tacc_ns;unsigned int r2w_factor;unsigned int max_dtr; +unsigned int erase_size;/* In sectors */ unsigned int read_blkbits;unsigned int write_blkbits;unsigned int capacity;
@@ -42,9 +43,16 @@ struct mmc_csd {struct mmc_ext_csd {u8 rev; +u8 erase_group_def; +u8 sec_feature_support;unsigned int sa_timeout;/* Units: 100ns */ unsigned int hs_max_dtr;unsigned int sectors; +unsigned int hc_erase_size;/* In sectors */ +unsigned int hc_erase_timeout;/* In milliseconds */ +unsigned int sec_trim_mult;/* Secure trim multiplier */ +unsigned int sec_erase_mult;/* Secure erase multiplier */ +unsigned int trim_timeout;/* In milliseconds */ };struct sd_scr {
@@ -54,6 +62,12 @@ struct sd_scr {#define SD_SCR_BUS_WIDTH_4 (1<<2) }; +struct sd_ssr { +unsigned int au;/* In sectors */ +unsigned int erase_timeout;/* In milliseconds */ +unsigned int erase_offset;/* In milliseconds */ +}; +struct sd_switch_caps {unsigned int hs_max_dtr; };
@@ -103,6 +117,10 @@ struct mmc_card {#define MMC_QUIRK_LENIENT_FN0 (1<<0)/* allow SDIO FN0 writes outside of the VS CCCR range */ #define MMC_QUIRK_BLKSZ_FOR_BYTE_MODE (1<<1)/* use func->cur_blksize */ /* for byte mode */ +unsigned int erase_size;/* erase size in sectors */ +unsigned int erase_shift;/* if erase unit is power 2 */ +unsigned int pref_erase;/* in sectors */ +u8 erased_byte;/* value of erased bytes */ u32 raw_cid[4 ];/* raw card CID */ u32 raw_csd[4 ];/* raw card CSD */
@@ -111,6 +129,7 @@ struct mmc_card {struct mmc_csd csd;/* card specific */ struct mmc_ext_csd ext_csd;/* mmc v4 extended card specific */ struct sd_scr scr;/* extra SD information */ +struct sd_ssr ssr;/* yet more SD information */ struct sd_switch_caps sw_caps;/* switch (CMD6) caps */ unsigned int sdio_funcs;/* number of SDIO functions */
include/linux/mmc/core.h +19 -0
@@ -92,6 +92,8 @@ struct mmc_command {* actively failing requests */ +unsigned int erase_timeout;/* in milliseconds */ +struct mmc_data *data;/* data segment associated with cmd */ struct mmc_request *mrq;/* associated request */ };
@@ -134,6 +136,23 @@ extern int mmc_wait_for_cmd(struct mmc_host *, struct mmc_command *, int);extern int mmc_wait_for_app_cmd (struct mmc_host *,struct mmc_card *,struct mmc_command *,int ); +#define MMC_ERASE_ARG 0x00000000 +#define MMC_SECURE_ERASE_ARG 0x80000000 +#define MMC_TRIM_ARG 0x00000001 +#define MMC_SECURE_TRIM1_ARG 0x80000001 +#define MMC_SECURE_TRIM2_ARG 0x80008000 + +#define MMC_SECURE_ARGS 0x80000000 +#define MMC_TRIM_ARGS 0x00008001 + +extern int mmc_erase (struct mmc_card *card,unsigned int from,unsigned int nr, +unsigned int arg); +extern int mmc_can_erase (struct mmc_card *card); +extern int mmc_can_trim (struct mmc_card *card); +extern int mmc_can_secure_erase_trim (struct mmc_card *card); +extern int mmc_erase_group_aligned (struct mmc_card *card,unsigned int from, +unsigned int nr); +extern void mmc_set_data_timeout (struct mmc_data *,const struct mmc_card *);extern unsigned int mmc_align_data_size (struct mmc_card *,unsigned int );
include/linux/mmc/host.h +1 -0
@@ -156,6 +156,7 @@ struct mmc_host {#define MMC_CAP_DISABLE (1 << 7)/* Can the host be disabled */ #define MMC_CAP_NONREMOVABLE (1 << 8)/* Nonremovable e.g. eMMC */ #define MMC_CAP_WAIT_WHILE_BUSY (1 << 9)/* Waits while card is busy */ +#define MMC_CAP_ERASE (1 << 10)/* Allow erase/trim commands */ mmc_pm_flag_t pm_caps;/* supported pm features */
include/linux/mmc/mmc.h +19 -7
@@ -251,13 +251,21 @@ struct _mmc_csd {* EXT_CSD fields */ -#define EXT_CSD_BUS_WIDTH 183/* R/W */ -#define EXT_CSD_HS_TIMING 185/* R/W */ -#define EXT_CSD_CARD_TYPE 196/* RO */ -#define EXT_CSD_STRUCTURE 194/* RO */ -#define EXT_CSD_REV 192/* RO */ -#define EXT_CSD_SEC_CNT 212/* RO, 4 bytes */ -#define EXT_CSD_S_A_TIMEOUT 217 +#define EXT_CSD_ERASE_GROUP_DEF 175/* R/W */ +#define EXT_CSD_ERASED_MEM_CONT 181/* RO */ +#define EXT_CSD_BUS_WIDTH 183/* R/W */ +#define EXT_CSD_HS_TIMING 185/* R/W */ +#define EXT_CSD_REV 192/* RO */ +#define EXT_CSD_STRUCTURE 194/* RO */ +#define EXT_CSD_CARD_TYPE 196/* RO */ +#define EXT_CSD_SEC_CNT 212/* RO, 4 bytes */ +#define EXT_CSD_S_A_TIMEOUT 217/* RO */ +#define EXT_CSD_ERASE_TIMEOUT_MULT 223/* RO */ +#define EXT_CSD_HC_ERASE_GRP_SIZE 224/* RO */ +#define EXT_CSD_SEC_TRIM_MULT 229/* RO */ +#define EXT_CSD_SEC_ERASE_MULT 230/* RO */ +#define EXT_CSD_SEC_FEATURE_SUPPORT 231/* RO */ +#define EXT_CSD_TRIM_MULT 232/* RO */ /* * EXT_CSD field definitions
@@ -275,6 +283,10 @@ struct _mmc_csd {#define EXT_CSD_BUS_WIDTH_4 1/* Card is in 4 bit mode */ #define EXT_CSD_BUS_WIDTH_8 2/* Card is in 8 bit mode */ +#define EXT_CSD_SEC_ER_EN BIT(0) +#define EXT_CSD_SEC_BD_BLK_EN BIT(2) +#define EXT_CSD_SEC_GB_CL_EN BIT(4) +/* * MMC_SWITCH access modes */
include/linux/mmc/sd.h +5 -0
@@ -21,8 +21,13 @@/* class 10 */ #define SD_SWITCH 6/* adtc [31:0] See below R1 */ +/* class 5 */ +#define SD_ERASE_WR_BLK_START 32/* ac [31:0] data addr R1 */ +#define SD_ERASE_WR_BLK_END 33/* ac [31:0] data addr R1 */ +/* Application commands */ #define SD_APP_SET_BUS_WIDTH 6/* ac [1:0] bus width R1 */ +#define SD_APP_SD_STATUS 13/* adtc R1 */ #define SD_APP_SEND_NUM_WR_BLKS 22/* adtc R1 */ #define SD_APP_OP_COND 41/* bcr [31:0] OCR R3 */ #define SD_APP_SEND_SCR 51/* adtc R1 */
Signature · 1 line
1.6.3.3
Re: [PATCH V4 1/5] mmc: Add erase, secure erase, trim and secure trim operations
Quoted 5 lines · Adrian Hunter
From
7f01ad3c4be6ec09318176db12db66f353b526e0Mon Sep 17 00:00:00 2001SD/MMC cards tend to support an erase operation. In addition, eMMC v4.4 cards can support secure erase, trim and secure trim operations that are all variants of the basic erase command.
This is great. I am interested primarily in SD media.
Please forgive my naive perspective: it seems that with the features enabled by this patchset and a filesystem that is capable of issuing erase block commands, the wear-leveling on SD media will be improved -- much like with CF TRIM commands. Do you also think that is the case? I would be very interested in hearing your expert opinion on this.
I have a couple comments regarding mostly the SD support introduced in this patch. Patches 2..5 of 5 seem fine to me but I'm not sure I'm qualified to add acks or reviewed-by's.
Quoted 21 lines
drivers/mmc/core/core.c +21
-0+int mmc_erase (struct mmc_card *card,unsigned int from,unsigned int nr, + unsigned int arg) +{ + unsigned int rem, to = from + nr; + + if (!(card->host->caps & MMC_CAP_ERASE) || + !(card->csd.cmdclass & CCC_ERASE)) + return -EOPNOTSUPP; + + if (!card->erase_size) + return -EOPNOTSUPP; + + if (mmc_card_sd(card) && arg != MMC_ERASE_ARG) + return -EOPNOTSUPP; + + if ((arg & MMC_SECURE_ARGS) && + !(card->ext_csd.sec_feature_support & EXT_CSD_SEC_ER_EN)) + return -EOPNOTSUPP; + + if ((arg & MMC_TRIM_ARGS) && + !(card->ext_csd.sec_feature_support & EXT_CSD_SEC_GB_CL_EN))
drivers/mmc/core/core.c void mmc_detect_change(struct mmc_host *host, unsigned long delay) · line 1379
Quoted 10 lines
drivers/mmc/core/core.c +9
-0+ return -EOPNOTSUPP; + +int mmc_can_trim (struct mmc_card *card) +{ + if (card->ext_csd.sec_feature_support & EXT_CSD_SEC_GB_CL_EN) + return 1; + return 0; +} +EXPORT_SYMBOL (mmc_can_trim);
It looks like mmc_can_trim(card) would return true when mmc_card_sd(card) is true; but the mmc_erase function will return -EOPNOTSUPP in such a case. I think that this results in the mmc_blk_issue_discard_rq function (from 2/5) also returning -EOPNOTSUPP whenever mmc_card_sd(card) is true:
From 2/5:
+ if (mmc_can_trim(card))
+ arg = MMC_TRIM_ARG;
+ else
+ arg = MMC_ERASE_ARG;
+
+ err = mmc_erase(card, from, nr, arg);
Also, there is some duplication between the sec_feature_support checking in mmc_erase and in the mmc_can* functions; If mmc_erase could call the mmc_can_* functions then the the bit-checking logic could be centralized.
drivers/mmc/core/sd.c static int mmc_decode_scr(struct mmc_card *card) · line 204
Quoted 5 lines
/*
+ * Fetch and process SD Status register.
+ */drivers/mmc/core/sd.c +2
-0+static int mmc_read_ssr (struct mmc_card *card) +{
It looks like the conventional function prefix for SD-specific functions in the rest of this file is mmc_sd_ ; 'mmc_read_ssr' -> 'mmc_sd_read_ssr' or -> 'mmc_read_sd_sr' perhaps?
Quoted 1 line
+ ssr =
kmalloc(64, GFP_KERNEL);
Why '64' instead of 'sizeof(*ssr)' ?
Best Regards,
Ben Gardiner
---
Nanometrics Inc.
http://www.nanometrics.ca
Re: [PATCH V4 1/5] mmc: Add erase, secure erase, trim and secure trim operations
Quoted 7 lines · Ben Gardiner
Quoted 5 lines · Adrian Hunter
From
7f01ad3c4be6ec09318176db12db66f353b526e0Mon Sep 17 00:00:00 2001SD/MMC cards tend to support an erase operation. In addition, eMMC v4.4 cards can support secure erase, trim and secure trim operations that are all variants of the basic erase command.
Quoted 8 lines
This is great. I am interested primarily in SD media.
Please forgive my naive perspective: it seems that with the features enabled by this patchset and a filesystem that is capable of issuing erase block commands, the wear-leveling on SD media will be improved -- much like with CF TRIM commands. Do you also think that is the case? I would be very interested in hearing your expert opinion on this.
I am sorry but I don't know. Wear-levelling in cards tends to be kept secret by the manufacturers. However, it is not clear to me that cards
bother to record whether or not anything has been erased. For example,
erase a card twice - it takes the same amount of time the second time as the first time, whereas if the card knew it was already erased, why wasn't the second time much quicker?
Quoted 29 lines
I have a couple comments regarding mostly the SD support introduced in this patch. Patches 2..5 of 5 seem fine to me but I'm not sure I'm qualified to add acks or reviewed-by's.
Quoted 23 lines
drivers/mmc/core/core.c +23
-0+int mmc_erase (struct mmc_card *card,unsigned int from,unsigned int nr, +unsigned int arg) +{ +unsigned int rem, to = from + nr; + +if (!(card->host->caps &MMC_CAP_ERASE ) || + !(card->csd.cmdclass &CCC_ERASE )) +return -EOPNOTSUPP ; + +if (!card->erase_size) +return -EOPNOTSUPP ; + +if (mmc_card_sd (card) && arg !=MMC_ERASE_ARG ) +return -EOPNOTSUPP ; + +if ((arg &MMC_SECURE_ARGS ) && + !(card->ext_csd.sec_feature_support &EXT_CSD_SEC_ER_EN )) +return -EOPNOTSUPP ; + +if ((arg &MMC_TRIM_ARGS ) && + !(card->ext_csd.sec_feature_support &EXT_CSD_SEC_GB_CL_EN )) +return -EOPNOTSUPP ; +
Quoted 10 lines
drivers/mmc/core/core.c void mmc_detect_change(struct mmc_host *host, unsigned long delay) · line 1379
Quoted 7 lines
drivers/mmc/core/core.c +7
-0+int mmc_can_trim (struct mmc_card *card) +{ +if (card->ext_csd.sec_feature_support &EXT_CSD_SEC_GB_CL_EN ) +return 1 ; +return 0 ; +} +EXPORT_SYMBOL (mmc_can_trim);It looks like
mmc_can_trim(card)would return true whenmmc_card_sd(card)is true;
It will return false for SD. card->ext_csd.sec_feature_support is only used by MMC.
Quoted 13 lines
but the
mmc_erasefunction will return-EOPNOTSUPPin such a case. I think that this results in themmc_blk_issue_discard_rqfunction (from 2/5) also returning-EOPNOTSUPPwhenevermmc_card_sd(card)is true:Quoted 1 line
From 2/5:
(quoted diff) +6
-0+ if (mmc_can_trim(card)) + arg = MMC_TRIM_ARG; + else + arg = MMC_ERASE_ARG; + + err = mmc_erase(card, from, nr, arg);
Quoted 4 lines
Also, there is some duplication between the
sec_feature_supportchecking inmmc_eraseand in the mmc_can* functions; Ifmmc_erasecould call the mmc_can_* functions then the the bit-checking logic could be centralized.
I can do that if there is a V5 but I do not think it is worth rolling another set of patches just for that.
Quoted 11 lines
drivers/mmc/core/sd.c static int mmc_decode_scr(struct mmc_card *card) · line 204
Quoted 7 lines
/*
+ * Fetch and process SD Status register.
+ */drivers/mmc/core/sd.c +2
-0+static int mmc_read_ssr (struct mmc_card *card) +{It looks like the conventional function prefix for SD-specific functions in the rest of this file is
mmc_sd_; 'mmc_read_ssr' -> 'mmc_sd_read_ssr' or -> 'mmc_read_sd_sr' perhaps?
Well there is also mmc_decode_*, and mmc_read_switch so the other functions that do smilar things also do not follow that convention.
Quoted 4 lines
Quoted 2 lines
+ ssr =
kmalloc(64, GFP_KERNEL);Why '64' instead of '
sizeof(*ssr)' ?
sizeof(*ssr) is 4
Quoted 8 lines
Best Regards,
Ben Gardiner---
Nanometrics Inc.
http://www.nanometrics.ca
Ben Gardiner
Reviewed-byRe: [PATCH V4 1/5] mmc: Add erase, secure erase, trim and secure trim operations
Quoted 20 lines · Adrian Hunter
Quoted 10 lines · Ben Gardiner
Quoted 6 lines · Adrian Hunter
From
7f01ad3c4be6ec09318176db12db66f353b526e0Mon Sep 17 00:00:00 2001SD/MMC cards tend to support an erase operation. In addition, eMMC v4.4 cards can support secure erase, trim and secure trim operations that are all variants of the basic erase command.
Quoted 8 lines
This is great. I am interested primarily in SD media.
Please forgive my naive perspective: it seems that with the features enabled by this patchset and a filesystem that is capable of issuing erase block commands, the wear-leveling on SD media will be improved -- much like with CF TRIM commands. Do you also think that is the case? I would be very interested in hearing your expert opinion on this.
Quoted 6 lines
I am sorry but I don't know. Wear-levelling in cards tends to be kept secret by the manufacturers. However, it is not clear to me that cards bother to record whether or not anything has been erased. For example, erase a card twice - it takes the same amount of time the second time as the first time, whereas if the card knew it was already erased, why wasn't the second time much quicker?
No worries. I'm happy to hear your opinion anyways.
Interesting observation re: erase time of cards, I assume that is "erase" as in the SD erase operations as proposed in this patch as opposed to erase as in 'mkfs'.
Quoted 40 lines
Quoted 29 lines
I have a couple comments regarding mostly the SD support introduced in this patch. Patches 2..5 of 5 seem fine to me but I'm not sure I'm qualified to add acks or reviewed-by's.
Quoted 23 lines
drivers/mmc/core/core.c +23
-0+int mmc_erase (struct mmc_card *card,unsigned int from,unsigned int nr, + unsigned int arg) +{ + unsigned int rem, to = from + nr; + + if (!(card->host->caps & MMC_CAP_ERASE) || + !(card->csd.cmdclass & CCC_ERASE)) + return -EOPNOTSUPP; + + if (!card->erase_size) + return -EOPNOTSUPP; + + if (mmc_card_sd(card) && arg != MMC_ERASE_ARG) + return -EOPNOTSUPP; + + if ((arg & MMC_SECURE_ARGS) && + !(card->ext_csd.sec_feature_support & EXT_CSD_SEC_ER_EN)) + return -EOPNOTSUPP; + + if ((arg & MMC_TRIM_ARGS) && + !(card->ext_csd.sec_feature_support & EXT_CSD_SEC_GB_CL_EN)) + return -EOPNOTSUPP; +Quoted 10 lines
drivers/mmc/core/core.c void mmc_detect_change(struct mmc_host *host, unsigned long delay) · line 1379
Quoted 7 lines
drivers/mmc/core/core.c +7
-0+int mmc_can_trim (struct mmc_card *card) +{ + if (card->ext_csd.sec_feature_support & EXT_CSD_SEC_GB_CL_EN) + return 1; + return 0; +} +EXPORT_SYMBOL (mmc_can_trim);It looks like
mmc_can_trim(card)would return true whenmmc_card_sd(card)is true;
Quoted 2 lines
It will return false for SD. card->ext_csd.sec_feature_support is only used by MMC.
Makes sense now, thanks.
Quoted 10 lines
Quoted 9 lines
drivers/mmc/core/sd.c static int mmc_decode_scr(struct mmc_card *card) · line 204
Quoted 5 lines
/*
+ * Fetch and process SD Status register.
+ */drivers/mmc/core/sd.c +2
-0+static int mmc_read_ssr (struct mmc_card *card) +{It looks like the conventional function prefix for SD-specific functions in the rest of this file is
mmc_sd_; 'mmc_read_ssr' -> 'mmc_sd_read_ssr' or -> 'mmc_read_sd_sr' perhaps?
Quoted 2 lines
Well there is also mmc_decode_*, and
mmc_read_switchso the other functions that do smilar things also do not follow that convention.
Good point.
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
+ ssr =
kmalloc(64, GFP_KERNEL);Why '64' instead of '
sizeof(*ssr)' ?
sizeof(*ssr)is 4
Right -- my mistake :)
I guess I was _thinking_ 16*sizeof(*ssr) or SSR_SIZE*sizeof(*ssr) instead of a magic number '64'. I see now that this wouldn't be the only kmalloc of a magic number in sd.c -- so I'll stop being so picky.
---
Ben Gardiner
Nanometrics Inc.
http://www.nanometrics.ca
PATCH v4 2/5 mmc_block: Add discard support
In reply to Adrian HunterQuoted 1 line
From
3f40c236b15902aa878640d89bc11dd0bc4511fcMon Sep 17 00:00:00 2001
From: Adrian Hunter <[email protected]>
Date: Thu, 3 Jun 2010 10:47:12 +0300
Subject: [PATCH 2/5] mmc_block: Add discard support
Enable MMC to service discard requests. In the case of SD and MMC cards that do not support trim, discards become erases. In the case of cards (MMC) that only allow erases in multiples of erase group size, round to the nearest completely discarded erase group.
--- drivers/mmc/card/block.c | 42 +++++++++++++++++++++++++++++++++++++++++- drivers/mmc/card/queue.c | 16 ++++++++++++++-- 2 files changed, 55 insertions(+), 3 deletions(-)
drivers/mmc/card/block.c +41 -1
@@ -242,7 +242,40 @@ static u32 get_card_status(struct mmc_card *card, struct request *req)return cmd.resp[0 ]; } -static int mmc_blk_issue_rq (struct mmc_queue *mq,struct request *req) +static int mmc_blk_issue_discard_rq (struct mmc_queue *mq,struct request *req) +{ +struct mmc_blk_data *md = mq->data; +struct mmc_card *card = md->queue.card; +unsigned int from, nr, arg; +int err =0 ; + +mmc_claim_host (card->host); + +if (!mmc_can_erase (card)) { + err = -EOPNOTSUPP ; + goto out; + } + + from =blk_rq_pos (req); + nr =blk_rq_sectors (req); + +if (mmc_can_trim (card)) + arg =MMC_TRIM_ARG ; +else + arg =MMC_ERASE_ARG ; + + err =mmc_erase (card, from, nr, arg); +out: +spin_lock_irq (&md->lock); +__blk_end_request (req, err,blk_rq_bytes (req)); +spin_unlock_irq (&md->lock); + +mmc_release_host (card->host); + +return err ?0 :1 ; +} + +static int mmc_blk_issue_rw_rq (struct mmc_queue *mq,struct request *req) {struct mmc_blk_data *md = mq->data;struct mmc_card *card = md->queue.card;
@@ -470,6 +503,13 @@ static int mmc_blk_issue_rq(struct mmc_queue *mq, struct request *req)return 0 ; } +static int mmc_blk_issue_rq (struct mmc_queue *mq,struct request *req) +{ +if (req->cmd_flags &REQ_DISCARD ) +return mmc_blk_issue_discard_rq (mq, req); +else +return mmc_blk_issue_rw_rq (mq, req); +}static inline int mmc_blk_readonly (struct mmc_card *card) {
drivers/mmc/card/queue.c +14 -2
@@ -30,9 +30,9 @@static int mmc_prep_request (struct request_queue *q,struct request *req) {/* -* We only like normal block requests. +* We only like normal block requests and discards. */ -if (req->cmd_type !=REQ_TYPE_FS ) { +if (req->cmd_type !=REQ_TYPE_FS && !(req->cmd_flags &REQ_DISCARD )) {blk_dump_rq_flags (req,"MMC bad request" );return BLKPREP_KILL ; }
@@ -130,6 +130,18 @@ int mmc_init_queue(struct mmc_queue *mq, struct mmc_card *card, spinlock_t *lockblk_queue_prep_rq (mq->queue, mmc_prep_request);blk_queue_ordered (mq->queue,QUEUE_ORDERED_DRAIN ,NULL );queue_flag_set_unlocked (QUEUE_FLAG_NONROT , mq->queue); +if (mmc_can_erase (card)) { +queue_flag_set_unlocked (QUEUE_FLAG_DISCARD , mq->queue); + mq->queue->limits.max_discard_sectors =UINT_MAX ; +if (card->erased_byte ==0 ) + mq->queue->limits.discard_zeroes_data =1 ; +if (!mmc_can_trim (card) &&is_power_of_2 (card->erase_size)) { + mq->queue->limits.discard_granularity = + card->erase_size <<9 ; + mq->queue->limits.discard_alignment = + card->erase_size <<9 ; + } + }#ifdef CONFIG_MMC_BLOCK_BOUNCE if (host->max_hw_segs ==1 ) {
Signature · 1 line
1.6.3.3
PATCH v4 3/5 omap_hsmmc: Add erase capability
In reply to Adrian HunterQuoted 1 line
From
db31a11109e7f0c89a7a9ca70ad03beff354aa8eMon Sep 17 00:00:00 2001
From: Adrian Hunter <[email protected]>
Date: Tue, 18 May 2010 17:33:13 +0300
Subject: [PATCH 3/5] omap_hsmmc: Add erase capability
Disable the data (busy) timeout for erases and set the MMC_CAP_ERASE capability.
--- drivers/mmc/host/omap_hsmmc.c | 13 ++++++++++--- 1 files changed, 10 insertions(+), 3 deletions(-)
drivers/mmc/host/omap_hsmmc.c +10 -3
@@ -28,6 +28,7 @@#include <linux/clk.h> #include <linux/mmc/host.h> #include <linux/mmc/core.h> +#include <linux/mmc/mmc.h> #include <linux/io.h> #include <linux/semaphore.h> #include <linux/gpio.h>
@@ -78,6 +79,7 @@#define INT_EN_MASK 0x307F0033#define BWR_ENABLE (1 << 4)#define BRR_ENABLE (1 << 5) +#define DTO_ENABLE (1 << 20)#define INIT_STREAM (1 << 1)#define DP_SELECT (1 << 21)#define DDIR (1 << 4)
@@ -523,7 +525,8 @@ static void omap_hsmmc_stop_clock(struct omap_hsmmc_host *host)dev_dbg (mmc_dev (host->mmc),"MMC Clock is not stoped\n" ); } -static void omap_hsmmc_enable_irq (struct omap_hsmmc_host *host) +static void omap_hsmmc_enable_irq (struct omap_hsmmc_host *host, +struct mmc_command *cmd) {unsigned int irq_mask;
@@ -532,6 +535,10 @@ static void omap_hsmmc_enable_irq(struct omap_hsmmc_host *host)else irq_mask =INT_EN_MASK ; +/* Disable timeout for erases */ +if (cmd->opcode ==MMC_ERASE ) + irq_mask &= ~DTO_ENABLE ; +OMAP_HSMMC_WRITE (host->base,STAT ,STAT_CLEAR );OMAP_HSMMC_WRITE (host->base,ISE , irq_mask);OMAP_HSMMC_WRITE (host->base,IE , irq_mask);
@@ -782,7 +789,7 @@ omap_hsmmc_start_command(struct omap_hsmmc_host *host, struct mmc_command *cmd, mmc_hostname(host->mmc), cmd->opcode, cmd->arg); host->cmd = cmd; -omap_hsmmc_enable_irq (host); +omap_hsmmc_enable_irq (host, cmd); host->response_busy =0 ;if (cmd->flags &MMC_RSP_PRESENT ) {
@@ -2094,7 +2101,7 @@ static int __init omap_hsmmc_probe(struct platform_device *pdev) mmc->max_seg_size = mmc->max_req_size; mmc->caps |=MMC_CAP_MMC_HIGHSPEED |MMC_CAP_SD_HIGHSPEED | -MMC_CAP_WAIT_WHILE_BUSY ; +MMC_CAP_WAIT_WHILE_BUSY |MMC_CAP_ERASE ;switch (mmc_slot (host).wires) {case 8 :
Signature · 1 line
1.6.3.3
PATCH v4 4/5 block: Add secure discard
In reply to Adrian HunterQuoted 1 line
From
1cdd5b576bfafcd53857ed4d37830446e96e8206Mon Sep 17 00:00:00 2001
From: Adrian Hunter <[email protected]>
Date: Wed, 23 Jun 2010 15:41:38 +0300
Subject: [PATCH 4/5] block: Add secure discard
Secure discard is the same as discard except that all copies of the discarded sectors (perhaps created by garbage collection) must also be erased.
--- block/blk-core.c | 5 ++++- block/blk-lib.c | 6 ++++++ block/compat_ioctl.c | 1 + block/elevator.c | 6 ++++++ block/ioctl.c | 15 ++++++++++----- include/linux/bio.h | 2 ++ include/linux/blkdev.h | 7 ++++++- include/linux/fs.h | 2 ++ kernel/trace/blktrace.c | 8 ++++++++ 9 files changed, 45 insertions(+), 7 deletions(-)
block/blk-core.c +4 -1
@@ -1513,7 +1513,10 @@ static inline void __generic_make_request(struct bio *bio)if (bio_check_eod (bio, nr_sectors)) goto end_io; -if ((bio->bi_rw &REQ_DISCARD ) && !blk_queue_discard (q)) { +if ((bio->bi_rw &REQ_DISCARD ) && + (!blk_queue_discard (q) || + ((bio->bi_rw &REQ_SECURE ) && + !blk_queue_secdiscard (q)))) { err = -EOPNOTSUPP ; goto end_io; }
block/blk-lib.c +6 -0
@@ -50,6 +50,12 @@ int blkdev_issue_discard(struct block_device *bdev, sector_t sector,if (!blk_queue_discard (q))return -EOPNOTSUPP ; +if (flags &BLKDEV_IFL_SECURE ) { +if (!blk_queue_secdiscard (q)) +return -EOPNOTSUPP ; + type |=DISCARD_SECURE ; + } +while (nr_sects && !ret) {unsigned int max_discard_sectors =min (q->limits.max_discard_sectors,UINT_MAX >>9 );
block/compat_ioctl.c +1 -0
@@ -753,6 +753,7 @@ long compat_blkdev_ioctl(struct file *file, unsigned cmd, unsigned long arg)case BLKFLSBUF :case BLKROSET :case BLKDISCARD : +case BLKSECDISCARD :/* * the ones below are implemented in blkdev_locked_ioctl, * but we call blkdev_ioctl, which gets the lock for us
block/elevator.c +6 -0
@@ -83,6 +83,12 @@ int elv_rq_merge_ok(struct request *rq, struct bio *bio)return 0 ;/* +* Don't merge discard requests and secure discard requests +*/ +if ((bio->bi_rw &REQ_SECURE ) != (rq->bio->bi_rw &REQ_SECURE )) +return 0 ; + +/* * different data direction or already started, don't merge */ if (bio_data_dir (bio) !=rq_data_dir (rq))
block/ioctl.c +10 -5
@@ -114,8 +114,10 @@ static int blkdev_reread_part(struct block_device *bdev) }static int blk_ioctl_discard (struct block_device *bdev,uint64_t start, -uint64_t len) +uint64_t len,int secure) { +unsigned long flags =BLKDEV_IFL_WAIT ; +if (start &511 )return -EINVAL ;if (len &511 )
@@ -125,8 +127,9 @@ static int blk_ioctl_discard(struct block_device *bdev, uint64_t start,if (start + len > (bdev->bd_inode->i_size >>9 ))return -EINVAL ; -return blkdev_issue_discard (bdev, start, len,GFP_KERNEL , -BLKDEV_IFL_WAIT ); +if (secure) + flags |=BLKDEV_IFL_SECURE ; +return blkdev_issue_discard (bdev, start, len,GFP_KERNEL , flags); }static int put_ushort (unsigned long arg,unsigned short val)
@@ -226,7 +229,8 @@ int blkdev_ioctl(struct block_device *bdev, fmode_t mode, unsigned cmd,unlock_kernel ();return 0 ; -case BLKDISCARD : { +case BLKDISCARD : +case BLKSECDISCARD : {uint64_t range[2 ];if (!(mode &FMODE_WRITE ))
@@ -235,7 +239,8 @@ int blkdev_ioctl(struct block_device *bdev, fmode_t mode, unsigned cmd,if (copy_from_user (range, (void __user *)arg,sizeof (range)))return -EFAULT ; -return blk_ioctl_discard (bdev, range[0 ], range[1 ]); +return blk_ioctl_discard (bdev, range[0 ], range[1 ], + cmd ==BLKSECDISCARD ); }case HDIO_GETGEO : {
include/linux/bio.h +2 -0
@@ -176,6 +176,7 @@ enum rq_flag_bits { __REQ_INTEGRITY,/* integrity metadata has been remapped */ __REQ_IO_STAT,/* account I/O stat */ __REQ_MIXED_MERGE,/* merge of different types, fail separately */ + __REQ_SECURE,/* secure discard (used with __REQ_DISCARD) */ __REQ_NR_BITS, /* stops here */ };
@@ -215,6 +216,7 @@ enum rq_flag_bits {#define REQ_INTEGRITY (1 << __REQ_INTEGRITY)#define REQ_IO_STAT (1 << __REQ_IO_STAT)#define REQ_MIXED_MERGE (1 << __REQ_MIXED_MERGE) +#define REQ_SECURE (1 << __REQ_SECURE)/* * upper 16 bits of bi_rw define the io priority of this bio
include/linux/blkdev.h +6 -1
@@ -404,6 +404,7 @@ struct request_queue#define QUEUE_FLAG_DISCARD 16/* supports DISCARD */ #define QUEUE_FLAG_NOXMERGES 17/* No extended merges */ #define QUEUE_FLAG_ADD_RANDOM 18/* Contributes to random pool */ +#define QUEUE_FLAG_SECDISCARD 19/* supports SECDISCARD */ #define QUEUE_FLAG_DEFAULT ((1 << QUEUE_FLAG_IO_STAT) | \ (1 << QUEUE_FLAG_CLUSTER) | \
@@ -539,6 +540,8 @@ enum {#define blk_queue_stackable (q) \ test_bit(QUEUE_FLAG_STACKABLE, &(q)->queue_flags)#define blk_queue_discard (q) test_bit(QUEUE_FLAG_DISCARD, &(q)->queue_flags) +#define blk_queue_secdiscard (q) (blk_queue_discard(q) && \ + test_bit(QUEUE_FLAG_SECDISCARD, &(q)->queue_flags))#define blk_noretry_request (rq) \ ((rq)->cmd_flags & (REQ_FAILFAST_DEV|REQ_FAILFAST_TRANSPORT| \
@@ -931,10 +934,12 @@ static inline struct request *blk_map_queue_find_tag(struct blk_queue_tag *bqt, }enum {BLKDEV_WAIT ,/* wait for completion */ -BLKDEV_BARRIER ,/*issue request with barrier */ +BLKDEV_BARRIER ,/* issue request with barrier */ +BLKDEV_SECURE ,/* secure discard */ };#define BLKDEV_IFL_WAIT (1 << BLKDEV_WAIT)#define BLKDEV_IFL_BARRIER (1 << BLKDEV_BARRIER) +#define BLKDEV_IFL_SECURE (1 << BLKDEV_SECURE)extern int blkdev_issue_flush (struct block_device *,gfp_t ,sector_t *,unsigned long ); extern int blkdev_issue_discard(struct block_device *bdev, sector_t sector,
include/linux/fs.h +2 -0
@@ -176,6 +176,7 @@ struct inodes_stat_t {*/ #define DISCARD_NOBARRIER (WRITE | REQ_DISCARD)#define DISCARD_BARRIER (WRITE | REQ_DISCARD | REQ_HARDBARRIER) +#define DISCARD_SECURE (DISCARD_NOBARRIER | REQ_SECURE)#define SEL_IN 1#define SEL_OUT 2
@@ -318,6 +319,7 @@ struct inodes_stat_t {#define BLKALIGNOFF _IO(0x12,122)#define BLKPBSZGET _IO(0x12,123)#define BLKDISCARDZEROES _IO(0x12,124) +#define BLKSECDISCARD _IO(0x12,125)#define BMAP_IOCTL 1/* obsolete - kept for compatibility */ #define FIBMAP _IO(0x00,1)/* bmap access */
kernel/trace/blktrace.c +8 -0
@@ -667,6 +667,9 @@ static void blk_add_trace_rq(struct request_queue *q, struct request *rq,if (rq->cmd_flags &REQ_DISCARD ) rw |=REQ_DISCARD ; +if (rq->cmd_flags &REQ_SECURE ) + rw |=REQ_SECURE ; +if (rq->cmd_type ==REQ_TYPE_BLOCK_PC ) { what |=BLK_TC_ACT (BLK_TC_PC ); __blk_add_trace(bt, 0, blk_rq_bytes(rq), rw,
@@ -1773,6 +1776,8 @@ void blk_fill_rwbs(char *rwbs, u32 rw, int bytes) rwbs[i++] ='S' ;if (rw &REQ_META ) rwbs[i++] ='M' ; +if (rw &REQ_SECURE ) + rwbs[i++] ='E' ; rwbs[i] ='\0' ; }
@@ -1785,6 +1790,9 @@ void blk_fill_rwbs_rq(char *rwbs, struct request *rq)if (rq->cmd_flags &REQ_DISCARD ) rw |=REQ_DISCARD ; +if (rq->cmd_flags &REQ_SECURE ) + rw |=REQ_SECURE ; + bytes =blk_rq_bytes (rq);blk_fill_rwbs (rwbs, rw, bytes);
Signature · 1 line
1.6.3.3
Re: [PATCH V4 4/5] block: Add secure discard
Quoted 10 lines · Hunter Adrian (Nokia-MS/Helsinki)
Quoted 1 line
From
1cdd5b576bfafcd53857ed4d37830446e96e8206Mon Sep 17 00:00:00 2001From: Adrian Hunter <[email protected]>
Date: Wed, 23 Jun 2010 15:41:38 +0300
Subject: [PATCH 4/5] block: Add secure discardSecure discard is the same as discard except that all copies of the discarded sectors (perhaps created by garbage collection) must also be erased.
Signed-off-by Adrian Hunter <[email protected]>
Christoph will you comment on this patch? Is it doing what you asked?
Quoted 230 lines
--- block/blk-core.c | 5 ++++- block/blk-lib.c | 6 ++++++ block/compat_ioctl.c | 1 + block/elevator.c | 6 ++++++ block/ioctl.c | 15 ++++++++++----- include/linux/bio.h | 2 ++ include/linux/blkdev.h | 7 ++++++- include/linux/fs.h | 2 ++ kernel/trace/blktrace.c | 8 ++++++++ 9 files changed, 45 insertions(+), 7 deletions(-)block/blk-core.c +4
-1@@ -1513,7 +1513,10 @@ static inline void __generic_make_request(struct bio *bio)if (bio_check_eod (bio, nr_sectors)) goto end_io; -if ((bio->bi_rw &REQ_DISCARD ) && !blk_queue_discard (q)) { +if ((bio->bi_rw &REQ_DISCARD ) && + (!blk_queue_discard (q) || + ((bio->bi_rw &REQ_SECURE ) && + !blk_queue_secdiscard (q)))) { err = -EOPNOTSUPP ; goto end_io; }block/blk-lib.c +6
-0@@ -50,6 +50,12 @@ int blkdev_issue_discard(struct block_device *bdev, sector_t sector,if (!blk_queue_discard (q))return -EOPNOTSUPP ; +if (flags &BLKDEV_IFL_SECURE ) { +if (!blk_queue_secdiscard (q)) +return -EOPNOTSUPP ; + type |=DISCARD_SECURE ; + } +while (nr_sects && !ret) {unsigned int max_discard_sectors =min (q->limits.max_discard_sectors,UINT_MAX >>9 );block/compat_ioctl.c +1
-0@@ -753,6 +753,7 @@ long compat_blkdev_ioctl(struct file *file, unsigned cmd, unsigned long arg)case BLKFLSBUF :case BLKROSET :case BLKDISCARD : +case BLKSECDISCARD :/* * the ones below are implemented in blkdev_locked_ioctl, * but we call blkdev_ioctl, which gets the lock for us block/elevator.c +6
-0@@ -83,6 +83,12 @@ int elv_rq_merge_ok(struct request *rq, struct bio *bio)return 0 ;/* +* Don't merge discard requests and secure discard requests +*/ +if ((bio->bi_rw &REQ_SECURE ) != (rq->bio->bi_rw &REQ_SECURE )) +return 0 ; + +/* * different data direction or already started, don't merge */ if (bio_data_dir (bio) !=rq_data_dir (rq))block/ioctl.c +10
-5@@ -114,8 +114,10 @@ static int blkdev_reread_part(struct block_device *bdev) }static int blk_ioctl_discard (struct block_device *bdev,uint64_t start, -uint64_t len) +uint64_t len,int secure) { +unsigned long flags =BLKDEV_IFL_WAIT ; +if (start &511 )return -EINVAL ;if (len &511 )@@ -125,8 +127,9 @@ static int blk_ioctl_discard(struct block_device *bdev, uint64_t start,if (start + len > (bdev->bd_inode->i_size >>9 ))return -EINVAL ; -return blkdev_issue_discard (bdev, start, len,GFP_KERNEL , -BLKDEV_IFL_WAIT ); +if (secure) + flags |=BLKDEV_IFL_SECURE ; +return blkdev_issue_discard (bdev, start, len,GFP_KERNEL , flags); }static int put_ushort (unsigned long arg,unsigned short val)@@ -226,7 +229,8 @@ int blkdev_ioctl(struct block_device *bdev, fmode_t mode, unsigned cmd,unlock_kernel ();return 0 ; -case BLKDISCARD : { +case BLKDISCARD : +case BLKSECDISCARD : {uint64_t range[2 ];if (!(mode &FMODE_WRITE ))@@ -235,7 +239,8 @@ int blkdev_ioctl(struct block_device *bdev, fmode_t mode, unsigned cmd,if (copy_from_user (range, (void __user *)arg,sizeof (range)))return -EFAULT ; -return blk_ioctl_discard (bdev, range[0 ], range[1 ]); +return blk_ioctl_discard (bdev, range[0 ], range[1 ], + cmd ==BLKSECDISCARD ); }case HDIO_GETGEO : {include/linux/bio.h +2
-0@@ -176,6 +176,7 @@ enum rq_flag_bits { __REQ_INTEGRITY,/* integrity metadata has been remapped */ __REQ_IO_STAT,/* account I/O stat */ __REQ_MIXED_MERGE,/* merge of different types, fail separately */ + __REQ_SECURE,/* secure discard (used with __REQ_DISCARD) */ __REQ_NR_BITS, /* stops here */ };@@ -215,6 +216,7 @@ enum rq_flag_bits {#define REQ_INTEGRITY (1 << __REQ_INTEGRITY)#define REQ_IO_STAT (1 << __REQ_IO_STAT)#define REQ_MIXED_MERGE (1 << __REQ_MIXED_MERGE) +#define REQ_SECURE (1 << __REQ_SECURE)/* * upper 16 bits of bi_rw define the io priority of this bio include/linux/blkdev.h +6
-1@@ -404,6 +404,7 @@ struct request_queue#define QUEUE_FLAG_DISCARD 16/* supports DISCARD */ #define QUEUE_FLAG_NOXMERGES 17/* No extended merges */ #define QUEUE_FLAG_ADD_RANDOM 18/* Contributes to random pool */ +#define QUEUE_FLAG_SECDISCARD 19/* supports SECDISCARD */ #define QUEUE_FLAG_DEFAULT ((1 << QUEUE_FLAG_IO_STAT) | \ (1 << QUEUE_FLAG_CLUSTER) | \@@ -539,6 +540,8 @@ enum {#define blk_queue_stackable (q) \ test_bit(QUEUE_FLAG_STACKABLE, &(q)->queue_flags)#define blk_queue_discard (q) test_bit(QUEUE_FLAG_DISCARD, &(q)->queue_flags) +#define blk_queue_secdiscard (q) (blk_queue_discard(q) && \ + test_bit(QUEUE_FLAG_SECDISCARD, &(q)->queue_flags))#define blk_noretry_request (rq) \ ((rq)->cmd_flags & (REQ_FAILFAST_DEV|REQ_FAILFAST_TRANSPORT| \@@ -931,10 +934,12 @@ static inline struct request *blk_map_queue_find_tag(struct blk_queue_tag *bqt, }enum {BLKDEV_WAIT ,/* wait for completion */ -BLKDEV_BARRIER ,/*issue request with barrier */ +BLKDEV_BARRIER ,/* issue request with barrier */ +BLKDEV_SECURE ,/* secure discard */ };#define BLKDEV_IFL_WAIT (1 << BLKDEV_WAIT)#define BLKDEV_IFL_BARRIER (1 << BLKDEV_BARRIER) +#define BLKDEV_IFL_SECURE (1 << BLKDEV_SECURE)extern int blkdev_issue_flush (struct block_device *,gfp_t ,sector_t *,unsigned long ); extern int blkdev_issue_discard(struct block_device *bdev, sector_t sector,include/linux/fs.h +2
-0@@ -176,6 +176,7 @@ struct inodes_stat_t {*/ #define DISCARD_NOBARRIER (WRITE | REQ_DISCARD)#define DISCARD_BARRIER (WRITE | REQ_DISCARD | REQ_HARDBARRIER) +#define DISCARD_SECURE (DISCARD_NOBARRIER | REQ_SECURE)#define SEL_IN 1#define SEL_OUT 2@@ -318,6 +319,7 @@ struct inodes_stat_t {#define BLKALIGNOFF _IO(0x12,122)#define BLKPBSZGET _IO(0x12,123)#define BLKDISCARDZEROES _IO(0x12,124) +#define BLKSECDISCARD _IO(0x12,125)#define BMAP_IOCTL 1/* obsolete - kept for compatibility */ #define FIBMAP _IO(0x00,1)/* bmap access */ kernel/trace/blktrace.c +8
-0@@ -667,6 +667,9 @@ static void blk_add_trace_rq(struct request_queue *q, struct request *rq,if (rq->cmd_flags &REQ_DISCARD ) rw |=REQ_DISCARD ; +if (rq->cmd_flags &REQ_SECURE ) + rw |=REQ_SECURE ; +if (rq->cmd_type ==REQ_TYPE_BLOCK_PC ) { what |=BLK_TC_ACT (BLK_TC_PC ); __blk_add_trace(bt, 0, blk_rq_bytes(rq), rw,@@ -1773,6 +1776,8 @@ void blk_fill_rwbs(char *rwbs, u32 rw, int bytes) rwbs[i++] ='S' ;if (rw &REQ_META ) rwbs[i++] ='M' ; +if (rw &REQ_SECURE ) + rwbs[i++] ='E' ; rwbs[i] ='\0' ; }@@ -1785,6 +1790,9 @@ void blk_fill_rwbs_rq(char *rwbs, struct request *rq)if (rq->cmd_flags &REQ_DISCARD ) rw |=REQ_DISCARD ; +if (rq->cmd_flags &REQ_SECURE ) + rw |=REQ_SECURE ; + bytes =blk_rq_bytes (rq);blk_fill_rwbs (rwbs, rw, bytes);
Re: [PATCH V4 4/5] block: Add secure discard
The patches look good to me, but they'll need some work to apply against Jens' block tree.
PATCH 1/1 block: Add secure discard
Quoted 1 line
From
9ba7750fb96d9994e8715b14d8091c37b832b3e6Mon Sep 17 00:00:00 2001
From: Adrian Hunter <[email protected]>
Date: Wed, 23 Jun 2010 15:41:38 +0300
Subject: [PATCH] block: Add secure discard
Secure discard is the same as discard except that all copies of the discarded sectors (perhaps created by garbage collection) must also be erased.
---
Here is "[PATCH V4 4/5] block: Add secure discard" applied togit://git.kernel.dk/linux-2.6-block.git for-next.
If Jens takes this patch (originally 4th of 5), Andrew takes patches 1 to 3, and patch 5 waits for this one to propagate, then there will be no dependency problem.
block/blk-core.c | 5 ++++- block/blk-lib.c | 6 ++++++ block/compat_ioctl.c | 1 + block/elevator.c | 6 ++++++ block/ioctl.c | 15 ++++++++++----- include/linux/bio.h | 2 ++ include/linux/blkdev.h | 7 ++++++- include/linux/fs.h | 2 ++ kernel/trace/blktrace.c | 8 ++++++++ 9 files changed, 45 insertions(+), 7 deletions(-)
block/blk-core.c +0 -0
@@ -1514,7 +1514,10 @@ static inline void __generic_make_request(struct bio *bio)
if (bio_check_eod(bio, nr_sectors)) goto end_io;
- if ((bio->bi_rw & REQ_DISCARD) && !blk_queue_discard(q)) {
+ if ((bio->bi_rw & REQ_DISCARD) &&
+ (!blk_queue_discard(q) ||
+ ((bio->bi_rw & REQ_SECURE) &&
+ !blk_queue_secdiscard(q)))) {
err = -EOPNOTSUPP;
goto end_io;
}block/blk-lib.c +0 -0
@@ -50,6 +50,12 @@ int blkdev_issue_discard(struct block_device *bdev, sector_t sector,
if (!blk_queue_discard(q)) return -EOPNOTSUPP;
+ if (flags & BLKDEV_IFL_SECURE) {
+ if (!blk_queue_secdiscard(q))
+ return -EOPNOTSUPP;
+ type |= DISCARD_SECURE;
+ }
+
while (nr_sects && !ret) {
unsigned int max_discard_sectors =
min(q->limits.max_discard_sectors, UINT_MAX >> 9);block/compat_ioctl.c +0 -0
@@ -703,6 +703,7 @@ long compat_blkdev_ioctl(struct file *file, unsigned cmd, unsigned long arg)
case BLKFLSBUF:
case BLKROSET:
case BLKDISCARD:
+ case BLKSECDISCARD:
/*
* the ones below are implemented in blkdev_locked_ioctl,
* but we call blkdev_ioctl, which gets the lock for us
block/elevator.c +0 -0
@@ -83,6 +83,12 @@ int elv_rq_merge_ok(struct request *rq, struct bio *bio)
return 0; /*
+ * Don't merge discard requests and secure discard requests
+ */
+ if ((bio->bi_rw & REQ_SECURE) != (rq->bio->bi_rw & REQ_SECURE))
+ return 0;
+
+ /*
* different data direction or already started, don't merge */ if (bio_data_dir(bio) != rq_data_dir(rq))
block/ioctl.c +0 -0
@@ -114,8 +114,10 @@ static int blkdev_reread_part(struct block_device *bdev)
}
static int blk_ioctl_discard(struct block_device *bdev, uint64_t start,
- uint64_t len)
+ uint64_t len, int secure)
{
+ unsigned long flags = BLKDEV_IFL_WAIT;
+
if (start & 511) return -EINVAL; if (len & 511)
@@ -125,8 +127,9 @@ static int blk_ioctl_discard(struct block_device *bdev, uint64_t start,
if (start + len > (bdev->bd_inode->i_size >> 9)) return -EINVAL;
- return blkdev_issue_discard(bdev, start, len, GFP_KERNEL,
- BLKDEV_IFL_WAIT);
+ if (secure)
+ flags |= BLKDEV_IFL_SECURE;
+ return blkdev_issue_discard(bdev, start, len, GFP_KERNEL, flags);
}
static int put_ushort(unsigned long arg, unsigned short val)
@@ -213,7 +216,8 @@ int blkdev_ioctl(struct block_device *bdev, fmode_t mode, unsigned cmd,
set_device_ro(bdev, n); return 0;
- case BLKDISCARD: {
+ case BLKDISCARD:
+ case BLKSECDISCARD: {
uint64_t range[2];
if (!(mode & FMODE_WRITE))
@@ -222,7 +226,8 @@ int blkdev_ioctl(struct block_device *bdev, fmode_t mode, unsigned cmd,
if (copy_from_user(range, (void __user *)arg, sizeof(range)))
return -EFAULT;- return blk_ioctl_discard(bdev, range[0], range[1]);
+ return blk_ioctl_discard(bdev, range[0], range[1],
+ cmd == BLKSECDISCARD);
}
case HDIO_GETGEO: {include/linux/bio.h +0 -0
@@ -177,6 +177,7 @@ enum rq_flag_bits {
__REQ_FLUSH, /* request for cache flush */
__REQ_IO_STAT, /* account I/O stat */
__REQ_MIXED_MERGE, /* merge of different types, fail separately */
+ __REQ_SECURE, /* secure discard (used with __REQ_DISCARD) */
__REQ_NR_BITS, /* stops here */ };
@@ -217,6 +218,7 @@ enum rq_flag_bits {
#define REQ_FLUSH (1 << __REQ_FLUSH)
#define REQ_IO_STAT (1 << __REQ_IO_STAT)
#define REQ_MIXED_MERGE (1 << __REQ_MIXED_MERGE)
+#define REQ_SECURE (1 << __REQ_SECURE)
/*
* upper 16 bits of bi_rw define the io priority of this bio
include/linux/blkdev.h +0 -0
@@ -389,6 +389,7 @@ struct request_queue
#define QUEUE_FLAG_DISCARD 16 /* supports DISCARD */ #define QUEUE_FLAG_NOXMERGES 17 /* No extended merges */ #define QUEUE_FLAG_ADD_RANDOM 18 /* Contributes to random pool */
+#define QUEUE_FLAG_SECDISCARD 19 /* supports SECDISCARD */
#define QUEUE_FLAG_DEFAULT ((1 << QUEUE_FLAG_IO_STAT) | \
(1 << QUEUE_FLAG_CLUSTER) | \
@@ -524,6 +525,8 @@ enum {
#define blk_queue_stackable(q) \
test_bit(QUEUE_FLAG_STACKABLE, &(q)->queue_flags)#define blk_queue_discard(q) test_bit(QUEUE_FLAG_DISCARD, &(q)->queue_flags)
+#define blk_queue_secdiscard(q) (blk_queue_discard(q) && \
+ test_bit(QUEUE_FLAG_SECDISCARD, &(q)->queue_flags))
#define blk_noretry_request(rq) \ ((rq)->cmd_flags & (REQ_FAILFAST_DEV|REQ_FAILFAST_TRANSPORT| \
@@ -918,10 +921,12 @@ static inline struct request *blk_map_queue_find_tag(struct blk_queue_tag *bqt, }
enum{
BLKDEV_WAIT, /* wait for completion */
- BLKDEV_BARRIER, /*issue request with barrier */
+ BLKDEV_BARRIER, /* issue request with barrier */
+ BLKDEV_SECURE, /* secure discard */
};
#define BLKDEV_IFL_WAIT (1 << BLKDEV_WAIT)
#define BLKDEV_IFL_BARRIER (1 << BLKDEV_BARRIER)
+#define BLKDEV_IFL_SECURE (1 << BLKDEV_SECURE)
extern int blkdev_issue_flush(struct block_device *, gfp_t, sector_t *,
unsigned long);
extern int blkdev_issue_discard(struct block_device *bdev, sector_t sector,
include/linux/fs.h +0 -0
@@ -169,6 +169,7 @@ struct inodes_stat_t {*/
#define DISCARD_NOBARRIER (WRITE | REQ_DISCARD)
#define DISCARD_BARRIER (WRITE | REQ_DISCARD | REQ_HARDBARRIER)
+#define DISCARD_SECURE (DISCARD_NOBARRIER | REQ_SECURE)
#define SEL_IN 1
#define SEL_OUT 2
@@ -311,6 +312,7 @@ struct inodes_stat_t {
#define BLKALIGNOFF _IO(0x12,122)
#define BLKPBSZGET _IO(0x12,123)
#define BLKDISCARDZEROES _IO(0x12,124)
+#define BLKSECDISCARD _IO(0x12,125)
#define BMAP_IOCTL 1 /* obsolete - kept for compatibility */
#define FIBMAP _IO(0x00,1) /* bmap access */
kernel/trace/blktrace.c +0 -0
@@ -710,6 +710,9 @@ static void blk_add_trace_rq(struct request_queue *q, struct request *rq,
if (rq->cmd_flags & REQ_DISCARD) rw |= REQ_DISCARD;
+ if (rq->cmd_flags & REQ_SECURE)
+ rw |= REQ_SECURE;
+
if (rq->cmd_type == REQ_TYPE_BLOCK_PC) {
what |= BLK_TC_ACT(BLK_TC_PC);
__blk_add_trace(bt, 0, blk_rq_bytes(rq), rw,
@@ -1816,6 +1819,8 @@ void blk_fill_rwbs(char *rwbs, u32 rw, int bytes)
rwbs[i++] = 'S';
if (rw & REQ_META)
rwbs[i++] = 'M';+ if (rw & REQ_SECURE)
+ rwbs[i++] = 'E';
rwbs[i] = '\0'; } @@ -1828,6 +1833,9 @@ void blk_fill_rwbs_rq(char *rwbs, struct request *rq) if (rq->cmd_flags & REQ_DISCARD) rw |= REQ_DISCARD;
+ if (rq->cmd_flags & REQ_SECURE)
+ rw |= REQ_SECURE;
+
bytes = blk_rq_bytes(rq); blk_fill_rwbs(rwbs, rw, bytes);
Signature · 1 line
1.6.3.3
Re: [PATCH] block: Add secure discard
Quoted 14 lines · On Wed, 14 Jul 2010 13:50:39 +0300 Adrian Hunter <[email protected]>…
Quoted 1 line
From
9ba7750fb96d9994e8715b14d8091c37b832b3e6Mon Sep 17 00:00:00 2001From: Adrian Hunter <[email protected]>
Date: Wed, 23 Jun 2010 15:41:38 +0300
Subject: [PATCH] block: Add secure discardSecure discard is the same as discard except that all copies of the discarded sectors (perhaps created by garbage collection) must also be erased.
Signed-off-by Adrian Hunter <[email protected]>---
Quoted 6 lines
Here is "[PATCH V4 4/5] block: Add secure discard" applied to
git://git.kernel.dk/linux-2.6-block.gitfor-next.If Jens takes this patch (originally 4th of 5), Andrew takes patches 1 to 3, and patch 5 waits for this one to propagate, then there will be no dependency problem.
hm, complicated.
I merged all five into -mm. If Jens sends along some acks then I send all five along to Linus, nice and simple.
Jens Axboe
maintainerRe: [PATCH] block: Add secure discard
Quoted 20 lines · Andrew Morton
Quoted 17 lines · On Wed, 14 Jul 2010 13:50:39 +0300 Adrian Hunter <[email protected]>…
Quoted 1 line
From
9ba7750fb96d9994e8715b14d8091c37b832b3e6Mon Sep 17 00:00:00 2001From: Adrian Hunter <[email protected]>
Date: Wed, 23 Jun 2010 15:41:38 +0300
Subject: [PATCH] block: Add secure discardSecure discard is the same as discard except that all copies of the discarded sectors (perhaps created by garbage collection) must also be erased.
Signed-off-by Adrian Hunter <[email protected]>---
Here is "[PATCH V4 4/5] block: Add secure discard" applied to
git://git.kernel.dk/linux-2.6-block.gitfor-next.
Quoted 9 lines
Quoted 3 lines
If Jens takes this patch (originally 4th of 5), Andrew takes patches 1 to 3, and patch 5 waits for this one to propagate, then there will be no dependency problem.
hm, complicated.
I merged all five into -mm. If Jens sends along some acks then I send all five along to Linus, nice and simple.
I was about to pick them up, but yeah just adds my acks to the series and shove them off for the next series.
Signature · 1 line
Jens Axboe
PATCH v4 5/5 mmc_block: Add support for secure discard
In reply to Adrian HunterQuoted 1 line
From
548ec42c86a88092b92597ff2774691e5498974fMon Sep 17 00:00:00 2001
From: Adrian Hunter <[email protected]>
Date: Wed, 23 Jun 2010 15:55:50 +0300
Subject: [PATCH 5/5] mmc_block: Add support for secure discard
Secure discard is implemented by Secure Trim if the discard is unaligned or Secure Erase otherwise.
--- drivers/mmc/card/block.c | 46 +++++++++++++++++++++++++++++++++++++++++++--- drivers/mmc/card/queue.c | 3 +++ 2 files changed, 46 insertions(+), 3 deletions(-)
drivers/mmc/card/block.c +43 -3
@@ -275,6 +275,42 @@ out:return err ?0 :1 ; } +static int mmc_blk_issue_secdiscard_rq (struct mmc_queue *mq, +struct request *req) +{ +struct mmc_blk_data *md = mq->data; +struct mmc_card *card = md->queue.card; +unsigned int from, nr, arg; +int err =0 ; + +mmc_claim_host (card->host); + +if (!mmc_can_secure_erase_trim (card)) { + err = -EOPNOTSUPP ; + goto out; + } + + from =blk_rq_pos (req); + nr =blk_rq_sectors (req); + +if (mmc_can_trim (card) && !mmc_erase_group_aligned (card, from, nr)) + arg =MMC_SECURE_TRIM1_ARG ; +else + arg =MMC_SECURE_ERASE_ARG ; + + err =mmc_erase (card, from, nr, arg); +if (!err && arg ==MMC_SECURE_TRIM1_ARG ) + err =mmc_erase (card, from, nr,MMC_SECURE_TRIM2_ARG ); +out: +spin_lock_irq (&md->lock); +__blk_end_request (req, err,blk_rq_bytes (req)); +spin_unlock_irq (&md->lock); + +mmc_release_host (card->host); + +return err ?0 :1 ; +} +static int mmc_blk_issue_rw_rq (struct mmc_queue *mq,struct request *req) {struct mmc_blk_data *md = mq->data;
@@ -505,10 +541,14 @@ static int mmc_blk_issue_rw_rq(struct mmc_queue *mq, struct request *req)static int mmc_blk_issue_rq (struct mmc_queue *mq,struct request *req) { -if (req->cmd_flags &REQ_DISCARD ) -return mmc_blk_issue_discard_rq (mq, req); -else +if (req->cmd_flags &REQ_DISCARD ) { +if (req->cmd_flags &REQ_SECURE ) +return mmc_blk_issue_secdiscard_rq (mq, req); +else +return mmc_blk_issue_discard_rq (mq, req); + }else {return mmc_blk_issue_rw_rq (mq, req); + } }static inline int mmc_blk_readonly (struct mmc_card *card)
drivers/mmc/card/queue.c +3 -0
@@ -141,6 +141,9 @@ int mmc_init_queue(struct mmc_queue *mq, struct mmc_card *card, spinlock_t *lock mq->queue->limits.discard_alignment = card->erase_size <<9 ; } +if (mmc_can_secure_erase_trim (card)) +queue_flag_set_unlocked (QUEUE_FLAG_SECDISCARD , + mq->queue); }#ifdef CONFIG_MMC_BLOCK_BOUNCE
Signature · 1 line
1.6.3.3