Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp2041950rwb; Mon, 7 Nov 2022 08:30:08 -0800 (PST) X-Google-Smtp-Source: AMsMyM6psCzqN9sN1KIenVx2eLF4pm7anqTxltzs+6zdv9kwL8GbKg9PgMdOLUbhvmxX9p4kcriY X-Received: by 2002:aa7:8888:0:b0:56d:41a9:dbb3 with SMTP id z8-20020aa78888000000b0056d41a9dbb3mr45850125pfe.15.1667838608673; Mon, 07 Nov 2022 08:30:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667838608; cv=none; d=google.com; s=arc-20160816; b=pzNycpmw/CRrsY9XtUDw1uce05goTOkNz2nvPkgjwjuNbl1atVOSgDy0xsKK7+Wv8g IHH+ELmkn8kZHmnlJeetxh4E2t03M+W8Q6UgA2Z7YMFLmTN0Zai6HcRZXLiZgfzoekd/ Smw0IS34/0+WvaxX9uYvTuGgFPSrXNwGESS6qDyLrOOBjnqX8H8G83tyycLTkGRDw78n xF68GSg/BpYPTIl4v2DJ4n5lSizDoNcM05gudXFKoGE2cFShRcQLLRqZZmfFzFQsJH3o 3hz/9z78DM/DxxWjS/Q4/TPJV487kqQk8uAtftm+tamtxsjXrh1D8ynS3XZ58722d4O8 cLhA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=oCZ/nMUN/7C6KeSZtw+vpEn8Cw/FfofNU7HRtG+t0rA=; b=DwPrIthJXJ6ugB4Fq68Mu4575vN49GEVJSPbfUR+Jx9qcZ1Vy5LHMkVAR3bO0OfAgn qeG3m9hf/FPPoo++at7emeUqk5ENUsCIfXO/4OMYOePDdWvse1fLvKZoeXKLsyLNQQ0G m+GQzRJTiZJI72trVfUHZ9ZNj2Z+fouHabxEYCy/rl8k4ZhFSDRwbeb9VMOa+p6XyHdQ vxUqkY5m3R/Zlzs4K+SRn9od9hAZwN2H2iSZqQGr6Y/MP3t8IqTmrsWVOkzHU+xXCENE ftw+QvXaO0JqrCldjUBCNZd8QgCKSkCejkKZf3Py4niGJLN20snIzGztUqv90u0O043x 3PXQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=XYwAxJ8D; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c21-20020a63ef55000000b0043a061cc079si10896035pgk.358.2022.11.07.08.29.56; Mon, 07 Nov 2022 08:30:08 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=XYwAxJ8D; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232001AbiKGQW0 (ORCPT + 92 others); Mon, 7 Nov 2022 11:22:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42366 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232835AbiKGQVK (ORCPT ); Mon, 7 Nov 2022 11:21:10 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 419C621E3C for ; Mon, 7 Nov 2022 08:20:15 -0800 (PST) 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=oCZ/nMUN/7C6KeSZtw+vpEn8Cw/FfofNU7HRtG+t0rA=; b=XYwAxJ8DzyQAkyaAXqc7IgvdVj HrBx/ism/pUCdiQp1jOTWPUMxY1qyZMaY09ofG7f0gWvri/1WA0cZsFGl2Ocomrl4nZcEfqHOTruZ j4hzdUhmTvKONN39aICfWPZ5+vy/Bdb2DOIxcpMP5PJh8VGjBinH7pmmlWoIkbEamsc0uILJrCY6H 379cqheJaAZQbDkfUIvBnT7nK1WofTs5qxQNPhxFiaxPBM4sI4ddi7E/JK1/dXH9fNCSSDJo+hiBc h4piDACrpQwGkdZ+vwwuz5M+b6LZKogX3orSfKwxpKL2DFbEYI47+nYhQ1z78Nkd+Fcl2gu0Jpbo/ uNRsF8Ew==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1os4r1-009Up3-LY; Mon, 07 Nov 2022 16:20:07 +0000 Date: Mon, 7 Nov 2022 16:20:07 +0000 From: Matthew Wilcox To: Oded Gabbay Cc: =?utf-8?Q?Micha=C5=82?= Winiarski , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, intel-gfx@lists.freedesktop.org, David Airlie , Daniel Vetter , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , Simon Ser Subject: Re: [PATCH v5 1/3] drm: Use XArray instead of IDR for minors Message-ID: References: <20220911211443.581481-1-michal.winiarski@intel.com> <20220911211443.581481-2-michal.winiarski@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Nov 06, 2022 at 04:51:39PM +0200, Oded Gabbay wrote: > I tried executing the following code in a dummy driver I wrote: You don't need to write a dummy driver; you can write test-cases entirely in userspace. Just add them to lib/test_xarray.c and then make -C tools/testing/radix-tree/ > static DEFINE_XARRAY_ALLOC(xa_dummy); > void check_xa(void *pdev) > { > void *entry; > int ret, index; > > ret = xa_alloc(&xa_dummy, &index, NULL, XA_LIMIT(0, 63), GFP_NOWAIT); > if (ret < 0) > return ret; > > entry = xa_cmpxchg(&xa_dummy, index, NULL, pdev, GFP_KERNEL); > if (xa_is_err(entry)) > return; > > xa_lock(&xa_dummy); > xa_dev = xa_load(&xa_dummy, index); > xa_unlock(&xa_dummy); > } > > And to my surprise xa_dev is always NULL, when it should be pdev. > I believe that because we first allocate the entry with NULL, it is > considered a "zero" entry in the XA. > And when we replace it, this attribute doesn't change so when we do > xa_load, the xa code thinks the entry is a "zero" entry and returns > NULL. There's no "attribute" to mark a zero entry. It's just a zero entry. The problem is that you're cmpxchg'ing against NULL, and it's not NULL, it's the ZERO entry. This is even documented in the test code: /* cmpxchg sees a reserved entry as ZERO */ XA_BUG_ON(xa, xa_reserve(xa, 12345678, GFP_KERNEL) != 0); XA_BUG_ON(xa, xa_cmpxchg(xa, 12345678, XA_ZERO_ENTRY, xa_mk_value(12345678), GFP_NOWAIT) != NULL); I'm not quite sure why you're using xa_cmpxchg() here anyway; if you allocated it, it's yours and you can just xa_store() to it.