Skip to content

Commit

Permalink
linux/ena: Fix compilation of UEK3/4
Browse files Browse the repository at this point in the history
Background
----------
Commit [1] replaced the older representation of dma attributes
from struct dma_attr to an unsigned long of flags.

Commit [2] added dma_unmap_page_attr(), which receives dma attributes.

Both of these commits are needed for the code to compile
without any changes.

Issue 1
-------
Compilation failure in UEK4 due to redefinition of page_ref_count().

Searched the uek git ([3]) and found that page_ref_count() was added
in kernel version 4.1.12-124.43.1. Added the necessary ifdef
conditions to kcompat to define page_ref_count() in UEK only for
older kernels.

Issue 2
-------
Compilation failure due to undefined dma_unmap_page_attrs()

According to uek git [3]:
1. dma_unmap_page_attrs() was first introduced to UEK4 in
   kernel 4.1.12-105.0.0, with struct dma_attrs as type of attributes.
2. Commit [1] was never backported to UEK4.
3. UEK5 has kernel 4.14 [4] , which includes commits [1] and [2]
   and therefore doesn't need any kcpompat fixes for this issue.

From the above 3 it follows that:
1. For kernels < 4.1.12-105.0.0 dma_unmap_page_attrs() needs to be
   defined in kcompat.
2. For 4.1.12-105.0.0 =< kernels in UEK4, kcompat needs to translate
   unsigned long attributes to struct dma_attrs to be used by
   dma_unmap_page_attrs(). For the upper kernel we use 4.1.13, since
   it is larger than all UEK4 kernels that are of the form 4.1.12-X.Y.Z
3. All other kernels need no fixes for dma_unmap_page_attrs()

This commit implements the above conclusions.
These kcompat fixes also fix the compilation of UEK3.

[1]: torvalds/linux@00085f1
[2]: torvalds/linux@0495c3d
[3]: https://github.com/oracle/linux-uek
[4]: https://docs.oracle.com/en/operating-systems/uek/

Signed-off-by: Arthur Kiyanovski <[email protected]>
Change-Id: I58427404f18b746f4ab56989ad25fdcff62a7d64
  • Loading branch information
akiyano committed May 17, 2023
1 parent d95afdf commit bd2ac32
Showing 1 changed file with 27 additions and 9 deletions.
36 changes: 27 additions & 9 deletions kernel/linux/ena/kcompat.h
Original file line number Diff line number Diff line change
Expand Up @@ -848,17 +848,32 @@ static inline void netdev_rss_key_fill(void *buffer, size_t len)

#if ((LINUX_VERSION_CODE < KERNEL_VERSION(4, 6 ,0)) && \
!(RHEL_RELEASE_CODE && RHEL_RELEASE_CODE >= RHEL_RELEASE_VERSION(7,3)))
/* Linux versions 4.4.216 - 4.5 (non inclusive) back propagated page_ref_count
* function from kernel 4.6. To make things more difficult, Ubuntu didn't add
* these changes to its 4.4.* kernels
/* Linux versions 4.4.216 - 4.5 (non inclusive) back propagated
* page_ref_count() from kernel 4.6.
* Ubuntu didn't add these changes to its 4.4.* kernels.
* UEK added this function in kernel 4.1.12-124.43.1
* Here is a figure that shows all of the cases:
* Legend:
* -------- page_ref_count() is present in the kernel
* ******** page_ref_count() is missing in the kernel
*
* Distro\Kernel 4.1.12-124.43.1 4.4.216 4.5 4.6
* | | | |
* Upstrem kernel ***********|**************|--------|******|
* | | | |
* Ubuntu ***********|**************|********|******|
* | | | |
* UEK ***********|--------------|--------|------|
*/
#if !(KERNEL_VERSION(4, 4 ,216) <= LINUX_VERSION_CODE && LINUX_VERSION_CODE < KERNEL_VERSION(4, 5 ,0)) ||\
defined(UBUNTU_VERSION_CODE)
#if (defined(IS_UEK) && !ENA_KERNEL_VERSION_GTE(4, 1, 12, 124, 43, 1)) || \
(defined(ubuntu)) || \
(!defined(IS_UEK) && !defined(ubuntu) && \
!(KERNEL_VERSION(4, 4, 216) <= LINUX_VERSION_CODE && LINUX_VERSION_CODE < KERNEL_VERSION(4, 5, 0)))
static inline int page_ref_count(struct page *page)
{
return atomic_read(&page->_count);
}
#endif /* !(KERNEL_VERSION(4, 4 ,216) <= LINUX_VERSION_CODE && LINUX_VERSION_CODE < KERNEL_VERSION(4, 5 ,0)) */
#endif /* (defined(IS_UEK) && !ENA_KERNEL_VERSION_GTE(4, 1, 12, 124, 43, 1)) ... */

static inline void page_ref_inc(struct page *page)
{
Expand Down Expand Up @@ -1089,7 +1104,8 @@ static inline void ena_netif_napi_add(struct net_device *dev,
}

#if (RHEL_RELEASE_CODE && (RHEL_RELEASE_CODE <= RHEL_RELEASE_VERSION(7, 4))) || \
(defined(UBUNTU_VERSION_CODE) && UBUNTU_VERSION_CODE < UBUNTU_VERSION(4, 5, 0, 0))
(defined(UBUNTU_VERSION_CODE) && UBUNTU_VERSION_CODE < UBUNTU_VERSION(4, 5, 0, 0)) || \
(defined(IS_UEK) && !ENA_KERNEL_VERSION_GTE(4, 1, 12, 105, 0, 0))
static inline void dma_unmap_page_attrs(struct device *dev,
dma_addr_t addr, size_t size,
enum dma_data_direction dir,
Expand All @@ -1107,7 +1123,8 @@ static inline void dma_unmap_page_attrs(struct device *dev,
#if (RHEL_RELEASE_CODE && (RHEL_RELEASE_CODE <= RHEL_RELEASE_VERSION(7, 9)) && \
(RHEL_RELEASE_CODE >= RHEL_RELEASE_VERSION(7, 0)) && \
(LINUX_VERSION_CODE != KERNEL_VERSION(4, 14, 0))) || \
(defined(UBUNTU_VERSION_CODE) && UBUNTU_VERSION_CODE < UBUNTU_VERSION(4, 5, 0, 0))
(defined(UBUNTU_VERSION_CODE) && UBUNTU_VERSION_CODE < UBUNTU_VERSION(4, 5, 0, 0)) || \
(defined(IS_UEK) && LINUX_VERSION_CODE < KERNEL_VERSION(4, 1, 13))
#define ENA_DMA_ATTR_SKIP_CPU_SYNC (1 << DMA_ATTR_SKIP_CPU_SYNC)
#elif (RHEL_RELEASE_CODE && (RHEL_RELEASE_CODE <= RHEL_RELEASE_VERSION(6, 10)))
#define ENA_DMA_ATTR_SKIP_CPU_SYNC 0
Expand All @@ -1122,7 +1139,8 @@ static inline void ena_dma_unmap_page_attrs(struct device *dev,
{
#if (RHEL_RELEASE_CODE && (RHEL_RELEASE_CODE <= RHEL_RELEASE_VERSION(7, 9)) && \
(LINUX_VERSION_CODE != KERNEL_VERSION(4, 14, 0))) || \
(defined(UBUNTU_VERSION_CODE) && UBUNTU_VERSION_CODE < UBUNTU_VERSION(4, 5, 0, 0))
(defined(UBUNTU_VERSION_CODE) && UBUNTU_VERSION_CODE < UBUNTU_VERSION(4, 5, 0, 0)) || \
(defined(IS_UEK) && LINUX_VERSION_CODE < KERNEL_VERSION(4, 1, 13))
struct dma_attrs dma_attrs;

init_dma_attrs(&dma_attrs);
Expand Down

0 comments on commit bd2ac32

Please sign in to comment.