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

Re: [PATCH v7 5/6] xen/riscv: introduce an implementation of macros from <asm/bug.h>


  • To: Oleksii <oleksii.kurochko@xxxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Tue, 8 Aug 2023 11:15:34 +0200
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=VAsLA7s8Di76h+92NZz50JjD7JBHvWH9yNdvc7cCjz8=; b=dccA5Ypc4Ada+xCrFPSYF8h3VOwz7x5gcSL8y/9LGFR71b3Hz1OPPTXzzO0IXLsMazf282WE4NIa6RVlMio8q+uxkm17DrRC823IAnBvtqtlRY4AL2rs3kGLHUIuZCj1ck/PKPiYqmaWXViybMk/41P5Jm2OasLnuLn8GySJnscBWrBlwnkmWUIb4F9LK+HbL+RK84jui1ZJtgnyLylyPA3qcxY9tILi1PuBP7kvbP/EB5h+2fQXgCS6evzkMVYrMckOM1etN7WANlUgwfI9YyC0HkxHD1Fuafu7iB1DMvp/hdl1GxjJvS7K/CDhBnZBAvM0rQvPZyR4V9WuSznlrA==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=XFgj2Q5teOd/SEjVqTa3gxAE1iyQFUmIZi3D34sFbyiNgt09etjECYsidW2VG6iLqkWa1mM+Rd6bUeQLG9XEiEfNzztJ17x/8QrzOWV3K1DbjmFSnasXiUCAGUmlkP6xH087XsBgwlGKyr8wS/S1aIiyk0GOUB9o5xFEWKvlybZ/oW8hBfM8LFXP+GJSdDJeY6F7czw0JXXjuoDETB959kiMSN2iCFiR0N7gI3HrEUz/7plN5WfN/skaf1otvHO7LmowSWPpclQAbSaGeasvhVhAVoqdAOuG6YcSU1fcU/dFNyiMqMtzBlj4SubkIXSvuwz8k993G9YXRPetENCibw==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com;
  • Cc: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Bob Eshleman <bobbyeshleman@xxxxxxxxx>, Alistair Francis <alistair.francis@xxxxxxx>, Connor Davis <connojdavis@xxxxxxxxx>, xen-devel@xxxxxxxxxxxxxxxxxxxx
  • Delivery-date: Tue, 08 Aug 2023 09:15:43 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 08.08.2023 10:48, Oleksii wrote:
> On Mon, 2023-08-07 at 15:29 +0200, Jan Beulich wrote:
>> On 03.08.2023 14:05, Oleksii Kurochko wrote:
>>> +static uint32_t read_instr(unsigned long pc)
>>> +{
>>> +    uint16_t instr16 = *(uint16_t *)pc;
>>> +
>>> +    if ( GET_INSN_LENGTH(instr16) == 2 )
>>> +        return (uint32_t)instr16;
>>
>> (I don't think this cast is needed.)
>>
>>> +    else
>>> +        return *(uint32_t *)pc;
>>> +}
>>
>> ... there still being a double read here, do you perhaps mean to
>> make a statement (that this code isn't safe to use on guest code)?
> I wonder if it'll be safe to read 16 bytes at a time then we won't have
> double read ( if you meant that first 16 bytes are read twice ):
> 
> static uint32_t read_instr(unsigned long pc)
> {
>     uint16_t instr16 = *(uint16_t *)pc;
> 
>     if ( GET_INSN_LENGTH(instr16) == 2 )
>         return (uint32_t)instr16;
>     else{
>         // return *(uint32_t *)pc;
> 
>         uint16_t next_16 = *((uint16_t *)pc + 1);
>         return ((uint32_t)instr16 << sizeof(instr16)) + next_16;
>     }
> }

Whether this is safe for guest code depends further on what underlying
mappings there are. Surely you can't simply cast a guest add (coming
in as "unsigned long pc") to a hypervisor address. So as it stands the
function can only ever be used on Xen code anyway.

Jan



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.