From patchwork Fri Dec 11 17:45:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Ivanov X-Patchwork-Id: 1415168 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2001:8b0:10b:1231::1; helo=merlin.infradead.org; envelope-from=linux-um-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=cambridgegreys.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=merlin.20170209 header.b=SopSR722; dkim-atps=neutral Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:8b0:10b:1231::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Csyrq2WF5z9sVk for ; Sat, 12 Dec 2020 04:46:35 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=iS5KsB6iO3JTurKMmJRb/dJBPOsMhaxndFFg3i5XiiQ=; b=SopSR72201Bzcv6GgKLp2Leh3 /fTTidO3O8JrS91kESvd6C9z9hJi2WrNzwDI8X9MXuJXSxuvypCTAHowpNVwHFKJccDXPzfE8Wkje aQ3ViqI0FBwo1bqtNRyXu7QUJqPj4sSNCZgJam1JVt8BXKaFELmhOfAzvMuYOqot/6eE4LWDIyMDp 42aYAbU94KWMaJ7XyZDx3MQYPyj6EPF48Iy0xBI/1IJ18szwqL/sQVTJ8J617C4bTuOe1wKBqjymq VPU5BeEt4WjNSFW98AnLL4GSA3gWVYgfh53ZSYUeRXPN4hLhChq+vgrbpOrvHBR/Dg7QQFNepg0ft swuyY1K3w==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1knmUm-0008Fg-Sg; Fri, 11 Dec 2020 17:46:20 +0000 Received: from ivanoab7.miniserver.com ([37.128.132.42] helo=www.kot-begemot.co.uk) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1knmUl-0008FD-9L for linux-um@lists.infradead.org; Fri, 11 Dec 2020 17:46:20 +0000 Received: from tun252.jain.kot-begemot.co.uk ([192.168.18.6] helo=jain.kot-begemot.co.uk) by www.kot-begemot.co.uk with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1knmUk-0001zr-FJ; Fri, 11 Dec 2020 17:46:18 +0000 Received: from jain.kot-begemot.co.uk ([192.168.3.3]) by jain.kot-begemot.co.uk with esmtp (Exim 4.92) (envelope-from ) id 1knmUh-0006zn-0a; Fri, 11 Dec 2020 17:46:16 +0000 From: anton.ivanov@cambridgegreys.com To: linux-um@lists.infradead.org Subject: [PATCH v4 1/7] um: allow the use of glibc functions instead of builtins Date: Fri, 11 Dec 2020 17:45:53 +0000 Message-Id: <20201211174559.26010-2-anton.ivanov@cambridgegreys.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20201211174559.26010-1-anton.ivanov@cambridgegreys.com> References: <20201211174559.26010-1-anton.ivanov@cambridgegreys.com> MIME-Version: 1.0 X-Spam-Score: -1.0 X-Spam-Score: -1.0 X-Clacks-Overhead: GNU Terry Pratchett X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201211_124619_369427_2FEABFF0 X-CRM114-Status: GOOD ( 17.54 ) X-Spam-Score: 0.4 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (0.4 points) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 SPF_NONE SPF: sender does not publish an SPF Record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.4 KHOP_HELO_FCRDNS Relay HELO differs from its IP's reverse DNS X-BeenThere: linux-um@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: richard@nod.at, Anton Ivanov Sender: "linux-um" Errors-To: linux-um-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org From: Anton Ivanov The UML kernel runs as a normal userspace process and can use most of glibc string.h functionality instead of built-ins. At present, when using built-ins, it is also limited to their unoptimized versions, because it does not have the runtime code patching present on x86 via apply_alternatives() Allowing the use of glibc for memcpy, memmove, etc provides 1-5% boost on common file io as measured by cat and dd. The size of the linux executable is also reduced by ~10KBytes. It is possible to turn this on/off via the kernel configuration. Signed-off-by: Anton Ivanov Reviewed-by: Johannes Berg --- arch/um/Kconfig | 10 ++++++ arch/um/include/asm/string.h | 70 ++++++++++++++++++++++++++++++++++++ arch/um/os-Linux/user_syms.c | 28 ++++++++++++++- arch/x86/um/Makefile | 6 ++-- 4 files changed, 111 insertions(+), 3 deletions(-) create mode 100644 arch/um/include/asm/string.h diff --git a/arch/um/Kconfig b/arch/um/Kconfig index 4b799fad8b48..ec2802ded9d1 100644 --- a/arch/um/Kconfig +++ b/arch/um/Kconfig @@ -189,6 +189,16 @@ config UML_TIME_TRAVEL_SUPPORT It is safe to say Y, but you probably don't need this. +config UML_USE_BUILT_IN_STRINGS + bool + default N + prompt "Use kernel memcpy, memmove, etc" + help + UML can use the kernel built in memcpy, memmove, etc functions + or use the glibc equivalents instead. + The glibc equivalents are slightly faster and will result in a + slightly smaller executable when linking UML dynamically. + endmenu source "arch/um/drivers/Kconfig" diff --git a/arch/um/include/asm/string.h b/arch/um/include/asm/string.h new file mode 100644 index 000000000000..ac16890e0867 --- /dev/null +++ b/arch/um/include/asm/string.h @@ -0,0 +1,70 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +/* + * Copyright (C) 2020 Cambridge Greys Ltd. + * Copyright (C) 2020 Red Hat Inc. + */ + +#ifndef __ASM_UM_STRING_H +#define __ASM_UM_STRING_H + +#ifndef CONFIG_UML_USE_BUILT_IN_STRINGS + +#include + +#define __HAVE_ARCH_STRCPY +extern char *strcpy(char *dest, const char *src); +#define __HAVE_ARCH_STRNCPY +extern char *strncpy(char *dest, const char *src, size_t n); +#define __HAVE_ARCH_STRCAT +extern char *strcat(char *dest, const char *src); +#define __HAVE_ARCH_STRNCAT +extern char *strncat(char *dest, const char *src, size_t n); +#define __HAVE_ARCH_STRCMP +extern int strcmp(const char *s1, const char *s2); +#define __HAVE_ARCH_STRNCMP +extern int strncmp(const char *s1, const char *s2, size_t n); +#define __HAVE_ARCH_STRCHR +extern char *strchr(const char *s, int c); +#define __HAVE_ARCH_STRLEN +extern size_t strlen(const char *s); +#define __HAVE_ARCH_MEMCPY +extern void *memcpy(void *dest, const void *src, size_t n); +#define __HAVE_ARCH_MEMMOVE +extern void *memmove(void *dest, const void *src, size_t n); +#define __HAVE_ARCH_MEMCHR +extern void *memchr(const void *s, int c, size_t n); +#define __HAVE_ARCH_STRNLEN +extern size_t strnlen(const char *s, size_t maxlen); +#define __HAVE_ARCH_STRSTR +extern char *strstr(const char *haystack, const char *needle); +#define __HAVE_ARCH_MEMSET +extern void *memset(void *s, int c, size_t n); +#define __HAVE_ARCH_STRNCASECMP +extern int strncasecmp(const char *s1, const char *s2, size_t n); +#define __HAVE_ARCH_STRCASECMP +extern int strcasecmp(const char *s1, const char *s2); +#define __HAVE_ARCH_STRCHRNUL +extern char *strchrnul(const char *s, int c); +#define __HAVE_ARCH_STRRCH +extern char *strchrnul(const char *s, int c); +#define __HAVE_ARCH_STRSPN +extern size_t strspn(const char *s, const char *accept); +#define __HAVE_ARCH_STRCSPN +extern size_t strcspn(const char *s, const char *reject); +#define __HAVE_ARCH_STRPBRK +extern char *strpbrk(const char *s, const char *accept); +#define __HAVE_ARCH_STRSEP +extern char *strsep(char **stringp, const char *delim); +#define __HAVE_ARCH_MEMCMP +extern int memcmp(const void *s1, const void *s2, size_t n); +#define __HAVE_ARCH_BCMP +extern int bcmp(const void *s1, const void *s2, size_t n); + +#else + +#include + +#endif + +#endif /* __ASM_UM_STRING_H */ diff --git a/arch/um/os-Linux/user_syms.c b/arch/um/os-Linux/user_syms.c index 715594fe5719..040c8303e0b4 100644 --- a/arch/um/os-Linux/user_syms.c +++ b/arch/um/os-Linux/user_syms.c @@ -9,6 +9,7 @@ * add an EXPORT for the glibc one. */ +#ifdef CONFIG_UML_USE_BUILT_IN_STRINGS #undef strlen #undef strstr #undef memcpy @@ -17,6 +18,7 @@ extern size_t strlen(const char *); extern void *memmove(void *, const void *, size_t); extern void *memset(void *, int, size_t); +#endif extern int printf(const char *, ...); /* If it's not defined, the export is included in lib/string.c.*/ @@ -24,14 +26,38 @@ extern int printf(const char *, ...); EXPORT_SYMBOL(strstr); #endif -#ifndef __x86_64__ +#if !defined(__x86_64__) && defined(CONFIG_UML_USE_BUILT_IN_STRINGS) extern void *memcpy(void *, const void *, size_t); EXPORT_SYMBOL(memcpy); #endif + +#ifndef CONFIG_UML_USE_BUILT_IN_STRINGS +/* These all come from glibc */ +EXPORT_SYMBOL(memcpy); EXPORT_SYMBOL(memmove); EXPORT_SYMBOL(memset); EXPORT_SYMBOL(printf); +EXPORT_SYMBOL(strcpy); +EXPORT_SYMBOL(strncpy); +EXPORT_SYMBOL(strcat); +EXPORT_SYMBOL(strncat); +EXPORT_SYMBOL(strcmp); +EXPORT_SYMBOL(strncmp); +EXPORT_SYMBOL(strchr); +EXPORT_SYMBOL(strlen); +EXPORT_SYMBOL(memchr); +EXPORT_SYMBOL(strnlen); +EXPORT_SYMBOL(strncasecmp); +EXPORT_SYMBOL(strcasecmp); +EXPORT_SYMBOL(strchrnul); +EXPORT_SYMBOL(strcspn); +EXPORT_SYMBOL(strpbrk); +EXPORT_SYMBOL(strsep); +EXPORT_SYMBOL(memcmp); +EXPORT_SYMBOL(bcmp); + +#endif /* Here, instead, I can provide a fake prototype. Yes, someone cares: genksyms. * However, the modules will use the CRC defined *here*, no matter if it is diff --git a/arch/x86/um/Makefile b/arch/x86/um/Makefile index 77f70b969d14..453ea23a9770 100644 --- a/arch/x86/um/Makefile +++ b/arch/x86/um/Makefile @@ -20,14 +20,16 @@ ifeq ($(CONFIG_X86_32),y) obj-y += checksum_32.o syscalls_32.o obj-$(CONFIG_ELF_CORE) += elfcore.o -subarch-y = ../lib/string_32.o ../lib/atomic64_32.o ../lib/atomic64_cx8_32.o +subarch-y = ../lib/atomic64_32.o ../lib/atomic64_cx8_32.o subarch-y += ../kernel/sys_ia32.o +subarch-$(CONFIG_UML_USE_BUILT_IN_STRINGS) += ../lib/string_32.o else obj-y += syscalls_64.o vdso/ -subarch-y = ../lib/csum-partial_64.o ../lib/memcpy_64.o ../entry/thunk_64.o +subarch-y = ../lib/csum-partial_64.o ../entry/thunk_64.o +subarch-$(CONFIG_UML_USE_BUILT_IN_STRINGS) += ../lib/memcpy_64.o endif From patchwork Fri Dec 11 17:45:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Ivanov X-Patchwork-Id: 1415170 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2001:8b0:10b:1231::1; helo=merlin.infradead.org; envelope-from=linux-um-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=cambridgegreys.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=merlin.20170209 header.b=05q1SUH6; dkim-atps=neutral Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:8b0:10b:1231::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Csyrr6mWNz9sVJ for ; Sat, 12 Dec 2020 04:46:36 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=wkbZIlgQl9knDqUQWfGxpQfXqSNbphb3m5jSMIOSmMY=; b=05q1SUH6LCIAzALk4wDsAD1+P QoTDTIpyZpnNCf3WucPT9+B+tBqIGblH1vSeX4DHtGXCLvX+Y7wPTgrNdniOAPD6cc/kAMyT3BEFj coHx7CjrgOybTyBIUK7rZiJHqbKL3dyVZH/19b+RexP9JhuCL0kEattm6aItUOPQiboCOAkVgtRGU NBvFyAVFdwyUuZGCo1uo5v5H6p3xxt6NH/Opq8VPzQGwLh1hJQ5FEtgor8jhbixl4/+vuJDzwK9r5 9+8UUBVQ4ktNwpXReO3n1XFZwN3qeQenTRkmxyVJv4SDmWxws7LW6COa8Us3GK8E3CvyQL2ZVPo3f Zty0O7+rA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1knmUq-0008Hb-8g; Fri, 11 Dec 2020 17:46:24 +0000 Received: from ivanoab7.miniserver.com ([37.128.132.42] helo=www.kot-begemot.co.uk) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1knmUn-0008Fi-8x for linux-um@lists.infradead.org; Fri, 11 Dec 2020 17:46:22 +0000 Received: from tun252.jain.kot-begemot.co.uk ([192.168.18.6] helo=jain.kot-begemot.co.uk) by www.kot-begemot.co.uk with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1knmUm-0001zw-CC; Fri, 11 Dec 2020 17:46:20 +0000 Received: from jain.kot-begemot.co.uk ([192.168.3.3]) by jain.kot-begemot.co.uk with esmtp (Exim 4.92) (envelope-from ) id 1knmUi-0006zn-OP; Fri, 11 Dec 2020 17:46:18 +0000 From: anton.ivanov@cambridgegreys.com To: linux-um@lists.infradead.org Subject: [PATCH v4 2/7] um: enable the use of optimized xor routines in UML Date: Fri, 11 Dec 2020 17:45:54 +0000 Message-Id: <20201211174559.26010-3-anton.ivanov@cambridgegreys.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20201211174559.26010-1-anton.ivanov@cambridgegreys.com> References: <20201211174559.26010-1-anton.ivanov@cambridgegreys.com> MIME-Version: 1.0 X-Spam-Score: -1.0 X-Spam-Score: -1.0 X-Clacks-Overhead: GNU Terry Pratchett X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201211_124621_467191_5317C48B X-CRM114-Status: GOOD ( 23.16 ) X-Spam-Score: 0.4 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (0.4 points) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 SPF_NONE SPF: sender does not publish an SPF Record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.4 KHOP_HELO_FCRDNS Relay HELO differs from its IP's reverse DNS X-BeenThere: linux-um@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: richard@nod.at, Anton Ivanov Sender: "linux-um" Errors-To: linux-um-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org From: Anton Ivanov This patch enable the use of optimized xor routines from the x86 tree as well as supply the necessary macros for them to be used in UML. The macros supply several "fake" flags and definitions to allow using the x86 files "as is". This patchset implements only the flags needed for the optimized strings.h, xor.h and checksum.h implementations instead of trying to copy the entire x86 flags environment. Signed-off-by: Anton Ivanov --- arch/um/include/asm/cpufeature.h | 17 +++++++++++++ arch/um/include/asm/cpufeatures.h | 15 ++++++++++++ arch/um/include/asm/fpu/api.h | 14 +++++++++++ arch/um/include/asm/processor-generic.h | 3 +++ arch/um/include/asm/xor-x86.h | 1 + arch/um/include/asm/xor.h | 17 ++++++++++++- arch/um/include/asm/xor_32.h | 1 + arch/um/include/asm/xor_64.h | 1 + arch/um/include/asm/xor_avx.h | 1 + arch/um/include/shared/os.h | 1 + arch/um/kernel/um_arch.c | 17 +++++++++++-- arch/um/os-Linux/start_up.c | 32 +++++++++++++++++++++++++ 12 files changed, 117 insertions(+), 3 deletions(-) create mode 100644 arch/um/include/asm/cpufeature.h create mode 100644 arch/um/include/asm/cpufeatures.h create mode 100644 arch/um/include/asm/fpu/api.h create mode 120000 arch/um/include/asm/xor-x86.h create mode 120000 arch/um/include/asm/xor_32.h create mode 120000 arch/um/include/asm/xor_64.h create mode 120000 arch/um/include/asm/xor_avx.h diff --git a/arch/um/include/asm/cpufeature.h b/arch/um/include/asm/cpufeature.h new file mode 100644 index 000000000000..19a2394d03a4 --- /dev/null +++ b/arch/um/include/asm/cpufeature.h @@ -0,0 +1,17 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_UM_CPUFEATURE_H +#define _ASM_UM_CPUFEATURE_H + +#include +#include +#include +#include + + +const char *host_cpu_feature_names[] = {"mmx", "xmm", "avx", "osxsave", "rep_good", "erms", "xmm2"}; +#define MAX_UM_CPU_FEATURES ARRAY_SIZE(host_cpu_feature_names) + + +#define boot_cpu_has(bit) (boot_cpu_data.host_features & bit) + +#endif /* _ASM_UM_CPUFEATURE_H */ diff --git a/arch/um/include/asm/cpufeatures.h b/arch/um/include/asm/cpufeatures.h new file mode 100644 index 000000000000..d02da39b039d --- /dev/null +++ b/arch/um/include/asm/cpufeatures.h @@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_UM_CPUFEATURES_H +#define _ASM_UM_CPUFEATURES_H + +/* Fake x86 Features of actual interest to UML */ + +#define X86_FEATURE_MMX (1 << 0) +#define X86_FEATURE_XMM (1 << 1) +#define X86_FEATURE_AVX (1 << 2) +#define X86_FEATURE_OSXSAVE (1 << 3) +#define X86_FEATURE_REP_GOOD (1 << 4) +#define X86_FEATURE_ERMS (1 << 5) +#define X86_FEATURE_XMM2 (1 << 6) + +#endif /* _ASM_UM_CPUFEATURES_H */ diff --git a/arch/um/include/asm/fpu/api.h b/arch/um/include/asm/fpu/api.h new file mode 100644 index 000000000000..2873a6f0105d --- /dev/null +++ b/arch/um/include/asm/fpu/api.h @@ -0,0 +1,14 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +#ifndef _ASM_UM_FPU_API_H +#define _ASM_UM_FPU_API_H + +/* Copyright (c) 2020 Cambridge Greys Ltd + * Copyright (c) 2020 Red Hat Inc. + * A set of "dummy" defines to allow the direct inclusion + * of x86 optimized copy, xor, etc routines into the + * UML code tree. */ + +#define kernel_fpu_begin() (void)0 +#define kernel_fpu_end() (void)0 + +#endif diff --git a/arch/um/include/asm/processor-generic.h b/arch/um/include/asm/processor-generic.h index afd9b267cf81..b8bcddbb1898 100644 --- a/arch/um/include/asm/processor-generic.h +++ b/arch/um/include/asm/processor-generic.h @@ -90,6 +90,9 @@ extern void start_thread(struct pt_regs *regs, unsigned long entry, struct cpuinfo_um { unsigned long loops_per_jiffy; int ipi_pipe[2]; + /* There is only a small set of x86 features we are interested + * in for now */ + unsigned long host_features; }; extern struct cpuinfo_um boot_cpu_data; diff --git a/arch/um/include/asm/xor-x86.h b/arch/um/include/asm/xor-x86.h new file mode 120000 index 000000000000..beff7de6890d --- /dev/null +++ b/arch/um/include/asm/xor-x86.h @@ -0,0 +1 @@ +../../../x86/include/asm/xor.h \ No newline at end of file diff --git a/arch/um/include/asm/xor.h b/arch/um/include/asm/xor.h index 36b33d62a35d..18bcb5b6189d 100644 --- a/arch/um/include/asm/xor.h +++ b/arch/um/include/asm/xor.h @@ -1,7 +1,22 @@ /* SPDX-License-Identifier: GPL-2.0 */ -#include +#ifndef _ASM_UM_XOR_H +#define _ASM_UM_XOR_H + +#ifdef CONFIG_64BIT +#undef CONFIG_X86_32 +#else +#define CONFIG_X86_32 1 +#endif + +#include +#include #include +#ifdef CONFIG_UML_TIME_TRAVEL_SUPPORT +#undef XOR_SELECT_TEMPLATE /* pick an arbitrary one - measuring isn't possible with inf-cpu */ #define XOR_SELECT_TEMPLATE(x) \ (time_travel_mode == TT_MODE_INFCPU ? &xor_block_8regs : NULL) +#endif + +#endif diff --git a/arch/um/include/asm/xor_32.h b/arch/um/include/asm/xor_32.h new file mode 120000 index 000000000000..8a0894e996d7 --- /dev/null +++ b/arch/um/include/asm/xor_32.h @@ -0,0 +1 @@ +../../../x86/include/asm/xor_32.h \ No newline at end of file diff --git a/arch/um/include/asm/xor_64.h b/arch/um/include/asm/xor_64.h new file mode 120000 index 000000000000..b8d346c516bf --- /dev/null +++ b/arch/um/include/asm/xor_64.h @@ -0,0 +1 @@ +../../../x86/include/asm/xor_64.h \ No newline at end of file diff --git a/arch/um/include/asm/xor_avx.h b/arch/um/include/asm/xor_avx.h new file mode 120000 index 000000000000..370ded122095 --- /dev/null +++ b/arch/um/include/asm/xor_avx.h @@ -0,0 +1 @@ +../../../x86/include/asm/xor_avx.h \ No newline at end of file diff --git a/arch/um/include/shared/os.h b/arch/um/include/shared/os.h index f467d28fc0b4..c2ff855af603 100644 --- a/arch/um/include/shared/os.h +++ b/arch/um/include/shared/os.h @@ -187,6 +187,7 @@ int os_poll(unsigned int n, const int *fds); extern void os_early_checks(void); extern void os_check_bugs(void); extern void check_host_supports_tls(int *supports_tls, int *tls_min); +extern unsigned long check_host_cpu_features(const char **feature_names, int n); /* mem.c */ extern int create_mem_file(unsigned long long len); diff --git a/arch/um/kernel/um_arch.c b/arch/um/kernel/um_arch.c index 76b37297b7d4..b7dfc4fcc130 100644 --- a/arch/um/kernel/um_arch.c +++ b/arch/um/kernel/um_arch.c @@ -15,6 +15,7 @@ #include #include +#include #include #include #include @@ -48,9 +49,12 @@ static void __init add_arg(char *arg) */ struct cpuinfo_um boot_cpu_data = { .loops_per_jiffy = 0, - .ipi_pipe = { -1, -1 } + .ipi_pipe = { -1, -1 }, + .host_features = 0 }; +EXPORT_SYMBOL(boot_cpu_data); + union thread_union cpu0_irqstack __section(".data..init_irqstack") = { .thread_info = INIT_THREAD_INFO(init_task) }; @@ -67,9 +71,15 @@ static int show_cpuinfo(struct seq_file *m, void *v) seq_printf(m, "model name\t: UML\n"); seq_printf(m, "mode\t\t: skas\n"); seq_printf(m, "host\t\t: %s\n", host_info); - seq_printf(m, "bogomips\t: %lu.%02lu\n\n", + seq_printf(m, "bogomips\t: %lu.%02lu\n", loops_per_jiffy/(500000/HZ), (loops_per_jiffy/(5000/HZ)) % 100); + seq_printf(m, "flags\t\t:"); + for (index = 0; index < MAX_UM_CPU_FEATURES; index++) { + if (boot_cpu_data.host_features & (1 << index)) + seq_printf(m, " %s", host_cpu_feature_names[index]); + } + seq_printf(m, "\n\n"); return 0; } @@ -275,6 +285,9 @@ int __init linux_main(int argc, char **argv) /* OS sanity checks that need to happen before the kernel runs */ os_early_checks(); + boot_cpu_data.host_features = + check_host_cpu_features(host_cpu_feature_names, MAX_UM_CPU_FEATURES); + brk_start = (unsigned long) sbrk(0); /* diff --git a/arch/um/os-Linux/start_up.c b/arch/um/os-Linux/start_up.c index f79dc338279e..be884ed86b30 100644 --- a/arch/um/os-Linux/start_up.c +++ b/arch/um/os-Linux/start_up.c @@ -321,6 +321,38 @@ static void __init check_coredump_limit(void) os_info("%llu\n", (unsigned long long)lim.rlim_max); } +unsigned long __init check_host_cpu_features(const char **feature_names, int n) +{ + FILE *cpuinfo; + char *line = NULL; + size_t len = 0; + int i; + bool done_parsing = false; + unsigned long result = 0; + + cpuinfo = fopen("/proc/cpuinfo", "r"); + if (cpuinfo == NULL) { + os_info("Failed to get host CPU features\n"); + } else { + while ((getline(&line, &len, cpuinfo)) != -1) { + if (strstr(line, "flags")) { + for (i = 0; i < n; i++) { + if (strstr(line, feature_names[i])) { + result |= (1 << i); + } + } + done_parsing = true; + } + free(line); + line = NULL; + if (done_parsing) + break; + } + fclose(cpuinfo); + } + return result; +} + void __init os_early_checks(void) { int pid; From patchwork Fri Dec 11 17:45:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Ivanov X-Patchwork-Id: 1415169 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2001:8b0:10b:1231::1; helo=merlin.infradead.org; envelope-from=linux-um-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=cambridgegreys.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=merlin.20170209 header.b=MpYs/MUD; dkim-atps=neutral Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:8b0:10b:1231::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Csyrr5l2Fz9sSf for ; Sat, 12 Dec 2020 04:46:36 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=PQGoYT1J6GZmXPN7pghahMci58um5aJEvE56WG23yiA=; b=MpYs/MUDI++nSVTK4JwGu9m3Q w78tx7hIXhM8KOj1ZCvHXdtdwmePGpqBs0HKnyGvk9TOAibPhwCy3eOs497CwUDS7k+PYrxYHuxns 0kJS7P2ovMq0etEvjpvHtQ8OsbkO9pCnrNfbmVQNuKqElhPjCGSXYvdYgrtLmscSUFrtL8biJOrGL d4rm2itCSNbJD2auXd6hOLX2A6uQjtXCngKghecN5oX+gegbxBCEHoBbAADJEvS3m7gMWzcsKfyKW yWO+0H360gUMOjznZMwKu4qXNCw09hgKpRozNFP9gE3FT1HBoobTBbGkbcnvLI3elY7MCe05zecB+ szgFT+dTA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1knmUt-0008Ix-Kf; Fri, 11 Dec 2020 17:46:27 +0000 Received: from ivanoab7.miniserver.com ([37.128.132.42] helo=www.kot-begemot.co.uk) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1knmUn-0008G1-So for linux-um@lists.infradead.org; Fri, 11 Dec 2020 17:46:23 +0000 Received: from tun252.jain.kot-begemot.co.uk ([192.168.18.6] helo=jain.kot-begemot.co.uk) by www.kot-begemot.co.uk with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1knmUn-000201-6a; Fri, 11 Dec 2020 17:46:21 +0000 Received: from jain.kot-begemot.co.uk ([192.168.3.3]) by jain.kot-begemot.co.uk with esmtp (Exim 4.92) (envelope-from ) id 1knmUk-0006zn-Ip; Fri, 11 Dec 2020 17:46:20 +0000 From: anton.ivanov@cambridgegreys.com To: linux-um@lists.infradead.org Subject: [PATCH v4 3/7] um: "borrow" atomics from x86 architecture Date: Fri, 11 Dec 2020 17:45:55 +0000 Message-Id: <20201211174559.26010-4-anton.ivanov@cambridgegreys.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20201211174559.26010-1-anton.ivanov@cambridgegreys.com> References: <20201211174559.26010-1-anton.ivanov@cambridgegreys.com> MIME-Version: 1.0 X-Spam-Score: -1.0 X-Spam-Score: -1.0 X-Clacks-Overhead: GNU Terry Pratchett X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201211_124621_974844_4EC919D1 X-CRM114-Status: GOOD ( 11.29 ) X-Spam-Score: 0.4 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (0.4 points) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 SPF_NONE SPF: sender does not publish an SPF Record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.4 KHOP_HELO_FCRDNS Relay HELO differs from its IP's reverse DNS X-BeenThere: linux-um@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: richard@nod.at, Anton Ivanov Sender: "linux-um" Errors-To: linux-um-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org From: Anton Ivanov This moves UML on 64 bit from generic atomics to their x86 equivalents. Generic atomics bracket most operations by interrupts off/interrupts on. This is quite expensive on UML - it translates to changing the signal mask and rerunning the signal loop every time. Signed-off-by: Anton Ivanov --- arch/um/include/asm/atomic-x86.h | 1 + arch/um/include/asm/atomic.h | 7 +++++++ arch/um/include/asm/atomic64_64.h | 1 + 3 files changed, 9 insertions(+) create mode 120000 arch/um/include/asm/atomic-x86.h create mode 100644 arch/um/include/asm/atomic.h create mode 120000 arch/um/include/asm/atomic64_64.h diff --git a/arch/um/include/asm/atomic-x86.h b/arch/um/include/asm/atomic-x86.h new file mode 120000 index 000000000000..e71a389e112d --- /dev/null +++ b/arch/um/include/asm/atomic-x86.h @@ -0,0 +1 @@ +../../../x86/include/asm/atomic.h \ No newline at end of file diff --git a/arch/um/include/asm/atomic.h b/arch/um/include/asm/atomic.h new file mode 100644 index 000000000000..6ff22c587c10 --- /dev/null +++ b/arch/um/include/asm/atomic.h @@ -0,0 +1,7 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_ATOMIC_XOR_H +#define _ASM_ATOMIC_XOR_H + +#include + +#endif diff --git a/arch/um/include/asm/atomic64_64.h b/arch/um/include/asm/atomic64_64.h new file mode 120000 index 000000000000..f817a1478603 --- /dev/null +++ b/arch/um/include/asm/atomic64_64.h @@ -0,0 +1 @@ +../../../x86/include/asm/atomic64_64.h \ No newline at end of file From patchwork Fri Dec 11 17:45:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Ivanov X-Patchwork-Id: 1415171 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2001:8b0:10b:1231::1; helo=merlin.infradead.org; envelope-from=linux-um-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=cambridgegreys.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=merlin.20170209 header.b=qFyiofNM; dkim-atps=neutral Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:8b0:10b:1231::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Csyrv6XK4z9sSf for ; Sat, 12 Dec 2020 04:46:39 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=JtbtvH3wwjcN5Qe1rlPq8a5aC4V+zVSg3fC9/9MJEyo=; b=qFyiofNM+4Q7Ckt5i5bP3jwRD x6chU21fV1Lgv/OrL2i6cFN6Pp2Q7Afn0eV+cHj0OMa8UloLRZYtaadkP3NUHDch/qOvfhH6vJbQY rnj5C16uhz3pNmiKQiaLJNXhPanYcd+cj4S9Ugt4BsuYCibV9AtfP8wDDw0n9blgrwXGntRJGw5ZX SEjzAmCTFc2LUMz6carYIm6gPRSS5/zohK3iJXIsweRcdx2mP27bv7HXp6VGv4tbqM6AeEOmjjp6W 5pGWH4IecFojQ83s+LyvPDnpGqFuyiYJOlGR4iOtPuBamsKyB6vHeyuo6baGiNkM5e8vuWarx6kjM kt8Rfl7xg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1knmUu-0008JN-Qp; Fri, 11 Dec 2020 17:46:28 +0000 Received: from ivanoab7.miniserver.com ([37.128.132.42] helo=www.kot-begemot.co.uk) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1knmUp-0008HA-UW for linux-um@lists.infradead.org; Fri, 11 Dec 2020 17:46:24 +0000 Received: from tun252.jain.kot-begemot.co.uk ([192.168.18.6] helo=jain.kot-begemot.co.uk) by www.kot-begemot.co.uk with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1knmUp-000206-4T; Fri, 11 Dec 2020 17:46:23 +0000 Received: from jain.kot-begemot.co.uk ([192.168.3.3]) by jain.kot-begemot.co.uk with esmtp (Exim 4.92) (envelope-from ) id 1knmUm-0006zn-8J; Fri, 11 Dec 2020 17:46:22 +0000 From: anton.ivanov@cambridgegreys.com To: linux-um@lists.infradead.org Subject: [PATCH v4 4/7] um: add a UML specific futex implementation Date: Fri, 11 Dec 2020 17:45:56 +0000 Message-Id: <20201211174559.26010-5-anton.ivanov@cambridgegreys.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20201211174559.26010-1-anton.ivanov@cambridgegreys.com> References: <20201211174559.26010-1-anton.ivanov@cambridgegreys.com> MIME-Version: 1.0 X-Spam-Score: -1.0 X-Spam-Score: -1.0 X-Clacks-Overhead: GNU Terry Pratchett X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201211_124624_030321_0C079741 X-CRM114-Status: GOOD ( 20.70 ) X-Spam-Score: 0.4 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (0.4 points) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 SPF_NONE SPF: sender does not publish an SPF Record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.4 KHOP_HELO_FCRDNS Relay HELO differs from its IP's reverse DNS X-BeenThere: linux-um@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: richard@nod.at, Anton Ivanov Sender: "linux-um" Errors-To: linux-um-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org From: Anton Ivanov The generic asm futex implementation emulates atomic access to memory by doing a get_user followed by put_user. These translate to two mapping operations on UML with paging enabled in the meantime. This, in turn may end up changing interrupts, invoking the signal loop, etc. This replaces the generic implementation by a mapping followed by an operation on the mapped segment. Signed-off-by: Anton Ivanov --- arch/um/include/asm/Kbuild | 1 - arch/um/include/asm/futex.h | 14 ++++ arch/um/kernel/skas/uaccess.c | 130 ++++++++++++++++++++++++++++++++++ 3 files changed, 144 insertions(+), 1 deletion(-) create mode 100644 arch/um/include/asm/futex.h diff --git a/arch/um/include/asm/Kbuild b/arch/um/include/asm/Kbuild index 1c63b260ecc4..873e6815bc50 100644 --- a/arch/um/include/asm/Kbuild +++ b/arch/um/include/asm/Kbuild @@ -8,7 +8,6 @@ generic-y += emergency-restart.h generic-y += exec.h generic-y += extable.h generic-y += ftrace.h -generic-y += futex.h generic-y += hw_irq.h generic-y += irq_regs.h generic-y += irq_work.h diff --git a/arch/um/include/asm/futex.h b/arch/um/include/asm/futex.h new file mode 100644 index 000000000000..0a01f1f60de0 --- /dev/null +++ b/arch/um/include/asm/futex.h @@ -0,0 +1,14 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_GENERIC_FUTEX_H +#define _ASM_GENERIC_FUTEX_H + +#include +#include +#include + + +extern int arch_futex_atomic_op_inuser(int op, u32 oparg, int *oval, u32 __user *uaddr); +extern int futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr, + u32 oldval, u32 newval); + +#endif diff --git a/arch/um/kernel/skas/uaccess.c b/arch/um/kernel/skas/uaccess.c index 2dec915abe6f..de71048b5371 100644 --- a/arch/um/kernel/skas/uaccess.c +++ b/arch/um/kernel/skas/uaccess.c @@ -11,6 +11,7 @@ #include #include #include +#include #include pte_t *virt_to_pte(struct mm_struct *mm, unsigned long addr) @@ -248,3 +249,132 @@ long __strnlen_user(const void __user *str, long len) return 0; } EXPORT_SYMBOL(__strnlen_user); + +/** + * arch_futex_atomic_op_inuser() - Atomic arithmetic operation with constant + * argument and comparison of the previous + * futex value with another constant. + * + * @encoded_op: encoded operation to execute + * @uaddr: pointer to user space address + * + * Return: + * 0 - On success + * -EFAULT - User access resulted in a page fault + * -EAGAIN - Atomic operation was unable to complete due to contention + * -ENOSYS - Operation not supported + */ + +int arch_futex_atomic_op_inuser(int op, u32 oparg, int *oval, u32 __user *uaddr) +{ + int oldval, ret; + struct page *page; + unsigned long addr = (unsigned long) uaddr; + pte_t *pte; + + ret = -EFAULT; + if (!access_ok(uaddr, sizeof(*uaddr))) + return -EFAULT; + preempt_disable(); + pte = maybe_map((unsigned long) uaddr, 1); + if (pte == NULL) + goto out_inuser; + + page = pte_page(*pte); +#ifdef CONFIG_64BIT + pagefault_disable(); + addr = page_address(page) + (((unsigned long) addr) & ~PAGE_MASK); +#else + addr = (unsigned long) kmap_atomic(page) + + ((unsigned long) addr & ~PAGE_MASK); +#endif + + oldval = *((u32 *)addr); + + ret = 0; + + switch (op) { + case FUTEX_OP_SET: + *uaddr = oparg; + break; + case FUTEX_OP_ADD: + *uaddr += oparg; + break; + case FUTEX_OP_OR: + *uaddr |= oparg; + break; + case FUTEX_OP_ANDN: + *uaddr &= ~oparg; + break; + case FUTEX_OP_XOR: + *uaddr ^= oparg; + break; + default: + ret = -ENOSYS; + } +#ifdef CONFIG_64BIT + pagefault_enable(); +#else + kunmap_atomic((void *)addr); +#endif + +out_inuser: + preempt_enable(); + + if (ret == 0) + *oval = oldval; + + return ret; +} +EXPORT_SYMBOL(arch_futex_atomic_op_inuser); + +/** + * futex_atomic_cmpxchg_inatomic() - Compare and exchange the content of the + * uaddr with newval if the current value is + * oldval. + * @uval: pointer to store content of @uaddr + * @uaddr: pointer to user space address + * @oldval: old value + * @newval: new value to store to @uaddr + * + * Return: + * 0 - On success + * -EFAULT - User access resulted in a page fault + * -EAGAIN - Atomic operation was unable to complete due to contention + * -ENOSYS - Function not implemented (only if !HAVE_FUTEX_CMPXCHG) + */ + +int futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr, + u32 oldval, u32 newval) +{ + u32 val; + struct page *page; + pte_t *pte; + int ret = -EFAULT; + + if (!access_ok(uaddr, sizeof(*uaddr))) + return -EFAULT; + + preempt_disable(); + pte = maybe_map((unsigned long) uaddr, 1); + if (pte == NULL) + goto out_inatomic; + + page = pte_page(*pte); + pagefault_disable(); + uaddr = page_address(page) + (((unsigned long) uaddr) & ~PAGE_MASK); + + val = *uaddr; + + if (val == oldval) + *uaddr = newval; + + *uval = val; + pagefault_enable(); + ret = 0; + +out_inatomic: + preempt_enable(); + return ret; +} +EXPORT_SYMBOL(futex_atomic_cmpxchg_inatomic); From patchwork Fri Dec 11 17:45:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Ivanov X-Patchwork-Id: 1415172 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2001:8b0:10b:1231::1; helo=merlin.infradead.org; envelope-from=linux-um-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=cambridgegreys.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=merlin.20170209 header.b=RRj9Rhln; dkim-atps=neutral Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:8b0:10b:1231::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Csyrw6bqlz9sVJ for ; Sat, 12 Dec 2020 04:46:40 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=LgcjvJ6vaKmDNkeP9czA6C/drdISpfVwWR2YwSLTRxc=; b=RRj9RhlnMfGd5e3hFpewaApJ/ 1YwBI/jw69K2kPv1zy1tclZ57/9F/mIdRrMo15Z7moJXThEuPWL/aDCRqN/en1/2PwV6z2M6wwbGy ajAfumf9g4wciHVoEVtu8Dpxcn6GjPHNy4uGRXW4g6bT8uoxgPhNVuRaC3JLVCnTSKlcdZ5xwSZVp p2kICdgMHazLgHYqGWPItX37E5zjm11TIePSiGCSRfzAKduWGLBxa7elPfonpV5YaaUvTbfxZXv2O kXKPn1PlCu1JmYYBWcFjCVXH7xFchloLVt37MqzA6CbC/gxTReOr5tW2ofMIcvLwsiDvavEwJpSM/ yIR0Mi5/A==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1knmUw-0008K1-6p; Fri, 11 Dec 2020 17:46:30 +0000 Received: from ivanoab7.miniserver.com ([37.128.132.42] helo=www.kot-begemot.co.uk) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1knmUr-0008Hz-F7 for linux-um@lists.infradead.org; Fri, 11 Dec 2020 17:46:26 +0000 Received: from tun252.jain.kot-begemot.co.uk ([192.168.18.6] helo=jain.kot-begemot.co.uk) by www.kot-begemot.co.uk with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1knmUq-00020C-Mx; Fri, 11 Dec 2020 17:46:24 +0000 Received: from jain.kot-begemot.co.uk ([192.168.3.3]) by jain.kot-begemot.co.uk with esmtp (Exim 4.92) (envelope-from ) id 1knmUo-0006zn-0m; Fri, 11 Dec 2020 17:46:23 +0000 From: anton.ivanov@cambridgegreys.com To: linux-um@lists.infradead.org Subject: [PATCH v4 5/7] um: "borrow" cmpxchg from x86 tree in UML Date: Fri, 11 Dec 2020 17:45:57 +0000 Message-Id: <20201211174559.26010-6-anton.ivanov@cambridgegreys.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20201211174559.26010-1-anton.ivanov@cambridgegreys.com> References: <20201211174559.26010-1-anton.ivanov@cambridgegreys.com> MIME-Version: 1.0 X-Spam-Score: -1.0 X-Spam-Score: -1.0 X-Clacks-Overhead: GNU Terry Pratchett X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201211_124625_564785_AE393178 X-CRM114-Status: GOOD ( 11.47 ) X-Spam-Score: 0.4 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (0.4 points) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 SPF_NONE SPF: sender does not publish an SPF Record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.4 KHOP_HELO_FCRDNS Relay HELO differs from its IP's reverse DNS X-BeenThere: linux-um@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: richard@nod.at, Anton Ivanov Sender: "linux-um" Errors-To: linux-um-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org From: Anton Ivanov UML was falling back to asm-generic cmpxchg which emulates atomic behaviour by turning irqs on/off. On UML this means turning on/off signals for each cmpxchg which is expensive. Signed-off-by: Anton Ivanov --- arch/um/include/asm/cmpxchg-x86.h | 1 + arch/um/include/asm/cmpxchg.h | 7 +++++++ arch/um/include/asm/cmpxchg_32.h | 1 + arch/um/include/asm/cmpxchg_64.h | 1 + 4 files changed, 10 insertions(+) create mode 120000 arch/um/include/asm/cmpxchg-x86.h create mode 100644 arch/um/include/asm/cmpxchg.h create mode 120000 arch/um/include/asm/cmpxchg_32.h create mode 120000 arch/um/include/asm/cmpxchg_64.h diff --git a/arch/um/include/asm/cmpxchg-x86.h b/arch/um/include/asm/cmpxchg-x86.h new file mode 120000 index 000000000000..a5c607edde88 --- /dev/null +++ b/arch/um/include/asm/cmpxchg-x86.h @@ -0,0 +1 @@ +../../../x86/include/asm/cmpxchg.h \ No newline at end of file diff --git a/arch/um/include/asm/cmpxchg.h b/arch/um/include/asm/cmpxchg.h new file mode 100644 index 000000000000..03e7a669eeef --- /dev/null +++ b/arch/um/include/asm/cmpxchg.h @@ -0,0 +1,7 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_UM_CMPXCHG_H +#define _ASM_UM_CMPXCHG_H + +#include + +#endif diff --git a/arch/um/include/asm/cmpxchg_32.h b/arch/um/include/asm/cmpxchg_32.h new file mode 120000 index 000000000000..1f360d0a9fa9 --- /dev/null +++ b/arch/um/include/asm/cmpxchg_32.h @@ -0,0 +1 @@ +../../../x86/include/asm/cmpxchg_32.h \ No newline at end of file diff --git a/arch/um/include/asm/cmpxchg_64.h b/arch/um/include/asm/cmpxchg_64.h new file mode 120000 index 000000000000..bc09ae22b0cb --- /dev/null +++ b/arch/um/include/asm/cmpxchg_64.h @@ -0,0 +1 @@ +../../../x86/include/asm/cmpxchg_64.h \ No newline at end of file From patchwork Fri Dec 11 17:45:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Ivanov X-Patchwork-Id: 1415173 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2001:8b0:10b:1231::1; helo=merlin.infradead.org; envelope-from=linux-um-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=cambridgegreys.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=merlin.20170209 header.b=ICCHPY/s; dkim-atps=neutral Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:8b0:10b:1231::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Csyry4rlfz9sSf for ; Sat, 12 Dec 2020 04:46:42 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=Ce3nKtouTt3aKAOid49D51qOla7LZ0AXSN81fKeLorY=; b=ICCHPY/s7AFAt/qxe7TXIcKvw YzIjS29My3veo8ek6q2CTntITnWJVU0C6mwgYBKqWpCUsj41l8XhnxhP6nlhtH372JOSlrPVrVAWZ xdAMAYRShVgeP9bJRGteTvL23HZNuoAlh7QG4IcSEghCVDZRVILgcCNDwVpoWvyCvJ1xNfWHoUFDV Wic9hfD7zcK+tYWAiz8fKYv1wcCKnMo5fv409R/mOIznUJ2pWy2n1LRUWJYw8OqugMsI0Ny/PlsaH 8/Y6qNPXai3RsMtUooS87sWX2QQtSYsEgdUxJcGjI/C98eQ6RAg3lmtp0quz1rBEUKUVOtueKA1+Q T61LIWYjg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1knmUx-0008KS-Fo; Fri, 11 Dec 2020 17:46:31 +0000 Received: from ivanoab7.miniserver.com ([37.128.132.42] helo=www.kot-begemot.co.uk) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1knmUt-0008IV-40 for linux-um@lists.infradead.org; Fri, 11 Dec 2020 17:46:27 +0000 Received: from tun252.jain.kot-begemot.co.uk ([192.168.18.6] helo=jain.kot-begemot.co.uk) by www.kot-begemot.co.uk with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1knmUs-00020H-AQ; Fri, 11 Dec 2020 17:46:26 +0000 Received: from jain.kot-begemot.co.uk ([192.168.3.3]) by jain.kot-begemot.co.uk with esmtp (Exim 4.92) (envelope-from ) id 1knmUp-0006zn-Mb; Fri, 11 Dec 2020 17:46:25 +0000 From: anton.ivanov@cambridgegreys.com To: linux-um@lists.infradead.org Subject: [PATCH v4 6/7] um: swithch futex ops to cmpxchg Date: Fri, 11 Dec 2020 17:45:58 +0000 Message-Id: <20201211174559.26010-7-anton.ivanov@cambridgegreys.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20201211174559.26010-1-anton.ivanov@cambridgegreys.com> References: <20201211174559.26010-1-anton.ivanov@cambridgegreys.com> MIME-Version: 1.0 X-Spam-Score: -1.0 X-Spam-Score: -1.0 X-Clacks-Overhead: GNU Terry Pratchett X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201211_124627_233420_E6DAD137 X-CRM114-Status: UNSURE ( 9.25 ) X-CRM114-Notice: Please train this message. X-Spam-Score: 0.4 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (0.4 points) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 SPF_NONE SPF: sender does not publish an SPF Record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.4 KHOP_HELO_FCRDNS Relay HELO differs from its IP's reverse DNS X-BeenThere: linux-um@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: richard@nod.at, Anton Ivanov Sender: "linux-um" Errors-To: linux-um-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org From: Anton Ivanov As a result of switching from emulated to true atomic cmpxchg we can use cmpxchg in the corresponding um futex op. Signed-off-by: Anton Ivanov --- arch/um/kernel/skas/uaccess.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/arch/um/kernel/skas/uaccess.c b/arch/um/kernel/skas/uaccess.c index de71048b5371..858b2e16e364 100644 --- a/arch/um/kernel/skas/uaccess.c +++ b/arch/um/kernel/skas/uaccess.c @@ -343,7 +343,6 @@ EXPORT_SYMBOL(arch_futex_atomic_op_inuser); * -EAGAIN - Atomic operation was unable to complete due to contention * -ENOSYS - Function not implemented (only if !HAVE_FUTEX_CMPXCHG) */ - int futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr, u32 oldval, u32 newval) { @@ -366,8 +365,7 @@ int futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr, val = *uaddr; - if (val == oldval) - *uaddr = newval; + ret = cmpxchg(uaddr, oldval, newval); *uval = val; pagefault_enable(); From patchwork Fri Dec 11 17:45:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Ivanov X-Patchwork-Id: 1415174 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2001:8b0:10b:1231::1; helo=merlin.infradead.org; envelope-from=linux-um-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=cambridgegreys.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=merlin.20170209 header.b=bOzDgatx; dkim-atps=neutral Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:8b0:10b:1231::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Csys03c5cz9sSf for ; Sat, 12 Dec 2020 04:46:44 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=+QTr9jxsTp9gnAGxQprozWTK/q+g3hiZNFTK5RncR+U=; b=bOzDgatxUSazs9c67t/JxMsgi QAHgCaV2K0wacYHkGzad6PSfB87/dP9r+/5CJun/Vk5knjXxIZ2tDy3jaZ4UdtHJc7+6LeCXUwi5l TUvfIEghOIDwm+RmHj4CGtlDsJx8HGvaFfFB8yeJ/7xTfPevLsps+coU3L3mlNxu7PbRumE80Imfj MODpdnwxqRj1abfQeSBYkh3Yk9w3oEXVji97iViduxtWDoCoMaDCFeADYf9yc6jFEI6C2b58VG/BJ UtgEVoVn4n26u3uzLgmfzmLFmYJqmfa0trzO/SpFf+P9Umq0N3/kS81eKXFsql52Vehls/9CAYYJp XEDHppcRw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1knmUy-0008Ky-SP; Fri, 11 Dec 2020 17:46:32 +0000 Received: from ivanoab7.miniserver.com ([37.128.132.42] helo=www.kot-begemot.co.uk) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1knmUu-0008JG-MF for linux-um@lists.infradead.org; Fri, 11 Dec 2020 17:46:29 +0000 Received: from tun252.jain.kot-begemot.co.uk ([192.168.18.6] helo=jain.kot-begemot.co.uk) by www.kot-begemot.co.uk with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1knmUt-00020M-VN; Fri, 11 Dec 2020 17:46:28 +0000 Received: from jain.kot-begemot.co.uk ([192.168.3.3]) by jain.kot-begemot.co.uk with esmtp (Exim 4.92) (envelope-from ) id 1knmUr-0006zn-BS; Fri, 11 Dec 2020 17:46:27 +0000 From: anton.ivanov@cambridgegreys.com To: linux-um@lists.infradead.org Subject: [PATCH v4 7/7] um: borrow bitops from the x86 tree Date: Fri, 11 Dec 2020 17:45:59 +0000 Message-Id: <20201211174559.26010-8-anton.ivanov@cambridgegreys.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20201211174559.26010-1-anton.ivanov@cambridgegreys.com> References: <20201211174559.26010-1-anton.ivanov@cambridgegreys.com> MIME-Version: 1.0 X-Spam-Score: -1.0 X-Spam-Score: -1.0 X-Clacks-Overhead: GNU Terry Pratchett X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201211_124628_822882_CFC47A2F X-CRM114-Status: GOOD ( 11.41 ) X-Spam-Score: 0.4 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (0.4 points) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 SPF_NONE SPF: sender does not publish an SPF Record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.4 KHOP_HELO_FCRDNS Relay HELO differs from its IP's reverse DNS X-BeenThere: linux-um@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: richard@nod.at, Anton Ivanov Sender: "linux-um" Errors-To: linux-um-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org From: Anton Ivanov Using x86 bitops instead of the asm-generic allows to squeeze a couple of percents improvement on fs IO in UML. It should improve other areas as well. Signed-off-by: Anton Ivanov --- arch/um/include/asm/bitops-x86.h | 1 + arch/um/include/asm/bitops.h | 7 +++++++ 2 files changed, 8 insertions(+) create mode 120000 arch/um/include/asm/bitops-x86.h create mode 100644 arch/um/include/asm/bitops.h diff --git a/arch/um/include/asm/bitops-x86.h b/arch/um/include/asm/bitops-x86.h new file mode 120000 index 000000000000..15a96ff554b2 --- /dev/null +++ b/arch/um/include/asm/bitops-x86.h @@ -0,0 +1 @@ +../../../x86/include/asm/bitops.h \ No newline at end of file diff --git a/arch/um/include/asm/bitops.h b/arch/um/include/asm/bitops.h new file mode 100644 index 000000000000..a0cd978c6aaa --- /dev/null +++ b/arch/um/include/asm/bitops.h @@ -0,0 +1,7 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_UM_BITOPS_H +#define _ASM_UM_BITOPS_H + +#include + +#endif