Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp951000ybz; Fri, 1 May 2020 11:30:47 -0700 (PDT) X-Google-Smtp-Source: APiQypKxu2dOnugQDpRg68kCVCyk2QJ9/ifVZcAgYJqXip/k4WSkIywmtpW3Am5m+u3k3jJ+53bp X-Received: by 2002:a17:906:534b:: with SMTP id j11mr4352618ejo.142.1588357847741; Fri, 01 May 2020 11:30:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588357847; cv=none; d=google.com; s=arc-20160816; b=h4LHzazxlNPwdw+anKfmJbDkbQiLK4pqgwI6kIzi6bbGEpaq2dJp5UYEXkFOMLrb6y oQEJhOxnW1Quj9OjdrW8B58C4u0DC8eJ4CjNQr73J9Ja4kOzuVm6WlpWsNhW5MVh5/j9 9hPpP4XhTIA68vrlj/pZnIxW+QuLh6baa701u/WQURKKp0HoDfUWnU2f1RdoeKREjiku TBuu+EV/WwoqmnYhFmy5IcUgCpHMp2dVjFcBT3xfJhsxYSLDpFJUXWAnZ28Z1L/4xEzY rDZS0BKJzzq9i6HvEfD8m0hQFYpcxI6rv2jiZvnKxJA2gk9G/PwsWS6ZBjPAH4ZaEvMF oMvA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=Rg73oT2i7CN6P9GKzkav2692ScwMvCV8w1kfBm2rvpc=; b=keLKN8YqECdzBY7k7Kghg0p+We0B7S/tnEJQU5BjwVjR8M4Z0FUPnbif0a9SphDOup qCQ+bCKr+KXGEETpCH23EPlVTM1YAuwsujhliCdND7CbsopgNFBv9JoQk8Zocas8OKct BhnENKJAciwwJMDSiF1T0zCi6D+3S4zFvuB24YG1YXT1eZEHSJgvD2Rhb2L471qa/PN7 Y2fyJElLnn6YV9UZ0cjvaWLv7zkJ4VQ6U6qw8/SQKJr/xbggwJKTIF8kPlt4utYmAJv4 h/Z74DwxhnJy4ApHgmZjjZdLY6joYYQJ84czUE6B2E2iMduhT4YGfYUsdKKS+TpeBqsB Mjxw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=DBxmwg4X; 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 o16si2093513edi.482.2020.05.01.11.30.23; Fri, 01 May 2020 11:30:47 -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=@linux-foundation.org header.s=google header.b=DBxmwg4X; 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 S1730062AbgEAS25 (ORCPT + 99 others); Fri, 1 May 2020 14:28:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41458 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1729767AbgEAS25 (ORCPT ); Fri, 1 May 2020 14:28:57 -0400 Received: from mail-lf1-x143.google.com (mail-lf1-x143.google.com [IPv6:2a00:1450:4864:20::143]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 03336C061A0E for ; Fri, 1 May 2020 11:28:57 -0700 (PDT) Received: by mail-lf1-x143.google.com with SMTP id l11so4519086lfc.5 for ; Fri, 01 May 2020 11:28:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=Rg73oT2i7CN6P9GKzkav2692ScwMvCV8w1kfBm2rvpc=; b=DBxmwg4XXi8IArR4p+XyseptF37LsJFDYGKqn4Fej360l2/VSOaUYBVFHiPhk/xhQ8 s6lROshASV7jHjtWyNPvqjhgrgkaFVzegagn8zAtbWr/xDt6AORujuznySe6OYHZ6Vgb o4yy070krugoANDoZtUamLdr0Ij+rfCPnRdZE= 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=Rg73oT2i7CN6P9GKzkav2692ScwMvCV8w1kfBm2rvpc=; b=sx3Bo1aSepp64w7oINdAsEOwpZoFFMCmiPjJ4mYYiYaCGAP0KHLqIDqklKHvXuoZaR WXBRR/19KDKv4GkE8cGeItJ4FDP/bHBL6iGBNxbZm6ydxbHkgpWwUCMDdnstoGQ74IDN kzEXutzCUS4qBv7KB304XHEZnnVhOURnZ9cZekSVoimbj6PDiHecOMOyymX/JBUeY6k4 MK+Dh6KOvZFHTueg79YpOOIyUSgo/2PeXsVf+cbp41MT28oKSS+sRedEBNnlkSOtOzMc kmwWFVSVf+PEQ5MMVuwRmzSiC1HCmnpRaevUdPdYJTferwB4VDnOk+RmbbiaObMTvtNL lx+Q== X-Gm-Message-State: AGi0PuZ8fp/Ay2O7hdbrMus4tITCAlQh6r5/SH7i2GtyquBRxqZaWlSm YoWK5caqMMlCDMUOtdD3S4Qmbu2OsjY= X-Received: by 2002:a19:4843:: with SMTP id v64mr3288491lfa.155.1588357733960; Fri, 01 May 2020 11:28:53 -0700 (PDT) Received: from mail-lj1-f176.google.com (mail-lj1-f176.google.com. [209.85.208.176]) by smtp.gmail.com with ESMTPSA id o3sm2699661lfl.78.2020.05.01.11.28.51 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 01 May 2020 11:28:52 -0700 (PDT) Received: by mail-lj1-f176.google.com with SMTP id h4so3380615ljg.12 for ; Fri, 01 May 2020 11:28:51 -0700 (PDT) X-Received: by 2002:a2e:7308:: with SMTP id o8mr3129793ljc.16.1588357731518; Fri, 01 May 2020 11:28:51 -0700 (PDT) MIME-Version: 1.0 References: <158823509800.2094061.9683997333958344535.stgit@dwillia2-desk3.amr.corp.intel.com> <20200430192258.GA24749@agluck-desk2.amr.corp.intel.com> In-Reply-To: From: Linus Torvalds Date: Fri, 1 May 2020 11:28:35 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v2 0/2] Replace and improve "mcsafe" with copy_safe() To: Dan Williams Cc: "Luck, Tony" , Andy Lutomirski , Thomas Gleixner , Ingo Molnar , Peter Zijlstra , Borislav Petkov , stable , "the arch/x86 maintainers" , "H. Peter Anvin" , Paul Mackerras , Benjamin Herrenschmidt , Erwin Tsaur , Michael Ellerman , Arnaldo Carvalho de Melo , linux-nvdimm , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Apr 30, 2020 at 6:21 PM Dan Williams wrote: > > However now I see that copy_user_generic() works for the wrong reason. > It works because the exception on the source address due to poison > looks no different than a write fault on the user address to the > caller, it's still just a short copy. So it makes copy_to_user() work > for the wrong reason relative to the name. Right. And it won't work that way on other architectures. On x86, we have a generic function that can take faults on either side, and we use it for both cases (and for the "in_user" case too), but that's an artifact of the architecture oddity. In fact, it's probably wrong even on x86 - because it can hide bugs - but writing those things is painful enough that everybody prefers having just one function. That's particularly true since that "one function" is actually a whole family of functions - just for different optimizations. Plus on x86 you can't reasonably even have different code sequences for that case, because CLAC/STAC don't have a "enable users read accesses" vs "write accesses" case. It's an all-or-nothing "enable user faults". We _used_ to have a difference on x86, back when we did the whole "fs segment points to user space". But on other architectures, there really is a difference between "copy_to_user()" and "copy_from_user()", and the functions won't do fault handling for the kernel side accesses. > How about, following your suggestion, introduce copy_mc_to_user() (can > just use copy_user_generic() internally) and copy_mc_to_kernel() for > the other the helpers that the copy_to_iter() implementation needs? Yes. That at least solves my naming worries, and is conceptually something that works on other architectures. Those other architectures may not have nvdimm support yet, but I think everybody is at least looking at it. And I really do think it will make the users more readable too, when you see on a source level that "oh, this code is expecting that it could take a poison fault/machine check on the source/destination". > Following Jann's ex_handler_uaccess() example I could arrange for > copy_mc_to_kernel() to use a new _ASM_EXTABLE_MC() to validate that > the only type of exception meant to be handled is MC and warn > otherwise? That may be a good idea, but won't work for any shared case. IOW, it would be lovely to have a "copy_mc_to_user()" check that if it's a write fault, it's because it's a user address (and if it's a read fault it's because it's a poisoned page or mc or whatever, but a valid kernel address). But it's exactly the kind of thing that we currently don't do even for the bog-standard "copy_to_user()", because we share all the code because we're lazy. And as DavidL pointed out - if you ever have "iomem" as a source or destination, you need yet another case. Not because they can take another kind of fault (although on some platforms you have the machine checks for that too), but because they have *very* different performance profiles (and the ERMS "rep movsb" sucks baby donkeys through a straw). Linus