From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f74.google.com (mail-wr1-f74.google.com [209.85.221.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2DB332749C1 for ; Mon, 16 Feb 2026 08:52:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.74 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771231925; cv=none; b=Hsu6rbPZZGzQNH3A1JDh9Yl9xq/vSus1nPyRwPkGvrBCW584BgEqjG0Zhg84xJEKhcf0xrne0KJRxqth2IbhgT9QsnnB4R+NVVX7+LLhF7xGKbt8MJtV6EjoplI5fEo92BJI4Q4x1jBqcHYc0C2OdJuPLPNi/060+XwsjxdLizw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771231925; c=relaxed/simple; bh=Mm4a36sb1UZxgVEdUjrkBvqdvl5PSflqiquLY7npOW4=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=Voa1l0gEuAajidptHRetMBl3GKqLpBkqve9GWOUl3RPkVJXtyGxw4AxUDl+AUAFQxsPMSYJhDMQxn4xLZiKPlSP8/Qztiu8hrSxf02fytYfWS5Yo8DoR/092hW8EI/0VyOPNWvvoGsv5ds2Z1FN3D5oUvC6xszZWqWXCK6Fo0l0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--aliceryhl.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=ES4AwBmz; arc=none smtp.client-ip=209.85.221.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--aliceryhl.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="ES4AwBmz" Received: by mail-wr1-f74.google.com with SMTP id ffacd0b85a97d-435add03f12so2165728f8f.3 for ; Mon, 16 Feb 2026 00:52:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1771231922; x=1771836722; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=kjj5IXbObxNi606Z5qjJ0Qk+HGDfGi8eP2D19UZKb1Y=; b=ES4AwBmzlWbwunZTh1JNnPykwwuqG2mL7LJYj0nbFp529CYAQ6KUEzjPrmK51oM7HW 9vYY57FRVjcEFLpVk2k+YaiUt3ePj9jpYma4OqIqtO49xPKO7bmwnIlULlreFkdZoKm0 wgps9vkR3BzEC2PlE2QbKTamPhOtGXH8hH5OCEYcnKv0AhtCU3sokPbxI7B4EQUbrVm7 hLb4/QSYGpNgKwVTOa/gHBxSSYyMhYn1yHn5zMnyBhYYVZY62grWt9o8TVq3y+/9ji3D kI5LRMwxYwuWAXkPCSUjGMHHmLejMPoq3vMsiABuMqPcgN2rwI6Mbd/iiWwnGER8nIXH HH5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1771231922; x=1771836722; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=kjj5IXbObxNi606Z5qjJ0Qk+HGDfGi8eP2D19UZKb1Y=; b=aRZdwKBXILCEkK5IMTYgMUUWMACecLUuUcq5mFGRiP/27eaA3xi70M2wfuakSVekAp GAhscVe2PnjxtY2KggI4pmYckKDW6OAPUuAUYR9TJ0uv+yR2or11pCoDUk915qS8Kyt4 u4UjW1oggpmPsmclUkbZNKwA15ouvE6VredEA2A85cUNzuH8xVChQNDQ0KG2scFUd7th 0yq3msZOp9QIr86at3MPMP9YSbaZElYLU29Ja5h3BQNwwdJv4+jC7PgMw0lsd/F5T83q g62bjA7kk4FCAvQfqugNwVzSjHkq1LhthZXjDp2wfPGvXSMNtGz2byuw9PStlr2LunJr KGTQ== X-Forwarded-Encrypted: i=1; AJvYcCXlylEH24zlOLJ99ql0ZzQrm2voCfuFpwqpVI214EHEhAlZ/RJD3YSOMREytwNgEErsN2HB57i0JijnPaQ=@vger.kernel.org X-Gm-Message-State: AOJu0YyMa9zU6vAz4m3xMzFzZIl2gdM+419uIAwNAhExdyIlm2wvrl1b n07HBTgAkHD4ias/z2OhuuVahWIyorofWDA30ZtwgPJk0natv3PBXnHa/GrHiEDCuMyyaNctsRk G1rGuzE9n/q3MMA8oOQ== X-Received: from wrvf7.prod.google.com ([2002:a5d:5687:0:b0:436:d0e7:35fd]) (user=aliceryhl job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6000:240e:b0:437:6906:8235 with SMTP id ffacd0b85a97d-4379db2576fmr11778027f8f.3.1771231922263; Mon, 16 Feb 2026 00:52:02 -0800 (PST) Date: Mon, 16 Feb 2026 08:52:01 +0000 In-Reply-To: <20260215-page-additions-v1-1-4827790a9bc4@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260215-page-additions-v1-0-4827790a9bc4@kernel.org> <20260215-page-additions-v1-1-4827790a9bc4@kernel.org> Message-ID: Subject: Re: [PATCH 1/2] rust: page: add `SafePage` for race-free page access From: Alice Ryhl To: Andreas Hindborg Cc: Lorenzo Stoakes , "Liam R. Howlett" , Miguel Ojeda , Boqun Feng , Gary Guo , "=?utf-8?B?QmrDtnJu?= Roy Baron" , Benno Lossin , Trevor Gross , Danilo Krummrich , linux-mm@kvack.org, rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" On Sun, Feb 15, 2026 at 09:03:30PM +0100, Andreas Hindborg wrote: > `SafePage` wraps a regular page but adds an invariant that the page data > area does not incur data races. This means `SafePage` cannot be mapped to > user space or shared with devices, and it becomes simpler to directly > reference the contents of the page. > > Signed-off-by: Andreas Hindborg > impl Page { > + fn alloc_page_raw(flags: Flags) -> Result, AllocError> { > + // SAFETY: Depending on the value of `gfp_flags`, this call may sleep. Other than that, it > + // is always safe to call this method. > + let page = unsafe { bindings::alloc_pages(flags.as_raw(), 0) }; > + NonNull::new(page).ok_or(AllocError) > + } Could potentially just implement Page::alloc_page() in terms of SafePage::alloc_page() > +/// A page whose data area does not incur data races. > +/// > +/// [`SafePage`] has the same usage constraints as other Rust types. Thus, it cannot be mapped to > +/// user space or shared with devices. This makes it safe to reference the contents of the page > +/// while the page is mapped in kernel space. > +/// > +/// # Invariants > +/// > +/// There are no data races for the contents of this page. This isn't really a great invariant. You could say something more direct such as "has exclusive access to the contents of the page". Alice