From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=40.107.193.118 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796394942; b=QiIKj+IK9LuTNF+Yqfqyb90DVVY66cHPzsZ7OReAIFBqc+HdZYsnLFUGrXWAfJ8P9CTf KHtG/Spi1QQgXNonQD2s2SHfEd67WgPTpOlgGL+hW2NCDdC5R3fg6ds9cuKWpJQyRQ5kI uV6VCyTjRg2JlFdHXYzoFAQzRtOAZj96OoCYrWNuLo8jX5MV0fwthq5cobvI9hbwcJc41 uFkx/iPNsTwSodtehDSbthm1gLlLx/WCtry2B/Dp2BzMA6aLNl/GiiAkQsSmiexaHIDcg YXMvYh8JqlpU70UZiaY6P5Tn/f+Rzxvqarxe4p9DejUaqA+9/vBGzvIyieB1Gqck5KA== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796394942; h=DMARC-Filter:DKIM-Signature:Received:Received:Message-ID:Date: User-Agent:Subject:To:Cc:References:From:Content-Language:In-Reply-To: Content-Type:Content-Transfer-Encoding:X-ClientProxiedBy:MIME-Version: X-MS-PublicTrafficType:X-MS-TrafficTypeDiagnostic: X-MS-Office365-Filtering-Correlation-Id:X-MS-Exchange-SenderADCheck: X-MS-Exchange-AntiSpam-Relay:X-Microsoft-Antispam: X-Microsoft-Antispam-Message-Info:X-Forefront-Antispam-Report: X-MS-Exchange-AntiSpam-MessageData-ChunkCount: X-MS-Exchange-AntiSpam-MessageData-0: X-MS-Exchange-AntiSpam-MessageData-1:X-OriginatorOrg: X-MS-Exchange-CrossTenant-Network-Message-Id: X-MS-Exchange-CrossTenant-AuthSource:X-MS-Exchange-CrossTenant-AuthAs: X-MS-Exchange-CrossTenant-OriginalArrivalTime: X-MS-Exchange-CrossTenant-FromEntityHeader: X-MS-Exchange-CrossTenant-Id:X-MS-Exchange-CrossTenant-MailboxType: X-MS-Exchange-CrossTenant-UserPrincipalName: X-MS-Exchange-Transport-CrossTenantHeadersStamped; bh=MXDSsLHZzhAI4i3UhdGsvgAWhpcojWFYTfER64PLc+o=; b=LTCNTUE5edZQZapLmJjrMpnXG/CM3PNLskT60iMFIMjWn6NWrITr9874yU/G/1p/3YEr Xn6qFW0E2Gq32azB+aZWz3SPybULcgqDshLr+WjjfU+6wN3TUaJKtZuxtQwg30WiPzSp3 TapfO2krEGzTiM3K5Ojk3eBkqpzOQOuJSnonFrOS5vLwdTXZW24wxf0nVQhGWAxTWn4Y8 QWCx6eMJd7cGs0AuvX1YkoPXB8LdG/7NQjS9anTUzR0z/ySgVA6ofokZSbmC4gyhTuYrj pACipZm0F4Hvju9RDEDGNbwpqlRVZ8/Qsbdf0HxTWQwlaOze2YVH4FpsCWSY/KrGvxA== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass header.from=efficios.com; spf=pass smtp.mailfrom=efficios.com; dkim=pass header.d=efficios.com header.i=@efficios.com header.a=rsa-sha256 header.s=selector1 header.b=WShjShp1; arc=pass header.oldest-pass=0 smtp.remote-ip=40.107.193.118 Received: from YT6PR01CU002.outbound.protection.outlook.com (mail-canadacentralazon11022118.outbound.protection.outlook.com [40.107.193.118]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (secp384r1) server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CC4F2606A322; Fri, 4 Dec 2026 14:35:41 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org CC4F2606A322 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=efficios.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=efficios.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=efficios.com header.i=@efficios.com header.a=rsa-sha256 header.s=selector1 header.b=WShjShp1 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=FEJf+fKcPky5XhaNenN0k54CH4DMS2d6x3eB4Ts7LFeQWydrzUdlnMXhvGwdbtSSiBXSxzZCf/4hZOB0Mbkhbe6/6wHVYVSxg40VOfaTtcm1o6pVGRuF2DitGQ3bIjkSg78AF07xVn4MMjqfwY1nD67yqvPQYPuGSoi7t/dkMFAbsZz23EC2hywPDpCZ9gG4N/e/t/SSIyOQ4FkuLqdUnZCo4rBEL6XXKB9RW6mN5fjh6Wy+bmRw9PASt7wQFMV2O++uWcBTUUcLgnFLZcH7O1COzkyhl/wojtgyHWdugfFxN4tmE9UJQMiEafNnzq0Ao946ZIOglmW+EPr7CUUtXQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=MXDSsLHZzhAI4i3UhdGsvgAWhpcojWFYTfER64PLc+o=; b=UxBjzhepRa2L5l3Yr51N/zq8LYZqfucteOMHrIiAzB0Dm+98rklDNan4IIVF7li8XxJpCIhVHOSXklYOhyVY6b583/uTcSKVRg2/WRAI731buPSPAIi7KwkAGD9hGIGBsPq59lqWVxrjuegbrAriujrbjzuPytG+3PxEm75OK+NhFYm9QqTUqn1IyOzgPyIqafgbWGWXl5Zj57w3RFc1WnHTbQpRxmGtBbNaF8vob0qviirOM0Xu/BKmHKeYJ+C/BTvnlZmoEUQXWrbB7Moqxd1zXO3SwQTO336vx9DBh4Fvd28e6/F6kj+LNkB9fPyWqDXMLa/EP3rEGTu4+AQBJQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=efficios.com; dmarc=pass action=none header.from=efficios.com; dkim=pass header.d=efficios.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=efficios.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=MXDSsLHZzhAI4i3UhdGsvgAWhpcojWFYTfER64PLc+o=; b=WShjShp1To7S9qaNzliBPnfx5AoxY4gK4z17BO038+UiE+Nqz+2aADafxqFxs3LS8sGy3mPWWYO4II24F4wp8KRBSx7Aqf2XVjO29hGxh1tPJQ8w+PwXrVYdVDcgjoLlSGahYmF/5fB7Kv5evN8f+PzM6PfXkYwSHTHqr7aSJA4KW2thpQ5r25V51ToiVlKSnmys4ZU1+v8qt82DMPITojWImBA7OqhkyxBnd+aZiCeUHEMtgEQOc5O8UiV2ItN2waQLyu1BUsmuA4T3hoHRS+9pMorpZFWAPdGaJXQs7Or/reQw8L0hjonxKJR8R1Ckac3eTTfLwx630vUxZgq18A== Authentication-Results: mx.microsoft.com 1; dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=efficios.com; Received: from YT6PR01MB491026.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:b01:1d0::10) by YQBPR0101MB5624.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:c01:44::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.688.13; Fri, 4 Dec 2026 14:35:38 +0000 Received: from YT6PR01MB491026.CANPRD01.PROD.OUTLOOK.COM ([fe80::6b9e:a901:67c5:7ddc]) by YT6PR01MB491026.CANPRD01.PROD.OUTLOOK.COM ([fe80::6b9e:a901:67c5:7ddc%6]) with mapi id 15.21.0688.011; Fri, 4 Dec 2026 14:35:38 +0000 Message-ID: <054ad46a-46bd-4e04-8479-4bc3b19637fb@efficios.com> Date: Fri, 4 Dec 2026 09:35:36 -0500 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2 08/16] LoongArch: membarrier: Add full memory barrier in switch_mm() To: Huacai Chen Cc: Peter Zijlstra , Ingo Molnar , WANG Xuerui , "Paul E. McKenney" , loongarch@lists.linux.dev, linux-kernel@vger.kernel.org, stable@vger.kernel.org References: <20261127185822.158216-1-mathieu.desnoyers@efficios.com> <20261127185822.158216-9-mathieu.desnoyers@efficios.com> From: Mathieu Desnoyers Content-Language: en-US In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-ClientProxiedBy: YQZPR01CA0172.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:c01:8b::10) To YT6PR01MB491026.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:b01:1d0::10) X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: YT6PR01MB491026:EE_|YQBPR0101MB5624:EE_ X-MS-Office365-Filtering-Correlation-Id: 2c020317-8aed-4ae0-6073-08df5213dd4c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|10070799003|1800799024|366016|376014|23010399003|5023799004|4143699003|261009223027099003|22082099003|18002099003|10067099003|56012099006|261021123027099003|261102123227099003|261026140227099003|261021121427099003|261022105027099003|261028144727099003|261026121527099003; X-Microsoft-Antispam-Message-Info: dxsm9ltJEvSgzNj+L5EJ45loj0zoqpCgLPV8Sp6KnrucpEGrmKKtmOYUiTx1kvs19TITdhdygGlt0zeVXP6c17UD0h5FmkYFmXQB/QXA/bPp1vhyyxdFFJHgPif0vaR/u5cf/mSKOJoN2J+sznRkOmkANG0vzSScjtn8qhgGXpbPMthVQs2Px2I0iknUIfprszpmuBmcNHHlsz8Imdt3u124W2idgkSp0QeXjXj5DtKsLSbDeNMkoi68gMsIeNv+3kdizc9Mju7quNWQi8WRI4lE7dZKkLM0dGI7nDkb9QR508DpxTk+7OIGTlxil+BGbfSZsE0L0Yr1I1n3II8JXrSIWbNrdl51C/BfLSWNplySSL81V/309D+2M+Eg4Sdulg1vrqKMBsrhLI2YNQ61VhaDOQPkTFQl/hh/OLmdw9snj3XHKEAX+/PS8WFYvhp65I6bJoBstlEh9ElZaqFRYCopJGXFZgRUWu02R1Kh1a8fA6Q9hyOIwWMJ91ZyMlOWo4NiK9oDvFmo9upfw3tE0hua1vjyRzkKAnWKrKQxPDSoKst5jLY9N5n1LnbrIKkbSJFm2fRR4ucV5F82zxVd7S0HzUXbby3KNCiCL5ADtkY= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:YT6PR01MB491026.CANPRD01.PROD.OUTLOOK.COM;PTR:;CAT:NONE;SFS:(13230040)(10070799003)(1800799024)(366016)(376014)(23010399003)(5023799004)(4143699003)(261009223027099003)(22082099003)(18002099003)(10067099003)(56012099006)(261021123027099003)(261102123227099003)(261026140227099003)(261021121427099003)(261022105027099003)(261028144727099003)(261026121527099003);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 2 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?dkdwYmV6UVdFRW5iU0JlMVAwZ3ViMFZHNzFDbWxQcmErclJsU3BiRndwd2VD?= =?utf-8?B?UXo2VWZEWTUzTGpXa0xZOFVYM3hvbEUwV1BWZGxTbFNQc0NjTWJacHVsaVJ2?= =?utf-8?B?NkNYVmpCdEFsRm42Q1pmNkZub205K1BPU2FFTUNuZlhyb3Q3UlhoSlZ2bEpY?= =?utf-8?B?eGE5Y0Q5WE42N0wvODNHS0x4WDdkKys0Kzl5aVBHZEM2MmF3VmV0a0ZCblVi?= =?utf-8?B?Y3pJaDhnaGdzMFludXZwd0xKUnUvYnBLcTMyb0dFWThTYkY0TWk1dmRSRWVq?= =?utf-8?B?ZVppZVRKYngwclVwbGs2cFpVRmhoZUwzWDl6UDdndlFmZmlleFdoUlB0eVNB?= =?utf-8?B?UlNrSC9HNW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E3WDJxYXVmbVVISGQy?= =?utf-8?B?SFl1YkhLdzV4bVNqQ05PZHE2T0FVaXVhM0hobFVDbVZKZzBsQkhpUXRxazVp?= =?utf-8?B?MlpZbG5EVnYwWlhXVExqNjRTRVlZWjBjWG1Nck5RMU1uZ1dHN3JSZkFlS1Nn?= =?utf-8?B?RFZKNTQ5cXA3SU5GRTBoQU1EZXJ1MGpLTUduc21TSTY5b3BQb0x0dGV0UDZq?= =?utf-8?Q?D3LHUgq142aE40B7RxAtpvuQYxUZmTKPj21G0x4IaN3vH?= X-MS-Exchange-AntiSpam-MessageData-1: NXvN8fajjfyXhJbtmcG3sGOd8elC6CBTaCM= X-OriginatorOrg: efficios.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2c020317-8aed-4ae0-6073-08df5213dd4c X-MS-Exchange-CrossTenant-AuthSource: YT6PR01MB491026.CANPRD01.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Dec 2026 14:35:38.1212 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4f278736-4ab6-415c-957e-1f55336bd31e X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: EM3PsdYNmOfpLuOiQ85496m6sbS2h8JMqDerenU6KPVyqBqNvIgP98javcxAq7+vexHU1FtEFO9qWxkerSEjITO2hnd+BtIRXsqzgWcB7SE= X-MS-Exchange-Transport-CrossTenantHeadersStamped: YQBPR0101MB5624 Hi Huacai, On 2026-12-04, Huacai Chen wrote: > I should say sorry because my previous reply has some mistakes. > Writing to PGDL/PGDH/ASID doesn't imply a "dbar 0", instead, it > implies a "ibar 0". > But "ibar 0" is also enough for the current purpose. It doesn't block > previous read, but blocks previous write, and for hazard protection it > flush (not just stall) the pipeline, so blocks succeeding read and > write. > So the effect is similar to "dbar 0b11000", and it will still be true > in future (yes, I think our manuals should be updated). Thank you for the correction. I agree that "dbar 0b11000" is enough here. membarrier needs the store to rq->curr to be ordered before the user-space accesses which follow. That store is a write, so the reads which stay unordered do not matter. I checked it with the Linux kernel memory model. I added a fence which orders previous writes before all later accesses, and nothing else. The membarrier scenario of patch 8 cannot fail with it. It fails with "dbar 0b10010", the barrier of smp_store_release(). I can send these litmus tests if you want them. The model assumes one more property. Before a later access runs, the previous stores must be visible to the other CPUs. Ordering them on the local CPU only is not enough. Is that what "blocks previous write" means? Two more questions: 1. Can this guarantee be written down, in the manual or in a document from Loongson which the kernel can cite? Without it, a later change to switch_mm_irqs_off() can drop these CSR writes, and nobody will know that membarrier needs them. 2. Does it also hold in a KVM guest, when the guest writes PGDL and ASID? If the answers are yes, the planned next version drops this patch. It adds a comment in atomic_update_pgd_asid() instead. The comment says that membarrier relies on these CSR writes as a barrier, and cites the document. Patch 10 ("Documentation/membarrier: Update the per-architecture barrier list") then names these CSR writes as the LoongArch barrier. Would you ack such a comment? Until the guarantee is written down, I would rather keep the smp_mb(). It runs only when the next mm is registered for an expedited membarrier command, so other processes do not pay for it. Thanks, Mathieu -- Mathieu Desnoyers EfficiOS Inc. https://www.efficios.com