intel: igb: igb_ethtool.c: Convert kmap() to kmap_local_page()
Subsystems (3)
PATCH v3 1/1 intel: igb: igb_ethtool.c: Convert kmap() to kmap_local_page()
Convert kmap() to kmap_local_page()
With kmap_local_page(), the mapping is per thread, CPU local and not globally visible.
---
changes in V2:
fix kunmap_local path value to take address of the mapped page.
---
changes in V3:
edit commit message to be clearer
--- drivers/net/ethernet/intel/igb/igb_ethtool.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/ethernet/intel/igb/igb_ethtool.c +2 -2
@@ -1798,14 +1798,14 @@ static int igb_check_lbtest_frame(struct igb_rx_buffer *rx_buffer, frame_size >>=1 ; - data =kmap (rx_buffer->page); + data =kmap_local_page (rx_buffer->page);if (data[3 ] !=0xFF || data[frame_size +10 ] !=0xBE || data[frame_size +12 ] !=0xAF ) match = false; -kunmap (rx_buffer->page); +kunmap_local (data);return match; }
Signature · 1 line
2.35.2
Quoted 4 lines · Alaa Mohamed
Convert
kmap()tokmap_local_page()With
kmap_local_page(), the mapping is per thread, CPU local and not globally visible.
It's not clearer. This is a general statement about the function. You need to explain why it is appropriate to use it here. Unless it is the case that all calls to kmap should be converted to call kmap_local_page.
julia
Quoted 38 lines
Signed-off-by Alaa Mohamed <[email protected]>---
changes in V2:
fixkunmap_localpath value to take address of the mapped page.
---
changes in V3:
edit commit message to be clearer--- drivers/net/ethernet/intel/igb/igb_ethtool.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/net/ethernet/intel/igb/igb_ethtool.c +2
-3@@ -1798,14 +1798,14 @@ static int igb_check_lbtest_frame(struct igb_rx_buffer *rx_buffer, frame_size >>=1 ; - data =kmap (rx_buffer->page); + data =kmap_local_page (rx_buffer->page);if (data[3 ] !=0xFF || data[frame_size +10 ] !=0xBE || data[frame_size +12 ] !=0xAF ) match = false; -kunmap (rx_buffer->page); +kunmap_local (data);return match; } --2.35.2
PATCH v3 1/1 intel: igb: igb_ethtool.c: Convert kmap() to kmap_local_page()
Quoted 8 lines · Julia Lawall
Quoted 4 lines · Alaa Mohamed
Convert
kmap()tokmap_local_page()With
kmap_local_page(), the mapping is per thread, CPU local and not globally visible.It's not clearer.
I mean this " fix kunmap_local path value to take address of the mapped page" be more clearer
Quoted 3 lines
This is a general statement about the function. You
need to explain why it is appropriate to use it here. Unless it is the case that all calls to kmap should be converted to callkmap_local_page.
It's required to convert all calls kmap to kmap_local_page. So, I don't what should the commit message be?
Is this will be good :
"kmap_local_page() was recently developed as a replacement for kmap().? The kmap_local_page() creates a mapping which is restricted to local use by a single thread of execution. "
Quoted 33 lines
julia
Quoted 30 lines
Signed-off-by Alaa Mohamed<[email protected]>---
changes in V2:
fixkunmap_localpath value to take address of the mapped page.
---
changes in V3:
edit commit message to be clearer--- drivers/net/ethernet/intel/igb/igb_ethtool.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/net/ethernet/intel/igb/igb_ethtool.c +2
-2@@ -1798,14 +1798,14 @@ static int igb_check_lbtest_frame(struct igb_rx_buffer *rx_buffer, frame_size >>=1 ; - data =kmap (rx_buffer->page); + data =kmap_local_page (rx_buffer->page);if (data[3 ] !=0xFF || data[frame_size +10 ] !=0xBE || data[frame_size +12 ] !=0xAF ) match = false; -kunmap (rx_buffer->page); +kunmap_local (data);
Quoted 7 lines
Quoted 7 lines
drivers/net/ethernet/intel/igb/igb_ethtool.c +0
-1return match; } --2.35.2
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osuosl.org/pipermail/intel-wired-lan/attachments/20220416/173e7199/attachment-0001.html>
Quoted 23 lines · Alaa Mohamed
On ???/??/???? ??:??, Julia Lawall wrote:On Sat, 16 Apr 2022, Alaa Mohamed wrote:
Convert
kmap()tokmap_local_page()With
kmap_local_page(), the mapping is per thread, CPU local and not globally visible.It's not clearer.
I mean this " fix
kunmap_localpath value to take address of the mapped page" be more clearerThis is a general statement about the function. You
need to explain why it is appropriate to use it here. Unless it is the case that all calls to kmap should be converted to callkmap_local_page.It's required to convert all calls kmap to
kmap_local_page. So, I don't what should the commit message be?
Quoted 7 lines
Is this will be good :
"
kmap_local_page()was recently developed as a replacement forkmap(). The
kmap_local_page()creates a mapping which is restricted to local use by a single thread of execution. "
I think I am missing some thread context here. I'm not sure who said what above. So I'm going to start over.
Alaa,
It is important to remember that a good commit message says 2 things.
1) What is the problem you are trying to solve
2) Overview of the solution
First off I understand your frustration. In my opinion fixes and clean ups like this are very hard to write good commit messages for because so often the code diff seems so self explanatory. However, each code change comes at the identification of a problem. And remember that 'problem' does not always mean a bug fix.
The deprecation of kmap() may not seem like a problem. I mean why can't we just leave kmap() as it is? It works right?
But the problem is that the kmap (highmem) interface has become stale and its original purpose was targeted toward large memory systems with 32 bit kernels. There are very few systems being run like that any longer.
So how do we clean up the kmap interface to be more useful to the kernel community now that 32 bit kernels with highmem are so rare?
The community has identified that a first step of that is to move away from and eventually remove the kmap() call. This is due to the call being incorrectly used to create long term mappings. Most calls to kmap() are not used incorrectly but those call sites needed something in between kmap() and kmap_atmoic(). That call is kmap_local_page().
Now that kmap_local_page() exists the kmap() calls can be audited and most (I hope most)[1] can be replaced with kmap_local_page().
The change you have below is correct. But it lacks a good commit message. We need to cover the 2 points above.
1) Julia is asking why you needed to do this change. What is the problem or reason for this change? (Ira told you to is not a good reason. ;-)
PS In fact me telling you to may actually be a very bad reason... j/k ;-)
2) Why is this solution ok as part of the deprecation and removal of kmap()?
A final note; the 2 above points don't need a lot of text. Here I used 2 simple sentences.
https://lore.kernel.org/lkml/20220124015409.807587-2-ira.weiny at intel.com/
I hope this helps,
Ira
[1] But not all... some uses of kmap() have been identified as being pretty complex.
Quoted 38 lines
julia
Signed-off-by Alaa Mohamed <[email protected]>---
changes in V2:
fixkunmap_localpath value to take address of the mapped page.
---
changes in V3:
edit commit message to be clearer
---drivers/net/ethernet/intel/igb/igb_ethtool.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)diff --git
a/drivers/net/ethernet/intel/igb/igb_ethtool.cb/drivers/net/ethernet/intel/igb/igb_ethtool.cindex2a5782063f4c..c14fc871dd41100644
---a/drivers/net/ethernet/intel/igb/igb_ethtool.c
+++b/drivers/net/ethernet/intel/igb/igb_ethtool.c
@@ -1798,14 +1798,14 @@ static int igb_check_lbtest_frame(structigb_rx_buffer*rx_buffer,frame_size >>= 1;- data =
kmap(rx_buffer->page);
+ data =kmap_local_page(rx_buffer->page);if (data[3] != 0xFF || data[frame_size + 10] != 0xBE || data[frame_size + 12] != 0xAF) match = false;-
kunmap(rx_buffer->page);
+kunmap_local(data);return match;}
--
2.35.2
Quoted 82 lines · Ira Weiny
Quoted 23 lines · Alaa Mohamed
On ???/??/???? ??:??, Julia Lawall wrote:On Sat, 16 Apr 2022, Alaa Mohamed wrote:
Convert
kmap()tokmap_local_page()With
kmap_local_page(), the mapping is per thread, CPU local and not globally visible.It's not clearer.
I mean this " fix
kunmap_localpath value to take address of the mapped page" be more clearerThis is a general statement about the function. You
need to explain why it is appropriate to use it here. Unless it is the case that all calls to kmap should be converted to callkmap_local_page.It's required to convert all calls kmap to
kmap_local_page. So, I don't what should the commit message be?Quoted 7 lines
Is this will be good :
"
kmap_local_page()was recently developed as a replacement forkmap(). The
kmap_local_page()creates a mapping which is restricted to local use by a single thread of execution. "I think I am missing some thread context here. I'm not sure who said what above. So I'm going to start over.
Alaa,
It is important to remember that a good commit message says 2 things.
1) What is the problem you are trying to solve
2) Overview of the solutionFirst off I understand your frustration. In my opinion fixes and clean ups like this are very hard to write good commit messages for because so often the code diff seems so self explanatory. However, each code change comes at the identification of a problem. And remember that 'problem' does not always mean a bug fix.
The deprecation of
kmap()may not seem like a problem. I mean why can't we just leavekmap()as it is? It works right?But the problem is that the kmap (highmem) interface has become stale and its original purpose was targeted toward large memory systems with 32 bit kernels. There are very few systems being run like that any longer.
So how do we clean up the kmap interface to be more useful to the kernel community now that 32 bit kernels with highmem are so rare?
The community has identified that a first step of that is to move away from and eventually remove the
kmap()call. This is due to the call being incorrectly used to create long term mappings. Most calls tokmap()are not used incorrectly but those call sites needed something in betweenkmap()andkmap_atmoic(). That call iskmap_local_page().Now that
kmap_local_page()exists thekmap()calls can be audited and most (I hope most)[1] can be replaced withkmap_local_page().The change you have below is correct. But it lacks a good commit message. We need to cover the 2 points above.
1) Julia is asking why you needed to do this change. What is the problem or reason for this change? (Ira told you to is not a good reason. ;-)
PS In fact me telling you to may actually be a very bad reason... j/k ;-)
2) Why is this solution ok as part of the deprecation and removal of
kmap()?A final note; the 2 above points don't need a lot of text. Here I used 2 simple sentences.
Quoted 7 lines
https://lore.kernel.org/lkml/20220124015409.807587-2-ira.weiny at intel.com/
I hope this helps,
Ira[1] But not all... some uses of
kmap()have been identified as being pretty complex.
Thanks a lot for detailed explaining , yes you help me a lot.
Thanks again,
Alaa
Quoted 37 lines
Quoted 37 lines
julia
Signed-off-by Alaa Mohamed <[email protected]>---
changes in V2:
fixkunmap_localpath value to take address of the mapped page.
---
changes in V3:
edit commit message to be clearer
---drivers/net/ethernet/intel/igb/igb_ethtool.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)diff --git
a/drivers/net/ethernet/intel/igb/igb_ethtool.cb/drivers/net/ethernet/intel/igb/igb_ethtool.cindex2a5782063f4c..c14fc871dd41100644
---a/drivers/net/ethernet/intel/igb/igb_ethtool.c
+++b/drivers/net/ethernet/intel/igb/igb_ethtool.c
@@ -1798,14 +1798,14 @@ static int igb_check_lbtest_frame(structigb_rx_buffer*rx_buffer,frame_size >>= 1;- data =
kmap(rx_buffer->page);
+ data =kmap_local_page(rx_buffer->page);if (data[3] != 0xFF || data[frame_size + 10] != 0xBE || data[frame_size + 12] != 0xAF) match = false;-
kunmap(rx_buffer->page);
+kunmap_local(data);return match;}
--
2.35.2
Quoted 8 lines · Julia Lawall
Quoted 4 lines · Alaa Mohamed
Convert
kmap()tokmap_local_page()With
kmap_local_page(), the mapping is per thread, CPU local and not globally visible.It's not clearer.
I mean this " fix kunmap_local path value to take address of the mapped page" be more clearer
Quoted 3 lines
This is a general statement about the function. You
need to explain why it is appropriate to use it here. Unless it is the case that all calls to kmap should be converted to callkmap_local_page.
It's required to convert all calls kmap to kmap_local_page. So, I don't what should the commit message be?
Is this will be good :
"kmap_local_page() was recently developed as a replacement for kmap().? The kmap_local_page() creates a mapping which is restricted to local use by a single thread of execution. "
Quoted 40 lines
julia
Quoted 37 lines
Signed-off-by Alaa Mohamed <[email protected]>---
changes in V2:
fixkunmap_localpath value to take address of the mapped page.
---
changes in V3:
edit commit message to be clearer--- drivers/net/ethernet/intel/igb/igb_ethtool.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/net/ethernet/intel/igb/igb_ethtool.c +2
-3@@ -1798,14 +1798,14 @@ static int igb_check_lbtest_frame(struct igb_rx_buffer *rx_buffer, frame_size >>=1 ; - data =kmap (rx_buffer->page); + data =kmap_local_page (rx_buffer->page);if (data[3 ] !=0xFF || data[frame_size +10 ] !=0xBE || data[frame_size +12 ] !=0xAF ) match = false; -kunmap (rx_buffer->page); +kunmap_local (data);return match; } --2.35.2
Quoted 9 lines · Alaa Mohamed
Quoted 7 lines · Julia Lawall
Quoted 4 lines · Alaa Mohamed
Convert
kmap()tokmap_local_page()With
kmap_local_page(), the mapping is per thread, CPU local and not globally visible.
Quoted 8 lines
Quoted 1 line
It's not clearer.
I mean this " fix
kunmap_localpath value to take address of the mapped page" be more clearerQuoted 3 lines
This is a general statement about the function. You
need to explain why it is appropriate to use it here. Unless it is the case that all calls to kmap should be converted to callkmap_local_page.It's required to convert all calls kmap to
kmap_local_page. So, I don't what should the commit message be?
If all calls should be changed then you can also say that.
I thought that a previous commit on the outreachy list made some arguments about how the affacted value was just allocated and thus could not yet be shared.
julia
Quoted 49 lines
Is this will be good :
"
kmap_local_page()was recently developed as a replacement forkmap().? Thekmap_local_page()creates a mapping which is restricted to local use by a single thread of execution. "Quoted 42 lines
julia
Quoted 39 lines
Signed-off-by Alaa Mohamed <[email protected]>---
changes in V2:
fixkunmap_localpath value to take address of the mapped page.
---
changes in V3:
edit commit message to be clearer--- drivers/net/ethernet/intel/igb/igb_ethtool.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/net/ethernet/intel/igb/igb_ethtool.c +2
-2@@ -1798,14 +1798,14 @@ static int igb_check_lbtest_frame(struct igb_rx_buffer *rx_buffer, frame_size >>=1 ; - data =kmap (rx_buffer->page); + data =kmap_local_page (rx_buffer->page);if (data[3 ] !=0xFF || data[frame_size +10 ] !=0xBE || data[frame_size +12 ] !=0xAF ) match = false; -kunmap (rx_buffer->page); +kunmap_local (data);return match;}
--
2.35.2
Quoted 11 lines · On sabato 16 aprile 2022 16:09:58 CEST Julia Lawall wrote:
Quoted 8 lines · Alaa Mohamed
Quoted 6 lines · Julia Lawall
Quoted 3 lines · Alaa Mohamed
Convert
kmap()tokmap_local_page()With
kmap_local_page(), the mapping is per thread, CPU local and
not
Quoted 3 lines
Quoted 3 lines
Quoted 2 lines
Quoted 1 line
globally visible.
It's not clearer.
I mean this " fix
kunmap_localpath value to take address of the mapped
page"
Quoted 3 lines
Quoted 3 lines
be more clearer
Quoted 2 lines
This is a general statement about the function. You need to explain why it is appropriate to use it here. Unless it is
the
Quoted 1 line
Quoted 1 line
Quoted 1 line
case that all calls to kmap should be converted to call
kmap_local_page.
Quoted 1 line
Quoted 1 line
It's required to convert all calls kmap to
kmap_local_page. So, I don't
what
Quoted 3 lines
Quoted 1 line
should the commit message be?
If all calls should be changed then you can also say that.
If all calls should be changed with no regards to the surrounding contexts and special situations, we can just make an automated s/kmap()/ kmap_local_page()/ or something else similar :)
Thanks,
Fabio M. De Francesco
Quoted 2 lines
I thought that a previous commit on the outreachy list made some
arguments
Quoted 4 lines
about how the affacted value was just allocated and thus could not yet be shared.
julia
PATCH v3 1/1 intel: igb: igb_ethtool.c: Convert kmap() to kmap_local_page()
Quoted 5 lines · On sabato 16 aprile 2022 17:52:20 CEST Fabio M. De Francesco wrote:
Quoted 4 lines · On sabato 16 aprile 2022 16:09:58 CEST Julia Lawall wrote:
Quoted 1 line · Alaa Mohamed
Quoted 11 lines
Quoted 7 lines
Quoted 7 lines · Julia Lawall
Quoted 6 lines · Alaa Mohamed
Quoted 4 lines
Convert
kmap()tokmap_local_page()With
kmap_local_page(), the mapping is per thread, CPU local andnot
Quoted 3 lines
Quoted 3 lines
Quoted 2 lines
Quoted 1 line
globally visible.
It's not clearer.
I mean this " fix
kunmap_localpath value to take address of the
mapped
Quoted 8 lines
page"
Quoted 3 lines
Quoted 3 lines
be more clearer
Quoted 2 lines
This is a general statement about the function. You need to explain why it is appropriate to use it here. Unless it is
the
Quoted 1 line
Quoted 1 line
Quoted 1 line
case that all calls to kmap should be converted to call
kmap_local_page.Quoted 1 line
Quoted 1 line
It's required to convert all calls kmap to
kmap_local_page. So, I
don't
Quoted 6 lines
what
Quoted 3 lines
Quoted 1 line
should the commit message be?
If all calls should be changed then you can also say that.
If all calls should be changed with no regards to the surrounding
contexts
Quoted 2 lines
and special situations, we can just make an automated s/kmap()/ kmap_local_page()/ or something else similar :)
Obviously, I was just kidding because we cannot massively and blindly change all kmap() calls to kmap_local_page().
IMO, here the changes in code are good but Julia's objections are legitimate too.
Thanks,
Fabio
Quoted 4 lines
Quoted 2 lines
I thought that a previous commit on the outreachy list made some
arguments
Quoted 1 line
about how the affacted value was just allocated and thus could not yet
be
Quoted 4 lines
Quoted 3 lines
shared.
julia
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osuosl.org/pipermail/intel-wired-lan/attachments/20220416/51c29e10/attachment-0001.html>
PATCH v3 1/1 intel: igb: igb_ethtool.c: Convert kmap() to kmap_local_page()
In reply to Fabio M. De FrancescoQuoted 5 lines · On sabato 16 aprile 2022 17:52:20 CEST Fabio M. De Francesco wrote:
Quoted 2 lines · On sabato 16 aprile 2022 16:09:58 CEST Julia Lawall wrote:
If all calls should be changed then you can also say that.
If all calls should be changed with no regards to the surrounding
contexts
Quoted 2 lines
and special situations, we can just make an automated s/kmap()/ kmap_local_page()/ or something else similar :)
Hi Julia,
Of course I was just kidding when talking of massively automated substitutions. They are not feasible and we cannot blindly replace all kmap() calls with kmap_local_page().
Although these code changes look good, your objections are appropriate and legitimate.
Not all kmap() calls can be changed to kmap_local_page() and, if someone wants to make such replacements, they should also "prove" somehow that they are doing the right changes in that specific context.
For example, the following is one of those cases where such a replacement is not allowed and a different solution has yet to be found:
https://lore.kernel.org/lkml/2a7030f5-d55f-94c7-90ba-5a57235159f6 at amd.com/
Furthermore, if people cannot "prove" that this change is feasible, their patches will probably be ignored / rejected just because many maintainers still don't know if those changes are correct and safe.
Whoever wants to do these changes should understand the specific context in which they are working.
For example, there have also been cases where alloc_page() + kmap() was simply replaced by kmalloc(). Sure!
If you are interested to see how and why, please take a look at the commit 633b0616cfe0 ("x86/sgx: Remove unnecessary kmap() from sgx_ioc_enclave_init()") from Ira Weiny.
Regards,
Fabio
Quoted 4 lines
Quoted 2 lines
I thought that a previous commit on the outreachy list made some
arguments
Quoted 1 line
about how the affacted value was just allocated and thus could not yet
be
Quoted 4 lines
Quoted 3 lines
shared.
julia
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osuosl.org/pipermail/intel-wired-lan/attachments/20220416/daee33e4/attachment-0001.html>
Quoted 1 line · On sabato 16 aprile 2022 17:52:20 CEST Fabio M. De Francesco wrote:
If all calls should be changed with no regards to the surrounding
contexts
Quoted 2 lines
and special situations, we can just make an automated s/kmap()/ kmap_local_page()/ or something else similar
(I'm afraid that somehow I messed up with the HTML filters in KMail therefore I have to send this email again to the Outreachy list because this message has already been rejected twice - I hope this time it works).
Hi Julia,
Of course I was just kidding when talking of massively automated
substitutions. They are not feasible and we cannot blindly replace all kmap() calls with kmap_local_page().
Although these code changes look good, your objections are appropriate and legitimate.
Not all kmap() calls can be changed to kmap_local_page() and, if someone wants to make such replacements, they should also "prove" somehow that they are doing the right changes in that specific context.
For example, the following is one of those cases where such a replacement is not allowed and a different solution has yet to be found:
https://lore.kernel.org/lkml/[email protected]/
Furthermore, if people cannot "prove" that this change is feasible, their patches will probably be ignored / rejected just because many maintainers still don't know if those changes are correct and safe.
Whoever wants to do these changes should understand the specific context in which they are working.
For example, there have also been cases where alloc_page() + kmap() was simply replaced by kmalloc(). Sure!
If you are interested to see how and why, please take a look at the commit 633b0616cfe0 ("x86/sgx: Remove unnecessary kmap() from sgx_ioc_enclave_init()") from Ira Weiny.
Regards,
Fabio
Quoted 24 lines · Fabio M. De Francesco
Quoted 1 line · On sabato 16 aprile 2022 17:52:20 CEST Fabio M. De Francesco wrote:
If all calls should be changed with no regards to the surrounding
contexts
Quoted 2 lines
and special situations, we can just make an automated s/kmap()/ kmap_local_page()/ or something else similar
(I'm afraid that somehow I messed up with the HTML filters in KMail therefore I have to send this email again to the Outreachy list because this message has already been rejected twice - I hope this time it works).
Hi Julia,
Of course I was just kidding when talking of massively automated
substitutions. They are not feasible and we cannot blindly replace all
kmap()calls withkmap_local_page().Although these code changes look good, your objections are appropriate and legitimate.
Not all
kmap()calls can be changed tokmap_local_page()and, if someone wants to make such replacements, they should also "prove" somehow that they are doing the right changes in that specific context.
Quoted 8 lines
For example, the following is one of those cases where such a replacement is not allowed and a different solution has yet to be found:
https://lore.kernel.org/lkml/[email protected]/
Furthermore, if people cannot "prove" that this change is feasible, their patches will probably be ignored / rejected just because many maintainers still don't know if those changes are correct and safe.
I think that all patches in which the log message does not explain why the change is correct should be rejected. Not because the maintainer can't do the proof himself, but because the reasoning should be explicit in the git history.
julia
Quoted 19 lines
Whoever wants to do these changes should understand the specific context in which they are working.
For example, there have also been cases where
alloc_page()+kmap()was simply replaced bykmalloc(). Sure!If you are interested to see how and why, please take a look at the commit
633b0616cfe0("x86/sgx: Remove unnecessarykmap()fromsgx_ioc_enclave_init()") from Ira Weiny.Regards,
Fabio