From patchwork Wed Oct 21 08:56:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Daniel Vetter X-Patchwork-Id: 11848859 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=-12.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable 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 77FEBC561F8 for ; Wed, 21 Oct 2020 09:22:43 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 0633920770 for ; Wed, 21 Oct 2020 09:22:42 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="AQCML01b"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="e8qFGRPw"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=ffwll.ch header.i=@ffwll.ch header.b="EE/91tuK" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0633920770 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=ffwll.ch Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=OJKCYm1WZNzTtxh0DtjuL7F4Gu8WMVo72+AcSrdcMzE=; b=AQCML01bUWjxL5QZOb9q5YSD/ 0qaqOYc2YDHtrrsjWVu8wm5v2yKGxl0be9cT6YPVTzyoe7f4uqHFh7w6vLhDiJN6/SuNLrPyzb8/m epGy/5IXp6yw24HkNie5tdBRrX17MJti/14Pz/z0aj3q6KAMcNGwZloFODrvld3YEM5LkrlUYjEjw YSNZWQwRmFY+iGWiGmUHwGHbwC7R/tnrSRdSC4tG/mW1TNG+R2XLnWIztDkt0rBxIISglhRwuxPNj pE057Ttn3bNibD8ffNZuaafgVHbJCv/dM7ML5sd9nTkkRp04evd24NjFG6656PGd2wTOyKV8NX58Y 5xxk90TYQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kVAIy-0006NT-BV; Wed, 21 Oct 2020 09:21:12 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kVAIs-0006Es-46 for linux-arm-kernel@merlin.infradead.org; Wed, 21 Oct 2020 09:21:06 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:Content-Type: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-ID:Content-Description; bh=oQvkweh0coyyHFs1+P/kZMwtZJPPWi3HClx7V6v1fv0=; b=e8qFGRPw54iQlbLhybHJZQsjbY 89ysEFWT3oqF57Utir3a/V15uUv8tZPD7VS/CN01+0qO/SY359eJMQmP+OibtJDNs9deE9IMXTtDr nkMFlU9vsZQ03oAFAKW+QQpOm6ee6yBFhE/omfOVrF41PIpcj1a4cZFCnJolW5/TChNCYCMe6QZaS A+o6SUaCbu5iXBJGFihIUtHPQ+HUsrr3QdyR5p3sxwP8R5vDNJMF9AdazS6UrdCPyg8kgXoP8cVXz q/6U2MKj3vqm2PXVGJBHwIXJbKd/Z9SR5FkEwdZzl0itopVkOOGNvkvsI1009o4bBbzC+nGOB6vcK VaC4hBvA==; Received: from mail-wm1-x343.google.com ([2a00:1450:4864:20::343]) by casper.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kV9w1-00014Q-Ma for linux-arm-kernel@lists.infradead.org; Wed, 21 Oct 2020 08:57:39 +0000 Received: by mail-wm1-x343.google.com with SMTP id k18so900535wmj.5 for ; Wed, 21 Oct 2020 01:57:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=oQvkweh0coyyHFs1+P/kZMwtZJPPWi3HClx7V6v1fv0=; b=EE/91tuK+LnQ6Bg/BJZHq1+5OAQo6TOscz5wTlYQlFCOdrCXYSUlrYitteOGw9m+LY STU6xM7NhAXVZvMrs/CddxhZ9Ce+pijIkJL18SFd1amKxNAH30F/FyM/bG8C+7+O+j11 /6ubZyozbslsGF1Lvd8CED3xyzh3w0GshGNLU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=oQvkweh0coyyHFs1+P/kZMwtZJPPWi3HClx7V6v1fv0=; b=klD+R4WOLErldgbcQpSa2Pw2GYnjYOTgNTlnjL3oLZB+FxY801n3b8M241vO42HYnc 3Hmjr1dXgkJ5a0XY/B3+gYvck5Ii+GqiQUUxeSfbB9HJleb94xbwijmVMC1njowQdeeX +jzLq1+hvhHdLEzJdsU8bviYhothVLdw1rE1mtvjAQaSwu/W81Tje1OB2gtFu4t3i2pG Pha4NMpdmHqBeeIDf0hAq8nqXjBRenFKXLlJCeaO6SyJ9+bMHCkPndbx72uyyjJzj6xy CNo3vOEc33Fw9tEt3qVmoOmwzx68iIBQfaBnKoEWYawZpNrQOKpkJEbRG0UUzLK/Iv26 7qkg== X-Gm-Message-State: AOAM531KPn5GbBMYHi4Mzw6QMrl4fNAb2GChqzr3dMDdRhmnJWvlB/89 Ro1o+KOSals8BOo2DApp9d3w+A== X-Google-Smtp-Source: ABdhPJxh5W+195BRlQ75jcVqoxSqHuITL1MkZ8kYhnwY/3GuozWB13g2bfVDwEcl3AUtRbmZy3j2Zw== X-Received: by 2002:a1c:e089:: with SMTP id x131mr2512477wmg.78.1603270644597; Wed, 21 Oct 2020 01:57:24 -0700 (PDT) Received: from phenom.ffwll.local ([2a02:168:57f4:0:efd0:b9e5:5ae6:c2fa]) by smtp.gmail.com with ESMTPSA id q8sm2675939wro.32.2020.10.21.01.57.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Oct 2020 01:57:23 -0700 (PDT) From: Daniel Vetter To: DRI Development , LKML Subject: [PATCH v3 15/16] sysfs: Support zapping of binary attr mmaps Date: Wed, 21 Oct 2020 10:56:54 +0200 Message-Id: <20201021085655.1192025-16-daniel.vetter@ffwll.ch> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201021085655.1192025-1-daniel.vetter@ffwll.ch> References: <20201021085655.1192025-1-daniel.vetter@ffwll.ch> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201021_095732_403663_A10AD123 X-CRM114-Status: GOOD ( 19.12 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jan Kara , kvm@vger.kernel.org, "Rafael J. Wysocki" , Daniel Vetter , linux-mm@kvack.org, Daniel Vetter , Christian Brauner , linux-s390@vger.kernel.org, linux-samsung-soc@vger.kernel.org, Mauro Carvalho Chehab , Michael Ellerman , Nayna Jain , Jason Gunthorpe , Daniel Vetter , linux-pci@vger.kernel.org, linux-media@vger.kernel.org, Kees Cook , John Hubbard , =?utf-8?b?SsOpcsO0bWUgR2xpc3Nl?= , Bjorn Helgaas , Dan Williams , linux-arm-kernel@lists.infradead.org, Greg Kroah-Hartman , Sourabh Jain , Andrew Morton , "David S. Miller" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org We want to be able to revoke pci mmaps so that the same access rules applies as for /dev/kmem. Revoke support for devmem was added in 3234ac664a87 ("/dev/mem: Revoke mappings when a driver claims the region"). The simplest way to achieve this is by having the same filp->f_mapping for all mappings, so that unmap_mapping_range can find them all, no matter through which file they've been created. Since this must be set at open time we need sysfs support for this. Add an optional mapping parameter bin_attr, which is only consulted when there's also an mmap callback, since without mmap support allowing to adjust the ->f_mapping makes no sense. Reviewed-by: Greg Kroah-Hartman Signed-off-by: Daniel Vetter Cc: Jason Gunthorpe Cc: Kees Cook Cc: Dan Williams Cc: Andrew Morton Cc: John Hubbard Cc: Jérôme Glisse Cc: Jan Kara Cc: Dan Williams Cc: linux-mm@kvack.org Cc: linux-arm-kernel@lists.infradead.org Cc: linux-samsung-soc@vger.kernel.org Cc: linux-media@vger.kernel.org Cc: Bjorn Helgaas Cc: linux-pci@vger.kernel.org Cc: Greg Kroah-Hartman Cc: "Rafael J. Wysocki" Cc: Christian Brauner Cc: "David S. Miller" Cc: Michael Ellerman Cc: Sourabh Jain Cc: Daniel Vetter Cc: Mauro Carvalho Chehab Cc: Nayna Jain Signed-off-by: Daniel Vetter --- fs/sysfs/file.c | 11 +++++++++++ include/linux/sysfs.h | 2 ++ 2 files changed, 13 insertions(+) diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c index eb6897ab78e7..9d8ccdb000e3 100644 --- a/fs/sysfs/file.c +++ b/fs/sysfs/file.c @@ -169,6 +169,16 @@ static int sysfs_kf_bin_mmap(struct kernfs_open_file *of, return battr->mmap(of->file, kobj, battr, vma); } +static int sysfs_kf_bin_open(struct kernfs_open_file *of) +{ + struct bin_attribute *battr = of->kn->priv; + + if (battr->mapping) + of->file->f_mapping = battr->mapping; + + return 0; +} + void sysfs_notify(struct kobject *kobj, const char *dir, const char *attr) { struct kernfs_node *kn = kobj->sd, *tmp; @@ -240,6 +250,7 @@ static const struct kernfs_ops sysfs_bin_kfops_mmap = { .read = sysfs_kf_bin_read, .write = sysfs_kf_bin_write, .mmap = sysfs_kf_bin_mmap, + .open = sysfs_kf_bin_open, }; int sysfs_add_file_mode_ns(struct kernfs_node *parent, diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h index 34e84122f635..a17a474d1601 100644 --- a/include/linux/sysfs.h +++ b/include/linux/sysfs.h @@ -164,11 +164,13 @@ __ATTRIBUTE_GROUPS(_name) struct file; struct vm_area_struct; +struct address_space; struct bin_attribute { struct attribute attr; size_t size; void *private; + struct address_space *mapping; ssize_t (*read)(struct file *, struct kobject *, struct bin_attribute *, char *, loff_t, size_t); ssize_t (*write)(struct file *, struct kobject *, struct bin_attribute *,