From patchwork Sun Jun 10 03:01:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 138154 Delivered-To: patch@linaro.org Received: by 2002:a2e:970d:0:0:0:0:0 with SMTP id r13-v6csp2605052lji; Sat, 9 Jun 2018 21:00:14 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJlh4SFvXXP+F8KOt8/nX+bO7KBcFqiSlUauOOtumKxrg5e8pkgIg7QiWSKYwPV6a5iEiDR X-Received: by 2002:a37:ba47:: with SMTP id k68-v6mr10546686qkf.105.1528603214683; Sat, 09 Jun 2018 21:00:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528603214; cv=none; d=google.com; s=arc-20160816; b=k9k3adx5iAPG5/cw9JhhY8XNV6Z1jJ1HNnfDULCKTXcxKuek5QL5PZWIIO8tBtovht +w9HLTfUEyGo++hWEiohCfTIAfrqmvz/u7X8bG9teOTjFvt5Kr8dTyoy8CPFfft1XzMe DVj0TIhY2oIimCgEnxKdlYMY951ZwFgCrbeJ3svlLsutB2ZzlqFrCJPI5wjuwom3nxND zh2G2NzzG3pk0jz/8GTJXKnkdh6KOB4Ka98bTJTmCA5RFQnWIsnTsG8HwRob1kMGio4X MIPJZfvkzrrvEzw2svhVuhyAy8Y2AFo6j3eqI4bJQXquvS8XWd92Y4/+bzU0dbOlO9ho 3rLA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:to:from:dkim-signature:arc-authentication-results; bh=OXhzWrCzOnky8k7+EQTtpUJxLpSgxeCkisL1amDlPa4=; b=uXMWdG1l6vYWwAJMGl4O3wMPEmBq/n7Yd+lXw+NIOSDqbxkAG7I+t+MZ2jnt4MCspa AR4nZCPDpk4D8exRLKnylTPC9EVYuWkafJi5wM0DaK/keCb4FdILf7qnorPaICPdopb3 Iq+ZtjSlIYRzjbr5KW7PAElB0qqb2z3IV6UEdly+zpP1cGCR/9HNk0D65lWBV6KDOEiT AymiCgcH3zbIjnCdiYiHQ2aEvE48ILf1z9eLPXUTd7EEEJu4ne2gIRuxPOs0fwZbd6Fx Cv6MRauDDL7IMGxWLQOTrZUaEKgYLA1QRe61vWbjdBy6cdD9jkTu6ob0Iw4UxLR5OOJJ 6c0g== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=MMRP6Ft/; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id m100-v6si153858qkh.104.2018.06.09.21.00.14 for (version=TLS1 cipher=AES128-SHA bits=128/128); Sat, 09 Jun 2018 21:00:14 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=MMRP6Ft/; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:42488 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fRrWY-0004HG-4Z for patch@linaro.org; Sun, 10 Jun 2018 00:00:14 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41285) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fRqfU-00048D-9f for qemu-devel@nongnu.org; Sat, 09 Jun 2018 23:05:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fRqfS-0004Rp-Px for qemu-devel@nongnu.org; Sat, 09 Jun 2018 23:05:24 -0400 Received: from mail-pg0-x243.google.com ([2607:f8b0:400e:c05::243]:38930) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fRqfS-0004QX-B0 for qemu-devel@nongnu.org; Sat, 09 Jun 2018 23:05:22 -0400 Received: by mail-pg0-x243.google.com with SMTP id w12-v6so8139803pgc.6 for ; Sat, 09 Jun 2018 20:05:22 -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; bh=OXhzWrCzOnky8k7+EQTtpUJxLpSgxeCkisL1amDlPa4=; b=MMRP6Ft/HTwnpZn8ieOBlReaYXl1m16/jw71GaGLHuY9sQ+qYzOZCOasGdOSW87Pcf qW7tZ71cD+eAl79OOm98h/imDs32o/bKaipQEXVaBZWAUSjEGTgqBzVWR533Ef9AuOcw s75oTd8pvXOII6OhLYvKKik/jAOtX63UmZwmY= 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; bh=OXhzWrCzOnky8k7+EQTtpUJxLpSgxeCkisL1amDlPa4=; b=RKS/T08Jqe/7YK+ZqGlMsX1JKDaSyc9vlazBIs8Zt1XkKEzEbkEauBuMTxyOv5mobt n9n3MEqw88U2V7dz71FRzHcVkEy/xuaxRgNg6VGtw9YxVdIsasxAs0rzapoDMrqQP21K pBk4oPIG53uE6ZkfvlvKkc4ULMDLfFITBbCoZ79/SZIDtNOtG+6/HQKrmeJCo3tc1rSN b6LY/OWdLa52NreMONbZA0pJ7rvEuAeH7aDjRGcSZxXqV1XsVpWFL9nrvlscWbJly+76 p+OMm0hF7hAOV1LTvS4c3qdMzHXW3lkzDMYho7bIy6WlUI41wBxXm/gHA5LBKQMPpZR/ p46A== X-Gm-Message-State: APt69E1CUdUDYA7zGs1BLZTZbKjjWc1/M1/jj7meH5RFxpjC9MFOa+lS JCjkgdM8EgX3t6HTP2c0xzmVNC+u1jE= X-Received: by 2002:a65:60d2:: with SMTP id r18-v6mr5032809pgv.306.1528599921141; Sat, 09 Jun 2018 20:05:21 -0700 (PDT) Received: from cloudburst.twiddle.net (rrcs-173-198-77-219.west.biz.rr.com. [173.198.77.219]) by smtp.gmail.com with ESMTPSA id y17-v6sm31712718pfe.33.2018.06.09.20.05.19 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 09 Jun 2018 20:05:20 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Sat, 9 Jun 2018 17:01:56 -1000 Message-Id: <20180610030220.3777-85-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180610030220.3777-1-richard.henderson@linaro.org> References: <20180610030220.3777-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c05::243 Subject: [Qemu-devel] [PATCH v2 084/108] linux-user: Split out fadvise64, fadvise64_64 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: laurent@vivier.eu Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Generalize the s390x guest advice frobbing to support s390x as a host. Signed-off-by: Richard Henderson --- linux-user/syscall.c | 189 ++++++++++++++++++++++++++----------------- 1 file changed, 113 insertions(+), 76 deletions(-) -- 2.17.1 diff --git a/linux-user/syscall.c b/linux-user/syscall.c index afe6df5efa..5f056cf660 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -8110,6 +8110,109 @@ IMPL(faccessat) return ret; } +/* The advise values for DONTNEED and NOREUSE differ for s390x. + * Which means that we need to translate for the host as well. + */ +static int target_to_host_fadvise64_advice(int advice) +{ + switch (advice) { + case 0 ... 3: + return advice; +#ifdef TARGET_S390X + case 6: + return POSIX_FADV_DONTNEED; + case 7: + return POSIX_FADV_NOREUSE; +#else + case 4: + return POSIX_FADV_DONTNEED; + case 5: + return POSIX_FADV_NOREUSE; +#endif + default: + return -TARGET_EINVAL; + } +} + +#if TARGET_ABI_BITS == 32 +# ifdef TARGET_NR_fadvise64 +IMPL(fadvise64) +{ + abi_long ret; + off_t off, len; + int advice; + + /* 5 args: fd, offset (high, low), len, advice */ + if (regpairs_aligned(cpu_env, num)) { + /* offset is in (3,4), len in 5 and advice in 6 */ + off = target_offset64(arg3, arg4); + len = arg5; + advice = arg6; + } else { + off = target_offset64(arg2, arg3); + len = arg4; + advice = arg5; + } + advice = target_to_host_fadvise64_advice(advice); + if (advice < 0) { + return advice; + } + ret = posix_fadvise(arg1, off, len, advice); + return -host_to_target_errno(ret); +} +# endif +/* ??? TARGET_NR_arm_fadvise64_64 should be TARGET_NR_fadvise64_64. + * The argument ordering is the same as ppc32 and xtensa anyway. + */ +# ifdef TARGET_NR_arm_fadvise64_64 +# define TARGET_NR_fadvise64_64 TARGET_NR_arm_fadvise64_64 +# endif +# ifdef TARGET_NR_fadvise64_64 +IMPL(fadvise64_64) +{ + abi_long ret; + off_t off, len; + int advice; + +# if defined(TARGET_ARM) || defined(TARGET_PPC) || defined(TARGET_XTENSA) + /* 6 args: fd, advice, offset (high, low), len (high, low) */ + advice = arg2; + off = target_offset64(arg3, arg4); + len = target_offset64(arg5, arg6); +# else + /* 6 args: fd, offset (high, low), len (high, low), advice */ + if (regpairs_aligned(cpu_env, num)) { + /* offset is in (3,4), len in (5,6) and advice in 7 */ + off = target_offset64(arg3, arg4); + len = target_offset64(arg5, arg6); + advice = arg7; + } else { + off = target_offset64(arg2, arg3); + len = target_offset64(arg4, arg5); + advice = arg6; + } +# endif + advice = target_to_host_fadvise64_advice(advice); + if (advice < 0) { + return advice; + } + ret = posix_fadvise(arg1, off, len, advice); + return -host_to_target_errno(ret); +} +# endif +#else /* TARGET_ABI_BITS == 64 */ +# if defined(TARGET_NR_fadvise64_64) || defined(TARGET_NR_fadvise64) +IMPL(fadvise64) +{ + int advice = target_to_host_fadvise64_advice(arg4); + if (advice < 0) { + return advice; + } + return -host_to_target_errno(posix_fadvise(arg1, arg2, arg3, advice)); +} +# endif +#endif /* end fadvise64 handling */ + IMPL(fchdir) { return get_errno(fchdir(arg1)); @@ -12011,82 +12114,6 @@ static abi_long do_syscall1(void *cpu_env, unsigned num, abi_long arg1, void *p; switch(num) { -#ifdef TARGET_NR_arm_fadvise64_64 - case TARGET_NR_arm_fadvise64_64: - /* arm_fadvise64_64 looks like fadvise64_64 but - * with different argument order: fd, advice, offset, len - * rather than the usual fd, offset, len, advice. - * Note that offset and len are both 64-bit so appear as - * pairs of 32-bit registers. - */ - ret = posix_fadvise(arg1, target_offset64(arg3, arg4), - target_offset64(arg5, arg6), arg2); - return -host_to_target_errno(ret); -#endif - -#if TARGET_ABI_BITS == 32 - -#ifdef TARGET_NR_fadvise64_64 - case TARGET_NR_fadvise64_64: -#if defined(TARGET_PPC) || defined(TARGET_XTENSA) - /* 6 args: fd, advice, offset (high, low), len (high, low) */ - ret = arg2; - arg2 = arg3; - arg3 = arg4; - arg4 = arg5; - arg5 = arg6; - arg6 = ret; -#else - /* 6 args: fd, offset (high, low), len (high, low), advice */ - if (regpairs_aligned(cpu_env, num)) { - /* offset is in (3,4), len in (5,6) and advice in 7 */ - arg2 = arg3; - arg3 = arg4; - arg4 = arg5; - arg5 = arg6; - arg6 = arg7; - } -#endif - ret = posix_fadvise(arg1, target_offset64(arg2, arg3), - target_offset64(arg4, arg5), arg6); - return -host_to_target_errno(ret); -#endif - -#ifdef TARGET_NR_fadvise64 - case TARGET_NR_fadvise64: - /* 5 args: fd, offset (high, low), len, advice */ - if (regpairs_aligned(cpu_env, num)) { - /* offset is in (3,4), len in 5 and advice in 6 */ - arg2 = arg3; - arg3 = arg4; - arg4 = arg5; - arg5 = arg6; - } - ret = posix_fadvise(arg1, target_offset64(arg2, arg3), arg4, arg5); - return -host_to_target_errno(ret); -#endif - -#else /* not a 32-bit ABI */ -#if defined(TARGET_NR_fadvise64_64) || defined(TARGET_NR_fadvise64) -#ifdef TARGET_NR_fadvise64_64 - case TARGET_NR_fadvise64_64: -#endif -#ifdef TARGET_NR_fadvise64 - case TARGET_NR_fadvise64: -#endif -#ifdef TARGET_S390X - switch (arg4) { - case 4: arg4 = POSIX_FADV_NOREUSE + 1; break; /* make sure it's an invalid value */ - case 5: arg4 = POSIX_FADV_NOREUSE + 2; break; /* ditto */ - case 6: arg4 = POSIX_FADV_DONTNEED; break; - case 7: arg4 = POSIX_FADV_NOREUSE; break; - default: break; - } -#endif - return -host_to_target_errno(posix_fadvise(arg1, arg2, arg3, arg4)); -#endif -#endif /* end of 64-bit ABI fadvise handling */ - #ifdef TARGET_NR_madvise case TARGET_NR_madvise: /* A straight passthrough may not be safe because qemu sometimes @@ -13189,6 +13216,16 @@ static impl_fn *syscall_table(unsigned num) SYSCALL_WITH(exit_group, enosys); #endif SYSCALL(faccessat); +#ifdef TARGET_NR_fadvise64 + SYSCALL(fadvise64); +#endif +#ifdef TARGET_NR_fadvise64_64 +# if TARGET_ABI_BITS == 32 + SYSCALL(fadvise64_64); +# else + SYSCALL_WITH(fadvise64_64, fadvise64); +# endif +#endif SYSCALL(fchdir); SYSCALL(fchmod); SYSCALL(fchmodat);