From patchwork Thu Sep 2 16:09:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 12472029 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=-8.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=ham 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 02307C87FDE for ; Thu, 2 Sep 2021 16:25:58 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 5057161168 for ; Thu, 2 Sep 2021 16:09:30 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 5057161168 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id A48376B006C; Thu, 2 Sep 2021 12:09:29 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9F7996B0071; Thu, 2 Sep 2021 12:09:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8E7216B0072; Thu, 2 Sep 2021 12:09:29 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0042.hostedemail.com [216.40.44.42]) by kanga.kvack.org (Postfix) with ESMTP id 7F33B6B006C for ; Thu, 2 Sep 2021 12:09:29 -0400 (EDT) Received: from smtpin36.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 349C11827D87E for ; Thu, 2 Sep 2021 16:09:29 +0000 (UTC) X-FDA: 78543118458.36.4A3D7D4 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by imf05.hostedemail.com (Postfix) with ESMTP id DB46D5042237 for ; Thu, 2 Sep 2021 16:09:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1630598968; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=mXH2n/UZqZkS6UTydkV0bNVxlvNTafikkYo4yOh5+V8=; b=Nml72N3uu9si1tar15Y9wEbU9FMS5NMEcrXHW5SBSbHxACQXUwbmYd12mKmOp55Tc14CKV d51dORJskFPtpJjz+7vqozWULe5CHrs0dup42RO3LS+wpSUct+qK/5rUSN+HHzkHkTqRBM zpvFMYFJ5rh89FFEz6cl5Q5DaWnjMlw= 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-227-vQyWhdU8OqijUtU0czrTOg-1; Thu, 02 Sep 2021 12:09:25 -0400 X-MC-Unique: vQyWhdU8OqijUtU0czrTOg-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 87C2D835DE0; Thu, 2 Sep 2021 16:09:23 +0000 (UTC) Received: from t480s.redhat.com (unknown [10.39.193.198]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6637360853; Thu, 2 Sep 2021 16:09:20 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: David Hildenbrand , Arnd Bergmann , Greg Kroah-Hartman , "Michael S. Tsirkin" , Jason Wang , "Rafael J. Wysocki" , Andrew Morton , Dan Williams , Hanjun Guo , Andy Shevchenko , virtualization@lists.linux-foundation.org, linux-mm@kvack.org Subject: [PATCH v4 0/3] virtio-mem: disallow mapping virtio-mem memory via /dev/mem Date: Thu, 2 Sep 2021 18:09:16 +0200 Message-Id: <20210902160919.25683-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Nml72N3u; dmarc=pass (policy=none) header.from=redhat.com; spf=none (imf05.hostedemail.com: domain of david@redhat.com has no SPF policy when checking 216.205.24.124) smtp.mailfrom=david@redhat.com X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: DB46D5042237 X-Stat-Signature: ktrdxmi4wxamyryxm19jhm7bs6di5p89 X-HE-Tag: 1630598968-227898 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: I think this might be a good fit for the -mm tree, as the actual virtio-mem changes are rather small. --- Let's add the basic infrastructure to exclude some physical memory regions marked as "IORESOURCE_SYSTEM_RAM" completely from /dev/mem access, even though they are not marked IORESOURCE_BUSY and even though "iomem=relaxed" is set. Resource IORESOURCE_EXCLUSIVE for that purpose instead of adding new flags to express something similar to "soft-busy" or "not busy yet, but already prepared by a driver and not to be mapped by user space". Use it for virtio-mem, to disallow mapping any virtio-mem memory via /dev/mem to user space after the virtio-mem driver was loaded. Details can be found in patch #2 and #3. v3 -> v4: - Added Dans RBs (thanks!) - Actually send the patches to the CC list ... v2 -> v3: - "kernel/resource: clean up and optimize iomem_is_exclusive()" -- Reshuffled and moved for_each_resource() etc. into this patch - "kernel/resource: disallow access to exclusive system RAM regions" -- Leave CONFIG_STRICT_DEVMEM=n alone. Hoog into iomem_is_exclusive() instead. -- Improve comments - "virtio-mem: disallow mapping virtio-mem memory via /dev/mem" -- Don't allow building virtio_mem without CONFIG_STRICT_DEVMEM when we have CONFIG_DEVMEM, where we don't have any guarantees. - Rework all patch descriptions v1 -> v2: - "/dev/mem: disallow access to explicitly excluded system RAM regions" -- Introduce and use for_each_resource() and next_resource_skip_children() -- s/iomem_range_contains_excluded/iomem_range_contains_excluded_devmem/ - "kernel/resource: cleanup and optimize iomem_is_exclusive()" -- Use for_each_resource() Cc: Arnd Bergmann Cc: Greg Kroah-Hartman Cc: "Michael S. Tsirkin" Cc: Jason Wang Cc: "Rafael J. Wysocki" Cc: Andrew Morton Cc: Dan Williams Cc: Hanjun Guo Cc: Andy Shevchenko Cc: virtualization@lists.linux-foundation.org Cc: linux-mm@kvack.org David Hildenbrand (3): kernel/resource: clean up and optimize iomem_is_exclusive() kernel/resource: disallow access to exclusive system RAM regions virtio-mem: disallow mapping virtio-mem memory via /dev/mem drivers/virtio/Kconfig | 1 + drivers/virtio/virtio_mem.c | 4 ++- kernel/resource.c | 54 ++++++++++++++++++++++++++----------- 3 files changed, 43 insertions(+), 16 deletions(-) base-commit: 7d2a07b769330c34b4deabeed939325c77a7ec2f