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=-2.4 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,USER_AGENT_SANE_1 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 BABDBC4332B for ; Sat, 21 Mar 2020 12:38:07 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 6DF4320754 for ; Sat, 21 Mar 2020 12:38:07 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=ziepe.ca header.i=@ziepe.ca header.b="YDGwjbkA" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6DF4320754 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=ziepe.ca Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 17F1C6B0003; Sat, 21 Mar 2020 08:38:07 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 109556B0005; Sat, 21 Mar 2020 08:38:07 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F12AE6B0007; Sat, 21 Mar 2020 08:38:06 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0020.hostedemail.com [216.40.44.20]) by kanga.kvack.org (Postfix) with ESMTP id D69AD6B0003 for ; Sat, 21 Mar 2020 08:38:06 -0400 (EDT) Received: from smtpin01.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id BA207181AEF09 for ; Sat, 21 Mar 2020 12:38:06 +0000 (UTC) X-FDA: 76619321772.01.idea16_29acd0e145655 X-HE-Tag: idea16_29acd0e145655 X-Filterd-Recvd-Size: 4973 Received: from mail-qt1-f193.google.com (mail-qt1-f193.google.com [209.85.160.193]) by imf11.hostedemail.com (Postfix) with ESMTP for ; Sat, 21 Mar 2020 12:38:06 +0000 (UTC) Received: by mail-qt1-f193.google.com with SMTP id z8so7489556qto.12 for ; Sat, 21 Mar 2020 05:38:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ziepe.ca; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=g+X9axIFKiWeeLdgLNKPr3c4V/oqgekJuwFhbkyQ++0=; b=YDGwjbkAmGbRPiuztvMLIJR+RwawI4R9lJXPH7QbDer2L1eqjxZOfSzYRCCj4dQ5h8 LNYL0Qb6QIV4gt87dOC0YK5+NDHpJGtkgCpJBFSFWnHUJCpL6bA/zH6X2PbD4oba5F9X 4lF2ePGxbLhqL7Avh2Kbh5MuaD//GpzLoKkm1KR91LzlOKe5zf8jp3fXJVkuXqFT0LLH i/29ilqiHUkbjkkIoZmdWorukI0/POVB5ozTft4Y6Cw9/PlM+vmj2AY/0dCrZCVNzgv4 H8QgXPaP1swxfNMMnqoy+V3apr+4E00PTyGnIvPuh+MDi0XALGpCfRy6FNa8JnL1/fVU GasQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=g+X9axIFKiWeeLdgLNKPr3c4V/oqgekJuwFhbkyQ++0=; b=ZUbkc0dL3mi/ss+sy8/teFaQwQ+6q2lW+VMCE4WZLI8FWI/4DhU/6soK6w3pu4ZWBS TGcypJ/sxzBGikDK6WNYfbalGVjqQt+OHAGZr7DBp3C5wRoD8RN3Pvw07faRGgQMrzzI fnaa3CZDzfU5FcNMv2fV25EmKMiC8Rt0k8jMMWFxcZ892glLpFkhVRAbGCz8P3XtL8NQ fpsJ9nKpWakvOyr7iWihsjDGi8CIdsc9WEqQTapms/I+bNa40tilyxp4XVjc0P1Q9QeD MDPmelznsXG/ntSonIg2XQBl66bj1FHfgVjHk+XS2F1GcOO3brXAjYYuqFDdD6nx7IPZ vwEA== X-Gm-Message-State: ANhLgQ1xAAbOpgASaw1WZFl+FyURWw2bVRP/ICzadq4kA9F75KB5v/hk RdNZU20DvCO+llnE8CF6tTEnpA== X-Google-Smtp-Source: ADFU+vszEC65qtGCdETefXI+dh5dGaMDFaODrGKKrJmVGUsFuszKPiaO8AXtfztZJoZUFwabBOS2GA== X-Received: by 2002:ac8:b8d:: with SMTP id h13mr13019242qti.298.1584794285323; Sat, 21 Mar 2020 05:38:05 -0700 (PDT) Received: from ziepe.ca (hlfxns017vw-142-68-57-212.dhcp-dynamic.fibreop.ns.bellaliant.net. [142.68.57.212]) by smtp.gmail.com with ESMTPSA id u40sm7435378qtc.62.2020.03.21.05.38.04 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 21 Mar 2020 05:38:04 -0700 (PDT) Received: from jgg by mlx.ziepe.ca with local (Exim 4.90_1) (envelope-from ) id 1jFdO8-0008OQ-7G; Sat, 21 Mar 2020 09:38:04 -0300 Date: Sat, 21 Mar 2020 09:38:04 -0300 From: Jason Gunthorpe To: Christoph Hellwig Cc: Dan Williams , Bharata B Rao , Christian =?utf-8?B?S8O2bmln?= , Ben Skeggs , Jerome Glisse , kvm-ppc@vger.kernel.org, amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, nouveau@lists.freedesktop.org, linux-mm@kvack.org Subject: Re: [PATCH 4/4] mm: check the device private page owner in hmm_range_fault Message-ID: <20200321123804.GV20941@ziepe.ca> References: <20200316193216.920734-1-hch@lst.de> <20200316193216.920734-5-hch@lst.de> <20200320134109.GA30230@ziepe.ca> <20200321082236.GB28613@lst.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200321082236.GB28613@lst.de> User-Agent: Mutt/1.9.4 (2018-02-28) 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 Sat, Mar 21, 2020 at 09:22:36AM +0100, Christoph Hellwig wrote: > On Fri, Mar 20, 2020 at 10:41:09AM -0300, Jason Gunthorpe wrote: > > Thinking about this some more, does the locking work out here? > > > > hmm_range_fault() runs with mmap_sem in read, and does not lock any of > > the page table levels. > > > > So it relies on accessing stale pte data being safe, and here we > > introduce for the first time a page pointer dereference and a pgmap > > dereference without any locking/refcounting. > > > > The get_dev_pagemap() worked on the PFN and obtained a refcount, so it > > created safety. > > > > Is there some tricky reason this is safe, eg a DEVICE_PRIVATE page > > cannot be removed from the vma without holding mmap_sem in write or > > something? > > I don't think there is any specific protection. Let me see if we > can throw in a get_dev_pagemap here The page tables are RCU protected right? could we do something like if (is_device_private_entry()) { rcu_read_lock() if (READ_ONCE(*ptep) != pte) return -EBUSY; hmm_is_device_private_entry() rcu_read_unlock() } ? Then pgmap needs a synchronize_rcu before the struct page's are destroyed (possibly gup_fast already requires this?) I've got some other patches trying to close some of these styles of bugs, but > note that current mainline doesn't even use it for this path.. Don't follow? Jason