Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp3520369pxu; Tue, 8 Dec 2020 14:26:39 -0800 (PST) X-Google-Smtp-Source: ABdhPJxbXrXNq3OZ44m8l370ppzw9LYH8cBpYsky5oXznbqG0mavGDC1UAI1AbgMzJmmB3FQmF+5 X-Received: by 2002:a17:906:cd14:: with SMTP id oz20mr23514473ejb.99.1607466399412; Tue, 08 Dec 2020 14:26:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607466399; cv=none; d=google.com; s=arc-20160816; b=q/ghB2RIXAcUtAuyAIcv+PJ/dLupkQZumpAxpzOR44Y8wAAC+HoMFYkKeIilCtlzD8 uIIv/EYA4379cL6UNI2RoLdyueXQDqoU3/cZYjgfn5hN81O9qIBC52P9c4ECABdxO+2C 4xYLW5W4Tcg5RQOtUYLQ13j2bZR4uWVmlkCdmVEHUTj8D5fwq8wXZLaw5eGo8iHP2w/X rzvvflvDsv09A9BbLpSHA2iw5gArEx9Rbx2ZFG1nJh/BYUNYyCrzg4v1y+Rci3mnbjF0 lkCtlTRn/OKZPumvxCt/szTxoN6wNBKkLgmQB+NLlBnE8Vpt8F1Lg2QB3s9q6a1NggjH iVJQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=vDvIgwM3KYUr0vGzGaIWWHLyAec1spjaULYt1zzdT4s=; b=C+L70QHgvsYace+3wzBlOT+yMYryd2xbvngb5vaQjmDVC93vn+/tbQQT7JoL/rjZCf 6LjwaXxU9FoP6sXaUVejZt+5fqOYZtOklfnxoXFdoc/ihVXl2+HrVGXywdaVDcfkPof+ STfvq+lwOw9CuzZB5FYL7UWXjOgpuBfYs3ZA/dsT/8f8sk64L0PnEjdr4YuXVzKUrciF 4QKu/b4k5dn6jgL8MbewGWrhhHDAnFoq36hjp2SLYNnIOfsGsuiHMxqeLa+l3iqXUhpA pRiTQQI5dSYZlB3JipU5Ky35lIMEOfYoj0DG3bVuXYMNXRwV3cfWFqe0H5cuZCflBw/z ne7g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel-com.20150623.gappssmtp.com header.s=20150623 header.b=lcCLQiHg; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r10si4670511edy.187.2020.12.08.14.26.16; Tue, 08 Dec 2020 14:26:39 -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=@intel-com.20150623.gappssmtp.com header.s=20150623 header.b=lcCLQiHg; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731050AbgLHWXy (ORCPT + 99 others); Tue, 8 Dec 2020 17:23:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57130 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730450AbgLHWXy (ORCPT ); Tue, 8 Dec 2020 17:23:54 -0500 Received: from mail-ej1-x642.google.com (mail-ej1-x642.google.com [IPv6:2a00:1450:4864:20::642]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A8CBFC0613CF for ; Tue, 8 Dec 2020 14:23:13 -0800 (PST) Received: by mail-ej1-x642.google.com with SMTP id qw4so66974ejb.12 for ; Tue, 08 Dec 2020 14:23:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=vDvIgwM3KYUr0vGzGaIWWHLyAec1spjaULYt1zzdT4s=; b=lcCLQiHgKOnWsKLetWZmR5QtSD6blr1zwiw554WVg0AiNLsDu/kt6/L2pZGQeRHIlR sk4AVKxRad9oVAN0P4xpOslW8DxPRoB5wUGIl/7BR8VDXluBCoCy3GltHE+FXzPRrQxR wQej/D6bXtMRk92njXQqKJZQH8etZbXv83JEtSOT5th+HgexH+PpCMk0aUGWuYCayWqM vOXlOUNv+ppF55wtH9HFHRDVUrwvk/2TbLHkv8ldtjRRWc/2AULYvbscWV+jss9n54tu WpKpNOLYTePYoJy7ePGx930oJcVthHof02l6Ltv8q8N765mB7nbm99dZ7SnDj/JyCKdm eCNA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=vDvIgwM3KYUr0vGzGaIWWHLyAec1spjaULYt1zzdT4s=; b=WWL9X9PSt9j9pLleQZ1HTAHTpSFyMrYRdBUc0Mb7wwCxQGXExkk9xh/JKve3OI/oyR ZyEM6fpbr22Ztz2y8LfaZvwkGqd3iQ487YVEgrWuQrEF427zFXrB+fA5uuvNUSccjbTu c2BPwxC0UhgWkj+6Ob0WlY5p3TPSrmk1f2FCYz8zGqMPP0tcjeWLsCl5OvF3DMqZziAo wyG+GHY58Rh98KvGQTHrioEfpMT9fg3gXHvRbxZXMSGIjW6iDW43+89DPaaoH0fmGb4h Xi/lVhCE6zYbO9Pldt20RVm7Jsvvs92dyXQ7AqrmCGrw2njn23apsKbF8qZr48XgwcjN EeSw== X-Gm-Message-State: AOAM533/PCZmj30CjPm8mGT6I/13Ktm0vGlOHxzUh+AU9g0h9pQ6Hf1G hJV/HL9rcdsIgKZcZl5WiQW0s1RwJFs0hgWDhNFmGA== X-Received: by 2002:a17:906:edb2:: with SMTP id sa18mr23993748ejb.264.1607466192389; Tue, 08 Dec 2020 14:23:12 -0800 (PST) MIME-Version: 1.0 References: <20201207225703.2033611-1-ira.weiny@intel.com> <20201207225703.2033611-3-ira.weiny@intel.com> <20201207232649.GD7338@casper.infradead.org> <20201207234008.GE7338@casper.infradead.org> <20201208213255.GO1563847@iweiny-DESK2.sc.intel.com> <20201208215028.GK7338@casper.infradead.org> In-Reply-To: <20201208215028.GK7338@casper.infradead.org> From: Dan Williams Date: Tue, 8 Dec 2020 14:23:10 -0800 Message-ID: Subject: Re: [PATCH V2 2/2] mm/highmem: Lift memcpy_[to|from]_page to core To: Matthew Wilcox Cc: Ira Weiny , Thomas Gleixner , Andrew Morton , Dave Hansen , Christoph Hellwig , Al Viro , Eric Biggers , Joonas Lahtinen , Linux Kernel Mailing List , linux-fsdevel Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Dec 8, 2020 at 1:51 PM Matthew Wilcox wrote: > > On Tue, Dec 08, 2020 at 01:32:55PM -0800, Ira Weiny wrote: > > On Mon, Dec 07, 2020 at 03:49:55PM -0800, Dan Williams wrote: > > > On Mon, Dec 7, 2020 at 3:40 PM Matthew Wilcox wrote: > > > > > > > > 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? > > > > > > Wouldn't it fault in HIGHMEM=y case? I guess not necessarily... > > > > > > > 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? > > > > > > Right, if the driver was relying on "corruption" for correct operation. > > > > > > If corruption actual were happening in practice wouldn't there have > > > been screams by now? Again, not necessarily... > > > > > > At least with just plain WARN the kernel will start screaming on the > > > user's behalf, and if it worked before it will keep working. > > > > So I decided to just sleep on this because I was recently told to not introduce > > new WARN_ON's[1] > > > > I don't think that truncating len is worth the effort. The conversions being > > done should all 'work' At least corrupting users data in the same way as it > > used to... ;-) I'm ok with adding the WARN_ON's and I have modified the patch > > to do so while I work through the 0-day issues. (not sure what is going on > > there.) > > > > However, are we ok with adding the WARN_ON's given what Greg KH told me? This > > is a bit more critical than the PKS API in that it could result in corrupt > > data. > > zero_user_segments contains: > > BUG_ON(end1 > page_size(page) || end2 > page_size(page)); > > These should be consistent. I think we've demonstrated that there is > no good option here. True, but these helpers are being deployed to many new locations where they were not used before.