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=-5.1 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,NICE_REPLY_A, 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 CBACCC433E0 for ; Thu, 25 Mar 2021 13:02:56 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 7033E61A17 for ; Thu, 25 Mar 2021 13:02:56 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7033E61A17 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 0EA616B0073; Thu, 25 Mar 2021 09:02:56 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0C2526B0074; Thu, 25 Mar 2021 09:02:56 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EA3F26B0075; Thu, 25 Mar 2021 09:02:55 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id D055A6B0073 for ; Thu, 25 Mar 2021 09:02:55 -0400 (EDT) Received: from smtpin40.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 946381813E4EF for ; Thu, 25 Mar 2021 13:02:55 +0000 (UTC) X-FDA: 77958411510.40.57ED004 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by imf12.hostedemail.com (Postfix) with ESMTP id 1891379D for ; Thu, 25 Mar 2021 13:02:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1616677368; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=FwWZJPBaAmN+VY9ozn1oVCEcu1CBKTJa99Q0BFn4OQI=; b=cGOygGXRS+CClPZ+WJnCEx98dFdpRMQmbSydrbGYRWZzzulIroljQSp5zqVMZ58/BUnzVw 1oWYuFoaNQtkQ0jy/Cwb563sitLjEScI7p89ihFihD5Avo8z33PLj3AVcy6WuW5YTPhiJO k/zBwZo7LwT9zapsriTxXVjMI5ndVio= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-515-t0Ss08QpONaeHfc-Em4w5Q-1; Thu, 25 Mar 2021 09:02:43 -0400 X-MC-Unique: t0Ss08QpONaeHfc-Em4w5Q-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 84AEE801817; Thu, 25 Mar 2021 13:02:40 +0000 (UTC) Received: from [10.36.115.72] (ovpn-115-72.ams2.redhat.com [10.36.115.72]) by smtp.corp.redhat.com (Postfix) with ESMTP id C7EE25D9CA; Thu, 25 Mar 2021 13:02:35 +0000 (UTC) To: Dan Williams , linux-mm@kvack.org, linux-nvdimm@lists.01.org Cc: Ira Weiny , Jason Gunthorpe , Dave Jiang , Vishal Verma , Jan Kara , Christoph Hellwig , "Darrick J. Wong" , Dave Chinner , Matthew Wilcox , Naoya Horiguchi , Shiyang Ruan , Andrew Morton , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org References: <161604048257.1463742.1374527716381197629.stgit@dwillia2-desk3.amr.corp.intel.com> From: David Hildenbrand Organization: Red Hat GmbH Subject: Re: [PATCH 0/3] mm, pmem: Force unmap pmem on surprise remove Message-ID: <22545105-d3f1-23b1-948c-8481af839f21@redhat.com> Date: Thu, 25 Mar 2021 14:02:34 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.0 MIME-Version: 1.0 In-Reply-To: <161604048257.1463742.1374527716381197629.stgit@dwillia2-desk3.amr.corp.intel.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Stat-Signature: 1usq8whcbczs5i7pqq49axk7skcenis5 X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 1891379D Received-SPF: none (redhat.com>: No applicable sender policy available) receiver=imf12; identity=mailfrom; envelope-from=""; helo=us-smtp-delivery-124.mimecast.com; client-ip=216.205.24.124 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1616677367-526752 Content-Transfer-Encoding: quoted-printable 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 18.03.21 05:08, Dan Williams wrote: > Summary: >=20 > A dax_dev can be unbound from its driver at any time. Unbind can not > fail. The driver-core will always trigger ->remove() and the result fro= m > ->remove() is ignored. After ->remove() the driver-core proceeds to tea= r > down context. The filesystem-dax implementation can leave pfns mapped > after ->remove() if it is triggered while the filesystem is mounted. > Security and data-integrity is forfeit if the dax_dev is repurposed for > another security domain (new filesystem or change device modes), or if > the dax_dev is physically replaced. CXL is a hotplug bus that makes > dax_dev physical replace a real world prospect. >=20 > All dax_dev pfns must be unmapped at remove. Detect the "remove while > mounted" case and trigger memory_failure() over the entire dax_dev > range. >=20 > Details: >=20 > The get_user_pages_fast() path expects all synchronization to be handle= d > by the pattern of checking for pte presence, taking a page reference, > and then validating that the pte was stable over that event. The > gup-fast path for devmap / DAX pages additionally attempts to take/hold > a live reference against the hosting pgmap over the page pin. The > rational for the pgmap reference is to synchronize against a dax-device > unbind / ->remove() event, but that is unnecessary if pte invalidation > is guaranteed in the ->remove() path. >=20 > Global dax-device pte invalidation *does* happen when the device is in > raw "device-dax" mode where there is a single shared inode to unmap at > remove, but the filesystem-dax path has a large number of actively > mapped inodes unknown to the driver at ->remove() time. So, that unmap > does not happen today for filesystem-dax. However, as Jason points out, > that unmap / invalidation *needs* to happen not only to cleanup > get_user_pages_fast() semantics, but in a future (see CXL) where dax_de= v > ->remove() is correlated with actual physical removal / replacement the > implications of allowing a physical pfn to be exchanged without tearing > down old mappings are severe (security and data-integrity). >=20 > What is not in this patch set is coordination with the dax_kmem driver > to trigger memory_failure() when the dax_dev is onlined as "System > RAM". The remove_memory() API was built with the assumption that > platform firmware negotiates all removal requests and the OS has a > chance to say "no". This is why dax_kmem today simply leaks > request_region() to burn that physical address space for any other > usage until the next reboot on a manual unbind event if the memory can'= t > be offlined. However a future to make sure that remove_memory() succeed= s > after memory_failure() of the same range seems a better semantic than > permanently burning physical address space. I'd have similar requirements for virtio-mem on forced driver unloading=20 (although less of an issue, because in contrast to cxl, it doesn't=20 really happen in sane environments). However, I'm afraid there are=20 absolutely no guarantees that you can actually offline+rip out memory=20 exposed to the buddy, at least in the general case. I guess it might be possible to some degree if memory was onlined to=20 ZONE_MOVABLE (there are still no guarantees, though), however, bets are=20 completely off with ZONE_NORMAL. Just imagine the memmap of one dax=20 device being allocated from another dax device. You cannot possibly=20 invalidate via memory_failure() and rip out the memory without crashing=20 the whole system afterwards. --=20 Thanks, David / dhildenb