From nobody Sun May 12 15:43:07 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1621508971; cv=none; d=zohomail.com; s=zohoarc; b=NgkxXAbeXxjiZAbsSbc4pGsoFTrYKTmXdog1m7toJhm40CoDWj1tcuXGpcDq0A3l5QqEVuoQkqvqbPDy+OH1EZkpXCYYcrCWEay527KVE5jhVUNBFX2Yjdr95oJepn2z2A7KGxXSStdgfnzH/mZl/u+o141aTfl0VSbFt2QLbX4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1621508971; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=9HmbSl5d9pXpS90PMMdxl3LY29W1LC7gy3N9ueCnGUQ=; b=Sj9GcLKT9xXgPvz0TmQUYRziw/Zy0VPle5vX+Jze9EPd3bnHP3urgW7UvSS8bHD42suAYNX5LKy01Rx6XWvwKKQXa4Q1c72j0K4qJ0aFgRjPUW9wwzpkoWihNJgzxcGF/tKhb7nvYEOSl/xRZiQKAfAzuBIqm90JaDkMttyz/pw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1621508971372198.3680039759903; Thu, 20 May 2021 04:09:31 -0700 (PDT) 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-194-3MVKeh4CN3SBkHoSova4JA-1; Thu, 20 May 2021 07:09:26 -0400 Received: by mail-wm1-f71.google.com with SMTP id y193-20020a1c32ca0000b029014cbf30c3f2so2192719wmy.1 for ; Thu, 20 May 2021 04:09:26 -0700 (PDT) Return-Path: Return-Path: 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) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1621508970; 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=ftG/YlhZSCdFlMJaO+QVoLLUMFTQKBqM3gV9vfeaoVQGRAfWGYz1Ik3Qo5Ybmr/NgAz+UQ O5qxnm9RjRvc6ZCVHNNRfTymX84mznfBJmaPdiBa2wl6Jxa4sYI0zthRlqHbAzm9siC0hr BfI/+Vo9XN57zpso3ZYTbFAFDIM+hjA= X-MC-Unique: 3MVKeh4CN3SBkHoSova4JA-1 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=CphVyfNIVWAt0BHK5hrNBcMHdMwVJ+/oIaicAz9mUj0QgqYZBo5zhDYcpdEKa2Uzc8 bE/D64KcvvO5lCeRBjaSZgNveX6P6IO19sb2RX0Sw6nF2oWKvRcyYaqEtG0pJi6m9ESb 2M0VAjkpCF35zJ6rzfq9JpCyxFVrtBscsdNAuYsfRGM7itUalIw2uCBEYiDYp16ni2L6 WkFlcUMDyHEqS4oZfac3Ohcl6QRfJ1lg+4CeCB2pW5gIp9lsrcXmUSzv+wIPtF14RumN kGsYjBApqX8aMpAHa7cuaDyJeOQsXXdyCNRpYeIx4Tl5FPBKH70fRpBnFDetlvhKr4P5 d4zQ== X-Gm-Message-State: AOAM533334R1ntel45QbEzWYJHqIU4P59yGEHYTpLkCnI11h77oXsCQp vtUzUI9wwrGZUIePxWsZkGxMhRT3J+OKH6YdoEAXnhRkV5nAgmzVevR9i2ZKDeW8Vi0hqTseXYm Orrg6Z0PKQM6MeA== X-Received: by 2002:a5d:618f:: with SMTP id j15mr3609378wru.273.1621508965583; 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) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: "Michael S. Tsirkin" , Stefan Hajnoczi , Peter Maydell , Peter Xu , Paolo Bonzini , Richard Henderson , Bibo Mao , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= 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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Use uint8_t for (unsigned) byte, and uint16_t for (unsigned) 16-bit word. Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- 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 @@ */ =20 #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_DE= CL, 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); } =20 -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, } =20 /* 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_intern= al, SUFFIX)(ARG1_DECL, return val; } =20 -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, re= sult, DEVICE_NATIVE_ENDIAN); } =20 -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, re= sult, DEVICE_LITTLE_ENDIAN); } =20 -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, re= sult, @@ -366,7 +366,7 @@ void glue(address_space_stl_be, SUFFIX)(ARG1_DECL, } =20 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, =20 /* 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, S= UFFIX)(ARG1_DECL, } =20 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, resul= t, DEVICE_NATIVE_ENDIAN); } =20 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, resul= t, DEVICE_LITTLE_ENDIAN); } =20 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, resul= t, DEVICE_BIG_ENDIAN); --=20 2.26.3 From nobody Sun May 12 15:43:07 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1621508973; cv=none; d=zohomail.com; s=zohoarc; b=d7cNretqJg6LL3xY/Q6P5uiEzSF2T6385Nkzyx05metvqo7osURXYnMWpmx+m2WeQ2Vu5goiDtoTuOQImodgM9de0cKUZNHTS77sZ5tEIdzf4P75BXI8U2VgPu+OfHW3nn3vbchdoa5Qph4WIkQJMfxivsTQ47GP9VQ32s13KU0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1621508973; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=z3/KZxEceqNBHXRRxZ4yuG2qkGWWINMUXp6C+3kJ9h4=; b=eTVAFtZtS4RAyYU0XkFmEwl/sdz08F/2ZVQgPhduIBs8DvB4Ig/iXNdwnOxs8R+lbWjABrh+APiPNscAO1uNKNjKoT1d/Id0cnjTNdsz13BGnfAC2zoqJAolApVMIxx5LDfVU4RubgYyw+qYnTs+du8/7vTMxxfxOPqf/5S8fbY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1621508973859505.9872342059516; Thu, 20 May 2021 04:09:33 -0700 (PDT) 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-434-xjbV_970PB6dwqYavzkjsA-1; Thu, 20 May 2021 07:09:31 -0400 Received: by mail-wm1-f72.google.com with SMTP id g17-20020a05600c0011b029014399f816a3so1310745wmc.7 for ; Thu, 20 May 2021 04:09:31 -0700 (PDT) Return-Path: Return-Path: 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) 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= X-MC-Unique: xjbV_970PB6dwqYavzkjsA-1 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=rOik5RABuYdUxXizjWe7AQ3Njv2hKVVUygk3s7Lhqt0q3wPtH/mocrOH+1JMYdNS16 zi49wclhRzqBX+AglFuohpz540JOcs6vbgXra8fWQzez4jitWsoBGrqg9ort0s0bIxAf 9peyla0jegY1/0/Ahn/I/riKdMZjOggwfjASv6CC9EYjhDP76RkWCbrIImLSfDwBo6C1 SEGDQL54d/V1KRh3snNTrAZ8uANeYKU08OiStzlYgwLsMTYL5q9lQ5eViRgO7ITOclDY jJ362Hp9F3J51+PXzDfG2y2gFKKgv/JszC/1CFXGAbhruvw//xif78WNnrMUKbBmLskX ejJw== X-Gm-Message-State: AOAM532DbUpy1dPfdhmY/MKo/U3v7wYxFOjax4yKZ/dGopFBql08ogaZ Hd/k8eA4rThcAFkNSF50JIZW+d8GTCq4zvLzBlmPNZjCMF1wwdglzDF7OvXORSUVPqTTYuU4lWZ plyM0rQAPWA8cPA== X-Received: by 2002:a5d:5008:: with SMTP id e8mr3641401wrt.386.1621508970190; 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) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: "Michael S. Tsirkin" , Stefan Hajnoczi , Peter Maydell , Peter Xu , Paolo Bonzini , Richard Henderson , Bibo Mao , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= 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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) 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=C3=A9 --- 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 struct= ure @@ -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; =20 #endif --=20 2.26.3 From nobody Sun May 12 15:43:07 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1621508978; cv=none; d=zohomail.com; s=zohoarc; b=nxGC1RbHXITZd/n7QixgyVlnNNQkbBxJwRBDG1eVkImCjmTwJnlh8pCbUSC9xb6IUrVAgJSJr9bGqqIwMEukWDn/m9O3OhnyR+DSoSoZUxhafHHg9FA2AC2gKwK873eD0JuRgu5ICjXajCqM3eAQyzTdfck76Bn4vDNCeISJ9gk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1621508978; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=BIUKBelUrGAg7JFPfqNH9aSjg1FuXfUME+/SSVTybmA=; b=ea27qBr8mLKRvK7jpH5vS86i1xdbhzBt7Zk5gV8i1rNnFSG44cgdXX4SP6KCXcuDzkp1kJcIfqaiCkg6HyOtByLr6OD6H/GGZBVjk9HJ3UpQSOGF9ItjhvyC2CIGY722MZ920svoU438B4Y6WgnGu4uuvUJvawQ8TB1U0N7ka7Q= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1621508978321184.99203207211735; Thu, 20 May 2021 04:09:38 -0700 (PDT) Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-555-XGktsYa_MEySmUcsCFanXA-1; Thu, 20 May 2021 07:09:35 -0400 Received: by mail-wm1-f70.google.com with SMTP id 12-20020a1c010c0000b0290176491efde9so2188408wmb.4 for ; Thu, 20 May 2021 04:09:35 -0700 (PDT) Return-Path: Return-Path: 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) 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= X-MC-Unique: XGktsYa_MEySmUcsCFanXA-1 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=BiSBVOdF/3m35cLBv0PuKfE51eqcpYA5w8eMbi0D/5FblICsN4AsEbhai/u5g6ZeOw /yHQYG5kTsylMXIikBoyMbOlvbYTVlZuLtuHf32NcFmmp9a44drPxQqTAaXIOnaFiOVt w0ej9zQG71cTBUNsOYlcOaA34cA15n9wG2JG+yJ9kDKlkrMdh+DI/bxuLkv58NFZ848u xSc9tC9HI86tvQzHOFGikULLYP8Utxpz9XD01b2DfAtQLfAYtu2PvkYISrsgE0WiLD9q X7+eTm5xweQcU3KB2A2VIhU5NGsEkNoWWHA7+v4YL+6m2NdtaKl91aSO0bBgWgFBJzLD LJkA== X-Gm-Message-State: AOAM533A7CKSmbzkpiwxqWy/mB5mmRDU4ST+/C3pYaSeQpyGJiUpsOcu FIcz+2/jwAuS77ePG6dIcd+p7Zc8+QcEP4fMj0bwxvPeggyEcQfclJGxlE7zfnDrBPVmS9MA/8K 9O8WYbEHKvUH4ig== X-Received: by 2002:a5d:62c7:: with SMTP id o7mr3673001wrv.372.1621508974668; 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) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: "Michael S. Tsirkin" , Stefan Hajnoczi , Peter Maydell , Peter Xu , Paolo Bonzini , Richard Henderson , Bibo Mao , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= 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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) 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=C3=A9 --- 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 =3D false; =20 + if (unlikely(!QEMU_IS_ALIGNED(addr, sizeof(uint32_t)))) { + if (result) { + *result =3D MEMTX_UNALIGNED_ERROR; + } + return (uint32_t)-1; /* XXX */ + } + RCU_READ_LOCK(); mr =3D 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 =3D false; =20 + if (unlikely(!QEMU_IS_ALIGNED(addr, sizeof(uint64_t)))) { + if (result) { + *result =3D MEMTX_UNALIGNED_ERROR; + } + return (uint64_t)-1; /* XXX */ + } + RCU_READ_LOCK(); mr =3D 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_interna= l, SUFFIX)(ARG1_DECL, MemTxResult r; bool release_lock =3D false; =20 + if (unlikely(!QEMU_IS_ALIGNED(addr, sizeof(uint16_t)))) { + if (result) { + *result =3D MEMTX_UNALIGNED_ERROR; + } + return (uint16_t)-1; /* XXX */ + } + RCU_READ_LOCK(); mr =3D 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_DEC= L, uint8_t dirty_log_mask; bool release_lock =3D false; =20 + if (unlikely(!QEMU_IS_ALIGNED(addr, sizeof(uint32_t)))) { + if (result) { + *result =3D MEMTX_UNALIGNED_ERROR; + } + return; + } + RCU_READ_LOCK(); mr =3D 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, SU= FFIX)(ARG1_DECL, MemTxResult r; bool release_lock =3D false; =20 + if (unlikely(!QEMU_IS_ALIGNED(addr, sizeof(uint32_t)))) { + if (result) { + *result =3D MEMTX_UNALIGNED_ERROR; + } + return; + } + RCU_READ_LOCK(); mr =3D 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, SU= FFIX)(ARG1_DECL, MemTxResult r; bool release_lock =3D false; =20 + if (unlikely(!QEMU_IS_ALIGNED(addr, sizeof(uint16_t)))) { + if (result) { + *result =3D MEMTX_UNALIGNED_ERROR; + } + return; + } + RCU_READ_LOCK(); mr =3D 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)(A= RG1_DECL, MemTxResult r; bool release_lock =3D false; =20 + if (unlikely(!QEMU_IS_ALIGNED(addr, sizeof(uint64_t)))) { + if (result) { + *result =3D MEMTX_UNALIGNED_ERROR; + } + return; + } + RCU_READ_LOCK(); mr =3D TRANSLATE(addr, &addr1, &l, true, attrs); if (l < 8 || !memory_access_is_direct(mr, true)) { --=20 2.26.3 From nobody Sun May 12 15:43:07 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1621508984; cv=none; d=zohomail.com; s=zohoarc; b=YL9sLtSra+nC/r+xXST9mOr4hXKZyoKqrZEayjOaICkhaOd9Kk4aEPpIiPL2DAZZGDf4ISe9GdGLoxDc8Sdv5Ft46XIaKMFpELBRNNJKbx9ZKvRg2w5s9N35WJUFSughXDPIMXukfi3CI4hIkUTBYgUjPvfiXQsD3wirbTJk1h4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1621508984; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=2KSH1YwMn8zpDyDH9Uq0LVnJ/rgrT/JgFf8hkb+U/HU=; b=mUZK4lsNjE13PqSoARGPfDB81Pa+CBDjZAPLgVkbFEyh7CSUEyrcLlqSPTRfxQZ0UIhubXCHTpWmYK9izKXJBp9TYkwRoEpOtJlVgg6cfCkszFl5iIdy/xKMemxdasdjpXLB3He9FoYoiYTWG9fbMe6xplJsmIZLQUKsch06j3A= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1621508984427769.8571104849906; Thu, 20 May 2021 04:09:44 -0700 (PDT) Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-23-V73a-fHUOVSeiq-tiLAgwg-1; Thu, 20 May 2021 07:09:40 -0400 Received: by mail-wr1-f72.google.com with SMTP id u20-20020a0560001614b02901115c8f2d89so8415926wrb.3 for ; Thu, 20 May 2021 04:09:40 -0700 (PDT) Return-Path: Return-Path: 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) 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= X-MC-Unique: V73a-fHUOVSeiq-tiLAgwg-1 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=szdVfy9gvnwbJJcYFIlFN63IeNMkrelYV/1u+p2eZANVfGKajvkPG2lU3zGZdOiLQo V0Hdiah2yOpgDBuoEexyUcrZYjWoZyoJTP4FjGyaZ7k/jdaV0JU/XhdVGJ8OP346rp1Z nWxvMoA6/Y//tKIFIcu7qe1uojPVgJn8cITFOhRZrxNXbSdFdccj/ucoCbbM7qKEDGEY BuNcwT89q8G/cxFdur8xPWC6LHpk12baHpGeApRDRxndHfKEju3ErU1kMvE+I9AUZPIH UBLwzb7toH0gbFwk5QXfZGqKPGNZEN/yFGm3DhzZCPL1yV+/aTMB6A20GnSb/K1ArZWi tWqA== X-Gm-Message-State: AOAM5302pZO082uVMPYs0Q2z98YAI9mnnTmcsw34XP63KdZ6XukxO79r 52JEghdVSnWd8o7IDg6bK7LZ9C69KVKbb2Spv7Gp5Q18BzcYzqv0LhpasYzUMOg0y0pk7agp7mD jLiyO7eWCkTBUzw== X-Received: by 2002:a7b:c14f:: with SMTP id z15mr3523681wmi.149.1621508979264; 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) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: "Michael S. Tsirkin" , Stefan Hajnoczi , Peter Maydell , Peter Xu , Paolo Bonzini , Richard Henderson , Bibo Mao , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= 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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) 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=C3=A9 --- 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_ld= st_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)) =20 +static inline uint32_t ADDRESS_SPACE_LD_CACHED(uw)(MemoryRegionCache *cach= e, + hwaddr addr, MemTxAttrs attrs, MemTxResult *result) +{ + assert(addr < cache->len && 2 <=3D 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)(Memory= RegionCache *cache, } } =20 -static inline uint32_t ADDRESS_SPACE_LD_CACHED(uw)(MemoryRegionCache *cach= e, - hwaddr addr, MemTxAttrs attrs, MemTxResult *result) -{ - assert(addr < cache->len && 2 <=3D 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)(Memor= yRegionCache *cache, #define ST_P(size) \ glue(glue(st, size), glue(ENDIANNESS, _p)) =20 -static inline void ADDRESS_SPACE_ST_CACHED(l)(MemoryRegionCache *cache, - hwaddr addr, uint32_t val, MemTxAttrs attrs, MemTxResult *result) -{ - assert(addr < cache->len && 4 <=3D 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)(MemoryRegi= onCache *cache, } } =20 +static inline void ADDRESS_SPACE_ST_CACHED(l)(MemoryRegionCache *cache, + hwaddr addr, uint32_t val, MemTxAttrs attrs, MemTxResult *result) +{ + assert(addr < cache->len && 4 <=3D 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) { --=20 2.26.3 From nobody Sun May 12 15:43:07 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1621508990; cv=none; d=zohomail.com; s=zohoarc; b=RTeWywFENY6MSA8aCi3KfRZC7TFfj+sVs82DlMQHUnV2UTJTTs34Q8d034XTLLovGsuI38am4tcyK6CEZ5w09CziuBtg5FJDdi2pN3dA7rghB2mPS3bbl1o9e03WHdNabmYUbJlv5ocBZ670TEQROuc8KPEe2sKCBFG5dE+ZJPU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1621508990; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=Z2KMRus6wjZmSwZp3NDF0wx5q7DfpOUE+gwTHQ1DOIM=; b=T2nXgpivCLM3uct2Xd7J+1G9Djgd2iZkGVWYLCiu1AO0DyjUF0mzPPlMVEe9y9gs9v91+29xg8v2DG1DLG9mWv0VcDJ9OL2AdeRulH3c0QUuWrvcuSV0t6gnXyZQYpatd9Wh+UqQIIFD3rGVGCS8tgcPnblIOlTFc6HFZmNYAlc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1621508989998879.9176066827132; Thu, 20 May 2021 04:09:49 -0700 (PDT) Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-311-aI8W3JwaMkWXO2se68xjUg-1; Thu, 20 May 2021 07:09:44 -0400 Received: by mail-wm1-f70.google.com with SMTP id y193-20020a1c32ca0000b029014cbf30c3f2so2193066wmy.1 for ; Thu, 20 May 2021 04:09:44 -0700 (PDT) Return-Path: Return-Path: 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) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1621508988; 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=QCacbFnM2gHiVZlnYfIKjHC0fqaBfJgqfHHAs2ZP+m2iWyUr38+KLCQ3wQWT82zp4muxRP IFwl8X0waUbAgx3px8bRLrvgbroGOEqnHpT+gtTKsYYPokpdJLQf5Dqk1gkOgOnG0BVnQs dsPnVNny+u0F7tvgcBEx7GoVKfoCy8I= X-MC-Unique: aI8W3JwaMkWXO2se68xjUg-1 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=HoGwjq47Ebz2yWmnNimm1ZyVvZ4n9+DYpRVc7qSxsmEAe4cq1sberK92sWT4gHIZnY B1qLYHTOH99kbEtEisrBGgNBsaKHxpHYbC5A78W6qaaw/8QO1UpCrWj9iKuMslXphg8x U/9TiKzuaiiTdikcwkMF+jcrpJwZRQYfVyllMbDtZ2HICNxSxHdzx43caDIHd87n/l5m HNfZCXsPffoCfY7jb/q9iZSOW7Jq43LN8N8WnYK57TAd2yDm7gzjy1dQ1C4B8/hWTVkR igWcigQJabcN5h5WWDwwn2gCYG1qqGtvGpA3GynyeAKJZkjmDMjMinb2DHN7H0tsU5oV vjOw== X-Gm-Message-State: AOAM533A5Uco8/wgvzDhBH+YggwiMps9vPG5FhhGUlGMRlUoN2DljyBW A7OKdx3+QPBbvbC8cRQgi/t8Ddwake3sl+mA9wVaNfGjVl5B9G7+AafzUDzKTfk+K3hSQGXV9oK o5mv69yej9vdRsQ== X-Received: by 2002:a1c:e912:: with SMTP id q18mr3537317wmc.59.1621508983687; 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) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: "Michael S. Tsirkin" , Stefan Hajnoczi , Peter Maydell , Peter Xu , Paolo Bonzini , Richard Henderson , Bibo Mao , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= 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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Use uint16_t for (unsigned) 16-bit word. Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- 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_ld= st_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)) =20 -static inline uint32_t ADDRESS_SPACE_LD_CACHED(uw)(MemoryRegionCache *cach= e, +static inline uint16_t ADDRESS_SPACE_LD_CACHED(uw)(MemoryRegionCache *cach= e, hwaddr addr, MemTxAttrs attrs, MemTxResult *result) { assert(addr < cache->len && 2 <=3D cache->len - addr); @@ -72,7 +72,7 @@ static inline uint64_t ADDRESS_SPACE_LD_CACHED(q)(MemoryR= egionCache *cache, glue(glue(st, size), glue(ENDIANNESS, _p)) =20 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 <=3D cache->len - addr); if (likely(cache->ptr)) { --=20 2.26.3 From nobody Sun May 12 15:43:07 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1621508992; cv=none; d=zohomail.com; s=zohoarc; b=kxjC7UTfkJYaBvaAHZ/c8uAFo7ORBCWk/YejdwPDoSI+nWFRV+QrRR4Hx9RKHikBNUyFXOAs081mqirCIrAPHKCq76ViVdRhwVKxAwqnZT+LWkwpx/qu2aM579xbs//2ZogS86Nd3TE2b9Ue0DgWXOYEUt2y8RUSDWIYBjm4vzs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1621508992; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=tQhRr1d+vMSeLXHOF3EqT8MC2o1YqDGEA5IrzwoyL/A=; b=d+iWTboDc+Tznp3I4zb61BSllXR5U2HBu7kazJHbE/XgSNLjhsFseNpJw4p/StYPMsiLjBfe3lNACet1K3U6BQZTrucgm50IvqmZ9FHuC/kQitBwR4MlRpwQh46azgtSkiAumU38UoWEi9ClG/44YwFQe+a1/kjJ+L2Tu7j5JIw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1621508992822448.62250079714124; Thu, 20 May 2021 04:09:52 -0700 (PDT) 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-159-V1T6yG-rNqqmoAsfafcrDQ-1; Thu, 20 May 2021 07:09:49 -0400 Received: by mail-wm1-f71.google.com with SMTP id l185-20020a1c25c20000b029014b0624775eso2188216wml.6 for ; Thu, 20 May 2021 04:09:49 -0700 (PDT) Return-Path: Return-Path: 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) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1621508991; 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=bBnPciyKw4mgWlwVE5D3VUToibbxGKERJdo/qCPyInNcSA8ZEikp4PA6oME7q5mewyMquT KaeCgy69BahJA7Hwg1DtBjTL8gB9k3SczyiUxmKx8/G4XXmUU5YCEhBE73UW5ooMvW6z1l gmxRET2+GruV5YORGMQA0EJyvE1H8AA= X-MC-Unique: V1T6yG-rNqqmoAsfafcrDQ-1 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=gpMShAwsCnhZ5hwDew1swHsl3WBgR+8v1azLGKA93zejUIcB0f4TSTnEnDr5Gb5dZi i1HbTeCW1WIyodUsa9zRvpNV+kgFiHkgh5dnS3VAiZdmnsTfDuJh09id5RidhTheEPQr s4D4yBM/8/7YaWV2iv/pUeuoWEIGhceNFQngdOFyswc7HznkVCPp/TDj62rBr9ewmWTc Kmkn1rUk20Dlgql9xIEe/UrTx50stwqfbSo8dfCUzI8Xa66LYgCIWAtyABdscE4BLM8o aHSBzy1QUt196nW/RGbdNNjZD35wYD0VXV4ytTgQ+rF9TPa1os+f3/1lMg7n1fW0xbnh vZog== X-Gm-Message-State: AOAM5337ICoqt6QIbz8rdgon41WWNjv+UKGlJiLHtNKnT7cd4O8FeHfl XHvLeDa91NvTC6iTL49wkTufeJCBoqwr5zl4fio1PNIVTu0TSdmqClQquBn4ywooJq8nHhLZzoL NgJ+PmOXjMzXgWg== X-Received: by 2002:a5d:64eb:: with SMTP id g11mr3770258wri.260.1621508988250; 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) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: "Michael S. Tsirkin" , Stefan Hajnoczi , Peter Maydell , Peter Xu , Paolo Bonzini , Richard Henderson , Bibo Mao , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= 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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) 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=C3=A9 --- 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_ld= st_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)(Memory= RegionCache *cache, assert(addr < cache->len && 2 <=3D cache->len - addr); fuzz_dma_read_cb(cache->xlat + addr, 2, cache->mrs.mr); if (likely(cache->ptr)) { + if (result) { + *result =3D 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)(MemoryR= egionCache *cache, assert(addr < cache->len && 4 <=3D cache->len - addr); fuzz_dma_read_cb(cache->xlat + addr, 4, cache->mrs.mr); if (likely(cache->ptr)) { + if (result) { + *result =3D 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)(MemoryR= egionCache *cache, assert(addr < cache->len && 8 <=3D cache->len - addr); fuzz_dma_read_cb(cache->xlat + addr, 8, cache->mrs.mr); if (likely(cache->ptr)) { + if (result) { + *result =3D 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)(MemoryRegio= nCache *cache, { assert(addr < cache->len && 2 <=3D cache->len - addr); if (likely(cache->ptr)) { + if (result) { + *result =3D 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)(MemoryRegio= nCache *cache, { assert(addr < cache->len && 4 <=3D cache->len - addr); if (likely(cache->ptr)) { + if (result) { + *result =3D 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)(MemoryRegi= onCache *cache, { assert(addr < cache->len && 8 <=3D cache->len - addr); if (likely(cache->ptr)) { + if (result) { + *result =3D MEMTX_OK; + } ST_P(q)(cache->ptr + addr, val); } else { ADDRESS_SPACE_ST_CACHED_SLOW(q)(cache, addr, val, attrs, result); --=20 2.26.3 From nobody Sun May 12 15:43:07 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1621508998; cv=none; d=zohomail.com; s=zohoarc; b=PUiI082KMPMP68cUPywpjcFtypgptxNUFly036RYXYWv5V/bPs1n7fGdsdxUYo9dfklyBnOPwaD3PInYrrGo6gxzptniqv6QvpRXGA5sJQK2MIBhlj+kCDe2irlVBuhCQAKwPYjLGLUHN6ibO+VPELp8GWxz0e4q+AE+2NQFFac= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1621508998; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=fXNvsUG+9jJQpscb+R8eaH4L2n3MJcy4IDVc87G545A=; b=Gds4Vm22sfo8CKpAXR81xFcpoqmcZ94BS6ZN6k27wiSCKjY7QsnYtQyi7+zXASZ4QtRYz5vNr/IPBWPxEp601KJkgZssvvqRPg8cn2n7ctf99CPI7dB8Lm24bzgh4+qEJxVM7+RIZ03nSxu+c0jQ4OT41VZsaPmXxyYNwBYZv1c= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1621508998476649.8503194851352; Thu, 20 May 2021 04:09:58 -0700 (PDT) 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-427-6lnvCAYlOFyxvb6JCPXpYA-1; Thu, 20 May 2021 07:09:53 -0400 Received: by mail-wm1-f71.google.com with SMTP id b206-20020a1c1bd70000b02901713122405eso1314326wmb.1 for ; Thu, 20 May 2021 04:09:53 -0700 (PDT) Return-Path: Return-Path: 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) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1621508997; 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=ZnKS2UJAgh2F1eCE/+LYPEbQNIRcWW5I4WOc2BgFLvwTLa5ayCwGzHPIRb+QsnTkT00GYL hNecMAnA3Qs+yycd8gYXbIvZSTucpec+yVH+UJYOcNHl+sYL+lITzZGBDheT+cYuoiRFEo dbve8tKwNTbitYOoidz/yHndhWJ9nUI= X-MC-Unique: 6lnvCAYlOFyxvb6JCPXpYA-1 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=Iak1qkTYwoA0PmHPabdSCCf9Yjtip8zdwPUrOV2UZ9dKHeOmZKH/SJ0xMiTjaXergo TXXIwpjSLEtFI3L0bJs1xYP1dl9njuZUf2EctIWa1M9XxMB1FmnrLa0e60RcKwMQ83Dq VPdQIgO+JlTwIHOp7e6+sXSDdpxYMg06HMrxPaa53Nmev1zGL1ztAHWkyZounKQDa/Rj XhYUpNE0dA2Q10Ra4Py/9UevbucxArJ+ChtkFSutlwcRncIDkoU2B+klrhgoiXR2yXkS 1qNDI/Sh4xKt6SWWwSHxnkwFtj3nS8bydqy/M6/uST74uRkPg7AqcuP4dmmcSnVAHBvi Enpg== X-Gm-Message-State: AOAM530z+R2MCZjW6ZbY0YwtdRlJsQQendopY54hmst9c1KH+20NhueE CyaEh7whMu7scw9ymNkcq9qfFgeJkaneaQr4NgLMK1Ut87qylsg8w2dgQ0v/WKMGQbADfP2YmmI Cv6XHWCxzz3KE3A== X-Received: by 2002:adf:b64b:: with SMTP id i11mr3726385wre.157.1621508992706; 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) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: "Michael S. Tsirkin" , Stefan Hajnoczi , Peter Maydell , Peter Xu , Paolo Bonzini , Richard Henderson , Bibo Mao , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= 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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- 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_ld= st_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)) =20 +/* warning: addr must be aligned */ static inline uint16_t ADDRESS_SPACE_LD_CACHED(uw)(MemoryRegionCache *cach= e, hwaddr addr, MemTxAttrs attrs, MemTxResult *result) { @@ -39,6 +40,7 @@ static inline uint16_t ADDRESS_SPACE_LD_CACHED(uw)(Memory= RegionCache *cache, } } =20 +/* 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)(MemoryR= egionCache *cache, } } =20 +/* 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)(MemoryR= egionCache *cache, #define ST_P(size) \ glue(glue(st, size), glue(ENDIANNESS, _p)) =20 +/* 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)(MemoryRegio= nCache *cache, } } =20 +/* 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)(MemoryReg= ionCache *cache, } } =20 +/* warning: addr must be aligned */ static inline void ADDRESS_SPACE_ST_CACHED(q)(MemoryRegionCache *cache, hwaddr addr, uint64_t val, MemTxAttrs attrs, MemTxResult *result) { --=20 2.26.3 From nobody Sun May 12 15:43:07 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1621509000; cv=none; d=zohomail.com; s=zohoarc; b=mGLAei7YJUW/aIHrtTslYdbUvKU3nSAjB8Prf3QezDiTnikrdjESAoZkmC7WCZqOrG95TzvZ0P0HHehZSDiUzf0vzVQkQwsIg3hfKuoY3F6s38LmzabhmevUQCxsOJOk9u2RXwA2HaXbRZyAgoc+tGeogoS9ksDzD7OqsDhrBjQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1621509000; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=QEjpdg/IZ00DpLUx/mVY0KVvckbtUYRfwfr8N0WJ7zo=; b=BkMuSY8X+bg0/FmGiMpzIZAftI9COD+wpxBebwzTNQ83aL+RvyW6nwj5FrRgEFCgsHS7vz/N09y6UAIcxTJwS/5FI94xj8UaF4OpNkca6TWUu5Hcb5AYwXHWmM6hzrX4HOELN1MjnSscxrT6N/vvCZSWeaA13QirkEB+AiU/tKs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1621509000852869.1324845597298; Thu, 20 May 2021 04:10:00 -0700 (PDT) Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-206-eucBqCreOuC1Gfj9y55Qvg-1; Thu, 20 May 2021 07:09:58 -0400 Received: by mail-wr1-f72.google.com with SMTP id p11-20020adfc38b0000b0290111f48b8adfso5026390wrf.7 for ; Thu, 20 May 2021 04:09:58 -0700 (PDT) Return-Path: Return-Path: 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) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1621508999; 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=IQD6WoO0dyRZp8zYT4lRYt9sZ54KwhwB6Lln0BBWdj7u8Q3Rn2A3PkpRp/UEk8uHKXNfOR Yqtnn3PcnyuO3rxtCIFhG6x3PPgK9oaWnD7zqIg009h3B62lRJf6ySVQOfz8zh2evM2QaY fSfqxwybfrfYio2kA8KD6jPPpgkGbU4= X-MC-Unique: eucBqCreOuC1Gfj9y55Qvg-1 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=TRD7ZcxR21OmLHzWWVdGRV382BgF8QzVPivQiA1Awqb/bRi9T25R/Wj2VW34ENCE/8 umHEBxVBpP6EcCEX7l/0vlLceGgIvEw0UVHKReZwu82XEe8WlHMOY+YqwDBwnQ6iPV2h f0CUkXbsnh/WsKcMQzLlXslI9xN9xtsxiz6tObN4QeehXIVknPLG/dZaomsH8fpKj0eR 03H9k/bjgc1Uto9J986kW+mcKLxHE6u96cvpQ72OeDDdWDo7C0A6hdrH5VNpLkl4sFyl 5MV70VIbdQK20sOv++SWA+Zw6n0Hl21AyiziQV8s/M4EcYb+1c3kvcPSU09ImxvUWk3f hDCg== X-Gm-Message-State: AOAM5317uw2kblZo2Lpf0fcce4YHRYsBGXcdO1PRXI9nm9rk1RWLx4Sn 2MddDVBSfFVhJixaQJaILa1V3hrAm1NH4KTC3pQ56JmUqOFsMI5l9Wt6GsCMh6L1EImuwi9+Tnp VNTPJAqODQFXXwA== X-Received: by 2002:adf:d4d1:: with SMTP id w17mr3820159wrk.413.1621508997219; 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) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: "Michael S. Tsirkin" , Stefan Hajnoczi , Peter Maydell , Peter Xu , Paolo Bonzini , Richard Henderson , Bibo Mao , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= 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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) 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=C3=A9 --- 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_ld= st_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)(Memor= yRegionCache *cache, assert(addr < cache->len && 2 <=3D 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 =3D MEMTX_UNALIGNED_ERROR; + } + return (uint16_t)-1; /* XXX */ + } if (result) { *result =3D MEMTX_OK; } @@ -47,6 +54,13 @@ static inline uint32_t ADDRESS_SPACE_LD_CACHED(l)(Memory= RegionCache *cache, assert(addr < cache->len && 4 <=3D 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 =3D MEMTX_UNALIGNED_ERROR; + } + return (uint32_t)-1; /* XXX */ + } if (result) { *result =3D MEMTX_OK; } @@ -63,6 +77,13 @@ static inline uint64_t ADDRESS_SPACE_LD_CACHED(q)(Memory= RegionCache *cache, assert(addr < cache->len && 8 <=3D 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 =3D MEMTX_UNALIGNED_ERROR; + } + return (uint64_t)-1; /* XXX */ + } if (result) { *result =3D MEMTX_OK; } @@ -89,6 +110,13 @@ static inline void ADDRESS_SPACE_ST_CACHED(w)(MemoryReg= ionCache *cache, { assert(addr < cache->len && 2 <=3D cache->len - addr); if (likely(cache->ptr)) { + if (attrs.aligned && unlikely(!QEMU_PTR_IS_ALIGNED(cache->ptr, + sizeof(uint16_t= )))) { + if (result) { + *result =3D MEMTX_UNALIGNED_ERROR; + } + return; + } if (result) { *result =3D MEMTX_OK; } @@ -104,6 +132,13 @@ static inline void ADDRESS_SPACE_ST_CACHED(l)(MemoryRe= gionCache *cache, { assert(addr < cache->len && 4 <=3D cache->len - addr); if (likely(cache->ptr)) { + if (attrs.aligned && unlikely(!QEMU_PTR_IS_ALIGNED(cache->ptr, + sizeof(uint32_t= )))) { + if (result) { + *result =3D MEMTX_UNALIGNED_ERROR; + } + return; + } if (result) { *result =3D MEMTX_OK; } @@ -119,6 +154,13 @@ static inline void ADDRESS_SPACE_ST_CACHED(q)(MemoryRe= gionCache *cache, { assert(addr < cache->len && 8 <=3D cache->len - addr); if (likely(cache->ptr)) { + if (attrs.aligned && unlikely(!QEMU_PTR_IS_ALIGNED(cache->ptr, + sizeof(uint64_t= )))) { + if (result) { + *result =3D MEMTX_UNALIGNED_ERROR; + } + return; + } if (result) { *result =3D MEMTX_OK; } --=20 2.26.3 From nobody Sun May 12 15:43:07 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1621509007; cv=none; d=zohomail.com; s=zohoarc; b=gZ9OI29LlhSg17T6iBiayHEb0T1BC0rNW5IysPqMBGAdPLC7gA10CjlJQ982iH9qorUTFf7mdV5r4lAd33aIe9z2T5DOh+/zHDsVNRPH3uLNxNUmuiIcns/yFvXkjkgotr9aBQzllfYjh7y+KoHgTKhPfnI9SQqnO51J8iS7fZg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1621509007; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=S06OJbLcsLoisVvd+3p+23m8ISoQC7YgJjRfb76l+Q8=; b=ItbBdlT3vBcP6EHm0GPuWgMg51kOanAf4fjpB+8ZPiQL8GVAIhqZp27IVmsxwVL505aQ2Q9HZeLwXjjEcK9OWcurYTMFoXWzG6vpOinm512RfOqvdTgx1VyzTMGXUhXDlVZZvHJ5clx2iOaHHNLqJ2mORqO9Aorqpv1Hoey8k4U= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1621509007468284.3098123891566; Thu, 20 May 2021 04:10:07 -0700 (PDT) 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-547-SUPynbbtPvmef_BKOeMzrA-1; Thu, 20 May 2021 07:10:02 -0400 Received: by mail-wr1-f70.google.com with SMTP id c13-20020a5d6ccd0000b029010ec741b84bso8490720wrc.23 for ; Thu, 20 May 2021 04:10:02 -0700 (PDT) Return-Path: Return-Path: 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) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1621509006; 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=SNG4mxs6QtRgojCgXjvyeq7l4LXrlv3USsbn4wqxnROAUroz9+netzvUW2Oh42Aee9+Qh8 A7mqaUx2eD4zacZ/RUo7HAv3cAkFDowmnXai9VEeky0aFWgnYwoQnReLgjo2kFZoZ36RjI 38r7WTy8OVl3rxesSfh9hoV5UCYe7a0= X-MC-Unique: SUPynbbtPvmef_BKOeMzrA-1 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=nU0faGjlEmrKufyvDyBCO/9l6UtVXextSmQyZE9lff7FEX6HaNIIKLRUr6kWlsOcPo j4+7wzz5X02fv+Ob51l2hxLGWqUTN5VmARxoD1RwLQ5MN992Q71ffr467iTO/FkDVGBH tFra/bTbQDI4O0oqdGbTs3MoBJspuG4XNFZEHTtF14Y1jGXKjbqrqpo4R8rA6egTHtt8 OEci26A+vC/xw30JoQvhcma98YSwfCMVlZrvTZcJWQHYNMx1RPU5DmXmqxSCwO3ppOvE v7M+jWbLx+/lWST/3Zv9Orhjftx/nJze0u7q+qiusEO1KeDBd2jaJ2Uyg4crZWV81uEI RXfg== X-Gm-Message-State: AOAM533SRtZh8LvGnUGprPAb2xGuA9mkJAh/Z6zw4r467B0sBJeO+MtU e7pBnOFtCrNhp1m+dl2HYc0EZ6W+OUoIPWdPPVAGUTirA2NHvfWcunXm97MAfg7tsfxh6aUM2zT VV27gjOzyxScDYg== X-Received: by 2002:a05:6000:1286:: with SMTP id f6mr3585450wrx.226.1621509001831; 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) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: "Michael S. Tsirkin" , Stefan Hajnoczi , Peter Maydell , Peter Xu , Paolo Bonzini , Richard Henderson , Bibo Mao , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= 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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Use uint16_t for unsigned 16-bit data and uint32_t for unsigned 32-bit. Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- 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-a= ccess.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, voi= d *ptr, uint64_t v) } } =20 -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, con= st void *ptr) } } =20 -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); --=20 2.26.3 From nobody Sun May 12 15:43:07 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1621509010; cv=none; d=zohomail.com; s=zohoarc; b=Ayfzr+8u+/mi1DUhw+IOUpUNtPjZcAOxMBV/Rkuf7vZMvqH99KCbXSyNXfAB50cV9f+3YT/9T8pJrZYeTsqNY+eBlfBRvNddmJoFWn7vpDkIbVc4j8z6CaOvS3hgq4sDvu/+mFZPtA8hyfQA1EhlU6jzl2tgLDMFaVSjQrH2bZk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1621509010; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=B2sGmsuzq6ssxzUGpyvhj2pP3TABHbW6gQF2vvqdbU8=; b=l5BdCWjs/VQTRVNard+GvLUg6s4LeVoUpYC7w1OcJkuxUj74X2AVi10//4p+21Ph2QxkqeDYgUFL/1yJQEPjN6wCupR+fGcpg2JQVe+9aozon52IAx3VguILmFrzWRZkoJeOmSukrbWWtpxu1Gw7Uw4e3+wZ/GwS76B3hEJeGvc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1621509010336971.8114157977484; Thu, 20 May 2021 04:10:10 -0700 (PDT) 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-528-DAkvujRaNWqkrBZ3QZO_6Q-1; Thu, 20 May 2021 07:10:07 -0400 Received: by mail-wr1-f69.google.com with SMTP id a9-20020adfc4490000b0290112095ca785so3287612wrg.14 for ; Thu, 20 May 2021 04:10:07 -0700 (PDT) Return-Path: Return-Path: 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) 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= X-MC-Unique: DAkvujRaNWqkrBZ3QZO_6Q-1 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=UeVNmLunLnftEUQH9ceRaBTy2bXXRl1vV5obUfYVUBifEpeZZiMwZwGeHSG9DDud27 hPGxtc5REpgzGSHEvtAWVJXeX7UB7XxeNgGqM2Y6RUrNhd88xiGFqs9UpokdOMRqYCKB 7UHcVGGNWcftd77zBxMAJZRhj6HBLI+X5DK/Z30ljywHkQh6+GGPPKHtzgiCULoFBNh6 UAWphr80bNhYG5ukBjmsBDegnqitAQI6M1x7Ty+lTHUjxy1bkpMVH8dJwo0NtZghKtvw F6+Gbb2dz54X5wvUpI2rC6+/fn+tFm2Mve4VjCr3/AKWgTuHVFx1t7+pCRysSbR8XBDY sDaw== X-Gm-Message-State: AOAM530yW15Kl3TQ4tx6iUYgB/QoB9fU7pH/u7jVs+AD04LcmuwsVi7Z FEt2eYwaKkfnXfXtXvjJEulZLW6l4GN+eYnyfnHnggqNcxKb5HumZqXcohr7hoZpz7gIkSFpVPc b59AhgScf6yiPng== X-Received: by 2002:a5d:58d0:: with SMTP id o16mr3688285wrf.420.1621509006516; 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) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: "Michael S. Tsirkin" , Stefan Hajnoczi , Peter Maydell , Peter Xu , Paolo Bonzini , Richard Henderson , Bibo Mao , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= 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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) 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=C3=A9 --- 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-a= ccess.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 *v= dev, uint16_t s) #endif } =20 +/** + * virtio_ld*_phys_cached_with_attrs: load from a VirtIO cached #MemoryReg= ion + * virtio_st*_phys_cached_with_attrs: store to a VirtIO cached #MemoryRegi= on + * + * 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 w= ithin + * 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 *vd= ev, + MemoryRegionCache *cache, + hwaddr pa, MemTxAttrs attr= s, + 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= ); } =20 static inline uint32_t virtio_ldl_phys_cached(VirtIODevice *vdev, --=20 2.26.3 From nobody Sun May 12 15:43:07 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1621509014; cv=none; d=zohomail.com; s=zohoarc; b=h1+CEvcrbOH4sFKuHFw+tMoSwCkn8XJv5mQfVr9H4uZFp3iNnPZSNvuONMGaIivdUuxeQSP8094a4NL5vs7rPpRucGhX/2tbk7gIlPXxPSAJgpXPa1w3JhFU6VXgMUuSXLl9PvZfOKzWGb3jzaIIxWkC63VpvkHRXPHgPohl95k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1621509014; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=hT9YCxRj1ou3uPTM7bSJ+zjEyH6kGbopTpVH+99i5eA=; b=TRcW6QRdd7Fwrawzjs9LuUq0IQdof+4q74PwKgMR/Rt2HsRXspKsfRSfiOB2Q0GoGZjgXjHm+6CsfSDll1cf2k2Fec/zRTwEQy7d03OTsIhSRhwlnACXNQhAfJZVpn/DL56preoMUvBoglClTpoRPCB7Y547o5qbD8eG+9IyQbc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1621509014709929.2536681533354; Thu, 20 May 2021 04:10:14 -0700 (PDT) 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-570-_THqcu1dPky5pYOT91ePFQ-1; Thu, 20 May 2021 07:10:12 -0400 Received: by mail-wr1-f69.google.com with SMTP id 67-20020adf81490000b029010756d109e6so8435359wrm.13 for ; Thu, 20 May 2021 04:10:11 -0700 (PDT) Return-Path: Return-Path: 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) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1621509013; 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=HO9dqijb1Yl9a/WJpsVFU5iPlOono3NyxdBfp8uTxmH7iQzRRCXm96tghZW1eNvlev5eFk Q1aqkIS7UlG0PWsJJoEemDT6JDaRpriA1zY4I38kQuVIf/n2Pru1W+hDXVnPEzs+08CWbv FTz3rcSKqLR30UMXml3C5U9FDG3w2f0= X-MC-Unique: _THqcu1dPky5pYOT91ePFQ-1 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=lRffBMQ+9YUGxNZPjbiG9ySzZviZsJyZXJDT+3Xgy6FH8OT+rdk9LNkYgAbb2C5YG2 fsgWdjcyZn5aS8xEfP8b5mCyCxijF5xp71uwqY78PIlozLRC/05IR66/o4kW98Bncp+6 +SaDMBdZ9oNbKVTr8WEc6xCdjKiNu5tUSHwZUlb4dNOST19eraNC6A3NAyAsZdvTfOLF sU1Ccwp+t6N7tzE15MEsA2imily+ORS7leyBfCmzlldPvjYW0+mh9PzWMFFuCeqQ3Ado ZgKB0rvIFXWfqR4XrZrIHxEZWSJ/1OuNplu4NzgWwuGLLD7aCEX75VvKdox4Qvjc8JIU jW2A== X-Gm-Message-State: AOAM5301jNwojWi58dLpDK8zd7nSZMcTKUO7hjv9L2CqG51Dh9KKbS2X QyOk5NT1T+pNJrU2d73QlQMkcsn31/xvqTuq/pX0DT1yE3CHsFxLU5RXPZX+pvTu5rvXJkRFwEy UcoVeJJ3DkFc1yA== X-Received: by 2002:a05:600c:1909:: with SMTP id j9mr3175846wmq.100.1621509010984; Thu, 20 May 2021 04:10:10 -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) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: "Michael S. Tsirkin" , Stefan Hajnoczi , Peter Maydell , Peter Xu , Paolo Bonzini , Richard Henderson , Bibo Mao , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= 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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) 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=C3=A9 --- 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_cach= es(struct VirtQueue *vq) } =20 /* 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 =3D vring_get_region_caches(vq); hwaddr pa =3D offsetof(VRingAvail, flags); =20 if (!caches) { - return 0; + *val =3D 0; + return true; } =20 - return virtio_lduw_phys_cached(vq->vdev, &caches->avail, pa); + *val =3D virtio_lduw_phys_cached_with_attrs(vq->vdev, &caches->avail, = pa); + + return true; } =20 /* Called within rcu_read_lock(). */ @@ -2462,7 +2465,9 @@ static bool virtio_split_should_notify(VirtIODevice *= vdev, VirtQueue *vq) } =20 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); } =20 v =3D vq->signalled_used_valid; --=20 2.26.3 From nobody Sun May 12 15:43:07 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1621509019; cv=none; d=zohomail.com; s=zohoarc; b=grEknvvx9JgBRQCeKgD/ke2zyFzb/jWtnJIiQv+dvUeSalvKHRl/Y4lUDmubSDUP174OFmCp6fLvCKm4l5ZDFArp+dPyGk9piPsEOFQdXVO8pZtFYQszGf/X4So3RlS7iUMEsV3l9Py3lirsBZkqyF8/L9rEDt3G+ltecUlIIJw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1621509019; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=SEIK0+f8xAhENSUO1Wsp9GXIhMyGmKAMVfEhOA0o4Xo=; b=DYMSyIYXHNXt9sZ53dLgOL3JrHTGdT9OafXBSzdPhl1PJU8Wm+D5nlHDev6Xd+HItXE7Cmsmb30MAoF6vIJjga+dioRi86qmmyew6VtfSp9XcduJ59gRFGGnNTXRGuaE6I/E55el8B66yO0RHcJYWlmqpMmcLxUDQ3LEnOpqZTs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1621509019261518.9309014680293; Thu, 20 May 2021 04:10:19 -0700 (PDT) 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-420-erX2qkoLNsW6y0owdAtYHg-1; Thu, 20 May 2021 07:10:16 -0400 Received: by mail-wr1-f69.google.com with SMTP id i15-20020a5d558f0000b029011215b1cf5cso2138822wrv.22 for ; Thu, 20 May 2021 04:10:16 -0700 (PDT) Return-Path: Return-Path: 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) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1621509018; 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=h7foC6jXPwSLlnK0IANgf5ObN46rCZvn++ydBmaJbeTZZUTuZA4OjLrZX9jbZpbj0Swfqq rBl0fP+hmMW6d4RZEHPInyuwdd+zbBQpmZ/b/TE9tNrwwd6sMk7VUcD0Eyk4Wuk00o7/+/ Np6zv/7dA0+78L2bsKTYF1/RRBq1TpQ= X-MC-Unique: erX2qkoLNsW6y0owdAtYHg-1 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=SLd5KleIO8rpr5uBdo2zLJTr7mBsXtvdi+XWmvSTNbxmH4J00WJlC9TdPXWcX76SKN NogUJV0kNHf3KV6b0K0sLOpieN2cdOmQCiE/pGKjOMwofE/4RDvXdJI/DoadBdSHnh9b Rl0S3ChY1qwIQl3fA2ouOieTwIl/fWU3v8WBIsDyHaM6OzCpOqIPnLCb0T7RtWgUNdo/ jOZ39+k1Tq3qenuASVuIWoMdEQzTSRO1PM5eeGGrm6bWZqIw7AGJPslVgu/IpDN0Ytj+ UD5mYkAEENX+1xBBdTDlWshJe7E1FcouZ/Y+qiZBXMHb5JwUno7brAUYxZA95f9IClEl HU+Q== X-Gm-Message-State: AOAM531ZuTupzem/E/dIO0BCi6oJdqeSFWt/sswQG+2NMvwYD4XnQZ7f 4nWKFUsxS9oDYTP1ZSi9MJ0jv/OP9ckfW72RIVwMbIePsb6fMukKpHZCj8grHIAKXvYVu7mZnJp JI47M9h5FIOGgnQ== X-Received: by 2002:adf:e608:: with SMTP id p8mr3801832wrm.162.1621509015591; 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) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: "Michael S. Tsirkin" , Stefan Hajnoczi , Peter Maydell , Peter Xu , Paolo Bonzini , Richard Henderson , Bibo Mao , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= 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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) 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=C3=A9 --- 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, u= int16_t *val) { VRingMemoryRegionCaches *caches =3D vring_get_region_caches(vq); hwaddr pa =3D offsetof(VRingAvail, flags); + MemTxAttrs attrs =3D { .aligned =3D 1 }; + MemTxResult res; =20 if (!caches) { *val =3D 0; return true; } =20 - *val =3D virtio_lduw_phys_cached_with_attrs(vq->vdev, &caches->avail, = pa); + *val =3D virtio_lduw_phys_cached_with_attrs(vq->vdev, &caches->avail, + pa, attrs, &res); + if (res =3D=3D MEMTX_UNALIGNED_ERROR) { + qemu_log_mask(LOG_GUEST_ERROR, + "virtio: vring flag address 0x%" HWADDR_PRIX " " + "is not aligned\n", pa); + return false; + } =20 - return true; + return res =3D=3D MEMTX_OK; } =20 /* Called within rcu_read_lock(). */ --=20 2.26.3