Received: by 10.223.185.116 with SMTP id b49csp66544wrg; Fri, 2 Mar 2018 13:46:02 -0800 (PST) X-Google-Smtp-Source: AG47ELvZbsLCrLDYNdb59AcCmrc4iu3gcZ3yHNMHQesJiClhC8UHz2PIWKGUkAG7BQhPu7pc3XCV X-Received: by 10.98.214.218 with SMTP id a87mr7024508pfl.146.1520027161979; Fri, 02 Mar 2018 13:46:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520027161; cv=none; d=google.com; s=arc-20160816; b=Bhs0YpKU7NuNkWh3hbYz1g0pNDZbk89ddOuykDXTLiegzwWmrab5sPXzp70k3xTRA1 MB+MUxoZZSKYnQ3bwtlEpbWuLt13NWR/4vw0fV2zO1lguqCRtRY3S81+XrZY5nWBjsSg ee2j5Ck3+gUA7uS0cHF7HEIhw4tj6kUS9mElGYOw1qMmF3dgNnm068nR09tPrjBOeP0d hIsoZy4GaBOdiSkToUatpnkoAoIzTPNBSdYndDQXZwGi0GBzb9C19YwYujvnZsLppX5D Ft8G8o7ZDc0GIq70D9G+KuspSTwx39wkOI0PmX56xcU7kplC6xzpHNoyTPOlFHS+2a4e 02QQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:subject:mime-version:user-agent :message-id:in-reply-to:date:references:cc:to:from :arc-authentication-results; bh=ixvIaynLLdLsV9+ebLYylW8kfBeD3/Qa8Zt/708gS9s=; b=NK0UlWlWyXd728F7BrUnfLSRtByCMkDgRdYeUrr0VbBElBKgPbnpJMVSPEyojHpxJI 583SrMOSt8jh7oavsYaS9L9lFn/VAIQ2xgSrpqAyIPBpA2UD4HnUybBMNGeu3S5sxWtF W4egLD6IptaOBYP69PFFHYi4q+l27oWGRI2lXO43bCMPytjVAMuTVdX78aNKN+HIor3t xElOQtPyZea1svIAxae0oL2yu5sr3jvtV8AZCi4F9Jsz9omXM7/YEsP8NAkyU5TuZO8b VOl2jt3IvPaiYkPLjRgVsZaqrHhx4gKbJAfIAzS9HdQzqdVBPcbIFmQJWJ+jzWwmZnhc xALA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w7si3542737pgp.150.2018.03.02.13.45.39; Fri, 02 Mar 2018 13:46:01 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932417AbeCBTyZ (ORCPT + 99 others); Fri, 2 Mar 2018 14:54:25 -0500 Received: from out01.mta.xmission.com ([166.70.13.231]:38724 "EHLO out01.mta.xmission.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932387AbeCBTyX (ORCPT ); Fri, 2 Mar 2018 14:54:23 -0500 Received: from in02.mta.xmission.com ([166.70.13.52]) by out01.mta.xmission.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.87) (envelope-from ) id 1erql3-0006rN-QM; Fri, 02 Mar 2018 12:54:21 -0700 Received: from 174-19-85-160.omah.qwest.net ([174.19.85.160] helo=x220.xmission.com) by in02.mta.xmission.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.87) (envelope-from ) id 1erql3-0005vv-3M; Fri, 02 Mar 2018 12:54:21 -0700 From: ebiederm@xmission.com (Eric W. Biederman) To: Linus Torvalds Cc: Miklos Szeredi , Linux Kernel Mailing List , Linux Containers , linux-fsdevel , Alban Crequy , Seth Forshee , Sargun Dhillon , Dongsu Park , "Serge E. Hallyn" References: <87po4rz4ui.fsf_-_@xmission.com> <20180226235302.12708-3-ebiederm@xmission.com> <87r2p7rvn5.fsf@xmission.com> <87tvu3qg2b.fsf@xmission.com> Date: Fri, 02 Mar 2018 13:53:45 -0600 In-Reply-To: (Linus Torvalds's message of "Mon, 26 Feb 2018 19:41:21 -0800") Message-ID: <87r2p2b6eu.fsf_-_@xmission.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-XM-SPF: eid=1erql3-0005vv-3M;;;mid=<87r2p2b6eu.fsf_-_@xmission.com>;;;hst=in02.mta.xmission.com;;;ip=174.19.85.160;;;frm=ebiederm@xmission.com;;;spf=neutral X-XM-AID: U2FsdGVkX1/4t4hSeajxuYNMhrp57GHLiqpesI6YFTw= X-SA-Exim-Connect-IP: 174.19.85.160 X-SA-Exim-Mail-From: ebiederm@xmission.com X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on sa04.xmission.com X-Spam-Level: *** X-Spam-Status: No, score=3.1 required=8.0 tests=ALL_TRUSTED,BAYES_50, DCC_CHECK_NEGATIVE,TR_Symld_Words,TVD_RCVD_IP,T_TooManySym_01,XMSlimDrugH, XMSolicitRefs_0,XMSubLong autolearn=disabled version=3.4.1 X-Spam-Report: * -1.0 ALL_TRUSTED Passed through trusted hosts only via SMTP * 1.0 XMSlimDrugH Weight loss drug headers * 1.5 TR_Symld_Words too many words that have symbols inside * 0.7 XMSubLong Long Subject * 0.0 TVD_RCVD_IP Message was received from an IP address * 0.8 BAYES_50 BODY: Bayes spam probability is 40 to 60% * [score: 0.5000] * -0.0 DCC_CHECK_NEGATIVE Not listed in DCC * [sa04 1397; Body=1 Fuz1=1 Fuz2=1] * 0.0 T_TooManySym_01 4+ unique symbols in subject * 0.1 XMSolicitRefs_0 Weightloss drug X-Spam-DCC: XMission; sa04 1397; Body=1 Fuz1=1 Fuz2=1 X-Spam-Combo: ***;Linus Torvalds X-Spam-Relay-Country: X-Spam-Timing: total 353 ms - load_scoreonly_sql: 0.06 (0.0%), signal_user_changed: 2.7 (0.8%), b_tie_ro: 1.83 (0.5%), parse: 0.95 (0.3%), extract_message_metadata: 11 (3.2%), get_uri_detail_list: 2.7 (0.8%), tests_pri_-1000: 6 (1.6%), tests_pri_-950: 1.15 (0.3%), tests_pri_-900: 0.93 (0.3%), tests_pri_-400: 31 (8.8%), check_bayes: 30 (8.5%), b_tokenize: 10 (3.0%), b_tok_get_all: 11 (3.1%), b_comp_prob: 2.5 (0.7%), b_tok_touch_all: 3.0 (0.9%), b_finish: 0.59 (0.2%), tests_pri_0: 290 (82.1%), check_dkim_signature: 0.57 (0.2%), check_dkim_adsp: 2.6 (0.7%), tests_pri_500: 6 (1.8%), rewrite_mail: 0.00 (0.0%) Subject: [RFC][PATCH] fs/posix_acl: Update the comments and support lightweight cache skipping X-Spam-Flag: No X-SA-Exim-Version: 4.2.1 (built Thu, 05 May 2016 13:38:54 -0600) X-SA-Exim-Scanned: Yes (on in02.mta.xmission.com) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The code has been missing a way for a ->get_acl method to not cache a return value without risking invalidating a cached value that was set while get_acl() was returning. Add that support by implementing to_uncachable_acl, to_cachable_acl, is_uncacheable_acl, and dealing with uncachable acls in get_acl(). Update the comments so that they are a little clearer about what is going on in get_acl() Signed-off-by: "Eric W. Biederman" --- Linus my issue with the forget_cached_acl case was really that it was too big of a hammer. If you care about caching acls only somtimes forget_cached_acl called from ->get_acl can stomp that acl you explicitly cached with set_cached_acl. With this change I can unify the legacy horrible fuse posix acl case that requires not caching acls with a single if statement in the get_acl method. AKA: + if (!IS_ERR(acl) && !fc->posix_acl) + acl = to_uncacheable_acl(acl); return acl; That code I know is locally correct even if later fuse decides to cache negative acls when the underlying filesystem does not support xattrs. fs/posix_acl.c | 56 ++++++++++++++++++++++++++++++++++------------- include/linux/posix_acl.h | 17 ++++++++++++++ 2 files changed, 58 insertions(+), 15 deletions(-) diff --git a/fs/posix_acl.c b/fs/posix_acl.c index 2fd0fde16fe1..e58a68e18603 100644 --- a/fs/posix_acl.c +++ b/fs/posix_acl.c @@ -96,12 +96,16 @@ struct posix_acl *get_acl(struct inode *inode, int type) { void *sentinel; struct posix_acl **p; - struct posix_acl *acl; + struct posix_acl *acl, *to_cache; /* * The sentinel is used to detect when another operation like * set_cached_acl() or forget_cached_acl() races with get_acl(). * It is guaranteed that is_uncached_acl(sentinel) is true. + * + * This is sufficient to prevent races between ->set_acl + * calling set_cached_acl (outside of filesystem specific + * locking) and get_acl() caching the returned acl. */ acl = get_cached_acl(inode, type); @@ -126,12 +130,18 @@ struct posix_acl *get_acl(struct inode *inode, int type) /* fall through */ ; /* - * Normally, the ACL returned by ->get_acl will be cached. - * A filesystem can prevent that by calling - * forget_cached_acl(inode, type) in ->get_acl. + * Normally, the ACL returned by ->get_acl() will be cached. + * + * A filesystem can prevent the acl returned by ->get_acl() + * from being cached by wrapping it with to_uncachable_acl(). + * + * A filesystem can at anytime effect the cache directly and + * cause in process calls of get_acl() not to update the cache + * by calling forget_cache_acl(inode, type) or + * set_cached_acl(inode, type, acl). * - * If the filesystem doesn't have a get_acl() function at all, we'll - * just create the negative cache entry. + * If the filesystem doesn't have a ->get_acl() function at + * all, we'll just create the negative cache entry. */ if (!inode->i_op->get_acl) { set_cached_acl(inode, type, NULL); @@ -139,21 +149,37 @@ struct posix_acl *get_acl(struct inode *inode, int type) } acl = inode->i_op->get_acl(inode, type); + + /* To keep the logic simple default to not caching an acl when + * the sentinel is cleared. + */ + to_cache = ACL_NOT_CACHED; if (IS_ERR(acl)) { - /* - * Remove our sentinel so that we don't block future attempts - * to cache the ACL. + /* Clears the sentinel so that we don't block future + * attempts to cache the ACL, and return an error. */ - cmpxchg(p, sentinel, ACL_NOT_CACHED); - return acl; + } + else if (is_uncacheable_acl(acl)) { + /* Clears the sentinel so that we don't block future + * attempts to cache the ACL, and return a valid ACL. + */ + acl = to_cacheable_acl(acl); + } + else { + to_cache = acl; + posix_acl_dup(to_cache); } /* - * Cache the result, but only if our sentinel is still in place. + * Remove the sentinel and replace it with the value that + * needs to be cached, but only if the sentinel is still in + * place. */ - posix_acl_dup(acl); - if (unlikely(cmpxchg(p, sentinel, acl) != sentinel)) - posix_acl_release(acl); + if (unlikely(cmpxchg(p, sentinel, to_cache) != sentinel)) { + if (!is_uncached_acl(to_cache)) + posix_acl_release(to_cache); + } + return acl; } EXPORT_SYMBOL(get_acl); diff --git a/include/linux/posix_acl.h b/include/linux/posix_acl.h index 540595a321a7..3be8929b9f48 100644 --- a/include/linux/posix_acl.h +++ b/include/linux/posix_acl.h @@ -56,6 +56,23 @@ posix_acl_release(struct posix_acl *acl) kfree_rcu(acl, a_rcu); } +/* + * Allow for acls returned from ->get_acl() to not be cached. + */ +static inline bool is_uncacheable_acl(struct posix_acl *acl) +{ + return ((unsigned long)acl) & 1UL; +} + +static inline struct posix_acl *to_uncacheable_acl(struct posix_acl *acl) +{ + return (struct posix_acl *)(((unsigned long)acl) | 1UL); +} + +static inline struct posix_acl *to_cacheable_acl(struct posix_acl *acl) +{ + return (struct posix_acl *)(((unsigned long)acl) & ~1UL); +} /* posix_acl.c */ -- 2.14.1