Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp1168953rwl; Wed, 5 Apr 2023 12:49:59 -0700 (PDT) X-Google-Smtp-Source: AKy350YBpD4QRKTV0vd9U0HlRxxrxbv1NnqKTihTyYFVkjmjpn7HT9+CawFVIJoEkcjSmv6f23vW X-Received: by 2002:a05:6402:3d9:b0:4fd:2346:7225 with SMTP id t25-20020a05640203d900b004fd23467225mr3246917edw.34.1680724199230; Wed, 05 Apr 2023 12:49:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680724199; cv=none; d=google.com; s=arc-20160816; b=r2zfYDgla88vvT322So6Bbe4HvYzgO2PWUNyMLXQrOK/xjXuvbQvKw+1V2tZx1zVNz AL0nk8/zAZMPEc9oO8Mr/iX/oyVjRdRzqsAblYDKoaMTbsWU9w0lmRRrPmBvpUZV9dAL hXKkpue+eygT1M8TGCTCUQKQIzgmk5UPjwMRejzGxtAmhVZT+W8WkMuf/pAYKUmlEJm0 EKSPcireTjg9xFWAAQ5pVDU00HKpcO7PmiEyBa6tT2AJjX6cQ5g7ttnDgyQZClXVb8ip zd9Oe32VcKSBc5tN8ccziRKBb7k7LXRObHE2+jEpjOf2dpYRJZARWOwi53gY0Iv7+yIj 4XlQ== 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=+2zEtqXoZ8EUol2cclpRVKkKNXmBP9BtyvyLsaVT0jc=; b=NYrOom/WT9qAOZsDO1hzoQXyxL9J4j87uP3iTfrpMdG5XSiRzvdFDCYc8cftXrU14G 1zogfm02ZUIhI4S0L8OAUQnURbrR/+EJbhWUq+g/7bcCLtWt27EtAuywzh+o0uLjrSd6 zpeUK79S/FDr9dMk8BR2mykEz/Id2aENBDJHpo7eLd1Zyf5s9UJGaV1x9F7bZ4sqaZCa vRN6l1l8nZpC9VowQVNJfxguatjxIEFsg6/7LltcHTM7p3BlvubRLeKpwXoPhGsua9p1 DIfHmuE+2NQudAXlfF6ClYhi6m+6EpU5i8+nED6FXpKxb7NXxi+MEYdfQLwAuiMvcnat u+bA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=IHr326Oj; 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=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bf20-20020a0564021a5400b00501d3a19a45si4057618edb.167.2023.04.05.12.49.34; Wed, 05 Apr 2023 12:49:59 -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=@redhat.com header.s=mimecast20190719 header.b=IHr326Oj; 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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230396AbjDETqw (ORCPT + 99 others); Wed, 5 Apr 2023 15:46:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43076 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229756AbjDETqv (ORCPT ); Wed, 5 Apr 2023 15:46:51 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3F502E75 for ; Wed, 5 Apr 2023 12:46:03 -0700 (PDT) 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-Spam-Status: No, score=-0.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE 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 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).