* [PATCH] x86/hyperv: Use pointer from memcpy() call for assignment in hv_crash_setup_trampdata()
@ 2025-10-31 8:33 Markus Elfring
2025-10-31 9:28 ` Naman Jain
2025-10-31 18:26 ` Wei Liu
0 siblings, 2 replies; 6+ messages in thread
From: Markus Elfring @ 2025-10-31 8:33 UTC (permalink / raw)
To: linux-hyperv, x86, Borislav Petkov, Dave Hansen, Dexuan Cui,
Haiyang Zhang, H. Peter Anvin, Ingo Molnar, K. Y. Srinivasan,
Long Li, Mukesh Rathor, Thomas Gleixner, Wei Liu
Cc: LKML, kernel-janitors, Miaoqian Lin
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Fri, 31 Oct 2025 09:24:31 +0100
A pointer was assigned to a variable. The same pointer was used for
the destination parameter of a memcpy() call.
This function is documented in the way that the same value is returned.
Thus convert two separate statements into a direct variable assignment for
the return value from a memory copy action.
The source code was transformed by using the Coccinelle software.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
arch/x86/hyperv/hv_crash.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/arch/x86/hyperv/hv_crash.c b/arch/x86/hyperv/hv_crash.c
index c0e22921ace1..745d02066308 100644
--- a/arch/x86/hyperv/hv_crash.c
+++ b/arch/x86/hyperv/hv_crash.c
@@ -464,9 +464,7 @@ static int hv_crash_setup_trampdata(u64 trampoline_va)
return -1;
}
- dest = (void *)trampoline_va;
- memcpy(dest, &hv_crash_asm32, size);
-
+ dest = memcpy((void *)trampoline_va, &hv_crash_asm32, size);
dest += size;
dest = (void *)round_up((ulong)dest, 16);
tramp = (struct hv_crash_tramp_data *)dest;
--
2.51.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] x86/hyperv: Use pointer from memcpy() call for assignment in hv_crash_setup_trampdata()
2025-10-31 8:33 [PATCH] x86/hyperv: Use pointer from memcpy() call for assignment in hv_crash_setup_trampdata() Markus Elfring
@ 2025-10-31 9:28 ` Naman Jain
2025-10-31 9:37 ` Julia Lawall
2025-10-31 9:44 ` Markus Elfring
2025-10-31 18:26 ` Wei Liu
1 sibling, 2 replies; 6+ messages in thread
From: Naman Jain @ 2025-10-31 9:28 UTC (permalink / raw)
To: Markus Elfring, linux-hyperv, x86, Borislav Petkov, Dave Hansen,
Dexuan Cui, Haiyang Zhang, H. Peter Anvin, Ingo Molnar,
K. Y. Srinivasan, Long Li, Mukesh Rathor, Thomas Gleixner,
Wei Liu
Cc: LKML, kernel-janitors, Miaoqian Lin
On 10/31/2025 2:03 PM, Markus Elfring wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Fri, 31 Oct 2025 09:24:31 +0100
>
> A pointer was assigned to a variable. The same pointer was used for
> the destination parameter of a memcpy() call.
> This function is documented in the way that the same value is returned.
> Thus convert two separate statements into a direct variable assignment for
> the return value from a memory copy action.
>
> The source code was transformed by using the Coccinelle software.
>
> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
> ---
> arch/x86/hyperv/hv_crash.c | 4 +---
> 1 file changed, 1 insertion(+), 3 deletions(-)
>
> diff --git a/arch/x86/hyperv/hv_crash.c b/arch/x86/hyperv/hv_crash.c
> index c0e22921ace1..745d02066308 100644
> --- a/arch/x86/hyperv/hv_crash.c
> +++ b/arch/x86/hyperv/hv_crash.c
> @@ -464,9 +464,7 @@ static int hv_crash_setup_trampdata(u64 trampoline_va)
> return -1;
> }
>
> - dest = (void *)trampoline_va;
> - memcpy(dest, &hv_crash_asm32, size);
> -
> + dest = memcpy((void *)trampoline_va, &hv_crash_asm32, size);
> dest += size;
> dest = (void *)round_up((ulong)dest, 16);
> tramp = (struct hv_crash_tramp_data *)dest;
I tried running spatch Coccinelle checks on this file, but could not get
it to flag this improvement. Do you mind sharing more details on the
issue reproduction please.
I am OK with this change, though it may cost code readability a little
bit. But if this is a result of some known standard rule, added as part
of these Coccinelle rules, we should be good.
Regards,
Naman
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] x86/hyperv: Use pointer from memcpy() call for assignment in hv_crash_setup_trampdata()
2025-10-31 9:28 ` Naman Jain
@ 2025-10-31 9:37 ` Julia Lawall
2025-10-31 9:44 ` Markus Elfring
1 sibling, 0 replies; 6+ messages in thread
From: Julia Lawall @ 2025-10-31 9:37 UTC (permalink / raw)
To: Naman Jain
Cc: Markus Elfring, linux-hyperv, x86, Borislav Petkov, Dave Hansen,
Dexuan Cui, Haiyang Zhang, H. Peter Anvin, Ingo Molnar,
K. Y. Srinivasan, Long Li, Mukesh Rathor, Thomas Gleixner,
Wei Liu, LKML, kernel-janitors, Miaoqian Lin
On Fri, 31 Oct 2025, Naman Jain wrote:
>
>
> On 10/31/2025 2:03 PM, Markus Elfring wrote:
> > From: Markus Elfring <elfring@users.sourceforge.net>
> > Date: Fri, 31 Oct 2025 09:24:31 +0100
> >
> > A pointer was assigned to a variable. The same pointer was used for
> > the destination parameter of a memcpy() call.
> > This function is documented in the way that the same value is returned.
> > Thus convert two separate statements into a direct variable assignment for
> > the return value from a memory copy action.
> >
> > The source code was transformed by using the Coccinelle software.
> >
> > Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
> > ---
> > arch/x86/hyperv/hv_crash.c | 4 +---
> > 1 file changed, 1 insertion(+), 3 deletions(-)
> >
> > diff --git a/arch/x86/hyperv/hv_crash.c b/arch/x86/hyperv/hv_crash.c
> > index c0e22921ace1..745d02066308 100644
> > --- a/arch/x86/hyperv/hv_crash.c
> > +++ b/arch/x86/hyperv/hv_crash.c
> > @@ -464,9 +464,7 @@ static int hv_crash_setup_trampdata(u64 trampoline_va)
> > return -1;
> > }
> > - dest = (void *)trampoline_va;
> > - memcpy(dest, &hv_crash_asm32, size);
> > -
> > + dest = memcpy((void *)trampoline_va, &hv_crash_asm32, size);
> > dest += size;
> > dest = (void *)round_up((ulong)dest, 16);
> > tramp = (struct hv_crash_tramp_data *)dest;
>
>
> I tried running spatch Coccinelle checks on this file, but could not get it to
> flag this improvement. Do you mind sharing more details on the issue
> reproduction please.
>
> I am OK with this change, though it may cost code readability a little bit.
> But if this is a result of some known standard rule, added as part of these
> Coccinelle rules, we should be good.
Multiple people have suggested that due to the loos of readability the
change is not a good idea.
It's not done by a standard rule.
julia
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] x86/hyperv: Use pointer from memcpy() call for assignment in hv_crash_setup_trampdata()
2025-10-31 9:28 ` Naman Jain
2025-10-31 9:37 ` Julia Lawall
@ 2025-10-31 9:44 ` Markus Elfring
2025-10-31 12:32 ` Naman Jain
1 sibling, 1 reply; 6+ messages in thread
From: Markus Elfring @ 2025-10-31 9:44 UTC (permalink / raw)
To: Naman Jain, linux-hyperv, x86, Borislav Petkov, Dave Hansen,
Dexuan Cui, Haiyang Zhang, H. Peter Anvin, Ingo Molnar,
K. Y. Srinivasan, Long Li, Mukesh Rathor, Thomas Gleixner,
Wei Liu
Cc: LKML, kernel-janitors, Miaoqian Lin
…>> +++ b/arch/x86/hyperv/hv_crash.c
>> @@ -464,9 +464,7 @@ static int hv_crash_setup_trampdata(u64 trampoline_va)
>> return -1;
>> }
>> - dest = (void *)trampoline_va;
>> - memcpy(dest, &hv_crash_asm32, size);
>> -
>> + dest = memcpy((void *)trampoline_va, &hv_crash_asm32, size);
>> dest += size;
>> dest = (void *)round_up((ulong)dest, 16);
>> tramp = (struct hv_crash_tramp_data *)dest;
>
>
> I tried running spatch Coccinelle checks on this file, but could not get it to flag this improvement.
The proposed source code transformation is not supported by a coccicheck script so far.
> Do you mind sharing more details on the issue reproduction please.
Would you like to take another look at corresponding development discussions?
Example:
[RFC] Increasing usage of direct pointer assignments from memcpy() calls with SmPL?
https://lore.kernel.org/cocci/ddc8654a-9505-451f-87ad-075bfa646381@web.de/
https://sympa.inria.fr/sympa/arc/cocci/2025-10/msg00049.html
> I am OK with this change,
Thanks for a bit of positive feedback.
> though it may cost code readability a little bit.
Would you complain about other variable assignments in such a direction?
Regards,
Markus
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] x86/hyperv: Use pointer from memcpy() call for assignment in hv_crash_setup_trampdata()
2025-10-31 9:44 ` Markus Elfring
@ 2025-10-31 12:32 ` Naman Jain
0 siblings, 0 replies; 6+ messages in thread
From: Naman Jain @ 2025-10-31 12:32 UTC (permalink / raw)
To: Markus Elfring, linux-hyperv, x86, Borislav Petkov, Dave Hansen,
Dexuan Cui, Haiyang Zhang, H. Peter Anvin, Ingo Molnar,
K. Y. Srinivasan, Long Li, Mukesh Rathor, Thomas Gleixner,
Wei Liu
Cc: LKML, kernel-janitors, Miaoqian Lin
On 10/31/2025 3:14 PM, Markus Elfring wrote:
> …>> +++ b/arch/x86/hyperv/hv_crash.c
>>> @@ -464,9 +464,7 @@ static int hv_crash_setup_trampdata(u64 trampoline_va)
>>> return -1;
>>> }
>>> - dest = (void *)trampoline_va;
>>> - memcpy(dest, &hv_crash_asm32, size);
>>> -
>>> + dest = memcpy((void *)trampoline_va, &hv_crash_asm32, size);
>>> dest += size;
>>> dest = (void *)round_up((ulong)dest, 16);
>>> tramp = (struct hv_crash_tramp_data *)dest;
>>
>>
>> I tried running spatch Coccinelle checks on this file, but could not get it to flag this improvement.
>
> The proposed source code transformation is not supported by a coccicheck script so far.
>
>
>> Do you mind sharing more details on the issue reproduction please.
>
> Would you like to take another look at corresponding development discussions?
>
> Example:
> [RFC] Increasing usage of direct pointer assignments from memcpy() calls with SmPL?
> https://lore.kernel.org/cocci/ddc8654a-9505-451f-87ad-075bfa646381@web.de/
> https://sympa.inria.fr/sympa/arc/cocci/2025-10/msg00049.html
>
>
>> I am OK with this change,
>
> Thanks for a bit of positive feedback.
>
>
>> though it may cost code readability a little bit.
>
> Would you complain about other variable assignments in such a direction?
>
> Regards,
> Markus
The only thing which concerns readability IMO is that it is based on the
assumption that the person reading the code is aware of the return value
of memcpy. Now, it is debatable if that is something which can be
considered trivial. I don't have a strong opinion there, but would
prefer it in its current form.
Also, we could have optimized it further by writing it as below, but we
are not doing that for a reason as we want to keep the code simpler to
read and understand. The same may apply here as well.
dest = memcpy((void *)trampoline_va, &hv_crash_asm32, size) + size;
Regards,
Naman
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] x86/hyperv: Use pointer from memcpy() call for assignment in hv_crash_setup_trampdata()
2025-10-31 8:33 [PATCH] x86/hyperv: Use pointer from memcpy() call for assignment in hv_crash_setup_trampdata() Markus Elfring
2025-10-31 9:28 ` Naman Jain
@ 2025-10-31 18:26 ` Wei Liu
1 sibling, 0 replies; 6+ messages in thread
From: Wei Liu @ 2025-10-31 18:26 UTC (permalink / raw)
To: Markus Elfring
Cc: linux-hyperv, x86, Borislav Petkov, Dave Hansen, Dexuan Cui,
Haiyang Zhang, H. Peter Anvin, Ingo Molnar, K. Y. Srinivasan,
Long Li, Mukesh Rathor, Thomas Gleixner, Wei Liu, LKML,
kernel-janitors, Miaoqian Lin
On Fri, Oct 31, 2025 at 09:33:17AM +0100, Markus Elfring wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Fri, 31 Oct 2025 09:24:31 +0100
>
> A pointer was assigned to a variable. The same pointer was used for
> the destination parameter of a memcpy() call.
> This function is documented in the way that the same value is returned.
> Thus convert two separate statements into a direct variable assignment for
> the return value from a memory copy action.
>
> The source code was transformed by using the Coccinelle software.
>
> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
> ---
> arch/x86/hyperv/hv_crash.c | 4 +---
> 1 file changed, 1 insertion(+), 3 deletions(-)
>
> diff --git a/arch/x86/hyperv/hv_crash.c b/arch/x86/hyperv/hv_crash.c
> index c0e22921ace1..745d02066308 100644
> --- a/arch/x86/hyperv/hv_crash.c
> +++ b/arch/x86/hyperv/hv_crash.c
> @@ -464,9 +464,7 @@ static int hv_crash_setup_trampdata(u64 trampoline_va)
> return -1;
> }
>
> - dest = (void *)trampoline_va;
> - memcpy(dest, &hv_crash_asm32, size);
> -
> + dest = memcpy((void *)trampoline_va, &hv_crash_asm32, size);
I don't think this change is needed.
There aren't that many places in the kernel tree that use this pattern.
The pattern used by the original code is far more pervasive.
Wei
> dest += size;
> dest = (void *)round_up((ulong)dest, 16);
> tramp = (struct hv_crash_tramp_data *)dest;
> --
> 2.51.1
>
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2025-10-31 18:26 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-31 8:33 [PATCH] x86/hyperv: Use pointer from memcpy() call for assignment in hv_crash_setup_trampdata() Markus Elfring
2025-10-31 9:28 ` Naman Jain
2025-10-31 9:37 ` Julia Lawall
2025-10-31 9:44 ` Markus Elfring
2025-10-31 12:32 ` Naman Jain
2025-10-31 18:26 ` Wei Liu
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).