Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp596790pxu; Thu, 15 Oct 2020 11:29:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwH9k4WPZjbVjPs7GYRJ47rldyKGF8kkYGrlWA9S5Z0ucn/YXmPmWqA0IIH5YH1iQJyxSSk X-Received: by 2002:a05:6402:74f:: with SMTP id p15mr5957448edy.69.1602786553349; Thu, 15 Oct 2020 11:29:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1602786553; cv=none; d=google.com; s=arc-20160816; b=aQdPZwLqkKTbpM6RluiO2rALGmtQyceFsHvxcT7C5GeiOF+6yfPvcEudac4muKr23R fFiW/JPiEggLnoAFI2jyhkrPH77vjCevJmOhMsjJHuqbxRJXyYCe2EfnjN+PAi1rgB9d fvSYLpp3+Kx41BzxOaF8KJrXMuYqAC3dxi5DGEyiIs/1+7xbg7vMxFXRczdWKTT1dEeN q4nsavniiOVyqvREynsuCuIlCs74HeNU5TStYJFUVl9g6iRnG9esrphOM9jjkm9hnFpn c4ASLJ98RE7GUgm3ziogRQ3mRVKb4HHoWysCmKOKYvRkJi024or6V71+MUIqRTJgHHpi w8vA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=LJwfZvZzZbL3U3dsefi4j72Jm0TppMPnsxaVcVl6iT0=; b=YeMSqPKzAx44ACapWn6UIXCJs6IvJ/kjyaWQyN2hGoeEHBVl+FPYrxwo9ek2Asuyr+ 24wwFf3gr6tJuQtYhwyn/9Q3bqfRVwpIB68NxCN0twmcRxicldfv9YXyB0ZBIRpoFhj7 jUwK271KGa2UMhI2FwjyWbyNOY9rm7WIWgc3hR0HlCtzVg40Uh7QrjegRE8S6xPBlQtF gYS1gfr5bHKEFXqwldAQcPu4ptcf3vCTBMEcSIZIorwfn+OhfjTCmsDf0Q4/p2oito+C z9NDtNkt96js+Qv2d7Me/fU+N/Ouz6MsjDLv7xlQrFoiH3F+kAft5tK51mkOvCZ36PT7 GNhA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ffwll.ch header.s=google header.b=jiwyZuJU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r17si3244379eds.37.2020.10.15.11.28.42; Thu, 15 Oct 2020 11:29:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@ffwll.ch header.s=google header.b=jiwyZuJU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389705AbgJOP3S (ORCPT + 99 others); Thu, 15 Oct 2020 11:29:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38318 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388357AbgJOP3R (ORCPT ); Thu, 15 Oct 2020 11:29:17 -0400 Received: from mail-oo1-xc44.google.com (mail-oo1-xc44.google.com [IPv6:2607:f8b0:4864:20::c44]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 83CFEC061755 for ; Thu, 15 Oct 2020 08:29:17 -0700 (PDT) Received: by mail-oo1-xc44.google.com with SMTP id x1so797497ooo.12 for ; Thu, 15 Oct 2020 08:29:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=LJwfZvZzZbL3U3dsefi4j72Jm0TppMPnsxaVcVl6iT0=; b=jiwyZuJU82zqfM3xXQZkNpewO6fCkqA7igabDZ79l9dEml7MlNt9/W6KspOKdTFMBv l0ZZKLNyCyInH/bWkyXoNA3+A+JhbIMgDBR1thG0QOHKB4hsUrxgAlsNauv981ymHMte aG33qVap5atzCP8H/NRFqSDXso79lnD2nYDfc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=LJwfZvZzZbL3U3dsefi4j72Jm0TppMPnsxaVcVl6iT0=; b=tIrqWqygLENficvjysb6vICggn2LgSd9Zz2cF3+WBIDE38rqXtjtmd2QPIM3Z6u21t IOIkiAT65N4PXKz2i4WJx11i7r6e7wjt6wsSpieViAMGc9hsSofp1/0NHY2qO9K6KjXB qA9RU4eCwARiteb+fmi5FO0RVKSRMyTeXplqZ5E9K8tldYFkG72X5aSERMOguevSdmnC 88pZZa1JuKus+up69PSI0Lx1XADLOIZa72F/njCFi+nPqcOMMsB5wQzYeSXuzqtONRMo gTuimUqSWWHEyA5i1bJF5i+Nh58uH7VGpUW0pZVv1BJ66uQ2e6JFbsD+Ey4dSvlBhBZO LmKQ== X-Gm-Message-State: AOAM530XuCz+XC60RPFPuL2t2IzVa0+HhXzZJjDIS6XWgI/7X7QI9N+Z dcOtfdgq2mL8VTUo0AuQcfLCw1CIlVMcCN6iSoxPxg== X-Received: by 2002:a4a:e1d7:: with SMTP id n23mr2788554oot.85.1602775756786; Thu, 15 Oct 2020 08:29:16 -0700 (PDT) MIME-Version: 1.0 References: <20201009075934.3509076-1-daniel.vetter@ffwll.ch> <20201009075934.3509076-15-daniel.vetter@ffwll.ch> <20201009123109.GO5177@ziepe.ca> <20201009143209.GS5177@ziepe.ca> <20201015000939.GD6763@ziepe.ca> In-Reply-To: <20201015000939.GD6763@ziepe.ca> From: Daniel Vetter Date: Thu, 15 Oct 2020 17:29:05 +0200 Message-ID: Subject: Re: [PATCH v2 14/17] resource: Move devmem revoke code to resource framework To: Jason Gunthorpe Cc: Dan Williams , DRI Development , LKML , KVM list , Linux MM , Linux ARM , linux-samsung-soc , "open list:DMA BUFFER SHARING FRAMEWORK" , linux-s390 , Daniel Vetter , Kees Cook , Andrew Morton , John Hubbard , =?UTF-8?B?SsOpcsO0bWUgR2xpc3Nl?= , Jan Kara , Arnd Bergmann , Greg Kroah-Hartman , David Hildenbrand , "Rafael J. Wysocki" Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Oct 15, 2020 at 2:09 AM Jason Gunthorpe wrote: > > On Fri, Oct 09, 2020 at 11:28:54AM -0700, Dan Williams wrote: > > On Fri, Oct 9, 2020 at 7:32 AM Jason Gunthorpe wrote: > > > > > > On Fri, Oct 09, 2020 at 04:24:45PM +0200, Daniel Vetter wrote: > > > > On Fri, Oct 9, 2020 at 2:31 PM Jason Gunthorpe wrote: > > > > > > > > > > On Fri, Oct 09, 2020 at 09:59:31AM +0200, Daniel Vetter wrote: > > > > > > > > > > > +struct address_space *iomem_get_mapping(void) > > > > > > +{ > > > > > > + return iomem_inode->i_mapping; > > > > > > > > > > This should pair an acquire with the release below > > > > > > > > > > > + /* > > > > > > + * Publish /dev/mem initialized. > > > > > > + * Pairs with smp_load_acquire() in revoke_iomem(). > > > > > > + */ > > > > > > + smp_store_release(&iomem_inode, inode); > > > > > > > > > > However, this seems abnormal, initcalls rarely do this kind of stuff > > > > > with global data.. > > > > > > > > > > The kernel crashes if this fs_initcall is raced with > > > > > iomem_get_mapping() due to the unconditional dereference, so I think > > > > > it can be safely switched to a simple assignment. > > > > > > > > Ah yes I checked this all, but forgot to correctly annotate the > > > > iomem_get_mapping access. For reference, see b34e7e298d7a ("/dev/mem: > > > > Add missing memory barriers for devmem_inode"). > > > > > > Oh yikes, so revoke_iomem can run concurrently during early boot, > > > tricky. > > > > It runs early because request_mem_region() can run before fs_initcall. > > Rather than add an unnecessary lock just arrange for the revoke to be > > skipped before the inode is initialized. The expectation is that any > > early resource reservations will block future userspace mapping > > attempts. > > Actually, on this point a simple WRITE_ONCE/READ_ONCE pairing is OK, > Paul once explained that the pointer chase on the READ_ONCE side is > required to be like an acquire - this is why rcu_dereference is just > READ_ONCE Hm so WRITE_ONCE doesn't have any barriers, and we'd need that for updating the pointer. That would leave things rather inconsistent, so I think I'll just leave it as-is for symmetry reasons. None of this code matters for performance anyway, so micro-optimizing barriers seems a bit silly. -Daniel -- Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch