From nobody Thu May 2 04:05:26 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1602517423; cv=none; d=zohomail.com; s=zohoarc; b=bbvnwgKX+9jGNkIBwE61QgrtbVN7n/qk04voLljUjPRrzrtlSw8zB+uJ1Y7sVI64yrvGo5q51mrPrFpapYHySRCJsdHZ6W/QEPI0+bMErrtyg1aF76631M37J9kiedaImkWVEGOhUb2ohKLXCAoqo4P7/OhMqsCXIne1RaMlJio= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602517423; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=3HBlEcMasIy4oDb25g21pdvkhkMGpmMaGyWG6UZXcVY=; b=e3IyftP9K0kAuTvvxlzuEtH3nBbfwE45AlLJR0EvpDAdFgmsB2obPFmQ6vI0k+AkQ18JCwPcXCq/QDwnhv9YUF0b+nHm8WFN0HnkaH0UipMz3qmvDUpl6kBfsLfZaAYR2lLYAaT6KRJD/OPxzZsg3OMFU2KMR9W8lJ943G/BlGA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1602517423129948.3078899760899; Mon, 12 Oct 2020 08:43:43 -0700 (PDT) Received: from localhost ([::1]:57840 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kRzzC-0001pD-23 for importer@patchew.org; Mon, 12 Oct 2020 11:43:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57082) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kRzqa-00078W-Qo for qemu-devel@nongnu.org; Mon, 12 Oct 2020 11:34:50 -0400 Received: from mail-wm1-x343.google.com ([2a00:1450:4864:20::343]:36597) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kRzqP-0007LG-P6 for qemu-devel@nongnu.org; Mon, 12 Oct 2020 11:34:44 -0400 Received: by mail-wm1-x343.google.com with SMTP id e2so17969597wme.1 for ; Mon, 12 Oct 2020 08:34:35 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [81.2.115.148]) by smtp.gmail.com with ESMTPSA id y10sm19675284wrq.73.2020.10.12.08.34.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Oct 2020 08:34:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=3HBlEcMasIy4oDb25g21pdvkhkMGpmMaGyWG6UZXcVY=; b=XiMRGjrt3XZdV7lYHGRutgqWE5PCk89dcxaiotWvyRkgRb8O++Kf1X+Vu/EFIZ8Mxp UaCl280RgEI6ddCbLctLO0TDwd9K1ANiIwO3T3lYfgQUqUgjn9GC0MU1hzOqkzi0YSt6 TlxqJJB2zgxfVeW8+HREB17+QgcZp6e6jihVcfA0dZn77z3Ie9bKQ3bEJdC7x/huaLdS uLonmv7yRQhMTdyeYLuEIM4/2OyruHsuel3s2X/PQk/jgBtXCqlX7JUuSdJ6uq0Z++77 V4eSdqxiR+4TLq4sc5RpwP8yJjRY426HpJrDQi+Kl1m1sRBWpqjwsSR4T6Bll+Z1eErk ScUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=3HBlEcMasIy4oDb25g21pdvkhkMGpmMaGyWG6UZXcVY=; b=Az8qrJv1MDr8dwWAMXSUWUeP1Yjy2b7Dj5JdIwq7yKD5cD1d84gb+ZczVQFi2tCrty GamHmewwQTTiod5Ym/ZKVkn+xr8AkYxRiP2os0gvPj53jWqMePGIbba7WT6tE190Cg/t vAHLypLMCZQipOhLpbt6axovatMRAwBPHxWcIU6VLtVTIFUy8vzYXyrS8o/C9vvyyh16 AvI4QKQm3EtNM4EN6SnQRmcTPQQ9G9jKwsOcB5+TaRoJkJgq1tzf4hAKBEityJ/XCMBj rkFaaY2SE9HuGvUt9bC+uSMp4OD4J3OR5ZqduFXJsLAxRMxSYGVCN0XfizJbX0BzBr8U OjDg== X-Gm-Message-State: AOAM532dCKFQAnc2YW0p+JogeBmgvWTy0MNMpLTHTmRtBSNXyyyh4N+u 5hKYMmlyju8dQViiT1T0TXogWw== X-Google-Smtp-Source: ABdhPJwgz1ZRG1R5q2wnTgdgP16tDHGKqt8qBLi9LlWX2DJ6vMsWP4eeNhSmMCbSPNQazzFWysi9kg== X-Received: by 2002:a1c:1d89:: with SMTP id d131mr10235175wmd.188.1602516874954; Mon, 12 Oct 2020 08:34:34 -0700 (PDT) From: Peter Maydell To: qemu-arm@nongnu.org, qemu-devel@nongnu.org Subject: [RFC PATCH v2] linux-user: Use FD_32BIT_MODE fd flag for 32-bit guests Date: Mon, 12 Oct 2020 16:33:44 +0100 Message-Id: <20201012153408.9747-22-peter.maydell@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20201012153408.9747-1-peter.maydell@linaro.org> References: <20201012153408.9747-1-peter.maydell@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::343; envelope-from=peter.maydell@linaro.org; helo=mail-wm1-x343.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) Content-Type: text/plain; charset="utf-8" If the guest is 32 bit then there is a potential problem if the host gives us back a 64-bit sized value that we can't fit into the ABI the guest requires. This is a theoretical issue for many syscalls, but a real issue for directory reads where the host is using ext3 or ext4. There the 'offset' values retured via the getdents syscall are hashes, and on a 64-bit system they will always fill the full 64 bits. Use the FD_32BIT_MODE fd flag to tell the kernel to stick to 32-bit sized hashes for fds used by the guest. This is an RFC patch because the kernel patch that adds the new fd flag hasn't yet been accepted upstream. The kernel patch is: https://patchew.org/QEMU/20200529072017.2906-1-linus.walleij@linaro.org/ Signed-off-by: Peter Maydell --- This is just a minor update of the testing patch I sent out in the thread discussing Linus's v1 kernel patch. linux-user/syscall.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 97de9fb5c92..265b9a096a0 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -884,6 +884,33 @@ static inline int host_to_target_sock_type(int host_ty= pe) return target_type; } =20 +/* + * If the guest is using a 32 bit ABI then we should try to ask the kernel + * to provide 32-bit offsets in getdents syscalls, as otherwise some + * filesystems will return 64-bit hash values which we can't fit into + * the field sizes the guest ABI mandates. + */ +#ifndef FD_32BIT_MODE +#define FD_32BIT_MODE 2 +#endif + +static inline void request_32bit_fs(int fd) +{ +#if HOST_LONG_BITS > TARGET_ABI_BITS + /* + * Ignore errors, which are likely due to the host kernel being + * too old to support FD_32BIT_MODE. We'll continue anyway, which + * might or might not work, depending on the guest code and on the + * host filesystem. + */ + int flags =3D fcntl(fd, F_GETFD); + if (flags =3D=3D -1) { + return; + } + fcntl(fd, F_SETFD, flags | FD_32BIT_MODE); +#endif +} + static abi_ulong target_brk; static abi_ulong target_original_brk; static abi_ulong brk_page; @@ -7725,6 +7752,7 @@ static abi_long do_syscall1(void *cpu_env, int num, a= bi_long arg1, target_to_host_bitmask(arg2, fcntl_flags= _tbl), arg3)); fd_trans_unregister(ret); + request_32bit_fs(ret); unlock_user(p, arg1, 0); return ret; #endif @@ -7735,6 +7763,7 @@ static abi_long do_syscall1(void *cpu_env, int num, a= bi_long arg1, target_to_host_bitmask(arg3, fcntl_flags= _tbl), arg4)); fd_trans_unregister(ret); + request_32bit_fs(ret); unlock_user(p, arg2, 0); return ret; #if defined(TARGET_NR_name_to_handle_at) && defined(CONFIG_OPEN_BY_HANDLE) @@ -7746,6 +7775,7 @@ static abi_long do_syscall1(void *cpu_env, int num, a= bi_long arg1, case TARGET_NR_open_by_handle_at: ret =3D do_open_by_handle_at(arg1, arg2, arg3); fd_trans_unregister(ret); + request_32bit_fs(ret); return ret; #endif case TARGET_NR_close: @@ -7790,6 +7820,7 @@ static abi_long do_syscall1(void *cpu_env, int num, a= bi_long arg1, return -TARGET_EFAULT; ret =3D get_errno(creat(p, arg2)); fd_trans_unregister(ret); + request_32bit_fs(ret); unlock_user(p, arg1, 0); return ret; #endif @@ -12419,6 +12450,7 @@ static abi_long do_syscall1(void *cpu_env, int num,= abi_long arg1, } ret =3D get_errno(memfd_create(p, arg2)); fd_trans_unregister(ret); + request_32bit_fs(ret); unlock_user(p, arg1, 0); return ret; #endif --=20 2.20.1