From patchwork Fri Jul 13 05:54:25 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shivaprasad G Bhat X-Patchwork-Id: 943287 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=linux.vnet.ibm.com Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41Rhr35Gv9z9s3R for ; Fri, 13 Jul 2018 15:56:02 +1000 (AEST) Received: from localhost ([::1]:35376 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fdr3e-0005Hp-CR for incoming@patchwork.ozlabs.org; Fri, 13 Jul 2018 01:55:58 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37186) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fdr3J-0005Hh-SU for qemu-devel@nongnu.org; Fri, 13 Jul 2018 01:55:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fdr3G-0003Om-Or for qemu-devel@nongnu.org; Fri, 13 Jul 2018 01:55:37 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:41450) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fdr3G-0002WU-F5 for qemu-devel@nongnu.org; Fri, 13 Jul 2018 01:55:34 -0400 Received: from pps.filterd (m0098394.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w6D5s4bb129133 for ; Fri, 13 Jul 2018 01:54:32 -0400 Received: from e06smtp04.uk.ibm.com (e06smtp04.uk.ibm.com [195.75.94.100]) by mx0a-001b2d01.pphosted.com with ESMTP id 2k6krqvthw-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 13 Jul 2018 01:54:32 -0400 Received: from localhost by e06smtp04.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 13 Jul 2018 06:54:29 +0100 Received: from b06cxnps4074.portsmouth.uk.ibm.com (9.149.109.196) by e06smtp04.uk.ibm.com (192.168.101.134) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Fri, 13 Jul 2018 06:54:27 +0100 Received: from d06av23.portsmouth.uk.ibm.com (d06av23.portsmouth.uk.ibm.com [9.149.105.59]) by b06cxnps4074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w6D5sRmP31326250 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Fri, 13 Jul 2018 05:54:27 GMT Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 07B57A4040; Fri, 13 Jul 2018 08:54:48 +0100 (BST) Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 579C5A404D; Fri, 13 Jul 2018 08:54:47 +0100 (BST) Received: from lep8c.aus.stglabs.ibm.com (unknown [9.40.192.207]) by d06av23.portsmouth.uk.ibm.com (Postfix) with ESMTP; Fri, 13 Jul 2018 08:54:47 +0100 (BST) From: Shivaprasad G Bhat To: riku.voipio@iki.fi, laurent@vivier.eu Date: Fri, 13 Jul 2018 00:54:25 -0500 User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-TM-AS-GCONF: 00 x-cbid: 18071305-0016-0000-0000-000001E6534E X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18071305-0017-0000-0000-0000323AEB96 Message-Id: <153146124589.56005.13899878058836206262.stgit@lep8c.aus.stglabs.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2018-07-13_02:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=897 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1806210000 definitions=main-1807130031 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 148.163.156.1 Subject: [Qemu-devel] [PATCH v2] linux-user: ppc64: use the correct values for F_*LK64s 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: qemu-devel@nongnu.org, david@gibson.dropbear.id.au Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Qemu includes the glibc headers for the host defines and target headers are part of the qemu source themselves. The glibc has the F_GETLK64, F_SETLK64 and F_SETLKW64 defined to 12, 13 and 14 for all archs in sysdeps/unix/sysv/linux/bits/fcntl-linux.h. The linux kernel generic definition for F_*LK is 5, 6 & 7 and F_*LK64* is 12,13, and 14 as seen in include/uapi/asm-generic/fcntl.h. On 64bit machine, by default the kernel assumes all F_*LK to 64bit calls and doesnt support use of F_*LK64* as can be seen in include/linux/fcntl.h in linux source. On x86_64 host, the values for F_*LK64* are set to 5, 6 and 7 explicitly in /usr/include/x86_64-linux-gnu/bits/fcntl.h by the glibc. Whereas, a PPC64 host doesn't have such a definition in /usr/include/powerpc64le-linux-gnu/bits/fcntl.h by the glibc. So, the sources on PPC64 host sees the default value of F_*LK64* as 12, 13 & 14(fcntl-linux.h). Since the 64bit kernel doesnt support 12, 13 & 14; the glibc fcntl syscall implementation(__libc_fcntl*(), __fcntl64_nocancel) does the F_*LK64* value convertion back to F_*LK* values on PPC64 as seen in sysdeps/unix/sysv/linux/powerpc/powerpc64/sysdep.h with FCNTL_ADJUST_CMD() macro. Whereas on x86_64 host the values for F_*LK64* are set to 5, 6 and 7 and no adjustments are needed. Since qemu doesnt use the glibc fcntl, but makes the safe_syscall* on its own, the PPC64 qemu is calling the syscall with 12, 13, and 14(without adjustment) and they all fail. The fcntl calls to F_GETLK/F_SETLK|W all fail by all pplications run on PPC64 host user emulation. The fix here could be to see why on PPC64 the glibc is still keeping F_*LK64* different from F_*LK and why adjusting them to 5, 6 and 7 before the syscall for PPC only. See if we can make the /usr/include/powerpc64le-linux-gnu/bits/fcntl.h to have the values 5, 6 & 7 just like x86_64 and remove the adjustment code in glibc. That way, qemu sources see the kernel supported values in glibc headers. OR On PPC64 host, qemu sources see both F_*LK & F_*LK64* as same and set to 12, 13 and 14 because __USE_FILE_OFFSET64 is defined in qemu sources(also refer sysdeps/unix/sysv/linux/bits/fcntl-linux.h). Do the value adjustment just like it is done by glibc source by using F_GETLK value of 5. That way, we make the syscalls with the actual supported values in Qemu. The patch is taking this approach. Signed-off-by: Shivaprasad G Bhat --- Changes from v1: - Changed the overwrite of F*LK64* with 5, 6 and 7 in using #define instead using the adjustment code similar to glibc as suggested. - Dropped __linux__ check for the adjustment code as suggested. - Moved the adjustment code inside target_to_host_fcntl_cmd to address all possible|future cases. linux-user/syscall.c | 73 ++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 52 insertions(+), 21 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 643b8833de..38c2f1e90f 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -6475,63 +6475,94 @@ static int do_fork(CPUArchState *env, unsigned int flags, abi_ulong newsp, /* warning : doesn't handle linux specific flags... */ static int target_to_host_fcntl_cmd(int cmd) { + int ret = -TARGET_EINVAL; switch(cmd) { case TARGET_F_DUPFD: case TARGET_F_GETFD: case TARGET_F_SETFD: case TARGET_F_GETFL: case TARGET_F_SETFL: - return cmd; + ret = cmd; + break; case TARGET_F_GETLK: - return F_GETLK64; + ret = F_GETLK64; + break; case TARGET_F_SETLK: - return F_SETLK64; + ret = F_SETLK64; + break; case TARGET_F_SETLKW: - return F_SETLKW64; + ret = F_SETLKW64; + break; case TARGET_F_GETOWN: - return F_GETOWN; + ret = F_GETOWN; + break; case TARGET_F_SETOWN: - return F_SETOWN; + ret = F_SETOWN; + break; case TARGET_F_GETSIG: - return F_GETSIG; + ret = F_GETSIG; + break; case TARGET_F_SETSIG: - return F_SETSIG; + ret = F_SETSIG; + break; #if TARGET_ABI_BITS == 32 case TARGET_F_GETLK64: - return F_GETLK64; + ret = F_GETLK64; + break; case TARGET_F_SETLK64: - return F_SETLK64; + ret = F_SETLK64; + break; case TARGET_F_SETLKW64: - return F_SETLKW64; + ret = F_SETLKW64; + break; #endif case TARGET_F_SETLEASE: - return F_SETLEASE; + ret = F_SETLEASE; + break; case TARGET_F_GETLEASE: - return F_GETLEASE; + ret = F_GETLEASE; + break; #ifdef F_DUPFD_CLOEXEC case TARGET_F_DUPFD_CLOEXEC: - return F_DUPFD_CLOEXEC; + ret = F_DUPFD_CLOEXEC; + break; #endif case TARGET_F_NOTIFY: - return F_NOTIFY; + ret = F_NOTIFY; + break; #ifdef F_GETOWN_EX case TARGET_F_GETOWN_EX: - return F_GETOWN_EX; + ret = F_GETOWN_EX; + break; #endif #ifdef F_SETOWN_EX case TARGET_F_SETOWN_EX: - return F_SETOWN_EX; + ret = F_SETOWN_EX; + break; #endif #ifdef F_SETPIPE_SZ case TARGET_F_SETPIPE_SZ: - return F_SETPIPE_SZ; + ret = F_SETPIPE_SZ; + break; case TARGET_F_GETPIPE_SZ: - return F_GETPIPE_SZ; + ret = F_GETPIPE_SZ; + break; #endif default: - return -TARGET_EINVAL; + ret = -TARGET_EINVAL; } - return -TARGET_EINVAL; + +#if defined(__powerpc64__) +/* On PPC64, glibc headers has the F_*LK* defined to 12, 13 and 14 and + * is not supported by kernel. The glibc fcntl call actually adjusts + * them to 5, 6 and 7 before making the syscall(). Since we make the + * syscall directly, adjust to what is supported by the kernel. + */ + if (ret >= F_GETLK64 && ret <= F_SETLKW64) { + ret -= F_GETLK64 - 5; +#endif + + return ret; } #define TRANSTBL_CONVERT(a) { -1, TARGET_##a, -1, a }