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 CB7AB42A96 for ; Tue, 3 Jun 2025 07:58:39 +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=1748937521; cv=none; b=jHq0PbSoatfy5BDiBxVFhPRZJVGxyW0QcOfUiS3oCrJ5kFVYcMeCNBNAE8UCkX7thOLA+HVrmELi/J7kYxKSmg60QSUgDcV2yt6K1naw9mGKETK53JmOqhG133Q5I+OJVGkw2MOd6YRKOdk42uMNmymH7ACA/1iufR2QugKmW24= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748937521; c=relaxed/simple; bh=cy72lPA7fIybA0rZs5R1Jbp8qv0j8pisUfL/1px13qk=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=s/vThGGoda9Rgim1GksQHnfQF3e6SSkbDDU0nhdB8KYZKFt35wyWp7NvBgUiEdi2+BuBiumhpEXkVBUbzcTBEOboNZRdOBfwu2keubrU1OlIqxRTo8bdSOGZfKSXOPG/kSgFoP932IV/3ZW2+jsKxme9Zu3qE80PG8eNowSpRZo= 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=c5gurGnx; 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="c5gurGnx" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1748937518; 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:autocrypt:autocrypt; bh=CU0N6UgF0Wu801mnXgPiaSIy9UpUp1v4ajkhrRpQ1f8=; b=c5gurGnxd9zvlcuZbyjiIgVBCPjOYTabCsBKaYTJhROTioQPBzq8ffK4+3WV2EKJHhdpE0 4EW7VAkabiABcUm0KtK1gbA4D5TBG40mz7g1T8GvrchRqEACfVT1K47+ZPkpH7A8f5liEE QI9LLrtF6RIQ/f2ksC08UKeU8IBhJhc= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-441-Mmc2oo8fNLG8ahMUdk-EXw-1; Tue, 03 Jun 2025 03:58:37 -0400 X-MC-Unique: Mmc2oo8fNLG8ahMUdk-EXw-1 X-Mimecast-MFC-AGG-ID: Mmc2oo8fNLG8ahMUdk-EXw_1748937516 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-442fda1cba7so24630665e9.1 for ; Tue, 03 Jun 2025 00:58:37 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1748937516; x=1749542316; h=content-transfer-encoding:in-reply-to:organization:autocrypt :content-language:from:references:cc:to:subject:user-agent :mime-version:date:message-id:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=CU0N6UgF0Wu801mnXgPiaSIy9UpUp1v4ajkhrRpQ1f8=; b=bQKMoW6bx5XeYMROKgQZjq8TQxCXG1LtpjKFiydrA5maztNlW4P8rnAm3xGm2JXg38 i7WoTfVcACMSZS34K/oepNV37UgnRsN24malEAIF+jAP6V26ECMKsQw+tIblu2RccSVg 84st3eWMNZ34m6w3AKx8Ba9MoufLWPfqdM4+RzzTTHmiYc92X3CpzBZ3+DZV1pPmyPeD fdSlStAxxnJdNdKZ4eLMgQLa9uJWeC5MValk900AW+NUhrble0bBOot8gqiVBJofR3mr F4gn4AWZsKAszfXP5n4IEyLajiR9G0RoXeVTDf+mHTAOqMTRKHS9BCzlmDU6eTOgNYVi kuIw== X-Forwarded-Encrypted: i=1; AJvYcCWON2lZQnMPleXk29DS8Nm+QaaMQbCG/tZeiCqNoR5ANDbHeohhDT5M2nAvIcspL1Sna6/vd3oJ+TBSQ1o=@vger.kernel.org X-Gm-Message-State: AOJu0YzV6u0y1XioSIa0JPQrrnC2Ter6x1D3hqiMHCE1M7meNAEglo5p mY1YBvvEXs/Gts+CFcvq6VUNJ25Jfcgfs3fdV/qqF91RXToKO+kl7dE/uFm+N8Kd5y50rAFIc6r uj7d9OmBz2NKU8+lLaE/XotRiL77NOEOd23ytNRxqVg+dnj8luZQsswYsZYOJpI3e2w== X-Gm-Gg: ASbGncs9KJVVK8GV8iKoKCk7dRobyvraJvnFUHAzrfsVWBgO9oMAd/cuhAoJzSPFWhq IzkewS/kkmGHEbSjUP0T/JWIG445YtPQkpFwysnI1qjDya69A5/bdR7yhXlbQE9Gotma/vLW0YK KFZmH7CDxd4TkP7Hfr4W4yGjy5tajHRIa9W+wiZ//nkECT3fE8vhfkF2u3/T0qOSiG2Tpv8dPsB npdS7K07gbIV1SKgZ/XpqsQU6s8/xmy/HaViwj7Rl+0l6sXKYuJfQovUJswvg1D7l60SktJ3q9K iQ5kALYM9n0rd+MyO0alACcvXOIneOXkmS731xpqYYwEASJropBaBVKlNi3MDdgJar1JzN9RjgB Ooye+OtXpv9rb6C1/toDMM1g846vXyb2FHX9HSeM= X-Received: by 2002:a05:600c:3e83:b0:43d:7588:667b with SMTP id 5b1f17b1804b1-450d8846c1dmr174157545e9.10.1748937516079; Tue, 03 Jun 2025 00:58:36 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFuF8+vnhtRNmRyCVVcDcXRSlMRzaw2IM+WDvELnB/XLtRFKZRwQLOj0Esqbuh3xRvpcNyDMA== X-Received: by 2002:a05:600c:3e83:b0:43d:7588:667b with SMTP id 5b1f17b1804b1-450d8846c1dmr174157115e9.10.1748937515629; Tue, 03 Jun 2025 00:58:35 -0700 (PDT) Received: from ?IPV6:2003:d8:2f0d:f000:eec9:2b8d:4913:f32a? (p200300d82f0df000eec92b8d4913f32a.dip0.t-ipconnect.de. [2003:d8:2f0d:f000:eec9:2b8d:4913:f32a]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-450d7fb00ccsm151727445e9.17.2025.06.03.00.58.34 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 03 Jun 2025 00:58:35 -0700 (PDT) Message-ID: <053ae9ec-1113-4ed8-9625-adf382070bc5@redhat.com> Date: Tue, 3 Jun 2025 09:58:34 +0200 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] xarray: Add a BUG_ON() to ensure caller is not sibling To: Dev Jain , Zi Yan Cc: akpm@linux-foundation.org, willy@infradead.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, anshuman.khandual@arm.com, ryan.roberts@arm.com References: <20250528113124.87084-1-dev.jain@arm.com> <30EECA35-4622-46B5-857D-484282E92AAF@nvidia.com> <4fb15ee4-1049-4459-a10e-9f4544545a20@arm.com> <8fb366e2-cec2-42ba-97c4-2d927423a26e@arm.com> From: David Hildenbrand Content-Language: en-US Autocrypt: addr=david@redhat.com; keydata= xsFNBFXLn5EBEAC+zYvAFJxCBY9Tr1xZgcESmxVNI/0ffzE/ZQOiHJl6mGkmA1R7/uUpiCjJ dBrn+lhhOYj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5deGuwxgb65pWIzufa N7eop7uh+6bezi+rugUI+w6DABEBAAHCwXwEGAEIACYCGwwWIQQb2cqtc1xMOkYN/MpN3hD3 AP+DWgUCXw7HsgUJEqkpoQAKCRBN3hD3AP+DWrrpD/4qS3dyVRxDcDHIlmguXjC1Q5tZTwNB boaBTPHSy/Nksu0eY7x6HfQJ3xajVH32Ms6t1trDQmPx2iP5+7iDsb7OKAb5eOS8h+BEBDeq 3ecsQDv0fFJOA9ag5O3LLNk+3x3q7e0uo06XMaY7UHS341ozXUUI7wC7iKfoUTv03iO9El5f XpNMx/YrIMduZ2+nd9Di7o5+KIwlb2mAB9sTNHdMrXesX8eBL6T9b+MZJk+mZuPxKNVfEQMQ a5SxUEADIPQTPNvBewdeI80yeOCrN+Zzwy/Mrx9EPeu59Y5vSJOx/z6OUImD/GhX7Xvkt3kq Er5KTrJz3++B6SH9pum9PuoE/k+nntJkNMmQpR4MCBaV/J9gIOPGodDKnjdng+mXliF3Ptu6 3oxc2RCyGzTlxyMwuc2U5Q7KtUNTdDe8T0uE+9b8BLMVQDDfJjqY0VVqSUwImzTDLX9S4g/8 kC4HRcclk8hpyhY2jKGluZO0awwTIMgVEzmTyBphDg/Gx7dZU1Xf8HFuE+UZ5UDHDTnwgv7E th6RC9+WrhDNspZ9fJjKWRbveQgUFCpe1sa77LAw+XFrKmBHXp9ZVIe90RMe2tRL06BGiRZr jPrnvUsUUsjRoRNJjKKA/REq+sAnhkNPPZ/NNMjaZ5b8Tovi8C0tmxiCHaQYqj7G2rgnT0kt WNyWQQ== Organization: Red Hat In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 03.06.25 07:23, Dev Jain wrote: > > On 02/06/25 8:33 pm, Zi Yan wrote: >> On 29 May 2025, at 23:44, Dev Jain wrote: >> >>> On 30/05/25 4:17 am, Zi Yan wrote: >>>> On 28 May 2025, at 23:17, Dev Jain wrote: >>>> >>>>> On 28/05/25 10:42 pm, Zi Yan wrote: >>>>>> On 28 May 2025, at 7:31, Dev Jain wrote: >>>>>> >>>>>>> Suppose xas is pointing somewhere near the end of the multi-entry batch. >>>>>>> Then it may happen that the computed slot already falls beyond the batch, >>>>>>> thus breaking the loop due to !xa_is_sibling(), and computing the wrong >>>>>>> order. Thus ensure that the caller is aware of this by triggering a BUG >>>>>>> when the entry is a sibling entry. >>>>>> Is it possible to add a test case in lib/test_xarray.c for this? >>>>>> You can compile the tests with “make -C tools/testing/radix-tree” >>>>>> and run “./tools/testing/radix-tree/xarray”. >>>>> Sorry forgot to Cc you. >>>>> I can surely do that later, but does this patch look fine? >>>> I am not sure the exact situation you are describing, so I asked you >>>> to write a test case to demonstrate the issue. :) >>> >>> Suppose we have a shift-6 node having an order-9 entry => 8 - 1 = 7 siblings, >>> so assume the slots are at offset 0 till 7 in this node. If xas->xa_offset is 6, >>> then the code will compute order as 1 + xas->xa_node->shift = 7. So I mean to >>> say that the order computation must start from the beginning of the multi-slot >>> entries, that is, the non-sibling entry. >> Got it. Thanks for the explanation. It will be great to add this explanation >> to the commit log. >> >> I also notice that in the comment of xas_get_order() it says >> “Called after xas_load()” and xas_load() returns NULL or an internal >> entry for a sibling. So caller is responsible to make sure xas is not pointing >> to a sibling entry. It is good to have a check here. >> >> In terms of the patch, we are moving away from BUG()/BUG_ON(), so I wonder >> if there is a less disruptive way of handling this. Something like return >> -EINVAL instead with modified function comments and adding a comment >> at the return -EIVAL saying something like caller needs to pass >> a non-sibling entry. > > What's the reason for moving away from BUG_ON()? BUG_ON is in general a bad thing. See Documentation/process/coding-style.rst and the history on the related changes for details. Here, it is less critical than it looks. XA_NODE_BUG_ON is only active with XA_DEBUG. And XA_DEBUG is only defined in tools/testing/shared/xarray-shared.h:#define XA_DEBUG So IIUC, it's only active in selftests, and completely inactive in any kernel builds. -- Cheers, David / dhildenb