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 9E673C433F5 for ; Thu, 2 Dec 2021 15:54:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C869D6B0072; Thu, 2 Dec 2021 10:54:33 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C36346B0073; Thu, 2 Dec 2021 10:54:33 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B251E6B0074; Thu, 2 Dec 2021 10:54:33 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0151.hostedemail.com [216.40.44.151]) by kanga.kvack.org (Postfix) with ESMTP id A47C86B0072 for ; Thu, 2 Dec 2021 10:54:33 -0500 (EST) Received: from smtpin14.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 6244C89D2F for ; Thu, 2 Dec 2021 15:54:23 +0000 (UTC) X-FDA: 78873301206.14.7C26674 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf19.hostedemail.com (Postfix) with ESMTP id 797F8B00009D for ; Thu, 2 Dec 2021 15:54:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=nISvdc0rk0mqJv1dMg3hZ3+TKFJZuCZ9z2wVt5ec1Mc=; b=l5NqpvD2VQ7QdSqyI6T+fY/p2S 0WDKb5SwGMMHCgZQiIkKFWlORVOOzry/QUBLcsxS0HFvGRw7uXcrY1i3Ylkkvjvv+GyZzQnh/jn9J UKbvN+1ZOkOloWQr0zyEDCFuqXp0DZLSZj8gfi7jSYPu+f4Pc488AqaCIERUKG643OI59st5b81Gn i18Iz5JVCy+IpkyBXNm0eHQnDt0UFFjTM1bOZryaiUlIoWQPJapnOC1boBM1+G/3ydWv+ZgmLaJll qy+s8o4IaW1YVDVKVnrc4x2vmfyGlz13jRhLDn6uleIFV0JS0BHOzvCRo/hLYOv0DLUT4mAUEgXdX cXz05Row==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1msoPV-004aWo-Dj; Thu, 02 Dec 2021 15:54:13 +0000 Date: Thu, 2 Dec 2021 15:54:13 +0000 From: Matthew Wilcox To: Charan Teja Kalla Cc: Charan Teja Reddy , hughd@google.com, akpm@linux-foundation.org, vbabka@suse.cz, rientjes@google.com, david@redhat.com, mhocko@suse.com, surenb@google.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] mm: shmem: implement POSIX_FADV_[WILL|DONT]NEED for shmem Message-ID: References: <1638442253-1591-1-git-send-email-quic_charante@quicinc.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 797F8B00009D Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=l5NqpvD2; dmarc=none; spf=none (imf19.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org X-Stat-Signature: ipgthzeh3wtwoinehw4p59538hm6xoip X-HE-Tag: 1638460462-721438 X-Bogosity: Ham, tests=bogofilter, spamicity=0.013932, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Thu, Dec 02, 2021 at 08:59:52PM +0530, Charan Teja Kalla wrote: > > What part of the XArray documentation led you to believe that this is a > > safe thing to do? Because it needs to be rewritten immediately! > > The above code changes made from my understanding of both the > Documentation and the implementation of xa_for_each(). The Locking > section of the document[1] says that xa_for_each() takes the rcu lock > thus can be used without any explicit locking and the "Advanced API" > section says that users need to take xa_lock/rcu lock as no locking done > for you. > > Further I have looked at the xa_for_each() implementation details, > where, it is taking the rcu_lock just across xas_find() in both > xa_find() and xa_find_after() which made me to think that it just needs > to take the rcu lock just across the xas_find(). > > But a comment from you saying that this implementation is wrong making > me to think that I lack very trivial understanding about xarray usage. Would this change to the documentation have prevented you from making this mistake? The advanced API is based around the xa_state. This is an opaque data structure which you declare on the stack using the XA_STATE() macro. This macro initialises the xa_state ready to start walking around the XArray. It is used as a cursor to maintain the position in the XArray and let you compose various operations together without -having to restart from the top every time. +having to restart from the top every time. The contents of the xa_state +are protected by the rcu_read_lock() or the xas_lock(). If you need to +drop whichever of those locks is protecting your state and tree, you must +call xas_pause() so that future calls do not rely on the parts of the +state which were left unprotected.