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.133.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 D16623815F3 for ; Tue, 30 Jun 2026 07:25:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782804316; cv=none; b=hRnWps8Ue0V6yMKMOEE43hWlPyJ0WpB4f/MQGrQbbt865xj4ccXVyJ9gUg1STkjx6NisWoZ9sTgHHFZzTs+lxiz0cUPMhPUkYQpJz12DitEAdKcnRnhcs9NRnbvQ9ud9eq83tW2KaJu80scu6IPDfz9Q5CyqdINmb8PlOke1sD4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782804316; c=relaxed/simple; bh=LXjwGtnES6N1Kc9ABDRgfM1xnVQrZ9A6GsoyVrwU4No=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=GubEgC2eqvp2SRtX61yXd+K2FjrT0GD0bRqG7Si6gn+XVAhmXfsWTRXBLajoo0Q8m+QgxImnUWEhjm3KgI5Bv4esa4kA6GXuoxwGVc/cIsIMFb8GmC6WjUZyLaA9wk4HUOb4oGhMc5uiFYC0HtrPmENlUmB/H+f4hnmFxgZpZ3Y= 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=LaHs9OTL; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=iZFMNooK; arc=none smtp.client-ip=170.10.133.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="LaHs9OTL"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="iZFMNooK" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1782804314; 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=T8IRfAFAOswM/FHwO19+KBl7CbCbKiUJMFkwpdewsoE=; b=LaHs9OTLL4cE4wxiwlUo+IYr++zInBZT2SUC003Yy5BpgnOnnzhxeHgfLdWJeUal92jRCg Vyl+CFV/etTHvIKU9OLjKs1dcXFMzHXT/ncvrNU0xN2cWC6ZLNwcQmXzWnIB7nN04Imcpd H9hI5YkfpDodDI6O2KayyAk9r2OIbSY= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-168-lk-lsBVnMbyJeKz3x-EggQ-1; Tue, 30 Jun 2026 03:25:11 -0400 X-MC-Unique: lk-lsBVnMbyJeKz3x-EggQ-1 X-Mimecast-MFC-AGG-ID: lk-lsBVnMbyJeKz3x-EggQ_1782804310 Received: by mail-wr1-f72.google.com with SMTP id ffacd0b85a97d-474170b59dfso781869f8f.3 for ; Tue, 30 Jun 2026 00:25:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1782804310; x=1783409110; 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=T8IRfAFAOswM/FHwO19+KBl7CbCbKiUJMFkwpdewsoE=; b=iZFMNooKakv5DcFR0WLvZetvNxwS61x/Cv4Tj5kEI+qn+bQgudxdsP5tM4F9hUnusG 3COGtmwsMMHYD6k3MT+d3kDdfH2lbDUvMHEiWNjyqjtdw06JS9esTzH7el50kbqzQYGz 6QE4mWQb8zopTVd6nrbk9NviYCmHFn9hGEcp8VWM8mCvqKyisYf4tgsir15Kdq3w1nmA qrJefK+lgBZVsEbnOEd8zMcFOayIiID9ZJIzTld3OvbhRhxUlfdDn9WklUS3olYkaQyL O4xbaPUNYxCHcr5ww1CuwWeb3K/9CdqbgZZMyMJw9gGtxpnY5WlAn1ELL4k/mDSSYzsY h2jQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782804310; x=1783409110; 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=T8IRfAFAOswM/FHwO19+KBl7CbCbKiUJMFkwpdewsoE=; b=nxJHdD8Bef8ZJ8NRLEp2gifrBmtEGc7Hf4Crb3A596ppuA+UAKCsR13lW426DsYaY5 ng+CCXr/f82xEz/Z0Z61bwOR9KyhbTdQddk1r8n+c8dsDBAXa6sgwspP0nMOFQDpQNcI yiu29iYeAsX/FYrg4CXs9hDjaKuEEEpIkKyaH+4opnmnhk8J89/xeZSJbo55GWr6D+vw CgSDuo9LNKnrBnjDivW4yYY4Algw5jQOTPGU6WcGMCShhTGGwevOCWqHmDpsL+yr7zaU 5yNX9E7iLTsD+sNkI4b0sLVrJexMuuOZkVELczp/tSB32CcQUsSbu17cHL0/JtiCKDhV +EHw== X-Gm-Message-State: AOJu0YxHbMJeLGMVKsPZGB/q9hnygzoOAuZE6W9yHcsMiUSmUwo8pR/4 T7LxZxg7DjVIDYJ158nKAZp+3NruM4bur2KLH6kgkWuYrT2wiRKjOTb+Lv1zyP/bQURqrgvUkAH Pi68iv2mLHLxGvf66KdeNQRJl18GsMtD1Y7F3fjZHfvQl2xc9N1cv8C/gkrUqSk2JwQ== X-Gm-Gg: AfdE7clyuEsfEsWAhOSVjofI658Mj/nJABOKKcXtNYW/NRe/6U//VbemLOb65rA6V+1 qtYJ664wB8dOjDPN56ZW6je2k4vbwZW5N+VtYqevWUQpjhXnYtt+wlIkeZAGnOdCFWr0Rp5Jq+j 3GiA+XIvvJBQJIKQwGsrSCVX61HvPn6PA54yrje9hXdi0MHV3uLnlyWJPDa0KKnEmAswbM1dO6h Hu0LL4yJaiuMN1kVqXrpA3Lb9rqZxp5hC5b97ZWPtyrRpoQEaUdD/GPpQVTWIgbqGM9utB73eXi bG5hDe2N4hcM3QP6nRtHfIHd6j7pvKAuaZKqqglbz3rtB+2pp3oAkWSx8T1THEbpP2c3yizH457 RDw== X-Received: by 2002:a05:6000:27db:10b0:460:2ee5:67b8 with SMTP id ffacd0b85a97d-47552a67f7bmr2268112f8f.36.1782804309997; Tue, 30 Jun 2026 00:25:09 -0700 (PDT) X-Received: by 2002:a05:6000:27db:10b0:460:2ee5:67b8 with SMTP id ffacd0b85a97d-47552a67f7bmr2268047f8f.36.1782804309448; Tue, 30 Jun 2026 00:25:09 -0700 (PDT) Received: from redhat.com ([31.187.78.205]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-47563e0eee5sm5074622f8f.5.2026.06.30.00.25.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jun 2026 00:25:07 -0700 (PDT) Date: Tue, 30 Jun 2026 03:25:02 -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: <20260630032001-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> <20260630022129-mutt-send-email-mst@kernel.org> <0fb36931-9097-43db-98bb-d087b7b0fa12@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: <0fb36931-9097-43db-98bb-d087b7b0fa12@kernel.org> On Tue, Jun 30, 2026 at 08:34:44AM +0200, David Hildenbrand (Arm) wrote: > On 6/30/26 08:27, Michael S. Tsirkin wrote: > > On Tue, Jun 30, 2026 at 08:17:42AM +0200, David Hildenbrand (Arm) wrote: > >> On 6/30/26 01:34, Michael S. Tsirkin wrote: > >>> > >>> 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. > > Well, it will be cheaper in the general case (CONFIG_PREEMPT_RCU) :) > > But yes, not for this case. > > > > > I can test if you want but it seems clear. > > > > If you measured only !CONFIG_PREEMPT_RCU, then yes, it won't change a thing for > that scenario. > > > > > 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? > > I thought that still requires protection of sorts (preempt_disable / > rcu_read_lock), because it might fire whenever the task is preempted? Why do you think so? >From Documentation/RCU/Design/Requirements/Requirements.rst Note well that involuntary context switches are *not* Tasks-RCU quiescent states. After all, in preemptible kernels, a task executing code in a trampoline might be preempted. In this case, the Tasks-RCU grace period clearly cannot end until that task resumes and its execution leaves that trampoline. -- MST