linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] blk-mq: use force attribute for blk_status_t casts
@ 2022-05-14 10:03 Vasily Averin
  2022-05-14 21:24 ` Jens Axboe
  2022-05-16  6:53 ` Christoph Hellwig
  0 siblings, 2 replies; 6+ messages in thread
From: Vasily Averin @ 2022-05-14 10:03 UTC (permalink / raw)
  To: Jens Axboe, linux-block; +Cc: kernel, linux-kernel

Fixes sparse warnings:
block/blk-mq.c:1163:36: sparse:
 warning: cast from restricted blk_status_t
block/blk-mq.c:1251:17: sparse:
 warning: cast to restricted blk_status_t

Signed-off-by: Vasily Averin <vvs@openvz.org>
---
 block/blk-mq.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/block/blk-mq.c b/block/blk-mq.c
index 84d749511f55..1b887f2d4a19 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -1160,7 +1160,7 @@ static void blk_end_sync_rq(struct request *rq, blk_status_t error)
 {
 	struct completion *waiting = rq->end_io_data;
 
-	rq->end_io_data = (void *)(uintptr_t)error;
+	rq->end_io_data = (void *)(__force uintptr_t)error;
 
 	/*
 	 * complete last, if this is a stack request the process (and thus
@@ -1248,7 +1248,7 @@ blk_status_t blk_execute_rq(struct request *rq, bool at_head)
 	else
 		wait_for_completion_io(&wait);
 
-	return (blk_status_t)(uintptr_t)rq->end_io_data;
+	return (__force blk_status_t)(uintptr_t)rq->end_io_data;
 }
 EXPORT_SYMBOL(blk_execute_rq);
 
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] blk-mq: use force attribute for blk_status_t casts
  2022-05-14 10:03 [PATCH] blk-mq: use force attribute for blk_status_t casts Vasily Averin
@ 2022-05-14 21:24 ` Jens Axboe
  2022-05-16  6:53 ` Christoph Hellwig
  1 sibling, 0 replies; 6+ messages in thread
From: Jens Axboe @ 2022-05-14 21:24 UTC (permalink / raw)
  To: linux-block, Vasily Averin; +Cc: kernel, linux-kernel

On Sat, 14 May 2022 13:03:54 +0300, Vasily Averin wrote:
> Fixes sparse warnings:
> block/blk-mq.c:1163:36: sparse:
>  warning: cast from restricted blk_status_t
> block/blk-mq.c:1251:17: sparse:
>  warning: cast to restricted blk_status_t
> 
> 
> [...]

Applied, thanks!

[1/1] blk-mq: use force attribute for blk_status_t casts
      commit: cb9e061e974f8a3a8f2b8c89d93f34ffa7cacafb

Best regards,
-- 
Jens Axboe



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] blk-mq: use force attribute for blk_status_t casts
  2022-05-14 10:03 [PATCH] blk-mq: use force attribute for blk_status_t casts Vasily Averin
  2022-05-14 21:24 ` Jens Axboe
@ 2022-05-16  6:53 ` Christoph Hellwig
  2022-05-18 12:45   ` [PATCH v2] blk-mq: fix incorrect " Vasily Averin
  1 sibling, 1 reply; 6+ messages in thread
From: Christoph Hellwig @ 2022-05-16  6:53 UTC (permalink / raw)
  To: Vasily Averin; +Cc: Jens Axboe, linux-block, kernel, linux-kernel


No, no, no.  Really, stop these patches that just make things worse
now.  __force casts are a really bad idea.  Please just fix this
in a way that does not require casting away these attributes as they
are there for a reason!

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v2] blk-mq: fix incorrect blk_status_t casts
  2022-05-16  6:53 ` Christoph Hellwig
@ 2022-05-18 12:45   ` Vasily Averin
  2022-05-18 20:35     ` Chaitanya Kulkarni
  2022-05-19  7:53     ` Christoph Hellwig
  0 siblings, 2 replies; 6+ messages in thread
From: Vasily Averin @ 2022-05-18 12:45 UTC (permalink / raw)
  To: Christoph Hellwig, Jens Axboe; +Cc: kernel, linux-kernel, linux-block

Fixes sparse warnings:
block/blk-mq.c:1163:36: sparse:
 warning: cast from restricted blk_status_t
block/blk-mq.c:1251:17: sparse:
 warning: cast to restricted blk_status_t

blk_status_t type is bitwaise and requires __force for any casts.

Signed-off-by: Vasily Averin <vvs@openvz.org>
---
v2: introduced request_blk_status_en/decode helpers
	thanks Christoph Hellwig for the hint
---
 block/blk-mq.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/block/blk-mq.c b/block/blk-mq.c
index 84d749511f55..8f067b021af3 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -1151,6 +1151,16 @@ void blk_mq_start_request(struct request *rq)
 }
 EXPORT_SYMBOL(blk_mq_start_request);
 
+static void *request_blk_status_encode(blk_status_t status)
+{
+	return (void *)(__force uintptr_t)status;
+}
+
+static blk_status_t request_blk_status_decode(void *ptr)
+{
+	return (__force blk_status_t)(uintptr_t)ptr;
+}
+
 /**
  * blk_end_sync_rq - executes a completion event on a request
  * @rq: request to complete
@@ -1160,7 +1170,7 @@ static void blk_end_sync_rq(struct request *rq, blk_status_t error)
 {
 	struct completion *waiting = rq->end_io_data;
 
-	rq->end_io_data = (void *)(uintptr_t)error;
+	rq->end_io_data = request_blk_status_encode(error);
 
 	/*
 	 * complete last, if this is a stack request the process (and thus
@@ -1228,6 +1238,7 @@ static void blk_rq_poll_completion(struct request *rq, struct completion *wait)
  *    for execution and wait for completion.
  * Return: The blk_status_t result provided to blk_mq_end_request().
  */
+
 blk_status_t blk_execute_rq(struct request *rq, bool at_head)
 {
 	DECLARE_COMPLETION_ONSTACK(wait);
@@ -1248,7 +1259,7 @@ blk_status_t blk_execute_rq(struct request *rq, bool at_head)
 	else
 		wait_for_completion_io(&wait);
 
-	return (blk_status_t)(uintptr_t)rq->end_io_data;
+	return request_blk_status_decode(rq->end_io_data);
 }
 EXPORT_SYMBOL(blk_execute_rq);
 
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] blk-mq: fix incorrect blk_status_t casts
  2022-05-18 12:45   ` [PATCH v2] blk-mq: fix incorrect " Vasily Averin
@ 2022-05-18 20:35     ` Chaitanya Kulkarni
  2022-05-19  7:53     ` Christoph Hellwig
  1 sibling, 0 replies; 6+ messages in thread
From: Chaitanya Kulkarni @ 2022-05-18 20:35 UTC (permalink / raw)
  To: Vasily Averin
  Cc: kernel, linux-kernel, Jens Axboe, Christoph Hellwig, linux-block

On 5/18/22 05:45, Vasily Averin wrote:
> Fixes sparse warnings:
> block/blk-mq.c:1163:36: sparse:
>   warning: cast from restricted blk_status_t
> block/blk-mq.c:1251:17: sparse:
>   warning: cast to restricted blk_status_t
> 
> blk_status_t type is bitwaise and requires __force for any casts.
> 
> Signed-off-by: Vasily Averin <vvs@openvz.org>
> ---
> v2: introduced request_blk_status_en/decode helpers
> 	thanks Christoph Hellwig for the hint
> ---
>   block/blk-mq.c | 15 +++++++++++++--
>   1 file changed, 13 insertions(+), 2 deletions(-)
> 
> diff --git a/block/blk-mq.c b/block/blk-mq.c
> index 84d749511f55..8f067b021af3 100644
> --- a/block/blk-mq.c
> +++ b/block/blk-mq.c
> @@ -1151,6 +1151,16 @@ void blk_mq_start_request(struct request *rq)
>   }
>   EXPORT_SYMBOL(blk_mq_start_request);
>   
> +static void *request_blk_status_encode(blk_status_t status)
> +{
> +	return (void *)(__force uintptr_t)status;
> +}
> +
> +static blk_status_t request_blk_status_decode(void *ptr)
> +{
> +	return (__force blk_status_t)(uintptr_t)ptr;
> +}
> +

why not use blk_sts_encode() and blk_sts_decode() since both the
functions neither accept request parameter nor return request in any
form ?

-ck

>   /**
>    * blk_end_sync_rq - executes a completion event on a request
>    * @rq: request to complete
> @@ -1160,7 +1170,7 @@ static void blk_end_sync_rq(struct request *rq, blk_status_t error)
>   {
>   	struct completion *waiting = rq->end_io_data;
>   
> -	rq->end_io_data = (void *)(uintptr_t)error;
> +	rq->end_io_data = request_blk_status_encode(error);
>   
>   	/*
>   	 * complete last, if this is a stack request the process (and thus
> @@ -1228,6 +1238,7 @@ static void blk_rq_poll_completion(struct request *rq, struct completion *wait)
>    *    for execution and wait for completion.
>    * Return: The blk_status_t result provided to blk_mq_end_request().
>    */
> +

white line ?

>   blk_status_t blk_execute_rq(struct request *rq, bool at_head)
>   {
>   	DECLARE_COMPLETION_ONSTACK(wait);
> @@ -1248,7 +1259,7 @@ blk_status_t blk_execute_rq(struct request *rq, bool at_head)
>   	else
>   		wait_for_completion_io(&wait);
>   
> -	return (blk_status_t)(uintptr_t)rq->end_io_data;
> +	return request_blk_status_decode(rq->end_io_data);
>   }
>   EXPORT_SYMBOL(blk_execute_rq);
>   

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] blk-mq: fix incorrect blk_status_t casts
  2022-05-18 12:45   ` [PATCH v2] blk-mq: fix incorrect " Vasily Averin
  2022-05-18 20:35     ` Chaitanya Kulkarni
@ 2022-05-19  7:53     ` Christoph Hellwig
  1 sibling, 0 replies; 6+ messages in thread
From: Christoph Hellwig @ 2022-05-19  7:53 UTC (permalink / raw)
  To: Vasily Averin
  Cc: Christoph Hellwig, Jens Axboe, kernel, linux-kernel, linux-block

Still a whole lot of casts.  Take a look at my "cleanup blk_execute_rq*"
for how think we can solve this in a much nicer way.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2022-05-19  7:53 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-14 10:03 [PATCH] blk-mq: use force attribute for blk_status_t casts Vasily Averin
2022-05-14 21:24 ` Jens Axboe
2022-05-16  6:53 ` Christoph Hellwig
2022-05-18 12:45   ` [PATCH v2] blk-mq: fix incorrect " Vasily Averin
2022-05-18 20:35     ` Chaitanya Kulkarni
2022-05-19  7:53     ` Christoph Hellwig

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).