From patchwork Fri Apr 28 06:57:35 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexey Perevalov X-Patchwork-Id: 9703935 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id B1101602BF for ; Fri, 28 Apr 2017 07:00:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A24632624A for ; Fri, 28 Apr 2017 07:00:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 96E2428304; Fri, 28 Apr 2017 07:00:40 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 1B67D2624A for ; Fri, 28 Apr 2017 07:00:40 +0000 (UTC) Received: from localhost ([::1]:35460 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d3ztP-0002PQ-A9 for patchwork-qemu-devel@patchwork.kernel.org; Fri, 28 Apr 2017 03:00:39 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44850) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d3zqr-0001Ju-T0 for qemu-devel@nongnu.org; Fri, 28 Apr 2017 02:58:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d3zqo-00035u-Py for qemu-devel@nongnu.org; Fri, 28 Apr 2017 02:58:01 -0400 Received: from mailout1.w1.samsung.com ([210.118.77.11]:63296) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1d3zqo-00033A-KU for qemu-devel@nongnu.org; Fri, 28 Apr 2017 02:57:58 -0400 Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout1.w1.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTP id <0OP300BA7Y0I4D20@mailout1.w1.samsung.com> for qemu-devel@nongnu.org; Fri, 28 Apr 2017 07:57:54 +0100 (BST) Received: from eusmges1.samsung.com (unknown [203.254.199.239]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20170428065754eucas1p1822c0e702c85b5fc54d5862c0b21404c~5fXC09PTz1734817348eucas1p18; Fri, 28 Apr 2017 06:57:54 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges1.samsung.com (EUCPMTA) with SMTP id D4.BA.14140.4F7E2095; Fri, 28 Apr 2017 07:57:57 +0100 (BST) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20170428065753eucas1p1524aa2bd8e469e6c94a88ee80eb54a6e~5fXCRIg721555515555eucas1p1E; Fri, 28 Apr 2017 06:57:53 +0000 (GMT) X-AuditID: cbfec7ef-f796a6d00000373c-0d-5902e7f458fa Received: from eusync3.samsung.com ( [203.254.199.213]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id 31.7A.17452.A78E2095; Fri, 28 Apr 2017 08:00:10 +0100 (BST) Received: from aperevalov-ubuntu.rnd.samsung.ru ([106.109.129.199]) by eusync3.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTPA id <0OP300L3YY07A050@eusync3.samsung.com>; Fri, 28 Apr 2017 07:57:53 +0100 (BST) From: Alexey Perevalov To: qemu-devel@nongnu.org Date: Fri, 28 Apr 2017 09:57:35 +0300 Message-id: <1493362658-8179-4-git-send-email-a.perevalov@samsung.com> X-Mailer: git-send-email 1.9.1 In-reply-to: <1493362658-8179-1-git-send-email-a.perevalov@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrHIsWRmVeSWpSXmKPExsWy7djP87pfnzNFGjy7wGgx9+55FovebffY LU5sOshscaX9J7vFlv3f2C2O9+5gcWDzOPBiIbvHk2ubmTze77vK5tG3ZRVjAEsUl01Kak5m WWqRvl0CV8bvIzPZC27LVByd8oilgfG7aBcjJ4eEgInE8jV32SFsMYkL99azdTFycQgJLGOU 2LPuFQtIQkjgM6PEvY1RMA2Hvt5ggSt6/PE5VFE3k8SyMwZdjBwcbAIGEvvu2YKERQQkJX53 nWYGsZkF8iQeTT7PDFIiLJAmcWiBJ0iYRUBV4vX8VWwgNq+Am8SNnj4miFVyEiePTWYFsTkF 3CV2P74FdpuEwHM2iVsrN7GCzJEQkJXYdIAZot5FYtP/TSwQtrDEq+NboP6SkejsOMgE0dvO KNG9s5MVwpnAKHFm+l+oKnuJUzevMkEcyicxadt0ZogFvBIdbUIQJR4Sv2Z1M0LYjhKdC1qh gTWLUaK95xDjBEaZBYwMqxhFUkuLc9NTiw31ihNzi0vz0vWS83M3MQJj9fS/4+93MD5tDjnE KMDBqMTDy/CBMVKINbGsuDL3EKMEB7OSCK9kIlOkEG9KYmVValF+fFFpTmrxIUZpDhYlcV7e U9cihATSE0tSs1NTC1KLYLJMHJxSDYx9HJKBj36FnN6hzcmWJvzAbEeX/uNDUbfeRN5mYntT pivqKZampX16d0z4Kk2b5Dnfj034dFRwRdwued89qmsDVb9u43LbWvmUJ+ZDV8WH5+tWTj5z vO2lg73QnRXMa2bk8W+5UHPmjPNLsxWMaxT4Flb6zCuey3Yt0PpWzIEfSwJ//RWK9AhQYinO SDTUYi4qTgQAqheFgNECAAA= X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrHLMWRmVeSWpSXmKPExsVy+t/xq7pVL5giDRoPcVjMvXuexaJ32z12 ixObDjJbXGn/yW6xZf83dovjvTtYHNg8DrxYyO7x5NpmJo/3+66yefRtWcUYwBLlZpORmpiS WqSQmpecn5KZl26rFBripmuhpJCXmJtqqxSh6xsSpKRQlphTCuQZGaABB+cA92AlfbsEt4zf R2ayF9yWqTg65RFLA+N30S5GTg4JAROJQ19vsEDYYhIX7q1n62Lk4hASWMIoMW3rTlYIp5dJ YvXGbqAMBwebgIHEvnu2IA0iApISv7tOM4PYzAJ5Eitn/GcEKREWSJM4tMATJMwioCrxev4q NhCbV8BN4kZPHxPELjmJk8cms4LYnALuErsf3wKrEQKqWfJ6GvMERt4FjAyrGEVSS4tz03OL DfWKE3OLS/PS9ZLzczcxAsN227Gfm3cwXtoYfIhRgINRiYeX4QNjpBBrYllxZe4hRgkOZiUR XslEpkgh3pTEyqrUovz4otKc1OJDjKZAR01klhJNzgfGVF5JvKGJobmloZGxhYW5kZGSOG/J hyvhQgLpiSWp2ampBalFMH1MHJxSDYyc/oUKqUcyb/T1Lnis9jLnVfhmv82+EgIRr1fYrp/y TjHWM+ORH/u1pZKLNWRS/s6xm1aQKqN8/k/OjccB9neNjyvXzlwSJc7t/05ta+8J59fily+V zo25legro+1S7rfizifbRfkX3mdJLWP3S1LXjFf8y5G271PEWaWDRjP2sipMdpxtN1+JpTgj 0VCLuag4EQAOUByvcQIAAA== X-MTR: 20000000000000000@CPGS X-CMS-MailID: 20170428065753eucas1p1524aa2bd8e469e6c94a88ee80eb54a6e X-Msg-Generator: CA X-Sender-IP: 182.198.249.179 X-Local-Sender: =?UTF-8?B?QWxleGV5IFBlcmV2YWxvdhtTUlItVmlydHVhbGl6YXRpb24g?= =?UTF-8?B?TGFiG+yCvOyEseyghOyekBtTZW5pb3IgRW5naW5lZXI=?= X-Global-Sender: =?UTF-8?B?QWxleGV5IFBlcmV2YWxvdhtTUlItVmlydHVhbGl6YXRpb24g?= =?UTF-8?B?TGFiG1NhbXN1bmcgRWxlY3Ryb25pY3MbU2VuaW9yIEVuZ2luZWVy?= X-Sender-Code: =?UTF-8?B?QzEwG0NJU0hRG0MxMEdEMDFHRDAxMDE1NA==?= CMS-TYPE: 201P X-HopCount: 7 X-CMS-RootMailID: 20170428065753eucas1p1524aa2bd8e469e6c94a88ee80eb54a6e X-RootMTR: 20170428065753eucas1p1524aa2bd8e469e6c94a88ee80eb54a6e References: <1493362658-8179-1-git-send-email-a.perevalov@samsung.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 210.118.77.11 Subject: [Qemu-devel] [PATCH RESEND V3 3/6] migration: split ufd_version_check onto receive/request features part 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: i.maximets@samsung.com, f4bug@amsat.org, dgilbert@redhat.com, peterx@redhat.com, a.perevalov@samsung.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP This modification is necessary for userfault fd features which are required to be requested from userspace. UFFD_FEATURE_THREAD_ID is a one of such "on demand" feature, which will be introduced in the next patch. QEMU need to use separate userfault file descriptor, due to userfault context has internal state, and after first call of ioctl UFFD_API it changes its state to UFFD_STATE_RUNNING (in case of success), but kernel while handling ioctl UFFD_API expects UFFD_STATE_WAIT_API. So only one ioctl with UFFD_API is possible per ufd. Signed-off-by: Alexey Perevalov --- migration/postcopy-ram.c | 68 ++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 63 insertions(+), 5 deletions(-) diff --git a/migration/postcopy-ram.c b/migration/postcopy-ram.c index 4c859b4..21e7150 100644 --- a/migration/postcopy-ram.c +++ b/migration/postcopy-ram.c @@ -60,15 +60,51 @@ struct PostcopyDiscardState { #include #include -static bool ufd_version_check(int ufd, MigrationIncomingState *mis) + +/* + * Check userfault fd features, to request only supported features in + * future. + * __NR_userfaultfd - should be checked before + * Return obtained features + */ +static bool receive_ufd_features(__u64 *features) { - struct uffdio_api api_struct; - uint64_t ioctl_mask; + struct uffdio_api api_struct = {0}; + int ufd; + bool ret = true; + /* if we are here __NR_userfaultfd should exists */ + ufd = syscall(__NR_userfaultfd, O_CLOEXEC); + if (ufd == -1) { + return false; + } + + /* ask features */ api_struct.api = UFFD_API; api_struct.features = 0; if (ioctl(ufd, UFFDIO_API, &api_struct)) { - error_report("postcopy_ram_supported_by_host: UFFDIO_API failed: %s", + error_report("receive_ufd_features: UFFDIO_API failed: %s", + strerror(errno)); + ret = false; + goto release_ufd; + } + + *features = api_struct.features; + +release_ufd: + close(ufd); + return ret; +} + +static bool request_ufd_features(int ufd, __u64 features) +{ + struct uffdio_api api_struct = {0}; + uint64_t ioctl_mask; + + api_struct.api = UFFD_API; + api_struct.features = features; + if (ioctl(ufd, UFFDIO_API, &api_struct)) { + error_report("request_ufd_features: UFFDIO_API failed: %s", strerror(errno)); return false; } @@ -81,11 +117,33 @@ static bool ufd_version_check(int ufd, MigrationIncomingState *mis) return false; } + return true; +} + +static bool ufd_version_check(int ufd, MigrationIncomingState *mis) +{ + __u64 new_features = 0; + + /* ask features */ + __u64 supported_features; + + if (!receive_ufd_features(&supported_features)) { + error_report("ufd_version_check failed"); + return false; + } + + /* request features */ + if (new_features && !request_ufd_features(ufd, new_features)) { + error_report("ufd_version_check failed: features %" PRIu64, + (uint64_t)new_features); + return false; + } + if (getpagesize() != ram_pagesize_summary()) { bool have_hp = false; /* We've got a huge page */ #ifdef UFFD_FEATURE_MISSING_HUGETLBFS - have_hp = api_struct.features & UFFD_FEATURE_MISSING_HUGETLBFS; + have_hp = supported_features & UFFD_FEATURE_MISSING_HUGETLBFS; #endif if (!have_hp) { error_report("Userfault on this host does not support huge pages");