From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ua1-f50.google.com (mail-ua1-f50.google.com [209.85.222.50]) (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 79BAF21324F for ; Fri, 10 Jan 2025 17:24:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.50 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736529865; cv=none; b=tvdy4obIVmaa8pHQU8xRS2JAJLJnJ5GiLpwAMZPR5wLY0KXumGqn4vz6kol6qezc37uWfzwKiicHkvIs3i1TFA1lsa8HaOLUtgx+yyNp1qsgpNMqvfucg8C6CVuLjcKgRrtLG6fM39y+m7D8yon703/CygriojjsPBh1c+vORh4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736529865; c=relaxed/simple; bh=m4Ald6wlTEBRZVWNpDJLSpvt0BZFUkiR9ql1vQT7zX8=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=b4yjPFADSgSIZI18Hp6snf82uWeXEttSifomCRSXfiRI90A1xwfE8mZHsdjymRENpO2K8ZlNAe83paB1t6etBgF/lo0N+GxgyBy//a92dIEcvWerBm3F2GOGlzPVCLT+wvyK5U2lIXqa3E6wSHUywupagiGfIzovLyjcGqVfOGA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=UR4FSP9P; arc=none smtp.client-ip=209.85.222.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="UR4FSP9P" Received: by mail-ua1-f50.google.com with SMTP id a1e0cc1a2514c-85c436db302so1085807241.0 for ; Fri, 10 Jan 2025 09:24:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1736529862; x=1737134662; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:organization:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:from:to:cc:subject:date:message-id:reply-to; bh=feJeFpoafKL4YPGmniZZ6N9x1bbbvEkPga0rP7K8/OA=; b=UR4FSP9PqCBxG2BxGYiXXNs5I12PLwrTrB4NhqfYXbRdkHm6P/fOrORaEPv4pvw2lF OOIKnboHrJevcDDshXlXVcJtywG0d6UVUFgTWLDUQxFQDS0Xtb1hvyxX+bSM4TYiqpnw TBkuqCgxHt4LFCMC3GN7y9LrNeKTnVZeYiehxlGlV1vR6vNCGrcf/JbcRr4NDUorUgeg CrrHoyNYDRBmlp3iVmUtR2ln11nGVSRw1kRTuUwM32vFfguWBlM1u8dEHODHDj8GjcZD 2XCDpEImdd8bgy1FTvN60OTu2klVExYRPdQffObFqJCgn6b4n0UcTNqJNVaLEk+ZHjpT BxOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736529862; x=1737134662; h=content-transfer-encoding:in-reply-to:organization:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=feJeFpoafKL4YPGmniZZ6N9x1bbbvEkPga0rP7K8/OA=; b=OMffDBP6L15q2WQuovAvhwv10BbOAGOyrsHe8NqNtVog/ed6Ka6wW63XgAoR3b4wWF VBNYqEOod55zKXzgqjg5CMUKHF/ehNIu1gH0JsPFPphLEB7O9QUIBxlVwtaNi8qvI+0Y ybZVq6EUH4HsdmXe2hwW3ArWCPrUMoPCGcpw22L2D7meDHA5djoXefkf0V1HhqKwXqQk U9A1h+jqd6O1UdaTcETbz+tcfFuaegPsBwoRM8ysgYmUuG/khjC+SJHO0tBeKPUZ7bnz dy3CPg1RVeXbl2JUJ6gTqftvuLcVvUEVbxG9yo5h38R+As4X9pUwHSRllBHhQjCyKAob D+yQ== X-Forwarded-Encrypted: i=1; AJvYcCWt+NHOoupJEeKJ6Q92u+lxvLHygglerisYTC0ZaGRtnYUo+YRaZHTtZF9bV+0d+dbSPKoHVf0FTR+7GkQ=@vger.kernel.org X-Gm-Message-State: AOJu0YzMxWnnYf1Bm04T8e0N39tkzQSHzmG/z8/4YuYaukckjs2p4TfK 7ysHXXUMvY6VUr10STzaL6KCFzEPU9vaOQWsS8lh4txs3oORkJgbcYIZ2oHZPwU4RmIpTeO0DtF 8 X-Gm-Gg: ASbGncuzEpqajtQ6vZbkUq/uMkge+xC9v66dyynIEfA3IEgn19es1Udf5zgqekAkWjB LUayrE3D2vi6g2zgN2PZrIlxxiobp5enhRf9yJoqKBBqxFVKP3lHP0M/BAyOHmU2T9M4ryLd3VE EsPHr1YE76GTYyXf08YaPKTfTwvc5B8f1Sax+3w0ZO3o14StGOkmj1GB85kNIMID26GQhiT9O8/ JCgOyhT8ISgTqzKPhqtQd1elJmaJP2zZqGDvabeps7C6izwq0SgrsWRg88FRjq17cKF/U64kR3K yUxuRBbz4oSH4SfC4XLUqZ00zwVqEowruL/Ab7IBiSzN7Xr3GNL8NbuQWNVBw44l X-Google-Smtp-Source: AGHT+IEudz2ARucWQgvXio4Ar8D2nRjOx72KPi9H6gxDM6XLtAIKiigMEtzz0uOSNYMP7/ckE/zTvg== X-Received: by 2002:a05:6122:41d:b0:515:25f5:46f6 with SMTP id 71dfb90a1353d-51c7c818af3mr5926319e0c.4.1736529862326; Fri, 10 Jan 2025 09:24:22 -0800 (PST) Received: from ?IPV6:2804:1b3:a7c0:f41c:e104:7f6c:f2c3:2134? ([2804:1b3:a7c0:f41c:e104:7f6c:f2c3:2134]) by smtp.gmail.com with ESMTPSA id 71dfb90a1353d-51c7fcfe545sm2391569e0c.38.2025.01.10.09.24.18 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 10 Jan 2025 09:24:21 -0800 (PST) Message-ID: <81f06e13-0e05-4421-9a65-9fa65ef5ebae@linaro.org> Date: Fri, 10 Jan 2025 14:24:17 -0300 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: Prevent inconsistent CPU state after sequence of dlclose/dlopen To: Mathieu Desnoyers , Florian Weimer Cc: Peter Zijlstra , "libc-alpha@sourceware.org" , "carlos@redhat.com" , Mark Rutland , linux-kernel , x86@kernel.org, paulmck , Michael Jeanson References: <20250110165412.GC4213@noisy.programming.kicks-ass.net> <8c1ad304-61bb-4bdf-aa75-8633f3d0196c@efficios.com> <87ldvitx0t.fsf@oldenburg.str.redhat.com> Content-Language: en-US From: Adhemerval Zanella Netto Organization: Linaro In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On 10/01/25 14:15, Mathieu Desnoyers wrote: > On 2025-01-10 12:10, Florian Weimer wrote: >> * Mathieu Desnoyers: >> >>> On 2025-01-10 11:54, Peter Zijlstra wrote: >>>> On Fri, Jan 10, 2025 at 10:55:36AM -0500, Mathieu Desnoyers wrote: >>>>> Hi, >>>>> >>>>> I was discussing with Mark Rutland recently, and he pointed out that a >>>>> sequence of dlclose/dlopen mapping new code at the same addresses in >>>>> multithreaded environments is an issue on ARM, and possibly on Intel/AMD >>>>> with the newer TLB broadcast maintenance. >>>> What is the exact race? Should not munmap() invalidate the TLBs >>>> before >>>> it allows overlapping mmap() to complete? >>> >>> The race Mark mentioned (on ARM) is AFAIU the following scenario: >>> >>> CPU 0                     CPU 1 >>> >>> - dlopen() >>>    - mmap PROT_EXEC @addr >>>                            - fetch insn @addr, CPU state expects unchanged insn. >>>                            - execute unrelated code >>> - dlclose(addr) >>>    - munmap @addr >>> - dlopen() >>>    - mmap PROT_EXEC @addr >>>                            - fetch new insn @addr. Incoherent CPU state. >> >> Unmapping an object while code is executing in it is undefined. > > That's not the scenario though. In this scenario, CPU 1 executes > _unrelated code_ while we unmap @addr. But in this scenario you still a concurrent dlclose while you have a running thread executing code from that module, right? Or am I still missing something here? Or, are you saying that even after dlopen returns (assuming the scenario where it maps the code in a previous used mapping), the CPU is in an inconsistent state unless MEMBARRIER_CMD_PRIVATE_EXPEDITED_SYNC_CORE is issued?