Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp5061794pxb; Tue, 28 Sep 2021 09:44:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwAS3GOUzXt4H8vRNK13UmAFnESH0OVBQYQyFdj82b8LrrtQiYf4alZMJqJUrLmSBcCFqTM X-Received: by 2002:a17:902:7043:b0:13e:1007:3d6d with SMTP id h3-20020a170902704300b0013e10073d6dmr5791434plt.79.1632847458330; Tue, 28 Sep 2021 09:44:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632847458; cv=none; d=google.com; s=arc-20160816; b=ivNmjlomXX4XbRySrXqoSP16kZOxmSkhx0cRXScEORn7eLZJ+XPaGASsyeYYAvyyn6 CclEksPV/9kRVEhIwgVNYDbYgNZE6mSu9MV+cocbipOtOyYSlDDtENxBtzVR8DX2x7+P Rl8ACijr81Mlb7iZQ/g1EdR6PHYQK92gvcnX+qAo7Vss3cHQbU2oxRraqDcgvcbYz7MR uIygCQxkagghNmzNed2tUYIZYA8at1ocxqrLuC72zHEHOvhQMbyJcXqgWlWfMXSUcmC3 xMwd/oOqexd8k0uJQI2Np3TjpdHDsWGIQrwhvJ3Czcfcn/2Tpq0pyKAAgNSZvG6WQGE8 IaQQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=WZIHzocEelFp8OufIzX41zG6IC2iFCm0QYf5egEA+AI=; b=rZ2E3I77AfTzrHFW28MTYN31mry5QLgSIqezVNxbb5q7si+NrGCTUzcsW+6guD1Lkr phv2BRe02Ua52yqTHoEiEAZgOAE2G1aFaX1+MoC7HNixPo/f51cLeYrMeMClTJEvyR63 xQqN6QDxMjdU/eUxBIYQh4774jny5Dvm7zunFgi9Xozg0XkVYg33Cd7x7tJxH1q4csKk 1pvxRzku8SuQ/1MqzusF8lDWAldTQY0bVHvcp2Ixmk9svPaLnnVnA43/HVND+Ok3+Kh6 u+6UKdQ5brIwJYdjzuOMytKuvolJJar2UA2k5RlcYyqtXwgLSah8bdOt6Qjew19kLqio jmZg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=u1HDPNTg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m15si28523674plx.14.2021.09.28.09.44.04; Tue, 28 Sep 2021 09:44:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=u1HDPNTg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241872AbhI1Qnj (ORCPT + 99 others); Tue, 28 Sep 2021 12:43:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55330 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241781AbhI1Qni (ORCPT ); Tue, 28 Sep 2021 12:43:38 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ED482C06161C; Tue, 28 Sep 2021 09:41:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=WZIHzocEelFp8OufIzX41zG6IC2iFCm0QYf5egEA+AI=; b=u1HDPNTgGv7XbtgQTpfZqd9EMt xHFhyYl5PFwciQXO6WwKozCfWvmNRCBH3p6FJ0e+ehJXr50ItGoKxkP/Al4oULutIFHIYvIpC6Rsh Wyibelk5B5a/3aye9oZDkweSh+Cz8K3KlPdsVySGLypu593p0SE8qn8xx/hZO3YJsLmKhKA9E6q9e wmNTzkb/u00t9t9zBOdEH6BP18mL7jERfUaGJR1YU9Q4zhbmYYDMb+BEw7B6g1ZY2M9JfdYYx3a/2 zgLsjpewzwHSHxafEKEz5R23yuj2mbcRSGhacufhS1rLSL2LcoQolz5jiiYml/tJSSeOrVn/xvcVT rhCkUe9A==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1mVG76-00B1nC-Up; Tue, 28 Sep 2021 16:38:06 +0000 Date: Tue, 28 Sep 2021 17:37:52 +0100 From: Matthew Wilcox To: Andreas Gruenbacher Cc: fdmanana@gmail.com, Linus Torvalds , Alexander Viro , Christoph Hellwig , "Darrick J. Wong" , Jan Kara , cluster-devel , linux-fsdevel , Linux Kernel Mailing List , ocfs2-devel@oss.oracle.com Subject: Re: [PATCH v7 03/19] gup: Turn fault_in_pages_{readable,writeable} into fault_in_{readable,writeable} Message-ID: References: <20210827164926.1726765-1-agruenba@redhat.com> <20210827164926.1726765-4-agruenba@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Sep 28, 2021 at 05:02:43PM +0200, Andreas Gruenbacher wrote: > On Fri, Sep 3, 2021 at 4:57 PM Filipe Manana wrote: > > On Fri, Aug 27, 2021 at 5:52 PM Andreas Gruenbacher wrote: > > > +size_t fault_in_writeable(char __user *uaddr, size_t size) > > > +{ > > > + char __user *start = uaddr, *end; > > > + > > > + if (unlikely(size == 0)) > > > + return 0; > > > + if (!PAGE_ALIGNED(uaddr)) { > > > + if (unlikely(__put_user(0, uaddr) != 0)) > > > + return size; > > > + uaddr = (char __user *)PAGE_ALIGN((unsigned long)uaddr); > > > + } > > > + end = (char __user *)PAGE_ALIGN((unsigned long)start + size); > > > + if (unlikely(end < start)) > > > + end = NULL; > > > + while (uaddr != end) { > > > + if (unlikely(__put_user(0, uaddr) != 0)) > > > + goto out; > > > + uaddr += PAGE_SIZE; > > > > Won't we loop endlessly or corrupt some unwanted page when 'end' was > > set to NULL? > > What do you mean? We set 'end' to NULL when start + size < start > exactly so that the loop will stop when uaddr wraps around. But think about x86-64. The virtual address space (unless you have 5 level PTs) looks like: [0, 2^47) userspace [2^47, 2^64 - 2^47) hole [2^64 - 2^47, 2^64) kernel space If we try to copy from the hole we'll get some kind of fault (I forget the details). We have to stop at the top of userspace.