Received: by 2002:a05:7412:cfc7:b0:fc:a2b0:25d7 with SMTP id by7csp1817937rdb; Tue, 20 Feb 2024 07:54:21 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVZWrDTIxtHhk6y29u6OLl2hoEknVO1E9OuK62Ghw6Ps/CtlTaHFg0dB/PasE8jkx3K6j/4+Pbcf+sSrMlMxiDZ1viX7afCYWMYgdym0Q== X-Google-Smtp-Source: AGHT+IGpFK/Oh+S46yCluWuSKyka6vfBpFzT3Gbwr6VSKtjSTExKESeiqsbf10RnBfWOz4r7ma1y X-Received: by 2002:a17:906:b885:b0:a3e:9952:e146 with SMTP id hb5-20020a170906b88500b00a3e9952e146mr5710076ejb.26.1708444460927; Tue, 20 Feb 2024 07:54:20 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708444460; cv=pass; d=google.com; s=arc-20160816; b=qys8D18psfO5wmnfAxNFhX+gsHjqXepmlDbbqx3pkPlu24diwpMG3a8Z8xnLzgZJmf mPMmSMF9vLHNzQHvJkwCoSY1qmL+KxRubQZ4CrSJbskpqLPW9paO7czYk1EBXfFHMRgj VRCNW1ngUmOLebrTOaVTcUWZCjeA4KRZMBou8tJa5eRmbjX+2cVXGTpFWUuL5o/qPFkd Tomkd+yRPbvsDw6HoUNtAdT47DmOFsvKvn9ISkZ3/SRV52BglwApKcTf127wUr54ecbP N9GwM2M4oJNhEQH2rmxw72jzYdvCT4OHDIlcZlTf0bnbZ2dKDKnrof3irxVY2LlDbWef 7OhA== 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:references :in-reply-to:subject:cc:to:dkim-signature:dkim-signature:from; bh=IxZf+GSRiuJn0QynLFhu7uKPGCPz3hSj1LX5ayl6vRs=; fh=FmKrlC8Yg7zX2nwUS9HH2t4ZLi7JqeRj32vQHxupbOo=; b=HZhaTNNexLpxwK7bdVVjH+yPHml5nHdKZFE+IPujVrXpFn2kUFJel92147svjmqBTb FQ9DzihmHtFWlrS0vqF0cpVRBTF42M5Z/eIwe1Gz4DTCdKQxnpfpGq5NJR6HuUulFSgX X5WL45RPVvoAoc6p6pHJvKx9d5Hg5Ccd+qdMq+VX1wZ+Q8cA6Ne5aSccguESE9kwwzXh uk+WI4wPJWxaWn4f85sk8rwGOmSYO4GPFa6WiBORoa4a9tRuhNNqfv6IqpaxQfojJ+1e X7FY6tcEBCopFSf6krABvmwYaJYQMKVR8NIuhD7oggLPTBjneAY01zOB2mL8IuZAcHA1 42uQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=CStDWttW; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=Lx75ninb; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-73278-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-73278-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id i20-20020a170906a29400b00a3ec216c61bsi1553447ejz.530.2024.02.20.07.54.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Feb 2024 07:54:20 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-73278-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=CStDWttW; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=Lx75ninb; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-73278-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-73278-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de 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 A92DA1F22839 for ; Tue, 20 Feb 2024 15:54:20 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 680BD762E5; Tue, 20 Feb 2024 15:54:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="CStDWttW"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="Lx75ninb" Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 30AD776033 for ; Tue, 20 Feb 2024 15:54:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708444453; cv=none; b=nxKcox47OG+BcsbEC9jcsPiW/RMhr8H6CXS70lc+0lyLbjEsHz5HPPuxq2lb1k2KiLhyZ3q45DZaw4Fe1K/akmbDFccHHi8Tuu838nV/Sa30yQQL60gV5Rs8HNjT52YdjL+UgoG5jalOTu+MNoIe5KMqBNI4tDPoS+8MAwnPgUg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708444453; c=relaxed/simple; bh=12zW48ePexZ0k+y2CYm6y/WG/nHpA+YjLh0HmgwcExY=; h=From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID: MIME-Version:Content-Type; b=POtdTa+swuw5QdiQXH0khUkMh8JLx7Fi5i6DCZXUwlGjAzSBU2/XPiYGOLvaPg8xpwAEOS7jo//xnWI5ymZpdaaS7tuDvC0V84H4oc98hLeI719pUSdn50AMpwDSA+sLG9J/HrbWC1lvf8ah5k0e1TrD3QaPFebHQQEqeaTiE7Q= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=CStDWttW; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=Lx75ninb; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de From: Thomas Gleixner DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1708444450; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=IxZf+GSRiuJn0QynLFhu7uKPGCPz3hSj1LX5ayl6vRs=; b=CStDWttWR/onVKZm1927ofC1lS+PrG4n+0gUY9RNk4JBwHvGuxC4z1GBFtUZCAQ1L2BN1z CFLcvtjBEKYWpKLSijjM03GQJziFBB5sHukR4ua3wSqO6TlGTdz7Wl9bWbtcMgd/npqRFD cFQaH180A78K0XltTlbWBVVMc4WU7/tJo4TPvml9d6BcGcYCJcg7O+oZGh9B+JbmtkFSmb 69zXBXlb/qVmN5of3tuz3BwuW/OSyvC58z1BHLDbOVHtIGlM1LISKeUzZUeBG+8J1Cy/7K mquCNvyNjwCy0C4omZUe1xFLpPEmIjx9ye0Z8HxF106IXVKOevxIiHZ9dtOopw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1708444450; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=IxZf+GSRiuJn0QynLFhu7uKPGCPz3hSj1LX5ayl6vRs=; b=Lx75ninblEBiACICOlD1GKkm6rCtTyj3Fp0hnQiVFMHTmj4AvvyDsjavwX6bp93cAhUnjI 77DUlyiYXiHmiLDw== To: James Morse , 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 Subject: Re: [PATCH v9 02/24] x86/resctrl: kfree() rmid_ptrs from resctrl_exit() In-Reply-To: <59ebda21-6164-4dff-9ba8-956d5a715048@arm.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> Date: Tue, 20 Feb 2024 16:54:10 +0100 Message-ID: <87v86jgmhp.ffs@tglx> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable 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) >>> +{ >>> +=C2=A0=C2=A0=C2=A0 mutex_lock(&rdtgroup_mutex); >>> + >>> +=C2=A0=C2=A0=C2=A0 kfree(rmid_ptrs); >>> +=C2=A0=C2=A0=C2=A0 rmid_ptrs =3D NULL; >>> + >>> +=C2=A0=C2=A0=C2=A0 mutex_unlock(&rdtgroup_mutex); >>=20 >> Just curious: is grabbing that mutex really required? >>=20 >> Against which race are we trying to protect ourselves? > > Not a race, but its to protect against having to think about memory order= ing! > >> I suspect this mutex is not required here: if we could racing with someo= ne else, likely >> freeing that memory would not be safe either. > > All the accesses to that variable take the mutex, its necessary to take t= he mutex to > ensure the most recently stored values are seen. In this case the array v= alues 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 simpl= er to check that > all accesses take the mutex. > > With MPAM this code can be invoked from an error IRQ signalled by the har= dware, so it > could happen anytime. Which does not work because you can't acquire a mutex from hard interrupt context. Thanks, tglx