Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

【6.9】飞腾 PWM 驱动无法构建 #5

Open
Tracked by #11 ...
MingcongBai opened this issue Jul 1, 2024 · 1 comment
Open
Tracked by #11 ...

【6.9】飞腾 PWM 驱动无法构建 #5

MingcongBai opened this issue Jul 1, 2024 · 1 comment

Comments

@MingcongBai
Copy link

构建时遇到如下错误:

drivers/pwm/pwm-phytium.c: In function ‘pwm_phytium_free’:
drivers/pwm/pwm-phytium.c:112:31: error: implicit declaration of function ‘pwm_get_chip_data’; did you mean ‘irq_get_chip_data’? [-Werror=implicit-function-declaration]
  112 |         devm_kfree(chip->dev, pwm_get_chip_data(pwm));
      |                               ^~~~~~~~~~~~~~~~~
      |                               irq_get_chip_data
drivers/pwm/pwm-phytium.c:112:31: error: passing argument 2 of ‘devm_kfree’ makes pointer from integer without a cast [-Werror=int-conversion]
  112 |         devm_kfree(chip->dev, pwm_get_chip_data(pwm));
      |                               ^~~~~~~~~~~~~~~~~~~~~~
      |                               |
      |                               int
In file included from ./include/linux/platform_device.h:13,
                 from drivers/pwm/pwm-phytium.c:16:
./include/linux/device.h:341:49: note: expected ‘const void *’ but argument is of type ‘int’
  341 | void devm_kfree(struct device *dev, const void *p);
      |                                     ~~~~~~~~~~~~^
drivers/pwm/pwm-phytium.c:113:9: error: implicit declaration of function ‘pwm_set_chip_data’; did you mean ‘irq_set_chip_data’? [-Werror=implicit-function-declaration]
  113 |         pwm_set_chip_data(pwm, NULL);
      |         ^~~~~~~~~~~~~~~~~
      |         irq_set_chip_data
drivers/pwm/pwm-phytium.c: At top level:
drivers/pwm/pwm-phytium.c:384:10: error: ‘const struct pwm_ops’ has no member named ‘owner’
  384 |         .owner   = THIS_MODULE,
      |          ^~~~~
In file included from ./arch/arm64/include/asm/alternative.h:9,
                 from ./arch/arm64/include/asm/lse.h:14,
                 from ./arch/arm64/include/asm/cmpxchg.h:14,
                 from ./arch/arm64/include/asm/atomic.h:16,
                 from ./include/linux/atomic.h:7,
                 from ./include/asm-generic/bitops/atomic.h:5,
                 from ./arch/arm64/include/asm/bitops.h:25,
                 from ./include/linux/bitops.h:68,
                 from drivers/pwm/pwm-phytium.c:8:
./include/linux/init.h:180:21: error: initialization of ‘int (*)(struct pwm_chip *, struct pwm_device *, struct pwm_state *)’ from incompatible pointer type ‘struct module *’ [-Werror=incompatible-pointer-types]
  180 | #define THIS_MODULE (&__this_module)
      |                     ^
drivers/pwm/pwm-phytium.c:384:20: note: in expansion of macro ‘THIS_MODULE’
  384 |         .owner   = THIS_MODULE,
      |                    ^~~~~~~~~~~
./include/linux/init.h:180:21: note: (near initialization for ‘pwm_phytium_ops.get_state’)
  180 | #define THIS_MODULE (&__this_module)
      |                     ^
drivers/pwm/pwm-phytium.c:384:20: note: in expansion of macro ‘THIS_MODULE’
  384 |         .owner   = THIS_MODULE,
      |                    ^~~~~~~~~~~
drivers/pwm/pwm-phytium.c: In function ‘pwm_phytium_probe’:
drivers/pwm/pwm-phytium.c:462:19: error: ‘struct pwm_chip’ has no member named ‘base’
  462 |         chip->chip.base = -1;
      |                   ^
drivers/pwm/pwm-phytium.c:468:27: error: ‘struct pwm_chip’ has no member named ‘of_pwm_n_cells’
  468 |                 chip->chip.of_pwm_n_cells = 3;
      |                           ^
cc1: all warnings being treated as errors

此处的错误应该是 6.7 前后两个上游更改导致的:

  1. 上游移除了 linux/pwm.hpwm_device->pwm 的定义,提交信息如下:
    pwm: Drop unused member "pwm" from struct pwm_device
    
    This member is only assigned to and never read. So drop it.
    
    Signed-off-by: Uwe Kleine-König <[email protected]>
    Signed-off-by: Thierry Reding <[email protected]>
  1. 移除了 pwm_[gs]et_chip_data,导致驱动 .free 成员实现无法继续使用
@MingcongBai
Copy link
Author

cc @Avenger-285714 @opsiff

MingcongBai pushed a commit that referenced this issue Nov 18, 2024
Disable strict aliasing, as has been done in the kernel proper for decades
(literally since before git history) to fix issues where gcc will optimize
away loads in code that looks 100% correct, but is _technically_ undefined
behavior, and thus can be thrown away by the compiler.

E.g. arm64's vPMU counter access test casts a uint64_t (unsigned long)
pointer to a u64 (unsigned long long) pointer when setting PMCR.N via
u64p_replace_bits(), which gcc-13 detects and optimizes away, i.e. ignores
the result and uses the original PMCR.

The issue is most easily observed by making set_pmcr_n() noinline and
wrapping the call with printf(), e.g. sans comments, for this code:

  printf("orig = %lx, next = %lx, want = %lu\n", pmcr_orig, pmcr, pmcr_n);
  set_pmcr_n(&pmcr, pmcr_n);
  printf("orig = %lx, next = %lx, want = %lu\n", pmcr_orig, pmcr, pmcr_n);

gcc-13 generates:

 0000000000401c90 <set_pmcr_n>:
  401c90:       f9400002        ldr     x2, [x0]
  401c94:       b3751022        bfi     x2, x1, #11, #5
  401c98:       f9000002        str     x2, [x0]
  401c9c:       d65f03c0        ret

 0000000000402660 <test_create_vpmu_vm_with_pmcr_n>:
  402724:       aa1403e3        mov     x3, x20
  402728:       aa1503e2        mov     x2, x21
  40272c:       aa1603e0        mov     x0, x22
  402730:       aa1503e1        mov     x1, x21
  402734:       940060ff        bl      41ab30 <_IO_printf>
  402738:       aa1403e1        mov     x1, x20
  40273c:       910183e0        add     x0, sp, #0x60
  402740:       97fffd54        bl      401c90 <set_pmcr_n>
  402744:       aa1403e3        mov     x3, x20
  402748:       aa1503e2        mov     x2, x21
  40274c:       aa1503e1        mov     x1, x21
  402750:       aa1603e0        mov     x0, x22
  402754:       940060f7        bl      41ab30 <_IO_printf>

with the value stored in [sp + 0x60] ignored by both printf() above and
in the test proper, resulting in a false failure due to vcpu_set_reg()
simply storing the original value, not the intended value.

  $ ./vpmu_counter_access
  Random seed: 0x6b8b4567
  orig = 3040, next = 3040, want = 0
  orig = 3040, next = 3040, want = 0
  ==== Test Assertion Failure ====
    aarch64/vpmu_counter_access.c:505: pmcr_n == get_pmcr_n(pmcr)
    pid=71578 tid=71578 errno=9 - Bad file descriptor
       1        0x400673: run_access_test at vpmu_counter_access.c:522
       2         (inlined by) main at vpmu_counter_access.c:643
       3        0x4132d7: __libc_start_call_main at libc-start.o:0
       4        0x413653: __libc_start_main at ??:0
       5        0x40106f: _start at ??:0
    Failed to update PMCR.N to 0 (received: 6)

Somewhat bizarrely, gcc-11 also exhibits the same behavior, but only if
set_pmcr_n() is marked noinline, whereas gcc-13 fails even if set_pmcr_n()
is inlined in its sole caller.

Cc: [email protected]
Link: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116912
Signed-off-by: Sean Christopherson <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant