From patchwork Thu May 20 11:09:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 12269689 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=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham 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 B96AFC433B4 for ; Thu, 20 May 2021 11:14:19 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 5912F60FDB for ; Thu, 20 May 2021 11:14:19 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5912F60FDB Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:45978 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ljgd8-0007R8-Ea for qemu-devel@archiver.kernel.org; Thu, 20 May 2021 07:14:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44458) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ljgYV-0007jS-0Y for qemu-devel@nongnu.org; Thu, 20 May 2021 07:09:31 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:54086) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ljgYT-0004NN-5B for qemu-devel@nongnu.org; Thu, 20 May 2021 07:09:30 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1621508968; 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=9HmbSl5d9pXpS90PMMdxl3LY29W1LC7gy3N9ueCnGUQ=; b=DH0QLfxnyZvINS3SlQmnJ4TxUGSQTmtIk0pQzAbLaZDsWr6ComOse9mqTI0AJS7ZOfdDYI Z4W4YHBDRanVlTt+VqE/hsQPhfTSyerTvtAbmq3Z1JueJvkC4IVecovhKVbzwoQtGiL5xA 06V3PkNmAjuGtK6UyqqvJzYwy7m9hOQ= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-404-3lDD5V2SMWym14gmOXmPrQ-1; Thu, 20 May 2021 07:09:27 -0400 X-MC-Unique: 3lDD5V2SMWym14gmOXmPrQ-1 Received: by mail-wr1-f70.google.com with SMTP id c13-20020a5d6ccd0000b029010ec741b84bso8490350wrc.23 for ; Thu, 20 May 2021 04:09:27 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=9HmbSl5d9pXpS90PMMdxl3LY29W1LC7gy3N9ueCnGUQ=; b=I0Kxa33h94b8TEMekyF/CAC7WpJS6WpRB/7yTMEqi5LhekC1kU8Ll029Xv+V6F4Is1 iWDaQXraY8BxwFJlpL7AOPgcOm3qQmzqehE1lxKMNPBdk+LsJRzt6OcEJDRiS83CLwm/ XVX03RTmPOE2+iwcZKavDV1FA0FAMznXqyUgo429puo2nHi1B3+7lGTkHg8/l36wjqVN hA62gtDXzfzmLPbKADUTqoFAzqAU6a0B44x9uNphkhdrNf/vGOZ+jWCE6BsxCSuZtDF5 Pdi8dz8jwxSa/IU86l4rwGPZqDHkQYRyJRiKkTAPe+KGR4YkrrlfAaG1SxW5XPPa215j sNPw== X-Gm-Message-State: AOAM530fh1qqbOfghqUyzh9lhQK1bKJ/Per41/ujGpWmBZCIh0ZP2yEt vsH835DsrI80EraI2bw9npyn20eduAL72KKhfk2wA4ARp99+I9Lg+EhGSO0JTPPU6TXWPvXHrnh 1mXemVSrtjPxhyB/+Er5RCM9Yw35ffhKc4Gy/cb1QYhM1ZTg9lotLtY9BoXMaSucp X-Received: by 2002:a5d:618f:: with SMTP id j15mr3609400wru.273.1621508965741; Thu, 20 May 2021 04:09:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwF78sliMDmoM7ECbddjDeFmNWk084x1Wis7UM7Ge+KC0HrAOaH0g2rhGB7Pc0mdz7II5eGLw== X-Received: by 2002:a5d:618f:: with SMTP id j15mr3609358wru.273.1621508965371; Thu, 20 May 2021 04:09:25 -0700 (PDT) Received: from x1w.redhat.com (31.red-83-51-215.dynamicip.rima-tde.net. [83.51.215.31]) by smtp.gmail.com with ESMTPSA id m7sm2773621wrv.35.2021.05.20.04.09.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 May 2021 04:09:25 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [RFC PATCH 01/12] exec/memory_ldst: Use correct type sizes Date: Thu, 20 May 2021 13:09:08 +0200 Message-Id: <20210520110919.2483190-2-philmd@redhat.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20210520110919.2483190-1-philmd@redhat.com> References: <20210520110919.2483190-1-philmd@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=philmd@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=170.10.133.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.39, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , "Michael S. Tsirkin" , Richard Henderson , Peter Xu , Bibo Mao , Stefan Hajnoczi , Paolo Bonzini , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Use uint8_t for (unsigned) byte, and uint16_t for (unsigned) 16-bit word. Signed-off-by: Philippe Mathieu-Daudé --- include/exec/memory_ldst.h.inc | 16 ++++++++-------- memory_ldst.c.inc | 20 ++++++++++---------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/include/exec/memory_ldst.h.inc b/include/exec/memory_ldst.h.inc index 46e6c220d35..7c3a641f7ed 100644 --- a/include/exec/memory_ldst.h.inc +++ b/include/exec/memory_ldst.h.inc @@ -20,7 +20,7 @@ */ #ifdef TARGET_ENDIANNESS -extern uint32_t glue(address_space_lduw, SUFFIX)(ARG1_DECL, +extern uint16_t glue(address_space_lduw, SUFFIX)(ARG1_DECL, hwaddr addr, MemTxAttrs attrs, MemTxResult *result); extern uint32_t glue(address_space_ldl, SUFFIX)(ARG1_DECL, hwaddr addr, MemTxAttrs attrs, MemTxResult *result); @@ -29,17 +29,17 @@ extern uint64_t glue(address_space_ldq, SUFFIX)(ARG1_DECL, extern void glue(address_space_stl_notdirty, SUFFIX)(ARG1_DECL, hwaddr addr, uint32_t val, MemTxAttrs attrs, MemTxResult *result); extern void glue(address_space_stw, SUFFIX)(ARG1_DECL, - hwaddr addr, uint32_t val, MemTxAttrs attrs, MemTxResult *result); + hwaddr addr, uint16_t val, MemTxAttrs attrs, MemTxResult *result); extern void glue(address_space_stl, SUFFIX)(ARG1_DECL, hwaddr addr, uint32_t val, MemTxAttrs attrs, MemTxResult *result); extern void glue(address_space_stq, SUFFIX)(ARG1_DECL, hwaddr addr, uint64_t val, MemTxAttrs attrs, MemTxResult *result); #else -extern uint32_t glue(address_space_ldub, SUFFIX)(ARG1_DECL, +extern uint8_t glue(address_space_ldub, SUFFIX)(ARG1_DECL, hwaddr addr, MemTxAttrs attrs, MemTxResult *result); -extern uint32_t glue(address_space_lduw_le, SUFFIX)(ARG1_DECL, +extern uint16_t glue(address_space_lduw_le, SUFFIX)(ARG1_DECL, hwaddr addr, MemTxAttrs attrs, MemTxResult *result); -extern uint32_t glue(address_space_lduw_be, SUFFIX)(ARG1_DECL, +extern uint16_t glue(address_space_lduw_be, SUFFIX)(ARG1_DECL, hwaddr addr, MemTxAttrs attrs, MemTxResult *result); extern uint32_t glue(address_space_ldl_le, SUFFIX)(ARG1_DECL, hwaddr addr, MemTxAttrs attrs, MemTxResult *result); @@ -50,11 +50,11 @@ extern uint64_t glue(address_space_ldq_le, SUFFIX)(ARG1_DECL, extern uint64_t glue(address_space_ldq_be, SUFFIX)(ARG1_DECL, hwaddr addr, MemTxAttrs attrs, MemTxResult *result); extern void glue(address_space_stb, SUFFIX)(ARG1_DECL, - hwaddr addr, uint32_t val, MemTxAttrs attrs, MemTxResult *result); + hwaddr addr, uint8_t val, MemTxAttrs attrs, MemTxResult *result); extern void glue(address_space_stw_le, SUFFIX)(ARG1_DECL, - hwaddr addr, uint32_t val, MemTxAttrs attrs, MemTxResult *result); + hwaddr addr, uint16_t val, MemTxAttrs attrs, MemTxResult *result); extern void glue(address_space_stw_be, SUFFIX)(ARG1_DECL, - hwaddr addr, uint32_t val, MemTxAttrs attrs, MemTxResult *result); + hwaddr addr, uint16_t val, MemTxAttrs attrs, MemTxResult *result); extern void glue(address_space_stl_le, SUFFIX)(ARG1_DECL, hwaddr addr, uint32_t val, MemTxAttrs attrs, MemTxResult *result); extern void glue(address_space_stl_be, SUFFIX)(ARG1_DECL, diff --git a/memory_ldst.c.inc b/memory_ldst.c.inc index b56e9619674..84b868f2946 100644 --- a/memory_ldst.c.inc +++ b/memory_ldst.c.inc @@ -157,7 +157,7 @@ uint64_t glue(address_space_ldq_be, SUFFIX)(ARG1_DECL, DEVICE_BIG_ENDIAN); } -uint32_t glue(address_space_ldub, SUFFIX)(ARG1_DECL, +uint8_t glue(address_space_ldub, SUFFIX)(ARG1_DECL, hwaddr addr, MemTxAttrs attrs, MemTxResult *result) { uint8_t *ptr; @@ -193,7 +193,7 @@ uint32_t glue(address_space_ldub, SUFFIX)(ARG1_DECL, } /* warning: addr must be aligned */ -static inline uint32_t glue(address_space_lduw_internal, SUFFIX)(ARG1_DECL, +static inline uint16_t glue(address_space_lduw_internal, SUFFIX)(ARG1_DECL, hwaddr addr, MemTxAttrs attrs, MemTxResult *result, enum device_endian endian) { @@ -240,21 +240,21 @@ static inline uint32_t glue(address_space_lduw_internal, SUFFIX)(ARG1_DECL, return val; } -uint32_t glue(address_space_lduw, SUFFIX)(ARG1_DECL, +uint16_t glue(address_space_lduw, SUFFIX)(ARG1_DECL, hwaddr addr, MemTxAttrs attrs, MemTxResult *result) { return glue(address_space_lduw_internal, SUFFIX)(ARG1, addr, attrs, result, DEVICE_NATIVE_ENDIAN); } -uint32_t glue(address_space_lduw_le, SUFFIX)(ARG1_DECL, +uint16_t glue(address_space_lduw_le, SUFFIX)(ARG1_DECL, hwaddr addr, MemTxAttrs attrs, MemTxResult *result) { return glue(address_space_lduw_internal, SUFFIX)(ARG1, addr, attrs, result, DEVICE_LITTLE_ENDIAN); } -uint32_t glue(address_space_lduw_be, SUFFIX)(ARG1_DECL, +uint16_t glue(address_space_lduw_be, SUFFIX)(ARG1_DECL, hwaddr addr, MemTxAttrs attrs, MemTxResult *result) { return glue(address_space_lduw_internal, SUFFIX)(ARG1, addr, attrs, result, @@ -366,7 +366,7 @@ void glue(address_space_stl_be, SUFFIX)(ARG1_DECL, } void glue(address_space_stb, SUFFIX)(ARG1_DECL, - hwaddr addr, uint32_t val, MemTxAttrs attrs, MemTxResult *result) + hwaddr addr, uint8_t val, MemTxAttrs attrs, MemTxResult *result) { uint8_t *ptr; MemoryRegion *mr; @@ -398,7 +398,7 @@ void glue(address_space_stb, SUFFIX)(ARG1_DECL, /* warning: addr must be aligned */ static inline void glue(address_space_stw_internal, SUFFIX)(ARG1_DECL, - hwaddr addr, uint32_t val, MemTxAttrs attrs, + hwaddr addr, uint16_t val, MemTxAttrs attrs, MemTxResult *result, enum device_endian endian) { uint8_t *ptr; @@ -441,21 +441,21 @@ static inline void glue(address_space_stw_internal, SUFFIX)(ARG1_DECL, } void glue(address_space_stw, SUFFIX)(ARG1_DECL, - hwaddr addr, uint32_t val, MemTxAttrs attrs, MemTxResult *result) + hwaddr addr, uint16_t val, MemTxAttrs attrs, MemTxResult *result) { glue(address_space_stw_internal, SUFFIX)(ARG1, addr, val, attrs, result, DEVICE_NATIVE_ENDIAN); } void glue(address_space_stw_le, SUFFIX)(ARG1_DECL, - hwaddr addr, uint32_t val, MemTxAttrs attrs, MemTxResult *result) + hwaddr addr, uint16_t val, MemTxAttrs attrs, MemTxResult *result) { glue(address_space_stw_internal, SUFFIX)(ARG1, addr, val, attrs, result, DEVICE_LITTLE_ENDIAN); } void glue(address_space_stw_be, SUFFIX)(ARG1_DECL, - hwaddr addr, uint32_t val, MemTxAttrs attrs, MemTxResult *result) + hwaddr addr, uint16_t val, MemTxAttrs attrs, MemTxResult *result) { glue(address_space_stw_internal, SUFFIX)(ARG1, addr, val, attrs, result, DEVICE_BIG_ENDIAN); From patchwork Thu May 20 11:09:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 12269667 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=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham 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 B7B26C433ED for ; Thu, 20 May 2021 11:11:44 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 6C88360FDB for ; Thu, 20 May 2021 11:11:44 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6C88360FDB Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:37914 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ljgad-0001vV-Fo for qemu-devel@archiver.kernel.org; Thu, 20 May 2021 07:11:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44502) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ljgYZ-0007ne-0q for qemu-devel@nongnu.org; Thu, 20 May 2021 07:09:35 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:39868) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ljgYX-0004Po-Er for qemu-devel@nongnu.org; Thu, 20 May 2021 07:09:34 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1621508972; 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=z3/KZxEceqNBHXRRxZ4yuG2qkGWWINMUXp6C+3kJ9h4=; b=RpjFhsB/+8s2XK64X1eDqQPj4nT9HPRAp/2hu/CTg4Pnh/Vgn4PajRkrWMOfmgZ2lxH6ip swERpbVcxGDuAmsWn1bMuvxQSK3qQoW2LFn3CPxn0RAEvXF7FcUuDw0SubjWcxj0t2kBj6 qcCzIyxWtnzc5bLIgt4W06G/2S4hwW8= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-191-brOYqp0AObSVHJOJK4W74Q-1; Thu, 20 May 2021 07:09:31 -0400 X-MC-Unique: brOYqp0AObSVHJOJK4W74Q-1 Received: by mail-wm1-f69.google.com with SMTP id v2-20020a7bcb420000b0290146b609814dso1317005wmj.0 for ; Thu, 20 May 2021 04:09:31 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=z3/KZxEceqNBHXRRxZ4yuG2qkGWWINMUXp6C+3kJ9h4=; b=kvLXa+CUQCTQ6en/7sJaCdVELZcv6dQE3yRCLflMxpP97znCYIGOLtPFtbsLLqDt7A ZolkUhDUQd/CtZsiqzJFzTZmwprxw2vUqZxGqn8tk5XUU3sZ3tTrFsJLFLDnp9LLRD8m tcUB6HNVnaqnMilePXpLDvaexs6oOxCB+SfyYxmwtROCB0R7aq5DsCOYSrS6QvsR6ajh Ag/7rL6Dg6kSAyY00WgoSL6gWshfErZS5I2oBXN6NHUFY7oJrPqSiHTvYTE/aKHflI7Y /D4ulM6d7kuMdIYYVwaYAYeftnWeiCashoBGmLqFYlxAuooOKSYqhxNJOO2ibp1kURGH tfug== X-Gm-Message-State: AOAM530WdZJ5Tp+2LHE8JlKgltsr5BeEtO7TUb42NPoGRW8EFAprEDSt uBaOXLTfqgiA/zzUWdXuvGkCv1qnjLUWzqArkHVOyndYDuyfBPgh8twUEXv4IuB2RU68Ow9bu90 8LrmzDcJPiL/40DJ/UJvZHKky0EeGxTTsFdKoe1ug1UgsgBgzCcLiAimMhxVRBg6E X-Received: by 2002:a5d:5008:: with SMTP id e8mr3641406wrt.386.1621508970233; Thu, 20 May 2021 04:09:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzOqk6hVjufnuap/b7mFO0PpMjE1Kc0WB3eAcoLpFr39pSsAkfOvHC1dpN9xEobxcRXxiycOg== X-Received: by 2002:a5d:5008:: with SMTP id e8mr3641385wrt.386.1621508970060; Thu, 20 May 2021 04:09:30 -0700 (PDT) Received: from x1w.redhat.com (31.red-83-51-215.dynamicip.rima-tde.net. [83.51.215.31]) by smtp.gmail.com with ESMTPSA id y137sm3081451wmc.11.2021.05.20.04.09.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 May 2021 04:09:29 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [RFC PATCH 02/12] exec/memattrs: Add attribute/error for address alignment Date: Thu, 20 May 2021 13:09:09 +0200 Message-Id: <20210520110919.2483190-3-philmd@redhat.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20210520110919.2483190-1-philmd@redhat.com> References: <20210520110919.2483190-1-philmd@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=philmd@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=216.205.24.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.39, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , "Michael S. Tsirkin" , Richard Henderson , Peter Xu , Bibo Mao , Stefan Hajnoczi , Paolo Bonzini , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" A bus master might specify the 'aligned' attribute to enforce a transaction using aligned address. If the address is not aligned, the accessor will return MEMTX_UNALIGNED_ERROR. Signed-off-by: Philippe Mathieu-Daudé --- include/exec/memattrs.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/include/exec/memattrs.h b/include/exec/memattrs.h index 95f2d20d55b..6fe59194e35 100644 --- a/include/exec/memattrs.h +++ b/include/exec/memattrs.h @@ -39,6 +39,8 @@ typedef struct MemTxAttrs { unsigned int requester_id:16; /* Invert endianness for this page */ unsigned int byte_swap:1; + /* Memory access must be aligned */ + unsigned int aligned:1; /* * The following are target-specific page-table bits. These are not * related to actual memory transactions at all. However, this structure @@ -66,6 +68,7 @@ typedef struct MemTxAttrs { #define MEMTX_OK 0 #define MEMTX_ERROR (1U << 0) /* device returned an error */ #define MEMTX_DECODE_ERROR (1U << 1) /* nothing at that address */ +#define MEMTX_UNALIGNED_ERROR (1U << 2) /* address is not aligned */ typedef uint32_t MemTxResult; #endif From patchwork Thu May 20 11:09:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 12269669 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=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham 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 B8EEAC43470 for ; Thu, 20 May 2021 11:11:49 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 2D0846100A for ; Thu, 20 May 2021 11:11:49 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2D0846100A Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:38444 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ljgai-0002IB-AG for qemu-devel@archiver.kernel.org; Thu, 20 May 2021 07:11:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44516) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ljgYd-0007xx-MT for qemu-devel@nongnu.org; Thu, 20 May 2021 07:09:39 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:35781) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ljgYb-0004T8-Uz for qemu-devel@nongnu.org; Thu, 20 May 2021 07:09:39 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1621508977; 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=BIUKBelUrGAg7JFPfqNH9aSjg1FuXfUME+/SSVTybmA=; b=Ads1KW9jf9UgrIJmirUn3zN7HPJfZ5ueJX7QxY6xv6GAxf4+6ZUCM+On44IQMEJsteOeco TplGyI/JF8kn8EFRxlGQfSnAIowyYSHsrfLSV+7ZDUYaPGF7WgZfx9dV7bZ9VgkcxWwwr1 HVhd1CP/v6Lt/kXk2rQH7c5q1SwAlUE= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-60-g_FFBUT2Pa-3SQk7IAGPzg-1; Thu, 20 May 2021 07:09:36 -0400 X-MC-Unique: g_FFBUT2Pa-3SQk7IAGPzg-1 Received: by mail-wr1-f71.google.com with SMTP id q15-20020adfc50f0000b0290111f48b865cso5029323wrf.4 for ; Thu, 20 May 2021 04:09:36 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=BIUKBelUrGAg7JFPfqNH9aSjg1FuXfUME+/SSVTybmA=; b=AmxfUdEDpbguboRsqF+jDJMavSSNJRCp2AGTmoch+UPq9h0C/zM4WYxzTQ0vrbkhOi wsW3VxV/jHAB0zQsYJ6H+ff8trA8/WyZv1hXSD8APXcWW2DOrTa9NzOrSXtiaUY2ycph /Q0GFaOmw2pqqim/hu/oDW/uICEK3RgqdBuQHDAI/MuRuhNh+KIxMl6tF4zlW0GaNEgy ML1ZzdEiyRmfv/sOgy2bU3vYNFde1UQW0c45OycSdvaUIq1DKbAZrL+NSJlXl9D0VmNw dKvBJwEOz5GKXo+cBDsjVOBuk/dOeE94tqSag87IYQt1SoZGWoKXU1JKUK23df5kX2Wc o4Ig== X-Gm-Message-State: AOAM532HUL7y6pfX5NgVQeNBHwGMi0Fun04/Zzbvh3h08o4dkesss4gB CJfyhnoDpmdlGqYUl1Y9YBwSINtqfCXpCJmPOE+MEQIlgkj3qmCvHgb4BpjIMEaY2eqsx2y0+78 pk0GM/Tn2iP1u9SjFPdQ6JiXXTBuQ0V9N6l5l2ZJqY+HJYwYsqp5ZFuMh4+aRFKHq X-Received: by 2002:a5d:62c7:: with SMTP id o7mr3673020wrv.372.1621508974757; Thu, 20 May 2021 04:09:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwEUAwnlIZe3JtCq7uoFHBWXQoJs3UxNmzzOa9mrg8Z+HtdwTbQUbXUK7S5h4KZbQr5i0Yq5A== X-Received: by 2002:a5d:62c7:: with SMTP id o7mr3672987wrv.372.1621508974526; Thu, 20 May 2021 04:09:34 -0700 (PDT) Received: from x1w.redhat.com (31.red-83-51-215.dynamicip.rima-tde.net. [83.51.215.31]) by smtp.gmail.com with ESMTPSA id c6sm2750046wru.50.2021.05.20.04.09.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 May 2021 04:09:34 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [RFC PATCH 03/12] exec/memory_ldst: Return MEMTX_UNALIGNED_ERROR for unaligned addresses Date: Thu, 20 May 2021 13:09:10 +0200 Message-Id: <20210520110919.2483190-4-philmd@redhat.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20210520110919.2483190-1-philmd@redhat.com> References: <20210520110919.2483190-1-philmd@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=philmd@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=170.10.133.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.39, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , "Michael S. Tsirkin" , Richard Henderson , Peter Xu , Bibo Mao , Stefan Hajnoczi , Paolo Bonzini , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" All address_space internal handlers have the /* warning: addr must be aligned */ comment, so we don't expect any caller to pass unaligned addresses. Now than we added the MemTxAttrs.aligned attribute, callers might want to pass unaligned addresses. In case they do, be ready and return MEMTX_UNALIGNED_ERROR. Signed-off-by: Philippe Mathieu-Daudé --- memory_ldst.c.inc | 49 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/memory_ldst.c.inc b/memory_ldst.c.inc index 84b868f2946..efeb545479e 100644 --- a/memory_ldst.c.inc +++ b/memory_ldst.c.inc @@ -32,6 +32,13 @@ static inline uint32_t glue(address_space_ldl_internal, SUFFIX)(ARG1_DECL, MemTxResult r; bool release_lock = false; + if (unlikely(!QEMU_IS_ALIGNED(addr, sizeof(uint32_t)))) { + if (result) { + *result = MEMTX_UNALIGNED_ERROR; + } + return (uint32_t)-1; /* XXX */ + } + RCU_READ_LOCK(); mr = TRANSLATE(addr, &addr1, &l, false, attrs); if (l < 4 || !memory_access_is_direct(mr, false)) { @@ -101,6 +108,13 @@ static inline uint64_t glue(address_space_ldq_internal, SUFFIX)(ARG1_DECL, MemTxResult r; bool release_lock = false; + if (unlikely(!QEMU_IS_ALIGNED(addr, sizeof(uint64_t)))) { + if (result) { + *result = MEMTX_UNALIGNED_ERROR; + } + return (uint64_t)-1; /* XXX */ + } + RCU_READ_LOCK(); mr = TRANSLATE(addr, &addr1, &l, false, attrs); if (l < 8 || !memory_access_is_direct(mr, false)) { @@ -205,6 +219,13 @@ static inline uint16_t glue(address_space_lduw_internal, SUFFIX)(ARG1_DECL, MemTxResult r; bool release_lock = false; + if (unlikely(!QEMU_IS_ALIGNED(addr, sizeof(uint16_t)))) { + if (result) { + *result = MEMTX_UNALIGNED_ERROR; + } + return (uint16_t)-1; /* XXX */ + } + RCU_READ_LOCK(); mr = TRANSLATE(addr, &addr1, &l, false, attrs); if (l < 2 || !memory_access_is_direct(mr, false)) { @@ -275,6 +296,13 @@ void glue(address_space_stl_notdirty, SUFFIX)(ARG1_DECL, uint8_t dirty_log_mask; bool release_lock = false; + if (unlikely(!QEMU_IS_ALIGNED(addr, sizeof(uint32_t)))) { + if (result) { + *result = MEMTX_UNALIGNED_ERROR; + } + return; + } + RCU_READ_LOCK(); mr = TRANSLATE(addr, &addr1, &l, true, attrs); if (l < 4 || !memory_access_is_direct(mr, true)) { @@ -312,6 +340,13 @@ static inline void glue(address_space_stl_internal, SUFFIX)(ARG1_DECL, MemTxResult r; bool release_lock = false; + if (unlikely(!QEMU_IS_ALIGNED(addr, sizeof(uint32_t)))) { + if (result) { + *result = MEMTX_UNALIGNED_ERROR; + } + return; + } + RCU_READ_LOCK(); mr = TRANSLATE(addr, &addr1, &l, true, attrs); if (l < 4 || !memory_access_is_direct(mr, true)) { @@ -408,6 +443,13 @@ static inline void glue(address_space_stw_internal, SUFFIX)(ARG1_DECL, MemTxResult r; bool release_lock = false; + if (unlikely(!QEMU_IS_ALIGNED(addr, sizeof(uint16_t)))) { + if (result) { + *result = MEMTX_UNALIGNED_ERROR; + } + return; + } + RCU_READ_LOCK(); mr = TRANSLATE(addr, &addr1, &l, true, attrs); if (l < 2 || !memory_access_is_direct(mr, true)) { @@ -472,6 +514,13 @@ static void glue(address_space_stq_internal, SUFFIX)(ARG1_DECL, MemTxResult r; bool release_lock = false; + if (unlikely(!QEMU_IS_ALIGNED(addr, sizeof(uint64_t)))) { + if (result) { + *result = MEMTX_UNALIGNED_ERROR; + } + return; + } + RCU_READ_LOCK(); mr = TRANSLATE(addr, &addr1, &l, true, attrs); if (l < 8 || !memory_access_is_direct(mr, true)) { From patchwork Thu May 20 11:09:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 12269699 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=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham 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 7296DC433ED for ; Thu, 20 May 2021 11:17:21 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id E02D460FEE for ; Thu, 20 May 2021 11:17:20 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E02D460FEE Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:53246 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ljgg3-0003yG-Uy for qemu-devel@archiver.kernel.org; Thu, 20 May 2021 07:17:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44560) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ljgYl-0008GD-RA for qemu-devel@nongnu.org; Thu, 20 May 2021 07:09:47 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:58647) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ljgYi-0004Ww-6r for qemu-devel@nongnu.org; Thu, 20 May 2021 07:09:47 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1621508983; 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=2KSH1YwMn8zpDyDH9Uq0LVnJ/rgrT/JgFf8hkb+U/HU=; b=OV0nHobY3dvLLfiopvZSXcoTv1UjiNcdnLbdNWCjm4Eht7yL6sTM2me6EE2YSS2SPBrjuF mZUALYfdK7dbtfr1WLmkvkcDwkO0++Zm2LjggKx2QY3P4J1sQEoGyvIdWGsgCu2eh2U5m/ MUKZEGbsiAv/9J77EijjldqgI0YQWsQ= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-27-B2yJIMNrM6m4_NNJ8VYKvw-1; Thu, 20 May 2021 07:09:40 -0400 X-MC-Unique: B2yJIMNrM6m4_NNJ8VYKvw-1 Received: by mail-wr1-f70.google.com with SMTP id c13-20020a5d6ccd0000b029010ec741b84bso8490480wrc.23 for ; Thu, 20 May 2021 04:09:40 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=2KSH1YwMn8zpDyDH9Uq0LVnJ/rgrT/JgFf8hkb+U/HU=; b=Kdl4GodgcA7nUOB4tnBN9QyIfg3SUEgQkfTL0JdeVl282cbliYKsHM5ux4OiwILnHU SGHwsab9QnUX6GZJEIYjAJSyHeqJKOz/w/VLExBrznLFXFMmRw8QnCi5ilMm+h2DMtqr JdRy7ahgA/ZzWmSk8J5OYJfTuOsBRpItPnzGvkIPBx6v53IGc/SS/adI14zYhhlDZgyg +bDSdI9V2x3TdasIlV06sJCVG6kjNSHTrQ2xzVMWiybzlEjCQdCEYfLEY+TAXHYj9OFZ CbjYRWBaSG4f4RXgHLbElw6RCOq0/GtffkzJaXtgPFthJ9IwsE25rnzjXYEBKCT5pXvj sDaw== X-Gm-Message-State: AOAM5302salVs6+nRJLD0F+WZKqVD76GyHEv6JaWfQ/wPm6iPRBreVtL NCyfhAaaprrWZoJw17KLOBBKYU/J6Sh04E1ZTqI5PRZn1gPKHsLcYkIXQBvGWkxkhHRE+tEQut1 x/8dj5krVGzejEnZAViPBm+i+g9LCj9iY6M0Ej80e0H5AW+T7AtSRugCq6QdAEq0Z X-Received: by 2002:a7b:c14f:: with SMTP id z15mr3523690wmi.149.1621508979357; Thu, 20 May 2021 04:09:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJypV8QrtTFYcqAaQN2mqsbrJHwtiEW9wPUgdsnxyNxoDiibzKWPs82c8gxFMqHEngLwVBDtKA== X-Received: by 2002:a7b:c14f:: with SMTP id z15mr3523669wmi.149.1621508979128; Thu, 20 May 2021 04:09:39 -0700 (PDT) Received: from x1w.redhat.com (31.red-83-51-215.dynamicip.rima-tde.net. [83.51.215.31]) by smtp.gmail.com with ESMTPSA id m7sm2774233wrv.35.2021.05.20.04.09.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 May 2021 04:09:38 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [RFC PATCH 04/12] exec/memory_ldst_cached: Sort declarations Date: Thu, 20 May 2021 13:09:11 +0200 Message-Id: <20210520110919.2483190-5-philmd@redhat.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20210520110919.2483190-1-philmd@redhat.com> References: <20210520110919.2483190-1-philmd@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=philmd@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=216.205.24.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.39, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , "Michael S. Tsirkin" , Richard Henderson , Peter Xu , Bibo Mao , Stefan Hajnoczi , Paolo Bonzini , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" To ease the file review, sort the declarations by the size of the access (8, 16, 32). Simple code movement, no logical change. Signed-off-by: Philippe Mathieu-Daudé --- include/exec/memory_ldst_cached.h.inc | 46 +++++++++++++-------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/include/exec/memory_ldst_cached.h.inc b/include/exec/memory_ldst_cached.h.inc index 7bc8790d346..c33449d0cd5 100644 --- a/include/exec/memory_ldst_cached.h.inc +++ b/include/exec/memory_ldst_cached.h.inc @@ -24,6 +24,18 @@ #define LD_P(size) \ glue(glue(ld, size), glue(ENDIANNESS, _p)) +static inline uint32_t ADDRESS_SPACE_LD_CACHED(uw)(MemoryRegionCache *cache, + hwaddr addr, MemTxAttrs attrs, MemTxResult *result) +{ + assert(addr < cache->len && 2 <= cache->len - addr); + fuzz_dma_read_cb(cache->xlat + addr, 2, cache->mrs.mr); + if (likely(cache->ptr)) { + return LD_P(uw)(cache->ptr + addr); + } else { + return ADDRESS_SPACE_LD_CACHED_SLOW(uw)(cache, addr, attrs, result); + } +} + static inline uint32_t ADDRESS_SPACE_LD_CACHED(l)(MemoryRegionCache *cache, hwaddr addr, MemTxAttrs attrs, MemTxResult *result) { @@ -48,18 +60,6 @@ static inline uint64_t ADDRESS_SPACE_LD_CACHED(q)(MemoryRegionCache *cache, } } -static inline uint32_t ADDRESS_SPACE_LD_CACHED(uw)(MemoryRegionCache *cache, - hwaddr addr, MemTxAttrs attrs, MemTxResult *result) -{ - assert(addr < cache->len && 2 <= cache->len - addr); - fuzz_dma_read_cb(cache->xlat + addr, 2, cache->mrs.mr); - if (likely(cache->ptr)) { - return LD_P(uw)(cache->ptr + addr); - } else { - return ADDRESS_SPACE_LD_CACHED_SLOW(uw)(cache, addr, attrs, result); - } -} - #undef ADDRESS_SPACE_LD_CACHED #undef ADDRESS_SPACE_LD_CACHED_SLOW #undef LD_P @@ -71,17 +71,6 @@ static inline uint32_t ADDRESS_SPACE_LD_CACHED(uw)(MemoryRegionCache *cache, #define ST_P(size) \ glue(glue(st, size), glue(ENDIANNESS, _p)) -static inline void ADDRESS_SPACE_ST_CACHED(l)(MemoryRegionCache *cache, - hwaddr addr, uint32_t val, MemTxAttrs attrs, MemTxResult *result) -{ - assert(addr < cache->len && 4 <= cache->len - addr); - if (likely(cache->ptr)) { - ST_P(l)(cache->ptr + addr, val); - } else { - ADDRESS_SPACE_ST_CACHED_SLOW(l)(cache, addr, val, attrs, result); - } -} - static inline void ADDRESS_SPACE_ST_CACHED(w)(MemoryRegionCache *cache, hwaddr addr, uint32_t val, MemTxAttrs attrs, MemTxResult *result) { @@ -93,6 +82,17 @@ static inline void ADDRESS_SPACE_ST_CACHED(w)(MemoryRegionCache *cache, } } +static inline void ADDRESS_SPACE_ST_CACHED(l)(MemoryRegionCache *cache, + hwaddr addr, uint32_t val, MemTxAttrs attrs, MemTxResult *result) +{ + assert(addr < cache->len && 4 <= cache->len - addr); + if (likely(cache->ptr)) { + ST_P(l)(cache->ptr + addr, val); + } else { + ADDRESS_SPACE_ST_CACHED_SLOW(l)(cache, addr, val, attrs, result); + } +} + static inline void ADDRESS_SPACE_ST_CACHED(q)(MemoryRegionCache *cache, hwaddr addr, uint64_t val, MemTxAttrs attrs, MemTxResult *result) { From patchwork Thu May 20 11:09:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 12269687 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=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham 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 77968C43461 for ; Thu, 20 May 2021 11:12:12 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 22811611AB for ; Thu, 20 May 2021 11:12:12 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 22811611AB Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:39132 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ljgb5-0002pf-5F for qemu-devel@archiver.kernel.org; Thu, 20 May 2021 07:12:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44590) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ljgYp-0008LI-QN for qemu-devel@nongnu.org; Thu, 20 May 2021 07:09:53 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:28413) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ljgYl-0004Yw-HO for qemu-devel@nongnu.org; Thu, 20 May 2021 07:09:51 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1621508986; 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=Z2KMRus6wjZmSwZp3NDF0wx5q7DfpOUE+gwTHQ1DOIM=; b=OvIwjHtx16e8o68pBJiP26jflzS1gTmo9sXfwL2lBisbG0aEBIney1fmpC2fBBILBrJH+j yiQIEaOFJO5Mns+it5UNRPUSjR67BRvUUkq+0D6O3UOutxVFZAUjkg0E81gjTpYsKEapVb IWBDNjjMnthhQ2vCs9/fxuZt0qYQyZg= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-351-0iqnPVf-OxGDd7W_SzKpBA-1; Thu, 20 May 2021 07:09:45 -0400 X-MC-Unique: 0iqnPVf-OxGDd7W_SzKpBA-1 Received: by mail-wr1-f70.google.com with SMTP id u20-20020a0560001614b02901115c8f2d89so8415973wrb.3 for ; Thu, 20 May 2021 04:09:44 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Z2KMRus6wjZmSwZp3NDF0wx5q7DfpOUE+gwTHQ1DOIM=; b=dqjbyIzo+tG0pcS3mEbZD2AmcgixEw39dE6/8BN/Y4jQ2Tpl1P+OUN3YpK9dJ2xy8X jKO7CYMX9YVPdyXFw40A9gdMYZT4t3I3KAAX/HHYQ2w5J+C6WhiTcqRaEsTHmW2ZGn8/ KSnAXL/Eg9DpqrAL7aGYORVuhz5REbMP1kAuH5S0R6D98nehyhsdl3qJkLslAjoHlCLc 08qsam7i7pQXQtuwnU0SEgbRnnKMzyLRRLDnMNGJ7+iavkVeAewYeHWrjmeC6gFs7HLt 9NS1wFqXQlRhoCayVp44P+nVTTRExZcKz31yfNQGXFYNKzMs2AHoRo430KSqiHx13AFN mDtg== X-Gm-Message-State: AOAM53056JPSnp2K3SwspygeDQs1Zplq0Fpe/jROYEee1IMmx114mZNs J+8aqjRb9o6Yb3qCx65xwhqbqfn1g10edOvj6Uvc6YpQqTOFVj8Q5ztJmB8KiLLJSXyXRL7YSXV p2VO5ns6cy4DrHoDSd17HI74FpNtq2TJTrI660g/zzCj3/nX7BCpCg1mReE6HLzzP X-Received: by 2002:a1c:e912:: with SMTP id q18mr3537325wmc.59.1621508983718; Thu, 20 May 2021 04:09:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxLhOJKw0e+IS+8hJ9Mbrivf9UaERQte7v+dmAjQJHYAmlB2Ck2m5Gb2a36fs4CI+wOqsTQwA== X-Received: by 2002:a1c:e912:: with SMTP id q18mr3537300wmc.59.1621508983572; Thu, 20 May 2021 04:09:43 -0700 (PDT) Received: from x1w.redhat.com (31.red-83-51-215.dynamicip.rima-tde.net. [83.51.215.31]) by smtp.gmail.com with ESMTPSA id f202sm1290316wmf.14.2021.05.20.04.09.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 May 2021 04:09:43 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [RFC PATCH 05/12] exec/memory_ldst_cached: Use correct type size Date: Thu, 20 May 2021 13:09:12 +0200 Message-Id: <20210520110919.2483190-6-philmd@redhat.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20210520110919.2483190-1-philmd@redhat.com> References: <20210520110919.2483190-1-philmd@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=philmd@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=216.205.24.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.39, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , "Michael S. Tsirkin" , Richard Henderson , Peter Xu , Bibo Mao , Stefan Hajnoczi , Paolo Bonzini , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Use uint16_t for (unsigned) 16-bit word. Signed-off-by: Philippe Mathieu-Daudé --- include/exec/memory_ldst_cached.h.inc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/exec/memory_ldst_cached.h.inc b/include/exec/memory_ldst_cached.h.inc index c33449d0cd5..d7834f852c4 100644 --- a/include/exec/memory_ldst_cached.h.inc +++ b/include/exec/memory_ldst_cached.h.inc @@ -24,7 +24,7 @@ #define LD_P(size) \ glue(glue(ld, size), glue(ENDIANNESS, _p)) -static inline uint32_t ADDRESS_SPACE_LD_CACHED(uw)(MemoryRegionCache *cache, +static inline uint16_t ADDRESS_SPACE_LD_CACHED(uw)(MemoryRegionCache *cache, hwaddr addr, MemTxAttrs attrs, MemTxResult *result) { assert(addr < cache->len && 2 <= cache->len - addr); @@ -72,7 +72,7 @@ static inline uint64_t ADDRESS_SPACE_LD_CACHED(q)(MemoryRegionCache *cache, glue(glue(st, size), glue(ENDIANNESS, _p)) static inline void ADDRESS_SPACE_ST_CACHED(w)(MemoryRegionCache *cache, - hwaddr addr, uint32_t val, MemTxAttrs attrs, MemTxResult *result) + hwaddr addr, uint16_t val, MemTxAttrs attrs, MemTxResult *result) { assert(addr < cache->len && 2 <= cache->len - addr); if (likely(cache->ptr)) { From patchwork Thu May 20 11:09:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 12269695 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=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham 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 C08CAC43461 for ; Thu, 20 May 2021 11:14:39 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 5C70960240 for ; Thu, 20 May 2021 11:14:39 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5C70960240 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:47610 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ljgdS-0008Vm-DZ for qemu-devel@archiver.kernel.org; Thu, 20 May 2021 07:14:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44644) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ljgYv-00005B-Dc for qemu-devel@nongnu.org; Thu, 20 May 2021 07:09:57 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:20590) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ljgYs-0004ad-FI for qemu-devel@nongnu.org; Thu, 20 May 2021 07:09:57 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1621508993; 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=tQhRr1d+vMSeLXHOF3EqT8MC2o1YqDGEA5IrzwoyL/A=; b=BIEtd2LKtNF1xzEoqejpLq884xStnEp9GjuzIPMqfnPysivvTNJi+k37yJjg7fbvtXVp09 mTEVumSe0+64g9zDTUon8BVtJ2E2C7y6bBn0B1PtNxRQ9FmY+jMxTkX4vvoVi2IyRDJqeF 0e0ioQLJ7FpLCvODEaybO7SN8eyUp5Y= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-333-kUOxFY_HM6uVngaDyZVC_Q-1; Thu, 20 May 2021 07:09:49 -0400 X-MC-Unique: kUOxFY_HM6uVngaDyZVC_Q-1 Received: by mail-wm1-f71.google.com with SMTP id k124-20020a1ca1820000b0290175dd5429afso2190129wme.7 for ; Thu, 20 May 2021 04:09:49 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=tQhRr1d+vMSeLXHOF3EqT8MC2o1YqDGEA5IrzwoyL/A=; b=mO6ljzIO+IxO40HPk2xyc05My48q7m4BL+oGY718kpgqc+N9G8aHSAOSo/CTFLCshA xQTo4ssg2TzPjbHgy1pU9IFo13/N5bTogF7aLVAySDneVEVrz+jz7/hsSCY4YVO34Cts BbH6naa4P+qgNv7Cg5S3vjOpW1oXrKVPGGmt9biA0Ez+r3ssXkeT+6HlAB52nM0ZvRST yij/3hgKpFLzCZFnkTUTU1MZumrKCobFp9nfoqBvll+49c+EkCnfymzgQ0CcLeMgAqRG UKgXyW/9FZgN2C+csIMJzzNGLlID4dlKzJhhM7kFW+IMKyyrHrWkHz9og6rv1/DKXnrA LICQ== X-Gm-Message-State: AOAM531fCFt1VRx2CBn5NTrSQOfdbwd1e47Cflm+PXlrz+2VLeES6Asd wiDsV5McwGyUlun0TeiMq7QYmeMuuo+5Y3TnyauKIrUYzKxtUX5pZwtCtf3peQDdqIISwCfD2uJ PqxljLGiucNVJ/8A5wVLVC+pzlnCSnNEwTN4mO3YCK0jPlnsyB9yaurvmDhRn6MgC X-Received: by 2002:a5d:64eb:: with SMTP id g11mr3770271wri.260.1621508988336; Thu, 20 May 2021 04:09:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyvmtUkJ6f+dcEKHN9qasYVs6lq5BJbUSp5Zjup/3gB/YtMpl/W8Zp2YdMNfPqKFTtDG3y7Zw== X-Received: by 2002:a5d:64eb:: with SMTP id g11mr3770245wri.260.1621508988100; Thu, 20 May 2021 04:09:48 -0700 (PDT) Received: from x1w.redhat.com (31.red-83-51-215.dynamicip.rima-tde.net. [83.51.215.31]) by smtp.gmail.com with ESMTPSA id m20sm3826907wmi.5.2021.05.20.04.09.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 May 2021 04:09:47 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [RFC PATCH 06/12] exec/memory_ldst_cached: Set MemTxResult on success Date: Thu, 20 May 2021 13:09:13 +0200 Message-Id: <20210520110919.2483190-7-philmd@redhat.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20210520110919.2483190-1-philmd@redhat.com> References: <20210520110919.2483190-1-philmd@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=philmd@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=216.205.24.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.39, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , "Michael S. Tsirkin" , Richard Henderson , Peter Xu , Bibo Mao , Stefan Hajnoczi , Paolo Bonzini , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" If the caller passed a MemTxResult argument, we must fill it with the transaction result. We do it when no cache is present, complete the other case (which is always successful). Fixes: 48564041a73 ("exec: reintroduce MemoryRegion caching") Signed-off-by: Philippe Mathieu-Daudé --- include/exec/memory_ldst_cached.h.inc | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/include/exec/memory_ldst_cached.h.inc b/include/exec/memory_ldst_cached.h.inc index d7834f852c4..a8f146251d4 100644 --- a/include/exec/memory_ldst_cached.h.inc +++ b/include/exec/memory_ldst_cached.h.inc @@ -30,6 +30,9 @@ static inline uint16_t ADDRESS_SPACE_LD_CACHED(uw)(MemoryRegionCache *cache, assert(addr < cache->len && 2 <= cache->len - addr); fuzz_dma_read_cb(cache->xlat + addr, 2, cache->mrs.mr); if (likely(cache->ptr)) { + if (result) { + *result = MEMTX_OK; + } return LD_P(uw)(cache->ptr + addr); } else { return ADDRESS_SPACE_LD_CACHED_SLOW(uw)(cache, addr, attrs, result); @@ -42,6 +45,9 @@ static inline uint32_t ADDRESS_SPACE_LD_CACHED(l)(MemoryRegionCache *cache, assert(addr < cache->len && 4 <= cache->len - addr); fuzz_dma_read_cb(cache->xlat + addr, 4, cache->mrs.mr); if (likely(cache->ptr)) { + if (result) { + *result = MEMTX_OK; + } return LD_P(l)(cache->ptr + addr); } else { return ADDRESS_SPACE_LD_CACHED_SLOW(l)(cache, addr, attrs, result); @@ -54,6 +60,9 @@ static inline uint64_t ADDRESS_SPACE_LD_CACHED(q)(MemoryRegionCache *cache, assert(addr < cache->len && 8 <= cache->len - addr); fuzz_dma_read_cb(cache->xlat + addr, 8, cache->mrs.mr); if (likely(cache->ptr)) { + if (result) { + *result = MEMTX_OK; + } return LD_P(q)(cache->ptr + addr); } else { return ADDRESS_SPACE_LD_CACHED_SLOW(q)(cache, addr, attrs, result); @@ -76,6 +85,9 @@ static inline void ADDRESS_SPACE_ST_CACHED(w)(MemoryRegionCache *cache, { assert(addr < cache->len && 2 <= cache->len - addr); if (likely(cache->ptr)) { + if (result) { + *result = MEMTX_OK; + } ST_P(w)(cache->ptr + addr, val); } else { ADDRESS_SPACE_ST_CACHED_SLOW(w)(cache, addr, val, attrs, result); @@ -87,6 +99,9 @@ static inline void ADDRESS_SPACE_ST_CACHED(l)(MemoryRegionCache *cache, { assert(addr < cache->len && 4 <= cache->len - addr); if (likely(cache->ptr)) { + if (result) { + *result = MEMTX_OK; + } ST_P(l)(cache->ptr + addr, val); } else { ADDRESS_SPACE_ST_CACHED_SLOW(l)(cache, addr, val, attrs, result); @@ -98,6 +113,9 @@ static inline void ADDRESS_SPACE_ST_CACHED(q)(MemoryRegionCache *cache, { assert(addr < cache->len && 8 <= cache->len - addr); if (likely(cache->ptr)) { + if (result) { + *result = MEMTX_OK; + } ST_P(q)(cache->ptr + addr, val); } else { ADDRESS_SPACE_ST_CACHED_SLOW(q)(cache, addr, val, attrs, result); From patchwork Thu May 20 11:09:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 12269701 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=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham 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 7E3A7C433ED for ; Thu, 20 May 2021 11:17:35 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 06FC160240 for ; Thu, 20 May 2021 11:17:34 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 06FC160240 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:54016 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ljggI-0004Vu-4j for qemu-devel@archiver.kernel.org; Thu, 20 May 2021 07:17:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44648) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ljgYx-0000CK-2y for qemu-devel@nongnu.org; Thu, 20 May 2021 07:09:59 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:35110) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ljgYu-0004as-2j for qemu-devel@nongnu.org; Thu, 20 May 2021 07:09:58 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1621508995; 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=fXNvsUG+9jJQpscb+R8eaH4L2n3MJcy4IDVc87G545A=; b=ddUPxr98ala7hn0IhUBj0LEsOb2gMEhFjlOu7aanjQGMdm+5Nh39GiGcUGv2xFkTqkFHRc +YQoVbZ3WS3Wn6MFB8KZ4J4mWC1Dle4z2xDyyUstPJe4MJfA+bPd8KAcVcq/PrPNEY3MW/ 1UKOTKUoH/tS9L+eSgmBAbudQKZ0Yws= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-442-cUvMqT6cOeiFo4Iep1Asyg-1; Thu, 20 May 2021 07:09:54 -0400 X-MC-Unique: cUvMqT6cOeiFo4Iep1Asyg-1 Received: by mail-wr1-f71.google.com with SMTP id x10-20020adfc18a0000b029010d83c83f2aso8501938wre.8 for ; Thu, 20 May 2021 04:09:54 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=fXNvsUG+9jJQpscb+R8eaH4L2n3MJcy4IDVc87G545A=; b=AQ7tFjwUKDpuc1+qLY6/nFS9fXpYLDhOkBhBPjgHCQQSs9pit6IjkgxkzJvEBrAUqH jBlpvk02o2FPzMU1fH8RCMzU1H49cnTMdCwCTYkLxbLWcer7QQAp6GtR+E3PkHlesKUe ZUzKm2hK1ocf3ku2nNpRxThwSpVnL2jGE9U60ELx9ryUetYMo4w1nzIZ2v1tDWOtcKBk 3ebnR+/ptR+eiiwz9d6bba9e9/b15daPzlRbNSU5ShAnLFpD/5GOiy+C/8GAfnSVgdCq WUMS6KVC1IXapcsaG2v/vSgdX3rkdZZyu3/M2N4cXIC2bn9vQAq91H+qKbM6sdWWklDV 8uMA== X-Gm-Message-State: AOAM5331i6/aCI4R156zrlftenobyT8kCOOQM4Jc4U2GSRt57CxcBhmp utyKnXPiitlhXjlCeCUSaFXZa0S9MdQGKLUre3QEylceYUzJ7R8PYYPzHjwhli7BKtEfJEaTHmC 9YXtQnUDdqUnu3lm6QDoiaPuROsPZTQi7mnRDvVlbi5QgdKfk+Drm3m+GKHlbjvHa X-Received: by 2002:adf:b64b:: with SMTP id i11mr3726391wre.157.1621508992758; Thu, 20 May 2021 04:09:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxTd7krMeYhURd9rrzhSkonYF7s2c7PAIqcYV+Pz2bB20+DP+TDoCedf1y+fERUFDwyh3WMFw== X-Received: by 2002:adf:b64b:: with SMTP id i11mr3726360wre.157.1621508992578; Thu, 20 May 2021 04:09:52 -0700 (PDT) Received: from x1w.redhat.com (31.red-83-51-215.dynamicip.rima-tde.net. [83.51.215.31]) by smtp.gmail.com with ESMTPSA id l14sm2981326wrv.94.2021.05.20.04.09.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 May 2021 04:09:52 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [RFC PATCH 07/12] exec/memory_ldst_cached: Document aligned addresses are expected Date: Thu, 20 May 2021 13:09:14 +0200 Message-Id: <20210520110919.2483190-8-philmd@redhat.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20210520110919.2483190-1-philmd@redhat.com> References: <20210520110919.2483190-1-philmd@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=philmd@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=170.10.133.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.39, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , "Michael S. Tsirkin" , Richard Henderson , Peter Xu , Bibo Mao , Stefan Hajnoczi , Paolo Bonzini , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Philippe Mathieu-Daudé --- include/exec/memory_ldst_cached.h.inc | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/include/exec/memory_ldst_cached.h.inc b/include/exec/memory_ldst_cached.h.inc index a8f146251d4..515beb48f47 100644 --- a/include/exec/memory_ldst_cached.h.inc +++ b/include/exec/memory_ldst_cached.h.inc @@ -24,6 +24,7 @@ #define LD_P(size) \ glue(glue(ld, size), glue(ENDIANNESS, _p)) +/* warning: addr must be aligned */ static inline uint16_t ADDRESS_SPACE_LD_CACHED(uw)(MemoryRegionCache *cache, hwaddr addr, MemTxAttrs attrs, MemTxResult *result) { @@ -39,6 +40,7 @@ static inline uint16_t ADDRESS_SPACE_LD_CACHED(uw)(MemoryRegionCache *cache, } } +/* warning: addr must be aligned */ static inline uint32_t ADDRESS_SPACE_LD_CACHED(l)(MemoryRegionCache *cache, hwaddr addr, MemTxAttrs attrs, MemTxResult *result) { @@ -54,6 +56,7 @@ static inline uint32_t ADDRESS_SPACE_LD_CACHED(l)(MemoryRegionCache *cache, } } +/* warning: addr must be aligned */ static inline uint64_t ADDRESS_SPACE_LD_CACHED(q)(MemoryRegionCache *cache, hwaddr addr, MemTxAttrs attrs, MemTxResult *result) { @@ -80,6 +83,7 @@ static inline uint64_t ADDRESS_SPACE_LD_CACHED(q)(MemoryRegionCache *cache, #define ST_P(size) \ glue(glue(st, size), glue(ENDIANNESS, _p)) +/* warning: addr must be aligned */ static inline void ADDRESS_SPACE_ST_CACHED(w)(MemoryRegionCache *cache, hwaddr addr, uint16_t val, MemTxAttrs attrs, MemTxResult *result) { @@ -94,6 +98,7 @@ static inline void ADDRESS_SPACE_ST_CACHED(w)(MemoryRegionCache *cache, } } +/* warning: addr must be aligned */ static inline void ADDRESS_SPACE_ST_CACHED(l)(MemoryRegionCache *cache, hwaddr addr, uint32_t val, MemTxAttrs attrs, MemTxResult *result) { @@ -108,6 +113,7 @@ static inline void ADDRESS_SPACE_ST_CACHED(l)(MemoryRegionCache *cache, } } +/* warning: addr must be aligned */ static inline void ADDRESS_SPACE_ST_CACHED(q)(MemoryRegionCache *cache, hwaddr addr, uint64_t val, MemTxAttrs attrs, MemTxResult *result) { From patchwork Thu May 20 11:09:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 12269691 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=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham 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 393FCC433B4 for ; Thu, 20 May 2021 11:14:24 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id CB48160240 for ; Thu, 20 May 2021 11:14:23 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CB48160240 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:46428 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ljgdC-0007jG-TZ for qemu-devel@archiver.kernel.org; Thu, 20 May 2021 07:14:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44682) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ljgZ0-0000RJ-Fc for qemu-devel@nongnu.org; Thu, 20 May 2021 07:10:02 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:42150) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ljgYy-0004eG-Kr for qemu-devel@nongnu.org; Thu, 20 May 2021 07:10:02 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1621509000; 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=QEjpdg/IZ00DpLUx/mVY0KVvckbtUYRfwfr8N0WJ7zo=; b=WLQ1INpCdihdrOX0tKNGdN6l+nYTx84B8X81I3JP+ZHGEMllCIOLGyJLUFz/bC3sQgPN6u LBdA804sVWcTcuFPCX+a0aOMc4c7UrxeBmsJvKGou7gTzhgiLRO7HEl2FMjC5vN5cl2tR/ wvmF9hSh+fJ50v4tSduQgwhpIW1qmEE= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-208-NCqmkrCSO-qGZLZh29ykFQ-1; Thu, 20 May 2021 07:09:58 -0400 X-MC-Unique: NCqmkrCSO-qGZLZh29ykFQ-1 Received: by mail-wm1-f69.google.com with SMTP id 12-20020a1c010c0000b0290176491efde9so2188819wmb.4 for ; Thu, 20 May 2021 04:09:58 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=QEjpdg/IZ00DpLUx/mVY0KVvckbtUYRfwfr8N0WJ7zo=; b=h2NsXl8RBJZzUKAFkItQRFYQXRj8EEwtcjk/5PWVvHDmm9NhOwpSEmgoa++XHb87+N magB/iPb+D1/n3OuB/9reoRw77DwUVymwcGwWihs0Aak49mmeyuJz0HkqRFMQ9eWPOzn qD6WTowTCgS/cEI4yH2U1ZZmGbShYAIXWFYhGRWIRKfawgBrj89JWO3L0BxA1avdGU0+ OQlO55tP0lGIS76xzMUDh3JISUOFD34VnyU1e2UCBzQSo0Hj1RaoW5XdXHovqYFUcPqR zz4WKxIOOr0VOyjlcHsOkglzPO17TpiaUct0siCl4kAZ+zRWTx6RCUOjHet4iOyQC4i2 HiFw== X-Gm-Message-State: AOAM531+e9nsmkCrvM4aG3Nma8/6WSU2dAJ0+ysxtDPXrD2vz8zN+5of 7q2zaNaGr6PKwsU0i+1ArVI1VyMSWefMX4MyjauxnHPV+n71PhMM6FipfcWI2kZOhMnZrIuPRx4 ine3+54mJVDeM4iS1FtLV9SPgAcadH9D0c7m86LwOwnHo6zTKJvsHnJC16bA2D2TL X-Received: by 2002:adf:d4d1:: with SMTP id w17mr3820168wrk.413.1621508997263; Thu, 20 May 2021 04:09:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxMKWz7tO4wpoHu+uid8luC73vTDixiYStFcHSGB6n9Cm0IESN0cTtD5YhN/4V8wQe7Onypow== X-Received: by 2002:adf:d4d1:: with SMTP id w17mr3820143wrk.413.1621508997051; Thu, 20 May 2021 04:09:57 -0700 (PDT) Received: from x1w.redhat.com (31.red-83-51-215.dynamicip.rima-tde.net. [83.51.215.31]) by smtp.gmail.com with ESMTPSA id a19sm2290569wmb.40.2021.05.20.04.09.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 May 2021 04:09:56 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [RFC PATCH 08/12] exec/memory_ldst_cached: Check address alignment if requested Date: Thu, 20 May 2021 13:09:15 +0200 Message-Id: <20210520110919.2483190-9-philmd@redhat.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20210520110919.2483190-1-philmd@redhat.com> References: <20210520110919.2483190-1-philmd@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=philmd@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=170.10.133.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.39, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , "Michael S. Tsirkin" , Richard Henderson , Peter Xu , Bibo Mao , Stefan Hajnoczi , Paolo Bonzini , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" If the caller requires strict alignment, check the address satisfies it before doing the transaction. Otherwise return a MEMTX_UNALIGNED_ERROR. Signed-off-by: Philippe Mathieu-Daudé --- include/exec/memory_ldst_cached.h.inc | 42 +++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/include/exec/memory_ldst_cached.h.inc b/include/exec/memory_ldst_cached.h.inc index 515beb48f47..311a9759a22 100644 --- a/include/exec/memory_ldst_cached.h.inc +++ b/include/exec/memory_ldst_cached.h.inc @@ -31,6 +31,13 @@ static inline uint16_t ADDRESS_SPACE_LD_CACHED(uw)(MemoryRegionCache *cache, assert(addr < cache->len && 2 <= cache->len - addr); fuzz_dma_read_cb(cache->xlat + addr, 2, cache->mrs.mr); if (likely(cache->ptr)) { + if (attrs.aligned && unlikely(!QEMU_PTR_IS_ALIGNED(cache->ptr, + sizeof(uint16_t)))) { + if (result) { + *result = MEMTX_UNALIGNED_ERROR; + } + return (uint16_t)-1; /* XXX */ + } if (result) { *result = MEMTX_OK; } @@ -47,6 +54,13 @@ static inline uint32_t ADDRESS_SPACE_LD_CACHED(l)(MemoryRegionCache *cache, assert(addr < cache->len && 4 <= cache->len - addr); fuzz_dma_read_cb(cache->xlat + addr, 4, cache->mrs.mr); if (likely(cache->ptr)) { + if (attrs.aligned && unlikely(!QEMU_PTR_IS_ALIGNED(cache->ptr, + sizeof(uint32_t)))) { + if (result) { + *result = MEMTX_UNALIGNED_ERROR; + } + return (uint32_t)-1; /* XXX */ + } if (result) { *result = MEMTX_OK; } @@ -63,6 +77,13 @@ static inline uint64_t ADDRESS_SPACE_LD_CACHED(q)(MemoryRegionCache *cache, assert(addr < cache->len && 8 <= cache->len - addr); fuzz_dma_read_cb(cache->xlat + addr, 8, cache->mrs.mr); if (likely(cache->ptr)) { + if (attrs.aligned && unlikely(!QEMU_PTR_IS_ALIGNED(cache->ptr, + sizeof(uint64_t)))) { + if (result) { + *result = MEMTX_UNALIGNED_ERROR; + } + return (uint64_t)-1; /* XXX */ + } if (result) { *result = MEMTX_OK; } @@ -89,6 +110,13 @@ static inline void ADDRESS_SPACE_ST_CACHED(w)(MemoryRegionCache *cache, { assert(addr < cache->len && 2 <= cache->len - addr); if (likely(cache->ptr)) { + if (attrs.aligned && unlikely(!QEMU_PTR_IS_ALIGNED(cache->ptr, + sizeof(uint16_t)))) { + if (result) { + *result = MEMTX_UNALIGNED_ERROR; + } + return; + } if (result) { *result = MEMTX_OK; } @@ -104,6 +132,13 @@ static inline void ADDRESS_SPACE_ST_CACHED(l)(MemoryRegionCache *cache, { assert(addr < cache->len && 4 <= cache->len - addr); if (likely(cache->ptr)) { + if (attrs.aligned && unlikely(!QEMU_PTR_IS_ALIGNED(cache->ptr, + sizeof(uint32_t)))) { + if (result) { + *result = MEMTX_UNALIGNED_ERROR; + } + return; + } if (result) { *result = MEMTX_OK; } @@ -119,6 +154,13 @@ static inline void ADDRESS_SPACE_ST_CACHED(q)(MemoryRegionCache *cache, { assert(addr < cache->len && 8 <= cache->len - addr); if (likely(cache->ptr)) { + if (attrs.aligned && unlikely(!QEMU_PTR_IS_ALIGNED(cache->ptr, + sizeof(uint64_t)))) { + if (result) { + *result = MEMTX_UNALIGNED_ERROR; + } + return; + } if (result) { *result = MEMTX_OK; } From patchwork Thu May 20 11:09:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 12269703 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=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,USER_AGENT_GIT autolearn=ham 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 C4F8BC43460 for ; Thu, 20 May 2021 11:19:18 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 86EF360240 for ; Thu, 20 May 2021 11:19:18 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 86EF360240 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:57514 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ljghx-0006sl-Is for qemu-devel@archiver.kernel.org; Thu, 20 May 2021 07:19:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44694) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ljgZ4-0000dk-KY for qemu-devel@nongnu.org; Thu, 20 May 2021 07:10:06 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:28009) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ljgZ2-0004hU-VJ for qemu-devel@nongnu.org; Thu, 20 May 2021 07:10:06 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1621509004; 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=S06OJbLcsLoisVvd+3p+23m8ISoQC7YgJjRfb76l+Q8=; b=Ty+eaoUNAdtvtdruFndStzIMAlTQOxlw3pGCI9LWShTDeqE1fAWR2JByeVCI0RycV8Zh3P op/lWqGQd3h+1dEs2bItNltywW0475VrtYI5xxHk/oROyPmjKHqeYcD1WreKzhevi0LlUy YC1qbDhoe8fO8A8KpaIFlD0RnoB5Qnw= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-551-FvA5gzS3OQqrY9TCVJ1aVA-1; Thu, 20 May 2021 07:10:03 -0400 X-MC-Unique: FvA5gzS3OQqrY9TCVJ1aVA-1 Received: by mail-wm1-f71.google.com with SMTP id w7-20020a1cdf070000b02901698cfc1c04so2109239wmg.6 for ; Thu, 20 May 2021 04:10:03 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=S06OJbLcsLoisVvd+3p+23m8ISoQC7YgJjRfb76l+Q8=; b=EzxQ/hJRfU0+pzNgCXXCVNoESztzy5fn3kqVGA7PvHAsl3QRsbjmqw4ySk/c/2yc8m Rvy8Wo4udQm5sv0kSAWmFwmJFOFWZC+kuCbfgq6XwUVGrWAPkgHpnPHDwIHuW+Yxrtqw 17iM8VJlxifeB1FEDvBlwQVXKCw0v7u9VuZMlYHVKmnn0ctdJD7uIT6N3ONSXElX/fF1 aChGVExZ2jagdTUW6ja2j29Cq1gIx0pzoNZ3J88LTn8jEcgYcRiWPVm9SYJkrrfx2Mj/ 2GaTVM/87S/tqsBHdGF5vEu/EXjbwISVfj9pgJ8rtn9W1pBZiMjVYDDDHFPQfMOUwwBb jlOg== X-Gm-Message-State: AOAM5309q7oxNJbl3eq4poKKv761ddQocwZYYm6lLxij4xkfq5TOZNO1 pfgtyyNtMPEleKi6bguiTq0xb8OYbM8L+OJnRPRD4cd4mJW5wOZXMN8r9mfj5Nd7Kzg9E7+LKpU CE4ih8R5gPlw1TnBWNrGQ9sA8V3pyKYT2iloYbkXFmlpb9WMluAXJGMzcoioFgpwU X-Received: by 2002:a05:6000:1286:: with SMTP id f6mr3585457wrx.226.1621509001855; Thu, 20 May 2021 04:10:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzBTw1FpHwB4pwErnBQjO1DZafXorcKIJrnaoUYt/FQiRqv9609/jjGwfr6axovpAJfHyEdgQ== X-Received: by 2002:a05:6000:1286:: with SMTP id f6mr3585439wrx.226.1621509001703; Thu, 20 May 2021 04:10:01 -0700 (PDT) Received: from x1w.redhat.com (31.red-83-51-215.dynamicip.rima-tde.net. [83.51.215.31]) by smtp.gmail.com with ESMTPSA id r7sm2094567wmq.18.2021.05.20.04.10.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 May 2021 04:10:01 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [RFC PATCH 09/12] hw/virtio: Use correct type sizes Date: Thu, 20 May 2021 13:09:16 +0200 Message-Id: <20210520110919.2483190-10-philmd@redhat.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20210520110919.2483190-1-philmd@redhat.com> References: <20210520110919.2483190-1-philmd@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=philmd@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=216.205.24.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.39, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , "Michael S. Tsirkin" , Richard Henderson , Peter Xu , Bibo Mao , Stefan Hajnoczi , Paolo Bonzini , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Use uint16_t for unsigned 16-bit data and uint32_t for unsigned 32-bit. Signed-off-by: Philippe Mathieu-Daudé --- include/hw/virtio/virtio-access.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/hw/virtio/virtio-access.h b/include/hw/virtio/virtio-access.h index 6818a23a2d3..ae8c9feffc5 100644 --- a/include/hw/virtio/virtio-access.h +++ b/include/hw/virtio/virtio-access.h @@ -120,7 +120,7 @@ static inline void virtio_stq_p(VirtIODevice *vdev, void *ptr, uint64_t v) } } -static inline int virtio_lduw_p(VirtIODevice *vdev, const void *ptr) +static inline uint16_t virtio_lduw_p(VirtIODevice *vdev, const void *ptr) { if (virtio_access_is_big_endian(vdev)) { return lduw_be_p(ptr); @@ -129,7 +129,7 @@ static inline int virtio_lduw_p(VirtIODevice *vdev, const void *ptr) } } -static inline int virtio_ldl_p(VirtIODevice *vdev, const void *ptr) +static inline uint32_t virtio_ldl_p(VirtIODevice *vdev, const void *ptr) { if (virtio_access_is_big_endian(vdev)) { return ldl_be_p(ptr); From patchwork Thu May 20 11:09:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 12269705 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=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham 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 07AFCC43470 for ; Thu, 20 May 2021 11:19:40 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 9370260240 for ; Thu, 20 May 2021 11:19:39 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9370260240 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:58340 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ljgiI-0007R2-M0 for qemu-devel@archiver.kernel.org; Thu, 20 May 2021 07:19:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44722) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ljgZB-0000ih-3Q for qemu-devel@nongnu.org; Thu, 20 May 2021 07:10:14 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:50377) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ljgZ8-0004kY-Ob for qemu-devel@nongnu.org; Thu, 20 May 2021 07:10:12 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1621509009; 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=B2sGmsuzq6ssxzUGpyvhj2pP3TABHbW6gQF2vvqdbU8=; b=QHS/+nqp4jaZscfdDkjpcglFd2exjY4eLrQl463DHk30M/YDJWR3IbdUc1kGYNV/clgWXu bfS5As62ylIXXrUdJe8SGYu3kCC5D6U4yf29NX1StNDHD3y2bv7+dOMRYKZyeVSa9yADdM HamF2/y1804qjjDCJ6ZCmBVMwkKMa7w= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-488-4Qb3L5ILOPSEvYNh3-YZcw-1; Thu, 20 May 2021 07:10:08 -0400 X-MC-Unique: 4Qb3L5ILOPSEvYNh3-YZcw-1 Received: by mail-wr1-f69.google.com with SMTP id i15-20020a5d558f0000b029011215b1cf5cso2138724wrv.22 for ; Thu, 20 May 2021 04:10:07 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=B2sGmsuzq6ssxzUGpyvhj2pP3TABHbW6gQF2vvqdbU8=; b=ksX8MHe45VnFDqqm0y5A1515qWQ85IATqMj0WcNYpjgNerq5rP4qLBWj4kNhfTZUIj ML/G6YFXJOfgKVsrAz5IqVM6tEB8gXc2iEH+PB40M9pm1uvEFtXhQZSrAWgBaJUeytPC 3LBn4VTuYBdsokdbL3w7bxIk/9W7j6u7P32WE6o211/bk7gemRgUmRmVhKiqPcFAUJC9 KzwTaGasalJ4V3Qgu/apiaXEVULGOs7lHjVYhhqLIRAUXhT6qxtmmQ/ChSHQu4ROPa/V XugdQ2dplFuVVV6cpzL/RyVRxqblFXlZXnJkrxIOm0prq/iTIe2IlxfeR8/WDv+uH2r9 VqPQ== X-Gm-Message-State: AOAM530QzUyq5EWue7XfGrYCfyXHD8a4hzBHDuGvo2mB4EgXh1S8iqtE g10xaxqfBt1hzUJ7IWvWaPQxy7czOfusXwPepiyjY1aVg29lWe52NCn9gLPG9piuOJ9Oh/FkYhB n2qPmEbS6QTjX4tWtTPxEgG6ReUkqeqrT8jxGD0Max2ROqNFC4VLDsHD9rIb654P7 X-Received: by 2002:a5d:58d0:: with SMTP id o16mr3688297wrf.420.1621509006561; Thu, 20 May 2021 04:10:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzr1jKsgTU7z86XYAXdKX+v2p3GgjdQGU1xnatVqO28ldznpuvEBjfHYdTua9fyxEgVJdXhNg== X-Received: by 2002:a5d:58d0:: with SMTP id o16mr3688266wrf.420.1621509006290; Thu, 20 May 2021 04:10:06 -0700 (PDT) Received: from x1w.redhat.com (31.red-83-51-215.dynamicip.rima-tde.net. [83.51.215.31]) by smtp.gmail.com with ESMTPSA id j18sm2153364wmq.27.2021.05.20.04.10.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 May 2021 04:10:05 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [RFC PATCH 10/12] hw/virtio: Extract virtio_lduw_phys_cached_with_attrs() Date: Thu, 20 May 2021 13:09:17 +0200 Message-Id: <20210520110919.2483190-11-philmd@redhat.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20210520110919.2483190-1-philmd@redhat.com> References: <20210520110919.2483190-1-philmd@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=philmd@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=170.10.133.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.39, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , "Michael S. Tsirkin" , Richard Henderson , Peter Xu , Bibo Mao , Stefan Hajnoczi , Paolo Bonzini , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" To be able to specify memory transaction attributes (such the address alignment), extract virtio_lduw_phys_cached_with_attrs() from virtio_lduw_phys_cached(). Signed-off-by: Philippe Mathieu-Daudé --- include/hw/virtio/virtio-access.h | 35 +++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/include/hw/virtio/virtio-access.h b/include/hw/virtio/virtio-access.h index ae8c9feffc5..aebf0a088a0 100644 --- a/include/hw/virtio/virtio-access.h +++ b/include/hw/virtio/virtio-access.h @@ -156,14 +156,41 @@ static inline uint16_t virtio_tswap16(VirtIODevice *vdev, uint16_t s) #endif } +/** + * virtio_ld*_phys_cached_with_attrs: load from a VirtIO cached #MemoryRegion + * virtio_st*_phys_cached_with_attrs: store to a VirtIO cached #MemoryRegion + * + * These functions perform a load or store of the byte, word, + * longword or quad to the specified address. The address is + * a physical address in the VirtIO device AddressSpace, but it must lie within + * a #MemoryRegion that was mapped with address_space_cache_init. + * + * @vdev: virtio device accessed + * @cache: previously initialized #MemoryRegionCache to be accessed + * @pa: physical address within the address space + * @val: data value, for stores + * @attrs: memory transaction attributes + * @result: location to write the success/failure of the transaction; + * if NULL, this information is discarded + */ + +static inline uint16_t virtio_lduw_phys_cached_with_attrs(VirtIODevice *vdev, + MemoryRegionCache *cache, + hwaddr pa, MemTxAttrs attrs, + MemTxResult *result) +{ + if (virtio_access_is_big_endian(vdev)) { + return address_space_lduw_be_cached(cache, pa, attrs, result); + } + return address_space_lduw_le_cached(cache, pa, attrs, result); +} + static inline uint16_t virtio_lduw_phys_cached(VirtIODevice *vdev, MemoryRegionCache *cache, hwaddr pa) { - if (virtio_access_is_big_endian(vdev)) { - return lduw_be_phys_cached(cache, pa); - } - return lduw_le_phys_cached(cache, pa); + return virtio_lduw_phys_cached_with_attrs(vdev, cache, pa, + MEMTXATTRS_UNSPECIFIED, NULL); } static inline uint32_t virtio_ldl_phys_cached(VirtIODevice *vdev, From patchwork Thu May 20 11:09:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 12269715 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=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham 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 051ADC433ED for ; Thu, 20 May 2021 11:22:30 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id B1E00613AD for ; Thu, 20 May 2021 11:22:29 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B1E00613AD Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:35404 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ljgl2-0002jo-Sa for qemu-devel@archiver.kernel.org; Thu, 20 May 2021 07:22:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44770) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ljgZR-0000qy-8P for qemu-devel@nongnu.org; Thu, 20 May 2021 07:10:30 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:24036) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ljgZE-0004q0-G6 for qemu-devel@nongnu.org; Thu, 20 May 2021 07:10:29 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1621509015; 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=hT9YCxRj1ou3uPTM7bSJ+zjEyH6kGbopTpVH+99i5eA=; b=U0IC6NNcPAIICAYcoZ4O9ALpga3nVinRx7fhfowFpObaM96alSsHC4Ib3mHWn08lGX1BO/ XOJSPmfPXPjBElkWfLSkJcrq6sQ72PELYcQU/udoAtj9m25tqEt0CpBkQ+UP2vYjkPoP0w +rRSiwLDKgVSuj7mYL4PuiEVYV6P6Sg= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-357--UsEFaXqOyu41KoHqu9Dwg-1; Thu, 20 May 2021 07:10:12 -0400 X-MC-Unique: -UsEFaXqOyu41KoHqu9Dwg-1 Received: by mail-wr1-f69.google.com with SMTP id q15-20020adfc50f0000b0290111f48b865cso5029759wrf.4 for ; Thu, 20 May 2021 04:10:12 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=hT9YCxRj1ou3uPTM7bSJ+zjEyH6kGbopTpVH+99i5eA=; b=avnEio57j91LfZn14vKfrx5HHM0m9GLUlFMxaAiTKaPhj2fZmgsY5F+j1nC1G/271Q +sR4XDsBw3wzJOkI9xbB9sXnfhr1h0G6jALICUga1BXzP54l2ZtL5p//Uuv4EgcSIxAM d/zFYSfV0eZPoH47907q1SMxo48PO87/8IhpFC23+NICs/ahUvcu5yzTzPfal9t5AR6R TLPjnYnyJ7u/fs3SOFN6MBpaEoy6JEpehvVL7CfmwqBXKIYshl5TdKldmRHtu8JAvERJ AfIX4RRAfOXRkGJQ17BJ6u6nOQOzmmWsKPfDpas/17qdcmkElcql2Eo9rt2VZaC90Xbz U+JA== X-Gm-Message-State: AOAM532cA5n5FzRNyT2W4m4DVHwM7bJRPXC/9fob7awxGvOHI4dX7V8H s1X+B/yepQskWYX3IRg3595nlv5zgvrtKdP7+S+7ONmdizZUCbPC4nOx4zRTGH5O9dLhmHfDxdJ je67tKm23PuaEGlmB257VW3dP1q+xSEx9b7UXENr9ACv0Hmi95c4iR9XicRHfJSqx X-Received: by 2002:a05:600c:1909:: with SMTP id j9mr3175859wmq.100.1621509011020; Thu, 20 May 2021 04:10:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwNpo4h4UrADIjXZ1b95pgvWd070pZ4FEyaaomJsGttuRFQyMPcbIM8LWkbeqgCSQnyXkoUtA== X-Received: by 2002:a05:600c:1909:: with SMTP id j9mr3175822wmq.100.1621509010775; Thu, 20 May 2021 04:10:10 -0700 (PDT) Received: from x1w.redhat.com (31.red-83-51-215.dynamicip.rima-tde.net. [83.51.215.31]) by smtp.gmail.com with ESMTPSA id f13sm3010371wrt.86.2021.05.20.04.10.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 May 2021 04:10:10 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [RFC PATCH 11/12] hw/virtio: Have vring_avail_flags() return a boolean value Date: Thu, 20 May 2021 13:09:18 +0200 Message-Id: <20210520110919.2483190-12-philmd@redhat.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20210520110919.2483190-1-philmd@redhat.com> References: <20210520110919.2483190-1-philmd@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=philmd@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=216.205.24.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.39, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , "Michael S. Tsirkin" , Richard Henderson , Peter Xu , Bibo Mao , Stefan Hajnoczi , Paolo Bonzini , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" To be able to check the memory transaction succeeded, change the vring_avail_flags() to take the value to read by argument, so we can return a boolean whether we succeeded or not. Signed-off-by: Philippe Mathieu-Daudé --- hw/virtio/virtio.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index e02544b2df7..1b8bc194ce1 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -287,16 +287,19 @@ static VRingMemoryRegionCaches *vring_get_region_caches(struct VirtQueue *vq) } /* Called within rcu_read_lock(). */ -static inline uint16_t vring_avail_flags(VirtQueue *vq) +static inline bool vring_avail_flags(VirtQueue *vq, uint16_t *val) { VRingMemoryRegionCaches *caches = vring_get_region_caches(vq); hwaddr pa = offsetof(VRingAvail, flags); if (!caches) { - return 0; + *val = 0; + return true; } - return virtio_lduw_phys_cached(vq->vdev, &caches->avail, pa); + *val = virtio_lduw_phys_cached_with_attrs(vq->vdev, &caches->avail, pa); + + return true; } /* Called within rcu_read_lock(). */ @@ -2462,7 +2465,9 @@ static bool virtio_split_should_notify(VirtIODevice *vdev, VirtQueue *vq) } if (!virtio_vdev_has_feature(vdev, VIRTIO_RING_F_EVENT_IDX)) { - return !(vring_avail_flags(vq) & VRING_AVAIL_F_NO_INTERRUPT); + uint16_t flags; + return vring_avail_flags(vq, &flags) + && !(flags & VRING_AVAIL_F_NO_INTERRUPT); } v = vq->signalled_used_valid; From patchwork Thu May 20 11:09:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 12269693 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=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham 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 4426EC433ED for ; Thu, 20 May 2021 11:14:33 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 0DD4C60E09 for ; Thu, 20 May 2021 11:14:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0DD4C60E09 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:46922 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ljgdM-00083N-45 for qemu-devel@archiver.kernel.org; Thu, 20 May 2021 07:14:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44768) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ljgZN-0000pc-7m for qemu-devel@nongnu.org; Thu, 20 May 2021 07:10:27 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:36684) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ljgZJ-0004tt-1h for qemu-devel@nongnu.org; Thu, 20 May 2021 07:10:24 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1621509020; 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=SEIK0+f8xAhENSUO1Wsp9GXIhMyGmKAMVfEhOA0o4Xo=; b=IIMtm31G01fbJRopAxbhH7p8buMyEOQZHrhosTd9GPQ1zoZJj29q+ElTscOu+fYZQXFCeP cCl13pTg9uN85T91tbKsfNH1vwBsRCorUhu6sUzY/fNG8K/97bdp8bGGcVdQ5DiXJtCPTE PX/176Az6F3ucQ9cRO5I8Jj3XQEDGr8= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-381-Fp4JHnprOZamwN8lYhcukQ-1; Thu, 20 May 2021 07:10:17 -0400 X-MC-Unique: Fp4JHnprOZamwN8lYhcukQ-1 Received: by mail-wm1-f72.google.com with SMTP id u203-20020a1cddd40000b029016dbb86d796so2199564wmg.0 for ; Thu, 20 May 2021 04:10:16 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=SEIK0+f8xAhENSUO1Wsp9GXIhMyGmKAMVfEhOA0o4Xo=; b=Ir3Wwx8rZm0lclAV7RDTTvWN9cifmD3c40TE4hh1enz39PyMZAKO3pwXO6wyQ78ulH dVVcbXhep6oycvrbj17aHUd41a/OFLLUih2O1i48cvaXPSmbSH3d4yXZy4pDkj5ezjdK L5Tuud2+029v7Hu98OimU6oWXKrYrAVmyAZ/kUlGHNjTk7RgUD9QqwGhM+4QlbDk2fQu H/e0gK8OklpD+D1IrhAi//XfKNjruwByCXYR94wGZeq8ygDed80iK/RpfnscQTSyTGI8 pKR/LibBCcEfNZZEwF+CHHAK+yOfP6+Egrwo1f+cORzGEkCf/8b2bkrqzyXDS65wMphT zJ+g== X-Gm-Message-State: AOAM531Byx+t3Umcek1qmLBl12w9mPWJGIEGF5eiBwwU93dFo5vwjgpo Fy6YMx18Ybgo3wZiz615gpZY5XIFQ1Y+EOV4mX+fHyUzumI2/oWvxOuol2NNxXHnThq/AE2nFqZ Zmtg5LkXeqNu/v2ZOxt0l5Y28BpWSvGsnqzpf0cWnMtlQ2jA6LcRt7OTTzw1Zwi0i X-Received: by 2002:adf:e608:: with SMTP id p8mr3801845wrm.162.1621509015623; Thu, 20 May 2021 04:10:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzgOa3Tel7oAr+U0C0L/KLNS+VyKeVlMa8TYcIL1vcCGh34R3TMJnS/Xhv4kOqefrqVE7VApA== X-Received: by 2002:adf:e608:: with SMTP id p8mr3801817wrm.162.1621509015405; Thu, 20 May 2021 04:10:15 -0700 (PDT) Received: from x1w.redhat.com (31.red-83-51-215.dynamicip.rima-tde.net. [83.51.215.31]) by smtp.gmail.com with ESMTPSA id l3sm2331270wmh.2.2021.05.20.04.10.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 May 2021 04:10:15 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [RFC PATCH 12/12] hw/virtio: Display error if vring flag field is not aligned Date: Thu, 20 May 2021 13:09:19 +0200 Message-Id: <20210520110919.2483190-13-philmd@redhat.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20210520110919.2483190-1-philmd@redhat.com> References: <20210520110919.2483190-1-philmd@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=philmd@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=216.205.24.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.39, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , "Michael S. Tsirkin" , Richard Henderson , Peter Xu , Bibo Mao , Stefan Hajnoczi , Paolo Bonzini , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Per the virtio spec [*] the vring is aligned, so the 'flag' field is also 16-bit aligned. If it is not, this is a guest error, and we'd rather report any malicious activity. Enforce the transaction alignment by setting the 'aligned' attribute and log unaligned addresses. Signed-off-by: Philippe Mathieu-Daudé --- hw/virtio/virtio.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index 1b8bc194ce1..f19d12fc71e 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -291,15 +291,24 @@ static inline bool vring_avail_flags(VirtQueue *vq, uint16_t *val) { VRingMemoryRegionCaches *caches = vring_get_region_caches(vq); hwaddr pa = offsetof(VRingAvail, flags); + MemTxAttrs attrs = { .aligned = 1 }; + MemTxResult res; if (!caches) { *val = 0; return true; } - *val = virtio_lduw_phys_cached_with_attrs(vq->vdev, &caches->avail, pa); + *val = virtio_lduw_phys_cached_with_attrs(vq->vdev, &caches->avail, + pa, attrs, &res); + if (res == MEMTX_UNALIGNED_ERROR) { + qemu_log_mask(LOG_GUEST_ERROR, + "virtio: vring flag address 0x%" HWADDR_PRIX " " + "is not aligned\n", pa); + return false; + } - return true; + return res == MEMTX_OK; } /* Called within rcu_read_lock(). */