Received: by 2002:a89:413:0:b0:1fd:dba5:e537 with SMTP id m19csp915838lqs; Fri, 14 Jun 2024 09:09:31 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUhTpN0CpcatTZTYKEdov23tzDtOBFy6C40y8eHqstzgiJwkUbWitboJmIh+rlol28PpMUtxhm6UJlGmHouIs2QkDCGpiLKE8ThEdLGqw== X-Google-Smtp-Source: AGHT+IHqDIgXyfJZIL8tTdj+Ag48pRSGH+Y54fvNg4htx6DY1fLXHs3PicF51uLwF5fe9KNugfoU X-Received: by 2002:a17:907:1604:b0:a6f:668b:3442 with SMTP id a640c23a62f3a-a6f668b3528mr172752966b.77.1718381371546; Fri, 14 Jun 2024 09:09:31 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718381371; cv=pass; d=google.com; s=arc-20160816; b=DVDtgl0EJJWeBpGE7BhoAg69VMm0GLomTI5urjZfzK0ApfH5JgjavY8TKl8AID8g/R zGYhD3AhOMeel6Yp5WmYXQ75VXzBPgoMf3KgDNiX3dq9lNn/t4tddFKbfRBTFq6EFuUb ab8d4uAV3PdEE7oitYtWaZc/DwP3Cq5+VPaAyHpiBv3Z9Oy75YTMUVFtrCHOg0RqkURZ nZ9aMDiwn1+x36c4BxZmGnS0qD96xci1U7DTEm6LhoWHXqO4LLHK2pXBiDUhX8YF0G8o 3u9HUz9QvZhg2wXYTLikrxigJ8v/QT5S4keTT5H/XO9a3i0YauunPp9qjF9F0UkHTNFD JzMg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from; bh=mLOECCNPQdyZx6wI1tU74ufuNPpbYKGQYkTBT/6Jiug=; fh=Vo4MxA0u7CmSKYL/GjcyKHwusyvU+nKR43bqJem+vcY=; b=kCRBL1gsnXBkzzv3AALbXNX8zmTx6PBZzGwlRPY+4xxmE6Lc4AfkDeKhLi5YPc/hgd XzPQTRfEFsp6l7ph/64alSqmtH8ohD8/1QsIWAbgT2Y7mfMgLJDzq9dkY8fUI7/ipaDE 3rFEoYLG9XDuHiPgeyJ06i6yjr52kk+yxAgLvOpHkgzvUOG6gwXDeIywAf2pIc/eyzuh 739ovcALfcfDh6wdFiURTfiXQJXR6D+J8gIqq1RNn+4almudGRZTBLIYe/s0rmZQ1wu2 znHdfG4Eq3/vxXCLazHx00IB0y9FioL5WmVqctAKpXvCPDPmws9pivyXKqKUDloi7z3v /lHw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-215200-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-215200-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id a640c23a62f3a-a6f56e26bf2si184100266b.769.2024.06.14.09.09.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Jun 2024 09:09:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-215200-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-215200-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-215200-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.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 am.mirrors.kernel.org (Postfix) with ESMTPS id 434CF1F22661 for ; Fri, 14 Jun 2024 16:09:31 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DC1FD187560; Fri, 14 Jun 2024 16:08:55 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2278D178CE2 for ; Fri, 14 Jun 2024 16:08:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718381335; cv=none; b=I9XEDgzCQcxzSSygql4hoo11MFIcFZxTqZfQiOlkkTwdhfkRLwmTqhnCKwIJ3QYRR9E1Yw1xlnb0khQjLqH2YKG5KossMMEeG8yQ98tWBP84+OfiRAGIXwzLs58HdwmGHoxWUW3+JDTuBkPNW2N2gM+HZKMRVxm/AwQeVyDlZp4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718381335; c=relaxed/simple; bh=ka13FiTsUCW41tCahqnBvKKgjl5W8W7Jddph2BhNW1s=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=OgzSUzHtFdG1rT6blY8ZmoyNirVt5F1RjL9w3roE2o00KNFlr+qivFDICY4LArqlGLxUTgUjDH/YY0N59WPmet8zKxc8lrJhI5oSnUNcPX5VpblRbn+S6dJ2t4sL4LNIiHOdm1IdS3HjgoyT4WoDUB4W5jWAmCTMMU4j9z39/Wc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 9E71FFEC; Fri, 14 Jun 2024 09:09:16 -0700 (PDT) Received: from e133380.cambridge.arm.com (e133380.arm.com [10.1.197.55]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 975363F5A1; Fri, 14 Jun 2024 09:08:48 -0700 (PDT) From: Dave Martin To: x86@kernel.org, linux-kernel@vger.kernel.org Cc: James Morse , Fenghua Yu , Reinette Chatre , Thomas Gleixner , Ingo Molnar , Borislav Petkov , H Peter Anvin , Babu Moger , shameerali.kolothum.thodi@huawei.com, D Scott Phillips OS , carl@os.amperecomputing.com, lcherian@marvell.com, bobo.shaobowang@huawei.com, "Shaopeng Tan (Fujitsu)" , baolin.wang@linux.alibaba.com, Jamie Iles , Xin Hao , Peter Newman , dfustini@baylibre.com, amitsinght@marvell.com, David Hildenbrand , Rex Nie Subject: [PATCH] x86/resctrl: Don't try to free nonexistent RMIDs Date: Fri, 14 Jun 2024 17:08:43 +0100 Message-Id: <20240614160843.11006-1-Dave.Martin@arm.com> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Commit 6791e0ea3071 ("x86/resctrl: Access per-rmid structures by index") adds logic to map individual monitoring groups into a global index space used for tracking allocated RMIDs. That patch keept the logic to ignore requests to free the default RMID in free_rmid(), and this works fine on x86. With arm64 MPAM, there is a latent bug here: on platforms with no monitors exposed through resctrl, each control group still gets a different monitoring group ID as seen by the hardware, since the CLOSID always forms part of the monitoring group ID. This means that when removing a control group, the code may try to free this group's default monitoring group RMID for real. If there are no monitors however, the RMID tracking table rmid_ptrs[] would be a waste of memory and is never allocated, leading to a splat when a free_rmid() tries to dereference the table. One option would be to treat RMID 0 as special for every CLOSID, but this would be ugly since we still want to do bookkeeping for these monitoring group IDs when there are monitors present in the hardware. Instead, add a gating check of resctrl_arch_mon_capable() in free_rmid(), and just do nothing if the hardware doesn't have monitors. This fix mirrors the gating checks already present in mkdir_rdt_prepare_rmid_alloc() and elsewhere. No functional change on x86. Fixes: 6791e0ea3071 ("x86/resctrl: Access per-rmid structures by index") Signed-off-by: Dave Martin --- Based on v6.10-rc3. Tested on x86 (But so far for the monitors-present case. Testing on Atom would be appreciated.) Tested on arm64 for the no-monitors case. --- arch/x86/kernel/cpu/resctrl/monitor.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/arch/x86/kernel/cpu/resctrl/monitor.c b/arch/x86/kernel/cpu/resctrl/monitor.c index 2345e6836593..366f496ca3ce 100644 --- a/arch/x86/kernel/cpu/resctrl/monitor.c +++ b/arch/x86/kernel/cpu/resctrl/monitor.c @@ -519,7 +519,8 @@ void free_rmid(u32 closid, u32 rmid) * allows architectures that ignore the closid parameter to avoid an * unnecessary check. */ - if (idx == resctrl_arch_rmid_idx_encode(RESCTRL_RESERVED_CLOSID, + if (!resctrl_arch_mon_capable() || + idx == resctrl_arch_rmid_idx_encode(RESCTRL_RESERVED_CLOSID, RESCTRL_RESERVED_RMID)) return; base-commit: 83a7eefedc9b56fe7bfeff13b6c7356688ffa670 -- 2.34.1