Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp1897064ybi; Sat, 25 May 2019 11:10:47 -0700 (PDT) X-Google-Smtp-Source: APXvYqzFbbQl3ierJMz5xwP8lKtNlJCQgfziTbVvGT3ViY3RsX0quDnriXTJZohNqRL/g16hUkO1 X-Received: by 2002:a17:902:b108:: with SMTP id q8mr109035501plr.110.1558807847253; Sat, 25 May 2019 11:10:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558807847; cv=none; d=google.com; s=arc-20160816; b=sJjB+msaPqi9+gpCKvB1+M14W/BfCQQPia84Vs2UlCp5nVjogPu16YH43oZX6IUj4D F5TRzaWqN1GA/o8xCN+rmFq99c+9GpR4Dc1aqjazCn28LfL/UQL40W5hKxoZbgd4BIQx 49y166veX284wPrJ/AwPRdzz336jGGH7BAGzDJZDN6yahg9jaGHmrrYotpT/MS2pwZ3G ZhUAUe8mZkdMyqlYmLeObIUIahkNYKuPXk4XjEVlLUyuGiwlDAyLHv8TntGg+zZegnBT gwuKGOI9vhjgkvktgmMBEVISxb+m0RsAKl7pQmDcb2BTSJ8I6bm6MXbQvyAmhc6mCF3P ZbNg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :message-id:in-reply-to:subject:cc:to:from:date:dkim-signature; bh=rFgOoMr190otbVvdh7Sjz5mXZ2cf+5wMmXCKsssM39U=; b=Biu9LA/mpjI5YuqTGZGXumn/KllrmJ+7+wrzoyCqyEuj+9A4UxtUlYdAm8VJaMd523 VntzgtArBpQIqI5j/1neU9CX+O5Rx2PGEIQBP3mEWR+gXG5I0FzG6z5IsllTsutorZ1J JKe/l1c5GvtYmeIjV6Emta7wEZTR0M3IJACHPndmUFPVulxoEeJ3yL70uVSL2mTQ3G6i 87qpl6mJr6qytLEuUE3upwxBe4rvpB3ajdJta8foeYpw3PLGfEoCeX+0GGYi1lZCeOzo EBoRHRZVPrkiRrI/A8Yf8q9b1qY3DwN0RI8oC2HJAXZK7fndGs7QwswsUVwqIlsH2Y56 hHhg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=B28z101M; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e2si9419143pfh.286.2019.05.25.11.10.30; Sat, 25 May 2019 11:10:47 -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=@google.com header.s=20161025 header.b=B28z101M; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727222AbfEYSJU (ORCPT + 99 others); Sat, 25 May 2019 14:09:20 -0400 Received: from mail-ot1-f67.google.com ([209.85.210.67]:46925 "EHLO mail-ot1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726647AbfEYSJU (ORCPT ); Sat, 25 May 2019 14:09:20 -0400 Received: by mail-ot1-f67.google.com with SMTP id j49so11484992otc.13 for ; Sat, 25 May 2019 11:09:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:in-reply-to:message-id:references :user-agent:mime-version; bh=rFgOoMr190otbVvdh7Sjz5mXZ2cf+5wMmXCKsssM39U=; b=B28z101MMb+xz5ZuNz32ZuUK400uyAbJBivZiOA8Ofss6C9wnz+t8aMAIY6qnP6Y/I P54tSGwQ1vux1+VjpZ4y98ugvd/Eu0/gtBhIPrMTfDUvHFQF2X+iuKxPXQa8FZQRNTni +ScKBaPz28JBqoQlc7xdrZMUM9Ww6A3FqoWXemzaPoEG39IvwPAl4IwKlliTRK/9Noz2 KO6hQubO8lSixzp/98fTUR4SAY9Ng1h0Ml/60gSb1ifOHIVmSF/dlf36quAIYfgCRVC6 t/byTjyZDPpqdU9nLdy+Tjqwviescps0rKHMYcj89Ewxhr/A4ttctv6pECjWvVgdgw0m aPgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:in-reply-to:message-id :references:user-agent:mime-version; bh=rFgOoMr190otbVvdh7Sjz5mXZ2cf+5wMmXCKsssM39U=; b=SAIYQHV20eyK77vsqMDvviXPqQIifSBZC1SB8US+PScJqLZpx0hhJYbcZjh9lf8mMP rX8/d6Blne0Fv6Yee1vJXKBSNWSD7JAXzfxPgEdAPhq1gIwbL3rWoYW0IMKdvKoUj+Sc MOaqbJ6HT1dIbSwWgrU/wdfAaTtvu7+4lKD97ygZRjAGta1pNHf7vfnEQMqcZAKo+hZr zIgrJ7SMgSU0zgYvKpyToF+kQNgLVxbUyhxsf11U4EcHk616z5RNWEQAKzs4KstDoA4L OjbP2py6PCIvtDDDHRucD++TD/BuvJ4k8XVeHzscQdIk33YKClygk/RAiSFhRY9rBAJn NsAg== X-Gm-Message-State: APjAAAVYQvV37pRkvQWPepCC3FHi6qOg4FBeHOaGd4msUNAwxnS/B5l0 3taCGndqsNCWgZ1ipylLgJLAGw== X-Received: by 2002:a9d:69c8:: with SMTP id v8mr12339129oto.6.1558807759055; Sat, 25 May 2019 11:09:19 -0700 (PDT) Received: from eggly.attlocal.net (172-10-233-147.lightspeed.sntcca.sbcglobal.net. [172.10.233.147]) by smtp.gmail.com with ESMTPSA id x91sm2377705otb.10.2019.05.25.11.09.17 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 25 May 2019 11:09:17 -0700 (PDT) Date: Sat, 25 May 2019 11:09:15 -0700 (PDT) From: Hugh Dickins X-X-Sender: hugh@eggly.anvils To: Sebastian Andrzej Siewior cc: Hugh Dickins , Andrew Morton , Mike Rapoport , Andrea Arcangeli , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Borislav Petkov , Pavel Machek , Dave Hansen Subject: Re: [PATCH] mm/gup: continue VM_FAULT_RETRY processing event for pre-faults In-Reply-To: <20190525084546.fap2wkefepeia22f@linutronix.de> Message-ID: References: <1557844195-18882-1-git-send-email-rppt@linux.ibm.com> <20190522122113.a2edc8aba32f0fad189bae21@linux-foundation.org> <20190522194322.5k52docwgp5zkdcj@linutronix.de> <20190525084546.fap2wkefepeia22f@linutronix.de> User-Agent: Alpine 2.11 (LSU 23 2013-08-11) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, 25 May 2019, Sebastian Andrzej Siewior wrote: > On 2019-05-24 15:22:51 [-0700], Hugh Dickins wrote: > > I've now run a couple of hours of load successfully with Mike's patch > > to GUP, no problem; but whatever the merits of that patch in general, > > I agree with Andrew that fault_in_pages_writeable() seems altogether > > more appropriate for copy_fpstate_to_sigframe(), and have now run a > > couple of hours of load successfully with this instead (rewrite to taste): > > so this patch instead of Mike's GUP patch fixes the issue you observed? Yes. > Is this just a taste question or limitation of the function in general? I'd say it's just a taste question. Though the the fact that your usage showed up a bug in the get_user_pages_unlocked() implementation, demanding a fix, does indicate that it's a more fragile and complex route, better avoided if there's a good simple alternative. If it were not already on your slowpath, I'd also argue fault_in_pages_writeable() is a more efficient way to do it. > > I'm asking because it has been suggested and is used in MPX code (in the > signal path but .mmap) and I'm not aware of any limitation. But as I > wrote earlier to akpm, if the MM folks suggest to use this instead I am > happy to switch. I know nothing of MPX, beyond that Dave Hansen has posted patches to remove that support entirely, so I'm surprised arch/x86/mm/mpx.c is still in the tree. But peering at it now, it looks as if it's using get_user_pages() while holding mmap_sem, whereas you (sensibly enough) used get_user_pages_unlocked() to handle the mmap_sem for you - the trouble with that is that since it knows it's in control of mmap_sem, it feels free to drop it internally, and that takes it down the path of the premature return when pages NULL that Mike is fixing. MPX's get_user_pages() is not free to go that way. > > > --- 5.2-rc1/arch/x86/kernel/fpu/signal.c > > +++ linux/arch/x86/kernel/fpu/signal.c > > @@ -3,6 +3,7 @@ > > * FPU signal frame handling routines. > > */ > > > > +#include > > #include > > #include > > > > @@ -189,15 +190,7 @@ retry: > > fpregs_unlock(); > > > > if (ret) { > > - int aligned_size; > > - int nr_pages; > > - > > - aligned_size = offset_in_page(buf_fx) + fpu_user_xstate_size; > > - nr_pages = DIV_ROUND_UP(aligned_size, PAGE_SIZE); > > - > > - ret = get_user_pages_unlocked((unsigned long)buf_fx, nr_pages, > > - NULL, FOLL_WRITE); > > - if (ret == nr_pages) > > + if (!fault_in_pages_writeable(buf_fx, fpu_user_xstate_size)) > > goto retry; > > return -EFAULT; > > } > > > > (I did wonder whether there needs to be an access_ok() check on buf_fx; > > but if so, then I think it would already have been needed before the > > earlier copy_fpregs_to_sigframe(); but I didn't get deep enough into > > that to be sure, nor into whether access_ok() check on buf covers buf_fx.) > > There is an access_ok() at the begin of copy_fpregs_to_sigframe(). The > memory is allocated from user's stack and there is (later) an > access_ok() for the whole region (which can be more than the memory used > by the FPU code). Yes, but remember I know nothing of this FPU signal code, so I cannot tell whether an access_ok(buf, size) is good enough to cover the range of an access_ok(buf_fx, fpu_user_xstate_size). Your "(later)" worries me a little - I hope you're not writing first and checking the limits later; but what you're doing may be perfectly correct, I'm just too far from understanding the details to say; but raised the matter because (I think) get_user_pages_unlocked() would entail an access_ok() check where fault_in_pages_writable() would not. Hugh