Received: by 2002:ab2:6816:0:b0:1f9:5764:f03e with SMTP id t22csp3272216lqo; Tue, 21 May 2024 11:36:54 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXUNRTNgqzAghNwn0ALicP+RnY2/H3+p2yVcgNhi08vV3sMBL6589KxzJCU3+MS0Uq9S573iDVH9CLgfyOw3i57qL0niKS61SRLXc0Fdg== X-Google-Smtp-Source: AGHT+IGt6rfV1wnFHFQ9y0iBjlsY+wEnj1AZ63z8nyTAxhqfHiJuBWgSWQ3R89ARhmlmSqw3Xtin X-Received: by 2002:a05:6808:13d0:b0:3c9:c373:1814 with SMTP id 5614622812f47-3c9c3731dc1mr19288043b6e.53.1716316614085; Tue, 21 May 2024 11:36:54 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716316614; cv=pass; d=google.com; s=arc-20160816; b=BNF/KuVoN6J/KnwSXKD9e7efdMOTB73bSdThGAzHyzOULIg1LEkw5oghgnOwJpO37M UBJXDfZheJfXC+Q3Xh0HTULGUjCwfh4CDQRpdMvuc3u3g9aSsD7x6sAGdZpLkXKHXA2K trCpSESlhUDKk9qFrSML+ishONSRCrTug0pej62Q0tOxBpDPCtW3uZqhxS7fvsT81KvM r1/Pb0Q4tgHu5PPoYlywVlTxH1eRUxoK4CB6AF0t/MVI5aKG86HoXf0uL7ogtr4d50gU 6vjsmD1Ruag7Rg4F7lEUZHRI1PZQWtivgEL2LPnE6QshJjOQTWWZqnz6I7Y4H4x4aoi3 DfXA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:message-id:subject:cc:to:from:date:dkim-signature; bh=jevMKRBxb/R55R0RVyGAIvU9KnGm8nwwPq1TksVQuy8=; fh=6xzFMUVJeUqPttI3iG4Kx9bjgMAVOh8dcFPNttCKTvo=; b=g9mIicNON6Mu67QjUCBXieVeb6To/I04aja9/V1OA1+lXMqXHro5pmHtHqJrFJVf3x SqtK7e8RTy3YZ9g5tCPRp38/BKUBVEVC+G/kXeEQjgkg/29hDBgh3v76T71jq3xvkX7/ 1ZDC0LbmqnCBzNl2N32Sb/Y6kHHoN5wN6E7TCQqiKeWU5r8zxQPGyJR3R2Tfgd4m4J/x CqOZ+uN3qCgaTBj3gVnhQGj2VGa9r6CAElQUbFE7frxa28wqSCVcSby5U3rPnW2I3zWU OwuLm/kBt+8hvxTOqG9rlFMN/p/OaVaSL5Oo37JfD9HH/oUi6peu0D/aLwl+RKoMIt06 fLaQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=cANlZAMp; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-185330-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-185330-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id af79cd13be357-7930bd3b9a7si793407585a.312.2024.05.21.11.36.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 May 2024 11:36:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-185330-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=cANlZAMp; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-185330-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-185330-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id C60B91C21544 for ; Tue, 21 May 2024 18:36:53 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DD935148FFE; Tue, 21 May 2024 18:36:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="cANlZAMp" 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 6DCAA14884F for ; Tue, 21 May 2024 18:36:44 +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=1716316606; cv=none; b=gxYiSNokwDbnhrHBSSw90Zm6WWF2YHBnbKMv9mm6kgCX5oHjvoOLnUgE3GD5dqCY5dQShWq/cxLvT7kTEaraim8FR6MWz7I7LcniUpOUzWIXUhSmmhvYuCkWhKgQf0X8jbfuQF14c6W0Yh2NNs8WB3EJarrIBtne4J1STAjkFYQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716316606; c=relaxed/simple; bh=qvsdQhZ7BuP31Y2XO01pfGuDmUVoBr18WPXViDhgp8o=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=SoSOnilIymtboAk750mnHDC3q2TCRE/oAlyIDWV9B1uAwUgwfj4YoX0RaziC5Cj82YRuODuczlwlRWxhWISroM3OsAK7lyhsJG21a5rJ+ZyV1GSezPZIuU0D2QukCICCd11t5rOT8URg5lUBpWJEGzY2LbLJR4/IzLpI9SXNlcU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none 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=cANlZAMp; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716316603; 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; bh=jevMKRBxb/R55R0RVyGAIvU9KnGm8nwwPq1TksVQuy8=; b=cANlZAMpCaWVkzl7YhRboGpv/tZBDU6NydVl3uVF/Ine7bq1XBR2TWR3zf5GZc77MRkCfZ rQNtUO+XaJQQxWhAzMqevI9vp2BY9JecVq0GNurHFIDwua0bj8XN5wXT0oUcA64piZd9ZZ M9IrmICgX8PZnQUVlnBssRL525Ryxn4= 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-169-WGzUnwuvMqGDsep8lFp7og-1; Tue, 21 May 2024 14:36:40 -0400 X-MC-Unique: WGzUnwuvMqGDsep8lFp7og-1 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-420eed123a2so13969015e9.1 for ; Tue, 21 May 2024 11:36:40 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716316599; x=1716921399; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=jevMKRBxb/R55R0RVyGAIvU9KnGm8nwwPq1TksVQuy8=; b=mB5YG6Ei47o7632S6/I1ESbH2nHIQaiMdVEzAhBkrNpvI4II46WkT9YH6gs5I8bajN MxWKt8T89oaTNrH0cHiSytLOxaoa3S+68CwxilfGEWdvx8fTCQ1CCtI3JdPw2s1fc9pO 6xdG45teclX5qqPmjb0kymw8UHqpXDgrBNaRDEyGiNAP89/+JAzNGQlOGdOXiMqxn2Fq 6TExrpJsoGGGPLzFovodCBHzwoR3R6C9ryRsCAOUQ1dqYaIX8wlB2hGlDObW7KazydYe SL7HJVOan1tEUIfu6vQ7+060M/bTVi2vUcAhOv5MKRpzHsRWz3M4hRI+Oec/8OEnRGMh TsMw== X-Forwarded-Encrypted: i=1; AJvYcCUNvaW213K2zidewzH9ETzHFgspz5Onbhbi9d5rzV44A1WhB5M6KPVrmnz+aFaEMrNhfUsGwld7i5sdJKNyT5MBdeR0NwQJZWuQUdK5 X-Gm-Message-State: AOJu0YxfEEvCJ8dy9gAV0CtaxUd5DYnTNz/nyPQAV0eF5hzEOqM0igwZ e9Z2QtyxMfDXJQMwbxTWTcXefuov6YQBQmSWYS4erQnIrkSYm9TQTaf77zS0Qh7VgZU/dlWKkgW Ea9LiFCCDVByJgCJuHObP8FBV4Fbo3CuCove0OcewNnpZ5aEMjYH+mgHJUPfIHg== X-Received: by 2002:a05:600c:3b23:b0:41b:f3b6:e5da with SMTP id 5b1f17b1804b1-41fead61b59mr287566365e9.36.1716316599618; Tue, 21 May 2024 11:36:39 -0700 (PDT) X-Received: by 2002:a05:600c:3b23:b0:41b:f3b6:e5da with SMTP id 5b1f17b1804b1-41fead61b59mr287566195e9.36.1716316599179; Tue, 21 May 2024 11:36:39 -0700 (PDT) Received: from pollux ([2a02:810d:4b3f:ee94:abf:b8ff:feee:998b]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-351b4af0b0asm25792883f8f.100.2024.05.21.11.36.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 May 2024 11:36:38 -0700 (PDT) Date: Tue, 21 May 2024 20:36:36 +0200 From: Danilo Krummrich To: Miguel Ojeda , Philipp Stanner , wedsonaf@gmail.com Cc: gregkh@linuxfoundation.org, rafael@kernel.org, bhelgaas@google.com, ojeda@kernel.org, alex.gaynor@gmail.com, boqun.feng@gmail.com, gary@garyguo.net, bjorn3_gh@protonmail.com, benno.lossin@proton.me, a.hindborg@samsung.com, aliceryhl@google.com, airlied@gmail.com, fujita.tomonori@gmail.com, lina@asahilina.net, ajanulgu@redhat.com, lyude@redhat.com, rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org Subject: Re: [RFC PATCH 10/11] rust: add basic abstractions for iomem operations Message-ID: References: <20240520172554.182094-1-dakr@redhat.com> <20240520172554.182094-11-dakr@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: On Tue, May 21, 2024 at 11:18:04AM +0200, Miguel Ojeda wrote: > On Tue, May 21, 2024 at 9:36 AM Philipp Stanner wrote: > > > > Justified questions – it is public because the Drop implementation for > > pci::Bar requires the ioptr to pass it to pci_iounmap(). > > > > The alternative would be to give pci::Bar a copy of ioptr (it's just an > > integer after all), but that would also not be exactly beautiful. > > If by copy you mean keeping an actual copy elsewhere, then you could > provide an access method instead. As mentioned earlier, given the context how we use IoMem, I think IoMem should just be a trait. And given that, maybe we'd want to name this trait differently then, something like `trait IoOps` maybe? pub trait IoOps { // INVARIANT: The implementation must ensure that the returned value is // either an error code or a non-null and valid address suitable for I/O // operations of the given offset and length. fn io_addr(&self, offset: usize, len: usize) -> Result; fn readb(&self, offset: usize) -> Result { let addr = self.io_addr(offset, 1)?; // SAFETY: `addr` is guaranteed to be valid as by the invariant required // by `io_addr`. Ok(unsafe { bindings::readb(addr as _) }) } [...] } We can let the resource type (e.g. `pci::Bar`) track the base address and limit instead and just let pci::Bar implement `IoMem::io_addr`. As for the compile time size, this would be up the the actual resource then. `pci::Bar` can't make use of this optimization, while others might be able to. Does that sound reasonable? - Danilo