From patchwork Thu Feb 16 23:33:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 1744009 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bsdimp-com.20210112.gappssmtp.com header.i=@bsdimp-com.20210112.gappssmtp.com header.a=rsa-sha256 header.s=20210112 header.b=zKdv/Pn8; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4PHrrx6tzzz23r4 for ; Fri, 17 Feb 2023 10:34:57 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pSnlL-0008Ub-HB; Thu, 16 Feb 2023 18:34:03 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pSnlG-0008SQ-Ip for qemu-devel@nongnu.org; Thu, 16 Feb 2023 18:33:58 -0500 Received: from mail-il1-x130.google.com ([2607:f8b0:4864:20::130]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pSnlE-0008Ph-Pp for qemu-devel@nongnu.org; Thu, 16 Feb 2023 18:33:58 -0500 Received: by mail-il1-x130.google.com with SMTP id v13so1422503iln.4 for ; Thu, 16 Feb 2023 15:33:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=v82U4AeojucC3DQqhT5F05E7FmGdLYXG/H9YwykhwGc=; b=zKdv/Pn8yayE8JFx3+Wz7/lkpVBdRFXuRrc2u5CAet2xgnWEts63iGIpzT7hvaB0zG 9LxgJdiTZ9KJi35LvBYycgPZEu/04i6oG1V0WGX+6vciOjd4mcTylqeMLrdupvKtJfqm mCdWC/b9bjuNeMwgThAJoRcSOo+QH0oO11z1R/1TSu/BrXjTAdU741Wcg5+OPiD3qoPz 0qfYvoZGzzzdmHLNd/PsojF2OQv+y3A23WtiCzvr+t+2d4ZfJMGRvoXHQQbkYUde9ebZ h25j5qt+ST33wbNyj1MMCAGLfcIzR3DCNq8G6ln35tRLDuskosTCrW2lcoM+ennr6jeR bzdQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=v82U4AeojucC3DQqhT5F05E7FmGdLYXG/H9YwykhwGc=; b=DYWvauv29U3b3lb6GCX5o7TOuVjfAegTub30KFNWY8vXr+K06rC9RsjzPoA6aBiyul keHeWvDspjIL2KTLNq7VL+JrCUjsSy6YQy+1tSbSXN6ZDTtnM3Awn0BCGQr8plRObFHB gggjhsKs11qjX2h9x9086Wi5svlywyV0k/IAjhnmscg8+PU3VvsliTHhOKlHbKsCTLdk OBAy0KHDpcjbA0jfmVIiuNZMNjUTkBaWmnO/tvxCx2EA571Xfdpnnz5KQftiXV5ZZemZ Skvjz1mtOXui2apvexpRJdhlNFR+n9D1beC9OsYUsla1bpVFlXBcNkx+eqxsilCO0Pjn 9lAw== X-Gm-Message-State: AO0yUKVkN/Fx1PGWnPk4Bj9I4leGmLpweqe7ZvxScZTeD9+tbeGeXTJb dhojAuaokDr4Nq16nwAOqnPYpYVRnp14bRBm X-Google-Smtp-Source: AK7set8h90//KLnQjJX+jwtTUl+OZnEIQFk2uPuD3qwqWYnMWtfDVujWRUTVZLZVIni6D94H7QtbeQ== X-Received: by 2002:a05:6e02:1e02:b0:315:29ff:da7f with SMTP id g2-20020a056e021e0200b0031529ffda7fmr7591716ila.11.1676590434945; Thu, 16 Feb 2023 15:33:54 -0800 (PST) Received: from dune.bsdimp.com (c-71-237-47-177.hsd1.co.comcast.net. [71.237.47.177]) by smtp.gmail.com with ESMTPSA id y7-20020a02a387000000b00346a98b0a76sm934816jak.77.2023.02.16.15.33.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Feb 2023 15:33:54 -0800 (PST) From: Warner Losh To: qemu-devel@nongnu.org Cc: Kyle Evans , richard.henderson@linaro.org, =?utf-8?q?Alex_Benn=C3=A9e?= , f4bug@amsat.org, Warner Losh , Paolo Bonzini , Thomas Huth , Doug Rabson Subject: [PATCH v3 01/11] bsd-user: Don't truncate the return value from freebsd_syscall Date: Thu, 16 Feb 2023 16:33:43 -0700 Message-Id: <20230216233353.13944-2-imp@bsdimp.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230216233353.13944-1-imp@bsdimp.com> References: <20230216233353.13944-1-imp@bsdimp.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::130; envelope-from=imp@bsdimp.com; helo=mail-il1-x130.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=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: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Doug Rabson System call return values on FreeBSD are in a register (which is spelled abi_long in qemu). This was being assigned into an int variable which causes problems for 64bit targets. Resolves: https://github.com/qemu-bsd-user/qemu-bsd-user/issues/40 Signed-off-by: Doug Rabson Reviewed-by: Warner Losh [ Edited commit message for upstreaming into qemu-project ] Signed-off-by: Warner Losh Reviewed-by: Richard Henderson --- bsd-user/freebsd/os-syscall.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bsd-user/freebsd/os-syscall.c b/bsd-user/freebsd/os-syscall.c index 57996cad8ae..b4a663fc021 100644 --- a/bsd-user/freebsd/os-syscall.c +++ b/bsd-user/freebsd/os-syscall.c @@ -512,7 +512,7 @@ abi_long do_freebsd_syscall(void *cpu_env, int num, abi_long arg1, abi_long arg8) { CPUState *cpu = env_cpu(cpu_env); - int ret; + abi_long ret; trace_guest_user_syscall(cpu, num, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8); if (do_strace) { From patchwork Thu Feb 16 23:33:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 1744012 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bsdimp-com.20210112.gappssmtp.com header.i=@bsdimp-com.20210112.gappssmtp.com header.a=rsa-sha256 header.s=20210112 header.b=wiE0LN3y; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4PHrsJ2bLBz1yYg for ; Fri, 17 Feb 2023 10:35:16 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pSnlN-00004u-4K; Thu, 16 Feb 2023 18:34:05 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pSnlH-0008TT-Uf for qemu-devel@nongnu.org; Thu, 16 Feb 2023 18:34:00 -0500 Received: from mail-il1-x133.google.com ([2607:f8b0:4864:20::133]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pSnlF-0008Pt-Mq for qemu-devel@nongnu.org; Thu, 16 Feb 2023 18:33:59 -0500 Received: by mail-il1-x133.google.com with SMTP id v13so1422522iln.4 for ; Thu, 16 Feb 2023 15:33:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=i/ho+o97t3oUvsCX6/tWPXAhBUu89VuwLZO+3r6EySU=; b=wiE0LN3y8BKkKs8xy87FAv2iMZzyCAWmNAs+w3jnfDJ1OSprBEW/4DOqf8ugdXKveX OPITdnidZM5T/j6m5KTSX/iqzj3sINr3E3yJK1NxM6Ly9pvzBv6OkTXVuY09kcNoQEFr BUEjD/HnZz6IYeUqTnS+oOo5uMy70N4Vff5u/QPcQcXtGUv4ydL0KIHCTyyAzCUiyV4L 8e1pQptIYuluzQBFXKf8R6CIJqFcXuW4OITyLHkKhiCw6mZ8B3Za515ICU9OvFZ//v/p GhMUfdes3+PVblOUNMHQPUPCgPP/vti8Ou4MaFT5L/bkQwfPo0WcimcDIB/o19rRtY3s ZnEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=i/ho+o97t3oUvsCX6/tWPXAhBUu89VuwLZO+3r6EySU=; b=LAGXWKKd1xwSGR5tVaZJyVFXGvdUYOg+EYURKSGkgNUCBanZHFPPW2tSKJlY6MPde5 Nk2DBGj9Y5F6KD1R/icrq+uAztz+UmZunyaQ6J2wzFt6QiAso2TlI1AFN3FLbIGHvkzH 5LsUe7mu548+HQsOSimF1YiKhXhF0T4Ek/f3VTJrv+sD0nYBA8I/faWSCVKqO6AlLoF1 bN+T+H5fbA1yu8dIx6nvcObUZ7lRQBOt52U369gL95dr76lXUDxhO0XWMwDqiGjgCWJd W+OQywFso+73mfGb6LUU5YUAVzBVoLzzooHPGcioHTTM4DDOKTzRz8Yr/Vahi4EKJlA0 h4Gg== X-Gm-Message-State: AO0yUKW8nl/mtitCBUvptANR+7fUnkf8G0HloHtuktG2PczqzccwJcAe +y+uVDc3sjEseJmL/7fw+noiRmNHq+5NVJaX X-Google-Smtp-Source: AK7set9wFCc8TRtXuUC/5Ce+IzLz9p4AA+HzrtoHvcplp4BTsm6ZkHi8/pqD/Ca6Dta1Mm98EGMWig== X-Received: by 2002:a05:6e02:20c4:b0:310:fd98:1cc2 with SMTP id 4-20020a056e0220c400b00310fd981cc2mr6832298ilq.13.1676590436230; Thu, 16 Feb 2023 15:33:56 -0800 (PST) Received: from dune.bsdimp.com (c-71-237-47-177.hsd1.co.comcast.net. [71.237.47.177]) by smtp.gmail.com with ESMTPSA id y7-20020a02a387000000b00346a98b0a76sm934816jak.77.2023.02.16.15.33.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Feb 2023 15:33:55 -0800 (PST) From: Warner Losh To: qemu-devel@nongnu.org Cc: Kyle Evans , richard.henderson@linaro.org, =?utf-8?q?Alex_Benn=C3=A9e?= , f4bug@amsat.org, Warner Losh , Paolo Bonzini , Thomas Huth Subject: [PATCH v3 02/11] build: Don't specify -no-pie for --static user-mode programs Date: Thu, 16 Feb 2023 16:33:44 -0700 Message-Id: <20230216233353.13944-3-imp@bsdimp.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230216233353.13944-1-imp@bsdimp.com> References: <20230216233353.13944-1-imp@bsdimp.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::133; envelope-from=imp@bsdimp.com; helo=mail-il1-x133.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=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: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org When building with clang, -no-pie gives a warning on every single build, so remove it. Signed-off-by: Warner Losh Reviewed-by: Alex Bennée --- configure | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure b/configure index 64960c6000f..eb284ccf308 100755 --- a/configure +++ b/configure @@ -1313,7 +1313,7 @@ if test "$static" = "yes"; then error_exit "-static-pie not available due to missing toolchain support" else pie="no" - QEMU_CFLAGS="-fno-pie -no-pie $QEMU_CFLAGS" + QEMU_CFLAGS="-fno-pie $QEMU_CFLAGS" fi elif test "$pie" = "no"; then if compile_prog "-Werror -fno-pie" "-no-pie"; then From patchwork Thu Feb 16 23:33:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 1744017 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bsdimp-com.20210112.gappssmtp.com header.i=@bsdimp-com.20210112.gappssmtp.com header.a=rsa-sha256 header.s=20210112 header.b=41vk+tWM; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4PHrsq6CyFz1yYg for ; Fri, 17 Feb 2023 10:35:43 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pSnlO-00006C-4y; Thu, 16 Feb 2023 18:34:06 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pSnlJ-0008UK-A1 for qemu-devel@nongnu.org; Thu, 16 Feb 2023 18:34:01 -0500 Received: from mail-il1-x131.google.com ([2607:f8b0:4864:20::131]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pSnlH-0008QE-CK for qemu-devel@nongnu.org; Thu, 16 Feb 2023 18:34:00 -0500 Received: by mail-il1-x131.google.com with SMTP id j12so1075454ila.6 for ; Thu, 16 Feb 2023 15:33:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=UDKo+pEqLr25ECZFRWghhYmC5CZ9G4l3ZCThpSQaZZ4=; b=41vk+tWM/pdvJBVS6Iyh7OGaTVfZ4wD+WXTssRJ2pHuzV83CFgwyBc6c9+Y8BJ6fjE y+ILjYfcaOaFd/AXqhKpeU/QUMvqlSG5b/6XqF60rJg3F18rxojhlEUEx3iTirIo9UbB ZHNVXv/e2os7ULMEk1fT3OV1hb1w2sknqPeXs2IsAkzRYPr3Wi7JMMC8plTpLzEon6wM ABqVxJdRXtMPRNfOOHsUyUDJVtURgrTHtnwl8ppJUOM+94wJB8r/nouqeWpsjnXUwrLW +3LzOWXU0aAuIS4JUwrE4p4pTgMkjJR1cSnvguI37Z70m3cBFghvxxgLScx2IGoMBXnC hOiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=UDKo+pEqLr25ECZFRWghhYmC5CZ9G4l3ZCThpSQaZZ4=; b=gER+b11vIITOt46L2JfiL+lz+2MBob+eSXf2hyeJ0Dks3wJkqhgDOZyBiiM5KyK24n dRWb8icEUzm6Mkheo0Stpt9T7CZz0PljXwxG5bdPesnbj/waQzVmEkmx5mWQIzQVnCoR of83mEobj+Y3dWAD6NfV2n40uBYWR/H0KnZdQ6a4kkCcAv4tCG2tsAZ4Bgll6Vjap13P +G10dNYvrAAXOgEzR1B6LrK9pxdKl5LiQFTwddKl9pl8+OOivv6qBQ05hV8qe735kdNv vX+tZvSSe4LCLyG0nX0bbOCljOjLKa0OEW7xnsQh4FGihoUWl2S30Z3Ys7bB5cH1WJ5I 5FfQ== X-Gm-Message-State: AO0yUKXJWMAL8rYTxsp9vZIW2HQxEgE4dR+ZzYmHIs+sfelZEv6kLMKx vxRQ/0RNngK8xRFdBc4erqrrog3qXP2YW2bD X-Google-Smtp-Source: AK7set8gomZ0aX49pS5dFfuZUrBCsUz9anrh6NHck/SlKGEhEjUqEIV/+HnlEwV+OqHwiE9I9N4dlA== X-Received: by 2002:a05:6e02:1c29:b0:315:7004:3e69 with SMTP id m9-20020a056e021c2900b0031570043e69mr7183896ilh.13.1676590437659; Thu, 16 Feb 2023 15:33:57 -0800 (PST) Received: from dune.bsdimp.com (c-71-237-47-177.hsd1.co.comcast.net. [71.237.47.177]) by smtp.gmail.com with ESMTPSA id y7-20020a02a387000000b00346a98b0a76sm934816jak.77.2023.02.16.15.33.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Feb 2023 15:33:56 -0800 (PST) From: Warner Losh To: qemu-devel@nongnu.org Cc: Kyle Evans , richard.henderson@linaro.org, =?utf-8?q?Alex_Benn=C3=A9e?= , f4bug@amsat.org, Warner Losh , Paolo Bonzini , Thomas Huth , Stacey Son , Juergen Lock Subject: [PATCH v3 03/11] bsd-user: Add sysarch syscall Date: Thu, 16 Feb 2023 16:33:45 -0700 Message-Id: <20230216233353.13944-4-imp@bsdimp.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230216233353.13944-1-imp@bsdimp.com> References: <20230216233353.13944-1-imp@bsdimp.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::131; envelope-from=imp@bsdimp.com; helo=mail-il1-x131.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=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: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Stacey Son Connect up the sysarch system call. Signed-off-by: Juergen Lock Co-authored-by: Juergen Lock Signed-off-by: Stacey Son Reviewed-by: Warner Losh Signed-off-by: Warner Losh Reviewed-by: Richard Henderson --- bsd-user/freebsd/os-syscall.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/bsd-user/freebsd/os-syscall.c b/bsd-user/freebsd/os-syscall.c index b4a663fc021..e00997a818c 100644 --- a/bsd-user/freebsd/os-syscall.c +++ b/bsd-user/freebsd/os-syscall.c @@ -491,6 +491,13 @@ static abi_long freebsd_syscall(void *cpu_env, int num, abi_long arg1, ret = do_bsd_undelete(arg1); break; + /* + * sys{ctl, arch, call} + */ + case TARGET_FREEBSD_NR_sysarch: /* sysarch(2) */ + ret = do_freebsd_sysarch(cpu_env, arg1, arg2); + break; + default: qemu_log_mask(LOG_UNIMP, "Unsupported syscall: %d\n", num); ret = -TARGET_ENOSYS; From patchwork Thu Feb 16 23:33:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 1744015 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bsdimp-com.20210112.gappssmtp.com header.i=@bsdimp-com.20210112.gappssmtp.com header.a=rsa-sha256 header.s=20210112 header.b=ET4p04pi; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4PHrsf1M12z240c for ; Fri, 17 Feb 2023 10:35:34 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pSnlR-00008g-3V; Thu, 16 Feb 2023 18:34:09 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pSnlK-0008US-4i for qemu-devel@nongnu.org; Thu, 16 Feb 2023 18:34:02 -0500 Received: from mail-il1-x12f.google.com ([2607:f8b0:4864:20::12f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pSnlI-0008QO-9a for qemu-devel@nongnu.org; Thu, 16 Feb 2023 18:34:01 -0500 Received: by mail-il1-x12f.google.com with SMTP id h7so959166ila.7 for ; Thu, 16 Feb 2023 15:33:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=jcQ3VoTbe+79hYfj0QV+d8UTWb9sjCudpysXyieHUGQ=; b=ET4p04pioKHHyivHk3PnLifrt5iLPOfCGyessSvMZxwauirg+UYemDvcPNqTriKbCb Zcu/dJZQYe+YG8OhILYT4bK62QKdget3skbxT8fGjTeRVXse0rgrGxKntRpD/POcfY7V nRGFJfhotG10bNyTM2eotXVXOba4sGcWtAzbjKDBBZHxJHAXx07s12gB556EJufpHuSh yu01a7cMSpsxawR8w2nNjNaIj4iLnKs9S27bqB/tPwTPCWGs96sFXxzdMMGvUFCZj8q0 0dddxHx3m9+bKL1nM33siNoZnJb2pvHwCtd7vZtT+eVnuxLf5TpyAL9Bed76wimr0D30 F56w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=jcQ3VoTbe+79hYfj0QV+d8UTWb9sjCudpysXyieHUGQ=; b=OCF3j8sGxA7UPUb1YtbRGBIMlhiE3iEeV+Ej/RdsMbxb5Fxocw0sCGvVFhxuGg92z4 M3QvW/x0XGh32T/xM9fogminjbKHNvEq3iDGmoYLyLRG1U/zSe6z6mkg1DZsmS8vXBz/ Ev4QMgC8mjML1455q5MhBpihQUCXnw49FEC4ewyo/79ih4MSC1cAqSIwm3e52eCfFbj1 evKxkLSFjCM8rezxZNhvKL1idCRQYsLogMU8UfsZCG8Ra3JVe44QgEUw4bZjKuUc1QaY d/ecTNQDajGwaAsb0RXT43FAA4YvPOvH9ny2zyC8QG7O/4nlOEcXm8E3A9A2GE3SSnJi 8n+g== X-Gm-Message-State: AO0yUKWxu3Ofl1FIK4uAEtiO+H6X9wyozpTyHD7BAavLTlFHsB8Tn+LH zMDVADklELpHQykRXgZoqRAq4RZc7FHefRsy X-Google-Smtp-Source: AK7set9uJhXEm4wFj/x/Qn+uvdYQYK6AxAridUptvbE5NXBLaYVL7oageCszHnjesufsVliSY+mUng== X-Received: by 2002:a05:6e02:19cb:b0:315:9749:7a25 with SMTP id r11-20020a056e0219cb00b0031597497a25mr1288022ill.17.1676590438667; Thu, 16 Feb 2023 15:33:58 -0800 (PST) Received: from dune.bsdimp.com (c-71-237-47-177.hsd1.co.comcast.net. [71.237.47.177]) by smtp.gmail.com with ESMTPSA id y7-20020a02a387000000b00346a98b0a76sm934816jak.77.2023.02.16.15.33.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Feb 2023 15:33:58 -0800 (PST) From: Warner Losh To: qemu-devel@nongnu.org Cc: Kyle Evans , richard.henderson@linaro.org, =?utf-8?q?Alex_Benn=C3=A9e?= , f4bug@amsat.org, Warner Losh , Paolo Bonzini , Thomas Huth Subject: [PATCH v3 04/11] bsd-user: various helper routines for sysctl Date: Thu, 16 Feb 2023 16:33:46 -0700 Message-Id: <20230216233353.13944-5-imp@bsdimp.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230216233353.13944-1-imp@bsdimp.com> References: <20230216233353.13944-1-imp@bsdimp.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::12f; envelope-from=imp@bsdimp.com; helo=mail-il1-x12f.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=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: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org cap_memory - Caps the memory to just below MAXINT scale_to_guest_pages - Account for difference in host / guest page size h2g_long_sat - converts a int64_t to a int32_t, saturating at max / min values h2g_ulong_sat - converts a uint64_t to a uint32_t, saturating at max value Signed-off-by: Warner Losh Reviewed-by: Richard Henderson --- bsd-user/freebsd/os-sys.c | 86 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) diff --git a/bsd-user/freebsd/os-sys.c b/bsd-user/freebsd/os-sys.c index 1676ec10f83..9b84e90cb32 100644 --- a/bsd-user/freebsd/os-sys.c +++ b/bsd-user/freebsd/os-sys.c @@ -21,6 +21,92 @@ #include "qemu.h" #include "target_arch_sysarch.h" +#include + +/* + * Length for the fixed length types. + * 0 means variable length for strings and structures + * Compare with sys/kern_sysctl.c ctl_size + * Note: Not all types appear to be used in-tree. + */ +static const int G_GNUC_UNUSED guest_ctl_size[CTLTYPE+1] = { + [CTLTYPE_INT] = sizeof(abi_int), + [CTLTYPE_UINT] = sizeof(abi_uint), + [CTLTYPE_LONG] = sizeof(abi_long), + [CTLTYPE_ULONG] = sizeof(abi_ulong), + [CTLTYPE_S8] = sizeof(int8_t), + [CTLTYPE_S16] = sizeof(int16_t), + [CTLTYPE_S32] = sizeof(int32_t), + [CTLTYPE_S64] = sizeof(int64_t), + [CTLTYPE_U8] = sizeof(uint8_t), + [CTLTYPE_U16] = sizeof(uint16_t), + [CTLTYPE_U32] = sizeof(uint32_t), + [CTLTYPE_U64] = sizeof(uint64_t), +}; + +static const int G_GNUC_UNUSED host_ctl_size[CTLTYPE+1] = { + [CTLTYPE_INT] = sizeof(int), + [CTLTYPE_UINT] = sizeof(u_int), + [CTLTYPE_LONG] = sizeof(long), + [CTLTYPE_ULONG] = sizeof(u_long), + [CTLTYPE_S8] = sizeof(int8_t), + [CTLTYPE_S16] = sizeof(int16_t), + [CTLTYPE_S32] = sizeof(int32_t), + [CTLTYPE_S64] = sizeof(int64_t), + [CTLTYPE_U8] = sizeof(uint8_t), + [CTLTYPE_U16] = sizeof(uint16_t), + [CTLTYPE_U32] = sizeof(uint32_t), + [CTLTYPE_U64] = sizeof(uint64_t), +}; + +#ifdef TARGET_ABI32 +/* + * Limit the amount of available memory to be most of the 32-bit address + * space. 0x100c000 was arrived at through trial and error as a good + * definition of 'most'. + */ +static const abi_ulong guest_max_mem = UINT32_MAX - 0x100c000 + 1; + +static abi_ulong G_GNUC_UNUSED cap_memory(uint64_t mem) +{ + return MIN(guest_max_mem, mem); +} +#endif + +static abi_ulong G_GNUC_UNUSED scale_to_guest_pages(uint64_t pages) +{ + /* Scale pages from host to guest */ + pages = muldiv64(pages, qemu_real_host_page_size(), TARGET_PAGE_SIZE); +#ifdef TARGET_ABI32 + /* cap pages if need be */ + pages = MIN(pages, guest_max_mem / (abi_ulong)TARGET_PAGE_SIZE); +#endif + return pages; +} + +#ifdef TARGET_ABI32 +/* Used only for TARGET_ABI32 */ +static abi_long G_GNUC_UNUSED h2g_long_sat(long l) +{ + if (l > INT32_MAX) { + l = INT32_MAX; + } else if (l < INT32_MIN) { + l = INT32_MIN; + } + return l; +} + +static abi_ulong G_GNUC_UNUSED h2g_ulong_sat(u_long ul) +{ + return MIN(ul, UINT32_MAX); +} +#endif + +/* + * placeholder until bsd-user downstream upstreams this with its thread support + */ +#define bsd_get_ncpu() 1 + /* sysarch() is architecture dependent. */ abi_long do_freebsd_sysarch(void *cpu_env, abi_long arg1, abi_long arg2) { From patchwork Thu Feb 16 23:33:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 1744014 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bsdimp-com.20210112.gappssmtp.com header.i=@bsdimp-com.20210112.gappssmtp.com header.a=rsa-sha256 header.s=20210112 header.b=7k5QiAXq; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4PHrsc6Rr1z1yYg for ; Fri, 17 Feb 2023 10:35:32 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pSnlO-00006w-TG; Thu, 16 Feb 2023 18:34:06 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pSnlK-0008UX-J8 for qemu-devel@nongnu.org; Thu, 16 Feb 2023 18:34:02 -0500 Received: from mail-il1-x12c.google.com ([2607:f8b0:4864:20::12c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pSnlI-0008Pc-Qc for qemu-devel@nongnu.org; Thu, 16 Feb 2023 18:34:02 -0500 Received: by mail-il1-x12c.google.com with SMTP id m18so838346ilf.10 for ; Thu, 16 Feb 2023 15:34:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=EvM91y79wsNlj247LVT9SBZIPzmchHvn7spP1Bu6T5s=; b=7k5QiAXq0ticqh0qUPNXOHL9z7p0sH33VJy//mIRmfuaX9ldG4uRgveEjGno+0J1r6 B0wAg9Fp3tmuJF64/RTZDh7iH2Y0SqLTG39eQ7d+38yuXbetTXlGV6yuFNOlEK9KnCEI qkk0P4DCgUmGonrk4fkicyr9ovtugtQw2ove1qmE9KcIipk790SrG7yq3RUaztq1kLB6 lP9nheqFqEWzrW7atmFlbtWc64uvUZfIlHWITSpeghOxYcjGgbHfpvHQFUBjMkJEwwBx dQR0Ig1D3RuYNZlTd0E3+ndUJWc03cO2N4KEFfM6Zgx3pwzjhu6PExb5cywsDmXYRrkb npvw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=EvM91y79wsNlj247LVT9SBZIPzmchHvn7spP1Bu6T5s=; b=1F71MNLfc57Lo3phgmy1dtYyPgrk9WgIjJkHyFQCjLazZnU/fYGynbrtVwYQkoSt9q YMVYFtibblrYi4ab1hRSgh8SEJ2h8ESGqMA4R4OCIgdu8StXpGmQOqPRYqf4y4UaORlN yh68DKR52GfUmMen4aRnKFfK+XDNSu1Xpu0+GoYL/RXZtpVNuirOFkgfCvIs5P98Wyob Tvx1igO0mbtzhqMzjpmb8sRZAdjHzGeo82T4xFBvcxFAPN9AKYg/qEk9PK+xNyIqaO96 iJUhUp+Wmt8pgPi1LEkB3y4S8O/La8XB6j2G7z/r30by1lZ600IHCdkoq50GS0ILAH5t /2tw== X-Gm-Message-State: AO0yUKXqEp9Il4k8vrmFJ2+aX2kPpY1iM4GCAa3pKw+xrXlEEFDBLm2z 2wGzcbXHZscAQIGuIvuvlOx+Qoeas/FRmJPi X-Google-Smtp-Source: AK7set+2jeVeS8E0fpEov3XM8ov9lY6os41vEyxDbuZHg7pFdrVftUYIvzjeY/jBqXkPEwp72ZKMKQ== X-Received: by 2002:a05:6e02:1e05:b0:315:4b70:8370 with SMTP id g5-20020a056e021e0500b003154b708370mr10223697ila.9.1676590439866; Thu, 16 Feb 2023 15:33:59 -0800 (PST) Received: from dune.bsdimp.com (c-71-237-47-177.hsd1.co.comcast.net. [71.237.47.177]) by smtp.gmail.com with ESMTPSA id y7-20020a02a387000000b00346a98b0a76sm934816jak.77.2023.02.16.15.33.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Feb 2023 15:33:59 -0800 (PST) From: Warner Losh To: qemu-devel@nongnu.org Cc: Kyle Evans , richard.henderson@linaro.org, =?utf-8?q?Alex_Benn=C3=A9e?= , f4bug@amsat.org, Warner Losh , Paolo Bonzini , Thomas Huth , Stacey Son , Sean Bruno , Juergen Lock , Raphael Kubo da Costa Subject: [PATCH v3 05/11] bsd-user: Helper routines oidfmt Date: Thu, 16 Feb 2023 16:33:47 -0700 Message-Id: <20230216233353.13944-6-imp@bsdimp.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230216233353.13944-1-imp@bsdimp.com> References: <20230216233353.13944-1-imp@bsdimp.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::12c; envelope-from=imp@bsdimp.com; helo=mail-il1-x12c.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=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: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Stacey Son oidfmt uses undocumented system call to get the type of the sysctl. Co-Authored-by: Sean Bruno Signed-off-by: Sean Bruno Co-Authored-by: Juergen Lock Signed-off-by: Juergen Lock Co-Authored-by: Raphael Kubo da Costa Signed-off-by: Raphael Kubo da Costa Signed-off-by: Stacey Son Reviewed-by: Warner Losh Signed-off-by: Warner Losh Acked-by: Richard Henderson --- bsd-user/freebsd/os-sys.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/bsd-user/freebsd/os-sys.c b/bsd-user/freebsd/os-sys.c index 9b84e90cb32..1bf2b51820e 100644 --- a/bsd-user/freebsd/os-sys.c +++ b/bsd-user/freebsd/os-sys.c @@ -107,6 +107,38 @@ static abi_ulong G_GNUC_UNUSED h2g_ulong_sat(u_long ul) */ #define bsd_get_ncpu() 1 +/* + * This uses the undocumented oidfmt interface to find the kind of a requested + * sysctl, see /sys/kern/kern_sysctl.c:sysctl_sysctl_oidfmt() (compare to + * src/sbin/sysctl/sysctl.c) + */ +static int G_GNUC_UNUSED oidfmt(int *oid, int len, char *fmt, uint32_t *kind) +{ + int qoid[CTL_MAXNAME + 2]; + uint8_t buf[BUFSIZ]; + int i; + size_t j; + + qoid[0] = CTL_SYSCTL; + qoid[1] = CTL_SYSCTL_OIDFMT; + memcpy(qoid + 2, oid, len * sizeof(int)); + + j = sizeof(buf); + i = sysctl(qoid, len + 2, buf, &j, 0, 0); + if (i) { + return i; + } + + if (kind) { + *kind = *(uint32_t *)buf; + } + + if (fmt) { + strcpy(fmt, (char *)(buf + sizeof(uint32_t))); + } + return 0; +} + /* sysarch() is architecture dependent. */ abi_long do_freebsd_sysarch(void *cpu_env, abi_long arg1, abi_long arg2) { From patchwork Thu Feb 16 23:33:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 1744016 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bsdimp-com.20210112.gappssmtp.com header.i=@bsdimp-com.20210112.gappssmtp.com header.a=rsa-sha256 header.s=20210112 header.b=DiwPs8ji; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4PHrsk5nWNz1yYg for ; Fri, 17 Feb 2023 10:35:38 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pSnlO-000065-2F; Thu, 16 Feb 2023 18:34:06 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pSnlN-00004v-45 for qemu-devel@nongnu.org; Thu, 16 Feb 2023 18:34:05 -0500 Received: from mail-il1-x12c.google.com ([2607:f8b0:4864:20::12c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pSnlL-0008Qr-5z for qemu-devel@nongnu.org; Thu, 16 Feb 2023 18:34:04 -0500 Received: by mail-il1-x12c.google.com with SMTP id i26so1403059ila.11 for ; Thu, 16 Feb 2023 15:34:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=t3IWrnGl4pF51ODc0/WxLp2uU7S+u2cBX78xflQCoHA=; b=DiwPs8jihFTx5+GePfqyeUDwULxgSMb7AHc1of+K6oYuukB+mHKk8P3wUhgIRTmnuL lpxhxc7bK6GbZQ5GOMb4g8+kK/L7O+lCHnWKq/g4Pooo5gzDKLE0cM3EMYLgoTNPius0 UPGWtD8+D8lT9lilETDwoJnPXqhk6OOg4/wtSYGEPleVT0G1LwENHya5WyojoaEyzrEZ H0fNAiWm49slIozlL+p4roiYctkhJlY7dxMG75QYciaM99sUDVUpMeWM7vB9JYVFb2al UObOIufSJz3WFJdaY0NLV/LobwcXVvfpoX98gnUUUViXcxUQRyODl8/P6Ib2/IdqfGul FDhg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=t3IWrnGl4pF51ODc0/WxLp2uU7S+u2cBX78xflQCoHA=; b=54vxAWIlSzuNbeI14s9GvDyODyDFq94FEj47S7n5JFSISPKuHAeH2mCFy5S6e6Qp0K bhRiyX9W6X9elmmBxy/nDe1flwPVb1105q4RZJd08LqnfuzPHoHupKpwaZosISbhw4vv GZVGKHgo8pkbrcHVBOY24OqAXaefTcp+GeXNrY0cZJWMHaiCVhKmtEqho8Ex0MTi137o 6QXOU86GM2lXl91w3qMIKQvFpk3T4bVR4xrBezcLz/AFruKTWdo1fOOiU4g/SDS+gTu7 UmaKUMqlrv11pi5cd76FwmPcquWczmSr08/S83KkhEXDEUuDDhNmMzyQIxNQioKCHY6D aIRg== X-Gm-Message-State: AO0yUKWtdsTR+PEyuDouhj3uXiczEFNwBuih22VYqXOofXymLNXV4wQz 45vebjd6tw6wR6baoIr5SIjbeIvYKTIcBkW3 X-Google-Smtp-Source: AK7set+aUbNiJ1SciV7biOJpk2v1vbdg0U2Ig6Ctdu91BmV9bb9FhSpuyaxIiSCgTrhS79qL/80KAw== X-Received: by 2002:a05:6e02:1488:b0:314:fa6:323c with SMTP id n8-20020a056e02148800b003140fa6323cmr7514382ilk.12.1676590440963; Thu, 16 Feb 2023 15:34:00 -0800 (PST) Received: from dune.bsdimp.com (c-71-237-47-177.hsd1.co.comcast.net. [71.237.47.177]) by smtp.gmail.com with ESMTPSA id y7-20020a02a387000000b00346a98b0a76sm934816jak.77.2023.02.16.15.33.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Feb 2023 15:34:00 -0800 (PST) From: Warner Losh To: qemu-devel@nongnu.org Cc: Kyle Evans , richard.henderson@linaro.org, =?utf-8?q?Alex_Benn=C3=A9e?= , f4bug@amsat.org, Warner Losh , Paolo Bonzini , Thomas Huth , Sean Bruno , Juergen Lock , Raphael Kubo da Costa , Stacey Son Subject: [PATCH v3 06/11] bsd-user: Helper routines h2g_old_sysctl Date: Thu, 16 Feb 2023 16:33:48 -0700 Message-Id: <20230216233353.13944-7-imp@bsdimp.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230216233353.13944-1-imp@bsdimp.com> References: <20230216233353.13944-1-imp@bsdimp.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::12c; envelope-from=imp@bsdimp.com; helo=mail-il1-x12c.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=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: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org h2g_old_sysctl does the byte swapping in the data to return it to the target for the 'well known' types. For most of the types, either the data is returned verbatim (strings, byte size, opaque we don't know about) or it's returned with byte swapping (for all the integer types). However, for ABI32 targets, LONG and ULONG are different sizes, and need to be carefully converted (along with help from the caller). Co-Authored-by: Sean Bruno Signed-off-by: Sean Bruno Co-Authored-by: Juergen Lock Signed-off-by: Juergen Lock Co-Authored-by: Raphael Kubo da Costa Signed-off-by: Raphael Kubo da Costa Co-Authored-by: Stacey Son Signed-off-by: Stacey Son Signed-off-by: Warner Losh Reviewed-by: Richard Henderson --- bsd-user/freebsd/os-sys.c | 100 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 96 insertions(+), 4 deletions(-) diff --git a/bsd-user/freebsd/os-sys.c b/bsd-user/freebsd/os-sys.c index 1bf2b51820e..77c2b157c61 100644 --- a/bsd-user/freebsd/os-sys.c +++ b/bsd-user/freebsd/os-sys.c @@ -29,7 +29,7 @@ * Compare with sys/kern_sysctl.c ctl_size * Note: Not all types appear to be used in-tree. */ -static const int G_GNUC_UNUSED guest_ctl_size[CTLTYPE+1] = { +static const int guest_ctl_size[CTLTYPE+1] = { [CTLTYPE_INT] = sizeof(abi_int), [CTLTYPE_UINT] = sizeof(abi_uint), [CTLTYPE_LONG] = sizeof(abi_long), @@ -44,7 +44,7 @@ static const int G_GNUC_UNUSED guest_ctl_size[CTLTYPE+1] = { [CTLTYPE_U64] = sizeof(uint64_t), }; -static const int G_GNUC_UNUSED host_ctl_size[CTLTYPE+1] = { +static const int host_ctl_size[CTLTYPE+1] = { [CTLTYPE_INT] = sizeof(int), [CTLTYPE_UINT] = sizeof(u_int), [CTLTYPE_LONG] = sizeof(long), @@ -86,7 +86,7 @@ static abi_ulong G_GNUC_UNUSED scale_to_guest_pages(uint64_t pages) #ifdef TARGET_ABI32 /* Used only for TARGET_ABI32 */ -static abi_long G_GNUC_UNUSED h2g_long_sat(long l) +static abi_long h2g_long_sat(long l) { if (l > INT32_MAX) { l = INT32_MAX; @@ -96,7 +96,7 @@ static abi_long G_GNUC_UNUSED h2g_long_sat(long l) return l; } -static abi_ulong G_GNUC_UNUSED h2g_ulong_sat(u_long ul) +static abi_ulong h2g_ulong_sat(u_long ul) { return MIN(ul, UINT32_MAX); } @@ -139,6 +139,98 @@ static int G_GNUC_UNUSED oidfmt(int *oid, int len, char *fmt, uint32_t *kind) return 0; } +/* + * Convert the old value from host to guest. + * + * For LONG and ULONG on ABI32, we need to 'down convert' the 8 byte quantities + * to 4 bytes. The caller setup a buffer in host memory to get this data from + * the kernel and pass it to us. We do the down conversion and adjust the length + * so the caller knows what to write as the returned length into the target when + * it copies the down converted values into the target. + * + * For normal integral types, we just need to byte swap. No size changes. + * + * For strings and node data, there's no conversion needed. + * + * For opaque data, per sysctl OID converts take care of it. + */ +static void G_GNUC_UNUSED h2g_old_sysctl(void *holdp, size_t *holdlen, uint32_t kind) +{ + size_t len; + int hlen, glen; + uint8_t *hp, *gp; + + /* + * Although rare, we can have arrays of sysctl. Both sysctl_old_ddb in + * kern_sysctl.c and show_var in sbin/sysctl/sysctl.c have code that loops + * this way. *holdlen has been set by the kernel to the host's length. + * Only LONG and ULONG on ABI32 have different sizes: see below. + */ + gp = hp = (uint8_t *)holdp; + len = 0; + hlen = host_ctl_size[kind & CTLTYPE]; + glen = guest_ctl_size[kind & CTLTYPE]; + + /* + * hlen == 0 for CTLTYPE_STRING and CTLTYPE_NODE, which need no conversion + * as well as CTLTYPE_OPAQUE, which needs special converters. + */ + if (hlen == 0) { + return; + } + + while (len < *holdlen) { + if (hlen == glen) { + switch (hlen) { + case 1: + /* Nothing needed: no byteswapping and assigning in place */ + break; + case 2: + *(uint16_t *)gp = tswap16(*(uint16_t *)hp); + break; + case 4: + *(uint32_t *)gp = tswap32(*(uint32_t *)hp); + break; + case 8: + *(uint64_t *)gp = tswap64(*(uint64_t *)hp); + break; + default: + g_assert_not_reached(); + } + } + else { +#ifdef TARGET_ABI32 + /* + * Saturating assignment for the only two types that differ between + * 32-bit and 64-bit machines. All other integral types have the + * same, fixed size and will be converted w/o loss of precision + * in the above switch. + */ + switch (kind & CTLTYPE) { + case CTLTYPE_LONG: + *(abi_long *)gp = tswap32(h2g_long_sat(*(long *)hp)); + break; + case CTLTYPE_ULONG: + *(abi_ulong *)gp = tswap32(h2g_ulong_sat(*(u_long *)hp)); + break; + default: + g_assert_not_reached(); + } +#else + g_assert_not_reached(); +#endif + } + gp += glen; + hp += hlen; + len += hlen; + } +#ifdef TARGET_ABI32 + if (hlen != glen) { + *holdlen = (*holdlen / hlen) * glen; + } +#endif +} + /* sysarch() is architecture dependent. */ abi_long do_freebsd_sysarch(void *cpu_env, abi_long arg1, abi_long arg2) { From patchwork Thu Feb 16 23:33:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 1744010 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bsdimp-com.20210112.gappssmtp.com header.i=@bsdimp-com.20210112.gappssmtp.com header.a=rsa-sha256 header.s=20210112 header.b=TyOZIoQ2; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4PHrs04G1Tz23r4 for ; Fri, 17 Feb 2023 10:35:00 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pSnlO-00006h-RT; Thu, 16 Feb 2023 18:34:06 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pSnlN-00005s-Pg for qemu-devel@nongnu.org; Thu, 16 Feb 2023 18:34:05 -0500 Received: from mail-il1-x12d.google.com ([2607:f8b0:4864:20::12d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pSnlL-0008Qw-Fa for qemu-devel@nongnu.org; Thu, 16 Feb 2023 18:34:05 -0500 Received: by mail-il1-x12d.google.com with SMTP id g14so1412724ild.8 for ; Thu, 16 Feb 2023 15:34:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=FhVzycqE0CnkRK/EllKXUUS5z7C/peztHUJhIU/Hd5o=; b=TyOZIoQ2Be03RZeOpwiC72Vso0MZ85tBYyYbewXtKz0yk+4UX4RhCU/YY2McmVlMNX hR7SqcrD8lI9ZujLiUJyrvxUHxM91gULiJcM6cHgbKCN3o7btaAcp+HSwoZAdHvlTutd 1SrZaISyI0ZwxRy5f51/vHREUEjaVjWyiRgvEz5rvnvx4G0FCxFlKOCNkxnjskuusqDx 50MksYSDquUVnP6YPJYLrQBRVfLS8f8ZUiHHK4twX6StTysZOZWCnEK9+eZAM75YypY8 655q9yaajhPwFLVkQU1RBdiBAg+MJD3Kx1fmZYDAPplxI8FxPcvsl7rIZ/++p7u1lnZU Rhvw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=FhVzycqE0CnkRK/EllKXUUS5z7C/peztHUJhIU/Hd5o=; b=Ic2d3X0DotGIDGtZ+gA7TYt2/qA6aEuMNX/0Z5i6JYTMt4hZZJbZoo/W8+FohNPoo5 QLrz9g26He4RtMrOyahMGUJPWagwUBlfL+6XJvLlc8UIKCck+eMEdYuvDBnM4QAZDi6Y z+DMBLb92ErQ8LVqZ48UmVqb4ZrkdXDru7dgMKgaLw7EJd9BKz9SvaqxAqi4QIEUiMp0 SvVWYw7E/XUl8v1/83cH5VDVRrzLQ5Yk22yxtZ4aUDIg5ZT/b4AHFL4XwVHWc344QZp8 qEe+OaY6pWl8sx7SToPBATs30OHPw/7wbFKb+3ZTiNTjAFQT4/N1HbJPvFj5cxBHVCC0 VsaQ== X-Gm-Message-State: AO0yUKUiOLpurzgg09eXoLjscTtfwjGvR7xKWH4cHWzIwCmHbWSJv5C2 kuU5/zNwYVH1yg2Yud+bB4E+TWiAI7FAQoU9 X-Google-Smtp-Source: AK7set8r4KOVpwfVLZgDbZfEDee+iOP/zcw+jEthp5xqTxbujf6PPFHAWNjRJ629LmLyKoaV/REzQw== X-Received: by 2002:a05:6e02:1525:b0:315:851c:279 with SMTP id i5-20020a056e02152500b00315851c0279mr3095212ilu.1.1676590441833; Thu, 16 Feb 2023 15:34:01 -0800 (PST) Received: from dune.bsdimp.com (c-71-237-47-177.hsd1.co.comcast.net. [71.237.47.177]) by smtp.gmail.com with ESMTPSA id y7-20020a02a387000000b00346a98b0a76sm934816jak.77.2023.02.16.15.34.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Feb 2023 15:34:01 -0800 (PST) From: Warner Losh To: qemu-devel@nongnu.org Cc: Kyle Evans , richard.henderson@linaro.org, =?utf-8?q?Alex_Benn=C3=A9e?= , f4bug@amsat.org, Warner Losh , Paolo Bonzini , Thomas Huth , Juergen Lock Subject: [PATCH v3 07/11] bsd-user: sysctl helper funtions: sysctl_name2oid and sysctl_oidfmt Date: Thu, 16 Feb 2023 16:33:49 -0700 Message-Id: <20230216233353.13944-8-imp@bsdimp.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230216233353.13944-1-imp@bsdimp.com> References: <20230216233353.13944-1-imp@bsdimp.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::12d; envelope-from=imp@bsdimp.com; helo=mail-il1-x12d.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=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: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Juergen Lock Helper functions for sysctl implementations. sysctl_name2oid and sysctl_oidfmt convert oids between host and targets Signed-off-by: Juergen Lock Reviewed-by: Warner Losh Signed-off-by: Warner Losh Reviewed-by: Richard Henderson --- bsd-user/freebsd/os-sys.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/bsd-user/freebsd/os-sys.c b/bsd-user/freebsd/os-sys.c index 77c2b157c61..dee8c92309b 100644 --- a/bsd-user/freebsd/os-sys.c +++ b/bsd-user/freebsd/os-sys.c @@ -231,6 +231,24 @@ static void G_GNUC_UNUSED h2g_old_sysctl(void *holdp, size_t *holdlen, uint32_t #endif } +/* + * Convert the undocmented name2oid sysctl data for the target. + */ +static inline void G_GNUC_UNUSED sysctl_name2oid(uint32_t *holdp, size_t holdlen) +{ + size_t i, num = holdlen / sizeof(uint32_t); + + for (i = 0; i < num; i++) { + holdp[i] = tswap32(holdp[i]); + } +} + +static inline void G_GNUC_UNUSED sysctl_oidfmt(uint32_t *holdp) +{ + /* byte swap the kind */ + holdp[0] = tswap32(holdp[0]); +} + /* sysarch() is architecture dependent. */ abi_long do_freebsd_sysarch(void *cpu_env, abi_long arg1, abi_long arg2) { From patchwork Thu Feb 16 23:33:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 1744018 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bsdimp-com.20210112.gappssmtp.com header.i=@bsdimp-com.20210112.gappssmtp.com header.a=rsa-sha256 header.s=20210112 header.b=eHcCFiqa; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4PHrt42cD6z1yYg for ; Fri, 17 Feb 2023 10:35:56 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pSnlQ-00007x-Dl; Thu, 16 Feb 2023 18:34:08 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pSnlO-00006P-Ju for qemu-devel@nongnu.org; Thu, 16 Feb 2023 18:34:06 -0500 Received: from mail-io1-xd34.google.com ([2607:f8b0:4864:20::d34]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pSnlM-0008R9-SM for qemu-devel@nongnu.org; Thu, 16 Feb 2023 18:34:06 -0500 Received: by mail-io1-xd34.google.com with SMTP id j4so1322461iog.8 for ; Thu, 16 Feb 2023 15:34:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=121msZ7BQw47YP3HHlZFZiV5/sv+6Qz3v9vW8ncVL2Q=; b=eHcCFiqal+MKDi4p3P9Yeyjpy3veTZVhdziRks09iocYe8F+QKMwVngQ434sCPcJGA i2D0OAyGZMs9e7a1Q5d0tA1U6buKWxjbwfDKuYWZhZ6SJC58d79eoPQJqADaJWw95prw 5AhErwZPfuJv6oZ/4WKmHtDFpwKVhTR5PK/9Av4Gv/WlsZ/GD06mOoGaOjY7rz74kDoB hvxapf28mzaHj8+dvXyaiVIoVYd5AYnmeuFIITQO6KEYnoUPvAF4pXbAViXrz+ProYat Y14W0JOFV8veLcuEwUy/zojQz48RNK0ANIkRxfm1ZMTUAMnHaYvPGd54SWL22pC1bluu YErw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=121msZ7BQw47YP3HHlZFZiV5/sv+6Qz3v9vW8ncVL2Q=; b=FYGilxZOsRMoefiAxuAR+MYpMtsMnHLH+AiTzjDq9bhPpGXLTalzRT4pbyDHtvl0GG /8Vn39QHGXtZ4DvN4nsVCnROL8UehSHGR9QgW8thgsUIPTKSSpBZvVhU1FbzqRXWoqO2 OwHmjGVdpUGhviefmklpL76TnzH0rHaIhYOuFBWRGHU3GH/ke9Tk1ikxFH6VBVv3S1KY SuSb51AQXeRhr2M8exijCAYUExCoZw9LdDHaj3DeYfuBkDt6b9qBrdYetJ2AI2W4/T28 8nKtTmDCyzNUOSEmsJraKrasEHrn5+dFUBhFZfRdTh2fC/Zl/M6guRB6Qjt5d99YFk/7 fRmA== X-Gm-Message-State: AO0yUKWQO/wQNpVvdcxaZVw18ywJsaF3oBkukr7GFWCxF/Petawcv0iL /9XD80b/yjskxKCRNfBSuRDw+pXnZwlGCmOu X-Google-Smtp-Source: AK7set+VTQl28qPjtZZqyDW4dfkz/S2vIzwzZkAismv7qDSKG+obg8LhNEnSNiF9XRZ8+hsZxSIGXw== X-Received: by 2002:a5d:8896:0:b0:717:df30:e56c with SMTP id d22-20020a5d8896000000b00717df30e56cmr5602538ioo.2.1676590442915; Thu, 16 Feb 2023 15:34:02 -0800 (PST) Received: from dune.bsdimp.com (c-71-237-47-177.hsd1.co.comcast.net. [71.237.47.177]) by smtp.gmail.com with ESMTPSA id y7-20020a02a387000000b00346a98b0a76sm934816jak.77.2023.02.16.15.34.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Feb 2023 15:34:02 -0800 (PST) From: Warner Losh To: qemu-devel@nongnu.org Cc: Kyle Evans , richard.henderson@linaro.org, =?utf-8?q?Alex_Benn=C3=A9e?= , f4bug@amsat.org, Warner Losh , Paolo Bonzini , Thomas Huth , Juergen Lock , Stacey Son Subject: [PATCH v3 08/11] bsd-user: common routine do_freebsd_sysctl_oid for all sysctl variants Date: Thu, 16 Feb 2023 16:33:50 -0700 Message-Id: <20230216233353.13944-9-imp@bsdimp.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230216233353.13944-1-imp@bsdimp.com> References: <20230216233353.13944-1-imp@bsdimp.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::d34; envelope-from=imp@bsdimp.com; helo=mail-io1-xd34.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=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: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Juergen Lock do_freebsd_sysctl_oid filters out some of the binary and special sysctls where host != target. None of the sysctls that have to be translated from host to target are handled here. Signed-off-by: Juergen Lock Co-Authored-by: Stacey Son Signed-off-by: Stacey Son Co-Authored-by: Warner Losh Signed-off-by: Warner Losh Reviewed-by: Richard Henderson --- bsd-user/freebsd/os-sys.c | 90 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 86 insertions(+), 4 deletions(-) diff --git a/bsd-user/freebsd/os-sys.c b/bsd-user/freebsd/os-sys.c index dee8c92309b..42f0cc82279 100644 --- a/bsd-user/freebsd/os-sys.c +++ b/bsd-user/freebsd/os-sys.c @@ -112,7 +112,7 @@ static abi_ulong h2g_ulong_sat(u_long ul) * sysctl, see /sys/kern/kern_sysctl.c:sysctl_sysctl_oidfmt() (compare to * src/sbin/sysctl/sysctl.c) */ -static int G_GNUC_UNUSED oidfmt(int *oid, int len, char *fmt, uint32_t *kind) +static int oidfmt(int *oid, int len, char *fmt, uint32_t *kind) { int qoid[CTL_MAXNAME + 2]; uint8_t buf[BUFSIZ]; @@ -154,7 +154,7 @@ static int G_GNUC_UNUSED oidfmt(int *oid, int len, char *fmt, uint32_t *kind) * * For opaque data, per sysctl OID converts take care of it. */ -static void G_GNUC_UNUSED h2g_old_sysctl(void *holdp, size_t *holdlen, uint32_t kind) +static void h2g_old_sysctl(void *holdp, size_t *holdlen, uint32_t kind) { size_t len; int hlen, glen; @@ -234,7 +234,7 @@ static void G_GNUC_UNUSED h2g_old_sysctl(void *holdp, size_t *holdlen, uint32_t /* * Convert the undocmented name2oid sysctl data for the target. */ -static inline void G_GNUC_UNUSED sysctl_name2oid(uint32_t *holdp, size_t holdlen) +static inline void sysctl_name2oid(uint32_t *holdp, size_t holdlen) { size_t i, num = holdlen / sizeof(uint32_t); @@ -243,12 +243,94 @@ static inline void G_GNUC_UNUSED sysctl_name2oid(uint32_t *holdp, size_t holdlen } } -static inline void G_GNUC_UNUSED sysctl_oidfmt(uint32_t *holdp) +static inline void sysctl_oidfmt(uint32_t *holdp) { /* byte swap the kind */ holdp[0] = tswap32(holdp[0]); } +static abi_long G_GNUC_UNUSED do_freebsd_sysctl_oid(CPUArchState *env, int32_t *snamep, + int32_t namelen, void *holdp, size_t *holdlenp, void *hnewp, + size_t newlen) +{ + uint32_t kind = 0; + abi_long ret; + size_t holdlen, oldlen; +#ifdef TARGET_ABI32 + void *old_holdp; +#endif + + holdlen = oldlen = *holdlenp; + oidfmt(snamep, namelen, NULL, &kind); + + /* Handle some arch/emulator dependent sysctl()'s here. */ + +#ifdef TARGET_ABI32 + /* + * For long and ulong with a 64-bit host and a 32-bit target we have to do + * special things. holdlen here is the length provided by the target to the + * system call. So we allocate a buffer twice as large because longs are twice + * as big on the host which will be writing them. In h2g_old_sysctl we'll adjust + * them and adjust the length. + */ + if (kind == CTLTYPE_LONG || kind == CTLTYPE_ULONG) { + old_holdp = holdp; + holdlen = holdlen * 2; + holdp = g_malloc(holdlen); + } +#endif + + ret = get_errno(sysctl(snamep, namelen, holdp, &holdlen, hnewp, newlen)); + if (!ret && (holdp != 0)) { + + if (snamep[0] == CTL_SYSCTL) { + switch (snamep[1]) { + case CTL_SYSCTL_NEXT: + case CTL_SYSCTL_NAME2OID: + case CTL_SYSCTL_NEXTNOSKIP: + /* + * All of these return an OID array, so we need to convert to + * target. + */ + sysctl_name2oid(holdp, holdlen); + break; + + case CTL_SYSCTL_OIDFMT: + /* Handle oidfmt */ + sysctl_oidfmt(holdp); + break; + case CTL_SYSCTL_OIDDESCR: + case CTL_SYSCTL_OIDLABEL: + default: + /* Handle it based on the type */ + h2g_old_sysctl(holdp, &holdlen, kind); + /* NB: None of these are LONG or ULONG */ + break; + } + } else { + /* + * Need to convert from host to target. All the weird special cases + * are handled above. + */ + h2g_old_sysctl(holdp, &holdlen, kind); +#ifdef TARGET_ABI32 + /* + * For the 32-bit on 64-bit case, for longs we need to copy the + * now-converted buffer to the target and free the buffer. + */ + if (kind == CTLTYPE_LONG || kind == CTLTYPE_ULONG) { + memcpy(old_holdp, holdp, holdlen); + g_free(holdp); + holdp = old_holdp; + } +#endif + } + } + + *holdlenp = holdlen; + return ret; +} + /* sysarch() is architecture dependent. */ abi_long do_freebsd_sysarch(void *cpu_env, abi_long arg1, abi_long arg2) { From patchwork Thu Feb 16 23:33:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 1744013 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bsdimp-com.20210112.gappssmtp.com header.i=@bsdimp-com.20210112.gappssmtp.com header.a=rsa-sha256 header.s=20210112 header.b=QFKPf6LF; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4PHrsL16Cvz1yYg for ; Fri, 17 Feb 2023 10:35:18 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pSnlQ-00008Z-UI; Thu, 16 Feb 2023 18:34:08 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pSnlP-000072-14 for qemu-devel@nongnu.org; Thu, 16 Feb 2023 18:34:07 -0500 Received: from mail-il1-x130.google.com ([2607:f8b0:4864:20::130]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pSnlN-0008Ph-5x for qemu-devel@nongnu.org; Thu, 16 Feb 2023 18:34:06 -0500 Received: by mail-il1-x130.google.com with SMTP id v13so1422629iln.4 for ; Thu, 16 Feb 2023 15:34:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=rQSSYyJH9Z4zIbAHEAHA5MUcncm7KN1aWBx0s4v1VyI=; b=QFKPf6LFTWauNR7a5SKlFcoS66l5aOyjGkPfvZNOyaT7S2Ng28N1soV4g9sunIQ1X7 OEyPJu55py12/wOWd9YAivThJaPQgcE4abK+/B/yVC1AHn4DEOAcI+WfTZfT6upMgP/G EamHmT4EdgKO29gxcbgbPwyBTnQBNzcsFXWPGpB45LWHKtFWey4nGYiSwo1Vr1yaAsAf 0CbG08M2Ozw/rYsn+/096vXlYWI22hmrUIPuvBcGYdx5AE6s5eAVIrSbrIWO7I6qVPTG 67QWl9MMd4v9S2kUddS9qqKUguFcRs9WahqIPwYpzTVbttqgR06W8JJ8UCxUDvISnE1Y 9BMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=rQSSYyJH9Z4zIbAHEAHA5MUcncm7KN1aWBx0s4v1VyI=; b=AMD/XC9HrlAgND+eECxi4n3YKNUfQ4zxyoMLq8H3ak7uZDb05uikMtAe4uqehEYkx9 7PhVsueJ/TgMH/3MKH9G/LvSpKhTtXx/2ojmkga4YWHVf3ngNEajipAdAZFS5/Z97LGf TuZgiqrX9bOT8HGW46EmJzhrJtxTUmrjuYraE5R+OP97e+Wcqknv7WwOSTRpw1zil9JG pI2V1f1k2P0riKW3QTruKsEK/hskBsl5VheJWj9US6J/QJ0sSY0yoPaoXhzBEQZggpWc MNRa1wwyIpSmxe4oeeGLjU+t0S6dqvPV4yNktCttD+kggoMD8qqDBu8sxzPjXCfV13CB tQhw== X-Gm-Message-State: AO0yUKUCCvGlpf8pyFkAN4Y2rrzMgC4koOjDCxkpI3MfrPoQp3dQAYkt 49roxddPA2LvgJe1MyA+6Wu/ji9W9mvCXxXc X-Google-Smtp-Source: AK7set9xGgBu1yLRiY4g2xXOSQseB6T1pn4ReylPte7Ya2x9ItyCzl85jqE32qbOOHpJ0XnPh1zscw== X-Received: by 2002:a05:6e02:1a4c:b0:315:9a9b:9b54 with SMTP id u12-20020a056e021a4c00b003159a9b9b54mr658353ilv.12.1676590444115; Thu, 16 Feb 2023 15:34:04 -0800 (PST) Received: from dune.bsdimp.com (c-71-237-47-177.hsd1.co.comcast.net. [71.237.47.177]) by smtp.gmail.com with ESMTPSA id y7-20020a02a387000000b00346a98b0a76sm934816jak.77.2023.02.16.15.34.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Feb 2023 15:34:03 -0800 (PST) From: Warner Losh To: qemu-devel@nongnu.org Cc: Kyle Evans , richard.henderson@linaro.org, =?utf-8?q?Alex_Benn=C3=A9e?= , f4bug@amsat.org, Warner Losh , Paolo Bonzini , Thomas Huth , Juergen Lock , Stacey Son Subject: [PATCH v3 09/11] bsd-user: Start translation of arch-specific sysctls Date: Thu, 16 Feb 2023 16:33:51 -0700 Message-Id: <20230216233353.13944-10-imp@bsdimp.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230216233353.13944-1-imp@bsdimp.com> References: <20230216233353.13944-1-imp@bsdimp.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::130; envelope-from=imp@bsdimp.com; helo=mail-il1-x130.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=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: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Juergen Lock Intercept some syscalls that we need to translate (like the archiecture we're running on) and translate them. These are only the simplest ones so far. Signed-off-by: Juergen Lock Co-Authored-by: Stacey Son Signed-off-by: Stacey Son Co-Authored-by: Warner Losh Signed-off-by: Warner Losh Reviewed-by: Richard Henderson --- bsd-user/freebsd/os-sys.c | 145 +++++++++++++++++++++++++++++++++++++- 1 file changed, 143 insertions(+), 2 deletions(-) diff --git a/bsd-user/freebsd/os-sys.c b/bsd-user/freebsd/os-sys.c index 42f0cc82279..1464e64428f 100644 --- a/bsd-user/freebsd/os-sys.c +++ b/bsd-user/freebsd/os-sys.c @@ -67,13 +67,13 @@ static const int host_ctl_size[CTLTYPE+1] = { */ static const abi_ulong guest_max_mem = UINT32_MAX - 0x100c000 + 1; -static abi_ulong G_GNUC_UNUSED cap_memory(uint64_t mem) +static abi_ulong cap_memory(uint64_t mem) { return MIN(guest_max_mem, mem); } #endif -static abi_ulong G_GNUC_UNUSED scale_to_guest_pages(uint64_t pages) +static abi_ulong scale_to_guest_pages(uint64_t pages) { /* Scale pages from host to guest */ pages = muldiv64(pages, qemu_real_host_page_size(), TARGET_PAGE_SIZE); @@ -264,6 +264,146 @@ static abi_long G_GNUC_UNUSED do_freebsd_sysctl_oid(CPUArchState *env, int32_t * oidfmt(snamep, namelen, NULL, &kind); /* Handle some arch/emulator dependent sysctl()'s here. */ + switch (snamep[0]) { + case CTL_KERN: + switch (snamep[1]) { + case KERN_USRSTACK: + if (oldlen) { + (*(abi_ulong *)holdp) = tswapal(TARGET_USRSTACK); + } + holdlen = sizeof(abi_ulong); + ret = 0; + goto out; + + case KERN_PS_STRINGS: + if (oldlen) { + (*(abi_ulong *)holdp) = tswapal(TARGET_PS_STRINGS); + } + holdlen = sizeof(abi_ulong); + ret = 0; + goto out; + + default: + break; + } + break; + + case CTL_HW: + switch (snamep[1]) { + case HW_MACHINE: + holdlen = sizeof(TARGET_HW_MACHINE); + if (holdp) { + strlcpy(holdp, TARGET_HW_MACHINE, oldlen); + } + ret = 0; + goto out; + + case HW_MACHINE_ARCH: + { + holdlen = sizeof(TARGET_HW_MACHINE_ARCH); + if (holdp) { + strlcpy(holdp, TARGET_HW_MACHINE_ARCH, oldlen); + } + ret = 0; + goto out; + } + case HW_NCPU: + if (oldlen) { + (*(abi_int *)holdp) = tswap32(bsd_get_ncpu()); + } + holdlen = sizeof(int32_t); + ret = 0; + goto out; +#if defined(TARGET_ARM) + case HW_FLOATINGPT: + if (oldlen) { + ARMCPU *cpu = env_archcpu(env); + *(abi_int *)holdp = cpu_isar_feature(aa32_vfp, cpu); + } + holdlen = sizeof(abi_int); + ret = 0; + goto out; +#endif + + +#ifdef TARGET_ABI32 + case HW_PHYSMEM: + case HW_USERMEM: + case HW_REALMEM: + holdlen = sizeof(abi_ulong); + ret = 0; + + if (oldlen) { + int mib[2] = {snamep[0], snamep[1]}; + unsigned long lvalue; + size_t len = sizeof(lvalue); + + if (sysctl(mib, 2, &lvalue, &len, NULL, 0) == -1) { + ret = -1; + } else { + lvalue = cap_memory(lvalue); + (*(abi_ulong *)holdp) = tswapal((abi_ulong)lvalue); + } + } + goto out; +#endif + + default: + { + static int oid_hw_availpages; + static int oid_hw_pagesizes; + + if (!oid_hw_availpages) { + int real_oid[CTL_MAXNAME + 2]; + size_t len = sizeof(real_oid) / sizeof(int); + + if (sysctlnametomib("hw.availpages", real_oid, &len) >= 0) { + oid_hw_availpages = real_oid[1]; + } + } + if (!oid_hw_pagesizes) { + int real_oid[CTL_MAXNAME + 2]; + size_t len = sizeof(real_oid) / sizeof(int); + + if (sysctlnametomib("hw.pagesizes", real_oid, &len) >= 0) { + oid_hw_pagesizes = real_oid[1]; + } + } + + if (oid_hw_availpages && snamep[1] == oid_hw_availpages) { + long lvalue; + size_t len = sizeof(lvalue); + + if (sysctlbyname("hw.availpages", &lvalue, &len, NULL, 0) == -1) { + ret = -1; + } else { + if (oldlen) { + lvalue = scale_to_guest_pages(lvalue); + (*(abi_ulong *)holdp) = tswapal((abi_ulong)lvalue); + } + holdlen = sizeof(abi_ulong); + ret = 0; + } + goto out; + } + + if (oid_hw_pagesizes && snamep[1] == oid_hw_pagesizes) { + if (oldlen) { + (*(abi_ulong *)holdp) = tswapal((abi_ulong)getpagesize()); + ((abi_ulong *)holdp)[1] = 0; + } + holdlen = sizeof(abi_ulong) * 2; + ret = 0; + goto out; + } + break; + } + } + break; + + default: + break; + } #ifdef TARGET_ABI32 /* @@ -327,6 +467,7 @@ static abi_long G_GNUC_UNUSED do_freebsd_sysctl_oid(CPUArchState *env, int32_t * } } +out: *holdlenp = holdlen; return ret; } From patchwork Thu Feb 16 23:33:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 1744008 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bsdimp-com.20210112.gappssmtp.com header.i=@bsdimp-com.20210112.gappssmtp.com header.a=rsa-sha256 header.s=20210112 header.b=r1X5vjJO; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4PHrrw19PCz23r4 for ; Fri, 17 Feb 2023 10:34:56 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pSnlS-00009Y-43; Thu, 16 Feb 2023 18:34:10 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pSnlQ-00007y-D2 for qemu-devel@nongnu.org; Thu, 16 Feb 2023 18:34:08 -0500 Received: from mail-il1-x133.google.com ([2607:f8b0:4864:20::133]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pSnlO-0008Pt-8G for qemu-devel@nongnu.org; Thu, 16 Feb 2023 18:34:08 -0500 Received: by mail-il1-x133.google.com with SMTP id v13so1422643iln.4 for ; Thu, 16 Feb 2023 15:34:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=O+xNG+XIxDzZrfUzAM1AKP8QRLGF04ZsNMQklPyjAdQ=; b=r1X5vjJOspIs0Fl80DHWrWQz/WLfbjM1rjYRKjBSjySclUPpGOlWfiZ2Vh/9vG31Pz dtcUjU2lfMksAlqhUN6JbBU6u9b0q2goqDyHOsDwIW4mtOUnUnlYqsGp8DYJ/6NmeUim JEscLLJ1robmb5VgTmqTKiYd+t+9yVtbnAVetsRLtlHBIU4JBLZ14cibkk/H1RLOqVq2 E0j4pRuSaBMsIamM1iMSEQRBqtTMoSHlcXatx/12LyeDrILwxod+oVLalRG8ceG/OisC IXRQVe73UDz3glfvk497LXP7rQLievdG2Jy/IWLx6QfXBs3chu8Fiz3Llzw00Ub9VZuM c9hA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=O+xNG+XIxDzZrfUzAM1AKP8QRLGF04ZsNMQklPyjAdQ=; b=rQL1Dh5INzHmCh7vQarebvRyh7JrtN9DY6JuhG2NwrcmpERQTjOfn3w6UItlET5UFT XCySdPKg/mnJhP7Mbv103JYEptd3R4DFCb2WmJHmfRzQq9u/eyvB4Q/a2YEsOFCg/3bl QyInM7r4c3Uuojj6wFRLmpAFF+CA4sRD/WeUMSiItMWvLPAIRsf4Rs25erl9QRIX5hzh Zc4EIQVLwtKnSYk8rNeFQ+z8nCpeSCiE3qyyqF9JewRi4ofa6FZqICCIrR57+5PYi7Y0 oXfgMCi/UFxdJxv4OCr7FWcc2JyhmgKJTO11uMN60I9grGN3Ir3ImF1hWO7aIeD7swwO Lz5g== X-Gm-Message-State: AO0yUKUtBjdZpKK+vitgu+51b3w+RumD1X49tuv3V5ItAyZk4zva7pPt RjcMpr5SsWhK2JcaxSEMLundqvPFokeTN4yY X-Google-Smtp-Source: AK7set8+14hLGUJ63avHF2f50tpGcP7pqeSg6ce5ZLFtRPmUZUx+upnLZPJoXAIUxl3cX2eqK5TmIQ== X-Received: by 2002:a05:6e02:2185:b0:312:7bbf:94f5 with SMTP id j5-20020a056e02218500b003127bbf94f5mr8473610ila.3.1676590445233; Thu, 16 Feb 2023 15:34:05 -0800 (PST) Received: from dune.bsdimp.com (c-71-237-47-177.hsd1.co.comcast.net. [71.237.47.177]) by smtp.gmail.com with ESMTPSA id y7-20020a02a387000000b00346a98b0a76sm934816jak.77.2023.02.16.15.34.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Feb 2023 15:34:04 -0800 (PST) From: Warner Losh To: qemu-devel@nongnu.org Cc: Kyle Evans , richard.henderson@linaro.org, =?utf-8?q?Alex_Benn=C3=A9e?= , f4bug@amsat.org, Warner Losh , Paolo Bonzini , Thomas Huth , Kyle Evans , Juergen Lock , Stacey Son Subject: [PATCH v3 10/11] bsd-user: do_freebsd_sysctl helper for sysctl(2) Date: Thu, 16 Feb 2023 16:33:52 -0700 Message-Id: <20230216233353.13944-11-imp@bsdimp.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230216233353.13944-1-imp@bsdimp.com> References: <20230216233353.13944-1-imp@bsdimp.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::133; envelope-from=imp@bsdimp.com; helo=mail-il1-x133.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=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: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Kyle Evans Implement the wrapper function for sysctl(2). This puts the oid arguments into a standard form and calls the common do_freebsd_sysctl_oid. Signed-off-by: Kyle Evans Co-Authored-by: Juergen Lock Signed-off-by: Juergen Lock Co-Authored-by: Stacey Son Signed-off-by: Stacey Son Reviewed-by: Warner Losh Signed-off-by: Warner Losh Reviewed-by: Richard Henderson --- bsd-user/freebsd/os-sys.c | 56 ++++++++++++++++++++++++++++++++++- bsd-user/freebsd/os-syscall.c | 4 +++ bsd-user/qemu.h | 2 ++ 3 files changed, 61 insertions(+), 1 deletion(-) diff --git a/bsd-user/freebsd/os-sys.c b/bsd-user/freebsd/os-sys.c index 1464e64428f..f07ae7da740 100644 --- a/bsd-user/freebsd/os-sys.c +++ b/bsd-user/freebsd/os-sys.c @@ -249,7 +249,7 @@ static inline void sysctl_oidfmt(uint32_t *holdp) holdp[0] = tswap32(holdp[0]); } -static abi_long G_GNUC_UNUSED do_freebsd_sysctl_oid(CPUArchState *env, int32_t *snamep, +static abi_long do_freebsd_sysctl_oid(CPUArchState *env, int32_t *snamep, int32_t namelen, void *holdp, size_t *holdlenp, void *hnewp, size_t newlen) { @@ -472,6 +472,60 @@ out: return ret; } +abi_long do_freebsd_sysctl(CPUArchState *env, abi_ulong namep, int32_t namelen, + abi_ulong oldp, abi_ulong oldlenp, abi_ulong newp, abi_ulong newlen) +{ + abi_long ret = -TARGET_EFAULT; + void *hnamep, *holdp = NULL, *hnewp = NULL; + size_t holdlen; + abi_ulong oldlen = 0; + int32_t *snamep = g_malloc(sizeof(int32_t) * namelen), *p, *q, i; + + /* oldlenp is read/write, pre-check here for write */ + if (oldlenp) { + if (!access_ok(VERIFY_WRITE, oldlenp, sizeof(abi_ulong)) || + get_user_ual(oldlen, oldlenp)) { + goto out; + } + } + hnamep = lock_user(VERIFY_READ, namep, namelen, 1); + if (hnamep == NULL) { + goto out; + } + if (newp) { + hnewp = lock_user(VERIFY_READ, newp, newlen, 1); + if (hnewp == NULL) { + goto out; + } + } + if (oldp) { + holdp = lock_user(VERIFY_WRITE, oldp, oldlen, 0); + if (holdp == NULL) { + goto out; + } + } + holdlen = oldlen; + for (p = hnamep, q = snamep, i = 0; i < namelen; p++, i++, q++) { + *q = tswap32(*p); + } + + ret = do_freebsd_sysctl_oid(env, snamep, namelen, holdp, &holdlen, hnewp, + newlen); + + /* + * writeability pre-checked above. __sysctl(2) returns ENOMEM and updates + * oldlenp for the proper size to use. + */ + if (oldlenp && (ret == 0 || ret == -TARGET_ENOMEM)) { + put_user_ual(holdlen, oldlenp); + } + unlock_user(hnamep, namep, 0); + unlock_user(holdp, oldp, ret == 0 ? holdlen : 0); +out: + g_free(snamep); + return ret; +} + /* sysarch() is architecture dependent. */ abi_long do_freebsd_sysarch(void *cpu_env, abi_long arg1, abi_long arg2) { diff --git a/bsd-user/freebsd/os-syscall.c b/bsd-user/freebsd/os-syscall.c index e00997a818c..20ab3d4d9a1 100644 --- a/bsd-user/freebsd/os-syscall.c +++ b/bsd-user/freebsd/os-syscall.c @@ -494,6 +494,10 @@ static abi_long freebsd_syscall(void *cpu_env, int num, abi_long arg1, /* * sys{ctl, arch, call} */ + case TARGET_FREEBSD_NR___sysctl: /* sysctl(3) */ + ret = do_freebsd_sysctl(cpu_env, arg1, arg2, arg3, arg4, arg5, arg6); + break; + case TARGET_FREEBSD_NR_sysarch: /* sysarch(2) */ ret = do_freebsd_sysarch(cpu_env, arg1, arg2); break; diff --git a/bsd-user/qemu.h b/bsd-user/qemu.h index 0ceecfb6dfa..c7248cfde6f 100644 --- a/bsd-user/qemu.h +++ b/bsd-user/qemu.h @@ -252,6 +252,8 @@ bool is_error(abi_long ret); int host_to_target_errno(int err); /* os-sys.c */ +abi_long do_freebsd_sysctl(CPUArchState *env, abi_ulong namep, int32_t namelen, + abi_ulong oldp, abi_ulong oldlenp, abi_ulong newp, abi_ulong newlen); abi_long do_freebsd_sysarch(void *cpu_env, abi_long arg1, abi_long arg2); /* user access */ From patchwork Thu Feb 16 23:33:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 1744011 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bsdimp-com.20210112.gappssmtp.com header.i=@bsdimp-com.20210112.gappssmtp.com header.a=rsa-sha256 header.s=20210112 header.b=IrTPshsT; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4PHrs46NYnz23yJ for ; Fri, 17 Feb 2023 10:35:04 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pSnlT-00009l-3s; Thu, 16 Feb 2023 18:34:11 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pSnlR-00008h-42 for qemu-devel@nongnu.org; Thu, 16 Feb 2023 18:34:09 -0500 Received: from mail-il1-x12d.google.com ([2607:f8b0:4864:20::12d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pSnlP-0008Qw-EA for qemu-devel@nongnu.org; Thu, 16 Feb 2023 18:34:08 -0500 Received: by mail-il1-x12d.google.com with SMTP id g14so1412788ild.8 for ; Thu, 16 Feb 2023 15:34:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=BzF5n/1/KVwLC31ZXtP5Hy3esjXH+09jTaZZtYxZEo4=; b=IrTPshsT3+9BU58xGEDEA10k66GUqKBeRVGZHn60DURMU04Z/wykdJVZ3goJn3Qwjy 6o89UuRoe3FAgHIyTqKcTSVlcAqvgmCkZv+6ttlCjzulm6aMGtBURR8LGSHBqMBy/f2A 0uXzstd2iD9eTBpSuCwwFtej8Y5XhEWxgbPXeFPosSRbMbhkDk1IMiRQQnAI8eW51pRL QTT/yDggS4/OjnDqcDamZCsR1VIYdrKA8Z89WvnLV1GGiopihIM16Pxn8gLKZ+B0UJJp vaCYxtDwZNR2GMqiQNgSef+nz3rX5XrCujul+XgrZOi6YxSOnqyl4lPRhIEPqlOVU0wC ZXsQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=BzF5n/1/KVwLC31ZXtP5Hy3esjXH+09jTaZZtYxZEo4=; b=ofTZ3G7qgTQmr4a5fGx9T05YVcg5WMZpyTQNksCjwaWfy6bkvypXPoqnI6C/WHADGc 4iiq9SqfYEZe+yuRTgp02pgQz65ZjTsLZIC8rZekiQwmKYUVeFGOHiTzVRxkDKAKzoUe Ka3JUkGYJlf9btz6OxtAkW109DkSIN8dzoNuVkalOoFrTy/A1DYI2JcYQpCklLsbcY1n 8VvFHBUgGbyrHN4YloCBR3THh2O7ekuartVzi70z9/AKUv8bnkAeG1FlUQ2x7l3zfUaz Rq5ae73MRtrbA2fOwTIZBytUBEL37wXmgqy8zLSl3nHsVNO5lmWuP1KXWHiKEjmOE6pn 6NRA== X-Gm-Message-State: AO0yUKVuDo9qtwA8Gu56Tn1g50KfRdkp9FGYFbBXoU8BrS3mvxidKtPq z8f6cXzBrTlJcRN8EgsAQpPdHkXHx7AVQYAh X-Google-Smtp-Source: AK7set/uPg3BZBoXrx4Tq1aSn8GGHDLyGEEi50Zdd7g81durcAzjDPtvJkSyRBbUmN2nwXMHYhFsfQ== X-Received: by 2002:a05:6e02:1c4c:b0:315:4350:9c09 with SMTP id d12-20020a056e021c4c00b0031543509c09mr7755952ilg.16.1676590446334; Thu, 16 Feb 2023 15:34:06 -0800 (PST) Received: from dune.bsdimp.com (c-71-237-47-177.hsd1.co.comcast.net. [71.237.47.177]) by smtp.gmail.com with ESMTPSA id y7-20020a02a387000000b00346a98b0a76sm934816jak.77.2023.02.16.15.34.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Feb 2023 15:34:05 -0800 (PST) From: Warner Losh To: qemu-devel@nongnu.org Cc: Kyle Evans , richard.henderson@linaro.org, =?utf-8?q?Alex_Benn=C3=A9e?= , f4bug@amsat.org, Warner Losh , Paolo Bonzini , Thomas Huth , Kyle Evans Subject: [PATCH v3 11/11] bsd-user: implement sysctlbyname(2) Date: Thu, 16 Feb 2023 16:33:53 -0700 Message-Id: <20230216233353.13944-12-imp@bsdimp.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230216233353.13944-1-imp@bsdimp.com> References: <20230216233353.13944-1-imp@bsdimp.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::12d; envelope-from=imp@bsdimp.com; helo=mail-il1-x12d.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=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: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Kyle Evans do_freebsd_sysctlbyname needs to translate the 'name' back down to a OID so we can intercept the special ones. Do that and call the common wrapper do_freebsd_sysctl_oid. Signed-off-by: Kyle Evans Reviewed-by: Warner Losh Signed-off-by: Warner Losh Reviewed-by: Richard Henderson --- bsd-user/freebsd/os-sys.c | 67 +++++++++++++++++++++++++++++++++++ bsd-user/freebsd/os-syscall.c | 4 +++ bsd-user/qemu.h | 3 ++ 3 files changed, 74 insertions(+) diff --git a/bsd-user/freebsd/os-sys.c b/bsd-user/freebsd/os-sys.c index f07ae7da740..d9386d3e7ef 100644 --- a/bsd-user/freebsd/os-sys.c +++ b/bsd-user/freebsd/os-sys.c @@ -472,6 +472,73 @@ out: return ret; } +/* + * This syscall was created to make sysctlbyname(3) more efficient, but we can't + * really provide it in bsd-user. Notably, we must always translate the names + * independently since some sysctl values have to be faked for the target + * environment, so it still has to break down to two syscalls for the underlying + * implementation. + */ +abi_long do_freebsd_sysctlbyname(CPUArchState *env, abi_ulong namep, + int32_t namelen, abi_ulong oldp, abi_ulong oldlenp, abi_ulong newp, + abi_ulong newlen) +{ + abi_long ret = -TARGET_EFAULT; + void *holdp = NULL, *hnewp = NULL; + char *snamep = NULL; + int oid[CTL_MAXNAME + 2]; + size_t holdlen, oidplen; + abi_ulong oldlen = 0; + + /* oldlenp is read/write, pre-check here for write */ + if (oldlenp) { + if (!access_ok(VERIFY_WRITE, oldlenp, sizeof(abi_ulong)) || + get_user_ual(oldlen, oldlenp)) { + goto out; + } + } + snamep = lock_user_string(namep); + if (snamep == NULL) { + goto out; + } + if (newp) { + hnewp = lock_user(VERIFY_READ, newp, newlen, 1); + if (hnewp == NULL) { + goto out; + } + } + if (oldp) { + holdp = lock_user(VERIFY_WRITE, oldp, oldlen, 0); + if (holdp == NULL) { + goto out; + } + } + holdlen = oldlen; + + oidplen = ARRAY_SIZE(oid); + if (sysctlnametomib(snamep, oid, &oidplen) != 0) { + ret = -TARGET_EINVAL; + goto out; + } + + ret = do_freebsd_sysctl_oid(env, oid, oidplen, holdp, &holdlen, hnewp, + newlen); + + /* + * writeability pre-checked above. __sysctl(2) returns ENOMEM and updates + * oldlenp for the proper size to use. + */ + if (oldlenp && (ret == 0 || ret == -TARGET_ENOMEM)) { + put_user_ual(holdlen, oldlenp); + } +out: + unlock_user(snamep, namep, 0); + unlock_user(holdp, oldp, ret == 0 ? holdlen : 0); + unlock_user(hnewp, newp, 0); + + return ret; +} + abi_long do_freebsd_sysctl(CPUArchState *env, abi_ulong namep, int32_t namelen, abi_ulong oldp, abi_ulong oldlenp, abi_ulong newp, abi_ulong newlen) { diff --git a/bsd-user/freebsd/os-syscall.c b/bsd-user/freebsd/os-syscall.c index 20ab3d4d9a1..179a20c304b 100644 --- a/bsd-user/freebsd/os-syscall.c +++ b/bsd-user/freebsd/os-syscall.c @@ -498,6 +498,10 @@ static abi_long freebsd_syscall(void *cpu_env, int num, abi_long arg1, ret = do_freebsd_sysctl(cpu_env, arg1, arg2, arg3, arg4, arg5, arg6); break; + case TARGET_FREEBSD_NR___sysctlbyname: /* sysctlbyname(2) */ + ret = do_freebsd_sysctlbyname(cpu_env, arg1, arg2, arg3, arg4, arg5, arg6); + break; + case TARGET_FREEBSD_NR_sysarch: /* sysarch(2) */ ret = do_freebsd_sysarch(cpu_env, arg1, arg2); break; diff --git a/bsd-user/qemu.h b/bsd-user/qemu.h index c7248cfde6f..e24a8cfcfb1 100644 --- a/bsd-user/qemu.h +++ b/bsd-user/qemu.h @@ -254,6 +254,9 @@ int host_to_target_errno(int err); /* os-sys.c */ abi_long do_freebsd_sysctl(CPUArchState *env, abi_ulong namep, int32_t namelen, abi_ulong oldp, abi_ulong oldlenp, abi_ulong newp, abi_ulong newlen); +abi_long do_freebsd_sysctlbyname(CPUArchState *env, abi_ulong namep, + int32_t namelen, abi_ulong oldp, abi_ulong oldlenp, abi_ulong newp, + abi_ulong newlen); abi_long do_freebsd_sysarch(void *cpu_env, abi_long arg1, abi_long arg2); /* user access */