Received: by 2002:a05:7412:8598:b0:f9:33c2:5753 with SMTP id n24csp129080rdh; Mon, 18 Dec 2023 13:57:52 -0800 (PST) X-Google-Smtp-Source: AGHT+IFIteqU9GE7L1Ew44ZwA/7kpIPR8snPzfEY2sE0QSNv/Oeaw+7H9C+w1nqpJbkdyFROzY/m X-Received: by 2002:a05:6358:7e48:b0:170:f17f:7070 with SMTP id p8-20020a0563587e4800b00170f17f7070mr8622808rwm.33.1702936672221; Mon, 18 Dec 2023 13:57:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702936672; cv=none; d=google.com; s=arc-20160816; b=Nq0ghf9D+Wo5QRWLMNi6+VtNbrvAGqi7Cv5rwWLBLOLLAmzB9mjKE5XbPGSuiffSse bf9EqhloYs/xhcg/Bs/YuiG39zKLLhkkSMkF8A4L8PaESw34WeuhcnfmSRGUozo5NQG8 KNdpOhdBOt4URIxFMsmOpm5nPPFQsj/KHlrATAOAh8Kd2h51/aSU9C5OCWMxpABO8/lo 9b0x9jjS8UCpjeiWPAkCe4oGqhzRkGuTwyXsP5aNGUweG1mGs+Bq9IJwgZ2LR9skf8VZ rhgOgUL04QsvK7lHNR4tIUImEKWua0CVbN//reFGJLFDl3eKr4WhZJRgvlVsrLIw0mDZ ZuwA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :message-id:date:references:in-reply-to:subject:cc:to:from :dkim-signature; bh=uBnfC6yUtSx79uhvcwnyjlwulX+n1O4lQWxq0kxMfiQ=; fh=0Cv6dNOJBWeSwuudzMWg7PCQnESBrc4IEk47xQNcNMQ=; b=05lgcWQmNL5hImboqnPXA8B8wz66WpVnvnFue2jOGhQLgib6lWUdrG3oKrQN+VjBeh 0M9GrM9kfG9deiUk7ENzUTt722ERVr6pm4BLFfwLpNHF4Uw8ciy8uCJbLsm2O/+ugg45 a3qT37fzLx9tCyNvNjI8L4H01WwDPS0ngurSH/5jJ6rkjzT79PoBbhB0rMWZylKYlHGR WPhSm9Chd0okZs1X3f0MdvAn81ncl3a4waVZWhgy6o76LwMYdhBLORQPMZqUt3Abm+LZ uyPwlpgxenhrAW3rEoKpUu1YAoAHaZQ/s7DNuisr3/3YeEOz0TIwL7rWjHsAVMBW1O2g yHCQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=hDsMDIIM; spf=pass (google.com: domain of linux-kernel+bounces-4433-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-4433-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id v6-20020a056a00148600b006d7e1c7b1f9si2052368pfu.316.2023.12.18.13.57.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Dec 2023 13:57:52 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-4433-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=hDsMDIIM; spf=pass (google.com: domain of linux-kernel+bounces-4433-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-4433-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id D6C07284D32 for ; Mon, 18 Dec 2023 21:57:51 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CA9B0740BC; Mon, 18 Dec 2023 21:57:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="hDsMDIIM" X-Original-To: linux-kernel@vger.kernel.org Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.8]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 486891DA3A; Mon, 18 Dec 2023 21:57:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1702936659; x=1734472659; h=from:to:cc:subject:in-reply-to:references:date: message-id:mime-version; bh=UTSFwDQbGfcrEl1amDoPvVacSO4lCY7esjcaPwWu+8s=; b=hDsMDIIMxNDXWso+rRNEhmYd9g1qOqgorTRtIL2GMACS4adIBW0CEA+2 HSlNuKF7kETrZAV96G4Z02dGgVOv40lcbdvDDOIojiuiGCZPadno0Pk3L nYCeC+qzt8r8Sz/pZ7rYi6rLHX5Dfg9DDYQJnW6BaZTbK8PtHb7aE81sB S6d1iTwxT/OjwmMleXyJajNh1OESHGQDF5ze+pLd6yG4hAhyei+7pnF/Y 54Z/v0ZO7E2KKtiEBB9MDYD66ZTw9FHXU57Vh+jyNgRQzUBVYGwBEDBrA 1TELq5RU3wap5D/yDs8ByhalrZaXjfizqn8P1KUdSsdomAzH/JSEXT0gi Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10928"; a="9019283" X-IronPort-AV: E=Sophos;i="6.04,286,1695711600"; d="scan'208";a="9019283" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmvoesa102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Dec 2023 13:57:38 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10928"; a="919408264" X-IronPort-AV: E=Sophos;i="6.04,286,1695711600"; d="scan'208";a="919408264" Received: from jamesgou-mobl1.amr.corp.intel.com (HELO vcostago-mobl3) ([10.213.162.171]) by fmsmga001-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Dec 2023 13:57:34 -0800 From: Vinicius Costa Gomes To: Christian Brauner , Amir Goldstein Cc: hu1.chen@intel.com, miklos@szeredi.hu, malini.bhandaru@intel.com, tim.c.chen@intel.com, mikko.ylinen@intel.com, lizhen.you@intel.com, linux-unionfs@vger.kernel.org, linux-kernel@vger.kernel.org, linux-fsdevel , Linus Torvalds , David Howells , Seth Forshee Subject: Re: [RFC] HACK: overlayfs: Optimize overlay/restore creds In-Reply-To: <20231218-intim-lehrstellen-dbe053d6c3a8@brauner> References: <20231214220222.348101-1-vinicius.gomes@intel.com> <87v88zp76v.fsf@intel.com> <20231218-intim-lehrstellen-dbe053d6c3a8@brauner> Date: Mon, 18 Dec 2023 13:57:31 -0800 Message-ID: <875y0vp41g.fsf@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain Christian Brauner writes: >> > Yes, the important thing is that an object cannot change >> > its non_refcount property during its lifetime - >> >> ... which means that put_creds_ref() should assert that >> there is only a single refcount - the one handed out by >> prepare_creds_ref() before removing non_refcount or >> directly freeing the cred object. >> >> I must say that the semantics of making a non-refcounted copy >> to an object whose lifetime is managed by the caller sounds a lot >> less confusing to me. > > So can't we do an override_creds() variant that is effectively just: > > /* caller guarantees lifetime of @new */ > const struct cred *foo_override_cred(const struct cred *new) > { > const struct cred *old = current->cred; > rcu_assign_pointer(current->cred, new); > return old; > } > > /* caller guarantees lifetime of @old */ > void foo_revert_creds(const struct cred *old) > { > const struct cred *override = current->cred; > rcu_assign_pointer(current->cred, old); > } > > Maybe I really fail to understand this problem or the proposed solution: > the single reference that overlayfs keeps in ovl->creator_cred is tied > to the lifetime of the overlayfs superblock, no? And anyone who needs a > long term cred reference e.g, file->f_cred will take it's own reference > anyway. So it should be safe to just keep that reference alive until > overlayfs is unmounted, no? I'm sure it's something quite obvious why > that doesn't work but I'm just not seeing it currently. My read of the code says that what you are proposing should work. (what I am seeing is that in the "optimized" cases, the only practical effect of override/revert is the rcu_assign_pointer() dance) I guess that the question becomes: Do we want this property (that the 'cred' associated with a subperblock/similar is long lived and the "inner" refcount can be omitted) to be encoded in the constructor? Or do we want it to be "encoded" in a call by call basis? I can see both working. Cheers, -- Vinicius