Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp941000pxp; Wed, 9 Mar 2022 16:32:01 -0800 (PST) X-Google-Smtp-Source: ABdhPJzLgHvM0tCy6UmZU0KNGlbj/w4jc3KXEnep+9kqQFFZIGc1SHQOoKZFUT0wYFrr6v6qxPYF X-Received: by 2002:aa7:cd53:0:b0:415:f5db:5d53 with SMTP id v19-20020aa7cd53000000b00415f5db5d53mr1851202edw.399.1646872321285; Wed, 09 Mar 2022 16:32:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646872321; cv=none; d=google.com; s=arc-20160816; b=tkfFW01+sFDd18SY6VXSpBezKfl6k+iikJ8BVHvTB2xFAxOCasCbxCmbR3JAGq4JQk 1398Mh8yPfHIXNShlDdctM704O+mnzxAvBX8P1f5FY16WoIigyGar9oSXUHRIxCWOqlA pk4kE78yIcAhxztDJD8EqVdpxniRstotNVppWo2ok3RcPv86YKcvr6Zfa2ZvT5JY7Q7D BO/J0QASd92pnNHZewh0oxXeVaHdvvTJZTJeE9ucrSxZea/wP6qLlENDBvkMWmzg8WV2 psZysCkXwZGJC47qNBYiB5EmKHbDXkzIV2VoxtMWwCtonRma7b+b8c0udavrJFEfhfSp qLug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:subject:mime-version:user-agent:message-id :in-reply-to:date:references:cc:to:from; bh=AvMkizAsKn61k9TmdhNIfVQDTd9ejkN16JaFig182Ns=; b=R0CiJEdnbIzXWunQiq5VC1Ok1dqa29BEHfy7ouVb00X8Som5ueFhw/7gr5eagVObCI emRreFtp6/O2k0xmjbtTXXJwcNrtNBL4N9hN9zXUsupBXlUos+ecNHGpmaZphKDqQxbr qRARopbNYci69Fwxt9fh/iig5c0RJRWNeneCpqHWnvW+lZ59Tsryi73ZAJH1GGQ2Bsjm WTMZhCZm1X4nf5Oy7jQkovKccW4vU23QVD4Uq12WL64zF+5RG3Cmf8uOSKdBHDDu7Vr2 3mIvMeEvQKmHfAkiNE8hlNfNwpEmi5FzrxQJ9+x/gOiGcNrNSUoec+b//9w0i6pKz74G kYmQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=xmission.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f19-20020a056402151300b00410be23764asi2025175edw.106.2022.03.09.16.31.39; Wed, 09 Mar 2022 16:32:01 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=xmission.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238721AbiCIX0E (ORCPT + 99 others); Wed, 9 Mar 2022 18:26:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37774 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238086AbiCIX0D (ORCPT ); Wed, 9 Mar 2022 18:26:03 -0500 Received: from out02.mta.xmission.com (out02.mta.xmission.com [166.70.13.232]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 09BA9B16C6 for ; Wed, 9 Mar 2022 15:25:04 -0800 (PST) Received: from in02.mta.xmission.com ([166.70.13.52]:58064) by out02.mta.xmission.com with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1nS5fy-00DLZt-FH; Wed, 09 Mar 2022 16:25:02 -0700 Received: from ip68-227-174-4.om.om.cox.net ([68.227.174.4]:34678 helo=email.froward.int.ebiederm.org.xmission.com) by in02.mta.xmission.com with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1nS5fw-007XsN-TV; Wed, 09 Mar 2022 16:25:01 -0700 From: "Eric W. Biederman" To: Jens Axboe Cc: linux-kernel@vger.kernel.org, Linus Torvalds , Alexey Gladkov , Kyle Huey , Oleg Nesterov , Kees Cook , Al Viro References: <87o82gdlu9.fsf_-_@email.froward.int.ebiederm.org> <20220309162454.123006-7-ebiederm@xmission.com> <01459886-2393-665a-43b1-70082ceace0c@kernel.dk> Date: Wed, 09 Mar 2022 17:24:37 -0600 In-Reply-To: <01459886-2393-665a-43b1-70082ceace0c@kernel.dk> (Jens Axboe's message of "Wed, 9 Mar 2022 14:05:50 -0700") Message-ID: <87cziubtfu.fsf@email.froward.int.ebiederm.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-XM-SPF: eid=1nS5fw-007XsN-TV;;;mid=<87cziubtfu.fsf@email.froward.int.ebiederm.org>;;;hst=in02.mta.xmission.com;;;ip=68.227.174.4;;;frm=ebiederm@xmission.com;;;spf=neutral X-XM-AID: U2FsdGVkX1904JK8obr4VAxpJhTYq0MRWEXfEX6zYh4= X-SA-Exim-Connect-IP: 68.227.174.4 X-SA-Exim-Mail-From: ebiederm@xmission.com X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Virus: No X-Spam-DCC: XMission; sa02 1397; Body=1 Fuz1=1 Fuz2=1 X-Spam-Combo: *;Jens Axboe X-Spam-Relay-Country: X-Spam-Timing: total 398 ms - load_scoreonly_sql: 0.03 (0.0%), signal_user_changed: 3.9 (1.0%), b_tie_ro: 2.8 (0.7%), parse: 1.01 (0.3%), extract_message_metadata: 12 (3.0%), get_uri_detail_list: 1.37 (0.3%), tests_pri_-1000: 16 (4.0%), tests_pri_-950: 1.46 (0.4%), tests_pri_-900: 1.16 (0.3%), tests_pri_-90: 136 (34.2%), check_bayes: 134 (33.7%), b_tokenize: 5 (1.3%), b_tok_get_all: 6 (1.5%), b_comp_prob: 2.1 (0.5%), b_tok_touch_all: 118 (29.6%), b_finish: 0.82 (0.2%), tests_pri_0: 214 (53.8%), check_dkim_signature: 0.55 (0.1%), check_dkim_adsp: 1.92 (0.5%), poll_dns_idle: 0.21 (0.1%), tests_pri_10: 1.84 (0.5%), tests_pri_500: 7 (1.7%), rewrite_mail: 0.00 (0.0%) Subject: Re: [PATCH 07/13] task_work: Introduce task_work_pending X-SA-Exim-Version: 4.2.1 (built Sat, 08 Feb 2020 21:53:50 +0000) X-SA-Exim-Scanned: Yes (on in02.mta.xmission.com) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Jens Axboe writes: > On 3/9/22 9:24 AM, Eric W. Biederman wrote: >> diff --git a/include/linux/task_work.h b/include/linux/task_work.h >> index 5b8a93f288bb..897494b597ba 100644 >> --- a/include/linux/task_work.h >> +++ b/include/linux/task_work.h >> @@ -19,6 +19,11 @@ enum task_work_notify_mode { >> TWA_SIGNAL, >> }; >> >> +static inline bool task_work_pending(struct task_struct *task) >> +{ >> + return READ_ONCE(task->task_works); >> +} >> + > > Most of the checks for this is current, do we need READ_ONCE here? There is a non-current use in fs/io_uring in __io_uring_show_fdinfo and another in task_work_cancel_match. Beyond that there are quite a few writes that are not at all from current so even on current task->task_works can change if you look twice. So if only to keep it from making unwarranted assumptions I think READ_ONCE makes sense. Given that READ_ONCE is practically free I don't see where there is any harm in using it to document the kind of code we expect the compiler to generate. Looking a second time I see all of the other reads of task->task_works are already READ_ONCE in kernel/task_work.c, so really I think if we don't want READ_ONCE we need a big fat comment about why it is safe in a check like task_work_pending and while it is needed everywhere else. At the moment I am not smart enough to write that comment. I will see about adding this bit of discussion in the commit comment to make it a little clearer why I am introducing READ_ONCE. Eric