Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp488022rwl; Wed, 5 Apr 2023 03:49:22 -0700 (PDT) X-Google-Smtp-Source: AKy350bVD+Lo6i7JfTg9Ecwog4l42IuNEgevZWgx0lE2vKCt+XbK+DclKP6qZr5dJHXI7VPh/ZFy X-Received: by 2002:a17:907:20bb:b0:93d:cffb:80ba with SMTP id pw27-20020a17090720bb00b0093dcffb80bamr2370315ejb.66.1680691762387; Wed, 05 Apr 2023 03:49:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680691762; cv=none; d=google.com; s=arc-20160816; b=a8qRHXZ64WExgqsQGDOx25cAC2zaLpRXY0bDeXV/nMlI0rGF2773Cmf883rOucICDF 2QHt4dh0r1tQ2rz1FZXI8IpXIu+p+6l8nwP1/FH+qPFWdQ8NrGWENvRe5t+XFlUXvXUA QOCSXqFm9Y+9+/A3WkWVqlNP3YTKeySSaZlPO34qSq/d/m7V7MzU1oSCHOPrzndEj9l/ QYNP6U6i9xPpZAiEjxQ1ZrZtA25xw0V9I0kKlQo9f/Py1Du9I52i/WNtdeFWd2tLcM8+ hIZyQ5DfXSxPmlFY18WXYcpAfoz+CnmVgbM5YEpxvnFth45ScMTul7YmuyAbnFXycgF9 ae6w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=FWEoECAfY+wWsgkbeCj2WH8L2epM/LlmHPmMJIPH3QM=; b=mhvwqokd1B7U5VP8+NV3fO3/iuOvRp3BNbDq1WR6s2LxpAFxZiedzX0C4eOCmGgWsE rz+o8pyJ31wbgGfykVWNvO1ceFjjI/VHk2ZtHmYIymiE9Oz/Zv4tgBSw3Ygrw1OXIK8V bSsOOtIG4sRQ/TpvF3fALMFHcvcsETYECjggNu+s/BaN7eMrwfMbrCoC01fyVFW1fZO6 3t8kFCOSfL+1I2RkKXAcH7+juNC1wxxfdWdnRdJ9ZWCIcABUPuP3tW0z/rD6qaBr2A2f 8AwdjKmPnzgRjYgi8wS7G2lwT/jOl16jTxadJlmBK7z6IEY/g/z1f2aoCd338Hglg5Go UA/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=RfEi0EWH; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b7-20020a056402138700b005024a8c6c30si2803758edv.272.2023.04.05.03.48.58; Wed, 05 Apr 2023 03:49:22 -0700 (PDT) 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; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=RfEi0EWH; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237721AbjDEKoG (ORCPT + 99 others); Wed, 5 Apr 2023 06:44:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53156 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237588AbjDEKoE (ORCPT ); Wed, 5 Apr 2023 06:44:04 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 98E694ECA; Wed, 5 Apr 2023 03:44:02 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 2975763C57; Wed, 5 Apr 2023 10:44:02 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BFC61C433EF; Wed, 5 Apr 2023 10:44:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1680691441; bh=+ZO/yBxfJv0GaHczUgdJTBFHBjfQ/ykADeJttq42HmQ=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=RfEi0EWHrVtgDNTDmAkQHpOA1xGMHUdirDcpsD08NWpiRE8In3RAHPfhmz+mLo3Re keFWgaWXAHpSzJgLMWdEzHtCNaP6XaC77hbIAZwK+4PpDX/Zwb9pTItZlq4DbE4Bcj gF37NoMLKD33dyuHM4yV5O3ouVk+s6lLupFGmAHvGBDdJp1MrGsgJ5ZzVLp7GXS7g2 UIOMTpAu0+CUNt+73VKyRli+76KWSC33YcG5QeaD76fiXSWmghliODfhBl98LZE/dA PhaBHuqHXYQ037jMpcPmRNTtYCqZtKeIbh0pk5/nikjbQBZDel/38qAxiwMpnOZnDc uqZAC/jHMG+Ow== Date: Wed, 5 Apr 2023 12:43:58 +0200 From: Frederic Weisbecker To: Yair Podemsky Cc: linux@armlinux.org.uk, mpe@ellerman.id.au, npiggin@gmail.com, christophe.leroy@csgroup.eu, hca@linux.ibm.com, gor@linux.ibm.com, agordeev@linux.ibm.com, borntraeger@linux.ibm.com, svens@linux.ibm.com, davem@davemloft.net, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, will@kernel.org, aneesh.kumar@linux.ibm.com, akpm@linux-foundation.org, peterz@infradead.org, arnd@arndb.de, keescook@chromium.org, paulmck@kernel.org, jpoimboe@kernel.org, samitolvanen@google.com, ardb@kernel.org, juerg.haefliger@canonical.com, rmk+kernel@armlinux.org.uk, geert+renesas@glider.be, tony@atomide.com, linus.walleij@linaro.org, sebastian.reichel@collabora.com, nick.hawkins@hpe.com, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linuxppc-dev@lists.ozlabs.org, linux-s390@vger.kernel.org, sparclinux@vger.kernel.org, linux-arch@vger.kernel.org, linux-mm@kvack.org, mtosatti@redhat.com, vschneid@redhat.com, dhildenb@redhat.com, alougovs@redhat.com Subject: Re: [PATCH 3/3] mm/mmu_gather: send tlb_remove_table_smp_sync IPI only to CPUs in kernel mode Message-ID: References: <20230404134224.137038-1-ypodemsk@redhat.com> <20230404134224.137038-4-ypodemsk@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230404134224.137038-4-ypodemsk@redhat.com> X-Spam-Status: No, score=-5.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI,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 lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Apr 04, 2023 at 04:42:24PM +0300, Yair Podemsky wrote: > @@ -191,6 +192,20 @@ static void tlb_remove_table_smp_sync(void *arg) > /* Simply deliver the interrupt */ > } > > + > +#ifdef CONFIG_CONTEXT_TRACKING > +static bool cpu_in_kernel(int cpu, void *info) > +{ > + struct context_tracking *ct = per_cpu_ptr(&context_tracking, cpu); Like Peter said, an smp_mb() is required here before the read (unless there is already one between the page table modification and that ct->state read?). So that you have this pairing: WRITE page_table WRITE ct->state smp_mb() smp_mb() // implied by atomic_fetch_or READ ct->state READ page_table > + int state = atomic_read(&ct->state); > + /* will return true only for cpus in kernel space */ > + return state & CT_STATE_MASK == CONTEXT_KERNEL; > +} Also note that this doesn't stricly prevent userspace from being interrupted. You may well observe the CPU in kernel but it may receive the IPI later after switching to userspace. We could arrange for avoiding that with marking ct->state with a pending work bit to flush upon user entry/exit but that's a bit more overhead so I first need to know about your expectations here, ie: can you tolerate such an occasional interruption or not? Thanks.