From nobody Wed Nov 27 18:45:03 2024 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9AFA518C00C; Tue, 8 Oct 2024 11:05:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728385515; cv=none; b=Rqrkr3Iq8MfYtH6CNkVpKeCwgCfBn06vcj556AHIKNOd0ozqKUpUs7W+vGHt9Hf62SfOqwRs6deIZqwaPkUW1YaLiByR//MDSiqAte2CEDI3Z7pNSvai6/oiGQNWkUTsefKVkmVi3P8r47rOSnFRx/XMr0HYOmd/bngVGWFTx80= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728385515; c=relaxed/simple; bh=WUpUD/Bl+IwKH5/Rgz/svt/Whv2KwhZO45LzE5Idhvs=; h=Date:From:To:Subject:Cc:In-Reply-To:References:MIME-Version: Message-ID:Content-Type; b=aQZg0bGSdi2SQZTrI+rqQ7NI+Om2Te2LxOrtUQs0WPRLwdSM50KAsg0yq5tnTVCBOe2Jgvi5XQs4eTL/lJjLTKjnADF+AWS/O/ohfM2JWtHoE8gcjubF7KoAtjylfJBj6ORVfTUGB2l8/eSqOeoZzRyixBlpBGCYsOk2J+lj/dQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=sCCRL4mf; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=/4OmwiOF; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="sCCRL4mf"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="/4OmwiOF" Date: Tue, 08 Oct 2024 11:05:11 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1728385512; h=from:from:sender:sender:reply-to: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; bh=0C1re5MoexYNggJIw/ByQAIWUX8IVGV2GFrlGl2Ie44=; b=sCCRL4mfnbJOeD4qqIDJ+LaPRG2+Nd9YjQZEY5EYhmix/w6xPy9KX199DHO83FVcGnFmjD Y14RZSxOOWZwVlfJrAR700xNDmH1Mko/rb+MI6HuGzm0/E+r8ldiZ2xR27FkyJhnXxLITI O4/GRtSs5lHXz/j0j+B54O/jpwghbSh6XUuKZQBjIOlBpbTOtIWmohO05Kkctjmj7U7mEv ZFngduTWD9+gI4FbNI98jWNR2kb+xueS4vbm2rAzoNGkiy+V+TQO/gMY3ZbCHGneqpVRLL gHv45SN+9FMMbQBiHyTaS5oKPVS4StN2qc0UWn0DRrMDQbGGDFydRpS6V6CjfQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1728385512; h=from:from:sender:sender:reply-to: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; bh=0C1re5MoexYNggJIw/ByQAIWUX8IVGV2GFrlGl2Ie44=; b=/4OmwiOFPYUaaUm7+4l/01r2tDnP3tKq03qDs5xRqy4HedDo4SaDunvLDEMKyvIUbnDTc7 cvv0X/vGIFHuM0BQ== From: "tip-bot2 for Oleg Nesterov" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: perf/core] uprobes: kill xol_area->slot_count Cc: Oleg Nesterov , "Peter Zijlstra (Intel)" , Andrii Nakryiko , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20241001142458.GA13629@redhat.com> References: <20241001142458.GA13629@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-ID: <172838551131.1442.2133799597969559576.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Precedence: bulk Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable The following commit has been merged into the perf/core branch of tip: Commit-ID: 7a166094bd2b1c084fd215747f9cd05a853d66c9 Gitweb: https://git.kernel.org/tip/7a166094bd2b1c084fd215747f9cd05a8= 53d66c9 Author: Oleg Nesterov AuthorDate: Tue, 01 Oct 2024 16:24:59 +02:00 Committer: Peter Zijlstra CommitterDate: Mon, 07 Oct 2024 09:28:45 +02:00 uprobes: kill xol_area->slot_count Add the new helper, xol_get_slot_nr() which does find_first_zero_bit() + test_and_set_bit(). xol_take_insn_slot() can wait for the "xol_get_slot_nr() < UINSNS_PER_PAGE" event instead of "area->slot_count < UINSNS_PER_PAGE". So we can kill area->slot_count and avoid atomic_inc() + atomic_dec(), this simplifies the code and can slightly improve the performance. Signed-off-by: Oleg Nesterov Signed-off-by: Peter Zijlstra (Intel) Acked-by: Andrii Nakryiko Link: https://lore.kernel.org/r/20241001142458.GA13629@redhat.com --- kernel/events/uprobes.c | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c index d3538b6..a1c801e 100644 --- a/kernel/events/uprobes.c +++ b/kernel/events/uprobes.c @@ -99,7 +99,6 @@ static LIST_HEAD(delayed_uprobe_list); */ struct xol_area { wait_queue_head_t wq; /* if all slots are busy */ - atomic_t slot_count; /* number of in-use slots */ unsigned long *bitmap; /* 0 =3D free slot */ =20 struct page *page; @@ -1556,7 +1555,6 @@ static struct xol_area *__create_xol_area(unsigned lo= ng vaddr) init_waitqueue_head(&area->wq); /* Reserve the 1st slot for get_trampoline_vaddr() */ set_bit(0, area->bitmap); - atomic_set(&area->slot_count, 1); insns =3D arch_uprobe_trampoline(&insns_size); arch_uprobe_copy_ixol(area->page, 0, insns, insns_size); =20 @@ -1629,24 +1627,28 @@ void uprobe_dup_mmap(struct mm_struct *oldmm, struc= t mm_struct *newmm) } } =20 +static unsigned long xol_get_slot_nr(struct xol_area *area) +{ + unsigned long slot_nr; + + slot_nr =3D find_first_zero_bit(area->bitmap, UINSNS_PER_PAGE); + if (slot_nr < UINSNS_PER_PAGE) { + if (!test_and_set_bit(slot_nr, area->bitmap)) + return slot_nr; + } + + return UINSNS_PER_PAGE; +} + /* * - search for a free slot. */ static unsigned long xol_take_insn_slot(struct xol_area *area) { - unsigned int slot_nr; + unsigned long slot_nr; =20 - for (;;) { - slot_nr =3D find_first_zero_bit(area->bitmap, UINSNS_PER_PAGE); - if (slot_nr < UINSNS_PER_PAGE) { - if (!test_and_set_bit(slot_nr, area->bitmap)) - break; - continue; - } - wait_event(area->wq, (atomic_read(&area->slot_count) < UINSNS_PER_PAGE)); - } + wait_event(area->wq, (slot_nr =3D xol_get_slot_nr(area)) < UINSNS_PER_PAG= E); =20 - atomic_inc(&area->slot_count); return area->vaddr + slot_nr * UPROBE_XOL_SLOT_BYTES; } =20 @@ -1682,7 +1684,6 @@ static void xol_free_insn_slot(struct uprobe_task *ut= ask) =20 slot_nr =3D offset / UPROBE_XOL_SLOT_BYTES; clear_bit(slot_nr, area->bitmap); - atomic_dec(&area->slot_count); smp_mb__after_atomic(); /* pairs with prepare_to_wait() */ if (waitqueue_active(&area->wq)) wake_up(&area->wq);