From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f74.google.com (mail-wm1-f74.google.com [209.85.128.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 437A12FF673 for ; Thu, 11 Dec 2025 14:24:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.74 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765463048; cv=none; b=C6iPbZJ9gKaS031P4N6hu6bTy6GETQGOZdTe03Ey+Htcy0W9ClkOUZy7IjZFta3ovIb/UGz3H8jf/0AFe4xBjfo8gthi0gR3tHfovE4mBS2RGn4uDkToKQvKkJi9ii/myZYmcCS0jcjF9qiTa+YWnXBZsMoHhEqrjEQTxA5GbME= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765463048; c=relaxed/simple; bh=e1XHdI3f932TjkztfbxisSyCsKvisyhKnU3z5nE3GGE=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=rLzQexwwetmTkgJjGEyfUCBvSR6So5S/pB6+0GVcEr2L9ZbXVCZCI4fF/lFRNzbvuCnsMXFClW6AErL3AJas6O/jdjSN+AsKquxuxV3HUogQlokcb7lAjyTIrWGFKe/FGU5BXAgMvYzWgN0rs2fF+gsdwzp1l5JkAUu61Ij/SQE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--jpiecuch.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=4P8h0tmm; arc=none smtp.client-ip=209.85.128.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--jpiecuch.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="4P8h0tmm" Received: by mail-wm1-f74.google.com with SMTP id 5b1f17b1804b1-47918084ac1so1515745e9.2 for ; Thu, 11 Dec 2025 06:24:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1765463045; x=1766067845; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=hGf8tytkhcfK83uzRhmu6L15V1EuZ+Gq3Gzcf0Y+UOw=; b=4P8h0tmm5dsfakus/pPWr76pnjQyMu+qTx7wUej6Dj6P/iczpQH9N+jj8Y1UcLf0Oa u8A4t2Ec7J0+T1RQHw/UOD5TSS61tkANYQ1iOcXOT8luhINBQdn5PdrvQWyRQnT/Lrwb yogGfJlGN/TTNKvq1URP+BqFAGkL9DuENboT35W0haSMsZELbtxNZs5t8TGT7eVrzQvX 9de7L0eT+vQjMbNdJ1+IocYZWqtsf2ThBmvCIGtqeLQDvlnUpNhj+1QORjJ1DVaPeWtB 1Ymns5flBMyIA1rUHb2xYfUY7Q0rpd22E6m0c1g9UlWkN1YDngWgmiczI7lAmSRGemaf RwNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765463045; x=1766067845; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=hGf8tytkhcfK83uzRhmu6L15V1EuZ+Gq3Gzcf0Y+UOw=; b=ZFFweYnfJLOHXlUl8LT+kRAxyWrSJ4deXF7M4ZCGvnwarR/GE6cH6KXMs+oXJZUAKD 3c3Y6aW0YRWAvk2cjvYb1w6OU9rwVCYPSBcyo6ztkyHrisFJKCktIbEeyeEhz8J4PfRz CqfRF4/5x6OsL2LIupgJnKeh9JHcln4WKmcmnnRN2szKzKWh454in0pS6VRVb3pv3Vyl KU9Pt+rehZ5zYbrTdk+P1iFGTWyKPnBOiEq5UAyMKB6wKaBcDmx+AD5Km7lhdj7piSjw pNklE9UTlsah0phYYTaxWiNcZHLJ2UtjIE9yJYIJ2R2SHinc4n6WaC3z+3uUU1p628EP GX/A== X-Gm-Message-State: AOJu0YztU71a9rKSgEDCjtY0vkGGMAJydAVkvAC1W/PURJZGhYxROJKa lhrp7xcKphowecCPqGv6uYy6V2ovy+FBlG4nOoWMW0jrKo9c3v2sG7zsLQC2Edjb9gDUJFH36yM pg6TdzWrbP1RtaQ== X-Google-Smtp-Source: AGHT+IHhEGxqJ0vj402qs74xX1FoqzH/A2sThKIHEVsgGHDvQN9bgz38z6DTsIhRjbqIENF9nS1kve9ss0axzg== X-Received: from wmbgx1.prod.google.com ([2002:a05:600c:8581:b0:477:9856:8f53]) (user=jpiecuch job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:310d:b0:479:3a88:de5f with SMTP id 5b1f17b1804b1-47a8385903emr51674065e9.36.1765463045634; Thu, 11 Dec 2025 06:24:05 -0800 (PST) Date: Thu, 11 Dec 2025 14:24:04 +0000 In-Reply-To: <7e9b27d70e31c243da3ce77e622b0af5@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20251025001849.1915635-1-tj@kernel.org> <7e9b27d70e31c243da3ce77e622b0af5@kernel.org> X-Mailer: aerc 0.20.1 Message-ID: Subject: Re: [PATCH v3 3/3] sched_ext: Allow scx_bpf_reenqueue_local() to be called from anywhere From: Kuba Piecuch To: Tejun Heo , David Vernet , Andrea Righi , Changwoo Min Cc: , , Peter Zijlstra , Wen-Fang Liu Content-Type: text/plain; charset="UTF-8" Hi Tejun, I think with the proposed implementation, using scx_bpf_reenqueue_local() from arbitrary contexts can have highly non-intuitive effects. For example, consider ops.enqueue() for a hypothetical userspace scheduler: void BPF_STRUCT_OPS(example_enqueue, struct task_struct *p, u64 enq_flags) { if (p->pid == user_scheduler_pid()) { /* * Remove existing tasks from the local DSQ so that * the userspace scheduler can schedule different tasks * before them. */ scx_bpf_reenqueue_local(); /* * Dispatch the user scheduler directly to the local DSQ. */ scx_bpf_dsq_insert(p, SCX_DSQ_LOCAL, SCX_SLICE_DFL, 0); } ... } I'm not arguing this is the way it should be written, but AFAIK it's perfectly legal. Since we're doing a direct dispatch, the user scheduler task will be inserted into the dispatch queue in enable_task_scx(), without dropping the rq lock between example_enqueue() and the insertion, which means reenq_local() will run afterwards (since it's deferred using irq_work), removing all tasks from the DSQ, including the userspace scheduler. A similar problem arises even if we don't do direct dispatch and drop the rq lock after example_enqueue(): since dispatching and reenq_local() are deferred using different irq_work entries, and irq_work_run() processes entries from newest to oldest, dispatching will be handled before reenq_local(), yielding the same result. The user may be unaware of this behavior (it's not mentioned anywhere) and expect the reenqueue to happen before dispatching the new task. I think at the very least we should make users aware of this in the comment for scx_bpf_reenqueue_local___v2(). Best, Kuba