Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp3432687pxx; Mon, 2 Nov 2020 08:45:07 -0800 (PST) X-Google-Smtp-Source: ABdhPJzFl6ECtBBIaiJ8a+HmcwiiHBpuMA2CBX8RR736WN7ukjBc6AJs8mJtGu4o7CnJ4pRiRj0F X-Received: by 2002:a05:6402:b3b:: with SMTP id bo27mr3233124edb.376.1604335507353; Mon, 02 Nov 2020 08:45:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604335507; cv=none; d=google.com; s=arc-20160816; b=TjqOI7seUSWpmjx2p+P9ODPf0bpG+Q/xz1lfp0AWOwpvfgkX2pCic7tyj5Z9sNJzbA T6xhm/mqEer7bQnpxXaFeTWt/FQg/dEKHa74/m3bub2MNj7qV7DKe/AESAXYaa2qlBEC BfrtvyElP3Ik6IUdJTJMVFjUBiBTHMsI5/3YISsPnPKP5KmThayBhZINyxPxA5vkBIhP LayIy7Nj97yGpmbS8ryrgXuS1kS9XjHEEPdJv4l/GROIlV77q/QYsF5UqfL3uHKpkhcl G59BklW7IVwZN/rska/BVI7KP7IsniHPxGZT2FazxjY/cbNWlIDrBZXQv8EDslQEXrNG hX7A== 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=LkcPNNpMLX6kEqUed20/jhdzhJZXy+qPlqOir1Z4UWg=; b=G24PtdpGYtaEmqqnuX3kooQ7yxV0JHxSVhjjE4fcxI+XgG/FPgJOyDP93Z8XYrJJby x+oIji7VjeRg5eJBV085iCmaq+BF6MqHZQ9R9sjBvR89ldrBx21+H8jBd9eDCguj4Yet Raygx3cW/uNonWzL0aDKYTdchslaS9grWXT1HPwn2YNm8Yi0hZZzo9FbZ08Y4kfDNWke RCe/lt2iJc99PlbZ2U5b6fRQJ6tjFRsOQ094xalH293zYHbY6uGtx37lqTaaL4EVjwLD xoersIkCwQs5fVO4Ul/RZUg0sDkMLVVtX+Tly4wU17L5FacZEv0wKRdPzTQSMuYO0BQo xyew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ffwll.ch header.s=google header.b=DejrOT1E; 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 gb9si8802931ejc.725.2020.11.02.08.44.44; Mon, 02 Nov 2020 08:45:07 -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=@ffwll.ch header.s=google header.b=DejrOT1E; 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 S1727345AbgKBQmf (ORCPT + 99 others); Mon, 2 Nov 2020 11:42:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41484 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727334AbgKBQmd (ORCPT ); Mon, 2 Nov 2020 11:42:33 -0500 Received: from mail-ot1-x341.google.com (mail-ot1-x341.google.com [IPv6:2607:f8b0:4864:20::341]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E3646C061A04 for ; Mon, 2 Nov 2020 08:42:32 -0800 (PST) Received: by mail-ot1-x341.google.com with SMTP id z16so8006730otq.6 for ; Mon, 02 Nov 2020 08:42:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=LkcPNNpMLX6kEqUed20/jhdzhJZXy+qPlqOir1Z4UWg=; b=DejrOT1ET977KzMedOZFf/nvESeZd35VW615DHzfUVNv/jtr5S39tQRR1rkXRrNQsS 8e7QakA0NQZajazNYknFTyPn7wzCTD0MaLh6LD79vAKy5J2WjkyqZwU1hUMlTMpcVTcY aRcqJL/19jZSjJmXa+xeFfRoO2oW4s/0IBZV8= 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=LkcPNNpMLX6kEqUed20/jhdzhJZXy+qPlqOir1Z4UWg=; b=LB50Iy3ALgfY0H/MP8IC1/ixodiAAo14lf8FkseEo+ePoIdljh0LXks/rPrd0BOSbs IGSu2bHVAJwGPe56IbYK6sS5vm70VS6tESXAxouQG5j3YFNcShCfBYVqKCDfdT5u0p3X ZiFFhuM1ouPRZtMPC7XkJhIGvi6CAUCbFNpon7WBDQnyNR2WHzChAiMQHDtXVI905jDM 3OOK4A+/wr3UJsqK1WL82hw/dbHVB1Ytfjeih4PTbn81urWlcyZdRi5/oL8wlFz1AhX2 9FB+U2I/NQl/e85AaJD0ZEaIE6fHwLubi+OIc8cdN/XC43yScP/aZcsl6EJqcfFmYfpa naAQ== X-Gm-Message-State: AOAM532Igk7YgYeUKGWwN4CmyRpZ9CxoIWAcoJDSSc+KAS4dVo2JrTce hqeudCssyVYAjoPbE5EY2JsNKokB/lWoza3tCMug0A== X-Received: by 2002:a05:6830:1647:: with SMTP id h7mr13325941otr.281.1604335352341; Mon, 02 Nov 2020 08:42:32 -0800 (PST) MIME-Version: 1.0 References: <20201030100815.2269-1-daniel.vetter@ffwll.ch> <20201030100815.2269-9-daniel.vetter@ffwll.ch> <20201102072931.GA16419@infradead.org> <20201102130115.GC36674@ziepe.ca> <20201102155256.GG36674@ziepe.ca> In-Reply-To: <20201102155256.GG36674@ziepe.ca> From: Daniel Vetter Date: Mon, 2 Nov 2020 17:42:20 +0100 Message-ID: Subject: Re: [PATCH v5 08/15] mm: Add unsafe_follow_pfn To: Jason Gunthorpe Cc: Christoph Hellwig , DRI Development , LKML , KVM list , Linux MM , Linux ARM , linux-samsung-soc , "open list:DMA BUFFER SHARING FRAMEWORK" , Daniel Vetter , Kees Cook , Dan Williams , Andrew Morton , John Hubbard , "J??r??me Glisse" , Jan Kara Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Nov 2, 2020 at 4:52 PM Jason Gunthorpe wrote: > > On Mon, Nov 02, 2020 at 02:23:58PM +0100, Daniel Vetter wrote: > > On Mon, Nov 2, 2020 at 2:01 PM Jason Gunthorpe wrote: > > > > > > On Mon, Nov 02, 2020 at 01:56:10PM +0100, Daniel Vetter wrote: > > > > On Mon, Nov 2, 2020 at 8:29 AM Christoph Hellwig wrote: > > > > > > > > > > On Fri, Oct 30, 2020 at 11:08:08AM +0100, Daniel Vetter wrote: > > > > > > Also mark up follow_pfn as EXPORT_SYMBOL_GPL. The only safe way to use > > > > > > that by drivers/modules is together with an mmu_notifier, and that's > > > > > > all _GPL stuff. > > > > > > > > > > I also think it also needs to be renamed to explicitly break any existing > > > > > users out of tree or int the submission queue. > > > > > > > > Ok I looked at the mmu notifier locking again and noticed that > > > > mm->subscriptions has its own spinlock. Since there usually shouldn't > > > > be a huge pile of these I think it's feasible to check for the mmu > > > > notifier in follow_pfn. And that would stuff this gap for good. I'll > > > > throw that on top as a final patch and see what people think. > > > > > > Probably the simplest is to just check mm_has_notifiers() when in > > > lockdep or something very simple like that > > > > lockdep feels wrong, was locking more at CONFIG_DEBUG_VM. And since > > generally you only have 1 mmu notifier (especially for kvm) I think we > > can also pay the 2nd cacheline miss and actually check the right mmu > > notifier is registered. > > Need to hold the lock to check that and there are two ways to register > notifiers these days, so it feels to expensive to me. Uh I mixed stuff up all along, struct mmu_notifier *subcription that all the mmu notifier users use has the ->mm pointer we want right there. That's good enough I think. Now I'm kinda lost in kvm code trying to wire it through, but it's looking ok-ish thus far :-) -Daniel > CH's 'export symbol only for kvm' really does seem the most robust way > to handle this though. > > Jason -- Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch