Received: by 2002:a25:86ce:0:0:0:0:0 with SMTP id y14csp837467ybm; Wed, 22 May 2019 12:22:41 -0700 (PDT) X-Google-Smtp-Source: APXvYqxplGx+nvTYWWo9754UyfvfIDh+cLj5LM0/1ek8IvvMy8Ur77T65cnGxa/s5DvhAi/XBkdf X-Received: by 2002:a63:6116:: with SMTP id v22mr91305434pgb.272.1558552961103; Wed, 22 May 2019 12:22:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558552961; cv=none; d=google.com; s=arc-20160816; b=Dl5jZP/loSRJFEUDOlAoEFvwY7DcoT5XOn0TIflqFACFwY7H8KeqRHZ8u33ajC6FDY JhjRVkEcQvmSQTuHOZW22krQ6ak10SpgRf2eOyzXRk+cfOQVRXBqUUkiulHeG9usVfjo 4uHdMigFgDZvLvbXBzfSce3dm5/7ik3t988xNd0KV52lMifqaQSqJKBlxmpxa4ycopnX qn0pyG/6eMdcQ8VbwgKJA1u6b+rDORvxwfrlXGuD30PxHBNh067y/aWseEMyzR5lnU31 S539OUl8MyVrErpLa7XWbYnMCvv/ttoIUw6KKYvcIa9kEmQBz8LTVVXiUmP9EZUkikMr qHXA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=s0s9hOakU6c7ONxSQh7jsvM+l1f4GSzFc7DHVYRkcE8=; b=WdyIXCq3czDmbrt1frnP1WADvhf0CWam8OeP6ibB0HLywM7QOErlcSettZOBYieDT8 7zVsy0KqwNulXXboBGBSAP4OGeWbujWb/X4Z6KreLtjWwWQ7QKUdl9T43RQWGeXKTQQe DtgaJTK7VBjqIFMC2KVz5h45ZHUNQ9etcLehSg7E6umV0HqhkDpPWa71kv8ZKNrRB6WC SrwJejM02SpL4aYttKFYgUos9vCkRSyLDoJ+I+/uLXcz9PEVLHld/M8SQnNrVtaYBJf6 FF8/E/lbsTHN6wydt/lryFiB9XiJKbwp0NusXGSGcCQLsYKdk5XWpmd78Ph45qkHJjpP wYhA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=wlA5IMAk; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t25si11720654pgk.442.2019.05.22.12.22.25; Wed, 22 May 2019 12:22:41 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=wlA5IMAk; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729679AbfEVTVQ (ORCPT + 99 others); Wed, 22 May 2019 15:21:16 -0400 Received: from mail.kernel.org ([198.145.29.99]:41606 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728615AbfEVTVQ (ORCPT ); Wed, 22 May 2019 15:21:16 -0400 Received: from localhost.localdomain (c-73-223-200-170.hsd1.ca.comcast.net [73.223.200.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 523F120879; Wed, 22 May 2019 19:21:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1558552875; bh=YbWw5jCdlVSPKASk0Am85SMF0LzLvtSiYq/4581+xHE=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=wlA5IMAkbdJJK84FwgfTk9vb9mKRpiUrE0gdmAYhRNeZdEZWLa1O+1TqMzYFFDkfR m8FRQRwg28nthhrzfBj+wuGjErUBKAjaQqkxYOpUwt4Yv2Q5F1PzzdjoWN+gmExmTD OETzWa9p/CSYA14EHx9WnsYDpghD4UP96mMh+maQ= Date: Wed, 22 May 2019 12:21:13 -0700 From: Andrew Morton To: Mike Rapoport Cc: Andrea Arcangeli , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Sebastian Andrzej Siewior , Borislav Petkov Subject: Re: [PATCH] mm/gup: continue VM_FAULT_RETRY processing event for pre-faults Message-Id: <20190522122113.a2edc8aba32f0fad189bae21@linux-foundation.org> In-Reply-To: <1557844195-18882-1-git-send-email-rppt@linux.ibm.com> References: <1557844195-18882-1-git-send-email-rppt@linux.ibm.com> X-Mailer: Sylpheed 3.5.1 (GTK+ 2.24.31; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 14 May 2019 17:29:55 +0300 Mike Rapoport wrote: > When get_user_pages*() is called with pages = NULL, the processing of > VM_FAULT_RETRY terminates early without actually retrying to fault-in all > the pages. > > If the pages in the requested range belong to a VMA that has userfaultfd > registered, handle_userfault() returns VM_FAULT_RETRY *after* user space > has populated the page, but for the gup pre-fault case there's no actual > retry and the caller will get no pages although they are present. > > This issue was uncovered when running post-copy memory restore in CRIU > after commit d9c9ce34ed5c ("x86/fpu: Fault-in user stack if > copy_fpstate_to_sigframe() fails"). > > After this change, the copying of FPU state to the sigframe switched from > copy_to_user() variants which caused a real page fault to get_user_pages() > with pages parameter set to NULL. You're saying that argument buf_fx in copy_fpstate_to_sigframe() is NULL? If so was that expected by the (now cc'ed) developers of d9c9ce34ed5c8923 ("x86/fpu: Fault-in user stack if copy_fpstate_to_sigframe() fails")? It seems rather odd. copy_fpregs_to_sigframe() doesn't look like it's expecting a NULL argument. Also, I wonder if copy_fpstate_to_sigframe() would be better using fault_in_pages_writeable() rather than get_user_pages_unlocked(). That seems like it operates at a more suitable level and I guess it will fix this issue also. > In post-copy mode of CRIU, the destination memory is managed with > userfaultfd and lack of the retry for pre-fault case in get_user_pages() > causes a crash of the restored process. > > Making the pre-fault behavior of get_user_pages() the same as the "normal" > one fixes the issue. Should this be backported into -stable trees? > Fixes: d9c9ce34ed5c ("x86/fpu: Fault-in user stack if copy_fpstate_to_sigframe() fails") > Signed-off-by: Mike Rapoport