From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.9 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6AD8BC5517A for ; Thu, 29 Oct 2020 09:23:24 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 60F2720796 for ; Thu, 29 Oct 2020 09:23:23 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=ffwll.ch header.i=@ffwll.ch header.b="CBZ8FpLc" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 60F2720796 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=ffwll.ch Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 8C5156B005C; Thu, 29 Oct 2020 05:23:22 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 84CF16B0062; Thu, 29 Oct 2020 05:23:22 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7131B6B0068; Thu, 29 Oct 2020 05:23:22 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0061.hostedemail.com [216.40.44.61]) by kanga.kvack.org (Postfix) with ESMTP id 3CBD26B005C for ; Thu, 29 Oct 2020 05:23:22 -0400 (EDT) Received: from smtpin10.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id BF376A8FC for ; Thu, 29 Oct 2020 09:23:21 +0000 (UTC) X-FDA: 77424424602.10.trees65_5b021ca2728c Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin10.hostedemail.com (Postfix) with ESMTP id 965CF16A07E for ; Thu, 29 Oct 2020 09:23:21 +0000 (UTC) X-HE-Tag: trees65_5b021ca2728c X-Filterd-Recvd-Size: 5021 Received: from mail-oi1-f193.google.com (mail-oi1-f193.google.com [209.85.167.193]) by imf19.hostedemail.com (Postfix) with ESMTP for ; Thu, 29 Oct 2020 09:23:20 +0000 (UTC) Received: by mail-oi1-f193.google.com with SMTP id f7so2540303oib.4 for ; Thu, 29 Oct 2020 02:23:20 -0700 (PDT) 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=HErX54nBW85Mz/DisB4HfNyGdAeDZ0yXv+UudeIIMTI=; b=CBZ8FpLcj2jbgAT+Vmv1XK/GbFU0hZrgfjfdtoEzh/dEuH+e0mn43Y+dqqjduTTKhF J7T958sHQ5/KYkABUDOFL7LBDzCndG/FofSZCVsgEfa1haI/dp0rDYf3SCs2rGay/PWL uDxd+MKtvtWQZGFZGQv1Mt5IJ+VVaOuC4yqDA= 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=HErX54nBW85Mz/DisB4HfNyGdAeDZ0yXv+UudeIIMTI=; b=IoC8/YO3YbvYZF7v73CQMgt51JqcWbMqscVHr3HH3nOYFNFLgoCLijPgGqaVakj5Gt 4wooUi+NAponkfBau/ISzfP7I3tdUU8vcgyhjMabyKkbUu7xtMOC29r6wI22OvvL+ukt rKfHuVQ2wl9pGwlZm4+T08Dzn1kZHILGtIB1/aVonCUzKzgafYu97rWjPT+vf5zq5GgN RWIuuvrt01nPjcB4276BmGIrdhSj8/f1eSee/zHOHN8jBB8voWRxTEoHrvlTMNR8j8KH p41qGOORDxC/pd5DxxQvAvEj2U0gtrsYeJJs0/kU6kScFIwklnlWUWBcrhVO1Mg2IoV6 ofIw== X-Gm-Message-State: AOAM5333q7eYN8y1dUvf7rdwo3keqaEvVs19q1U2UIks5CnCdFJd5No+ H7gdWlO7N+EVrbBugTQbBfzTo1RRSBcg7C749UQtXg== X-Google-Smtp-Source: ABdhPJwaJb96lRFRXk+hd1pHWMNo5GqlP779ZIojTGckKr1ysWVQINo4W6Rzy8Z9dUSTdKF2aKSvZQbQvjmujgECT7Y= X-Received: by 2002:aca:cc01:: with SMTP id c1mr2268480oig.128.1603963399942; Thu, 29 Oct 2020 02:23:19 -0700 (PDT) MIME-Version: 1.0 References: <20201026105818.2585306-1-daniel.vetter@ffwll.ch> <20201026105818.2585306-9-daniel.vetter@ffwll.ch> <20201029085644.GA25658@infradead.org> In-Reply-To: <20201029085644.GA25658@infradead.org> From: Daniel Vetter Date: Thu, 29 Oct 2020 10:23:09 +0100 Message-ID: Subject: Re: [PATCH v4 08/15] mm: Add unsafe_follow_pfn To: Christoph Hellwig Cc: DRI Development , LKML , KVM list , Linux MM , Linux ARM , linux-samsung-soc , "open list:DMA BUFFER SHARING FRAMEWORK" , linux-s390 , Daniel Vetter , Jason Gunthorpe , Kees Cook , Dan Williams , Andrew Morton , John Hubbard , "J??r??me Glisse" , Jan Kara Content-Type: text/plain; charset="UTF-8" X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Thu, Oct 29, 2020 at 9:56 AM Christoph Hellwig wrote: > > > +int unsafe_follow_pfn(struct vm_area_struct *vma, unsigned long address, > > + unsigned long *pfn) > > The one tab indent here looks weird, normally tis would be two tabs > or aligned aftetthe opening brace. > > > +{ > > +#ifdef CONFIG_STRICT_FOLLOW_PFN > > + pr_info("unsafe follow_pfn usage rejected, see CONFIG_STRICT_FOLLOW_PFN\n"); > > + return -EINVAL; > > +#else > > + WARN_ONCE(1, "unsafe follow_pfn usage\n"); > > + add_taint(TAINT_USER, LOCKDEP_STILL_OK); > > + > > + return follow_pfn(vma, address, pfn); > > +#endif > > Woudn't this be a pretty good use case of "if (IS_ENABLED(...)))"? > > Also I'd expect the inverse polarity of the config option, that is > a USAFE_FOLLOW_PFN option to enable to unsafe behavior. Was just about to send out v5, will apply your suggestions for that using IS_ENABLED. Wrt negative or positive Kconfig, I was following STRICT_DEVMEM symbol as precedence. But easy to invert if there's strong feeling the other way round, I'm not attached to either. > > +/** > > + * unsafe_follow_pfn - look up PFN at a user virtual address > > + * @vma: memory mapping > > + * @address: user virtual address > > + * @pfn: location to store found PFN > > + * > > + * Only IO mappings and raw PFN mappings are allowed. > > + * > > + * Returns zero and the pfn at @pfn on success, -ve otherwise. > > + */ > > +int unsafe_follow_pfn(struct vm_area_struct *vma, unsigned long address, > > + unsigned long *pfn) > > +{ > > + return follow_pfn(vma, address, pfn); > > +} > > +EXPORT_SYMBOL(unsafe_follow_pfn); > > Any reason this doesn't use the warn and disable logic? I figured without an mmu there's not much guarantees anyway. But I guess I can put it in here too for consistency. -Daniel -- Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch