From nobody Mon Feb 9 01:35:49 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.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.129.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=1639592678; cv=none; d=zohomail.com; s=zohoarc; b=Vc+1qRnfDWUVCWsQdVUwlfvoeib7N65i1TXpedNn8vnx+/gwTjbS6p8x7lt9GGj2mGcaO5s/uWWCzwj3W1qVCsxqzSWSSUwGiQ9GbAWEXIB6PM4VoF2EQOwhsybT79HizMZ14/fy0l5D7o329J8FUEMSQSXfRu1pp+q61KpuMjM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1639592678; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=7G1VF+PYn/+nnSsAzukj8f/eEEWiK0TuuEhDYLjNh0c=; b=U5DM09NrWbJLqi41q8WleuCEVITSu9g3lrTngocIbAxQXkFctmbsRYH2qgPm1agJyo42Ud040k2PJB8rReqMzaplbQmdd49fKsBK/lZEo1hL0CCx07WCUYHyr63/GN7SxD/XWWjj0LMQd+5fN6273LRJo6bAFBHsel5B6sLrnu8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass header.from= (p=none dis=none) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1639592678322868.3327828069786; Wed, 15 Dec 2021 10:24:38 -0800 (PST) Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-301-B9ErUUogP32bhIeVS5_1WQ-1; Wed, 15 Dec 2021 13:24:36 -0500 Received: by mail-wm1-f70.google.com with SMTP id ay34-20020a05600c1e2200b00337fd217772so9378491wmb.4 for ; Wed, 15 Dec 2021 10:24:35 -0800 (PST) Return-Path: Return-Path: Received: from localhost.localdomain (174.red-83-50-185.dynamicip.rima-tde.net. [83.50.185.174]) by smtp.gmail.com with ESMTPSA id l7sm3197050wry.86.2021.12.15.10.24.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Dec 2021 10:24:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1639592677; 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=7G1VF+PYn/+nnSsAzukj8f/eEEWiK0TuuEhDYLjNh0c=; b=Km7DPu+wwqho6VKpaWTKoLY8CyMP8HPZQLqmJU12BQpxXvJd9DZ1nxTpsFueJLE0OxmY77 VFMlEkV56ISdf5NSBiBzwb8t3QkHb2SrjRooxB0Ksc57BdPYDAqRpWDFaZXS1TpcDGbSgQ KJzjBgDauz764yZnEzvSrqThcWZBRJg= X-MC-Unique: B9ErUUogP32bhIeVS5_1WQ-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=7G1VF+PYn/+nnSsAzukj8f/eEEWiK0TuuEhDYLjNh0c=; b=Lpv4Mot5KQAxo1un6zxiWyC5b0tHFHkVud1Gji+R8/Yqz/p2jw2wU25n/DJ2ozzLyh 2uca+1WPMkjEZqQaz4iVCTsWAxEkDOX6VhjffOZZbCJwjHAKDlhEcqmrXV6TaNonrZBp 5m+Gx3ptqXCPwVGtSwOGvE2Y+/R/MQjRU+sggtFJFCguZF27VWqSYI59LkNo2xbPBAfr af4WiUeNGNthhWAksPWxn5hn6fxzYv71mLn8Fe1tbV6RJIqv8IzQITDd8l62YYlJIBKJ 5xEUTgl7dj0zariKgToPu5eAEWlQcaLe2myM8Bu2nHn00c5LY3gqCIa9jtg3HyZTbBch 72LQ== X-Gm-Message-State: AOAM530U4idTTYAPAqOpBWhLjxTQNNHaYT/hXamOVh7EpqkDVU4mqyYx y/MKXT/+xUMo9ABWS6FrA5ExtDKqDOEJS+v9p5qFW765PP8sNtXRt3dFxOAq8LQpLiESKwHwxnK iPilQpvHAj/xbkw== X-Received: by 2002:a5d:6e04:: with SMTP id h4mr5527085wrz.127.1639592674962; Wed, 15 Dec 2021 10:24:34 -0800 (PST) X-Google-Smtp-Source: ABdhPJy/6tQOC94ZVXRnSKKwJy/xHb6zXg14tepShevZlsuwcw/DDwFxXZmzwxaye+nN9pjDKGEubw== X-Received: by 2002:a5d:6e04:: with SMTP id h4mr5527064wrz.127.1639592674829; Wed, 15 Dec 2021 10:24:34 -0800 (PST) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Paolo Bonzini , Peter Maydell , Peter Xu , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Alexander Bulekov , Jason Wang , Qiuhao Li , Stefan Hajnoczi , David Hildenbrand , "Edgar E . Iglesias" , Li Qiang , Gerd Hoffmann , qemu-arm@nongnu.org Subject: [RFC PATCH v3 1/3] hw/intc/arm_gicv3: Check for !MEMTX_OK instead of MEMTX_ERROR Date: Wed, 15 Dec 2021 19:24:19 +0100 Message-Id: <20211215182421.418374-2-philmd@redhat.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211215182421.418374-1-philmd@redhat.com> References: <20211215182421.418374-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) X-ZM-MESSAGEID: 1639592680236100001 Quoting Peter Maydell: "These MEMTX_* aren't from the memory transaction API functions; they're just being used by gicd_readl() and friends as a way to indicate a success/failure so that the actual MemoryRegionOps read/write fns like gicv3_dist_read() can log a guest error." We are going to introduce more MemTxResult bits, so it is safer to check for !MEMTX_OK rather than MEMTX_ERROR. Reviewed-by: Peter Xu Reviewed-by: David Hildenbrand Reviewed-by: Peter Maydell Reviewed-by: Stefan Hajnoczi Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- hw/intc/arm_gicv3_redist.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hw/intc/arm_gicv3_redist.c b/hw/intc/arm_gicv3_redist.c index c8ff3eca085..99b11ca5eee 100644 --- a/hw/intc/arm_gicv3_redist.c +++ b/hw/intc/arm_gicv3_redist.c @@ -462,7 +462,7 @@ MemTxResult gicv3_redist_read(void *opaque, hwaddr offs= et, uint64_t *data, break; } =20 - if (r =3D=3D MEMTX_ERROR) { + if (r !=3D MEMTX_OK) { qemu_log_mask(LOG_GUEST_ERROR, "%s: invalid guest read at offset " TARGET_FMT_plx " size %u\n", __func__, offset, size); @@ -521,7 +521,7 @@ MemTxResult gicv3_redist_write(void *opaque, hwaddr off= set, uint64_t data, break; } =20 - if (r =3D=3D MEMTX_ERROR) { + if (r !=3D MEMTX_OK) { qemu_log_mask(LOG_GUEST_ERROR, "%s: invalid guest write at offset " TARGET_FMT_plx " size %u\n", __func__, offset, size); --=20 2.33.1 From nobody Mon Feb 9 01:35:49 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.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.129.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=1639592682; cv=none; d=zohomail.com; s=zohoarc; b=jNDFVeBbVwnzwbAaADJIj2JTnt/mORqyaxsdIoA6PiNLu66ESHodn9RTmdGYQ5wKz0PNf5i2mDnfBOztnvgOQEd+M9Z/WcX7qPgPjw7W+QUXV3x5j1UjsdFblUVHOnPBRYwl3E/npUcFPZJudXK1AeI1QJCibOGkb7quQ3xDGm0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1639592682; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=4mzR8fzIq0zn1fqfmM14R0Bl8uzchpxL44PQBaxe0yI=; b=DXkMD0x89HlIcbC6xHnI6iiE92eT6yMcktoBFFPYD0DOMlugGcWGtjr0WSYzirXTVqOG+8W7nr6ww4EBtljntkJV4pgwkBmI3qYyVXDJVcuZ1zlvFMpWzTUD8VePRAM6M33MKGZNU7A2NDwTAYlC9QbE8uGPacVrskiPHQw799w= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass header.from= (p=none dis=none) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 163959268290935.260964066362135; Wed, 15 Dec 2021 10:24:42 -0800 (PST) Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-363-h952Wyh_Nym0ZIPjFVemqg-1; Wed, 15 Dec 2021 13:24:40 -0500 Received: by mail-wm1-f69.google.com with SMTP id 138-20020a1c0090000000b00338bb803204so12967255wma.1 for ; Wed, 15 Dec 2021 10:24:40 -0800 (PST) Return-Path: Return-Path: Received: from localhost.localdomain (174.red-83-50-185.dynamicip.rima-tde.net. [83.50.185.174]) by smtp.gmail.com with ESMTPSA id 8sm3103664wrb.49.2021.12.15.10.24.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Dec 2021 10:24:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1639592681; 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=4mzR8fzIq0zn1fqfmM14R0Bl8uzchpxL44PQBaxe0yI=; b=KEJK/D5M7ZAlbC/D219vx3IAM5YAW+LLbOW07CPxRl0BI4Ch1nWVVSatZc+9vb8YayPUPw epUL1gQ5WZodBflI0FA0DA6FXor2aCb5taQya6yMu56FRWV2UnxcjCx5GWpHgg5+FinTlz f0Poxp7byWlHqIcGmlLbHI99ciayydw= X-MC-Unique: h952Wyh_Nym0ZIPjFVemqg-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=4mzR8fzIq0zn1fqfmM14R0Bl8uzchpxL44PQBaxe0yI=; b=3Qyzz4vRfWR1u5veYwxD+j/xXRAzcO0Os5QLWUHgMy2Jb0l8sBJjZ4VyReXvPBPKiG Y91O4YD38kyu7ADvNBP7rzNkRzNdDrYDioMa2QgTRG27lXW7HAKB5cxBsBvfgusP9Suu TwWTxcB7hdBW2ZRmBjHKYnMfQ9KCggc1Hti4/KOJrDtjxWSsuBX8h4F/9FUc3bON2tim 7kyNKdpfwr3XXb82n1Fx0lXpQO54SwDQQLyo+IYBaG7zB2RteDJQSgwMtnCfcVhGjXVb iFEchu6nNwtyYhOisa6JrXT7RGEOJlTOLnq4nP2XXarJkajSrRUfJtQbmG4enH+/lObl GyZA== X-Gm-Message-State: AOAM530rxLPmz+n7hDaBkTcGQkqKlkaVRdmcFVdqrpf5lXzU3Xl/RuVf lhN3YeF3w9STRl+ttqsnxtHvNrzL1z+u+cIOD9i4W9uEnaf9fZyETnhyXcCWNrEVbRZuPkOoaQI +H6CKthGkchjofw== X-Received: by 2002:a05:600c:3489:: with SMTP id a9mr1268590wmq.120.1639592679505; Wed, 15 Dec 2021 10:24:39 -0800 (PST) X-Google-Smtp-Source: ABdhPJzjDwwBzg4qM9VuIUo4SsY/rYgAnw8MhOpilDb7jMV/eZQPVAVJ9516Umrn+mKP4jElxhqajg== X-Received: by 2002:a05:600c:3489:: with SMTP id a9mr1268568wmq.120.1639592679356; Wed, 15 Dec 2021 10:24:39 -0800 (PST) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Paolo Bonzini , Peter Maydell , Peter Xu , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Alexander Bulekov , Jason Wang , Qiuhao Li , Stefan Hajnoczi , David Hildenbrand , "Edgar E . Iglesias" , Li Qiang , Gerd Hoffmann , qemu-arm@nongnu.org Subject: [RFC PATCH v3 2/3] softmmu/physmem: Simplify flatview_write and address_space_access_valid Date: Wed, 15 Dec 2021 19:24:20 +0100 Message-Id: <20211215182421.418374-3-philmd@redhat.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211215182421.418374-1-philmd@redhat.com> References: <20211215182421.418374-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) X-ZM-MESSAGEID: 1639592684971100001 Remove unuseful local 'result' variables. Reviewed-by: Peter Xu Reviewed-by: David Hildenbrand Reviewed-by: Alexander Bulekov Reviewed-by: Stefan Hajnoczi Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- softmmu/physmem.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/softmmu/physmem.c b/softmmu/physmem.c index 007e7526f0a..6c97a20107a 100644 --- a/softmmu/physmem.c +++ b/softmmu/physmem.c @@ -2815,14 +2815,11 @@ static MemTxResult flatview_write(FlatView *fv, hwa= ddr addr, MemTxAttrs attrs, hwaddr l; hwaddr addr1; MemoryRegion *mr; - MemTxResult result =3D MEMTX_OK; =20 l =3D len; mr =3D flatview_translate(fv, addr, &addr1, &l, true, attrs); - result =3D flatview_write_continue(fv, addr, attrs, buf, len, - addr1, l, mr); - - return result; + return flatview_write_continue(fv, addr, attrs, buf, len, + addr1, l, mr); } =20 /* Called within RCU critical section. */ @@ -3119,12 +3116,10 @@ bool address_space_access_valid(AddressSpace *as, h= waddr addr, MemTxAttrs attrs) { FlatView *fv; - bool result; =20 RCU_READ_LOCK_GUARD(); fv =3D address_space_to_flatview(as); - result =3D flatview_access_valid(fv, addr, len, is_write, attrs); - return result; + return flatview_access_valid(fv, addr, len, is_write, attrs); } =20 static hwaddr --=20 2.33.1 From nobody Mon Feb 9 01:35:49 2026 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=1639592687; cv=none; d=zohomail.com; s=zohoarc; b=Nnt+l5kWxyBjRKqjsHuZBxjDDIoabiMVLfr5wLqeiNfkQXM7LIKiqmrWJxOjL/LJH23lFSOJmsP72brkA7vCqeqaKgCc6fs/LKwFfKfeKl3ln9MYcYPxMWYuJufH1PdMxANwJg25fdfyHkqJ3p7jXuFqHvn5DSIM3XPQdIpFWuU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1639592687; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=Qgbl1qGGn0Mrb86U52QIs0aG9NLVai4plfdZIwipvAo=; b=a4OcfqjjjXeBwOk/8Qdg9NDO9tfKwnkQhvUi0zCY3wxiOWflQTLbGh2m0CmqPNXa44QodiqsDGf2SnqTwShSj2SSR7VGypcbz1duk209lWF7qnIPmnVnekxpC942VthVQxEecsVHeZhL53/W4ZQBaiRolCrnB2HHV46yTcOLDds= 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) 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 1639592687353430.440018937604; Wed, 15 Dec 2021 10:24:47 -0800 (PST) Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-590-rZOsS7wtPcy1np3jXsF-FA-1; Wed, 15 Dec 2021 13:24:45 -0500 Received: by mail-wm1-f72.google.com with SMTP id n31-20020a05600c3b9f00b0034440f99123so2408269wms.7 for ; Wed, 15 Dec 2021 10:24:45 -0800 (PST) Return-Path: Return-Path: Received: from localhost.localdomain (174.red-83-50-185.dynamicip.rima-tde.net. [83.50.185.174]) by smtp.gmail.com with ESMTPSA id o1sm3493282wri.100.2021.12.15.10.24.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Dec 2021 10:24:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1639592686; 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=Qgbl1qGGn0Mrb86U52QIs0aG9NLVai4plfdZIwipvAo=; b=RvJkx0SoTa5lVAH1DN/FIHHKuF0gZpzSCkmSwHr/odn6HvObe+72Va7py9HefTfMf3k8Rq HMnaRzlGcAEy7eELrEnR9Q6bm6wQwt1dR3/e7jZtzFtQNYXdzxWShI4UUtayinCtNQ4oOy nmcVQZiG5W81KZinoSHU8xIQCJSl3VM= X-MC-Unique: rZOsS7wtPcy1np3jXsF-FA-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Qgbl1qGGn0Mrb86U52QIs0aG9NLVai4plfdZIwipvAo=; b=FZIEbuIp5pbmq7268ujfNLNpmqeHf3CeDMI+mfJQO5sVYiYlDG2qYL4NmGjvwbFSv6 oVIbtaEkctgPfSIzCkwlReujWwMQp5fw61OETot5p/3DxfGdaW/UZ/k3e0X+pIN35scr EvpDfa0EYFJdtANf4wFwXs447qs2PLSkr84MZkH5Wze2dI6a9Nr4CeQetCEzp7ekLMFZ sC60oZmYuMcRDPHlZvitXSQAcStsBZPPMq1a4YXL9A0UkYm80Tx7HWlitNMoy7GPtpOc r9EApSwX3YPgMM7RGNyffKgVguYkF29c5rlSFYA3W9Rst5LX3s/QxlaWxOnM6+pxphOq 1Tsw== X-Gm-Message-State: AOAM531WY2yAxEmhhmajkJ4W4KQCqNff5oNoG70sCAPlJKwlroJd0hKB DemDFLR1QoWGNDIR0TIV/C/5OEdg76W7hQ9cAUx4JbzJe91H8fR9vg8klAcdEUtmr/W+ULaqkHz eYeiU5V4iwHIDkA== X-Received: by 2002:a1c:7714:: with SMTP id t20mr1239904wmi.139.1639592684128; Wed, 15 Dec 2021 10:24:44 -0800 (PST) X-Google-Smtp-Source: ABdhPJwpaabsCA78x06H1uYhXHm0o3inKjGufr9gQkFjF3/b1QFaIPlsGYfF0QkLkJlzYRwkOpJBzA== X-Received: by 2002:a1c:7714:: with SMTP id t20mr1239873wmi.139.1639592683929; Wed, 15 Dec 2021 10:24:43 -0800 (PST) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Paolo Bonzini , Peter Maydell , Peter Xu , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Alexander Bulekov , Jason Wang , Qiuhao Li , Stefan Hajnoczi , David Hildenbrand , "Edgar E . Iglesias" , Li Qiang , Gerd Hoffmann , qemu-arm@nongnu.org Subject: [RFC PATCH v3 3/3] softmmu/physmem: Introduce MemTxAttrs::memory field and MEMTX_BUS_ERROR Date: Wed, 15 Dec 2021 19:24:21 +0100 Message-Id: <20211215182421.418374-4-philmd@redhat.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211215182421.418374-1-philmd@redhat.com> References: <20211215182421.418374-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) X-ZM-MESSAGEID: 1639592687648100001 Add the 'memory' bit to the memory attributes to restrict bus controller accesses to memories. Introduce flatview_access_allowed() to check bus permission before running any bus transaction. Have read/write accessors return MEMTX_BUS_ERROR if an access is restricted. There is no change for the default case where 'memory' is not set. Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Richard Henderson Reviewed-by: Stefan Hajnoczi --- include/exec/memattrs.h | 9 +++++++++ softmmu/physmem.c | 43 +++++++++++++++++++++++++++++++++++++++-- 2 files changed, 50 insertions(+), 2 deletions(-) diff --git a/include/exec/memattrs.h b/include/exec/memattrs.h index 95f2d20d55b..f0063583ee2 100644 --- a/include/exec/memattrs.h +++ b/include/exec/memattrs.h @@ -35,6 +35,14 @@ typedef struct MemTxAttrs { unsigned int secure:1; /* Memory access is usermode (unprivileged) */ unsigned int user:1; + /* + * Bus interconnect and peripherals can access anything (memories, + * devices) by default. By setting the 'memory' bit, bus transaction + * are restricted to "normal" memories (per the AMBA documentation) + * versus devices. Access to devices will be logged and rejected + * (see MEMTX_BUS_ERROR). + */ + unsigned int memory:1; /* Requester ID (for MSI for example) */ unsigned int requester_id:16; /* Invert endianness for this page */ @@ -66,6 +74,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_BUS_ERROR (1U << 2) /* bus returned an error */ typedef uint32_t MemTxResult; =20 #endif diff --git a/softmmu/physmem.c b/softmmu/physmem.c index 6c97a20107a..c03abcc0362 100644 --- a/softmmu/physmem.c +++ b/softmmu/physmem.c @@ -2759,6 +2759,33 @@ static bool prepare_mmio_access(MemoryRegion *mr) return release_lock; } =20 +/** + * flatview_access_allowed + * @mr: #MemoryRegion to be accessed + * @attrs: memory transaction attributes + * @addr: address within that memory region + * @len: the number of bytes to access + * + * Check if a memory transaction is allowed. + * + * Returns: true if transaction is allowed, false if denied. + */ +static inline bool flatview_access_allowed(MemoryRegion *mr, MemTxAttrs at= trs, + hwaddr addr, hwaddr len) +{ + if (likely(!attrs.memory)) { + return true; + } + if (memory_region_is_ram(mr)) { + return true; + } + qemu_log_mask(LOG_GUEST_ERROR, + "Invalid access to non-RAM device at " + "addr 0x%" HWADDR_PRIX ", size %" HWADDR_PRIu ", " + "region '%s'\n", addr, len, memory_region_name(mr)); + return false; +} + /* Called within RCU critical section. */ static MemTxResult flatview_write_continue(FlatView *fv, hwaddr addr, MemTxAttrs attrs, @@ -2773,7 +2800,10 @@ static MemTxResult flatview_write_continue(FlatView = *fv, hwaddr addr, const uint8_t *buf =3D ptr; =20 for (;;) { - if (!memory_access_is_direct(mr, true)) { + if (!flatview_access_allowed(mr, attrs, addr1, l)) { + result |=3D MEMTX_BUS_ERROR; + /* Keep going. */ + } else if (!memory_access_is_direct(mr, true)) { release_lock |=3D prepare_mmio_access(mr); l =3D memory_access_size(mr, l, addr1); /* XXX: could force current_cpu to NULL to avoid @@ -2818,6 +2848,9 @@ static MemTxResult flatview_write(FlatView *fv, hwadd= r addr, MemTxAttrs attrs, =20 l =3D len; mr =3D flatview_translate(fv, addr, &addr1, &l, true, attrs); + if (!flatview_access_allowed(mr, attrs, addr, len)) { + return MEMTX_BUS_ERROR; + } return flatview_write_continue(fv, addr, attrs, buf, len, addr1, l, mr); } @@ -2836,7 +2869,10 @@ MemTxResult flatview_read_continue(FlatView *fv, hwa= ddr addr, =20 fuzz_dma_read_cb(addr, len, mr); for (;;) { - if (!memory_access_is_direct(mr, false)) { + if (!flatview_access_allowed(mr, attrs, addr1, l)) { + result |=3D MEMTX_BUS_ERROR; + /* Keep going. */ + } else if (!memory_access_is_direct(mr, false)) { /* I/O case */ release_lock |=3D prepare_mmio_access(mr); l =3D memory_access_size(mr, l, addr1); @@ -2879,6 +2915,9 @@ static MemTxResult flatview_read(FlatView *fv, hwaddr= addr, =20 l =3D len; mr =3D flatview_translate(fv, addr, &addr1, &l, false, attrs); + if (!flatview_access_allowed(mr, attrs, addr, len)) { + return MEMTX_BUS_ERROR; + } return flatview_read_continue(fv, addr, attrs, buf, len, addr1, l, mr); } --=20 2.33.1