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 X-Spam-Level: X-Spam-Status: No, score=-0.9 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E566FC3F2C1 for ; Thu, 27 Feb 2020 21:06:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A70722469F for ; Thu, 27 Feb 2020 21:06:59 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=anarazel.de header.i=@anarazel.de header.b="LQScykUU"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="kSBa+vgL" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729685AbgB0VG7 (ORCPT ); Thu, 27 Feb 2020 16:06:59 -0500 Received: from out1-smtp.messagingengine.com ([66.111.4.25]:39483 "EHLO out1-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726758AbgB0VG6 (ORCPT ); Thu, 27 Feb 2020 16:06:58 -0500 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 181C322007; Thu, 27 Feb 2020 16:06:58 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Thu, 27 Feb 2020 16:06:58 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=anarazel.de; h= date:from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; s=fm3; bh=A5NPuU34XQSov1fBK0TRE0xsC3A j/eAKJgGOyd2Z3ps=; b=LQScykUUfXDZau4xvZEXkb4EiW1Y+YnW1rMEUbs1+hA Zg8qil2w7/yF4CA3L+aSArUC/PBwhgjxsgCfGbmRyOkp85gH+YutfW3yM/kKPcPJ aZfpXPxEGEYAcLrevFEwJsjfDbKoxw/ZtvOknxi52s0Nxo7V5Plb7p+EoGutWTmc aTQEZAo/WWRP6fdl7uF5vzoouECJZwFd9KDKv5uLm4qlezkZWnVMqAMwKg0e2d0s zCSOhTTQ7BKR0B3Bn446as2Pkf/I07PgweH91tDoDSxh5eVdwt7BAucysrPD4wyK aQyeCO8vOypunO6gOqgJUXCPMCPvEpxo1VBHRka5Mhw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm2; bh=A5NPuU 34XQSov1fBK0TRE0xsC3Aj/eAKJgGOyd2Z3ps=; b=kSBa+vgLIO1pgh1jZsPn4S t5hDalGcSK1/mDu6PgjIL23FOgF6pirw8Ty5XhZFOnztp7gLdN3M4KVZW55JeiPN R6giCp4P8H8cWp+PyY6TWMII3zucj/1Fa6TS16MJ8KqkEa7y7KczuRdEuSZ3Uy+J BzAjRr7h63MwDJSPzei/PfylU33dqoyzAB2ku/T16poumGHa2B1JeRwA1XqYpnvU AcwEfakuVjqOFdIeG/R/oMh5ebZ66tdNCaol+RmNyu4on5pgnOBhYoXS6vMQq1XX pc4sb1Bs06AeFq0JV5vJ4Gfy1IwCTIhElH8DAqjGuaxkwE1tIdCxDADkBKObYvcw == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedugedrleeigddugeefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvffukfhfgggtuggjsehttdertddttddvnecuhfhrohhmpeetnhgurhgv shcuhfhrvghunhguuceorghnughrvghssegrnhgrrhgriigvlhdruggvqeenucfkphepie ejrdduiedtrddvudejrddvhedtnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghm pehmrghilhhfrhhomheprghnughrvghssegrnhgrrhgriigvlhdruggv X-ME-Proxy: Received: from intern.anarazel.de (c-67-160-217-250.hsd1.ca.comcast.net [67.160.217.250]) by mail.messagingengine.com (Postfix) with ESMTPA id 36D63328006A; Thu, 27 Feb 2020 16:06:57 -0500 (EST) Date: Thu, 27 Feb 2020 13:06:55 -0800 From: Andres Freund To: Pavel Begunkov Cc: Jens Axboe , io-uring@vger.kernel.org Subject: Re: Deduplicate io_*_prep calls? Message-ID: <20200227210655.fr3cqphj2ab4z36n@alap3.anarazel.de> References: <20200224010754.h7sr7xxspcbddcsj@alap3.anarazel.de> <20200224033352.j6bsyrncd7z7eefq@alap3.anarazel.de> <90097a02-ade0-bc9a-bc00-54867f3c24bc@kernel.dk> <20200224071211.bar3aqgo76sznqd5@alap3.anarazel.de> <933f2211-d395-fa84-59ae-0b2e725df613@kernel.dk> <23a49bca-26a6-ddbd-480b-d7f3caa16c29@gmail.com> <065ee992-7eaf-051a-e8c5-9e0e8731b3f1@kernel.dk> <746b93f0-d0b5-558a-28c7-a614b2367d91@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Sender: io-uring-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org Hi, On 2020-02-25 12:26:34 +0300, Pavel Begunkov wrote: > On 2/24/2020 6:50 PM, Pavel Begunkov wrote: > It seems I have one. It can be done by using a const-attributed getter > function. And I see nothing against it in gcc manuals. > > __attribute__((const)) > static inline u8 io_get_opcode(struct io_kiocb *req) > { > return req->opcode; > } That's practically safe, I'd assume, but I'm not sure it's theoretically sound. The gcc manual says: > Note that a function that has pointer arguments and examines the data > pointed to must not be declared const if the pointed-to data might > change between successive invocations of the function. In general, since > a function cannot distinguish data that might change from data that > cannot, const functions should never take pointer or, in C++, reference > arguments. Likewise, a function that calls a non-const function usually > must not be const itself. and since req might be reused, this seems to violate the point about reading pointers that could change. Which certainly isn't the case here. Theoretically the compiler could e.g. understand that fallback_req or such should never change it's opcode. Greetings, Andres Freund