ufs: core: Add support for qTimestamp attribute
Subsystems (2)
cover ufs: core: Add support for qTimestamp attribute
The new qTimestamp attribute was added to UFS 4.0 spec, in order to synchronize timestamp between device logs and the host. Due to this attribute, the attribute's max value was extended to 8 bytes. As a result, we need to adjust the definition of struct utp_upiu_query.
Arthur Simchaev (2):
include: uapi: scsi: Change utp_upiu_query struct
ufs: core: Providing Timestamp information to the device
drivers/ufs/core/ufs_bsg.c | 2 +- drivers/ufs/core/ufshcd.c | 62 +++++++++++++++++++++++++++++++--------- include/uapi/scsi/scsi_bsg_ufs.h | 17 +++++------ include/ufs/ufs.h | 1 + 4 files changed, 59 insertions(+), 23 deletions(-)
Signature · 1 line
2.7.4
PATCH 1/2 include: uapi: scsi: Change utp_upiu_query struct
In UFS 4.0 the attribute value was extended to 8 bytes. Therefore the current definition is incorrect. Change the struct fields to osf (Opcode Specific Field) in order define the struct generally. Remove redundant reserved field
--- drivers/ufs/core/ufs_bsg.c | 2 +- drivers/ufs/core/ufshcd.c | 24 ++++++++++++------------ include/uapi/scsi/scsi_bsg_ufs.h | 17 +++++++++-------- 3 files changed, 22 insertions(+), 21 deletions(-)
drivers/ufs/core/ufs_bsg.c +1 -1
@@ -16,7 +16,7 @@static int ufs_bsg_get_query_desc_size (struct ufs_hba *hba,int *desc_len,struct utp_upiu_query *qr) { -int desc_size =be16_to_cpu (qr->length); +int desc_size =be16_to_cpu (qr->osf5);if (desc_size <=0 )return -EINVAL ;
drivers/ufs/core/ufshcd.c +12 -12
@@ -80,7 +80,7 @@/* Maximum number of error handler retries before giving up */ #define MAX_ERR_HANDLER_RETRIES 5 -/* Expose the flag value from utp_upiu_query.value */ +/* Expose the flag value from utp_upiu_query.osf6 */ #define MASK_QUERY_UPIU_FLAG_LOC 0xFF/* Interrupt aggregation default timeout, unit: 40us */
@@ -2280,8 +2280,7 @@ int ufshcd_copy_query_response(struct ufs_hba *hba, struct ufshcd_lrb *lrbp)/* data segment length */ resp_len =be32_to_cpu (lrbp->ucd_rsp_ptr->header.dword_2) &MASK_QUERY_DATA_SEG_LEN ; - buf_len =be16_to_cpu ( - hba->dev_cmd.query.request.upiu_req.length); + buf_len =be16_to_cpu (hba->dev_cmd.query.request.upiu_req.osf5);if (likely (buf_len >= resp_len)) {memcpy (hba->dev_cmd.query.descriptor, descp, resp_len); }else {
@@ -2681,7 +2680,7 @@ static void ufshcd_prepare_utp_query_req_upiu(struct ufs_hba *hba, {struct utp_upiu_req *ucd_req_ptr = lrbp->ucd_req_ptr;struct ufs_query *query = &hba->dev_cmd.query; -u16 len =be16_to_cpu (query->request.upiu_req.length); +u16 len;/* Query request header */ ucd_req_ptr->header.dword_0 = UPIU_HEADER_DWORD(
@@ -2691,12 +2690,13 @@ static void ufshcd_prepare_utp_query_req_upiu(struct ufs_hba *hba, 0, query->request.query_func, 0, 0);/* Data segment length only need for WRITE_DESC */ -if (query->request.upiu_req.opcode ==UPIU_QUERY_OPCODE_WRITE_DESC ) +if (query->request.upiu_req.opcode ==UPIU_QUERY_OPCODE_WRITE_DESC ) { + len =be16_to_cpu (query->request.upiu_req.osf5); ucd_req_ptr->header.dword_2 =UPIU_HEADER_DWORD (0 ,0 , (len >>8 ), (u8 )len); -else + }else { ucd_req_ptr->header.dword_2 =0 ; - + }/* Copy the Query Request buffer as is */ memcpy (&ucd_req_ptr->qr, &query->request.upiu_req,QUERY_OSF_SIZE );
@@ -3287,7 +3287,7 @@ int ufshcd_query_flag(struct ufs_hba *hba, enum query_opcode opcode, }if (flag_res) - *flag_res = (be32_to_cpu (response->upiu_res.value) & + *flag_res = (be32_to_cpu (response->upiu_res.osf6) &MASK_QUERY_UPIU_FLAG_LOC ) &0x1 ; out_unlock:
@@ -3331,7 +3331,7 @@ int ufshcd_query_attr(struct ufs_hba *hba, enum query_opcode opcode,switch (opcode) {case UPIU_QUERY_OPCODE_WRITE_ATTR : request->query_func =UPIU_QUERY_FUNC_STANDARD_WRITE_REQUEST ; - request->upiu_req.value =cpu_to_be32 (*attr_val); + request->upiu_req.osf6 =cpu_to_be32 (*attr_val);break ;case UPIU_QUERY_OPCODE_READ_ATTR : request->query_func =UPIU_QUERY_FUNC_STANDARD_READ_REQUEST ;
@@ -3351,7 +3351,7 @@ int ufshcd_query_attr(struct ufs_hba *hba, enum query_opcode opcode, goto out_unlock; } - *attr_val =be32_to_cpu (response->upiu_res.value); + *attr_val =be32_to_cpu (response->upiu_res.osf6); out_unlock:mutex_unlock (&hba->dev_cmd.lock);
@@ -3424,7 +3424,7 @@ static int __ufshcd_query_descriptor(struct ufs_hba *hba,ufshcd_init_query (hba, &request, &response, opcode, idn, index, selector); hba->dev_cmd.query.descriptor = desc_buf; - request->upiu_req.length =cpu_to_be16 (*buf_len); + request->upiu_req.osf5 =cpu_to_be16 (*buf_len);switch (opcode) {case UPIU_QUERY_OPCODE_WRITE_DESC :
@@ -3449,7 +3449,7 @@ static int __ufshcd_query_descriptor(struct ufs_hba *hba, goto out_unlock; } - *buf_len =be16_to_cpu (response->upiu_res.length); + *buf_len =be16_to_cpu (response->upiu_res.osf5); out_unlock: hba->dev_cmd.query.descriptor =NULL ;
include/uapi/scsi/scsi_bsg_ufs.h +9 -8
@@ -54,20 +54,21 @@ struct utp_upiu_header {* @idn: a value that indicates the particular type of data B-1 * @index: Index to further identify data B-2 * @selector: Index to further identify data B-3 -* @reserved_osf: spec reserved field B-4,5 -* @length: number of descriptor bytes to read/write B-6,7 -* @value: Attribute value to be written DW-5 -* @reserved: spec reserved DW-6,7 +* @osf4: spec field B-5 +* @osf5: spec field B 6,7 +* @osf6: spec field DW 8,9 +* @osf7: spec field DW 10,11 */ struct utp_upiu_query {__u8 opcode;__u8 idn;__u8 index;__u8 selector; -__be16 reserved_osf; -__be16 length; -__be32 value; -__be32 reserved[2 ]; +__u8 osf3; +__u8 osf4; +__be16 osf5; +__be32 osf6; +__be32 osf7; };/**
Signature · 1 line
2.7.4
Bart Van Assche
reviewerRe: [PATCH 1/2] include: uapi: scsi: Change utp_upiu_query struct
Quoted 22 lines · Arthur Simchaev
include/uapi/scsi/scsi_bsg_ufs.h +4
-4@@ -54,20 +54,21 @@ struct utp_upiu_header {* @idn: a value that indicates the particular type of data B-1 * @index: Index to further identify data B-2 * @selector: Index to further identify data B-3 -* @reserved_osf: spec reserved field B-4,5 -* @length: number of descriptor bytes to read/write B-6,7 -* @value: Attribute value to be written DW-5 -* @reserved: spec reserved DW-6,7 +* @osf4: spec field B-5 +* @osf5: spec field B 6,7 +* @osf6: spec field DW 8,9 +* @osf7: spec field DW 10,11 */ struct utp_upiu_query {__u8 opcode;__u8 idn;__u8 index;__u8 selector;
include/uapi/scsi/scsi_bsg_ufs.h struct utp_upiu_header { · line 72
Quoted 10 lines
include/uapi/scsi/scsi_bsg_ufs.h +5
-4-__be16 reserved_osf; -__be16 length; -__be32 value; -__be32 reserved[2 ]; +__u8 osf3; +__u8 osf4; +__be16 osf5; +__be32 osf6; +__be32 osf7; };
All changes in UAPI headers must be backwards compatible. The above doesn't look like a backwards compatible change to me.
Bart.
RE: [PATCH 1/2] include: uapi: scsi: Change utp_upiu_query struct
Hi Bart,
Quoted 19 lines
Quoted 7 lines
*/
structutp_upiu_query{include/uapi/scsi/scsi_bsg_ufs.h +0
-0__u8 opcode;__u8 idn;__u8 index;__u8 selector;include/uapi/scsi/scsi_bsg_ufs.h struct utp_upiu_header { · line 72
Quoted 10 lines
include/uapi/scsi/scsi_bsg_ufs.h +5
-4-__be16 reserved_osf; -__be16 length; -__be32 value; -__be32 reserved[2 ]; +__u8 osf3; +__u8 osf4; +__be16 osf5; +__be32 osf6; +__be32 osf7; };All changes in UAPI headers must be backwards compatible. The above doesn't look like a backwards compatible change to me.
Quoted 1 line
Bart.
This API was originally invented to support ufs-bsg. AFAIK, ufs-utils is the only app that makes use of this API, and it doesn't dig into struct utp_upiu_query inner fields.
Thanks,
Arthur
Regards
Arthur
Quoted 53 lines
-----Original Message-----
From: Bart Van Assche <[email protected]>
Sent: Wednesday, February 22, 2023 5:26 PM
To: Arthur Simchaev <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; linux- [email protected]
Subject: Re: [PATCH 1/2] include: uapi: scsi: Changeutp_upiu_querystructCAUTION: This email originated from outside of Western Digital. Do not click on links or open attachments unless you recognize the sender and know that the content is safe.
Review
Quoted 1 line · Arthur Simchaev
(quoted diff) +0
-0
b/include/uapi/scsi/scsi_bsg_ufs.hQuoted 21 lines
index 2801b65..cccc07d 100644
include/uapi/scsi/scsi_bsg_ufs.h +4
-4@@ -54,20 +54,21 @@ struct utp_upiu_header {* @idn: a value that indicates the particular type of data B-1 * @index: Index to further identify data B-2 * @selector: Index to further identify data B-3 -* @reserved_osf: spec reserved field B-4,5 -* @length: number of descriptor bytes to read/write B-6,7 -* @value: Attribute value to be written DW-5 -* @reserved: spec reserved DW-6,7 +* @osf4: spec field B-5 +* @osf5: spec field B 6,7 +* @osf6: spec field DW 8,9 +* @osf7: spec field DW 10,11 */ struct utp_upiu_query {__u8 opcode;__u8 idn;__u8 index;__u8 selector;include/uapi/scsi/scsi_bsg_ufs.h struct utp_upiu_header { · line 72
Quoted 10 lines
include/uapi/scsi/scsi_bsg_ufs.h +5
-4-__be16 reserved_osf; -__be16 length; -__be32 value; -__be32 reserved[2 ]; +__u8 osf3; +__u8 osf4; +__be16 osf5; +__be32 osf6; +__be32 osf7; };All changes in UAPI headers must be backwards compatible. The above doesn't look like a backwards compatible change to me.
Bart.
Bart Van Assche
reviewerRe: [PATCH 1/2] include: uapi: scsi: Change utp_upiu_query struct
Quoted 19 lines · Arthur Simchaev
Quoted 10 lines
Quoted 10 lines
*/ struct utp_upiu_query { __u8 opcode; __u8 idn; __u8 index; __u8 selector;include/uapi/scsi/scsi_bsg_ufs.h +0
-3-__be16 reserved_osf; -__be16 length; -__be32 value;Quoted 8 lines
include/uapi/scsi/scsi_bsg_ufs.h struct utp_upiu_header { · line 72
Quoted 7 lines
include/uapi/scsi/scsi_bsg_ufs.h +5
-1-__be32 reserved[2 ]; +__u8 osf3; +__u8 osf4; +__be16 osf5; +__be32 osf6; +__be32 osf7; };All changes in UAPI headers must be backwards compatible. The above doesn't look like a backwards compatible change to me.
Quoted 3 lines
This API was originally invented to support ufs-bsg. AFAIK, ufs-utils is the only app that makes use of this API, and it doesn't dig into struct
utp_upiu_queryinner fields.
That does not match what I see. I see that code in ufs-utils accesses the 'length' and 'value' members of the above data structure.
Please follow the rules for UAPI header files.
Thanks,
Bart.
RE: [PATCH 1/2] include: uapi: scsi: Change utp_upiu_query struct
Quoted 22 lines
Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
struct utp_upiu_query { __u8 opcode; __u8 idn; __u8 index; __u8 selector;include/uapi/scsi/scsi_bsg_ufs.h +5
-4-__be16 reserved_osf; -__be16 length; -__be32 value; -__be32 reserved[2 ]; +__u8 osf3; +__u8 osf4; +__be16 osf5; +__be32 osf6; +__be32 osf7; };Quoted 1 line
Quoted 1 line
All changes in UAPI headers must be backwards compatible. The above
doesn't look like a backwards compatible change to me.
Quoted 4 lines
This API was originally invented to support ufs-bsg. AFAIK, ufs-utils is the only app that makes use of this API, and it doesn't dig into struct
utp_upiu_queryinner fields.
Quoted 8 lines
That does not match what I see. I see that code in ufs-utils accesses the 'length' and 'value' members of the above data structure.
Please follow the rules for UAPI header files.
Thanks,
Bart.
You are right , my fault.
Anyway, It just return reserved field to the struct.
Also I can update the tool accordingly. Instead length and value fields, using osf5 and osf6.
In this case we will keep it backward compatible.
Is it OK?
Regards
Arthur
Quoted 47 lines
-----Original Message-----
From: Bart Van Assche <[email protected]>
Sent: Monday, February 27, 2023 7:00 PM
To: Arthur Simchaev <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; linux- [email protected]
Subject: Re: [PATCH 1/2] include: uapi: scsi: Changeutp_upiu_querystructCAUTION: This email originated from outside of Western Digital. Do not click on links or open attachments unless you recognize the sender and know that the content is safe.
Quoted 17 lines · Arthur Simchaev
Quoted 17 lines
Quoted 17 lines
*/ struct utp_upiu_query { __u8 opcode; __u8 idn; __u8 index; __u8 selector;include/uapi/scsi/scsi_bsg_ufs.h +5
-4-__be16 reserved_osf; -__be16 length; -__be32 value; -__be32 reserved[2 ]; +__u8 osf3; +__u8 osf4; +__be16 osf5; +__be32 osf6; +__be32 osf7; };Quoted 1 line
Quoted 1 line
All changes in UAPI headers must be backwards compatible. The above
doesn't look like a backwards compatible change to me.
Quoted 4 lines
This API was originally invented to support ufs-bsg. AFAIK, ufs-utils is the only app that makes use of this API, and it doesn't dig into struct
utp_upiu_queryinner fields.That does not match what I see. I see that code in ufs-utils accesses the 'length' and 'value' members of the above data structure.
Please follow the rules for UAPI header files.
Thanks,
Bart.
Bart Van Assche
reviewerRe: [PATCH 1/2] include: uapi: scsi: Change utp_upiu_query struct
Quoted 29 lines · Arthur Simchaev
Quoted 29 lines
Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
struct utp_upiu_query { __u8 opcode; __u8 idn; __u8 index; __u8 selector;include/uapi/scsi/scsi_bsg_ufs.h +5
-4-__be16 reserved_osf; -__be16 length; -__be32 value; -__be32 reserved[2 ]; +__u8 osf3; +__u8 osf4; +__be16 osf5; +__be32 osf6; +__be32 osf7; };Quoted 1 line
Quoted 1 line
All changes in UAPI headers must be backwards compatible. The above
doesn't look like a backwards compatible change to me.
Quoted 4 lines
This API was originally invented to support ufs-bsg. AFAIK, ufs-utils is the only app that makes use of this API, and it doesn't dig into struct
utp_upiu_queryinner fields.That does not match what I see. I see that code in ufs-utils accesses the 'length' and 'value' members of the above data structure.
Please follow the rules for UAPI header files.
Thanks,
Quoted 8 lines
Quoted 1 line
Bart.
You are right , my fault.
Anyway, It just return reserved field to the struct.
Also I can update the tool accordingly. Instead length and value fields, using osf5 and osf6.
In this case we will keep it backward compatible.
Is it OK?
Hi Arthur,
I doubt that renaming structure members is acceptable for UAPI headers. How about introducing a second struct next to the utp_upiu_query struct?
Thanks,
Bart.
RE: [PATCH 1/2] include: uapi: scsi: Change utp_upiu_query struct
Quoted 8 lines
Hi Arthur,
I doubt that renaming structure members is acceptable for UAPI headers. How about introducing a second struct next to the
utp_upiu_querystruct?Thanks,
Bart.
Done
Regards
Arthur
Quoted 61 lines
-----Original Message-----
From: Bart Van Assche <[email protected]>
Sent: Wednesday, March 1, 2023 8:44 PM
To: Arthur Simchaev <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; linux- [email protected]
Subject: Re: [PATCH 1/2] include: uapi: scsi: Changeutp_upiu_querystructCAUTION: This email originated from outside of Western Digital. Do not click on links or open attachments unless you recognize the sender and know that the content is safe.
Quoted 29 lines · Arthur Simchaev
Quoted 29 lines
Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
struct utp_upiu_query { __u8 opcode; __u8 idn; __u8 index; __u8 selector;include/uapi/scsi/scsi_bsg_ufs.h +5
-4-__be16 reserved_osf; -__be16 length; -__be32 value; -__be32 reserved[2 ]; +__u8 osf3; +__u8 osf4; +__be16 osf5; +__be32 osf6; +__be32 osf7; };Quoted 1 line
Quoted 1 line
All changes in UAPI headers must be backwards compatible. The above
doesn't look like a backwards compatible change to me.
Quoted 4 lines
This API was originally invented to support ufs-bsg. AFAIK, ufs-utils is the only app that makes use of this API, and it doesn't dig into struct
utp_upiu_queryinner fields.That does not match what I see. I see that code in ufs-utils accesses the 'length' and 'value' members of the above data structure.
Please follow the rules for UAPI header files.
Thanks,
Quoted 8 lines
Quoted 1 line
Bart.
You are right , my fault.
Anyway, It just return reserved field to the struct.
Also I can update the tool accordingly. Instead length and value fields, using osf5 and osf6.
In this case we will keep it backward compatible.
Is it OK?Hi Arthur,
I doubt that renaming structure members is acceptable for UAPI headers. How about introducing a second struct next to the
utp_upiu_querystruct?Thanks,
Bart.
kernel test robot
build botRe: [PATCH 1/2] include: uapi: scsi: Change utp_upiu_query struct
In reply to Arthur SimchaevThank you for the patch! Perhaps something to improve:
Hi Arthur,
Thank you for the patch! Perhaps something to improve:
[auto build test WARNING on mkp-scsi/for-next]
[also build test WARNING on jejb-scsi/for-next linus/master next-20230222] [cannot apply to v6.2]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Arthur-Simchaev/include-uapi-scsi-Change-utp_upiu_query-struct/20230222-233738 base: https://git.kernel.org/pub/scm/linux/kernel/git/mkp/scsi.git for-next patch link: https://lore.kernel.org/r/1677078770-30994-2-git-send-email-Arthur.Simchaev%40wdc.com patch subject: [PATCH 1/2] include: uapi: scsi: Change utp_upiu_query struct config: riscv-randconfig-r025-20230222 (https://download.01.org/0day-ci/archive/20230223/[email protected]/config) compiler: clang version 17.0.0 (https://github.com/llvm/llvm-project db89896bbbd2251fff457699635acbbedeead27f)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# install riscv cross compiling tool for clang build
# apt-get install binutils-riscv64-linux-gnu
# https://github.com/intel-lab-lkp/linux/commit/b821692fde9b136903941365fae75b13d85c23c7
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Arthur-Simchaev/include-uapi-scsi-Change-utp_upiu_query-struct/20230222-233738 git checkout b821692fde9b136903941365fae75b13d85c23c7
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=riscv olddefconfig COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=riscv SHELL=/bin/bash drivers/ufs/core/
If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <[email protected]>
| Link: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All warnings (new ones prefixed by >>):
In file included from drivers/ufs/core/ufshcd.c:12:
In file included from include/linux/async.h:14:
In file included from include/linux/device.h:15:
In file included from include/linux/dev_printk.h:16:
In file included from include/linux/ratelimit.h:6:
In file included from include/linux/sched.h:14:
In file included from include/linux/pid.h:5:
In file included from include/linux/rculist.h:11:
In file included from include/linux/rcupdate.h:29:
In file included from include/linux/lockdep.h:14:
In file included from include/linux/smp.h:13:
In file included from include/linux/cpumask.h:12:
In file included from include/linux/bitmap.h:11:
In file included from include/linux/string.h:253:
>> include/linux/fortify-string.h:513:4: warning: call to '__write_overflow_field' declared with 'warning' attribute: detected write beyond size of field (1st parameter); maybe use struct_group()? [-Wattribute-warning]
__write_overflow_field(p_size_field, size);
^
include/linux/fortify-string.h:522:4: warning: call to '__read_overflow2_field' declared with 'warning' attribute: detected read beyond size of field (2nd parameter); maybe use struct_group()? [-Wattribute-warning]
__read_overflow2_field(q_size_field, size);
^
>> include/linux/fortify-string.h:513:4: warning: call to '__write_overflow_field' declared with 'warning' attribute: detected write beyond size of field (1st parameter); maybe use struct_group()? [-Wattribute-warning]
__write_overflow_field(p_size_field, size);
^
include/linux/fortify-string.h:522:4: warning: call to '__read_overflow2_field' declared with 'warning' attribute: detected read beyond size of field (2nd parameter); maybe use struct_group()? [-Wattribute-warning]
__read_overflow2_field(q_size_field, size);
^4 warnings generated.
vim +513 include/linux/fortify-string.h
a28a6e860c6cf2 Francis Laniel 2021-02-25 457
f68f2ff91512c1 Kees Cook 2021-04-20 458 /*
f68f2ff91512c1 Kees Cook 2021-04-20 459 * To make sure the compiler can enforce protection against buffer overflows,
f68f2ff91512c1 Kees Cook 2021-04-20 460 * memcpy(), memmove(), and memset() must not be used beyond individual
f68f2ff91512c1 Kees Cook 2021-04-20 461 * struct members. If you need to copy across multiple members, please use
f68f2ff91512c1 Kees Cook 2021-04-20 462 * struct_group() to create a named mirror of an anonymous struct union.
f68f2ff91512c1 Kees Cook 2021-04-20 463 * (e.g. see struct sk_buff.) Read overflow checking is currently only
f68f2ff91512c1 Kees Cook 2021-04-20 464 * done when a write overflow is also present, or when building with W=1.
f68f2ff91512c1 Kees Cook 2021-04-20 465 *
f68f2ff91512c1 Kees Cook 2021-04-20 466 * Mitigation coverage matrix
f68f2ff91512c1 Kees Cook 2021-04-20 467 * Bounds checking at:
f68f2ff91512c1 Kees Cook 2021-04-20 468 * +-------+-------+-------+-------+
f68f2ff91512c1 Kees Cook 2021-04-20 469 * | Compile time | Run time |
f68f2ff91512c1 Kees Cook 2021-04-20 470 * memcpy() argument sizes: | write | read | write | read |
f68f2ff91512c1 Kees Cook 2021-04-20 471 * dest source length +-------+-------+-------+-------+
f68f2ff91512c1 Kees Cook 2021-04-20 472 * memcpy(known, known, constant) | y | y | n/a | n/a |
f68f2ff91512c1 Kees Cook 2021-04-20 473 * memcpy(known, unknown, constant) | y | n | n/a | V |
f68f2ff91512c1 Kees Cook 2021-04-20 474 * memcpy(known, known, dynamic) | n | n | B | B |
f68f2ff91512c1 Kees Cook 2021-04-20 475 * memcpy(known, unknown, dynamic) | n | n | B | V |
f68f2ff91512c1 Kees Cook 2021-04-20 476 * memcpy(unknown, known, constant) | n | y | V | n/a |
f68f2ff91512c1 Kees Cook 2021-04-20 477 * memcpy(unknown, unknown, constant) | n | n | V | V |
f68f2ff91512c1 Kees Cook 2021-04-20 478 * memcpy(unknown, known, dynamic) | n | n | V | B |
f68f2ff91512c1 Kees Cook 2021-04-20 479 * memcpy(unknown, unknown, dynamic) | n | n | V | V |
f68f2ff91512c1 Kees Cook 2021-04-20 480 * +-------+-------+-------+-------+
f68f2ff91512c1 Kees Cook 2021-04-20 481 *
f68f2ff91512c1 Kees Cook 2021-04-20 482 * y = perform deterministic compile-time bounds checking
f68f2ff91512c1 Kees Cook 2021-04-20 483 * n = cannot perform deterministic compile-time bounds checking
f68f2ff91512c1 Kees Cook 2021-04-20 484 * n/a = no run-time bounds checking needed since compile-time deterministic
f68f2ff91512c1 Kees Cook 2021-04-20 485 * B = can perform run-time bounds checking (currently unimplemented)
f68f2ff91512c1 Kees Cook 2021-04-20 486 * V = vulnerable to run-time overflow (will need refactoring to solve)
f68f2ff91512c1 Kees Cook 2021-04-20 487 *
f68f2ff91512c1 Kees Cook 2021-04-20 488 */
54d9469bc515dc Kees Cook 2021-06-24 489 __FORTIFY_INLINE bool fortify_memcpy_chk(__kernel_size_t size,
f68f2ff91512c1 Kees Cook 2021-04-20 490 const size_t p_size,
f68f2ff91512c1 Kees Cook 2021-04-20 491 const size_t q_size,
f68f2ff91512c1 Kees Cook 2021-04-20 492 const size_t p_size_field,
f68f2ff91512c1 Kees Cook 2021-04-20 493 const size_t q_size_field,
f68f2ff91512c1 Kees Cook 2021-04-20 494 const char *func)
a28a6e860c6cf2 Francis Laniel 2021-02-25 495 {
a28a6e860c6cf2 Francis Laniel 2021-02-25 496 if (__builtin_constant_p(size)) {
f68f2ff91512c1 Kees Cook 2021-04-20 497 /*
f68f2ff91512c1 Kees Cook 2021-04-20 498 * Length argument is a constant expression, so we
f68f2ff91512c1 Kees Cook 2021-04-20 499 * can perform compile-time bounds checking where
fa35198f39571b Kees Cook 2022-09-19 500 * buffer sizes are also known at compile time.
f68f2ff91512c1 Kees Cook 2021-04-20 501 */
f68f2ff91512c1 Kees Cook 2021-04-20 502
f68f2ff91512c1 Kees Cook 2021-04-20 503 /* Error when size is larger than enclosing struct. */
fa35198f39571b Kees Cook 2022-09-19 504 if (__compiletime_lessthan(p_size_field, p_size) &&
fa35198f39571b Kees Cook 2022-09-19 505 __compiletime_lessthan(p_size, size))
a28a6e860c6cf2 Francis Laniel 2021-02-25 506 __write_overflow();
fa35198f39571b Kees Cook 2022-09-19 507 if (__compiletime_lessthan(q_size_field, q_size) &&
fa35198f39571b Kees Cook 2022-09-19 508 __compiletime_lessthan(q_size, size))
a28a6e860c6cf2 Francis Laniel 2021-02-25 509 __read_overflow2();
f68f2ff91512c1 Kees Cook 2021-04-20 510
f68f2ff91512c1 Kees Cook 2021-04-20 511 /* Warn when write size argument larger than dest field. */
fa35198f39571b Kees Cook 2022-09-19 512 if (__compiletime_lessthan(p_size_field, size))
f68f2ff91512c1 Kees Cook 2021-04-20 @513 __write_overflow_field(p_size_field, size);
f68f2ff91512c1 Kees Cook 2021-04-20 514 /*
f68f2ff91512c1 Kees Cook 2021-04-20 515 * Warn for source field over-read when building with W=1
f68f2ff91512c1 Kees Cook 2021-04-20 516 * or when an over-write happened, so both can be fixed at
f68f2ff91512c1 Kees Cook 2021-04-20 517 * the same time.
f68f2ff91512c1 Kees Cook 2021-04-20 518 */
fa35198f39571b Kees Cook 2022-09-19 519 if ((IS_ENABLED(KBUILD_EXTRA_WARN1) ||
fa35198f39571b Kees Cook 2022-09-19 520 __compiletime_lessthan(p_size_field, size)) &&
fa35198f39571b Kees Cook 2022-09-19 521 __compiletime_lessthan(q_size_field, size))
f68f2ff91512c1 Kees Cook 2021-04-20 522 __read_overflow2_field(q_size_field, size);
a28a6e860c6cf2 Francis Laniel 2021-02-25 523 }
f68f2ff91512c1 Kees Cook 2021-04-20 524 /*
f68f2ff91512c1 Kees Cook 2021-04-20 525 * At this point, length argument may not be a constant expression,
f68f2ff91512c1 Kees Cook 2021-04-20 526 * so run-time bounds checking can be done where buffer sizes are
f68f2ff91512c1 Kees Cook 2021-04-20 527 * known. (This is not an "else" because the above checks may only
f68f2ff91512c1 Kees Cook 2021-04-20 528 * be compile-time warnings, and we want to still warn for run-time
f68f2ff91512c1 Kees Cook 2021-04-20 529 * overflows.)
f68f2ff91512c1 Kees Cook 2021-04-20 530 */
f68f2ff91512c1 Kees Cook 2021-04-20 531
f68f2ff91512c1 Kees Cook 2021-04-20 532 /*
f68f2ff91512c1 Kees Cook 2021-04-20 533 * Always stop accesses beyond the struct that contains the
f68f2ff91512c1 Kees Cook 2021-04-20 534 * field, when the buffer's remaining size is known.
311fb40aa0569a Kees Cook 2022-09-02 535 * (The SIZE_MAX test is to optimize away checks where the buffer
f68f2ff91512c1 Kees Cook 2021-04-20 536 * lengths are unknown.)
f68f2ff91512c1 Kees Cook 2021-04-20 537 */
311fb40aa0569a Kees Cook 2022-09-02 538 if ((p_size != SIZE_MAX && p_size < size) ||
311fb40aa0569a Kees Cook 2022-09-02 539 (q_size != SIZE_MAX && q_size < size))
f68f2ff91512c1 Kees Cook 2021-04-20 540 fortify_panic(func);
54d9469bc515dc Kees Cook 2021-06-24 541
54d9469bc515dc Kees Cook 2021-06-24 542 /*
54d9469bc515dc Kees Cook 2021-06-24 543 * Warn when writing beyond destination field size.
54d9469bc515dc Kees Cook 2021-06-24 544 *
54d9469bc515dc Kees Cook 2021-06-24 545 * We must ignore p_size_field == 0 for existing 0-element
54d9469bc515dc Kees Cook 2021-06-24 546 * fake flexible arrays, until they are all converted to
54d9469bc515dc Kees Cook 2021-06-24 547 * proper flexible arrays.
54d9469bc515dc Kees Cook 2021-06-24 548 *
9f7d69c5cd2390 Kees Cook 2022-09-19 549 * The implementation of __builtin_*object_size() behaves
54d9469bc515dc Kees Cook 2021-06-24 550 * like sizeof() when not directly referencing a flexible
54d9469bc515dc Kees Cook 2021-06-24 551 * array member, which means there will be many bounds checks
54d9469bc515dc Kees Cook 2021-06-24 552 * that will appear at run-time, without a way for them to be
54d9469bc515dc Kees Cook 2021-06-24 553 * detected at compile-time (as can be done when the destination
54d9469bc515dc Kees Cook 2021-06-24 554 * is specifically the flexible array member).
54d9469bc515dc Kees Cook 2021-06-24 555 * https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101832
54d9469bc515dc Kees Cook 2021-06-24 556 */
54d9469bc515dc Kees Cook 2021-06-24 557 if (p_size_field != 0 && p_size_field != SIZE_MAX &&
54d9469bc515dc Kees Cook 2021-06-24 558 p_size != p_size_field && p_size_field < size)
54d9469bc515dc Kees Cook 2021-06-24 559 return true;
54d9469bc515dc Kees Cook 2021-06-24 560
54d9469bc515dc Kees Cook 2021-06-24 561 return false;
a28a6e860c6cf2 Francis Laniel 2021-02-25 562 }
a28a6e860c6cf2 Francis Laniel 2021-02-25 563 Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests
PATCH 2/2 ufs: core: Providing Timestamp information to the device
In reply to Arthur SimchaevThe new qTimestamp attribute was added to UFS 4.0 spec, in order to synchronize the timestamp between the host and the ufs device. The spec recommend to send this attribute upon device power-on Reset/HW reset or when switching to Active state (using SSU command)
--- drivers/ufs/core/ufshcd.c | 36 ++++++++++++++++++++++++++++++++++++ include/ufs/ufs.h | 1 + 2 files changed, 37 insertions(+)
drivers/ufs/core/ufshcd.c +36 -0
@@ -8378,6 +8378,39 @@ static int ufshcd_device_params_init(struct ufs_hba *hba)return ret; } +static void ufshcd_set_timestamp_attr (struct ufs_hba *hba) +{ +int err; +struct ufs_query_req *request =NULL ; +struct ufs_query_res *response =NULL ; +struct ufs_dev_info *dev_info = &hba->dev_info; + +if (dev_info->wspecversion <0x400 ) +return ; + +ufshcd_hold (hba, false); + +mutex_lock (&hba->dev_cmd.lock); + +ufshcd_init_query (hba, &request, &response, +UPIU_QUERY_OPCODE_WRITE_ATTR , +QUERY_ATTR_IDN_TIMESTAMP ,0 ,0 ); + + request->query_func =UPIU_QUERY_FUNC_STANDARD_WRITE_REQUEST ; + +put_unaligned_be64 (ktime_get_real_ns (), &request->upiu_req.osf3); + + err =ufshcd_exec_dev_cmd (hba,DEV_CMD_TYPE_QUERY ,QUERY_REQ_TIMEOUT ); + +if (err) +dev_err (hba->dev,"%s: failed to set timestamp %d\n" , + __func__, err); + +mutex_unlock (&hba->dev_cmd.lock); + +ufshcd_release (hba); +} +/** * ufshcd_add_lus - probe and add UFS logical units * @hba: per-adapter instance
@@ -8547,6 +8580,8 @@ static int ufshcd_device_init(struct ufs_hba *hba, bool init_dev_params)ufshcd_set_ufs_dev_active (hba);ufshcd_force_reset_auto_bkops (hba); +ufshcd_set_timestamp_attr (hba); +/* Gear up to HS gear if supported */ if (hba->max_pwr_info.is_valid) {/*
@@ -9566,6 +9601,7 @@ static int __ufshcd_wl_resume(struct ufs_hba *hba, enum ufs_pm_op pm_op) ret =ufshcd_set_dev_pwr_mode (hba,UFS_ACTIVE_PWR_MODE );if (ret) goto set_old_link_state; +ufshcd_set_timestamp_attr (hba); }if (ufshcd_keep_autobkops_enabled_except_suspend (hba))
include/ufs/ufs.h +1 -0
@@ -170,6 +170,7 @@ enum attr_idn {QUERY_ATTR_IDN_WB_BUFF_LIFE_TIME_EST =0x1E ,QUERY_ATTR_IDN_CURR_WB_BUFF_SIZE =0x1F ,QUERY_ATTR_IDN_EXT_IID_EN =0x2A , + QUERY_ATTR_IDN_TIMESTAMP = 0x30 };/* Descriptor idn for Query requests */
Signature · 1 line
2.7.4