Received: by 2002:a05:7412:cfc7:b0:fc:a2b0:25d7 with SMTP id by7csp1824849rdb; Tue, 20 Feb 2024 08:04:30 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCU5bc8zO5liDoPc6tjmCagi9rThujzvxeUELNckIcX3XmrCzfouRnbBvLv4YUp/pSA424F+UhdZuPQOgESucGjnHnPnnGF/usvRu6ZkNQ== X-Google-Smtp-Source: AGHT+IGZwm/O3YLdct4J7bsHt9kbkhpTYf80MfI1pN7bnIuimBmFZn9hBCELvwH20A/m4+aoTEBj X-Received: by 2002:a05:6512:159a:b0:512:a8bd:4bed with SMTP id bp26-20020a056512159a00b00512a8bd4bedmr7106408lfb.10.1708445070032; Tue, 20 Feb 2024 08:04:30 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708445070; cv=pass; d=google.com; s=arc-20160816; b=nA9EOxQYtGWwV3mbiTs1O7HWqSjNvo486l6Gyu59gbAkj+BPoO59TLhjvFPgiZJ6fl 5gvNqiTRKivCRWrqj4xpuahX1Irq3n6dfW5ICkntXzLdTJqyvMAio/lm5xH3dEXjfmUL 7GAaI24NXlJk+8yXDZBETq6+5J3oVRAGd8/0YzSbjE/49fKa4s/QZYYMoo4SBSzwetzL Qm+5+m7Gn2ybGqikRes14hSFKafvH16xuOWbvWTdLtYpJZXQLIZoA+sFJH5Mk1/OXtkH VqE2qhvw6dgow89rVbX3vYiGgJXIpgQU+jHMd2GOYsK5Pf7/7zV+7RXiaTjLgenZtE82 KkgA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id; bh=0U7mvIAVc/s+VrASBitnQesbjHJ1TmYLpWiSQ50N16Y=; fh=MPQsikFriSRS8BljBtmWMTHXgmVJyc7L1nc1x47sHAE=; b=HThBXrfmcsGmuBgcer7rm6mgfYs+pdGMRDCnGnvKjLRopQGNP1Sgrpo5Gr2N5mMHDb tJv3JHJUqnXgE0sUdtIkCXMucUyuXE6I0bZ9a1V91cmxNE4UzxPSAJ7RNqezrMRMvmd3 tmQtEC5TkboeTiUT/v/OaKu1FU3LYie5Q/IY5I/WVVJtbHKv+dwLgQP+Di94xpnk/u7Q vC0wZo/yTkobYsa5zGZsL0jQ/7TwiQvmkaiwQ2noMH4pGAttilPWyQRgLZW58GuN/U02 1sRCQTPVz5yNVPttSgC1cvrqA7LdhGQDzek3xMWu27R4VOec6S44GHAYhNpJUj/Zv3hX PV9A==; 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-73300-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-73300-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 qa19-20020a170907869300b00a3e8df44d58si2143559ejc.398.2024.02.20.08.04.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Feb 2024 08:04:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-73300-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-73300-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-73300-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 C2DE61F235D8 for ; Tue, 20 Feb 2024 16:04:29 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2F24D76412; Tue, 20 Feb 2024 16:02:05 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E9C542C6AA for ; Tue, 20 Feb 2024 16:02:01 +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=1708444924; cv=none; b=h59uV3WfXUPqFIRzIYx0lnziyzogyiJJTqxKNUqTtOlXIWfQ7EygH/BCbMyQc+47vhReClXBhQ13zctmDuUAATzl/q1gvVrwBJ6PS2F7ous5BK5gEw/taQ2Ksx7nSlah2CfHPSmb3K9D2W1l6na2lYXd6WOwcPLkv/xQEmBTo08= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708444924; c=relaxed/simple; bh=Uqt+DFpm33CB/n7o5DFgHzyUO3un5Sb5LmiMg5MCcCo=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=s/ayVuNFT8i2v44Rp1L0keEnRVCp+wZQyL0wI2X8+oRYmEL7yrr61Yv8gkK3WtbrNtC05LAO/MQc6o/qYcseI6Pk831qNl7B5EbtTzt7s/UGmoQj2L1Jp+FxHrlHGGwj3skVfz0GsIdtFsOq/8bNLlHs9lJmQI8bg2MQUkWeOPQ= 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 31255FEC; Tue, 20 Feb 2024 08:02:40 -0800 (PST) Received: from [10.1.197.60] (eglon.cambridge.arm.com [10.1.197.60]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id AE18B3F7F4; Tue, 20 Feb 2024 08:01:58 -0800 (PST) Message-ID: <49f42c63-63b9-4cf9-96ad-901b3fc1d50e@arm.com> Date: Tue, 20 Feb 2024 16:01:57 +0000 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v9 02/24] x86/resctrl: kfree() rmid_ptrs from resctrl_exit() Content-Language: en-GB To: Thomas Gleixner , David Hildenbrand , x86@kernel.org, linux-kernel@vger.kernel.org Cc: Fenghua Yu , Reinette Chatre , 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, tan.shaopeng@fujitsu.com, baolin.wang@linux.alibaba.com, Jamie Iles , Xin Hao , peternewman@google.com, dfustini@baylibre.com, amitsinght@marvell.com References: <20240213184438.16675-1-james.morse@arm.com> <20240213184438.16675-3-james.morse@arm.com> <52f81c45-efa7-42c7-86f4-fc1084b1d57a@redhat.com> <59ebda21-6164-4dff-9ba8-956d5a715048@arm.com> <87v86jgmhp.ffs@tglx> From: James Morse In-Reply-To: <87v86jgmhp.ffs@tglx> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On 20/02/2024 15:54, Thomas Gleixner wrote: > On Tue, Feb 20 2024 at 15:46, James Morse wrote: >> On 20/02/2024 15:27, David Hildenbrand wrote: >>> On 13.02.24 19:44, James Morse wrote: >>>> +static void __exit dom_data_exit(void) >>>> +{ >>>> +    mutex_lock(&rdtgroup_mutex); >>>> + >>>> +    kfree(rmid_ptrs); >>>> +    rmid_ptrs = NULL; >>>> + >>>> +    mutex_unlock(&rdtgroup_mutex); >>> >>> Just curious: is grabbing that mutex really required? >>> >>> Against which race are we trying to protect ourselves? >> >> Not a race, but its to protect against having to think about memory ordering! >> >>> I suspect this mutex is not required here: if we could racing with someone else, likely >>> freeing that memory would not be safe either. >> >> All the accesses to that variable take the mutex, its necessary to take the mutex to >> ensure the most recently stored values are seen. In this case the array values don't >> matter, but rmid_ptrs is written under the mutex too. >> There is almost certainly a control dependency that means the CPU calling dom_data_exit() >> will see the value of rmid_ptrs from dom_data_init() - but its much simpler to check that >> all accesses take the mutex. >> >> With MPAM this code can be invoked from an error IRQ signalled by the hardware, so it >> could happen anytime. > > Which does not work because you can't acquire a mutex from hard > interrupt context. Indeed - which is why that happens via schedule_work() [0] My point was that its non-obvious where/when this will happen, so taking the lock and forgetting about it is the simplest thing to do. Thanks, James [0] https://git.kernel.org/pub/scm/linux/kernel/git/morse/linux.git/tree/drivers/platform/mpam/mpam_devices.c?h=mpam/snapshot/v6.7-rc2&id=7da1c7f9d9ef723f829bf44ed96e1fc4a46ef29f#n1299