From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (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 4CC33272803 for ; Tue, 30 Jun 2026 06:27:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782800851; cv=none; b=WZJUl3jcfywEjnTov0l64/5d/VDjsda2BKXBkS+G/TEd5Nkq8dd3SMzqwg0tc2+NDMxhNN7BDCLtl+4ZieMCUGgodMOdbTdzOC0BJpxYbsF0bM6b6pPgVSzra2GfF9nprrOQ53JX8OodUVqJdZFrnMOpeoqh4oGpcw4juyswsFo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782800851; c=relaxed/simple; bh=k7Y3i6gcUQFWQIhUxHIA18uLOLsRwKJaGLkiwpaIM+o=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Rwu+Y0hEAkvo9LAhFhs9sEqj6H2UdaG0Dkbqc3Mnyuhwaft/9jFROLoAZfF6m5v/wsKv70YKsuSvJySIbWAs3EttxkA1IspX3kxAXU+LfLFxg6ZYVaET4l7Ov4HVfc3dHJWWzmH52eZkCq4O8R2PVdM9qs3TfXh8d3+EDZO9lKA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=O2ab3cAT; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=XF6FgpC/; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="O2ab3cAT"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="XF6FgpC/" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1782800849; 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: in-reply-to:in-reply-to:references:references; bh=g85B6h0E6wmvIawCj3aK3oknIgQ+/nlCgtdjk9sHnt4=; b=O2ab3cAT8rPVgYh6trCvQBG1PdHB/GORqABT8unyUkt3+0OGHqRn7pX8FVVtMbDFaryuqc G2o1KvdsmVALnlCugR+3gmU8MFC+mQFApqP3JU1pgz8lPuZrlphRceruxVjt9iQEMwYNFU sROKWaVO2FAZNOJqO5QlaoLjmp8GIRc= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-441-hRysmz4kP16SzS18Ac5P_g-1; Tue, 30 Jun 2026 02:27:27 -0400 X-MC-Unique: hRysmz4kP16SzS18Ac5P_g-1 X-Mimecast-MFC-AGG-ID: hRysmz4kP16SzS18Ac5P_g_1782800846 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-493b0fe95b6so12431355e9.1 for ; Mon, 29 Jun 2026 23:27:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1782800846; x=1783405646; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=g85B6h0E6wmvIawCj3aK3oknIgQ+/nlCgtdjk9sHnt4=; b=XF6FgpC/nv5qhSBafzfOcEInCXS1Mh6oSBCp9yoPVXs1KT8spzoqKXo94lqSHnfdHZ tvGqaB5lsGb+FEo1ZOBLb0QbgRS2U426hatU/nAShkWJ9B3E1SDu2tHzvt3xgm1B2w/D j8RPU/V263neGY10c8HrIgVHXP8ZGyCN4YgW7eWz8PPEu512V6EVEquaWS2M2ed/p8P8 YlhaYSkBnhkcUvOZjfuKqQAwgGqnEOxLFqqETuYqQxRNtWB8++8qcG4DyAhlTd6w6UVS ao+mbQopICvZItxE/1Y7UtpCr3OyrQNwWOieNiKhbPAHeVfoSwpehbCgXbO3u5kndAAZ +pDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782800846; x=1783405646; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=g85B6h0E6wmvIawCj3aK3oknIgQ+/nlCgtdjk9sHnt4=; b=XoBWydZij8sJSvePdYKiTy6fbIrekDCG7YuodPI+XrZTDIw3nto/CPvHSPzL5tbDrL IUk96T5TLXxO0RW8KGW+zCRYTMhEFdjvCC6KZkCPFv/BBQKntKGea/ACJPwCyrL8S1yP 7gSydNyuH4+Z/g++SNbGRfi8fKrDC/+5mwzC6HJHBAn0QqHYXjuUddrzmB3uvlHTUQhz n1wUuMWsGS87bKPrDnDPTcrkiAPWpseLwk3Pq7eCLZy4xV+WhsWjqoFHA0IAYRCHFcWu EZjueQfAmprWIMSFePmg+5lMZaNnlTCLMJZga7Etjc3DCYboBGMnwl7ciAuR+VNDCT6g PxsQ== X-Gm-Message-State: AOJu0Yzs/MnnaPQqXXBAYeqnfkglY3rmZKlBgN52RCNvvI1VFALwBSUU FkgoDQ2w9ouN0GXm2Gh4+k/xzgDcpdn0g/L5lWfVfRxTCLOacCDTk2wFW8u/YAXh2k6J4bLC1vr P6Fqi7YYwNgkwgiUZVgE71Em1534skB2o/3wVlHWJaHaXPKrWa30yNRoFIjqoUpc5fA== X-Gm-Gg: AfdE7cmKchy/OF6xoBNcHlqto6Xy9goI0F3kGJFnbnp8blLwNZlfQOnR03OgqSNt2q/ yINCkKRkf1NodgVHIjVD30LuK5Em25EpBjsVwtVthJ8Wl7LJ597o5Ewmb+Ns47XLdiOqRgrjIkP 2/yuR4A4z0gR9czTTHwQqUp2VkRUAXklN8XR+YW1/yd2Es6Gfe+pOxGUJH6vIFMLItXK661NzFP IJWwhTbl4V7KTETHpDEhAyTi3epgAiHRwGjcm2VHlO3e5gC3jTdDkgaKyflHbESObsEqcB3prKT eg6jJGtJzQkcs7xIl92nnSLlnm+FoiO67sBsQf7wTOm33P+7DqLIlIluI5mxLiUX5cMGO9Mto1k 0nA== X-Received: by 2002:a05:600c:a408:b0:492:5bc8:5e77 with SMTP id 5b1f17b1804b1-493b82b8b49mr23585475e9.29.1782800846080; Mon, 29 Jun 2026 23:27:26 -0700 (PDT) X-Received: by 2002:a05:600c:a408:b0:492:5bc8:5e77 with SMTP id 5b1f17b1804b1-493b82b8b49mr23585075e9.29.1782800845541; Mon, 29 Jun 2026 23:27:25 -0700 (PDT) Received: from redhat.com ([31.187.78.205]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-493bb4f174esm13896245e9.2.2026.06.29.23.27.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Jun 2026 23:27:24 -0700 (PDT) Date: Tue, 30 Jun 2026 02:27:20 -0400 From: "Michael S. Tsirkin" To: "David Hildenbrand (Arm)" Cc: linux-kernel@vger.kernel.org, Miaohe Lin , Naoya Horiguchi , Andrew Morton , Oscar Salvador , Andi Kleen , Hidehiro Kawai , Rik van Riel , Vlastimil Babka , Lorenzo Stoakes , "Liam R. Howlett" , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , Brendan Jackman , Johannes Weiner , Zi Yan , Baolin Wang , Nico Pache , Ryan Roberts , Dev Jain , Barry Song , Lance Yang , Christoph Lameter , David Rientjes , Roman Gushchin , Harry Yoo , Hao Li , Kiryl Shutsemau , Byungchul Park , linux-mm@kvack.org, linux-cxl@vger.kernel.org Subject: Re: [PATCH 0/2] mm: memory-failure: fix HWPoison flag race with non-atomic page flag ops Message-ID: <20260630022129-mutt-send-email-mst@kernel.org> References: <0b5f8b4b-d7dc-4b79-9555-a5b36265f3a9@kernel.org> <20260629030657-mutt-send-email-mst@kernel.org> <4f5ba5d6-246c-4430-9737-e8dd8e4c5142@kernel.org> <20260629092856-mutt-send-email-mst@kernel.org> <54c8cbee-9b26-458c-93ba-5aa594f5d1e8@kernel.org> <0a309ed3-378e-4d88-95a0-65bf47c5496d@kernel.org> <20260629193347-mutt-send-email-mst@kernel.org> <5c8ca96b-381a-4fd3-a218-6aaa87a9a3b7@kernel.org> 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=us-ascii Content-Disposition: inline In-Reply-To: <5c8ca96b-381a-4fd3-a218-6aaa87a9a3b7@kernel.org> On Tue, Jun 30, 2026 at 08:17:42AM +0200, David Hildenbrand (Arm) wrote: > On 6/30/26 01:34, Michael S. Tsirkin wrote: > > On Mon, Jun 29, 2026 at 11:43:32PM +0200, David Hildenbrand (Arm) wrote: > >> On 6/29/26 23:22, David Hildenbrand (Arm) wrote: > >>> [...] > >>> > >>> > >>> Fully agreed. I was hoping RCU was cheaper (I mean, we were once told that RCU > >>> read side locking is essentially for free ... well in some configs :) ) > >>> > >>> The question if we could optimize it reasonably enough ... > >>> > >>> > >>> ... for example, by doing the rcu read lock + unlock around the > >>> > >>> for (i = 1; i < (1 << order); i++) { > >>> > >>> loop on the alloc path. But I suspect it's not going to make that much of a > >>> difference. > >>> > >>> I concluded, similar to Andi, that stop_machine() is too big of a hammer. > >>> > >>> I wonder if something could be built out of preempt_disable() and sync SMP > >>> calls. hmm :( > >> > >> Scrap that, shouldn't work I think ... > >> > > > > Wait a sec, what about call_rcu_tasks? Use that and re-check the bit is > > still set? > > So, in essence the idea I had yestarday when it was late was the following: > > Assume we > > 1) Can have a way to guarantee that a function on a CPU cannot execute within > our critical section (while updating the flags) > > 2) We can request to execute a function on each CPU and wait for completion > > I think we could just let each CPU execute our desired action (e.g., try setting > the bit). > > E.g., > > local_irq_save(flags); > page->flags &= whatever; > local_irq_restore(flags); > > And assume we want to set the bit, do a > > SetPageHWPoison(page); > smp_call_function(set_hwpoison_smp_sync, page, 1); > > whereby > > static void set_hwpoison_smp_sync(void *info) > { > SetPageHWPoison(page); > } > > > The idea is (that needs double checking) that a CPU will execute the > SetPageHWPoison() either before the local_irq_save() or after the > local_irq_restore(). So it's own non-atomic update cannot get interrupted. > > Now, IIUC when it comes to "how expensive is this" I think we have (cheap to > expensive): > > 1) preempt_disable() > 2) rcu_read_lock() > 3) local_irq_save() > > > So the above wouldn't be better than an rcu-based approach we have right now. > We'd need something that relies on disabled preemption only. > > Huh, but I read that "anything that disables preemption also marks an RCU-sched > read-side critical section including preempt_disable() and preempt_enable()". > > So for our use case we should be able to use preempt_disable() instead of > local_irq_save(). That should already work for your existing implementation. > > -- > Cheers, > > David We have: #else /* #ifdef CONFIG_PREEMPT_RCU */ static inline void __rcu_read_lock(void) { preempt_disable(); } ... static __always_inline void rcu_read_lock(void) __acquires_shared(RCU) { __rcu_read_lock(); __acquire_shared(RCU); rcu_lock_acquire(&rcu_lock_map); RCU_LOCKDEP_WARN(!rcu_is_watching(), "rcu_read_lock() used illegally while idle"); } So on non-debug build witout CONFIG_PREEMPT_RCU (what I tested), rcu_lock is exactly same as preempt_disable. It's relatively cheap but not free. preempt_disable is not going to be cheaper. I can test if you want but it seems clear. But IIUC task rcu might be cheaper - IIUC it does not need rcu lock/unlock at all, it relies on readers to invoke the scheduler instead. No? -- MST