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 E7E3DC3ABAC for ; Tue, 6 May 2025 07:00:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F2FAE6B000A; Tue, 6 May 2025 03:00:08 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EDD3C6B0082; Tue, 6 May 2025 03:00:08 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DA57F6B0085; Tue, 6 May 2025 03:00:08 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id BBA246B000A for ; Tue, 6 May 2025 03:00:08 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id B3569121BB4 for ; Tue, 6 May 2025 07:00:09 +0000 (UTC) X-FDA: 83411583738.21.D38E623 Received: from mail-wm1-f53.google.com (mail-wm1-f53.google.com [209.85.128.53]) by imf30.hostedemail.com (Postfix) with ESMTP id 98E6180017 for ; Tue, 6 May 2025 07:00:07 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=FmgWI869; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf30.hostedemail.com: domain of nadav.amit@gmail.com designates 209.85.128.53 as permitted sender) smtp.mailfrom=nadav.amit@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1746514807; a=rsa-sha256; cv=none; b=x9XyQ7S5IWwy9CFkOSrXEiMJ/7KhINuRbZSW7P7VV8QlMcQSSfzD/aBeEmB31+mwtCBU6Y eFdOOmW82l4MHa4/gu1cDJ5P90XoaVDh5d1KQ6ke4o+u1NKW9hZuKyhR8qLD/XHAeeDTBv c1W3VpByYVFv3iVdmeiTZFkFoM4Y9Vk= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=FmgWI869; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf30.hostedemail.com: domain of nadav.amit@gmail.com designates 209.85.128.53 as permitted sender) smtp.mailfrom=nadav.amit@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1746514807; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=e8W/zK0wbFRaqQMcIxNlkME3S0vuzKvpSCW5alz79aE=; b=TOL0X0w6DnTj99ALcb9mNTJpQDiB5xu12txwix81ujUK6TDI//pIUqojn42J5ut89iQllI H4fGmC2jcnbA2/vk4A5cPkwHvGFKBQTVEsEQjTlTd989eKMCL1qVQ6wTjqC3CRgyyx1cLp JezmNdbufxuarFDSkoJGNCQpPOmTrLQ= Received: by mail-wm1-f53.google.com with SMTP id 5b1f17b1804b1-43cfebc343dso34694615e9.2 for ; Tue, 06 May 2025 00:00:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1746514806; x=1747119606; darn=kvack.org; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=e8W/zK0wbFRaqQMcIxNlkME3S0vuzKvpSCW5alz79aE=; b=FmgWI869qLNseFgEW/REGRgXYGfDwoBjQyDZvRf7xk9K+Zc2/SnAlek+1pwlmyQp5O pw/afzLM9okZjSwaZa+gE9FZSDrVXoyRriaQStvs1Ez6nuDIlvxZFwWPs04GGYXisQk6 aikA689SRWT5CB4milYW7ocOSxAQOXBMdVuOu6IlEHyjbeuCLSAEHvo25SM2s3lA50in qpNp7OsLbEUipYYtq4kESLGr4aW1TZAD8/2+r2VKCjpW4r+3uSvNBg5MTIjvgncZ/nBY hwPGzFJwUF4U+zAOicrxvL5I50eE40xcChdHYljzZRwM6x9VdkXWiDospdlgfG619/i8 FOUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1746514806; x=1747119606; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=e8W/zK0wbFRaqQMcIxNlkME3S0vuzKvpSCW5alz79aE=; b=hFpzn/69XcmUt0qK7QdGRjyT/ha9Lk/32Qdv78hP8PbUngX6PFhLnoq3Gqg3G6txHQ rr8LDV+tADGMLudk0LQY94saAyKB7wQMoCk/6FBql0guWFAcm7G/Co1lW4bT0zJb9psH jdopZ4npa2AhCmhGbBD1M5DRlAio0RqjXuu+tqv1KdQ6uari4FaKCw8p1+xT/u8RQ4zB sceK1faplMqhJ4XxWILgN7SlkTfoQh74oinv9ElgmlPDR/1gI0yei9vvfH+cu5Gh2Fky 6n6fBo12Em0gDL/XJM0W+A3HOseLXoO2y0556UfVYx1Icw4weJcjiedT8Am58ymAaQQS bQjw== X-Forwarded-Encrypted: i=1; AJvYcCVLzJBq1sSXDVcpatIOVKkgyoRJ7oLQ8uiuLL3iGcTjqKCwaDypwVcezhYrua4sV3n5chfRwrtWNQ==@kvack.org X-Gm-Message-State: AOJu0YzTI/JTOo+G99gR2lZYhX4TXdz+H0rjgUKpG8zqf6/KxRVh+ayq 1p0QwNYbO2Wk9W+ngeLGqdC0mHuJ2eMeYqZdZGv041Y/B3tCyygp X-Gm-Gg: ASbGncsQUWaBv73ro+356fXQ9exHXiAihbn55rnGcXql43wn07izlsTFPhIXmCGaR8O im41fbGUIEJFX7keww6vWu7+IXRlQ0EVVUgo+ou9wrEubDcXtP5/XKdVP1aLIDa1py2E9sZwApJ XlTVD7YDHBANNtfgonM3E7f0uEWUp2+EjvXGe7pVBzlrtqrNmOBxlasGjLOp1Uui/0dwLF5cGPc T2k5bDi5F6/O0YrpW5JWCfa7Sc0dwfwviy//rrsfnxeqIsXptyEtPUjPTlK8acGMNxjDUOHi4ff 6a9w4h5S66YGcQ10n/hzVp2wZm+tbOdQQPiwyS5AFLRuOhcllpDtccwn X-Google-Smtp-Source: AGHT+IGqtfXVfCThJ0EgiS/vbdS1mgUdEnBm0TGR9eBiAzaBJvc7xAqx9vZbwK2IfY31NFMRKfw/6A== X-Received: by 2002:a05:600c:500d:b0:43d:ed:ad07 with SMTP id 5b1f17b1804b1-441bbf3b4b3mr128466325e9.29.1746514805520; Tue, 06 May 2025 00:00:05 -0700 (PDT) Received: from smtpclient.apple ([77.137.66.48]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-441b89ee39esm156735185e9.21.2025.05.06.00.00.03 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 06 May 2025 00:00:04 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3826.500.181.1.5\)) Subject: Re: [RFC PATCH 7/9] x86/mm: Introduce Remote Action Request From: Nadav Amit In-Reply-To: <20250506003811.92405-8-riel@surriel.com> Date: Tue, 6 May 2025 09:59:52 +0300 Cc: Linux Kernel Mailing List , "open list:MEMORY MANAGEMENT" , the arch/x86 maintainers , kernel-team@meta.com, Dave Hansen , luto@kernel.org, peterz@infradead.org, Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , Yu-cheng Yu Content-Transfer-Encoding: quoted-printable Message-Id: <03E5F4D7-3E3F-4809-87FE-6BD0B792E90F@gmail.com> References: <20250506003811.92405-1-riel@surriel.com> <20250506003811.92405-8-riel@surriel.com> To: Rik van Riel X-Mailer: Apple Mail (2.3826.500.181.1.5) X-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JkHu5OFX+NdQPSn9aMci5l2 TkNqUOiN Xb0s5BawwOW5epxfOFTiNZGJw9Pe+giwHbjcGleKJiO3hD0FzulV67oV2zzc7tvoSR1tMxlUBxAB4chPMc14klL9OSGCa6wRNUbPfCB/4n16oLZODFciNXv7P5n+EhziaFDN3D2aeoneRY5nv2NEY99PXp1oMOUGpRHHoYtyJe8C/X71/Z1Sj1uWypY5wL43xdFCn+JoKzqtTvHC7xVzyhTT+8WRTC/puQGiG8E2JPTfKNxqeHeYFze5ZHp5mZyHuunQaP34dMhzNBOJzZrmVir9DndRwsrm6qxuymZAAUigmJtLF93w9foty3F6QpSwcTxpBxsxGSkLnNH/NTR4QLL8qcLBfZBePTtRJ6vEn7yUKim7hzV6hlUKm+wHwdfRcyeUN1FKG41uF9Uf44vPKIjUKKUBcbpl228fvdxi3/LdzDFf0kBQ4L6Vd9C6hKfAzplFrmUYAi9ziaHA++jqLa/OB5mJLqYQn5Ch3 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: List-Subscribe: List-Unsubscribe: > On 6 May 2025, at 3:37, Rik van Riel wrote: >=20 > +void smp_call_rar_many(const struct cpumask *mask, u16 pcid, > + unsigned long start, unsigned long end) > +{ > + unsigned long pages =3D (end - start + PAGE_SIZE) / PAGE_SIZE; > + int cpu, next_cpu, this_cpu =3D smp_processor_id(); > + cpumask_t *dest_mask; > + unsigned long idx; > + > + if (pages > RAR_INVLPG_MAX_PAGES || end =3D=3D TLB_FLUSH_ALL) > + pages =3D RAR_INVLPG_MAX_PAGES; > + > + /* > + * Can deadlock when called with interrupts disabled. > + * We allow cpu's that are not yet online though, as no one else = can > + * send smp call function interrupt to this cpu and as such = deadlocks > + * can't happen. > + */ > + WARN_ON_ONCE(cpu_online(this_cpu) && irqs_disabled() > + && !oops_in_progress && !early_boot_irqs_disabled); To ease it for the reader, consider using the updated version from smp.c (or - even better - refactor into common inline function): if (cpu_online(this_cpu) && !oops_in_progress && !early_boot_irqs_disabled) lockdep_assert_irqs_enabled(); > + > + /* Try to fastpath. So, what's a CPU they want? Ignoring this = one. */ > + cpu =3D cpumask_first_and(mask, cpu_online_mask); > + if (cpu =3D=3D this_cpu) > + cpu =3D cpumask_next_and(cpu, mask, cpu_online_mask); > + > + /* No online cpus? We're done. */ > + if (cpu >=3D nr_cpu_ids) > + return; > + > + /* Do we have another CPU which isn't us? */ > + next_cpu =3D cpumask_next_and(cpu, mask, cpu_online_mask); > + if (next_cpu =3D=3D this_cpu) > + next_cpu =3D cpumask_next_and(next_cpu, mask, = cpu_online_mask); > + > + /* Fastpath: do that cpu by itself. */ If you follow my comment (suggestion) about the concurrent flushes, then=20= this part should be moved to be in the same was as done in the updated smp_call_function_many_cond(). IOW, the main difference between this path and the =E2=80=9Cslow path=E2=80= =9D is=20 arch_send_rar_ipi_mask() vs arch_send_rar_single_ipi() (and maybe =E2=80=9Cand=E2=80=9D with cpu_online_mask). > + if (next_cpu >=3D nr_cpu_ids) { > + lock(this_cpu_ptr(&rar_lock)); > + idx =3D get_payload(); > + set_payload(idx, pcid, start, pages); > + set_action_entry(idx, cpu); > + arch_send_rar_single_ipi(cpu); > + wait_for_done(idx, cpu); > + free_payload(idx); > + unlock(this_cpu_ptr(&rar_lock)); > + return; > + } > + > + dest_mask =3D this_cpu_ptr(&rar_cpu_mask); > + cpumask_and(dest_mask, mask, cpu_online_mask); > + cpumask_clear_cpu(this_cpu, dest_mask); > + > + /* Some callers race with other cpus changing the passed mask */ > + if (unlikely(!cpumask_weight(dest_mask))) > + return; > + > + lock(this_cpu_ptr(&rar_lock)); > + idx =3D get_payload(); > + set_payload(idx, pcid, start, pages); > + > + for_each_cpu(cpu, dest_mask) > + set_action_entry(idx, cpu); > + > + /* Send a message to all CPUs in the map */ > + arch_send_rar_ipi_mask(dest_mask); Since 2019 we have move into =E2=80=9Cmulti=E2=80=9D TLB flush instead = of =E2=80=9Cmany=E2=80=9D. This means that try to take advantage of the time between sending the = IPI and the indication it was completed to do the local TLB flush. For both consistency and performance, I recommend you=E2=80=99d follow this = approach and do the local TLB flush (if needed) here, instead of doing it in the caller.=20 > + > + for_each_cpu(cpu, dest_mask) > + wait_for_done(idx, cpu); > + > + free_payload(idx); > + unlock(this_cpu_ptr(&rar_lock)); We don=E2=80=99t do lock/unlock on kernel/smp.c . So I would expect at = least a comment as for why it is required. > +} > +EXPORT_SYMBOL(smp_call_rar_many);