Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp2776448pxu; Mon, 7 Dec 2020 15:45:00 -0800 (PST) X-Google-Smtp-Source: ABdhPJxHg4Rlmt8GdfcmcCTaD0f6MShD0w4z6mSAkUM/3EP1X5Ww6PP8ZzfS3oQOl+L70cV23Z2N X-Received: by 2002:a17:906:55d0:: with SMTP id z16mr20768610ejp.466.1607384700723; Mon, 07 Dec 2020 15:45:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607384700; cv=none; d=google.com; s=arc-20160816; b=nBi5kCL+UDmiECpjNXlVsUuXgcVE0bUoRi7H8TycelGZB4CM8IhOCdJ19yaQAsIdcT hjAgLjmIqkDZzyesHNPhPclxAcFnNPi3sb13O+F/QF4VnJK1kRuPUD11JB1LsMhVh45W ooK8gZjMgHiWcGJlnFylVpLYTIualRYWE//HprH0/jSnNpN3xSUnmQr9O+Wt526LUNWv asdf/DxirCzvGn8f20Qvo2b4yYMRLSk6Arhj2Bd5Gar05Ks08mEqEbumUA/BtcfEMPIJ 1QqWD5gb5QG9fcIdEZ4V4A1xEkLObYCpFZr5IvfSB2tRJF/OldgBpH/OCnj/A7+UavAw hAUQ== 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=5AE7BSE6Le8OpJjv+/Aj3F3qvVXYZeWZq3mq2zg0PHQ=; b=xQ/l2Qs5iyj7GrZIpa7JtaHRHsBnMZifo0RPJmIfrP8JQJCNNVQUZKBOVp86m2l1i7 LzOzYENELujpjnPBxnB2QUZ62V09LKLlWfuTZ9CZuE1tFCdoQpQGd2YiSbh/T/UdPlHF F71NyYEgX2GcOihcoB2kXWg17aQb7vNkJIAPoGuhITzEcjIIO4b628YICMXjdWXwVGVD i+XURQQq6UG7bryl7YWjEyOfp17nDbhOFBqqXxxyxN83x0p/zWFogftghFXtgmoUGTOg 6lapozMhjgUxcteVvc0SlVesSXMFIJHVu7cV6sivgcpwQcRaTSz2zz3xCSHaAPblqsls QRcQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=fPiiJZs5; 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 dc18si8861113edb.76.2020.12.07.15.44.35; Mon, 07 Dec 2020 15:45:00 -0800 (PST) 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=fPiiJZs5; 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 S1728173AbgLGXk5 (ORCPT + 99 others); Mon, 7 Dec 2020 18:40:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41578 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726708AbgLGXk5 (ORCPT ); Mon, 7 Dec 2020 18:40:57 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EE8BBC061749; Mon, 7 Dec 2020 15:40:16 -0800 (PST) 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=5AE7BSE6Le8OpJjv+/Aj3F3qvVXYZeWZq3mq2zg0PHQ=; b=fPiiJZs5xU73noEHWcJcm4NTp7 QBEqwAjgUw28ab1vCCPxeqXcKGimGpc+CN7lt97fuyKgS71wexBhXgVOKo4pzYDq52SX3HJ/TtS2w VyBaLTV00ttN8I+BYiFMsHM4UgpX8ShWh6PaikCuoS+DGO9ACavqY1i5ZEazpgRfkpvrc6gaMFhO7 gz/89aWpUueRFu9BcElEvmaZQrZlnIjyGGtMUgPypMJ+h2HLRXiAhZCTYqzTBvlqvDvn+OzPsxyxO znOwjxoDUqODM2NiXu2tq0AOHX8teaAPgKmjnVWke6VONPMkZcb/ndx0Mugb5EIjhtuS5BznDQsj0 Dh9xJ4PQ==; Received: from willy by casper.infradead.org with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1kmQ6z-0002gV-0P; Mon, 07 Dec 2020 23:40:09 +0000 Date: Mon, 7 Dec 2020 23:40:08 +0000 From: Matthew Wilcox To: Dan Williams Cc: "Weiny, Ira" , Thomas Gleixner , Andrew Morton , Dave Hansen , Christoph Hellwig , Al Viro , Eric Biggers , Joonas Lahtinen , Linux Kernel Mailing List , linux-fsdevel Subject: Re: [PATCH V2 2/2] mm/highmem: Lift memcpy_[to|from]_page to core Message-ID: <20201207234008.GE7338@casper.infradead.org> References: <20201207225703.2033611-1-ira.weiny@intel.com> <20201207225703.2033611-3-ira.weiny@intel.com> <20201207232649.GD7338@casper.infradead.org> 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 Mon, Dec 07, 2020 at 03:34:44PM -0800, Dan Williams wrote: > On Mon, Dec 7, 2020 at 3:27 PM Matthew Wilcox wrote: > > > > On Mon, Dec 07, 2020 at 02:57:03PM -0800, ira.weiny@intel.com wrote: > > > +static inline void memcpy_page(struct page *dst_page, size_t dst_off, > > > + struct page *src_page, size_t src_off, > > > + size_t len) > > > +{ > > > + char *dst = kmap_local_page(dst_page); > > > + char *src = kmap_local_page(src_page); > > > > I appreciate you've only moved these, but please add: > > > > BUG_ON(dst_off + len > PAGE_SIZE || src_off + len > PAGE_SIZE); > > I imagine it's not outside the realm of possibility that some driver > on CONFIG_HIGHMEM=n is violating this assumption and getting away with > it because kmap_atomic() of contiguous pages "just works (TM)". > Shouldn't this WARN rather than BUG so that the user can report the > buggy driver and not have a dead system? As opposed to (on a HIGHMEM=y system) silently corrupting data that is on the next page of memory? I suppose ideally ... if (WARN_ON(dst_off + len > PAGE_SIZE)) len = PAGE_SIZE - dst_off; if (WARN_ON(src_off + len > PAGE_SIZE)) len = PAGE_SIZE - src_off; and then we just truncate the data of the offending caller instead of corrupting innocent data that happens to be adjacent. Although that's not ideal either ... I dunno, what's the least bad poison to drink here?