From patchwork Mon Sep 20 14:28:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 12505527 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 E7714C433EF for ; Mon, 20 Sep 2021 14:29:27 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 76825610CE for ; Mon, 20 Sep 2021 14:29:26 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 76825610CE 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 F3FE46B006C; Mon, 20 Sep 2021 10:29:25 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EEED76B0072; Mon, 20 Sep 2021 10:29:25 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DDDFA6B0073; Mon, 20 Sep 2021 10:29:25 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0078.hostedemail.com [216.40.44.78]) by kanga.kvack.org (Postfix) with ESMTP id CC73B6B006C for ; Mon, 20 Sep 2021 10:29:25 -0400 (EDT) Received: from smtpin33.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 7751E235C9 for ; Mon, 20 Sep 2021 14:29:25 +0000 (UTC) X-FDA: 78608184690.33.AF9BCA3 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf05.hostedemail.com (Postfix) with ESMTP id 23C8551B03F6 for ; Mon, 20 Sep 2021 14:29:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1632148164; 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=eKxXCIY3RXYoZJT+3h0svXLPmqhFXlaxuuqqZnTjWlM=; b=dhfPmkqwhXaEa8shNjoY5uxwRnu5hno3qkCoGcneFPTAuvCzI4TtGOtONLsM+yK6oZpPsu a1XlTNVnZJCw6PLZJ6SGY8CJrHGEoI7apboIzLVXFP2wmDT5jy6a8pFqqpK42I/l0eAhwB EWNV3fLzjH2rp6dMTRBnHYbSBaXsRWM= 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-250-Qsnarz32N5KVyUroFOyqHA-1; Mon, 20 Sep 2021 10:29:23 -0400 X-MC-Unique: Qsnarz32N5KVyUroFOyqHA-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 63E348CEA20; Mon, 20 Sep 2021 14:29:21 +0000 (UTC) Received: from t480s.redhat.com (unknown [10.39.194.236]) by smtp.corp.redhat.com (Postfix) with ESMTP id E117B60C17; Mon, 20 Sep 2021 14:28:57 +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 v5 0/3] virtio-mem: disallow mapping virtio-mem memory via /dev/mem Date: Mon, 20 Sep 2021 16:28:53 +0200 Message-Id: <20210920142856.17758-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=dhfPmkqw; spf=none (imf05.hostedemail.com: domain of david@redhat.com has no SPF policy when checking 170.10.133.124) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-Stat-Signature: ojo7bsenwzje5o8yjpgbe5azeo4ekc8r X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 23C8551B03F6 X-HE-Tag: 1632148164-640999 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: @Andrew, can you take this via the -mm tree? --- 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. v4 -> v5: - "kernel/resource: disallow access to exclusive system RAM regions" -- Add CONFIG_EXCLUSIVE_SYSTEM_RAM - "virtio-mem: disallow mapping virtio-mem memory via /dev/mem" -- Use CONFIG_EXCLUSIVE_SYSTEM_RAM -- Add ACK from MST 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 ++++++++++++++++++++++++++----------- mm/Kconfig | 7 +++++ 4 files changed, 50 insertions(+), 16 deletions(-) base-commit: e4e737bb5c170df6135a127739a9e6148ee3da82