Received: by 2002:a25:86ce:0:0:0:0:0 with SMTP id y14csp906403ybm; Wed, 22 May 2019 13:41:35 -0700 (PDT) X-Google-Smtp-Source: APXvYqwvImHpGT9mxe7vhfNnEhDxIMZ5x9NP1DxvHOacp4cIocv9a1cLqPaXEjK+57yq8RlQdEV3 X-Received: by 2002:a63:fd4a:: with SMTP id m10mr90666512pgj.302.1558557695508; Wed, 22 May 2019 13:41:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558557695; cv=none; d=google.com; s=arc-20160816; b=0V+TWGHoit8HXxZbuH+inw7dU3CeQL0g6zlL8M7WAvsvzDR0EIztM9zmA1Jx8u33/+ z+mYGkgFksSKj7QOM48A6k0lFJfyyeAPQceGUfpWDB4hfHcxgthoUg/K7/42YQdMI1N6 moz40dHwCmDeMreTnKDTIg8jHVwElZFkH7mNmklDeoQYe75GQzeYy68vg2ygRgWI6Sv5 wnuAUKyiFgBBfKwYJa9lQtu9SeuErgariDHZGFzE/SzFZ72Orv+mceCigzaCzxSFC59a pa7aohWwOsCu7n7fRkqV0M7g7Er0kvIb4utLI0X8GqE567kPRDWIb0vZKuyI2HpINKh2 AofQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:user-agent:in-reply-to :content-disposition:mime-version:references:subject:cc:to:from:date; bh=d+ndlJSLq+rU6RgWbIIbnH1PzqZ7zjvEvgMkuhh1tPQ=; b=jmLV3eVehGe2+2K2OaFlxULTyu4EfGQvomtkzMWnd55GU7Z18OQ3ehqq/KVv7XA470 doV+sPUSihCScth5Kaa8knHWfH5YEwwVJK7D6rL3P4JJwZzJXc2jNsy9TZw/us794amP J5+3HTs5Txfly5jAEXAg0SgRojud/obY1VSxIJ3WJ4YRb97TwLcWTcMT54BpTu//C4xR CwJ370iRkH942T/7BkLc6hjpoqQAYgYrK73pwzoH5t9aCJg7AGs5fqX7RUtsoeucOP2H wWsLZg8pEpSDVWTlDxUqOfhdz8EL6aG5lzQiB89yowOgkx3zQhQmPx9Ez0jxnsGEYZ5f wuuQ== ARC-Authentication-Results: i=1; mx.google.com; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t1si26428300plr.74.2019.05.22.13.41.20; Wed, 22 May 2019 13:41:35 -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; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729934AbfEVUij (ORCPT + 99 others); Wed, 22 May 2019 16:38:39 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:56274 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729667AbfEVUij (ORCPT ); Wed, 22 May 2019 16:38:39 -0400 Received: from pps.filterd (m0098394.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x4MKbQVZ110248 for ; Wed, 22 May 2019 16:38:38 -0400 Received: from e06smtp05.uk.ibm.com (e06smtp05.uk.ibm.com [195.75.94.101]) by mx0a-001b2d01.pphosted.com with ESMTP id 2snbqtce8q-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 22 May 2019 16:38:38 -0400 Received: from localhost by e06smtp05.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 22 May 2019 21:38:36 +0100 Received: from b06cxnps3074.portsmouth.uk.ibm.com (9.149.109.194) by e06smtp05.uk.ibm.com (192.168.101.135) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Wed, 22 May 2019 21:38:33 +0100 Received: from d06av26.portsmouth.uk.ibm.com (d06av26.portsmouth.uk.ibm.com [9.149.105.62]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id x4MKcW4Y50397334 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 22 May 2019 20:38:32 GMT Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 5E2C5AE045; Wed, 22 May 2019 20:38:32 +0000 (GMT) Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 87F48AE04D; Wed, 22 May 2019 20:38:31 +0000 (GMT) Received: from rapoport-lnx (unknown [9.148.205.81]) by d06av26.portsmouth.uk.ibm.com (Postfix) with ESMTPS; Wed, 22 May 2019 20:38:31 +0000 (GMT) Date: Wed, 22 May 2019 23:38:29 +0300 From: Mike Rapoport To: Andrew Morton Cc: Andrea Arcangeli , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Sebastian Andrzej Siewior , Borislav Petkov , "Dr. David Alan Gilbert" , kvm@vger.kernel.org Subject: Re: [PATCH] mm/gup: continue VM_FAULT_RETRY processing event for pre-faults References: <1557844195-18882-1-git-send-email-rppt@linux.ibm.com> <20190522122113.a2edc8aba32f0fad189bae21@linux-foundation.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190522122113.a2edc8aba32f0fad189bae21@linux-foundation.org> User-Agent: Mutt/1.5.24 (2015-08-30) X-TM-AS-GCONF: 00 x-cbid: 19052220-0020-0000-0000-0000033F6D06 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 19052220-0021-0000-0000-0000219253D1 Message-Id: <20190522203828.GC18865@rapoport-lnx> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-05-22_12:,, 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=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1905220144 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org (added kvm) On Wed, May 22, 2019 at 12:21:13PM -0700, Andrew Morton wrote: > 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? Apparently I haven't explained well. The 'pages' parameter in the call to get_user_pages_unlocked() 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. If I understand correctly, one of the points of d9c9ce34ed5c8923 ("x86/fpu: Fault-in user stack if copy_fpstate_to_sigframe() fails") was to to avoid page faults, hence the use of get_user_pages(). With fault_in_pages_writeable() there might be a page fault, unless I've completely mistaken. Unrelated to copy_fpstate_to_sigframe(), the issue could happen if any call to get_user_pages() with pages parameter set to NULL tries to access userfaultfd-managed memory. Currently, there are 4 in tree users: arch/x86/kernel/fpu/signal.c:198:8-31: -> gup with !pages arch/x86/mm/mpx.c:423:11-25: -> gup with !pages virt/kvm/async_pf.c:90:1-22: -> gup with !pages virt/kvm/kvm_main.c:1437:6-20: -> gup with !pages I don't know if anybody is using mpx with uffd and anyway mpx seems to go away. As for KVM, I think that post-copy live migration of L2 guest might trigger that as well. Not sure though, I'm not really familiar with KVM code. > > 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? I think that it depends on whether KVM affected by this or not. > > Fixes: d9c9ce34ed5c ("x86/fpu: Fault-in user stack if copy_fpstate_to_sigframe() fails") > > Signed-off-by: Mike Rapoport > > -- Sincerely yours, Mike.