Re: [kvm-unit-tests PATCH v3 7/7] x86: VMX: the "noclone" attribute is gcc-specific

Oliver Upton
2020-02-27T02:05:18Z

Hi Bill,

Perhaps it would be better to drill down the noclone attribute by GCC
version as well. May I suggest the following?

diff --git a/lib/compiler.h b/lib/compiler.h
new file mode 100644
index 000000000000..5cbcda94b0fe
--- /dev/null
+++ b/lib/compiler.h
@@ -0,0 +1,12 @@
+#ifndef _LIB_COMPILER_H_
+#define _LIB_COMPILER_H_
+
+#if GCC_VERSION >= 40500
+#define __noclone __attribute__((__noclone__, __optimize__("no-tracer")))
+#endif /* GCC_VERSION >= 40500 */
+
+#if !defined(__noclone)
+#define __noclone
+#endif
+
+#endif /* _LIB_COMPILER_H_ */
diff --git a/x86/vmx_tests.c b/x86/vmx_tests.c
index 0e2c2f8a7d34..2dfc010d5d49 100644
--- a/x86/vmx_tests.c
+++ b/x86/vmx_tests.c
@@ -5,6 +5,7 @@
*/

#include <asm/debugreg.h>
+#include <compiler.h>

#include "vmx.h"
#include "msr.h"
@@ -4974,7 +4975,7 @@ extern unsigned char test_mtf1;
extern unsigned char test_mtf2;
extern unsigned char test_mtf3;

-__attribute__((noclone)) static void test_mtf_guest(void)
+__noclone static void test_mtf_guest(void)
{
asm ("vmcall;\n\t"
"out %al, $0x80;\n\t"
--
Thanks,
Oliver

On Wed, Feb 26, 2020 at 12:13 PM Bill Wendling <morbo@google.com> wrote:
>
> Don't use the "noclone" attribute for clang as it's not supported.
>
> Signed-off-by: Bill Wendling <morbo@google.com>
> ---
> x86/vmx_tests.c | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/x86/vmx_tests.c b/x86/vmx_tests.c
> index ad8c002..ec88016 100644
> --- a/x86/vmx_tests.c
> +++ b/x86/vmx_tests.c
> @@ -4976,7 +4976,10 @@ extern unsigned char test_mtf1;
> extern unsigned char test_mtf2;
> extern unsigned char test_mtf3;
>
> -__attribute__((noclone)) static void test_mtf_guest(void)
> +#ifndef __clang__
> +__attribute__((noclone))
> +#endif
> +static void test_mtf_guest(void)
> {
> asm ("vmcall;\n\t"
> "out %al, $0x80;\n\t"
> --
> 2.25.1.481.gfbce0eb801-goog
>