From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 38A82C7619A for ; Wed, 5 Apr 2023 19:46:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 544B66B0074; Wed, 5 Apr 2023 15:46:05 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 51C0B6B0075; Wed, 5 Apr 2023 15:46:05 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 394706B0078; Wed, 5 Apr 2023 15:46:05 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 2AE0F6B0074 for ; Wed, 5 Apr 2023 15:46:05 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id EED29A0DD2 for ; Wed, 5 Apr 2023 19:46:04 +0000 (UTC) X-FDA: 80648368248.10.C004E0E Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf22.hostedemail.com (Postfix) with ESMTP id 24CA8C0018 for ; Wed, 5 Apr 2023 19:46:02 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=IHr326Oj; spf=pass (imf22.hostedemail.com: domain of mtosatti@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=mtosatti@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1680723963; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=+2zEtqXoZ8EUol2cclpRVKkKNXmBP9BtyvyLsaVT0jc=; b=KirnH4QCvGoG20AuRUnyuG2Tll/T64oBQOFK5TDLluHVOsnyCafotczdiepZtqnRapkY9Z LYZEATA7c5axFjVYonXMK116nJRjGz9uhPLu4ccLHBrXL8JGiHoeT8GpN1CNSwet8nBJ1/ z9hJig4xIstT0EuGeVM/8gL3mQNEsBQ= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=IHr326Oj; spf=pass (imf22.hostedemail.com: domain of mtosatti@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=mtosatti@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1680723963; a=rsa-sha256; cv=none; b=YN9UyenVr1a9Zpkpv7v35oGzCJ4GNpCrSjNXuIlTRaYJ4EBfoNaurxiy99XmYSoLjR5Yth GN7g2GNWT57yfcjgS3QmFrfoKJNdPXqBY4Aeb0qiIV5YL35rVz0EUEN7M+0hwLWJk1G5Ay TDCFkL/XyT/cAfm2Tl/MiOwkxhw5YQ0= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680723962; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=+2zEtqXoZ8EUol2cclpRVKkKNXmBP9BtyvyLsaVT0jc=; b=IHr326Oj0N26xa5gQkJW3os8cdcmQWMlINIkTgYno6gdUDUnNTTv/csK3/fUP3av3Sd8hU 2Z2vebdoiAkOo6CAgUKASMsGdssEeOBM6GTltzvz1XFtcQNofFD0ONTpeSJ9BjAk6sfUJF rLEGgkP1qL8KZk+d2C9112Mt/JpPC9U= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-428-6AAFnWjlOs2G1gaCxtVpqg-1; Wed, 05 Apr 2023 15:46:00 -0400 X-MC-Unique: 6AAFnWjlOs2G1gaCxtVpqg-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 2C7243C0D86F; Wed, 5 Apr 2023 19:45:57 +0000 (UTC) Received: from tpad.localdomain (ovpn-112-2.gru2.redhat.com [10.97.112.2]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B9FF21121314; Wed, 5 Apr 2023 19:45:55 +0000 (UTC) Received: by tpad.localdomain (Postfix, from userid 1000) id E6884400E055B; Wed, 5 Apr 2023 16:43:14 -0300 (-03) Date: Wed, 5 Apr 2023 16:43:14 -0300 From: Marcelo Tosatti To: Frederic Weisbecker Cc: Yair Podemsky , 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, 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: X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 24CA8C0018 X-Stat-Signature: 3kgfa8ixqs7fc1c651osmhsejagksx1w X-Rspam-User: X-HE-Tag: 1680723962-578958 X-HE-Meta: U2FsdGVkX19KOJkx9oyS268+P4Yu/P6cFrLDS1KWaodmCIQ65xWPzIhMo3i36Mwx4iLyL7+J2uqVG5I3XwKX+6R+V85i3zTT2w8gZdHQIJI2jkHxaRFaA6J0J1+SRvw1rGWp2gy6LEyWTPi/yIvATNmfysjal6sfF7ScGJcODTM0c/DUeivNJBldZ+Z383iRy5W6veWIhQrXxROBTPdU4XEiQCXazHzsML6eazObDmcrG10FLrwGq0XwY1eYaQLwe4wteLP9XiwkuuSbX8RHPaHtBOTGQo2JWPNFOiGm+H7m1wfMxfxRjnqLxQ8vCzkKUOvSKcc+wTFloRLoRCOo7U060WITi/6qE8ZxAT/k3YxAUfd1xxvADTdN05tL0aB0NvTvttolEajf7wAI30mXX/+mfsUtwHj6ckfNfI5sxEizR/Iagw4NZDJ8KhT+p2eLz7/JGlRw7u+w7dXlvNTh3vp/SXfBst1DFqZi1j50vOAumy3IO/leuGCkfqH5w4z0PQl9I/le4jIxgsMlYV/hCZC8EqkTt9OoDIXdceL+BvgV6O7H+nl5EODInrKlTfrEqIgUmztkvkOiZRD6mhR0YcTxcfOhEIkY+1iahnnMA+bJfI5RbPsbX+tm2up8xGCDtBK5pTURfkJWPBmGwK/27a/iItVgc+dV+GiuThGCvxxV/A93+NWWsoA4SxYp2wHyQnDYT2UwhHqxfY9KGQBwv29UHWPfKXoIer7rXSLFiQ8gebSFCrEOboNUslDC8I/SxmraRZjEWmT+6ViZV5AU0M2hoDRWzTsdGC0DVQG4NK0L+rJ1bZK/rDTbqDwo1BXH6qLWAG534jPHN4vqEEWImSivsvQtzm4z796PjkoseVPTR/0l3oFquvLuA5sHEv7CBmIcBKMGXUtClORBTqv1q6KtXcYmfnZqlEKr9s93hjb5VD+epOC3rTxasO6s+1L82Are1iOSP18fVvtH0P1 dTSfNqv4 JgvEs4uW2Bfr9LqscayHw20utKtjlaR5Ae23j66IOBGAdEDh65xcq2i8XJ0CA1BYIjJ/Hinhx7RCrXOmkaPHkBz14VA6fSIhXELsg8FRPDgGgAJpqS8qlfhTgXkzAD1DFy1XP1K7iQCqsdR87CwT9H5WLFjuYliMoa05yv7eq6sYBEz72RPfJtp1r5VdrkgV9wjUAvco6AaBjsHq4CSK9ikGCFw41dR3d0/I9z7xgocJcWhP/JtNHLDiXEGLfommeOAI6NOljspNMbueUJ39hHYkeEk1KlAbebMO2k06wzFOTgUffO5G83dn4WA== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Wed, Apr 05, 2023 at 12:43:58PM +0200, Frederic Weisbecker wrote: > 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? Two points: 1) For a virtualized system, the overhead is not only of executing the IPI but: VM-exit run VM-exit code in host handle IPI run VM-entry code in host VM-entry 2) Depends on the application and the definition of "occasional". For certain types of applications (for example PLC software or RAN processing), upon occurrence of an event, it is necessary to complete a certain task in a maximum amount of time (deadline). One way to express this requirement is with a pair of numbers, deadline time and execution time, where: * deadline time: length of time between event and deadline. * execution time: length of time it takes for processing of event to occur on a particular hardware platform (uninterrupted).