Re: [PATCH v6 09/13] KVM: selftests: aarch64: Add aarch64/page_fault_test

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, Sep 19, 2022, Ricardo Koller wrote:
> On Sat, Sep 17, 2022 at 09:58:28PM +0000, Oliver Upton wrote:
> > @@ -536,13 +536,7 @@ static void load_exec_code_for_test(struct kvm_vm *vm)
> >  	assert(TEST_EXEC_GVA - TEST_GVA);
> >  	code = hva + 8;
> >  
> > -	/*
> > -	 * We need the cast to be separate in order for the compiler to not
> > -	 * complain with: "‘memcpy’ forming offset [1, 7] is out of the bounds
> > -	 * [0, 1] of object ‘__exec_test’ with type ‘unsigned char’"
> > -	 */
> > -	c = (uint64_t *)&__exec_test;
> > -	memcpy(code, c, 8);
> > +	*code = __exec_test;
> 
> I remember trying many ways of getting the compiler to not complain, I
> must have tried this (wonder what happened). Anyway, gcc and clang are
> happy with it.

Alternatively, from a code documentation perspective it would be nice to capture
that the size isn't arbitrary.  E.g.

  typedef uint32_t aarch64_insn_t;

  extern aarch64_insn_t __exec_test[2];

  {
	void *code;

	memcpy(code, __exec_test, sizeof(__exec_test));
  }

Note, memcpy() is currently dangerous, but hopefully that will be remedied soonish[*]

[*] https://lore.kernel.org/all/20220908233134.3523339-1-seanjc@xxxxxxxxxx



[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux