From patchwork Fri Oct 15 04:10:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 515838 Delivered-To: patch@linaro.org Received: by 2002:ac0:da11:0:0:0:0:0 with SMTP id d17csp152370imi; Thu, 14 Oct 2021 21:49:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJytycdBC4UoVk0KbiR+LjmUjcswX4j6YZgMFL/bh4tJ4ipFxZwmAtR4Av0HpOPlhi+wX2Ha X-Received: by 2002:a05:6638:3052:: with SMTP id u18mr6984236jak.148.1634273398977; Thu, 14 Oct 2021 21:49:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634273398; cv=none; d=google.com; s=arc-20160816; b=C3ntrgcVy0XHrRvKlBCs2Xnj4p6EetRSPGEL3n3Ox8mzn1gGNL5TchjPur+Flj0cqB qO14O2G7wxJC7nFmtWBrVjM84BVkuONHnIUsFf4EJXxV9wjiqiqObucieOW8dH1CbyVk pu3mVVeUMsN74J06Eo4mOe/BnZK9evz5HaT2cSlVctLgNoK6TZh0Il9YQYGb85tSYWMB IRFqtwjlIgmw7ms0vFbCisg/tnJKpogAqIp/43N+6fr++b7f7GSvSqWdV4CqISdPJeZU r1SRz9mU5fXE0ygCmm/k5A+BvaBdYaukvwf2H9oEdZCdSXKvWVS+wB2fG24tfOtFJlLK W35g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=kgbxRfaLnXEAdarkY+uz+mGv9JnWFVB+tvkZlav9GvM=; b=HSKs3My/l6CNzgTzyPT5ddM2d3zY2ThmaW50iMBi4uW/wptx9QTI+jNsi0CHktPz49 vLierkSslCsgjLyfm0s1zXaP/LKPcH4LOR9yRbUpYFfIojQZjsBAIpkH6iuZCiwRxz8i jVxaok2g6TxHS2mOteOjR6oxapHe5ikxWXW4Zojuk5tQ4v/zqz5XHv57Dmfs7bU4qfX0 jVBak8TLATYSnj2n1zskQ4vGPjA4BnhAsxiUkxMf6PLTKlIDA0ZN1fBMcbUUw3yyb7tk +Q8/NUsf7cYLbGDdrO9czcrGoQkymuwmLKWQ2xVzIIGfMBCZm9y+38B/NQA7VgwVWNmz I31w== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b="aU/NZ9fb"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id y18si6240889ioq.44.2021.10.14.21.49.58 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 14 Oct 2021 21:49:58 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b="aU/NZ9fb"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:33336 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mbFAM-0006dU-4W for patch@linaro.org; Fri, 15 Oct 2021 00:49:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39774) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mbEcK-00070R-Hz for qemu-devel@nongnu.org; Fri, 15 Oct 2021 00:14:49 -0400 Received: from mail-pl1-x62b.google.com ([2607:f8b0:4864:20::62b]:40699) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mbEcI-00030m-Eu for qemu-devel@nongnu.org; Fri, 15 Oct 2021 00:14:48 -0400 Received: by mail-pl1-x62b.google.com with SMTP id v20so5597180plo.7 for ; Thu, 14 Oct 2021 21:14:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=kgbxRfaLnXEAdarkY+uz+mGv9JnWFVB+tvkZlav9GvM=; b=aU/NZ9fb7fK43uXivA7vwfLR31Sy/r9Ewf2AEE1QITN2wKlQLndOwlSuw17Nx7ayGR 3kPIyUmKiztLN9QwOFBhGm50+MjL9IlsyzhgYOWkn+FM6Alwv4Kvl9UFteKbDM9AeCcq D1qvjT2anwmGiIEXMVcZ4KaV5AkkkkMVsmB7uz9Oqr081QTKuPse57tlORu3wYIsndyZ 47LDeGSYdSunbB2sagXgeYJAVfywrgQjbWe+mRB3Ojlu8OC4mLooCCLr+WetCAdZI8JK e7KF+cHbTyxjEeHVswB7JqCNTkyhl3tczwq+R3z8HKfCDUe+q4ZGFJHVVYBauwC2+DWX eB/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=kgbxRfaLnXEAdarkY+uz+mGv9JnWFVB+tvkZlav9GvM=; b=PrOR5DMwM8Axo9spXFiMCJCNZVHs/JXD0XY7eTtvAJmY8VHaE3sVgnpEJRh6E8qJ6o AZApSbV9dntIHu1CU9RI5D38/o/AYNZVbaFH1xSz+01P0nbGaD4rKk4LnM1K+9JdLHUB bsO4Du0kU2+2HzdghRfzvT7ZwtGsarSo0VW07lWfpzB5JyqwjiJPa5VWPcyyja8xiUvt WjCddzBA4ahXYMYpdS15kTrGplXpqiPXQc481U1AQXV5RZR4xfSyfCwwh+o5FEesKtOf rS+r0oFlJCPaDTTnTgCkzHhoqbbwiA66EfL4t4a9IjI+sRiD3JFxJSMuaVEeYKmbdV0n oXHA== X-Gm-Message-State: AOAM530O6RfMiZZMMmab1gYlCWVHscY+QlpYCf/PWmh+nv6W8NLSiMvN tRMGvgrCkkLsj8VJWiYMaDiXUlj4IeKVew== X-Received: by 2002:a17:90b:388c:: with SMTP id mu12mr10977559pjb.146.1634271285073; Thu, 14 Oct 2021 21:14:45 -0700 (PDT) Received: from localhost.localdomain ([71.212.134.125]) by smtp.gmail.com with ESMTPSA id q8sm10236885pja.52.2021.10.14.21.14.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Oct 2021 21:14:44 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v5 64/67] linux-user: Add code for PR_GET/SET_UNALIGN Date: Thu, 14 Oct 2021 21:10:50 -0700 Message-Id: <20211015041053.2769193-65-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211015041053.2769193-1-richard.henderson@linaro.org> References: <20211015041053.2769193-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::62b; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x62b.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, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, 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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: alex.bennee@linaro.org, laurent@vivier.eu, imp@bsdimp.com Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" This requires extra work for each target, but adds the common syscall code, and the necessary flag in CPUState. Signed-off-by: Richard Henderson --- include/hw/core/cpu.h | 3 +++ linux-user/generic/target_prctl_unalign.h | 27 +++++++++++++++++++++++ cpu.c | 20 ++++++++++++----- linux-user/syscall.c | 13 +++++++++-- 4 files changed, 56 insertions(+), 7 deletions(-) create mode 100644 linux-user/generic/target_prctl_unalign.h -- 2.25.1 Reviewed-by: Warner Losh Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h index 1a10497af3..6202bbf9c3 100644 --- a/include/hw/core/cpu.h +++ b/include/hw/core/cpu.h @@ -412,6 +412,9 @@ struct CPUState { bool ignore_memory_transaction_failures; + /* Used for user-only emulation of prctl(PR_SET_UNALIGN). */ + bool prctl_unalign_sigbus; + struct hax_vcpu_state *hax_vcpu; struct hvf_vcpu_state *hvf; diff --git a/linux-user/generic/target_prctl_unalign.h b/linux-user/generic/target_prctl_unalign.h new file mode 100644 index 0000000000..bc3b83af2a --- /dev/null +++ b/linux-user/generic/target_prctl_unalign.h @@ -0,0 +1,27 @@ +/* + * Generic prctl unalign functions for linux-user + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ +#ifndef GENERIC_TARGET_PRCTL_UNALIGN_H +#define GENERIC_TARGET_PRCTL_UNALIGN_H + +static abi_long do_prctl_get_unalign(CPUArchState *env, target_long arg2) +{ + CPUState *cs = env_cpu(env); + uint32_t res = PR_UNALIGN_NOPRINT; + if (cs->prctl_unalign_sigbus) { + res |= PR_UNALIGN_SIGBUS; + } + return put_user_u32(res, arg2); +} +#define do_prctl_get_unalign do_prctl_get_unalign + +static abi_long do_prctl_set_unalign(CPUArchState *env, target_long arg2) +{ + env_cpu(env)->prctl_unalign_sigbus = arg2 & PR_UNALIGN_SIGBUS; + return 0; +} +#define do_prctl_set_unalign do_prctl_set_unalign + +#endif /* GENERIC_TARGET_PRCTL_UNALIGN_H */ diff --git a/cpu.c b/cpu.c index 9bce67ef55..9e388d9cd3 100644 --- a/cpu.c +++ b/cpu.c @@ -179,13 +179,23 @@ void cpu_exec_unrealizefn(CPUState *cpu) cpu_list_remove(cpu); } +/* + * This can't go in hw/core/cpu.c because that file is compiled only + * once for both user-mode and system builds. + */ static Property cpu_common_props[] = { -#ifndef CONFIG_USER_ONLY +#ifdef CONFIG_USER_ONLY /* - * Create a memory property for softmmu CPU object, - * so users can wire up its memory. (This can't go in hw/core/cpu.c - * because that file is compiled only once for both user-mode - * and system builds.) The default if no link is set up is to use + * Create a property for the user-only object, so users can + * adjust prctl(PR_SET_UNALIGN) from the command-line. + * Has no effect if the target does not support the feature. + */ + DEFINE_PROP_BOOL("prctl-unalign-sigbus", CPUState, + prctl_unalign_sigbus, false), +#else + /* + * Create a memory property for softmmu CPU object, so users can + * wire up its memory. The default if no link is set up is to use * the system address space. */ DEFINE_PROP_LINK("memory", CPUState, memory, TYPE_MEMORY_REGION, diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 7635c2397a..ac3bc8a330 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -6375,6 +6375,12 @@ static abi_long do_prctl_inval1(CPUArchState *env, abi_long arg2) #ifndef do_prctl_get_tagged_addr_ctrl #define do_prctl_get_tagged_addr_ctrl do_prctl_inval0 #endif +#ifndef do_prctl_get_unalign +#define do_prctl_get_unalign do_prctl_inval1 +#endif +#ifndef do_prctl_set_unalign +#define do_prctl_set_unalign do_prctl_inval1 +#endif static abi_long do_prctl(CPUArchState *env, abi_long option, abi_long arg2, abi_long arg3, abi_long arg4, abi_long arg5) @@ -6438,6 +6444,11 @@ static abi_long do_prctl(CPUArchState *env, abi_long option, abi_long arg2, } return do_prctl_get_tagged_addr_ctrl(env); + case PR_GET_UNALIGN: + return do_prctl_get_unalign(env, arg2); + case PR_SET_UNALIGN: + return do_prctl_set_unalign(env, arg2); + case PR_GET_DUMPABLE: case PR_SET_DUMPABLE: case PR_GET_KEEPCAPS: @@ -6480,8 +6491,6 @@ static abi_long do_prctl(CPUArchState *env, abi_long option, abi_long arg2, case PR_SET_THP_DISABLE: case PR_GET_TSC: case PR_SET_TSC: - case PR_GET_UNALIGN: - case PR_SET_UNALIGN: default: /* Disable to prevent the target disabling stuff we need. */ return -TARGET_EINVAL;