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 BBE7B213254 for ; Wed, 8 Jul 2026 13:00:17 +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=1783515619; cv=none; b=E1zDE2BHPxgBDLCOq825tHgpy3PqVhI8NRFEC0tRKh1Srh15uyy9CmaySCWdzV+F+L6chh/DNholdSdWbnEf79rcw+qC0AZ2CdrD3IbSULj8ODQlczoAbqZKsuJiB0H8E7IYrjL7tgvYh4vldl5LojYbKhmOLAobo4fVsSbyobg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783515619; c=relaxed/simple; bh=8TnT3cGzhgFtS9Xuu2VMgPRHUgC5kqQMxAr2Q9rBdoc=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=ik/eMte92EllICxfxbUD8i1t5xLJ30mUhuoBc6aI7DUFariHk6FQWu3EdXyly9Ae2zRmpOilpJL9GlBEJdTYXhYNpL9GwPWf8NhkCERfjH3mPdq+pe1PhUDhhfzJwUtXtI+I2ed/MuQ15SsveM9W39yVz1E+NXW3LMMdSy/R5U4= 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=Jwmtb8qr; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=hQmG1eAY; 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="Jwmtb8qr"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="hQmG1eAY" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1783515616; 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=l1nxHUHuYBD2sRGWeQWBd/Pf2pEVUcm+cL6w6ahUDa0=; b=Jwmtb8qrjx55649laHY+qJ0U7LhY2dQ9iGbnmXBHwgt4TjHEhkNc7JFk1EB35Z8mSuuUqn +Qa8mgbkNKHdqOs0/nFmduhIMu1tmQzRBmlS74fNJiFk2McZRJkoduwZHw4f99pcVDCtpQ TJ645uL0rIjZXX+zum2OX5YnIOjBeJc= Received: from mail-ej1-f69.google.com (mail-ej1-f69.google.com [209.85.218.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-263-7PSnmbJyP6WkAeL80zgH0w-1; Wed, 08 Jul 2026 09:00:14 -0400 X-MC-Unique: 7PSnmbJyP6WkAeL80zgH0w-1 X-Mimecast-MFC-AGG-ID: 7PSnmbJyP6WkAeL80zgH0w_1783515613 Received: by mail-ej1-f69.google.com with SMTP id a640c23a62f3a-c15d4107068so53506966b.1 for ; Wed, 08 Jul 2026 06:00:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1783515613; x=1784120413; 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=l1nxHUHuYBD2sRGWeQWBd/Pf2pEVUcm+cL6w6ahUDa0=; b=hQmG1eAY20nKoM6qQqy7QiodHzX2Qaepjq5tuTSmARjmnlk8mzooacT2ki727WEIHa ipq397akXIH0/LOzHrTcT7wq+qD5xvqUmbloAapyzF5YByFTD7YDjRajITR01CsonCKV ht/SdcEjVMUtnUtZZv6ypQQZcPM6NNyb7q+3eSOskr7rVk6UwCGaijaDSHKfRK/FuQjC STuqcjOMvJkopGX7SyAc/j7gqpOf7wSj9MD6AIjeTRAENkm6Tndy3/ZYmUQLlDJXhBgv qtHGEnakftoGvYKtk0iYMxwqiuH88MoyxSKojUAZpAtbaZG7BBE+wsAaaSRnUQRFpU+1 FDAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783515613; x=1784120413; 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=l1nxHUHuYBD2sRGWeQWBd/Pf2pEVUcm+cL6w6ahUDa0=; b=QfR2TpahtI+fDB0hPR02RDl8h0qOz9aI9Y6hb3vnIpaGtOOayvC+RyncWxE4cpcDxG TIOtgM+BwciIDdjdnG0eVnrnBGOBSjP6BlfCf1d5m4pdmFToIYF8Uc6IIlIgNc2jDbKB 1YID9RT3x6aiP8PK00LRxMyBWvxIdQoQ/tl7XueX7jZ0bKXJWxOtWzs4U8W6r5FPw4uE xhf+i3CpfoyPo8v4wOPxy+4ZFV/OH7SMkqp+8iwYCTv8ykf11R8XtGRFlil5FPVH3hH+ XjhytYqcX+sHf3gp3zym/+Hku8yiIu1Q7/Qa/9EGVHHwBYkAkyNqO0Sz9n30S0+3aTT4 fVPw== X-Gm-Message-State: AOJu0Yydp4HWIUzNvm6TsNOS/+SiscHOEw1m0FX6Ypr21Tk+W2Od7qDP R+XZVvGIw31ACc2VFYSygcMG5hV/6kHNERYNDW2AQ5Hbv+PQjANQfcqpqqnvTlRVLnwFFRqt5Dv +MAXoyZTm2tbjTt3GWNyJ2z3mCBDxh1WqK7+1aQUP9gsNpJLNvzGpdA0Gx01Z0qBhKyyLiSb17w == X-Gm-Gg: AfdE7clwXMFBsTptq+d0lW4JB9tdKLOCSwX4AKp6jwZXWInmKuv+f7y7RTKAUk+d1BV S07EPsVs1Ct8LQ6kMNG1cfQMEU+28VeiP1GXKJV27WwjGiCEC4XUfsvGnUYo1ln/k+6y+9ojQ0l xpBPq5fVeWLkP+q3VX9Ljlh21aVdc0No9ErMpsjNdJdfg2hcnhMSz8pw7UyfiAFjHpnpTZc0Qtr uSC+WClJOBPijzq3CA78lE+Qmlha92OSzGp0xaeuRXeIbx9YY2fhSz2B9OLAondElumoSDX3ZhO ATaaP8gNYJSmlSn544cG0OWFB2J+qKUPrF35EBmqmAttGM/ybtGSzvgJbnF3yGiLXjMfAWfnMFr tJSJiNARFJfKS2zT339Z0en1T5ZFskQgW X-Received: by 2002:a17:907:26c1:b0:c12:7e24:a76f with SMTP id a640c23a62f3a-c15ce025ae4mr111216966b.20.1783515612877; Wed, 08 Jul 2026 06:00:12 -0700 (PDT) X-Received: by 2002:a17:907:26c1:b0:c12:7e24:a76f with SMTP id a640c23a62f3a-c15ce025ae4mr111210366b.20.1783515611401; Wed, 08 Jul 2026 06:00:11 -0700 (PDT) Received: from redhat.com (IGLD-80-230-68-31.inter.net.il. [80.230.68.31]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-c15ddb9e1d2sm6630866b.52.2026.07.08.06.00.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Jul 2026 06:00:10 -0700 (PDT) Date: Wed, 8 Jul 2026 09:00:05 -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: <20260708085745-mutt-send-email-mst@kernel.org> References: <20260630174852-mutt-send-email-mst@kernel.org> <2f884bfa-3cd5-4fba-8aa4-c2e68890ab64@kernel.org> <20260701041112-mutt-send-email-mst@kernel.org> <20260701043024-mutt-send-email-mst@kernel.org> <20260701112946-mutt-send-email-mst@kernel.org> <20260701180511-mutt-send-email-mst@kernel.org> <6b0f028c-574b-4b80-b803-2bff15a5a148@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: <6b0f028c-574b-4b80-b803-2bff15a5a148@kernel.org> On Wed, Jul 08, 2026 at 02:13:27PM +0200, David Hildenbrand (Arm) wrote: > On 7/2/26 00:18, Michael S. Tsirkin wrote: > > On Wed, Jul 01, 2026 at 06:17:23PM +0200, David Hildenbrand (Arm) wrote: > >> On 7/1/26 17:54, Michael S. Tsirkin wrote: > >>> > >>> Not "generated" surely. But assisted, yes. > >> > >> What I thought. > >> > >>> Still hacking on it, but the difficulty > >>> with memory-failure is that fundamentally, it's not 100% robust. > >> > >> It's all a bit slapped on top of everything, yes. > >> > >> What I was wondering is, assuming the call_task_rcu() and it takes forever, > >> there might be quite a while where a hwpoisoned page that lost its bit is not > >> marked as hwpoisoned. > >> > >> So you'd actually want the one doing the test_and_set_bit() caller to wait until > >> the bit is stable. > > > > not sure I get it. > > Essentially, I think that after you set the bit you'd want everybody else in the > system to see that state before you continue. > > Such that other code that tests for poisoned pages would just immediately act on > it. Like the buddy not handing out such a page anymore, immediately. > > At least that way it's easier to reason about. Losing these bits is really just > nasty :( > > > > >> But that should be rather hairy as well. :( > >> > >>> > >>> For example, we have a fifo fed by hardware and consumed by a workqueue: > >>> > >>> struct memory_failure_cpu *mf_cpu; > >>> unsigned long proc_flags; > >>> bool buffer_overflow; > >>> struct memory_failure_entry entry = { > >>> .pfn = pfn, > >>> .flags = flags, > >>> }; > >>> > >>> mf_cpu = &get_cpu_var(memory_failure_cpu); > >>> raw_spin_lock_irqsave(&mf_cpu->lock, proc_flags); > >>> buffer_overflow = !kfifo_put(&mf_cpu->fifo, entry); > >>> if (!buffer_overflow) > >>> schedule_work_on(smp_processor_id(), &mf_cpu->work); > >>> raw_spin_unlock_irqrestore(&mf_cpu->lock, proc_flags); > >>> put_cpu_var(memory_failure_cpu); > >>> if (buffer_overflow) > >>> pr_err("buffer overflow when queuing memory failure at %#lx\n", > >>> pfn); > >>> > >>> > >>> if there are lots of these and the scheduler is slow and it overflows, > >>> it's sayonara you have lost the flag, right? > >> > >> I guess so. I assume on relevant hw you wouldn't expect a storm. But who knows :) > >> > >>> > >>> > >>> Oh and by the way, I just noticed that when buddy merges pages it does > >>> not check the poison bit. So it looks like there's a simple way to lose > >>> the poison bit - have it merge with a non poisoned page. > >> > >> When we poison, we try to take the free page off the buddy. At least that's what > >> I remember. > > > > > > Yes but not immediately - we set hwpoison then we try to take it off. > > > > > >> So I think we would just then go ahead and split the free higher-order buddy > >> page to remove the single page. > > > > Later we split, yes. But I don't see where it sets HWPoison after > > split - it calls > > SetPageHWPoisonTakenOff but it seems to assume HWPoison is already set. > > > > Am I missing something? It's late here... > So, we set hwpoison on a page and that is sticky, even when the buddy merges > them, right? right. bar races but that is separate. > When handing out pages, the buddy will check all pages through > check_new_pages(). If the poisoned page is part of a higher-order page, that > would still find it. > > So I would assume that the hwpoison page->flags stays there, and > PageHWPoisonTakenOff() only tells us if we succeeded in removing the page from > the buddy ourselves. Right, I see. Btw in a bunch of paths even if we unpoison we lose the page, right? And it seems we can also lose a hugepage just because 4k in it got poisoned? Is that expected? > > -- > Cheers, > > David