Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp281132pxx; Thu, 29 Oct 2020 02:25:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxPqZF7AAszr0qcRBo8iBtwB4x+o5kg6s+hR67uOztwcOF7u7DjthFU7ndE98h7zRzh7OvG X-Received: by 2002:aa7:d1d5:: with SMTP id g21mr2887394edp.388.1603963510808; Thu, 29 Oct 2020 02:25:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603963510; cv=none; d=google.com; s=arc-20160816; b=QrXRPQv+Ey4iZhBHSdxxY7wMUWPtLxffbRQSlUep67ok6boXTEYIhI7L57sPDMoAfy NJHdQS+nn1CgvWY1bIoRo+tT/sdKsaCByKz4V7BX0uk4HgniG1/WLbuhAc7tFJybItFV FQHSADiBzedGLRlRhzurwr+4uJtAViMxi06a2OUGAZ08ELwYIpdnlwUp5TLnEQ0QFkpn zZSg34mCdmRvTa8HfM8r8qRyTfUoeqFCgnErNXNpGNZSkQkaINq888Oo0g7F3J4ysWvT eo88eDGrGcc58Agk+fOqNeYlYqT9MjmMLolYv5ddUJIoSK45b+0I91YHrOic+OJ2POzb BQuw== 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=HErX54nBW85Mz/DisB4HfNyGdAeDZ0yXv+UudeIIMTI=; b=pQAx2W/ZwDoYJFmhRggJtOOQHr2NF5LbztMjtlsv6AFxtz4T6A87KAeJaJgZsojg9f pg09V9RuzI0gIqnKPPqYI2Fd0D26w6IPWIf+JDfCvvOpa5oUrBCtSDIj0rEZiDbtjSnF oFpFTRMuMYMyWHas1kMv7PX6pQ/QmOQD9YEguVa921y5NahLesj4rg5Dm2xh8uRI5PcX 4liORIw9baOFeC5HURrMAz2yyiZdKMnOqCem+hOPmWMrhnn/YMxCGqP8DpV15N32pkaQ dDaCbcx9yx3M37daUD+V9966+sLEgybHiuFR+mD2n+Zvdbd2f9v6IzHJxEcXJrofWL/W rGZw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ffwll.ch header.s=google header.b=CBZ8FpLc; 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 y22si1655299edi.469.2020.10.29.02.24.47; Thu, 29 Oct 2020 02:25:10 -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=@ffwll.ch header.s=google header.b=CBZ8FpLc; 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 S1726396AbgJ2JXW (ORCPT + 99 others); Thu, 29 Oct 2020 05:23:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45682 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725838AbgJ2JXW (ORCPT ); Thu, 29 Oct 2020 05:23:22 -0400 Received: from mail-oi1-x242.google.com (mail-oi1-x242.google.com [IPv6:2607:f8b0:4864:20::242]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 77897C0613CF for ; Thu, 29 Oct 2020 02:23:20 -0700 (PDT) Received: by mail-oi1-x242.google.com with SMTP id z23so2554139oic.1 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=Ec57sICx5KuBBJrOpjW8KPtLWi2JZvC9pi985Ylvzw2ceFSBgRREbwuPDC28Cz6Pzf E4SpT/BjkP9lyoLX5Mn8IMvI1bEqPiyBPAoQy/edOCDTZX9OPikJvWxR2/Lcyu0EPcOx sqJyQOdno1yQOTXLFlFFdGMVvYVY1qf9RJPMMA1NM0RLezv2w6PfHOFSnb9NRRMCfz11 PV4D7eW5i/xUb9LUaRx6JinZXtwW0R2T6Sio18HUqdFnfHhtOrkONHoIagKDSCgodTlI 5Hjip/jdYfgz+HoOaZM0VRpONoTcKiApU0VAPn0/FpmYtvvCHWKVcRluzk1XNja8wRr6 3x6g== X-Gm-Message-State: AOAM532Ldzy2Gw9MUNfRHQV2N4Di0X34Aa8bcrtWqtSdTPimJkBoPerl Gt7glhd68wAbTiny698VlXsx4O107WK1O+fng9oo3w== 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" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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