Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp3069984rwb; Mon, 19 Sep 2022 14:35:21 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4tGMQz4iXa6fr2u3p0TCmkxHzOJlvPH8fKH7R+q5fgP7snCrejAeEI0HzGH9HZSvGBrA57 X-Received: by 2002:a17:902:d502:b0:177:f287:269d with SMTP id b2-20020a170902d50200b00177f287269dmr1724560plg.140.1663623321682; Mon, 19 Sep 2022 14:35:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663623321; cv=none; d=google.com; s=arc-20160816; b=INdUKClQgvdzvlN/Cm+uANwTrEcA3qiCTr5Zp/ONsjkMYUv0iWli7e7FzL6ioszMoM 8DF4xGg35M/fsxjJ6WByd/uUHdLOmHQ0sgi9mzlOTuU1WMH+2msp+ZFgMsj6Rduf/dSa BcAL2HjvteBq0XqvjPh1fZet9Tz/3iQ8SoXlbhyvfh+b21oOp79sgvvhytAbg8PbSU39 rfURN41KWehBVzY6/H7U15NY4CqQqKQdSuOY1JtB39sTL/M51+2L8/xrFRX/94eZgV6u hy2rCGfwi9ufZiPiW+75dxCUo1WGJ1wIiHGlkqvZ6K8ig6pyqtRzHVHhGJAQHqI/JDDW sOSg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=5HWxnXSMmWeLCVG6N8JCi9SyzO3REhU8kWl1ApWzPSs=; b=Ro3ygJGfu25cCBVkN+dfGpDCoiwdIZjRwbLqRe8PAl42JGN9Bbw9CurcuDiuOjDmXr zI4XTSxwz4aPsocOzUSYSUWqV9IDOGuaoiu5vm5u4Rnc0AH9cTOOrGtGU46es+1ufnyZ +BQ8ccwSrZ61sGik6MUeN9wfruAbaePtjXZVtaneC/xXbEk3yroAOg+XNPeLFPX3eYfy Uz8uziHyJP/Yp73N8Ts6l6DFJ5prfm2MgG6T4PPLr3ykRBdjBBoKDm11yKVGa9Ch307i c7Mx3DHkru6fqViJH9KtWwvk4/TshsBoySbBAmaKlZmWxWBzGYIdoH2NuREuRyBIzX0C Bplg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=korg header.b="xd/jE4qv"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i31-20020a63131f000000b00430ae3ac71csi850331pgl.267.2022.09.19.14.35.09; Mon, 19 Sep 2022 14:35:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=korg header.b="xd/jE4qv"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229657AbiISU52 (ORCPT + 99 others); Mon, 19 Sep 2022 16:57:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56942 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229492AbiISU50 (ORCPT ); Mon, 19 Sep 2022 16:57:26 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B95E94B4BD for ; Mon, 19 Sep 2022 13:57:25 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 56B96B82072 for ; Mon, 19 Sep 2022 20:57:24 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 04EE6C433D6; Mon, 19 Sep 2022 20:57:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1663621043; bh=7IVgxN4jKizV0N/1jpx39bak2NnAK31U23PaJaUNaVo=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=xd/jE4qv5G2GKIlhUjgVOK4TRugup9Kxbo2h62YeeQvxfgVtEYsXEU2eCAvqu33Zb 2GmJIs5ldqc0OWF/SaL7OzkhvdEL4vSZnc9zE3Er4LVeVfSiaQ0zLXI1n4eBlaS/4h l8FCav0SV/ZDiA07kEdpXj+Ehi75h4vBSVY1FfUI= Date: Mon, 19 Sep 2022 13:57:10 -0700 From: Andrew Morton To: Dawei Li Cc: hch@lst.de, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] mm: mmap lock holding assertion on remap_pfn_range Message-Id: <20220919135710.d52984bda33620f42d450010@linux-foundation.org> In-Reply-To: References: X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.33; x86_64-redhat-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-8.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 19 Sep 2022 23:47:32 +0800 Dawei Li wrote: > remap_pfn_range() creates/modifies the mapping between user virtual > address and physical address, the caller of which must hold mmap > writer lock to achieve access consistency of mapping. > > The callers fall into categories below: > 1) fops->mmap() implemented by driver > For this case, mmap_lock has been taken externally, the rule holds true. > > 2) Some arch codes do mapping on their own(vdso e.g.), rather than via > fops->mmap(). > > 3) Some driver codes do mapping into user address space, for some > reasons, the mapping is not implemented by fops->mmap(). > > For the last two cases, an explicit assertion must be made. Why "must" it be made? Are callers known to get this wrong? > --- a/mm/memory.c > +++ b/mm/memory.c > @@ -2551,6 +2551,11 @@ int remap_pfn_range(struct vm_area_struct *vma, unsigned long addr, > { > int err; > > + if (!vma->vm_mm) > + return -EINVAL; Can this happen? If so, under what circumstances? > + mmap_assert_write_locked(vma->vm_mm); > + > err = track_pfn_remap(vma, &prot, pfn, addr, PAGE_ALIGN(size)); > if (err) > return -EINVAL; > -- > 2.25.1