From patchwork Mon Dec 27 15:01:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 528275 Delivered-To: patch@linaro.org Received: by 2002:ac0:b243:0:0:0:0:0 with SMTP id s3csp2224896imc; Mon, 27 Dec 2021 07:02:55 -0800 (PST) X-Google-Smtp-Source: ABdhPJx8ttqEZigvMmczvuTSuBbJ89FcrXGfYt7LrxGERwuSop3kaIGNiChznMNJKg9c1qV+Otbp X-Received: by 2002:a05:6214:2308:: with SMTP id gc8mr15407108qvb.12.1640617375198; Mon, 27 Dec 2021 07:02:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1640617375; cv=none; d=google.com; s=arc-20160816; b=BOXkezORQ2FoG0GokRBK8dgEwtppewUmeN3cQjbFhqDTEOycF8MalXzgZt/zmqnsyx KU3mBbwV0Mk8t6FIQ3SZ9Uq1iChLBBv5CKjRqXm7QqcWQgDMT8dUkozmtyXCsZIOZQiD gK3CkObCroXfBi5JePjoNvMMIh/tT5zZrS4HGzpsEXZACFIPX6MyYRUOcxpkqLP8Pm8X bSQunCX8BjrHMRsgXCF5wm0gkQuHOyXuFVFu9toDvm8ksLujK6bEJu0sptWQII0t7Qgz v3zGWSQrO1pK2CdDiUK0LhSi2df9N1Ya1FrUsCl1+Q0nH69CHZG8BjxIA26QcpqezahQ KRAQ== 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=yP/kb34Ziz8gNeF1s6OUVtEmlihcmFFw3he3QQHc/vU=; b=WLVrHdpRSQD3ZoBQSeZrlUp3gXQ+LONRYirugzf7BT/GftWLvA3bTgkcQu+NIqWphG /EiAjVXy9kRgbJ8LA3pUyyDTBVWjBK9URj3lrht9gszo31p0gLdPXpBffLzDOhOaI28B +GGmJIeNNuHvhXRzTskNOpt6T2QhJOJ/BN1KjZzYf90jW1TPYwonqPjDKqxzTObJPRJV NwAypWD8r+6TdHa84Sv/YeK7kC+IFnBkG4eyt1wmrY+MEO0k6HLhw8st11goUYXg6t1T +mgOMyzqIx62uCFNCmL7Ms7VHiPUJmfcm21iqKzk3R6mlwli3YqAERL+j50HCpvxiUvF Jukg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=e61cg2+a; 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=pass (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 w14si999493vsa.360.2021.12.27.07.02.55 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 27 Dec 2021 07:02:55 -0800 (PST) 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=pass header.i=@linaro.org header.s=google header.b=e61cg2+a; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:51424 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1n1rWY-0005mK-J8 for patch@linaro.org; Mon, 27 Dec 2021 10:02:54 -0500 Received: from eggs.gnu.org ([209.51.188.92]:36320) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n1rVF-0005gO-Uo for qemu-devel@nongnu.org; Mon, 27 Dec 2021 10:01:33 -0500 Received: from [2607:f8b0:4864:20::42c] (port=43577 helo=mail-pf1-x42c.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1n1rVD-0000lE-M7 for qemu-devel@nongnu.org; Mon, 27 Dec 2021 10:01:33 -0500 Received: by mail-pf1-x42c.google.com with SMTP id 196so13849518pfw.10 for ; Mon, 27 Dec 2021 07:01:31 -0800 (PST) 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=yP/kb34Ziz8gNeF1s6OUVtEmlihcmFFw3he3QQHc/vU=; b=e61cg2+aapaaj+tartRozLdRRgczJHjzWFzsbmjmQNnfNenj6GxSr0uF6S5fZ9TuQG n2plxq9RmqxRA1Wptp0TEdagm7qrsnt2UzWD1CGvC5xj1ErZYlRgikpz5uZ9YaUXwwTd izBgFSiuvbWZ8PJy0o9N/O4ziwekbcPPh5cTRfV4C4YBLBTrGI2VtwAWQG+l26jlbBIo IMIbXN966UheqqvV3+pm0NqQD+Tmemuqel/cMTeuSBRy6FYcECl8rxfpAhWicHUFMrN5 aJQcWsklHfQVc2G/XgNIDsDbSAFzT5DHaX3n199bPgnqKk6DyDFKVYQ72vlUuQZTfEco gXOA== 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=yP/kb34Ziz8gNeF1s6OUVtEmlihcmFFw3he3QQHc/vU=; b=UU59vTfZF6XWvo3bvglSJTHZ292b+R0YXAVbDY5Um7vV0kxQGmRoWORauMfxjyltFe ISE/g0qDMKgV63LHl8jLKBe6iGVseGNVwcEJqpng5lxt/BiJRT3gvXx8GdsfdsG0Doq4 02+IOP7KcUWRfTlgLr3lEwE1hexmJLguHl2pEvsbtVCRVes0Y+I6FcqJoe4Jbfpnqy4v pN8I2zMD46GfRnhnmgopgeXfXWFOlQFAKtaC3TjQk5tw8ShJ3UB+MeBQmUuKueMcvxm9 PafY+0KJQxu2V4n6M8sS0Wq0445kT+ewgb2AWIvzyqqMUjr0dgUdMMvJp7t9aTqHNAwy cdtw== X-Gm-Message-State: AOAM531CrvQNj2BxLEDbvedPGJ5tCVgI57BjlUygLaE6x61hjTpcOD92 LkHPIj/Y02GQ6P6CMJ1Pa2DdxBUxS25ITg== X-Received: by 2002:a63:5f57:: with SMTP id t84mr15842702pgb.192.1640617290351; Mon, 27 Dec 2021 07:01:30 -0800 (PST) Received: from localhost.localdomain (76-14-210-194.or.wavecable.com. [76.14.210.194]) by smtp.gmail.com with ESMTPSA id m13sm14756743pgt.22.2021.12.27.07.01.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Dec 2021 07:01:30 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 3/6] linux-user: Add code for PR_GET/SET_UNALIGN Date: Mon, 27 Dec 2021 07:01:24 -0800 Message-Id: <20211227150127.2659293-4-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211227150127.2659293-1-richard.henderson@linaro.org> References: <20211227150127.2659293-1-richard.henderson@linaro.org> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::42c (failed) Received-SPF: pass client-ip=2607:f8b0:4864:20::42c; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42c.google.com X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 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, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: laurent@vivier.eu, Warner Losh , =?utf-8?q?Philippe_Math?= =?utf-8?q?ieu-Daud=C3=A9?= 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. Reviewed-by: Warner Losh Reviewed-by: Laurent Vivier Reviewed-by: Philippe Mathieu-Daudé 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 diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h index e948e81f1a..76ab3b851c 100644 --- a/include/hw/core/cpu.h +++ b/include/hw/core/cpu.h @@ -413,6 +413,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 945dd3dded..016bf06a1a 100644 --- a/cpu.c +++ b/cpu.c @@ -174,13 +174,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 d868ef2910..b5112891b0 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -6378,6 +6378,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) @@ -6441,6 +6447,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: @@ -6483,8 +6494,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: /* Disable to prevent the target disabling stuff we need. */ return -TARGET_EINVAL;