From patchwork Wed Aug 11 20:36:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 12431899 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,URIBL_BLOCKED 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 228B9C4338F for ; Wed, 11 Aug 2021 20:36:30 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id B668660EB9 for ; Wed, 11 Aug 2021 20:36:29 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org B668660EB9 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 3B6528D0002; Wed, 11 Aug 2021 16:36:29 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 33FD38D0001; Wed, 11 Aug 2021 16:36:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 22E908D0002; Wed, 11 Aug 2021 16:36:29 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0137.hostedemail.com [216.40.44.137]) by kanga.kvack.org (Postfix) with ESMTP id 0A7328D0001 for ; Wed, 11 Aug 2021 16:36:29 -0400 (EDT) Received: from smtpin33.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id B324282499A8 for ; Wed, 11 Aug 2021 20:36:28 +0000 (UTC) X-FDA: 78463957656.33.1CE549D Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by imf30.hostedemail.com (Postfix) with ESMTP id 45A92E00737A for ; Wed, 11 Aug 2021 20:36:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1628714187; 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=F6mT/4MmPGt0OpBTI+vB4Ipr2jKicz7mUc5W2HAhCYc=; b=Utm3l/2x4EkZpApWpLiTVd86OIYEhXBg439EpVgCVHiud2gzugIe/Sau7z+mBufnbtV32W Z8BPKweQPNv9jPZ19ylSX66zlrKyVj3asXyKAJob74rIYKQikqI7X8Y4ihwbyud25deu/9 OKf6xjhNRzrNvyXUE8g5/j1AOk3tDak= 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-185-YTGvH1lAPJyBloRRyBVg5Q-1; Wed, 11 Aug 2021 16:36:26 -0400 X-MC-Unique: YTGvH1lAPJyBloRRyBVg5Q-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 B38988799E0; Wed, 11 Aug 2021 20:36:24 +0000 (UTC) Received: from t480s.redhat.com (unknown [10.39.194.112]) by smtp.corp.redhat.com (Postfix) with ESMTP id EB8541B46B; Wed, 11 Aug 2021 20:36:13 +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 v1 0/3] virtio-mem: disallow mapping virtio-mem memory via /dev/mem Date: Wed, 11 Aug 2021 22:36:09 +0200 Message-Id: <20210811203612.138506-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Rspamd-Queue-Id: 45A92E00737A Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="Utm3l/2x"; spf=none (imf30.hostedemail.com: domain of david@redhat.com has no SPF policy when checking 216.205.24.124) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-Rspamd-Server: rspam01 X-Stat-Signature: m6zyswbk8skdt5pt138u6mj6pgrdrshk X-HE-Tag: 1628714188-460338 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: Let's add the basic infrastructure to exclude some physical memory regions completely from /dev/mem access, on any architecture and under any system configuration (independent of CONFIG_STRICT_DEVMEM and independent of "iomem="). 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: there is no sane use case to access the device-managed memory region via /dev/mem once the driver is actively (un)plugging memory within that region and we want to make sure that nobody will accidentially access unplugged memory in a sane environment. Details can be found in patch #1. 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): /dev/mem: disallow access to explicitly excluded system RAM regions virtio-mem: disallow mapping virtio-mem memory via /dev/mem kernel/resource: cleanup and optimize iomem_is_exclusive() drivers/char/mem.c | 22 ++++++------- drivers/virtio/virtio_mem.c | 4 ++- include/linux/ioport.h | 1 + kernel/resource.c | 61 ++++++++++++++++++++++++++++++++----- lib/Kconfig.debug | 4 ++- 5 files changed, 69 insertions(+), 23 deletions(-)