Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp2336798rwb; Mon, 7 Nov 2022 12:04:10 -0800 (PST) X-Google-Smtp-Source: AMsMyM4Tm5uu7dGqEMHhe6NjxvhGbcd5bPYaGANekjjeHljXxFI2uZFS4fhl25aQP/4zZvjTN1qd X-Received: by 2002:a05:6402:538a:b0:457:b602:d5a6 with SMTP id ew10-20020a056402538a00b00457b602d5a6mr52160723edb.371.1667851450628; Mon, 07 Nov 2022 12:04:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667851450; cv=none; d=google.com; s=arc-20160816; b=aiDChkm47zsTl5dED5XIklcHmEylTrI2tfKPYmNaFF4Rgk8Hls1LQLQEWMX12HBmct 9axO+lUp3Ac9VFVFk/VoSwagGKu0pHyp8lH4XuWSiRUx50kxq+bKL+iYBDxj2TU6VRu1 0hQD3Ojmz6NAjfISQN4m0RDz14m/j8UxpxHL2H0F7vou4zZzKEinX86aa0WZZJlGTyP1 5xfq3Cur3Pj9GGpNjqICWWREhx54B287QVYaWuBJdYGSoa1aXl/OEd5METaqt85hOC3D 7MKXTh9MN9g0CHCwugi+eUyO1qmaZF21cnriDw+qTy4xS4hkXhUhmItcoIz6/XTXG4Wg BJUQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=UMZGTOdny/2Cu7IcdczmjpIZirM4/rlpeJ6rzXSz4tQ=; b=BUPcHbgzszrg1CyhIkusMAyO3lpYf6sF3P+TfRxD2k9J6tcDtsKZujCiBZ73r2GdpQ wezA1ylySEJ2BU+isYFV1YOqnMmyURgr0C4lAU/46XLo6wB1TpmxnrFehQtF77verh9O tRp2kFuqFiLCJlgUdE/SnYYKy2poejnMg7Fjr1XdGo1EwAtSCRTqYvXF3lpganeeUn58 nM0Bg7gnN+DW5H5eDB0AKJjPXZPleGT43wFjV85vz66ojS6nuV8VNIn8+J9EmVXVzPSK wHyAqI1iYSHCxMWWc9KCCPQ3vQxkOXAGHZ8Jq4HwQiLFEY+ImSnUVUauMIkAHinx3Ofx 84Zw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=RIqYW1fP; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e6-20020a17090658c600b007ae4c686a4esi12371192ejs.159.2022.11.07.12.03.48; Mon, 07 Nov 2022 12:04:10 -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=@kernel.org header.s=k20201202 header.b=RIqYW1fP; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232192AbiKGTTN (ORCPT + 92 others); Mon, 7 Nov 2022 14:19:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53338 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232261AbiKGTTJ (ORCPT ); Mon, 7 Nov 2022 14:19:09 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F287629C82 for ; Mon, 7 Nov 2022 11:19:08 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id B43F4B8166E for ; Mon, 7 Nov 2022 19:19:07 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 63EC0C43147 for ; Mon, 7 Nov 2022 19:19:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1667848746; bh=bGgthrUWF+3ZLq8n7+v7zjmqKldCWYKUlvW82mNHqpw=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=RIqYW1fPOkVK9o0W1XlCHfap+U7HIMgGLbShMh0v9M6IHqj5aYa3r1HLiGGlCzyK4 B9R35r2GwoDsy/QtFaLdeXM8kP6iM7yY8kYyNvukMNvYdzSiRKiXXlu4WB4Q5dWVRN GVtA3vLrDaZbvlybvL118ZDKSxxmvy4k48YcmklL8DrCMMbcwrqjqzbzeEtO/DmeQl VNqbOK/vfR1DDK4jdqAqJp88Lh8X7TUnhm3+mmBPPfUDZQL1Y7oZ2saCuapMxCbtAg NkI3x4bqUdoCAAIgfbpkfkDvLApamXUfHNf3vicnF+YnZTPAX1yZ8q4sV5Mknfukwj V/phhb7F+vdDw== Received: by mail-yw1-f172.google.com with SMTP id 00721157ae682-333a4a5d495so113813497b3.10 for ; Mon, 07 Nov 2022 11:19:06 -0800 (PST) X-Gm-Message-State: ACrzQf1t/kbfKh+lGzgX1Z2dwZxiH8z1d3jzdPLb5V2t8yKcxHZQYd57 beoILJsbg6gra0CCJeCMQwCX2Ma+j4OB0RWstUA= X-Received: by 2002:a81:9214:0:b0:36c:7b94:aa57 with SMTP id j20-20020a819214000000b0036c7b94aa57mr48162445ywg.221.1667848745201; Mon, 07 Nov 2022 11:19:05 -0800 (PST) MIME-Version: 1.0 References: <20220911211443.581481-1-michal.winiarski@intel.com> <20220911211443.581481-2-michal.winiarski@intel.com> In-Reply-To: From: Oded Gabbay Date: Mon, 7 Nov 2022 21:18:38 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v5 1/3] drm: Use XArray instead of IDR for minors To: Matthew Wilcox 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 Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS 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 Mon, Nov 7, 2022 at 6:20 PM Matthew Wilcox wrote: > > 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. > Hi Matthew, Thanks for the explanation. I believe Michal's will fix his original patch and I'll take that code. Oded