diff mbox series

[FFmpeg-devel] avutil: [LA] use getauxval to do runtime check.

Message ID 20230214122556.24384-1-yinshiyou-hf@loongson.cn
State Accepted
Commit b09f31af1b5e483e614d0f5d673753c5ab778034
Headers show
Series [FFmpeg-devel] avutil: [LA] use getauxval to do runtime check. | expand

Checks

Context Check Description
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Shiyou Yin Feb. 14, 2023, 12:25 p.m. UTC
Replace cpucfg with getauxval to avoid crash in case of
some processor capabilities are not supportted by kernel used.
---
 libavutil/loongarch/cpu.c | 24 ++++++++----------------
 1 file changed, 8 insertions(+), 16 deletions(-)

Comments

Steven Liu Feb. 23, 2023, 7:48 a.m. UTC | #1
Shiyou Yin <yinshiyou-hf@loongson.cn> 于2023年2月14日周二 20:26写道:
>
> Replace cpucfg with getauxval to avoid crash in case of
> some processor capabilities are not supportted by kernel used.
> ---
>  libavutil/loongarch/cpu.c | 24 ++++++++----------------
>  1 file changed, 8 insertions(+), 16 deletions(-)
>
> diff --git a/libavutil/loongarch/cpu.c b/libavutil/loongarch/cpu.c
> index e4b240bc44..cad8504fde 100644
> --- a/libavutil/loongarch/cpu.c
> +++ b/libavutil/loongarch/cpu.c
> @@ -21,26 +21,18 @@
>
>  #include <stdint.h>
>  #include "cpu.h"
> +#include <sys/auxv.h>
>
> -#define LOONGARCH_CFG2 0x2
> -#define LOONGARCH_CFG2_LSX    (1 << 6)
> -#define LOONGARCH_CFG2_LASX   (1 << 7)
> -
> -static int cpu_flags_cpucfg(void)
> +#define LA_HWCAP_LSX    (1<<4)
> +#define LA_HWCAP_LASX   (1<<5)
> +static int cpu_flags_getauxval(void)
>  {
>      int flags = 0;
> -    uint32_t cfg2 = 0;
> -
> -    __asm__ volatile(
> -        "cpucfg %0, %1 \n\t"
> -        : "+&r"(cfg2)
> -        : "r"(LOONGARCH_CFG2)
> -    );
> +    int flag  = (int)getauxval(AT_HWCAP);
>
> -    if (cfg2 & LOONGARCH_CFG2_LSX)
> +    if (flag & LA_HWCAP_LSX)
>          flags |= AV_CPU_FLAG_LSX;
> -
> -    if (cfg2 & LOONGARCH_CFG2_LASX)
> +    if (flag & LA_HWCAP_LASX)
>          flags |= AV_CPU_FLAG_LASX;
>
>      return flags;
> @@ -49,7 +41,7 @@ static int cpu_flags_cpucfg(void)
>  int ff_get_cpu_flags_loongarch(void)
>  {
>  #if defined __linux__
> -    return cpu_flags_cpucfg();
> +    return cpu_flags_getauxval();
>  #else
>      /* Assume no SIMD ASE supported */
>      return 0;
> --
> 2.20.1
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".


LGTM

Thanks
Steven
Shiyou Yin Feb. 27, 2023, 1:03 a.m. UTC | #2
> 2023年2月23日 15:48,Steven Liu <lingjiujianke@gmail.com> 写道:
> 
> Shiyou Yin <yinshiyou-hf@loongson.cn> 于2023年2月14日周二 20:26写道:
>> 
>> Replace cpucfg with getauxval to avoid crash in case of
>> some processor capabilities are not supportted by kernel used.
>> ---
>> libavutil/loongarch/cpu.c | 24 ++++++++----------------
>> 1 file changed, 8 insertions(+), 16 deletions(-)
>> 
>> diff --git a/libavutil/loongarch/cpu.c b/libavutil/loongarch/cpu.c
>> index e4b240bc44..cad8504fde 100644
>> --- a/libavutil/loongarch/cpu.c
>> +++ b/libavutil/loongarch/cpu.c
>> @@ -21,26 +21,18 @@
>> 
>> #include <stdint.h>
>> #include "cpu.h"
>> +#include <sys/auxv.h>
>> 
>> -#define LOONGARCH_CFG2 0x2
>> -#define LOONGARCH_CFG2_LSX    (1 << 6)
>> -#define LOONGARCH_CFG2_LASX   (1 << 7)
>> -
>> -static int cpu_flags_cpucfg(void)
>> +#define LA_HWCAP_LSX    (1<<4)
>> +#define LA_HWCAP_LASX   (1<<5)
>> +static int cpu_flags_getauxval(void)
>> {
>>     int flags = 0;
>> -    uint32_t cfg2 = 0;
>> -
>> -    __asm__ volatile(
>> -        "cpucfg %0, %1 \n\t"
>> -        : "+&r"(cfg2)
>> -        : "r"(LOONGARCH_CFG2)
>> -    );
>> +    int flag  = (int)getauxval(AT_HWCAP);
>> 
>> -    if (cfg2 & LOONGARCH_CFG2_LSX)
>> +    if (flag & LA_HWCAP_LSX)
>>         flags |= AV_CPU_FLAG_LSX;
>> -
>> -    if (cfg2 & LOONGARCH_CFG2_LASX)
>> +    if (flag & LA_HWCAP_LASX)
>>         flags |= AV_CPU_FLAG_LASX;
>> 
>>     return flags;
>> @@ -49,7 +41,7 @@ static int cpu_flags_cpucfg(void)
>> int ff_get_cpu_flags_loongarch(void)
>> {
>> #if defined __linux__
>> -    return cpu_flags_cpucfg();
>> +    return cpu_flags_getauxval();
>> #else
>>     /* Assume no SIMD ASE supported */
>>     return 0;
>> --
>> 2.20.1
>> 
>> _______________________________________________
>> ffmpeg-devel mailing list
>> ffmpeg-devel@ffmpeg.org
>> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>> 
>> To unsubscribe, visit link above, or email
>> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
> 
> 
> LGTM
> 
> Thanks
> Steven
> _______________________________________________

Could you please help to merge this patch.
Steven Liu Feb. 27, 2023, 2:47 a.m. UTC | #3
Shiyou Yin <yinshiyou-hf@loongson.cn> 于2023年2月27日周一 09:03写道:
>
>
>
> > 2023年2月23日 15:48,Steven Liu <lingjiujianke@gmail.com> 写道:
> >
> > Shiyou Yin <yinshiyou-hf@loongson.cn> 于2023年2月14日周二 20:26写道:
> >>
> >> Replace cpucfg with getauxval to avoid crash in case of
> >> some processor capabilities are not supportted by kernel used.
> >> ---
> >> libavutil/loongarch/cpu.c | 24 ++++++++----------------
> >> 1 file changed, 8 insertions(+), 16 deletions(-)
> >>
> >> diff --git a/libavutil/loongarch/cpu.c b/libavutil/loongarch/cpu.c
> >> index e4b240bc44..cad8504fde 100644
> >> --- a/libavutil/loongarch/cpu.c
> >> +++ b/libavutil/loongarch/cpu.c
> >> @@ -21,26 +21,18 @@
> >>
> >> #include <stdint.h>
> >> #include "cpu.h"
> >> +#include <sys/auxv.h>
> >>
> >> -#define LOONGARCH_CFG2 0x2
> >> -#define LOONGARCH_CFG2_LSX    (1 << 6)
> >> -#define LOONGARCH_CFG2_LASX   (1 << 7)
> >> -
> >> -static int cpu_flags_cpucfg(void)
> >> +#define LA_HWCAP_LSX    (1<<4)
> >> +#define LA_HWCAP_LASX   (1<<5)
> >> +static int cpu_flags_getauxval(void)
> >> {
> >>     int flags = 0;
> >> -    uint32_t cfg2 = 0;
> >> -
> >> -    __asm__ volatile(
> >> -        "cpucfg %0, %1 \n\t"
> >> -        : "+&r"(cfg2)
> >> -        : "r"(LOONGARCH_CFG2)
> >> -    );
> >> +    int flag  = (int)getauxval(AT_HWCAP);
> >>
> >> -    if (cfg2 & LOONGARCH_CFG2_LSX)
> >> +    if (flag & LA_HWCAP_LSX)
> >>         flags |= AV_CPU_FLAG_LSX;
> >> -
> >> -    if (cfg2 & LOONGARCH_CFG2_LASX)
> >> +    if (flag & LA_HWCAP_LASX)
> >>         flags |= AV_CPU_FLAG_LASX;
> >>
> >>     return flags;
> >> @@ -49,7 +41,7 @@ static int cpu_flags_cpucfg(void)
> >> int ff_get_cpu_flags_loongarch(void)
> >> {
> >> #if defined __linux__
> >> -    return cpu_flags_cpucfg();
> >> +    return cpu_flags_getauxval();
> >> #else
> >>     /* Assume no SIMD ASE supported */
> >>     return 0;
> >> --
> >> 2.20.1
> >>
> >> _______________________________________________
> >> ffmpeg-devel mailing list
> >> ffmpeg-devel@ffmpeg.org
> >> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> >>
> >> To unsubscribe, visit link above, or email
> >> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
> >
> >
> > LGTM
> >
> > Thanks
> > Steven
> > _______________________________________________
>
> Could you please help to merge this patch.


I have no permission now, maybe there have some problem?

(base) adeMacBook-Pro:project liuqi$ git clone git@source.ffmpeg.org:ffmpeg
正克隆到 'ffmpeg'...
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@    WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!     @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that a host key has just been changed.
The fingerprint for the ED25519 key sent by the remote host is
SHA256:dUNFtMwS3Z25nnzFF8UPYWsE0WiUR4majWLbWrsHBXU.
Please contact your system administrator.


Thanks
Steven
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
Steven Liu Feb. 27, 2023, 3:17 a.m. UTC | #4
Steven Liu <lingjiujianke@gmail.com> 于2023年2月27日周一 10:47写道:
>
> Shiyou Yin <yinshiyou-hf@loongson.cn> 于2023年2月27日周一 09:03写道:
> >
> >
> >
> > > 2023年2月23日 15:48,Steven Liu <lingjiujianke@gmail.com> 写道:
> > >
> > > Shiyou Yin <yinshiyou-hf@loongson.cn> 于2023年2月14日周二 20:26写道:
> > >>
> > >> Replace cpucfg with getauxval to avoid crash in case of
> > >> some processor capabilities are not supportted by kernel used.
> > >> ---
> > >> libavutil/loongarch/cpu.c | 24 ++++++++----------------
> > >> 1 file changed, 8 insertions(+), 16 deletions(-)
> > >>
> > >> diff --git a/libavutil/loongarch/cpu.c b/libavutil/loongarch/cpu.c
> > >> index e4b240bc44..cad8504fde 100644
> > >> --- a/libavutil/loongarch/cpu.c
> > >> +++ b/libavutil/loongarch/cpu.c
> > >> @@ -21,26 +21,18 @@
> > >>
> > >> #include <stdint.h>
> > >> #include "cpu.h"
> > >> +#include <sys/auxv.h>
> > >>
> > >> -#define LOONGARCH_CFG2 0x2
> > >> -#define LOONGARCH_CFG2_LSX    (1 << 6)
> > >> -#define LOONGARCH_CFG2_LASX   (1 << 7)
> > >> -
> > >> -static int cpu_flags_cpucfg(void)
> > >> +#define LA_HWCAP_LSX    (1<<4)
> > >> +#define LA_HWCAP_LASX   (1<<5)
> > >> +static int cpu_flags_getauxval(void)
> > >> {
> > >>     int flags = 0;
> > >> -    uint32_t cfg2 = 0;
> > >> -
> > >> -    __asm__ volatile(
> > >> -        "cpucfg %0, %1 \n\t"
> > >> -        : "+&r"(cfg2)
> > >> -        : "r"(LOONGARCH_CFG2)
> > >> -    );
> > >> +    int flag  = (int)getauxval(AT_HWCAP);
> > >>
> > >> -    if (cfg2 & LOONGARCH_CFG2_LSX)
> > >> +    if (flag & LA_HWCAP_LSX)
> > >>         flags |= AV_CPU_FLAG_LSX;
> > >> -
> > >> -    if (cfg2 & LOONGARCH_CFG2_LASX)
> > >> +    if (flag & LA_HWCAP_LASX)
> > >>         flags |= AV_CPU_FLAG_LASX;
> > >>
> > >>     return flags;
> > >> @@ -49,7 +41,7 @@ static int cpu_flags_cpucfg(void)
> > >> int ff_get_cpu_flags_loongarch(void)
> > >> {
> > >> #if defined __linux__
> > >> -    return cpu_flags_cpucfg();
> > >> +    return cpu_flags_getauxval();
> > >> #else
> > >>     /* Assume no SIMD ASE supported */
> > >>     return 0;
> > >> --
> > >> 2.20.1
> > >>
> > >> _______________________________________________
> > >> ffmpeg-devel mailing list
> > >> ffmpeg-devel@ffmpeg.org
> > >> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> > >>
> > >> To unsubscribe, visit link above, or email
> > >> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
> > >
> > >
> > > LGTM
> > >
> > > Thanks
> > > Steven
> > > _______________________________________________
> >
> > Could you please help to merge this patch.
>
>
> I have no permission now, maybe there have some problem?
>
> (base) adeMacBook-Pro:project liuqi$ git clone git@source.ffmpeg.org:ffmpeg
> 正克隆到 'ffmpeg'...
> @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
> @    WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!     @
> @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
> IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
> Someone could be eavesdropping on you right now (man-in-the-middle attack)!
> It is also possible that a host key has just been changed.
> The fingerprint for the ED25519 key sent by the remote host is
> SHA256:dUNFtMwS3Z25nnzFF8UPYWsE0WiUR4majWLbWrsHBXU.
> Please contact your system administrator.

Fixed

>
>
> Thanks
> Steven
> > _______________________________________________
> > ffmpeg-devel mailing list
> > ffmpeg-devel@ffmpeg.org
> > https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> >
> > To unsubscribe, visit link above, or email
> > ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
Steven Liu Feb. 27, 2023, 4:44 a.m. UTC | #5
Steven Liu <lingjiujianke@gmail.com> 于2023年2月27日周一 11:17写道:
>
> Steven Liu <lingjiujianke@gmail.com> 于2023年2月27日周一 10:47写道:
> >
> > Shiyou Yin <yinshiyou-hf@loongson.cn> 于2023年2月27日周一 09:03写道:
> > >
> > >
> > >
> > > > 2023年2月23日 15:48,Steven Liu <lingjiujianke@gmail.com> 写道:
> > > >
> > > > Shiyou Yin <yinshiyou-hf@loongson.cn> 于2023年2月14日周二 20:26写道:
> > > >>
> > > >> Replace cpucfg with getauxval to avoid crash in case of
> > > >> some processor capabilities are not supportted by kernel used.
> > > >> ---
> > > >> libavutil/loongarch/cpu.c | 24 ++++++++----------------
> > > >> 1 file changed, 8 insertions(+), 16 deletions(-)
> > > >>
> > > >> diff --git a/libavutil/loongarch/cpu.c b/libavutil/loongarch/cpu.c
> > > >> index e4b240bc44..cad8504fde 100644
> > > >> --- a/libavutil/loongarch/cpu.c
> > > >> +++ b/libavutil/loongarch/cpu.c
> > > >> @@ -21,26 +21,18 @@
> > > >>
> > > >> #include <stdint.h>
> > > >> #include "cpu.h"
> > > >> +#include <sys/auxv.h>
> > > >>
> > > >> -#define LOONGARCH_CFG2 0x2
> > > >> -#define LOONGARCH_CFG2_LSX    (1 << 6)
> > > >> -#define LOONGARCH_CFG2_LASX   (1 << 7)
> > > >> -
> > > >> -static int cpu_flags_cpucfg(void)
> > > >> +#define LA_HWCAP_LSX    (1<<4)
> > > >> +#define LA_HWCAP_LASX   (1<<5)
> > > >> +static int cpu_flags_getauxval(void)
> > > >> {
> > > >>     int flags = 0;
> > > >> -    uint32_t cfg2 = 0;
> > > >> -
> > > >> -    __asm__ volatile(
> > > >> -        "cpucfg %0, %1 \n\t"
> > > >> -        : "+&r"(cfg2)
> > > >> -        : "r"(LOONGARCH_CFG2)
> > > >> -    );
> > > >> +    int flag  = (int)getauxval(AT_HWCAP);
> > > >>
> > > >> -    if (cfg2 & LOONGARCH_CFG2_LSX)
> > > >> +    if (flag & LA_HWCAP_LSX)
> > > >>         flags |= AV_CPU_FLAG_LSX;
> > > >> -
> > > >> -    if (cfg2 & LOONGARCH_CFG2_LASX)
> > > >> +    if (flag & LA_HWCAP_LASX)
> > > >>         flags |= AV_CPU_FLAG_LASX;
> > > >>
> > > >>     return flags;
> > > >> @@ -49,7 +41,7 @@ static int cpu_flags_cpucfg(void)
> > > >> int ff_get_cpu_flags_loongarch(void)
> > > >> {
> > > >> #if defined __linux__
> > > >> -    return cpu_flags_cpucfg();
> > > >> +    return cpu_flags_getauxval();
> > > >> #else
> > > >>     /* Assume no SIMD ASE supported */
> > > >>     return 0;
> > > >> --
> > > >> 2.20.1
> > > >>
> > > >> _______________________________________________
> > > >> ffmpeg-devel mailing list
> > > >> ffmpeg-devel@ffmpeg.org
> > > >> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> > > >>
> > > >> To unsubscribe, visit link above, or email
> > > >> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
> > > >
> > > >
> > > > LGTM
> > > >
> > > > Thanks
> > > > Steven
> > > > _______________________________________________
> > >
> > > Could you please help to merge this patch.
> >
> >
> > I have no permission now, maybe there have some problem?
> >
> > (base) adeMacBook-Pro:project liuqi$ git clone git@source.ffmpeg.org:ffmpeg
> > 正克隆到 'ffmpeg'...
> > @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
> > @    WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!     @
> > @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
> > IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
> > Someone could be eavesdropping on you right now (man-in-the-middle attack)!
> > It is also possible that a host key has just been changed.
> > The fingerprint for the ED25519 key sent by the remote host is
> > SHA256:dUNFtMwS3Z25nnzFF8UPYWsE0WiUR4majWLbWrsHBXU.
> > Please contact your system administrator.
>
> Fixed
pushed as b09f31af1b5e483e614d0f5d673753c5ab778034
>
> >
> >
> > Thanks
> > Steven
> > > _______________________________________________
> > > ffmpeg-devel mailing list
> > > ffmpeg-devel@ffmpeg.org
> > > https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> > >
> > > To unsubscribe, visit link above, or email
> > > ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
diff mbox series

Patch

diff --git a/libavutil/loongarch/cpu.c b/libavutil/loongarch/cpu.c
index e4b240bc44..cad8504fde 100644
--- a/libavutil/loongarch/cpu.c
+++ b/libavutil/loongarch/cpu.c
@@ -21,26 +21,18 @@ 
 
 #include <stdint.h>
 #include "cpu.h"
+#include <sys/auxv.h>
 
-#define LOONGARCH_CFG2 0x2
-#define LOONGARCH_CFG2_LSX    (1 << 6)
-#define LOONGARCH_CFG2_LASX   (1 << 7)
-
-static int cpu_flags_cpucfg(void)
+#define LA_HWCAP_LSX    (1<<4)
+#define LA_HWCAP_LASX   (1<<5)
+static int cpu_flags_getauxval(void)
 {
     int flags = 0;
-    uint32_t cfg2 = 0;
-
-    __asm__ volatile(
-        "cpucfg %0, %1 \n\t"
-        : "+&r"(cfg2)
-        : "r"(LOONGARCH_CFG2)
-    );
+    int flag  = (int)getauxval(AT_HWCAP);
 
-    if (cfg2 & LOONGARCH_CFG2_LSX)
+    if (flag & LA_HWCAP_LSX)
         flags |= AV_CPU_FLAG_LSX;
-
-    if (cfg2 & LOONGARCH_CFG2_LASX)
+    if (flag & LA_HWCAP_LASX)
         flags |= AV_CPU_FLAG_LASX;
 
     return flags;
@@ -49,7 +41,7 @@  static int cpu_flags_cpucfg(void)
 int ff_get_cpu_flags_loongarch(void)
 {
 #if defined __linux__
-    return cpu_flags_cpucfg();
+    return cpu_flags_getauxval();
 #else
     /* Assume no SIMD ASE supported */
     return 0;