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 9D20EE65D03 for ; Thu, 21 Nov 2024 23:18:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B28296B007B; Thu, 21 Nov 2024 18:18:36 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id AFECA6B0083; Thu, 21 Nov 2024 18:18:36 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 99F616B0085; Thu, 21 Nov 2024 18:18:36 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 7C2D36B007B for ; Thu, 21 Nov 2024 18:18:36 -0500 (EST) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 02AE01C8132 for ; Thu, 21 Nov 2024 23:18:35 +0000 (UTC) X-FDA: 82811665650.09.6E0F47C Received: from mail-lj1-f182.google.com (mail-lj1-f182.google.com [209.85.208.182]) by imf13.hostedemail.com (Postfix) with ESMTP id E99C72000D for ; Thu, 21 Nov 2024 23:17:35 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=OLZ6gdPl; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf13.hostedemail.com: domain of abdiel.janulgue@gmail.com designates 209.85.208.182 as permitted sender) smtp.mailfrom=abdiel.janulgue@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1732230977; a=rsa-sha256; cv=none; b=1Ld/6XCO71WDFEdeZzPQuz4KTsatqJDKgbfck1xik5mT2/YAY74XzPoEZwX9HIBXtnBBr6 3Pdmw4oEoTOrTQsjEQB1QvInNKMN3uR1tK0nVXZ4m9Dv42Kx/AXa1LVtV74GXwpTCYonDX LcavKa1CIKm5dlNJA61dhcoZjuSKeLw= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=OLZ6gdPl; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf13.hostedemail.com: domain of abdiel.janulgue@gmail.com designates 209.85.208.182 as permitted sender) smtp.mailfrom=abdiel.janulgue@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1732230977; 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=OL9X8Kvpun/SWWLLZPeJ5t6X+R0QyKBPzXrsZ+HbodE=; b=glpGo7D3x38EXOIANUseng/DaUPcpA/bIV2AMbol5g3QMGxW+fNT2jCC4c/FaZFAo/bUUN 1LdAERtximJunDOlQTNhMCWdR6sVo1h4P5PZuU+wLkpwhkFWA3NRJGQiELWop8fJOKc3S1 h8/qpsAW/9eNOpOHEjatWhjYqU8TkVU= Received: by mail-lj1-f182.google.com with SMTP id 38308e7fff4ca-2f7657f9f62so16086061fa.3 for ; Thu, 21 Nov 2024 15:18:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1732231112; x=1732835912; darn=kvack.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=OL9X8Kvpun/SWWLLZPeJ5t6X+R0QyKBPzXrsZ+HbodE=; b=OLZ6gdPlSAtQwpaM39ORMBuRYK94VnpaLK2DmjNQ8JBNKyuyrVXoEkHhmMSAuZzJlz YiisaoZFCrh193HLwKVPEKb+VdfyPOvw3D9nAMraw9sZDmZrrM+bjh8CBVx5KFRzpkCB Ol6+RHlBVZIWqCnlgiR0ee8nDQFQfcPcXT4Iltn+A92EML4py58JHReYLmnNweuH8mSA KuJq2PyOgeKsyKE+s6f4WKFHmZ067FzekpxS/MjqZpZ44ZYRvOT8rhQkzx6p79SSPeFl vFPdvXnYNLKD5jGpTYStZ1HSKcoyNz+5BkiGeNQLww+0zOc36ziKNfHNQ+MXNvh0PurW bYKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732231112; x=1732835912; h=content-transfer-encoding:in-reply-to:from:content-language :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=OL9X8Kvpun/SWWLLZPeJ5t6X+R0QyKBPzXrsZ+HbodE=; b=HF/Xj5jyB8BEFQgpIGWT6ZkXm5V5DkHmqzvbiW2gP4UndhLftwK5GvsoGflVxFCegv Wbmdi64rW1ixekIBpYeHinQ6dNSYbRosgslfVgrP5Qpsu9DJgWXhRy+yP8eI22+Z4kbs pS/MxaOMSVWwp7Wz5U99PiOgIdp2LnOW9IOCgAzTdtf9kRhWpAsQ6v9m4lhYPO+/VOXw w385T8ukHkFhEpXW870wt4oy6j4iYc/lMg/CA+0ZsAY1s3B5mBmsb3Z6m1gH82FWh6W8 p+JKb9XaDXY6XlvIjh8DxuRq7BtZ0dyqP+B5iJmyYDT8dY7b/qmzv7qgF8A3tQpJmXRZ uG9A== X-Forwarded-Encrypted: i=1; AJvYcCVpkX7uWuP6nRxuRAAagEvG9Ky/RM9tmaHVV4qDpiKk0fYfR+FTicXb48XwBPK0HKssGQjHYxPI4w==@kvack.org X-Gm-Message-State: AOJu0Yx4WlyXOC8Ca8qAeZlEgV7ESR2ATdSwdoObQKYYtG2P0e5VdBkw UpMWYcs3qHmmvFTW2hv9yWfAL8rzm75so9dJCgmvm+RNx0elgRKp X-Gm-Gg: ASbGncthSk8+aUIVAStVZCTzac+T3t2SWrCHKr2TjJfTRUfqYrICrviai0D6f63iiWb 6aDHntGp2P7jSF0eBB7eVjm9fGFhqnRU2ACm8JdhOjzqQfkCTOVkKURSLhDG1/21dW4H3xYgciu Zn+ViUH5BcMLk6DIx277MowEBEhE4lrVZhB3CV37kBQv2ht7oHqxDUYfWt2yyfJPVGNHPYg/GkR uzxAl0NfoBpMTf8lAb853wu4qX9RYLfGf9FTEr85t1ucUujV+d0uqyXIuwF9+0MdY3RVqPZM6RR /P9ufrTiiGqubSDKYZWg X-Google-Smtp-Source: AGHT+IFBaOmLQRpRczqhiz1RGt8haQlGaTHwb+yghySwACcam9Nx+3MpjLfSASNv2RxM49KxOTq4lw== X-Received: by 2002:a05:6512:3ba2:b0:53d:a883:5a3e with SMTP id 2adb3069b0e04-53dd39b0e57mr331517e87.39.1732231111612; Thu, 21 Nov 2024 15:18:31 -0800 (PST) Received: from [192.168.1.146] (87-94-132-183.rev.dnainternet.fi. [87.94.132.183]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-53dd248997esm110198e87.181.2024.11.21.15.18.28 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 21 Nov 2024 15:18:30 -0800 (PST) Message-ID: <0195fb77-c55a-40d5-8fe2-5844158f4f63@gmail.com> Date: Fri, 22 Nov 2024 01:18:28 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v3 0/2] rust: page: Add support for existing struct page mappings To: Matthew Wilcox , Boqun Feng Cc: Alice Ryhl , rust-for-linux@vger.kernel.org, Miguel Ojeda , Alex Gaynor , Gary Guo , =?UTF-8?Q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Trevor Gross , Danilo Krummrich , Wedson Almeida Filho , Valentin Obst , open list , Andrew Morton , "open list:MEMORY MANAGEMENT" , airlied@redhat.com, Kairui Song References: <98a46b27-c4bb-4540-8f75-f176c3f2fae1@gmail.com> <650846e4-b6a0-472d-a14e-4357d20faadb@gmail.com> Content-Language: en-US From: Abdiel Janulgue In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Rspamd-Queue-Id: E99C72000D X-Stat-Signature: krz5eupsg33n8psqjg3qrz4z7q83r187 X-Rspam-User: X-Rspamd-Server: rspam05 X-HE-Tag: 1732231055-421633 X-HE-Meta: U2FsdGVkX193lwb2KcUPjmOTDFqzycOl6+QSRs9TwO0tSPhzcWaqRFByGnhWrOG1Dg8PzuzMS17Ajr/sx10Ke154RYv3r0rBQxWE4+5U9GBqswzWw007I4POwAI2Ja/k1zHVANZWmDJTj/f3PoWPJEaQgVLy2EEiEqb94HMEp8eQMS44kO74yCa06upK5CI0DFCdjq22PNGH3tRQNweYVM3X1JJFwfYWKD3oHER5GkNPtxt1gVPt8p2F8YwbOhUpbpotxrvMRMCy/U2AxAIByInbl51oLa/HTW8UYDmsbfI1D4aQCNqq8hkmfcgGuENDp809+OuY25EHOF8p0z5Wg9Rthhs3YcSGSAyx8WIQv0GxyHxl6/uZsdVTjhjh8drL/I9jW55GY+tiK763yb1pvEpXobO2IxEyJlFjLk/wHtmizHgnvzu6Iovk9h3j0YC2JAlRhusoyLzoU2hq0wg9bqQ4VCY2vU3STTb36Tbl6TvhkkMREeAwixZSZgKnYS4I4f5bHjXC3DpcBASBC6FCTLbsRzUt4rT6ks7O5hMVnqHV64jmdz4yh45rEhlNhXqUh2SSH6gXnDfePmGZKaFhf04tlk4kG3OJnRav2ughdwXk8vbQtgoNieNu9xIpKZW97J+zx1Te9mVN3IvsmA+eL+lWfxUpatPcR+66cpXipUeeOqj9IVLxCFPP57t2r4Xw9hQFyfkmmJAoqEqtOJNrCu9wVzpEDpWbljO//mHrKYB0mdPOryrGcHtZLgmVBo/wy8Dz8zOdWN4GZ8jNZSFVrlSJAsJEm+XeEPMyOyDeG/B21jRKf1EidY/tV063dH30+KuJlAsNtqTJRJ27QixlaC4uKvRkFV6wT6VFOWOOw9+0PxVDyDY8hw1jf7v0CcOBlqBcHE5VdJNUxHX8yW1VJvwkQs2dlI3ZQu579zSafo5A+SP1UJ0M2UZ9y8qBDzHgPXJ8nx3wIPzJO+1T8HP rGjf4S+f AUc3uAkNkZFSpQGqWwSVVMO7m99N5e3V6J8JEhLxs3AdYbsH+ZlcxuAqglIIgMJ1iDYW7atjjLFXauWgm8YhTkY05RSYlJyWYi0mL3VkRXIQqiqyXtmx7EhSrFN7VGCRe0DicsjDylz0tGvpEnqHWRhNu3R2oydsim5enfRhgU1FoBD6uCtpwriSQQ9Xnnie91BrZ3mB3I2e0iIUM/at7ocrhbgmaORLoHdzzy9BtXXesD1FaRyt4Ia3GzDNuY2V6nscGLpQN2qXzj2A15RIVP1H0hS/+QEhCgwcFtup2d0Wd+xoI7vCacw3AmbM7u//pRgdYpN61mnOVQWABVNGpvNJzRdkcyyMOiKM73awFdkQg/MBvRfV6H78ksrOESRNn6qU4oSkVzknbNnSRg/8vZRZed4BlCVCXSZ9mHoJ2DeK5P33ZKOk6CpSF7baYug7BluTKH18rRyuV110psH7eESME654mi80rOLWZjHczQpz0oFsI6Sulpbm81wg42HyAKGTo9PSFAKEegwFMKd+1+9JTYccIA7qDWdjUZG50NSmCTcYeyeboOMwKSg== 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: On 22/11/2024 00:01, Matthew Wilcox wrote: > On Thu, Nov 21, 2024 at 11:12:30AM -0800, Boqun Feng wrote: >> On Thu, Nov 21, 2024 at 11:30:13AM +0200, Abdiel Janulgue wrote: >>> Hi Boqun, Matthew: >>> >>> On 21/11/2024 02:24, Boqun Feng wrote: >>>>>> So if I understand correctly, what Abdiel needs here is a way to convert >>>>>> a virtual address to the corresponding page, would it make sense to just >>>>>> use folio in this case? Abdiel, what's the operation you are going to >>>>>> call on the page you get? >>>>> >>>>> Yes that's basically it. The goal here is represent those existing struct >>>>> page within this rust Page abstraction but at the same time to avoid taking >>>>> over its ownership. >>>>> >>>>> Boqun, Alice, should we reconsider Ownable and Owned trait again? :) >>>>> >>>> >>>> Could you use folio in your case? If so, we can provide a simple binding >>>> for folio which should be `AlwaysRefcounted`, and re-investigate how >>>> page should be wrapped. >>>> >>> >>> I'm not sure. Is there a way to get the struct folio from a vmalloc'd >>> address, e.g vmalloc_to_folio()? >>> >> >> I think you can use page_folio(vmalloc_to_page(..)) to get the folio, >> but one thing to notice is that folio is guaranteed to be a non-tail >> page, so if you want to do something later for the particular page (if >> it's a tail page), you will need to know the offset of the that page in >> folio. You can do something like below: > > This is one of those things which will work today, but will stop > working in the future, and anyway will only appear to work for some > users. > > For example, both vmalloc and slab allocations do not use the refcount > on the struct page for anything. eg this will be a UAF (please excuse > me writing in C): > > char *a = kmalloc(256, GFP_KERNEL); > struct page *page = get_page(virt_to_page(a)); > char *b = page_address(page) + offset_in_page(a); > // a and b will now have the same bit pattern > kfree(a); > *b = 1; > > Once you've called kfree(), slab is entitled to hand that memory out > to any other user of kmalloc(). This might actually work to protect > vmalloc() memory from going away under you, but I intend to change > vmalloc so that it won't work (nothing to do with this patch series, > rather an approach to make vmalloc more efficient). > > One reason you're confused today is that we have a temporary ambiguity > around what "folio" actually means. The original definition (ie mine) was > simply that it was a non-tail page. We're moving towards the definition > Johannes wanted, which is that it's only the memdesc for anonymous & > file-backed memory [1]. So while vmalloc_to_folio() makes sense under > the original definition, it's an absurdity under the new definition. > > So, Abdiel, why are you trying to add this? What are you actually > trying to accomplish in terms of "I am writing a device driver for XXX > and I need to ..."? You've been very evasive up to now. Background behind this is that we need this for the nova rust driver [0]. We need an abstraction of struct page to construct a scatterlist which is needed for an internal firmware structure. Now most of pages needed there come from vmalloc_to_page() which, unlike the current rust Page abstraction, not allocated on demand but is an existing mapping. Hope that clears things up! Regards, Abdiel [0] https://rust-for-linux.com/nova-gpu-driver