From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 25B5EC36010 for ; Mon, 7 Apr 2025 11:49:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 564D56B0008; Mon, 7 Apr 2025 07:49:08 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 513446B000A; Mon, 7 Apr 2025 07:49:08 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3B46A6B000C; Mon, 7 Apr 2025 07:49:08 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 1DEC46B0008 for ; Mon, 7 Apr 2025 07:49:08 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 124B2160B8E for ; Mon, 7 Apr 2025 11:49:08 +0000 (UTC) X-FDA: 83307076776.21.4E5C3DB Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf15.hostedemail.com (Postfix) with ESMTP id A8026A000B for ; Mon, 7 Apr 2025 11:49:05 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="ccqU/akC"; dmarc=pass (policy=quarantine) header.from=redhat.com; spf=pass (imf15.hostedemail.com: domain of toke@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=toke@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1744026545; a=rsa-sha256; cv=none; b=E50WQTn2+7mCc2px+fwuL6489Bvc3ac46UmUKkSYJUb41k/G0T2QivFTH/ZP+7KpPVGmDI kxW4aq1Kh9kR1G9DDBaENz/zq8hDoFb4Se72WaQw2UJHBHenmXwICjQ8BCu40sr36RrMXW K4mH2qzfDP+QnufZZE6wxCM1gFzTTGM= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="ccqU/akC"; dmarc=pass (policy=quarantine) header.from=redhat.com; spf=pass (imf15.hostedemail.com: domain of toke@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=toke@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1744026545; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=dDF8SyOnI552zZ++C7QHfc5GeK8gG44xvpaCupe+RLA=; b=nHh8JPt39mQXK7PRzn9wSM7lS6yM1TCZyjBiJr2cWnJQbFvaj33HL1AcbRO6Y4NG7J789P 7h7Hw+DF1z4CbLVcbUFAo7W+RK531H2PEwlS2xaJj4kOdCS2JI+O8jtWAfb1JHurc64C/+ IjNuvLlPrw9e99L9GOK7xOi8OFvpijk= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1744026545; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=dDF8SyOnI552zZ++C7QHfc5GeK8gG44xvpaCupe+RLA=; b=ccqU/akCee0RvyqaSGmyCbN11xK1jXPe078bf50jy+exM9bBSWnbNMtDEC7WD3EJzMJtE4 d/2eT+t0IprvyV9UhHjyq5jon62sZ8/Q1O3oOpX/XSU4f/oy7MxyOgkT1dByDqe/8J+oUp 4XoMizX9xI5bgnT0te2o7s8FH2awotE= Received: from mail-lj1-f197.google.com (mail-lj1-f197.google.com [209.85.208.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-304-bgJslfXINlKHqc2Jisi7zg-1; Mon, 07 Apr 2025 07:49:03 -0400 X-MC-Unique: bgJslfXINlKHqc2Jisi7zg-1 X-Mimecast-MFC-AGG-ID: bgJslfXINlKHqc2Jisi7zg_1744026542 Received: by mail-lj1-f197.google.com with SMTP id 38308e7fff4ca-30be985454aso20640141fa.2 for ; Mon, 07 Apr 2025 04:49:03 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744026542; x=1744631342; h=content-transfer-encoding:mime-version:message-id:date:references :in-reply-to:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=TLDIfHFc0cnuUtNn3wFV1KRo7sfcAABFYKPb/EFAlBY=; b=O2NcXrgq+xcSyYVUUx3gkgQYfa3AGRxzqMvohYWIyUfsbvwcOi7Qz3hx2a38HVc0gw 8R/WCFBvXIs7OzeiN6ycuBC9WEOWQ+5yub7kJVdcCnBhr7DUzr5cvxT7J8QmsL6NIg+Y 9lvNdUZBLwDAfFDAmOyFpmp3gXRxsiNc3oObpwHtbC1mAyLOZs4XgMVXkAy8qB6d+NXt 6Y25+10nChEnWQlraExjNAGk2WTKFfjwWNucjX9JgbBlldielbYvAilvmfXHBP3cvner kdaiZPWkT34vxCVQByKOkTvtnjhReyjuJA2MrqFmnLbh7fLr2VpMMEYGf5iaJxNIoxOM K8fQ== X-Forwarded-Encrypted: i=1; AJvYcCW95hV0UOrTvJJKFSu9v9sNlWXsE13Kqy3Tx/1BIpIE/p0SwhyXddtKhYXIr5Iyfj1zAluXtJBEfA==@kvack.org X-Gm-Message-State: AOJu0YwNse4Gziv4Fo0uvlXeYTOQgH0eZkKdMtSMwp3k7Kb+uzXUDeZp 1INON5MrdOzLTA5W79BkamglsjkAsmEqpfQ/wkVjwIpFUPCHnwgLWGmYvNamI+RmOsHbmXeLewF Q7AGXxItx3R0XDWfmqJ3MRghJd1ckhKno6Ryh9sUwJed5EcGZ X-Gm-Gg: ASbGncuHfMq5TG1nTW1O89/PuHRr+odkHugyBy2OxRMiRLiVMRWf6CMjklzowjzhY9f hru6eyDY8x1cev4NnCzZzGnoUWciNGLWFuXc1Xfnen5SBcvoi0kK2yBnIkp8kt1pJRZUuEVHBCy ydZ6jQzN/7VHX4OpRYRLF5gw4kSA1ONpoLmvvuNk9Es8jBLoqab4EBL2kl3udhKo/IK85XDcEhL LCZ7PNHye2erl3n68rstWxtXJLFwsi/3e1q4j/4L/d4kB2eUhGASqVzQNneuB7OkDoFjU2GoJ+a R4MmFvPatrhL X-Received: by 2002:a05:6512:230c:b0:549:38d2:f630 with SMTP id 2adb3069b0e04-54c232e27abmr3822844e87.24.1744026542008; Mon, 07 Apr 2025 04:49:02 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHJhH9DwjR+yY0lREbz+MbPKUBDZMsEOgHBc/onNClHx1Rv9EuZnA4xWzVH0KsBqxu+8cjt9A== X-Received: by 2002:a05:6512:230c:b0:549:38d2:f630 with SMTP id 2adb3069b0e04-54c232e27abmr3822825e87.24.1744026541557; Mon, 07 Apr 2025 04:49:01 -0700 (PDT) Received: from alrua-x1.borgediget.toke.dk ([2a0c:4d80:42:443::2]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-54c1e672c38sm1216538e87.254.2025.04.07.04.49.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Apr 2025 04:49:00 -0700 (PDT) Received: by alrua-x1.borgediget.toke.dk (Postfix, from userid 1000) id 0B7A4199188E; Mon, 07 Apr 2025 13:49:00 +0200 (CEST) From: Toke =?utf-8?Q?H=C3=B8iland-J=C3=B8rgensen?= To: Yunsheng Lin , Alexander Lobakin Cc: "David S. Miller" , Jakub Kicinski , Jesper Dangaard Brouer , Saeed Mahameed , Leon Romanovsky , Tariq Toukan , Andrew Lunn , Eric Dumazet , Paolo Abeni , Ilias Apalodimas , Simon Horman , Andrew Morton , Mina Almasry , Yonglong Liu , Pavel Begunkov , Matthew Wilcox , netdev@vger.kernel.org, bpf@vger.kernel.org, linux-rdma@vger.kernel.org, linux-mm@kvack.org, Qiuling Ren , Yuying Ma Subject: Re: [PATCH net-next v7 2/2] page_pool: Track DMA-mapped pages and unmap them when destroying the pool In-Reply-To: References: <20250404-page-pool-track-dma-v7-0-ad34f069bc18@redhat.com> <20250404-page-pool-track-dma-v7-2-ad34f069bc18@redhat.com> <3b933890-7ff2-4aaf-aea5-06e5889ca087@intel.com> <87jz7yhix3.fsf@toke.dk> X-Clacks-Overhead: GNU Terry Pratchett Date: Mon, 07 Apr 2025 13:49:00 +0200 Message-ID: <871pu4xkcz.fsf@toke.dk> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: sCyK2CPQjcauIielogWk_MLTiriJd0uFx960isKsvoI_1744026542 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Rspam-User: X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: A8026A000B X-Stat-Signature: mxgbga4bt3g5jgpqg6t79omee3hiqfyi X-HE-Tag: 1744026545-226821 X-HE-Meta: U2FsdGVkX1/YCwHk4ieP1L+A0YwIYkZr5JP8lGChf1RjPkNDOs5TqUgN7f+HQGMDVF4TeTZmqw/5bBvkIlD16OO6lh+m3b1s/T86VlfRE8a4qzcPDU95tto1L2bF6B+ilKSXoZGNA/r9Mea1cFAUIMIhHJQ604atFd1jf4eXEL6c8OWlEAusi52VYBPaE4fAMJ9PAtjAMT+T2BZhYZxYrWMI1Ubm75qY5mu3SvPe9duU/IZd7h2419DSa5v/oDYPiqpN7Tt7i7NlzjNNNPNi64EQpIfnUZhLCGiRVddO6n/dMmpJyGqtM7Rhe0JAfAFGzHYlolp0zcf6TqUd1J5rpLYKt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Dm+Sv0pYjoZ4HptMHzsfqflTgsAHmeJCpQX2gwBHGS6ORLOOkAtYzmxk/1V8NTe/913lcs9uHRz6cB0dH7qVrzEKgATVgWRyPg1Zld18vieE0TrHGkVy82upn+ixicixpEg8Xo43VcJi+UhstrFHe9v7FJT9rrZbOZhF5GTPwMXgaUF9aTISrbNQYrnvC33wGMM X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Yunsheng Lin writes: > On 2025/4/5 20:50, Toke H=C3=B8iland-J=C3=B8rgensen wrote: >> Alexander Lobakin writes: >>=20 >>> From: Alexander Lobakin >>> Date: Fri, 4 Apr 2025 17:55:43 +0200 >>> >>>> From: Toke H=C3=B8iland-J=C3=B8rgensen >>>> Date: Fri, 04 Apr 2025 12:18:36 +0200 >>>> >>>>> When enabling DMA mapping in page_pool, pages are kept DMA mapped unt= il >>>>> they are released from the pool, to avoid the overhead of re-mapping = the >>>>> pages every time they are used. This causes resource leaks and/or >>>>> crashes when there are pages still outstanding while the device is to= rn >>>>> down, because page_pool will attempt an unmap through a non-existent = DMA >>>>> device on the subsequent page return. >>>> >>>> [...] >>>> >>>>> -#define PP_MAGIC_MASK ~0x3UL >>>>> +#define PP_MAGIC_MASK ~(PP_DMA_INDEX_MASK | 0x3UL) >>>>> =20 >>>>> /** >>>>> * struct page_pool_params - page pool parameters >>>>> @@ -173,10 +212,10 @@ struct page_pool { >>>>> =09int cpuid; >>>>> =09u32 pages_state_hold_cnt; >>>>> =20 >>>>> -=09bool has_init_callback:1;=09/* slow::init_callback is set */ >>>>> +=09bool dma_sync;=09=09=09/* Perform DMA sync for device */ >>>> >>>> Yunsheng said this change to a full bool is redundant in the v6 thread >>>> =C2=AF\_(=E3=83=84)_/=C2=AF >>=20 >> AFAIU, the comment was that the second READ_ONCE() when reading the >> field was redundant, because of the rcu_read_lock(). Which may be the >> case, but I think keeping it makes the intent of the code clearer. And >> in any case, it has nothing to do with changing the type of the field... > > For changing the type of the field part, there are only two outcomes here > when using bit field here: > 1. The reading returns a correct value. > 2. The reading returns a incorrect value. > > So the question seems to be what would possibly go wrong when the reading > return an incorrect value when there is an additional reading under the r= cu > read lock and there is a rcu sync after clearing pool->dma_sync? Consider= ing > we only need to ensure there is no dma sync API called after rcu sync. Okay, so your argument is basically that the barrier in rcu_read_lock() should prevent the compiler from coalescing the two reads of the pp->dma_sync field in page_pool_dma_sync_for_device()? And that READ/WRITE_ONCE() are not needed for the same reason? > And it seems data_race() can be used to mark the above reading so that KC= SAN > will not complain. Where would you suggest to add those? Not sure such annotations would improve readability relative to the current use of READ/WRITE_ONCE()? The latter is more clear in communicating intent, I would say... > IOW, changing the type of the field part isn't that necessary as my > understanding. Since changing the field doesn't change the size of the structure, I would be inclined to keep the change for readability reasons, cf the above. -Toke