Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1tFvj5-00039e-UK for mharc-qemu-rust@gnu.org; Tue, 26 Nov 2024 08:35:35 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tFvj2-00038z-HB for qemu-rust@nongnu.org; Tue, 26 Nov 2024 08:35:33 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tFvj0-0008RL-Bp for qemu-rust@nongnu.org; Tue, 26 Nov 2024 08:35:31 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1732628127; 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=J/WMazwLDcVs71OKEl1CHvYjffjtAQIjP5TA8DAH+sw=; b=C/8ud2vdlTmG3okTap8aeTmenLbEp6DwOK8CIlG7maallG/Ier5vtaDzgJdtXoMBHJMjr0 oXEIgOR6U7CToRk7nrG6i35ZczLA4RZxnzNo1YVLLB76Y8L6Z0RcZCyzjYuGSwuqdFyy/y Dj8hLrbsoSC7tTpNzO86uAEH9ujNIoI= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-407-5WseO7PDP5ig7qJVZaOr0w-1; Tue, 26 Nov 2024 08:35:26 -0500 X-MC-Unique: 5WseO7PDP5ig7qJVZaOr0w-1 X-Mimecast-MFC-AGG-ID: 5WseO7PDP5ig7qJVZaOr0w Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-3823527eb9dso3093358f8f.1 for ; Tue, 26 Nov 2024 05:35:26 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732628125; x=1733232925; h=content-transfer-encoding:in-reply-to: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=J/WMazwLDcVs71OKEl1CHvYjffjtAQIjP5TA8DAH+sw=; b=RvdxkxVt4me2ebWOpHS/VQwHswrPLqUK2Sjo4i98J+R+bZzBdDl0Wk77qNSmZGwMKC CBPdK1SJ7BLcp5miOsFxMswJjIm6jpijTjzTiWK2kub558Hl2DbRcO+gcxW3KstJjS1m PfSED5eMn1h65lTFEbeiuw4Y++/ckufytj/Ava+7fdgEj6CHygwZ/4KCxEpnnvL94zji WUEMXKV7B9oJy5/L+EF7P9mTtD6bpfcTnAFm+YxSk4KGo2cTNrJ/lMMqyiGsIz8LCiPt NMmq7tPWB74JWDdNzuJy9913OpT3LhLodnpVvqgtZqsrH3YCUkvKvopVTiPelhioWW4x PbEQ== X-Forwarded-Encrypted: i=1; AJvYcCVF6X92r8zmIV/luKxQSHVZ1ysa0aSblFQBzjkMmSZUWs9sxKswHe3J62+bPmw4JO5qGuHUV0RVGtM=@nongnu.org X-Gm-Message-State: AOJu0YxuS/ofL0GqizEOsuUwJ9k9EHoLX0ztFkV9pnm0PMuYQdOqP8ha vQ0HmFwuaU1MXNKHlnqr5izAFw9e1iQxbiMySGtzTLOblKqScR3v97/fFOvgGXlDCFldDxx7ZjX iEKdk1NHSThaKkDQfjntzJS98C6I2ZyFL6CliR5yj6pkNLhX+2CTRaUydIk4= X-Gm-Gg: ASbGncv3dNL4pYVrZ27YdGi5SVZjRAvYqcsqRNyJ3eqzo+2eMz7dLslmquHTke+tNYu nAbYperT3o0rXXfXabqdFZwHNd0YSL2eDjV7TA1DXdMYY5vvbaAoyDfmV8tyviNoOPi8e7lpA4j qP91SfnxGp+nmKtzmml+ih4hJ8VhV6Xf+ICvJhs+Lq+xCVy/JGhQ7cW08Ns8r6zoOo8wcUDFCbp Y8E9OUaEFvdGPtbvfUI+S0aL3ulyLDVVYdQklL/9ml28GSR6838s+A= X-Received: by 2002:a05:6000:42c6:b0:382:4460:49ad with SMTP id ffacd0b85a97d-38260b986a4mr8376125f8f.32.1732628124822; Tue, 26 Nov 2024 05:35:24 -0800 (PST) X-Google-Smtp-Source: AGHT+IHAD9YksD4WOc8rI3h5sHOhd5QwF4bbCecVK9Y8sRkXSaHZ03mCoQOYKT8BqJubenH7hXkAbA== X-Received: by 2002:a05:6000:42c6:b0:382:4460:49ad with SMTP id ffacd0b85a97d-38260b986a4mr8376117f8f.32.1732628124515; Tue, 26 Nov 2024 05:35:24 -0800 (PST) Received: from [192.168.10.28] ([151.49.236.146]) by smtp.googlemail.com with ESMTPSA id 5b1f17b1804b1-434921ceea7sm114503795e9.25.2024.11.26.05.35.23 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 26 Nov 2024 05:35:24 -0800 (PST) Message-ID: <7a59cb8a-3da2-45d8-9c8a-92132374cecb@redhat.com> Date: Tue, 26 Nov 2024 14:35:22 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 2/2] rust: add bindings for interrupt sources To: Zhao Liu Cc: qemu-devel@nongnu.org, junjie.mao@hotmail.com, qemu-rust@nongnu.org References: <20241122074756.282142-1-pbonzini@redhat.com> <20241122074756.282142-3-pbonzini@redhat.com> From: Paolo Bonzini Autocrypt: addr=pbonzini@redhat.com; keydata= xsEhBFRCcBIBDqDGsz4K0zZun3jh+U6Z9wNGLKQ0kSFyjN38gMqU1SfP+TUNQepFHb/Gc0E2 CxXPkIBTvYY+ZPkoTh5xF9oS1jqI8iRLzouzF8yXs3QjQIZ2SfuCxSVwlV65jotcjD2FTN04 hVopm9llFijNZpVIOGUTqzM4U55sdsCcZUluWM6x4HSO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OZE/TT88qvEdhiIVUogHdo4qBrk41+gGQh b906Dudw5YhTJFU3nC6bbF2nrLlB4C/XSiH76ZvqzV0Z/cAMBo5NF/w= In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: hxH5tl2Eq3MJ3JUTx0eEUBw21d92NKdzpKI3iZjzoSU_1732628125 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Received-SPF: pass client-ip=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -29 X-Spam_score: -3.0 X-Spam_bar: --- X-Spam_report: (-3.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.931, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-rust@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: QEMU Rust-related patches and discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 26 Nov 2024 13:35:34 -0000 On 11/26/24 14:45, Zhao Liu wrote: > On Fri, Nov 22, 2024 at 08:47:56AM +0100, Paolo Bonzini wrote: >> Date: Fri, 22 Nov 2024 08:47:56 +0100 >> From: Paolo Bonzini >> Subject: [PATCH 2/2] rust: add bindings for interrupt sources >> X-Mailer: git-send-email 2.47.0 >> >> The InterruptSource bindings let us call qemu_set_irq() and sysbus_init_irq() >> as safe code. >> >> Interrupt sources, qemu_irq in C code, are pointers to IRQState objects. >> They are QOM link properties and can be written to outside the control >> of the device (i.e. from a shared reference); therefore they must be >> interior-mutable in Rust. > > Out of curiosity, are there any examples of this situation? Yes, qdev_connect_gpio_out_named() changes the pointer that is stored into the InterruptSource. >> + /// Send `level` to the interrupt sink. >> + pub fn set(&self, level: bool) { >> + unsafe { >> + qemu_set_irq(self.0.get(), level.into()); >> + } >> + } > > Regarding the boolean discussion, the c_int/i32->boolean conversion > seems unavoidable if it is changed to a boolean, for example, the > level parameter in qemu_irq_handler is declared to be c_int, and > there is a pattern of setting the level in qemu_irq_handler with the > level irq: > * hpet_handle_legacy_irq > * split_irq_handler > * a9mp_priv_set_irq > ... > > So it feels like a more direct way to follow the use of c_int or i32? > Inconsistent types for level are always confusing. Maybe we can change > the type of rust after the C version can be standardized to boolean? The problem is that auditing the C version would be quite some work, which is why I proposed adding the generic argument to Rust. On the other hand, it's relatively common in C to write int when you mean bool, because bool is a relatively recent ("only" 25 years :)) addition to C. >> + pub(crate) const fn as_ptr(&self) -> *mut *mut IRQState { >> + self.0.as_ptr() >> + } >> +} >> + >> +impl Default for InterruptSource { >> + fn default() -> Self { >> + InterruptSource(BqlCell::new(ptr::null_mut())) >> + } >> +} >> + > > I like this idea and this binding is very useful! > > HPET also needs qdev_init_gpio_in() and qdev_init_gpio_out(). > Should these two safe binding wrappers be implemented as methods of > DeviceState, or just the public functions? qdev_init_gpio_out() is basically the same as sysbus_init_irq() and it can be added to DeviceState. qdev_init_gpio_in() is more complicated because it includes a function pointer. For now please keep it as a direct call to bindings::qdev_init_gpio_in(), but we'll have to tackle callbacks soon because they appear in all of chardev, GPIO inputs and timers. Paolo