[{"id":3680176,"web_url":"http://patchwork.ozlabs.org/comment/3680176/","msgid":"<a6e16057-cfab-4d5b-a4fe-028203947e86@linaro.org>","list_archive_url":null,"date":"2026-04-22T01:30:32","subject":"Re: [PATCH v2 01/13] linux-user/mips, target/mips: honor MIPS_FIXADE\n for unaligned accesses","submitter":{"id":72104,"url":"http://patchwork.ozlabs.org/api/people/72104/","name":"Richard Henderson","email":"richard.henderson@linaro.org"},"content":"On 4/22/26 03:27, James Hilliard wrote:\n> Linux/MIPS enables software fixups for user-mode unaligned scalar\n> accesses by default through MIPS_FIXADE/TIF_FIXADE. QEMU linux-user did\n> not model that ABI, so MIPS guests took fatal AdEL/AdES exceptions\n> unless translation was forced to use unaligned host accesses.\n> \n> Replace the target-specific workaround with a generic MIPS linux-user\n> implementation:\n> \n> - key MIPS translation blocks on the linux-user unaligned policy,\n> - implement sysmips(MIPS_FIXADE) to toggle that policy,\n> - raise SIGBUS/BUS_ADRALN when fixups are disabled, and\n> - handle the existing sysmips(MIPS_ATOMIC_SET) and MIPS_FLUSH_CACHE\n>    commands in the new target-side sysmips dispatcher.\n> \n> This makes the default behaviour match native Linux/MIPS more closely\n> and keeps the signal semantics consistent with the kernel ABI without\n> regressing other user-mode sysmips commands.\n> \n> Signed-off-by: James Hilliard <james.hilliard1@gmail.com>\n\nThis patch does multiple things.\n\n(1) sysmips flush_cache.\n(2) sysmips atomic_set.\n(3) As stated, unaligned access controls.\n\nI suggest breaking it into 3 patches, in the order above.\nThat will add a bare-bones do_sysmips function in the first patch.\n\n\n> +#ifdef TARGET_NR_sysmips\n> +static abi_long do_sysmips_atomic_set(CPUArchState *env, abi_ulong addr,\n> +                                      abi_long value)\n> +{\n> +    uint32_t *ptr;\n> +    abi_long old;\n> +\n> +    if (addr & 3) {\n> +        return -TARGET_EINVAL;\n> +    }\n> +\n> +    ptr = lock_user(VERIFY_WRITE, addr, sizeof(*ptr), true);\n> +    if (!ptr) {\n> +        return -TARGET_EINVAL;\n> +    }\n> +\n> +    old = tswap32(qatomic_xchg(ptr, tswap32((uint32_t)value)));\n> +    unlock_user(ptr, addr, sizeof(*ptr));\n> +\n> +    /*\n> +     * MIPS uses a separate error flag, but the common linux-user syscall\n> +     * path infers that flag from the return value.  Successful atomic_set\n> +     * results can overlap the target errno range, so write the result\n> +     * registers here and ask the CPU loop to leave them alone.\n> +     */\n> +    if ((abi_ulong)old >= (abi_ulong)-TARGET_EDQUOT) {\n> +        env->active_tc.gpr[2] = old;\n> +        env->active_tc.gpr[7] = 0;\n> +        return -QEMU_ESIGRETURN;\n> +    }\n> +\n> +    return old;\n\nThe comment is good, but the IF is unnecessary: always use the ESIGRETURN path.\n\n\nr~","headers":{"Return-Path":"<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@legolas.ozlabs.org","Authentication-Results":["legolas.ozlabs.org;\n\tdkim=pass (2048-bit key;\n unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256\n header.s=google header.b=nJDna/+Z;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org\n (client-ip=209.51.188.17; helo=lists1p.gnu.org;\n envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org;\n receiver=patchwork.ozlabs.org)"],"Received":["from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17])\n\t(using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits))\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4g0hXH6Tfzz1y2d\n\tfor <incoming@patchwork.ozlabs.org>; Wed, 22 Apr 2026 11:31:42 +1000 (AEST)","from localhost ([::1] helo=lists1p.gnu.org)\n\tby lists1p.gnu.org with esmtp (Exim 4.90_1)\n\t(envelope-from <qemu-devel-bounces@nongnu.org>)\n\tid 1wFMQQ-0003ZF-SK; Tue, 21 Apr 2026 21:30:46 -0400","from eggs.gnu.org ([2001:470:142:3::10])\n by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)\n (Exim 4.90_1) (envelope-from <richard.henderson@linaro.org>)\n id 1wFMQP-0003Z7-Ew\n for qemu-devel@nongnu.org; Tue, 21 Apr 2026 21:30:45 -0400","from mail-oi1-x22f.google.com ([2607:f8b0:4864:20::22f])\n by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128)\n (Exim 4.90_1) (envelope-from <richard.henderson@linaro.org>)\n id 1wFMQM-0001H7-3i\n for qemu-devel@nongnu.org; Tue, 21 Apr 2026 21:30:45 -0400","by mail-oi1-x22f.google.com with SMTP id\n 5614622812f47-4779b2497b4so2885735b6e.3\n for <qemu-devel@nongnu.org>; Tue, 21 Apr 2026 18:30:41 -0700 (PDT)","from [10.72.56.227] ([172.59.197.244])\n by smtp.gmail.com with ESMTPSA id\n 46e09a7af769-7dcd5408b5asm3736106a34.11.2026.04.21.18.30.37\n (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128);\n Tue, 21 Apr 2026 18:30:38 -0700 (PDT)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=linaro.org; s=google; t=1776821439; x=1777426239; darn=nongnu.org;\n h=content-transfer-encoding:in-reply-to:content-language:from\n :references:to:subject:user-agent:mime-version:date:message-id:from\n :to:cc:subject:date:message-id:reply-to;\n bh=AY4DsEvHkoRyrMih1ndeDcANuFXV8hcGvLhaszfMLKk=;\n b=nJDna/+ZwqGmp5WhKH1X+vMxUo7sYaKi/t19TUff6n2HUQEO+VhVUYvizr3tSMFzK7\n CkxRmjtpIWOOtIEymxD7QSprQaTZ/lKUkrUpICVJA6oB+/AbI1RN5OzDP2IbvP/H3kQy\n 2JjyQNoHMBjeDnm3Vb9X4p8oV+5Th+O62BKW1bhVeubnwLFjDtOnxpvLS0OAIRlLu0So\n mdsC3MVEBX5e8KLC7EVaUkG55sfFVgewZ4nW+6VCG8hI0PsEK9wFXU69NAL5JNx+nBEP\n B7HCYqwSPpzxoapKdCBuu1dbKlwMPEuD5T2wQCgk5kQ794TdeO85IdKodtNCbMltTOAY\n 5maA==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=1e100.net; s=20251104; t=1776821439; x=1777426239;\n h=content-transfer-encoding:in-reply-to:content-language:from\n :references:to:subject:user-agent:mime-version:date:message-id\n :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id\n :reply-to;\n bh=AY4DsEvHkoRyrMih1ndeDcANuFXV8hcGvLhaszfMLKk=;\n b=f0bS2SOtX77HV1oF/VOJnhQ/97+Ug4ty+HNqqWRDpz0NHfAfgN/wfwGM/TWKL590Xk\n btAHa00twBqcEvkloVcS8s0ANh0rpwVQVfcpnWF/KLF5279gCX3Vq/2LDsl2YR2gOoXc\n FmsFKNhNlTc9FUd3cP0SdvU53zHb8pnCw3u7a3wEcDzuQjkaBqHHMeHdoOgEeUuvz2qq\n bbPv8AlGwJImfxl9UlAA2c/c0d3C7bFlmsUhCF3S8jHsJpwtdRme14NVXXRn915sMTte\n xbD27B49K7MyiiBHTejMz53xbgOmUz3a2bkPbf2fopTosTzm8b7ZnA5yx79iIgXIvdPW\n GHLw==","X-Gm-Message-State":"AOJu0YwAms5plijTUgbQsKAyHUdgXtmKWZoBwc5RIan5TqhLawbWJ/e3\n 2E/daBrUtEabDoHflYSL6hJkmacVwrlK6NyFkONCOp9EHUNapjhOVhZdHvgZ3IaD/WSP3DehZ+H\n wZaQLWR4=","X-Gm-Gg":"AeBDies5UCIvu4VMdiuRqlyCWnLdNsOWaBqcAHsOZ1fthkcY+WQaQHyy7ND+flCgIgE\n NGdv5oAov2ioL/NitxidQEWp+Oh0+xKqLUhCrO3KJjNE3JC7qOxIjpPhRzJUx3M0MTegXoGJUkv\n vXKUPhEKLan+o7e0crXWXbB1zZgyQuLzNgGApwUL2BDdh1Vwq/UtnenCUBbNASh9lTMOqp7Daqq\n FwvAmHaLyv8Xntu0NQB5H1y3wv4W/cabncieIxpFEHCV9KtOsB74X78IwlsQn8272r2ZKIorho5\n 8YWwrsrccDU3sBPaQqqVLwBuXblpw878PxT3wvnRijsYlCMpsd+VGY+6j6pSIo/FpV3AQRwUImk\n JJEDGxKsJbYbiv/nuwZHUmPYT39Z3y9+t2ztOzm+r82nexed3YcUw4bTp/5bVdCSMRHGQf9rguY\n y+iEpONpum1OfkOJjoTtGaVbm3Tnp1Mqq2oRAXXaYsaQnUjd73je/c4w+9mXT/LAEuxDM6Ac8A2\n TJT06r0eE1zDdlWIB8VKsM7j5LA5zwJ+F2jjzQ=","X-Received":"by 2002:a05:6808:4f0a:b0:45e:e07d:85af with SMTP id\n 5614622812f47-4799c872810mr10795017b6e.2.1776821439487;\n Tue, 21 Apr 2026 18:30:39 -0700 (PDT)","Message-ID":"<a6e16057-cfab-4d5b-a4fe-028203947e86@linaro.org>","Date":"Wed, 22 Apr 2026 11:30:32 +1000","MIME-Version":"1.0","User-Agent":"Mozilla Thunderbird","Subject":"Re: [PATCH v2 01/13] linux-user/mips, target/mips: honor MIPS_FIXADE\n for unaligned accesses","To":"qemu-devel@nongnu.org,\n =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= <philmd@linaro.org>","References":"\n <20260421-mips-octeon-missing-insns-v2-v2-0-a0791df188c9@gmail.com>\n <20260421-mips-octeon-missing-insns-v2-v2-1-a0791df188c9@gmail.com>","From":"Richard Henderson <richard.henderson@linaro.org>","Content-Language":"en-US","In-Reply-To":"\n <20260421-mips-octeon-missing-insns-v2-v2-1-a0791df188c9@gmail.com>","Content-Type":"text/plain; charset=UTF-8; format=flowed","Content-Transfer-Encoding":"7bit","Received-SPF":"pass client-ip=2607:f8b0:4864:20::22f;\n envelope-from=richard.henderson@linaro.org; helo=mail-oi1-x22f.google.com","X-Spam_score_int":"-20","X-Spam_score":"-2.1","X-Spam_bar":"--","X-Spam_report":"(-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1,\n DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,\n RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001,\n SPF_PASS=-0.001 autolearn=ham autolearn_force=no","X-Spam_action":"no action","X-BeenThere":"qemu-devel@nongnu.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"qemu development <qemu-devel.nongnu.org>","List-Unsubscribe":"<https://lists.nongnu.org/mailman/options/qemu-devel>,\n <mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>","List-Archive":"<https://lists.nongnu.org/archive/html/qemu-devel>","List-Post":"<mailto:qemu-devel@nongnu.org>","List-Help":"<mailto:qemu-devel-request@nongnu.org?subject=help>","List-Subscribe":"<https://lists.nongnu.org/mailman/listinfo/qemu-devel>,\n <mailto:qemu-devel-request@nongnu.org?subject=subscribe>","Errors-To":"qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org","Sender":"qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org"}}]