Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp2887530lqp; Mon, 25 Mar 2024 12:02:52 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCW5D0R1Q3MQAMNV4yWkRG3wdtfXBXBEg4bP/Pfc3ddlVJnmHTIe6YZjkhvieLF8WhmEuOQqi0yM16+v5ODt4ytUStEfSzuOZTRgmGfzvA== X-Google-Smtp-Source: AGHT+IEdS7ztyrI8LT9M82Xz+VITPE2mD/hYRoLyba7xaXe91qv8ueAXR5k/fgqEpi1gFgNsQakp X-Received: by 2002:a05:6a20:394e:b0:1a3:6ee8:b84c with SMTP id r14-20020a056a20394e00b001a36ee8b84cmr840633pzg.13.1711393371753; Mon, 25 Mar 2024 12:02:51 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711393371; cv=pass; d=google.com; s=arc-20160816; b=yGm+/BwmMuM7GDZ2xGb0G1a6RHP9JOc7P/NGtdV0fjZz+FiahJJHRIrDE5E098k+2P YMT7QAB5/V5OuYxFbsjWQGmILS3007+R12kOEn03/nQGOslXHizHWw11PJzdtqgBOk+x /z081dIyxzRdaWRpntfKq1lK37rzuhjWgysGwv7LQ5HBfSUfg8t8FF+XeKSOXgCmAnVE pv7FV4XE8Exl6mMaLWbvLqCT2c4qwDG7d9uqaOInjdti2U0+pWobhJdBy5HFG4OvcSB5 Nuxb8rmENcYcJ2ZGIke4I7uo0tTzm3htMie2ZCgHquSuLDHCcWZOPbrcxmJ74crDa3Nu GuVQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:references:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:in-reply-to:date :dkim-signature; bh=VNpwPuaEt/XFweY06CO9RkqXPvdKzwhVG5w7ZvFx+D4=; fh=yrmJed5llDxUhe6p8zhwDkKneR+mwUsjN/qHJDkwkO4=; b=jMqTWWvvDKCzHNZfzyZVA0S/GWQ7pc3OnSuJZSwbaT9EKM/L+sx5jQb6pJ8/+KHUbg GEKdMMyalJQVRoGqytca34atWRnQ897+xZKjJDIQvEi0KP0EZivlZmJLaUWmD41wh57W 00P+lGR0EJvonKLqE50uRk7nMe8ymG+SU0TBhBu5azZxviSprDfm/y3pcrbM0T3HeTxT NuML9w+IMFmqRFbbbH1ZBp487z8jFcIVNmMEq4+BOVG8M2CkgRII608N5tmpgyk29E8a pX6xmNmIalZV/XO3GwjE9C+W6svFkhPp+rAyoymYCkcIYJux7kAUlSTFB6tYeiFeLgf4 OsFQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=4Z3EsaD2; arc=pass (i=1 spf=pass spfdomain=flex--peternewman.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-117598-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-117598-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id j71-20020a63804a000000b005d8e22b5258si7882346pgd.879.2024.03.25.12.02.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 12:02:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-117598-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=4Z3EsaD2; arc=pass (i=1 spf=pass spfdomain=flex--peternewman.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-117598-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-117598-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 008183421E6 for ; Mon, 25 Mar 2024 18:07:36 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AA43012FB37; Mon, 25 Mar 2024 17:27:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="4Z3EsaD2" Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) (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 155E912F582 for ; Mon, 25 Mar 2024 17:27:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711387662; cv=none; b=u5TKh58VtUArhnVe2xJioegG8K/Q2GLVc5H9BCJK/urpMLmmugh57oTycFLk8D7qIWCsadUlwgRqTCh3vbnVffF1ff98Gc86C7hZOrDLCKSF3yxJPpCbvRq8DO8Ui9TvNWzxhlf3bRpZhBFJ7mH2sa/szWSLFfNHJvriAZRHePQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711387662; c=relaxed/simple; bh=AyBVpI9vaGXwp404hB8NwI0hWf2z6RpoeeU9eY+5rJE=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=YZc1fSh+ve0rtJUz/dz8PdtqxV+RQyyTr9X6Pd+a1532ZC4/FR5VsZbScENo4BkVwTROkxiy4xx6fCAzoVqcgd0sQo6yY4STm2X9BMG3Q7pieK9PfDDXOIfPBgyS/LY3KG6icXbUIBrN50chOljg0F3bQ2QbDkFDRueoS4v50Ag= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--peternewman.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=4Z3EsaD2; arc=none smtp.client-ip=209.85.128.202 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--peternewman.bounces.google.com Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-60a08eb0956so73033677b3.3 for ; Mon, 25 Mar 2024 10:27:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1711387660; x=1711992460; 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=VNpwPuaEt/XFweY06CO9RkqXPvdKzwhVG5w7ZvFx+D4=; b=4Z3EsaD2fSgqcMSqzxKlCbEjXGJ3rx7ZvfFGIk9sa7+mj+d79VhHMTbhRXOOd36SM9 ZLZNDn/eBkF5Z4OVZQUv/w4VxwGT6H60j8AXoAaz4k8Az07FeaUdD/sQ7dc+we1G2GPY hzWGGsx73nNt93k2Gc/707Eg4IeS52aoNWxMhV/eqE1n5aEO2LLP9n7uDR9iWCg7Wlo2 e8/Bnuv3x+KBqIU5s1FSE4vPORjdh5NXo0UB2QrkzZyCnNvPFPJcrcwqkUJcLjOzXHQV kF7R7hjnyQNhMHPqFYItQLSpeiTipInGxS9zL7BHseteSLQ/dFURhd/pYGfCUAG3pptV n9bA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711387660; x=1711992460; 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=VNpwPuaEt/XFweY06CO9RkqXPvdKzwhVG5w7ZvFx+D4=; b=tWVc7OwyS6fJBQn3dzGZrBH2YwAU2gogUp0yG+rUIjnu0nHOoY9rTZJ4khNU25xa2e oih7s67VQUEwyvVnj82hnIn03GlVq6MjaUXc0M0Xc0/KWLxCcgBKG+J2zNBj40qJxY63 W47dPFbtUsIrYnZw8N6N6vJ+aik+Hff1s5LEcNUpbZDIPfH6Vi5hxd6F5slzldW1T4tu ZKD2DXPjZj6zq/rBnou6/5GmfxMfKx4FppcSS5DleqTHREHsFl7yVDMqyaJtlqTFi9gR fCrPZPDkAlI7ALqQHE4b7BB8bCO4L1YoGdFTg8YY6UBAf8droFolrrsO25SW5YWQrlvd G2IA== X-Forwarded-Encrypted: i=1; AJvYcCUfvQ6rhYq3HGui4CaEJ+2HhawfNY5cOCAGNV7l1NYlSmbLfyYQbOlXdkbkF4NDJlIwbD5xZ2Dypgk3OMA32IcwZ9H1STB2Esaa9G8O X-Gm-Message-State: AOJu0YxNcm+6vlhpzWWeJN8BBdDiXOt/EFXExe0d05BoPs1HcLnKPQlg wqurgHOu3xWy1xWSr4OKLUBf1J3Fwkk8DZoiWdXXPIteIlbGmqVv7nneWawRdlemm16xUwfkP72 5zKOlfigYY/ifu3DxBzbWYA== X-Received: from peternewman-us.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:3dcc]) (user=peternewman job=sendgmr) by 2002:a81:de51:0:b0:609:f0f0:20c4 with SMTP id o17-20020a81de51000000b00609f0f020c4mr1784308ywl.4.1711387660115; Mon, 25 Mar 2024 10:27:40 -0700 (PDT) Date: Mon, 25 Mar 2024 10:27:03 -0700 In-Reply-To: <20240325172707.73966-1-peternewman@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240325172707.73966-1-peternewman@google.com> X-Mailer: git-send-email 2.44.0.396.g6e790dbe36-goog Message-ID: <20240325172707.73966-3-peternewman@google.com> Subject: [PATCH v1 2/6] x86/resctrl: Add hook for releasing task_struct references From: Peter Newman To: Fenghua Yu , Reinette Chatre , James Morse Cc: Stephane Eranian , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Daniel Bristot de Oliveira , Valentin Schneider , Uros Bizjak , Mike Rapoport , "Kirill A. Shutemov" , Rick Edgecombe , Xin Li , Babu Moger , Shaopeng Tan , Maciej Wieczor-Retman , Jens Axboe , Christian Brauner , Oleg Nesterov , Andrew Morton , Tycho Andersen , Nicholas Piggin , Beau Belgrave , "Matthew Wilcox (Oracle)" , linux-kernel@vger.kernel.org, Peter Newman Content-Type: text/plain; charset="UTF-8" In order for the task_struct to hold references to rdtgroups, it must be possible to release these references before a concurrent deletion causes them to be freed. It is not possible for resctrl code to do this with for_each_process_thread() because the task can still switch in after it has been removed from the tasklist, at which point the task_struct could be referring to freed memory. Signed-off-by: Peter Newman --- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 10 ++++++++++ include/linux/resctrl.h | 6 ++++++ kernel/exit.c | 3 +++ 3 files changed, 19 insertions(+) diff --git a/arch/x86/kernel/cpu/resctrl/rdtgroup.c b/arch/x86/kernel/cpu/resctrl/rdtgroup.c index 5d599d99f94b..9b1969e4235a 100644 --- a/arch/x86/kernel/cpu/resctrl/rdtgroup.c +++ b/arch/x86/kernel/cpu/resctrl/rdtgroup.c @@ -2931,6 +2931,16 @@ static void rdt_move_group_tasks(struct rdtgroup *from, struct rdtgroup *to, read_unlock(&tasklist_lock); } +/** + * exit_resctrl() - called at thread destruction to release resources + * + * This hook is called just before the task is removed from the global tasklist + * and still reachable via for_each_process_thread(). + */ +void exit_resctrl(struct task_struct *tsk) +{ +} + static void free_all_child_rdtgrp(struct rdtgroup *rdtgrp) { struct rdtgroup *sentry, *stmp; diff --git a/include/linux/resctrl.h b/include/linux/resctrl.h index 62d607939a73..b2af1fbc7aa1 100644 --- a/include/linux/resctrl.h +++ b/include/linux/resctrl.h @@ -325,4 +325,10 @@ static inline void resctrl_sched_in(struct task_struct *tsk) #endif } +#ifdef CONFIG_X86_CPU_RESCTRL +void exit_resctrl(struct task_struct *tsk); +#else +static inline void exit_resctrl(struct task_struct *tsk) {} +#endif + #endif /* _RESCTRL_H */ diff --git a/kernel/exit.c b/kernel/exit.c index 41a12630cbbc..ccdc90ff6d71 100644 --- a/kernel/exit.c +++ b/kernel/exit.c @@ -70,6 +70,7 @@ #include #include #include +#include #include @@ -862,6 +863,8 @@ void __noreturn do_exit(long code) tsk->exit_code = code; taskstats_exit(tsk, group_dead); + exit_resctrl(tsk); + exit_mm(); if (group_dead) -- 2.44.0.396.g6e790dbe36-goog