From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.2 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,NICE_REPLY_A, SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9FEB2C64E7A for ; Tue, 1 Dec 2020 10:42:20 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 0AC462076C for ; Tue, 1 Dec 2020 10:42:19 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Th00CvFd" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0AC462076C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.41819.75285 (Exim 4.92) (envelope-from ) id 1kk36j-0004BJ-6m; Tue, 01 Dec 2020 10:42:05 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 41819.75285; Tue, 01 Dec 2020 10:42:05 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kk36j-0004BC-3N; Tue, 01 Dec 2020 10:42:05 +0000 Received: by outflank-mailman (input) for mailman id 41819; Tue, 01 Dec 2020 10:42:04 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kk36i-0004B7-6z for xen-devel@lists.xenproject.org; Tue, 01 Dec 2020 10:42:04 +0000 Received: from mail-wr1-x444.google.com (unknown [2a00:1450:4864:20::444]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 6fe7f5c9-0acc-4984-80e9-7d825828368a; Tue, 01 Dec 2020 10:42:03 +0000 (UTC) Received: by mail-wr1-x444.google.com with SMTP id g14so1851471wrm.13 for ; Tue, 01 Dec 2020 02:42:03 -0800 (PST) Received: from [192.168.1.7] ([212.22.223.21]) by smtp.gmail.com with ESMTPSA id k16sm2390397wrl.65.2020.12.01.02.42.01 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 01 Dec 2020 02:42:02 -0800 (PST) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 6fe7f5c9-0acc-4984-80e9-7d825828368a DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding:content-language; bh=iYDXREdUAV/LJlcuptjzgZ8tcA4UyMaQyotxPegfS5k=; b=Th00CvFdx0Yl+1TbSox9O7R9OJnEXQO7n+oc68HeCU4mruNkTn/vhqBgh8BNiWY7sY yuKDcVEATZhBBjqYfKsgIXV8yFTy3t88Po9tLMPG4mQz5r6P+P7xYuBiOlui583rwrKt 5LX1UTFqFOYJAt0XgrAfZPPBw8WLATVEvStzpTdQiUqAHUVt/r/CZZOVDdEjWscA/+MV cy5TFfXlXr/D4ET6CAUXTEzlzr9OFYKQFTAkFxrfxdu9r4xXTFZZVhhhpHPVx0hzSJSW gN5MyhVdkJW7UIWiF1fFmCBEhCr3OKyZQ1icGiA7CjUMhrRBEW/t8gCWOqCLftVzmnSy TZ3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=iYDXREdUAV/LJlcuptjzgZ8tcA4UyMaQyotxPegfS5k=; b=dgr/EyA+jS96Z7xSV0mq8Psih5f8YM8iiB3eDnLFI2hqGX5j7x5PRiQG1NlISQWToU di1xz1SbU9FOOPCjHJ8YOH+qZAo0FDSHPDtDhbzaCvLPE0vB5+r276oxsyxaisUNr6es WHTOjvv75lHgb9xAvWSCrwxW8We30wmSpvLJupsIaNB2vxDsU04K6IxO0BHgdTiRFqVl owhHxyRbmSbXghb4lJtPEq6wZeob6iFls7jzEpUkSafWX7ZgP0lPXB3CIlI9bVNadhM6 7b6ZOLIWkhkvTyQwiVdzKoXE8SsyRuDD6kN+7uKfaLdwdc6pofaS61vtpINZ8V4dZg39 7+Ig== X-Gm-Message-State: AOAM530eemAJUoM0pqsEpmLZ1CPMJKcZeuDkf4902raGd9l69MjOllgW 3ZPwg40XyV0u9cqC/VMGiDU= X-Google-Smtp-Source: ABdhPJxEuo7SvEhaaLaHEsEFRfcVfd5HWV2auBfgupVEr89QKyJ+wHSJr9dcZQ+l1V6UyC85klQ2NA== X-Received: by 2002:adf:a191:: with SMTP id u17mr3004296wru.421.1606819322470; Tue, 01 Dec 2020 02:42:02 -0800 (PST) Subject: Re: [PATCH V3 19/23] xen/arm: io: Abstract sign-extension To: Julien Grall Cc: Jan Beulich , "xen-devel@lists.xenproject.org" , Oleksandr Tyshchenko , Stefano Stabellini , Julien Grall , Volodymyr Babchuk References: <1606732298-22107-1-git-send-email-olekstysh@gmail.com> <1606732298-22107-20-git-send-email-olekstysh@gmail.com> <878sai7e1a.fsf@epam.com> <93284ea1-e658-ffff-3223-174d633e38ad@suse.com> From: Oleksandr Message-ID: <932d7826-7e48-aaee-d566-44c384f84e1c@gmail.com> Date: Tue, 1 Dec 2020 12:42:01 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US On 01.12.20 12:30, Julien Grall wrote: Hi Julien > Hi Jan, > > On 01/12/2020 07:55, Jan Beulich wrote: >> On 01.12.2020 00:27, Oleksandr wrote: >>> On 30.11.20 23:03, Volodymyr Babchuk wrote: >>>> Oleksandr Tyshchenko writes: >>>>> --- a/xen/include/asm-arm/traps.h >>>>> +++ b/xen/include/asm-arm/traps.h >>>>> @@ -83,6 +83,30 @@ static inline bool VABORT_GEN_BY_GUEST(const >>>>> struct cpu_user_regs *regs) >>>>>            (unsigned long)abort_guest_exit_end == regs->pc; >>>>>    } >>>>>    +/* Check whether the sign extension is required and perform it */ >>>>> +static inline register_t sign_extend(const struct hsr_dabt dabt, >>>>> register_t r) >>>>> +{ >>>>> +    uint8_t size = (1 << dabt.size) * 8; >>>>> + >>>>> +    /* >>>>> +     * Sign extend if required. >>>>> +     * Note that we expect the read handler to have zeroed the bits >>>>> +     * outside the requested access size. >>>>> +     */ >>>>> +    if ( dabt.sign && (r & (1UL << (size - 1))) ) >>>>> +    { >>>>> +        /* >>>>> +         * We are relying on register_t using the same as >>>>> +         * an unsigned long in order to keep the 32-bit assembly >>>>> +         * code smaller. >>>>> +         */ >>>>> +        BUILD_BUG_ON(sizeof(register_t) != sizeof(unsigned long)); >>>>> +        r |= (~0UL) << size; >>>> If `size` is 64, you will get undefined behavior there. >>> I think, we don't need to worry about undefined behavior here. Having >>> size=64 would be possible with doubleword (dabt.size=3). But if "r" >>> adjustment gets called (I mean Syndrome Sign Extend bit is set) then >>> we deal with byte, halfword or word operations (dabt.size<3). Or I >>> missed something? >> >> At which point please put in a respective ASSERT(), possibly amended >> by a brief comment. > > ASSERT()s are only meant to catch programatic error. However, in this > case, the bigger risk is an hardware bug such as advertising a sign > extension for either 64-bit (or 32-bit) on Arm64 (resp. Arm32). > > Actually the Armv8 spec is a bit more blurry when running in AArch32 > state because they suggest that the sign extension can be set even for > 32-bit access. I think this is a spelling mistake, but it is probably > better to be cautious here. > > Therefore, I would recommend to rework the code so it is only called > when len < sizeof(register_t). I am not sure I understand the recommendation, could you please clarify (also I don't see 'len' being used here). -- Regards, Oleksandr Tyshchenko