From patchwork Fri Oct 20 14:43:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rong Tao X-Patchwork-Id: 156159 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp1106016vqb; Fri, 20 Oct 2023 07:44:02 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHNCQ2+4j+EyZFo4i4kThbdr1k1YZOKyMgT+KyCS+kXEabjZLKyk57kQvod4Le3wpp+2Coo X-Received: by 2002:a05:6358:7209:b0:166:e6da:5441 with SMTP id h9-20020a056358720900b00166e6da5441mr2070812rwa.6.1697813041818; Fri, 20 Oct 2023 07:44:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697813041; cv=none; d=google.com; s=arc-20160816; b=HVLC+gCmcYp3LufTL4X44XZJw4DwxiVacZvJKu09UlvJptan5B1nuDbY3Vq/2eaylE srgkzIKqoJJy0XHRRsrnfEGaKsMx1tcP+4w4d7ZYzi2w80zqUJracqpdkK73b2ilK1bj mSrvQy0uY37FXrjOEtinVkKpAb6eWJzYVcvmuknBXa26HfJld/S6iPNWwbd2/vD0k/4k RmlX+3sT4D+ilBu0vaxdmJU93BJUR3Kx4aO4CZC2gxT/7oh0cgXNoNJ4qFZYGhEaZiwv AT9MBvmKaPyC1Z34F8/7++yAowa/TgrTGWLEkmOUARTk+cgfA1m6fZuWT+CGpVtac5b6 yw9w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:date:subject:to:from:message-id :dkim-signature; bh=K83F6SskCJLMqeCBk7w6O0CFlOxHTQk9Oh1VXwnu6bQ=; fh=PGaP26rljTYcjLituiXWjvRiYsB22YGWGH+YkC/057Y=; b=KWuqMtU9artoZqGUCz+7cR/9WfnWDIf3t+5a/i8tZckeDeWb//psT+yzVI8PSky5lW kIYvTfwylYYmnrb994HhmS0Tpp0vGNV3yYi5VqHOYLSe3GU0W/Baun/q9d0XxLGxLJYJ MQ5F2+plgPOK56vfEXoDY/WRmdZA05GFMA7ysrrEXtbRK3FviOtIyqrQe0SRi4KRtyNL LPsjxUyBv5JWAXhOe2ZjiZ4LPS15yke/dJU17gBM2NaPJrP1zn2wz+nzibw00lAIjYdT 0Zvi+gxRMaC8sK9RtLO32xbGXyM/EMgIdkm13eWqKVYdo7jCNU4/jL9v5Xe09ksshv1P NhAg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@foxmail.com header.s=s201512 header.b=ZUHL2clx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=foxmail.com Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id s194-20020a632ccb000000b005b86140eabfsi1949996pgs.186.2023.10.20.07.44.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Oct 2023 07:44:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@foxmail.com header.s=s201512 header.b=ZUHL2clx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=foxmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 68F798369F5B; Fri, 20 Oct 2023 07:43:59 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377537AbjJTOns (ORCPT + 26 others); Fri, 20 Oct 2023 10:43:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36746 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377429AbjJTOnr (ORCPT ); Fri, 20 Oct 2023 10:43:47 -0400 X-Greylist: delayed 138733 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Fri, 20 Oct 2023 07:43:43 PDT Received: from out203-205-251-53.mail.qq.com (out203-205-251-53.mail.qq.com [203.205.251.53]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D0187106 for ; Fri, 20 Oct 2023 07:43:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foxmail.com; s=s201512; t=1697813021; bh=K83F6SskCJLMqeCBk7w6O0CFlOxHTQk9Oh1VXwnu6bQ=; h=From:To:Subject:Date:In-Reply-To:References; b=ZUHL2clxRG+MPwnLwAlGNm+vCWDYPoYi4XesKmvDoPxKz54FcJMi+v6U9eIKLxNSx RLkYZUY0okAmgsMYSgb+F9G0id4C7Bc8p93LblAEicfiM18hDd2ZhRQK5hLvFCc+NV k4WuQmFX8eph8hbb6wSQ2bnnprVu24cDfHKRFKbo= Received: from rtoax.lan ([120.245.114.36]) by newxmesmtplogicsvrszb6-0.qq.com (NewEsmtp) with SMTP id AE3AEEEC; Fri, 20 Oct 2023 22:43:35 +0800 X-QQ-mid: xmsmtpt1697813017tr3admgz9 Message-ID: X-QQ-XMAILINFO: MmpliBmRb3iCu0TFj/+Ks7ktWUvfayv2uurkgvqnyHovMHS0AUi4113gtu1fIz odH7cfi7qgLWd9vSrZh4Xyvw3YXJrb+zou0eOojNscTk6JxHjBDllg070sKwdX0AcrOg+Lu/vF8j 1bx60T6nDJvETAde7g/zs7V9dcDelygJZQwIIu+eXb1Z0KDHUbh4f8avtWiGp3ZIChMU+dyCMzP0 M47McCn4SQURXb+xPDUqkusXnqGx/K9sO5Jq9bVJjv+ppiKia5yMrHGVF2PjZvnJZwjI7052a+Gn PQU94362WzsBO7geGKIlD4tS8eNtjjDV5ZfR8vlofuIGR+b0/kIBaW4T9aCE5Z1OE90IlxmIBOMD L5Z9aylWK9GY1+YNrsVHIoxQIhYXdXCnvSsxevnEh+9vanX1QwVpgbeQREo+ph8toilGhQQBlpB7 Sxm9GVZvC3PXRJRF/ISCG/8dAcrxvMKyBdD3H8dZcQkL0Rrgt6I89sMcBeMJo1NvngZaVEYkUGjf 2sluDofD8ibXe6IRv82F4JAyxh5MBdbjncy3wnltrEWGB/XfsrLe4qg22vqHU7UVYds46nsMqB8w HS8Zt7SzQC1QPFcZJ8cLxC05kW8in7VQZK+wofBsm82mEftCM8IFYgFVt4epzfHLJKyaRDntFgkY 1I8b3730I5aaXdKomPdOW/EAFZHDzGIJoNYqBrWuIncD9PVYbfEjZsBpeRRfksfzeGjt/jVcbRVn k72To2fWg6EHQkshHPBJAQ/vSVzaB7Yd7YoxPGFz8Pxql6X2HqFccMGI6XItw3HVsLdmTJxpApY5 M8tpiqXnBXM/PMZWUUEibiWaSYmVOdRU5Y7a+C+wP29r4NUP4zkiSOOMCe8mgHNb5oXx2g2LPO+/ TfrL2Rb0+y3cxAlhUnBFV2BcVYHTLY8HKoI9S/XBS0zX8Lrx13IXVcdznk/5tVMEwvRwizEldvjw cdzJdk2MhK7Tpzh1TXzOV5CHMMyia4SJZh6LQIXTgDGh7KOf6uYYUzO8YRBT5UVpbUUCwVKFyYS2 GDMRAkJw== X-QQ-XMRINFO: OWPUhxQsoeAVDbp3OJHYyFg= From: Rong Tao To: mark.rutland@arm.com, elver@google.com, linux-kernel@vger.kernel.org, peterz@infradead.org, rongtao@cestc.cn, rtoax@foxmail.com, tglx@linutronix.de Subject: [PATCH 1/2] stop_machine: Use non-atomic read multi_stop_data::state clearly Date: Fri, 20 Oct 2023 22:43:33 +0800 X-OQ-MSGID: X-Mailer: git-send-email 2.41.0 In-Reply-To: References: MIME-Version: 1.0 X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Fri, 20 Oct 2023 07:43:59 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780286008166385158 X-GMAIL-MSGID: 1780286008166385158 From: Rong Tao commit b1fc58333575 ("stop_machine: Avoid potential race behaviour") solved the race behaviour problem, to better show that race behaviour does not exist, pass the 'curstate' directly to ack_state() instead of refetching msdata->state in ack_state(). Signed-off-by: Rong Tao Acked-by: Mark Rutland --- kernel/stop_machine.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/kernel/stop_machine.c b/kernel/stop_machine.c index cedb17ba158a..268c2e581698 100644 --- a/kernel/stop_machine.c +++ b/kernel/stop_machine.c @@ -188,10 +188,11 @@ static void set_state(struct multi_stop_data *msdata, } /* Last one to ack a state moves to the next state. */ -static void ack_state(struct multi_stop_data *msdata) +static void ack_state(struct multi_stop_data *msdata, + enum multi_stop_state curstate) { if (atomic_dec_and_test(&msdata->thread_ack)) - set_state(msdata, msdata->state + 1); + set_state(msdata, curstate + 1); } notrace void __weak stop_machine_yield(const struct cpumask *cpumask) @@ -242,7 +243,7 @@ static int multi_cpu_stop(void *data) default: break; } - ack_state(msdata); + ack_state(msdata, curstate); } else if (curstate > MULTI_STOP_PREPARE) { /* * At this stage all other CPUs we depend on must spin From patchwork Fri Oct 20 14:43:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rong Tao X-Patchwork-Id: 156167 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp1113051vqb; Fri, 20 Oct 2023 07:57:24 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGBg1spuoDxG1NsnzndWOn6ezyzOGaeizK+k22wy1TCJaq8llx/Jj7cVq+chd6BBFjLKwmu X-Received: by 2002:a05:6a21:a593:b0:15e:b8a1:57b0 with SMTP id gd19-20020a056a21a59300b0015eb8a157b0mr2082790pzc.39.1697813844064; Fri, 20 Oct 2023 07:57:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697813844; cv=none; d=google.com; s=arc-20160816; b=exVtg5nHrgeN6LiAJKlD9jGrtJ+Hm7Muemg8ScS8iThLYKlsuBCh4nL8+ianXOjW7F IhuVjL4MO6OKrl6qiAg7yP5jrb7fxsnCxuTDuqTVbGsuDWZAl2YrqbNcvQcMoY9KhkZw fhX7QGcdXADVX3lWwIh8k/+OjwBpAy2mYn0yP4IqEYAf9XXXgbtrnbUl45iBWyrdhwxD AFq+Ww53WAlyRWaKq0DHi+wgH75gyzPu4ZY1tOnL7DUAftcqhQmATC0qPGOi7z9+S+fn gK6PQ4I0bddc5w1xzy2NWgPQVKG7awyAVrHEb9lTead3ylliujIqXPjxlPnpwDfuC8ki ivpQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:date:subject:to:from:message-id :dkim-signature; bh=JHbwUQb8lD1tTuEb5a8cmghLPuMYhOm9x0/pntObncg=; fh=PGaP26rljTYcjLituiXWjvRiYsB22YGWGH+YkC/057Y=; b=AW46Bdz3Z/gVHY4aIie4fZlNUxQFYWL4H++W9k3e4vz3iJgf6vNqEZNZUPoyyUGfD2 7rxFO3OKeELeAQZ4O9b677LIEgrbox1M5KYxnd3eXxH3e+PbR7VRVSzpwsWnBTHaWtbA dZEfL55HHjgg3fk7aY6Sj/axd39bpbL6agcpxvObKAn4S2Km4k1nmexji11qoW/Idq1n hJuNw743a5x7DagCED/9gMg8hCbMarnDKEQeCbluFSVIgLVvUFF7zMqkx/yi7zdaHPa9 QKNfbPiyzv3tsRcH4sgvfE0IAPq7zanYzbQnhhlOd/gVPRYThgyKhE4doTOYM0bRUxja rD3g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@foxmail.com header.s=s201512 header.b=uxSF6Wrw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=foxmail.com Received: from morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id n1-20020a170902d2c100b001ca336f48bdsi2027363plc.556.2023.10.20.07.57.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Oct 2023 07:57:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@foxmail.com header.s=s201512 header.b=uxSF6Wrw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=foxmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id E1D6D836B4C6; Fri, 20 Oct 2023 07:57:21 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377597AbjJTO5P (ORCPT + 26 others); Fri, 20 Oct 2023 10:57:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46414 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377529AbjJTO5O (ORCPT ); Fri, 20 Oct 2023 10:57:14 -0400 Received: from out203-205-221-149.mail.qq.com (out203-205-221-149.mail.qq.com [203.205.221.149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A43C2D46 for ; Fri, 20 Oct 2023 07:57:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foxmail.com; s=s201512; t=1697813828; bh=JHbwUQb8lD1tTuEb5a8cmghLPuMYhOm9x0/pntObncg=; h=From:To:Subject:Date:In-Reply-To:References; b=uxSF6WrwYctZlChw7piyjZL3T4n6sMLbQzZCeEN9haHN1R+4FLXl5giJKUIfsDX3B ZwWrXq+FpQL+s2EKqcEylSpnyveny9DxZJohfQINChYEP4Wbv8oJleucEzHieUP4xt tNw+N9W6JUcyHe9MvaSCM0G3MlM42BX8NOJOwn+k= Received: from rtoax.lan ([120.245.114.36]) by newxmesmtplogicsvrszb6-0.qq.com (NewEsmtp) with SMTP id AE3AEEEC; Fri, 20 Oct 2023 22:43:35 +0800 X-QQ-mid: xmsmtpt1697813020tebywjqps Message-ID: X-QQ-XMAILINFO: N7h1OCCDntujuOVB48/Os70qsluFoiNYAhE4QPkzGQOyy7m7FTfareKCeYGFHS HihtYz16ET3FQGu+TcR4ZrkeLHMvR6w0pcQuzzfvQSdHaRxbOo6o1yPVU5pTQ5QlVkiMKQv5dAMn GhJXqifhL+hBkHmCIgvbYC3GAZRl2sKa7cUz5mJRxRJQ0Nt/sH/UlofAUWa40yiF19hmfF/niNg7 gNmRK68X9WtPa1HhNrnUBUvm9204LQXbd3Yinskj+MuYafHaHmeCcmcPzGIRNhAKP7HgWfLcZoLh 2CrOg1vLWd34j2oLvek9cUbR9DmfBrS2C6T56Hd2yXLQhDr4T8g+oeAtmvGM7O9OqXJyILhhDz0A x+fsPRqLJIudCt7PLGnLb2YUqCycL7DM5SWvbKedg3mb6KXqbzhjcng6qaqxQmqfQP14vUB087WW XoR6VbsEq+FL6IzFREdS4dSQNY3M2Cy50PlRzk5C4c8uz79jAmf9aNQotrjTxFrYeVfLxbQ/renI HCYl27eHbP0yTzUEdcAP595is+6SVJcN14Sz0J61IqSUaPeTTg/VBVlGRMxKOpKBWJwUTgpmrxHs jtSnuOmausx72KeWPXeRVaI0lvxIAoJWJwMIEHSw4tMARTnlEf0zma9MQksyAY3dXaKo5UfaU6nF o4k7VZZzeeFkglSuRcNWx7w0GubTN6Skng3sEHlxUEiAxpyHMhd+Xz9WpI6VbJq5qsjCExPg1YVB ZjhJgBsiiq7GxSZkTDyd9bt6OlHPcKC8mgradRT9aHlCgWnUwHddtbS/FSghaiXD+NSHIjHaaudd 7PVrtsasopKMr2nV8y3JVb7Q2e0Bv0h5SKEQw/fevxCLUTX0rVvvd3KtRsVIiZXDP7oViUuNOBT8 u846eVq0Griww4+dqLJUXrKJT0RA2VE3WI1v1+9TIAj/97l0xTL7TVPfvT7P/ikzhBWxzh+Jpvn/ tyrheEl15NJr2PttV3SBFZd9vEHMF0DYojW0yW/X7+BlU1c5GndAU7K1di62v2uvp2kp7Fma6dYE GzVLxEq0PW5O52yLfX8/BAqN9xunw= X-QQ-XMRINFO: NS+P29fieYNw95Bth2bWPxk= From: Rong Tao To: mark.rutland@arm.com, elver@google.com, linux-kernel@vger.kernel.org, peterz@infradead.org, rongtao@cestc.cn, rtoax@foxmail.com, tglx@linutronix.de Subject: [PATCH 2/2] stop_machine: Apply smp_store_release() to multi_stop_data::state Date: Fri, 20 Oct 2023 22:43:34 +0800 X-OQ-MSGID: X-Mailer: git-send-email 2.41.0 In-Reply-To: References: MIME-Version: 1.0 X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Fri, 20 Oct 2023 07:57:21 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780286849552783894 X-GMAIL-MSGID: 1780286849552783894 From: Rong Tao Replace smp_wmb()+WRITE_ONCE() with smp_store_release() and add comment. Signed-off-by: Rong Tao --- kernel/stop_machine.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/kernel/stop_machine.c b/kernel/stop_machine.c index 268c2e581698..cdf4a3fe0348 100644 --- a/kernel/stop_machine.c +++ b/kernel/stop_machine.c @@ -183,8 +183,10 @@ static void set_state(struct multi_stop_data *msdata, { /* Reset ack counter. */ atomic_set(&msdata->thread_ack, msdata->num_threads); - smp_wmb(); - WRITE_ONCE(msdata->state, newstate); + /* This smp_store_release() pair with READ_ONCE() in multi_cpu_stop(). + * Avoid potential access multi_stop_data::state race behaviour. + */ + smp_store_release(&msdata->state, newstate); } /* Last one to ack a state moves to the next state. */