2022-04-15 22:01:38

by Alaa Mohamed

[permalink] [raw]
Subject: [PATCH] intel: igb: igb_ethtool.c: Convert kmap() to kmap_local_page()

The use of kmap() is being deprecated in favor of kmap_local_page()
where it is feasible.

With kmap_local_page(), the mapping is per thread, CPU local and not
globally visible.

Signed-off-by: Alaa Mohamed <[email protected]>
---
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.c b/drivers/net/ethernet/intel/igb/igb_ethtool.c
index 2a5782063f4c..ba93aa4ae6a0 100644
--- 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(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(rx_buffer->page);

return match;
}
--
2.35.2


2022-04-16 00:36:56

by Ira Weiny

[permalink] [raw]
Subject: Re: [PATCH] intel: igb: igb_ethtool.c: Convert kmap() to kmap_local_page()

On Fri, Apr 15, 2022 at 10:53:07PM +0200, Alaa Mohamed wrote:
> The use of kmap() is being deprecated in favor of kmap_local_page()
> where it is feasible.
>
> With kmap_local_page(), the mapping is per thread, CPU local and not
> globally visible.
>
> Signed-off-by: Alaa Mohamed <[email protected]>
> ---
> 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.c b/drivers/net/ethernet/intel/igb/igb_ethtool.c
> index 2a5782063f4c..ba93aa4ae6a0 100644
> --- 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(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(rx_buffer->page);

kunmap_local() is different from kunmap(). It takes an address within the
mapped page. From the kdoc:

/**
* kunmap_local - Unmap a page mapped via kmap_local_page().
* @__addr: An address within the page mapped
*
* @__addr can be any address within the mapped page. Commonly it is the
* address return from kmap_local_page(), but it can also include offsets.
*
* Unmapping should be done in the reverse order of the mapping. See
* kmap_local_page() for details.
*/
#define kunmap_local(__addr) \
...


Ira

>
> return match;
> }
> --
> 2.35.2
>

2022-04-16 02:51:07

by Alaa Mohamed

[permalink] [raw]
Subject: Re: [PATCH] intel: igb: igb_ethtool.c: Convert kmap() to kmap_local_page()


On ١٥‏/٤‏/٢٠٢٢ ٢٣:٤٠, Ira Weiny wrote:
> On Fri, Apr 15, 2022 at 10:53:07PM +0200, Alaa Mohamed wrote:
>> The use of kmap() is being deprecated in favor of kmap_local_page()
>> where it is feasible.
>>
>> With kmap_local_page(), the mapping is per thread, CPU local and not
>> globally visible.
>>
>> Signed-off-by: Alaa Mohamed <[email protected]>
>> ---
>> 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.c b/drivers/net/ethernet/intel/igb/igb_ethtool.c
>> index 2a5782063f4c..ba93aa4ae6a0 100644
>> --- 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(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(rx_buffer->page);
> kunmap_local() is different from kunmap(). It takes an address within the
> mapped page. From the kdoc:
>
> /**
> * kunmap_local - Unmap a page mapped via kmap_local_page().
> * @__addr: An address within the page mapped
> *
> * @__addr can be any address within the mapped page. Commonly it is the
> * address return from kmap_local_page(), but it can also include offsets.
> *
> * Unmapping should be done in the reverse order of the mapping. See
> * kmap_local_page() for details.
> */
> #define kunmap_local(__addr) \
> ...
Got it , Thanks
>
>
> Ira
>
>>
>> return match;
>> }
>> --
>> 2.35.2
>>

2022-04-16 09:09:33

by Julia Lawall

[permalink] [raw]
Subject: Re: [PATCH] intel: igb: igb_ethtool.c: Convert kmap() to kmap_local_page()



On Fri, 15 Apr 2022, Alaa Mohamed wrote:

> The use of kmap() is being deprecated in favor of kmap_local_page()
> where it is feasible.

And why is it feasible here?

julia

>
> With kmap_local_page(), the mapping is per thread, CPU local and not
> globally visible.
>
> Signed-off-by: Alaa Mohamed <[email protected]>
> ---
> 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.c b/drivers/net/ethernet/intel/igb/igb_ethtool.c
> index 2a5782063f4c..ba93aa4ae6a0 100644
> --- 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(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(rx_buffer->page);
>
> return match;
> }
> --
> 2.35.2
>
>
>