From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-178.mta0.migadu.com (out-178.mta0.migadu.com [91.218.175.178]) (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 0C66827FB36 for ; Fri, 16 May 2025 18:32:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.178 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747420365; cv=none; b=nkMrJvE47l24lVEI3nyCp2dSyVPzBBCwZbFXmWFwgRECv4t7ZYUCnrr+fWcjpfZf0Qqfmv1B/VauSOW69xdUhXz/hBJyh6dMSi0zdGDhNAy56oYdx7sCVfOkRAY48+WgST5dvEUHXkM1TM6THEY1WgBj89C7QJMPPfF7EKA5XMw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747420365; c=relaxed/simple; bh=4ZjTVBpWHcRhiktqzgid2qNVT421D1E6/FiuocKdIR4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bxvwj1ZnmFuZHFjmWF2KyK8c6Uyu6s3VmX7279G1TKjdYnkLrPtyxWpUh7hFoqoAalMKyQQRVKfOuOiKVeV3ueodW/0+l6KPXm+bH+qdzWpCQ3c6tn93/9AcIHwpJf83chLgqHFiup9t3hBYKd41soRtKESvi/S0wBFlJLiBHww= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=g9Xud4nU; arc=none smtp.client-ip=91.218.175.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="g9Xud4nU" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1747420360; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2t99xT19g/7qy5mAbIT4AWoGMrbj8qhuG2xvxaCqjsc=; b=g9Xud4nUZSS+w16AXeSr86eISPm8z0RnsTRYEC0O7EG0WtZS2ILoi8kVtrFW57WBpTaSIi XBqNB77YOyqqJWg9yZW3MXM4KdQYrg+GewqdNyW3Kvx7LqNRJDuu4v9Pqd/pDno4e1MYoR X7yvh6M5HH3crF/7viXSJSX1y4rogok= From: Shakeel Butt To: Andrew Morton Cc: Johannes Weiner , Michal Hocko , Roman Gushchin , Muchun Song , Vlastimil Babka , Alexei Starovoitov , Sebastian Andrzej Siewior , Harry Yoo , Yosry Ahmed , Peter Zijlstra , Mathieu Desnoyers , Tejun Heo , bpf@vger.kernel.org, linux-mm@kvack.org, cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, Meta kernel team Subject: [PATCH v3 1/5] memcg: disable kmem charging in nmi for unsupported arch Date: Fri, 16 May 2025 11:32:27 -0700 Message-ID: <20250516183231.1615590-2-shakeel.butt@linux.dev> In-Reply-To: <20250516183231.1615590-1-shakeel.butt@linux.dev> References: <20250516183231.1615590-1-shakeel.butt@linux.dev> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT The memcg accounting and stats uses this_cpu* and atomic* ops. There are archs which define CONFIG_HAVE_NMI but does not define CONFIG_ARCH_HAS_NMI_SAFE_THIS_CPU_OPS and ARCH_HAVE_NMI_SAFE_CMPXCHG, so memcg accounting for such archs in nmi context is not possible to support. Let's just disable memcg accounting in nmi context for such archs. Signed-off-by: Shakeel Butt --- Changes since v2: - reorder the in_nmi() check as suggested by Vlastimil include/linux/memcontrol.h | 5 +++++ mm/memcontrol.c | 15 +++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h index f7848f73f41c..53920528821f 100644 --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h @@ -62,6 +62,11 @@ struct mem_cgroup_reclaim_cookie { #ifdef CONFIG_MEMCG +#if defined(CONFIG_ARCH_HAS_NMI_SAFE_THIS_CPU_OPS) || \ + !defined(CONFIG_HAVE_NMI) || defined(ARCH_HAVE_NMI_SAFE_CMPXCHG) +#define MEMCG_SUPPORTS_NMI_CHARGING +#endif + #define MEM_CGROUP_ID_SHIFT 16 struct mem_cgroup_id { diff --git a/mm/memcontrol.c b/mm/memcontrol.c index e17b698f6243..0f182e4a9da0 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -2647,11 +2647,26 @@ static struct obj_cgroup *current_objcg_update(void) return objcg; } +#ifdef MEMCG_SUPPORTS_NMI_CHARGING +static inline bool nmi_charging_allowed(void) +{ + return true; +} +#else +static inline bool nmi_charging_allowed(void) +{ + return false; +} +#endif + __always_inline struct obj_cgroup *current_obj_cgroup(void) { struct mem_cgroup *memcg; struct obj_cgroup *objcg; + if (!nmi_charging_allowed() && in_nmi()) + return NULL; + if (in_task()) { memcg = current->active_memcg; if (unlikely(memcg)) -- 2.47.1